aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/00-INDEX4
-rw-r--r--Documentation/DMA-API-HOWTO.txt10
-rw-r--r--Documentation/DMA-API.txt6
-rw-r--r--Documentation/DocBook/Makefile4
-rw-r--r--Documentation/DocBook/kernel-api.tmpl1
-rw-r--r--Documentation/cpu-hotplug.txt2
-rw-r--r--Documentation/devices.txt1
-rw-r--r--Documentation/feature-removal-schedule.txt17
-rw-r--r--Documentation/filesystems/squashfs.txt2
-rw-r--r--Documentation/gpio.txt35
-rw-r--r--Documentation/i2c/instantiating-devices2
-rw-r--r--Documentation/kernel-parameters.txt3
-rw-r--r--Documentation/mmc/00-INDEX4
-rw-r--r--Documentation/mmc/mmc-dev-attrs.txt56
-rw-r--r--Documentation/networking/wavelan.txt74
-rw-r--r--Documentation/padata.txt24
-rw-r--r--Documentation/powerpc/dts-bindings/fsl/esdhc.txt2
-rw-r--r--Documentation/sound/alsa/HD-Audio-Models.txt13
-rw-r--r--MAINTAINERS21
-rw-r--r--arch/alpha/include/asm/dma-mapping.h2
-rw-r--r--arch/arm/Kconfig51
-rw-r--r--arch/arm/Makefile1
-rw-r--r--arch/arm/boot/compressed/Makefile2
-rw-r--r--arch/arm/boot/compressed/head.S5
-rw-r--r--arch/arm/common/it8152.c8
-rw-r--r--arch/arm/configs/s5pc110_defconfig66
-rw-r--r--arch/arm/configs/s5pv210_defconfig5
-rw-r--r--arch/arm/include/asm/cache.h2
-rw-r--r--arch/arm/include/asm/dma-mapping.h18
-rw-r--r--arch/arm/include/asm/elf.h2
-rw-r--r--arch/arm/include/asm/hardware/coresight.h8
-rw-r--r--arch/arm/include/asm/hardware/scoop.h29
-rw-r--r--arch/arm/include/asm/tlbflush.h8
-rw-r--r--arch/arm/kernel/entry-common.S124
-rw-r--r--arch/arm/kernel/etm.c4
-rw-r--r--arch/arm/kernel/module.c34
-rw-r--r--arch/arm/mach-at91/board-cam60.c6
-rw-r--r--arch/arm/mach-clps711x/include/mach/hardware.h7
-rw-r--r--arch/arm/mach-gemini/Kconfig21
-rw-r--r--arch/arm/mach-gemini/Makefile3
-rw-r--r--arch/arm/mach-gemini/board-nas4220b.c111
-rw-r--r--arch/arm/mach-gemini/board-wbd111.c143
-rw-r--r--arch/arm/mach-gemini/board-wbd222.c143
-rw-r--r--arch/arm/mach-h720x/include/mach/hardware.h2
-rw-r--r--arch/arm/mach-imx/mach-pca100.c2
-rw-r--r--arch/arm/mach-integrator/include/mach/hardware.h1
-rw-r--r--arch/arm/mach-ixp23xx/include/mach/hardware.h1
-rw-r--r--arch/arm/mach-ixp4xx/Kconfig8
-rw-r--r--arch/arm/mach-ixp4xx/Makefile2
-rw-r--r--arch/arm/mach-ixp4xx/include/mach/debug-macro.S2
-rw-r--r--arch/arm/mach-ixp4xx/include/mach/io.h6
-rw-r--r--arch/arm/mach-ixp4xx/vulcan-pci.c73
-rw-r--r--arch/arm/mach-ixp4xx/vulcan-setup.c246
-rw-r--r--arch/arm/mach-mmp/aspenite.c6
-rw-r--r--arch/arm/mach-mmp/avengers_lite.c3
-rw-r--r--arch/arm/mach-mmp/common.c2
-rw-r--r--arch/arm/mach-mmp/common.h11
-rw-r--r--arch/arm/mach-mmp/flint.c3
-rw-r--r--arch/arm/mach-mmp/include/mach/devices.h4
-rw-r--r--arch/arm/mach-mmp/include/mach/mmp2.h7
-rw-r--r--arch/arm/mach-mmp/include/mach/pxa168.h5
-rw-r--r--arch/arm/mach-mmp/include/mach/pxa910.h5
-rw-r--r--arch/arm/mach-mmp/irq-mmp2.c1
-rw-r--r--arch/arm/mach-mmp/jasper.c3
-rw-r--r--arch/arm/mach-mmp/mmp2.c22
-rw-r--r--arch/arm/mach-mmp/tavorevb.c3
-rw-r--r--arch/arm/mach-mmp/time.c21
-rw-r--r--arch/arm/mach-mmp/ttc_dkb.c3
-rw-r--r--arch/arm/mach-msm/Makefile2
-rw-r--r--arch/arm/mach-msm/acpuclock-arm11.c1
-rw-r--r--arch/arm/mach-msm/board-trout-gpio.c115
-rw-r--r--arch/arm/mach-msm/board-trout-mmc.c186
-rw-r--r--arch/arm/mach-msm/board-trout.c11
-rw-r--r--arch/arm/mach-msm/clock.c1
-rw-r--r--arch/arm/mach-msm/devices-msm7x00.c3
-rw-r--r--arch/arm/mach-msm/include/mach/board.h4
-rw-r--r--arch/arm/mach-msm/include/mach/mmc.h2
-rw-r--r--arch/arm/mach-msm/smd.c2
-rw-r--r--arch/arm/mach-omap2/board-omap3pandora.c16
-rw-r--r--arch/arm/mach-omap2/hsmmc.c1
-rw-r--r--arch/arm/mach-omap2/hsmmc.h4
-rw-r--r--arch/arm/mach-pxa/Kconfig80
-rw-r--r--arch/arm/mach-pxa/Makefile13
-rw-r--r--arch/arm/mach-pxa/balloon3.c732
-rw-r--r--arch/arm/mach-pxa/cm-x300.c4
-rw-r--r--arch/arm/mach-pxa/colibri-pxa270-evalboard.c111
-rw-r--r--arch/arm/mach-pxa/colibri-pxa270-income.c272
-rw-r--r--arch/arm/mach-pxa/colibri-pxa270.c176
-rw-r--r--arch/arm/mach-pxa/colibri-pxa320.c40
-rw-r--r--arch/arm/mach-pxa/corgi.c5
-rw-r--r--arch/arm/mach-pxa/corgi_pm.c11
-rw-r--r--arch/arm/mach-pxa/devices.c14
-rw-r--r--arch/arm/mach-pxa/devices.h1
-rw-r--r--arch/arm/mach-pxa/e330.c78
-rw-r--r--arch/arm/mach-pxa/e350.c79
-rw-r--r--arch/arm/mach-pxa/e400.c155
-rw-r--r--arch/arm/mach-pxa/e740.c225
-rw-r--r--arch/arm/mach-pxa/e750.c226
-rw-r--r--arch/arm/mach-pxa/e800.c229
-rw-r--r--arch/arm/mach-pxa/eseries.c809
-rw-r--r--arch/arm/mach-pxa/imote2.c590
-rw-r--r--arch/arm/mach-pxa/include/mach/balloon3.h75
-rw-r--r--arch/arm/mach-pxa/include/mach/colibri.h32
-rw-r--r--arch/arm/mach-pxa/include/mach/corgi.h5
-rw-r--r--arch/arm/mach-pxa/include/mach/gumstix.h12
-rw-r--r--arch/arm/mach-pxa/include/mach/hardware.h5
-rw-r--r--arch/arm/mach-pxa/include/mach/palm27x.h81
-rw-r--r--arch/arm/mach-pxa/include/mach/pata_pxa.h33
-rw-r--r--arch/arm/mach-pxa/include/mach/sharpsl.h35
-rw-r--r--arch/arm/mach-pxa/include/mach/sharpsl_pm.h9
-rw-r--r--arch/arm/mach-pxa/include/mach/spitz.h2
-rw-r--r--arch/arm/mach-pxa/mioa701.c10
-rw-r--r--arch/arm/mach-pxa/palm27x.c477
-rw-r--r--arch/arm/mach-pxa/palmld.c292
-rw-r--r--arch/arm/mach-pxa/palmt5.c283
-rw-r--r--arch/arm/mach-pxa/palmte2.c20
-rw-r--r--arch/arm/mach-pxa/palmtreo.c354
-rw-r--r--arch/arm/mach-pxa/palmtx.c299
-rw-r--r--arch/arm/mach-pxa/palmz72.c264
-rw-r--r--arch/arm/mach-pxa/poodle.c2
-rw-r--r--arch/arm/mach-pxa/pxa25x.c1
-rw-r--r--arch/arm/mach-pxa/pxa27x.c1
-rw-r--r--arch/arm/mach-pxa/pxa3xx.c15
-rw-r--r--arch/arm/mach-pxa/raumfeld.c29
-rw-r--r--arch/arm/mach-pxa/sharpsl.h26
-rw-r--r--arch/arm/mach-pxa/sharpsl_pm.c23
-rw-r--r--arch/arm/mach-pxa/sleep.S7
-rw-r--r--arch/arm/mach-pxa/spitz.c727
-rw-r--r--arch/arm/mach-pxa/spitz_pm.c11
-rw-r--r--arch/arm/mach-pxa/stargate2.c679
-rw-r--r--arch/arm/mach-pxa/trizeps4.c6
-rw-r--r--arch/arm/mach-pxa/vpac270.c126
-rw-r--r--arch/arm/mach-pxa/z2.c118
-rw-r--r--arch/arm/mach-s3c2416/s3c2416.c3
-rw-r--r--arch/arm/mach-s3c2440/mach-gta02.c17
-rw-r--r--arch/arm/mach-s3c2443/s3c2443.c2
-rw-r--r--arch/arm/mach-s3c64xx/Kconfig15
-rw-r--r--arch/arm/mach-s3c64xx/Makefile2
-rw-r--r--arch/arm/mach-s3c64xx/clock.c24
-rw-r--r--arch/arm/mach-s3c64xx/dev-audio.c2
-rw-r--r--arch/arm/mach-s3c64xx/dev-spi.c2
-rw-r--r--arch/arm/mach-s3c64xx/gpiolib.c2
-rw-r--r--arch/arm/mach-s3c64xx/include/mach/map.h6
-rw-r--r--arch/arm/mach-s3c64xx/include/mach/regs-clock.h5
-rw-r--r--arch/arm/mach-s3c64xx/include/mach/regs-fb.h20
-rw-r--r--arch/arm/mach-s3c64xx/mach-anw6410.c1
-rw-r--r--arch/arm/mach-s3c64xx/mach-hmt.c1
-rw-r--r--arch/arm/mach-s3c64xx/mach-smartq5.c3
-rw-r--r--arch/arm/mach-s3c64xx/mach-smartq7.c3
-rw-r--r--arch/arm/mach-s3c64xx/mach-smdk6410.c34
-rw-r--r--arch/arm/mach-s3c64xx/s3c6410.c6
-rw-r--r--arch/arm/mach-s3c64xx/setup-fb-24bpp.c2
-rw-r--r--arch/arm/mach-s3c64xx/setup-i2c0.c2
-rw-r--r--arch/arm/mach-s3c64xx/setup-i2c1.c2
-rw-r--r--arch/arm/mach-s3c64xx/setup-ide.c46
-rw-r--r--arch/arm/mach-s3c64xx/setup-keypad.c34
-rw-r--r--arch/arm/mach-s3c64xx/setup-sdhci-gpio.c17
-rw-r--r--arch/arm/mach-s5p6440/Kconfig13
-rw-r--r--arch/arm/mach-s5p6440/Makefile1
-rw-r--r--arch/arm/mach-s5p6440/cpu.c3
-rw-r--r--arch/arm/mach-s5p6440/dev-audio.c2
-rw-r--r--arch/arm/mach-s5p6440/dev-spi.c2
-rw-r--r--arch/arm/mach-s5p6440/gpio.c4
-rw-r--r--arch/arm/mach-s5p6440/include/mach/irqs.h2
-rw-r--r--arch/arm/mach-s5p6440/include/mach/map.h4
-rw-r--r--arch/arm/mach-s5p6440/include/mach/system.h7
-rw-r--r--arch/arm/mach-s5p6440/mach-smdk6440.c51
-rw-r--r--arch/arm/mach-s5p6440/setup-i2c0.c7
-rw-r--r--arch/arm/mach-s5p6440/setup-i2c1.c30
-rw-r--r--arch/arm/mach-s5p6442/Kconfig1
-rw-r--r--arch/arm/mach-s5p6442/clock.c6
-rw-r--r--arch/arm/mach-s5p6442/dev-audio.c2
-rw-r--r--arch/arm/mach-s5p6442/dev-spi.c2
-rw-r--r--arch/arm/mach-s5p6442/include/mach/irqs.h2
-rw-r--r--arch/arm/mach-s5p6442/include/mach/map.h3
-rw-r--r--arch/arm/mach-s5p6442/include/mach/system.h7
-rw-r--r--arch/arm/mach-s5p6442/mach-smdk6442.c25
-rw-r--r--arch/arm/mach-s5pc100/Kconfig23
-rw-r--r--arch/arm/mach-s5pc100/Makefile2
-rw-r--r--arch/arm/mach-s5pc100/clock.c8
-rw-r--r--arch/arm/mach-s5pc100/cpu.c7
-rw-r--r--arch/arm/mach-s5pc100/dev-audio.c2
-rw-r--r--arch/arm/mach-s5pc100/dev-spi.c2
-rw-r--r--arch/arm/mach-s5pc100/include/mach/irqs.h4
-rw-r--r--arch/arm/mach-s5pc100/include/mach/map.h21
-rw-r--r--arch/arm/mach-s5pc100/include/mach/regs-clock.h3
-rw-r--r--arch/arm/mach-s5pc100/include/mach/regs-fb.h34
-rw-r--r--arch/arm/mach-s5pc100/include/mach/system.h9
-rw-r--r--arch/arm/mach-s5pc100/mach-smdkc100.c80
-rw-r--r--arch/arm/mach-s5pc100/setup-ide.c70
-rw-r--r--arch/arm/mach-s5pc100/setup-keypad.c34
-rw-r--r--arch/arm/mach-s5pc100/setup-sdhci-gpio.c22
-rw-r--r--arch/arm/mach-s5pc100/setup-sdhci.c8
-rw-r--r--arch/arm/mach-s5pv210/Kconfig87
-rw-r--r--arch/arm/mach-s5pv210/Makefile2
-rw-r--r--arch/arm/mach-s5pv210/cpu.c32
-rw-r--r--arch/arm/mach-s5pv210/dev-audio.c2
-rw-r--r--arch/arm/mach-s5pv210/dev-onenand.c7
-rw-r--r--arch/arm/mach-s5pv210/dev-spi.c2
-rw-r--r--arch/arm/mach-s5pv210/gpiolib.c14
-rw-r--r--arch/arm/mach-s5pv210/include/mach/gpio.h12
-rw-r--r--arch/arm/mach-s5pv210/include/mach/irqs.h4
-rw-r--r--arch/arm/mach-s5pv210/include/mach/map.h16
-rw-r--r--arch/arm/mach-s5pv210/include/mach/memory.h9
-rw-r--r--arch/arm/mach-s5pv210/include/mach/regs-clock.h2
-rw-r--r--arch/arm/mach-s5pv210/include/mach/system.h7
-rw-r--r--arch/arm/mach-s5pv210/mach-aquila.c419
-rw-r--r--arch/arm/mach-s5pv210/mach-goni.c437
-rw-r--r--arch/arm/mach-s5pv210/mach-smdkc110.c66
-rw-r--r--arch/arm/mach-s5pv210/mach-smdkv210.c93
-rw-r--r--arch/arm/mach-s5pv210/setup-fb-24bpp.c2
-rw-r--r--arch/arm/mach-s5pv210/setup-i2c0.c2
-rw-r--r--arch/arm/mach-s5pv210/setup-i2c1.c2
-rw-r--r--arch/arm/mach-s5pv210/setup-i2c2.c2
-rw-r--r--arch/arm/mach-s5pv210/setup-ide.c50
-rw-r--r--arch/arm/mach-s5pv210/setup-keypad.c34
-rw-r--r--arch/arm/mach-s5pv210/setup-sdhci-gpio.c47
-rw-r--r--arch/arm/mach-s5pv210/setup-sdhci.c4
-rw-r--r--arch/arm/mach-s5pv310/Kconfig45
-rw-r--r--arch/arm/mach-s5pv310/Makefile30
-rw-r--r--arch/arm/mach-s5pv310/Makefile.boot2
-rw-r--r--arch/arm/mach-s5pv310/clock.c544
-rw-r--r--arch/arm/mach-s5pv310/cpu.c122
-rw-r--r--arch/arm/mach-s5pv310/headsmp.S41
-rw-r--r--arch/arm/mach-s5pv310/include/mach/debug-macro.S36
-rw-r--r--arch/arm/mach-s5pv310/include/mach/entry-macro.S84
-rw-r--r--arch/arm/mach-s5pv310/include/mach/gpio.h135
-rw-r--r--arch/arm/mach-s5pv310/include/mach/hardware.h18
-rw-r--r--arch/arm/mach-s5pv310/include/mach/io.h26
-rw-r--r--arch/arm/mach-s5pv310/include/mach/irqs.h74
-rw-r--r--arch/arm/mach-s5pv310/include/mach/map.h69
-rw-r--r--arch/arm/mach-s5pv310/include/mach/memory.h22
-rw-r--r--arch/arm/mach-s5pv310/include/mach/pwm-clock.h70
-rw-r--r--arch/arm/mach-s5pv310/include/mach/regs-clock.h62
-rw-r--r--arch/arm/mach-s5pv310/include/mach/regs-irq.h19
-rw-r--r--arch/arm/mach-s5pv310/include/mach/smp.h29
-rw-r--r--arch/arm/mach-s5pv310/include/mach/system.h22
-rw-r--r--arch/arm/mach-s5pv310/include/mach/timex.h29
-rw-r--r--arch/arm/mach-s5pv310/include/mach/uncompress.h30
-rw-r--r--arch/arm/mach-s5pv310/include/mach/vmalloc.h22
-rw-r--r--arch/arm/mach-s5pv310/init.c41
-rw-r--r--arch/arm/mach-s5pv310/irq-combiner.c125
-rw-r--r--arch/arm/mach-s5pv310/localtimer.c25
-rw-r--r--arch/arm/mach-s5pv310/mach-smdkv310.c92
-rw-r--r--arch/arm/mach-s5pv310/mach-universal_c210.c86
-rw-r--r--arch/arm/mach-s5pv310/platsmp.c192
-rw-r--r--arch/arm/mach-s5pv310/setup-i2c0.c28
-rw-r--r--arch/arm/mach-s5pv310/setup-i2c1.c25
-rw-r--r--arch/arm/mach-s5pv310/setup-i2c2.c25
-rw-r--r--arch/arm/mach-s5pv310/time.c287
-rw-r--r--arch/arm/mach-sa1100/include/mach/irqs.h2
-rw-r--r--arch/arm/mach-shmobile/Kconfig26
-rw-r--r--arch/arm/mach-shmobile/Makefile6
-rw-r--r--arch/arm/mach-shmobile/board-ap4evb.c817
-rw-r--r--arch/arm/mach-shmobile/board-g3evm.c59
-rw-r--r--arch/arm/mach-shmobile/board-g4evm.c153
-rw-r--r--arch/arm/mach-shmobile/clock-sh7367.c357
-rw-r--r--arch/arm/mach-shmobile/clock-sh7372.c560
-rw-r--r--arch/arm/mach-shmobile/clock-sh7377.c369
-rw-r--r--arch/arm/mach-shmobile/clock.c44
-rw-r--r--arch/arm/mach-shmobile/include/mach/common.h10
-rw-r--r--arch/arm/mach-shmobile/include/mach/irqs.h6
-rw-r--r--arch/arm/mach-shmobile/include/mach/memory.h3
-rw-r--r--arch/arm/mach-shmobile/include/mach/sh7372.h30
-rw-r--r--arch/arm/mach-shmobile/include/mach/vmalloc.h3
-rw-r--r--arch/arm/mach-shmobile/intc-sh7367.c178
-rw-r--r--arch/arm/mach-shmobile/intc-sh7372.c232
-rw-r--r--arch/arm/mach-shmobile/intc-sh7377.c300
-rw-r--r--arch/arm/mach-shmobile/pfc-sh7372.c3
-rw-r--r--arch/arm/mach-shmobile/setup-sh7367.c30
-rw-r--r--arch/arm/mach-shmobile/setup-sh7372.c391
-rw-r--r--arch/arm/mach-shmobile/setup-sh7377.c34
-rw-r--r--arch/arm/mach-u300/clock.c139
-rw-r--r--arch/arm/mach-u300/clock.h5
-rw-r--r--arch/arm/mach-u300/core.c14
-rw-r--r--arch/arm/mach-u300/mmc.c8
-rw-r--r--arch/arm/mach-u300/timer.c28
-rw-r--r--arch/arm/mach-versatile/include/mach/hardware.h9
-rw-r--r--arch/arm/mm/Kconfig4
-rw-r--r--arch/arm/plat-mxc/include/mach/gpio.h1
-rw-r--r--arch/arm/plat-omap/include/plat/mmc.h2
-rw-r--r--arch/arm/plat-pxa/Makefile1
-rw-r--r--arch/arm/plat-pxa/pmu.c33
-rw-r--r--arch/arm/plat-s5p/Kconfig20
-rw-r--r--arch/arm/plat-s5p/Makefile6
-rw-r--r--arch/arm/plat-s5p/cpu.c19
-rw-r--r--arch/arm/plat-s5p/dev-fimc0.c36
-rw-r--r--arch/arm/plat-s5p/dev-fimc1.c36
-rw-r--r--arch/arm/plat-s5p/dev-fimc2.c36
-rw-r--r--arch/arm/plat-s5p/dev-pmu.c36
-rw-r--r--arch/arm/plat-s5p/include/plat/map-s5p.h23
-rw-r--r--arch/arm/plat-s5p/include/plat/pll.h41
-rw-r--r--arch/arm/plat-s5p/include/plat/reset.h16
-rw-r--r--arch/arm/plat-s5p/include/plat/s5pv310.h34
-rw-r--r--arch/arm/plat-s5p/include/plat/system-reset.h31
-rw-r--r--arch/arm/plat-s5p/irq.c2
-rw-r--r--arch/arm/plat-samsung/Kconfig15
-rw-r--r--arch/arm/plat-samsung/Makefile7
-rw-r--r--arch/arm/plat-samsung/dev-hsmmc.c5
-rw-r--r--arch/arm/plat-samsung/dev-hsmmc1.c5
-rw-r--r--arch/arm/plat-samsung/dev-hsmmc2.c5
-rw-r--r--arch/arm/plat-samsung/dev-hsmmc3.c77
-rw-r--r--arch/arm/plat-samsung/dev-ide.c44
-rw-r--r--arch/arm/plat-samsung/dev-keypad.c50
-rw-r--r--arch/arm/plat-samsung/dev-wdt.c2
-rw-r--r--arch/arm/plat-samsung/gpiolib.c2
-rw-r--r--arch/arm/plat-samsung/include/plat/adc-core.h28
-rw-r--r--arch/arm/plat-samsung/include/plat/ata-core.h28
-rw-r--r--arch/arm/plat-samsung/include/plat/ata.h36
-rw-r--r--arch/arm/plat-samsung/include/plat/devs.h20
-rw-r--r--arch/arm/plat-samsung/include/plat/fb-core.h29
-rw-r--r--arch/arm/plat-samsung/include/plat/fb.h3
-rw-r--r--arch/arm/plat-samsung/include/plat/fimc-core.h44
-rw-r--r--arch/arm/plat-samsung/include/plat/keypad-core.h31
-rw-r--r--arch/arm/plat-samsung/include/plat/keypad.h13
-rw-r--r--arch/arm/plat-samsung/include/plat/regs-ata.h56
-rw-r--r--arch/arm/plat-samsung/include/plat/regs-fb-v4.h78
-rw-r--r--arch/arm/plat-samsung/include/plat/regs-fb.h30
-rw-r--r--arch/arm/plat-samsung/include/plat/regs-rtc.h3
-rw-r--r--arch/arm/plat-samsung/include/plat/regs-serial.h2
-rw-r--r--arch/arm/plat-samsung/include/plat/sdhci.h127
-rw-r--r--arch/arm/plat-samsung/platformdata.c37
-rw-r--r--arch/avr32/include/asm/cache.h2
-rw-r--r--arch/avr32/include/asm/dma-mapping.h10
-rw-r--r--arch/blackfin/include/asm/cache.h2
-rw-r--r--arch/blackfin/include/asm/dma-mapping.h2
-rw-r--r--arch/cris/include/asm/dma-mapping.h8
-rw-r--r--arch/cris/include/asm/pgtable.h3
-rw-r--r--arch/frv/include/asm/dma-mapping.h8
-rw-r--r--arch/frv/include/asm/mem-layout.h2
-rw-r--r--arch/ia64/include/asm/dma-mapping.h4
-rw-r--r--arch/ia64/include/asm/rwsem.h6
-rw-r--r--arch/ia64/kernel/perfmon.c15
-rw-r--r--arch/ia64/kernel/setup.c6
-rw-r--r--arch/m68k/include/asm/cache.h2
-rw-r--r--arch/m68k/include/asm/dma-mapping.h10
-rw-r--r--arch/microblaze/include/asm/dma-mapping.h6
-rw-r--r--arch/microblaze/include/asm/page.h2
-rw-r--r--arch/mips/include/asm/dma-mapping.h9
-rw-r--r--arch/mips/include/asm/mach-generic/kmalloc.h2
-rw-r--r--arch/mips/include/asm/mach-ip27/kmalloc.h2
-rw-r--r--arch/mips/include/asm/mach-ip32/kmalloc.h4
-rw-r--r--arch/mips/mm/dma-default.c7
-rw-r--r--arch/mn10300/boot/compressed/misc.c1
-rw-r--r--arch/mn10300/include/asm/cache.h2
-rw-r--r--arch/mn10300/include/asm/dma-mapping.h8
-rw-r--r--arch/mn10300/include/asm/gdb-stub.h8
-rw-r--r--arch/mn10300/include/asm/posix_types.h7
-rw-r--r--arch/mn10300/kernel/mn10300-serial.c5
-rw-r--r--arch/mn10300/kernel/rtc.c5
-rw-r--r--arch/parisc/include/asm/cache.h2
-rw-r--r--arch/parisc/include/asm/dma-mapping.h12
-rw-r--r--arch/parisc/mm/ioremap.c2
-rw-r--r--arch/powerpc/boot/dts/p4080ds.dts2
-rw-r--r--arch/powerpc/include/asm/dma-mapping.h20
-rw-r--r--arch/powerpc/include/asm/page_32.h2
-rw-r--r--arch/powerpc/platforms/83xx/mpc837x_mds.c2
-rw-r--r--arch/powerpc/platforms/83xx/mpc837x_rdb.c2
-rw-r--r--arch/powerpc/sysdev/fsl_rio.c2
-rw-r--r--arch/s390/appldata/appldata_net_sum.c3
-rw-r--r--arch/s390/include/asm/unistd.h5
-rw-r--r--arch/s390/kernel/compat_wrapper.S26
-rw-r--r--arch/s390/kernel/entry.h2
-rw-r--r--arch/s390/kernel/sys_s390.c4
-rw-r--r--arch/s390/kernel/syscalls.S3
-rw-r--r--arch/score/mm/tlb-score.c2
-rw-r--r--arch/sh/boards/mach-ap325rxa/setup.c2
-rw-r--r--arch/sh/boards/mach-kfr2r09/Makefile6
-rw-r--r--arch/sh/boards/mach-kfr2r09/lcd_wqvga.c2
-rw-r--r--arch/sh/include/asm/dma-mapping.h15
-rw-r--r--arch/sh/include/asm/page.h2
-rw-r--r--arch/sh/include/mach-kfr2r09/mach/kfr2r09.h16
-rw-r--r--arch/sparc/include/asm/dma-mapping.h10
-rw-r--r--arch/tile/include/asm/dma-mapping.h9
-rw-r--r--arch/um/drivers/hostaudio_kern.c10
-rw-r--r--arch/um/include/asm/dma-mapping.h1
-rw-r--r--arch/x86/include/asm/dma-mapping.h8
-rw-r--r--arch/x86/include/asm/page.h7
-rw-r--r--arch/x86/include/asm/uv/uv_bau.h151
-rw-r--r--arch/x86/include/asm/xen/page.h8
-rw-r--r--arch/x86/include/asm/xen/swiotlb-xen.h14
-rw-r--r--arch/x86/kernel/apic/apic.c2
-rw-r--r--arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.c2
-rw-r--r--arch/x86/kernel/cpu/perf_event_p4.c9
-rw-r--r--arch/x86/kernel/hpet.c4
-rw-r--r--arch/x86/kernel/mpparse.c16
-rw-r--r--arch/x86/kernel/pci-dma.c7
-rw-r--r--arch/x86/kernel/tlb_uv.c756
-rw-r--r--arch/x86/lib/atomic64_386_32.S238
-rw-r--r--arch/x86/mm/fault.c4
-rw-r--r--arch/x86/oprofile/nmi_int.c1
-rw-r--r--arch/x86/xen/Makefile1
-rw-r--r--arch/x86/xen/enlighten.c4
-rw-r--r--arch/x86/xen/mmu.c293
-rw-r--r--arch/x86/xen/pci-swiotlb-xen.c58
-rw-r--r--arch/xtensa/include/asm/cache.h2
-rw-r--r--arch/xtensa/include/asm/dma-mapping.h8
-rw-r--r--block/blk-core.c5
-rw-r--r--block/blk-lib.c6
-rw-r--r--block/compat_ioctl.c1
-rw-r--r--block/elevator.c6
-rw-r--r--block/ioctl.c15
-rw-r--r--drivers/acpi/apei/erst.c1
-rw-r--r--drivers/acpi/debug.c32
-rw-r--r--drivers/ata/Kconfig11
-rw-r--r--drivers/ata/Makefile2
-rw-r--r--drivers/ata/pata_mpc52xx.c8
-rw-r--r--drivers/ata/pata_of_platform.c4
-rw-r--r--drivers/ata/pata_pxa.c411
-rw-r--r--drivers/ata/sata_fsl.c8
-rw-r--r--drivers/atm/fore200e.c26
-rw-r--r--drivers/block/xsysace.c4
-rw-r--r--drivers/char/Kconfig2
-rw-r--r--drivers/char/hvc_iucv.c9
-rw-r--r--drivers/char/hw_random/n2-drv.c4
-rw-r--r--drivers/char/hw_random/n2rng.h2
-rw-r--r--drivers/char/hw_random/pasemi-rng.c4
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c61
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c42
-rw-r--r--drivers/char/n_gsm.c2
-rw-r--r--drivers/char/nozomi.c3
-rw-r--r--drivers/char/rtc.c2
-rw-r--r--drivers/char/xilinx_hwicap/xilinx_hwicap.c4
-rw-r--r--drivers/crypto/Kconfig2
-rw-r--r--drivers/crypto/amcc/crypto4xx_core.c4
-rw-r--r--drivers/crypto/amcc/crypto4xx_core.h2
-rw-r--r--drivers/crypto/ixp4xx_crypto.c21
-rw-r--r--drivers/crypto/n2_core.c26
-rw-r--r--drivers/crypto/talitos.c6
-rw-r--r--drivers/dma/Kconfig2
-rw-r--r--drivers/dma/fsldma.c4
-rw-r--r--drivers/dma/mpc512x_dma.c4
-rw-r--r--drivers/dma/ppc4xx/adma.c8
-rw-r--r--drivers/dma/shdma.c8
-rw-r--r--drivers/edac/i5000_edac.c2
-rw-r--r--drivers/edac/i5400_edac.c2
-rw-r--r--drivers/edac/mpc85xx_edac.c28
-rw-r--r--drivers/edac/ppc4xx_edac.c12
-rw-r--r--drivers/gpio/Kconfig18
-rw-r--r--drivers/gpio/Makefile2
-rw-r--r--drivers/gpio/gpiolib.c96
-rw-r--r--drivers/gpio/max730x.c22
-rw-r--r--drivers/gpio/pcf857x.c9
-rw-r--r--drivers/gpio/stmpe-gpio.c399
-rw-r--r--drivers/gpio/sx150x.c645
-rw-r--r--drivers/gpio/wm831x-gpio.c32
-rw-r--r--drivers/gpu/drm/ati_pcigart.c2
-rw-r--r--drivers/gpu/drm/drm_bufs.c33
-rw-r--r--drivers/gpu/drm/drm_crtc.c6
-rw-r--r--drivers/gpu/drm/drm_crtc_helper.c10
-rw-r--r--drivers/gpu/drm/drm_edid.c840
-rw-r--r--drivers/gpu/drm/drm_edid_modes.h380
-rw-r--r--drivers/gpu/drm/drm_fops.c16
-rw-r--r--drivers/gpu/drm/drm_gem.c2
-rw-r--r--drivers/gpu/drm/drm_ioctl.c1
-rw-r--r--drivers/gpu/drm/i2c/ch7006_drv.c1
-rw-r--r--drivers/gpu/drm/i2c/ch7006_mode.c5
-rw-r--r--drivers/gpu/drm/i2c/ch7006_priv.h1
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c26
-rw-r--r--drivers/gpu/drm/i915/i915_gem_tiling.c4
-rw-r--r--drivers/gpu/drm/i915/intel_display.c15
-rw-r--r--drivers/gpu/drm/i915/intel_fb.c4
-rw-r--r--drivers/gpu/drm/nouveau/Makefile8
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bios.c194
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bios.h1
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bo.c6
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_connector.c19
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_display.c6
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_dp.c87
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drv.h45
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_encoder.h6
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_fbcon.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_gem.c8
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_hw.c11
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_i2c.c41
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_i2c.h8
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_irq.c6
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_mem.c15
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_reg.h18
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_state.c91
-rw-r--r--drivers/gpu/drm/nouveau/nv04_crtc.c15
-rw-r--r--drivers/gpu/drm/nouveau/nv04_dfp.c73
-rw-r--r--drivers/gpu/drm/nouveau/nv04_tv.c10
-rw-r--r--drivers/gpu/drm/nouveau/nv10_graph.c175
-rw-r--r--drivers/gpu/drm/nouveau/nv30_fb.c24
-rw-r--r--drivers/gpu/drm/nouveau/nv50_crtc.c34
-rw-r--r--drivers/gpu/drm/nouveau/nv50_display.c5
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_fb.c38
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_fifo.c96
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_graph.c75
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_instmem.c232
-rw-r--r--drivers/gpu/drm/radeon/r600_cp.c2
-rw-r--r--drivers/gpu/drm/radeon/r600_cs.c33
-rw-r--r--drivers/gpu/drm/radeon/radeon.h2
-rw-r--r--drivers/gpu/drm/radeon/radeon_atombios.c180
-rw-r--r--drivers/gpu/drm/radeon/radeon_clocks.c81
-rw-r--r--drivers/gpu/drm/radeon/radeon_combios.c388
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c45
-rw-r--r--drivers/gpu/drm/radeon/radeon_cs.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_cursor.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_device.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon_display.c34
-rw-r--r--drivers/gpu/drm/radeon/radeon_gem.c12
-rw-r--r--drivers/gpu/drm/radeon/radeon_i2c.c82
-rw-r--r--drivers/gpu/drm/radeon/radeon_kms.c28
-rw-r--r--drivers/gpu/drm/radeon/radeon_mode.h24
-rw-r--r--drivers/gpu/drm/radeon/radeon_pm.c24
-rw-r--r--drivers/gpu/drm/radeon/reg_srcs/rv5151
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_kms.c8
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c2
-rw-r--r--drivers/hwmon/ams/ams.h2
-rw-r--r--drivers/hwmon/coretemp.c3
-rw-r--r--drivers/hwmon/mc13783-adc.c17
-rw-r--r--drivers/hwmon/ultra45_env.c4
-rw-r--r--drivers/i2c/Kconfig13
-rw-r--r--drivers/i2c/Makefile3
-rw-r--r--drivers/i2c/busses/Kconfig13
-rw-r--r--drivers/i2c/busses/i2c-cpm.c8
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c6
-rw-r--r--drivers/i2c/busses/i2c-mpc.c4
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c121
-rw-r--r--drivers/i2c/i2c-core.c158
-rw-r--r--drivers/i2c/i2c-dev.c66
-rw-r--r--drivers/i2c/i2c-mux.c165
-rw-r--r--drivers/i2c/muxes/Kconfig18
-rw-r--r--drivers/i2c/muxes/Makefile8
-rw-r--r--drivers/i2c/muxes/pca954x.c301
-rw-r--r--drivers/ide/ide.c20
-rw-r--r--drivers/infiniband/hw/ehca/ehca_classes.h2
-rw-r--r--drivers/infiniband/hw/ehca/ehca_main.c4
-rw-r--r--drivers/input/keyboard/Kconfig10
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/stmpe-keypad.c386
-rw-r--r--drivers/input/misc/ati_remote2.c26
-rw-r--r--drivers/input/misc/sparcspkr.c10
-rw-r--r--drivers/input/mouse/psmouse-base.c14
-rw-r--r--drivers/input/serio/i8042-sparcio.h8
-rw-r--r--drivers/input/serio/i8042.c25
-rw-r--r--drivers/input/serio/xilinx_ps2.c4
-rw-r--r--drivers/input/touchscreen/Kconfig10
-rw-r--r--drivers/input/touchscreen/Makefile1
-rw-r--r--drivers/input/touchscreen/stmpe-ts.c397
-rw-r--r--drivers/isdn/hardware/avm/c4.c1
-rw-r--r--drivers/isdn/hardware/avm/t1pci.c1
-rw-r--r--drivers/isdn/hardware/mISDN/mISDNinfineon.c5
-rw-r--r--drivers/leds/leds-gpio.c4
-rw-r--r--drivers/macintosh/macio_sysfs.c6
-rw-r--r--drivers/macintosh/smu.c6
-rw-r--r--drivers/macintosh/therm_adt746x.c2
-rw-r--r--drivers/macintosh/therm_pm72.c6
-rw-r--r--drivers/macintosh/therm_windtunnel.c10
-rw-r--r--drivers/md/dm-crypt.c342
-rw-r--r--drivers/md/dm-delay.c6
-rw-r--r--drivers/md/dm-exception-store.c4
-rw-r--r--drivers/md/dm-exception-store.h3
-rw-r--r--drivers/md/dm-ioctl.c207
-rw-r--r--drivers/md/dm-linear.c3
-rw-r--r--drivers/md/dm-mpath.c11
-rw-r--r--drivers/md/dm-raid1.c2
-rw-r--r--drivers/md/dm-snap-persistent.c6
-rw-r--r--drivers/md/dm-snap.c62
-rw-r--r--drivers/md/dm-stripe.c87
-rw-r--r--drivers/md/dm-table.c99
-rw-r--r--drivers/md/dm-target.c5
-rw-r--r--drivers/md/dm-zero.c5
-rw-r--r--drivers/md/dm.c329
-rw-r--r--drivers/md/dm.h14
-rw-r--r--drivers/media/IR/Kconfig9
-rw-r--r--drivers/media/dvb/dm1105/Kconfig2
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig2
-rw-r--r--drivers/media/dvb/siano/Kconfig2
-rw-r--r--drivers/media/dvb/ttpci/Kconfig2
-rw-r--r--drivers/media/video/bt8xx/Kconfig2
-rw-r--r--drivers/media/video/bt8xx/bttv-i2c.c2
-rw-r--r--drivers/media/video/cx18/Kconfig2
-rw-r--r--drivers/media/video/cx18/cx18-i2c.c3
-rw-r--r--drivers/media/video/cx231xx/Kconfig2
-rw-r--r--drivers/media/video/cx23885/Kconfig2
-rw-r--r--drivers/media/video/cx23885/cx23885-i2c.c15
-rw-r--r--drivers/media/video/cx88/Kconfig2
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c19
-rw-r--r--drivers/media/video/em28xx/Kconfig2
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c2
-rw-r--r--drivers/media/video/fsl-viu.c8
-rw-r--r--drivers/media/video/ivtv/Kconfig2
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c9
-rw-r--r--drivers/media/video/saa7134/Kconfig2
-rw-r--r--drivers/media/video/tlg2300/Kconfig2
-rw-r--r--drivers/media/video/v4l2-common.c3
-rw-r--r--drivers/media/video/v4l2-ctrls.c1
-rw-r--r--drivers/memstick/core/mspro_block.c6
-rw-r--r--drivers/message/fusion/mptbase.c241
-rw-r--r--drivers/message/fusion/mptbase.h25
-rw-r--r--drivers/message/i2o/exec-osm.c8
-rw-r--r--drivers/message/i2o/i2o_block.c3
-rw-r--r--drivers/message/i2o/i2o_config.c18
-rw-r--r--drivers/message/i2o/i2o_scsi.c3
-rw-r--r--drivers/mfd/88pm860x-core.c84
-rw-r--r--drivers/mfd/Kconfig75
-rw-r--r--drivers/mfd/Makefile5
-rw-r--r--drivers/mfd/ab3100-otp.c16
-rw-r--r--drivers/mfd/ab3550-core.c23
-rw-r--r--drivers/mfd/ab8500-core.c4
-rw-r--r--drivers/mfd/ab8500-spi.c7
-rw-r--r--drivers/mfd/abx500-core.c2
-rw-r--r--drivers/mfd/davinci_voicecodec.c6
-rw-r--r--drivers/mfd/janz-cmodio.c1
-rw-r--r--drivers/mfd/jz4740-adc.c394
-rw-r--r--drivers/mfd/max8925-core.c27
-rw-r--r--drivers/mfd/max8998.c158
-rw-r--r--drivers/mfd/mc13783-core.c30
-rw-r--r--drivers/mfd/menelaus.c75
-rw-r--r--drivers/mfd/mfd-core.c4
-rw-r--r--drivers/mfd/stmpe.c985
-rw-r--r--drivers/mfd/stmpe.h183
-rw-r--r--drivers/mfd/t7l66xb.c3
-rw-r--r--drivers/mfd/tc6387xb.c16
-rw-r--r--drivers/mfd/tc6393xb.c4
-rw-r--r--drivers/mfd/tps6507x.c4
-rw-r--r--drivers/mfd/tps6586x.c375
-rw-r--r--drivers/mfd/twl6030-pwm.c163
-rw-r--r--drivers/mfd/ucb1400_core.c2
-rw-r--r--drivers/mfd/wm831x-core.c18
-rw-r--r--drivers/mfd/wm8350-core.c6
-rw-r--r--drivers/mfd/wm8994-core.c8
-rw-r--r--drivers/misc/cs5535-mfgpt.c11
-rw-r--r--drivers/misc/lkdtm.c4
-rw-r--r--drivers/mmc/card/block.c82
-rw-r--r--drivers/mmc/card/mmc_test.c811
-rw-r--r--drivers/mmc/card/queue.c19
-rw-r--r--drivers/mmc/core/bus.c9
-rw-r--r--drivers/mmc/core/core.c441
-rw-r--r--drivers/mmc/core/core.h2
-rw-r--r--drivers/mmc/core/host.c4
-rw-r--r--drivers/mmc/core/mmc.c75
-rw-r--r--drivers/mmc/core/sd.c331
-rw-r--r--drivers/mmc/core/sd.h17
-rw-r--r--drivers/mmc/core/sd_ops.c48
-rw-r--r--drivers/mmc/core/sd_ops.h1
-rw-r--r--drivers/mmc/core/sdio.c210
-rw-r--r--drivers/mmc/host/Kconfig9
-rw-r--r--drivers/mmc/host/Makefile5
-rw-r--r--drivers/mmc/host/mmc_spi.c1
-rw-r--r--drivers/mmc/host/msm_sdcc.c27
-rw-r--r--drivers/mmc/host/msm_sdcc.h6
-rw-r--r--drivers/mmc/host/omap_hsmmc.c47
-rw-r--r--drivers/mmc/host/sdhci-cns3xxx.c97
-rw-r--r--drivers/mmc/host/sdhci-of-core.c12
-rw-r--r--drivers/mmc/host/sdhci-pci.c49
-rw-r--r--drivers/mmc/host/sdhci-pltfm.c17
-rw-r--r--drivers/mmc/host/sdhci-pltfm.h18
-rw-r--r--drivers/mmc/host/sdhci-s3c.c123
-rw-r--r--drivers/mmc/host/sdhci.c53
-rw-r--r--drivers/mmc/host/sdhci.h10
-rw-r--r--drivers/mtd/maps/physmap_of.c8
-rw-r--r--drivers/mtd/maps/sun_uflash.c6
-rw-r--r--drivers/mtd/nand/fsl_elbc_nand.c4
-rw-r--r--drivers/mtd/nand/fsl_upm.c4
-rw-r--r--drivers/mtd/nand/mpc5121_nfc.c4
-rw-r--r--drivers/mtd/nand/nand_base.c39
-rw-r--r--drivers/mtd/nand/ndfc.c6
-rw-r--r--drivers/mtd/nand/pasemi_nand.c4
-rw-r--r--drivers/mtd/nand/socrates_nand.c4
-rw-r--r--drivers/net/arm/ixp4xx_eth.c2
-rw-r--r--drivers/net/caif/caif_spi_slave.c4
-rw-r--r--drivers/net/can/mscan/mpc5xxx_can.c18
-rw-r--r--drivers/net/can/sja1000/sja1000_of_platform.c4
-rw-r--r--drivers/net/ehea/ehea.h4
-rw-r--r--drivers/net/ehea/ehea_main.c12
-rw-r--r--drivers/net/fec_mpc52xx.c8
-rw-r--r--drivers/net/fec_mpc52xx_phy.c4
-rw-r--r--drivers/net/fs_enet/fs_enet-main.c4
-rw-r--r--drivers/net/fs_enet/mac-fcc.c2
-rw-r--r--drivers/net/fs_enet/mac-fec.c2
-rw-r--r--drivers/net/fs_enet/mac-scc.c2
-rw-r--r--drivers/net/fs_enet/mii-bitbang.c4
-rw-r--r--drivers/net/fs_enet/mii-fec.c4
-rw-r--r--drivers/net/fsl_pq_mdio.c4
-rw-r--r--drivers/net/gianfar.c10
-rw-r--r--drivers/net/gianfar.h2
-rw-r--r--drivers/net/greth.c6
-rw-r--r--drivers/net/greth.h2
-rw-r--r--drivers/net/ibm_newemac/core.c6
-rw-r--r--drivers/net/ibm_newemac/core.h12
-rw-r--r--drivers/net/ibm_newemac/mal.c4
-rw-r--r--drivers/net/ibm_newemac/mal.h2
-rw-r--r--drivers/net/ibm_newemac/rgmii.c18
-rw-r--r--drivers/net/ibm_newemac/rgmii.h16
-rw-r--r--drivers/net/ibm_newemac/tah.c14
-rw-r--r--drivers/net/ibm_newemac/tah.h12
-rw-r--r--drivers/net/ibm_newemac/zmii.c18
-rw-r--r--drivers/net/ibm_newemac/zmii.h16
-rw-r--r--drivers/net/irda/sh_irda.c6
-rw-r--r--drivers/net/ll_temac_main.c8
-rw-r--r--drivers/net/myri10ge/myri10ge.c54
-rw-r--r--drivers/net/myri_sbus.c4
-rw-r--r--drivers/net/myri_sbus.h2
-rw-r--r--drivers/net/niu.c8
-rw-r--r--drivers/net/phy/Kconfig2
-rw-r--r--drivers/net/phy/mdio-gpio.c4
-rw-r--r--drivers/net/phy/phy.c2
-rw-r--r--drivers/net/qlcnic/qlcnic_main.c72
-rw-r--r--drivers/net/sunbmac.c18
-rw-r--r--drivers/net/sunbmac.h4
-rw-r--r--drivers/net/sunhme.c22
-rw-r--r--drivers/net/sunhme.h2
-rw-r--r--drivers/net/sunlance.c20
-rw-r--r--drivers/net/sunqe.c16
-rw-r--r--drivers/net/sunqe.h4
-rw-r--r--drivers/net/ucc_geth.c8
-rw-r--r--drivers/net/usb/usbnet.c22
-rw-r--r--drivers/net/wan/farsync.c15
-rw-r--r--drivers/net/wan/ixp4xx_hss.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-1000.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c18
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c10
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-6000.c16
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c19
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-tx.c20
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c85
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c29
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h14
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c5
-rw-r--r--drivers/net/wireless/libertas/cfg.c3
-rw-r--r--drivers/net/wireless/libertas/if_sdio.c32
-rw-r--r--drivers/net/wireless/libertas/if_usb.c3
-rw-r--r--drivers/net/wireless/libertas_tf/if_usb.c3
-rw-r--r--drivers/net/wireless/p54/p54pci.c2
-rw-r--r--drivers/net/xilinx_emaclite.c6
-rw-r--r--drivers/of/device.c2
-rw-r--r--drivers/parport/parport_serial.c1
-rw-r--r--drivers/parport/parport_sunbpp.c4
-rw-r--r--drivers/pcmcia/Kconfig2
-rw-r--r--drivers/pcmcia/Makefile1
-rw-r--r--drivers/pcmcia/electra_cf.c6
-rw-r--r--drivers/pcmcia/m8xx_pcmcia.c4
-rw-r--r--drivers/pcmcia/pxa2xx_balloon3.c158
-rw-r--r--drivers/power/Kconfig13
-rw-r--r--drivers/power/Makefile2
-rw-r--r--drivers/power/intel_mid_battery.c799
-rw-r--r--drivers/power/olpc_battery.c2
-rw-r--r--drivers/power/s3c_adc_battery.c431
-rw-r--r--drivers/power/wm97xx_battery.c16
-rw-r--r--drivers/regulator/Kconfig34
-rw-r--r--drivers/regulator/Makefile5
-rw-r--r--drivers/regulator/ab8500.c427
-rw-r--r--drivers/regulator/ad5398.c288
-rw-r--r--drivers/regulator/isl6271a-regulator.c236
-rw-r--r--drivers/regulator/lp3971.c10
-rw-r--r--drivers/regulator/max1586.c10
-rw-r--r--drivers/regulator/max8660.c10
-rw-r--r--drivers/regulator/max8998.c635
-rw-r--r--drivers/regulator/tps65023-regulator.c2
-rw-r--r--drivers/regulator/tps6507x-regulator.c1
-rw-r--r--drivers/regulator/tps6586x-regulator.c396
-rw-r--r--drivers/regulator/wm8994-regulator.c5
-rw-r--r--drivers/rtc/Kconfig38
-rw-r--r--drivers/rtc/Makefile3
-rw-r--r--drivers/rtc/rtc-cmos.c6
-rw-r--r--drivers/rtc/rtc-ds3232.c326
-rw-r--r--drivers/rtc/rtc-fm3130.c181
-rw-r--r--drivers/rtc/rtc-imxdi.c519
-rw-r--r--drivers/rtc/rtc-isl12022.c327
-rw-r--r--drivers/rtc/rtc-m41t80.c4
-rw-r--r--drivers/rtc/rtc-m48t59.c5
-rw-r--r--drivers/rtc/rtc-m48t86.c2
-rw-r--r--drivers/rtc/rtc-max6900.c2
-rw-r--r--drivers/rtc/rtc-mpc5121.c4
-rw-r--r--drivers/rtc/rtc-mxc.c6
-rw-r--r--drivers/rtc/rtc-nuc900.c64
-rw-r--r--drivers/rtc/rtc-pcf8563.c8
-rw-r--r--drivers/rtc/rtc-pl031.c1
-rw-r--r--drivers/rtc/rtc-pxa.c42
-rw-r--r--drivers/rtc/rtc-rp5c01.c89
-rw-r--r--drivers/rtc/rtc-s3c.c44
-rw-r--r--drivers/s390/block/dasd.c4
-rw-r--r--drivers/s390/net/claw.c118
-rw-r--r--drivers/s390/net/claw.h4
-rw-r--r--drivers/s390/net/ctcm_fsms.c60
-rw-r--r--drivers/s390/net/ctcm_main.c80
-rw-r--r--drivers/s390/net/ctcm_main.h4
-rw-r--r--drivers/s390/net/ctcm_mpc.c64
-rw-r--r--drivers/s390/net/ctcm_sysfs.c20
-rw-r--r--drivers/sbus/char/bbc_envctrl.c6
-rw-r--r--drivers/sbus/char/bbc_i2c.c18
-rw-r--r--drivers/sbus/char/bbc_i2c.h10
-rw-r--r--drivers/sbus/char/display7seg.c4
-rw-r--r--drivers/sbus/char/envctrl.c4
-rw-r--r--drivers/sbus/char/flash.c4
-rw-r--r--drivers/sbus/char/uctrl.c4
-rw-r--r--drivers/scsi/53c700.c3
-rw-r--r--drivers/scsi/Kconfig2
-rw-r--r--drivers/scsi/NCR5380.c4
-rw-r--r--drivers/scsi/aacraid/rx.c5
-rw-r--r--drivers/scsi/aic94xx/aic94xx_init.c4
-rw-r--r--drivers/scsi/bfa/bfa_fcport.c2
-rw-r--r--drivers/scsi/bfa/bfad.c2
-rw-r--r--drivers/scsi/bfa/bfad_im.c4
-rw-r--r--drivers/scsi/bfa/include/protocol/fcp.h4
-rw-r--r--drivers/scsi/bnx2i/Kconfig3
-rw-r--r--drivers/scsi/ch.c89
-rw-r--r--drivers/scsi/dc395x.c2
-rw-r--r--drivers/scsi/fnic/fnic.h2
-rw-r--r--drivers/scsi/g_NCR5380.c47
-rw-r--r--drivers/scsi/g_NCR5380.h6
-rw-r--r--drivers/scsi/gdth.c2
-rw-r--r--drivers/scsi/initio.c1
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c23
-rw-r--r--drivers/scsi/osst.c3
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c4
-rw-r--r--drivers/scsi/qlogicpti.c14
-rw-r--r--drivers/scsi/qlogicpti.h2
-rw-r--r--drivers/scsi/scsi_lib.c6
-rw-r--r--drivers/scsi/scsi_transport_fc.c12
-rw-r--r--drivers/scsi/sd.c12
-rw-r--r--drivers/scsi/sg.c11
-rw-r--r--drivers/scsi/sun_esp.c44
-rw-r--r--drivers/serial/Kconfig4
-rw-r--r--drivers/serial/apbuart.c2
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_core.c4
-rw-r--r--drivers/serial/mpc52xx_uart.c8
-rw-r--r--drivers/serial/nwpserial.c2
-rw-r--r--drivers/serial/of_serial.c6
-rw-r--r--drivers/serial/s5pv210.c8
-rw-r--r--drivers/serial/samsung.c9
-rw-r--r--drivers/serial/sh-sci.c42
-rw-r--r--drivers/serial/sh-sci.h29
-rw-r--r--drivers/serial/sunhv.c4
-rw-r--r--drivers/serial/sunsab.c8
-rw-r--r--drivers/serial/sunsu.c8
-rw-r--r--drivers/serial/sunzilog.c6
-rw-r--r--drivers/serial/uartlite.c4
-rw-r--r--drivers/serial/ucc_uart.c4
-rw-r--r--drivers/sh/Makefile5
-rw-r--r--drivers/sh/clk-cpg.c58
-rw-r--r--drivers/spi/mpc512x_psc_spi.c4
-rw-r--r--drivers/spi/mpc52xx_psc_spi.c4
-rw-r--r--drivers/spi/mpc52xx_spi.c4
-rw-r--r--drivers/spi/spi_mpc8xxx.c4
-rw-r--r--drivers/spi/spi_ppc4xx.c6
-rw-r--r--drivers/spi/xilinx_spi_of.c6
-rw-r--r--drivers/staging/rtl8187se/r8180_core.c6
-rw-r--r--drivers/staging/rtl8192e/r8192E_core.c6
-rw-r--r--drivers/staging/rtl8192su/r8192U_core.c6
-rw-r--r--drivers/usb/atm/ueagle-atm.c2
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c10
-rw-r--r--drivers/usb/host/ehci-ppc-of.c6
-rw-r--r--drivers/usb/host/ehci-xilinx-of.c12
-rw-r--r--drivers/usb/host/fhci-hcd.c4
-rw-r--r--drivers/usb/host/isp1760-if.c4
-rw-r--r--drivers/usb/host/ohci-pnx4008.c2
-rw-r--r--drivers/usb/host/ohci-ppc-of.c6
-rw-r--r--drivers/video/Kconfig17
-rw-r--r--drivers/video/Makefile2
-rw-r--r--drivers/video/bw2.c4
-rw-r--r--drivers/video/cg14.c6
-rw-r--r--drivers/video/cg3.c4
-rw-r--r--drivers/video/cg6.c6
-rw-r--r--drivers/video/console/bitblit.c2
-rw-r--r--drivers/video/console/fbcon.c2
-rw-r--r--drivers/video/console/fbcon_ccw.c2
-rw-r--r--drivers/video/console/fbcon_cw.c2
-rw-r--r--drivers/video/console/fbcon_ud.c2
-rw-r--r--drivers/video/efifb.c8
-rw-r--r--drivers/video/fbmem.c6
-rw-r--r--drivers/video/ffb.c4
-rw-r--r--drivers/video/fsl-diu-fb.c8
-rw-r--r--drivers/video/igafb.c5
-rw-r--r--drivers/video/imxfb.c19
-rw-r--r--drivers/video/leo.c6
-rw-r--r--drivers/video/matrox/i2c-matroxfb.c2
-rw-r--r--drivers/video/mb862xx/mb862xxfb.c4
-rw-r--r--drivers/video/msm/mddi.c4
-rw-r--r--drivers/video/msm/mdp.c1
-rw-r--r--drivers/video/p9100.c4
-rw-r--r--drivers/video/platinumfb.c4
-rw-r--r--drivers/video/s3c-fb.c811
-rw-r--r--drivers/video/sh_mipi_dsi.c505
-rw-r--r--drivers/video/sh_mobile_hdmi.c1028
-rw-r--r--drivers/video/sh_mobile_lcdcfb.c196
-rw-r--r--drivers/video/sunxvr1000.c4
-rw-r--r--drivers/video/tcx.c6
-rw-r--r--drivers/video/uvesafb.c7
-rw-r--r--drivers/video/vt8623fb.c2
-rw-r--r--drivers/video/xilinxfb.c4
-rw-r--r--drivers/watchdog/cpwd.c4
-rw-r--r--drivers/watchdog/gef_wdt.c2
-rw-r--r--drivers/watchdog/mpc8xxx_wdt.c4
-rw-r--r--drivers/watchdog/riowd.c4
-rw-r--r--drivers/xen/Kconfig5
-rw-r--r--drivers/xen/Makefile1
-rw-r--r--drivers/xen/balloon.c15
-rw-r--r--drivers/xen/swiotlb-xen.c515
-rw-r--r--fs/9p/vfs_inode.c15
-rw-r--r--fs/afs/cell.c56
-rw-r--r--fs/afs/dir.c47
-rw-r--r--fs/afs/inode.c86
-rw-r--r--fs/afs/internal.h23
-rw-r--r--fs/afs/mntpt.c78
-rw-r--r--fs/afs/proc.c2
-rw-r--r--fs/afs/rxrpc.c1
-rw-r--r--fs/afs/super.c20
-rw-r--r--fs/autofs4/root.c3
-rw-r--r--fs/block_dev.c10
-rw-r--r--fs/cachefiles/daemon.c32
-rw-r--r--fs/cachefiles/internal.h13
-rw-r--r--fs/ceph/Makefile2
-rw-r--r--fs/ceph/addr.c16
-rw-r--r--fs/ceph/armor.c6
-rw-r--r--fs/ceph/auth.c6
-rw-r--r--fs/ceph/auth_x.c6
-rw-r--r--fs/ceph/buffer.c16
-rw-r--r--fs/ceph/caps.c303
-rw-r--r--fs/ceph/ceph_frag.h4
-rw-r--r--fs/ceph/ceph_fs.c50
-rw-r--r--fs/ceph/ceph_fs.h87
-rw-r--r--fs/ceph/ceph_hash.h4
-rw-r--r--fs/ceph/ceph_strings.c3
-rw-r--r--fs/ceph/crush/crush.h4
-rw-r--r--fs/ceph/crush/hash.h4
-rw-r--r--fs/ceph/crush/mapper.h4
-rw-r--r--fs/ceph/crypto.c27
-rw-r--r--fs/ceph/crypto.h4
-rw-r--r--fs/ceph/debugfs.c21
-rw-r--r--fs/ceph/decode.h6
-rw-r--r--fs/ceph/dir.c10
-rw-r--r--fs/ceph/file.c32
-rw-r--r--fs/ceph/inode.c5
-rw-r--r--fs/ceph/ioctl.c24
-rw-r--r--fs/ceph/ioctl.h2
-rw-r--r--fs/ceph/locks.c256
-rw-r--r--fs/ceph/mds_client.c235
-rw-r--r--fs/ceph/mds_client.h30
-rw-r--r--fs/ceph/mdsmap.c6
-rw-r--r--fs/ceph/mdsmap.h8
-rw-r--r--fs/ceph/messenger.c23
-rw-r--r--fs/ceph/mon_client.c170
-rw-r--r--fs/ceph/mon_client.h5
-rw-r--r--fs/ceph/msgr.h4
-rw-r--r--fs/ceph/osd_client.c9
-rw-r--r--fs/ceph/osdmap.c37
-rw-r--r--fs/ceph/rados.h13
-rw-r--r--fs/ceph/super.c88
-rw-r--r--fs/ceph/super.h40
-rw-r--r--fs/ceph/xattr.c2
-rw-r--r--fs/cifs/README10
-rw-r--r--fs/dcache.c188
-rw-r--r--fs/exofs/file.c29
-rw-r--r--fs/exofs/inode.c9
-rw-r--r--fs/exofs/ios.c44
-rw-r--r--fs/exofs/super.c1
-rw-r--r--fs/fcntl.c15
-rw-r--r--fs/file.c57
-rw-r--r--fs/file_table.c28
-rw-r--r--fs/fs-writeback.c81
-rw-r--r--fs/fs_struct.c7
-rw-r--r--fs/fscache/internal.h14
-rw-r--r--fs/isofs/inode.c7
-rw-r--r--fs/namei.c15
-rw-r--r--fs/namespace.c6
-rw-r--r--fs/nfs/Kconfig17
-rw-r--r--fs/nfs/callback.c11
-rw-r--r--fs/nfs/dns_resolve.c24
-rw-r--r--fs/nfs/dns_resolve.h12
-rw-r--r--fs/notify/fanotify/fanotify.c8
-rw-r--r--fs/notify/fanotify/fanotify_user.c6
-rw-r--r--fs/notify/fsnotify.c12
-rw-r--r--fs/notify/inotify/inotify_fsnotify.c12
-rw-r--r--fs/notify/notification.c33
-rw-r--r--fs/ocfs2/acl.c33
-rw-r--r--fs/ocfs2/cluster/tcp.c17
-rw-r--r--fs/ocfs2/dlm/dlmmaster.c9
-rw-r--r--fs/ocfs2/dlm/dlmrecovery.c22
-rw-r--r--fs/ocfs2/dlm/dlmthread.c114
-rw-r--r--fs/ocfs2/refcounttree.c20
-rw-r--r--fs/open.c4
-rw-r--r--fs/partitions/acorn.c35
-rw-r--r--fs/partitions/amiga.c20
-rw-r--r--fs/partitions/atari.c12
-rw-r--r--fs/partitions/check.c22
-rw-r--r--fs/partitions/check.h6
-rw-r--r--fs/partitions/efi.c2
-rw-r--r--fs/partitions/ibm.c17
-rw-r--r--fs/partitions/karma.c2
-rw-r--r--fs/partitions/ldm.c4
-rw-r--r--fs/partitions/mac.c4
-rw-r--r--fs/partitions/msdos.c67
-rw-r--r--fs/partitions/osf.c2
-rw-r--r--fs/partitions/sgi.c2
-rw-r--r--fs/partitions/sun.c2
-rw-r--r--fs/partitions/sysv68.c9
-rw-r--r--fs/partitions/ultrix.c2
-rw-r--r--fs/proc/Makefile2
-rw-r--r--fs/proc/base.c24
-rw-r--r--fs/reiserfs/journal.c1
-rw-r--r--fs/signalfd.c2
-rw-r--r--fs/squashfs/Kconfig25
-rw-r--r--fs/squashfs/Makefile4
-rw-r--r--fs/squashfs/decompressor.c6
-rw-r--r--fs/squashfs/lzo_wrapper.c136
-rw-r--r--fs/squashfs/squashfs.h3
-rw-r--r--fs/squashfs/squashfs_fs.h20
-rw-r--r--fs/squashfs/xattr.c4
-rw-r--r--fs/squashfs/xattr.h2
-rw-r--r--fs/sysv/super.c73
-rw-r--r--include/acpi/platform/aclinux.h10
-rw-r--r--include/asm-generic/dma-mapping-broken.h3
-rw-r--r--include/asm-generic/fcntl.h4
-rw-r--r--include/drm/drmP.h22
-rw-r--r--include/drm/drm_core.h2
-rw-r--r--include/drm/drm_crtc.h37
-rw-r--r--include/drm/drm_edid.h6
-rw-r--r--include/linux/backing-dev.h1
-rw-r--r--include/linux/blk_types.h2
-rw-r--r--include/linux/blkdev.h7
-rw-r--r--include/linux/dcache.h1
-rw-r--r--include/linux/device-mapper.h16
-rw-r--r--include/linux/dm-ioctl.h5
-rw-r--r--include/linux/dma-mapping.h8
-rw-r--r--include/linux/etherdevice.h2
-rw-r--r--include/linux/fs.h4
-rw-r--r--include/linux/fs_struct.h27
-rw-r--r--include/linux/fsnotify.h37
-rw-r--r--include/linux/fsnotify_backend.h16
-rw-r--r--include/linux/hugetlb.h14
-rw-r--r--include/linux/hugetlb_inline.h22
-rw-r--r--include/linux/i2c-mux.h46
-rw-r--r--include/linux/i2c.h33
-rw-r--r--include/linux/i2c/pca954x.h47
-rw-r--r--include/linux/i2c/sx150x.h78
-rw-r--r--include/linux/io-mapping.h3
-rw-r--r--include/linux/jz4740-adc.h32
-rw-r--r--include/linux/kernel.h10
-rw-r--r--include/linux/kfifo.h1193
-rw-r--r--include/linux/memcontrol.h5
-rw-r--r--include/linux/mfd/ab8500.h6
-rw-r--r--include/linux/mfd/max8998-private.h112
-rw-r--r--include/linux/mfd/max8998.h78
-rw-r--r--include/linux/mfd/mc13783-private.h220
-rw-r--r--include/linux/mfd/mc13783.h2
-rw-r--r--include/linux/mfd/stmpe.h201
-rw-r--r--include/linux/mfd/tps6586x.h47
-rw-r--r--include/linux/mfd/wm8994/gpio.h4
-rw-r--r--include/linux/miscdevice.h1
-rw-r--r--include/linux/mmc/card.h24
-rw-r--r--include/linux/mmc/core.h19
-rw-r--r--include/linux/mmc/host.h4
-rw-r--r--include/linux/mmc/mmc.h25
-rw-r--r--include/linux/mmc/sd.h5
-rw-r--r--include/linux/moduleparam.h288
-rw-r--r--include/linux/mount.h1
-rw-r--r--include/linux/netpoll.h2
-rw-r--r--include/linux/of_device.h16
-rw-r--r--include/linux/of_platform.h14
-rw-r--r--include/linux/oom.h2
-rw-r--r--include/linux/pagemap.h9
-rw-r--r--include/linux/path.h5
-rw-r--r--include/linux/poison.h9
-rw-r--r--include/linux/raid/pq.h2
-rw-r--r--include/linux/regulator/ab8500.h25
-rw-r--r--include/linux/rmap.h5
-rw-r--r--include/linux/s3c_adc_battery.h36
-rw-r--r--include/linux/serial_core.h3
-rw-r--r--include/linux/sh_clk.h23
-rw-r--r--include/linux/slab_def.h4
-rw-r--r--include/linux/slob_def.h4
-rw-r--r--include/linux/slub_def.h8
-rw-r--r--include/linux/spi/max7301.h8
-rw-r--r--include/linux/swap.h3
-rw-r--r--include/linux/sysv_fs.h11
-rw-r--r--include/linux/time.h2
-rw-r--r--include/linux/vgaarb.h1
-rw-r--r--include/linux/virtio_9p.h1
-rw-r--r--include/linux/vmalloc.h2
-rw-r--r--include/linux/wm97xx_batt.h16
-rw-r--r--include/linux/writeback.h5
-rw-r--r--include/net/bluetooth/l2cap.h4
-rw-r--r--include/net/sock.h4
-rw-r--r--include/scsi/scsi.h8
-rw-r--r--include/scsi/scsi_netlink.h4
-rw-r--r--include/video/mipi_display.h130
-rw-r--r--include/video/sh_mipi_dsi.h35
-rw-r--r--include/video/sh_mobile_hdmi.h22
-rw-r--r--include/video/sh_mobile_lcdc.h41
-rw-r--r--include/xen/interface/memory.h50
-rw-r--r--include/xen/swiotlb-xen.h65
-rw-r--r--include/xen/xen-ops.h6
-rw-r--r--init/Kconfig4
-rw-r--r--init/main.c8
-rw-r--r--kernel/audit_watch.c4
-rw-r--r--kernel/auditsc.c9
-rw-r--r--kernel/cgroup.c4
-rw-r--r--kernel/cred.c4
-rw-r--r--kernel/exit.c7
-rw-r--r--kernel/kexec.c8
-rw-r--r--kernel/kfifo.c750
-rw-r--r--kernel/panic.c60
-rw-r--r--kernel/params.c233
-rw-r--r--kernel/pid.c56
-rw-r--r--kernel/ptrace.c12
-rw-r--r--kernel/time/timekeeping.c11
-rw-r--r--kernel/trace/blktrace.c8
-rw-r--r--lib/bug.c12
-rw-r--r--lib/decompress_bunzip2.c10
-rw-r--r--lib/inflate.c2
-rw-r--r--lib/raid6/Makefile81
-rw-r--r--lib/raid6/algos.c (renamed from lib/raid6/raid6algos.c)4
-rw-r--r--lib/raid6/altivec.uc (renamed from lib/raid6/raid6altivec.uc)0
-rw-r--r--lib/raid6/int.uc (renamed from lib/raid6/raid6int.uc)0
-rw-r--r--lib/raid6/mmx.c (renamed from lib/raid6/raid6mmx.c)6
-rw-r--r--lib/raid6/raid6test/Makefile75
-rw-r--r--lib/raid6/recov.c (renamed from lib/raid6/raid6recov.c)2
-rw-r--r--lib/raid6/sse1.c (renamed from lib/raid6/raid6sse1.c)6
-rw-r--r--lib/raid6/sse2.c (renamed from lib/raid6/raid6sse2.c)4
-rw-r--r--lib/raid6/test/Makefile72
-rw-r--r--lib/raid6/test/test.c (renamed from lib/raid6/raid6test/test.c)0
-rw-r--r--lib/raid6/x86.h (renamed from lib/raid6/raid6x86.h)2
-rw-r--r--mm/backing-dev.c3
-rw-r--r--mm/hugetlb.c104
-rw-r--r--mm/hwpoison-inject.c15
-rw-r--r--mm/memcontrol.c407
-rw-r--r--mm/memory-failure.c120
-rw-r--r--mm/memory.c25
-rw-r--r--mm/oom_kill.c2
-rw-r--r--mm/page-writeback.c185
-rw-r--r--mm/rmap.c59
-rw-r--r--mm/vmalloc.c4
-rw-r--r--mm/vmscan.c15
-rw-r--r--net/bluetooth/l2cap.c11
-rw-r--r--net/caif/cfpkt_skbuff.c2
-rw-r--r--net/can/bcm.c41
-rw-r--r--net/dns_resolver/dns_key.c92
-rw-r--r--net/dns_resolver/dns_query.c5
-rw-r--r--net/dsa/Kconfig2
-rw-r--r--net/mac80211/rate.c2
-rw-r--r--net/rxrpc/ar-internal.h16
-rw-r--r--net/sched/sch_api.c22
-rw-r--r--net/sched/sch_atm.c4
-rw-r--r--net/sched/sch_sfq.c14
-rw-r--r--net/sched/sch_tbf.c4
-rw-r--r--net/sched/sch_teql.c2
-rw-r--r--net/sunrpc/auth.c9
-rw-r--r--net/sunrpc/xprtsock.c26
-rw-r--r--net/wireless/mlme.c8
-rw-r--r--samples/Kconfig10
-rw-r--r--samples/Makefile2
-rw-r--r--samples/kfifo/Makefile1
-rw-r--r--samples/kfifo/bytestream-example.c163
-rw-r--r--samples/kfifo/dma-example.c115
-rw-r--r--samples/kfifo/inttype-example.c157
-rw-r--r--samples/kfifo/record-example.c167
-rwxr-xr-xscripts/kernel-doc2
-rw-r--r--scripts/mod/modpost.c19
-rw-r--r--security/apparmor/lsm.c36
-rw-r--r--security/keys/internal.h5
-rw-r--r--sound/aoa/soundbus/core.c2
-rw-r--r--sound/aoa/soundbus/soundbus.h2
-rw-r--r--sound/aoa/soundbus/sysfs.c2
-rw-r--r--sound/oss/ad1848.c2
-rw-r--r--sound/oss/au1550_ac97.c1
-rw-r--r--sound/pci/hda/hda_codec.c150
-rw-r--r--sound/pci/hda/hda_codec.h12
-rw-r--r--sound/pci/hda/hda_intel.c6
-rw-r--r--sound/pci/hda/patch_conexant.c3
-rw-r--r--sound/pci/hda/patch_nvhdmi.c61
-rw-r--r--sound/pci/hda/patch_realtek.c41
-rw-r--r--sound/pci/hda/patch_sigmatel.c13
-rw-r--r--sound/soc/blackfin/Kconfig7
-rw-r--r--sound/soc/blackfin/bf5xx-ad1980.c10
-rw-r--r--sound/soc/codecs/ad1980.c10
-rw-r--r--sound/soc/codecs/ad1980.h6
-rw-r--r--sound/soc/codecs/wm8580.c6
-rw-r--r--sound/soc/fsl/mpc5200_dma.c4
-rw-r--r--sound/soc/fsl/mpc5200_dma.h4
-rw-r--r--sound/soc/fsl/mpc5200_psc_ac97.c4
-rw-r--r--sound/soc/fsl/mpc5200_psc_i2s.c4
-rw-r--r--sound/soc/fsl/mpc8610_hpcd.c4
-rw-r--r--sound/soc/imx/Kconfig4
-rw-r--r--sound/soc/soc-cache.c4
-rw-r--r--sound/sparc/amd7930.c8
-rw-r--r--sound/sparc/cs4231.c18
-rw-r--r--sound/sparc/dbri.c8
-rw-r--r--tools/perf/Makefile31
-rw-r--r--tools/perf/builtin-annotate.c2
-rw-r--r--tools/perf/builtin-report.c31
-rw-r--r--tools/perf/builtin-timechart.c4
-rw-r--r--tools/perf/builtin-trace.c19
-rw-r--r--tools/perf/util/debug.c2
-rw-r--r--tools/perf/util/debug.h9
-rw-r--r--tools/perf/util/hist.c16
-rw-r--r--tools/perf/util/hist.h3
-rw-r--r--tools/perf/util/include/linux/list.h8
-rw-r--r--tools/perf/util/include/linux/types.h12
-rw-r--r--tools/perf/util/probe-event.c11
-rw-r--r--tools/perf/util/probe-finder.c9
-rw-r--r--tools/perf/util/pstack.h2
-rw-r--r--tools/perf/util/sort.c6
-rw-r--r--tools/perf/util/symbol.c40
-rw-r--r--tools/perf/util/symbol.h1
-rw-r--r--tools/perf/util/ui/browser.c329
-rw-r--r--tools/perf/util/ui/browser.h46
-rw-r--r--tools/perf/util/ui/browsers/annotate.c240
-rw-r--r--tools/perf/util/ui/browsers/hists.c (renamed from tools/perf/util/newt.c)1454
-rw-r--r--tools/perf/util/ui/browsers/map.c161
-rw-r--r--tools/perf/util/ui/browsers/map.h6
-rw-r--r--tools/perf/util/ui/helpline.c69
-rw-r--r--tools/perf/util/ui/helpline.h11
-rw-r--r--tools/perf/util/ui/libslang.h27
-rw-r--r--tools/perf/util/ui/progress.c60
-rw-r--r--tools/perf/util/ui/progress.h11
-rw-r--r--tools/perf/util/ui/setup.c42
-rw-r--r--tools/perf/util/ui/util.c114
-rw-r--r--tools/perf/util/ui/util.h10
1214 files changed, 45563 insertions, 13456 deletions
diff --git a/Documentation/00-INDEX b/Documentation/00-INDEX
index 5405f7aecefc..8dfc6708a257 100644
--- a/Documentation/00-INDEX
+++ b/Documentation/00-INDEX
@@ -130,8 +130,6 @@ edac.txt
130 - information on EDAC - Error Detection And Correction 130 - information on EDAC - Error Detection And Correction
131eisa.txt 131eisa.txt
132 - info on EISA bus support. 132 - info on EISA bus support.
133exception.txt
134 - how Linux v2.2 handles exceptions without verify_area etc.
135fault-injection/ 133fault-injection/
136 - dir with docs about the fault injection capabilities infrastructure. 134 - dir with docs about the fault injection capabilities infrastructure.
137fb/ 135fb/
@@ -234,6 +232,8 @@ memory.txt
234 - info on typical Linux memory problems. 232 - info on typical Linux memory problems.
235mips/ 233mips/
236 - directory with info about Linux on MIPS architecture. 234 - directory with info about Linux on MIPS architecture.
235mmc/
236 - directory with info about the MMC subsystem
237mono.txt 237mono.txt
238 - how to execute Mono-based .NET binaries with the help of BINFMT_MISC. 238 - how to execute Mono-based .NET binaries with the help of BINFMT_MISC.
239mutex-design.txt 239mutex-design.txt
diff --git a/Documentation/DMA-API-HOWTO.txt b/Documentation/DMA-API-HOWTO.txt
index 98ce51796f71..3c4e07123e59 100644
--- a/Documentation/DMA-API-HOWTO.txt
+++ b/Documentation/DMA-API-HOWTO.txt
@@ -753,6 +753,16 @@ to "Closing".
753 alignment constraints (e.g. the alignment constraints about 64-bit 753 alignment constraints (e.g. the alignment constraints about 64-bit
754 objects). 754 objects).
755 755
7563) Supporting multiple types of IOMMUs
757
758 If your architecture needs to support multiple types of IOMMUs, you
759 can use include/linux/asm-generic/dma-mapping-common.h. It's a
760 library to support the DMA API with multiple types of IOMMUs. Lots
761 of architectures (x86, powerpc, sh, alpha, ia64, microblaze and
762 sparc) use it. Choose one to see how it can be used. If you need to
763 support multiple types of IOMMUs in a single system, the example of
764 x86 or powerpc helps.
765
756 Closing 766 Closing
757 767
758This document, and the API itself, would not be in its current 768This document, and the API itself, would not be in its current
diff --git a/Documentation/DMA-API.txt b/Documentation/DMA-API.txt
index 05e2ae236865..fe2326906610 100644
--- a/Documentation/DMA-API.txt
+++ b/Documentation/DMA-API.txt
@@ -456,12 +456,6 @@ be identical to those passed in (and returned by
456dma_alloc_noncoherent()). 456dma_alloc_noncoherent()).
457 457
458int 458int
459dma_is_consistent(struct device *dev, dma_addr_t dma_handle)
460
461Returns true if the device dev is performing consistent DMA on the memory
462area pointed to by the dma_handle.
463
464int
465dma_get_cache_alignment(void) 459dma_get_cache_alignment(void)
466 460
467Returns the processor cache alignment. This is the absolute minimum 461Returns the processor cache alignment. This is the absolute minimum
diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
index 4b603c5c3cc1..34929f24c284 100644
--- a/Documentation/DocBook/Makefile
+++ b/Documentation/DocBook/Makefile
@@ -35,7 +35,7 @@ PS_METHOD = $(prefer-db2x)
35PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs cleandocs xmldoclinks 35PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs cleandocs xmldoclinks
36 36
37BOOKS := $(addprefix $(obj)/,$(DOCBOOKS)) 37BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
38xmldocs: $(BOOKS) xmldoclinks 38xmldocs: $(BOOKS)
39sgmldocs: xmldocs 39sgmldocs: xmldocs
40 40
41PS := $(patsubst %.xml, %.ps, $(BOOKS)) 41PS := $(patsubst %.xml, %.ps, $(BOOKS))
@@ -95,7 +95,7 @@ define rule_docproc
95 ) > $(dir $@).$(notdir $@).cmd 95 ) > $(dir $@).$(notdir $@).cmd
96endef 96endef
97 97
98%.xml: %.tmpl FORCE 98%.xml: %.tmpl xmldoclinks FORCE
99 $(call if_changed_rule,docproc) 99 $(call if_changed_rule,docproc)
100 100
101### 101###
diff --git a/Documentation/DocBook/kernel-api.tmpl b/Documentation/DocBook/kernel-api.tmpl
index 44b3def961a2..a20c6f6fffc3 100644
--- a/Documentation/DocBook/kernel-api.tmpl
+++ b/Documentation/DocBook/kernel-api.tmpl
@@ -132,7 +132,6 @@ X!Ilib/string.c
132 <title>FIFO Buffer</title> 132 <title>FIFO Buffer</title>
133 <sect1><title>kfifo interface</title> 133 <sect1><title>kfifo interface</title>
134!Iinclude/linux/kfifo.h 134!Iinclude/linux/kfifo.h
135!Ekernel/kfifo.c
136 </sect1> 135 </sect1>
137 </chapter> 136 </chapter>
138 137
diff --git a/Documentation/cpu-hotplug.txt b/Documentation/cpu-hotplug.txt
index a99d7031cdf9..45d5a217484f 100644
--- a/Documentation/cpu-hotplug.txt
+++ b/Documentation/cpu-hotplug.txt
@@ -2,7 +2,7 @@
2 2
3 Maintainers: 3 Maintainers:
4 CPU Hotplug Core: 4 CPU Hotplug Core:
5 Rusty Russell <rusty@rustycorp.com.au> 5 Rusty Russell <rusty@rustcorp.com.au>
6 Srivatsa Vaddagiri <vatsa@in.ibm.com> 6 Srivatsa Vaddagiri <vatsa@in.ibm.com>
7 i386: 7 i386:
8 Zwane Mwaikambo <zwane@arm.linux.org.uk> 8 Zwane Mwaikambo <zwane@arm.linux.org.uk>
diff --git a/Documentation/devices.txt b/Documentation/devices.txt
index f2da781705b2..d0d1df6cb5de 100644
--- a/Documentation/devices.txt
+++ b/Documentation/devices.txt
@@ -445,6 +445,7 @@ Your cooperation is appreciated.
445 233 = /dev/kmview View-OS A process with a view 445 233 = /dev/kmview View-OS A process with a view
446 234 = /dev/btrfs-control Btrfs control device 446 234 = /dev/btrfs-control Btrfs control device
447 235 = /dev/autofs Autofs control device 447 235 = /dev/autofs Autofs control device
448 236 = /dev/mapper/control Device-Mapper control device
448 240-254 Reserved for local use 449 240-254 Reserved for local use
449 255 Reserved for MISC_DYNAMIC_MINOR 450 255 Reserved for MISC_DYNAMIC_MINOR
450 451
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index b16cbe4152ea..842aa9de84a6 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -547,3 +547,20 @@ Why: superseded by acpi_sleep=nonvs
547Who: Rafael J. Wysocki <rjw@sisk.pl> 547Who: Rafael J. Wysocki <rjw@sisk.pl>
548 548
549---------------------------- 549----------------------------
550
551What: PCI DMA unmap state API
552When: August 2012
553Why: PCI DMA unmap state API (include/linux/pci-dma.h) was replaced
554 with DMA unmap state API (DMA unmap state API can be used for
555 any bus).
556Who: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
557
558----------------------------
559
560What: DMA_xxBIT_MASK macros
561When: Jun 2011
562Why: DMA_xxBIT_MASK macros were replaced with DMA_BIT_MASK() macros.
563Who: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
564
565----------------------------
566
diff --git a/Documentation/filesystems/squashfs.txt b/Documentation/filesystems/squashfs.txt
index 203f7202cc9e..66699afd66ca 100644
--- a/Documentation/filesystems/squashfs.txt
+++ b/Documentation/filesystems/squashfs.txt
@@ -2,7 +2,7 @@ SQUASHFS 4.0 FILESYSTEM
2======================= 2=======================
3 3
4Squashfs is a compressed read-only filesystem for Linux. 4Squashfs is a compressed read-only filesystem for Linux.
5It uses zlib compression to compress files, inodes and directories. 5It uses zlib/lzo compression to compress files, inodes and directories.
6Inodes in the system are very small and all blocks are packed to minimise 6Inodes in the system are very small and all blocks are packed to minimise
7data overhead. Block sizes greater than 4K are supported up to a maximum 7data overhead. Block sizes greater than 4K are supported up to a maximum
8of 1Mbytes (default block size 128K). 8of 1Mbytes (default block size 128K).
diff --git a/Documentation/gpio.txt b/Documentation/gpio.txt
index c2c6e9b39bbe..d96a6dba5748 100644
--- a/Documentation/gpio.txt
+++ b/Documentation/gpio.txt
@@ -158,10 +158,11 @@ and configure pullups/pulldowns appropriately.)
158Spinlock-Safe GPIO access 158Spinlock-Safe GPIO access
159------------------------- 159-------------------------
160Most GPIO controllers can be accessed with memory read/write instructions. 160Most GPIO controllers can be accessed with memory read/write instructions.
161That doesn't need to sleep, and can safely be done from inside IRQ handlers. 161Those don't need to sleep, and can safely be done from inside hard
162(That includes hardirq contexts on RT kernels.) 162(nonthreaded) IRQ handlers and similar contexts.
163 163
164Use these calls to access such GPIOs: 164Use the following calls to access such GPIOs,
165for which gpio_cansleep() will always return false (see below):
165 166
166 /* GPIO INPUT: return zero or nonzero */ 167 /* GPIO INPUT: return zero or nonzero */
167 int gpio_get_value(unsigned gpio); 168 int gpio_get_value(unsigned gpio);
@@ -210,9 +211,31 @@ To access such GPIOs, a different set of accessors is defined:
210 /* GPIO OUTPUT, might sleep */ 211 /* GPIO OUTPUT, might sleep */
211 void gpio_set_value_cansleep(unsigned gpio, int value); 212 void gpio_set_value_cansleep(unsigned gpio, int value);
212 213
213Other than the fact that these calls might sleep, and will not be ignored 214
214for GPIOs that can't be accessed from IRQ handlers, these calls act the 215Accessing such GPIOs requires a context which may sleep, for example
215same as the spinlock-safe calls. 216a threaded IRQ handler, and those accessors must be used instead of
217spinlock-safe accessors without the cansleep() name suffix.
218
219Other than the fact that these accessors might sleep, and will work
220on GPIOs that can't be accessed from hardIRQ handlers, these calls act
221the same as the spinlock-safe calls.
222
223 ** IN ADDITION ** calls to setup and configure such GPIOs must be made
224from contexts which may sleep, since they may need to access the GPIO
225controller chip too: (These setup calls are usually made from board
226setup or driver probe/teardown code, so this is an easy constraint.)
227
228 gpio_direction_input()
229 gpio_direction_output()
230 gpio_request()
231
232## gpio_request_one()
233## gpio_request_array()
234## gpio_free_array()
235
236 gpio_free()
237 gpio_set_debounce()
238
216 239
217 240
218Claiming and Releasing GPIOs 241Claiming and Releasing GPIOs
diff --git a/Documentation/i2c/instantiating-devices b/Documentation/i2c/instantiating-devices
index e89490270aba..87da405a8597 100644
--- a/Documentation/i2c/instantiating-devices
+++ b/Documentation/i2c/instantiating-devices
@@ -102,7 +102,7 @@ static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev)
102 memset(&i2c_info, 0, sizeof(struct i2c_board_info)); 102 memset(&i2c_info, 0, sizeof(struct i2c_board_info));
103 strlcpy(i2c_info.name, "isp1301_pnx", I2C_NAME_SIZE); 103 strlcpy(i2c_info.name, "isp1301_pnx", I2C_NAME_SIZE);
104 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, 104 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info,
105 normal_i2c); 105 normal_i2c, NULL);
106 i2c_put_adapter(i2c_adap); 106 i2c_put_adapter(i2c_adap);
107 (...) 107 (...)
108} 108}
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index d529b1363e95..873b68090098 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -915,9 +915,6 @@ and is between 256 and 4096 characters. It is defined in the file
915 controller 915 controller
916 i8042.nopnp [HW] Don't use ACPIPnP / PnPBIOS to discover KBD/AUX 916 i8042.nopnp [HW] Don't use ACPIPnP / PnPBIOS to discover KBD/AUX
917 controllers 917 controllers
918 i8042.panicblink=
919 [HW] Frequency with which keyboard LEDs should blink
920 when kernel panics (default is 0.5 sec)
921 i8042.reset [HW] Reset the controller during init and cleanup 918 i8042.reset [HW] Reset the controller during init and cleanup
922 i8042.unlock [HW] Unlock (ignore) the keylock 919 i8042.unlock [HW] Unlock (ignore) the keylock
923 920
diff --git a/Documentation/mmc/00-INDEX b/Documentation/mmc/00-INDEX
new file mode 100644
index 000000000000..fca586f5b853
--- /dev/null
+++ b/Documentation/mmc/00-INDEX
@@ -0,0 +1,4 @@
100-INDEX
2 - this file
3mmc-dev-attrs.txt
4 - info on SD and MMC device attributes
diff --git a/Documentation/mmc/mmc-dev-attrs.txt b/Documentation/mmc/mmc-dev-attrs.txt
new file mode 100644
index 000000000000..ff2bd685bced
--- /dev/null
+++ b/Documentation/mmc/mmc-dev-attrs.txt
@@ -0,0 +1,56 @@
1SD and MMC Device Attributes
2============================
3
4All attributes are read-only.
5
6 cid Card Identifaction Register
7 csd Card Specific Data Register
8 scr SD Card Configuration Register (SD only)
9 date Manufacturing Date (from CID Register)
10 fwrev Firmware/Product Revision (from CID Register) (SD and MMCv1 only)
11 hwrev Hardware/Product Revision (from CID Register) (SD and MMCv1 only)
12 manfid Manufacturer ID (from CID Register)
13 name Product Name (from CID Register)
14 oemid OEM/Application ID (from CID Register)
15 serial Product Serial Number (from CID Register)
16 erase_size Erase group size
17 preferred_erase_size Preferred erase size
18
19Note on Erase Size and Preferred Erase Size:
20
21 "erase_size" is the minimum size, in bytes, of an erase
22 operation. For MMC, "erase_size" is the erase group size
23 reported by the card. Note that "erase_size" does not apply
24 to trim or secure trim operations where the minimum size is
25 always one 512 byte sector. For SD, "erase_size" is 512
26 if the card is block-addressed, 0 otherwise.
27
28 SD/MMC cards can erase an arbitrarily large area up to and
29 including the whole card. When erasing a large area it may
30 be desirable to do it in smaller chunks for three reasons:
31 1. A single erase command will make all other I/O on
32 the card wait. This is not a problem if the whole card
33 is being erased, but erasing one partition will make
34 I/O for another partition on the same card wait for the
35 duration of the erase - which could be a several
36 minutes.
37 2. To be able to inform the user of erase progress.
38 3. The erase timeout becomes too large to be very
39 useful. Because the erase timeout contains a margin
40 which is multiplied by the size of the erase area,
41 the value can end up being several minutes for large
42 areas.
43
44 "erase_size" is not the most efficient unit to erase
45 (especially for SD where it is just one sector),
46 hence "preferred_erase_size" provides a good chunk
47 size for erasing large areas.
48
49 For MMC, "preferred_erase_size" is the high-capacity
50 erase size if a card specifies one, otherwise it is
51 based on the capacity of the card.
52
53 For SD, "preferred_erase_size" is the allocation unit
54 size specified by the card.
55
56 "preferred_erase_size" is in bytes.
diff --git a/Documentation/networking/wavelan.txt b/Documentation/networking/wavelan.txt
deleted file mode 100644
index 90e0ac4e15da..000000000000
--- a/Documentation/networking/wavelan.txt
+++ /dev/null
@@ -1,74 +0,0 @@
1 The Wavelan drivers saga
2 ------------------------
3
4 By Jean Tourrilhes <jt@hpl.hp.com>
5
6 The Wavelan is a Radio network adapter designed by
7Lucent. Under this generic name is hidden quite a variety of hardware,
8and many Linux driver to support it.
9 The get the full story on Wireless LANs, please consult :
10 http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/
11
12"wavelan" driver (old ISA Wavelan)
13----------------
14 o Config : Network device -> Wireless LAN -> AT&T WaveLAN
15 o Location : .../drivers/net/wireless/wavelan*
16 o in-line doc : .../drivers/net/wireless/wavelan.p.h
17 o on-line doc :
18 http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Wavelan.html
19
20 This is the driver for the ISA version of the first generation
21of the Wavelan, now discontinued. The device is 2 Mb/s, composed of a
22Intel 82586 controller and a Lucent Modem, and is NOT 802.11 compliant.
23 The driver has been tested with the following hardware :
24 o Wavelan ISA 915 MHz (full length ISA card)
25 o Wavelan ISA 915 MHz 2.0 (half length ISA card)
26 o Wavelan ISA 2.4 GHz (full length ISA card, fixed frequency)
27 o Wavelan ISA 2.4 GHz 2.0 (half length ISA card, frequency selectable)
28 o Above cards with the optional DES encryption feature
29
30"wavelan_cs" driver (old Pcmcia Wavelan)
31-------------------
32 o Config : Network device -> PCMCIA network ->
33 Pcmcia Wireless LAN -> AT&T/Lucent WaveLAN
34 o Location : .../drivers/net/pcmcia/wavelan*
35 o in-line doc : .../drivers/net/pcmcia/wavelan_cs.h
36 o on-line doc :
37 http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Wavelan.html
38
39 This is the driver for the PCMCIA version of the first
40generation of the Wavelan, now discontinued. The device is 2 Mb/s,
41composed of a Intel 82593 controller (totally different from the 82586)
42and a Lucent Modem, and NOT 802.11 compatible.
43 The driver has been tested with the following hardware :
44 o Wavelan Pcmcia 915 MHz 2.0 (Pcmcia card + separate
45 modem/antenna block)
46 o Wavelan Pcmcia 2.4 GHz 2.0 (Pcmcia card + separate
47 modem/antenna block)
48
49"wvlan_cs" driver (Wavelan IEEE, GPL)
50-----------------
51 o Config : Not yet in kernel
52 o Location : Pcmcia package 3.1.10+
53 o on-line doc :
54 http://web.archive.org/web/*/http://www.fasta.fh-dortmund.de/users/andy/wvlan/
55
56 This is the driver for the current generation of Wavelan IEEE,
57which is 802.11 compatible. Depending on version, it is 2 Mb/s or 11
58Mb/s, with or without encryption, all implemented in Lucent specific
59DSP (the Hermes).
60 This is a GPL full source PCMCIA driver (ISA is just a Pcmcia
61card with ISA-Pcmcia bridge).
62
63"wavelan2_cs" driver (Wavelan IEEE, binary)
64--------------------
65 o Config : Not yet in kernel
66 o Location : ftp://sourceforge.org/pcmcia/contrib/
67
68 This driver support exactly the same hardware as the previous
69driver, the main difference is that it is based on a binary library
70and supported by Lucent.
71
72 I hope it clears the confusion ;-)
73
74 Jean
diff --git a/Documentation/padata.txt b/Documentation/padata.txt
index 473ebf22cd69..7ddfe216a0aa 100644
--- a/Documentation/padata.txt
+++ b/Documentation/padata.txt
@@ -19,7 +19,7 @@ overall control of how tasks are to be run:
19 19
20The pcpumask describes which processors will be used to execute work 20The pcpumask describes which processors will be used to execute work
21submitted to this instance in parallel. The cbcpumask defines which 21submitted to this instance in parallel. The cbcpumask defines which
22processors are allowed to use as the serialization callback processor. 22processors are allowed to be used as the serialization callback processor.
23The workqueue wq is where the work will actually be done; it should be 23The workqueue wq is where the work will actually be done; it should be
24a multithreaded queue, naturally. 24a multithreaded queue, naturally.
25 25
@@ -30,10 +30,10 @@ cpumasks this helper function can be used:
30 30
31Note: Padata maintains two kinds of cpumasks internally. The user supplied 31Note: Padata maintains two kinds of cpumasks internally. The user supplied
32cpumasks, submitted by padata_alloc/padata_alloc_possible and the 'usable' 32cpumasks, submitted by padata_alloc/padata_alloc_possible and the 'usable'
33cpumasks. The usable cpumasks are always the subset of active cpus in the 33cpumasks. The usable cpumasks are always a subset of active CPUs in the
34user supplied cpumasks, these are the cpumasks padata actually use. So 34user supplied cpumasks; these are the cpumasks padata actually uses. So
35it is legal to supply a cpumask to padata that contains offline cpus. 35it is legal to supply a cpumask to padata that contains offline CPUs.
36Once a offline cpu in the user supplied cpumask comes online, padata 36Once an offline CPU in the user supplied cpumask comes online, padata
37is going to use it. 37is going to use it.
38 38
39There are functions for enabling and disabling the instance: 39There are functions for enabling and disabling the instance:
@@ -44,7 +44,7 @@ There are functions for enabling and disabling the instance:
44These functions are setting or clearing the "PADATA_INIT" flag; 44These functions are setting or clearing the "PADATA_INIT" flag;
45if that flag is not set, other functions will refuse to work. 45if that flag is not set, other functions will refuse to work.
46padata_start returns zero on success (flag set) or -EINVAL if the 46padata_start returns zero on success (flag set) or -EINVAL if the
47padata cpumask contains no active cpu (flag not set). 47padata cpumask contains no active CPU (flag not set).
48padata_stop clears the flag and blocks until the padata instance 48padata_stop clears the flag and blocks until the padata instance
49is unused. 49is unused.
50 50
@@ -63,11 +63,11 @@ done with great frequency.
63 63
64It's possible to change both cpumasks of a padata instance with 64It's possible to change both cpumasks of a padata instance with
65padata_set_cpumasks by specifying the cpumasks for parallel execution (pcpumask) 65padata_set_cpumasks by specifying the cpumasks for parallel execution (pcpumask)
66and for the serial callback function (cbcpumask). padata_set_cpumask is to 66and for the serial callback function (cbcpumask). padata_set_cpumask is used to
67change just one of the cpumasks. Here cpumask_type is one of PADATA_CPU_SERIAL, 67change just one of the cpumasks. Here cpumask_type is one of PADATA_CPU_SERIAL,
68PADATA_CPU_PARALLEL and cpumask specifies the new cpumask to use. 68PADATA_CPU_PARALLEL and cpumask specifies the new cpumask to use.
69To simply add or remove one cpu from a certain cpumask the functions 69To simply add or remove one CPU from a certain cpumask the functions
70padata_add_cpu/padata_remove_cpu are used. cpu specifies the cpu to add or 70padata_add_cpu/padata_remove_cpu are used. cpu specifies the CPU to add or
71remove and mask is one of PADATA_CPU_SERIAL, PADATA_CPU_PARALLEL. 71remove and mask is one of PADATA_CPU_SERIAL, PADATA_CPU_PARALLEL.
72 72
73If a user is interested in padata cpumask changes, he can register to 73If a user is interested in padata cpumask changes, he can register to
@@ -82,7 +82,7 @@ To unregister from that notifier:
82 struct notifier_block *nblock); 82 struct notifier_block *nblock);
83 83
84The padata cpumask change notifier notifies about changes of the usable 84The padata cpumask change notifier notifies about changes of the usable
85cpumasks, i.e. the subset of active cpus in the user supplied cpumask. 85cpumasks, i.e. the subset of active CPUs in the user supplied cpumask.
86 86
87Padata calls the notifier chain with: 87Padata calls the notifier chain with:
88 88
@@ -92,7 +92,7 @@ Padata calls the notifier chain with:
92 92
93Here cpumask_change_notifier is registered notifier, notification_mask 93Here cpumask_change_notifier is registered notifier, notification_mask
94is one of PADATA_CPU_SERIAL, PADATA_CPU_PARALLEL and cpumask is a pointer 94is one of PADATA_CPU_SERIAL, PADATA_CPU_PARALLEL and cpumask is a pointer
95to a struct padata_cpumask that contains the new cpumask informations. 95to a struct padata_cpumask that contains the new cpumask information.
96 96
97Actually submitting work to the padata instance requires the creation of a 97Actually submitting work to the padata instance requires the creation of a
98padata_priv structure: 98padata_priv structure:
@@ -104,7 +104,7 @@ padata_priv structure:
104 }; 104 };
105 105
106This structure will almost certainly be embedded within some larger 106This structure will almost certainly be embedded within some larger
107structure specific to the work to be done. Most its fields are private to 107structure specific to the work to be done. Most of its fields are private to
108padata, but the structure should be zeroed at initialisation time, and the 108padata, but the structure should be zeroed at initialisation time, and the
109parallel() and serial() functions should be provided. Those functions will 109parallel() and serial() functions should be provided. Those functions will
110be called in the process of getting the work done as we will see 110be called in the process of getting the work done as we will see
diff --git a/Documentation/powerpc/dts-bindings/fsl/esdhc.txt b/Documentation/powerpc/dts-bindings/fsl/esdhc.txt
index 8a0040738969..64bcb8be973c 100644
--- a/Documentation/powerpc/dts-bindings/fsl/esdhc.txt
+++ b/Documentation/powerpc/dts-bindings/fsl/esdhc.txt
@@ -14,6 +14,8 @@ Required properties:
14 reports inverted write-protect state; 14 reports inverted write-protect state;
15 - sdhci,1-bit-only : (optional) specifies that a controller can 15 - sdhci,1-bit-only : (optional) specifies that a controller can
16 only handle 1-bit data transfers. 16 only handle 1-bit data transfers.
17 - sdhci,auto-cmd12: (optional) specifies that a controller can
18 only handle auto CMD12.
17 19
18Example: 20Example:
19 21
diff --git a/Documentation/sound/alsa/HD-Audio-Models.txt b/Documentation/sound/alsa/HD-Audio-Models.txt
index 03771d7c5dd7..ce46fa1e643e 100644
--- a/Documentation/sound/alsa/HD-Audio-Models.txt
+++ b/Documentation/sound/alsa/HD-Audio-Models.txt
@@ -83,8 +83,8 @@ ALC269
83====== 83======
84 basic Basic preset 84 basic Basic preset
85 quanta Quanta FL1 85 quanta Quanta FL1
86 eeepc-p703 ASUS Eeepc P703 P900A 86 laptop-amic Laptops with analog-mic input
87 eeepc-p901 ASUS Eeepc P901 S101 87 laptop-dmic Laptops with digital-mic input
88 fujitsu FSC Amilo 88 fujitsu FSC Amilo
89 lifebook Fujitsu Lifebook S6420 89 lifebook Fujitsu Lifebook S6420
90 auto auto-config reading BIOS (default) 90 auto auto-config reading BIOS (default)
@@ -109,6 +109,8 @@ ALC662/663/272
109 asus-mode4 ASUS 109 asus-mode4 ASUS
110 asus-mode5 ASUS 110 asus-mode5 ASUS
111 asus-mode6 ASUS 111 asus-mode6 ASUS
112 asus-mode7 ASUS
113 asus-mode8 ASUS
112 dell Dell with ALC272 114 dell Dell with ALC272
113 dell-zm1 Dell ZM1 with ALC272 115 dell-zm1 Dell ZM1 with ALC272
114 samsung-nc10 Samsung NC10 mini notebook 116 samsung-nc10 Samsung NC10 mini notebook
@@ -295,8 +297,10 @@ Conexant 5066
295============= 297=============
296 laptop Basic Laptop config (default) 298 laptop Basic Laptop config (default)
297 dell-laptop Dell laptops 299 dell-laptop Dell laptops
300 dell-vostro Dell Vostro
298 olpc-xo-1_5 OLPC XO 1.5 301 olpc-xo-1_5 OLPC XO 1.5
299 ideapad Lenovo IdeaPad U150 302 ideapad Lenovo IdeaPad U150
303 thinkpad Lenovo Thinkpad
300 304
301STAC9200 305STAC9200
302======== 306========
@@ -404,6 +408,7 @@ STAC92HD83*
404 mic-ref Reference board with power management for ports 408 mic-ref Reference board with power management for ports
405 dell-s14 Dell laptop 409 dell-s14 Dell laptop
406 hp HP laptops with (inverted) mute-LED 410 hp HP laptops with (inverted) mute-LED
411 hp-dv7-4000 HP dv-7 4000
407 auto BIOS setup (default) 412 auto BIOS setup (default)
408 413
409STAC9872 414STAC9872
@@ -416,3 +421,7 @@ Cirrus Logic CS4206/4207
416 mbp55 MacBook Pro 5,5 421 mbp55 MacBook Pro 5,5
417 imac27 IMac 27 Inch 422 imac27 IMac 27 Inch
418 auto BIOS setup (default) 423 auto BIOS setup (default)
424
425VIA VT17xx/VT18xx/VT20xx
426========================
427 auto BIOS setup (default)
diff --git a/MAINTAINERS b/MAINTAINERS
index 89399474d91f..39d8c5ce9913 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -616,10 +616,10 @@ M: Richard Purdie <rpurdie@rpsys.net>
616S: Maintained 616S: Maintained
617 617
618ARM/CORTINA SYSTEMS GEMINI ARM ARCHITECTURE 618ARM/CORTINA SYSTEMS GEMINI ARM ARCHITECTURE
619M: Paulius Zaleckas <paulius.zaleckas@gmail.com> 619M: Hans Ulli Kroll <ulli.kroll@googlemail.com>
620L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 620L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
621T: git git://gitorious.org/linux-gemini/mainline.git 621T: git git://git.berlios.de/gemini-board
622S: Odd Fixes 622S: Maintained
623F: arch/arm/mach-gemini/ 623F: arch/arm/mach-gemini/
624 624
625ARM/EBSA110 MACHINE SUPPORT 625ARM/EBSA110 MACHINE SUPPORT
@@ -641,9 +641,10 @@ T: topgit git://git.openezx.org/openezx.git
641F: arch/arm/mach-pxa/ezx.c 641F: arch/arm/mach-pxa/ezx.c
642 642
643ARM/FARADAY FA526 PORT 643ARM/FARADAY FA526 PORT
644M: Paulius Zaleckas <paulius.zaleckas@gmail.com> 644M: Hans Ulli Kroll <ulli.kroll@googlemail.com>
645L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 645L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
646S: Odd Fixes 646S: Maintained
647T: git://git.berlios.de/gemini-board
647F: arch/arm/mm/*-fa* 648F: arch/arm/mm/*-fa*
648 649
649ARM/FOOTBRIDGE ARCHITECTURE 650ARM/FOOTBRIDGE ARCHITECTURE
@@ -692,6 +693,13 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/kristoffer/linux-hpc.git
692F: arch/arm/mach-sa1100/jornada720.c 693F: arch/arm/mach-sa1100/jornada720.c
693F: arch/arm/mach-sa1100/include/mach/jornada720.h 694F: arch/arm/mach-sa1100/include/mach/jornada720.h
694 695
696ARM/INCOME PXA270 SUPPORT
697M: Marek Vasut <marek.vasut@gmail.com>
698L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
699S: Maintained
700F: arch/arm/mach-pxa/income.c
701F: arch/arm/mach-pxa/include/mach-pxa/income.h
702
695ARM/INTEL IOP32X ARM ARCHITECTURE 703ARM/INTEL IOP32X ARM ARCHITECTURE
696M: Lennert Buytenhek <kernel@wantstofly.org> 704M: Lennert Buytenhek <kernel@wantstofly.org>
697M: Dan Williams <dan.j.williams@intel.com> 705M: Dan Williams <dan.j.williams@intel.com>
@@ -947,8 +955,9 @@ ARM/SHMOBILE ARM ARCHITECTURE
947M: Paul Mundt <lethal@linux-sh.org> 955M: Paul Mundt <lethal@linux-sh.org>
948M: Magnus Damm <magnus.damm@gmail.com> 956M: Magnus Damm <magnus.damm@gmail.com>
949L: linux-sh@vger.kernel.org 957L: linux-sh@vger.kernel.org
950T: git git://git.kernel.org/pub/scm/linux/kernel/git/lethal/genesis-2.6.git
951W: http://oss.renesas.com 958W: http://oss.renesas.com
959Q: http://patchwork.kernel.org/project/linux-sh/list/
960T: git git://git.kernel.org/pub/scm/linux/kernel/git/lethal/genesis-2.6.git
952S: Supported 961S: Supported
953F: arch/arm/mach-shmobile/ 962F: arch/arm/mach-shmobile/
954F: drivers/sh/ 963F: drivers/sh/
diff --git a/arch/alpha/include/asm/dma-mapping.h b/arch/alpha/include/asm/dma-mapping.h
index 1bce8169733c..4567aca6fdd6 100644
--- a/arch/alpha/include/asm/dma-mapping.h
+++ b/arch/alpha/include/asm/dma-mapping.h
@@ -41,9 +41,7 @@ static inline int dma_set_mask(struct device *dev, u64 mask)
41 41
42#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 42#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
43#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) 43#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
44#define dma_is_consistent(d, h) (1)
45 44
46#define dma_cache_sync(dev, va, size, dir) ((void)0) 45#define dma_cache_sync(dev, va, size, dir) ((void)0)
47#define dma_get_cache_alignment() L1_CACHE_BYTES
48 46
49#endif /* _ALPHA_DMA_MAPPING_H */ 47#endif /* _ALPHA_DMA_MAPPING_H */
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 232f0c758252..92951103255a 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -644,6 +644,7 @@ config ARCH_S3C2410
644 select ARCH_HAS_CPUFREQ 644 select ARCH_HAS_CPUFREQ
645 select HAVE_CLK 645 select HAVE_CLK
646 select ARCH_USES_GETTIMEOFFSET 646 select ARCH_USES_GETTIMEOFFSET
647 select HAVE_S3C2410_I2C
647 help 648 help
648 Samsung S3C2410X CPU based systems, such as the Simtec Electronics 649 Samsung S3C2410X CPU based systems, such as the Simtec Electronics
649 BAST (<http://www.simtec.co.uk/products/EB110ITX/>), the IPAQ 1940 or 650 BAST (<http://www.simtec.co.uk/products/EB110ITX/>), the IPAQ 1940 or
@@ -673,6 +674,8 @@ config ARCH_S3C64XX
673 select S3C_DEV_NAND 674 select S3C_DEV_NAND
674 select USB_ARCH_HAS_OHCI 675 select USB_ARCH_HAS_OHCI
675 select SAMSUNG_GPIOLIB_4BIT 676 select SAMSUNG_GPIOLIB_4BIT
677 select HAVE_S3C2410_I2C
678 select HAVE_S3C2410_WATCHDOG
676 help 679 help
677 Samsung S3C64XX series based systems 680 Samsung S3C64XX series based systems
678 681
@@ -681,7 +684,10 @@ config ARCH_S5P6440
681 select CPU_V6 684 select CPU_V6
682 select GENERIC_GPIO 685 select GENERIC_GPIO
683 select HAVE_CLK 686 select HAVE_CLK
687 select HAVE_S3C2410_WATCHDOG
684 select ARCH_USES_GETTIMEOFFSET 688 select ARCH_USES_GETTIMEOFFSET
689 select HAVE_S3C2410_I2C
690 select HAVE_S3C_RTC
685 help 691 help
686 Samsung S5P6440 CPU based systems 692 Samsung S5P6440 CPU based systems
687 693
@@ -691,6 +697,7 @@ config ARCH_S5P6442
691 select GENERIC_GPIO 697 select GENERIC_GPIO
692 select HAVE_CLK 698 select HAVE_CLK
693 select ARCH_USES_GETTIMEOFFSET 699 select ARCH_USES_GETTIMEOFFSET
700 select HAVE_S3C2410_WATCHDOG
694 help 701 help
695 Samsung S5P6442 CPU based systems 702 Samsung S5P6442 CPU based systems
696 703
@@ -701,6 +708,9 @@ config ARCH_S5PC100
701 select CPU_V7 708 select CPU_V7
702 select ARM_L1_CACHE_SHIFT_6 709 select ARM_L1_CACHE_SHIFT_6
703 select ARCH_USES_GETTIMEOFFSET 710 select ARCH_USES_GETTIMEOFFSET
711 select HAVE_S3C2410_I2C
712 select HAVE_S3C_RTC
713 select HAVE_S3C2410_WATCHDOG
704 help 714 help
705 Samsung S5PC100 series based systems 715 Samsung S5PC100 series based systems
706 716
@@ -711,9 +721,21 @@ config ARCH_S5PV210
711 select HAVE_CLK 721 select HAVE_CLK
712 select ARM_L1_CACHE_SHIFT_6 722 select ARM_L1_CACHE_SHIFT_6
713 select ARCH_USES_GETTIMEOFFSET 723 select ARCH_USES_GETTIMEOFFSET
724 select HAVE_S3C2410_I2C
725 select HAVE_S3C_RTC
726 select HAVE_S3C2410_WATCHDOG
714 help 727 help
715 Samsung S5PV210/S5PC110 series based systems 728 Samsung S5PV210/S5PC110 series based systems
716 729
730config ARCH_S5PV310
731 bool "Samsung S5PV310/S5PC210"
732 select CPU_V7
733 select GENERIC_GPIO
734 select HAVE_CLK
735 select GENERIC_CLOCKEVENTS
736 help
737 Samsung S5PV310 series based systems
738
717config ARCH_SHARK 739config ARCH_SHARK
718 bool "Shark" 740 bool "Shark"
719 select CPU_SA110 741 select CPU_SA110
@@ -915,6 +937,8 @@ source "arch/arm/mach-s5pc100/Kconfig"
915 937
916source "arch/arm/mach-s5pv210/Kconfig" 938source "arch/arm/mach-s5pv210/Kconfig"
917 939
940source "arch/arm/mach-s5pv310/Kconfig"
941
918source "arch/arm/mach-shmobile/Kconfig" 942source "arch/arm/mach-shmobile/Kconfig"
919 943
920source "arch/arm/plat-stmp3xxx/Kconfig" 944source "arch/arm/plat-stmp3xxx/Kconfig"
@@ -1040,6 +1064,18 @@ config PL310_ERRATA_588369
1040 is not correctly implemented in PL310 as clean lines are not 1064 is not correctly implemented in PL310 as clean lines are not
1041 invalidated as a result of these operations. Note that this errata 1065 invalidated as a result of these operations. Note that this errata
1042 uses Texas Instrument's secure monitor api. 1066 uses Texas Instrument's secure monitor api.
1067
1068config ARM_ERRATA_720789
1069 bool "ARM errata: TLBIASIDIS and TLBIMVAIS operations can broadcast a faulty ASID"
1070 depends on CPU_V7 && SMP
1071 help
1072 This option enables the workaround for the 720789 Cortex-A9 (prior to
1073 r2p0) erratum. A faulty ASID can be sent to the other CPUs for the
1074 broadcasted CP15 TLB maintenance operations TLBIASIDIS and TLBIMVAIS.
1075 As a consequence of this erratum, some TLB entries which should be
1076 invalidated are not, resulting in an incoherency in the system page
1077 tables. The workaround changes the TLB flushing routines to invalidate
1078 entries regardless of the ASID.
1043endmenu 1079endmenu
1044 1080
1045source "arch/arm/common/Kconfig" 1081source "arch/arm/common/Kconfig"
@@ -1108,11 +1144,11 @@ config SMP
1108 bool "Symmetric Multi-Processing (EXPERIMENTAL)" 1144 bool "Symmetric Multi-Processing (EXPERIMENTAL)"
1109 depends on EXPERIMENTAL && (REALVIEW_EB_ARM11MP || REALVIEW_EB_A9MP ||\ 1145 depends on EXPERIMENTAL && (REALVIEW_EB_ARM11MP || REALVIEW_EB_A9MP ||\
1110 MACH_REALVIEW_PB11MP || MACH_REALVIEW_PBX || ARCH_OMAP4 ||\ 1146 MACH_REALVIEW_PB11MP || MACH_REALVIEW_PBX || ARCH_OMAP4 ||\
1111 ARCH_U8500 || ARCH_VEXPRESS_CA9X4 || ARCH_TEGRA) 1147 ARCH_S5PV310 || ARCH_TEGRA || ARCH_U8500 || ARCH_VEXPRESS_CA9X4)
1112 depends on GENERIC_CLOCKEVENTS 1148 depends on GENERIC_CLOCKEVENTS
1113 select USE_GENERIC_SMP_HELPERS 1149 select USE_GENERIC_SMP_HELPERS
1114 select HAVE_ARM_SCU if (ARCH_REALVIEW || ARCH_OMAP4 || ARCH_U8500 || \ 1150 select HAVE_ARM_SCU if ARCH_REALVIEW || ARCH_OMAP4 || ARCH_S5PV310 ||\
1115 ARCH_VEXPRESS_CA9X4 || ARCH_TEGRA) 1151 ARCH_TEGRA || ARCH_U8500 || ARCH_VEXPRESS_CA9X4
1116 help 1152 help
1117 This enables support for systems with more than one CPU. If you have 1153 This enables support for systems with more than one CPU. If you have
1118 a system with only one CPU, like most personal computers, say N. If 1154 a system with only one CPU, like most personal computers, say N. If
@@ -1182,10 +1218,10 @@ config LOCAL_TIMERS
1182 bool "Use local timer interrupts" 1218 bool "Use local timer interrupts"
1183 depends on SMP && (REALVIEW_EB_ARM11MP || MACH_REALVIEW_PB11MP || \ 1219 depends on SMP && (REALVIEW_EB_ARM11MP || MACH_REALVIEW_PB11MP || \
1184 REALVIEW_EB_A9MP || MACH_REALVIEW_PBX || ARCH_OMAP4 || \ 1220 REALVIEW_EB_A9MP || MACH_REALVIEW_PBX || ARCH_OMAP4 || \
1185 ARCH_U8500 || ARCH_VEXPRESS_CA9X4 || ARCH_TEGRA) 1221 ARCH_S5PV310 || ARCH_TEGRA || ARCH_U8500 || ARCH_VEXPRESS_CA9X4)
1186 default y 1222 default y
1187 select HAVE_ARM_TWD if (ARCH_REALVIEW || ARCH_VEXPRESS || ARCH_OMAP4 || \\ 1223 select HAVE_ARM_TWD if ARCH_REALVIEW || ARCH_OMAP4 || ARCH_S5PV310 || \
1188 ARCH_U8500 || ARCH_TEGRA 1224 ARCH_TEGRA || ARCH_U8500 || ARCH_VEXPRESS
1189 help 1225 help
1190 Enable support for local timers on SMP platforms, rather then the 1226 Enable support for local timers on SMP platforms, rather then the
1191 legacy IPI broadcast method. Local timers allows the system 1227 legacy IPI broadcast method. Local timers allows the system
@@ -1196,7 +1232,8 @@ source kernel/Kconfig.preempt
1196 1232
1197config HZ 1233config HZ
1198 int 1234 int
1199 default 200 if ARCH_EBSA110 || ARCH_S3C2410 || ARCH_S5P6440 || ARCH_S5P6442 || ARCH_S5PV210 1235 default 200 if ARCH_EBSA110 || ARCH_S3C2410 || ARCH_S5P6440 || \
1236 ARCH_S5P6442 || ARCH_S5PV210 || ARCH_S5PV310
1200 default OMAP_32K_TIMER_HZ if ARCH_OMAP && OMAP_32K_TIMER 1237 default OMAP_32K_TIMER_HZ if ARCH_OMAP && OMAP_32K_TIMER
1201 default AT91_TIMER_HZ if ARCH_AT91 1238 default AT91_TIMER_HZ if ARCH_AT91
1202 default SHMOBILE_TIMER_HZ if ARCH_SHMOBILE 1239 default SHMOBILE_TIMER_HZ if ARCH_SHMOBILE
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index a8d4dca9da35..99b8200138d2 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -174,6 +174,7 @@ machine-$(CONFIG_ARCH_S5P6440) := s5p6440
174machine-$(CONFIG_ARCH_S5P6442) := s5p6442 174machine-$(CONFIG_ARCH_S5P6442) := s5p6442
175machine-$(CONFIG_ARCH_S5PC100) := s5pc100 175machine-$(CONFIG_ARCH_S5PC100) := s5pc100
176machine-$(CONFIG_ARCH_S5PV210) := s5pv210 176machine-$(CONFIG_ARCH_S5PV210) := s5pv210
177machine-$(CONFIG_ARCH_S5PV310) := s5pv310
177machine-$(CONFIG_ARCH_SA1100) := sa1100 178machine-$(CONFIG_ARCH_SA1100) := sa1100
178machine-$(CONFIG_ARCH_SHARK) := shark 179machine-$(CONFIG_ARCH_SHARK) := shark
179machine-$(CONFIG_ARCH_SHMOBILE) := shmobile 180machine-$(CONFIG_ARCH_SHMOBILE) := shmobile
diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index 7636c9b3f9a7..68775e33476c 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -33,7 +33,7 @@ ifeq ($(CONFIG_CPU_XSCALE),y)
33OBJS += head-xscale.o 33OBJS += head-xscale.o
34endif 34endif
35 35
36ifeq ($(CONFIG_PXA_SHARPSL),y) 36ifeq ($(CONFIG_PXA_SHARPSL_DETECT_MACH_ID),y)
37OBJS += head-sharpsl.o 37OBJS += head-sharpsl.o
38endif 38endif
39 39
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index abf4d65acf62..6af9907c3b5c 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -170,9 +170,8 @@ not_angel:
170 170
171 .text 171 .text
172 adr r0, LC0 172 adr r0, LC0
173 ARM( ldmia r0, {r1, r2, r3, r5, r6, r11, ip, sp}) 173 ldmia r0, {r1, r2, r3, r5, r6, r11, ip}
174 THUMB( ldmia r0, {r1, r2, r3, r5, r6, r11, ip} ) 174 ldr sp, [r0, #28]
175 THUMB( ldr sp, [r0, #32] )
176#ifdef CONFIG_AUTO_ZRELADDR 175#ifdef CONFIG_AUTO_ZRELADDR
177 @ determine final kernel image address 176 @ determine final kernel image address
178 and r4, pc, #0xf8000000 177 and r4, pc, #0xf8000000
diff --git a/arch/arm/common/it8152.c b/arch/arm/common/it8152.c
index 7974baacafce..6c0913562455 100644
--- a/arch/arm/common/it8152.c
+++ b/arch/arm/common/it8152.c
@@ -263,14 +263,6 @@ static int it8152_pci_platform_notify_remove(struct device *dev)
263 return 0; 263 return 0;
264} 264}
265 265
266int dma_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)
267{
268 dev_dbg(dev, "%s: dma_addr %08x, size %08x\n",
269 __func__, dma_addr, size);
270 return (dev->bus == &pci_bus_type) &&
271 ((dma_addr + size - PHYS_OFFSET) >= SZ_64M);
272}
273
274int __init it8152_pci_setup(int nr, struct pci_sys_data *sys) 266int __init it8152_pci_setup(int nr, struct pci_sys_data *sys)
275{ 267{
276 it8152_io.start = IT8152_IO_BASE + 0x12000; 268 it8152_io.start = IT8152_IO_BASE + 0x12000;
diff --git a/arch/arm/configs/s5pc110_defconfig b/arch/arm/configs/s5pc110_defconfig
deleted file mode 100644
index 22c2d147f793..000000000000
--- a/arch/arm/configs/s5pc110_defconfig
+++ /dev/null
@@ -1,66 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2CONFIG_SYSFS_DEPRECATED_V2=y
3CONFIG_BLK_DEV_INITRD=y
4CONFIG_KALLSYMS_ALL=y
5CONFIG_MODULES=y
6CONFIG_MODULE_UNLOAD=y
7# CONFIG_BLK_DEV_BSG is not set
8CONFIG_ARCH_S5PV210=y
9CONFIG_S3C_LOWLEVEL_UART_PORT=1
10CONFIG_MACH_SMDKC110=y
11CONFIG_VMSPLIT_2G=y
12CONFIG_PREEMPT=y
13CONFIG_AEABI=y
14CONFIG_CMDLINE="root=/dev/ram0 rw ramdisk=8192 initrd=0x20800000,8M console=ttySAC1,115200 init=/linuxrc"
15CONFIG_VFP=y
16CONFIG_NEON=y
17CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
18CONFIG_BLK_DEV_LOOP=y
19CONFIG_BLK_DEV_RAM=y
20CONFIG_BLK_DEV_RAM_SIZE=8192
21# CONFIG_MISC_DEVICES is not set
22CONFIG_SCSI=y
23CONFIG_BLK_DEV_SD=y
24CONFIG_CHR_DEV_SG=y
25CONFIG_INPUT_EVDEV=y
26# CONFIG_INPUT_KEYBOARD is not set
27# CONFIG_INPUT_MOUSE is not set
28CONFIG_INPUT_TOUCHSCREEN=y
29CONFIG_SERIAL_8250=y
30CONFIG_SERIAL_SAMSUNG=y
31CONFIG_SERIAL_SAMSUNG_CONSOLE=y
32CONFIG_HW_RANDOM=y
33# CONFIG_HWMON is not set
34# CONFIG_VGA_CONSOLE is not set
35# CONFIG_HID_SUPPORT is not set
36# CONFIG_USB_SUPPORT is not set
37CONFIG_EXT2_FS=y
38CONFIG_INOTIFY=y
39CONFIG_MSDOS_FS=y
40CONFIG_VFAT_FS=y
41CONFIG_TMPFS=y
42CONFIG_TMPFS_POSIX_ACL=y
43CONFIG_CRAMFS=y
44CONFIG_ROMFS_FS=y
45CONFIG_PARTITION_ADVANCED=y
46CONFIG_BSD_DISKLABEL=y
47CONFIG_SOLARIS_X86_PARTITION=y
48CONFIG_NLS_CODEPAGE_437=y
49CONFIG_NLS_ASCII=y
50CONFIG_NLS_ISO8859_1=y
51CONFIG_MAGIC_SYSRQ=y
52CONFIG_DEBUG_KERNEL=y
53# CONFIG_DEBUG_PREEMPT is not set
54CONFIG_DEBUG_RT_MUTEXES=y
55CONFIG_DEBUG_SPINLOCK=y
56CONFIG_DEBUG_MUTEXES=y
57CONFIG_DEBUG_SPINLOCK_SLEEP=y
58CONFIG_DEBUG_INFO=y
59# CONFIG_RCU_CPU_STALL_DETECTOR is not set
60CONFIG_SYSCTL_SYSCALL_CHECK=y
61CONFIG_DEBUG_USER=y
62CONFIG_DEBUG_ERRORS=y
63CONFIG_DEBUG_LL=y
64CONFIG_EARLY_PRINTK=y
65CONFIG_DEBUG_S3C_UART=1
66CONFIG_CRC_CCITT=y
diff --git a/arch/arm/configs/s5pv210_defconfig b/arch/arm/configs/s5pv210_defconfig
index 1753836d0055..0488a1eb4d7d 100644
--- a/arch/arm/configs/s5pv210_defconfig
+++ b/arch/arm/configs/s5pv210_defconfig
@@ -7,6 +7,11 @@ CONFIG_MODULE_UNLOAD=y
7# CONFIG_BLK_DEV_BSG is not set 7# CONFIG_BLK_DEV_BSG is not set
8CONFIG_ARCH_S5PV210=y 8CONFIG_ARCH_S5PV210=y
9CONFIG_S3C_LOWLEVEL_UART_PORT=1 9CONFIG_S3C_LOWLEVEL_UART_PORT=1
10CONFIG_S3C_DEV_FB=y
11CONFIG_S5PV210_SETUP_FB_24BPP=y
12CONFIG_MACH_AQUILA=y
13CONFIG_MACH_GONI=y
14CONFIG_MACH_SMDKC110=y
10CONFIG_MACH_SMDKV210=y 15CONFIG_MACH_SMDKV210=y
11CONFIG_VMSPLIT_2G=y 16CONFIG_VMSPLIT_2G=y
12CONFIG_PREEMPT=y 17CONFIG_PREEMPT=y
diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
index 66c160b8547f..9d6122096fbe 100644
--- a/arch/arm/include/asm/cache.h
+++ b/arch/arm/include/asm/cache.h
@@ -14,7 +14,7 @@
14 * cache before the transfer is done, causing old data to be seen by 14 * cache before the transfer is done, causing old data to be seen by
15 * the CPU. 15 * the CPU.
16 */ 16 */
17#define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES 17#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
18 18
19/* 19/*
20 * With EABI on ARMv5 and above we must have 64-bit aligned slab pointers. 20 * With EABI on ARMv5 and above we must have 64-bit aligned slab pointers.
diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
index 69ce0727edb5..c226fe10553e 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -144,16 +144,6 @@ static inline int dma_set_mask(struct device *dev, u64 dma_mask)
144 return 0; 144 return 0;
145} 145}
146 146
147static inline int dma_get_cache_alignment(void)
148{
149 return 32;
150}
151
152static inline int dma_is_consistent(struct device *dev, dma_addr_t handle)
153{
154 return !!arch_is_coherent();
155}
156
157/* 147/*
158 * DMA errors are defined by all-bits-set in the DMA address. 148 * DMA errors are defined by all-bits-set in the DMA address.
159 */ 149 */
@@ -298,7 +288,15 @@ extern void dmabounce_unregister_dev(struct device *);
298 * DMA access and 1 if the buffer needs to be bounced. 288 * DMA access and 1 if the buffer needs to be bounced.
299 * 289 *
300 */ 290 */
291#ifdef CONFIG_SA1111
301extern int dma_needs_bounce(struct device*, dma_addr_t, size_t); 292extern int dma_needs_bounce(struct device*, dma_addr_t, size_t);
293#else
294static inline int dma_needs_bounce(struct device *dev, dma_addr_t addr,
295 size_t size)
296{
297 return 0;
298}
299#endif
302 300
303/* 301/*
304 * The DMA API, implemented by dmabounce.c. See below for descriptions. 302 * The DMA API, implemented by dmabounce.c. See below for descriptions.
diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
index 6750b8e45a49..5747a8baa413 100644
--- a/arch/arm/include/asm/elf.h
+++ b/arch/arm/include/asm/elf.h
@@ -59,6 +59,8 @@ typedef struct user_fp elf_fpregset_t;
59 59
60#define R_ARM_THM_CALL 10 60#define R_ARM_THM_CALL 10
61#define R_ARM_THM_JUMP24 30 61#define R_ARM_THM_JUMP24 30
62#define R_ARM_THM_MOVW_ABS_NC 47
63#define R_ARM_THM_MOVT_ABS 48
62 64
63/* 65/*
64 * These are used to set parameters in the core dumps. 66 * These are used to set parameters in the core dumps.
diff --git a/arch/arm/include/asm/hardware/coresight.h b/arch/arm/include/asm/hardware/coresight.h
index f82b25d4f73e..212e47828c79 100644
--- a/arch/arm/include/asm/hardware/coresight.h
+++ b/arch/arm/include/asm/hardware/coresight.h
@@ -48,8 +48,6 @@ struct tracectx {
48/* CoreSight Component Registers */ 48/* CoreSight Component Registers */
49#define CSCR_CLASS 0xff4 49#define CSCR_CLASS 0xff4
50 50
51#define CSCR_PRSR 0x314
52
53#define UNLOCK_MAGIC 0xc5acce55 51#define UNLOCK_MAGIC 0xc5acce55
54 52
55/* ETM control register, "ETM Architecture", 3.3.1 */ 53/* ETM control register, "ETM Architecture", 3.3.1 */
@@ -132,6 +130,12 @@ struct tracectx {
132 ETMCTRL_BRANCH_OUTPUT | \ 130 ETMCTRL_BRANCH_OUTPUT | \
133 ETMCTRL_DO_CONTEXTID) 131 ETMCTRL_DO_CONTEXTID)
134 132
133/* ETM management registers, "ETM Architecture", 3.5.24 */
134#define ETMMR_OSLAR 0x300
135#define ETMMR_OSLSR 0x304
136#define ETMMR_OSSRR 0x308
137#define ETMMR_PDSR 0x314
138
135/* ETB registers, "CoreSight Components TRM", 9.3 */ 139/* ETB registers, "CoreSight Components TRM", 9.3 */
136#define ETBR_DEPTH 0x04 140#define ETBR_DEPTH 0x04
137#define ETBR_STATUS 0x0c 141#define ETBR_STATUS 0x0c
diff --git a/arch/arm/include/asm/hardware/scoop.h b/arch/arm/include/asm/hardware/scoop.h
index 46492a63a7c4..ebb3ceaa8fac 100644
--- a/arch/arm/include/asm/hardware/scoop.h
+++ b/arch/arm/include/asm/hardware/scoop.h
@@ -22,18 +22,23 @@
22#define SCOOP_GPWR 0x24 22#define SCOOP_GPWR 0x24
23#define SCOOP_GPRR 0x28 23#define SCOOP_GPRR 0x28
24 24
25#define SCOOP_GPCR_PA22 ( 1 << 12 ) 25#define SCOOP_CPR_OUT (1 << 7)
26#define SCOOP_GPCR_PA21 ( 1 << 11 ) 26#define SCOOP_CPR_SD_3V (1 << 2)
27#define SCOOP_GPCR_PA20 ( 1 << 10 ) 27#define SCOOP_CPR_CF_XV (1 << 1)
28#define SCOOP_GPCR_PA19 ( 1 << 9 ) 28#define SCOOP_CPR_CF_3V (1 << 0)
29#define SCOOP_GPCR_PA18 ( 1 << 8 ) 29
30#define SCOOP_GPCR_PA17 ( 1 << 7 ) 30#define SCOOP_GPCR_PA22 (1 << 12)
31#define SCOOP_GPCR_PA16 ( 1 << 6 ) 31#define SCOOP_GPCR_PA21 (1 << 11)
32#define SCOOP_GPCR_PA15 ( 1 << 5 ) 32#define SCOOP_GPCR_PA20 (1 << 10)
33#define SCOOP_GPCR_PA14 ( 1 << 4 ) 33#define SCOOP_GPCR_PA19 (1 << 9)
34#define SCOOP_GPCR_PA13 ( 1 << 3 ) 34#define SCOOP_GPCR_PA18 (1 << 8)
35#define SCOOP_GPCR_PA12 ( 1 << 2 ) 35#define SCOOP_GPCR_PA17 (1 << 7)
36#define SCOOP_GPCR_PA11 ( 1 << 1 ) 36#define SCOOP_GPCR_PA16 (1 << 6)
37#define SCOOP_GPCR_PA15 (1 << 5)
38#define SCOOP_GPCR_PA14 (1 << 4)
39#define SCOOP_GPCR_PA13 (1 << 3)
40#define SCOOP_GPCR_PA12 (1 << 2)
41#define SCOOP_GPCR_PA11 (1 << 1)
37 42
38struct scoop_config { 43struct scoop_config {
39 unsigned short io_out; 44 unsigned short io_out;
diff --git a/arch/arm/include/asm/tlbflush.h b/arch/arm/include/asm/tlbflush.h
index bd863d8608cd..33b546ae72d4 100644
--- a/arch/arm/include/asm/tlbflush.h
+++ b/arch/arm/include/asm/tlbflush.h
@@ -378,7 +378,11 @@ static inline void local_flush_tlb_mm(struct mm_struct *mm)
378 if (tlb_flag(TLB_V6_I_ASID)) 378 if (tlb_flag(TLB_V6_I_ASID))
379 asm("mcr p15, 0, %0, c8, c5, 2" : : "r" (asid) : "cc"); 379 asm("mcr p15, 0, %0, c8, c5, 2" : : "r" (asid) : "cc");
380 if (tlb_flag(TLB_V7_UIS_ASID)) 380 if (tlb_flag(TLB_V7_UIS_ASID))
381#ifdef CONFIG_ARM_ERRATA_720789
382 asm("mcr p15, 0, %0, c8, c3, 0" : : "r" (zero) : "cc");
383#else
381 asm("mcr p15, 0, %0, c8, c3, 2" : : "r" (asid) : "cc"); 384 asm("mcr p15, 0, %0, c8, c3, 2" : : "r" (asid) : "cc");
385#endif
382 386
383 if (tlb_flag(TLB_BTB)) { 387 if (tlb_flag(TLB_BTB)) {
384 /* flush the branch target cache */ 388 /* flush the branch target cache */
@@ -424,7 +428,11 @@ local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
424 if (tlb_flag(TLB_V6_I_PAGE)) 428 if (tlb_flag(TLB_V6_I_PAGE))
425 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (uaddr) : "cc"); 429 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (uaddr) : "cc");
426 if (tlb_flag(TLB_V7_UIS_PAGE)) 430 if (tlb_flag(TLB_V7_UIS_PAGE))
431#ifdef CONFIG_ARM_ERRATA_720789
432 asm("mcr p15, 0, %0, c8, c3, 3" : : "r" (uaddr & PAGE_MASK) : "cc");
433#else
427 asm("mcr p15, 0, %0, c8, c3, 1" : : "r" (uaddr) : "cc"); 434 asm("mcr p15, 0, %0, c8, c3, 1" : : "r" (uaddr) : "cc");
435#endif
428 436
429 if (tlb_flag(TLB_BTB)) { 437 if (tlb_flag(TLB_BTB)) {
430 /* flush the branch target cache */ 438 /* flush the branch target cache */
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 2c1db77d7848..f05a35a59694 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -92,75 +92,111 @@ ENDPROC(ret_from_fork)
92#define CALL(x) .long x 92#define CALL(x) .long x
93 93
94#ifdef CONFIG_FUNCTION_TRACER 94#ifdef CONFIG_FUNCTION_TRACER
95/*
96 * When compiling with -pg, gcc inserts a call to the mcount routine at the
97 * start of every function. In mcount, apart from the function's address (in
98 * lr), we need to get hold of the function's caller's address.
99 *
100 * Older GCCs (pre-4.4) inserted a call to a routine called mcount like this:
101 *
102 * bl mcount
103 *
104 * These versions have the limitation that in order for the mcount routine to
105 * be able to determine the function's caller's address, an APCS-style frame
106 * pointer (which is set up with something like the code below) is required.
107 *
108 * mov ip, sp
109 * push {fp, ip, lr, pc}
110 * sub fp, ip, #4
111 *
112 * With EABI, these frame pointers are not available unless -mapcs-frame is
113 * specified, and if building as Thumb-2, not even then.
114 *
115 * Newer GCCs (4.4+) solve this problem by introducing a new version of mcount,
116 * with call sites like:
117 *
118 * push {lr}
119 * bl __gnu_mcount_nc
120 *
121 * With these compilers, frame pointers are not necessary.
122 *
123 * mcount can be thought of as a function called in the middle of a subroutine
124 * call. As such, it needs to be transparent for both the caller and the
125 * callee: the original lr needs to be restored when leaving mcount, and no
126 * registers should be clobbered. (In the __gnu_mcount_nc implementation, we
127 * clobber the ip register. This is OK because the ARM calling convention
128 * allows it to be clobbered in subroutines and doesn't use it to hold
129 * parameters.)
130 */
95#ifdef CONFIG_DYNAMIC_FTRACE 131#ifdef CONFIG_DYNAMIC_FTRACE
96ENTRY(mcount) 132ENTRY(mcount)
97 stmdb sp!, {r0-r3, lr} 133 stmdb sp!, {r0-r3, lr}
98 mov r0, lr 134 mov r0, lr
99 sub r0, r0, #MCOUNT_INSN_SIZE 135 sub r0, r0, #MCOUNT_INSN_SIZE
100 136
101 .globl mcount_call 137 .globl mcount_call
102mcount_call: 138mcount_call:
103 bl ftrace_stub 139 bl ftrace_stub
104 ldr lr, [fp, #-4] @ restore lr 140 ldr lr, [fp, #-4] @ restore lr
105 ldmia sp!, {r0-r3, pc} 141 ldmia sp!, {r0-r3, pc}
106 142
107ENTRY(ftrace_caller) 143ENTRY(ftrace_caller)
108 stmdb sp!, {r0-r3, lr} 144 stmdb sp!, {r0-r3, lr}
109 ldr r1, [fp, #-4] 145 ldr r1, [fp, #-4]
110 mov r0, lr 146 mov r0, lr
111 sub r0, r0, #MCOUNT_INSN_SIZE 147 sub r0, r0, #MCOUNT_INSN_SIZE
112 148
113 .globl ftrace_call 149 .globl ftrace_call
114ftrace_call: 150ftrace_call:
115 bl ftrace_stub 151 bl ftrace_stub
116 ldr lr, [fp, #-4] @ restore lr 152 ldr lr, [fp, #-4] @ restore lr
117 ldmia sp!, {r0-r3, pc} 153 ldmia sp!, {r0-r3, pc}
118 154
119#else 155#else
120 156
121ENTRY(__gnu_mcount_nc) 157ENTRY(__gnu_mcount_nc)
122 stmdb sp!, {r0-r3, lr} 158 stmdb sp!, {r0-r3, lr}
123 ldr r0, =ftrace_trace_function 159 ldr r0, =ftrace_trace_function
124 ldr r2, [r0] 160 ldr r2, [r0]
125 adr r0, ftrace_stub 161 adr r0, ftrace_stub
126 cmp r0, r2 162 cmp r0, r2
127 bne gnu_trace 163 bne gnu_trace
128 ldmia sp!, {r0-r3, ip, lr} 164 ldmia sp!, {r0-r3, ip, lr}
129 mov pc, ip 165 mov pc, ip
130 166
131gnu_trace: 167gnu_trace:
132 ldr r1, [sp, #20] @ lr of instrumented routine 168 ldr r1, [sp, #20] @ lr of instrumented routine
133 mov r0, lr 169 mov r0, lr
134 sub r0, r0, #MCOUNT_INSN_SIZE 170 sub r0, r0, #MCOUNT_INSN_SIZE
135 mov lr, pc 171 mov lr, pc
136 mov pc, r2 172 mov pc, r2
137 ldmia sp!, {r0-r3, ip, lr} 173 ldmia sp!, {r0-r3, ip, lr}
138 mov pc, ip 174 mov pc, ip
139 175
140ENTRY(mcount) 176ENTRY(mcount)
141 stmdb sp!, {r0-r3, lr} 177 stmdb sp!, {r0-r3, lr}
142 ldr r0, =ftrace_trace_function 178 ldr r0, =ftrace_trace_function
143 ldr r2, [r0] 179 ldr r2, [r0]
144 adr r0, ftrace_stub 180 adr r0, ftrace_stub
145 cmp r0, r2 181 cmp r0, r2
146 bne trace 182 bne trace
147 ldr lr, [fp, #-4] @ restore lr 183 ldr lr, [fp, #-4] @ restore lr
148 ldmia sp!, {r0-r3, pc} 184 ldmia sp!, {r0-r3, pc}
149 185
150trace: 186trace:
151 ldr r1, [fp, #-4] @ lr of instrumented routine 187 ldr r1, [fp, #-4] @ lr of instrumented routine
152 mov r0, lr 188 mov r0, lr
153 sub r0, r0, #MCOUNT_INSN_SIZE 189 sub r0, r0, #MCOUNT_INSN_SIZE
154 mov lr, pc 190 mov lr, pc
155 mov pc, r2 191 mov pc, r2
156 ldr lr, [fp, #-4] @ restore lr 192 ldr lr, [fp, #-4] @ restore lr
157 ldmia sp!, {r0-r3, pc} 193 ldmia sp!, {r0-r3, pc}
158 194
159#endif /* CONFIG_DYNAMIC_FTRACE */ 195#endif /* CONFIG_DYNAMIC_FTRACE */
160 196
161 .globl ftrace_stub 197 .globl ftrace_stub
162ftrace_stub: 198ftrace_stub:
163 mov pc, lr 199 mov pc, lr
164 200
165#endif /* CONFIG_FUNCTION_TRACER */ 201#endif /* CONFIG_FUNCTION_TRACER */
166 202
diff --git a/arch/arm/kernel/etm.c b/arch/arm/kernel/etm.c
index 827753966301..56418f98cd01 100644
--- a/arch/arm/kernel/etm.c
+++ b/arch/arm/kernel/etm.c
@@ -543,7 +543,9 @@ static int __init etm_probe(struct amba_device *dev, struct amba_id *id)
543 t->etm_portsz = 1; 543 t->etm_portsz = 1;
544 544
545 etm_unlock(t); 545 etm_unlock(t);
546 ret = etm_readl(t, CSCR_PRSR); 546 (void)etm_readl(t, ETMMR_PDSR);
547 /* dummy first read */
548 (void)etm_readl(&tracer, ETMMR_OSSRR);
547 549
548 t->ncmppairs = etm_readl(t, ETMR_CONFCODE) & 0xf; 550 t->ncmppairs = etm_readl(t, ETMR_CONFCODE) & 0xf;
549 etm_writel(t, 0x440, ETMR_CTRL); 551 etm_writel(t, 0x440, ETMR_CTRL);
diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
index c628bdf6c430..6b4605893f1e 100644
--- a/arch/arm/kernel/module.c
+++ b/arch/arm/kernel/module.c
@@ -102,7 +102,9 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
102 unsigned long loc; 102 unsigned long loc;
103 Elf32_Sym *sym; 103 Elf32_Sym *sym;
104 s32 offset; 104 s32 offset;
105#ifdef CONFIG_THUMB2_KERNEL
105 u32 upper, lower, sign, j1, j2; 106 u32 upper, lower, sign, j1, j2;
107#endif
106 108
107 offset = ELF32_R_SYM(rel->r_info); 109 offset = ELF32_R_SYM(rel->r_info);
108 if (offset < 0 || offset > (symsec->sh_size / sizeof(Elf32_Sym))) { 110 if (offset < 0 || offset > (symsec->sh_size / sizeof(Elf32_Sym))) {
@@ -185,6 +187,7 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
185 (offset & 0x0fff); 187 (offset & 0x0fff);
186 break; 188 break;
187 189
190#ifdef CONFIG_THUMB2_KERNEL
188 case R_ARM_THM_CALL: 191 case R_ARM_THM_CALL:
189 case R_ARM_THM_JUMP24: 192 case R_ARM_THM_JUMP24:
190 upper = *(u16 *)loc; 193 upper = *(u16 *)loc;
@@ -233,9 +236,40 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
233 *(u16 *)(loc + 2) = (u16)((lower & 0xd000) | 236 *(u16 *)(loc + 2) = (u16)((lower & 0xd000) |
234 (j1 << 13) | (j2 << 11) | 237 (j1 << 13) | (j2 << 11) |
235 ((offset >> 1) & 0x07ff)); 238 ((offset >> 1) & 0x07ff));
239 break;
240
241 case R_ARM_THM_MOVW_ABS_NC:
242 case R_ARM_THM_MOVT_ABS:
236 upper = *(u16 *)loc; 243 upper = *(u16 *)loc;
237 lower = *(u16 *)(loc + 2); 244 lower = *(u16 *)(loc + 2);
245
246 /*
247 * MOVT/MOVW instructions encoding in Thumb-2:
248 *
249 * i = upper[10]
250 * imm4 = upper[3:0]
251 * imm3 = lower[14:12]
252 * imm8 = lower[7:0]
253 *
254 * imm16 = imm4:i:imm3:imm8
255 */
256 offset = ((upper & 0x000f) << 12) |
257 ((upper & 0x0400) << 1) |
258 ((lower & 0x7000) >> 4) | (lower & 0x00ff);
259 offset = (offset ^ 0x8000) - 0x8000;
260 offset += sym->st_value;
261
262 if (ELF32_R_TYPE(rel->r_info) == R_ARM_THM_MOVT_ABS)
263 offset >>= 16;
264
265 *(u16 *)loc = (u16)((upper & 0xfbf0) |
266 ((offset & 0xf000) >> 12) |
267 ((offset & 0x0800) >> 1));
268 *(u16 *)(loc + 2) = (u16)((lower & 0x8f00) |
269 ((offset & 0x0700) << 4) |
270 (offset & 0x00ff));
238 break; 271 break;
272#endif
239 273
240 default: 274 default:
241 printk(KERN_ERR "%s: unknown relocation: %u\n", 275 printk(KERN_ERR "%s: unknown relocation: %u\n",
diff --git a/arch/arm/mach-at91/board-cam60.c b/arch/arm/mach-at91/board-cam60.c
index 02138af631e7..44eb9f764938 100644
--- a/arch/arm/mach-at91/board-cam60.c
+++ b/arch/arm/mach-at91/board-cam60.c
@@ -75,7 +75,7 @@ static struct at91_usbh_data __initdata cam60_usbh_data = {
75 * SPI devices. 75 * SPI devices.
76 */ 76 */
77#if defined(CONFIG_MTD_DATAFLASH) 77#if defined(CONFIG_MTD_DATAFLASH)
78static struct mtd_partition __initdata cam60_spi_partitions[] = { 78static struct mtd_partition cam60_spi_partitions[] = {
79 { 79 {
80 .name = "BOOT1", 80 .name = "BOOT1",
81 .offset = 0, 81 .offset = 0,
@@ -98,14 +98,14 @@ static struct mtd_partition __initdata cam60_spi_partitions[] = {
98 }, 98 },
99}; 99};
100 100
101static struct flash_platform_data __initdata cam60_spi_flash_platform_data = { 101static struct flash_platform_data cam60_spi_flash_platform_data = {
102 .name = "spi_flash", 102 .name = "spi_flash",
103 .parts = cam60_spi_partitions, 103 .parts = cam60_spi_partitions,
104 .nr_parts = ARRAY_SIZE(cam60_spi_partitions) 104 .nr_parts = ARRAY_SIZE(cam60_spi_partitions)
105}; 105};
106#endif 106#endif
107 107
108static struct spi_board_info cam60_spi_devices[] = { 108static struct spi_board_info cam60_spi_devices[] __initdata = {
109#if defined(CONFIG_MTD_DATAFLASH) 109#if defined(CONFIG_MTD_DATAFLASH)
110 { /* DataFlash chip */ 110 { /* DataFlash chip */
111 .modalias = "mtd_dataflash", 111 .modalias = "mtd_dataflash",
diff --git a/arch/arm/mach-clps711x/include/mach/hardware.h b/arch/arm/mach-clps711x/include/mach/hardware.h
index b3ebe9e4871f..d0b7d870be9c 100644
--- a/arch/arm/mach-clps711x/include/mach/hardware.h
+++ b/arch/arm/mach-clps711x/include/mach/hardware.h
@@ -69,13 +69,6 @@
69#define SYSPLD_VIRT_BASE 0xfe000000 69#define SYSPLD_VIRT_BASE 0xfe000000
70#define SYSPLD_BASE SYSPLD_VIRT_BASE 70#define SYSPLD_BASE SYSPLD_VIRT_BASE
71 71
72#ifndef __ASSEMBLER__
73
74#define PCIO_BASE IO_BASE
75
76#endif
77
78
79#if defined (CONFIG_ARCH_AUTCPU12) 72#if defined (CONFIG_ARCH_AUTCPU12)
80 73
81#define CS89712_VIRT_BASE CLPS7111_VIRT_BASE 74#define CS89712_VIRT_BASE CLPS7111_VIRT_BASE
diff --git a/arch/arm/mach-gemini/Kconfig b/arch/arm/mach-gemini/Kconfig
index 515b75cf2e8b..6f066ee4bf24 100644
--- a/arch/arm/mach-gemini/Kconfig
+++ b/arch/arm/mach-gemini/Kconfig
@@ -2,6 +2,13 @@ if ARCH_GEMINI
2 2
3menu "Cortina Systems Gemini Implementations" 3menu "Cortina Systems Gemini Implementations"
4 4
5config MACH_NAS4220B
6 bool "Raidsonic NAS-4220-B"
7 select GEMINI_MEM_SWAP
8 help
9 Say Y here if you intend to run this kernel on a
10 Raidsonic NAS-4220-B.
11
5config MACH_RUT100 12config MACH_RUT100
6 bool "Teltonika RUT100" 13 bool "Teltonika RUT100"
7 select GEMINI_MEM_SWAP 14 select GEMINI_MEM_SWAP
@@ -9,6 +16,20 @@ config MACH_RUT100
9 Say Y here if you intend to run this kernel on a 16 Say Y here if you intend to run this kernel on a
10 Teltonika 3G Router RUT100. 17 Teltonika 3G Router RUT100.
11 18
19config MACH_WBD111
20 bool "Wiliboard WBD-111"
21 select GEMINI_MEM_SWAP
22 help
23 Say Y here if you intend to run this kernel on a
24 Wiliboard WBD-111.
25
26config MACH_WBD222
27 bool "Wiliboard WBD-222"
28 select GEMINI_MEM_SWAP
29 help
30 Say Y here if you intend to run this kernel on a
31 Wiliboard WBD-222.
32
12endmenu 33endmenu
13 34
14config GEMINI_MEM_SWAP 35config GEMINI_MEM_SWAP
diff --git a/arch/arm/mach-gemini/Makefile b/arch/arm/mach-gemini/Makefile
index 719505b81821..c5b24b95a76e 100644
--- a/arch/arm/mach-gemini/Makefile
+++ b/arch/arm/mach-gemini/Makefile
@@ -7,4 +7,7 @@
7obj-y := irq.o mm.o time.o devices.o gpio.o 7obj-y := irq.o mm.o time.o devices.o gpio.o
8 8
9# Board-specific support 9# Board-specific support
10obj-$(CONFIG_MACH_NAS4220B) += board-nas4220b.o
10obj-$(CONFIG_MACH_RUT100) += board-rut1xx.o 11obj-$(CONFIG_MACH_RUT100) += board-rut1xx.o
12obj-$(CONFIG_MACH_WBD111) += board-wbd111.o
13obj-$(CONFIG_MACH_WBD222) += board-wbd222.o
diff --git a/arch/arm/mach-gemini/board-nas4220b.c b/arch/arm/mach-gemini/board-nas4220b.c
new file mode 100644
index 000000000000..01f1d6daab44
--- /dev/null
+++ b/arch/arm/mach-gemini/board-nas4220b.c
@@ -0,0 +1,111 @@
1/*
2 * Support for Raidsonic NAS-4220-B
3 *
4 * Copyright (C) 2009 Janos Laube <janos.dev@gmail.com>
5 *
6 * based on rut1xx.c
7 * Copyright (C) 2008 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 */
14
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/platform_device.h>
18#include <linux/leds.h>
19#include <linux/input.h>
20#include <linux/gpio_keys.h>
21#include <linux/mdio-gpio.h>
22#include <linux/io.h>
23
24#include <asm/setup.h>
25#include <asm/mach-types.h>
26#include <asm/mach/arch.h>
27#include <asm/mach/time.h>
28
29#include <mach/hardware.h>
30#include <mach/global_reg.h>
31
32#include "common.h"
33
34static struct sys_timer ib4220b_timer = {
35 .init = gemini_timer_init,
36};
37
38static struct gpio_led ib4220b_leds[] = {
39 {
40 .name = "nas4220b:orange:hdd",
41 .default_trigger = "none",
42 .gpio = 60,
43 },
44 {
45 .name = "nas4220b:green:os",
46 .default_trigger = "heartbeat",
47 .gpio = 62,
48 },
49};
50
51static struct gpio_led_platform_data ib4220b_leds_data = {
52 .num_leds = ARRAY_SIZE(ib4220b_leds),
53 .leds = ib4220b_leds,
54};
55
56static struct platform_device ib4220b_led_device = {
57 .name = "leds-gpio",
58 .id = -1,
59 .dev = {
60 .platform_data = &ib4220b_leds_data,
61 },
62};
63
64static struct gpio_keys_button ib4220b_keys[] = {
65 {
66 .code = KEY_SETUP,
67 .gpio = 61,
68 .active_low = 1,
69 .desc = "Backup Button",
70 .type = EV_KEY,
71 },
72 {
73 .code = KEY_RESTART,
74 .gpio = 63,
75 .active_low = 1,
76 .desc = "Softreset Button",
77 .type = EV_KEY,
78 },
79};
80
81static struct gpio_keys_platform_data ib4220b_keys_data = {
82 .buttons = ib4220b_keys,
83 .nbuttons = ARRAY_SIZE(ib4220b_keys),
84};
85
86static struct platform_device ib4220b_key_device = {
87 .name = "gpio-keys",
88 .id = -1,
89 .dev = {
90 .platform_data = &ib4220b_keys_data,
91 },
92};
93
94static void __init ib4220b_init(void)
95{
96 gemini_gpio_init();
97 platform_register_uart();
98 platform_register_pflash(SZ_16M, NULL, 0);
99 platform_device_register(&ib4220b_led_device);
100 platform_device_register(&ib4220b_key_device);
101}
102
103MACHINE_START(NAS4220B, "Raidsonic NAS IB-4220-B")
104 .phys_io = 0x7fffc000,
105 .io_pg_offst = ((0xffffc000) >> 18) & 0xfffc,
106 .boot_params = 0x100,
107 .map_io = gemini_map_io,
108 .init_irq = gemini_init_irq,
109 .timer = &ib4220b_timer,
110 .init_machine = ib4220b_init,
111MACHINE_END
diff --git a/arch/arm/mach-gemini/board-wbd111.c b/arch/arm/mach-gemini/board-wbd111.c
new file mode 100644
index 000000000000..36538c15b3c4
--- /dev/null
+++ b/arch/arm/mach-gemini/board-wbd111.c
@@ -0,0 +1,143 @@
1/*
2 * Support for Wiliboard WBD-111
3 *
4 * Copyright (C) 2009 Imre Kaloz <kaloz@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/platform_device.h>
14#include <linux/leds.h>
15#include <linux/input.h>
16#include <linux/skbuff.h>
17#include <linux/gpio_keys.h>
18#include <linux/mdio-gpio.h>
19#include <linux/mtd/mtd.h>
20#include <linux/mtd/partitions.h>
21#include <asm/mach-types.h>
22#include <asm/mach/arch.h>
23#include <asm/mach/time.h>
24
25
26#include "common.h"
27
28static struct gpio_keys_button wbd111_keys[] = {
29 {
30 .code = KEY_SETUP,
31 .gpio = 5,
32 .active_low = 1,
33 .desc = "reset",
34 .type = EV_KEY,
35 },
36};
37
38static struct gpio_keys_platform_data wbd111_keys_data = {
39 .buttons = wbd111_keys,
40 .nbuttons = ARRAY_SIZE(wbd111_keys),
41};
42
43static struct platform_device wbd111_keys_device = {
44 .name = "gpio-keys",
45 .id = -1,
46 .dev = {
47 .platform_data = &wbd111_keys_data,
48 },
49};
50
51static struct gpio_led wbd111_leds[] = {
52 {
53 .name = "L3red",
54 .gpio = 1,
55 },
56 {
57 .name = "L4green",
58 .gpio = 2,
59 },
60 {
61 .name = "L4red",
62 .gpio = 3,
63 },
64 {
65 .name = "L3green",
66 .gpio = 5,
67 },
68};
69
70static struct gpio_led_platform_data wbd111_leds_data = {
71 .num_leds = ARRAY_SIZE(wbd111_leds),
72 .leds = wbd111_leds,
73};
74
75static struct platform_device wbd111_leds_device = {
76 .name = "leds-gpio",
77 .id = -1,
78 .dev = {
79 .platform_data = &wbd111_leds_data,
80 },
81};
82
83static struct sys_timer wbd111_timer = {
84 .init = gemini_timer_init,
85};
86
87#ifdef CONFIG_MTD_PARTITIONS
88static struct mtd_partition wbd111_partitions[] = {
89 {
90 .name = "RedBoot",
91 .offset = 0,
92 .size = 0x020000,
93 .mask_flags = MTD_WRITEABLE,
94 } , {
95 .name = "kernel",
96 .offset = 0x020000,
97 .size = 0x100000,
98 } , {
99 .name = "rootfs",
100 .offset = 0x120000,
101 .size = 0x6a0000,
102 } , {
103 .name = "VCTL",
104 .offset = 0x7c0000,
105 .size = 0x010000,
106 .mask_flags = MTD_WRITEABLE,
107 } , {
108 .name = "cfg",
109 .offset = 0x7d0000,
110 .size = 0x010000,
111 .mask_flags = MTD_WRITEABLE,
112 } , {
113 .name = "FIS",
114 .offset = 0x7e0000,
115 .size = 0x010000,
116 .mask_flags = MTD_WRITEABLE,
117 }
118};
119#define wbd111_num_partitions ARRAY_SIZE(wbd111_partitions)
120#else
121#define wbd111_partitions NULL
122#define wbd111_num_partitions 0
123#endif /* CONFIG_MTD_PARTITIONS */
124
125static void __init wbd111_init(void)
126{
127 gemini_gpio_init();
128 platform_register_uart();
129 platform_register_pflash(SZ_8M, wbd111_partitions,
130 wbd111_num_partitions);
131 platform_device_register(&wbd111_leds_device);
132 platform_device_register(&wbd111_keys_device);
133}
134
135MACHINE_START(WBD111, "Wiliboard WBD-111")
136 .phys_io = 0x7fffc000,
137 .io_pg_offst = ((0xffffc000) >> 18) & 0xfffc,
138 .boot_params = 0x100,
139 .map_io = gemini_map_io,
140 .init_irq = gemini_init_irq,
141 .timer = &wbd111_timer,
142 .init_machine = wbd111_init,
143MACHINE_END
diff --git a/arch/arm/mach-gemini/board-wbd222.c b/arch/arm/mach-gemini/board-wbd222.c
new file mode 100644
index 000000000000..ece8b4c65110
--- /dev/null
+++ b/arch/arm/mach-gemini/board-wbd222.c
@@ -0,0 +1,143 @@
1/*
2 * Support for Wiliboard WBD-222
3 *
4 * Copyright (C) 2009 Imre Kaloz <kaloz@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/platform_device.h>
14#include <linux/leds.h>
15#include <linux/input.h>
16#include <linux/skbuff.h>
17#include <linux/gpio_keys.h>
18#include <linux/mdio-gpio.h>
19#include <linux/mtd/mtd.h>
20#include <linux/mtd/partitions.h>
21#include <asm/mach-types.h>
22#include <asm/mach/arch.h>
23#include <asm/mach/time.h>
24
25
26#include "common.h"
27
28static struct gpio_keys_button wbd222_keys[] = {
29 {
30 .code = KEY_SETUP,
31 .gpio = 5,
32 .active_low = 1,
33 .desc = "reset",
34 .type = EV_KEY,
35 },
36};
37
38static struct gpio_keys_platform_data wbd222_keys_data = {
39 .buttons = wbd222_keys,
40 .nbuttons = ARRAY_SIZE(wbd222_keys),
41};
42
43static struct platform_device wbd222_keys_device = {
44 .name = "gpio-keys",
45 .id = -1,
46 .dev = {
47 .platform_data = &wbd222_keys_data,
48 },
49};
50
51static struct gpio_led wbd222_leds[] = {
52 {
53 .name = "L3red",
54 .gpio = 1,
55 },
56 {
57 .name = "L4green",
58 .gpio = 2,
59 },
60 {
61 .name = "L4red",
62 .gpio = 3,
63 },
64 {
65 .name = "L3green",
66 .gpio = 5,
67 },
68};
69
70static struct gpio_led_platform_data wbd222_leds_data = {
71 .num_leds = ARRAY_SIZE(wbd222_leds),
72 .leds = wbd222_leds,
73};
74
75static struct platform_device wbd222_leds_device = {
76 .name = "leds-gpio",
77 .id = -1,
78 .dev = {
79 .platform_data = &wbd222_leds_data,
80 },
81};
82
83static struct sys_timer wbd222_timer = {
84 .init = gemini_timer_init,
85};
86
87#ifdef CONFIG_MTD_PARTITIONS
88static struct mtd_partition wbd222_partitions[] = {
89 {
90 .name = "RedBoot",
91 .offset = 0,
92 .size = 0x020000,
93 .mask_flags = MTD_WRITEABLE,
94 } , {
95 .name = "kernel",
96 .offset = 0x020000,
97 .size = 0x100000,
98 } , {
99 .name = "rootfs",
100 .offset = 0x120000,
101 .size = 0x6a0000,
102 } , {
103 .name = "VCTL",
104 .offset = 0x7c0000,
105 .size = 0x010000,
106 .mask_flags = MTD_WRITEABLE,
107 } , {
108 .name = "cfg",
109 .offset = 0x7d0000,
110 .size = 0x010000,
111 .mask_flags = MTD_WRITEABLE,
112 } , {
113 .name = "FIS",
114 .offset = 0x7e0000,
115 .size = 0x010000,
116 .mask_flags = MTD_WRITEABLE,
117 }
118};
119#define wbd222_num_partitions ARRAY_SIZE(wbd222_partitions)
120#else
121#define wbd222_partitions NULL
122#define wbd222_num_partitions 0
123#endif /* CONFIG_MTD_PARTITIONS */
124
125static void __init wbd222_init(void)
126{
127 gemini_gpio_init();
128 platform_register_uart();
129 platform_register_pflash(SZ_8M, wbd222_partitions,
130 wbd222_num_partitions);
131 platform_device_register(&wbd222_leds_device);
132 platform_device_register(&wbd222_keys_device);
133}
134
135MACHINE_START(WBD222, "Wiliboard WBD-222")
136 .phys_io = 0x7fffc000,
137 .io_pg_offst = ((0xffffc000) >> 18) & 0xfffc,
138 .boot_params = 0x100,
139 .map_io = gemini_map_io,
140 .init_irq = gemini_init_irq,
141 .timer = &wbd222_timer,
142 .init_machine = wbd222_init,
143MACHINE_END
diff --git a/arch/arm/mach-h720x/include/mach/hardware.h b/arch/arm/mach-h720x/include/mach/hardware.h
index 6c19156e2a42..c55a52c6541d 100644
--- a/arch/arm/mach-h720x/include/mach/hardware.h
+++ b/arch/arm/mach-h720x/include/mach/hardware.h
@@ -182,8 +182,6 @@
182#define SERIAL_ENABLE_EN (1<<0) 182#define SERIAL_ENABLE_EN (1<<0)
183 183
184/* General defines to pacify gcc */ 184/* General defines to pacify gcc */
185#define PCIO_BASE (0) /* for inb, outb and friends */
186#define PCIO_VIRT PCIO_BASE
187 185
188#define __ASM_ARCH_HARDWARE_INCMACH_H 186#define __ASM_ARCH_HARDWARE_INCMACH_H
189#include "boards.h" 187#include "boards.h"
diff --git a/arch/arm/mach-imx/mach-pca100.c b/arch/arm/mach-imx/mach-pca100.c
index 6c92deaf468f..a389d1148f18 100644
--- a/arch/arm/mach-imx/mach-pca100.c
+++ b/arch/arm/mach-imx/mach-pca100.c
@@ -408,7 +408,7 @@ static void __init pca100_init(void)
408 mxc_gpio_mode(GPIO_PORTD | 27 | GPIO_GPIO | GPIO_IN); 408 mxc_gpio_mode(GPIO_PORTD | 27 | GPIO_GPIO | GPIO_IN);
409 spi_register_board_info(pca100_spi_board_info, 409 spi_register_board_info(pca100_spi_board_info,
410 ARRAY_SIZE(pca100_spi_board_info)); 410 ARRAY_SIZE(pca100_spi_board_info));
411 imx27_add_spi_imx0(&pca100_spi_0_data); 411 imx27_add_spi_imx0(&pca100_spi0_data);
412#endif 412#endif
413 413
414 gpio_request(OTG_PHY_CS_GPIO, "usb-otg-cs"); 414 gpio_request(OTG_PHY_CS_GPIO, "usb-otg-cs");
diff --git a/arch/arm/mach-integrator/include/mach/hardware.h b/arch/arm/mach-integrator/include/mach/hardware.h
index 8e26360ce9a3..57f51ba11251 100644
--- a/arch/arm/mach-integrator/include/mach/hardware.h
+++ b/arch/arm/mach-integrator/include/mach/hardware.h
@@ -32,7 +32,6 @@
32#define IO_SIZE 0x0B000000 // How much? 32#define IO_SIZE 0x0B000000 // How much?
33#define IO_START INTEGRATOR_HDR_BASE // PA of IO 33#define IO_START INTEGRATOR_HDR_BASE // PA of IO
34 34
35#define PCIO_BASE PCI_IO_VADDR
36#define PCIMEM_BASE PCI_MEMORY_VADDR 35#define PCIMEM_BASE PCI_MEMORY_VADDR
37 36
38#define pcibios_assign_all_busses() 1 37#define pcibios_assign_all_busses() 1
diff --git a/arch/arm/mach-ixp23xx/include/mach/hardware.h b/arch/arm/mach-ixp23xx/include/mach/hardware.h
index c3192009a886..57b508bfe280 100644
--- a/arch/arm/mach-ixp23xx/include/mach/hardware.h
+++ b/arch/arm/mach-ixp23xx/include/mach/hardware.h
@@ -15,7 +15,6 @@
15#define __ASM_ARCH_HARDWARE_H 15#define __ASM_ARCH_HARDWARE_H
16 16
17/* PCI IO info */ 17/* PCI IO info */
18#define PCIO_BASE IXP23XX_PCI_IO_VIRT
19#define PCIBIOS_MIN_IO 0x00000000 18#define PCIBIOS_MIN_IO 0x00000000
20#define PCIBIOS_MIN_MEM 0xe0000000 19#define PCIBIOS_MIN_MEM 0xe0000000
21 20
diff --git a/arch/arm/mach-ixp4xx/Kconfig b/arch/arm/mach-ixp4xx/Kconfig
index 9e5070da17ae..6f991c5ae863 100644
--- a/arch/arm/mach-ixp4xx/Kconfig
+++ b/arch/arm/mach-ixp4xx/Kconfig
@@ -140,6 +140,14 @@ config MACH_FSG
140 FSG-3 device. For more information on this platform, 140 FSG-3 device. For more information on this platform,
141 see http://www.nslu2-linux.org/wiki/FSG3/HomePage 141 see http://www.nslu2-linux.org/wiki/FSG3/HomePage
142 142
143config MACH_ARCOM_VULCAN
144 bool
145 prompt "Arcom/Eurotech Vulcan"
146 select PCI
147 help
148 Say 'Y' here if you want your kernel to support Arcom's
149 Vulcan board.
150
143# 151#
144# Certain registers and IRQs are only enabled if supporting IXP465 CPUs 152# Certain registers and IRQs are only enabled if supporting IXP465 CPUs
145# 153#
diff --git a/arch/arm/mach-ixp4xx/Makefile b/arch/arm/mach-ixp4xx/Makefile
index 47d1f60d23fa..d807fc367dd3 100644
--- a/arch/arm/mach-ixp4xx/Makefile
+++ b/arch/arm/mach-ixp4xx/Makefile
@@ -16,6 +16,7 @@ obj-pci-$(CONFIG_MACH_DSMG600) += dsmg600-pci.o
16obj-pci-$(CONFIG_MACH_GATEWAY7001) += gateway7001-pci.o 16obj-pci-$(CONFIG_MACH_GATEWAY7001) += gateway7001-pci.o
17obj-pci-$(CONFIG_MACH_WG302V2) += wg302v2-pci.o 17obj-pci-$(CONFIG_MACH_WG302V2) += wg302v2-pci.o
18obj-pci-$(CONFIG_MACH_FSG) += fsg-pci.o 18obj-pci-$(CONFIG_MACH_FSG) += fsg-pci.o
19obj-pci-$(CONFIG_MACH_ARCOM_VULCAN) += vulcan-pci.o
19 20
20obj-y += common.o 21obj-y += common.o
21 22
@@ -31,6 +32,7 @@ obj-$(CONFIG_MACH_GATEWAY7001) += gateway7001-setup.o
31obj-$(CONFIG_MACH_WG302V2) += wg302v2-setup.o 32obj-$(CONFIG_MACH_WG302V2) += wg302v2-setup.o
32obj-$(CONFIG_MACH_FSG) += fsg-setup.o 33obj-$(CONFIG_MACH_FSG) += fsg-setup.o
33obj-$(CONFIG_MACH_GORAMO_MLR) += goramo_mlr.o 34obj-$(CONFIG_MACH_GORAMO_MLR) += goramo_mlr.o
35obj-$(CONFIG_MACH_ARCOM_VULCAN) += vulcan-setup.o
34 36
35obj-$(CONFIG_PCI) += $(obj-pci-$(CONFIG_PCI)) common-pci.o 37obj-$(CONFIG_PCI) += $(obj-pci-$(CONFIG_PCI)) common-pci.o
36obj-$(CONFIG_IXP4XX_QMGR) += ixp4xx_qmgr.o 38obj-$(CONFIG_IXP4XX_QMGR) += ixp4xx_qmgr.o
diff --git a/arch/arm/mach-ixp4xx/include/mach/debug-macro.S b/arch/arm/mach-ixp4xx/include/mach/debug-macro.S
index 893873eb2a0d..3fc66d6d00a0 100644
--- a/arch/arm/mach-ixp4xx/include/mach/debug-macro.S
+++ b/arch/arm/mach-ixp4xx/include/mach/debug-macro.S
@@ -16,8 +16,10 @@
16 moveq \rx, #0xc8000000 16 moveq \rx, #0xc8000000
17 movne \rx, #0xff000000 17 movne \rx, #0xff000000
18 orrne \rx, \rx, #0x00b00000 18 orrne \rx, \rx, #0x00b00000
19#ifdef __ARMEB__
19 add \rx,\rx,#3 @ Uart regs are at off set of 3 if 20 add \rx,\rx,#3 @ Uart regs are at off set of 3 if
20 @ byte writes used - Big Endian. 21 @ byte writes used - Big Endian.
22#endif
21 .endm 23 .endm
22 24
23#define UART_SHIFT 2 25#define UART_SHIFT 2
diff --git a/arch/arm/mach-ixp4xx/include/mach/io.h b/arch/arm/mach-ixp4xx/include/mach/io.h
index 6ea7e2fb2701..de274a1f19d7 100644
--- a/arch/arm/mach-ixp4xx/include/mach/io.h
+++ b/arch/arm/mach-ixp4xx/include/mach/io.h
@@ -353,7 +353,7 @@ static inline unsigned int ioread8(const void __iomem *addr)
353 return (unsigned int)inb(port & PIO_MASK); 353 return (unsigned int)inb(port & PIO_MASK);
354 else 354 else
355#ifndef CONFIG_IXP4XX_INDIRECT_PCI 355#ifndef CONFIG_IXP4XX_INDIRECT_PCI
356 return (unsigned int)__raw_readb(port); 356 return (unsigned int)__raw_readb(addr);
357#else 357#else
358 return (unsigned int)__indirect_readb(addr); 358 return (unsigned int)__indirect_readb(addr);
359#endif 359#endif
@@ -381,7 +381,7 @@ static inline unsigned int ioread16(const void __iomem *addr)
381 return (unsigned int)inw(port & PIO_MASK); 381 return (unsigned int)inw(port & PIO_MASK);
382 else 382 else
383#ifndef CONFIG_IXP4XX_INDIRECT_PCI 383#ifndef CONFIG_IXP4XX_INDIRECT_PCI
384 return le16_to_cpu(__raw_readw((u32)port)); 384 return le16_to_cpu((__force __le16)__raw_readw(addr));
385#else 385#else
386 return (unsigned int)__indirect_readw(addr); 386 return (unsigned int)__indirect_readw(addr);
387#endif 387#endif
@@ -440,7 +440,7 @@ static inline void iowrite8(u8 value, void __iomem *addr)
440 outb(value, port & PIO_MASK); 440 outb(value, port & PIO_MASK);
441 else 441 else
442#ifndef CONFIG_IXP4XX_INDIRECT_PCI 442#ifndef CONFIG_IXP4XX_INDIRECT_PCI
443 __raw_writeb(value, port); 443 __raw_writeb(value, addr);
444#else 444#else
445 __indirect_writeb(value, addr); 445 __indirect_writeb(value, addr);
446#endif 446#endif
diff --git a/arch/arm/mach-ixp4xx/vulcan-pci.c b/arch/arm/mach-ixp4xx/vulcan-pci.c
new file mode 100644
index 000000000000..f3111c6840ef
--- /dev/null
+++ b/arch/arm/mach-ixp4xx/vulcan-pci.c
@@ -0,0 +1,73 @@
1/*
2 * arch/arch/mach-ixp4xx/vulcan-pci.c
3 *
4 * Vulcan board-level PCI initialization
5 *
6 * Copyright (C) 2010 Marc Zyngier <maz@misterjones.org>
7 *
8 * based on ixdp425-pci.c:
9 * Copyright (C) 2002 Intel Corporation.
10 * Copyright (C) 2003-2004 MontaVista Software, Inc.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 */
17
18#include <linux/pci.h>
19#include <linux/init.h>
20#include <linux/irq.h>
21#include <asm/mach/pci.h>
22#include <asm/mach-types.h>
23
24/* PCI controller GPIO to IRQ pin mappings */
25#define INTA 2
26#define INTB 3
27
28void __init vulcan_pci_preinit(void)
29{
30#ifndef CONFIG_IXP4XX_INDIRECT_PCI
31 /*
32 * Cardbus bridge wants way more than the SoC can actually offer,
33 * and leaves the whole PCI bus in a mess. Artificially limit it
34 * to 8MB per region. Of course indirect mode doesn't have this
35 * limitation...
36 */
37 pci_cardbus_mem_size = SZ_8M;
38 pr_info("Vulcan PCI: limiting CardBus memory size to %dMB\n",
39 (int)(pci_cardbus_mem_size >> 20));
40#endif
41 set_irq_type(IXP4XX_GPIO_IRQ(INTA), IRQ_TYPE_LEVEL_LOW);
42 set_irq_type(IXP4XX_GPIO_IRQ(INTB), IRQ_TYPE_LEVEL_LOW);
43 ixp4xx_pci_preinit();
44}
45
46static int __init vulcan_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
47{
48 if (slot == 1)
49 return IXP4XX_GPIO_IRQ(INTA);
50
51 if (slot == 2)
52 return IXP4XX_GPIO_IRQ(INTB);
53
54 return -1;
55}
56
57struct hw_pci vulcan_pci __initdata = {
58 .nr_controllers = 1,
59 .preinit = vulcan_pci_preinit,
60 .swizzle = pci_std_swizzle,
61 .setup = ixp4xx_setup,
62 .scan = ixp4xx_scan_bus,
63 .map_irq = vulcan_map_irq,
64};
65
66int __init vulcan_pci_init(void)
67{
68 if (machine_is_arcom_vulcan())
69 pci_common_init(&vulcan_pci);
70 return 0;
71}
72
73subsys_initcall(vulcan_pci_init);
diff --git a/arch/arm/mach-ixp4xx/vulcan-setup.c b/arch/arm/mach-ixp4xx/vulcan-setup.c
new file mode 100644
index 000000000000..465cc5cce687
--- /dev/null
+++ b/arch/arm/mach-ixp4xx/vulcan-setup.c
@@ -0,0 +1,246 @@
1/*
2 * arch/arm/mach-ixp4xx/vulcan-setup.c
3 *
4 * Arcom/Eurotech Vulcan board-setup
5 *
6 * Copyright (C) 2010 Marc Zyngier <maz@misterjones.org>
7 *
8 * based on fsg-setup.c:
9 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
10 */
11
12#include <linux/if_ether.h>
13#include <linux/irq.h>
14#include <linux/serial.h>
15#include <linux/serial_8250.h>
16#include <linux/io.h>
17#include <linux/w1-gpio.h>
18#include <linux/mtd/plat-ram.h>
19#include <asm/mach-types.h>
20#include <asm/mach/arch.h>
21#include <asm/mach/flash.h>
22
23static struct flash_platform_data vulcan_flash_data = {
24 .map_name = "cfi_probe",
25 .width = 2,
26};
27
28static struct resource vulcan_flash_resource = {
29 .flags = IORESOURCE_MEM,
30};
31
32static struct platform_device vulcan_flash = {
33 .name = "IXP4XX-Flash",
34 .id = 0,
35 .dev = {
36 .platform_data = &vulcan_flash_data,
37 },
38 .resource = &vulcan_flash_resource,
39 .num_resources = 1,
40};
41
42static struct platdata_mtd_ram vulcan_sram_data = {
43 .mapname = "Vulcan SRAM",
44 .bankwidth = 1,
45};
46
47static struct resource vulcan_sram_resource = {
48 .flags = IORESOURCE_MEM,
49};
50
51static struct platform_device vulcan_sram = {
52 .name = "mtd-ram",
53 .id = 0,
54 .dev = {
55 .platform_data = &vulcan_sram_data,
56 },
57 .resource = &vulcan_sram_resource,
58 .num_resources = 1,
59};
60
61static struct resource vulcan_uart_resources[] = {
62 [0] = {
63 .start = IXP4XX_UART1_BASE_PHYS,
64 .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
65 .flags = IORESOURCE_MEM,
66 },
67 [1] = {
68 .start = IXP4XX_UART2_BASE_PHYS,
69 .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
70 .flags = IORESOURCE_MEM,
71 },
72 [2] = {
73 .flags = IORESOURCE_MEM,
74 },
75};
76
77static struct plat_serial8250_port vulcan_uart_data[] = {
78 [0] = {
79 .mapbase = IXP4XX_UART1_BASE_PHYS,
80 .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
81 .irq = IRQ_IXP4XX_UART1,
82 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
83 .iotype = UPIO_MEM,
84 .regshift = 2,
85 .uartclk = IXP4XX_UART_XTAL,
86 },
87 [1] = {
88 .mapbase = IXP4XX_UART2_BASE_PHYS,
89 .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
90 .irq = IRQ_IXP4XX_UART2,
91 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
92 .iotype = UPIO_MEM,
93 .regshift = 2,
94 .uartclk = IXP4XX_UART_XTAL,
95 },
96 [2] = {
97 .irq = IXP4XX_GPIO_IRQ(4),
98 .irqflags = IRQF_TRIGGER_LOW,
99 .flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
100 .iotype = UPIO_MEM,
101 .uartclk = 1843200,
102 },
103 [3] = {
104 .irq = IXP4XX_GPIO_IRQ(4),
105 .irqflags = IRQF_TRIGGER_LOW,
106 .flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
107 .iotype = UPIO_MEM,
108 .uartclk = 1843200,
109 },
110 { }
111};
112
113static struct platform_device vulcan_uart = {
114 .name = "serial8250",
115 .id = PLAT8250_DEV_PLATFORM,
116 .dev = {
117 .platform_data = vulcan_uart_data,
118 },
119 .resource = vulcan_uart_resources,
120 .num_resources = ARRAY_SIZE(vulcan_uart_resources),
121};
122
123static struct eth_plat_info vulcan_plat_eth[] = {
124 [0] = {
125 .phy = 0,
126 .rxq = 3,
127 .txreadyq = 20,
128 },
129 [1] = {
130 .phy = 1,
131 .rxq = 4,
132 .txreadyq = 21,
133 },
134};
135
136static struct platform_device vulcan_eth[] = {
137 [0] = {
138 .name = "ixp4xx_eth",
139 .id = IXP4XX_ETH_NPEB,
140 .dev = {
141 .platform_data = &vulcan_plat_eth[0],
142 },
143 },
144 [1] = {
145 .name = "ixp4xx_eth",
146 .id = IXP4XX_ETH_NPEC,
147 .dev = {
148 .platform_data = &vulcan_plat_eth[1],
149 },
150 },
151};
152
153static struct resource vulcan_max6369_resource = {
154 .flags = IORESOURCE_MEM,
155};
156
157static struct platform_device vulcan_max6369 = {
158 .name = "max6369_wdt",
159 .id = -1,
160 .resource = &vulcan_max6369_resource,
161 .num_resources = 1,
162};
163
164static struct w1_gpio_platform_data vulcan_w1_gpio_pdata = {
165 .pin = 14,
166};
167
168static struct platform_device vulcan_w1_gpio = {
169 .name = "w1-gpio",
170 .id = 0,
171 .dev = {
172 .platform_data = &vulcan_w1_gpio_pdata,
173 },
174};
175
176static struct platform_device *vulcan_devices[] __initdata = {
177 &vulcan_uart,
178 &vulcan_flash,
179 &vulcan_sram,
180 &vulcan_max6369,
181 &vulcan_eth[0],
182 &vulcan_eth[1],
183 &vulcan_w1_gpio,
184};
185
186static void __init vulcan_init(void)
187{
188 ixp4xx_sys_init();
189
190 /* Flash is spread over both CS0 and CS1 */
191 vulcan_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
192 vulcan_flash_resource.end = IXP4XX_EXP_BUS_BASE(0) + SZ_32M - 1;
193 *IXP4XX_EXP_CS0 = IXP4XX_EXP_BUS_CS_EN |
194 IXP4XX_EXP_BUS_STROBE_T(3) |
195 IXP4XX_EXP_BUS_SIZE(0xF) |
196 IXP4XX_EXP_BUS_BYTE_RD16 |
197 IXP4XX_EXP_BUS_WR_EN;
198 *IXP4XX_EXP_CS1 = *IXP4XX_EXP_CS0;
199
200 /* SRAM on CS2, (256kB, 8bit, writable) */
201 vulcan_sram_resource.start = IXP4XX_EXP_BUS_BASE(2);
202 vulcan_sram_resource.end = IXP4XX_EXP_BUS_BASE(2) + SZ_256K - 1;
203 *IXP4XX_EXP_CS2 = IXP4XX_EXP_BUS_CS_EN |
204 IXP4XX_EXP_BUS_STROBE_T(1) |
205 IXP4XX_EXP_BUS_HOLD_T(2) |
206 IXP4XX_EXP_BUS_SIZE(9) |
207 IXP4XX_EXP_BUS_SPLT_EN |
208 IXP4XX_EXP_BUS_WR_EN |
209 IXP4XX_EXP_BUS_BYTE_EN;
210
211 /* XR16L2551 on CS3 (Moto style, 512 bytes, 8bits, writable) */
212 vulcan_uart_resources[2].start = IXP4XX_EXP_BUS_BASE(3);
213 vulcan_uart_resources[2].end = IXP4XX_EXP_BUS_BASE(3) + 16 - 1;
214 vulcan_uart_data[2].mapbase = vulcan_uart_resources[2].start;
215 vulcan_uart_data[3].mapbase = vulcan_uart_data[2].mapbase + 8;
216 *IXP4XX_EXP_CS3 = IXP4XX_EXP_BUS_CS_EN |
217 IXP4XX_EXP_BUS_STROBE_T(3) |
218 IXP4XX_EXP_BUS_CYCLES(IXP4XX_EXP_BUS_CYCLES_MOTOROLA)|
219 IXP4XX_EXP_BUS_WR_EN |
220 IXP4XX_EXP_BUS_BYTE_EN;
221
222 /* GPIOS on CS4 (512 bytes, 8bits, writable) */
223 *IXP4XX_EXP_CS4 = IXP4XX_EXP_BUS_CS_EN |
224 IXP4XX_EXP_BUS_WR_EN |
225 IXP4XX_EXP_BUS_BYTE_EN;
226
227 /* max6369 on CS5 (512 bytes, 8bits, writable) */
228 vulcan_max6369_resource.start = IXP4XX_EXP_BUS_BASE(5);
229 vulcan_max6369_resource.end = IXP4XX_EXP_BUS_BASE(5);
230 *IXP4XX_EXP_CS5 = IXP4XX_EXP_BUS_CS_EN |
231 IXP4XX_EXP_BUS_WR_EN |
232 IXP4XX_EXP_BUS_BYTE_EN;
233
234 platform_add_devices(vulcan_devices, ARRAY_SIZE(vulcan_devices));
235}
236
237MACHINE_START(ARCOM_VULCAN, "Arcom/Eurotech Vulcan")
238 /* Maintainer: Marc Zyngier <maz@misterjones.org> */
239 .phys_io = IXP4XX_PERIPHERAL_BASE_PHYS,
240 .io_pg_offst = ((IXP4XX_PERIPHERAL_BASE_VIRT) >> 18) & 0xfffc,
241 .map_io = ixp4xx_map_io,
242 .init_irq = ixp4xx_init_irq,
243 .timer = &ixp4xx_timer,
244 .boot_params = 0x0100,
245 .init_machine = vulcan_init,
246MACHINE_END
diff --git a/arch/arm/mach-mmp/aspenite.c b/arch/arm/mach-mmp/aspenite.c
index 244655d323ea..0629394a5fb9 100644
--- a/arch/arm/mach-mmp/aspenite.c
+++ b/arch/arm/mach-mmp/aspenite.c
@@ -150,9 +150,8 @@ static void __init common_init(void)
150 150
151MACHINE_START(ASPENITE, "PXA168-based Aspenite Development Platform") 151MACHINE_START(ASPENITE, "PXA168-based Aspenite Development Platform")
152 .phys_io = APB_PHYS_BASE, 152 .phys_io = APB_PHYS_BASE,
153 .boot_params = 0x00000100,
154 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc, 153 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc,
155 .map_io = pxa_map_io, 154 .map_io = mmp_map_io,
156 .init_irq = pxa168_init_irq, 155 .init_irq = pxa168_init_irq,
157 .timer = &pxa168_timer, 156 .timer = &pxa168_timer,
158 .init_machine = common_init, 157 .init_machine = common_init,
@@ -160,9 +159,8 @@ MACHINE_END
160 159
161MACHINE_START(ZYLONITE2, "PXA168-based Zylonite2 Development Platform") 160MACHINE_START(ZYLONITE2, "PXA168-based Zylonite2 Development Platform")
162 .phys_io = APB_PHYS_BASE, 161 .phys_io = APB_PHYS_BASE,
163 .boot_params = 0x00000100,
164 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc, 162 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc,
165 .map_io = pxa_map_io, 163 .map_io = mmp_map_io,
166 .init_irq = pxa168_init_irq, 164 .init_irq = pxa168_init_irq,
167 .timer = &pxa168_timer, 165 .timer = &pxa168_timer,
168 .init_machine = common_init, 166 .init_machine = common_init,
diff --git a/arch/arm/mach-mmp/avengers_lite.c b/arch/arm/mach-mmp/avengers_lite.c
index 8c3fa5d14f4b..69bcba11f53f 100644
--- a/arch/arm/mach-mmp/avengers_lite.c
+++ b/arch/arm/mach-mmp/avengers_lite.c
@@ -42,9 +42,8 @@ static void __init avengers_lite_init(void)
42 42
43MACHINE_START(AVENGERS_LITE, "PXA168 Avengers lite Development Platform") 43MACHINE_START(AVENGERS_LITE, "PXA168 Avengers lite Development Platform")
44 .phys_io = APB_PHYS_BASE, 44 .phys_io = APB_PHYS_BASE,
45 .boot_params = 0x00000100,
46 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc, 45 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc,
47 .map_io = pxa_map_io, 46 .map_io = mmp_map_io,
48 .init_irq = pxa168_init_irq, 47 .init_irq = pxa168_init_irq,
49 .timer = &pxa168_timer, 48 .timer = &pxa168_timer,
50 .init_machine = avengers_lite_init, 49 .init_machine = avengers_lite_init,
diff --git a/arch/arm/mach-mmp/common.c b/arch/arm/mach-mmp/common.c
index e1e66c18b446..3b29fa7e9b08 100644
--- a/arch/arm/mach-mmp/common.c
+++ b/arch/arm/mach-mmp/common.c
@@ -31,7 +31,7 @@ static struct map_desc standard_io_desc[] __initdata = {
31 }, 31 },
32}; 32};
33 33
34void __init pxa_map_io(void) 34void __init mmp_map_io(void)
35{ 35{
36 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc)); 36 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
37} 37}
diff --git a/arch/arm/mach-mmp/common.h b/arch/arm/mach-mmp/common.h
index b4a0ba05a0f4..ec8d65ded25c 100644
--- a/arch/arm/mach-mmp/common.h
+++ b/arch/arm/mach-mmp/common.h
@@ -3,15 +3,6 @@
3struct sys_timer; 3struct sys_timer;
4 4
5extern void timer_init(int irq); 5extern void timer_init(int irq);
6extern void mmp2_clear_pmic_int(void);
7
8extern struct sys_timer pxa168_timer;
9extern struct sys_timer pxa910_timer;
10extern struct sys_timer mmp2_timer;
11extern void __init pxa168_init_irq(void);
12extern void __init pxa910_init_irq(void);
13extern void __init mmp2_init_icu(void);
14extern void __init mmp2_init_irq(void);
15 6
16extern void __init icu_init_irq(void); 7extern void __init icu_init_irq(void);
17extern void __init pxa_map_io(void); 8extern void __init mmp_map_io(void);
diff --git a/arch/arm/mach-mmp/flint.c b/arch/arm/mach-mmp/flint.c
index 4ec7709a3462..e4312d238eae 100644
--- a/arch/arm/mach-mmp/flint.c
+++ b/arch/arm/mach-mmp/flint.c
@@ -114,9 +114,8 @@ static void __init flint_init(void)
114 114
115MACHINE_START(FLINT, "Flint Development Platform") 115MACHINE_START(FLINT, "Flint Development Platform")
116 .phys_io = APB_PHYS_BASE, 116 .phys_io = APB_PHYS_BASE,
117 .boot_params = 0x00000100,
118 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc, 117 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc,
119 .map_io = pxa_map_io, 118 .map_io = mmp_map_io,
120 .init_irq = mmp2_init_irq, 119 .init_irq = mmp2_init_irq,
121 .timer = &mmp2_timer, 120 .timer = &mmp2_timer,
122 .init_machine = flint_init, 121 .init_machine = flint_init,
diff --git a/arch/arm/mach-mmp/include/mach/devices.h b/arch/arm/mach-mmp/include/mach/devices.h
index 1fa0a492454a..d0ec7dae88e4 100644
--- a/arch/arm/mach-mmp/include/mach/devices.h
+++ b/arch/arm/mach-mmp/include/mach/devices.h
@@ -1,3 +1,6 @@
1#ifndef __MACH_DEVICE_H
2#define __MACH_DEVICE_H
3
1#include <linux/types.h> 4#include <linux/types.h>
2 5
3#define MAX_RESOURCE_DMA 2 6#define MAX_RESOURCE_DMA 2
@@ -47,3 +50,4 @@ struct pxa_device_desc mmp2_device_##_name __initdata = { \
47} 50}
48 51
49extern int pxa_register_device(struct pxa_device_desc *, void *, size_t); 52extern int pxa_register_device(struct pxa_device_desc *, void *, size_t);
53#endif /* __MACH_DEVICE_H */
diff --git a/arch/arm/mach-mmp/include/mach/mmp2.h b/arch/arm/mach-mmp/include/mach/mmp2.h
index fec220bd5046..dbba6e8a60c4 100644
--- a/arch/arm/mach-mmp/include/mach/mmp2.h
+++ b/arch/arm/mach-mmp/include/mach/mmp2.h
@@ -1,6 +1,13 @@
1#ifndef __ASM_MACH_MMP2_H 1#ifndef __ASM_MACH_MMP2_H
2#define __ASM_MACH_MMP2_H 2#define __ASM_MACH_MMP2_H
3 3
4struct sys_timer;
5
6extern struct sys_timer mmp2_timer;
7extern void __init mmp2_init_icu(void);
8extern void __init mmp2_init_irq(void);
9extern void mmp2_clear_pmic_int(void);
10
4#include <linux/i2c.h> 11#include <linux/i2c.h>
5#include <mach/devices.h> 12#include <mach/devices.h>
6#include <plat/i2c.h> 13#include <plat/i2c.h>
diff --git a/arch/arm/mach-mmp/include/mach/pxa168.h b/arch/arm/mach-mmp/include/mach/pxa168.h
index 3b2bd5d5eb05..27e1bc758623 100644
--- a/arch/arm/mach-mmp/include/mach/pxa168.h
+++ b/arch/arm/mach-mmp/include/mach/pxa168.h
@@ -1,6 +1,11 @@
1#ifndef __ASM_MACH_PXA168_H 1#ifndef __ASM_MACH_PXA168_H
2#define __ASM_MACH_PXA168_H 2#define __ASM_MACH_PXA168_H
3 3
4struct sys_timer;
5
6extern struct sys_timer pxa168_timer;
7extern void __init pxa168_init_irq(void);
8
4#include <linux/i2c.h> 9#include <linux/i2c.h>
5#include <mach/devices.h> 10#include <mach/devices.h>
6#include <plat/i2c.h> 11#include <plat/i2c.h>
diff --git a/arch/arm/mach-mmp/include/mach/pxa910.h b/arch/arm/mach-mmp/include/mach/pxa910.h
index 4f0b4ec6f5d0..f13c49d6f8dc 100644
--- a/arch/arm/mach-mmp/include/mach/pxa910.h
+++ b/arch/arm/mach-mmp/include/mach/pxa910.h
@@ -1,6 +1,11 @@
1#ifndef __ASM_MACH_PXA910_H 1#ifndef __ASM_MACH_PXA910_H
2#define __ASM_MACH_PXA910_H 2#define __ASM_MACH_PXA910_H
3 3
4struct sys_timer;
5
6extern struct sys_timer pxa910_timer;
7extern void __init pxa910_init_irq(void);
8
4#include <linux/i2c.h> 9#include <linux/i2c.h>
5#include <mach/devices.h> 10#include <mach/devices.h>
6#include <plat/i2c.h> 11#include <plat/i2c.h>
diff --git a/arch/arm/mach-mmp/irq-mmp2.c b/arch/arm/mach-mmp/irq-mmp2.c
index cb18221c0af3..01342be91c3c 100644
--- a/arch/arm/mach-mmp/irq-mmp2.c
+++ b/arch/arm/mach-mmp/irq-mmp2.c
@@ -16,6 +16,7 @@
16#include <linux/io.h> 16#include <linux/io.h>
17 17
18#include <mach/regs-icu.h> 18#include <mach/regs-icu.h>
19#include <mach/mmp2.h>
19 20
20#include "common.h" 21#include "common.h"
21 22
diff --git a/arch/arm/mach-mmp/jasper.c b/arch/arm/mach-mmp/jasper.c
index d77dd41d60e1..80c3e7ab1e17 100644
--- a/arch/arm/mach-mmp/jasper.c
+++ b/arch/arm/mach-mmp/jasper.c
@@ -135,9 +135,8 @@ static void __init jasper_init(void)
135 135
136MACHINE_START(MARVELL_JASPER, "Jasper Development Platform") 136MACHINE_START(MARVELL_JASPER, "Jasper Development Platform")
137 .phys_io = APB_PHYS_BASE, 137 .phys_io = APB_PHYS_BASE,
138 .boot_params = 0x00000100,
139 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc, 138 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc,
140 .map_io = pxa_map_io, 139 .map_io = mmp_map_io,
141 .init_irq = mmp2_init_irq, 140 .init_irq = mmp2_init_irq,
142 .timer = &mmp2_timer, 141 .timer = &mmp2_timer,
143 .init_machine = jasper_init, 142 .init_machine = jasper_init,
diff --git a/arch/arm/mach-mmp/mmp2.c b/arch/arm/mach-mmp/mmp2.c
index 7f5eb059bb01..daf3993349f8 100644
--- a/arch/arm/mach-mmp/mmp2.c
+++ b/arch/arm/mach-mmp/mmp2.c
@@ -17,6 +17,7 @@
17 17
18#include <asm/hardware/cache-tauros2.h> 18#include <asm/hardware/cache-tauros2.h>
19 19
20#include <asm/mach/time.h>
20#include <mach/addr-map.h> 21#include <mach/addr-map.h>
21#include <mach/regs-apbc.h> 22#include <mach/regs-apbc.h>
22#include <mach/regs-apmu.h> 23#include <mach/regs-apmu.h>
@@ -26,6 +27,7 @@
26#include <mach/mfp.h> 27#include <mach/mfp.h>
27#include <mach/gpio.h> 28#include <mach/gpio.h>
28#include <mach/devices.h> 29#include <mach/devices.h>
30#include <mach/mmp2.h>
29 31
30#include "common.h" 32#include "common.h"
31#include "clock.h" 33#include "clock.h"
@@ -158,6 +160,26 @@ static int __init mmp2_init(void)
158} 160}
159postcore_initcall(mmp2_init); 161postcore_initcall(mmp2_init);
160 162
163static void __init mmp2_timer_init(void)
164{
165 unsigned long clk_rst;
166
167 __raw_writel(APBC_APBCLK | APBC_RST, APBC_MMP2_TIMERS);
168
169 /*
170 * enable bus/functional clock, enable 6.5MHz (divider 4),
171 * release reset
172 */
173 clk_rst = APBC_APBCLK | APBC_FNCLK | APBC_FNCLKSEL(1);
174 __raw_writel(clk_rst, APBC_MMP2_TIMERS);
175
176 timer_init(IRQ_MMP2_TIMER1);
177}
178
179struct sys_timer mmp2_timer = {
180 .init = mmp2_timer_init,
181};
182
161/* on-chip devices */ 183/* on-chip devices */
162MMP2_DEVICE(uart1, "pxa2xx-uart", 0, UART1, 0xd4030000, 0x30, 4, 5); 184MMP2_DEVICE(uart1, "pxa2xx-uart", 0, UART1, 0xd4030000, 0x30, 4, 5);
163MMP2_DEVICE(uart2, "pxa2xx-uart", 1, UART2, 0xd4017000, 0x30, 20, 21); 185MMP2_DEVICE(uart2, "pxa2xx-uart", 1, UART2, 0xd4017000, 0x30, 20, 21);
diff --git a/arch/arm/mach-mmp/tavorevb.c b/arch/arm/mach-mmp/tavorevb.c
index 0e0c9220eaba..e81db7428215 100644
--- a/arch/arm/mach-mmp/tavorevb.c
+++ b/arch/arm/mach-mmp/tavorevb.c
@@ -100,9 +100,8 @@ static void __init tavorevb_init(void)
100 100
101MACHINE_START(TAVOREVB, "PXA910 Evaluation Board (aka TavorEVB)") 101MACHINE_START(TAVOREVB, "PXA910 Evaluation Board (aka TavorEVB)")
102 .phys_io = APB_PHYS_BASE, 102 .phys_io = APB_PHYS_BASE,
103 .boot_params = 0x00000100,
104 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc, 103 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc,
105 .map_io = pxa_map_io, 104 .map_io = mmp_map_io,
106 .init_irq = pxa910_init_irq, 105 .init_irq = pxa910_init_irq,
107 .timer = &pxa910_timer, 106 .timer = &pxa910_timer,
108 .init_machine = tavorevb_init, 107 .init_machine = tavorevb_init,
diff --git a/arch/arm/mach-mmp/time.c b/arch/arm/mach-mmp/time.c
index cf75694e9687..66528193f939 100644
--- a/arch/arm/mach-mmp/time.c
+++ b/arch/arm/mach-mmp/time.c
@@ -200,24 +200,3 @@ void __init timer_init(int irq)
200 clocksource_register(&cksrc); 200 clocksource_register(&cksrc);
201 clockevents_register_device(&ckevt); 201 clockevents_register_device(&ckevt);
202} 202}
203
204static void __init mmp2_timer_init(void)
205{
206 unsigned long clk_rst;
207
208 __raw_writel(APBC_APBCLK | APBC_RST, APBC_MMP2_TIMERS);
209
210 /*
211 * enable bus/functional clock, enable 6.5MHz (divider 4),
212 * release reset
213 */
214 clk_rst = APBC_APBCLK | APBC_FNCLK | APBC_FNCLKSEL(1);
215 __raw_writel(clk_rst, APBC_MMP2_TIMERS);
216
217 timer_init(IRQ_MMP2_TIMER1);
218}
219
220struct sys_timer mmp2_timer = {
221 .init = mmp2_timer_init,
222};
223
diff --git a/arch/arm/mach-mmp/ttc_dkb.c b/arch/arm/mach-mmp/ttc_dkb.c
index b22dec4abf78..ee65e05f0cf1 100644
--- a/arch/arm/mach-mmp/ttc_dkb.c
+++ b/arch/arm/mach-mmp/ttc_dkb.c
@@ -123,9 +123,8 @@ static void __init ttc_dkb_init(void)
123 123
124MACHINE_START(TTC_DKB, "PXA910-based TTC_DKB Development Platform") 124MACHINE_START(TTC_DKB, "PXA910-based TTC_DKB Development Platform")
125 .phys_io = APB_PHYS_BASE, 125 .phys_io = APB_PHYS_BASE,
126 .boot_params = 0x00000100,
127 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc, 126 .io_pg_offst = (APB_VIRT_BASE >> 18) & 0xfffc,
128 .map_io = pxa_map_io, 127 .map_io = mmp_map_io,
129 .init_irq = pxa910_init_irq, 128 .init_irq = pxa910_init_irq,
130 .timer = &pxa910_timer, 129 .timer = &pxa910_timer,
131 .init_machine = ttc_dkb_init, 130 .init_machine = ttc_dkb_init,
diff --git a/arch/arm/mach-msm/Makefile b/arch/arm/mach-msm/Makefile
index 7ff8020d4d24..704610648a25 100644
--- a/arch/arm/mach-msm/Makefile
+++ b/arch/arm/mach-msm/Makefile
@@ -15,7 +15,7 @@ obj-$(CONFIG_ARCH_QSD8X50) += sirc.o
15obj-$(CONFIG_MSM_SMD) += smd.o smd_debug.o 15obj-$(CONFIG_MSM_SMD) += smd.o smd_debug.o
16obj-$(CONFIG_MSM_SMD) += last_radio_log.o 16obj-$(CONFIG_MSM_SMD) += last_radio_log.o
17 17
18obj-$(CONFIG_MACH_TROUT) += board-trout.o board-trout-gpio.o devices-msm7x00.o 18obj-$(CONFIG_MACH_TROUT) += board-trout.o board-trout-gpio.o board-trout-mmc.o devices-msm7x00.o
19obj-$(CONFIG_MACH_HALIBUT) += board-halibut.o devices-msm7x00.o 19obj-$(CONFIG_MACH_HALIBUT) += board-halibut.o devices-msm7x00.o
20obj-$(CONFIG_ARCH_MSM7X30) += board-msm7x30.o devices-msm7x30.o 20obj-$(CONFIG_ARCH_MSM7X30) += board-msm7x30.o devices-msm7x30.o
21obj-$(CONFIG_ARCH_QSD8X50) += board-qsd8x50.o devices-qsd8x50.o 21obj-$(CONFIG_ARCH_QSD8X50) += board-qsd8x50.o devices-qsd8x50.o
diff --git a/arch/arm/mach-msm/acpuclock-arm11.c b/arch/arm/mach-msm/acpuclock-arm11.c
index f060a3959a75..7ffbd987eb5d 100644
--- a/arch/arm/mach-msm/acpuclock-arm11.c
+++ b/arch/arm/mach-msm/acpuclock-arm11.c
@@ -17,7 +17,6 @@
17 * 17 *
18 */ 18 */
19 19
20#include <linux/version.h>
21#include <linux/kernel.h> 20#include <linux/kernel.h>
22#include <linux/init.h> 21#include <linux/init.h>
23#include <linux/list.h> 22#include <linux/list.h>
diff --git a/arch/arm/mach-msm/board-trout-gpio.c b/arch/arm/mach-msm/board-trout-gpio.c
index 523d213bf79e..c50f3afc3134 100644
--- a/arch/arm/mach-msm/board-trout-gpio.c
+++ b/arch/arm/mach-msm/board-trout-gpio.c
@@ -15,10 +15,20 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/irq.h> 17#include <linux/irq.h>
18#include <linux/interrupt.h>
18#include <linux/gpio.h> 19#include <linux/gpio.h>
19 20
20#include "board-trout.h" 21#include "board-trout.h"
21 22
23static uint8_t trout_int_mask[2] = {
24 [0] = 0xff, /* mask all interrupts */
25 [1] = 0xff,
26};
27static uint8_t trout_sleep_int_mask[] = {
28 [0] = 0xff,
29 [1] = 0xff,
30};
31
22struct msm_gpio_chip { 32struct msm_gpio_chip {
23 struct gpio_chip chip; 33 struct gpio_chip chip;
24 void __iomem *reg; /* Base of register bank */ 34 void __iomem *reg; /* Base of register bank */
@@ -95,16 +105,121 @@ static struct msm_gpio_chip msm_gpio_banks[] = {
95 TROUT_GPIO_BANK("VIRTUAL", 0x12, TROUT_GPIO_VIRTUAL_BASE, 0), 105 TROUT_GPIO_BANK("VIRTUAL", 0x12, TROUT_GPIO_VIRTUAL_BASE, 0),
96}; 106};
97 107
108static void trout_gpio_irq_ack(unsigned int irq)
109{
110 int bank = TROUT_INT_TO_BANK(irq);
111 uint8_t mask = TROUT_INT_TO_MASK(irq);
112 int reg = TROUT_BANK_TO_STAT_REG(bank);
113 /*printk(KERN_INFO "trout_gpio_irq_ack irq %d\n", irq);*/
114 writeb(mask, TROUT_CPLD_BASE + reg);
115}
116
117static void trout_gpio_irq_mask(unsigned int irq)
118{
119 unsigned long flags;
120 uint8_t reg_val;
121 int bank = TROUT_INT_TO_BANK(irq);
122 uint8_t mask = TROUT_INT_TO_MASK(irq);
123 int reg = TROUT_BANK_TO_MASK_REG(bank);
124
125 local_irq_save(flags);
126 reg_val = trout_int_mask[bank] |= mask;
127 /*printk(KERN_INFO "trout_gpio_irq_mask irq %d => %d:%02x\n",
128 irq, bank, reg_val);*/
129 writeb(reg_val, TROUT_CPLD_BASE + reg);
130 local_irq_restore(flags);
131}
132
133static void trout_gpio_irq_unmask(unsigned int irq)
134{
135 unsigned long flags;
136 uint8_t reg_val;
137 int bank = TROUT_INT_TO_BANK(irq);
138 uint8_t mask = TROUT_INT_TO_MASK(irq);
139 int reg = TROUT_BANK_TO_MASK_REG(bank);
140
141 local_irq_save(flags);
142 reg_val = trout_int_mask[bank] &= ~mask;
143 /*printk(KERN_INFO "trout_gpio_irq_unmask irq %d => %d:%02x\n",
144 irq, bank, reg_val);*/
145 writeb(reg_val, TROUT_CPLD_BASE + reg);
146 local_irq_restore(flags);
147}
148
149int trout_gpio_irq_set_wake(unsigned int irq, unsigned int on)
150{
151 unsigned long flags;
152 int bank = TROUT_INT_TO_BANK(irq);
153 uint8_t mask = TROUT_INT_TO_MASK(irq);
154
155 local_irq_save(flags);
156 if(on)
157 trout_sleep_int_mask[bank] &= ~mask;
158 else
159 trout_sleep_int_mask[bank] |= mask;
160 local_irq_restore(flags);
161 return 0;
162}
163
164static void trout_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
165{
166 int j, m;
167 unsigned v;
168 int bank;
169 int stat_reg;
170 int int_base = TROUT_INT_START;
171 uint8_t int_mask;
172
173 for (bank = 0; bank < 2; bank++) {
174 stat_reg = TROUT_BANK_TO_STAT_REG(bank);
175 v = readb(TROUT_CPLD_BASE + stat_reg);
176 int_mask = trout_int_mask[bank];
177 if (v & int_mask) {
178 writeb(v & int_mask, TROUT_CPLD_BASE + stat_reg);
179 printk(KERN_ERR "trout_gpio_irq_handler: got masked "
180 "interrupt: %d:%02x\n", bank, v & int_mask);
181 }
182 v &= ~int_mask;
183 while (v) {
184 m = v & -v;
185 j = fls(m) - 1;
186 /*printk(KERN_INFO "msm_gpio_irq_handler %d:%02x %02x b"
187 "it %d irq %d\n", bank, v, m, j, int_base + j);*/
188 v &= ~m;
189 generic_handle_irq(int_base + j);
190 }
191 int_base += TROUT_INT_BANK0_COUNT;
192 }
193 desc->chip->ack(irq);
194}
195
196static struct irq_chip trout_gpio_irq_chip = {
197 .name = "troutgpio",
198 .ack = trout_gpio_irq_ack,
199 .mask = trout_gpio_irq_mask,
200 .unmask = trout_gpio_irq_unmask,
201 .set_wake = trout_gpio_irq_set_wake,
202};
203
98/* 204/*
99 * Called from the processor-specific init to enable GPIO pin support. 205 * Called from the processor-specific init to enable GPIO pin support.
100 */ 206 */
101int __init trout_init_gpio(void) 207int __init trout_init_gpio(void)
102{ 208{
103 int i; 209 int i;
210 for(i = TROUT_INT_START; i <= TROUT_INT_END; i++) {
211 set_irq_chip(i, &trout_gpio_irq_chip);
212 set_irq_handler(i, handle_edge_irq);
213 set_irq_flags(i, IRQF_VALID);
214 }
104 215
105 for (i = 0; i < ARRAY_SIZE(msm_gpio_banks); i++) 216 for (i = 0; i < ARRAY_SIZE(msm_gpio_banks); i++)
106 gpiochip_add(&msm_gpio_banks[i].chip); 217 gpiochip_add(&msm_gpio_banks[i].chip);
107 218
219 set_irq_type(MSM_GPIO_TO_INT(17), IRQF_TRIGGER_HIGH);
220 set_irq_chained_handler(MSM_GPIO_TO_INT(17), trout_gpio_irq_handler);
221 set_irq_wake(MSM_GPIO_TO_INT(17), 1);
222
108 return 0; 223 return 0;
109} 224}
110 225
diff --git a/arch/arm/mach-msm/board-trout-mmc.c b/arch/arm/mach-msm/board-trout-mmc.c
new file mode 100644
index 000000000000..44be8464657b
--- /dev/null
+++ b/arch/arm/mach-msm/board-trout-mmc.c
@@ -0,0 +1,186 @@
1/* linux/arch/arm/mach-msm/board-trout-mmc.c
2** Author: Brian Swetland <swetland@google.com>
3*/
4
5#include <linux/kernel.h>
6#include <linux/init.h>
7#include <linux/platform_device.h>
8#include <linux/delay.h>
9#include <linux/mmc/host.h>
10#include <linux/mmc/sdio_ids.h>
11#include <linux/err.h>
12#include <linux/debugfs.h>
13
14#include <asm/gpio.h>
15#include <asm/io.h>
16
17#include <mach/vreg.h>
18
19#include <mach/mmc.h>
20
21#include "devices.h"
22
23#include "board-trout.h"
24
25#include "proc_comm.h"
26
27#define DEBUG_SDSLOT_VDD 1
28
29/* ---- COMMON ---- */
30static void config_gpio_table(uint32_t *table, int len)
31{
32 int n;
33 unsigned id;
34 for(n = 0; n < len; n++) {
35 id = table[n];
36 msm_proc_comm(PCOM_RPC_GPIO_TLMM_CONFIG_EX, &id, 0);
37 }
38}
39
40/* ---- SDCARD ---- */
41
42static uint32_t sdcard_on_gpio_table[] = {
43 PCOM_GPIO_CFG(62, 2, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_8MA), /* CLK */
44 PCOM_GPIO_CFG(63, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* CMD */
45 PCOM_GPIO_CFG(64, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* DAT3 */
46 PCOM_GPIO_CFG(65, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* DAT2 */
47 PCOM_GPIO_CFG(66, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT1 */
48 PCOM_GPIO_CFG(67, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT0 */
49};
50
51static uint32_t sdcard_off_gpio_table[] = {
52 PCOM_GPIO_CFG(62, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* CLK */
53 PCOM_GPIO_CFG(63, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* CMD */
54 PCOM_GPIO_CFG(64, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT3 */
55 PCOM_GPIO_CFG(65, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT2 */
56 PCOM_GPIO_CFG(66, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT1 */
57 PCOM_GPIO_CFG(67, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT0 */
58};
59
60static uint opt_disable_sdcard;
61
62static int __init trout_disablesdcard_setup(char *str)
63{
64 int cal = simple_strtol(str, NULL, 0);
65
66 opt_disable_sdcard = cal;
67 return 1;
68}
69
70__setup("board_trout.disable_sdcard=", trout_disablesdcard_setup);
71
72static struct vreg *vreg_sdslot; /* SD slot power */
73
74struct mmc_vdd_xlat {
75 int mask;
76 int level;
77};
78
79static struct mmc_vdd_xlat mmc_vdd_table[] = {
80 { MMC_VDD_165_195, 1800 },
81 { MMC_VDD_20_21, 2050 },
82 { MMC_VDD_21_22, 2150 },
83 { MMC_VDD_22_23, 2250 },
84 { MMC_VDD_23_24, 2350 },
85 { MMC_VDD_24_25, 2450 },
86 { MMC_VDD_25_26, 2550 },
87 { MMC_VDD_26_27, 2650 },
88 { MMC_VDD_27_28, 2750 },
89 { MMC_VDD_28_29, 2850 },
90 { MMC_VDD_29_30, 2950 },
91};
92
93static unsigned int sdslot_vdd = 0xffffffff;
94static unsigned int sdslot_vreg_enabled;
95
96static uint32_t trout_sdslot_switchvdd(struct device *dev, unsigned int vdd)
97{
98 int i, rc;
99
100 BUG_ON(!vreg_sdslot);
101
102 if (vdd == sdslot_vdd)
103 return 0;
104
105 sdslot_vdd = vdd;
106
107 if (vdd == 0) {
108#if DEBUG_SDSLOT_VDD
109 printk("%s: Disabling SD slot power\n", __func__);
110#endif
111 config_gpio_table(sdcard_off_gpio_table,
112 ARRAY_SIZE(sdcard_off_gpio_table));
113 vreg_disable(vreg_sdslot);
114 sdslot_vreg_enabled = 0;
115 return 0;
116 }
117
118 if (!sdslot_vreg_enabled) {
119 rc = vreg_enable(vreg_sdslot);
120 if (rc) {
121 printk(KERN_ERR "%s: Error enabling vreg (%d)\n",
122 __func__, rc);
123 }
124 config_gpio_table(sdcard_on_gpio_table,
125 ARRAY_SIZE(sdcard_on_gpio_table));
126 sdslot_vreg_enabled = 1;
127 }
128
129 for (i = 0; i < ARRAY_SIZE(mmc_vdd_table); i++) {
130 if (mmc_vdd_table[i].mask == (1 << vdd)) {
131#if DEBUG_SDSLOT_VDD
132 printk("%s: Setting level to %u\n",
133 __func__, mmc_vdd_table[i].level);
134#endif
135 rc = vreg_set_level(vreg_sdslot,
136 mmc_vdd_table[i].level);
137 if (rc) {
138 printk(KERN_ERR
139 "%s: Error setting vreg level (%d)\n",
140 __func__, rc);
141 }
142 return 0;
143 }
144 }
145
146 printk(KERN_ERR "%s: Invalid VDD %d specified\n", __func__, vdd);
147 return 0;
148}
149
150static unsigned int trout_sdslot_status(struct device *dev)
151{
152 unsigned int status;
153
154 status = (unsigned int) gpio_get_value(TROUT_GPIO_SDMC_CD_N);
155 return (!status);
156}
157
158#define TROUT_MMC_VDD MMC_VDD_165_195 | MMC_VDD_20_21 | MMC_VDD_21_22 \
159 | MMC_VDD_22_23 | MMC_VDD_23_24 | MMC_VDD_24_25 \
160 | MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 \
161 | MMC_VDD_28_29 | MMC_VDD_29_30
162
163static struct msm_mmc_platform_data trout_sdslot_data = {
164 .ocr_mask = TROUT_MMC_VDD,
165 .status = trout_sdslot_status,
166 .translate_vdd = trout_sdslot_switchvdd,
167};
168
169int __init trout_init_mmc(unsigned int sys_rev)
170{
171 sdslot_vreg_enabled = 0;
172
173 vreg_sdslot = vreg_get(0, "gp6");
174 if (IS_ERR(vreg_sdslot))
175 return PTR_ERR(vreg_sdslot);
176
177 set_irq_wake(TROUT_GPIO_TO_INT(TROUT_GPIO_SDMC_CD_N), 1);
178
179 if (!opt_disable_sdcard)
180 msm_add_sdcc(2, &trout_sdslot_data,
181 TROUT_GPIO_TO_INT(TROUT_GPIO_SDMC_CD_N), 0);
182 else
183 printk(KERN_INFO "trout: SD-Card interface disabled\n");
184 return 0;
185}
186
diff --git a/arch/arm/mach-msm/board-trout.c b/arch/arm/mach-msm/board-trout.c
index e69a1502e4e8..469e0be3499d 100644
--- a/arch/arm/mach-msm/board-trout.c
+++ b/arch/arm/mach-msm/board-trout.c
@@ -30,6 +30,8 @@
30#include "devices.h" 30#include "devices.h"
31#include "board-trout.h" 31#include "board-trout.h"
32 32
33extern int trout_init_mmc(unsigned int);
34
33static struct platform_device *devices[] __initdata = { 35static struct platform_device *devices[] __initdata = {
34 &msm_device_uart3, 36 &msm_device_uart3,
35 &msm_device_smd, 37 &msm_device_smd,
@@ -55,7 +57,16 @@ static void __init trout_fixup(struct machine_desc *desc, struct tag *tags,
55 57
56static void __init trout_init(void) 58static void __init trout_init(void)
57{ 59{
60 int rc;
61
58 platform_add_devices(devices, ARRAY_SIZE(devices)); 62 platform_add_devices(devices, ARRAY_SIZE(devices));
63
64#ifdef CONFIG_MMC
65 rc = trout_init_mmc(system_rev);
66 if (rc)
67 printk(KERN_CRIT "%s: MMC init failure (%d)\n", __func__, rc);
68#endif
69
59} 70}
60 71
61static struct map_desc trout_io_desc[] __initdata = { 72static struct map_desc trout_io_desc[] __initdata = {
diff --git a/arch/arm/mach-msm/clock.c b/arch/arm/mach-msm/clock.c
index 9cb1276ab749..c57210f4f06a 100644
--- a/arch/arm/mach-msm/clock.c
+++ b/arch/arm/mach-msm/clock.c
@@ -14,7 +14,6 @@
14 * 14 *
15 */ 15 */
16 16
17#include <linux/version.h>
18#include <linux/kernel.h> 17#include <linux/kernel.h>
19#include <linux/init.h> 18#include <linux/init.h>
20#include <linux/module.h> 19#include <linux/module.h>
diff --git a/arch/arm/mach-msm/devices-msm7x00.c b/arch/arm/mach-msm/devices-msm7x00.c
index fde9d8f69f10..4e8c0bcdc92d 100644
--- a/arch/arm/mach-msm/devices-msm7x00.c
+++ b/arch/arm/mach-msm/devices-msm7x00.c
@@ -322,7 +322,8 @@ static struct platform_device *msm_sdcc_devices[] __initdata = {
322 &msm_device_sdc4, 322 &msm_device_sdc4,
323}; 323};
324 324
325int __init msm_add_sdcc(unsigned int controller, struct mmc_platform_data *plat, 325int __init msm_add_sdcc(unsigned int controller,
326 struct msm_mmc_platform_data *plat,
326 unsigned int stat_irq, unsigned long stat_irq_flags) 327 unsigned int stat_irq, unsigned long stat_irq_flags)
327{ 328{
328 struct platform_device *pdev; 329 struct platform_device *pdev;
diff --git a/arch/arm/mach-msm/include/mach/board.h b/arch/arm/mach-msm/include/mach/board.h
index e302fbdc439b..5a79bcf50413 100644
--- a/arch/arm/mach-msm/include/mach/board.h
+++ b/arch/arm/mach-msm/include/mach/board.h
@@ -18,6 +18,7 @@
18#define __ASM_ARCH_MSM_BOARD_H 18#define __ASM_ARCH_MSM_BOARD_H
19 19
20#include <linux/types.h> 20#include <linux/types.h>
21#include <mach/mmc.h>
21 22
22/* platform device data structures */ 23/* platform device data structures */
23 24
@@ -40,5 +41,8 @@ void __init msm_init_irq(void);
40void __init msm_init_gpio(void); 41void __init msm_init_gpio(void);
41void __init msm_clock_init(struct clk *clock_tbl, unsigned num_clocks); 42void __init msm_clock_init(struct clk *clock_tbl, unsigned num_clocks);
42void __init msm_acpu_clock_init(struct msm_acpu_clock_platform_data *); 43void __init msm_acpu_clock_init(struct msm_acpu_clock_platform_data *);
44int __init msm_add_sdcc(unsigned int controller,
45 struct msm_mmc_platform_data *plat,
46 unsigned int stat_irq, unsigned long stat_irq_flags);
43 47
44#endif 48#endif
diff --git a/arch/arm/mach-msm/include/mach/mmc.h b/arch/arm/mach-msm/include/mach/mmc.h
index 0ecf25426284..d54b6b086cff 100644
--- a/arch/arm/mach-msm/include/mach/mmc.h
+++ b/arch/arm/mach-msm/include/mach/mmc.h
@@ -15,7 +15,7 @@ struct embedded_sdio_data {
15 int num_funcs; 15 int num_funcs;
16}; 16};
17 17
18struct mmc_platform_data { 18struct msm_mmc_platform_data {
19 unsigned int ocr_mask; /* available voltages */ 19 unsigned int ocr_mask; /* available voltages */
20 u32 (*translate_vdd)(struct device *, unsigned int); 20 u32 (*translate_vdd)(struct device *, unsigned int);
21 unsigned int (*status)(struct device *); 21 unsigned int (*status)(struct device *);
diff --git a/arch/arm/mach-msm/smd.c b/arch/arm/mach-msm/smd.c
index cf11d414b425..f07dc7c738f0 100644
--- a/arch/arm/mach-msm/smd.c
+++ b/arch/arm/mach-msm/smd.c
@@ -997,7 +997,7 @@ int smd_core_init(void)
997 return 0; 997 return 0;
998} 998}
999 999
1000static int __init msm_smd_probe(struct platform_device *pdev) 1000static int __devinit msm_smd_probe(struct platform_device *pdev)
1001{ 1001{
1002 pr_info("smd_init()\n"); 1002 pr_info("smd_init()\n");
1003 1003
diff --git a/arch/arm/mach-omap2/board-omap3pandora.c b/arch/arm/mach-omap2/board-omap3pandora.c
index 55836fa35060..dd3af2be13be 100644
--- a/arch/arm/mach-omap2/board-omap3pandora.c
+++ b/arch/arm/mach-omap2/board-omap3pandora.c
@@ -32,6 +32,7 @@
32#include <linux/input.h> 32#include <linux/input.h>
33#include <linux/input/matrix_keypad.h> 33#include <linux/input/matrix_keypad.h>
34#include <linux/gpio_keys.h> 34#include <linux/gpio_keys.h>
35#include <linux/mmc/card.h>
35 36
36#include <asm/mach-types.h> 37#include <asm/mach-types.h>
37#include <asm/mach/arch.h> 38#include <asm/mach/arch.h>
@@ -258,6 +259,20 @@ static struct platform_device pandora_dss_device = {
258 }, 259 },
259}; 260};
260 261
262static void pandora_wl1251_init_card(struct mmc_card *card)
263{
264 /*
265 * We have TI wl1251 attached to MMC3. Pass this information to
266 * SDIO core because it can't be probed by normal methods.
267 */
268 card->quirks |= MMC_QUIRK_NONSTD_SDIO;
269 card->cccr.wide_bus = 1;
270 card->cis.vendor = 0x104c;
271 card->cis.device = 0x9066;
272 card->cis.blksize = 512;
273 card->cis.max_dtr = 20000000;
274}
275
261static struct omap2_hsmmc_info omap3pandora_mmc[] = { 276static struct omap2_hsmmc_info omap3pandora_mmc[] = {
262 { 277 {
263 .mmc = 1, 278 .mmc = 1,
@@ -279,6 +294,7 @@ static struct omap2_hsmmc_info omap3pandora_mmc[] = {
279 .wires = 4, 294 .wires = 4,
280 .gpio_cd = -EINVAL, 295 .gpio_cd = -EINVAL,
281 .gpio_wp = -EINVAL, 296 .gpio_wp = -EINVAL,
297 .init_card = pandora_wl1251_init_card,
282 }, 298 },
283 {} /* Terminator */ 299 {} /* Terminator */
284}; 300};
diff --git a/arch/arm/mach-omap2/hsmmc.c b/arch/arm/mach-omap2/hsmmc.c
index 1ef54b036103..c8f647b6205e 100644
--- a/arch/arm/mach-omap2/hsmmc.c
+++ b/arch/arm/mach-omap2/hsmmc.c
@@ -268,6 +268,7 @@ void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers)
268 mmc->slots[0].gpio_wp = c->gpio_wp; 268 mmc->slots[0].gpio_wp = c->gpio_wp;
269 269
270 mmc->slots[0].remux = c->remux; 270 mmc->slots[0].remux = c->remux;
271 mmc->slots[0].init_card = c->init_card;
271 272
272 if (c->cover_only) 273 if (c->cover_only)
273 mmc->slots[0].cover = 1; 274 mmc->slots[0].cover = 1;
diff --git a/arch/arm/mach-omap2/hsmmc.h b/arch/arm/mach-omap2/hsmmc.h
index 36f0ba8d89e2..1fe6f0187177 100644
--- a/arch/arm/mach-omap2/hsmmc.h
+++ b/arch/arm/mach-omap2/hsmmc.h
@@ -6,6 +6,8 @@
6 * published by the Free Software Foundation. 6 * published by the Free Software Foundation.
7 */ 7 */
8 8
9struct mmc_card;
10
9struct omap2_hsmmc_info { 11struct omap2_hsmmc_info {
10 u8 mmc; /* controller 1/2/3 */ 12 u8 mmc; /* controller 1/2/3 */
11 u8 wires; /* 1/4/8 wires */ 13 u8 wires; /* 1/4/8 wires */
@@ -23,6 +25,8 @@ struct omap2_hsmmc_info {
23 int ocr_mask; /* temporary HACK */ 25 int ocr_mask; /* temporary HACK */
24 /* Remux (pad configuation) when powering on/off */ 26 /* Remux (pad configuation) when powering on/off */
25 void (*remux)(struct device *dev, int slot, int power_on); 27 void (*remux)(struct device *dev, int slot, int power_on);
28 /* init some special card */
29 void (*init_card)(struct mmc_card *card);
26}; 30};
27 31
28#if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE) 32#if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
diff --git a/arch/arm/mach-pxa/Kconfig b/arch/arm/mach-pxa/Kconfig
index 3b51741a4810..7aefb9074852 100644
--- a/arch/arm/mach-pxa/Kconfig
+++ b/arch/arm/mach-pxa/Kconfig
@@ -238,6 +238,17 @@ config MACH_COLIBRI
238 bool "Toradex Colibri PXA270" 238 bool "Toradex Colibri PXA270"
239 select PXA27x 239 select PXA27x
240 240
241config MACH_COLIBRI_PXA270_EVALBOARD
242 bool "Toradex Colibri Evaluation Carrier Board support (PXA270)"
243 depends on MACH_COLIBRI
244
245config MACH_COLIBRI_PXA270_INCOME
246 bool "Income s.r.o. PXA270 SBC"
247 depends on MACH_COLIBRI
248 select PXA27x
249 select HAVE_PWM
250 select PXA_HAVE_BOARD_IRQS
251
241config MACH_COLIBRI300 252config MACH_COLIBRI300
242 bool "Toradex Colibri PXA300/310" 253 bool "Toradex Colibri PXA300/310"
243 select PXA3xx 254 select PXA3xx
@@ -336,6 +347,9 @@ config ARCH_PXA_PALM
336 bool "PXA based Palm PDAs" 347 bool "PXA based Palm PDAs"
337 select HAVE_PWM 348 select HAVE_PWM
338 349
350config MACH_PALM27X
351 bool
352
339config MACH_PALMTE2 353config MACH_PALMTE2
340 bool "Palm Tungsten|E2" 354 bool "Palm Tungsten|E2"
341 default y 355 default y
@@ -360,6 +374,7 @@ config MACH_PALMT5
360 depends on ARCH_PXA_PALM 374 depends on ARCH_PXA_PALM
361 select PXA27x 375 select PXA27x
362 select IWMMXT 376 select IWMMXT
377 select MACH_PALM27X
363 help 378 help
364 Say Y here if you intend to run this kernel on a Palm Tungsten|T5 379 Say Y here if you intend to run this kernel on a Palm Tungsten|T5
365 handheld computer. 380 handheld computer.
@@ -370,6 +385,7 @@ config MACH_PALMTX
370 depends on ARCH_PXA_PALM 385 depends on ARCH_PXA_PALM
371 select PXA27x 386 select PXA27x
372 select IWMMXT 387 select IWMMXT
388 select MACH_PALM27X
373 help 389 help
374 Say Y here if you intend to run this kernel on a Palm T|X 390 Say Y here if you intend to run this kernel on a Palm T|X
375 handheld computer. 391 handheld computer.
@@ -380,6 +396,7 @@ config MACH_PALMZ72
380 depends on ARCH_PXA_PALM 396 depends on ARCH_PXA_PALM
381 select PXA27x 397 select PXA27x
382 select IWMMXT 398 select IWMMXT
399 select MACH_PALM27X
383 help 400 help
384 Say Y here if you intend to run this kernel on Palm Zire 72 401 Say Y here if you intend to run this kernel on Palm Zire 72
385 handheld computer. 402 handheld computer.
@@ -390,6 +407,7 @@ config MACH_PALMLD
390 depends on ARCH_PXA_PALM 407 depends on ARCH_PXA_PALM
391 select PXA27x 408 select PXA27x
392 select IWMMXT 409 select IWMMXT
410 select MACH_PALM27X
393 help 411 help
394 Say Y here if you intend to run this kernel on a Palm LifeDrive 412 Say Y here if you intend to run this kernel on a Palm LifeDrive
395 handheld computer. 413 handheld computer.
@@ -447,16 +465,13 @@ config PXA_SHARPSL
447 SL-C3000 (Spitz), SL-C3100 (Borzoi) or SL-C6000x (Tosa) 465 SL-C3000 (Spitz), SL-C3100 (Borzoi) or SL-C6000x (Tosa)
448 handheld computer. 466 handheld computer.
449 467
450config SHARPSL_PM 468config PXA_SHARPSL_DETECT_MACH_ID
451 bool 469 bool "Detect machine ID at run-time in the decompressor"
452 select APM_EMULATION 470 depends on PXA_SHARPSL
453 select SHARPSL_PM_MAX1111 471 help
454 472 Say Y here if you want the zImage decompressor to detect
455config SHARPSL_PM_MAX1111 473 the Zaurus machine ID at run-time. For latest kexec-based
456 bool 474 boot loader, this is not necessary.
457 depends on !CORGI_SSP_DEPRECATED
458 select HWMON
459 select SENSORS_MAX1111
460 475
461config MACH_POODLE 476config MACH_POODLE
462 bool "Enable Sharp SL-5600 (Poodle) Support" 477 bool "Enable Sharp SL-5600 (Poodle) Support"
@@ -510,6 +525,25 @@ config MACH_TOSA
510 select PXA25x 525 select PXA25x
511 select PXA_HAVE_BOARD_IRQS 526 select PXA_HAVE_BOARD_IRQS
512 527
528config TOSA_BT
529 tristate "Control the state of built-in bluetooth chip on Sharp SL-6000"
530 depends on MACH_TOSA
531 select RFKILL
532 help
533 This is a simple driver that is able to control
534 the state of built in bluetooth chip on tosa.
535
536config TOSA_USE_EXT_KEYCODES
537 bool "Tosa keyboard: use extended keycodes"
538 depends on MACH_TOSA
539 default n
540 help
541 Say Y here to enable the tosa keyboard driver to generate extended
542 (>= 127) keycodes. Be aware, that they can't be correctly interpreted
543 by either console keyboard driver or by Kdrive keybd driver.
544
545 Say Y only if you know, what you are doing!
546
513config MACH_ICONTROL 547config MACH_ICONTROL
514 bool "TMT iControl/SafeTCam based on the MXM-8x10 CoM" 548 bool "TMT iControl/SafeTCam based on the MXM-8x10 CoM"
515 select CPU_PXA320 549 select CPU_PXA320
@@ -648,25 +682,15 @@ config PXA_SHARP_Cxx00
648 help 682 help
649 Enable common support for Sharp Cxx00 models 683 Enable common support for Sharp Cxx00 models
650 684
651config TOSA_BT 685config SHARPSL_PM
652 tristate "Control the state of built-in bluetooth chip on Sharp SL-6000" 686 bool
653 depends on MACH_TOSA 687 select APM_EMULATION
654 select RFKILL 688 select SHARPSL_PM_MAX1111
655 help
656 This is a simple driver that is able to control
657 the state of built in bluetooth chip on tosa.
658
659config TOSA_USE_EXT_KEYCODES
660 bool "Tosa keyboard: use extended keycodes"
661 depends on MACH_TOSA
662 default n
663 help
664 Say Y here to enable the tosa keyboard driver to generate extended
665 (>= 127) keycodes. Be aware, that they can't be correctly interpreted
666 by either console keyboard driver or by Kdrive keybd driver.
667
668 Say Y only if you know, what you are doing!
669 689
690config SHARPSL_PM_MAX1111
691 bool
692 select HWMON
693 select SENSORS_MAX1111
670 694
671config PXA_HAVE_BOARD_IRQS 695config PXA_HAVE_BOARD_IRQS
672 bool 696 bool
diff --git a/arch/arm/mach-pxa/Makefile b/arch/arm/mach-pxa/Makefile
index b8f1f4bc7ca7..85c7fb324dbb 100644
--- a/arch/arm/mach-pxa/Makefile
+++ b/arch/arm/mach-pxa/Makefile
@@ -51,14 +51,16 @@ obj-$(CONFIG_MACH_CAPC7117) += capc7117.o mxm8x10.o
51obj-$(CONFIG_ARCH_GUMSTIX) += gumstix.o 51obj-$(CONFIG_ARCH_GUMSTIX) += gumstix.o
52obj-$(CONFIG_GUMSTIX_AM200EPD) += am200epd.o 52obj-$(CONFIG_GUMSTIX_AM200EPD) += am200epd.o
53obj-$(CONFIG_GUMSTIX_AM300EPD) += am300epd.o 53obj-$(CONFIG_GUMSTIX_AM300EPD) += am300epd.o
54obj-$(CONFIG_MACH_INTELMOTE2) += imote2.o 54obj-$(CONFIG_MACH_INTELMOTE2) += stargate2.o
55obj-$(CONFIG_MACH_STARGATE2) += stargate2.o 55obj-$(CONFIG_MACH_STARGATE2) += stargate2.o
56obj-$(CONFIG_MACH_XCEP) += xcep.o 56obj-$(CONFIG_MACH_XCEP) += xcep.o
57obj-$(CONFIG_MACH_TRIZEPS4) += trizeps4.o 57obj-$(CONFIG_MACH_TRIZEPS4) += trizeps4.o
58obj-$(CONFIG_MACH_LOGICPD_PXA270) += lpd270.o 58obj-$(CONFIG_MACH_LOGICPD_PXA270) += lpd270.o
59obj-$(CONFIG_MACH_PCM027) += pcm027.o 59obj-$(CONFIG_MACH_PCM027) += pcm027.o
60obj-$(CONFIG_MACH_PCM990_BASEBOARD) += pcm990-baseboard.o 60obj-$(CONFIG_MACH_PCM990_BASEBOARD) += pcm990-baseboard.o
61obj-$(CONFIG_MACH_COLIBRI) += colibri-pxa270.o 61obj-$(CONFIG_MACH_COLIBRI) += colibri-pxa270.o
62obj-$(CONFIG_MACH_COLIBRI_PXA270_EVALBOARD) += colibri-pxa270-evalboard.o
63obj-$(CONFIG_MACH_COLIBRI_PXA270_INCOME) += colibri-pxa270-income.o
62obj-$(CONFIG_MACH_COLIBRI300) += colibri-pxa3xx.o colibri-pxa300.o 64obj-$(CONFIG_MACH_COLIBRI300) += colibri-pxa3xx.o colibri-pxa300.o
63obj-$(CONFIG_MACH_COLIBRI320) += colibri-pxa3xx.o colibri-pxa320.o 65obj-$(CONFIG_MACH_COLIBRI320) += colibri-pxa3xx.o colibri-pxa320.o
64obj-$(CONFIG_MACH_VPAC270) += vpac270.o 66obj-$(CONFIG_MACH_VPAC270) += vpac270.o
@@ -73,6 +75,7 @@ obj-$(CONFIG_PXA_EZX) += ezx.o
73obj-$(CONFIG_MACH_MP900C) += mp900.o 75obj-$(CONFIG_MACH_MP900C) += mp900.o
74obj-$(CONFIG_MACH_PALMTE2) += palmte2.o 76obj-$(CONFIG_MACH_PALMTE2) += palmte2.o
75obj-$(CONFIG_MACH_PALMTC) += palmtc.o 77obj-$(CONFIG_MACH_PALMTC) += palmtc.o
78obj-$(CONFIG_MACH_PALM27X) += palm27x.o
76obj-$(CONFIG_MACH_PALMT5) += palmt5.o 79obj-$(CONFIG_MACH_PALMT5) += palmt5.o
77obj-$(CONFIG_MACH_PALMTX) += palmtx.o 80obj-$(CONFIG_MACH_PALMTX) += palmtx.o
78obj-$(CONFIG_MACH_PALMZ72) += palmz72.o 81obj-$(CONFIG_MACH_PALMZ72) += palmz72.o
@@ -84,12 +87,6 @@ obj-$(CONFIG_MACH_POODLE) += poodle.o
84obj-$(CONFIG_MACH_TOSA) += tosa.o 87obj-$(CONFIG_MACH_TOSA) += tosa.o
85obj-$(CONFIG_MACH_ICONTROL) += icontrol.o mxm8x10.o 88obj-$(CONFIG_MACH_ICONTROL) += icontrol.o mxm8x10.o
86obj-$(CONFIG_ARCH_PXA_ESERIES) += eseries.o 89obj-$(CONFIG_ARCH_PXA_ESERIES) += eseries.o
87obj-$(CONFIG_MACH_E330) += e330.o
88obj-$(CONFIG_MACH_E350) += e350.o
89obj-$(CONFIG_MACH_E740) += e740.o
90obj-$(CONFIG_MACH_E750) += e750.o
91obj-$(CONFIG_MACH_E400) += e400.o
92obj-$(CONFIG_MACH_E800) += e800.o
93obj-$(CONFIG_MACH_RAUMFELD_RC) += raumfeld.o 90obj-$(CONFIG_MACH_RAUMFELD_RC) += raumfeld.o
94obj-$(CONFIG_MACH_RAUMFELD_CONNECTOR) += raumfeld.o 91obj-$(CONFIG_MACH_RAUMFELD_CONNECTOR) += raumfeld.o
95obj-$(CONFIG_MACH_RAUMFELD_SPEAKER) += raumfeld.o 92obj-$(CONFIG_MACH_RAUMFELD_SPEAKER) += raumfeld.o
diff --git a/arch/arm/mach-pxa/balloon3.c b/arch/arm/mach-pxa/balloon3.c
index f3b5ace815e5..9041340fee1d 100644
--- a/arch/arm/mach-pxa/balloon3.c
+++ b/arch/arm/mach-pxa/balloon3.c
@@ -22,9 +22,14 @@
22#include <linux/fb.h> 22#include <linux/fb.h>
23#include <linux/gpio.h> 23#include <linux/gpio.h>
24#include <linux/ioport.h> 24#include <linux/ioport.h>
25#include <linux/ucb1400.h>
25#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
26#include <linux/mtd/partitions.h> 27#include <linux/mtd/partitions.h>
27#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/i2c/pcf857x.h>
30#include <linux/mtd/nand.h>
31#include <linux/mtd/physmap.h>
32#include <linux/regulator/max1586.h>
28 33
29#include <asm/setup.h> 34#include <asm/setup.h>
30#include <asm/mach-types.h> 35#include <asm/mach-types.h>
@@ -51,6 +56,59 @@
51#include "generic.h" 56#include "generic.h"
52#include "devices.h" 57#include "devices.h"
53 58
59/******************************************************************************
60 * Pin configuration
61 ******************************************************************************/
62static unsigned long balloon3_pin_config[] __initdata = {
63 /* Select BTUART 'COM1/ttyS0' as IO option for pins 42/43/44/45 */
64 GPIO42_BTUART_RXD,
65 GPIO43_BTUART_TXD,
66 GPIO44_BTUART_CTS,
67 GPIO45_BTUART_RTS,
68
69 /* Reset, configured as GPIO wakeup source */
70 GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
71
72 /* LEDs */
73 GPIO9_GPIO, /* NAND activity LED */
74 GPIO10_GPIO, /* Heartbeat LED */
75
76 /* AC97 */
77 GPIO28_AC97_BITCLK,
78 GPIO29_AC97_SDATA_IN_0,
79 GPIO30_AC97_SDATA_OUT,
80 GPIO31_AC97_SYNC,
81 GPIO113_AC97_nRESET,
82 GPIO95_GPIO,
83
84 /* MMC */
85 GPIO32_MMC_CLK,
86 GPIO92_MMC_DAT_0,
87 GPIO109_MMC_DAT_1,
88 GPIO110_MMC_DAT_2,
89 GPIO111_MMC_DAT_3,
90 GPIO112_MMC_CMD,
91
92 /* USB Host */
93 GPIO88_USBH1_PWR,
94 GPIO89_USBH1_PEN,
95
96 /* PC Card */
97 GPIO48_nPOE,
98 GPIO49_nPWE,
99 GPIO50_nPIOR,
100 GPIO51_nPIOW,
101 GPIO85_nPCE_1,
102 GPIO54_nPCE_2,
103 GPIO79_PSKTSEL,
104 GPIO55_nPREG,
105 GPIO56_nPWAIT,
106 GPIO57_nIOIS16,
107};
108
109/******************************************************************************
110 * Compatibility: Parameter parsing
111 ******************************************************************************/
54static unsigned long balloon3_irq_enabled; 112static unsigned long balloon3_irq_enabled;
55 113
56static unsigned long balloon3_features_present = 114static unsigned long balloon3_features_present =
@@ -73,6 +131,321 @@ int __init parse_balloon3_features(char *arg)
73} 131}
74early_param("balloon3_features", parse_balloon3_features); 132early_param("balloon3_features", parse_balloon3_features);
75 133
134/******************************************************************************
135 * NOR Flash
136 ******************************************************************************/
137#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
138static struct mtd_partition balloon3_nor_partitions[] = {
139 {
140 .name = "Flash",
141 .offset = 0x00000000,
142 .size = MTDPART_SIZ_FULL,
143 }
144};
145
146static struct physmap_flash_data balloon3_flash_data[] = {
147 {
148 .width = 2, /* bankwidth in bytes */
149 .parts = balloon3_nor_partitions,
150 .nr_parts = ARRAY_SIZE(balloon3_nor_partitions)
151 }
152};
153
154static struct resource balloon3_flash_resource = {
155 .start = PXA_CS0_PHYS,
156 .end = PXA_CS0_PHYS + SZ_64M - 1,
157 .flags = IORESOURCE_MEM,
158};
159
160static struct platform_device balloon3_flash = {
161 .name = "physmap-flash",
162 .id = 0,
163 .resource = &balloon3_flash_resource,
164 .num_resources = 1,
165 .dev = {
166 .platform_data = balloon3_flash_data,
167 },
168};
169static void __init balloon3_nor_init(void)
170{
171 platform_device_register(&balloon3_flash);
172}
173#else
174static inline void balloon3_nor_init(void) {}
175#endif
176
177/******************************************************************************
178 * Audio and Touchscreen
179 ******************************************************************************/
180#if defined(CONFIG_TOUCHSCREEN_UCB1400) || \
181 defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
182static struct ucb1400_pdata vpac270_ucb1400_pdata = {
183 .irq = IRQ_GPIO(BALLOON3_GPIO_CODEC_IRQ),
184};
185
186
187static struct platform_device balloon3_ucb1400_device = {
188 .name = "ucb1400_core",
189 .id = -1,
190 .dev = {
191 .platform_data = &vpac270_ucb1400_pdata,
192 },
193};
194
195static void __init balloon3_ts_init(void)
196{
197 if (!balloon3_has(BALLOON3_FEATURE_AUDIO))
198 return;
199
200 pxa_set_ac97_info(NULL);
201 platform_device_register(&balloon3_ucb1400_device);
202}
203#else
204static inline void balloon3_ts_init(void) {}
205#endif
206
207/******************************************************************************
208 * Framebuffer
209 ******************************************************************************/
210#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
211static struct pxafb_mode_info balloon3_lcd_modes[] = {
212 {
213 .pixclock = 38000,
214 .xres = 480,
215 .yres = 640,
216 .bpp = 16,
217 .hsync_len = 8,
218 .left_margin = 8,
219 .right_margin = 8,
220 .vsync_len = 2,
221 .upper_margin = 4,
222 .lower_margin = 5,
223 .sync = 0,
224 },
225};
226
227static struct pxafb_mach_info balloon3_lcd_screen = {
228 .modes = balloon3_lcd_modes,
229 .num_modes = ARRAY_SIZE(balloon3_lcd_modes),
230 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
231};
232
233static void balloon3_backlight_power(int on)
234{
235 gpio_set_value(BALLOON3_GPIO_RUN_BACKLIGHT, on);
236}
237
238static void __init balloon3_lcd_init(void)
239{
240 int ret;
241
242 if (!balloon3_has(BALLOON3_FEATURE_TOPPOLY))
243 return;
244
245 ret = gpio_request(BALLOON3_GPIO_RUN_BACKLIGHT, "BKL-ON");
246 if (ret) {
247 pr_err("Requesting BKL-ON GPIO failed!\n");
248 goto err;
249 }
250
251 ret = gpio_direction_output(BALLOON3_GPIO_RUN_BACKLIGHT, 1);
252 if (ret) {
253 pr_err("Setting BKL-ON GPIO direction failed!\n");
254 goto err2;
255 }
256
257 balloon3_lcd_screen.pxafb_backlight_power = balloon3_backlight_power;
258 set_pxa_fb_info(&balloon3_lcd_screen);
259 return;
260
261err2:
262 gpio_free(BALLOON3_GPIO_RUN_BACKLIGHT);
263err:
264 return;
265}
266#else
267static inline void balloon3_lcd_init(void) {}
268#endif
269
270/******************************************************************************
271 * SD/MMC card controller
272 ******************************************************************************/
273#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
274static struct pxamci_platform_data balloon3_mci_platform_data = {
275 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
276 .gpio_card_detect = -1,
277 .gpio_card_ro = -1,
278 .gpio_power = -1,
279 .detect_delay_ms = 200,
280};
281
282static void __init balloon3_mmc_init(void)
283{
284 pxa_set_mci_info(&balloon3_mci_platform_data);
285}
286#else
287static inline void balloon3_mmc_init(void) {}
288#endif
289
290/******************************************************************************
291 * USB Gadget
292 ******************************************************************************/
293#if defined(CONFIG_USB_GADGET_PXA27X)||defined(CONFIG_USB_GADGET_PXA27X_MODULE)
294static void balloon3_udc_command(int cmd)
295{
296 if (cmd == PXA2XX_UDC_CMD_CONNECT)
297 UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
298 else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
299 UP2OCR &= ~UP2OCR_DPPUE;
300}
301
302static int balloon3_udc_is_connected(void)
303{
304 return 1;
305}
306
307static struct pxa2xx_udc_mach_info balloon3_udc_info __initdata = {
308 .udc_command = balloon3_udc_command,
309 .udc_is_connected = balloon3_udc_is_connected,
310 .gpio_pullup = -1,
311};
312
313static void __init balloon3_udc_init(void)
314{
315 pxa_set_udc_info(&balloon3_udc_info);
316 platform_device_register(&balloon3_gpio_vbus);
317}
318#else
319static inline void balloon3_udc_init(void) {}
320#endif
321
322/******************************************************************************
323 * IrDA
324 ******************************************************************************/
325#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
326static struct pxaficp_platform_data balloon3_ficp_platform_data = {
327 .transceiver_cap = IR_FIRMODE | IR_SIRMODE | IR_OFF,
328};
329
330static void __init balloon3_irda_init(void)
331{
332 pxa_set_ficp_info(&balloon3_ficp_platform_data);
333}
334#else
335static inline void balloon3_irda_init(void) {}
336#endif
337
338/******************************************************************************
339 * USB Host
340 ******************************************************************************/
341#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
342static struct pxaohci_platform_data balloon3_ohci_info = {
343 .port_mode = PMM_PERPORT_MODE,
344 .flags = ENABLE_PORT_ALL | POWER_CONTROL_LOW | POWER_SENSE_LOW,
345};
346
347static void __init balloon3_uhc_init(void)
348{
349 if (!balloon3_has(BALLOON3_FEATURE_OHCI))
350 return;
351 pxa_set_ohci_info(&balloon3_ohci_info);
352}
353#else
354static inline void balloon3_uhc_init(void) {}
355#endif
356
357/******************************************************************************
358 * LEDs
359 ******************************************************************************/
360#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
361struct gpio_led balloon3_gpio_leds[] = {
362 {
363 .name = "balloon3:green:idle",
364 .default_trigger = "heartbeat",
365 .gpio = BALLOON3_GPIO_LED_IDLE,
366 .active_low = 1,
367 }, {
368 .name = "balloon3:green:nand",
369 .default_trigger = "nand-disk",
370 .gpio = BALLOON3_GPIO_LED_NAND,
371 .active_low = 1,
372 },
373};
374
375static struct gpio_led_platform_data balloon3_gpio_led_info = {
376 .leds = balloon3_gpio_leds,
377 .num_leds = ARRAY_SIZE(balloon3_gpio_leds),
378};
379
380static struct platform_device balloon3_leds = {
381 .name = "leds-gpio",
382 .id = 0,
383 .dev = {
384 .platform_data = &balloon3_gpio_led_info,
385 }
386};
387
388struct gpio_led balloon3_pcf_gpio_leds[] = {
389 {
390 .name = "balloon3:green:led0",
391 .gpio = BALLOON3_PCF_GPIO_LED0,
392 .active_low = 1,
393 }, {
394 .name = "balloon3:green:led1",
395 .gpio = BALLOON3_PCF_GPIO_LED1,
396 .active_low = 1,
397 }, {
398 .name = "balloon3:orange:led2",
399 .gpio = BALLOON3_PCF_GPIO_LED2,
400 .active_low = 1,
401 }, {
402 .name = "balloon3:orange:led3",
403 .gpio = BALLOON3_PCF_GPIO_LED3,
404 .active_low = 1,
405 }, {
406 .name = "balloon3:orange:led4",
407 .gpio = BALLOON3_PCF_GPIO_LED4,
408 .active_low = 1,
409 }, {
410 .name = "balloon3:orange:led5",
411 .gpio = BALLOON3_PCF_GPIO_LED5,
412 .active_low = 1,
413 }, {
414 .name = "balloon3:red:led6",
415 .gpio = BALLOON3_PCF_GPIO_LED6,
416 .active_low = 1,
417 }, {
418 .name = "balloon3:red:led7",
419 .gpio = BALLOON3_PCF_GPIO_LED7,
420 .active_low = 1,
421 },
422};
423
424static struct gpio_led_platform_data balloon3_pcf_gpio_led_info = {
425 .leds = balloon3_pcf_gpio_leds,
426 .num_leds = ARRAY_SIZE(balloon3_pcf_gpio_leds),
427};
428
429static struct platform_device balloon3_pcf_leds = {
430 .name = "leds-gpio",
431 .id = 1,
432 .dev = {
433 .platform_data = &balloon3_pcf_gpio_led_info,
434 }
435};
436
437static void __init balloon3_leds_init(void)
438{
439 platform_device_register(&balloon3_leds);
440 platform_device_register(&balloon3_pcf_leds);
441}
442#else
443static inline void balloon3_leds_init(void) {}
444#endif
445
446/******************************************************************************
447 * FPGA IRQ
448 ******************************************************************************/
76static void balloon3_mask_irq(unsigned int irq) 449static void balloon3_mask_irq(unsigned int irq)
77{ 450{
78 int balloon3_irq = (irq - BALLOON3_IRQ(0)); 451 int balloon3_irq = (irq - BALLOON3_IRQ(0));
@@ -98,7 +471,6 @@ static void balloon3_irq_handler(unsigned int irq, struct irq_desc *desc)
98{ 471{
99 unsigned long pending = __raw_readl(BALLOON3_INT_CONTROL_REG) & 472 unsigned long pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
100 balloon3_irq_enabled; 473 balloon3_irq_enabled;
101
102 do { 474 do {
103 /* clear useless edge notification */ 475 /* clear useless edge notification */
104 if (desc->chip->ack) 476 if (desc->chip->ack)
@@ -132,201 +504,259 @@ static void __init balloon3_init_irq(void)
132 "enabled\n", __func__, BALLOON3_AUX_NIRQ); 504 "enabled\n", __func__, BALLOON3_AUX_NIRQ);
133} 505}
134 506
135static unsigned long balloon3_ac97_pin_config[] = { 507/******************************************************************************
136 GPIO28_AC97_BITCLK, 508 * GPIO expander
137 GPIO29_AC97_SDATA_IN_0, 509 ******************************************************************************/
138 GPIO30_AC97_SDATA_OUT, 510#if defined(CONFIG_GPIO_PCF857X) || defined(CONFIG_GPIO_PCF857X_MODULE)
139 GPIO31_AC97_SYNC, 511static struct pcf857x_platform_data balloon3_pcf857x_pdata = {
140 GPIO113_AC97_nRESET, 512 .gpio_base = BALLOON3_PCF_GPIO_BASE,
141}; 513 .n_latch = 0,
142 514 .setup = NULL,
143static void balloon3_backlight_power(int on) 515 .teardown = NULL,
144{ 516 .context = NULL,
145 pr_debug("%s: power is %s\n", __func__, on ? "on" : "off");
146 gpio_set_value(BALLOON3_GPIO_RUN_BACKLIGHT, on);
147}
148
149static unsigned long balloon3_lcd_pin_config[] = {
150 /* LCD - 16bpp Active TFT */
151 GPIOxx_LCD_TFT_16BPP,
152
153 GPIO99_GPIO, /* Backlight */
154}; 517};
155 518
156static struct pxafb_mode_info balloon3_lcd_modes[] = { 519static struct i2c_board_info __initdata balloon3_i2c_devs[] = {
157 { 520 {
158 .pixclock = 38000, 521 I2C_BOARD_INFO("pcf8574a", 0x38),
159 .xres = 480, 522 .platform_data = &balloon3_pcf857x_pdata,
160 .yres = 640,
161 .bpp = 16,
162 .hsync_len = 8,
163 .left_margin = 8,
164 .right_margin = 8,
165 .vsync_len = 2,
166 .upper_margin = 4,
167 .lower_margin = 5,
168 .sync = 0,
169 }, 523 },
170}; 524};
171 525
172static struct pxafb_mach_info balloon3_pxafb_info = { 526static void __init balloon3_i2c_init(void)
173 .modes = balloon3_lcd_modes, 527{
174 .num_modes = ARRAY_SIZE(balloon3_lcd_modes), 528 pxa_set_i2c_info(NULL);
175 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL, 529 i2c_register_board_info(0, ARRAY_AND_SIZE(balloon3_i2c_devs));
176 .pxafb_backlight_power = balloon3_backlight_power, 530}
177}; 531#else
532static inline void balloon3_i2c_init(void) {}
533#endif
534
535/******************************************************************************
536 * NAND
537 ******************************************************************************/
538#if defined(CONFIG_MTD_NAND_PLATFORM)||defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
539static uint16_t balloon3_ctl =
540 BALLOON3_NAND_CONTROL_FLCE0 | BALLOON3_NAND_CONTROL_FLCE1 |
541 BALLOON3_NAND_CONTROL_FLCE2 | BALLOON3_NAND_CONTROL_FLCE3 |
542 BALLOON3_NAND_CONTROL_FLWP;
543
544static void balloon3_nand_cmd_ctl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
545{
546 struct nand_chip *this = mtd->priv;
178 547
179static unsigned long balloon3_mmc_pin_config[] = { 548 if (ctrl & NAND_CTRL_CHANGE) {
180 GPIO32_MMC_CLK, 549 if (ctrl & NAND_CLE)
181 GPIO92_MMC_DAT_0, 550 balloon3_ctl |= BALLOON3_NAND_CONTROL_FLCLE;
182 GPIO109_MMC_DAT_1, 551 else
183 GPIO110_MMC_DAT_2, 552 balloon3_ctl &= ~BALLOON3_NAND_CONTROL_FLCLE;
184 GPIO111_MMC_DAT_3,
185 GPIO112_MMC_CMD,
186};
187 553
188static void balloon3_mci_setpower(struct device *dev, unsigned int vdd) 554 if (ctrl & NAND_ALE)
189{ 555 balloon3_ctl |= BALLOON3_NAND_CONTROL_FLALE;
190 struct pxamci_platform_data *p_d = dev->platform_data; 556 else
191 557 balloon3_ctl &= ~BALLOON3_NAND_CONTROL_FLALE;
192 if ((1 << vdd) & p_d->ocr_mask) { 558
193 pr_debug("%s: on\n", __func__); 559 __raw_writel(balloon3_ctl, BALLOON3_NAND_CONTROL_REG);
194 /* FIXME something to prod here? */
195 } else {
196 pr_debug("%s: off\n", __func__);
197 /* FIXME something to prod here? */
198 } 560 }
561
562 if (cmd != NAND_CMD_NONE)
563 writeb(cmd, this->IO_ADDR_W);
199} 564}
200 565
201static struct pxamci_platform_data balloon3_mci_platform_data = { 566static void balloon3_nand_select_chip(struct mtd_info *mtd, int chip)
202 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34, 567{
203 .setpower = balloon3_mci_setpower, 568 if (chip < 0 || chip > 3)
204}; 569 return;
205 570
206static int balloon3_udc_is_connected(void) 571 balloon3_ctl |= BALLOON3_NAND_CONTROL_FLCE0 |
572 BALLOON3_NAND_CONTROL_FLCE1 |
573 BALLOON3_NAND_CONTROL_FLCE2 |
574 BALLOON3_NAND_CONTROL_FLCE3;
575
576 /* Deassert correct nCE line */
577 balloon3_ctl &= ~(BALLOON3_NAND_CONTROL_FLCE0 << chip);
578
579 __raw_writew(balloon3_ctl, BALLOON3_NAND_CONTROL_REG);
580}
581
582static int balloon3_nand_probe(struct platform_device *pdev)
207{ 583{
208 pr_debug("%s: udc connected\n", __func__); 584 void __iomem *temp_map;
209 return 1; 585 uint16_t ver;
586 int ret;
587
588 __raw_writew(BALLOON3_NAND_CONTROL2_16BIT, BALLOON3_NAND_CONTROL2_REG);
589
590 ver = __raw_readw(BALLOON3_FPGA_VER);
591 if (ver > 0x0201)
592 pr_warn("The FPGA code, version 0x%04x, is newer than rel-0.3. "
593 "NAND support might be broken in this version!", ver);
594
595 /* Power up the NAND chips */
596 ret = gpio_request(BALLOON3_GPIO_RUN_NAND, "NAND");
597 if (ret)
598 goto err1;
599
600 ret = gpio_direction_output(BALLOON3_GPIO_RUN_NAND, 1);
601 if (ret)
602 goto err2;
603
604 gpio_set_value(BALLOON3_GPIO_RUN_NAND, 1);
605
606 /* Deassert all nCE lines and write protect line */
607 __raw_writel(balloon3_ctl, BALLOON3_NAND_CONTROL_REG);
608 return 0;
609
610err2:
611 gpio_free(BALLOON3_GPIO_RUN_NAND);
612err1:
613 return ret;
210} 614}
211 615
212static void balloon3_udc_command(int cmd) 616static void balloon3_nand_remove(struct platform_device *pdev)
213{ 617{
214 switch (cmd) { 618 /* Power down the NAND chips */
215 case PXA2XX_UDC_CMD_CONNECT: 619 gpio_set_value(BALLOON3_GPIO_RUN_NAND, 0);
216 UP2OCR |= (UP2OCR_DPPUE + UP2OCR_DPPUBE); 620 gpio_free(BALLOON3_GPIO_RUN_NAND);
217 pr_debug("%s: connect\n", __func__);
218 break;
219 case PXA2XX_UDC_CMD_DISCONNECT:
220 UP2OCR &= ~UP2OCR_DPPUE;
221 pr_debug("%s: disconnect\n", __func__);
222 break;
223 }
224} 621}
225 622
226static struct pxa2xx_udc_mach_info balloon3_udc_info = { 623static struct mtd_partition balloon3_partition_info[] = {
227 .udc_is_connected = balloon3_udc_is_connected, 624 [0] = {
228 .udc_command = balloon3_udc_command, 625 .name = "Boot",
626 .offset = 0,
627 .size = SZ_4M,
628 },
629 [1] = {
630 .name = "RootFS",
631 .offset = MTDPART_OFS_APPEND,
632 .size = MTDPART_SIZ_FULL
633 },
229}; 634};
230 635
231static struct pxaficp_platform_data balloon3_ficp_platform_data = { 636static const char *balloon3_part_probes[] = { "cmdlinepart", NULL };
232 .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
233};
234 637
235static unsigned long balloon3_ohci_pin_config[] = { 638struct platform_nand_data balloon3_nand_pdata = {
236 GPIO88_USBH1_PWR, 639 .chip = {
237 GPIO89_USBH1_PEN, 640 .nr_chips = 4,
641 .chip_offset = 0,
642 .nr_partitions = ARRAY_SIZE(balloon3_partition_info),
643 .partitions = balloon3_partition_info,
644 .chip_delay = 50,
645 .part_probe_types = balloon3_part_probes,
646 },
647 .ctrl = {
648 .hwcontrol = 0,
649 .dev_ready = 0,
650 .select_chip = balloon3_nand_select_chip,
651 .cmd_ctrl = balloon3_nand_cmd_ctl,
652 .probe = balloon3_nand_probe,
653 .remove = balloon3_nand_remove,
654 },
238}; 655};
239 656
240static struct pxaohci_platform_data balloon3_ohci_platform_data = { 657static struct resource balloon3_nand_resource[] = {
241 .port_mode = PMM_PERPORT_MODE, 658 [0] = {
242 .flags = ENABLE_PORT_ALL | POWER_CONTROL_LOW | POWER_SENSE_LOW, 659 .start = BALLOON3_NAND_BASE,
660 .end = BALLOON3_NAND_BASE + 0x4,
661 .flags = IORESOURCE_MEM,
662 },
243}; 663};
244 664
245static unsigned long balloon3_pin_config[] __initdata = { 665static struct platform_device balloon3_nand = {
246 /* Select BTUART 'COM1/ttyS0' as IO option for pins 42/43/44/45 */ 666 .name = "gen_nand",
247 GPIO42_BTUART_RXD, 667 .num_resources = ARRAY_SIZE(balloon3_nand_resource),
248 GPIO43_BTUART_TXD, 668 .resource = balloon3_nand_resource,
249 GPIO44_BTUART_CTS, 669 .id = -1,
250 GPIO45_BTUART_RTS, 670 .dev = {
251 671 .platform_data = &balloon3_nand_pdata,
252 /* Wakeup GPIO */ 672 }
253 GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
254
255 /* NAND & IDLE LED GPIOs */
256 GPIO9_GPIO,
257 GPIO10_GPIO,
258}; 673};
259 674
260static struct gpio_led balloon3_gpio_leds[] = { 675static void __init balloon3_nand_init(void)
676{
677 platform_device_register(&balloon3_nand);
678}
679#else
680static inline void balloon3_nand_init(void) {}
681#endif
682
683/******************************************************************************
684 * Core power regulator
685 ******************************************************************************/
686#if defined(CONFIG_REGULATOR_MAX1586) || \
687 defined(CONFIG_REGULATOR_MAX1586_MODULE)
688static struct regulator_consumer_supply balloon3_max1587a_consumers[] = {
261 { 689 {
262 .name = "balloon3:green:idle", 690 .supply = "vcc_core",
263 .default_trigger = "heartbeat", 691 }
264 .gpio = BALLOON3_GPIO_LED_IDLE, 692};
265 .active_low = 1, 693
694static struct regulator_init_data balloon3_max1587a_v3_info = {
695 .constraints = {
696 .name = "vcc_core range",
697 .min_uV = 900000,
698 .max_uV = 1705000,
699 .always_on = 1,
700 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
266 }, 701 },
702 .consumer_supplies = balloon3_max1587a_consumers,
703 .num_consumer_supplies = ARRAY_SIZE(balloon3_max1587a_consumers),
704};
705
706static struct max1586_subdev_data balloon3_max1587a_subdevs[] = {
267 { 707 {
268 .name = "balloon3:green:nand", 708 .name = "vcc_core",
269 .default_trigger = "nand-disk", 709 .id = MAX1586_V3,
270 .gpio = BALLOON3_GPIO_LED_NAND, 710 .platform_data = &balloon3_max1587a_v3_info,
271 .active_low = 1, 711 }
272 },
273}; 712};
274 713
275static struct gpio_led_platform_data balloon3_gpio_leds_platform_data = { 714static struct max1586_platform_data balloon3_max1587a_info = {
276 .leds = balloon3_gpio_leds, 715 .subdevs = balloon3_max1587a_subdevs,
277 .num_leds = ARRAY_SIZE(balloon3_gpio_leds), 716 .num_subdevs = ARRAY_SIZE(balloon3_max1587a_subdevs),
717 .v3_gain = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
278}; 718};
279 719
280static struct platform_device balloon3led_device = { 720static struct i2c_board_info __initdata balloon3_pi2c_board_info[] = {
281 .name = "leds-gpio", 721 {
282 .id = -1, 722 I2C_BOARD_INFO("max1586", 0x14),
283 .dev = { 723 .platform_data = &balloon3_max1587a_info,
284 .platform_data = &balloon3_gpio_leds_platform_data,
285 }, 724 },
286}; 725};
287 726
288static void __init balloon3_init(void) 727static void __init balloon3_pmic_init(void)
289{ 728{
290 pr_info("Initialising Balloon3\n"); 729 pxa27x_set_i2c_power_info(NULL);
730 i2c_register_board_info(1, ARRAY_AND_SIZE(balloon3_pi2c_board_info));
731}
732#else
733static inline void balloon3_pmic_init(void) {}
734#endif
291 735
292 /* system bus arbiter setting 736/******************************************************************************
293 * - Core_Park 737 * Machine init
294 * - LCD_wt:DMA_wt:CORE_Wt = 2:3:4 738 ******************************************************************************/
295 */ 739static void __init balloon3_init(void)
740{
296 ARB_CNTRL = ARB_CORE_PARK | 0x234; 741 ARB_CNTRL = ARB_CORE_PARK | 0x234;
297 742
743 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_pin_config));
744
298 pxa_set_ffuart_info(NULL); 745 pxa_set_ffuart_info(NULL);
299 pxa_set_btuart_info(NULL); 746 pxa_set_btuart_info(NULL);
300 pxa_set_stuart_info(NULL); 747 pxa_set_stuart_info(NULL);
301 748
302 pxa_set_i2c_info(NULL); 749 balloon3_i2c_init();
303 if (balloon3_has(BALLOON3_FEATURE_AUDIO)) { 750 balloon3_irda_init();
304 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_ac97_pin_config)); 751 balloon3_lcd_init();
305 pxa_set_ac97_info(NULL); 752 balloon3_leds_init();
306 } 753 balloon3_mmc_init();
307 754 balloon3_nand_init();
308 if (balloon3_has(BALLOON3_FEATURE_TOPPOLY)) { 755 balloon3_nor_init();
309 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_lcd_pin_config)); 756 balloon3_pmic_init();
310 gpio_request(BALLOON3_GPIO_RUN_BACKLIGHT, 757 balloon3_ts_init();
311 "LCD Backlight Power"); 758 balloon3_udc_init();
312 gpio_direction_output(BALLOON3_GPIO_RUN_BACKLIGHT, 1); 759 balloon3_uhc_init();
313 set_pxa_fb_info(&balloon3_pxafb_info);
314 }
315
316 if (balloon3_has(BALLOON3_FEATURE_MMC)) {
317 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_mmc_pin_config));
318 pxa_set_mci_info(&balloon3_mci_platform_data);
319 }
320 pxa_set_ficp_info(&balloon3_ficp_platform_data);
321 if (balloon3_has(BALLOON3_FEATURE_OHCI)) {
322 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_ohci_pin_config));
323 pxa_set_ohci_info(&balloon3_ohci_platform_data);
324 }
325 pxa_set_udc_info(&balloon3_udc_info);
326
327 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_pin_config));
328
329 platform_device_register(&balloon3led_device);
330} 760}
331 761
332static struct map_desc balloon3_io_desc[] __initdata = { 762static struct map_desc balloon3_io_desc[] __initdata = {
diff --git a/arch/arm/mach-pxa/cm-x300.c b/arch/arm/mach-pxa/cm-x300.c
index fdda6be6c391..c70e6c2f4e7c 100644
--- a/arch/arm/mach-pxa/cm-x300.c
+++ b/arch/arm/mach-pxa/cm-x300.c
@@ -689,6 +689,7 @@ static void __init cm_x300_init_da9030(void)
689{ 689{
690 pxa3xx_set_i2c_power_info(&cm_x300_pwr_i2c_info); 690 pxa3xx_set_i2c_power_info(&cm_x300_pwr_i2c_info);
691 i2c_register_board_info(1, &cm_x300_pmic_info, 1); 691 i2c_register_board_info(1, &cm_x300_pmic_info, 1);
692 set_irq_wake(IRQ_WAKEUP0, 1);
692} 693}
693 694
694static void __init cm_x300_init_wi2wi(void) 695static void __init cm_x300_init_wi2wi(void)
@@ -745,9 +746,10 @@ static void __init cm_x300_init(void)
745{ 746{
746 cm_x300_init_mfp(); 747 cm_x300_init_mfp();
747 748
748 pxa_set_ffuart_info(NULL);
749 pxa_set_btuart_info(NULL); 749 pxa_set_btuart_info(NULL);
750 pxa_set_stuart_info(NULL); 750 pxa_set_stuart_info(NULL);
751 if (cpu_is_pxa300())
752 pxa_set_ffuart_info(NULL);
751 753
752 cm_x300_init_da9030(); 754 cm_x300_init_da9030();
753 cm_x300_init_dm9000(); 755 cm_x300_init_dm9000();
diff --git a/arch/arm/mach-pxa/colibri-pxa270-evalboard.c b/arch/arm/mach-pxa/colibri-pxa270-evalboard.c
new file mode 100644
index 000000000000..0f3b632c3b14
--- /dev/null
+++ b/arch/arm/mach-pxa/colibri-pxa270-evalboard.c
@@ -0,0 +1,111 @@
1/*
2 * linux/arch/arm/mach-pxa/colibri-pxa270-evalboard.c
3 *
4 * Support for Toradex PXA270 based Colibri Evaluation Carrier Board
5 * Daniel Mack <daniel@caiaq.de>
6 * Marek Vasut <marek.vasut@gmail.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#include <linux/init.h>
14#include <linux/kernel.h>
15#include <linux/platform_device.h>
16#include <linux/sysdev.h>
17#include <linux/interrupt.h>
18#include <linux/gpio.h>
19#include <asm/mach-types.h>
20#include <mach/hardware.h>
21#include <asm/mach/arch.h>
22
23#include <mach/pxa27x.h>
24#include <mach/colibri.h>
25#include <mach/mmc.h>
26#include <mach/ohci.h>
27#include <mach/pxa27x-udc.h>
28
29#include "generic.h"
30#include "devices.h"
31
32/******************************************************************************
33 * Pin configuration
34 ******************************************************************************/
35static mfp_cfg_t colibri_pxa270_evalboard_pin_config[] __initdata = {
36 /* MMC */
37 GPIO32_MMC_CLK,
38 GPIO92_MMC_DAT_0,
39 GPIO109_MMC_DAT_1,
40 GPIO110_MMC_DAT_2,
41 GPIO111_MMC_DAT_3,
42 GPIO112_MMC_CMD,
43 GPIO0_GPIO, /* SD detect */
44
45 /* FFUART */
46 GPIO39_FFUART_TXD,
47 GPIO34_FFUART_RXD,
48
49 /* UHC */
50 GPIO88_USBH1_PWR,
51 GPIO89_USBH1_PEN,
52 GPIO119_USBH2_PWR,
53 GPIO120_USBH2_PEN,
54};
55
56/******************************************************************************
57 * SD/MMC card controller
58 ******************************************************************************/
59#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
60static struct pxamci_platform_data colibri_pxa270_mci_platform_data = {
61 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
62 .gpio_power = -1,
63 .gpio_card_detect = GPIO0_COLIBRI_PXA270_SD_DETECT,
64 .gpio_card_ro = -1,
65 .detect_delay_ms = 200,
66};
67
68static void __init colibri_pxa270_mmc_init(void)
69{
70 pxa_set_mci_info(&colibri_pxa270_mci_platform_data);
71}
72#else
73static inline void colibri_pxa270_mmc_init(void) {}
74#endif
75
76/******************************************************************************
77 * USB Host
78 ******************************************************************************/
79#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
80static int colibri_pxa270_ohci_init(struct device *dev)
81{
82 UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE;
83 return 0;
84}
85
86static struct pxaohci_platform_data colibri_pxa270_ohci_info = {
87 .port_mode = PMM_PERPORT_MODE,
88 .flags = ENABLE_PORT1 | ENABLE_PORT2 |
89 POWER_CONTROL_LOW | POWER_SENSE_LOW,
90 .init = colibri_pxa270_ohci_init,
91};
92
93static void __init colibri_pxa270_uhc_init(void)
94{
95 pxa_set_ohci_info(&colibri_pxa270_ohci_info);
96}
97#else
98static inline void colibri_pxa270_uhc_init(void) {}
99#endif
100
101void __init colibri_pxa270_evalboard_init(void)
102{
103 pxa2xx_mfp_config(ARRAY_AND_SIZE(colibri_pxa270_evalboard_pin_config));
104 pxa_set_ffuart_info(NULL);
105 pxa_set_btuart_info(NULL);
106 pxa_set_stuart_info(NULL);
107
108 colibri_pxa270_mmc_init();
109 colibri_pxa270_uhc_init();
110}
111
diff --git a/arch/arm/mach-pxa/colibri-pxa270-income.c b/arch/arm/mach-pxa/colibri-pxa270-income.c
new file mode 100644
index 000000000000..37f0f3ed7c61
--- /dev/null
+++ b/arch/arm/mach-pxa/colibri-pxa270-income.c
@@ -0,0 +1,272 @@
1/*
2 * linux/arch/arm/mach-pxa/income.c
3 *
4 * Support for Income s.r.o. SH-Dmaster PXA270 SBC
5 *
6 * Copyright (C) 2010
7 * Marek Vasut <marek.vasut@gmail.com>
8 * Pavel Revak <palo@bielyvlk.sk>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/bitops.h>
16#include <linux/delay.h>
17#include <linux/gpio.h>
18#include <linux/init.h>
19#include <linux/interrupt.h>
20#include <linux/ioport.h>
21#include <linux/kernel.h>
22#include <linux/platform_device.h>
23#include <linux/pwm_backlight.h>
24#include <linux/sysdev.h>
25
26#include <asm/irq.h>
27#include <asm/mach-types.h>
28
29#include <mach/hardware.h>
30#include <mach/mmc.h>
31#include <mach/ohci.h>
32#include <mach/pxa27x.h>
33#include <mach/pxa27x-udc.h>
34#include <mach/pxafb.h>
35
36#include <plat/i2c.h>
37
38#include "devices.h"
39#include "generic.h"
40
41#define GPIO114_INCOME_ETH_IRQ (114)
42#define GPIO0_INCOME_SD_DETECT (0)
43#define GPIO0_INCOME_SD_RO (1)
44#define GPIO54_INCOME_LED_A (54)
45#define GPIO55_INCOME_LED_B (55)
46#define GPIO113_INCOME_TS_IRQ (113)
47
48/******************************************************************************
49 * Pin configuration
50 ******************************************************************************/
51static mfp_cfg_t income_pin_config[] __initdata = {
52 /* MMC */
53 GPIO32_MMC_CLK,
54 GPIO92_MMC_DAT_0,
55 GPIO109_MMC_DAT_1,
56 GPIO110_MMC_DAT_2,
57 GPIO111_MMC_DAT_3,
58 GPIO112_MMC_CMD,
59 GPIO0_GPIO, /* SD detect */
60 GPIO1_GPIO, /* SD read-only */
61
62 /* FFUART */
63 GPIO39_FFUART_TXD,
64 GPIO34_FFUART_RXD,
65
66 /* BFUART */
67 GPIO42_BTUART_RXD,
68 GPIO43_BTUART_TXD,
69 GPIO45_BTUART_RTS,
70
71 /* STUART */
72 GPIO46_STUART_RXD,
73 GPIO47_STUART_TXD,
74
75 /* UHC */
76 GPIO88_USBH1_PWR,
77 GPIO89_USBH1_PEN,
78
79 /* LCD */
80 GPIOxx_LCD_TFT_16BPP,
81
82 /* PWM */
83 GPIO16_PWM0_OUT,
84
85 /* I2C */
86 GPIO117_I2C_SCL,
87 GPIO118_I2C_SDA,
88
89 /* LED */
90 GPIO54_GPIO, /* LED A */
91 GPIO55_GPIO, /* LED B */
92};
93
94/******************************************************************************
95 * SD/MMC card controller
96 ******************************************************************************/
97#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
98static struct pxamci_platform_data income_mci_platform_data = {
99 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
100 .gpio_power = -1,
101 .gpio_card_detect = GPIO0_INCOME_SD_DETECT,
102 .gpio_card_ro = GPIO0_INCOME_SD_RO,
103 .detect_delay_ms = 200,
104};
105
106static void __init income_mmc_init(void)
107{
108 pxa_set_mci_info(&income_mci_platform_data);
109}
110#else
111static inline void income_mmc_init(void) {}
112#endif
113
114/******************************************************************************
115 * USB Host
116 ******************************************************************************/
117#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
118static struct pxaohci_platform_data income_ohci_info = {
119 .port_mode = PMM_PERPORT_MODE,
120 .flags = ENABLE_PORT1 | POWER_CONTROL_LOW | POWER_SENSE_LOW,
121};
122
123static void __init income_uhc_init(void)
124{
125 pxa_set_ohci_info(&income_ohci_info);
126}
127#else
128static inline void income_uhc_init(void) {}
129#endif
130
131/******************************************************************************
132 * LED
133 ******************************************************************************/
134#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
135struct gpio_led income_gpio_leds[] = {
136 {
137 .name = "income:green:leda",
138 .default_trigger = "none",
139 .gpio = GPIO54_INCOME_LED_A,
140 .active_low = 1,
141 },
142 {
143 .name = "income:green:ledb",
144 .default_trigger = "none",
145 .gpio = GPIO55_INCOME_LED_B,
146 .active_low = 1,
147 }
148};
149
150static struct gpio_led_platform_data income_gpio_led_info = {
151 .leds = income_gpio_leds,
152 .num_leds = ARRAY_SIZE(income_gpio_leds),
153};
154
155static struct platform_device income_leds = {
156 .name = "leds-gpio",
157 .id = -1,
158 .dev = {
159 .platform_data = &income_gpio_led_info,
160 }
161};
162
163static void __init income_led_init(void)
164{
165 platform_device_register(&income_leds);
166}
167#else
168static inline void income_led_init(void) {}
169#endif
170
171/******************************************************************************
172 * I2C
173 ******************************************************************************/
174#if defined(CONFIG_I2C_PXA) || defined(CONFIG_I2C_PXA_MODULE)
175static struct i2c_board_info __initdata income_i2c_devs[] = {
176 {
177 I2C_BOARD_INFO("ds1340", 0x68),
178 }, {
179 I2C_BOARD_INFO("lm75", 0x4f),
180 },
181};
182
183static void __init income_i2c_init(void)
184{
185 pxa_set_i2c_info(NULL);
186 pxa27x_set_i2c_power_info(NULL);
187 i2c_register_board_info(0, ARRAY_AND_SIZE(income_i2c_devs));
188}
189#else
190static inline void income_i2c_init(void) {}
191#endif
192
193/******************************************************************************
194 * Framebuffer
195 ******************************************************************************/
196#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
197static struct pxafb_mode_info income_lcd_modes[] = {
198{
199 .pixclock = 144700,
200 .xres = 320,
201 .yres = 240,
202 .bpp = 32,
203 .depth = 18,
204
205 .left_margin = 10,
206 .right_margin = 10,
207 .upper_margin = 7,
208 .lower_margin = 8,
209
210 .hsync_len = 20,
211 .vsync_len = 2,
212
213 .sync = FB_SYNC_VERT_HIGH_ACT,
214},
215};
216
217static struct pxafb_mach_info income_lcd_screen = {
218 .modes = income_lcd_modes,
219 .num_modes = ARRAY_SIZE(income_lcd_modes),
220 .lcd_conn = LCD_COLOR_TFT_18BPP | LCD_PCLK_EDGE_FALL,
221};
222
223static void __init income_lcd_init(void)
224{
225 set_pxa_fb_info(&income_lcd_screen);
226}
227#else
228static inline void income_lcd_init(void) {}
229#endif
230
231/******************************************************************************
232 * Backlight
233 ******************************************************************************/
234#if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM__MODULE)
235static struct platform_pwm_backlight_data income_backlight_data = {
236 .pwm_id = 0,
237 .max_brightness = 0x3ff,
238 .dft_brightness = 0x1ff,
239 .pwm_period_ns = 1000000,
240};
241
242static struct platform_device income_backlight = {
243 .name = "pwm-backlight",
244 .dev = {
245 .parent = &pxa27x_device_pwm0.dev,
246 .platform_data = &income_backlight_data,
247 },
248};
249
250static void __init income_pwm_init(void)
251{
252 platform_device_register(&income_backlight);
253}
254#else
255static inline void income_pwm_init(void) {}
256#endif
257
258void __init colibri_pxa270_income_boardinit(void)
259{
260 pxa2xx_mfp_config(ARRAY_AND_SIZE(income_pin_config));
261 pxa_set_ffuart_info(NULL);
262 pxa_set_btuart_info(NULL);
263 pxa_set_stuart_info(NULL);
264
265 income_mmc_init();
266 income_uhc_init();
267 income_led_init();
268 income_i2c_init();
269 income_lcd_init();
270 income_pwm_init();
271}
272
diff --git a/arch/arm/mach-pxa/colibri-pxa270.c b/arch/arm/mach-pxa/colibri-pxa270.c
index 061c45316de8..98673ac6efd0 100644
--- a/arch/arm/mach-pxa/colibri-pxa270.c
+++ b/arch/arm/mach-pxa/colibri-pxa270.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * Support for Toradex PXA270 based Colibri module 4 * Support for Toradex PXA270 based Colibri module
5 * Daniel Mack <daniel@caiaq.de> 5 * Daniel Mack <daniel@caiaq.de>
6 * Marek Vasut <marek.vasut@gmail.com>
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 9 * it under the terms of the GNU General Public License version 2 as
@@ -10,49 +11,55 @@
10 */ 11 */
11 12
12#include <linux/init.h> 13#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/platform_device.h>
15#include <linux/sysdev.h>
16#include <linux/interrupt.h> 14#include <linux/interrupt.h>
17#include <linux/bitops.h> 15#include <linux/kernel.h>
18#include <linux/ioport.h>
19#include <linux/delay.h>
20#include <linux/mtd/mtd.h> 16#include <linux/mtd/mtd.h>
21#include <linux/mtd/partitions.h> 17#include <linux/mtd/partitions.h>
22#include <linux/mtd/physmap.h> 18#include <linux/mtd/physmap.h>
23#include <linux/gpio.h> 19#include <linux/platform_device.h>
24#include <asm/mach-types.h> 20#include <linux/sysdev.h>
25#include <mach/hardware.h> 21#include <linux/ucb1400.h>
26#include <asm/irq.h> 22
27#include <asm/sizes.h>
28#include <asm/mach/arch.h> 23#include <asm/mach/arch.h>
29#include <asm/mach/map.h>
30#include <asm/mach/irq.h>
31#include <asm/mach/flash.h> 24#include <asm/mach/flash.h>
25#include <asm/mach-types.h>
26#include <asm/sizes.h>
32 27
33#include <mach/pxa27x.h> 28#include <mach/audio.h>
34#include <mach/colibri.h> 29#include <mach/colibri.h>
30#include <mach/pxa27x.h>
35 31
36#include "generic.h"
37#include "devices.h" 32#include "devices.h"
33#include "generic.h"
38 34
39/* 35/******************************************************************************
40 * GPIO configuration 36 * Pin configuration
41 */ 37 ******************************************************************************/
42static mfp_cfg_t colibri_pxa270_pin_config[] __initdata = { 38static mfp_cfg_t colibri_pxa270_pin_config[] __initdata = {
39 /* Ethernet */
43 GPIO78_nCS_2, /* Ethernet CS */ 40 GPIO78_nCS_2, /* Ethernet CS */
44 GPIO114_GPIO, /* Ethernet IRQ */ 41 GPIO114_GPIO, /* Ethernet IRQ */
42
43 /* AC97 */
44 GPIO28_AC97_BITCLK,
45 GPIO29_AC97_SDATA_IN_0,
46 GPIO30_AC97_SDATA_OUT,
47 GPIO31_AC97_SYNC,
48 GPIO95_AC97_nRESET,
49 GPIO98_AC97_SYSCLK,
50 GPIO113_GPIO, /* Touchscreen IRQ */
45}; 51};
46 52
47/* 53/******************************************************************************
48 * NOR flash 54 * NOR Flash
49 */ 55 ******************************************************************************/
56#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
50static struct mtd_partition colibri_partitions[] = { 57static struct mtd_partition colibri_partitions[] = {
51 { 58 {
52 .name = "Bootloader", 59 .name = "Bootloader",
53 .offset = 0x00000000, 60 .offset = 0x00000000,
54 .size = 0x00040000, 61 .size = 0x00040000,
55 .mask_flags = MTD_WRITEABLE /* force read-only */ 62 .mask_flags = MTD_WRITEABLE /* force read-only */
56 }, { 63 }, {
57 .name = "Kernel", 64 .name = "Kernel",
58 .offset = 0x00040000, 65 .offset = 0x00040000,
@@ -90,50 +97,113 @@ static struct platform_device colibri_pxa270_flash_device = {
90 .num_resources = 1, 97 .num_resources = 1,
91}; 98};
92 99
93/* 100static void __init colibri_pxa270_nor_init(void)
94 * DM9000 Ethernet 101{
95 */ 102 platform_device_register(&colibri_pxa270_flash_device);
96#if defined(CONFIG_DM9000) 103}
97static struct resource dm9000_resources[] = { 104#else
98 [0] = { 105static inline void colibri_pxa270_nor_init(void) {}
99 .start = COLIBRI_PXA270_ETH_PHYS, 106#endif
100 .end = COLIBRI_PXA270_ETH_PHYS + 3, 107
108/******************************************************************************
109 * Ethernet
110 ******************************************************************************/
111#if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
112static struct resource colibri_pxa270_dm9000_resources[] = {
113 {
114 .start = PXA_CS2_PHYS,
115 .end = PXA_CS2_PHYS + 3,
101 .flags = IORESOURCE_MEM, 116 .flags = IORESOURCE_MEM,
102 }, 117 },
103 [1] = { 118 {
104 .start = COLIBRI_PXA270_ETH_PHYS + 4, 119 .start = PXA_CS2_PHYS + 4,
105 .end = COLIBRI_PXA270_ETH_PHYS + 4 + 500, 120 .end = PXA_CS2_PHYS + 4 + 500,
106 .flags = IORESOURCE_MEM, 121 .flags = IORESOURCE_MEM,
107 }, 122 },
108 [2] = { 123 {
109 .start = COLIBRI_PXA270_ETH_IRQ, 124 .start = gpio_to_irq(GPIO114_COLIBRI_PXA270_ETH_IRQ),
110 .end = COLIBRI_PXA270_ETH_IRQ, 125 .end = gpio_to_irq(GPIO114_COLIBRI_PXA270_ETH_IRQ),
111 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_RISING, 126 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_RISING,
112 }, 127 },
113}; 128};
114 129
115static struct platform_device dm9000_device = { 130static struct platform_device colibri_pxa270_dm9000_device = {
116 .name = "dm9000", 131 .name = "dm9000",
117 .id = -1, 132 .id = -1,
118 .num_resources = ARRAY_SIZE(dm9000_resources), 133 .num_resources = ARRAY_SIZE(colibri_pxa270_dm9000_resources),
119 .resource = dm9000_resources, 134 .resource = colibri_pxa270_dm9000_resources,
120}; 135};
121#endif /* CONFIG_DM9000 */
122 136
123static struct platform_device *colibri_pxa270_devices[] __initdata = { 137static void __init colibri_pxa270_eth_init(void)
124 &colibri_pxa270_flash_device, 138{
125#if defined(CONFIG_DM9000) 139 platform_device_register(&colibri_pxa270_dm9000_device);
126 &dm9000_device, 140}
141#else
142static inline void colibri_pxa270_eth_init(void) {}
127#endif 143#endif
144
145/******************************************************************************
146 * Audio and Touchscreen
147 ******************************************************************************/
148#if defined(CONFIG_TOUCHSCREEN_UCB1400) || \
149 defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
150static pxa2xx_audio_ops_t colibri_pxa270_ac97_pdata = {
151 .reset_gpio = 95,
152};
153
154static struct ucb1400_pdata colibri_pxa270_ucb1400_pdata = {
155 .irq = gpio_to_irq(GPIO113_COLIBRI_PXA270_TS_IRQ),
156};
157
158static struct platform_device colibri_pxa270_ucb1400_device = {
159 .name = "ucb1400_core",
160 .id = -1,
161 .dev = {
162 .platform_data = &colibri_pxa270_ucb1400_pdata,
163 },
128}; 164};
129 165
166static void __init colibri_pxa270_tsc_init(void)
167{
168 pxa_set_ac97_info(&colibri_pxa270_ac97_pdata);
169 platform_device_register(&colibri_pxa270_ucb1400_device);
170}
171#else
172static inline void colibri_pxa270_tsc_init(void) {}
173#endif
174
175static int colibri_pxa270_baseboard;
176core_param(colibri_pxa270_baseboard, colibri_pxa270_baseboard, int, 0444);
177
130static void __init colibri_pxa270_init(void) 178static void __init colibri_pxa270_init(void)
131{ 179{
132 pxa2xx_mfp_config(ARRAY_AND_SIZE(colibri_pxa270_pin_config)); 180 pxa2xx_mfp_config(ARRAY_AND_SIZE(colibri_pxa270_pin_config));
133 pxa_set_ffuart_info(NULL); 181
134 pxa_set_btuart_info(NULL); 182 colibri_pxa270_nor_init();
135 pxa_set_stuart_info(NULL); 183 colibri_pxa270_eth_init();
136 platform_add_devices(ARRAY_AND_SIZE(colibri_pxa270_devices)); 184 colibri_pxa270_tsc_init();
185
186 switch (colibri_pxa270_baseboard) {
187 case COLIBRI_PXA270_EVALBOARD:
188 colibri_pxa270_evalboard_init();
189 break;
190 case COLIBRI_PXA270_INCOME:
191 colibri_pxa270_income_boardinit();
192 break;
193 default:
194 printk(KERN_ERR "Illegal colibri_pxa270_baseboard type %d\n",
195 colibri_pxa270_baseboard);
196 }
197}
198
199/* The "Income s.r.o. SH-Dmaster PXA270 SBC" board can be booted either
200 * with the INCOME mach type or with COLIBRI and the kernel parameter
201 * "colibri_pxa270_baseboard=1"
202 */
203static void __init colibri_pxa270_income_init(void)
204{
205 colibri_pxa270_baseboard = COLIBRI_PXA270_INCOME;
206 colibri_pxa270_init();
137} 207}
138 208
139MACHINE_START(COLIBRI, "Toradex Colibri PXA270") 209MACHINE_START(COLIBRI, "Toradex Colibri PXA270")
@@ -146,3 +216,13 @@ MACHINE_START(COLIBRI, "Toradex Colibri PXA270")
146 .timer = &pxa_timer, 216 .timer = &pxa_timer,
147MACHINE_END 217MACHINE_END
148 218
219MACHINE_START(INCOME, "Income s.r.o. SH-Dmaster PXA270 SBC")
220 .phys_io = 0x40000000,
221 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
222 .boot_params = 0xa0000100,
223 .init_machine = colibri_pxa270_income_init,
224 .map_io = pxa_map_io,
225 .init_irq = pxa27x_init_irq,
226 .timer = &pxa_timer,
227MACHINE_END
228
diff --git a/arch/arm/mach-pxa/colibri-pxa320.c b/arch/arm/mach-pxa/colibri-pxa320.c
index ae835fad7d10..99e850d84710 100644
--- a/arch/arm/mach-pxa/colibri-pxa320.c
+++ b/arch/arm/mach-pxa/colibri-pxa320.c
@@ -16,6 +16,7 @@
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/gpio.h> 17#include <linux/gpio.h>
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/usb/gpio_vbus.h>
19 20
20#include <asm/mach-types.h> 21#include <asm/mach-types.h>
21#include <asm/sizes.h> 22#include <asm/sizes.h>
@@ -28,6 +29,8 @@
28#include <mach/pxafb.h> 29#include <mach/pxafb.h>
29#include <mach/ohci.h> 30#include <mach/ohci.h>
30#include <mach/audio.h> 31#include <mach/audio.h>
32#include <mach/pxa27x-udc.h>
33#include <mach/udc.h>
31 34
32#include "generic.h" 35#include "generic.h"
33#include "devices.h" 36#include "devices.h"
@@ -101,6 +104,42 @@ void __init colibri_pxa320_init_ohci(void)
101static inline void colibri_pxa320_init_ohci(void) {} 104static inline void colibri_pxa320_init_ohci(void) {}
102#endif /* CONFIG_USB_OHCI_HCD || CONFIG_USB_OHCI_HCD_MODULE */ 105#endif /* CONFIG_USB_OHCI_HCD || CONFIG_USB_OHCI_HCD_MODULE */
103 106
107#if defined(CONFIG_USB_GADGET_PXA27X)||defined(CONFIG_USB_GADGET_PXA27X_MODULE)
108static struct gpio_vbus_mach_info colibri_pxa320_gpio_vbus_info = {
109 .gpio_vbus = mfp_to_gpio(MFP_PIN_GPIO96),
110 .gpio_pullup = -1,
111};
112
113static struct platform_device colibri_pxa320_gpio_vbus = {
114 .name = "gpio-vbus",
115 .id = -1,
116 .dev = {
117 .platform_data = &colibri_pxa320_gpio_vbus_info,
118 },
119};
120
121static void colibri_pxa320_udc_command(int cmd)
122{
123 if (cmd == PXA2XX_UDC_CMD_CONNECT)
124 UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE;
125 else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
126 UP2OCR = UP2OCR_HXOE;
127}
128
129static struct pxa2xx_udc_mach_info colibri_pxa320_udc_info __initdata = {
130 .udc_command = colibri_pxa320_udc_command,
131 .gpio_pullup = -1,
132};
133
134static void __init colibri_pxa320_init_udc(void)
135{
136 pxa_set_udc_info(&colibri_pxa320_udc_info);
137 platform_device_register(&colibri_pxa320_gpio_vbus);
138}
139#else
140static inline void colibri_pxa320_init_udc(void) {}
141#endif
142
104static mfp_cfg_t colibri_pxa320_mmc_pin_config[] __initdata = { 143static mfp_cfg_t colibri_pxa320_mmc_pin_config[] __initdata = {
105 GPIO22_MMC1_CLK, 144 GPIO22_MMC1_CLK,
106 GPIO23_MMC1_CMD, 145 GPIO23_MMC1_CMD,
@@ -212,6 +251,7 @@ void __init colibri_pxa320_init(void)
212 colibri_pxa3xx_init_mmc(ARRAY_AND_SIZE(colibri_pxa320_mmc_pin_config), 251 colibri_pxa3xx_init_mmc(ARRAY_AND_SIZE(colibri_pxa320_mmc_pin_config),
213 mfp_to_gpio(MFP_PIN_GPIO28)); 252 mfp_to_gpio(MFP_PIN_GPIO28));
214 colibri_pxa320_init_uart(); 253 colibri_pxa320_init_uart();
254 colibri_pxa320_init_udc();
215} 255}
216 256
217MACHINE_START(COLIBRI320, "Toradex Colibri PXA320") 257MACHINE_START(COLIBRI320, "Toradex Colibri PXA320")
diff --git a/arch/arm/mach-pxa/corgi.c b/arch/arm/mach-pxa/corgi.c
index 461ba4080155..3fb0fc099080 100644
--- a/arch/arm/mach-pxa/corgi.c
+++ b/arch/arm/mach-pxa/corgi.c
@@ -50,14 +50,13 @@
50#include <mach/udc.h> 50#include <mach/udc.h>
51#include <mach/pxa2xx_spi.h> 51#include <mach/pxa2xx_spi.h>
52#include <mach/corgi.h> 52#include <mach/corgi.h>
53#include <mach/sharpsl.h> 53#include <mach/sharpsl_pm.h>
54 54
55#include <asm/mach/sharpsl_param.h> 55#include <asm/mach/sharpsl_param.h>
56#include <asm/hardware/scoop.h> 56#include <asm/hardware/scoop.h>
57 57
58#include "generic.h" 58#include "generic.h"
59#include "devices.h" 59#include "devices.h"
60#include "sharpsl.h"
61 60
62static unsigned long corgi_pin_config[] __initdata = { 61static unsigned long corgi_pin_config[] __initdata = {
63 /* Static Memory I/O */ 62 /* Static Memory I/O */
@@ -185,8 +184,6 @@ static struct scoop_pcmcia_config corgi_pcmcia_config = {
185 .num_devs = 1, 184 .num_devs = 1,
186}; 185};
187 186
188EXPORT_SYMBOL(corgiscoop_device);
189
190static struct w100_mem_info corgi_fb_mem = { 187static struct w100_mem_info corgi_fb_mem = {
191 .ext_cntl = 0x00040003, 188 .ext_cntl = 0x00040003,
192 .sdram_mode_reg = 0x00650021, 189 .sdram_mode_reg = 0x00650021,
diff --git a/arch/arm/mach-pxa/corgi_pm.c b/arch/arm/mach-pxa/corgi_pm.c
index 3f1dc74ac048..29034778bfda 100644
--- a/arch/arm/mach-pxa/corgi_pm.c
+++ b/arch/arm/mach-pxa/corgi_pm.c
@@ -23,12 +23,11 @@
23#include <asm/mach-types.h> 23#include <asm/mach-types.h>
24#include <mach/hardware.h> 24#include <mach/hardware.h>
25 25
26#include <mach/sharpsl.h>
27#include <mach/corgi.h> 26#include <mach/corgi.h>
28#include <mach/pxa2xx-regs.h> 27#include <mach/pxa2xx-regs.h>
28#include <mach/sharpsl_pm.h>
29 29
30#include "generic.h" 30#include "generic.h"
31#include "sharpsl.h"
32 31
33#define SHARPSL_CHARGE_ON_VOLT 0x99 /* 2.9V */ 32#define SHARPSL_CHARGE_ON_VOLT 0x99 /* 2.9V */
34#define SHARPSL_CHARGE_ON_TEMP 0xe0 /* 2.9V */ 33#define SHARPSL_CHARGE_ON_TEMP 0xe0 /* 2.9V */
@@ -134,11 +133,11 @@ unsigned long corgipm_read_devdata(int type)
134 case SHARPSL_STATUS_ACIN: 133 case SHARPSL_STATUS_ACIN:
135 return ((GPLR(CORGI_GPIO_AC_IN) & GPIO_bit(CORGI_GPIO_AC_IN)) != 0); 134 return ((GPLR(CORGI_GPIO_AC_IN) & GPIO_bit(CORGI_GPIO_AC_IN)) != 0);
136 case SHARPSL_STATUS_LOCK: 135 case SHARPSL_STATUS_LOCK:
137 return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_batlock); 136 return gpio_get_value(sharpsl_pm.machinfo->gpio_batlock);
138 case SHARPSL_STATUS_CHRGFULL: 137 case SHARPSL_STATUS_CHRGFULL:
139 return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_batfull); 138 return gpio_get_value(sharpsl_pm.machinfo->gpio_batfull);
140 case SHARPSL_STATUS_FATAL: 139 case SHARPSL_STATUS_FATAL:
141 return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_fatal); 140 return gpio_get_value(sharpsl_pm.machinfo->gpio_fatal);
142 case SHARPSL_ACIN_VOLT: 141 case SHARPSL_ACIN_VOLT:
143 return sharpsl_pm_pxa_read_max1111(MAX1111_ACIN_VOLT); 142 return sharpsl_pm_pxa_read_max1111(MAX1111_ACIN_VOLT);
144 case SHARPSL_BATT_TEMP: 143 case SHARPSL_BATT_TEMP:
@@ -165,8 +164,6 @@ static struct sharpsl_charger_machinfo corgi_pm_machinfo = {
165 .should_wakeup = corgi_should_wakeup, 164 .should_wakeup = corgi_should_wakeup,
166#if defined(CONFIG_LCD_CORGI) 165#if defined(CONFIG_LCD_CORGI)
167 .backlight_limit = corgi_lcd_limit_intensity, 166 .backlight_limit = corgi_lcd_limit_intensity,
168#elif defined(CONFIG_BACKLIGHT_CORGI)
169 .backlight_limit = corgibl_limit_intensity,
170#endif 167#endif
171 .charge_on_volt = SHARPSL_CHARGE_ON_VOLT, 168 .charge_on_volt = SHARPSL_CHARGE_ON_VOLT,
172 .charge_on_temp = SHARPSL_CHARGE_ON_TEMP, 169 .charge_on_temp = SHARPSL_CHARGE_ON_TEMP,
diff --git a/arch/arm/mach-pxa/devices.c b/arch/arm/mach-pxa/devices.c
index 8e10db148f1b..65447dc736c2 100644
--- a/arch/arm/mach-pxa/devices.c
+++ b/arch/arm/mach-pxa/devices.c
@@ -4,6 +4,7 @@
4#include <linux/platform_device.h> 4#include <linux/platform_device.h>
5#include <linux/dma-mapping.h> 5#include <linux/dma-mapping.h>
6 6
7#include <asm/pmu.h>
7#include <mach/udc.h> 8#include <mach/udc.h>
8#include <mach/pxafb.h> 9#include <mach/pxafb.h>
9#include <mach/mmc.h> 10#include <mach/mmc.h>
@@ -31,6 +32,19 @@ void __init pxa_register_device(struct platform_device *dev, void *data)
31 dev_err(&dev->dev, "unable to register device: %d\n", ret); 32 dev_err(&dev->dev, "unable to register device: %d\n", ret);
32} 33}
33 34
35static struct resource pxa_resource_pmu = {
36 .start = IRQ_PMU,
37 .end = IRQ_PMU,
38 .flags = IORESOURCE_IRQ,
39};
40
41struct platform_device pxa_device_pmu = {
42 .name = "arm-pmu",
43 .id = ARM_PMU_DEVICE_CPU,
44 .resource = &pxa_resource_pmu,
45 .num_resources = 1,
46};
47
34static struct resource pxamci_resources[] = { 48static struct resource pxamci_resources[] = {
35 [0] = { 49 [0] = {
36 .start = 0x41100000, 50 .start = 0x41100000,
diff --git a/arch/arm/mach-pxa/devices.h b/arch/arm/mach-pxa/devices.h
index 93817d99761e..50353ea49ba4 100644
--- a/arch/arm/mach-pxa/devices.h
+++ b/arch/arm/mach-pxa/devices.h
@@ -1,3 +1,4 @@
1extern struct platform_device pxa_device_pmu;
1extern struct platform_device pxa_device_mci; 2extern struct platform_device pxa_device_mci;
2extern struct platform_device pxa3xx_device_mci2; 3extern struct platform_device pxa3xx_device_mci2;
3extern struct platform_device pxa3xx_device_mci3; 4extern struct platform_device pxa3xx_device_mci3;
diff --git a/arch/arm/mach-pxa/e330.c b/arch/arm/mach-pxa/e330.c
deleted file mode 100644
index 8fde3387279d..000000000000
--- a/arch/arm/mach-pxa/e330.c
+++ /dev/null
@@ -1,78 +0,0 @@
1/*
2 * Hardware definitions for the Toshiba e330 PDAs
3 *
4 * Copyright (c) 2003 Ian Molton <spyro@f2s.com>
5 *
6 * This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/clk.h>
16#include <linux/platform_device.h>
17#include <linux/mfd/tc6387xb.h>
18
19#include <asm/setup.h>
20#include <asm/mach/arch.h>
21#include <asm/mach-types.h>
22
23#include <mach/pxa25x.h>
24#include <mach/eseries-gpio.h>
25#include <mach/udc.h>
26
27#include "generic.h"
28#include "eseries.h"
29#include "clock.h"
30
31/* -------------------- e330 tc6387xb parameters -------------------- */
32
33static struct tc6387xb_platform_data e330_tc6387xb_info = {
34 .enable = &eseries_tmio_enable,
35 .disable = &eseries_tmio_disable,
36 .suspend = &eseries_tmio_suspend,
37 .resume = &eseries_tmio_resume,
38};
39
40static struct platform_device e330_tc6387xb_device = {
41 .name = "tc6387xb",
42 .id = -1,
43 .dev = {
44 .platform_data = &e330_tc6387xb_info,
45 },
46 .num_resources = 2,
47 .resource = eseries_tmio_resources,
48};
49
50/* --------------------------------------------------------------- */
51
52static struct platform_device *devices[] __initdata = {
53 &e330_tc6387xb_device,
54};
55
56static void __init e330_init(void)
57{
58 pxa_set_ffuart_info(NULL);
59 pxa_set_btuart_info(NULL);
60 pxa_set_stuart_info(NULL);
61 eseries_register_clks();
62 eseries_get_tmio_gpios();
63 platform_add_devices(devices, ARRAY_SIZE(devices));
64 pxa_set_udc_info(&e7xx_udc_mach_info);
65}
66
67MACHINE_START(E330, "Toshiba e330")
68 /* Maintainer: Ian Molton (spyro@f2s.com) */
69 .phys_io = 0x40000000,
70 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
71 .boot_params = 0xa0000100,
72 .map_io = pxa_map_io,
73 .init_irq = pxa25x_init_irq,
74 .fixup = eseries_fixup,
75 .init_machine = e330_init,
76 .timer = &pxa_timer,
77MACHINE_END
78
diff --git a/arch/arm/mach-pxa/e350.c b/arch/arm/mach-pxa/e350.c
deleted file mode 100644
index f50f055f5720..000000000000
--- a/arch/arm/mach-pxa/e350.c
+++ /dev/null
@@ -1,79 +0,0 @@
1/*
2 * Hardware definitions for the Toshiba e350 PDAs
3 *
4 * Copyright (c) 2003 Ian Molton <spyro@f2s.com>
5 *
6 * This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/clk.h>
16#include <linux/platform_device.h>
17#include <linux/mfd/t7l66xb.h>
18
19#include <asm/setup.h>
20#include <asm/mach/arch.h>
21#include <asm/mach-types.h>
22
23#include <mach/irqs.h>
24#include <mach/pxa25x.h>
25#include <mach/eseries-gpio.h>
26#include <mach/udc.h>
27
28#include "generic.h"
29#include "eseries.h"
30#include "clock.h"
31
32/* -------------------- e350 t7l66xb parameters -------------------- */
33
34static struct t7l66xb_platform_data e350_t7l66xb_info = {
35 .irq_base = IRQ_BOARD_START,
36 .enable = &eseries_tmio_enable,
37 .suspend = &eseries_tmio_suspend,
38 .resume = &eseries_tmio_resume,
39};
40
41static struct platform_device e350_t7l66xb_device = {
42 .name = "t7l66xb",
43 .id = -1,
44 .dev = {
45 .platform_data = &e350_t7l66xb_info,
46 },
47 .num_resources = 2,
48 .resource = eseries_tmio_resources,
49};
50
51/* ---------------------------------------------------------- */
52
53static struct platform_device *devices[] __initdata = {
54 &e350_t7l66xb_device,
55};
56
57static void __init e350_init(void)
58{
59 pxa_set_ffuart_info(NULL);
60 pxa_set_btuart_info(NULL);
61 pxa_set_stuart_info(NULL);
62 eseries_register_clks();
63 eseries_get_tmio_gpios();
64 platform_add_devices(devices, ARRAY_SIZE(devices));
65 pxa_set_udc_info(&e7xx_udc_mach_info);
66}
67
68MACHINE_START(E350, "Toshiba e350")
69 /* Maintainer: Ian Molton (spyro@f2s.com) */
70 .phys_io = 0x40000000,
71 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
72 .boot_params = 0xa0000100,
73 .map_io = pxa_map_io,
74 .init_irq = pxa25x_init_irq,
75 .fixup = eseries_fixup,
76 .init_machine = e350_init,
77 .timer = &pxa_timer,
78MACHINE_END
79
diff --git a/arch/arm/mach-pxa/e400.c b/arch/arm/mach-pxa/e400.c
deleted file mode 100644
index 55b950f12844..000000000000
--- a/arch/arm/mach-pxa/e400.c
+++ /dev/null
@@ -1,155 +0,0 @@
1/*
2 * Hardware definitions for the Toshiba eseries PDAs
3 *
4 * Copyright (c) 2003 Ian Molton <spyro@f2s.com>
5 *
6 * This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/clk.h>
16#include <linux/platform_device.h>
17#include <linux/mfd/t7l66xb.h>
18#include <linux/mtd/nand.h>
19#include <linux/mtd/partitions.h>
20
21#include <asm/setup.h>
22#include <asm/mach/arch.h>
23#include <asm/mach-types.h>
24
25#include <mach/pxa25x.h>
26#include <mach/eseries-gpio.h>
27#include <mach/pxafb.h>
28#include <mach/udc.h>
29#include <mach/irqs.h>
30
31#include "generic.h"
32#include "eseries.h"
33#include "clock.h"
34
35/* ------------------------ E400 LCD definitions ------------------------ */
36
37static struct pxafb_mode_info e400_pxafb_mode_info = {
38 .pixclock = 140703,
39 .xres = 240,
40 .yres = 320,
41 .bpp = 16,
42 .hsync_len = 4,
43 .left_margin = 28,
44 .right_margin = 8,
45 .vsync_len = 3,
46 .upper_margin = 5,
47 .lower_margin = 6,
48 .sync = 0,
49};
50
51static struct pxafb_mach_info e400_pxafb_mach_info = {
52 .modes = &e400_pxafb_mode_info,
53 .num_modes = 1,
54 .lcd_conn = LCD_COLOR_TFT_16BPP,
55 .lccr3 = 0,
56 .pxafb_backlight_power = NULL,
57};
58
59/* ------------------------ E400 MFP config ----------------------------- */
60
61static unsigned long e400_pin_config[] __initdata = {
62 /* Chip selects */
63 GPIO15_nCS_1, /* CS1 - Flash */
64 GPIO80_nCS_4, /* CS4 - TMIO */
65
66 /* Clocks */
67 GPIO12_32KHz,
68
69 /* BTUART */
70 GPIO42_BTUART_RXD,
71 GPIO43_BTUART_TXD,
72 GPIO44_BTUART_CTS,
73
74 /* TMIO controller */
75 GPIO19_GPIO, /* t7l66xb #PCLR */
76 GPIO45_GPIO, /* t7l66xb #SUSPEND (NOT BTUART!) */
77
78 /* wakeup */
79 GPIO0_GPIO | WAKEUP_ON_EDGE_RISE,
80};
81
82/* ---------------------------------------------------------------------- */
83
84static struct mtd_partition partition_a = {
85 .name = "Internal NAND flash",
86 .offset = 0,
87 .size = MTDPART_SIZ_FULL,
88};
89
90static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
91
92static struct nand_bbt_descr e400_t7l66xb_nand_bbt = {
93 .options = 0,
94 .offs = 4,
95 .len = 2,
96 .pattern = scan_ff_pattern
97};
98
99static struct tmio_nand_data e400_t7l66xb_nand_config = {
100 .num_partitions = 1,
101 .partition = &partition_a,
102 .badblock_pattern = &e400_t7l66xb_nand_bbt,
103};
104
105static struct t7l66xb_platform_data e400_t7l66xb_info = {
106 .irq_base = IRQ_BOARD_START,
107 .enable = &eseries_tmio_enable,
108 .suspend = &eseries_tmio_suspend,
109 .resume = &eseries_tmio_resume,
110
111 .nand_data = &e400_t7l66xb_nand_config,
112};
113
114static struct platform_device e400_t7l66xb_device = {
115 .name = "t7l66xb",
116 .id = -1,
117 .dev = {
118 .platform_data = &e400_t7l66xb_info,
119 },
120 .num_resources = 2,
121 .resource = eseries_tmio_resources,
122};
123
124/* ---------------------------------------------------------- */
125
126static struct platform_device *devices[] __initdata = {
127 &e400_t7l66xb_device,
128};
129
130static void __init e400_init(void)
131{
132 pxa2xx_mfp_config(ARRAY_AND_SIZE(e400_pin_config));
133 pxa_set_ffuart_info(NULL);
134 pxa_set_btuart_info(NULL);
135 pxa_set_stuart_info(NULL);
136 /* Fixme - e400 may have a switched clock */
137 eseries_register_clks();
138 eseries_get_tmio_gpios();
139 set_pxa_fb_info(&e400_pxafb_mach_info);
140 platform_add_devices(devices, ARRAY_SIZE(devices));
141 pxa_set_udc_info(&e7xx_udc_mach_info);
142}
143
144MACHINE_START(E400, "Toshiba e400")
145 /* Maintainer: Ian Molton (spyro@f2s.com) */
146 .phys_io = 0x40000000,
147 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
148 .boot_params = 0xa0000100,
149 .map_io = pxa_map_io,
150 .init_irq = pxa25x_init_irq,
151 .fixup = eseries_fixup,
152 .init_machine = e400_init,
153 .timer = &pxa_timer,
154MACHINE_END
155
diff --git a/arch/arm/mach-pxa/e740.c b/arch/arm/mach-pxa/e740.c
deleted file mode 100644
index d578021d1a10..000000000000
--- a/arch/arm/mach-pxa/e740.c
+++ /dev/null
@@ -1,225 +0,0 @@
1/*
2 * Hardware definitions for the Toshiba eseries PDAs
3 *
4 * Copyright (c) 2003 Ian Molton <spyro@f2s.com>
5 *
6 * This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/device.h>
16#include <linux/platform_device.h>
17#include <linux/fb.h>
18#include <linux/clk.h>
19#include <linux/mfd/t7l66xb.h>
20
21#include <video/w100fb.h>
22
23#include <asm/setup.h>
24#include <asm/mach/arch.h>
25#include <asm/mach-types.h>
26
27#include <mach/pxa25x.h>
28#include <mach/eseries-gpio.h>
29#include <mach/udc.h>
30#include <mach/irda.h>
31#include <mach/irqs.h>
32#include <mach/audio.h>
33
34#include "generic.h"
35#include "eseries.h"
36#include "clock.h"
37#include "devices.h"
38
39/* ------------------------ e740 video support --------------------------- */
40
41static struct w100_gen_regs e740_lcd_regs = {
42 .lcd_format = 0x00008023,
43 .lcdd_cntl1 = 0x0f000000,
44 .lcdd_cntl2 = 0x0003ffff,
45 .genlcd_cntl1 = 0x00ffff03,
46 .genlcd_cntl2 = 0x003c0f03,
47 .genlcd_cntl3 = 0x000143aa,
48};
49
50static struct w100_mode e740_lcd_mode = {
51 .xres = 240,
52 .yres = 320,
53 .left_margin = 20,
54 .right_margin = 28,
55 .upper_margin = 9,
56 .lower_margin = 8,
57 .crtc_ss = 0x80140013,
58 .crtc_ls = 0x81150110,
59 .crtc_gs = 0x80050005,
60 .crtc_vpos_gs = 0x000a0009,
61 .crtc_rev = 0x0040010a,
62 .crtc_dclk = 0xa906000a,
63 .crtc_gclk = 0x80050108,
64 .crtc_goe = 0x80050108,
65 .pll_freq = 57,
66 .pixclk_divider = 4,
67 .pixclk_divider_rotated = 4,
68 .pixclk_src = CLK_SRC_XTAL,
69 .sysclk_divider = 1,
70 .sysclk_src = CLK_SRC_PLL,
71 .crtc_ps1_active = 0x41060010,
72};
73
74static struct w100_gpio_regs e740_w100_gpio_info = {
75 .init_data1 = 0x21002103,
76 .gpio_dir1 = 0xffffdeff,
77 .gpio_oe1 = 0x03c00643,
78 .init_data2 = 0x003f003f,
79 .gpio_dir2 = 0xffffffff,
80 .gpio_oe2 = 0x000000ff,
81};
82
83static struct w100fb_mach_info e740_fb_info = {
84 .modelist = &e740_lcd_mode,
85 .num_modes = 1,
86 .regs = &e740_lcd_regs,
87 .gpio = &e740_w100_gpio_info,
88 .xtal_freq = 14318000,
89 .xtal_dbl = 1,
90};
91
92static struct resource e740_fb_resources[] = {
93 [0] = {
94 .start = 0x0c000000,
95 .end = 0x0cffffff,
96 .flags = IORESOURCE_MEM,
97 },
98};
99
100static struct platform_device e740_fb_device = {
101 .name = "w100fb",
102 .id = -1,
103 .dev = {
104 .platform_data = &e740_fb_info,
105 },
106 .num_resources = ARRAY_SIZE(e740_fb_resources),
107 .resource = e740_fb_resources,
108};
109
110/* --------------------------- MFP Pin config -------------------------- */
111
112static unsigned long e740_pin_config[] __initdata = {
113 /* Chip selects */
114 GPIO15_nCS_1, /* CS1 - Flash */
115 GPIO79_nCS_3, /* CS3 - IMAGEON */
116 GPIO80_nCS_4, /* CS4 - TMIO */
117
118 /* Clocks */
119 GPIO12_32KHz,
120
121 /* BTUART */
122 GPIO42_BTUART_RXD,
123 GPIO43_BTUART_TXD,
124 GPIO44_BTUART_CTS,
125
126 /* TMIO controller */
127 GPIO19_GPIO, /* t7l66xb #PCLR */
128 GPIO45_GPIO, /* t7l66xb #SUSPEND (NOT BTUART!) */
129
130 /* UDC */
131 GPIO13_GPIO,
132 GPIO3_GPIO,
133
134 /* IrDA */
135 GPIO38_GPIO | MFP_LPM_DRIVE_HIGH,
136
137 /* AC97 */
138 GPIO28_AC97_BITCLK,
139 GPIO29_AC97_SDATA_IN_0,
140 GPIO30_AC97_SDATA_OUT,
141 GPIO31_AC97_SYNC,
142
143 /* Audio power control */
144 GPIO16_GPIO, /* AC97 codec AVDD2 supply (analogue power) */
145 GPIO40_GPIO, /* Mic amp power */
146 GPIO41_GPIO, /* Headphone amp power */
147
148 /* PC Card */
149 GPIO8_GPIO, /* CD0 */
150 GPIO44_GPIO, /* CD1 */
151 GPIO11_GPIO, /* IRQ0 */
152 GPIO6_GPIO, /* IRQ1 */
153 GPIO27_GPIO, /* RST0 */
154 GPIO24_GPIO, /* RST1 */
155 GPIO20_GPIO, /* PWR0 */
156 GPIO23_GPIO, /* PWR1 */
157 GPIO48_nPOE,
158 GPIO49_nPWE,
159 GPIO50_nPIOR,
160 GPIO51_nPIOW,
161 GPIO52_nPCE_1,
162 GPIO53_nPCE_2,
163 GPIO54_nPSKTSEL,
164 GPIO55_nPREG,
165 GPIO56_nPWAIT,
166 GPIO57_nIOIS16,
167
168 /* wakeup */
169 GPIO0_GPIO | WAKEUP_ON_EDGE_RISE,
170};
171
172/* -------------------- e740 t7l66xb parameters -------------------- */
173
174static struct t7l66xb_platform_data e740_t7l66xb_info = {
175 .irq_base = IRQ_BOARD_START,
176 .enable = &eseries_tmio_enable,
177 .suspend = &eseries_tmio_suspend,
178 .resume = &eseries_tmio_resume,
179};
180
181static struct platform_device e740_t7l66xb_device = {
182 .name = "t7l66xb",
183 .id = -1,
184 .dev = {
185 .platform_data = &e740_t7l66xb_info,
186 },
187 .num_resources = 2,
188 .resource = eseries_tmio_resources,
189};
190
191/* ----------------------------------------------------------------------- */
192
193static struct platform_device *devices[] __initdata = {
194 &e740_fb_device,
195 &e740_t7l66xb_device,
196};
197
198static void __init e740_init(void)
199{
200 pxa2xx_mfp_config(ARRAY_AND_SIZE(e740_pin_config));
201 pxa_set_ffuart_info(NULL);
202 pxa_set_btuart_info(NULL);
203 pxa_set_stuart_info(NULL);
204 eseries_register_clks();
205 clk_add_alias("CLK_CK48M", e740_t7l66xb_device.name,
206 "UDCCLK", &pxa25x_device_udc.dev),
207 eseries_get_tmio_gpios();
208 platform_add_devices(devices, ARRAY_SIZE(devices));
209 pxa_set_udc_info(&e7xx_udc_mach_info);
210 pxa_set_ac97_info(NULL);
211 pxa_set_ficp_info(&e7xx_ficp_platform_data);
212}
213
214MACHINE_START(E740, "Toshiba e740")
215 /* Maintainer: Ian Molton (spyro@f2s.com) */
216 .phys_io = 0x40000000,
217 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
218 .boot_params = 0xa0000100,
219 .map_io = pxa_map_io,
220 .init_irq = pxa25x_init_irq,
221 .fixup = eseries_fixup,
222 .init_machine = e740_init,
223 .timer = &pxa_timer,
224MACHINE_END
225
diff --git a/arch/arm/mach-pxa/e750.c b/arch/arm/mach-pxa/e750.c
deleted file mode 100644
index af83caa52dd4..000000000000
--- a/arch/arm/mach-pxa/e750.c
+++ /dev/null
@@ -1,226 +0,0 @@
1/*
2 * Hardware definitions for the Toshiba eseries PDAs
3 *
4 * Copyright (c) 2003 Ian Molton <spyro@f2s.com>
5 *
6 * This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/device.h>
16#include <linux/platform_device.h>
17#include <linux/fb.h>
18#include <linux/mfd/tc6393xb.h>
19
20#include <video/w100fb.h>
21
22#include <asm/setup.h>
23#include <asm/mach/arch.h>
24#include <asm/mach-types.h>
25
26#include <mach/pxa25x.h>
27#include <mach/eseries-gpio.h>
28#include <mach/udc.h>
29#include <mach/irda.h>
30#include <mach/irqs.h>
31#include <mach/audio.h>
32
33#include "generic.h"
34#include "eseries.h"
35#include "clock.h"
36
37/* ---------------------- E750 LCD definitions -------------------- */
38
39static struct w100_gen_regs e750_lcd_regs = {
40 .lcd_format = 0x00008003,
41 .lcdd_cntl1 = 0x00000000,
42 .lcdd_cntl2 = 0x0003ffff,
43 .genlcd_cntl1 = 0x00fff003,
44 .genlcd_cntl2 = 0x003c0f03,
45 .genlcd_cntl3 = 0x000143aa,
46};
47
48static struct w100_mode e750_lcd_mode = {
49 .xres = 240,
50 .yres = 320,
51 .left_margin = 21,
52 .right_margin = 22,
53 .upper_margin = 5,
54 .lower_margin = 4,
55 .crtc_ss = 0x80150014,
56 .crtc_ls = 0x8014000d,
57 .crtc_gs = 0xc1000005,
58 .crtc_vpos_gs = 0x00020147,
59 .crtc_rev = 0x0040010a,
60 .crtc_dclk = 0xa1700030,
61 .crtc_gclk = 0x80cc0015,
62 .crtc_goe = 0x80cc0015,
63 .crtc_ps1_active = 0x61060017,
64 .pll_freq = 57,
65 .pixclk_divider = 4,
66 .pixclk_divider_rotated = 4,
67 .pixclk_src = CLK_SRC_XTAL,
68 .sysclk_divider = 1,
69 .sysclk_src = CLK_SRC_PLL,
70};
71
72static struct w100_gpio_regs e750_w100_gpio_info = {
73 .init_data1 = 0x01192f1b,
74 .gpio_dir1 = 0xd5ffdeff,
75 .gpio_oe1 = 0x000020bf,
76 .init_data2 = 0x010f010f,
77 .gpio_dir2 = 0xffffffff,
78 .gpio_oe2 = 0x000001cf,
79};
80
81static struct w100fb_mach_info e750_fb_info = {
82 .modelist = &e750_lcd_mode,
83 .num_modes = 1,
84 .regs = &e750_lcd_regs,
85 .gpio = &e750_w100_gpio_info,
86 .xtal_freq = 14318000,
87 .xtal_dbl = 1,
88};
89
90static struct resource e750_fb_resources[] = {
91 [0] = {
92 .start = 0x0c000000,
93 .end = 0x0cffffff,
94 .flags = IORESOURCE_MEM,
95 },
96};
97
98static struct platform_device e750_fb_device = {
99 .name = "w100fb",
100 .id = -1,
101 .dev = {
102 .platform_data = &e750_fb_info,
103 },
104 .num_resources = ARRAY_SIZE(e750_fb_resources),
105 .resource = e750_fb_resources,
106};
107
108/* -------------------- e750 MFP parameters -------------------- */
109
110static unsigned long e750_pin_config[] __initdata = {
111 /* Chip selects */
112 GPIO15_nCS_1, /* CS1 - Flash */
113 GPIO79_nCS_3, /* CS3 - IMAGEON */
114 GPIO80_nCS_4, /* CS4 - TMIO */
115
116 /* Clocks */
117 GPIO11_3_6MHz,
118
119 /* BTUART */
120 GPIO42_BTUART_RXD,
121 GPIO43_BTUART_TXD,
122 GPIO44_BTUART_CTS,
123
124 /* TMIO controller */
125 GPIO19_GPIO, /* t7l66xb #PCLR */
126 GPIO45_GPIO, /* t7l66xb #SUSPEND (NOT BTUART!) */
127
128 /* UDC */
129 GPIO13_GPIO,
130 GPIO3_GPIO,
131
132 /* IrDA */
133 GPIO38_GPIO | MFP_LPM_DRIVE_HIGH,
134
135 /* AC97 */
136 GPIO28_AC97_BITCLK,
137 GPIO29_AC97_SDATA_IN_0,
138 GPIO30_AC97_SDATA_OUT,
139 GPIO31_AC97_SYNC,
140
141 /* Audio power control */
142 GPIO4_GPIO, /* Headphone amp power */
143 GPIO7_GPIO, /* Speaker amp power */
144 GPIO37_GPIO, /* Headphone detect */
145
146 /* PC Card */
147 GPIO8_GPIO, /* CD0 */
148 GPIO44_GPIO, /* CD1 */
149 GPIO11_GPIO, /* IRQ0 */
150 GPIO6_GPIO, /* IRQ1 */
151 GPIO27_GPIO, /* RST0 */
152 GPIO24_GPIO, /* RST1 */
153 GPIO20_GPIO, /* PWR0 */
154 GPIO23_GPIO, /* PWR1 */
155 GPIO48_nPOE,
156 GPIO49_nPWE,
157 GPIO50_nPIOR,
158 GPIO51_nPIOW,
159 GPIO52_nPCE_1,
160 GPIO53_nPCE_2,
161 GPIO54_nPSKTSEL,
162 GPIO55_nPREG,
163 GPIO56_nPWAIT,
164 GPIO57_nIOIS16,
165
166 /* wakeup */
167 GPIO0_GPIO | WAKEUP_ON_EDGE_RISE,
168};
169
170/* ----------------- e750 tc6393xb parameters ------------------ */
171
172static struct tc6393xb_platform_data e750_tc6393xb_info = {
173 .irq_base = IRQ_BOARD_START,
174 .scr_pll2cr = 0x0cc1,
175 .scr_gper = 0,
176 .gpio_base = -1,
177 .suspend = &eseries_tmio_suspend,
178 .resume = &eseries_tmio_resume,
179 .enable = &eseries_tmio_enable,
180 .disable = &eseries_tmio_disable,
181};
182
183static struct platform_device e750_tc6393xb_device = {
184 .name = "tc6393xb",
185 .id = -1,
186 .dev = {
187 .platform_data = &e750_tc6393xb_info,
188 },
189 .num_resources = 2,
190 .resource = eseries_tmio_resources,
191};
192
193/* ------------------------------------------------------------- */
194
195static struct platform_device *devices[] __initdata = {
196 &e750_fb_device,
197 &e750_tc6393xb_device,
198};
199
200static void __init e750_init(void)
201{
202 pxa2xx_mfp_config(ARRAY_AND_SIZE(e750_pin_config));
203 pxa_set_ffuart_info(NULL);
204 pxa_set_btuart_info(NULL);
205 pxa_set_stuart_info(NULL);
206 clk_add_alias("CLK_CK3P6MI", e750_tc6393xb_device.name,
207 "GPIO11_CLK", NULL),
208 eseries_get_tmio_gpios();
209 platform_add_devices(devices, ARRAY_SIZE(devices));
210 pxa_set_udc_info(&e7xx_udc_mach_info);
211 pxa_set_ac97_info(NULL);
212 pxa_set_ficp_info(&e7xx_ficp_platform_data);
213}
214
215MACHINE_START(E750, "Toshiba e750")
216 /* Maintainer: Ian Molton (spyro@f2s.com) */
217 .phys_io = 0x40000000,
218 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
219 .boot_params = 0xa0000100,
220 .map_io = pxa_map_io,
221 .init_irq = pxa25x_init_irq,
222 .fixup = eseries_fixup,
223 .init_machine = e750_init,
224 .timer = &pxa_timer,
225MACHINE_END
226
diff --git a/arch/arm/mach-pxa/e800.c b/arch/arm/mach-pxa/e800.c
deleted file mode 100644
index 8ea97bf53fe1..000000000000
--- a/arch/arm/mach-pxa/e800.c
+++ /dev/null
@@ -1,229 +0,0 @@
1/*
2 * Hardware definitions for the Toshiba eseries PDAs
3 *
4 * Copyright (c) 2003 Ian Molton <spyro@f2s.com>
5 *
6 * This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/device.h>
16#include <linux/platform_device.h>
17#include <linux/fb.h>
18#include <linux/mfd/tc6393xb.h>
19
20#include <video/w100fb.h>
21
22#include <asm/setup.h>
23#include <asm/mach/arch.h>
24#include <asm/mach-types.h>
25
26#include <mach/pxa25x.h>
27#include <mach/eseries-gpio.h>
28#include <mach/udc.h>
29#include <mach/irqs.h>
30#include <mach/audio.h>
31
32#include "generic.h"
33#include "eseries.h"
34#include "clock.h"
35
36/* ------------------------ e800 LCD definitions ------------------------- */
37
38static unsigned long e800_pin_config[] __initdata = {
39 /* AC97 */
40 GPIO28_AC97_BITCLK,
41 GPIO29_AC97_SDATA_IN_0,
42 GPIO30_AC97_SDATA_OUT,
43 GPIO31_AC97_SYNC,
44};
45
46static struct w100_gen_regs e800_lcd_regs = {
47 .lcd_format = 0x00008003,
48 .lcdd_cntl1 = 0x02a00000,
49 .lcdd_cntl2 = 0x0003ffff,
50 .genlcd_cntl1 = 0x000ff2a3,
51 .genlcd_cntl2 = 0x000002a3,
52 .genlcd_cntl3 = 0x000102aa,
53};
54
55static struct w100_mode e800_lcd_mode[2] = {
56 [0] = {
57 .xres = 480,
58 .yres = 640,
59 .left_margin = 52,
60 .right_margin = 148,
61 .upper_margin = 2,
62 .lower_margin = 6,
63 .crtc_ss = 0x80350034,
64 .crtc_ls = 0x802b0026,
65 .crtc_gs = 0x80160016,
66 .crtc_vpos_gs = 0x00020003,
67 .crtc_rev = 0x0040001d,
68 .crtc_dclk = 0xe0000000,
69 .crtc_gclk = 0x82a50049,
70 .crtc_goe = 0x80ee001c,
71 .crtc_ps1_active = 0x00000000,
72 .pll_freq = 128,
73 .pixclk_divider = 4,
74 .pixclk_divider_rotated = 6,
75 .pixclk_src = CLK_SRC_PLL,
76 .sysclk_divider = 0,
77 .sysclk_src = CLK_SRC_PLL,
78 },
79 [1] = {
80 .xres = 240,
81 .yres = 320,
82 .left_margin = 15,
83 .right_margin = 88,
84 .upper_margin = 0,
85 .lower_margin = 7,
86 .crtc_ss = 0xd010000f,
87 .crtc_ls = 0x80070003,
88 .crtc_gs = 0x80000000,
89 .crtc_vpos_gs = 0x01460147,
90 .crtc_rev = 0x00400003,
91 .crtc_dclk = 0xa1700030,
92 .crtc_gclk = 0x814b0008,
93 .crtc_goe = 0x80cc0015,
94 .crtc_ps1_active = 0x00000000,
95 .pll_freq = 100,
96 .pixclk_divider = 6, /* Wince uses 14 which gives a */
97 .pixclk_divider_rotated = 6, /* 7MHz Pclk. We use a 14MHz one */
98 .pixclk_src = CLK_SRC_PLL,
99 .sysclk_divider = 0,
100 .sysclk_src = CLK_SRC_PLL,
101 }
102};
103
104
105static struct w100_gpio_regs e800_w100_gpio_info = {
106 .init_data1 = 0xc13fc019,
107 .gpio_dir1 = 0x3e40df7f,
108 .gpio_oe1 = 0x003c3000,
109 .init_data2 = 0x00000000,
110 .gpio_dir2 = 0x00000000,
111 .gpio_oe2 = 0x00000000,
112};
113
114static struct w100_mem_info e800_w100_mem_info = {
115 .ext_cntl = 0x09640011,
116 .sdram_mode_reg = 0x00600021,
117 .ext_timing_cntl = 0x10001545,
118 .io_cntl = 0x7ddd7333,
119 .size = 0x1fffff,
120};
121
122static void e800_tg_change(struct w100fb_par *par)
123{
124 unsigned long tmp;
125
126 tmp = w100fb_gpio_read(W100_GPIO_PORT_A);
127 if (par->mode->xres == 480)
128 tmp |= 0x100;
129 else
130 tmp &= ~0x100;
131 w100fb_gpio_write(W100_GPIO_PORT_A, tmp);
132}
133
134static struct w100_tg_info e800_tg_info = {
135 .change = e800_tg_change,
136};
137
138static struct w100fb_mach_info e800_fb_info = {
139 .modelist = e800_lcd_mode,
140 .num_modes = 2,
141 .regs = &e800_lcd_regs,
142 .gpio = &e800_w100_gpio_info,
143 .mem = &e800_w100_mem_info,
144 .tg = &e800_tg_info,
145 .xtal_freq = 16000000,
146};
147
148static struct resource e800_fb_resources[] = {
149 [0] = {
150 .start = 0x0c000000,
151 .end = 0x0cffffff,
152 .flags = IORESOURCE_MEM,
153 },
154};
155
156static struct platform_device e800_fb_device = {
157 .name = "w100fb",
158 .id = -1,
159 .dev = {
160 .platform_data = &e800_fb_info,
161 },
162 .num_resources = ARRAY_SIZE(e800_fb_resources),
163 .resource = e800_fb_resources,
164};
165
166/* --------------------------- UDC definitions --------------------------- */
167
168static struct pxa2xx_udc_mach_info e800_udc_mach_info = {
169 .gpio_vbus = GPIO_E800_USB_DISC,
170 .gpio_pullup = GPIO_E800_USB_PULLUP,
171 .gpio_pullup_inverted = 1
172};
173
174/* ----------------- e800 tc6393xb parameters ------------------ */
175
176static struct tc6393xb_platform_data e800_tc6393xb_info = {
177 .irq_base = IRQ_BOARD_START,
178 .scr_pll2cr = 0x0cc1,
179 .scr_gper = 0,
180 .gpio_base = -1,
181 .suspend = &eseries_tmio_suspend,
182 .resume = &eseries_tmio_resume,
183 .enable = &eseries_tmio_enable,
184 .disable = &eseries_tmio_disable,
185};
186
187static struct platform_device e800_tc6393xb_device = {
188 .name = "tc6393xb",
189 .id = -1,
190 .dev = {
191 .platform_data = &e800_tc6393xb_info,
192 },
193 .num_resources = 2,
194 .resource = eseries_tmio_resources,
195};
196
197/* ----------------------------------------------------------------------- */
198
199static struct platform_device *devices[] __initdata = {
200 &e800_fb_device,
201 &e800_tc6393xb_device,
202};
203
204static void __init e800_init(void)
205{
206 pxa2xx_mfp_config(ARRAY_AND_SIZE(e800_pin_config));
207 pxa_set_ffuart_info(NULL);
208 pxa_set_btuart_info(NULL);
209 pxa_set_stuart_info(NULL);
210 clk_add_alias("CLK_CK3P6MI", e800_tc6393xb_device.name,
211 "GPIO11_CLK", NULL),
212 eseries_get_tmio_gpios();
213 platform_add_devices(devices, ARRAY_SIZE(devices));
214 pxa_set_udc_info(&e800_udc_mach_info);
215 pxa_set_ac97_info(NULL);
216}
217
218MACHINE_START(E800, "Toshiba e800")
219 /* Maintainer: Ian Molton (spyro@f2s.com) */
220 .phys_io = 0x40000000,
221 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
222 .boot_params = 0xa0000100,
223 .map_io = pxa_map_io,
224 .init_irq = pxa25x_init_irq,
225 .fixup = eseries_fixup,
226 .init_machine = e800_init,
227 .timer = &pxa_timer,
228MACHINE_END
229
diff --git a/arch/arm/mach-pxa/eseries.c b/arch/arm/mach-pxa/eseries.c
index a0ab3082a000..349212a1cbd3 100644
--- a/arch/arm/mach-pxa/eseries.c
+++ b/arch/arm/mach-pxa/eseries.c
@@ -15,6 +15,13 @@
15#include <linux/gpio.h> 15#include <linux/gpio.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/mfd/tc6387xb.h>
19#include <linux/mfd/tc6393xb.h>
20#include <linux/mfd/t7l66xb.h>
21#include <linux/mtd/nand.h>
22#include <linux/mtd/partitions.h>
23
24#include <video/w100fb.h>
18 25
19#include <asm/setup.h> 26#include <asm/setup.h>
20#include <asm/mach/arch.h> 27#include <asm/mach/arch.h>
@@ -22,9 +29,12 @@
22 29
23#include <mach/pxa25x.h> 30#include <mach/pxa25x.h>
24#include <mach/eseries-gpio.h> 31#include <mach/eseries-gpio.h>
32#include <mach/audio.h>
33#include <mach/pxafb.h>
25#include <mach/udc.h> 34#include <mach/udc.h>
26#include <mach/irda.h> 35#include <mach/irda.h>
27 36
37#include "devices.h"
28#include "generic.h" 38#include "generic.h"
29#include "clock.h" 39#include "clock.h"
30 40
@@ -130,3 +140,802 @@ void eseries_register_clks(void)
130 clkdev_add_table(eseries_clkregs, ARRAY_SIZE(eseries_clkregs)); 140 clkdev_add_table(eseries_clkregs, ARRAY_SIZE(eseries_clkregs));
131} 141}
132 142
143#ifdef CONFIG_MACH_E330
144/* -------------------- e330 tc6387xb parameters -------------------- */
145
146static struct tc6387xb_platform_data e330_tc6387xb_info = {
147 .enable = &eseries_tmio_enable,
148 .disable = &eseries_tmio_disable,
149 .suspend = &eseries_tmio_suspend,
150 .resume = &eseries_tmio_resume,
151};
152
153static struct platform_device e330_tc6387xb_device = {
154 .name = "tc6387xb",
155 .id = -1,
156 .dev = {
157 .platform_data = &e330_tc6387xb_info,
158 },
159 .num_resources = 2,
160 .resource = eseries_tmio_resources,
161};
162
163/* --------------------------------------------------------------- */
164
165static struct platform_device *e330_devices[] __initdata = {
166 &e330_tc6387xb_device,
167};
168
169static void __init e330_init(void)
170{
171 pxa_set_ffuart_info(NULL);
172 pxa_set_btuart_info(NULL);
173 pxa_set_stuart_info(NULL);
174 eseries_register_clks();
175 eseries_get_tmio_gpios();
176 platform_add_devices(ARRAY_AND_SIZE(e330_devices));
177 pxa_set_udc_info(&e7xx_udc_mach_info);
178}
179
180MACHINE_START(E330, "Toshiba e330")
181 /* Maintainer: Ian Molton (spyro@f2s.com) */
182 .phys_io = 0x40000000,
183 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
184 .boot_params = 0xa0000100,
185 .map_io = pxa_map_io,
186 .init_irq = pxa25x_init_irq,
187 .fixup = eseries_fixup,
188 .init_machine = e330_init,
189 .timer = &pxa_timer,
190MACHINE_END
191#endif
192
193#ifdef CONFIG_MACH_E350
194/* -------------------- e350 t7l66xb parameters -------------------- */
195
196static struct t7l66xb_platform_data e350_t7l66xb_info = {
197 .irq_base = IRQ_BOARD_START,
198 .enable = &eseries_tmio_enable,
199 .suspend = &eseries_tmio_suspend,
200 .resume = &eseries_tmio_resume,
201};
202
203static struct platform_device e350_t7l66xb_device = {
204 .name = "t7l66xb",
205 .id = -1,
206 .dev = {
207 .platform_data = &e350_t7l66xb_info,
208 },
209 .num_resources = 2,
210 .resource = eseries_tmio_resources,
211};
212
213/* ---------------------------------------------------------- */
214
215static struct platform_device *e350_devices[] __initdata = {
216 &e350_t7l66xb_device,
217};
218
219static void __init e350_init(void)
220{
221 pxa_set_ffuart_info(NULL);
222 pxa_set_btuart_info(NULL);
223 pxa_set_stuart_info(NULL);
224 eseries_register_clks();
225 eseries_get_tmio_gpios();
226 platform_add_devices(ARRAY_AND_SIZE(e350_devices));
227 pxa_set_udc_info(&e7xx_udc_mach_info);
228}
229
230MACHINE_START(E350, "Toshiba e350")
231 /* Maintainer: Ian Molton (spyro@f2s.com) */
232 .phys_io = 0x40000000,
233 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
234 .boot_params = 0xa0000100,
235 .map_io = pxa_map_io,
236 .init_irq = pxa25x_init_irq,
237 .fixup = eseries_fixup,
238 .init_machine = e350_init,
239 .timer = &pxa_timer,
240MACHINE_END
241#endif
242
243#ifdef CONFIG_MACH_E400
244/* ------------------------ E400 LCD definitions ------------------------ */
245
246static struct pxafb_mode_info e400_pxafb_mode_info = {
247 .pixclock = 140703,
248 .xres = 240,
249 .yres = 320,
250 .bpp = 16,
251 .hsync_len = 4,
252 .left_margin = 28,
253 .right_margin = 8,
254 .vsync_len = 3,
255 .upper_margin = 5,
256 .lower_margin = 6,
257 .sync = 0,
258};
259
260static struct pxafb_mach_info e400_pxafb_mach_info = {
261 .modes = &e400_pxafb_mode_info,
262 .num_modes = 1,
263 .lcd_conn = LCD_COLOR_TFT_16BPP,
264 .lccr3 = 0,
265 .pxafb_backlight_power = NULL,
266};
267
268/* ------------------------ E400 MFP config ----------------------------- */
269
270static unsigned long e400_pin_config[] __initdata = {
271 /* Chip selects */
272 GPIO15_nCS_1, /* CS1 - Flash */
273 GPIO80_nCS_4, /* CS4 - TMIO */
274
275 /* Clocks */
276 GPIO12_32KHz,
277
278 /* BTUART */
279 GPIO42_BTUART_RXD,
280 GPIO43_BTUART_TXD,
281 GPIO44_BTUART_CTS,
282
283 /* TMIO controller */
284 GPIO19_GPIO, /* t7l66xb #PCLR */
285 GPIO45_GPIO, /* t7l66xb #SUSPEND (NOT BTUART!) */
286
287 /* wakeup */
288 GPIO0_GPIO | WAKEUP_ON_EDGE_RISE,
289};
290
291/* ---------------------------------------------------------------------- */
292
293static struct mtd_partition partition_a = {
294 .name = "Internal NAND flash",
295 .offset = 0,
296 .size = MTDPART_SIZ_FULL,
297};
298
299static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
300
301static struct nand_bbt_descr e400_t7l66xb_nand_bbt = {
302 .options = 0,
303 .offs = 4,
304 .len = 2,
305 .pattern = scan_ff_pattern
306};
307
308static struct tmio_nand_data e400_t7l66xb_nand_config = {
309 .num_partitions = 1,
310 .partition = &partition_a,
311 .badblock_pattern = &e400_t7l66xb_nand_bbt,
312};
313
314static struct t7l66xb_platform_data e400_t7l66xb_info = {
315 .irq_base = IRQ_BOARD_START,
316 .enable = &eseries_tmio_enable,
317 .suspend = &eseries_tmio_suspend,
318 .resume = &eseries_tmio_resume,
319
320 .nand_data = &e400_t7l66xb_nand_config,
321};
322
323static struct platform_device e400_t7l66xb_device = {
324 .name = "t7l66xb",
325 .id = -1,
326 .dev = {
327 .platform_data = &e400_t7l66xb_info,
328 },
329 .num_resources = 2,
330 .resource = eseries_tmio_resources,
331};
332
333/* ---------------------------------------------------------- */
334
335static struct platform_device *e400_devices[] __initdata = {
336 &e400_t7l66xb_device,
337};
338
339static void __init e400_init(void)
340{
341 pxa2xx_mfp_config(ARRAY_AND_SIZE(e400_pin_config));
342 pxa_set_ffuart_info(NULL);
343 pxa_set_btuart_info(NULL);
344 pxa_set_stuart_info(NULL);
345 /* Fixme - e400 may have a switched clock */
346 eseries_register_clks();
347 eseries_get_tmio_gpios();
348 set_pxa_fb_info(&e400_pxafb_mach_info);
349 platform_add_devices(ARRAY_AND_SIZE(e400_devices));
350 pxa_set_udc_info(&e7xx_udc_mach_info);
351}
352
353MACHINE_START(E400, "Toshiba e400")
354 /* Maintainer: Ian Molton (spyro@f2s.com) */
355 .phys_io = 0x40000000,
356 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
357 .boot_params = 0xa0000100,
358 .map_io = pxa_map_io,
359 .init_irq = pxa25x_init_irq,
360 .fixup = eseries_fixup,
361 .init_machine = e400_init,
362 .timer = &pxa_timer,
363MACHINE_END
364#endif
365
366#ifdef CONFIG_MACH_E740
367/* ------------------------ e740 video support --------------------------- */
368
369static struct w100_gen_regs e740_lcd_regs = {
370 .lcd_format = 0x00008023,
371 .lcdd_cntl1 = 0x0f000000,
372 .lcdd_cntl2 = 0x0003ffff,
373 .genlcd_cntl1 = 0x00ffff03,
374 .genlcd_cntl2 = 0x003c0f03,
375 .genlcd_cntl3 = 0x000143aa,
376};
377
378static struct w100_mode e740_lcd_mode = {
379 .xres = 240,
380 .yres = 320,
381 .left_margin = 20,
382 .right_margin = 28,
383 .upper_margin = 9,
384 .lower_margin = 8,
385 .crtc_ss = 0x80140013,
386 .crtc_ls = 0x81150110,
387 .crtc_gs = 0x80050005,
388 .crtc_vpos_gs = 0x000a0009,
389 .crtc_rev = 0x0040010a,
390 .crtc_dclk = 0xa906000a,
391 .crtc_gclk = 0x80050108,
392 .crtc_goe = 0x80050108,
393 .pll_freq = 57,
394 .pixclk_divider = 4,
395 .pixclk_divider_rotated = 4,
396 .pixclk_src = CLK_SRC_XTAL,
397 .sysclk_divider = 1,
398 .sysclk_src = CLK_SRC_PLL,
399 .crtc_ps1_active = 0x41060010,
400};
401
402static struct w100_gpio_regs e740_w100_gpio_info = {
403 .init_data1 = 0x21002103,
404 .gpio_dir1 = 0xffffdeff,
405 .gpio_oe1 = 0x03c00643,
406 .init_data2 = 0x003f003f,
407 .gpio_dir2 = 0xffffffff,
408 .gpio_oe2 = 0x000000ff,
409};
410
411static struct w100fb_mach_info e740_fb_info = {
412 .modelist = &e740_lcd_mode,
413 .num_modes = 1,
414 .regs = &e740_lcd_regs,
415 .gpio = &e740_w100_gpio_info,
416 .xtal_freq = 14318000,
417 .xtal_dbl = 1,
418};
419
420static struct resource e740_fb_resources[] = {
421 [0] = {
422 .start = 0x0c000000,
423 .end = 0x0cffffff,
424 .flags = IORESOURCE_MEM,
425 },
426};
427
428static struct platform_device e740_fb_device = {
429 .name = "w100fb",
430 .id = -1,
431 .dev = {
432 .platform_data = &e740_fb_info,
433 },
434 .num_resources = ARRAY_SIZE(e740_fb_resources),
435 .resource = e740_fb_resources,
436};
437
438/* --------------------------- MFP Pin config -------------------------- */
439
440static unsigned long e740_pin_config[] __initdata = {
441 /* Chip selects */
442 GPIO15_nCS_1, /* CS1 - Flash */
443 GPIO79_nCS_3, /* CS3 - IMAGEON */
444 GPIO80_nCS_4, /* CS4 - TMIO */
445
446 /* Clocks */
447 GPIO12_32KHz,
448
449 /* BTUART */
450 GPIO42_BTUART_RXD,
451 GPIO43_BTUART_TXD,
452 GPIO44_BTUART_CTS,
453
454 /* TMIO controller */
455 GPIO19_GPIO, /* t7l66xb #PCLR */
456 GPIO45_GPIO, /* t7l66xb #SUSPEND (NOT BTUART!) */
457
458 /* UDC */
459 GPIO13_GPIO,
460 GPIO3_GPIO,
461
462 /* IrDA */
463 GPIO38_GPIO | MFP_LPM_DRIVE_HIGH,
464
465 /* AC97 */
466 GPIO28_AC97_BITCLK,
467 GPIO29_AC97_SDATA_IN_0,
468 GPIO30_AC97_SDATA_OUT,
469 GPIO31_AC97_SYNC,
470
471 /* Audio power control */
472 GPIO16_GPIO, /* AC97 codec AVDD2 supply (analogue power) */
473 GPIO40_GPIO, /* Mic amp power */
474 GPIO41_GPIO, /* Headphone amp power */
475
476 /* PC Card */
477 GPIO8_GPIO, /* CD0 */
478 GPIO44_GPIO, /* CD1 */
479 GPIO11_GPIO, /* IRQ0 */
480 GPIO6_GPIO, /* IRQ1 */
481 GPIO27_GPIO, /* RST0 */
482 GPIO24_GPIO, /* RST1 */
483 GPIO20_GPIO, /* PWR0 */
484 GPIO23_GPIO, /* PWR1 */
485 GPIO48_nPOE,
486 GPIO49_nPWE,
487 GPIO50_nPIOR,
488 GPIO51_nPIOW,
489 GPIO52_nPCE_1,
490 GPIO53_nPCE_2,
491 GPIO54_nPSKTSEL,
492 GPIO55_nPREG,
493 GPIO56_nPWAIT,
494 GPIO57_nIOIS16,
495
496 /* wakeup */
497 GPIO0_GPIO | WAKEUP_ON_EDGE_RISE,
498};
499
500/* -------------------- e740 t7l66xb parameters -------------------- */
501
502static struct t7l66xb_platform_data e740_t7l66xb_info = {
503 .irq_base = IRQ_BOARD_START,
504 .enable = &eseries_tmio_enable,
505 .suspend = &eseries_tmio_suspend,
506 .resume = &eseries_tmio_resume,
507};
508
509static struct platform_device e740_t7l66xb_device = {
510 .name = "t7l66xb",
511 .id = -1,
512 .dev = {
513 .platform_data = &e740_t7l66xb_info,
514 },
515 .num_resources = 2,
516 .resource = eseries_tmio_resources,
517};
518
519/* ----------------------------------------------------------------------- */
520
521static struct platform_device *e740_devices[] __initdata = {
522 &e740_fb_device,
523 &e740_t7l66xb_device,
524};
525
526static void __init e740_init(void)
527{
528 pxa2xx_mfp_config(ARRAY_AND_SIZE(e740_pin_config));
529 pxa_set_ffuart_info(NULL);
530 pxa_set_btuart_info(NULL);
531 pxa_set_stuart_info(NULL);
532 eseries_register_clks();
533 clk_add_alias("CLK_CK48M", e740_t7l66xb_device.name,
534 "UDCCLK", &pxa25x_device_udc.dev),
535 eseries_get_tmio_gpios();
536 platform_add_devices(ARRAY_AND_SIZE(e740_devices));
537 pxa_set_udc_info(&e7xx_udc_mach_info);
538 pxa_set_ac97_info(NULL);
539 pxa_set_ficp_info(&e7xx_ficp_platform_data);
540}
541
542MACHINE_START(E740, "Toshiba e740")
543 /* Maintainer: Ian Molton (spyro@f2s.com) */
544 .phys_io = 0x40000000,
545 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
546 .boot_params = 0xa0000100,
547 .map_io = pxa_map_io,
548 .init_irq = pxa25x_init_irq,
549 .fixup = eseries_fixup,
550 .init_machine = e740_init,
551 .timer = &pxa_timer,
552MACHINE_END
553#endif
554
555#ifdef CONFIG_MACH_E750
556/* ---------------------- E750 LCD definitions -------------------- */
557
558static struct w100_gen_regs e750_lcd_regs = {
559 .lcd_format = 0x00008003,
560 .lcdd_cntl1 = 0x00000000,
561 .lcdd_cntl2 = 0x0003ffff,
562 .genlcd_cntl1 = 0x00fff003,
563 .genlcd_cntl2 = 0x003c0f03,
564 .genlcd_cntl3 = 0x000143aa,
565};
566
567static struct w100_mode e750_lcd_mode = {
568 .xres = 240,
569 .yres = 320,
570 .left_margin = 21,
571 .right_margin = 22,
572 .upper_margin = 5,
573 .lower_margin = 4,
574 .crtc_ss = 0x80150014,
575 .crtc_ls = 0x8014000d,
576 .crtc_gs = 0xc1000005,
577 .crtc_vpos_gs = 0x00020147,
578 .crtc_rev = 0x0040010a,
579 .crtc_dclk = 0xa1700030,
580 .crtc_gclk = 0x80cc0015,
581 .crtc_goe = 0x80cc0015,
582 .crtc_ps1_active = 0x61060017,
583 .pll_freq = 57,
584 .pixclk_divider = 4,
585 .pixclk_divider_rotated = 4,
586 .pixclk_src = CLK_SRC_XTAL,
587 .sysclk_divider = 1,
588 .sysclk_src = CLK_SRC_PLL,
589};
590
591static struct w100_gpio_regs e750_w100_gpio_info = {
592 .init_data1 = 0x01192f1b,
593 .gpio_dir1 = 0xd5ffdeff,
594 .gpio_oe1 = 0x000020bf,
595 .init_data2 = 0x010f010f,
596 .gpio_dir2 = 0xffffffff,
597 .gpio_oe2 = 0x000001cf,
598};
599
600static struct w100fb_mach_info e750_fb_info = {
601 .modelist = &e750_lcd_mode,
602 .num_modes = 1,
603 .regs = &e750_lcd_regs,
604 .gpio = &e750_w100_gpio_info,
605 .xtal_freq = 14318000,
606 .xtal_dbl = 1,
607};
608
609static struct resource e750_fb_resources[] = {
610 [0] = {
611 .start = 0x0c000000,
612 .end = 0x0cffffff,
613 .flags = IORESOURCE_MEM,
614 },
615};
616
617static struct platform_device e750_fb_device = {
618 .name = "w100fb",
619 .id = -1,
620 .dev = {
621 .platform_data = &e750_fb_info,
622 },
623 .num_resources = ARRAY_SIZE(e750_fb_resources),
624 .resource = e750_fb_resources,
625};
626
627/* -------------------- e750 MFP parameters -------------------- */
628
629static unsigned long e750_pin_config[] __initdata = {
630 /* Chip selects */
631 GPIO15_nCS_1, /* CS1 - Flash */
632 GPIO79_nCS_3, /* CS3 - IMAGEON */
633 GPIO80_nCS_4, /* CS4 - TMIO */
634
635 /* Clocks */
636 GPIO11_3_6MHz,
637
638 /* BTUART */
639 GPIO42_BTUART_RXD,
640 GPIO43_BTUART_TXD,
641 GPIO44_BTUART_CTS,
642
643 /* TMIO controller */
644 GPIO19_GPIO, /* t7l66xb #PCLR */
645 GPIO45_GPIO, /* t7l66xb #SUSPEND (NOT BTUART!) */
646
647 /* UDC */
648 GPIO13_GPIO,
649 GPIO3_GPIO,
650
651 /* IrDA */
652 GPIO38_GPIO | MFP_LPM_DRIVE_HIGH,
653
654 /* AC97 */
655 GPIO28_AC97_BITCLK,
656 GPIO29_AC97_SDATA_IN_0,
657 GPIO30_AC97_SDATA_OUT,
658 GPIO31_AC97_SYNC,
659
660 /* Audio power control */
661 GPIO4_GPIO, /* Headphone amp power */
662 GPIO7_GPIO, /* Speaker amp power */
663 GPIO37_GPIO, /* Headphone detect */
664
665 /* PC Card */
666 GPIO8_GPIO, /* CD0 */
667 GPIO44_GPIO, /* CD1 */
668 GPIO11_GPIO, /* IRQ0 */
669 GPIO6_GPIO, /* IRQ1 */
670 GPIO27_GPIO, /* RST0 */
671 GPIO24_GPIO, /* RST1 */
672 GPIO20_GPIO, /* PWR0 */
673 GPIO23_GPIO, /* PWR1 */
674 GPIO48_nPOE,
675 GPIO49_nPWE,
676 GPIO50_nPIOR,
677 GPIO51_nPIOW,
678 GPIO52_nPCE_1,
679 GPIO53_nPCE_2,
680 GPIO54_nPSKTSEL,
681 GPIO55_nPREG,
682 GPIO56_nPWAIT,
683 GPIO57_nIOIS16,
684
685 /* wakeup */
686 GPIO0_GPIO | WAKEUP_ON_EDGE_RISE,
687};
688
689/* ----------------- e750 tc6393xb parameters ------------------ */
690
691static struct tc6393xb_platform_data e750_tc6393xb_info = {
692 .irq_base = IRQ_BOARD_START,
693 .scr_pll2cr = 0x0cc1,
694 .scr_gper = 0,
695 .gpio_base = -1,
696 .suspend = &eseries_tmio_suspend,
697 .resume = &eseries_tmio_resume,
698 .enable = &eseries_tmio_enable,
699 .disable = &eseries_tmio_disable,
700};
701
702static struct platform_device e750_tc6393xb_device = {
703 .name = "tc6393xb",
704 .id = -1,
705 .dev = {
706 .platform_data = &e750_tc6393xb_info,
707 },
708 .num_resources = 2,
709 .resource = eseries_tmio_resources,
710};
711
712/* ------------------------------------------------------------- */
713
714static struct platform_device *e750_devices[] __initdata = {
715 &e750_fb_device,
716 &e750_tc6393xb_device,
717};
718
719static void __init e750_init(void)
720{
721 pxa2xx_mfp_config(ARRAY_AND_SIZE(e750_pin_config));
722 pxa_set_ffuart_info(NULL);
723 pxa_set_btuart_info(NULL);
724 pxa_set_stuart_info(NULL);
725 clk_add_alias("CLK_CK3P6MI", e750_tc6393xb_device.name,
726 "GPIO11_CLK", NULL),
727 eseries_get_tmio_gpios();
728 platform_add_devices(ARRAY_AND_SIZE(e750_devices));
729 pxa_set_udc_info(&e7xx_udc_mach_info);
730 pxa_set_ac97_info(NULL);
731 pxa_set_ficp_info(&e7xx_ficp_platform_data);
732}
733
734MACHINE_START(E750, "Toshiba e750")
735 /* Maintainer: Ian Molton (spyro@f2s.com) */
736 .phys_io = 0x40000000,
737 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
738 .boot_params = 0xa0000100,
739 .map_io = pxa_map_io,
740 .init_irq = pxa25x_init_irq,
741 .fixup = eseries_fixup,
742 .init_machine = e750_init,
743 .timer = &pxa_timer,
744MACHINE_END
745#endif
746
747#ifdef CONFIG_MACH_E800
748/* ------------------------ e800 LCD definitions ------------------------- */
749
750static unsigned long e800_pin_config[] __initdata = {
751 /* AC97 */
752 GPIO28_AC97_BITCLK,
753 GPIO29_AC97_SDATA_IN_0,
754 GPIO30_AC97_SDATA_OUT,
755 GPIO31_AC97_SYNC,
756};
757
758static struct w100_gen_regs e800_lcd_regs = {
759 .lcd_format = 0x00008003,
760 .lcdd_cntl1 = 0x02a00000,
761 .lcdd_cntl2 = 0x0003ffff,
762 .genlcd_cntl1 = 0x000ff2a3,
763 .genlcd_cntl2 = 0x000002a3,
764 .genlcd_cntl3 = 0x000102aa,
765};
766
767static struct w100_mode e800_lcd_mode[2] = {
768 [0] = {
769 .xres = 480,
770 .yres = 640,
771 .left_margin = 52,
772 .right_margin = 148,
773 .upper_margin = 2,
774 .lower_margin = 6,
775 .crtc_ss = 0x80350034,
776 .crtc_ls = 0x802b0026,
777 .crtc_gs = 0x80160016,
778 .crtc_vpos_gs = 0x00020003,
779 .crtc_rev = 0x0040001d,
780 .crtc_dclk = 0xe0000000,
781 .crtc_gclk = 0x82a50049,
782 .crtc_goe = 0x80ee001c,
783 .crtc_ps1_active = 0x00000000,
784 .pll_freq = 128,
785 .pixclk_divider = 4,
786 .pixclk_divider_rotated = 6,
787 .pixclk_src = CLK_SRC_PLL,
788 .sysclk_divider = 0,
789 .sysclk_src = CLK_SRC_PLL,
790 },
791 [1] = {
792 .xres = 240,
793 .yres = 320,
794 .left_margin = 15,
795 .right_margin = 88,
796 .upper_margin = 0,
797 .lower_margin = 7,
798 .crtc_ss = 0xd010000f,
799 .crtc_ls = 0x80070003,
800 .crtc_gs = 0x80000000,
801 .crtc_vpos_gs = 0x01460147,
802 .crtc_rev = 0x00400003,
803 .crtc_dclk = 0xa1700030,
804 .crtc_gclk = 0x814b0008,
805 .crtc_goe = 0x80cc0015,
806 .crtc_ps1_active = 0x00000000,
807 .pll_freq = 100,
808 .pixclk_divider = 6, /* Wince uses 14 which gives a */
809 .pixclk_divider_rotated = 6, /* 7MHz Pclk. We use a 14MHz one */
810 .pixclk_src = CLK_SRC_PLL,
811 .sysclk_divider = 0,
812 .sysclk_src = CLK_SRC_PLL,
813 }
814};
815
816
817static struct w100_gpio_regs e800_w100_gpio_info = {
818 .init_data1 = 0xc13fc019,
819 .gpio_dir1 = 0x3e40df7f,
820 .gpio_oe1 = 0x003c3000,
821 .init_data2 = 0x00000000,
822 .gpio_dir2 = 0x00000000,
823 .gpio_oe2 = 0x00000000,
824};
825
826static struct w100_mem_info e800_w100_mem_info = {
827 .ext_cntl = 0x09640011,
828 .sdram_mode_reg = 0x00600021,
829 .ext_timing_cntl = 0x10001545,
830 .io_cntl = 0x7ddd7333,
831 .size = 0x1fffff,
832};
833
834static void e800_tg_change(struct w100fb_par *par)
835{
836 unsigned long tmp;
837
838 tmp = w100fb_gpio_read(W100_GPIO_PORT_A);
839 if (par->mode->xres == 480)
840 tmp |= 0x100;
841 else
842 tmp &= ~0x100;
843 w100fb_gpio_write(W100_GPIO_PORT_A, tmp);
844}
845
846static struct w100_tg_info e800_tg_info = {
847 .change = e800_tg_change,
848};
849
850static struct w100fb_mach_info e800_fb_info = {
851 .modelist = e800_lcd_mode,
852 .num_modes = 2,
853 .regs = &e800_lcd_regs,
854 .gpio = &e800_w100_gpio_info,
855 .mem = &e800_w100_mem_info,
856 .tg = &e800_tg_info,
857 .xtal_freq = 16000000,
858};
859
860static struct resource e800_fb_resources[] = {
861 [0] = {
862 .start = 0x0c000000,
863 .end = 0x0cffffff,
864 .flags = IORESOURCE_MEM,
865 },
866};
867
868static struct platform_device e800_fb_device = {
869 .name = "w100fb",
870 .id = -1,
871 .dev = {
872 .platform_data = &e800_fb_info,
873 },
874 .num_resources = ARRAY_SIZE(e800_fb_resources),
875 .resource = e800_fb_resources,
876};
877
878/* --------------------------- UDC definitions --------------------------- */
879
880static struct pxa2xx_udc_mach_info e800_udc_mach_info = {
881 .gpio_vbus = GPIO_E800_USB_DISC,
882 .gpio_pullup = GPIO_E800_USB_PULLUP,
883 .gpio_pullup_inverted = 1
884};
885
886/* ----------------- e800 tc6393xb parameters ------------------ */
887
888static struct tc6393xb_platform_data e800_tc6393xb_info = {
889 .irq_base = IRQ_BOARD_START,
890 .scr_pll2cr = 0x0cc1,
891 .scr_gper = 0,
892 .gpio_base = -1,
893 .suspend = &eseries_tmio_suspend,
894 .resume = &eseries_tmio_resume,
895 .enable = &eseries_tmio_enable,
896 .disable = &eseries_tmio_disable,
897};
898
899static struct platform_device e800_tc6393xb_device = {
900 .name = "tc6393xb",
901 .id = -1,
902 .dev = {
903 .platform_data = &e800_tc6393xb_info,
904 },
905 .num_resources = 2,
906 .resource = eseries_tmio_resources,
907};
908
909/* ----------------------------------------------------------------------- */
910
911static struct platform_device *e800_devices[] __initdata = {
912 &e800_fb_device,
913 &e800_tc6393xb_device,
914};
915
916static void __init e800_init(void)
917{
918 pxa2xx_mfp_config(ARRAY_AND_SIZE(e800_pin_config));
919 pxa_set_ffuart_info(NULL);
920 pxa_set_btuart_info(NULL);
921 pxa_set_stuart_info(NULL);
922 clk_add_alias("CLK_CK3P6MI", e800_tc6393xb_device.name,
923 "GPIO11_CLK", NULL),
924 eseries_get_tmio_gpios();
925 platform_add_devices(ARRAY_AND_SIZE(e800_devices));
926 pxa_set_udc_info(&e800_udc_mach_info);
927 pxa_set_ac97_info(NULL);
928}
929
930MACHINE_START(E800, "Toshiba e800")
931 /* Maintainer: Ian Molton (spyro@f2s.com) */
932 .phys_io = 0x40000000,
933 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
934 .boot_params = 0xa0000100,
935 .map_io = pxa_map_io,
936 .init_irq = pxa25x_init_irq,
937 .fixup = eseries_fixup,
938 .init_machine = e800_init,
939 .timer = &pxa_timer,
940MACHINE_END
941#endif
diff --git a/arch/arm/mach-pxa/imote2.c b/arch/arm/mach-pxa/imote2.c
deleted file mode 100644
index 5161dca8ccc0..000000000000
--- a/arch/arm/mach-pxa/imote2.c
+++ /dev/null
@@ -1,590 +0,0 @@
1/*
2 * linux/arch/arm/mach-pxa/imote2.c
3 *
4 * Author: Ed C. Epp
5 * Created: Nov 05, 2002
6 * Copyright: Intel Corp.
7 *
8 * Modified 2008: Jonathan Cameron
9 *
10 * The Imote2 is a wireless sensor node platform sold
11 * by Crossbow (www.xbow.com).
12 */
13
14#include <linux/init.h>
15#include <linux/device.h>
16#include <linux/mtd/mtd.h>
17#include <linux/mtd/partitions.h>
18#include <linux/platform_device.h>
19#include <linux/regulator/machine.h>
20#include <linux/gpio.h>
21#include <linux/leds.h>
22#include <linux/spi/spi.h>
23#include <linux/i2c.h>
24#include <linux/mfd/da903x.h>
25#include <linux/sht15.h>
26
27#include <asm/mach-types.h>
28#include <asm/mach/arch.h>
29#include <asm/mach/map.h>
30#include <asm/mach/flash.h>
31
32#include <mach/pxa27x.h>
33#include <plat/i2c.h>
34#include <mach/udc.h>
35#include <mach/mmc.h>
36#include <mach/pxa2xx_spi.h>
37#include <mach/pxa27x-udc.h>
38
39#include "devices.h"
40#include "generic.h"
41
42static unsigned long imote2_pin_config[] __initdata = {
43
44 /* Device Identification for wakeup*/
45 GPIO102_GPIO,
46
47 /* Button */
48 GPIO91_GPIO,
49
50 /* DA9030 */
51 GPIO1_GPIO,
52
53 /* MMC */
54 GPIO32_MMC_CLK,
55 GPIO112_MMC_CMD,
56 GPIO92_MMC_DAT_0,
57 GPIO109_MMC_DAT_1,
58 GPIO110_MMC_DAT_2,
59 GPIO111_MMC_DAT_3,
60
61 /* 802.15.4 radio - driver out of mainline */
62 GPIO22_GPIO, /* CC_RSTN */
63 GPIO114_GPIO, /* CC_FIFO */
64 GPIO116_GPIO, /* CC_CCA */
65 GPIO0_GPIO, /* CC_FIFOP */
66 GPIO16_GPIO, /* CCSFD */
67 GPIO115_GPIO, /* Power enable */
68
69 /* I2C */
70 GPIO117_I2C_SCL,
71 GPIO118_I2C_SDA,
72
73 /* SSP 3 - 802.15.4 radio */
74 GPIO39_GPIO, /* Chip Select */
75 GPIO34_SSP3_SCLK,
76 GPIO35_SSP3_TXD,
77 GPIO41_SSP3_RXD,
78
79 /* SSP 2 - to daughter boards */
80 GPIO37_GPIO, /* Chip Select */
81 GPIO36_SSP2_SCLK,
82 GPIO38_SSP2_TXD,
83 GPIO11_SSP2_RXD,
84
85 /* SSP 1 - to daughter boards */
86 GPIO24_GPIO, /* Chip Select */
87 GPIO23_SSP1_SCLK,
88 GPIO25_SSP1_TXD,
89 GPIO26_SSP1_RXD,
90
91 /* BTUART Basic Connector*/
92 GPIO42_BTUART_RXD,
93 GPIO43_BTUART_TXD,
94 GPIO44_BTUART_CTS,
95 GPIO45_BTUART_RTS,
96
97 /* STUART Serial console via debug board*/
98 GPIO46_STUART_RXD,
99 GPIO47_STUART_TXD,
100
101 /* Basic sensor board */
102 GPIO96_GPIO, /* accelerometer interrupt */
103 GPIO99_GPIO, /* ADC interrupt */
104
105 /* SHT15 */
106 GPIO100_GPIO,
107 GPIO98_GPIO,
108
109 /* Connector pins specified as gpios */
110 GPIO94_GPIO, /* large basic connector pin 14 */
111 GPIO10_GPIO, /* large basic connector pin 23 */
112
113 /* LEDS */
114 GPIO103_GPIO, /* red led */
115 GPIO104_GPIO, /* green led */
116 GPIO105_GPIO, /* blue led */
117};
118
119static struct sht15_platform_data platform_data_sht15 = {
120 .gpio_data = 100,
121 .gpio_sck = 98,
122};
123
124static struct platform_device sht15 = {
125 .name = "sht15",
126 .id = -1,
127 .dev = {
128 .platform_data = &platform_data_sht15,
129 },
130};
131
132static struct regulator_consumer_supply imote2_sensor_3_con[] = {
133 {
134 .dev = &sht15.dev,
135 .supply = "vcc",
136 },
137};
138
139static struct gpio_led imote2_led_pins[] = {
140 {
141 .name = "imote2:red",
142 .gpio = 103,
143 .active_low = 1,
144 }, {
145 .name = "imote2:green",
146 .gpio = 104,
147 .active_low = 1,
148 }, {
149 .name = "imote2:blue",
150 .gpio = 105,
151 .active_low = 1,
152 },
153};
154
155static struct gpio_led_platform_data imote2_led_data = {
156 .num_leds = ARRAY_SIZE(imote2_led_pins),
157 .leds = imote2_led_pins,
158};
159
160static struct platform_device imote2_leds = {
161 .name = "leds-gpio",
162 .id = -1,
163 .dev = {
164 .platform_data = &imote2_led_data,
165 },
166};
167
168/* Reverse engineered partly from Platformx drivers */
169enum imote2_ldos{
170 vcc_vref,
171 vcc_cc2420,
172 vcc_mica,
173 vcc_bt,
174 /* The two voltages available to sensor boards */
175 vcc_sensor_1_8,
176 vcc_sensor_3,
177
178 vcc_sram_ext, /* directly connected to the pxa271 */
179 vcc_pxa_pll,
180 vcc_pxa_usim, /* Reference voltage for certain gpios */
181 vcc_pxa_mem,
182 vcc_pxa_flash,
183 vcc_pxa_core, /*Dc-Dc buck not yet supported */
184 vcc_lcd,
185 vcc_bb,
186 vcc_bbio,
187 vcc_io, /* cc2420 802.15.4 radio and pxa vcc_io ?*/
188};
189
190/* The values of the various regulator constraints are obviously dependent
191 * on exactly what is wired to each ldo. Unfortunately this information is
192 * not generally available. More information has been requested from Xbow
193 * but as of yet they haven't been forthcoming.
194 *
195 * Some of these are clearly Stargate 2 related (no way of plugging
196 * in an lcd on the IM2 for example!).
197 */
198static struct regulator_init_data imote2_ldo_init_data[] = {
199 [vcc_bbio] = {
200 .constraints = { /* board default 1.8V */
201 .name = "vcc_bbio",
202 .min_uV = 1800000,
203 .max_uV = 1800000,
204 },
205 },
206 [vcc_bb] = {
207 .constraints = { /* board default 2.8V */
208 .name = "vcc_bb",
209 .min_uV = 2700000,
210 .max_uV = 3000000,
211 },
212 },
213 [vcc_pxa_flash] = {
214 .constraints = {/* default is 1.8V */
215 .name = "vcc_pxa_flash",
216 .min_uV = 1800000,
217 .max_uV = 1800000,
218 },
219 },
220 [vcc_cc2420] = { /* also vcc_io */
221 .constraints = {
222 /* board default is 2.8V */
223 .name = "vcc_cc2420",
224 .min_uV = 2700000,
225 .max_uV = 3300000,
226 },
227 },
228 [vcc_vref] = { /* Reference for what? */
229 .constraints = { /* default 1.8V */
230 .name = "vcc_vref",
231 .min_uV = 1800000,
232 .max_uV = 1800000,
233 },
234 },
235 [vcc_sram_ext] = {
236 .constraints = { /* default 2.8V */
237 .name = "vcc_sram_ext",
238 .min_uV = 2800000,
239 .max_uV = 2800000,
240 },
241 },
242 [vcc_mica] = {
243 .constraints = { /* default 2.8V */
244 .name = "vcc_mica",
245 .min_uV = 2800000,
246 .max_uV = 2800000,
247 },
248 },
249 [vcc_bt] = {
250 .constraints = { /* default 2.8V */
251 .name = "vcc_bt",
252 .min_uV = 2800000,
253 .max_uV = 2800000,
254 },
255 },
256 [vcc_lcd] = {
257 .constraints = { /* default 2.8V */
258 .name = "vcc_lcd",
259 .min_uV = 2700000,
260 .max_uV = 3300000,
261 },
262 },
263 [vcc_io] = { /* Same or higher than everything
264 * bar vccbat and vccusb */
265 .constraints = { /* default 2.8V */
266 .name = "vcc_io",
267 .min_uV = 2692000,
268 .max_uV = 3300000,
269 },
270 },
271 [vcc_sensor_1_8] = {
272 .constraints = { /* default 1.8V */
273 .name = "vcc_sensor_1_8",
274 .min_uV = 1800000,
275 .max_uV = 1800000,
276 },
277 },
278 [vcc_sensor_3] = { /* curiously default 2.8V */
279 .constraints = {
280 .name = "vcc_sensor_3",
281 .min_uV = 2800000,
282 .max_uV = 3000000,
283 },
284 .num_consumer_supplies = ARRAY_SIZE(imote2_sensor_3_con),
285 .consumer_supplies = imote2_sensor_3_con,
286 },
287 [vcc_pxa_pll] = { /* 1.17V - 1.43V, default 1.3V*/
288 .constraints = {
289 .name = "vcc_pxa_pll",
290 .min_uV = 1170000,
291 .max_uV = 1430000,
292 },
293 },
294 [vcc_pxa_usim] = {
295 .constraints = { /* default 1.8V */
296 .name = "vcc_pxa_usim",
297 .min_uV = 1710000,
298 .max_uV = 2160000,
299 },
300 },
301 [vcc_pxa_mem] = {
302 .constraints = { /* default 1.8V */
303 .name = "vcc_pxa_mem",
304 .min_uV = 1800000,
305 .max_uV = 1800000,
306 },
307 },
308};
309
310static struct da903x_subdev_info imote2_da9030_subdevs[] = {
311 {
312 .name = "da903x-regulator",
313 .id = DA9030_ID_LDO2,
314 .platform_data = &imote2_ldo_init_data[vcc_bbio],
315 }, {
316 .name = "da903x-regulator",
317 .id = DA9030_ID_LDO3,
318 .platform_data = &imote2_ldo_init_data[vcc_bb],
319 }, {
320 .name = "da903x-regulator",
321 .id = DA9030_ID_LDO4,
322 .platform_data = &imote2_ldo_init_data[vcc_pxa_flash],
323 }, {
324 .name = "da903x-regulator",
325 .id = DA9030_ID_LDO5,
326 .platform_data = &imote2_ldo_init_data[vcc_cc2420],
327 }, {
328 .name = "da903x-regulator",
329 .id = DA9030_ID_LDO6,
330 .platform_data = &imote2_ldo_init_data[vcc_vref],
331 }, {
332 .name = "da903x-regulator",
333 .id = DA9030_ID_LDO7,
334 .platform_data = &imote2_ldo_init_data[vcc_sram_ext],
335 }, {
336 .name = "da903x-regulator",
337 .id = DA9030_ID_LDO8,
338 .platform_data = &imote2_ldo_init_data[vcc_mica],
339 }, {
340 .name = "da903x-regulator",
341 .id = DA9030_ID_LDO9,
342 .platform_data = &imote2_ldo_init_data[vcc_bt],
343 }, {
344 .name = "da903x-regulator",
345 .id = DA9030_ID_LDO10,
346 .platform_data = &imote2_ldo_init_data[vcc_sensor_1_8],
347 }, {
348 .name = "da903x-regulator",
349 .id = DA9030_ID_LDO11,
350 .platform_data = &imote2_ldo_init_data[vcc_sensor_3],
351 }, {
352 .name = "da903x-regulator",
353 .id = DA9030_ID_LDO12,
354 .platform_data = &imote2_ldo_init_data[vcc_lcd],
355 }, {
356 .name = "da903x-regulator",
357 .id = DA9030_ID_LDO15,
358 .platform_data = &imote2_ldo_init_data[vcc_pxa_pll],
359 }, {
360 .name = "da903x-regulator",
361 .id = DA9030_ID_LDO17,
362 .platform_data = &imote2_ldo_init_data[vcc_pxa_usim],
363 }, {
364 .name = "da903x-regulator",
365 .id = DA9030_ID_LDO18,
366 .platform_data = &imote2_ldo_init_data[vcc_io],
367 }, {
368 .name = "da903x-regulator",
369 .id = DA9030_ID_LDO19,
370 .platform_data = &imote2_ldo_init_data[vcc_pxa_mem],
371 },
372};
373
374static struct da903x_platform_data imote2_da9030_pdata = {
375 .num_subdevs = ARRAY_SIZE(imote2_da9030_subdevs),
376 .subdevs = imote2_da9030_subdevs,
377};
378
379/* As the the imote2 doesn't currently have a conventional SD slot
380 * there is no option to hotplug cards, making all this rather simple
381 */
382static int imote2_mci_get_ro(struct device *dev)
383{
384 return 0;
385}
386
387/* Rather simple case as hotplugging not possible */
388static struct pxamci_platform_data imote2_mci_platform_data = {
389 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, /* default anyway */
390 .get_ro = imote2_mci_get_ro,
391 .gpio_card_detect = -1,
392 .gpio_card_ro = -1,
393 .gpio_power = -1,
394};
395
396static struct mtd_partition imote2flash_partitions[] = {
397 {
398 .name = "Bootloader",
399 .size = 0x00040000,
400 .offset = 0,
401 .mask_flags = MTD_WRITEABLE,
402 }, {
403 .name = "Kernel",
404 .size = 0x00200000,
405 .offset = 0x00040000,
406 .mask_flags = 0,
407 }, {
408 .name = "Filesystem",
409 .size = 0x01DC0000,
410 .offset = 0x00240000,
411 .mask_flags = 0,
412 },
413};
414
415static struct resource flash_resources = {
416 .start = PXA_CS0_PHYS,
417 .end = PXA_CS0_PHYS + SZ_32M - 1,
418 .flags = IORESOURCE_MEM,
419};
420
421static struct flash_platform_data imote2_flash_data = {
422 .map_name = "cfi_probe",
423 .parts = imote2flash_partitions,
424 .nr_parts = ARRAY_SIZE(imote2flash_partitions),
425 .name = "PXA27xOnChipROM",
426 .width = 2,
427};
428
429static struct platform_device imote2_flash_device = {
430 .name = "pxa2xx-flash",
431 .id = 0,
432 .dev = {
433 .platform_data = &imote2_flash_data,
434 },
435 .resource = &flash_resources,
436 .num_resources = 1,
437};
438
439/* Some of the drivers here are out of kernel at the moment (parts of IIO)
440 * and it may be a while before they are in the mainline.
441 */
442static struct i2c_board_info __initdata imote2_i2c_board_info[] = {
443 { /* UCAM sensor board */
444 .type = "max1239",
445 .addr = 0x35,
446 }, { /* ITS400 Sensor board only */
447 .type = "max1363",
448 .addr = 0x34,
449 /* Through a nand gate - Also beware, on V2 sensor board the
450 * pull up resistors are missing.
451 */
452 .irq = IRQ_GPIO(99),
453 }, { /* ITS400 Sensor board only */
454 .type = "tsl2561",
455 .addr = 0x49,
456 /* Through a nand gate - Also beware, on V2 sensor board the
457 * pull up resistors are missing.
458 */
459 .irq = IRQ_GPIO(99),
460 }, { /* ITS400 Sensor board only */
461 .type = "tmp175",
462 .addr = 0x4A,
463 .irq = IRQ_GPIO(96),
464 }, { /* IMB400 Multimedia board */
465 .type = "wm8940",
466 .addr = 0x1A,
467 },
468};
469
470static struct i2c_board_info __initdata imote2_pwr_i2c_board_info[] = {
471 {
472 .type = "da9030",
473 .addr = 0x49,
474 .platform_data = &imote2_da9030_pdata,
475 .irq = gpio_to_irq(1),
476 },
477};
478
479static struct pxa2xx_spi_master pxa_ssp_master_0_info = {
480 .num_chipselect = 1,
481};
482
483static struct pxa2xx_spi_master pxa_ssp_master_1_info = {
484 .num_chipselect = 1,
485};
486
487static struct pxa2xx_spi_master pxa_ssp_master_2_info = {
488 .num_chipselect = 1,
489};
490
491static struct pxa2xx_spi_chip staccel_chip_info = {
492 .tx_threshold = 8,
493 .rx_threshold = 8,
494 .dma_burst_size = 8,
495 .timeout = 235,
496 .gpio_cs = 24,
497};
498
499static struct pxa2xx_spi_chip cc2420_info = {
500 .tx_threshold = 8,
501 .rx_threshold = 8,
502 .dma_burst_size = 8,
503 .timeout = 235,
504 .gpio_cs = 39,
505};
506
507static struct spi_board_info spi_board_info[] __initdata = {
508 { /* Driver in IIO */
509 .modalias = "lis3l02dq",
510 .max_speed_hz = 8000000,/* 8MHz max spi frequency at 3V */
511 .bus_num = 1,
512 .chip_select = 0,
513 .controller_data = &staccel_chip_info,
514 .irq = IRQ_GPIO(96),
515 }, { /* Driver out of kernel as it needs considerable rewriting */
516 .modalias = "cc2420",
517 .max_speed_hz = 6500000,
518 .bus_num = 3,
519 .chip_select = 0,
520 .controller_data = &cc2420_info,
521 },
522};
523
524static void im2_udc_command(int cmd)
525{
526 switch (cmd) {
527 case PXA2XX_UDC_CMD_CONNECT:
528 UP2OCR |= UP2OCR_HXOE | UP2OCR_DPPUE | UP2OCR_DPPUBE;
529 break;
530 case PXA2XX_UDC_CMD_DISCONNECT:
531 UP2OCR &= ~(UP2OCR_HXOE | UP2OCR_DPPUE | UP2OCR_DPPUBE);
532 break;
533 }
534}
535
536static struct pxa2xx_udc_mach_info imote2_udc_info __initdata = {
537 .udc_command = im2_udc_command,
538};
539
540static struct platform_device *imote2_devices[] = {
541 &imote2_flash_device,
542 &imote2_leds,
543 &sht15,
544};
545
546static struct i2c_pxa_platform_data i2c_pwr_pdata = {
547 .fast_mode = 1,
548};
549
550static struct i2c_pxa_platform_data i2c_pdata = {
551 .fast_mode = 1,
552};
553
554static void __init imote2_init(void)
555{
556 pxa2xx_mfp_config(ARRAY_AND_SIZE(imote2_pin_config));
557
558 pxa_set_ffuart_info(NULL);
559 pxa_set_btuart_info(NULL);
560 pxa_set_stuart_info(NULL);
561
562 platform_add_devices(imote2_devices, ARRAY_SIZE(imote2_devices));
563
564 pxa2xx_set_spi_info(1, &pxa_ssp_master_0_info);
565 pxa2xx_set_spi_info(2, &pxa_ssp_master_1_info);
566 pxa2xx_set_spi_info(3, &pxa_ssp_master_2_info);
567
568 spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
569
570 i2c_register_board_info(0, imote2_i2c_board_info,
571 ARRAY_SIZE(imote2_i2c_board_info));
572 i2c_register_board_info(1, imote2_pwr_i2c_board_info,
573 ARRAY_SIZE(imote2_pwr_i2c_board_info));
574
575 pxa27x_set_i2c_power_info(&i2c_pwr_pdata);
576 pxa_set_i2c_info(&i2c_pdata);
577
578 pxa_set_mci_info(&imote2_mci_platform_data);
579 pxa_set_udc_info(&imote2_udc_info);
580}
581
582MACHINE_START(INTELMOTE2, "IMOTE 2")
583 .phys_io = 0x40000000,
584 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
585 .map_io = pxa_map_io,
586 .init_irq = pxa27x_init_irq,
587 .timer = &pxa_timer,
588 .init_machine = imote2_init,
589 .boot_params = 0xA0000100,
590MACHINE_END
diff --git a/arch/arm/mach-pxa/include/mach/balloon3.h b/arch/arm/mach-pxa/include/mach/balloon3.h
index 1a741065045f..eec92e6fd7cf 100644
--- a/arch/arm/mach-pxa/include/mach/balloon3.h
+++ b/arch/arm/mach-pxa/include/mach/balloon3.h
@@ -26,21 +26,55 @@ enum balloon3_features {
26#define BALLOON3_FPGA_VIRT (0xf1000000) /* as per balloon2 */ 26#define BALLOON3_FPGA_VIRT (0xf1000000) /* as per balloon2 */
27#define BALLOON3_FPGA_LENGTH 0x01000000 27#define BALLOON3_FPGA_LENGTH 0x01000000
28 28
29/* FPGA/CPLD registers */ 29/* FPGA / CPLD registers for CF socket */
30#define BALLOON3_PCMCIA0_REG (BALLOON3_FPGA_VIRT + 0x00e00008) 30#define BALLOON3_CF_STATUS_REG (BALLOON3_FPGA_VIRT + 0x00e00008)
31/* fixme - same for now */ 31#define BALLOON3_CF_CONTROL_REG (BALLOON3_FPGA_VIRT + 0x00e00008)
32#define BALLOON3_PCMCIA1_REG (BALLOON3_FPGA_VIRT + 0x00e00008) 32/* FPGA / CPLD version register */
33#define BALLOON3_NANDIO_IO_REG (BALLOON3_FPGA_VIRT + 0x00e00000) 33#define BALLOON3_FPGA_VER (BALLOON3_FPGA_VIRT + 0x00e0001c)
34/* FPGA / CPLD registers for NAND flash */
35#define BALLOON3_NAND_BASE (PXA_CS4_PHYS + 0x00e00000)
36#define BALLOON3_NAND_IO_REG (BALLOON3_FPGA_VIRT + 0x00e00000)
37#define BALLOON3_NAND_CONTROL2_REG (BALLOON3_FPGA_VIRT + 0x00e00010)
38#define BALLOON3_NAND_STAT_REG (BALLOON3_FPGA_VIRT + 0x00e00010)
39#define BALLOON3_NAND_CONTROL_REG (BALLOON3_FPGA_VIRT + 0x00e00014)
40
34/* fpga/cpld interrupt control register */ 41/* fpga/cpld interrupt control register */
35#define BALLOON3_INT_CONTROL_REG (BALLOON3_FPGA_VIRT + 0x00e0000C) 42#define BALLOON3_INT_CONTROL_REG (BALLOON3_FPGA_VIRT + 0x00e0000C)
36#define BALLOON3_NANDIO_CTL2_REG (BALLOON3_FPGA_VIRT + 0x00e00010)
37#define BALLOON3_NANDIO_CTL_REG (BALLOON3_FPGA_VIRT + 0x00e00014)
38#define BALLOON3_VERSION_REG (BALLOON3_FPGA_VIRT + 0x00e0001c) 43#define BALLOON3_VERSION_REG (BALLOON3_FPGA_VIRT + 0x00e0001c)
39 44
40#define BALLOON3_SAMOSA_ADDR_REG (BALLOON3_FPGA_VIRT + 0x00c00000) 45#define BALLOON3_SAMOSA_ADDR_REG (BALLOON3_FPGA_VIRT + 0x00c00000)
41#define BALLOON3_SAMOSA_DATA_REG (BALLOON3_FPGA_VIRT + 0x00c00004) 46#define BALLOON3_SAMOSA_DATA_REG (BALLOON3_FPGA_VIRT + 0x00c00004)
42#define BALLOON3_SAMOSA_STATUS_REG (BALLOON3_FPGA_VIRT + 0x00c0001c) 47#define BALLOON3_SAMOSA_STATUS_REG (BALLOON3_FPGA_VIRT + 0x00c0001c)
43 48
49/* CF Status Register bits (read-only) bits */
50#define BALLOON3_CF_nIRQ (1 << 0)
51#define BALLOON3_CF_nSTSCHG_BVD1 (1 << 1)
52
53/* CF Control Set Register bits / CF Control Clear Register bits (write-only) */
54#define BALLOON3_CF_RESET (1 << 0)
55#define BALLOON3_CF_ENABLE (1 << 1)
56#define BALLOON3_CF_ADD_ENABLE (1 << 2)
57
58/* CF Interrupt sources */
59#define BALLOON3_BP_CF_NRDY_IRQ BALLOON3_IRQ(0)
60#define BALLOON3_BP_NSTSCHG_IRQ BALLOON3_IRQ(1)
61
62/* NAND Control register */
63#define BALLOON3_NAND_CONTROL_FLWP (1 << 7)
64#define BALLOON3_NAND_CONTROL_FLSE (1 << 6)
65#define BALLOON3_NAND_CONTROL_FLCE3 (1 << 5)
66#define BALLOON3_NAND_CONTROL_FLCE2 (1 << 4)
67#define BALLOON3_NAND_CONTROL_FLCE1 (1 << 3)
68#define BALLOON3_NAND_CONTROL_FLCE0 (1 << 2)
69#define BALLOON3_NAND_CONTROL_FLALE (1 << 1)
70#define BALLOON3_NAND_CONTROL_FLCLE (1 << 0)
71
72/* NAND Status register */
73#define BALLOON3_NAND_STAT_RNB (1 << 0)
74
75/* NAND Control2 register */
76#define BALLOON3_NAND_CONTROL2_16BIT (1 << 0)
77
44/* GPIOs for irqs */ 78/* GPIOs for irqs */
45#define BALLOON3_GPIO_AUX_NIRQ (94) 79#define BALLOON3_GPIO_AUX_NIRQ (94)
46#define BALLOON3_GPIO_CODEC_IRQ (95) 80#define BALLOON3_GPIO_CODEC_IRQ (95)
@@ -54,20 +88,24 @@ enum balloon3_features {
54 88
55#define BALLOON3_GPIO_S0_CD (105) 89#define BALLOON3_GPIO_S0_CD (105)
56 90
91/* NAND */
92#define BALLOON3_GPIO_RUN_NAND (102)
93
94/* PCF8574A Leds */
95#define BALLOON3_PCF_GPIO_BASE 160
96#define BALLOON3_PCF_GPIO_LED0 (BALLOON3_PCF_GPIO_BASE + 0)
97#define BALLOON3_PCF_GPIO_LED1 (BALLOON3_PCF_GPIO_BASE + 1)
98#define BALLOON3_PCF_GPIO_LED2 (BALLOON3_PCF_GPIO_BASE + 2)
99#define BALLOON3_PCF_GPIO_LED3 (BALLOON3_PCF_GPIO_BASE + 3)
100#define BALLOON3_PCF_GPIO_LED4 (BALLOON3_PCF_GPIO_BASE + 4)
101#define BALLOON3_PCF_GPIO_LED5 (BALLOON3_PCF_GPIO_BASE + 5)
102#define BALLOON3_PCF_GPIO_LED6 (BALLOON3_PCF_GPIO_BASE + 6)
103#define BALLOON3_PCF_GPIO_LED7 (BALLOON3_PCF_GPIO_BASE + 7)
104
57/* FPGA Interrupt Mask/Acknowledge Register */ 105/* FPGA Interrupt Mask/Acknowledge Register */
58#define BALLOON3_INT_S0_IRQ (1 << 0) /* PCMCIA 0 IRQ */ 106#define BALLOON3_INT_S0_IRQ (1 << 0) /* PCMCIA 0 IRQ */
59#define BALLOON3_INT_S0_STSCHG (1 << 1) /* PCMCIA 0 status changed */ 107#define BALLOON3_INT_S0_STSCHG (1 << 1) /* PCMCIA 0 status changed */
60 108
61/* CF Status Register */
62#define BALLOON3_PCMCIA_nIRQ (1 << 0) /* IRQ / ready signal */
63#define BALLOON3_PCMCIA_nSTSCHG_BVD1 (1 << 1)
64 /* VDD sense / card status changed */
65
66/* CF control register (write) */
67#define BALLOON3_PCMCIA_RESET (1 << 0) /* Card reset signal */
68#define BALLOON3_PCMCIA_ENABLE (1 << 1)
69#define BALLOON3_PCMCIA_ADD_ENABLE (1 << 2)
70
71/* CPLD (and FPGA) interface definitions */ 109/* CPLD (and FPGA) interface definitions */
72#define CPLD_LCD0_DATA_SET 0x00 110#define CPLD_LCD0_DATA_SET 0x00
73#define CPLD_LCD0_DATA_CLR 0x10 111#define CPLD_LCD0_DATA_CLR 0x10
@@ -132,9 +170,6 @@ enum balloon3_features {
132/* Balloon3 Interrupts */ 170/* Balloon3 Interrupts */
133#define BALLOON3_IRQ(x) (IRQ_BOARD_START + (x)) 171#define BALLOON3_IRQ(x) (IRQ_BOARD_START + (x))
134 172
135#define BALLOON3_BP_CF_NRDY_IRQ BALLOON3_IRQ(0)
136#define BALLOON3_BP_NSTSCHG_IRQ BALLOON3_IRQ(1)
137
138#define BALLOON3_AUX_NIRQ IRQ_GPIO(BALLOON3_GPIO_AUX_NIRQ) 173#define BALLOON3_AUX_NIRQ IRQ_GPIO(BALLOON3_GPIO_AUX_NIRQ)
139#define BALLOON3_CODEC_IRQ IRQ_GPIO(BALLOON3_GPIO_CODEC_IRQ) 174#define BALLOON3_CODEC_IRQ IRQ_GPIO(BALLOON3_GPIO_CODEC_IRQ)
140#define BALLOON3_S0_CD_IRQ IRQ_GPIO(BALLOON3_GPIO_S0_CD) 175#define BALLOON3_S0_CD_IRQ IRQ_GPIO(BALLOON3_GPIO_S0_CD)
diff --git a/arch/arm/mach-pxa/include/mach/colibri.h b/arch/arm/mach-pxa/include/mach/colibri.h
index 5f2ba8d9015c..58dada11054f 100644
--- a/arch/arm/mach-pxa/include/mach/colibri.h
+++ b/arch/arm/mach-pxa/include/mach/colibri.h
@@ -5,6 +5,27 @@
5#include <mach/mfp.h> 5#include <mach/mfp.h>
6 6
7/* 7/*
8 * base board glue for PXA270 module
9 */
10
11enum {
12 COLIBRI_PXA270_EVALBOARD = 0,
13 COLIBRI_PXA270_INCOME,
14};
15
16#if defined(CONFIG_MACH_COLIBRI_PXA270_EVALBOARD)
17extern void colibri_pxa270_evalboard_init(void);
18#else
19static inline void colibri_pxa270_evalboard_init(void) {}
20#endif
21
22#if defined(CONFIG_MACH_COLIBRI_PXA270_INCOME)
23extern void colibri_pxa270_income_boardinit(void);
24#else
25static inline void colibri_pxa270_income_boardinit(void) {}
26#endif
27
28/*
8 * common settings for all modules 29 * common settings for all modules
9 */ 30 */
10 31
@@ -33,13 +54,10 @@ static inline void colibri_pxa3xx_init_nand(void) {}
33/* physical memory regions */ 54/* physical memory regions */
34#define COLIBRI_SDRAM_BASE 0xa0000000 /* SDRAM region */ 55#define COLIBRI_SDRAM_BASE 0xa0000000 /* SDRAM region */
35 56
36/* definitions for Colibri PXA270 */ 57/* GPIO definitions for Colibri PXA270 */
37 58#define GPIO114_COLIBRI_PXA270_ETH_IRQ 114
38#define COLIBRI_PXA270_FLASH_PHYS (PXA_CS0_PHYS) /* Flash region */ 59#define GPIO0_COLIBRI_PXA270_SD_DETECT 0
39#define COLIBRI_PXA270_ETH_PHYS (PXA_CS2_PHYS) /* Ethernet */ 60#define GPIO113_COLIBRI_PXA270_TS_IRQ 113
40#define COLIBRI_PXA270_ETH_IRQ_GPIO 114
41#define COLIBRI_PXA270_ETH_IRQ \
42 gpio_to_irq(mfp_to_gpio(COLIBRI_PXA270_ETH_IRQ_GPIO))
43 61
44#endif /* _COLIBRI_H_ */ 62#endif /* _COLIBRI_H_ */
45 63
diff --git a/arch/arm/mach-pxa/include/mach/corgi.h b/arch/arm/mach-pxa/include/mach/corgi.h
index 585970ef08ce..0011055bc3f9 100644
--- a/arch/arm/mach-pxa/include/mach/corgi.h
+++ b/arch/arm/mach-pxa/include/mach/corgi.h
@@ -109,10 +109,5 @@
109#define CORGI_GPIO_BACKLIGHT_CONT (CORGI_SCOOP_GPIO_BASE + 7) 109#define CORGI_GPIO_BACKLIGHT_CONT (CORGI_SCOOP_GPIO_BASE + 7)
110#define CORGI_GPIO_MIC_BIAS (CORGI_SCOOP_GPIO_BASE + 8) 110#define CORGI_GPIO_MIC_BIAS (CORGI_SCOOP_GPIO_BASE + 8)
111 111
112/*
113 * Shared data structures
114 */
115extern struct platform_device corgiscoop_device;
116
117#endif /* __ASM_ARCH_CORGI_H */ 112#endif /* __ASM_ARCH_CORGI_H */
118 113
diff --git a/arch/arm/mach-pxa/include/mach/gumstix.h b/arch/arm/mach-pxa/include/mach/gumstix.h
index 06abd4160607..9b898680b206 100644
--- a/arch/arm/mach-pxa/include/mach/gumstix.h
+++ b/arch/arm/mach-pxa/include/mach/gumstix.h
@@ -14,25 +14,15 @@
14 14
15/* 15/*
16GPIOn - Input from MAX823 (or equiv), normalizing USB +5V into a clean 16GPIOn - Input from MAX823 (or equiv), normalizing USB +5V into a clean
17interrupt signal for determining cable presence. On the original gumstix, 17interrupt signal for determining cable presence. On the gumstix F,
18this is GPIO81, and GPIO83 needs to be defined as well. On the gumstix F,
19this moves to GPIO17 and GPIO37. */ 18this moves to GPIO17 and GPIO37. */
20 19
21/* GPIOx - Connects to USB D+ and used as a pull-up after GPIOn 20/* GPIOx - Connects to USB D+ and used as a pull-up after GPIOn
22has detected a cable insertion; driven low otherwise. */ 21has detected a cable insertion; driven low otherwise. */
23 22
24#ifdef CONFIG_ARCH_GUMSTIX_ORIG
25
26#define GPIO_GUMSTIX_USB_GPIOn 81
27#define GPIO_GUMSTIX_USB_GPIOx 83
28
29#else
30
31#define GPIO_GUMSTIX_USB_GPIOn 35 23#define GPIO_GUMSTIX_USB_GPIOn 35
32#define GPIO_GUMSTIX_USB_GPIOx 41 24#define GPIO_GUMSTIX_USB_GPIOx 41
33 25
34#endif
35
36/* usb state change */ 26/* usb state change */
37#define GUMSTIX_USB_INTR_IRQ IRQ_GPIO(GPIO_GUMSTIX_USB_GPIOn) 27#define GUMSTIX_USB_INTR_IRQ IRQ_GPIO(GPIO_GUMSTIX_USB_GPIOn)
38 28
diff --git a/arch/arm/mach-pxa/include/mach/hardware.h b/arch/arm/mach-pxa/include/mach/hardware.h
index 3d8d8cb09685..7f64d24cd564 100644
--- a/arch/arm/mach-pxa/include/mach/hardware.h
+++ b/arch/arm/mach-pxa/include/mach/hardware.h
@@ -14,11 +14,6 @@
14#define __ASM_ARCH_HARDWARE_H 14#define __ASM_ARCH_HARDWARE_H
15 15
16/* 16/*
17 * We requires absolute addresses.
18 */
19#define PCIO_BASE 0
20
21/*
22 * Workarounds for at least 2 errata so far require this. 17 * Workarounds for at least 2 errata so far require this.
23 * The mapping is set in mach-pxa/generic.c. 18 * The mapping is set in mach-pxa/generic.c.
24 */ 19 */
diff --git a/arch/arm/mach-pxa/include/mach/palm27x.h b/arch/arm/mach-pxa/include/mach/palm27x.h
new file mode 100644
index 000000000000..0a5e5eadebf5
--- /dev/null
+++ b/arch/arm/mach-pxa/include/mach/palm27x.h
@@ -0,0 +1,81 @@
1/*
2 * Common functions for Palm LD, T5, TX, Z72
3 *
4 * Copyright (C) 2010
5 * Marek Vasut <marek.vasut@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 */
12#ifndef __INCLUDE_MACH_PALM27X__
13#define __INCLUDE_MACH_PALM27X__
14
15#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
16extern void __init palm27x_mmc_init(int detect, int ro, int power,
17 int power_inverted);
18#else
19static inline void palm27x_mmc_init(int detect, int ro, int power,
20 int power_inverted)
21{}
22#endif
23
24#if defined(CONFIG_SUSPEND)
25extern void __init palm27x_pm_init(unsigned long str_base);
26#else
27static inline void palm27x_pm_init(unsigned long str_base) {}
28#endif
29
30#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
31extern struct pxafb_mode_info palm_320x480_lcd_mode;
32extern struct pxafb_mode_info palm_320x320_lcd_mode;
33extern struct pxafb_mode_info palm_320x320_new_lcd_mode;
34extern void __init palm27x_lcd_init(int power,
35 struct pxafb_mode_info *mode);
36#else
37static inline void palm27x_lcd_init(int power, struct pxafb_mode_info *mode) {}
38#endif
39
40#if defined(CONFIG_USB_GADGET_PXA27X) || \
41 defined(CONFIG_USB_GADGET_PXA27X_MODULE)
42extern void __init palm27x_udc_init(int vbus, int pullup,
43 int vbus_inverted);
44#else
45static inline void palm27x_udc_init(int vbus, int pullup, int vbus_inverted) {}
46#endif
47
48#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
49extern void __init palm27x_irda_init(int pwdn);
50#else
51static inline void palm27x_irda_init(int pwdn) {}
52#endif
53
54#if defined(CONFIG_TOUCHSCREEN_WM97XX) || \
55 defined(CONFIG_TOUCHSCREEN_WM97XX_MODULE)
56extern void __init palm27x_ac97_init(int minv, int maxv, int jack,
57 int reset);
58#else
59static inline void palm27x_ac97_init(int minv, int maxv, int jack, int reset) {}
60#endif
61
62#if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
63extern void __init palm27x_pwm_init(int bl, int lcd);
64#else
65static inline void palm27x_pwm_init(int bl, int lcd) {}
66#endif
67
68#if defined(CONFIG_PDA_POWER) || defined(CONFIG_PDA_POWER_MODULE)
69extern void __init palm27x_power_init(int ac, int usb);
70#else
71static inline void palm27x_power_init(int ac, int usb) {}
72#endif
73
74#if defined(CONFIG_REGULATOR_MAX1586) || \
75 defined(CONFIG_REGULATOR_MAX1586_MODULE)
76extern void __init palm27x_pmic_init(void);
77#else
78static inline void palm27x_pmic_init(void) {}
79#endif
80
81#endif /* __INCLUDE_MACH_PALM27X__ */
diff --git a/arch/arm/mach-pxa/include/mach/pata_pxa.h b/arch/arm/mach-pxa/include/mach/pata_pxa.h
new file mode 100644
index 000000000000..6cf7df1d5830
--- /dev/null
+++ b/arch/arm/mach-pxa/include/mach/pata_pxa.h
@@ -0,0 +1,33 @@
1/*
2 * Generic PXA PATA driver
3 *
4 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#ifndef __MACH_PATA_PXA_H__
22#define __MACH_PATA_PXA_H__
23
24struct pata_pxa_pdata {
25 /* PXA DMA DREQ<0:2> pin */
26 uint32_t dma_dreq;
27 /* Register shift */
28 uint32_t reg_shift;
29 /* IRQ flags */
30 uint32_t irq_flags;
31};
32
33#endif /* __MACH_PATA_PXA_H__ */
diff --git a/arch/arm/mach-pxa/include/mach/sharpsl.h b/arch/arm/mach-pxa/include/mach/sharpsl.h
deleted file mode 100644
index 8242e14a44fa..000000000000
--- a/arch/arm/mach-pxa/include/mach/sharpsl.h
+++ /dev/null
@@ -1,35 +0,0 @@
1/*
2 * SharpSL SSP Driver
3 */
4
5unsigned long corgi_ssp_ads7846_putget(unsigned long);
6unsigned long corgi_ssp_ads7846_get(void);
7void corgi_ssp_ads7846_put(unsigned long data);
8void corgi_ssp_ads7846_lock(void);
9void corgi_ssp_ads7846_unlock(void);
10void corgi_ssp_lcdtg_send (unsigned char adrs, unsigned char data);
11void corgi_ssp_blduty_set(int duty);
12int corgi_ssp_max1111_get(unsigned long data);
13
14/*
15 * SharpSL Touchscreen Driver
16 */
17
18struct corgits_machinfo {
19 unsigned long (*get_hsync_invperiod)(void);
20 void (*put_hsync)(void);
21 void (*wait_hsync)(void);
22};
23
24
25/*
26 * SharpSL Backlight
27 */
28extern void corgibl_limit_intensity(int limit);
29extern void corgi_lcd_limit_intensity(int limit);
30
31
32/*
33 * SharpSL Battery/PM Driver
34 */
35extern void sharpsl_battery_kick(void);
diff --git a/arch/arm/mach-pxa/include/mach/sharpsl_pm.h b/arch/arm/mach-pxa/include/mach/sharpsl_pm.h
index 1920dc6b05dc..905be6755f04 100644
--- a/arch/arm/mach-pxa/include/mach/sharpsl_pm.h
+++ b/arch/arm/mach-pxa/include/mach/sharpsl_pm.h
@@ -93,6 +93,8 @@ struct sharpsl_pm_status {
93 93
94extern struct sharpsl_pm_status sharpsl_pm; 94extern struct sharpsl_pm_status sharpsl_pm;
95 95
96extern struct battery_thresh sharpsl_battery_levels_acin[];
97extern struct battery_thresh sharpsl_battery_levels_noac[];
96 98
97#define SHARPSL_LED_ERROR 2 99#define SHARPSL_LED_ERROR 2
98#define SHARPSL_LED_ON 1 100#define SHARPSL_LED_ON 1
@@ -101,4 +103,11 @@ extern struct sharpsl_pm_status sharpsl_pm;
101void sharpsl_battery_kick(void); 103void sharpsl_battery_kick(void);
102void sharpsl_pm_led(int val); 104void sharpsl_pm_led(int val);
103 105
106/* MAX1111 Channel Definitions */
107#define MAX1111_BATT_VOLT 4u
108#define MAX1111_BATT_TEMP 2u
109#define MAX1111_ACIN_VOLT 6u
110int sharpsl_pm_pxa_read_max1111(int channel);
111
112void corgi_lcd_limit_intensity(int limit);
104#endif 113#endif
diff --git a/arch/arm/mach-pxa/include/mach/spitz.h b/arch/arm/mach-pxa/include/mach/spitz.h
index fa1998caa78e..685749a51c42 100644
--- a/arch/arm/mach-pxa/include/mach/spitz.h
+++ b/arch/arm/mach-pxa/include/mach/spitz.h
@@ -185,7 +185,5 @@
185/* 185/*
186 * Shared data structures 186 * Shared data structures
187 */ 187 */
188extern struct platform_device spitzscoop_device;
189extern struct platform_device spitzscoop2_device;
190extern struct platform_device spitzssp_device; 188extern struct platform_device spitzssp_device;
191extern struct sharpsl_charger_machinfo spitz_pm_machinfo; 189extern struct sharpsl_charger_machinfo spitz_pm_machinfo;
diff --git a/arch/arm/mach-pxa/mioa701.c b/arch/arm/mach-pxa/mioa701.c
index fa6a708b4099..dc66942ef9ab 100644
--- a/arch/arm/mach-pxa/mioa701.c
+++ b/arch/arm/mach-pxa/mioa701.c
@@ -34,7 +34,7 @@
34#include <linux/irq.h> 34#include <linux/irq.h>
35#include <linux/pda_power.h> 35#include <linux/pda_power.h>
36#include <linux/power_supply.h> 36#include <linux/power_supply.h>
37#include <linux/wm97xx_batt.h> 37#include <linux/wm97xx.h>
38#include <linux/mtd/physmap.h> 38#include <linux/mtd/physmap.h>
39#include <linux/usb/gpio_vbus.h> 39#include <linux/usb/gpio_vbus.h>
40#include <linux/regulator/max1586.h> 40#include <linux/regulator/max1586.h>
@@ -636,7 +636,7 @@ static struct platform_device power_dev = {
636 }, 636 },
637}; 637};
638 638
639static struct wm97xx_batt_info mioa701_battery_data = { 639static struct wm97xx_batt_pdata mioa701_battery_data = {
640 .batt_aux = WM97XX_AUX_ID1, 640 .batt_aux = WM97XX_AUX_ID1,
641 .temp_aux = -1, 641 .temp_aux = -1,
642 .charge_gpio = -1, 642 .charge_gpio = -1,
@@ -648,6 +648,10 @@ static struct wm97xx_batt_info mioa701_battery_data = {
648 .batt_name = "mioa701_battery", 648 .batt_name = "mioa701_battery",
649}; 649};
650 650
651static struct wm97xx_pdata mioa701_wm97xx_pdata = {
652 .batt_pdata = &mioa701_battery_data,
653};
654
651/* 655/*
652 * Voltage regulation 656 * Voltage regulation
653 */ 657 */
@@ -716,6 +720,7 @@ struct i2c_pxa_platform_data i2c_pdata = {
716 720
717static pxa2xx_audio_ops_t mioa701_ac97_info = { 721static pxa2xx_audio_ops_t mioa701_ac97_info = {
718 .reset_gpio = 95, 722 .reset_gpio = 95,
723 .codec_pdata = { &mioa701_wm97xx_pdata, },
719}; 724};
720 725
721/* 726/*
@@ -794,7 +799,6 @@ static void __init mioa701_machine_init(void)
794 set_pxa_fb_info(&mioa701_pxafb_info); 799 set_pxa_fb_info(&mioa701_pxafb_info);
795 pxa_set_mci_info(&mioa701_mci_info); 800 pxa_set_mci_info(&mioa701_mci_info);
796 pxa_set_keypad_info(&mioa701_keypad_info); 801 pxa_set_keypad_info(&mioa701_keypad_info);
797 wm97xx_bat_set_pdata(&mioa701_battery_data);
798 pxa_set_udc_info(&mioa701_udc_info); 802 pxa_set_udc_info(&mioa701_udc_info);
799 pxa_set_ac97_info(&mioa701_ac97_info); 803 pxa_set_ac97_info(&mioa701_ac97_info);
800 pm_power_off = mioa701_poweroff; 804 pm_power_off = mioa701_poweroff;
diff --git a/arch/arm/mach-pxa/palm27x.c b/arch/arm/mach-pxa/palm27x.c
new file mode 100644
index 000000000000..77ad6d34ab5b
--- /dev/null
+++ b/arch/arm/mach-pxa/palm27x.c
@@ -0,0 +1,477 @@
1/*
2 * Common code for Palm LD, T5, TX, Z72
3 *
4 * Copyright (C) 2010
5 * Marek Vasut <marek.vasut@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 */
12
13#include <linux/platform_device.h>
14#include <linux/delay.h>
15#include <linux/irq.h>
16#include <linux/gpio_keys.h>
17#include <linux/input.h>
18#include <linux/pda_power.h>
19#include <linux/pwm_backlight.h>
20#include <linux/gpio.h>
21#include <linux/wm97xx.h>
22#include <linux/power_supply.h>
23#include <linux/usb/gpio_vbus.h>
24#include <linux/regulator/max1586.h>
25
26#include <asm/mach-types.h>
27#include <asm/mach/arch.h>
28#include <asm/mach/map.h>
29
30#include <mach/pxa27x.h>
31#include <mach/audio.h>
32#include <mach/mmc.h>
33#include <mach/pxafb.h>
34#include <mach/irda.h>
35#include <mach/udc.h>
36#include <mach/palmasoc.h>
37#include <mach/palm27x.h>
38
39#include <plat/i2c.h>
40
41#include "generic.h"
42#include "devices.h"
43
44/******************************************************************************
45 * SD/MMC card controller
46 ******************************************************************************/
47#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
48static struct pxamci_platform_data palm27x_mci_platform_data = {
49 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
50 .detect_delay_ms = 200,
51};
52
53void __init palm27x_mmc_init(int detect, int ro, int power,
54 int power_inverted)
55{
56 palm27x_mci_platform_data.gpio_card_detect = detect;
57 palm27x_mci_platform_data.gpio_card_ro = ro;
58 palm27x_mci_platform_data.gpio_power = power;
59 palm27x_mci_platform_data.gpio_power_invert = power_inverted;
60
61 pxa_set_mci_info(&palm27x_mci_platform_data);
62}
63#endif
64
65/******************************************************************************
66 * Power management - standby
67 ******************************************************************************/
68#if defined(CONFIG_SUSPEND)
69void __init palm27x_pm_init(unsigned long str_base)
70{
71 static const unsigned long resume[] = {
72 0xe3a00101, /* mov r0, #0x40000000 */
73 0xe380060f, /* orr r0, r0, #0x00f00000 */
74 0xe590f008, /* ldr pc, [r0, #0x08] */
75 };
76
77 /*
78 * Copy the bootloader.
79 * NOTE: PalmZ72 uses a different wakeup method!
80 */
81 memcpy(phys_to_virt(str_base), resume, sizeof(resume));
82}
83#endif
84
85/******************************************************************************
86 * Framebuffer
87 ******************************************************************************/
88#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
89struct pxafb_mode_info palm_320x480_lcd_mode = {
90 .pixclock = 57692,
91 .xres = 320,
92 .yres = 480,
93 .bpp = 16,
94
95 .left_margin = 32,
96 .right_margin = 1,
97 .upper_margin = 7,
98 .lower_margin = 1,
99
100 .hsync_len = 4,
101 .vsync_len = 1,
102};
103
104struct pxafb_mode_info palm_320x320_lcd_mode = {
105 .pixclock = 115384,
106 .xres = 320,
107 .yres = 320,
108 .bpp = 16,
109
110 .left_margin = 27,
111 .right_margin = 7,
112 .upper_margin = 7,
113 .lower_margin = 8,
114
115 .hsync_len = 6,
116 .vsync_len = 1,
117};
118
119struct pxafb_mode_info palm_320x320_new_lcd_mode = {
120 .pixclock = 86538,
121 .xres = 320,
122 .yres = 320,
123 .bpp = 16,
124
125 .left_margin = 20,
126 .right_margin = 8,
127 .upper_margin = 8,
128 .lower_margin = 5,
129
130 .hsync_len = 4,
131 .vsync_len = 1,
132};
133
134static struct pxafb_mach_info palm27x_lcd_screen = {
135 .num_modes = 1,
136 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
137};
138
139static int palm27x_lcd_power;
140static void palm27x_lcd_ctl(int on, struct fb_var_screeninfo *info)
141{
142 gpio_set_value(palm27x_lcd_power, on);
143}
144
145void __init palm27x_lcd_init(int power, struct pxafb_mode_info *mode)
146{
147 palm27x_lcd_screen.modes = mode;
148
149 if (gpio_is_valid(power)) {
150 if (!gpio_request(power, "LCD power")) {
151 pr_err("Palm27x: failed to claim lcd power gpio!\n");
152 return;
153 }
154 if (!gpio_direction_output(power, 1)) {
155 pr_err("Palm27x: lcd power configuration failed!\n");
156 return;
157 }
158 palm27x_lcd_power = power;
159 palm27x_lcd_screen.pxafb_lcd_power = palm27x_lcd_ctl;
160 }
161
162 set_pxa_fb_info(&palm27x_lcd_screen);
163}
164#endif
165
166/******************************************************************************
167 * USB Gadget
168 ******************************************************************************/
169#if defined(CONFIG_USB_GADGET_PXA27X) || \
170 defined(CONFIG_USB_GADGET_PXA27X_MODULE)
171static struct gpio_vbus_mach_info palm27x_udc_info = {
172 .gpio_vbus_inverted = 1,
173};
174
175static struct platform_device palm27x_gpio_vbus = {
176 .name = "gpio-vbus",
177 .id = -1,
178 .dev = {
179 .platform_data = &palm27x_udc_info,
180 },
181};
182
183void __init palm27x_udc_init(int vbus, int pullup, int vbus_inverted)
184{
185 palm27x_udc_info.gpio_vbus = vbus;
186 palm27x_udc_info.gpio_pullup = pullup;
187
188 palm27x_udc_info.gpio_vbus_inverted = vbus_inverted;
189
190 if (!gpio_request(pullup, "USB Pullup")) {
191 gpio_direction_output(pullup,
192 palm27x_udc_info.gpio_vbus_inverted);
193 gpio_free(pullup);
194 } else
195 return;
196
197 platform_device_register(&palm27x_gpio_vbus);
198}
199#endif
200
201/******************************************************************************
202 * IrDA
203 ******************************************************************************/
204#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
205static struct pxaficp_platform_data palm27x_ficp_platform_data = {
206 .transceiver_cap = IR_SIRMODE | IR_OFF,
207};
208
209void __init palm27x_irda_init(int pwdn)
210{
211 palm27x_ficp_platform_data.gpio_pwdown = pwdn;
212 pxa_set_ficp_info(&palm27x_ficp_platform_data);
213}
214#endif
215
216/******************************************************************************
217 * WM97xx audio, battery
218 ******************************************************************************/
219#if defined(CONFIG_TOUCHSCREEN_WM97XX) || \
220 defined(CONFIG_TOUCHSCREEN_WM97XX_MODULE)
221static struct wm97xx_batt_pdata palm27x_batt_pdata = {
222 .batt_aux = WM97XX_AUX_ID3,
223 .temp_aux = WM97XX_AUX_ID2,
224 .charge_gpio = -1,
225 .batt_mult = 1000,
226 .batt_div = 414,
227 .temp_mult = 1,
228 .temp_div = 1,
229 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
230 .batt_name = "main-batt",
231};
232
233static struct wm97xx_pdata palm27x_wm97xx_pdata = {
234 .batt_pdata = &palm27x_batt_pdata,
235};
236
237static pxa2xx_audio_ops_t palm27x_ac97_pdata = {
238 .codec_pdata = { &palm27x_wm97xx_pdata, },
239};
240
241static struct palm27x_asoc_info palm27x_asoc_pdata = {
242 .jack_gpio = -1,
243};
244
245static struct platform_device palm27x_asoc = {
246 .name = "palm27x-asoc",
247 .id = -1,
248 .dev = {
249 .platform_data = &palm27x_asoc_pdata,
250 },
251};
252
253void __init palm27x_ac97_init(int minv, int maxv, int jack, int reset)
254{
255 palm27x_ac97_pdata.reset_gpio = reset;
256 palm27x_asoc_pdata.jack_gpio = jack;
257
258 if (minv < 0 || maxv < 0) {
259 palm27x_ac97_pdata.codec_pdata[0] = NULL;
260 pxa_set_ac97_info(&palm27x_ac97_pdata);
261 } else {
262 palm27x_batt_pdata.min_voltage = minv,
263 palm27x_batt_pdata.max_voltage = maxv,
264
265 pxa_set_ac97_info(&palm27x_ac97_pdata);
266 platform_device_register(&palm27x_asoc);
267 }
268}
269#endif
270
271/******************************************************************************
272 * Backlight
273 ******************************************************************************/
274#if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
275static int palm_bl_power;
276static int palm_lcd_power;
277
278static int palm27x_backlight_init(struct device *dev)
279{
280 int ret;
281
282 ret = gpio_request(palm_bl_power, "BL POWER");
283 if (ret)
284 goto err;
285 ret = gpio_direction_output(palm_bl_power, 0);
286 if (ret)
287 goto err2;
288
289 if (gpio_is_valid(palm_lcd_power)) {
290 ret = gpio_request(palm_lcd_power, "LCD POWER");
291 if (ret)
292 goto err2;
293 ret = gpio_direction_output(palm_lcd_power, 0);
294 if (ret)
295 goto err3;
296 }
297
298 return 0;
299err3:
300 gpio_free(palm_lcd_power);
301err2:
302 gpio_free(palm_bl_power);
303err:
304 return ret;
305}
306
307static int palm27x_backlight_notify(struct device *dev, int brightness)
308{
309 gpio_set_value(palm_bl_power, brightness);
310 if (gpio_is_valid(palm_lcd_power))
311 gpio_set_value(palm_lcd_power, brightness);
312 return brightness;
313}
314
315static void palm27x_backlight_exit(struct device *dev)
316{
317 gpio_free(palm_bl_power);
318 if (gpio_is_valid(palm_lcd_power))
319 gpio_free(palm_lcd_power);
320}
321
322static struct platform_pwm_backlight_data palm27x_backlight_data = {
323 .pwm_id = 0,
324 .max_brightness = 0xfe,
325 .dft_brightness = 0x7e,
326 .pwm_period_ns = 3500,
327 .init = palm27x_backlight_init,
328 .notify = palm27x_backlight_notify,
329 .exit = palm27x_backlight_exit,
330};
331
332static struct platform_device palm27x_backlight = {
333 .name = "pwm-backlight",
334 .dev = {
335 .parent = &pxa27x_device_pwm0.dev,
336 .platform_data = &palm27x_backlight_data,
337 },
338};
339
340void __init palm27x_pwm_init(int bl, int lcd)
341{
342 palm_bl_power = bl;
343 palm_lcd_power = lcd;
344 platform_device_register(&palm27x_backlight);
345}
346#endif
347
348/******************************************************************************
349 * Power supply
350 ******************************************************************************/
351#if defined(CONFIG_PDA_POWER) || defined(CONFIG_PDA_POWER_MODULE)
352static int palm_ac_state;
353static int palm_usb_state;
354
355static int palm27x_power_supply_init(struct device *dev)
356{
357 int ret;
358
359 ret = gpio_request(palm_ac_state, "AC state");
360 if (ret)
361 goto err1;
362 ret = gpio_direction_input(palm_ac_state);
363 if (ret)
364 goto err2;
365
366 if (gpio_is_valid(palm_usb_state)) {
367 ret = gpio_request(palm_usb_state, "USB state");
368 if (ret)
369 goto err2;
370 ret = gpio_direction_input(palm_usb_state);
371 if (ret)
372 goto err3;
373 }
374
375 return 0;
376err3:
377 gpio_free(palm_usb_state);
378err2:
379 gpio_free(palm_ac_state);
380err1:
381 return ret;
382}
383
384static void palm27x_power_supply_exit(struct device *dev)
385{
386 gpio_free(palm_usb_state);
387 gpio_free(palm_ac_state);
388}
389
390static int palm27x_is_ac_online(void)
391{
392 return gpio_get_value(palm_ac_state);
393}
394
395static int palm27x_is_usb_online(void)
396{
397 return !gpio_get_value(palm_usb_state);
398}
399static char *palm27x_supplicants[] = {
400 "main-battery",
401};
402
403static struct pda_power_pdata palm27x_ps_info = {
404 .init = palm27x_power_supply_init,
405 .exit = palm27x_power_supply_exit,
406 .is_ac_online = palm27x_is_ac_online,
407 .is_usb_online = palm27x_is_usb_online,
408 .supplied_to = palm27x_supplicants,
409 .num_supplicants = ARRAY_SIZE(palm27x_supplicants),
410};
411
412static struct platform_device palm27x_power_supply = {
413 .name = "pda-power",
414 .id = -1,
415 .dev = {
416 .platform_data = &palm27x_ps_info,
417 },
418};
419
420void __init palm27x_power_init(int ac, int usb)
421{
422 palm_ac_state = ac;
423 palm_usb_state = usb;
424 platform_device_register(&palm27x_power_supply);
425}
426#endif
427
428/******************************************************************************
429 * Core power regulator
430 ******************************************************************************/
431#if defined(CONFIG_REGULATOR_MAX1586) || \
432 defined(CONFIG_REGULATOR_MAX1586_MODULE)
433static struct regulator_consumer_supply palm27x_max1587a_consumers[] = {
434 {
435 .supply = "vcc_core",
436 }
437};
438
439static struct regulator_init_data palm27x_max1587a_v3_info = {
440 .constraints = {
441 .name = "vcc_core range",
442 .min_uV = 900000,
443 .max_uV = 1705000,
444 .always_on = 1,
445 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
446 },
447 .consumer_supplies = palm27x_max1587a_consumers,
448 .num_consumer_supplies = ARRAY_SIZE(palm27x_max1587a_consumers),
449};
450
451static struct max1586_subdev_data palm27x_max1587a_subdevs[] = {
452 {
453 .name = "vcc_core",
454 .id = MAX1586_V3,
455 .platform_data = &palm27x_max1587a_v3_info,
456 }
457};
458
459static struct max1586_platform_data palm27x_max1587a_info = {
460 .subdevs = palm27x_max1587a_subdevs,
461 .num_subdevs = ARRAY_SIZE(palm27x_max1587a_subdevs),
462 .v3_gain = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
463};
464
465static struct i2c_board_info __initdata palm27x_pi2c_board_info[] = {
466 {
467 I2C_BOARD_INFO("max1586", 0x14),
468 .platform_data = &palm27x_max1587a_info,
469 },
470};
471
472void __init palm27x_pmic_init(void)
473{
474 i2c_register_board_info(1, ARRAY_AND_SIZE(palm27x_pi2c_board_info));
475 pxa27x_set_i2c_power_info(NULL);
476}
477#endif
diff --git a/arch/arm/mach-pxa/palmld.c b/arch/arm/mach-pxa/palmld.c
index 1963819dba98..91038eeafe44 100644
--- a/arch/arm/mach-pxa/palmld.c
+++ b/arch/arm/mach-pxa/palmld.c
@@ -22,7 +22,7 @@
22#include <linux/pda_power.h> 22#include <linux/pda_power.h>
23#include <linux/pwm_backlight.h> 23#include <linux/pwm_backlight.h>
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/wm97xx_batt.h> 25#include <linux/wm97xx.h>
26#include <linux/power_supply.h> 26#include <linux/power_supply.h>
27#include <linux/sysdev.h> 27#include <linux/sysdev.h>
28#include <linux/mtd/mtd.h> 28#include <linux/mtd/mtd.h>
@@ -41,6 +41,7 @@
41#include <mach/irda.h> 41#include <mach/irda.h>
42#include <mach/pxa27x_keypad.h> 42#include <mach/pxa27x_keypad.h>
43#include <mach/palmasoc.h> 43#include <mach/palmasoc.h>
44#include <mach/palm27x.h>
44 45
45#include "generic.h" 46#include "generic.h"
46#include "devices.h" 47#include "devices.h"
@@ -127,6 +128,7 @@ static unsigned long palmld_pin_config[] __initdata = {
127/****************************************************************************** 128/******************************************************************************
128 * NOR Flash 129 * NOR Flash
129 ******************************************************************************/ 130 ******************************************************************************/
131#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
130static struct mtd_partition palmld_partitions[] = { 132static struct mtd_partition palmld_partitions[] = {
131 { 133 {
132 .name = "Flash", 134 .name = "Flash",
@@ -160,20 +162,18 @@ static struct platform_device palmld_flash = {
160 }, 162 },
161}; 163};
162 164
163/****************************************************************************** 165static void __init palmld_nor_init(void)
164 * SD/MMC card controller 166{
165 ******************************************************************************/ 167 platform_device_register(&palmld_flash);
166static struct pxamci_platform_data palmld_mci_platform_data = { 168}
167 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, 169#else
168 .gpio_card_detect = GPIO_NR_PALMLD_SD_DETECT_N, 170static inline void palmld_nor_init(void) {}
169 .gpio_card_ro = GPIO_NR_PALMLD_SD_READONLY, 171#endif
170 .gpio_power = GPIO_NR_PALMLD_SD_POWER,
171 .detect_delay_ms = 200,
172};
173 172
174/****************************************************************************** 173/******************************************************************************
175 * GPIO keyboard 174 * GPIO keyboard
176 ******************************************************************************/ 175 ******************************************************************************/
176#if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
177static unsigned int palmld_matrix_keys[] = { 177static unsigned int palmld_matrix_keys[] = {
178 KEY(0, 1, KEY_F2), 178 KEY(0, 1, KEY_F2),
179 KEY(0, 2, KEY_UP), 179 KEY(0, 2, KEY_UP),
@@ -200,9 +200,18 @@ static struct pxa27x_keypad_platform_data palmld_keypad_platform_data = {
200 .debounce_interval = 30, 200 .debounce_interval = 30,
201}; 201};
202 202
203static void __init palmld_kpc_init(void)
204{
205 pxa_set_keypad_info(&palmld_keypad_platform_data);
206}
207#else
208static inline void palmld_kpc_init(void) {}
209#endif
210
203/****************************************************************************** 211/******************************************************************************
204 * GPIO keys 212 * GPIO keys
205 ******************************************************************************/ 213 ******************************************************************************/
214#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
206static struct gpio_keys_button palmld_pxa_buttons[] = { 215static struct gpio_keys_button palmld_pxa_buttons[] = {
207 {KEY_F8, GPIO_NR_PALMLD_HOTSYNC_BUTTON_N, 1, "HotSync Button" }, 216 {KEY_F8, GPIO_NR_PALMLD_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
208 {KEY_F9, GPIO_NR_PALMLD_LOCK_SWITCH, 0, "Lock Switch" }, 217 {KEY_F9, GPIO_NR_PALMLD_LOCK_SWITCH, 0, "Lock Switch" },
@@ -222,77 +231,18 @@ static struct platform_device palmld_pxa_keys = {
222 }, 231 },
223}; 232};
224 233
225/****************************************************************************** 234static void __init palmld_keys_init(void)
226 * Backlight
227 ******************************************************************************/
228static int palmld_backlight_init(struct device *dev)
229{
230 int ret;
231
232 ret = gpio_request(GPIO_NR_PALMLD_BL_POWER, "BL POWER");
233 if (ret)
234 goto err;
235 ret = gpio_direction_output(GPIO_NR_PALMLD_BL_POWER, 0);
236 if (ret)
237 goto err2;
238 ret = gpio_request(GPIO_NR_PALMLD_LCD_POWER, "LCD POWER");
239 if (ret)
240 goto err2;
241 ret = gpio_direction_output(GPIO_NR_PALMLD_LCD_POWER, 0);
242 if (ret)
243 goto err3;
244
245 return 0;
246err3:
247 gpio_free(GPIO_NR_PALMLD_LCD_POWER);
248err2:
249 gpio_free(GPIO_NR_PALMLD_BL_POWER);
250err:
251 return ret;
252}
253
254static int palmld_backlight_notify(struct device *dev, int brightness)
255{ 235{
256 gpio_set_value(GPIO_NR_PALMLD_BL_POWER, brightness); 236 platform_device_register(&palmld_pxa_keys);
257 gpio_set_value(GPIO_NR_PALMLD_LCD_POWER, brightness);
258 return brightness;
259} 237}
260 238#else
261static void palmld_backlight_exit(struct device *dev) 239static inline void palmld_keys_init(void) {}
262{ 240#endif
263 gpio_free(GPIO_NR_PALMLD_BL_POWER);
264 gpio_free(GPIO_NR_PALMLD_LCD_POWER);
265}
266
267static struct platform_pwm_backlight_data palmld_backlight_data = {
268 .pwm_id = 0,
269 .max_brightness = PALMLD_MAX_INTENSITY,
270 .dft_brightness = PALMLD_MAX_INTENSITY,
271 .pwm_period_ns = PALMLD_PERIOD_NS,
272 .init = palmld_backlight_init,
273 .notify = palmld_backlight_notify,
274 .exit = palmld_backlight_exit,
275};
276
277static struct platform_device palmld_backlight = {
278 .name = "pwm-backlight",
279 .dev = {
280 .parent = &pxa27x_device_pwm0.dev,
281 .platform_data = &palmld_backlight_data,
282 },
283};
284
285/******************************************************************************
286 * IrDA
287 ******************************************************************************/
288static struct pxaficp_platform_data palmld_ficp_platform_data = {
289 .gpio_pwdown = GPIO_NR_PALMLD_IR_DISABLE,
290 .transceiver_cap = IR_SIRMODE | IR_OFF,
291};
292 241
293/****************************************************************************** 242/******************************************************************************
294 * LEDs 243 * LEDs
295 ******************************************************************************/ 244 ******************************************************************************/
245#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
296struct gpio_led gpio_leds[] = { 246struct gpio_led gpio_leds[] = {
297{ 247{
298 .name = "palmld:green:led", 248 .name = "palmld:green:led",
@@ -318,174 +268,34 @@ static struct platform_device palmld_leds = {
318 } 268 }
319}; 269};
320 270
321/****************************************************************************** 271static void __init palmld_leds_init(void)
322 * Power supply
323 ******************************************************************************/
324static int power_supply_init(struct device *dev)
325{
326 int ret;
327
328 ret = gpio_request(GPIO_NR_PALMLD_POWER_DETECT, "CABLE_STATE_AC");
329 if (ret)
330 goto err1;
331 ret = gpio_direction_input(GPIO_NR_PALMLD_POWER_DETECT);
332 if (ret)
333 goto err2;
334
335 ret = gpio_request(GPIO_NR_PALMLD_USB_DETECT_N, "CABLE_STATE_USB");
336 if (ret)
337 goto err2;
338 ret = gpio_direction_input(GPIO_NR_PALMLD_USB_DETECT_N);
339 if (ret)
340 goto err3;
341
342 return 0;
343
344err3:
345 gpio_free(GPIO_NR_PALMLD_USB_DETECT_N);
346err2:
347 gpio_free(GPIO_NR_PALMLD_POWER_DETECT);
348err1:
349 return ret;
350}
351
352static int palmld_is_ac_online(void)
353{ 272{
354 return gpio_get_value(GPIO_NR_PALMLD_POWER_DETECT); 273 platform_device_register(&palmld_leds);
355} 274}
356 275#else
357static int palmld_is_usb_online(void) 276static inline void palmld_leds_init(void) {}
358{ 277#endif
359 return !gpio_get_value(GPIO_NR_PALMLD_USB_DETECT_N);
360}
361
362static void power_supply_exit(struct device *dev)
363{
364 gpio_free(GPIO_NR_PALMLD_USB_DETECT_N);
365 gpio_free(GPIO_NR_PALMLD_POWER_DETECT);
366}
367
368static char *palmld_supplicants[] = {
369 "main-battery",
370};
371
372static struct pda_power_pdata power_supply_info = {
373 .init = power_supply_init,
374 .is_ac_online = palmld_is_ac_online,
375 .is_usb_online = palmld_is_usb_online,
376 .exit = power_supply_exit,
377 .supplied_to = palmld_supplicants,
378 .num_supplicants = ARRAY_SIZE(palmld_supplicants),
379};
380
381static struct platform_device power_supply = {
382 .name = "pda-power",
383 .id = -1,
384 .dev = {
385 .platform_data = &power_supply_info,
386 },
387};
388
389/******************************************************************************
390 * WM97xx battery
391 ******************************************************************************/
392static struct wm97xx_batt_info wm97xx_batt_pdata = {
393 .batt_aux = WM97XX_AUX_ID3,
394 .temp_aux = WM97XX_AUX_ID2,
395 .charge_gpio = -1,
396 .max_voltage = PALMLD_BAT_MAX_VOLTAGE,
397 .min_voltage = PALMLD_BAT_MIN_VOLTAGE,
398 .batt_mult = 1000,
399 .batt_div = 414,
400 .temp_mult = 1,
401 .temp_div = 1,
402 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
403 .batt_name = "main-batt",
404};
405
406/******************************************************************************
407 * aSoC audio
408 ******************************************************************************/
409static struct palm27x_asoc_info palmld_asoc_pdata = {
410 .jack_gpio = GPIO_NR_PALMLD_EARPHONE_DETECT,
411};
412
413static pxa2xx_audio_ops_t palmld_ac97_pdata = {
414 .reset_gpio = 95,
415};
416
417static struct platform_device palmld_asoc = {
418 .name = "palm27x-asoc",
419 .id = -1,
420 .dev = {
421 .platform_data = &palmld_asoc_pdata,
422 },
423};
424 278
425/****************************************************************************** 279/******************************************************************************
426 * HDD 280 * HDD
427 ******************************************************************************/ 281 ******************************************************************************/
428static struct platform_device palmld_hdd = { 282#if defined(CONFIG_PATA_PALMLD) || defined(CONFIG_PATA_PALMLD_MODULE)
283static struct platform_device palmld_ide_device = {
429 .name = "pata_palmld", 284 .name = "pata_palmld",
430 .id = -1, 285 .id = -1,
431}; 286};
432 287
433/****************************************************************************** 288static void __init palmld_ide_init(void)
434 * Framebuffer
435 ******************************************************************************/
436static struct pxafb_mode_info palmld_lcd_modes[] = {
437{
438 .pixclock = 57692,
439 .xres = 320,
440 .yres = 480,
441 .bpp = 16,
442
443 .left_margin = 32,
444 .right_margin = 1,
445 .upper_margin = 7,
446 .lower_margin = 1,
447
448 .hsync_len = 4,
449 .vsync_len = 1,
450},
451};
452
453static struct pxafb_mach_info palmld_lcd_screen = {
454 .modes = palmld_lcd_modes,
455 .num_modes = ARRAY_SIZE(palmld_lcd_modes),
456 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
457};
458
459/******************************************************************************
460 * Power management - standby
461 ******************************************************************************/
462static void __init palmld_pm_init(void)
463{ 289{
464 static u32 resume[] = { 290 platform_device_register(&palmld_ide_device);
465 0xe3a00101, /* mov r0, #0x40000000 */
466 0xe380060f, /* orr r0, r0, #0x00f00000 */
467 0xe590f008, /* ldr pc, [r0, #0x08] */
468 };
469
470 /* copy the bootloader */
471 memcpy(phys_to_virt(PALMLD_STR_BASE), resume, sizeof(resume));
472} 291}
292#else
293static inline void palmld_ide_init(void) {}
294#endif
473 295
474/****************************************************************************** 296/******************************************************************************
475 * Machine init 297 * Machine init
476 ******************************************************************************/ 298 ******************************************************************************/
477static struct platform_device *devices[] __initdata = {
478#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
479 &palmld_pxa_keys,
480#endif
481 &palmld_backlight,
482 &palmld_leds,
483 &power_supply,
484 &palmld_asoc,
485 &palmld_hdd,
486 &palmld_flash,
487};
488
489static struct map_desc palmld_io_desc[] __initdata = { 299static struct map_desc palmld_io_desc[] __initdata = {
490{ 300{
491 .virtual = PALMLD_IDE_VIRT, 301 .virtual = PALMLD_IDE_VIRT,
@@ -510,20 +320,26 @@ static void __init palmld_map_io(void)
510static void __init palmld_init(void) 320static void __init palmld_init(void)
511{ 321{
512 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmld_pin_config)); 322 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmld_pin_config));
513
514 pxa_set_ffuart_info(NULL); 323 pxa_set_ffuart_info(NULL);
515 pxa_set_btuart_info(NULL); 324 pxa_set_btuart_info(NULL);
516 pxa_set_stuart_info(NULL); 325 pxa_set_stuart_info(NULL);
517 326
518 palmld_pm_init(); 327 palm27x_mmc_init(GPIO_NR_PALMLD_SD_DETECT_N, GPIO_NR_PALMLD_SD_READONLY,
519 set_pxa_fb_info(&palmld_lcd_screen); 328 GPIO_NR_PALMLD_SD_POWER, 0);
520 pxa_set_mci_info(&palmld_mci_platform_data); 329 palm27x_pm_init(PALMLD_STR_BASE);
521 pxa_set_ac97_info(&palmld_ac97_pdata); 330 palm27x_lcd_init(-1, &palm_320x480_lcd_mode);
522 pxa_set_ficp_info(&palmld_ficp_platform_data); 331 palm27x_irda_init(GPIO_NR_PALMLD_IR_DISABLE);
523 pxa_set_keypad_info(&palmld_keypad_platform_data); 332 palm27x_ac97_init(PALMLD_BAT_MIN_VOLTAGE, PALMLD_BAT_MAX_VOLTAGE,
524 wm97xx_bat_set_pdata(&wm97xx_batt_pdata); 333 GPIO_NR_PALMLD_EARPHONE_DETECT, 95);
525 334 palm27x_pwm_init(GPIO_NR_PALMLD_BL_POWER, GPIO_NR_PALMLD_LCD_POWER);
526 platform_add_devices(devices, ARRAY_SIZE(devices)); 335 palm27x_power_init(GPIO_NR_PALMLD_POWER_DETECT,
336 GPIO_NR_PALMLD_USB_DETECT_N);
337 palm27x_pmic_init();
338 palmld_kpc_init();
339 palmld_keys_init();
340 palmld_nor_init();
341 palmld_leds_init();
342 palmld_ide_init();
527} 343}
528 344
529MACHINE_START(PALMLD, "Palm LifeDrive") 345MACHINE_START(PALMLD, "Palm LifeDrive")
diff --git a/arch/arm/mach-pxa/palmt5.c b/arch/arm/mach-pxa/palmt5.c
index 5e92d84fe50d..1c281995f658 100644
--- a/arch/arm/mach-pxa/palmt5.c
+++ b/arch/arm/mach-pxa/palmt5.c
@@ -25,7 +25,7 @@
25#include <linux/pda_power.h> 25#include <linux/pda_power.h>
26#include <linux/pwm_backlight.h> 26#include <linux/pwm_backlight.h>
27#include <linux/gpio.h> 27#include <linux/gpio.h>
28#include <linux/wm97xx_batt.h> 28#include <linux/wm97xx.h>
29#include <linux/power_supply.h> 29#include <linux/power_supply.h>
30#include <linux/usb/gpio_vbus.h> 30#include <linux/usb/gpio_vbus.h>
31 31
@@ -42,6 +42,7 @@
42#include <mach/pxa27x_keypad.h> 42#include <mach/pxa27x_keypad.h>
43#include <mach/udc.h> 43#include <mach/udc.h>
44#include <mach/palmasoc.h> 44#include <mach/palmasoc.h>
45#include <mach/palm27x.h>
45 46
46#include "generic.h" 47#include "generic.h"
47#include "devices.h" 48#include "devices.h"
@@ -104,19 +105,9 @@ static unsigned long palmt5_pin_config[] __initdata = {
104}; 105};
105 106
106/****************************************************************************** 107/******************************************************************************
107 * SD/MMC card controller
108 ******************************************************************************/
109static struct pxamci_platform_data palmt5_mci_platform_data = {
110 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
111 .gpio_card_detect = GPIO_NR_PALMT5_SD_DETECT_N,
112 .gpio_card_ro = GPIO_NR_PALMT5_SD_READONLY,
113 .gpio_power = GPIO_NR_PALMT5_SD_POWER,
114 .detect_delay_ms = 200,
115};
116
117/******************************************************************************
118 * GPIO keyboard 108 * GPIO keyboard
119 ******************************************************************************/ 109 ******************************************************************************/
110#if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
120static unsigned int palmt5_matrix_keys[] = { 111static unsigned int palmt5_matrix_keys[] = {
121 KEY(0, 0, KEY_POWER), 112 KEY(0, 0, KEY_POWER),
122 KEY(0, 1, KEY_F1), 113 KEY(0, 1, KEY_F1),
@@ -142,9 +133,18 @@ static struct pxa27x_keypad_platform_data palmt5_keypad_platform_data = {
142 .debounce_interval = 30, 133 .debounce_interval = 30,
143}; 134};
144 135
136static void __init palmt5_kpc_init(void)
137{
138 pxa_set_keypad_info(&palmt5_keypad_platform_data);
139}
140#else
141static inline void palmt5_kpc_init(void) {}
142#endif
143
145/****************************************************************************** 144/******************************************************************************
146 * GPIO keys 145 * GPIO keys
147 ******************************************************************************/ 146 ******************************************************************************/
147#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
148static struct gpio_keys_button palmt5_pxa_buttons[] = { 148static struct gpio_keys_button palmt5_pxa_buttons[] = {
149 {KEY_F8, GPIO_NR_PALMT5_HOTSYNC_BUTTON_N, 1, "HotSync Button" }, 149 {KEY_F8, GPIO_NR_PALMT5_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
150}; 150};
@@ -162,241 +162,17 @@ static struct platform_device palmt5_pxa_keys = {
162 }, 162 },
163}; 163};
164 164
165/****************************************************************************** 165static void __init palmt5_keys_init(void)
166 * Backlight
167 ******************************************************************************/
168static int palmt5_backlight_init(struct device *dev)
169{
170 int ret;
171
172 ret = gpio_request(GPIO_NR_PALMT5_BL_POWER, "BL POWER");
173 if (ret)
174 goto err;
175 ret = gpio_direction_output(GPIO_NR_PALMT5_BL_POWER, 0);
176 if (ret)
177 goto err2;
178 ret = gpio_request(GPIO_NR_PALMT5_LCD_POWER, "LCD POWER");
179 if (ret)
180 goto err2;
181 ret = gpio_direction_output(GPIO_NR_PALMT5_LCD_POWER, 0);
182 if (ret)
183 goto err3;
184
185 return 0;
186err3:
187 gpio_free(GPIO_NR_PALMT5_LCD_POWER);
188err2:
189 gpio_free(GPIO_NR_PALMT5_BL_POWER);
190err:
191 return ret;
192}
193
194static int palmt5_backlight_notify(struct device *dev, int brightness)
195{
196 gpio_set_value(GPIO_NR_PALMT5_BL_POWER, brightness);
197 gpio_set_value(GPIO_NR_PALMT5_LCD_POWER, brightness);
198 return brightness;
199}
200
201static void palmt5_backlight_exit(struct device *dev)
202{
203 gpio_free(GPIO_NR_PALMT5_BL_POWER);
204 gpio_free(GPIO_NR_PALMT5_LCD_POWER);
205}
206
207static struct platform_pwm_backlight_data palmt5_backlight_data = {
208 .pwm_id = 0,
209 .max_brightness = PALMT5_MAX_INTENSITY,
210 .dft_brightness = PALMT5_MAX_INTENSITY,
211 .pwm_period_ns = PALMT5_PERIOD_NS,
212 .init = palmt5_backlight_init,
213 .notify = palmt5_backlight_notify,
214 .exit = palmt5_backlight_exit,
215};
216
217static struct platform_device palmt5_backlight = {
218 .name = "pwm-backlight",
219 .dev = {
220 .parent = &pxa27x_device_pwm0.dev,
221 .platform_data = &palmt5_backlight_data,
222 },
223};
224
225/******************************************************************************
226 * IrDA
227 ******************************************************************************/
228static struct pxaficp_platform_data palmt5_ficp_platform_data = {
229 .gpio_pwdown = GPIO_NR_PALMT5_IR_DISABLE,
230 .transceiver_cap = IR_SIRMODE | IR_OFF,
231};
232
233/******************************************************************************
234 * UDC
235 ******************************************************************************/
236static struct gpio_vbus_mach_info palmt5_udc_info = {
237 .gpio_vbus = GPIO_NR_PALMT5_USB_DETECT_N,
238 .gpio_vbus_inverted = 1,
239 .gpio_pullup = GPIO_NR_PALMT5_USB_PULLUP,
240};
241
242static struct platform_device palmt5_gpio_vbus = {
243 .name = "gpio-vbus",
244 .id = -1,
245 .dev = {
246 .platform_data = &palmt5_udc_info,
247 },
248};
249
250/******************************************************************************
251 * Power supply
252 ******************************************************************************/
253static int power_supply_init(struct device *dev)
254{
255 int ret;
256
257 ret = gpio_request(GPIO_NR_PALMT5_POWER_DETECT, "CABLE_STATE_AC");
258 if (ret)
259 goto err1;
260 ret = gpio_direction_input(GPIO_NR_PALMT5_POWER_DETECT);
261 if (ret)
262 goto err2;
263
264 return 0;
265err2:
266 gpio_free(GPIO_NR_PALMT5_POWER_DETECT);
267err1:
268 return ret;
269}
270
271static int palmt5_is_ac_online(void)
272{
273 return gpio_get_value(GPIO_NR_PALMT5_POWER_DETECT);
274}
275
276static void power_supply_exit(struct device *dev)
277{
278 gpio_free(GPIO_NR_PALMT5_POWER_DETECT);
279}
280
281static char *palmt5_supplicants[] = {
282 "main-battery",
283};
284
285static struct pda_power_pdata power_supply_info = {
286 .init = power_supply_init,
287 .is_ac_online = palmt5_is_ac_online,
288 .exit = power_supply_exit,
289 .supplied_to = palmt5_supplicants,
290 .num_supplicants = ARRAY_SIZE(palmt5_supplicants),
291};
292
293static struct platform_device power_supply = {
294 .name = "pda-power",
295 .id = -1,
296 .dev = {
297 .platform_data = &power_supply_info,
298 },
299};
300
301/******************************************************************************
302 * WM97xx battery
303 ******************************************************************************/
304static struct wm97xx_batt_info wm97xx_batt_pdata = {
305 .batt_aux = WM97XX_AUX_ID3,
306 .temp_aux = WM97XX_AUX_ID2,
307 .charge_gpio = -1,
308 .max_voltage = PALMT5_BAT_MAX_VOLTAGE,
309 .min_voltage = PALMT5_BAT_MIN_VOLTAGE,
310 .batt_mult = 1000,
311 .batt_div = 414,
312 .temp_mult = 1,
313 .temp_div = 1,
314 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
315 .batt_name = "main-batt",
316};
317
318/******************************************************************************
319 * aSoC audio
320 ******************************************************************************/
321static struct palm27x_asoc_info palmt5_asoc_pdata = {
322 .jack_gpio = GPIO_NR_PALMT5_EARPHONE_DETECT,
323};
324
325static pxa2xx_audio_ops_t palmt5_ac97_pdata = {
326 .reset_gpio = 95,
327};
328
329static struct platform_device palmt5_asoc = {
330 .name = "palm27x-asoc",
331 .id = -1,
332 .dev = {
333 .platform_data = &palmt5_asoc_pdata,
334 },
335};
336
337/******************************************************************************
338 * Framebuffer
339 ******************************************************************************/
340static struct pxafb_mode_info palmt5_lcd_modes[] = {
341{
342 .pixclock = 57692,
343 .xres = 320,
344 .yres = 480,
345 .bpp = 16,
346
347 .left_margin = 32,
348 .right_margin = 1,
349 .upper_margin = 7,
350 .lower_margin = 1,
351
352 .hsync_len = 4,
353 .vsync_len = 1,
354},
355};
356
357static struct pxafb_mach_info palmt5_lcd_screen = {
358 .modes = palmt5_lcd_modes,
359 .num_modes = ARRAY_SIZE(palmt5_lcd_modes),
360 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
361};
362
363/******************************************************************************
364 * Power management - standby
365 ******************************************************************************/
366static void __init palmt5_pm_init(void)
367{ 166{
368 static u32 resume[] = { 167 platform_device_register(&palmt5_pxa_keys);
369 0xe3a00101, /* mov r0, #0x40000000 */
370 0xe380060f, /* orr r0, r0, #0x00f00000 */
371 0xe590f008, /* ldr pc, [r0, #0x08] */
372 };
373
374 /* copy the bootloader */
375 memcpy(phys_to_virt(PALMT5_STR_BASE), resume, sizeof(resume));
376} 168}
169#else
170static inline void palmt5_keys_init(void) {}
171#endif
377 172
378/****************************************************************************** 173/******************************************************************************
379 * Machine init 174 * Machine init
380 ******************************************************************************/ 175 ******************************************************************************/
381static struct platform_device *devices[] __initdata = {
382#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
383 &palmt5_pxa_keys,
384#endif
385 &palmt5_backlight,
386 &power_supply,
387 &palmt5_asoc,
388 &palmt5_gpio_vbus,
389};
390
391/* setup udc GPIOs initial state */
392static void __init palmt5_udc_init(void)
393{
394 if (!gpio_request(GPIO_NR_PALMT5_USB_PULLUP, "UDC Vbus")) {
395 gpio_direction_output(GPIO_NR_PALMT5_USB_PULLUP, 1);
396 gpio_free(GPIO_NR_PALMT5_USB_PULLUP);
397 }
398}
399
400static void __init palmt5_reserve(void) 176static void __init palmt5_reserve(void)
401{ 177{
402 memblock_reserve(0xa0200000, 0x1000); 178 memblock_reserve(0xa0200000, 0x1000);
@@ -405,21 +181,24 @@ static void __init palmt5_reserve(void)
405static void __init palmt5_init(void) 181static void __init palmt5_init(void)
406{ 182{
407 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmt5_pin_config)); 183 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmt5_pin_config));
408
409 pxa_set_ffuart_info(NULL); 184 pxa_set_ffuart_info(NULL);
410 pxa_set_btuart_info(NULL); 185 pxa_set_btuart_info(NULL);
411 pxa_set_stuart_info(NULL); 186 pxa_set_stuart_info(NULL);
412 187
413 palmt5_pm_init(); 188 palm27x_mmc_init(GPIO_NR_PALMT5_SD_DETECT_N, GPIO_NR_PALMT5_SD_READONLY,
414 set_pxa_fb_info(&palmt5_lcd_screen); 189 GPIO_NR_PALMT5_SD_POWER, 0);
415 pxa_set_mci_info(&palmt5_mci_platform_data); 190 palm27x_pm_init(PALMT5_STR_BASE);
416 palmt5_udc_init(); 191 palm27x_lcd_init(-1, &palm_320x480_lcd_mode);
417 pxa_set_ac97_info(&palmt5_ac97_pdata); 192 palm27x_udc_init(GPIO_NR_PALMT5_USB_DETECT_N,
418 pxa_set_ficp_info(&palmt5_ficp_platform_data); 193 GPIO_NR_PALMT5_USB_PULLUP, 1);
419 pxa_set_keypad_info(&palmt5_keypad_platform_data); 194 palm27x_irda_init(GPIO_NR_PALMT5_IR_DISABLE);
420 wm97xx_bat_set_pdata(&wm97xx_batt_pdata); 195 palm27x_ac97_init(PALMT5_BAT_MIN_VOLTAGE, PALMT5_BAT_MAX_VOLTAGE,
421 196 GPIO_NR_PALMT5_EARPHONE_DETECT, 95);
422 platform_add_devices(devices, ARRAY_SIZE(devices)); 197 palm27x_pwm_init(GPIO_NR_PALMT5_BL_POWER, GPIO_NR_PALMT5_LCD_POWER);
198 palm27x_power_init(GPIO_NR_PALMT5_POWER_DETECT, -1);
199 palm27x_pmic_init();
200 palmt5_kpc_init();
201 palmt5_keys_init();
423} 202}
424 203
425MACHINE_START(PALMT5, "Palm Tungsten|T5") 204MACHINE_START(PALMT5, "Palm Tungsten|T5")
diff --git a/arch/arm/mach-pxa/palmte2.c b/arch/arm/mach-pxa/palmte2.c
index 3d284ff1a64e..93c11a0438d5 100644
--- a/arch/arm/mach-pxa/palmte2.c
+++ b/arch/arm/mach-pxa/palmte2.c
@@ -23,7 +23,7 @@
23#include <linux/pda_power.h> 23#include <linux/pda_power.h>
24#include <linux/pwm_backlight.h> 24#include <linux/pwm_backlight.h>
25#include <linux/gpio.h> 25#include <linux/gpio.h>
26#include <linux/wm97xx_batt.h> 26#include <linux/wm97xx.h>
27#include <linux/power_supply.h> 27#include <linux/power_supply.h>
28#include <linux/usb/gpio_vbus.h> 28#include <linux/usb/gpio_vbus.h>
29 29
@@ -271,9 +271,9 @@ static struct platform_device power_supply = {
271}; 271};
272 272
273/****************************************************************************** 273/******************************************************************************
274 * WM97xx battery 274 * WM97xx audio, battery
275 ******************************************************************************/ 275 ******************************************************************************/
276static struct wm97xx_batt_info wm97xx_batt_pdata = { 276static struct wm97xx_batt_pdata palmte2_batt_pdata = {
277 .batt_aux = WM97XX_AUX_ID3, 277 .batt_aux = WM97XX_AUX_ID3,
278 .temp_aux = WM97XX_AUX_ID2, 278 .temp_aux = WM97XX_AUX_ID2,
279 .charge_gpio = -1, 279 .charge_gpio = -1,
@@ -287,9 +287,14 @@ static struct wm97xx_batt_info wm97xx_batt_pdata = {
287 .batt_name = "main-batt", 287 .batt_name = "main-batt",
288}; 288};
289 289
290/****************************************************************************** 290static struct wm97xx_pdata palmte2_wm97xx_pdata = {
291 * aSoC audio 291 .batt_pdata = &palmte2_batt_pdata,
292 ******************************************************************************/ 292};
293
294static pxa2xx_audio_ops_t palmte2_ac97_pdata = {
295 .codec_pdata = { &palmte2_wm97xx_pdata, },
296};
297
293static struct palm27x_asoc_info palmte2_asoc_pdata = { 298static struct palm27x_asoc_info palmte2_asoc_pdata = {
294 .jack_gpio = GPIO_NR_PALMTE2_EARPHONE_DETECT, 299 .jack_gpio = GPIO_NR_PALMTE2_EARPHONE_DETECT,
295}; 300};
@@ -361,9 +366,8 @@ static void __init palmte2_init(void)
361 set_pxa_fb_info(&palmte2_lcd_screen); 366 set_pxa_fb_info(&palmte2_lcd_screen);
362 pxa_set_mci_info(&palmte2_mci_platform_data); 367 pxa_set_mci_info(&palmte2_mci_platform_data);
363 palmte2_udc_init(); 368 palmte2_udc_init();
364 pxa_set_ac97_info(NULL); 369 pxa_set_ac97_info(&palmte2_ac97_pdata);
365 pxa_set_ficp_info(&palmte2_ficp_platform_data); 370 pxa_set_ficp_info(&palmte2_ficp_platform_data);
366 wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
367 371
368 platform_add_devices(devices, ARRAY_SIZE(devices)); 372 platform_add_devices(devices, ARRAY_SIZE(devices));
369} 373}
diff --git a/arch/arm/mach-pxa/palmtreo.c b/arch/arm/mach-pxa/palmtreo.c
index 3d0c9cc2a406..52defd5e42e5 100644
--- a/arch/arm/mach-pxa/palmtreo.c
+++ b/arch/arm/mach-pxa/palmtreo.c
@@ -24,7 +24,6 @@
24#include <linux/pda_power.h> 24#include <linux/pda_power.h>
25#include <linux/pwm_backlight.h> 25#include <linux/pwm_backlight.h>
26#include <linux/gpio.h> 26#include <linux/gpio.h>
27#include <linux/wm97xx_batt.h>
28#include <linux/power_supply.h> 27#include <linux/power_supply.h>
29#include <linux/sysdev.h> 28#include <linux/sysdev.h>
30#include <linux/w1-gpio.h> 29#include <linux/w1-gpio.h>
@@ -46,6 +45,7 @@
46#include <mach/pxa2xx-regs.h> 45#include <mach/pxa2xx-regs.h>
47#include <mach/palmasoc.h> 46#include <mach/palmasoc.h>
48#include <mach/camera.h> 47#include <mach/camera.h>
48#include <mach/palm27x.h>
49 49
50#include <sound/pxa2xx-lib.h> 50#include <sound/pxa2xx-lib.h>
51 51
@@ -160,31 +160,9 @@ static unsigned long centro685_pin_config[] __initdata = {
160#endif /* CONFIG_MACH_CENTRO */ 160#endif /* CONFIG_MACH_CENTRO */
161 161
162/****************************************************************************** 162/******************************************************************************
163 * SD/MMC card controller
164 ******************************************************************************/
165#ifdef CONFIG_MACH_TREO680
166static struct pxamci_platform_data treo680_mci_platform_data = {
167 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
168 .gpio_card_detect = GPIO_NR_TREO_SD_DETECT_N,
169 .gpio_card_ro = GPIO_NR_TREO680_SD_READONLY,
170 .gpio_power = GPIO_NR_TREO680_SD_POWER,
171};
172#endif /* CONFIG_MACH_TREO680 */
173
174#ifdef CONFIG_MACH_CENTRO
175static struct pxamci_platform_data centro_mci_platform_data = {
176 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
177 .gpio_card_detect = GPIO_NR_TREO_SD_DETECT_N,
178 .gpio_card_ro = -1,
179 .gpio_power = GPIO_NR_CENTRO_SD_POWER,
180 .gpio_power_invert = 1,
181};
182#endif /* CONFIG_MACH_CENTRO */
183
184/******************************************************************************
185 * GPIO keyboard 163 * GPIO keyboard
186 ******************************************************************************/ 164 ******************************************************************************/
187#ifdef CONFIG_MACH_TREO680 165#if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
188static unsigned int treo680_matrix_keys[] = { 166static unsigned int treo680_matrix_keys[] = {
189 KEY(0, 0, KEY_F8), /* Red/Off/Power */ 167 KEY(0, 0, KEY_F8), /* Red/Off/Power */
190 KEY(0, 1, KEY_LEFT), 168 KEY(0, 1, KEY_LEFT),
@@ -244,19 +222,6 @@ static unsigned int treo680_matrix_keys[] = {
244 KEY(7, 5, KEY_I), 222 KEY(7, 5, KEY_I),
245}; 223};
246 224
247static struct pxa27x_keypad_platform_data treo680_keypad_platform_data = {
248 .matrix_key_rows = 8,
249 .matrix_key_cols = 7,
250 .matrix_key_map = treo680_matrix_keys,
251 .matrix_key_map_size = ARRAY_SIZE(treo680_matrix_keys),
252 .direct_key_map = { KEY_CONNECT },
253 .direct_key_num = 1,
254
255 .debounce_interval = 30,
256};
257#endif /* CONFIG_MACH_TREO680 */
258
259#ifdef CONFIG_MACH_CENTRO
260static unsigned int centro_matrix_keys[] = { 225static unsigned int centro_matrix_keys[] = {
261 KEY(0, 0, KEY_F9), /* Home */ 226 KEY(0, 0, KEY_F9), /* Home */
262 KEY(0, 1, KEY_LEFT), 227 KEY(0, 1, KEY_LEFT),
@@ -316,157 +281,50 @@ static unsigned int centro_matrix_keys[] = {
316 KEY(7, 5, KEY_I), 281 KEY(7, 5, KEY_I),
317}; 282};
318 283
319static struct pxa27x_keypad_platform_data centro_keypad_platform_data = { 284static struct pxa27x_keypad_platform_data treo680_keypad_pdata = {
320 .matrix_key_rows = 8, 285 .matrix_key_rows = 8,
321 .matrix_key_cols = 7, 286 .matrix_key_cols = 7,
322 .matrix_key_map = centro_matrix_keys, 287 .matrix_key_map = treo680_matrix_keys,
323 .matrix_key_map_size = ARRAY_SIZE(centro_matrix_keys), 288 .matrix_key_map_size = ARRAY_SIZE(treo680_matrix_keys),
324 .direct_key_map = { KEY_CONNECT }, 289 .direct_key_map = { KEY_CONNECT },
325 .direct_key_num = 1, 290 .direct_key_num = 1,
326 291
327 .debounce_interval = 30, 292 .debounce_interval = 30,
328}; 293};
329#endif /* CONFIG_MACH_CENTRO */
330 294
331/****************************************************************************** 295static void __init palmtreo_kpc_init(void)
332 * aSoC audio
333 ******************************************************************************/
334
335static pxa2xx_audio_ops_t treo_ac97_pdata = {
336 .reset_gpio = 95,
337};
338
339/******************************************************************************
340 * Backlight
341 ******************************************************************************/
342static int treo_backlight_init(struct device *dev)
343{ 296{
344 int ret; 297 static struct pxa27x_keypad_platform_data *data = &treo680_keypad_pdata;
345
346 ret = gpio_request(GPIO_NR_TREO_BL_POWER, "BL POWER");
347 if (ret)
348 goto err;
349 ret = gpio_direction_output(GPIO_NR_TREO_BL_POWER, 0);
350 if (ret)
351 goto err2;
352
353 return 0;
354 298
355err2: 299 if (machine_is_centro()) {
356 gpio_free(GPIO_NR_TREO_BL_POWER); 300 data->matrix_key_map = centro_matrix_keys;
357err: 301 data->matrix_key_map_size = ARRAY_SIZE(centro_matrix_keys);
358 return ret; 302 }
359}
360
361static int treo_backlight_notify(struct device *dev, int brightness)
362{
363 gpio_set_value(GPIO_NR_TREO_BL_POWER, brightness);
364 return TREO_MAX_INTENSITY - brightness;
365};
366 303
367static void treo_backlight_exit(struct device *dev) 304 pxa_set_keypad_info(&treo680_keypad_pdata);
368{
369 gpio_free(GPIO_NR_TREO_BL_POWER);
370} 305}
371 306#else
372static struct platform_pwm_backlight_data treo_backlight_data = { 307static inline void palmtreo_kpc_init(void) {}
373 .pwm_id = 0, 308#endif
374 .max_brightness = TREO_MAX_INTENSITY,
375 .dft_brightness = TREO_DEFAULT_INTENSITY,
376 .pwm_period_ns = TREO_PERIOD_NS,
377 .init = treo_backlight_init,
378 .notify = treo_backlight_notify,
379 .exit = treo_backlight_exit,
380};
381
382static struct platform_device treo_backlight = {
383 .name = "pwm-backlight",
384 .dev = {
385 .parent = &pxa27x_device_pwm0.dev,
386 .platform_data = &treo_backlight_data,
387 },
388};
389
390/******************************************************************************
391 * IrDA
392 ******************************************************************************/
393static struct pxaficp_platform_data treo_ficp_info = {
394 .gpio_pwdown = GPIO_NR_TREO_IR_EN,
395 .transceiver_cap = IR_SIRMODE | IR_OFF,
396};
397
398/******************************************************************************
399 * UDC
400 ******************************************************************************/
401static struct pxa2xx_udc_mach_info treo_udc_info __initdata = {
402 .gpio_vbus = GPIO_NR_TREO_USB_DETECT,
403 .gpio_vbus_inverted = 1,
404 .gpio_pullup = GPIO_NR_TREO_USB_PULLUP,
405};
406
407 309
408/****************************************************************************** 310/******************************************************************************
409 * USB host 311 * USB host
410 ******************************************************************************/ 312 ******************************************************************************/
411#ifdef CONFIG_MACH_TREO680 313#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
412static struct pxaohci_platform_data treo680_ohci_info = { 314static struct pxaohci_platform_data treo680_ohci_info = {
413 .port_mode = PMM_PERPORT_MODE, 315 .port_mode = PMM_PERPORT_MODE,
414 .flags = ENABLE_PORT1 | ENABLE_PORT3, 316 .flags = ENABLE_PORT1 | ENABLE_PORT3,
415 .power_budget = 0, 317 .power_budget = 0,
416}; 318};
417#endif /* CONFIG_MACH_TREO680 */
418 319
419/****************************************************************************** 320static void __init palmtreo_uhc_init(void)
420 * Power supply
421 ******************************************************************************/
422static int power_supply_init(struct device *dev)
423{ 321{
424 int ret; 322 if (machine_is_treo680())
425 323 pxa_set_ohci_info(&treo680_ohci_info);
426 ret = gpio_request(GPIO_NR_TREO_POWER_DETECT, "CABLE_STATE_AC");
427 if (ret)
428 goto err1;
429 ret = gpio_direction_input(GPIO_NR_TREO_POWER_DETECT);
430 if (ret)
431 goto err2;
432
433 return 0;
434
435err2:
436 gpio_free(GPIO_NR_TREO_POWER_DETECT);
437err1:
438 return ret;
439}
440
441static int treo_is_ac_online(void)
442{
443 return gpio_get_value(GPIO_NR_TREO_POWER_DETECT);
444} 324}
445 325#else
446static void power_supply_exit(struct device *dev) 326static inline void palmtreo_uhc_init(void) {}
447{ 327#endif
448 gpio_free(GPIO_NR_TREO_POWER_DETECT);
449}
450
451static char *treo_supplicants[] = {
452 "main-battery",
453};
454
455static struct pda_power_pdata power_supply_info = {
456 .init = power_supply_init,
457 .is_ac_online = treo_is_ac_online,
458 .exit = power_supply_exit,
459 .supplied_to = treo_supplicants,
460 .num_supplicants = ARRAY_SIZE(treo_supplicants),
461};
462
463static struct platform_device power_supply = {
464 .name = "pda-power",
465 .id = -1,
466 .dev = {
467 .platform_data = &power_supply_info,
468 },
469};
470 328
471/****************************************************************************** 329/******************************************************************************
472 * Vibra and LEDs 330 * Vibra and LEDs
@@ -495,16 +353,6 @@ static struct gpio_led_platform_data treo680_gpio_led_info = {
495 .num_leds = ARRAY_SIZE(treo680_gpio_leds), 353 .num_leds = ARRAY_SIZE(treo680_gpio_leds),
496}; 354};
497 355
498static struct platform_device treo680_leds = {
499 .name = "leds-gpio",
500 .id = -1,
501 .dev = {
502 .platform_data = &treo680_gpio_led_info,
503 }
504};
505#endif /* CONFIG_MACH_TREO680 */
506
507#ifdef CONFIG_MACH_CENTRO
508static struct gpio_led centro_gpio_leds[] = { 356static struct gpio_led centro_gpio_leds[] = {
509 { 357 {
510 .name = "centro:vibra:vibra", 358 .name = "centro:vibra:vibra",
@@ -529,145 +377,67 @@ static struct gpio_led_platform_data centro_gpio_led_info = {
529 .num_leds = ARRAY_SIZE(centro_gpio_leds), 377 .num_leds = ARRAY_SIZE(centro_gpio_leds),
530}; 378};
531 379
532static struct platform_device centro_leds = { 380static struct platform_device palmtreo_leds = {
533 .name = "leds-gpio", 381 .name = "leds-gpio",
534 .id = -1, 382 .id = -1,
535 .dev = { 383 .dev = {
536 .platform_data = &centro_gpio_led_info, 384 .platform_data = &treo680_gpio_led_info,
537 } 385 }
538}; 386};
539#endif /* CONFIG_MACH_CENTRO */
540
541/******************************************************************************
542 * Framebuffer
543 ******************************************************************************/
544/* TODO: add support for 324x324 */
545static struct pxafb_mode_info treo_lcd_modes[] = {
546{
547 .pixclock = 86538,
548 .xres = 320,
549 .yres = 320,
550 .bpp = 16,
551
552 .left_margin = 20,
553 .right_margin = 8,
554 .upper_margin = 8,
555 .lower_margin = 5,
556
557 .hsync_len = 4,
558 .vsync_len = 1,
559},
560};
561 387
562static void treo_lcd_power(int on, struct fb_var_screeninfo *info) 388static void __init palmtreo_leds_init(void)
563{ 389{
564 gpio_set_value(GPIO_NR_TREO_BL_POWER, on); 390 if (machine_is_centro())
565} 391 palmtreo_leds.dev.platform_data = &centro_gpio_led_info;
566
567static struct pxafb_mach_info treo_lcd_screen = {
568 .modes = treo_lcd_modes,
569 .num_modes = ARRAY_SIZE(treo_lcd_modes),
570 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
571};
572 392
573/****************************************************************************** 393 platform_device_register(&palmtreo_leds);
574 * Power management - standby
575 ******************************************************************************/
576static void __init treo_pm_init(void)
577{
578 static u32 resume[] = {
579 0xe3a00101, /* mov r0, #0x40000000 */
580 0xe380060f, /* orr r0, r0, #0x00f00000 */
581 0xe590f008, /* ldr pc, [r0, #0x08] */
582 };
583
584 /* this is where the bootloader jumps */
585 memcpy(phys_to_virt(TREO_STR_BASE), resume, sizeof(resume));
586} 394}
395#else
396static inline void palmtreo_leds_init(void) {}
397#endif
587 398
588/****************************************************************************** 399/******************************************************************************
589 * Machine init 400 * Machine init
590 ******************************************************************************/ 401 ******************************************************************************/
591static struct platform_device *treo_devices[] __initdata = {
592 &treo_backlight,
593 &power_supply,
594};
595
596#ifdef CONFIG_MACH_TREO680
597static struct platform_device *treo680_devices[] __initdata = {
598 &treo680_leds,
599};
600#endif /* CONFIG_MACH_TREO680 */
601
602#ifdef CONFIG_MACH_CENTRO
603static struct platform_device *centro_devices[] __initdata = {
604 &centro_leds,
605};
606#endif /* CONFIG_MACH_CENTRO */
607
608/* setup udc GPIOs initial state */
609static void __init treo_udc_init(void)
610{
611 if (!gpio_request(GPIO_NR_TREO_USB_PULLUP, "UDC Vbus")) {
612 gpio_direction_output(GPIO_NR_TREO_USB_PULLUP, 1);
613 gpio_free(GPIO_NR_TREO_USB_PULLUP);
614 }
615}
616
617static void __init treo_lcd_power_init(void)
618{
619 int ret;
620
621 ret = gpio_request(GPIO_NR_TREO_LCD_POWER, "LCD POWER");
622 if (ret) {
623 pr_err("Treo680: LCD power GPIO request failed!\n");
624 return;
625 }
626
627 ret = gpio_direction_output(GPIO_NR_TREO_LCD_POWER, 0);
628 if (ret) {
629 pr_err("Treo680: setting LCD power GPIO direction failed!\n");
630 gpio_free(GPIO_NR_TREO_LCD_POWER);
631 return;
632 }
633
634 treo_lcd_screen.pxafb_lcd_power = treo_lcd_power;
635}
636
637static void __init treo_reserve(void) 402static void __init treo_reserve(void)
638{ 403{
639 memblock_reserve(0xa0000000, 0x1000); 404 memblock_reserve(0xa0000000, 0x1000);
640 memblock_reserve(0xa2000000, 0x1000); 405 memblock_reserve(0xa2000000, 0x1000);
641} 406}
642 407
643static void __init treo_init(void) 408static void __init palmphone_common_init(void)
644{ 409{
410 pxa2xx_mfp_config(ARRAY_AND_SIZE(treo_pin_config));
645 pxa_set_ffuart_info(NULL); 411 pxa_set_ffuart_info(NULL);
646 pxa_set_btuart_info(NULL); 412 pxa_set_btuart_info(NULL);
647 pxa_set_stuart_info(NULL); 413 pxa_set_stuart_info(NULL);
648 414 palm27x_pm_init(TREO_STR_BASE);
649 treo_pm_init(); 415 palm27x_lcd_init(GPIO_NR_TREO_BL_POWER, &palm_320x320_new_lcd_mode);
650 pxa2xx_mfp_config(ARRAY_AND_SIZE(treo_pin_config)); 416 palm27x_udc_init(GPIO_NR_TREO_USB_DETECT, GPIO_NR_TREO_USB_PULLUP, 1);
651 treo_lcd_power_init(); 417 palm27x_irda_init(GPIO_NR_TREO_IR_EN);
652 set_pxa_fb_info(&treo_lcd_screen); 418 palm27x_ac97_init(-1, -1, -1, 95);
653 treo_udc_init(); 419 palm27x_pwm_init(GPIO_NR_TREO_BL_POWER, -1);
654 pxa_set_udc_info(&treo_udc_info); 420 palm27x_power_init(GPIO_NR_TREO_POWER_DETECT, -1);
655 pxa_set_ac97_info(&treo_ac97_pdata); 421 palm27x_pmic_init();
656 pxa_set_ficp_info(&treo_ficp_info); 422 palmtreo_kpc_init();
657 423 palmtreo_uhc_init();
658 platform_add_devices(ARRAY_AND_SIZE(treo_devices)); 424 palmtreo_leds_init();
659} 425}
660 426
661#ifdef CONFIG_MACH_TREO680
662static void __init treo680_init(void) 427static void __init treo680_init(void)
663{ 428{
664 treo_init();
665 pxa2xx_mfp_config(ARRAY_AND_SIZE(treo680_pin_config)); 429 pxa2xx_mfp_config(ARRAY_AND_SIZE(treo680_pin_config));
666 pxa_set_mci_info(&treo680_mci_platform_data); 430 palmphone_common_init();
667 pxa_set_keypad_info(&treo680_keypad_platform_data); 431 palm27x_mmc_init(GPIO_NR_TREO_SD_DETECT_N, GPIO_NR_TREO680_SD_READONLY,
668 pxa_set_ohci_info(&treo680_ohci_info); 432 GPIO_NR_TREO680_SD_POWER, 0);
433}
669 434
670 platform_add_devices(ARRAY_AND_SIZE(treo680_devices)); 435static void __init centro_init(void)
436{
437 pxa2xx_mfp_config(ARRAY_AND_SIZE(centro685_pin_config));
438 palmphone_common_init();
439 palm27x_mmc_init(GPIO_NR_TREO_SD_DETECT_N, -1,
440 GPIO_NR_CENTRO_SD_POWER, 1);
671} 441}
672 442
673MACHINE_START(TREO680, "Palm Treo 680") 443MACHINE_START(TREO680, "Palm Treo 680")
@@ -680,19 +450,6 @@ MACHINE_START(TREO680, "Palm Treo 680")
680 .timer = &pxa_timer, 450 .timer = &pxa_timer,
681 .init_machine = treo680_init, 451 .init_machine = treo680_init,
682MACHINE_END 452MACHINE_END
683#endif /* CONFIG_MACH_TREO680 */
684
685#ifdef CONFIG_MACH_CENTRO
686static void __init centro_init(void)
687{
688 treo_init();
689 pxa2xx_mfp_config(ARRAY_AND_SIZE(centro685_pin_config));
690 pxa_set_mci_info(&centro_mci_platform_data);
691
692 pxa_set_keypad_info(&centro_keypad_platform_data);
693
694 platform_add_devices(ARRAY_AND_SIZE(centro_devices));
695}
696 453
697MACHINE_START(CENTRO, "Palm Centro 685") 454MACHINE_START(CENTRO, "Palm Centro 685")
698 .phys_io = TREO_PHYS_IO_START, 455 .phys_io = TREO_PHYS_IO_START,
@@ -702,6 +459,5 @@ MACHINE_START(CENTRO, "Palm Centro 685")
702 .reserve = treo_reserve, 459 .reserve = treo_reserve,
703 .init_irq = pxa27x_init_irq, 460 .init_irq = pxa27x_init_irq,
704 .timer = &pxa_timer, 461 .timer = &pxa_timer,
705 .init_machine = centro_init, 462 .init_machine = centro_init,
706MACHINE_END 463MACHINE_END
707#endif /* CONFIG_MACH_CENTRO */
diff --git a/arch/arm/mach-pxa/palmtx.c b/arch/arm/mach-pxa/palmtx.c
index ecc1a401598e..144dc2b6911f 100644
--- a/arch/arm/mach-pxa/palmtx.c
+++ b/arch/arm/mach-pxa/palmtx.c
@@ -25,7 +25,7 @@
25#include <linux/pda_power.h> 25#include <linux/pda_power.h>
26#include <linux/pwm_backlight.h> 26#include <linux/pwm_backlight.h>
27#include <linux/gpio.h> 27#include <linux/gpio.h>
28#include <linux/wm97xx_batt.h> 28#include <linux/wm97xx.h>
29#include <linux/power_supply.h> 29#include <linux/power_supply.h>
30#include <linux/usb/gpio_vbus.h> 30#include <linux/usb/gpio_vbus.h>
31#include <linux/mtd/nand.h> 31#include <linux/mtd/nand.h>
@@ -46,6 +46,7 @@
46#include <mach/pxa27x_keypad.h> 46#include <mach/pxa27x_keypad.h>
47#include <mach/udc.h> 47#include <mach/udc.h>
48#include <mach/palmasoc.h> 48#include <mach/palmasoc.h>
49#include <mach/palm27x.h>
49 50
50#include "generic.h" 51#include "generic.h"
51#include "devices.h" 52#include "devices.h"
@@ -129,6 +130,7 @@ static unsigned long palmtx_pin_config[] __initdata = {
129/****************************************************************************** 130/******************************************************************************
130 * NOR Flash 131 * NOR Flash
131 ******************************************************************************/ 132 ******************************************************************************/
133#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
132static struct mtd_partition palmtx_partitions[] = { 134static struct mtd_partition palmtx_partitions[] = {
133 { 135 {
134 .name = "Flash", 136 .name = "Flash",
@@ -162,20 +164,18 @@ static struct platform_device palmtx_flash = {
162 }, 164 },
163}; 165};
164 166
165/****************************************************************************** 167static void __init palmtx_nor_init(void)
166 * SD/MMC card controller 168{
167 ******************************************************************************/ 169 platform_device_register(&palmtx_flash);
168static struct pxamci_platform_data palmtx_mci_platform_data = { 170}
169 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, 171#else
170 .gpio_card_detect = GPIO_NR_PALMTX_SD_DETECT_N, 172static inline void palmtx_nor_init(void) {}
171 .gpio_card_ro = GPIO_NR_PALMTX_SD_READONLY, 173#endif
172 .gpio_power = GPIO_NR_PALMTX_SD_POWER,
173 .detect_delay_ms = 200,
174};
175 174
176/****************************************************************************** 175/******************************************************************************
177 * GPIO keyboard 176 * GPIO keyboard
178 ******************************************************************************/ 177 ******************************************************************************/
178#if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
179static unsigned int palmtx_matrix_keys[] = { 179static unsigned int palmtx_matrix_keys[] = {
180 KEY(0, 0, KEY_POWER), 180 KEY(0, 0, KEY_POWER),
181 KEY(0, 1, KEY_F1), 181 KEY(0, 1, KEY_F1),
@@ -201,9 +201,18 @@ static struct pxa27x_keypad_platform_data palmtx_keypad_platform_data = {
201 .debounce_interval = 30, 201 .debounce_interval = 30,
202}; 202};
203 203
204static void __init palmtx_kpc_init(void)
205{
206 pxa_set_keypad_info(&palmtx_keypad_platform_data);
207}
208#else
209static inline void palmtx_kpc_init(void) {}
210#endif
211
204/****************************************************************************** 212/******************************************************************************
205 * GPIO keys 213 * GPIO keys
206 ******************************************************************************/ 214 ******************************************************************************/
215#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
207static struct gpio_keys_button palmtx_pxa_buttons[] = { 216static struct gpio_keys_button palmtx_pxa_buttons[] = {
208 {KEY_F8, GPIO_NR_PALMTX_HOTSYNC_BUTTON_N, 1, "HotSync Button" }, 217 {KEY_F8, GPIO_NR_PALMTX_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
209}; 218};
@@ -221,208 +230,18 @@ static struct platform_device palmtx_pxa_keys = {
221 }, 230 },
222}; 231};
223 232
224/****************************************************************************** 233static void __init palmtx_keys_init(void)
225 * Backlight
226 ******************************************************************************/
227static int palmtx_backlight_init(struct device *dev)
228{
229 int ret;
230
231 ret = gpio_request(GPIO_NR_PALMTX_BL_POWER, "BL POWER");
232 if (ret)
233 goto err;
234 ret = gpio_direction_output(GPIO_NR_PALMTX_BL_POWER, 0);
235 if (ret)
236 goto err2;
237 ret = gpio_request(GPIO_NR_PALMTX_LCD_POWER, "LCD POWER");
238 if (ret)
239 goto err2;
240 ret = gpio_direction_output(GPIO_NR_PALMTX_LCD_POWER, 0);
241 if (ret)
242 goto err3;
243
244 return 0;
245err3:
246 gpio_free(GPIO_NR_PALMTX_LCD_POWER);
247err2:
248 gpio_free(GPIO_NR_PALMTX_BL_POWER);
249err:
250 return ret;
251}
252
253static int palmtx_backlight_notify(struct device *dev, int brightness)
254{
255 gpio_set_value(GPIO_NR_PALMTX_BL_POWER, brightness);
256 gpio_set_value(GPIO_NR_PALMTX_LCD_POWER, brightness);
257 return brightness;
258}
259
260static void palmtx_backlight_exit(struct device *dev)
261{
262 gpio_free(GPIO_NR_PALMTX_BL_POWER);
263 gpio_free(GPIO_NR_PALMTX_LCD_POWER);
264}
265
266static struct platform_pwm_backlight_data palmtx_backlight_data = {
267 .pwm_id = 0,
268 .max_brightness = PALMTX_MAX_INTENSITY,
269 .dft_brightness = PALMTX_MAX_INTENSITY,
270 .pwm_period_ns = PALMTX_PERIOD_NS,
271 .init = palmtx_backlight_init,
272 .notify = palmtx_backlight_notify,
273 .exit = palmtx_backlight_exit,
274};
275
276static struct platform_device palmtx_backlight = {
277 .name = "pwm-backlight",
278 .dev = {
279 .parent = &pxa27x_device_pwm0.dev,
280 .platform_data = &palmtx_backlight_data,
281 },
282};
283
284/******************************************************************************
285 * IrDA
286 ******************************************************************************/
287static struct pxaficp_platform_data palmtx_ficp_platform_data = {
288 .gpio_pwdown = GPIO_NR_PALMTX_IR_DISABLE,
289 .transceiver_cap = IR_SIRMODE | IR_OFF,
290};
291
292/******************************************************************************
293 * UDC
294 ******************************************************************************/
295static struct gpio_vbus_mach_info palmtx_udc_info = {
296 .gpio_vbus = GPIO_NR_PALMTX_USB_DETECT_N,
297 .gpio_vbus_inverted = 1,
298 .gpio_pullup = GPIO_NR_PALMTX_USB_PULLUP,
299};
300
301static struct platform_device palmtx_gpio_vbus = {
302 .name = "gpio-vbus",
303 .id = -1,
304 .dev = {
305 .platform_data = &palmtx_udc_info,
306 },
307};
308
309/******************************************************************************
310 * Power supply
311 ******************************************************************************/
312static int power_supply_init(struct device *dev)
313{
314 int ret;
315
316 ret = gpio_request(GPIO_NR_PALMTX_POWER_DETECT, "CABLE_STATE_AC");
317 if (ret)
318 goto err1;
319 ret = gpio_direction_input(GPIO_NR_PALMTX_POWER_DETECT);
320 if (ret)
321 goto err2;
322
323 return 0;
324
325err2:
326 gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
327err1:
328 return ret;
329}
330
331static int palmtx_is_ac_online(void)
332{
333 return gpio_get_value(GPIO_NR_PALMTX_POWER_DETECT);
334}
335
336static void power_supply_exit(struct device *dev)
337{ 234{
338 gpio_free(GPIO_NR_PALMTX_POWER_DETECT); 235 platform_device_register(&palmtx_pxa_keys);
339} 236}
340 237#else
341static char *palmtx_supplicants[] = { 238static inline void palmtx_keys_init(void) {}
342 "main-battery", 239#endif
343};
344
345static struct pda_power_pdata power_supply_info = {
346 .init = power_supply_init,
347 .is_ac_online = palmtx_is_ac_online,
348 .exit = power_supply_exit,
349 .supplied_to = palmtx_supplicants,
350 .num_supplicants = ARRAY_SIZE(palmtx_supplicants),
351};
352
353static struct platform_device power_supply = {
354 .name = "pda-power",
355 .id = -1,
356 .dev = {
357 .platform_data = &power_supply_info,
358 },
359};
360
361/******************************************************************************
362 * WM97xx battery
363 ******************************************************************************/
364static struct wm97xx_batt_info wm97xx_batt_pdata = {
365 .batt_aux = WM97XX_AUX_ID3,
366 .temp_aux = WM97XX_AUX_ID2,
367 .charge_gpio = -1,
368 .max_voltage = PALMTX_BAT_MAX_VOLTAGE,
369 .min_voltage = PALMTX_BAT_MIN_VOLTAGE,
370 .batt_mult = 1000,
371 .batt_div = 414,
372 .temp_mult = 1,
373 .temp_div = 1,
374 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
375 .batt_name = "main-batt",
376};
377
378/******************************************************************************
379 * aSoC audio
380 ******************************************************************************/
381static struct palm27x_asoc_info palmtx_asoc_pdata = {
382 .jack_gpio = GPIO_NR_PALMTX_EARPHONE_DETECT,
383};
384
385static pxa2xx_audio_ops_t palmtx_ac97_pdata = {
386 .reset_gpio = 95,
387};
388
389static struct platform_device palmtx_asoc = {
390 .name = "palm27x-asoc",
391 .id = -1,
392 .dev = {
393 .platform_data = &palmtx_asoc_pdata,
394 },
395};
396
397/******************************************************************************
398 * Framebuffer
399 ******************************************************************************/
400static struct pxafb_mode_info palmtx_lcd_modes[] = {
401{
402 .pixclock = 57692,
403 .xres = 320,
404 .yres = 480,
405 .bpp = 16,
406
407 .left_margin = 32,
408 .right_margin = 1,
409 .upper_margin = 7,
410 .lower_margin = 1,
411
412 .hsync_len = 4,
413 .vsync_len = 1,
414},
415};
416
417static struct pxafb_mach_info palmtx_lcd_screen = {
418 .modes = palmtx_lcd_modes,
419 .num_modes = ARRAY_SIZE(palmtx_lcd_modes),
420 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
421};
422 240
423/****************************************************************************** 241/******************************************************************************
424 * NAND Flash 242 * NAND Flash
425 ******************************************************************************/ 243 ******************************************************************************/
244#if defined(CONFIG_MTD_NAND_GPIO) || defined(CONFIG_MTD_NAND_GPIO_MODULE)
426static void palmtx_nand_cmd_ctl(struct mtd_info *mtd, int cmd, 245static void palmtx_nand_cmd_ctl(struct mtd_info *mtd, int cmd,
427 unsigned int ctrl) 246 unsigned int ctrl)
428{ 247{
@@ -482,36 +301,17 @@ static struct platform_device palmtx_nand = {
482 } 301 }
483}; 302};
484 303
485/****************************************************************************** 304static void __init palmtx_nand_init(void)
486 * Power management - standby
487 ******************************************************************************/
488static void __init palmtx_pm_init(void)
489{ 305{
490 static u32 resume[] = { 306 platform_device_register(&palmtx_nand);
491 0xe3a00101, /* mov r0, #0x40000000 */
492 0xe380060f, /* orr r0, r0, #0x00f00000 */
493 0xe590f008, /* ldr pc, [r0, #0x08] */
494 };
495
496 /* copy the bootloader */
497 memcpy(phys_to_virt(PALMTX_STR_BASE), resume, sizeof(resume));
498} 307}
308#else
309static inline void palmtx_nand_init(void) {}
310#endif
499 311
500/****************************************************************************** 312/******************************************************************************
501 * Machine init 313 * Machine init
502 ******************************************************************************/ 314 ******************************************************************************/
503static struct platform_device *devices[] __initdata = {
504#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
505 &palmtx_pxa_keys,
506#endif
507 &palmtx_backlight,
508 &power_supply,
509 &palmtx_asoc,
510 &palmtx_gpio_vbus,
511 &palmtx_flash,
512 &palmtx_nand,
513};
514
515static struct map_desc palmtx_io_desc[] __initdata = { 315static struct map_desc palmtx_io_desc[] __initdata = {
516{ 316{
517 .virtual = PALMTX_PCMCIA_VIRT, 317 .virtual = PALMTX_PCMCIA_VIRT,
@@ -537,34 +337,29 @@ static void __init palmtx_map_io(void)
537 iotable_init(palmtx_io_desc, ARRAY_SIZE(palmtx_io_desc)); 337 iotable_init(palmtx_io_desc, ARRAY_SIZE(palmtx_io_desc));
538} 338}
539 339
540/* setup udc GPIOs initial state */
541static void __init palmtx_udc_init(void)
542{
543 if (!gpio_request(GPIO_NR_PALMTX_USB_PULLUP, "UDC Vbus")) {
544 gpio_direction_output(GPIO_NR_PALMTX_USB_PULLUP, 1);
545 gpio_free(GPIO_NR_PALMTX_USB_PULLUP);
546 }
547}
548
549
550static void __init palmtx_init(void) 340static void __init palmtx_init(void)
551{ 341{
552 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmtx_pin_config)); 342 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmtx_pin_config));
553
554 pxa_set_ffuart_info(NULL); 343 pxa_set_ffuart_info(NULL);
555 pxa_set_btuart_info(NULL); 344 pxa_set_btuart_info(NULL);
556 pxa_set_stuart_info(NULL); 345 pxa_set_stuart_info(NULL);
557 346
558 palmtx_pm_init(); 347 palm27x_mmc_init(GPIO_NR_PALMTX_SD_DETECT_N, GPIO_NR_PALMTX_SD_READONLY,
559 set_pxa_fb_info(&palmtx_lcd_screen); 348 GPIO_NR_PALMTX_SD_POWER, 0);
560 pxa_set_mci_info(&palmtx_mci_platform_data); 349 palm27x_pm_init(PALMTX_STR_BASE);
561 palmtx_udc_init(); 350 palm27x_lcd_init(-1, &palm_320x480_lcd_mode);
562 pxa_set_ac97_info(&palmtx_ac97_pdata); 351 palm27x_udc_init(GPIO_NR_PALMTX_USB_DETECT_N,
563 pxa_set_ficp_info(&palmtx_ficp_platform_data); 352 GPIO_NR_PALMTX_USB_PULLUP, 1);
564 pxa_set_keypad_info(&palmtx_keypad_platform_data); 353 palm27x_irda_init(GPIO_NR_PALMTX_IR_DISABLE);
565 wm97xx_bat_set_pdata(&wm97xx_batt_pdata); 354 palm27x_ac97_init(PALMTX_BAT_MIN_VOLTAGE, PALMTX_BAT_MAX_VOLTAGE,
566 355 GPIO_NR_PALMTX_EARPHONE_DETECT, 95);
567 platform_add_devices(devices, ARRAY_SIZE(devices)); 356 palm27x_pwm_init(GPIO_NR_PALMTX_BL_POWER, GPIO_NR_PALMTX_LCD_POWER);
357 palm27x_power_init(GPIO_NR_PALMTX_POWER_DETECT, -1);
358 palm27x_pmic_init();
359 palmtx_kpc_init();
360 palmtx_keys_init();
361 palmtx_nor_init();
362 palmtx_nand_init();
568} 363}
569 364
570MACHINE_START(PALMTX, "Palm T|X") 365MACHINE_START(PALMTX, "Palm T|X")
diff --git a/arch/arm/mach-pxa/palmz72.c b/arch/arm/mach-pxa/palmz72.c
index 3a7925ca3944..87e4b1044e0b 100644
--- a/arch/arm/mach-pxa/palmz72.c
+++ b/arch/arm/mach-pxa/palmz72.c
@@ -27,7 +27,7 @@
27#include <linux/pda_power.h> 27#include <linux/pda_power.h>
28#include <linux/pwm_backlight.h> 28#include <linux/pwm_backlight.h>
29#include <linux/gpio.h> 29#include <linux/gpio.h>
30#include <linux/wm97xx_batt.h> 30#include <linux/wm97xx.h>
31#include <linux/power_supply.h> 31#include <linux/power_supply.h>
32#include <linux/usb/gpio_vbus.h> 32#include <linux/usb/gpio_vbus.h>
33 33
@@ -44,6 +44,7 @@
44#include <mach/pxa27x_keypad.h> 44#include <mach/pxa27x_keypad.h>
45#include <mach/udc.h> 45#include <mach/udc.h>
46#include <mach/palmasoc.h> 46#include <mach/palmasoc.h>
47#include <mach/palm27x.h>
47 48
48#include <mach/pm.h> 49#include <mach/pm.h>
49 50
@@ -109,21 +110,9 @@ static unsigned long palmz72_pin_config[] __initdata = {
109}; 110};
110 111
111/****************************************************************************** 112/******************************************************************************
112 * SD/MMC card controller
113 ******************************************************************************/
114/* SD_POWER is not actually power, but it is more like chip
115 * select, i.e. it is inverted */
116static struct pxamci_platform_data palmz72_mci_platform_data = {
117 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
118 .gpio_card_detect = GPIO_NR_PALMZ72_SD_DETECT_N,
119 .gpio_card_ro = GPIO_NR_PALMZ72_SD_RO,
120 .gpio_power = GPIO_NR_PALMZ72_SD_POWER_N,
121 .gpio_power_invert = 1,
122};
123
124/******************************************************************************
125 * GPIO keyboard 113 * GPIO keyboard
126 ******************************************************************************/ 114 ******************************************************************************/
115#if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
127static unsigned int palmz72_matrix_keys[] = { 116static unsigned int palmz72_matrix_keys[] = {
128 KEY(0, 0, KEY_POWER), 117 KEY(0, 0, KEY_POWER),
129 KEY(0, 1, KEY_F1), 118 KEY(0, 1, KEY_F1),
@@ -149,77 +138,18 @@ static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data = {
149 .debounce_interval = 30, 138 .debounce_interval = 30,
150}; 139};
151 140
152/****************************************************************************** 141static void __init palmz72_kpc_init(void)
153 * Backlight
154 ******************************************************************************/
155static int palmz72_backlight_init(struct device *dev)
156{ 142{
157 int ret; 143 pxa_set_keypad_info(&palmz72_keypad_platform_data);
158
159 ret = gpio_request(GPIO_NR_PALMZ72_BL_POWER, "BL POWER");
160 if (ret)
161 goto err;
162 ret = gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER, 0);
163 if (ret)
164 goto err2;
165 ret = gpio_request(GPIO_NR_PALMZ72_LCD_POWER, "LCD POWER");
166 if (ret)
167 goto err2;
168 ret = gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER, 0);
169 if (ret)
170 goto err3;
171
172 return 0;
173err3:
174 gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
175err2:
176 gpio_free(GPIO_NR_PALMZ72_BL_POWER);
177err:
178 return ret;
179}
180
181static int palmz72_backlight_notify(struct device *dev, int brightness)
182{
183 gpio_set_value(GPIO_NR_PALMZ72_BL_POWER, brightness);
184 gpio_set_value(GPIO_NR_PALMZ72_LCD_POWER, brightness);
185 return brightness;
186}
187
188static void palmz72_backlight_exit(struct device *dev)
189{
190 gpio_free(GPIO_NR_PALMZ72_BL_POWER);
191 gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
192} 144}
193 145#else
194static struct platform_pwm_backlight_data palmz72_backlight_data = { 146static inline void palmz72_kpc_init(void) {}
195 .pwm_id = 0, 147#endif
196 .max_brightness = PALMZ72_MAX_INTENSITY,
197 .dft_brightness = PALMZ72_MAX_INTENSITY,
198 .pwm_period_ns = PALMZ72_PERIOD_NS,
199 .init = palmz72_backlight_init,
200 .notify = palmz72_backlight_notify,
201 .exit = palmz72_backlight_exit,
202};
203
204static struct platform_device palmz72_backlight = {
205 .name = "pwm-backlight",
206 .dev = {
207 .parent = &pxa27x_device_pwm0.dev,
208 .platform_data = &palmz72_backlight_data,
209 },
210};
211
212/******************************************************************************
213 * IrDA
214 ******************************************************************************/
215static struct pxaficp_platform_data palmz72_ficp_platform_data = {
216 .gpio_pwdown = GPIO_NR_PALMZ72_IR_DISABLE,
217 .transceiver_cap = IR_SIRMODE | IR_OFF,
218};
219 148
220/****************************************************************************** 149/******************************************************************************
221 * LEDs 150 * LEDs
222 ******************************************************************************/ 151 ******************************************************************************/
152#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
223static struct gpio_led gpio_leds[] = { 153static struct gpio_led gpio_leds[] = {
224 { 154 {
225 .name = "palmz72:green:led", 155 .name = "palmz72:green:led",
@@ -241,139 +171,13 @@ static struct platform_device palmz72_leds = {
241 } 171 }
242}; 172};
243 173
244/****************************************************************************** 174static void __init palmz72_leds_init(void)
245 * UDC
246 ******************************************************************************/
247static struct gpio_vbus_mach_info palmz72_udc_info = {
248 .gpio_vbus = GPIO_NR_PALMZ72_USB_DETECT_N,
249 .gpio_pullup = GPIO_NR_PALMZ72_USB_PULLUP,
250};
251
252static struct platform_device palmz72_gpio_vbus = {
253 .name = "gpio-vbus",
254 .id = -1,
255 .dev = {
256 .platform_data = &palmz72_udc_info,
257 },
258};
259
260/******************************************************************************
261 * Power supply
262 ******************************************************************************/
263static int power_supply_init(struct device *dev)
264{
265 int ret;
266
267 ret = gpio_request(GPIO_NR_PALMZ72_POWER_DETECT, "CABLE_STATE_AC");
268 if (ret)
269 goto err1;
270 ret = gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT);
271 if (ret)
272 goto err2;
273
274 ret = gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N, "CABLE_STATE_USB");
275 if (ret)
276 goto err2;
277 ret = gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N);
278 if (ret)
279 goto err3;
280
281 return 0;
282err3:
283 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
284err2:
285 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
286err1:
287 return ret;
288}
289
290static int palmz72_is_ac_online(void)
291{
292 return gpio_get_value(GPIO_NR_PALMZ72_POWER_DETECT);
293}
294
295static int palmz72_is_usb_online(void)
296{ 175{
297 return !gpio_get_value(GPIO_NR_PALMZ72_USB_DETECT_N); 176 platform_device_register(&palmz72_leds);
298} 177}
299 178#else
300static void power_supply_exit(struct device *dev) 179static inline void palmz72_leds_init(void) {}
301{ 180#endif
302 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
303 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
304}
305
306static char *palmz72_supplicants[] = {
307 "main-battery",
308};
309
310static struct pda_power_pdata power_supply_info = {
311 .init = power_supply_init,
312 .is_ac_online = palmz72_is_ac_online,
313 .is_usb_online = palmz72_is_usb_online,
314 .exit = power_supply_exit,
315 .supplied_to = palmz72_supplicants,
316 .num_supplicants = ARRAY_SIZE(palmz72_supplicants),
317};
318
319static struct platform_device power_supply = {
320 .name = "pda-power",
321 .id = -1,
322 .dev = {
323 .platform_data = &power_supply_info,
324 },
325};
326
327/******************************************************************************
328 * WM97xx battery
329 ******************************************************************************/
330static struct wm97xx_batt_info wm97xx_batt_pdata = {
331 .batt_aux = WM97XX_AUX_ID3,
332 .temp_aux = WM97XX_AUX_ID2,
333 .charge_gpio = -1,
334 .max_voltage = PALMZ72_BAT_MAX_VOLTAGE,
335 .min_voltage = PALMZ72_BAT_MIN_VOLTAGE,
336 .batt_mult = 1000,
337 .batt_div = 414,
338 .temp_mult = 1,
339 .temp_div = 1,
340 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
341 .batt_name = "main-batt",
342};
343
344/******************************************************************************
345 * aSoC audio
346 ******************************************************************************/
347static struct platform_device palmz72_asoc = {
348 .name = "palm27x-asoc",
349 .id = -1,
350};
351
352/******************************************************************************
353 * Framebuffer
354 ******************************************************************************/
355static struct pxafb_mode_info palmz72_lcd_modes[] = {
356{
357 .pixclock = 115384,
358 .xres = 320,
359 .yres = 320,
360 .bpp = 16,
361
362 .left_margin = 27,
363 .right_margin = 7,
364 .upper_margin = 7,
365 .lower_margin = 8,
366
367 .hsync_len = 6,
368 .vsync_len = 1,
369},
370};
371
372static struct pxafb_mach_info palmz72_lcd_screen = {
373 .modes = palmz72_lcd_modes,
374 .num_modes = ARRAY_SIZE(palmz72_lcd_modes),
375 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
376};
377 181
378#ifdef CONFIG_PM 182#ifdef CONFIG_PM
379 183
@@ -452,40 +256,26 @@ device_initcall(palmz72_pm_init);
452/****************************************************************************** 256/******************************************************************************
453 * Machine init 257 * Machine init
454 ******************************************************************************/ 258 ******************************************************************************/
455static struct platform_device *devices[] __initdata = {
456 &palmz72_backlight,
457 &palmz72_leds,
458 &palmz72_asoc,
459 &power_supply,
460 &palmz72_gpio_vbus,
461};
462
463/* setup udc GPIOs initial state */
464static void __init palmz72_udc_init(void)
465{
466 if (!gpio_request(GPIO_NR_PALMZ72_USB_PULLUP, "USB Pullup")) {
467 gpio_direction_output(GPIO_NR_PALMZ72_USB_PULLUP, 0);
468 gpio_free(GPIO_NR_PALMZ72_USB_PULLUP);
469 }
470}
471
472static void __init palmz72_init(void) 259static void __init palmz72_init(void)
473{ 260{
474 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config)); 261 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
475
476 pxa_set_ffuart_info(NULL); 262 pxa_set_ffuart_info(NULL);
477 pxa_set_btuart_info(NULL); 263 pxa_set_btuart_info(NULL);
478 pxa_set_stuart_info(NULL); 264 pxa_set_stuart_info(NULL);
479 265
480 set_pxa_fb_info(&palmz72_lcd_screen); 266 palm27x_mmc_init(GPIO_NR_PALMZ72_SD_DETECT_N, GPIO_NR_PALMZ72_SD_RO,
481 pxa_set_mci_info(&palmz72_mci_platform_data); 267 GPIO_NR_PALMZ72_SD_POWER_N, 1);
482 palmz72_udc_init(); 268 palm27x_lcd_init(-1, &palm_320x320_lcd_mode);
483 pxa_set_ac97_info(NULL); 269 palm27x_udc_init(GPIO_NR_PALMZ72_USB_DETECT_N,
484 pxa_set_ficp_info(&palmz72_ficp_platform_data); 270 GPIO_NR_PALMZ72_USB_PULLUP, 0);
485 pxa_set_keypad_info(&palmz72_keypad_platform_data); 271 palm27x_irda_init(GPIO_NR_PALMZ72_IR_DISABLE);
486 wm97xx_bat_set_pdata(&wm97xx_batt_pdata); 272 palm27x_ac97_init(PALMZ72_BAT_MIN_VOLTAGE, PALMZ72_BAT_MAX_VOLTAGE,
487 273 -1, 113);
488 platform_add_devices(devices, ARRAY_SIZE(devices)); 274 palm27x_pwm_init(-1, -1);
275 palm27x_power_init(-1, -1);
276 palm27x_pmic_init();
277 palmz72_kpc_init();
278 palmz72_leds_init();
489} 279}
490 280
491MACHINE_START(PALMZ72, "Palm Zire72") 281MACHINE_START(PALMZ72, "Palm Zire72")
diff --git a/arch/arm/mach-pxa/poodle.c b/arch/arm/mach-pxa/poodle.c
index bc2758b54446..55e8fcde0141 100644
--- a/arch/arm/mach-pxa/poodle.c
+++ b/arch/arm/mach-pxa/poodle.c
@@ -43,7 +43,6 @@
43#include <mach/irda.h> 43#include <mach/irda.h>
44#include <mach/poodle.h> 44#include <mach/poodle.h>
45#include <mach/pxafb.h> 45#include <mach/pxafb.h>
46#include <mach/sharpsl.h>
47#include <mach/pxa2xx_spi.h> 46#include <mach/pxa2xx_spi.h>
48#include <plat/i2c.h> 47#include <plat/i2c.h>
49 48
@@ -53,7 +52,6 @@
53 52
54#include "generic.h" 53#include "generic.h"
55#include "devices.h" 54#include "devices.h"
56#include "sharpsl.h"
57 55
58static unsigned long poodle_pin_config[] __initdata = { 56static unsigned long poodle_pin_config[] __initdata = {
59 /* I/O */ 57 /* I/O */
diff --git a/arch/arm/mach-pxa/pxa25x.c b/arch/arm/mach-pxa/pxa25x.c
index 0b9ad30bfd51..de53f2e4aa39 100644
--- a/arch/arm/mach-pxa/pxa25x.c
+++ b/arch/arm/mach-pxa/pxa25x.c
@@ -322,6 +322,7 @@ void __init pxa26x_init_irq(void)
322 322
323static struct platform_device *pxa25x_devices[] __initdata = { 323static struct platform_device *pxa25x_devices[] __initdata = {
324 &pxa25x_device_udc, 324 &pxa25x_device_udc,
325 &pxa_device_pmu,
325 &pxa_device_i2s, 326 &pxa_device_i2s,
326 &sa1100_device_rtc, 327 &sa1100_device_rtc,
327 &pxa25x_device_ssp, 328 &pxa25x_device_ssp,
diff --git a/arch/arm/mach-pxa/pxa27x.c b/arch/arm/mach-pxa/pxa27x.c
index c059dac02b61..12e5b9f01e6f 100644
--- a/arch/arm/mach-pxa/pxa27x.c
+++ b/arch/arm/mach-pxa/pxa27x.c
@@ -383,6 +383,7 @@ void __init pxa27x_set_i2c_power_info(struct i2c_pxa_platform_data *info)
383 383
384static struct platform_device *devices[] __initdata = { 384static struct platform_device *devices[] __initdata = {
385 &pxa27x_device_udc, 385 &pxa27x_device_udc,
386 &pxa_device_pmu,
386 &pxa_device_i2s, 387 &pxa_device_i2s,
387 &sa1100_device_rtc, 388 &sa1100_device_rtc,
388 &pxa_device_rtc, 389 &pxa_device_rtc,
diff --git a/arch/arm/mach-pxa/pxa3xx.c b/arch/arm/mach-pxa/pxa3xx.c
index f544e58e1536..fa0014847c71 100644
--- a/arch/arm/mach-pxa/pxa3xx.c
+++ b/arch/arm/mach-pxa/pxa3xx.c
@@ -52,7 +52,7 @@
52static unsigned char smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, }; 52static unsigned char smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, };
53 53
54/* crystal frequency to HSIO bus frequency multiplier (HSS) */ 54/* crystal frequency to HSIO bus frequency multiplier (HSS) */
55static unsigned char hss_mult[4] = { 8, 12, 16, 0 }; 55static unsigned char hss_mult[4] = { 8, 12, 16, 24 };
56 56
57/* 57/*
58 * Get the clock frequency as reflected by CCSR and the turbo flag. 58 * Get the clock frequency as reflected by CCSR and the turbo flag.
@@ -552,11 +552,23 @@ static void pxa_unmask_ext_wakeup(unsigned int irq)
552 PECR |= PECR_IE(irq - IRQ_WAKEUP0); 552 PECR |= PECR_IE(irq - IRQ_WAKEUP0);
553} 553}
554 554
555static int pxa_set_ext_wakeup_type(unsigned int irq, unsigned int flow_type)
556{
557 if (flow_type & IRQ_TYPE_EDGE_RISING)
558 PWER |= 1 << (irq - IRQ_WAKEUP0);
559
560 if (flow_type & IRQ_TYPE_EDGE_FALLING)
561 PWER |= 1 << (irq - IRQ_WAKEUP0 + 2);
562
563 return 0;
564}
565
555static struct irq_chip pxa_ext_wakeup_chip = { 566static struct irq_chip pxa_ext_wakeup_chip = {
556 .name = "WAKEUP", 567 .name = "WAKEUP",
557 .ack = pxa_ack_ext_wakeup, 568 .ack = pxa_ack_ext_wakeup,
558 .mask = pxa_mask_ext_wakeup, 569 .mask = pxa_mask_ext_wakeup,
559 .unmask = pxa_unmask_ext_wakeup, 570 .unmask = pxa_unmask_ext_wakeup,
571 .set_type = pxa_set_ext_wakeup_type,
560}; 572};
561 573
562static void __init pxa_init_ext_wakeup_irq(set_wake_t fn) 574static void __init pxa_init_ext_wakeup_irq(set_wake_t fn)
@@ -596,6 +608,7 @@ void __init pxa3xx_set_i2c_power_info(struct i2c_pxa_platform_data *info)
596 608
597static struct platform_device *devices[] __initdata = { 609static struct platform_device *devices[] __initdata = {
598 &pxa27x_device_udc, 610 &pxa27x_device_udc,
611 &pxa_device_pmu,
599 &pxa_device_i2s, 612 &pxa_device_i2s,
600 &sa1100_device_rtc, 613 &sa1100_device_rtc,
601 &pxa_device_rtc, 614 &pxa_device_rtc,
diff --git a/arch/arm/mach-pxa/raumfeld.c b/arch/arm/mach-pxa/raumfeld.c
index d4b61b3f08f3..67e04f4e07c1 100644
--- a/arch/arm/mach-pxa/raumfeld.c
+++ b/arch/arm/mach-pxa/raumfeld.c
@@ -745,13 +745,32 @@ static int raumfeld_is_usb_online(void)
745 745
746static char *raumfeld_power_supplicants[] = { "ds2760-battery.0" }; 746static char *raumfeld_power_supplicants[] = { "ds2760-battery.0" };
747 747
748static void raumfeld_power_signal_charged(void)
749{
750 struct power_supply *psy =
751 power_supply_get_by_name(raumfeld_power_supplicants[0]);
752
753 if (psy)
754 power_supply_set_battery_charged(psy);
755}
756
757static int raumfeld_power_resume(void)
758{
759 /* check if GPIO_CHARGE_DONE went low while we were sleeping */
760 if (!gpio_get_value(GPIO_CHARGE_DONE))
761 raumfeld_power_signal_charged();
762
763 return 0;
764}
765
748static struct pda_power_pdata power_supply_info = { 766static struct pda_power_pdata power_supply_info = {
749 .init = power_supply_init, 767 .init = power_supply_init,
750 .is_ac_online = raumfeld_is_ac_online, 768 .is_ac_online = raumfeld_is_ac_online,
751 .is_usb_online = raumfeld_is_usb_online, 769 .is_usb_online = raumfeld_is_usb_online,
752 .exit = power_supply_exit, 770 .exit = power_supply_exit,
753 .supplied_to = raumfeld_power_supplicants, 771 .supplied_to = raumfeld_power_supplicants,
754 .num_supplicants = ARRAY_SIZE(raumfeld_power_supplicants) 772 .num_supplicants = ARRAY_SIZE(raumfeld_power_supplicants),
773 .resume = raumfeld_power_resume,
755}; 774};
756 775
757static struct resource power_supply_resources[] = { 776static struct resource power_supply_resources[] = {
@@ -766,13 +785,7 @@ static struct resource power_supply_resources[] = {
766 785
767static irqreturn_t charge_done_irq(int irq, void *dev_id) 786static irqreturn_t charge_done_irq(int irq, void *dev_id)
768{ 787{
769 struct power_supply *psy; 788 raumfeld_power_signal_charged();
770
771 psy = power_supply_get_by_name("ds2760-battery.0");
772
773 if (psy)
774 power_supply_set_battery_charged(psy);
775
776 return IRQ_HANDLED; 789 return IRQ_HANDLED;
777} 790}
778 791
diff --git a/arch/arm/mach-pxa/sharpsl.h b/arch/arm/mach-pxa/sharpsl.h
deleted file mode 100644
index 0cc1203c5bef..000000000000
--- a/arch/arm/mach-pxa/sharpsl.h
+++ /dev/null
@@ -1,26 +0,0 @@
1/*
2 * Copyright (c) 2004-2005 Richard Purdie
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 */
9
10#include <mach/sharpsl_pm.h>
11
12/*
13 * SharpSL Battery/PM Driver
14 */
15#define READ_GPIO_BIT(x) (GPLR(x) & GPIO_bit(x))
16
17/* MAX1111 Channel Definitions */
18#define MAX1111_BATT_VOLT 4u
19#define MAX1111_BATT_TEMP 2u
20#define MAX1111_ACIN_VOLT 6u
21
22extern struct battery_thresh sharpsl_battery_levels_acin[];
23extern struct battery_thresh sharpsl_battery_levels_noac[];
24int sharpsl_pm_pxa_read_max1111(int channel);
25
26
diff --git a/arch/arm/mach-pxa/sharpsl_pm.c b/arch/arm/mach-pxa/sharpsl_pm.c
index cb4767251f3c..8fed027b12dc 100644
--- a/arch/arm/mach-pxa/sharpsl_pm.c
+++ b/arch/arm/mach-pxa/sharpsl_pm.c
@@ -29,11 +29,8 @@
29#include <mach/pm.h> 29#include <mach/pm.h>
30#include <mach/pxa2xx-regs.h> 30#include <mach/pxa2xx-regs.h>
31#include <mach/regs-rtc.h> 31#include <mach/regs-rtc.h>
32#include <mach/sharpsl.h>
33#include <mach/sharpsl_pm.h> 32#include <mach/sharpsl_pm.h>
34 33
35#include "sharpsl.h"
36
37/* 34/*
38 * Constants 35 * Constants
39 */ 36 */
@@ -180,17 +177,12 @@ int sharpsl_pm_pxa_read_max1111(int channel)
180 if (machine_is_tosa()) 177 if (machine_is_tosa())
181 return 0; 178 return 0;
182 179
183#ifdef CONFIG_CORGI_SSP_DEPRECATED
184 return corgi_ssp_max1111_get((channel << MAXCTRL_SEL_SH) | MAXCTRL_PD0 | MAXCTRL_PD1
185 | MAXCTRL_SGL | MAXCTRL_UNI | MAXCTRL_STR);
186#else
187 extern int max1111_read_channel(int); 180 extern int max1111_read_channel(int);
188 181
189 /* max1111 accepts channels from 0-3, however, 182 /* max1111 accepts channels from 0-3, however,
190 * it is encoded from 0-7 here in the code. 183 * it is encoded from 0-7 here in the code.
191 */ 184 */
192 return max1111_read_channel(channel >> 1); 185 return max1111_read_channel(channel >> 1);
193#endif
194} 186}
195 187
196static int get_percentage(int voltage) 188static int get_percentage(int voltage)
@@ -277,21 +269,6 @@ static void sharpsl_battery_thread(struct work_struct *private_)
277 dev_dbg(sharpsl_pm.dev, "Battery: voltage: %d, status: %d, percentage: %d, time: %ld\n", voltage, 269 dev_dbg(sharpsl_pm.dev, "Battery: voltage: %d, status: %d, percentage: %d, time: %ld\n", voltage,
278 sharpsl_pm.battstat.mainbat_status, sharpsl_pm.battstat.mainbat_percent, jiffies); 270 sharpsl_pm.battstat.mainbat_status, sharpsl_pm.battstat.mainbat_percent, jiffies);
279 271
280#ifdef CONFIG_BACKLIGHT_CORGI
281 /* If battery is low. limit backlight intensity to save power. */
282 if ((sharpsl_pm.battstat.ac_status != APM_AC_ONLINE)
283 && ((sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_LOW)
284 || (sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_CRITICAL))) {
285 if (!(sharpsl_pm.flags & SHARPSL_BL_LIMIT)) {
286 sharpsl_pm.machinfo->backlight_limit(1);
287 sharpsl_pm.flags |= SHARPSL_BL_LIMIT;
288 }
289 } else if (sharpsl_pm.flags & SHARPSL_BL_LIMIT) {
290 sharpsl_pm.machinfo->backlight_limit(0);
291 sharpsl_pm.flags &= ~SHARPSL_BL_LIMIT;
292 }
293#endif
294
295 /* Suspend if critical battery level */ 272 /* Suspend if critical battery level */
296 if ((sharpsl_pm.battstat.ac_status != APM_AC_ONLINE) 273 if ((sharpsl_pm.battstat.ac_status != APM_AC_ONLINE)
297 && (sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_CRITICAL) 274 && (sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_CRITICAL)
diff --git a/arch/arm/mach-pxa/sleep.S b/arch/arm/mach-pxa/sleep.S
index 2ed95f369cfc..52c30b01a671 100644
--- a/arch/arm/mach-pxa/sleep.S
+++ b/arch/arm/mach-pxa/sleep.S
@@ -339,10 +339,6 @@ ENTRY(pxa_cpu_resume)
339 mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs 339 mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
340 mcr p15, 0, r1, c7, c7, 0 @ invalidate I & D caches, BTB 340 mcr p15, 0, r1, c7, c7, 0 @ invalidate I & D caches, BTB
341 341
342#ifdef CONFIG_XSCALE_CACHE_ERRATA
343 bic r9, r9, #0x0004 @ see cpu_xscale_proc_init
344#endif
345
346 mcr p14, 0, r3, c6, c0, 0 @ clock configuration, turbo mode. 342 mcr p14, 0, r3, c6, c0, 0 @ clock configuration, turbo mode.
347 mcr p15, 0, r4, c15, c1, 0 @ CP access reg 343 mcr p15, 0, r4, c15, c1, 0 @ CP access reg
348 mcr p15, 0, r5, c13, c0, 0 @ PID 344 mcr p15, 0, r5, c13, c0, 0 @ PID
@@ -368,9 +364,6 @@ sleep_save_sp:
368 364
369 .text 365 .text
370resume_after_mmu: 366resume_after_mmu:
371#ifdef CONFIG_XSCALE_CACHE_ERRATA
372 bl cpu_xscale_proc_init
373#endif
374 ldmfd sp!, {r2, r3} 367 ldmfd sp!, {r2, r3}
375#ifndef CONFIG_IWMMXT 368#ifndef CONFIG_IWMMXT
376 mar acc0, r2, r3 369 mar acc0, r2, r3
diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c
index 51756c723557..1cd99cb87bb1 100644
--- a/arch/arm/mach-pxa/spitz.c
+++ b/arch/arm/mach-pxa/spitz.c
@@ -18,14 +18,15 @@
18#include <linux/gpio_keys.h> 18#include <linux/gpio_keys.h>
19#include <linux/gpio.h> 19#include <linux/gpio.h>
20#include <linux/leds.h> 20#include <linux/leds.h>
21#include <linux/mtd/physmap.h>
22#include <linux/i2c.h> 21#include <linux/i2c.h>
23#include <linux/i2c/pca953x.h> 22#include <linux/i2c/pca953x.h>
24#include <linux/spi/spi.h> 23#include <linux/spi/spi.h>
25#include <linux/spi/ads7846.h> 24#include <linux/spi/ads7846.h>
26#include <linux/spi/corgi_lcd.h> 25#include <linux/spi/corgi_lcd.h>
26#include <linux/mtd/physmap.h>
27#include <linux/mtd/sharpsl.h> 27#include <linux/mtd/sharpsl.h>
28#include <linux/input/matrix_keypad.h> 28#include <linux/input/matrix_keypad.h>
29#include <linux/regulator/machine.h>
29 30
30#include <asm/setup.h> 31#include <asm/setup.h>
31#include <asm/mach-types.h> 32#include <asm/mach-types.h>
@@ -33,22 +34,25 @@
33#include <asm/mach/sharpsl_param.h> 34#include <asm/mach/sharpsl_param.h>
34#include <asm/hardware/scoop.h> 35#include <asm/hardware/scoop.h>
35 36
36
37#include <mach/pxa27x.h> 37#include <mach/pxa27x.h>
38#include <mach/pxa27x-udc.h> 38#include <mach/pxa27x-udc.h>
39#include <mach/reset.h> 39#include <mach/reset.h>
40#include <plat/i2c.h>
41#include <mach/irda.h> 40#include <mach/irda.h>
42#include <mach/mmc.h> 41#include <mach/mmc.h>
43#include <mach/ohci.h> 42#include <mach/ohci.h>
44#include <mach/pxafb.h> 43#include <mach/pxafb.h>
45#include <mach/pxa2xx_spi.h> 44#include <mach/pxa2xx_spi.h>
46#include <mach/spitz.h> 45#include <mach/spitz.h>
46#include <mach/sharpsl_pm.h>
47
48#include <plat/i2c.h>
47 49
48#include "generic.h" 50#include "generic.h"
49#include "devices.h" 51#include "devices.h"
50#include "sharpsl.h"
51 52
53/******************************************************************************
54 * Pin configuration
55 ******************************************************************************/
52static unsigned long spitz_pin_config[] __initdata = { 56static unsigned long spitz_pin_config[] __initdata = {
53 /* Chip Selects */ 57 /* Chip Selects */
54 GPIO78_nCS_2, /* SCOOP #2 */ 58 GPIO78_nCS_2, /* SCOOP #2 */
@@ -124,10 +128,13 @@ static unsigned long spitz_pin_config[] __initdata = {
124 GPIO1_GPIO | WAKEUP_ON_EDGE_FALL, /* SPITZ_GPIO_RESET */ 128 GPIO1_GPIO | WAKEUP_ON_EDGE_FALL, /* SPITZ_GPIO_RESET */
125}; 129};
126 130
127/* 131
128 * Spitz SCOOP Device #1 132/******************************************************************************
129 */ 133 * Scoop GPIO expander
130static struct resource spitz_scoop_resources[] = { 134 ******************************************************************************/
135#if defined(CONFIG_SHARP_SCOOP) || defined(CONFIG_SHARP_SCOOP_MODULE)
136/* SCOOP Device #1 */
137static struct resource spitz_scoop_1_resources[] = {
131 [0] = { 138 [0] = {
132 .start = 0x10800000, 139 .start = 0x10800000,
133 .end = 0x10800fff, 140 .end = 0x10800fff,
@@ -135,7 +142,7 @@ static struct resource spitz_scoop_resources[] = {
135 }, 142 },
136}; 143};
137 144
138static struct scoop_config spitz_scoop_setup = { 145static struct scoop_config spitz_scoop_1_setup = {
139 .io_dir = SPITZ_SCP_IO_DIR, 146 .io_dir = SPITZ_SCP_IO_DIR,
140 .io_out = SPITZ_SCP_IO_OUT, 147 .io_out = SPITZ_SCP_IO_OUT,
141 .suspend_clr = SPITZ_SCP_SUS_CLR, 148 .suspend_clr = SPITZ_SCP_SUS_CLR,
@@ -143,20 +150,18 @@ static struct scoop_config spitz_scoop_setup = {
143 .gpio_base = SPITZ_SCP_GPIO_BASE, 150 .gpio_base = SPITZ_SCP_GPIO_BASE,
144}; 151};
145 152
146struct platform_device spitzscoop_device = { 153struct platform_device spitz_scoop_1_device = {
147 .name = "sharp-scoop", 154 .name = "sharp-scoop",
148 .id = 0, 155 .id = 0,
149 .dev = { 156 .dev = {
150 .platform_data = &spitz_scoop_setup, 157 .platform_data = &spitz_scoop_1_setup,
151 }, 158 },
152 .num_resources = ARRAY_SIZE(spitz_scoop_resources), 159 .num_resources = ARRAY_SIZE(spitz_scoop_1_resources),
153 .resource = spitz_scoop_resources, 160 .resource = spitz_scoop_1_resources,
154}; 161};
155 162
156/* 163/* SCOOP Device #2 */
157 * Spitz SCOOP Device #2 164static struct resource spitz_scoop_2_resources[] = {
158 */
159static struct resource spitz_scoop2_resources[] = {
160 [0] = { 165 [0] = {
161 .start = 0x08800040, 166 .start = 0x08800040,
162 .end = 0x08800fff, 167 .end = 0x08800fff,
@@ -164,7 +169,7 @@ static struct resource spitz_scoop2_resources[] = {
164 }, 169 },
165}; 170};
166 171
167static struct scoop_config spitz_scoop2_setup = { 172static struct scoop_config spitz_scoop_2_setup = {
168 .io_dir = SPITZ_SCP2_IO_DIR, 173 .io_dir = SPITZ_SCP2_IO_DIR,
169 .io_out = SPITZ_SCP2_IO_OUT, 174 .io_out = SPITZ_SCP2_IO_OUT,
170 .suspend_clr = SPITZ_SCP2_SUS_CLR, 175 .suspend_clr = SPITZ_SCP2_SUS_CLR,
@@ -172,82 +177,110 @@ static struct scoop_config spitz_scoop2_setup = {
172 .gpio_base = SPITZ_SCP2_GPIO_BASE, 177 .gpio_base = SPITZ_SCP2_GPIO_BASE,
173}; 178};
174 179
175struct platform_device spitzscoop2_device = { 180struct platform_device spitz_scoop_2_device = {
176 .name = "sharp-scoop", 181 .name = "sharp-scoop",
177 .id = 1, 182 .id = 1,
178 .dev = { 183 .dev = {
179 .platform_data = &spitz_scoop2_setup, 184 .platform_data = &spitz_scoop_2_setup,
180 }, 185 },
181 .num_resources = ARRAY_SIZE(spitz_scoop2_resources), 186 .num_resources = ARRAY_SIZE(spitz_scoop_2_resources),
182 .resource = spitz_scoop2_resources, 187 .resource = spitz_scoop_2_resources,
183}; 188};
184 189
185#define SPITZ_PWR_SD 0x01 190static void __init spitz_scoop_init(void)
186#define SPITZ_PWR_CF 0x02 191{
192 platform_device_register(&spitz_scoop_1_device);
193
194 /* Akita doesn't have the second SCOOP chip */
195 if (!machine_is_akita())
196 platform_device_register(&spitz_scoop_2_device);
197}
187 198
188/* Power control is shared with between one of the CF slots and SD */ 199/* Power control is shared with between one of the CF slots and SD */
189static void spitz_card_pwr_ctrl(int device, unsigned short new_cpr) 200static void spitz_card_pwr_ctrl(uint8_t enable, uint8_t new_cpr)
190{ 201{
191 unsigned short cpr = read_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR); 202 unsigned short cpr;
203 unsigned long flags;
192 204
193 if (new_cpr & 0x0007) { 205 if (new_cpr & 0x7) {
194 gpio_set_value(SPITZ_GPIO_CF_POWER, 1); 206 gpio_set_value(SPITZ_GPIO_CF_POWER, 1);
195 if (!(cpr & 0x0002) && !(cpr & 0x0004)) 207 mdelay(5);
196 mdelay(5); 208 }
197 if (device == SPITZ_PWR_CF) 209
198 cpr |= 0x0002; 210 local_irq_save(flags);
199 if (device == SPITZ_PWR_SD) 211
200 cpr |= 0x0004; 212 cpr = read_scoop_reg(&spitz_scoop_1_device.dev, SCOOP_CPR);
201 write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, cpr | new_cpr); 213
202 } else { 214 if (enable & new_cpr)
203 if (device == SPITZ_PWR_CF) 215 cpr |= new_cpr;
204 cpr &= ~0x0002; 216 else
205 if (device == SPITZ_PWR_SD) 217 cpr &= ~enable;
206 cpr &= ~0x0004; 218
207 if (!(cpr & 0x0002) && !(cpr & 0x0004)) { 219 write_scoop_reg(&spitz_scoop_1_device.dev, SCOOP_CPR, cpr);
208 write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, 0x0000); 220
209 mdelay(1); 221 local_irq_restore(flags);
210 gpio_set_value(SPITZ_GPIO_CF_POWER, 0); 222
211 } else { 223 if (!(cpr & 0x7)) {
212 write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, cpr | new_cpr); 224 mdelay(1);
213 } 225 gpio_set_value(SPITZ_GPIO_CF_POWER, 0);
214 } 226 }
215} 227}
216 228
217static void spitz_pcmcia_pwr(struct device *scoop, unsigned short cpr, int nr) 229#else
230static inline void spitz_scoop_init(void) {}
231static inline void spitz_card_pwr_ctrl(uint8_t enable, uint8_t new_cpr) {}
232#endif
233
234/******************************************************************************
235 * PCMCIA
236 ******************************************************************************/
237#if defined(CONFIG_PCMCIA_PXA2XX) || defined(CONFIG_PCMCIA_PXA2XX_MODULE)
238static void spitz_pcmcia_pwr(struct device *scoop, uint16_t cpr, int nr)
218{ 239{
219 /* Only need to override behaviour for slot 0 */ 240 /* Only need to override behaviour for slot 0 */
220 if (nr == 0) 241 if (nr == 0)
221 spitz_card_pwr_ctrl(SPITZ_PWR_CF, cpr); 242 spitz_card_pwr_ctrl(
243 cpr & (SCOOP_CPR_CF_3V | SCOOP_CPR_CF_XV), cpr);
222 else 244 else
223 write_scoop_reg(scoop, SCOOP_CPR, cpr); 245 write_scoop_reg(scoop, SCOOP_CPR, cpr);
224} 246}
225 247
226static struct scoop_pcmcia_dev spitz_pcmcia_scoop[] = { 248static struct scoop_pcmcia_dev spitz_pcmcia_scoop[] = {
227{ 249 {
228 .dev = &spitzscoop_device.dev, 250 .dev = &spitz_scoop_1_device.dev,
229 .irq = SPITZ_IRQ_GPIO_CF_IRQ, 251 .irq = SPITZ_IRQ_GPIO_CF_IRQ,
230 .cd_irq = SPITZ_IRQ_GPIO_CF_CD, 252 .cd_irq = SPITZ_IRQ_GPIO_CF_CD,
231 .cd_irq_str = "PCMCIA0 CD", 253 .cd_irq_str = "PCMCIA0 CD",
232},{ 254 }, {
233 .dev = &spitzscoop2_device.dev, 255 .dev = &spitz_scoop_2_device.dev,
234 .irq = SPITZ_IRQ_GPIO_CF2_IRQ, 256 .irq = SPITZ_IRQ_GPIO_CF2_IRQ,
235 .cd_irq = -1, 257 .cd_irq = -1,
236}, 258 },
237}; 259};
238 260
239static struct scoop_pcmcia_config spitz_pcmcia_config = { 261static struct scoop_pcmcia_config spitz_pcmcia_config = {
240 .devs = &spitz_pcmcia_scoop[0], 262 .devs = &spitz_pcmcia_scoop[0],
241 .num_devs = 2, 263 .num_devs = 2,
242 .power_ctrl = spitz_pcmcia_pwr, 264 .power_ctrl = spitz_pcmcia_pwr,
243}; 265};
244 266
245EXPORT_SYMBOL(spitzscoop_device); 267static void __init spitz_pcmcia_init(void)
246EXPORT_SYMBOL(spitzscoop2_device); 268{
269 /* Akita has only one PCMCIA slot used */
270 if (machine_is_akita())
271 spitz_pcmcia_config.num_devs = 1;
272
273 platform_scoop_config = &spitz_pcmcia_config;
274}
275#else
276static inline void spitz_pcmcia_init(void) {}
277#endif
278
279/******************************************************************************
280 * GPIO keyboard
281 ******************************************************************************/
282#if defined(CONFIG_KEYBOARD_MATRIX) || defined(CONFIG_KEYBOARD_MATRIX_MODULE)
247 283
248/*
249 * Spitz Keyboard Device
250 */
251#define SPITZ_KEY_CALENDAR KEY_F1 284#define SPITZ_KEY_CALENDAR KEY_F1
252#define SPITZ_KEY_ADDRESS KEY_F2 285#define SPITZ_KEY_ADDRESS KEY_F2
253#define SPITZ_KEY_FN KEY_F3 286#define SPITZ_KEY_FN KEY_F3
@@ -263,7 +296,7 @@ EXPORT_SYMBOL(spitzscoop2_device);
263#define SPITZ_KEY_OK KEY_F11 296#define SPITZ_KEY_OK KEY_F11
264#define SPITZ_KEY_MENU KEY_F12 297#define SPITZ_KEY_MENU KEY_F12
265 298
266static const uint32_t spitzkbd_keymap[] = { 299static const uint32_t spitz_keymap[] = {
267 KEY(0, 0, KEY_LEFTCTRL), 300 KEY(0, 0, KEY_LEFTCTRL),
268 KEY(0, 1, KEY_1), 301 KEY(0, 1, KEY_1),
269 KEY(0, 2, KEY_3), 302 KEY(0, 2, KEY_3),
@@ -330,36 +363,47 @@ static const uint32_t spitzkbd_keymap[] = {
330 KEY(6, 8, KEY_RIGHT), 363 KEY(6, 8, KEY_RIGHT),
331}; 364};
332 365
333static const struct matrix_keymap_data spitzkbd_keymap_data = { 366static const struct matrix_keymap_data spitz_keymap_data = {
334 .keymap = spitzkbd_keymap, 367 .keymap = spitz_keymap,
335 .keymap_size = ARRAY_SIZE(spitzkbd_keymap), 368 .keymap_size = ARRAY_SIZE(spitz_keymap),
336}; 369};
337 370
338static const uint32_t spitzkbd_row_gpios[] = 371static const uint32_t spitz_row_gpios[] =
339 { 12, 17, 91, 34, 36, 38, 39 }; 372 { 12, 17, 91, 34, 36, 38, 39 };
340static const uint32_t spitzkbd_col_gpios[] = 373static const uint32_t spitz_col_gpios[] =
341 { 88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114 }; 374 { 88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114 };
342 375
343static struct matrix_keypad_platform_data spitzkbd_pdata = { 376static struct matrix_keypad_platform_data spitz_mkp_pdata = {
344 .keymap_data = &spitzkbd_keymap_data, 377 .keymap_data = &spitz_keymap_data,
345 .row_gpios = spitzkbd_row_gpios, 378 .row_gpios = spitz_row_gpios,
346 .col_gpios = spitzkbd_col_gpios, 379 .col_gpios = spitz_col_gpios,
347 .num_row_gpios = ARRAY_SIZE(spitzkbd_row_gpios), 380 .num_row_gpios = ARRAY_SIZE(spitz_row_gpios),
348 .num_col_gpios = ARRAY_SIZE(spitzkbd_col_gpios), 381 .num_col_gpios = ARRAY_SIZE(spitz_col_gpios),
349 .col_scan_delay_us = 10, 382 .col_scan_delay_us = 10,
350 .debounce_ms = 10, 383 .debounce_ms = 10,
351 .wakeup = 1, 384 .wakeup = 1,
352}; 385};
353 386
354static struct platform_device spitzkbd_device = { 387static struct platform_device spitz_mkp_device = {
355 .name = "matrix-keypad", 388 .name = "matrix-keypad",
356 .id = -1, 389 .id = -1,
357 .dev = { 390 .dev = {
358 .platform_data = &spitzkbd_pdata, 391 .platform_data = &spitz_mkp_pdata,
359 }, 392 },
360}; 393};
361 394
395static void __init spitz_mkp_init(void)
396{
397 platform_device_register(&spitz_mkp_device);
398}
399#else
400static inline void spitz_mkp_init(void) {}
401#endif
362 402
403/******************************************************************************
404 * GPIO keys
405 ******************************************************************************/
406#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
363static struct gpio_keys_button spitz_gpio_keys[] = { 407static struct gpio_keys_button spitz_gpio_keys[] = {
364 { 408 {
365 .type = EV_PWR, 409 .type = EV_PWR,
@@ -396,10 +440,18 @@ static struct platform_device spitz_gpio_keys_device = {
396 }, 440 },
397}; 441};
398 442
443static void __init spitz_keys_init(void)
444{
445 platform_device_register(&spitz_gpio_keys_device);
446}
447#else
448static inline void spitz_keys_init(void) {}
449#endif
399 450
400/* 451/******************************************************************************
401 * Spitz LEDs 452 * LEDs
402 */ 453 ******************************************************************************/
454#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
403static struct gpio_led spitz_gpio_leds[] = { 455static struct gpio_led spitz_gpio_leds[] = {
404 { 456 {
405 .name = "spitz:amber:charge", 457 .name = "spitz:amber:charge",
@@ -418,20 +470,27 @@ static struct gpio_led_platform_data spitz_gpio_leds_info = {
418 .num_leds = ARRAY_SIZE(spitz_gpio_leds), 470 .num_leds = ARRAY_SIZE(spitz_gpio_leds),
419}; 471};
420 472
421static struct platform_device spitzled_device = { 473static struct platform_device spitz_led_device = {
422 .name = "leds-gpio", 474 .name = "leds-gpio",
423 .id = -1, 475 .id = -1,
424 .dev = { 476 .dev = {
425 .platform_data = &spitz_gpio_leds_info, 477 .platform_data = &spitz_gpio_leds_info,
426 }, 478 },
427}; 479};
428 480
429#if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE) 481static void __init spitz_leds_init(void)
430static struct pxa2xx_spi_master spitz_spi_info = { 482{
431 .num_chipselect = 3, 483 platform_device_register(&spitz_led_device);
432}; 484}
485#else
486static inline void spitz_leds_init(void) {}
487#endif
433 488
434static void spitz_wait_for_hsync(void) 489/******************************************************************************
490 * SSP Devices
491 ******************************************************************************/
492#if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
493static void spitz_ads7846_wait_for_hsync(void)
435{ 494{
436 while (gpio_get_value(SPITZ_GPIO_HSYNC)) 495 while (gpio_get_value(SPITZ_GPIO_HSYNC))
437 cpu_relax(); 496 cpu_relax();
@@ -447,7 +506,7 @@ static struct ads7846_platform_data spitz_ads7846_info = {
447 .y_plate_ohms = 486, 506 .y_plate_ohms = 486,
448 .pressure_max = 1024, 507 .pressure_max = 1024,
449 .gpio_pendown = SPITZ_GPIO_TP_INT, 508 .gpio_pendown = SPITZ_GPIO_TP_INT,
450 .wait_for_sync = spitz_wait_for_hsync, 509 .wait_for_sync = spitz_ads7846_wait_for_hsync,
451}; 510};
452 511
453static struct pxa2xx_spi_chip spitz_ads7846_chip = { 512static struct pxa2xx_spi_chip spitz_ads7846_chip = {
@@ -485,72 +544,88 @@ static struct pxa2xx_spi_chip spitz_max1111_chip = {
485 544
486static struct spi_board_info spitz_spi_devices[] = { 545static struct spi_board_info spitz_spi_devices[] = {
487 { 546 {
488 .modalias = "ads7846", 547 .modalias = "ads7846",
489 .max_speed_hz = 1200000, 548 .max_speed_hz = 1200000,
490 .bus_num = 2, 549 .bus_num = 2,
491 .chip_select = 0, 550 .chip_select = 0,
492 .platform_data = &spitz_ads7846_info, 551 .platform_data = &spitz_ads7846_info,
493 .controller_data= &spitz_ads7846_chip, 552 .controller_data = &spitz_ads7846_chip,
494 .irq = gpio_to_irq(SPITZ_GPIO_TP_INT), 553 .irq = gpio_to_irq(SPITZ_GPIO_TP_INT),
495 }, { 554 }, {
496 .modalias = "corgi-lcd", 555 .modalias = "corgi-lcd",
497 .max_speed_hz = 50000, 556 .max_speed_hz = 50000,
498 .bus_num = 2, 557 .bus_num = 2,
499 .chip_select = 1, 558 .chip_select = 1,
500 .platform_data = &spitz_lcdcon_info, 559 .platform_data = &spitz_lcdcon_info,
501 .controller_data= &spitz_lcdcon_chip, 560 .controller_data = &spitz_lcdcon_chip,
502 }, { 561 }, {
503 .modalias = "max1111", 562 .modalias = "max1111",
504 .max_speed_hz = 450000, 563 .max_speed_hz = 450000,
505 .bus_num = 2, 564 .bus_num = 2,
506 .chip_select = 2, 565 .chip_select = 2,
507 .controller_data= &spitz_max1111_chip, 566 .controller_data = &spitz_max1111_chip,
508 }, 567 },
509}; 568};
510 569
511static void __init spitz_init_spi(void) 570static struct pxa2xx_spi_master spitz_spi_info = {
571 .num_chipselect = 3,
572};
573
574static void __init spitz_spi_init(void)
512{ 575{
576 struct corgi_lcd_platform_data *lcd_data = &spitz_lcdcon_info;
577
513 if (machine_is_akita()) { 578 if (machine_is_akita()) {
514 spitz_lcdcon_info.gpio_backlight_cont = AKITA_GPIO_BACKLIGHT_CONT; 579 lcd_data->gpio_backlight_cont = AKITA_GPIO_BACKLIGHT_CONT;
515 spitz_lcdcon_info.gpio_backlight_on = AKITA_GPIO_BACKLIGHT_ON; 580 lcd_data->gpio_backlight_on = AKITA_GPIO_BACKLIGHT_ON;
516 } 581 }
517 582
518 pxa2xx_set_spi_info(2, &spitz_spi_info); 583 pxa2xx_set_spi_info(2, &spitz_spi_info);
519 spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices)); 584 spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices));
520} 585}
521#else 586#else
522static inline void spitz_init_spi(void) {} 587static inline void spitz_spi_init(void) {}
523#endif 588#endif
524 589
590/******************************************************************************
591 * SD/MMC card controller
592 ******************************************************************************/
593#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
525/* 594/*
526 * MMC/SD Device 595 * NOTE: The card detect interrupt isn't debounced so we delay it by 250ms to
527 * 596 * give the card a chance to fully insert/eject.
528 * The card detect interrupt isn't debounced so we delay it by 250ms
529 * to give the card a chance to fully insert/eject.
530 */ 597 */
531static void spitz_mci_setpower(struct device *dev, unsigned int vdd) 598static void spitz_mci_setpower(struct device *dev, unsigned int vdd)
532{ 599{
533 struct pxamci_platform_data* p_d = dev->platform_data; 600 struct pxamci_platform_data* p_d = dev->platform_data;
534 601
535 if (( 1 << vdd) & p_d->ocr_mask) 602 if ((1 << vdd) & p_d->ocr_mask)
536 spitz_card_pwr_ctrl(SPITZ_PWR_SD, 0x0004); 603 spitz_card_pwr_ctrl(SCOOP_CPR_SD_3V, SCOOP_CPR_SD_3V);
537 else 604 else
538 spitz_card_pwr_ctrl(SPITZ_PWR_SD, 0x0000); 605 spitz_card_pwr_ctrl(SCOOP_CPR_SD_3V, 0x0);
539} 606}
540 607
541static struct pxamci_platform_data spitz_mci_platform_data = { 608static struct pxamci_platform_data spitz_mci_platform_data = {
542 .detect_delay_ms = 250, 609 .detect_delay_ms = 250,
543 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34, 610 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
544 .setpower = spitz_mci_setpower, 611 .setpower = spitz_mci_setpower,
545 .gpio_card_detect = SPITZ_GPIO_nSD_DETECT, 612 .gpio_card_detect = SPITZ_GPIO_nSD_DETECT,
546 .gpio_card_ro = SPITZ_GPIO_nSD_WP, 613 .gpio_card_ro = SPITZ_GPIO_nSD_WP,
547 .gpio_power = -1, 614 .gpio_power = -1,
548}; 615};
549 616
617static void __init spitz_mmc_init(void)
618{
619 pxa_set_mci_info(&spitz_mci_platform_data);
620}
621#else
622static inline void spitz_mmc_init(void) {}
623#endif
550 624
551/* 625/******************************************************************************
552 * USB Host (OHCI) 626 * USB Host
553 */ 627 ******************************************************************************/
628#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
554static int spitz_ohci_init(struct device *dev) 629static int spitz_ohci_init(struct device *dev)
555{ 630{
556 int err; 631 int err;
@@ -559,9 +634,7 @@ static int spitz_ohci_init(struct device *dev)
559 if (err) 634 if (err)
560 return err; 635 return err;
561 636
562 /* Only Port 2 is connected 637 /* Only Port 2 is connected, setup USB Port 2 Output Control Register */
563 * Setup USB Port 2 Output Control Register
564 */
565 UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE; 638 UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE;
566 639
567 return gpio_direction_output(SPITZ_GPIO_USB_HOST, 1); 640 return gpio_direction_output(SPITZ_GPIO_USB_HOST, 1);
@@ -580,67 +653,95 @@ static struct pxaohci_platform_data spitz_ohci_platform_data = {
580 .power_budget = 150, 653 .power_budget = 150,
581}; 654};
582 655
656static void __init spitz_uhc_init(void)
657{
658 pxa_set_ohci_info(&spitz_ohci_platform_data);
659}
660#else
661static inline void spitz_uhc_init(void) {}
662#endif
583 663
584/* 664/******************************************************************************
585 * Irda 665 * IrDA
586 */ 666 ******************************************************************************/
587 667#if defined(CONFIG_PXA_FICP) || defined(CONFIG_PXA_FICP_MODULE)
588static struct pxaficp_platform_data spitz_ficp_platform_data = { 668static struct pxaficp_platform_data spitz_ficp_platform_data = {
589/* .gpio_pwdown is set in spitz_init() and akita_init() accordingly */
590 .transceiver_cap = IR_SIRMODE | IR_OFF, 669 .transceiver_cap = IR_SIRMODE | IR_OFF,
591}; 670};
592 671
672static void __init spitz_irda_init(void)
673{
674 if (machine_is_akita())
675 spitz_ficp_platform_data.gpio_pwdown = AKITA_GPIO_IR_ON;
676 else
677 spitz_ficp_platform_data.gpio_pwdown = SPITZ_GPIO_IR_ON;
593 678
594/* 679 pxa_set_ficp_info(&spitz_ficp_platform_data);
595 * Spitz PXA Framebuffer 680}
596 */ 681#else
682static inline void spitz_irda_init(void) {}
683#endif
597 684
685/******************************************************************************
686 * Framebuffer
687 ******************************************************************************/
688#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
598static struct pxafb_mode_info spitz_pxafb_modes[] = { 689static struct pxafb_mode_info spitz_pxafb_modes[] = {
599{ 690 {
600 .pixclock = 19231, 691 .pixclock = 19231,
601 .xres = 480, 692 .xres = 480,
602 .yres = 640, 693 .yres = 640,
603 .bpp = 16, 694 .bpp = 16,
604 .hsync_len = 40, 695 .hsync_len = 40,
605 .left_margin = 46, 696 .left_margin = 46,
606 .right_margin = 125, 697 .right_margin = 125,
607 .vsync_len = 3, 698 .vsync_len = 3,
608 .upper_margin = 1, 699 .upper_margin = 1,
609 .lower_margin = 0, 700 .lower_margin = 0,
610 .sync = 0, 701 .sync = 0,
611},{ 702 }, {
612 .pixclock = 134617, 703 .pixclock = 134617,
613 .xres = 240, 704 .xres = 240,
614 .yres = 320, 705 .yres = 320,
615 .bpp = 16, 706 .bpp = 16,
616 .hsync_len = 20, 707 .hsync_len = 20,
617 .left_margin = 20, 708 .left_margin = 20,
618 .right_margin = 46, 709 .right_margin = 46,
619 .vsync_len = 2, 710 .vsync_len = 2,
620 .upper_margin = 1, 711 .upper_margin = 1,
621 .lower_margin = 0, 712 .lower_margin = 0,
622 .sync = 0, 713 .sync = 0,
623}, 714 },
624}; 715};
625 716
626static struct pxafb_mach_info spitz_pxafb_info = { 717static struct pxafb_mach_info spitz_pxafb_info = {
627 .modes = &spitz_pxafb_modes[0], 718 .modes = spitz_pxafb_modes,
628 .num_modes = 2, 719 .num_modes = ARRAY_SIZE(spitz_pxafb_modes),
629 .fixed_modes = 1, 720 .fixed_modes = 1,
630 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_ALTERNATE_MAPPING, 721 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_ALTERNATE_MAPPING,
631}; 722};
632 723
633static struct mtd_partition sharpsl_nand_partitions[] = { 724static void __init spitz_lcd_init(void)
725{
726 set_pxa_fb_info(&spitz_pxafb_info);
727}
728#else
729static inline void spitz_lcd_init(void) {}
730#endif
731
732/******************************************************************************
733 * Framebuffer
734 ******************************************************************************/
735#if defined(CONFIG_MTD_NAND_SHARPSL) || defined(CONFIG_MTD_NAND_SHARPSL_MODULE)
736static struct mtd_partition spitz_nand_partitions[] = {
634 { 737 {
635 .name = "System Area", 738 .name = "System Area",
636 .offset = 0, 739 .offset = 0,
637 .size = 7 * 1024 * 1024, 740 .size = 7 * 1024 * 1024,
638 }, 741 }, {
639 {
640 .name = "Root Filesystem", 742 .name = "Root Filesystem",
641 .offset = 7 * 1024 * 1024, 743 .offset = 7 * 1024 * 1024,
642 }, 744 }, {
643 {
644 .name = "Home Filesystem", 745 .name = "Home Filesystem",
645 .offset = MTDPART_OFS_APPEND, 746 .offset = MTDPART_OFS_APPEND,
646 .size = MTDPART_SIZ_FULL, 747 .size = MTDPART_SIZ_FULL,
@@ -649,37 +750,72 @@ static struct mtd_partition sharpsl_nand_partitions[] = {
649 750
650static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; 751static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
651 752
652static struct nand_bbt_descr sharpsl_bbt = { 753static struct nand_bbt_descr spitz_nand_bbt = {
653 .options = 0, 754 .options = 0,
654 .offs = 4, 755 .offs = 4,
655 .len = 2, 756 .len = 2,
656 .pattern = scan_ff_pattern 757 .pattern = scan_ff_pattern
758};
759
760static struct nand_ecclayout akita_oobinfo = {
761 .oobfree = { {0x08, 0x09} },
762 .eccbytes = 24,
763 .eccpos = {
764 0x05, 0x01, 0x02, 0x03, 0x06, 0x07, 0x15, 0x11,
765 0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23,
766 0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37,
767 },
657}; 768};
658 769
659static struct sharpsl_nand_platform_data sharpsl_nand_platform_data = { 770static struct sharpsl_nand_platform_data spitz_nand_pdata = {
660 .badblock_pattern = &sharpsl_bbt, 771 .badblock_pattern = &spitz_nand_bbt,
661 .partitions = sharpsl_nand_partitions, 772 .partitions = spitz_nand_partitions,
662 .nr_partitions = ARRAY_SIZE(sharpsl_nand_partitions), 773 .nr_partitions = ARRAY_SIZE(spitz_nand_partitions),
663}; 774};
664 775
665static struct resource sharpsl_nand_resources[] = { 776static struct resource spitz_nand_resources[] = {
666 { 777 {
667 .start = 0x0C000000, 778 .start = PXA_CS3_PHYS,
668 .end = 0x0C000FFF, 779 .end = PXA_CS3_PHYS + SZ_4K - 1,
669 .flags = IORESOURCE_MEM, 780 .flags = IORESOURCE_MEM,
670 }, 781 },
671}; 782};
672 783
673static struct platform_device sharpsl_nand_device = { 784static struct platform_device spitz_nand_device = {
674 .name = "sharpsl-nand", 785 .name = "sharpsl-nand",
675 .id = -1, 786 .id = -1,
676 .resource = sharpsl_nand_resources, 787 .resource = spitz_nand_resources,
677 .num_resources = ARRAY_SIZE(sharpsl_nand_resources), 788 .num_resources = ARRAY_SIZE(spitz_nand_resources),
678 .dev.platform_data = &sharpsl_nand_platform_data, 789 .dev = {
790 .platform_data = &spitz_nand_pdata,
791 }
679}; 792};
680 793
794static void __init spitz_nand_init(void)
795{
796 if (machine_is_spitz()) {
797 spitz_nand_partitions[1].size = 5 * 1024 * 1024;
798 } else if (machine_is_akita()) {
799 spitz_nand_partitions[1].size = 58 * 1024 * 1024;
800 spitz_nand_bbt.len = 1;
801 spitz_nand_pdata.ecc_layout = &akita_oobinfo;
802 } else if (machine_is_borzoi()) {
803 spitz_nand_partitions[1].size = 32 * 1024 * 1024;
804 spitz_nand_bbt.len = 1;
805 spitz_nand_pdata.ecc_layout = &akita_oobinfo;
806 }
807
808 platform_device_register(&spitz_nand_device);
809}
810#else
811static inline void spitz_nand_init(void) {}
812#endif
681 813
682static struct mtd_partition sharpsl_rom_parts[] = { 814/******************************************************************************
815 * NOR Flash
816 ******************************************************************************/
817#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
818static struct mtd_partition spitz_rom_parts[] = {
683 { 819 {
684 .name ="Boot PROM Filesystem", 820 .name ="Boot PROM Filesystem",
685 .offset = 0x00140000, 821 .offset = 0x00140000,
@@ -687,37 +823,105 @@ static struct mtd_partition sharpsl_rom_parts[] = {
687 }, 823 },
688}; 824};
689 825
690static struct physmap_flash_data sharpsl_rom_data = { 826static struct physmap_flash_data spitz_rom_data = {
691 .width = 2, 827 .width = 2,
692 .nr_parts = ARRAY_SIZE(sharpsl_rom_parts), 828 .nr_parts = ARRAY_SIZE(spitz_rom_parts),
693 .parts = sharpsl_rom_parts, 829 .parts = spitz_rom_parts,
694}; 830};
695 831
696static struct resource sharpsl_rom_resources[] = { 832static struct resource spitz_rom_resources[] = {
697 { 833 {
698 .start = 0x00000000, 834 .start = PXA_CS0_PHYS,
699 .end = 0x007fffff, 835 .end = PXA_CS0_PHYS + SZ_8M - 1,
700 .flags = IORESOURCE_MEM, 836 .flags = IORESOURCE_MEM,
701 }, 837 },
702}; 838};
703 839
704static struct platform_device sharpsl_rom_device = { 840static struct platform_device spitz_rom_device = {
705 .name = "physmap-flash", 841 .name = "physmap-flash",
706 .id = -1, 842 .id = -1,
707 .resource = sharpsl_rom_resources, 843 .resource = spitz_rom_resources,
708 .num_resources = ARRAY_SIZE(sharpsl_rom_resources), 844 .num_resources = ARRAY_SIZE(spitz_rom_resources),
709 .dev.platform_data = &sharpsl_rom_data, 845 .dev = {
846 .platform_data = &spitz_rom_data,
847 },
710}; 848};
711 849
712static struct platform_device *devices[] __initdata = { 850static void __init spitz_nor_init(void)
713 &spitzscoop_device, 851{
714 &spitzkbd_device, 852 platform_device_register(&spitz_rom_device);
715 &spitz_gpio_keys_device, 853}
716 &spitzled_device, 854#else
717 &sharpsl_nand_device, 855static inline void spitz_nor_init(void) {}
718 &sharpsl_rom_device, 856#endif
857
858/******************************************************************************
859 * GPIO expander
860 ******************************************************************************/
861#if defined(CONFIG_I2C_PXA) || defined(CONFIG_I2C_PXA_MODULE)
862static struct pca953x_platform_data akita_pca953x_pdata = {
863 .gpio_base = AKITA_IOEXP_GPIO_BASE,
719}; 864};
720 865
866static struct i2c_board_info spitz_i2c_devs[] = {
867 {
868 .type = "wm8750",
869 .addr = 0x1b,
870 }, {
871 .type = "max7310",
872 .addr = 0x18,
873 .platform_data = &akita_pca953x_pdata,
874 },
875};
876
877static struct regulator_consumer_supply isl6271a_consumers[] = {
878 {
879 .supply = "vcc_core",
880 }
881};
882
883static struct regulator_init_data isl6271a_info[] = {
884 {
885 .constraints = {
886 .name = "vcc_core range",
887 .min_uV = 850000,
888 .max_uV = 1600000,
889 .always_on = 1,
890 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
891 },
892 .consumer_supplies = isl6271a_consumers,
893 .num_consumer_supplies = ARRAY_SIZE(isl6271a_consumers),
894 }
895};
896
897static struct i2c_board_info spitz_pi2c_devs[] = {
898 {
899 .type = "isl6271a",
900 .addr = 0x0c,
901 .platform_data = &isl6271a_info,
902 },
903};
904
905static void __init spitz_i2c_init(void)
906{
907 int size = ARRAY_SIZE(spitz_i2c_devs);
908
909 /* Only Akita has the max7310 chip */
910 if (!machine_is_akita())
911 size--;
912
913 pxa_set_i2c_info(NULL);
914 pxa27x_set_i2c_power_info(NULL);
915 i2c_register_board_info(0, spitz_i2c_devs, size);
916 i2c_register_board_info(1, ARRAY_AND_SIZE(spitz_pi2c_devs));
917}
918#else
919static inline void spitz_i2c_init(void) {}
920#endif
921
922/******************************************************************************
923 * Machine init
924 ******************************************************************************/
721static void spitz_poweroff(void) 925static void spitz_poweroff(void)
722{ 926{
723 arm_machine_restart('g', NULL); 927 arm_machine_restart('g', NULL);
@@ -726,26 +930,18 @@ static void spitz_poweroff(void)
726static void spitz_restart(char mode, const char *cmd) 930static void spitz_restart(char mode, const char *cmd)
727{ 931{
728 /* Bootloader magic for a reboot */ 932 /* Bootloader magic for a reboot */
729 if((MSC0 & 0xffff0000) == 0x7ff00000) 933 if ((MSC0 & 0xffff0000) == 0x7ff00000)
730 MSC0 = (MSC0 & 0xffff) | 0x7ee00000; 934 MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
731 935
732 spitz_poweroff(); 936 spitz_poweroff();
733} 937}
734 938
735static void __init common_init(void) 939static void __init spitz_init(void)
736{ 940{
737 init_gpio_reset(SPITZ_GPIO_ON_RESET, 1, 0); 941 init_gpio_reset(SPITZ_GPIO_ON_RESET, 1, 0);
738 pm_power_off = spitz_poweroff; 942 pm_power_off = spitz_poweroff;
739 arm_pm_restart = spitz_restart; 943 arm_pm_restart = spitz_restart;
740 944
741 if (machine_is_spitz()) {
742 sharpsl_nand_partitions[1].size = 5 * 1024 * 1024;
743 } else if (machine_is_akita()) {
744 sharpsl_nand_partitions[1].size = 58 * 1024 * 1024;
745 } else if (machine_is_borzoi()) {
746 sharpsl_nand_partitions[1].size = 32 * 1024 * 1024;
747 }
748
749 PMCR = 0x00; 945 PMCR = 0x00;
750 946
751 /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */ 947 /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
@@ -757,91 +953,22 @@ static void __init common_init(void)
757 pxa_set_btuart_info(NULL); 953 pxa_set_btuart_info(NULL);
758 pxa_set_stuart_info(NULL); 954 pxa_set_stuart_info(NULL);
759 955
760 spitz_init_spi(); 956 spitz_spi_init();
761 957 spitz_scoop_init();
762 platform_add_devices(devices, ARRAY_SIZE(devices)); 958 spitz_mkp_init();
763 pxa_set_mci_info(&spitz_mci_platform_data); 959 spitz_keys_init();
764 pxa_set_ohci_info(&spitz_ohci_platform_data); 960 spitz_leds_init();
765 pxa_set_ficp_info(&spitz_ficp_platform_data); 961 spitz_mmc_init();
766 set_pxa_fb_info(&spitz_pxafb_info); 962 spitz_pcmcia_init();
767 pxa_set_i2c_info(NULL); 963 spitz_irda_init();
964 spitz_uhc_init();
965 spitz_lcd_init();
966 spitz_nor_init();
967 spitz_nand_init();
968 spitz_i2c_init();
768} 969}
769 970
770#if defined(CONFIG_MACH_AKITA) || defined(CONFIG_MACH_BORZOI) 971static void __init spitz_fixup(struct machine_desc *desc,
771static struct nand_bbt_descr sharpsl_akita_bbt = {
772 .options = 0,
773 .offs = 4,
774 .len = 1,
775 .pattern = scan_ff_pattern
776};
777
778static struct nand_ecclayout akita_oobinfo = {
779 .eccbytes = 24,
780 .eccpos = {
781 0x5, 0x1, 0x2, 0x3, 0x6, 0x7, 0x15, 0x11,
782 0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23,
783 0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37},
784 .oobfree = {{0x08, 0x09}}
785};
786#endif
787
788#if defined(CONFIG_MACH_SPITZ) || defined(CONFIG_MACH_BORZOI)
789static void __init spitz_init(void)
790{
791 spitz_ficp_platform_data.gpio_pwdown = SPITZ_GPIO_IR_ON;
792
793#ifdef CONFIG_MACH_BORZOI
794 if (machine_is_borzoi()) {
795 sharpsl_nand_platform_data.badblock_pattern = &sharpsl_akita_bbt;
796 sharpsl_nand_platform_data.ecc_layout = &akita_oobinfo;
797 }
798#endif
799
800 platform_scoop_config = &spitz_pcmcia_config;
801
802 common_init();
803
804 platform_device_register(&spitzscoop2_device);
805}
806#endif
807
808#ifdef CONFIG_MACH_AKITA
809/*
810 * Akita IO Expander
811 */
812static struct pca953x_platform_data akita_ioexp = {
813 .gpio_base = AKITA_IOEXP_GPIO_BASE,
814};
815
816static struct i2c_board_info akita_i2c_board_info[] = {
817 {
818 .type = "max7310",
819 .addr = 0x18,
820 .platform_data = &akita_ioexp,
821 }, {
822 .type = "wm8750",
823 .addr = 0x1b,
824 },
825};
826
827static void __init akita_init(void)
828{
829 spitz_ficp_platform_data.gpio_pwdown = AKITA_GPIO_IR_ON;
830
831 sharpsl_nand_platform_data.badblock_pattern = &sharpsl_akita_bbt;
832 sharpsl_nand_platform_data.ecc_layout = &akita_oobinfo;
833
834 /* We just pretend the second element of the array doesn't exist */
835 spitz_pcmcia_config.num_devs = 1;
836 platform_scoop_config = &spitz_pcmcia_config;
837
838 i2c_register_board_info(0, ARRAY_AND_SIZE(akita_i2c_board_info));
839
840 common_init();
841}
842#endif
843
844static void __init fixup_spitz(struct machine_desc *desc,
845 struct tag *tags, char **cmdline, struct meminfo *mi) 972 struct tag *tags, char **cmdline, struct meminfo *mi)
846{ 973{
847 sharpsl_save_param(); 974 sharpsl_save_param();
@@ -854,7 +981,7 @@ static void __init fixup_spitz(struct machine_desc *desc,
854MACHINE_START(SPITZ, "SHARP Spitz") 981MACHINE_START(SPITZ, "SHARP Spitz")
855 .phys_io = 0x40000000, 982 .phys_io = 0x40000000,
856 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc, 983 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
857 .fixup = fixup_spitz, 984 .fixup = spitz_fixup,
858 .map_io = pxa_map_io, 985 .map_io = pxa_map_io,
859 .init_irq = pxa27x_init_irq, 986 .init_irq = pxa27x_init_irq,
860 .init_machine = spitz_init, 987 .init_machine = spitz_init,
@@ -866,7 +993,7 @@ MACHINE_END
866MACHINE_START(BORZOI, "SHARP Borzoi") 993MACHINE_START(BORZOI, "SHARP Borzoi")
867 .phys_io = 0x40000000, 994 .phys_io = 0x40000000,
868 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc, 995 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
869 .fixup = fixup_spitz, 996 .fixup = spitz_fixup,
870 .map_io = pxa_map_io, 997 .map_io = pxa_map_io,
871 .init_irq = pxa27x_init_irq, 998 .init_irq = pxa27x_init_irq,
872 .init_machine = spitz_init, 999 .init_machine = spitz_init,
@@ -878,10 +1005,10 @@ MACHINE_END
878MACHINE_START(AKITA, "SHARP Akita") 1005MACHINE_START(AKITA, "SHARP Akita")
879 .phys_io = 0x40000000, 1006 .phys_io = 0x40000000,
880 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc, 1007 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
881 .fixup = fixup_spitz, 1008 .fixup = spitz_fixup,
882 .map_io = pxa_map_io, 1009 .map_io = pxa_map_io,
883 .init_irq = pxa27x_init_irq, 1010 .init_irq = pxa27x_init_irq,
884 .init_machine = akita_init, 1011 .init_machine = spitz_init,
885 .timer = &pxa_timer, 1012 .timer = &pxa_timer,
886MACHINE_END 1013MACHINE_END
887#endif 1014#endif
diff --git a/arch/arm/mach-pxa/spitz_pm.c b/arch/arm/mach-pxa/spitz_pm.c
index 4209ddf6da61..7fe74067d85f 100644
--- a/arch/arm/mach-pxa/spitz_pm.c
+++ b/arch/arm/mach-pxa/spitz_pm.c
@@ -22,11 +22,10 @@
22#include <asm/mach-types.h> 22#include <asm/mach-types.h>
23#include <mach/hardware.h> 23#include <mach/hardware.h>
24 24
25#include <mach/sharpsl.h>
26#include <mach/spitz.h> 25#include <mach/spitz.h>
27#include <mach/pxa27x.h> 26#include <mach/pxa27x.h>
27#include <mach/sharpsl_pm.h>
28 28
29#include "sharpsl.h"
30#include "generic.h" 29#include "generic.h"
31 30
32#define SHARPSL_CHARGE_ON_VOLT 0x99 /* 2.9V */ 31#define SHARPSL_CHARGE_ON_VOLT 0x99 /* 2.9V */
@@ -178,11 +177,11 @@ unsigned long spitzpm_read_devdata(int type)
178 case SHARPSL_STATUS_ACIN: 177 case SHARPSL_STATUS_ACIN:
179 return (((~GPLR(SPITZ_GPIO_AC_IN)) & GPIO_bit(SPITZ_GPIO_AC_IN)) != 0); 178 return (((~GPLR(SPITZ_GPIO_AC_IN)) & GPIO_bit(SPITZ_GPIO_AC_IN)) != 0);
180 case SHARPSL_STATUS_LOCK: 179 case SHARPSL_STATUS_LOCK:
181 return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_batlock); 180 return gpio_get_value(sharpsl_pm.machinfo->gpio_batlock);
182 case SHARPSL_STATUS_CHRGFULL: 181 case SHARPSL_STATUS_CHRGFULL:
183 return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_batfull); 182 return gpio_get_value(sharpsl_pm.machinfo->gpio_batfull);
184 case SHARPSL_STATUS_FATAL: 183 case SHARPSL_STATUS_FATAL:
185 return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_fatal); 184 return gpio_get_value(sharpsl_pm.machinfo->gpio_fatal);
186 case SHARPSL_ACIN_VOLT: 185 case SHARPSL_ACIN_VOLT:
187 return sharpsl_pm_pxa_read_max1111(MAX1111_ACIN_VOLT); 186 return sharpsl_pm_pxa_read_max1111(MAX1111_ACIN_VOLT);
188 case SHARPSL_BATT_TEMP: 187 case SHARPSL_BATT_TEMP:
@@ -212,8 +211,6 @@ struct sharpsl_charger_machinfo spitz_pm_machinfo = {
212 .should_wakeup = spitz_should_wakeup, 211 .should_wakeup = spitz_should_wakeup,
213#if defined(CONFIG_LCD_CORGI) 212#if defined(CONFIG_LCD_CORGI)
214 .backlight_limit = corgi_lcd_limit_intensity, 213 .backlight_limit = corgi_lcd_limit_intensity,
215#elif defined(CONFIG_BACKLIGHT_CORGI)
216 .backlight_limit = corgibl_limit_intensity,
217#endif 214#endif
218 .charge_on_volt = SHARPSL_CHARGE_ON_VOLT, 215 .charge_on_volt = SHARPSL_CHARGE_ON_VOLT,
219 .charge_on_temp = SHARPSL_CHARGE_ON_TEMP, 216 .charge_on_temp = SHARPSL_CHARGE_ON_TEMP,
diff --git a/arch/arm/mach-pxa/stargate2.c b/arch/arm/mach-pxa/stargate2.c
index af40d2a12d37..a654d1e6b38a 100644
--- a/arch/arm/mach-pxa/stargate2.c
+++ b/arch/arm/mach-pxa/stargate2.c
@@ -29,6 +29,7 @@
29#include <linux/i2c/at24.h> 29#include <linux/i2c/at24.h>
30#include <linux/smc91x.h> 30#include <linux/smc91x.h>
31#include <linux/gpio.h> 31#include <linux/gpio.h>
32#include <linux/leds.h>
32 33
33#include <asm/types.h> 34#include <asm/types.h>
34#include <asm/setup.h> 35#include <asm/setup.h>
@@ -62,37 +63,12 @@
62#define SG2_GPIO_nSD_DETECT 90 63#define SG2_GPIO_nSD_DETECT 90
63#define SG2_SD_POWER_ENABLE 89 64#define SG2_SD_POWER_ENABLE 89
64 65
65static unsigned long stargate2_pin_config[] __initdata = { 66static unsigned long sg2_im2_unified_pin_config[] __initdata = {
66
67 GPIO15_nCS_1, /* SRAM */
68 /* SMC91x */
69 GPIO80_nCS_4,
70 GPIO40_GPIO, /*cable detect?*/
71 /* Device Identification for wakeup*/ 67 /* Device Identification for wakeup*/
72 GPIO102_GPIO, 68 GPIO102_GPIO,
73
74 /* Button */
75 GPIO91_GPIO | WAKEUP_ON_LEVEL_HIGH,
76
77 /* DA9030 */ 69 /* DA9030 */
78 GPIO1_GPIO, 70 GPIO1_GPIO,
79 71
80 /* Compact Flash */
81 GPIO79_PSKTSEL,
82 GPIO48_nPOE,
83 GPIO49_nPWE,
84 GPIO50_nPIOR,
85 GPIO51_nPIOW,
86 GPIO85_nPCE_1,
87 GPIO54_nPCE_2,
88 GPIO55_nPREG,
89 GPIO56_nPWAIT,
90 GPIO57_nIOIS16,
91 GPIO120_GPIO, /* Buff ctrl */
92 GPIO108_GPIO, /* Power ctrl */
93 GPIO82_GPIO, /* Reset */
94 GPIO53_GPIO, /* SG2_S0_GPIO_DETECT */
95
96 /* MMC */ 72 /* MMC */
97 GPIO32_MMC_CLK, 73 GPIO32_MMC_CLK,
98 GPIO112_MMC_CMD, 74 GPIO112_MMC_CMD,
@@ -100,49 +76,44 @@ static unsigned long stargate2_pin_config[] __initdata = {
100 GPIO109_MMC_DAT_1, 76 GPIO109_MMC_DAT_1,
101 GPIO110_MMC_DAT_2, 77 GPIO110_MMC_DAT_2,
102 GPIO111_MMC_DAT_3, 78 GPIO111_MMC_DAT_3,
103 GPIO90_GPIO, /* nSD detect */
104 GPIO89_GPIO, /* SD_POWER_ENABLE */
105 79
106 /* Bluetooth */ 80 /* 802.15.4 radio - driver out of mainline */
107 GPIO81_GPIO, /* reset */ 81 GPIO22_GPIO, /* CC_RSTN */
108 82 GPIO114_GPIO, /* CC_FIFO */
109 /* cc2420 802.15.4 radio */ 83 GPIO116_GPIO, /* CC_CCA */
110 GPIO22_GPIO, /* CC_RSTN (out)*/ 84 GPIO0_GPIO, /* CC_FIFOP */
111 GPIO114_GPIO, /* CC_FIFO (in) */ 85 GPIO16_GPIO, /* CCSFD */
112 GPIO116_GPIO, /* CC_CCA (in) */ 86 GPIO115_GPIO, /* Power enable */
113 GPIO0_GPIO, /* CC_FIFOP (in) */
114 GPIO16_GPIO, /* CCSFD (in) */
115 GPIO39_GPIO, /* CSn (out) */
116 87
117 /* I2C */ 88 /* I2C */
118 GPIO117_I2C_SCL, 89 GPIO117_I2C_SCL,
119 GPIO118_I2C_SDA, 90 GPIO118_I2C_SDA,
120 91
121 /* SSP 3 - 802.15.4 radio */ 92 /* SSP 3 - 802.15.4 radio */
122 GPIO39_GPIO, /* chip select */ 93 GPIO39_GPIO, /* Chip Select */
123 GPIO34_SSP3_SCLK, 94 GPIO34_SSP3_SCLK,
124 GPIO35_SSP3_TXD, 95 GPIO35_SSP3_TXD,
125 GPIO41_SSP3_RXD, 96 GPIO41_SSP3_RXD,
126 97
127 /* SSP 2 */ 98 /* SSP 2 to daughter boards */
128 GPIO11_SSP2_RXD, 99 GPIO11_SSP2_RXD,
129 GPIO38_SSP2_TXD, 100 GPIO38_SSP2_TXD,
130 GPIO36_SSP2_SCLK, 101 GPIO36_SSP2_SCLK,
131 GPIO37_GPIO, /* chip select */ 102 GPIO37_GPIO, /* chip select */
132 103
133 /* SSP 1 */ 104 /* SSP 1 - to daughter boards */
134 GPIO26_SSP1_RXD, 105 GPIO24_GPIO, /* Chip Select */
135 GPIO25_SSP1_TXD,
136 GPIO23_SSP1_SCLK, 106 GPIO23_SSP1_SCLK,
137 GPIO24_GPIO, /* chip select */ 107 GPIO25_SSP1_TXD,
108 GPIO26_SSP1_RXD,
138 109
139 /* BTUART */ 110 /* BTUART Basic Connector*/
140 GPIO42_BTUART_RXD, 111 GPIO42_BTUART_RXD,
141 GPIO43_BTUART_TXD, 112 GPIO43_BTUART_TXD,
142 GPIO44_BTUART_CTS, 113 GPIO44_BTUART_CTS,
143 GPIO45_BTUART_RTS, 114 GPIO45_BTUART_RTS,
144 115
145 /* STUART */ 116 /* STUART - IM2 via debug board not sure on SG2*/
146 GPIO46_STUART_RXD, 117 GPIO46_STUART_RXD,
147 GPIO47_STUART_TXD, 118 GPIO47_STUART_TXD,
148 119
@@ -150,47 +121,17 @@ static unsigned long stargate2_pin_config[] __initdata = {
150 GPIO96_GPIO, /* accelerometer interrupt */ 121 GPIO96_GPIO, /* accelerometer interrupt */
151 GPIO99_GPIO, /* ADC interrupt */ 122 GPIO99_GPIO, /* ADC interrupt */
152 123
153 /* Connector pins specified as gpios */
154 GPIO94_GPIO, /* large basic connector pin 14 */
155 GPIO10_GPIO, /* large basic connector pin 23 */
156
157 /* SHT15 */ 124 /* SHT15 */
158 GPIO100_GPIO, 125 GPIO100_GPIO,
159 GPIO98_GPIO, 126 GPIO98_GPIO,
160};
161 127
162/** 128 /* Basic sensor board */
163 * stargate2_reset_bluetooth() reset the bluecore to ensure consistent state 129 GPIO96_GPIO, /* accelerometer interrupt */
164 **/ 130 GPIO99_GPIO, /* ADC interrupt */
165static int stargate2_reset_bluetooth(void)
166{
167 int err;
168 err = gpio_request(SG2_BT_RESET, "SG2_BT_RESET");
169 if (err) {
170 printk(KERN_ERR "Could not get gpio for bluetooth reset \n");
171 return err;
172 }
173 gpio_direction_output(SG2_BT_RESET, 1);
174 mdelay(5);
175 /* now reset it - 5 msec minimum */
176 gpio_set_value(SG2_BT_RESET, 0);
177 mdelay(10);
178 gpio_set_value(SG2_BT_RESET, 1);
179 gpio_free(SG2_BT_RESET);
180 return 0;
181}
182 131
183static struct led_info stargate2_leds[] = { 132 /* Connector pins specified as gpios */
184 { 133 GPIO94_GPIO, /* large basic connector pin 14 */
185 .name = "sg2:red", 134 GPIO10_GPIO, /* large basic connector pin 23 */
186 .flags = DA9030_LED_RATE_ON,
187 }, {
188 .name = "sg2:blue",
189 .flags = DA9030_LED_RATE_ON,
190 }, {
191 .name = "sg2:green",
192 .flags = DA9030_LED_RATE_ON,
193 },
194}; 135};
195 136
196static struct sht15_platform_data platform_data_sht15 = { 137static struct sht15_platform_data platform_data_sht15 = {
@@ -352,20 +293,184 @@ static struct regulator_init_data stargate2_ldo_init_data[] = {
352 }, 293 },
353}; 294};
354 295
355static struct da903x_subdev_info stargate2_da9030_subdevs[] = { 296static struct mtd_partition stargate2flash_partitions[] = {
356 { 297 {
357 .name = "da903x-led", 298 .name = "Bootloader",
358 .id = DA9030_ID_LED_2, 299 .size = 0x00040000,
359 .platform_data = &stargate2_leds[0], 300 .offset = 0,
301 .mask_flags = 0,
360 }, { 302 }, {
361 .name = "da903x-led", 303 .name = "Kernel",
362 .id = DA9030_ID_LED_3, 304 .size = 0x00200000,
363 .platform_data = &stargate2_leds[2], 305 .offset = 0x00040000,
306 .mask_flags = 0
364 }, { 307 }, {
365 .name = "da903x-led", 308 .name = "Filesystem",
366 .id = DA9030_ID_LED_4, 309 .size = 0x01DC0000,
367 .platform_data = &stargate2_leds[1], 310 .offset = 0x00240000,
311 .mask_flags = 0
312 },
313};
314
315static struct resource flash_resources = {
316 .start = PXA_CS0_PHYS,
317 .end = PXA_CS0_PHYS + SZ_32M - 1,
318 .flags = IORESOURCE_MEM,
319};
320
321static struct flash_platform_data stargate2_flash_data = {
322 .map_name = "cfi_probe",
323 .parts = stargate2flash_partitions,
324 .nr_parts = ARRAY_SIZE(stargate2flash_partitions),
325 .name = "PXA27xOnChipROM",
326 .width = 2,
327};
328
329static struct platform_device stargate2_flash_device = {
330 .name = "pxa2xx-flash",
331 .id = 0,
332 .dev = {
333 .platform_data = &stargate2_flash_data,
334 },
335 .resource = &flash_resources,
336 .num_resources = 1,
337};
338
339static struct pxa2xx_spi_master pxa_ssp_master_0_info = {
340 .num_chipselect = 1,
341};
342
343static struct pxa2xx_spi_master pxa_ssp_master_1_info = {
344 .num_chipselect = 1,
345};
346
347static struct pxa2xx_spi_master pxa_ssp_master_2_info = {
348 .num_chipselect = 1,
349};
350
351/* An upcoming kernel change will scrap SFRM usage so these
352 * drivers have been moved to use gpio's via cs_control */
353static struct pxa2xx_spi_chip staccel_chip_info = {
354 .tx_threshold = 8,
355 .rx_threshold = 8,
356 .dma_burst_size = 8,
357 .timeout = 235,
358 .gpio_cs = 24,
359};
360
361static struct pxa2xx_spi_chip cc2420_info = {
362 .tx_threshold = 8,
363 .rx_threshold = 8,
364 .dma_burst_size = 8,
365 .timeout = 235,
366 .gpio_cs = 39,
367};
368
369static struct spi_board_info spi_board_info[] __initdata = {
370 {
371 .modalias = "lis3l02dq",
372 .max_speed_hz = 8000000,/* 8MHz max spi frequency at 3V */
373 .bus_num = 1,
374 .chip_select = 0,
375 .controller_data = &staccel_chip_info,
376 .irq = IRQ_GPIO(96),
368 }, { 377 }, {
378 .modalias = "cc2420",
379 .max_speed_hz = 6500000,
380 .bus_num = 3,
381 .chip_select = 0,
382 .controller_data = &cc2420_info,
383 },
384};
385
386static void sg2_udc_command(int cmd)
387{
388 switch (cmd) {
389 case PXA2XX_UDC_CMD_CONNECT:
390 UP2OCR |= UP2OCR_HXOE | UP2OCR_DPPUE | UP2OCR_DPPUBE;
391 break;
392 case PXA2XX_UDC_CMD_DISCONNECT:
393 UP2OCR &= ~(UP2OCR_HXOE | UP2OCR_DPPUE | UP2OCR_DPPUBE);
394 break;
395 }
396}
397
398static struct i2c_pxa_platform_data i2c_pwr_pdata = {
399 .fast_mode = 1,
400};
401
402static struct i2c_pxa_platform_data i2c_pdata = {
403 .fast_mode = 1,
404};
405
406static void __init imote2_stargate2_init(void)
407{
408
409 pxa2xx_mfp_config(ARRAY_AND_SIZE(sg2_im2_unified_pin_config));
410
411 pxa_set_ffuart_info(NULL);
412 pxa_set_btuart_info(NULL);
413 pxa_set_stuart_info(NULL);
414
415 pxa2xx_set_spi_info(1, &pxa_ssp_master_0_info);
416 pxa2xx_set_spi_info(2, &pxa_ssp_master_1_info);
417 pxa2xx_set_spi_info(3, &pxa_ssp_master_2_info);
418 spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
419
420
421 pxa27x_set_i2c_power_info(&i2c_pwr_pdata);
422 pxa_set_i2c_info(&i2c_pdata);
423}
424
425#ifdef CONFIG_MACH_INTELMOTE2
426/* As the the imote2 doesn't currently have a conventional SD slot
427 * there is no option to hotplug cards, making all this rather simple
428 */
429static int imote2_mci_get_ro(struct device *dev)
430{
431 return 0;
432}
433
434/* Rather simple case as hotplugging not possible */
435static struct pxamci_platform_data imote2_mci_platform_data = {
436 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, /* default anyway */
437 .get_ro = imote2_mci_get_ro,
438 .gpio_card_detect = -1,
439 .gpio_card_ro = -1,
440 .gpio_power = -1,
441};
442
443static struct gpio_led imote2_led_pins[] = {
444 {
445 .name = "imote2:red",
446 .gpio = 103,
447 .active_low = 1,
448 }, {
449 .name = "imote2:green",
450 .gpio = 104,
451 .active_low = 1,
452 }, {
453 .name = "imote2:blue",
454 .gpio = 105,
455 .active_low = 1,
456 },
457};
458
459static struct gpio_led_platform_data imote2_led_data = {
460 .num_leds = ARRAY_SIZE(imote2_led_pins),
461 .leds = imote2_led_pins,
462};
463
464static struct platform_device imote2_leds = {
465 .name = "leds-gpio",
466 .id = -1,
467 .dev = {
468 .platform_data = &imote2_led_data,
469 },
470};
471
472static struct da903x_subdev_info imote2_da9030_subdevs[] = {
473 {
369 .name = "da903x-regulator", 474 .name = "da903x-regulator",
370 .id = DA9030_ID_LDO2, 475 .id = DA9030_ID_LDO2,
371 .platform_data = &stargate2_ldo_init_data[vcc_bbio], 476 .platform_data = &stargate2_ldo_init_data[vcc_bbio],
@@ -428,9 +533,121 @@ static struct da903x_subdev_info stargate2_da9030_subdevs[] = {
428 }, 533 },
429}; 534};
430 535
431static struct da903x_platform_data stargate2_da9030_pdata = { 536static struct da903x_platform_data imote2_da9030_pdata = {
432 .num_subdevs = ARRAY_SIZE(stargate2_da9030_subdevs), 537 .num_subdevs = ARRAY_SIZE(imote2_da9030_subdevs),
433 .subdevs = stargate2_da9030_subdevs, 538 .subdevs = imote2_da9030_subdevs,
539};
540
541static struct i2c_board_info __initdata imote2_pwr_i2c_board_info[] = {
542 {
543 .type = "da9030",
544 .addr = 0x49,
545 .platform_data = &imote2_da9030_pdata,
546 .irq = gpio_to_irq(1),
547 },
548};
549
550static struct i2c_board_info __initdata imote2_i2c_board_info[] = {
551 { /* UCAM sensor board */
552 .type = "max1239",
553 .addr = 0x35,
554 }, { /* ITS400 Sensor board only */
555 .type = "max1363",
556 .addr = 0x34,
557 /* Through a nand gate - Also beware, on V2 sensor board the
558 * pull up resistors are missing.
559 */
560 .irq = IRQ_GPIO(99),
561 }, { /* ITS400 Sensor board only */
562 .type = "tsl2561",
563 .addr = 0x49,
564 /* Through a nand gate - Also beware, on V2 sensor board the
565 * pull up resistors are missing.
566 */
567 .irq = IRQ_GPIO(99),
568 }, { /* ITS400 Sensor board only */
569 .type = "tmp175",
570 .addr = 0x4A,
571 .irq = IRQ_GPIO(96),
572 }, { /* IMB400 Multimedia board */
573 .type = "wm8940",
574 .addr = 0x1A,
575 },
576};
577
578static unsigned long imote2_pin_config[] __initdata = {
579
580 /* Button */
581 GPIO91_GPIO,
582
583 /* LEDS */
584 GPIO103_GPIO, /* red led */
585 GPIO104_GPIO, /* green led */
586 GPIO105_GPIO, /* blue led */
587};
588
589static struct pxa2xx_udc_mach_info imote2_udc_info __initdata = {
590 .udc_command = sg2_udc_command,
591};
592
593static struct platform_device *imote2_devices[] = {
594 &stargate2_flash_device,
595 &imote2_leds,
596 &sht15,
597};
598
599static void __init imote2_init(void)
600{
601 pxa2xx_mfp_config(ARRAY_AND_SIZE(imote2_pin_config));
602
603 imote2_stargate2_init();
604
605 platform_add_devices(imote2_devices, ARRAY_SIZE(imote2_devices));
606
607 i2c_register_board_info(0, imote2_i2c_board_info,
608 ARRAY_SIZE(imote2_i2c_board_info));
609 i2c_register_board_info(1, imote2_pwr_i2c_board_info,
610 ARRAY_SIZE(imote2_pwr_i2c_board_info));
611
612 pxa_set_mci_info(&imote2_mci_platform_data);
613 pxa_set_udc_info(&imote2_udc_info);
614}
615#endif
616
617#ifdef CONFIG_MACH_STARGATE2
618
619static unsigned long stargate2_pin_config[] __initdata = {
620
621 GPIO15_nCS_1, /* SRAM */
622 /* SMC91x */
623 GPIO80_nCS_4,
624 GPIO40_GPIO, /*cable detect?*/
625
626 /* Button */
627 GPIO91_GPIO | WAKEUP_ON_LEVEL_HIGH,
628
629 /* Compact Flash */
630 GPIO79_PSKTSEL,
631 GPIO48_nPOE,
632 GPIO49_nPWE,
633 GPIO50_nPIOR,
634 GPIO51_nPIOW,
635 GPIO85_nPCE_1,
636 GPIO54_nPCE_2,
637 GPIO55_nPREG,
638 GPIO56_nPWAIT,
639 GPIO57_nIOIS16,
640 GPIO120_GPIO, /* Buff ctrl */
641 GPIO108_GPIO, /* Power ctrl */
642 GPIO82_GPIO, /* Reset */
643 GPIO53_GPIO, /* SG2_S0_GPIO_DETECT */
644
645 /* MMC not shared with imote2 */
646 GPIO90_GPIO, /* nSD detect */
647 GPIO89_GPIO, /* SD_POWER_ENABLE */
648
649 /* Bluetooth */
650 GPIO81_GPIO, /* reset */
434}; 651};
435 652
436static struct resource smc91x_resources[] = { 653static struct resource smc91x_resources[] = {
@@ -463,7 +680,6 @@ static struct platform_device smc91x_device = {
463}; 680};
464 681
465 682
466
467/* 683/*
468 * The card detect interrupt isn't debounced so we delay it by 250ms 684 * The card detect interrupt isn't debounced so we delay it by 250ms
469 * to give the card a chance to fully insert / eject. 685 * to give the card a chance to fully insert / eject.
@@ -532,48 +748,6 @@ static struct pxamci_platform_data stargate2_mci_platform_data = {
532 .exit = stargate2_mci_exit, 748 .exit = stargate2_mci_exit,
533}; 749};
534 750
535static struct mtd_partition stargate2flash_partitions[] = {
536 {
537 .name = "Bootloader",
538 .size = 0x00040000,
539 .offset = 0,
540 .mask_flags = 0,
541 }, {
542 .name = "Kernel",
543 .size = 0x00200000,
544 .offset = 0x00040000,
545 .mask_flags = 0
546 }, {
547 .name = "Filesystem",
548 .size = 0x01DC0000,
549 .offset = 0x00240000,
550 .mask_flags = 0
551 },
552};
553
554static struct resource flash_resources = {
555 .start = PXA_CS0_PHYS,
556 .end = PXA_CS0_PHYS + SZ_32M - 1,
557 .flags = IORESOURCE_MEM,
558};
559
560static struct flash_platform_data stargate2_flash_data = {
561 .map_name = "cfi_probe",
562 .parts = stargate2flash_partitions,
563 .nr_parts = ARRAY_SIZE(stargate2flash_partitions),
564 .name = "PXA27xOnChipROM",
565 .width = 2,
566};
567
568static struct platform_device stargate2_flash_device = {
569 .name = "pxa2xx-flash",
570 .id = 0,
571 .dev = {
572 .platform_data = &stargate2_flash_data,
573 },
574 .resource = &flash_resources,
575 .num_resources = 1,
576};
577 751
578/* 752/*
579 * SRAM - The Stargate 2 has 32MB of SRAM. 753 * SRAM - The Stargate 2 has 32MB of SRAM.
@@ -616,6 +790,129 @@ static struct at24_platform_data pca9500_eeprom_pdata = {
616 .page_size = 4, 790 .page_size = 4,
617}; 791};
618 792
793/**
794 * stargate2_reset_bluetooth() reset the bluecore to ensure consistent state
795 **/
796static int stargate2_reset_bluetooth(void)
797{
798 int err;
799 err = gpio_request(SG2_BT_RESET, "SG2_BT_RESET");
800 if (err) {
801 printk(KERN_ERR "Could not get gpio for bluetooth reset\n");
802 return err;
803 }
804 gpio_direction_output(SG2_BT_RESET, 1);
805 mdelay(5);
806 /* now reset it - 5 msec minimum */
807 gpio_set_value(SG2_BT_RESET, 0);
808 mdelay(10);
809 gpio_set_value(SG2_BT_RESET, 1);
810 gpio_free(SG2_BT_RESET);
811 return 0;
812}
813
814static struct led_info stargate2_leds[] = {
815 {
816 .name = "sg2:red",
817 .flags = DA9030_LED_RATE_ON,
818 }, {
819 .name = "sg2:blue",
820 .flags = DA9030_LED_RATE_ON,
821 }, {
822 .name = "sg2:green",
823 .flags = DA9030_LED_RATE_ON,
824 },
825};
826
827static struct da903x_subdev_info stargate2_da9030_subdevs[] = {
828 {
829 .name = "da903x-led",
830 .id = DA9030_ID_LED_2,
831 .platform_data = &stargate2_leds[0],
832 }, {
833 .name = "da903x-led",
834 .id = DA9030_ID_LED_3,
835 .platform_data = &stargate2_leds[2],
836 }, {
837 .name = "da903x-led",
838 .id = DA9030_ID_LED_4,
839 .platform_data = &stargate2_leds[1],
840 }, {
841 .name = "da903x-regulator",
842 .id = DA9030_ID_LDO2,
843 .platform_data = &stargate2_ldo_init_data[vcc_bbio],
844 }, {
845 .name = "da903x-regulator",
846 .id = DA9030_ID_LDO3,
847 .platform_data = &stargate2_ldo_init_data[vcc_bb],
848 }, {
849 .name = "da903x-regulator",
850 .id = DA9030_ID_LDO4,
851 .platform_data = &stargate2_ldo_init_data[vcc_pxa_flash],
852 }, {
853 .name = "da903x-regulator",
854 .id = DA9030_ID_LDO5,
855 .platform_data = &stargate2_ldo_init_data[vcc_cc2420],
856 }, {
857 .name = "da903x-regulator",
858 .id = DA9030_ID_LDO6,
859 .platform_data = &stargate2_ldo_init_data[vcc_vref],
860 }, {
861 .name = "da903x-regulator",
862 .id = DA9030_ID_LDO7,
863 .platform_data = &stargate2_ldo_init_data[vcc_sram_ext],
864 }, {
865 .name = "da903x-regulator",
866 .id = DA9030_ID_LDO8,
867 .platform_data = &stargate2_ldo_init_data[vcc_mica],
868 }, {
869 .name = "da903x-regulator",
870 .id = DA9030_ID_LDO9,
871 .platform_data = &stargate2_ldo_init_data[vcc_bt],
872 }, {
873 .name = "da903x-regulator",
874 .id = DA9030_ID_LDO10,
875 .platform_data = &stargate2_ldo_init_data[vcc_sensor_1_8],
876 }, {
877 .name = "da903x-regulator",
878 .id = DA9030_ID_LDO11,
879 .platform_data = &stargate2_ldo_init_data[vcc_sensor_3],
880 }, {
881 .name = "da903x-regulator",
882 .id = DA9030_ID_LDO12,
883 .platform_data = &stargate2_ldo_init_data[vcc_lcd],
884 }, {
885 .name = "da903x-regulator",
886 .id = DA9030_ID_LDO15,
887 .platform_data = &stargate2_ldo_init_data[vcc_pxa_pll],
888 }, {
889 .name = "da903x-regulator",
890 .id = DA9030_ID_LDO17,
891 .platform_data = &stargate2_ldo_init_data[vcc_pxa_usim],
892 }, {
893 .name = "da903x-regulator", /*pxa vcc i/o and cc2420 vcc i/o */
894 .id = DA9030_ID_LDO18,
895 .platform_data = &stargate2_ldo_init_data[vcc_io],
896 }, {
897 .name = "da903x-regulator",
898 .id = DA9030_ID_LDO19,
899 .platform_data = &stargate2_ldo_init_data[vcc_pxa_mem],
900 },
901};
902
903static struct da903x_platform_data stargate2_da9030_pdata = {
904 .num_subdevs = ARRAY_SIZE(stargate2_da9030_subdevs),
905 .subdevs = stargate2_da9030_subdevs,
906};
907
908static struct i2c_board_info __initdata stargate2_pwr_i2c_board_info[] = {
909 {
910 .type = "da9030",
911 .addr = 0x49,
912 .platform_data = &stargate2_da9030_pdata,
913 .irq = gpio_to_irq(1),
914 },
915};
619 916
620static struct i2c_board_info __initdata stargate2_i2c_board_info[] = { 917static struct i2c_board_info __initdata stargate2_i2c_board_info[] = {
621 /* Techically this a pca9500 - but it's compatible with the 8574 918 /* Techically this a pca9500 - but it's compatible with the 8574
@@ -653,74 +950,6 @@ static struct i2c_board_info __initdata stargate2_i2c_board_info[] = {
653 }, 950 },
654}; 951};
655 952
656static struct i2c_board_info __initdata stargate2_pwr_i2c_board_info[] = {
657 {
658 .type = "da9030",
659 .addr = 0x49,
660 .platform_data = &stargate2_da9030_pdata,
661 .irq = gpio_to_irq(1),
662 },
663};
664
665static struct pxa2xx_spi_master pxa_ssp_master_0_info = {
666 .num_chipselect = 1,
667};
668
669static struct pxa2xx_spi_master pxa_ssp_master_1_info = {
670 .num_chipselect = 1,
671};
672
673static struct pxa2xx_spi_master pxa_ssp_master_2_info = {
674 .num_chipselect = 1,
675};
676
677/* An upcoming kernel change will scrap SFRM usage so these
678 * drivers have been moved to use gpio's via cs_control */
679static struct pxa2xx_spi_chip staccel_chip_info = {
680 .tx_threshold = 8,
681 .rx_threshold = 8,
682 .dma_burst_size = 8,
683 .timeout = 235,
684 .gpio_cs = 24,
685};
686
687static struct pxa2xx_spi_chip cc2420_info = {
688 .tx_threshold = 8,
689 .rx_threshold = 8,
690 .dma_burst_size = 8,
691 .timeout = 235,
692 .gpio_cs = 39,
693};
694
695static struct spi_board_info spi_board_info[] __initdata = {
696 {
697 .modalias = "lis3l02dq",
698 .max_speed_hz = 8000000,/* 8MHz max spi frequency at 3V */
699 .bus_num = 1,
700 .chip_select = 0,
701 .controller_data = &staccel_chip_info,
702 .irq = IRQ_GPIO(96),
703 }, {
704 .modalias = "cc2420",
705 .max_speed_hz = 6500000,
706 .bus_num = 3,
707 .chip_select = 0,
708 .controller_data = &cc2420_info,
709 },
710};
711
712static void sg2_udc_command(int cmd)
713{
714 switch (cmd) {
715 case PXA2XX_UDC_CMD_CONNECT:
716 UP2OCR |= UP2OCR_HXOE | UP2OCR_DPPUE | UP2OCR_DPPUBE;
717 break;
718 case PXA2XX_UDC_CMD_DISCONNECT:
719 UP2OCR &= ~(UP2OCR_HXOE | UP2OCR_DPPUE | UP2OCR_DPPUBE);
720 break;
721 }
722}
723
724/* Board doesn't support cable detection - so always lie and say 953/* Board doesn't support cable detection - so always lie and say
725 * something is there. 954 * something is there.
726 */ 955 */
@@ -741,14 +970,6 @@ static struct platform_device *stargate2_devices[] = {
741 &sht15, 970 &sht15,
742}; 971};
743 972
744static struct i2c_pxa_platform_data i2c_pwr_pdata = {
745 .fast_mode = 1,
746};
747
748static struct i2c_pxa_platform_data i2c_pdata = {
749 .fast_mode = 1,
750};
751
752static void __init stargate2_init(void) 973static void __init stargate2_init(void)
753{ 974{
754 /* This is probably a board specific hack as this must be set 975 /* This is probably a board specific hack as this must be set
@@ -757,22 +978,13 @@ static void __init stargate2_init(void)
757 978
758 pxa2xx_mfp_config(ARRAY_AND_SIZE(stargate2_pin_config)); 979 pxa2xx_mfp_config(ARRAY_AND_SIZE(stargate2_pin_config));
759 980
760 pxa_set_ffuart_info(NULL); 981 imote2_stargate2_init();
761 pxa_set_btuart_info(NULL);
762 pxa_set_stuart_info(NULL);
763 982
764 platform_add_devices(ARRAY_AND_SIZE(stargate2_devices)); 983 platform_add_devices(ARRAY_AND_SIZE(stargate2_devices));
765 984
766 pxa2xx_set_spi_info(1, &pxa_ssp_master_0_info);
767 pxa2xx_set_spi_info(2, &pxa_ssp_master_1_info);
768 pxa2xx_set_spi_info(3, &pxa_ssp_master_2_info);
769 spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
770
771 i2c_register_board_info(0, ARRAY_AND_SIZE(stargate2_i2c_board_info)); 985 i2c_register_board_info(0, ARRAY_AND_SIZE(stargate2_i2c_board_info));
772 i2c_register_board_info(1, 986 i2c_register_board_info(1, stargate2_pwr_i2c_board_info,
773 ARRAY_AND_SIZE(stargate2_pwr_i2c_board_info)); 987 ARRAY_SIZE(stargate2_pwr_i2c_board_info));
774 pxa27x_set_i2c_power_info(&i2c_pwr_pdata);
775 pxa_set_i2c_info(&i2c_pdata);
776 988
777 pxa_set_mci_info(&stargate2_mci_platform_data); 989 pxa_set_mci_info(&stargate2_mci_platform_data);
778 990
@@ -780,7 +992,21 @@ static void __init stargate2_init(void)
780 992
781 stargate2_reset_bluetooth(); 993 stargate2_reset_bluetooth();
782} 994}
995#endif
996
997#ifdef CONFIG_MACH_INTELMOTE2
998MACHINE_START(INTELMOTE2, "IMOTE 2")
999 .phys_io = 0x40000000,
1000 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
1001 .map_io = pxa_map_io,
1002 .init_irq = pxa27x_init_irq,
1003 .timer = &pxa_timer,
1004 .init_machine = imote2_init,
1005 .boot_params = 0xA0000100,
1006MACHINE_END
1007#endif
783 1008
1009#ifdef CONFIG_MACH_STARGATE2
784MACHINE_START(STARGATE2, "Stargate 2") 1010MACHINE_START(STARGATE2, "Stargate 2")
785 .phys_io = 0x40000000, 1011 .phys_io = 0x40000000,
786 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc, 1012 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
@@ -790,3 +1016,4 @@ MACHINE_START(STARGATE2, "Stargate 2")
790 .init_machine = stargate2_init, 1016 .init_machine = stargate2_init,
791 .boot_params = 0xA0000100, 1017 .boot_params = 0xA0000100,
792MACHINE_END 1018MACHINE_END
1019#endif
diff --git a/arch/arm/mach-pxa/trizeps4.c b/arch/arm/mach-pxa/trizeps4.c
index 69689112eae7..0acff172ef22 100644
--- a/arch/arm/mach-pxa/trizeps4.c
+++ b/arch/arm/mach-pxa/trizeps4.c
@@ -530,13 +530,9 @@ static void __init trizeps4_init(void)
530 i2c_register_board_info(0, trizeps4_i2c_devices, 530 i2c_register_board_info(0, trizeps4_i2c_devices,
531 ARRAY_SIZE(trizeps4_i2c_devices)); 531 ARRAY_SIZE(trizeps4_i2c_devices));
532 532
533#ifdef CONFIG_IDE_PXA_CF
534 /* if boot direct from compact flash dont disable power */
535 trizeps_conxs_bcr = 0x0009;
536#else
537 /* this is the reset value */ 533 /* this is the reset value */
538 trizeps_conxs_bcr = 0x00A0; 534 trizeps_conxs_bcr = 0x00A0;
539#endif 535
540 BCR_writew(trizeps_conxs_bcr); 536 BCR_writew(trizeps_conxs_bcr);
541 board_backlight_power(1); 537 board_backlight_power(1);
542} 538}
diff --git a/arch/arm/mach-pxa/vpac270.c b/arch/arm/mach-pxa/vpac270.c
index 9884fa978f16..c9b747cedea8 100644
--- a/arch/arm/mach-pxa/vpac270.c
+++ b/arch/arm/mach-pxa/vpac270.c
@@ -25,6 +25,7 @@
25#include <linux/dm9000.h> 25#include <linux/dm9000.h>
26#include <linux/ucb1400.h> 26#include <linux/ucb1400.h>
27#include <linux/ata_platform.h> 27#include <linux/ata_platform.h>
28#include <linux/regulator/max1586.h>
28 29
29#include <asm/mach-types.h> 30#include <asm/mach-types.h>
30#include <asm/mach/arch.h> 31#include <asm/mach/arch.h>
@@ -37,6 +38,7 @@
37#include <mach/ohci.h> 38#include <mach/ohci.h>
38#include <mach/pxa27x-udc.h> 39#include <mach/pxa27x-udc.h>
39#include <mach/udc.h> 40#include <mach/udc.h>
41#include <mach/pata_pxa.h>
40 42
41#include <plat/i2c.h> 43#include <plat/i2c.h>
42 44
@@ -464,7 +466,6 @@ static struct i2c_board_info __initdata vpac270_i2c_devs[] = {
464 466
465static void __init vpac270_rtc_init(void) 467static void __init vpac270_rtc_init(void)
466{ 468{
467 pxa_set_i2c_info(NULL);
468 i2c_register_board_info(0, ARRAY_AND_SIZE(vpac270_i2c_devs)); 469 i2c_register_board_info(0, ARRAY_AND_SIZE(vpac270_i2c_devs));
469} 470}
470#else 471#else
@@ -492,7 +493,55 @@ static struct pxafb_mode_info vpac270_lcd_modes[] = {
492 .vsync_len = 2, 493 .vsync_len = 2,
493 494
494 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 495 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
495}, 496}, { /* CRT 640x480 */
497 .pixclock = 35000,
498 .xres = 640,
499 .yres = 480,
500 .bpp = 16,
501 .depth = 16,
502
503 .left_margin = 96,
504 .right_margin = 48,
505 .upper_margin = 33,
506 .lower_margin = 10,
507
508 .hsync_len = 48,
509 .vsync_len = 1,
510
511 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
512}, { /* CRT 800x600 H=30kHz V=48HZ */
513 .pixclock = 25000,
514 .xres = 800,
515 .yres = 600,
516 .bpp = 16,
517 .depth = 16,
518
519 .left_margin = 50,
520 .right_margin = 1,
521 .upper_margin = 21,
522 .lower_margin = 12,
523
524 .hsync_len = 8,
525 .vsync_len = 1,
526
527 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
528}, { /* CRT 1024x768 H=40kHz V=50Hz */
529 .pixclock = 15000,
530 .xres = 1024,
531 .yres = 768,
532 .bpp = 16,
533 .depth = 16,
534
535 .left_margin = 220,
536 .right_margin = 8,
537 .upper_margin = 33,
538 .lower_margin = 2,
539
540 .hsync_len = 48,
541 .vsync_len = 1,
542
543 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
544}
496}; 545};
497 546
498static struct pxafb_mach_info vpac270_lcd_screen = { 547static struct pxafb_mach_info vpac270_lcd_screen = {
@@ -538,9 +587,10 @@ static inline void vpac270_lcd_init(void) {}
538/****************************************************************************** 587/******************************************************************************
539 * PATA IDE 588 * PATA IDE
540 ******************************************************************************/ 589 ******************************************************************************/
541#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE) 590#if defined(CONFIG_PATA_PXA) || defined(CONFIG_PATA_PXA_MODULE)
542static struct pata_platform_info vpac270_pata_pdata = { 591static struct pata_pxa_pdata vpac270_pata_pdata = {
543 .ioport_shift = 1, 592 .reg_shift = 1,
593 .dma_dreq = 1,
544 .irq_flags = IRQF_TRIGGER_RISING, 594 .irq_flags = IRQF_TRIGGER_RISING,
545}; 595};
546 596
@@ -555,7 +605,12 @@ static struct resource vpac270_ide_resources[] = {
555 .end = PXA_CS3_PHYS + 0x15f, 605 .end = PXA_CS3_PHYS + 0x15f,
556 .flags = IORESOURCE_MEM 606 .flags = IORESOURCE_MEM
557 }, 607 },
558 [2] = { /* IDE IRQ pin */ 608 [2] = { /* DMA Base address */
609 .start = PXA_CS3_PHYS + 0x20,
610 .end = PXA_CS3_PHYS + 0x2f,
611 .flags = IORESOURCE_DMA
612 },
613 [3] = { /* IDE IRQ pin */
559 .start = gpio_to_irq(GPIO36_VPAC270_IDE_IRQ), 614 .start = gpio_to_irq(GPIO36_VPAC270_IDE_IRQ),
560 .end = gpio_to_irq(GPIO36_VPAC270_IDE_IRQ), 615 .end = gpio_to_irq(GPIO36_VPAC270_IDE_IRQ),
561 .flags = IORESOURCE_IRQ 616 .flags = IORESOURCE_IRQ
@@ -563,11 +618,12 @@ static struct resource vpac270_ide_resources[] = {
563}; 618};
564 619
565static struct platform_device vpac270_ide_device = { 620static struct platform_device vpac270_ide_device = {
566 .name = "pata_platform", 621 .name = "pata_pxa",
567 .num_resources = ARRAY_SIZE(vpac270_ide_resources), 622 .num_resources = ARRAY_SIZE(vpac270_ide_resources),
568 .resource = vpac270_ide_resources, 623 .resource = vpac270_ide_resources,
569 .dev = { 624 .dev = {
570 .platform_data = &vpac270_pata_pdata, 625 .platform_data = &vpac270_pata_pdata,
626 .coherent_dma_mask = 0xffffffff,
571 } 627 }
572}; 628};
573 629
@@ -580,6 +636,59 @@ static inline void vpac270_ide_init(void) {}
580#endif 636#endif
581 637
582/****************************************************************************** 638/******************************************************************************
639 * Core power regulator
640 ******************************************************************************/
641#if defined(CONFIG_REGULATOR_MAX1586) || \
642 defined(CONFIG_REGULATOR_MAX1586_MODULE)
643static struct regulator_consumer_supply vpac270_max1587a_consumers[] = {
644 {
645 .supply = "vcc_core",
646 }
647};
648
649static struct regulator_init_data vpac270_max1587a_v3_info = {
650 .constraints = {
651 .name = "vcc_core range",
652 .min_uV = 900000,
653 .max_uV = 1705000,
654 .always_on = 1,
655 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
656 },
657 .consumer_supplies = vpac270_max1587a_consumers,
658 .num_consumer_supplies = ARRAY_SIZE(vpac270_max1587a_consumers),
659};
660
661static struct max1586_subdev_data vpac270_max1587a_subdevs[] = {
662 {
663 .name = "vcc_core",
664 .id = MAX1586_V3,
665 .platform_data = &vpac270_max1587a_v3_info,
666 }
667};
668
669static struct max1586_platform_data vpac270_max1587a_info = {
670 .subdevs = vpac270_max1587a_subdevs,
671 .num_subdevs = ARRAY_SIZE(vpac270_max1587a_subdevs),
672 .v3_gain = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
673};
674
675static struct i2c_board_info __initdata vpac270_pi2c_board_info[] = {
676 {
677 I2C_BOARD_INFO("max1586", 0x14),
678 .platform_data = &vpac270_max1587a_info,
679 },
680};
681
682static void __init vpac270_pmic_init(void)
683{
684 i2c_register_board_info(1, ARRAY_AND_SIZE(vpac270_pi2c_board_info));
685}
686#else
687static inline void vpac270_pmic_init(void) {}
688#endif
689
690
691/******************************************************************************
583 * Machine init 692 * Machine init
584 ******************************************************************************/ 693 ******************************************************************************/
585static void __init vpac270_init(void) 694static void __init vpac270_init(void)
@@ -589,7 +698,10 @@ static void __init vpac270_init(void)
589 pxa_set_ffuart_info(NULL); 698 pxa_set_ffuart_info(NULL);
590 pxa_set_btuart_info(NULL); 699 pxa_set_btuart_info(NULL);
591 pxa_set_stuart_info(NULL); 700 pxa_set_stuart_info(NULL);
701 pxa_set_i2c_info(NULL);
702 pxa27x_set_i2c_power_info(NULL);
592 703
704 vpac270_pmic_init();
593 vpac270_lcd_init(); 705 vpac270_lcd_init();
594 vpac270_mmc_init(); 706 vpac270_mmc_init();
595 vpac270_nor_init(); 707 vpac270_nor_init();
diff --git a/arch/arm/mach-pxa/z2.c b/arch/arm/mach-pxa/z2.c
index d303c6929d32..f0d02288b4ca 100644
--- a/arch/arm/mach-pxa/z2.c
+++ b/arch/arm/mach-pxa/z2.c
@@ -17,6 +17,7 @@
17#include <linux/mtd/mtd.h> 17#include <linux/mtd/mtd.h>
18#include <linux/mtd/partitions.h> 18#include <linux/mtd/partitions.h>
19#include <linux/pwm_backlight.h> 19#include <linux/pwm_backlight.h>
20#include <linux/z2_battery.h>
20#include <linux/dma-mapping.h> 21#include <linux/dma-mapping.h>
21#include <linux/spi/spi.h> 22#include <linux/spi/spi.h>
22#include <linux/spi/libertas_spi.h> 23#include <linux/spi/libertas_spi.h>
@@ -26,6 +27,7 @@
26#include <linux/gpio.h> 27#include <linux/gpio.h>
27#include <linux/gpio_keys.h> 28#include <linux/gpio_keys.h>
28#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/regulator/machine.h>
29 31
30#include <asm/mach-types.h> 32#include <asm/mach-types.h>
31#include <asm/mach/arch.h> 33#include <asm/mach/arch.h>
@@ -162,7 +164,7 @@ static struct mtd_partition z2_flash_parts[] = {
162 }, { 164 }, {
163 .name = "U-Boot Environment", 165 .name = "U-Boot Environment",
164 .offset = 0x40000, 166 .offset = 0x40000,
165 .size = 0x60000, 167 .size = 0x20000,
166 }, { 168 }, {
167 .name = "Flash", 169 .name = "Flash",
168 .offset = 0x60000, 170 .offset = 0x60000,
@@ -452,6 +454,42 @@ static inline void z2_keys_init(void) {}
452#endif 454#endif
453 455
454/****************************************************************************** 456/******************************************************************************
457 * Battery
458 ******************************************************************************/
459#if defined(CONFIG_I2C_PXA) || defined(CONFIG_I2C_PXA_MODULE)
460static struct z2_battery_info batt_chip_info = {
461 .batt_I2C_bus = 0,
462 .batt_I2C_addr = 0x55,
463 .batt_I2C_reg = 2,
464 .charge_gpio = GPIO0_ZIPITZ2_AC_DETECT,
465 .min_voltage = 2400000,
466 .max_voltage = 3700000,
467 .batt_div = 69,
468 .batt_mult = 1000000,
469 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LION,
470 .batt_name = "Z2",
471};
472
473static struct i2c_board_info __initdata z2_i2c_board_info[] = {
474 {
475 I2C_BOARD_INFO("aer915", 0x55),
476 .platform_data = &batt_chip_info,
477 }, {
478 I2C_BOARD_INFO("wm8750", 0x1b),
479 },
480
481};
482
483static void __init z2_i2c_init(void)
484{
485 pxa_set_i2c_info(NULL);
486 i2c_register_board_info(0, ARRAY_AND_SIZE(z2_i2c_board_info));
487}
488#else
489static inline void z2_i2c_init(void) {}
490#endif
491
492/******************************************************************************
455 * SSP Devices - WiFi and LCD control 493 * SSP Devices - WiFi and LCD control
456 ******************************************************************************/ 494 ******************************************************************************/
457#if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE) 495#if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
@@ -573,23 +611,95 @@ static inline void z2_spi_init(void) {}
573#endif 611#endif
574 612
575/****************************************************************************** 613/******************************************************************************
614 * Core power regulator
615 ******************************************************************************/
616#if defined(CONFIG_REGULATOR_TPS65023) || \
617 defined(CONFIG_REGULATOR_TPS65023_MODULE)
618static struct regulator_consumer_supply z2_tps65021_consumers[] = {
619 {
620 .supply = "vcc_core",
621 }
622};
623
624static struct regulator_init_data z2_tps65021_info[] = {
625 {
626 .constraints = {
627 .name = "vcc_core range",
628 .min_uV = 800000,
629 .max_uV = 1600000,
630 .always_on = 1,
631 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
632 },
633 .consumer_supplies = z2_tps65021_consumers,
634 .num_consumer_supplies = ARRAY_SIZE(z2_tps65021_consumers),
635 }, {
636 .constraints = {
637 .name = "DCDC2",
638 .min_uV = 3300000,
639 .max_uV = 3300000,
640 .always_on = 1,
641 },
642 }, {
643 .constraints = {
644 .name = "DCDC3",
645 .min_uV = 1800000,
646 .max_uV = 1800000,
647 .always_on = 1,
648 },
649 }, {
650 .constraints = {
651 .name = "LDO1",
652 .min_uV = 1000000,
653 .max_uV = 3150000,
654 .always_on = 1,
655 },
656 }, {
657 .constraints = {
658 .name = "LDO2",
659 .min_uV = 1050000,
660 .max_uV = 3300000,
661 .always_on = 1,
662 },
663 }
664};
665
666static struct i2c_board_info __initdata z2_pi2c_board_info[] = {
667 {
668 I2C_BOARD_INFO("tps65021", 0x48),
669 .platform_data = &z2_tps65021_info,
670 },
671};
672
673static void __init z2_pmic_init(void)
674{
675 pxa27x_set_i2c_power_info(NULL);
676 i2c_register_board_info(1, ARRAY_AND_SIZE(z2_pi2c_board_info));
677}
678#else
679static inline void z2_pmic_init(void) {}
680#endif
681
682/******************************************************************************
576 * Machine init 683 * Machine init
577 ******************************************************************************/ 684 ******************************************************************************/
578static void __init z2_init(void) 685static void __init z2_init(void)
579{ 686{
580 pxa2xx_mfp_config(ARRAY_AND_SIZE(z2_pin_config)); 687 pxa2xx_mfp_config(ARRAY_AND_SIZE(z2_pin_config));
581 688
689 pxa_set_ffuart_info(NULL);
690 pxa_set_btuart_info(NULL);
691 pxa_set_stuart_info(NULL);
692
582 z2_lcd_init(); 693 z2_lcd_init();
583 z2_mmc_init(); 694 z2_mmc_init();
584 z2_mkp_init(); 695 z2_mkp_init();
585 696 z2_i2c_init();
586 pxa_set_i2c_info(NULL);
587
588 z2_spi_init(); 697 z2_spi_init();
589 z2_nor_init(); 698 z2_nor_init();
590 z2_pwm_init(); 699 z2_pwm_init();
591 z2_leds_init(); 700 z2_leds_init();
592 z2_keys_init(); 701 z2_keys_init();
702 z2_pmic_init();
593} 703}
594 704
595MACHINE_START(ZIPIT2, "Zipit Z2") 705MACHINE_START(ZIPIT2, "Zipit Z2")
diff --git a/arch/arm/mach-s3c2416/s3c2416.c b/arch/arm/mach-s3c2416/s3c2416.c
index 35dabccd0ac2..bc30245e133b 100644
--- a/arch/arm/mach-s3c2416/s3c2416.c
+++ b/arch/arm/mach-s3c2416/s3c2416.c
@@ -55,6 +55,7 @@
55#include <plat/cpu.h> 55#include <plat/cpu.h>
56 56
57#include <plat/iic-core.h> 57#include <plat/iic-core.h>
58#include <plat/fb-core.h>
58 59
59static struct map_desc s3c2416_iodesc[] __initdata = { 60static struct map_desc s3c2416_iodesc[] __initdata = {
60 IODESC_ENT(WATCHDOG), 61 IODESC_ENT(WATCHDOG),
@@ -90,7 +91,7 @@ int __init s3c2416_init(void)
90 s3c_i2c0_setname("s3c2440-i2c"); 91 s3c_i2c0_setname("s3c2440-i2c");
91 s3c_i2c1_setname("s3c2440-i2c"); 92 s3c_i2c1_setname("s3c2440-i2c");
92 93
93 s3c_device_fb.name = "s3c2443-fb"; 94 s3c_fb_setname("s3c2443-fb");
94 95
95 return sysdev_register(&s3c2416_sysdev); 96 return sysdev_register(&s3c2416_sysdev);
96} 97}
diff --git a/arch/arm/mach-s3c2440/mach-gta02.c b/arch/arm/mach-s3c2440/mach-gta02.c
index 9e39faa283b9..deaabe86741d 100644
--- a/arch/arm/mach-s3c2440/mach-gta02.c
+++ b/arch/arm/mach-s3c2440/mach-gta02.c
@@ -90,24 +90,17 @@
90static struct pcf50633 *gta02_pcf; 90static struct pcf50633 *gta02_pcf;
91 91
92/* 92/*
93 * This gets called every 1ms when we paniced. 93 * This gets called frequently when we paniced.
94 */ 94 */
95 95
96static long gta02_panic_blink(long count) 96static long gta02_panic_blink(int state)
97{ 97{
98 long delay = 0; 98 long delay = 0;
99 static long last_blink; 99 char led;
100 static char led;
101 100
102 /* Fast blink: 200ms period. */ 101 led = (state) ? 1 : 0;
103 if (count - last_blink < 100)
104 return 0;
105
106 led ^= 1;
107 gpio_direction_output(GTA02_GPIO_AUX_LED, led); 102 gpio_direction_output(GTA02_GPIO_AUX_LED, led);
108 103
109 last_blink = count;
110
111 return delay; 104 return delay;
112} 105}
113 106
@@ -556,7 +549,7 @@ static void gta02_poweroff(void)
556 549
557static void __init gta02_machine_init(void) 550static void __init gta02_machine_init(void)
558{ 551{
559 /* Set the panic callback to make AUX LED blink at ~5Hz. */ 552 /* Set the panic callback to turn AUX LED on or off. */
560 panic_blink = gta02_panic_blink; 553 panic_blink = gta02_panic_blink;
561 554
562 s3c_pm_init(); 555 s3c_pm_init();
diff --git a/arch/arm/mach-s3c2443/s3c2443.c b/arch/arm/mach-s3c2443/s3c2443.c
index ce2ec3298930..839b6b2ced74 100644
--- a/arch/arm/mach-s3c2443/s3c2443.c
+++ b/arch/arm/mach-s3c2443/s3c2443.c
@@ -35,6 +35,7 @@
35#include <plat/s3c2443.h> 35#include <plat/s3c2443.h>
36#include <plat/devs.h> 36#include <plat/devs.h>
37#include <plat/cpu.h> 37#include <plat/cpu.h>
38#include <plat/fb-core.h>
38 39
39static struct map_desc s3c2443_iodesc[] __initdata = { 40static struct map_desc s3c2443_iodesc[] __initdata = {
40 IODESC_ENT(WATCHDOG), 41 IODESC_ENT(WATCHDOG),
@@ -62,6 +63,7 @@ int __init s3c2443_init(void)
62 s3c24xx_reset_hook = s3c2443_hard_reset; 63 s3c24xx_reset_hook = s3c2443_hard_reset;
63 64
64 s3c_device_nand.name = "s3c2412-nand"; 65 s3c_device_nand.name = "s3c2412-nand";
66 s3c_fb_setname("s3c2443-fb");
65 67
66 /* change WDT IRQ number */ 68 /* change WDT IRQ number */
67 s3c_device_wdt.resource[1].start = IRQ_S3C2443_WDT; 69 s3c_device_wdt.resource[1].start = IRQ_S3C2443_WDT;
diff --git a/arch/arm/mach-s3c64xx/Kconfig b/arch/arm/mach-s3c64xx/Kconfig
index f5a59727949f..071e8a1e0765 100644
--- a/arch/arm/mach-s3c64xx/Kconfig
+++ b/arch/arm/mach-s3c64xx/Kconfig
@@ -57,11 +57,21 @@ config S3C64XX_SETUP_I2C1
57 help 57 help
58 Common setup code for i2c bus 1. 58 Common setup code for i2c bus 1.
59 59
60config S3C64XX_SETUP_IDE
61 bool
62 help
63 Common setup code for S3C64XX IDE.
64
60config S3C64XX_SETUP_FB_24BPP 65config S3C64XX_SETUP_FB_24BPP
61 bool 66 bool
62 help 67 help
63 Common setup code for S3C64XX with an 24bpp RGB display helper. 68 Common setup code for S3C64XX with an 24bpp RGB display helper.
64 69
70config S3C64XX_SETUP_KEYPAD
71 bool
72 help
73 Common setup code for S3C64XX KEYPAD GPIO configurations
74
65config S3C64XX_SETUP_SDHCI_GPIO 75config S3C64XX_SETUP_SDHCI_GPIO
66 bool 76 bool
67 help 77 help
@@ -95,15 +105,20 @@ config MACH_SMDK6410
95 select S3C_DEV_HSMMC 105 select S3C_DEV_HSMMC
96 select S3C_DEV_HSMMC1 106 select S3C_DEV_HSMMC1
97 select S3C_DEV_I2C1 107 select S3C_DEV_I2C1
108 select SAMSUNG_DEV_IDE
98 select S3C_DEV_FB 109 select S3C_DEV_FB
110 select S3C_DEV_RTC
99 select SAMSUNG_DEV_TS 111 select SAMSUNG_DEV_TS
100 select S3C_DEV_USB_HOST 112 select S3C_DEV_USB_HOST
101 select S3C_DEV_USB_HSOTG 113 select S3C_DEV_USB_HSOTG
102 select S3C_DEV_WDT 114 select S3C_DEV_WDT
115 select SAMSUNG_DEV_KEYPAD
103 select HAVE_S3C2410_WATCHDOG 116 select HAVE_S3C2410_WATCHDOG
104 select S3C64XX_SETUP_SDHCI 117 select S3C64XX_SETUP_SDHCI
105 select S3C64XX_SETUP_I2C1 118 select S3C64XX_SETUP_I2C1
119 select S3C64XX_SETUP_IDE
106 select S3C64XX_SETUP_FB_24BPP 120 select S3C64XX_SETUP_FB_24BPP
121 select S3C64XX_SETUP_KEYPAD
107 help 122 help
108 Machine support for the Samsung SMDK6410 123 Machine support for the Samsung SMDK6410
109 124
diff --git a/arch/arm/mach-s3c64xx/Makefile b/arch/arm/mach-s3c64xx/Makefile
index 9d1006938f5c..48d3dfac8dd7 100644
--- a/arch/arm/mach-s3c64xx/Makefile
+++ b/arch/arm/mach-s3c64xx/Makefile
@@ -35,6 +35,8 @@ obj-$(CONFIG_S3C64XX_DMA) += dma.o
35 35
36obj-$(CONFIG_S3C64XX_SETUP_I2C0) += setup-i2c0.o 36obj-$(CONFIG_S3C64XX_SETUP_I2C0) += setup-i2c0.o
37obj-$(CONFIG_S3C64XX_SETUP_I2C1) += setup-i2c1.o 37obj-$(CONFIG_S3C64XX_SETUP_I2C1) += setup-i2c1.o
38obj-$(CONFIG_S3C64XX_SETUP_IDE) += setup-ide.o
39obj-$(CONFIG_S3C64XX_SETUP_KEYPAD) += setup-keypad.o
38obj-$(CONFIG_S3C64XX_SETUP_SDHCI) += setup-sdhci.o 40obj-$(CONFIG_S3C64XX_SETUP_SDHCI) += setup-sdhci.o
39obj-$(CONFIG_S3C64XX_SETUP_FB_24BPP) += setup-fb-24bpp.o 41obj-$(CONFIG_S3C64XX_SETUP_FB_24BPP) += setup-fb-24bpp.o
40obj-$(CONFIG_S3C64XX_SETUP_SDHCI_GPIO) += setup-sdhci-gpio.o 42obj-$(CONFIG_S3C64XX_SETUP_SDHCI_GPIO) += setup-sdhci-gpio.o
diff --git a/arch/arm/mach-s3c64xx/clock.c b/arch/arm/mach-s3c64xx/clock.c
index fbd85a9b7bbf..7e03f0ae2fc8 100644
--- a/arch/arm/mach-s3c64xx/clock.c
+++ b/arch/arm/mach-s3c64xx/clock.c
@@ -133,6 +133,12 @@ static struct clk init_clocks_disable[] = {
133 .id = -1, 133 .id = -1,
134 .parent = &clk_h, 134 .parent = &clk_h,
135 }, { 135 }, {
136 .name = "rtc",
137 .id = -1,
138 .parent = &clk_p,
139 .enable = s3c64xx_pclk_ctrl,
140 .ctrlbit = S3C_CLKCON_PCLK_RTC,
141 }, {
136 .name = "adc", 142 .name = "adc",
137 .id = -1, 143 .id = -1,
138 .parent = &clk_p, 144 .parent = &clk_p,
@@ -165,6 +171,12 @@ static struct clk init_clocks_disable[] = {
165 .ctrlbit = S3C6410_CLKCON_PCLK_IIS2, 171 .ctrlbit = S3C6410_CLKCON_PCLK_IIS2,
166 }, { 172 }, {
167#endif 173#endif
174 .name = "keypad",
175 .id = -1,
176 .parent = &clk_p,
177 .enable = s3c64xx_pclk_ctrl,
178 .ctrlbit = S3C_CLKCON_PCLK_KEYPAD,
179 }, {
168 .name = "spi", 180 .name = "spi",
169 .id = 0, 181 .id = 0,
170 .parent = &clk_p, 182 .parent = &clk_p,
@@ -295,12 +307,6 @@ static struct clk init_clocks[] = {
295 .enable = s3c64xx_pclk_ctrl, 307 .enable = s3c64xx_pclk_ctrl,
296 .ctrlbit = S3C_CLKCON_PCLK_UART3, 308 .ctrlbit = S3C_CLKCON_PCLK_UART3,
297 }, { 309 }, {
298 .name = "rtc",
299 .id = -1,
300 .parent = &clk_p,
301 .enable = s3c64xx_pclk_ctrl,
302 .ctrlbit = S3C_CLKCON_PCLK_RTC,
303 }, {
304 .name = "watchdog", 310 .name = "watchdog",
305 .id = -1, 311 .id = -1,
306 .parent = &clk_p, 312 .parent = &clk_p,
@@ -310,6 +316,12 @@ static struct clk init_clocks[] = {
310 .id = -1, 316 .id = -1,
311 .parent = &clk_p, 317 .parent = &clk_p,
312 .ctrlbit = S3C_CLKCON_PCLK_AC97, 318 .ctrlbit = S3C_CLKCON_PCLK_AC97,
319 }, {
320 .name = "cfcon",
321 .id = -1,
322 .parent = &clk_h,
323 .enable = s3c64xx_hclk_ctrl,
324 .ctrlbit = S3C_CLKCON_HCLK_IHOST,
313 } 325 }
314}; 326};
315 327
diff --git a/arch/arm/mach-s3c64xx/dev-audio.c b/arch/arm/mach-s3c64xx/dev-audio.c
index c3e9e73bd0f9..9648fbc36eec 100644
--- a/arch/arm/mach-s3c64xx/dev-audio.c
+++ b/arch/arm/mach-s3c64xx/dev-audio.c
@@ -12,11 +12,11 @@
12#include <linux/string.h> 12#include <linux/string.h>
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/dma-mapping.h> 14#include <linux/dma-mapping.h>
15#include <linux/gpio.h>
15 16
16#include <mach/irqs.h> 17#include <mach/irqs.h>
17#include <mach/map.h> 18#include <mach/map.h>
18#include <mach/dma.h> 19#include <mach/dma.h>
19#include <mach/gpio.h>
20 20
21#include <plat/devs.h> 21#include <plat/devs.h>
22#include <plat/audio.h> 22#include <plat/audio.h>
diff --git a/arch/arm/mach-s3c64xx/dev-spi.c b/arch/arm/mach-s3c64xx/dev-spi.c
index 29c32d088515..a492b982aa06 100644
--- a/arch/arm/mach-s3c64xx/dev-spi.c
+++ b/arch/arm/mach-s3c64xx/dev-spi.c
@@ -12,10 +12,10 @@
12#include <linux/string.h> 12#include <linux/string.h>
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/dma-mapping.h> 14#include <linux/dma-mapping.h>
15#include <linux/gpio.h>
15 16
16#include <mach/dma.h> 17#include <mach/dma.h>
17#include <mach/map.h> 18#include <mach/map.h>
18#include <mach/gpio.h>
19#include <mach/gpio-bank-c.h> 19#include <mach/gpio-bank-c.h>
20#include <mach/spi-clocks.h> 20#include <mach/spi-clocks.h>
21 21
diff --git a/arch/arm/mach-s3c64xx/gpiolib.c b/arch/arm/mach-s3c64xx/gpiolib.c
index 60c929a3cab6..300dee4a667b 100644
--- a/arch/arm/mach-s3c64xx/gpiolib.c
+++ b/arch/arm/mach-s3c64xx/gpiolib.c
@@ -15,9 +15,9 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/irq.h> 16#include <linux/irq.h>
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/gpio.h>
18 19
19#include <mach/map.h> 20#include <mach/map.h>
20#include <mach/gpio.h>
21 21
22#include <plat/gpio-core.h> 22#include <plat/gpio-core.h>
23#include <plat/gpio-cfg.h> 23#include <plat/gpio-cfg.h>
diff --git a/arch/arm/mach-s3c64xx/include/mach/map.h b/arch/arm/mach-s3c64xx/include/mach/map.h
index e1eab3c94aea..a1f13f02c841 100644
--- a/arch/arm/mach-s3c64xx/include/mach/map.h
+++ b/arch/arm/mach-s3c64xx/include/mach/map.h
@@ -67,6 +67,7 @@
67#define S3C64XX_PA_USB_HSOTG (0x7C000000) 67#define S3C64XX_PA_USB_HSOTG (0x7C000000)
68#define S3C64XX_PA_WATCHDOG (0x7E004000) 68#define S3C64XX_PA_WATCHDOG (0x7E004000)
69#define S3C64XX_PA_RTC (0x7E005000) 69#define S3C64XX_PA_RTC (0x7E005000)
70#define S3C64XX_PA_KEYPAD (0x7E00A000)
70#define S3C64XX_PA_ADC (0x7E00B000) 71#define S3C64XX_PA_ADC (0x7E00B000)
71#define S3C64XX_PA_SYSCON (0x7E00F000) 72#define S3C64XX_PA_SYSCON (0x7E00F000)
72#define S3C64XX_PA_AC97 (0x7F001000) 73#define S3C64XX_PA_AC97 (0x7F001000)
@@ -86,6 +87,9 @@
86#define S3C64XX_SZ_GPIO SZ_4K 87#define S3C64XX_SZ_GPIO SZ_4K
87 88
88#define S3C64XX_PA_SDRAM (0x50000000) 89#define S3C64XX_PA_SDRAM (0x50000000)
90
91#define S3C64XX_PA_CFCON (0x70300000)
92
89#define S3C64XX_PA_VIC0 (0x71200000) 93#define S3C64XX_PA_VIC0 (0x71200000)
90#define S3C64XX_PA_VIC1 (0x71300000) 94#define S3C64XX_PA_VIC1 (0x71300000)
91 95
@@ -120,5 +124,7 @@
120#define S3C_PA_WDT S3C64XX_PA_WATCHDOG 124#define S3C_PA_WDT S3C64XX_PA_WATCHDOG
121 125
122#define SAMSUNG_PA_ADC S3C64XX_PA_ADC 126#define SAMSUNG_PA_ADC S3C64XX_PA_ADC
127#define SAMSUNG_PA_CFCON S3C64XX_PA_CFCON
128#define SAMSUNG_PA_KEYPAD S3C64XX_PA_KEYPAD
123 129
124#endif /* __ASM_ARCH_6400_MAP_H */ 130#endif /* __ASM_ARCH_6400_MAP_H */
diff --git a/arch/arm/mach-s3c64xx/include/mach/regs-clock.h b/arch/arm/mach-s3c64xx/include/mach/regs-clock.h
index 0114eb0c1fe7..05332b998ec0 100644
--- a/arch/arm/mach-s3c64xx/include/mach/regs-clock.h
+++ b/arch/arm/mach-s3c64xx/include/mach/regs-clock.h
@@ -34,6 +34,7 @@
34#define S3C_SCLK_GATE S3C_CLKREG(0x38) 34#define S3C_SCLK_GATE S3C_CLKREG(0x38)
35#define S3C_MEM0_GATE S3C_CLKREG(0x3C) 35#define S3C_MEM0_GATE S3C_CLKREG(0x3C)
36#define S3C6410_CLK_SRC2 S3C_CLKREG(0x10C) 36#define S3C6410_CLK_SRC2 S3C_CLKREG(0x10C)
37#define S3C_MEM_SYS_CFG S3C_CLKREG(0x120)
37 38
38/* CLKDIV0 */ 39/* CLKDIV0 */
39#define S3C6400_CLKDIV0_PCLK_MASK (0xf << 12) 40#define S3C6400_CLKDIV0_PCLK_MASK (0xf << 12)
@@ -154,4 +155,8 @@
154#define S3C6400_CLKSRC_EPLL_MOUT_SHIFT (2) 155#define S3C6400_CLKSRC_EPLL_MOUT_SHIFT (2)
155#define S3C6400_CLKSRC_MFC (1 << 4) 156#define S3C6400_CLKSRC_MFC (1 << 4)
156 157
158/* MEM_SYS_CFG */
159#define MEM_SYS_CFG_INDEP_CF 0x4000
160#define MEM_SYS_CFG_EBI_FIX_PRI_CFCON 0x30
161
157#endif /* _PLAT_REGS_CLOCK_H */ 162#endif /* _PLAT_REGS_CLOCK_H */
diff --git a/arch/arm/mach-s3c64xx/include/mach/regs-fb.h b/arch/arm/mach-s3c64xx/include/mach/regs-fb.h
index f56611526c63..a06ee0af9a4b 100644
--- a/arch/arm/mach-s3c64xx/include/mach/regs-fb.h
+++ b/arch/arm/mach-s3c64xx/include/mach/regs-fb.h
@@ -18,24 +18,4 @@
18 18
19#include <plat/regs-fb-v4.h> 19#include <plat/regs-fb-v4.h>
20 20
21/* Palette registers */
22#define WIN2_PAL(_entry) (0x300 + ((_entry) * 2))
23#define WIN3_PAL(_entry) (0x320 + ((_entry) * 2))
24#define WIN4_PAL(_entry) (0x340 + ((_entry) * 2))
25#define WIN0_PAL(_entry) (0x400 + ((_entry) * 4))
26#define WIN1_PAL(_entry) (0x800 + ((_entry) * 4))
27
28static inline unsigned int s3c_fb_pal_reg(unsigned int window, int reg)
29{
30 switch (window) {
31 case 0: return WIN0_PAL(reg);
32 case 1: return WIN1_PAL(reg);
33 case 2: return WIN2_PAL(reg);
34 case 3: return WIN3_PAL(reg);
35 case 4: return WIN4_PAL(reg);
36 }
37
38 BUG();
39}
40
41#endif /* __ASM_ARCH_MACH_REGS_FB_H */ 21#endif /* __ASM_ARCH_MACH_REGS_FB_H */
diff --git a/arch/arm/mach-s3c64xx/mach-anw6410.c b/arch/arm/mach-s3c64xx/mach-anw6410.c
index 4a0bb243d14a..742dc87bd9c1 100644
--- a/arch/arm/mach-s3c64xx/mach-anw6410.c
+++ b/arch/arm/mach-s3c64xx/mach-anw6410.c
@@ -134,7 +134,6 @@ static struct platform_device anw6410_lcd_powerdev = {
134static struct s3c_fb_pd_win anw6410_fb_win0 = { 134static struct s3c_fb_pd_win anw6410_fb_win0 = {
135 /* this is to ensure we use win0 */ 135 /* this is to ensure we use win0 */
136 .win_mode = { 136 .win_mode = {
137 .pixclock = 41094,
138 .left_margin = 8, 137 .left_margin = 8,
139 .right_margin = 13, 138 .right_margin = 13,
140 .upper_margin = 7, 139 .upper_margin = 7,
diff --git a/arch/arm/mach-s3c64xx/mach-hmt.c b/arch/arm/mach-s3c64xx/mach-hmt.c
index 187441a78dd5..fba90229f0df 100644
--- a/arch/arm/mach-s3c64xx/mach-hmt.c
+++ b/arch/arm/mach-s3c64xx/mach-hmt.c
@@ -128,7 +128,6 @@ static struct platform_device hmt_backlight_device = {
128 128
129static struct s3c_fb_pd_win hmt_fb_win0 = { 129static struct s3c_fb_pd_win hmt_fb_win0 = {
130 .win_mode = { 130 .win_mode = {
131 .pixclock = 41094,
132 .left_margin = 8, 131 .left_margin = 8,
133 .right_margin = 13, 132 .right_margin = 13,
134 .upper_margin = 7, 133 .upper_margin = 7,
diff --git a/arch/arm/mach-s3c64xx/mach-smartq5.c b/arch/arm/mach-s3c64xx/mach-smartq5.c
index 1d0326ead90f..a065062ec2a4 100644
--- a/arch/arm/mach-s3c64xx/mach-smartq5.c
+++ b/arch/arm/mach-s3c64xx/mach-smartq5.c
@@ -134,8 +134,6 @@ static struct platform_device smartq5_buttons_device = {
134 134
135static struct s3c_fb_pd_win smartq5_fb_win0 = { 135static struct s3c_fb_pd_win smartq5_fb_win0 = {
136 .win_mode = { 136 .win_mode = {
137 .pixclock = 1000000000000ULL /
138 ((40+1+216+800)*(10+1+35+480)*80),
139 .left_margin = 40, 137 .left_margin = 40,
140 .right_margin = 216, 138 .right_margin = 216,
141 .upper_margin = 10, 139 .upper_margin = 10,
@@ -144,6 +142,7 @@ static struct s3c_fb_pd_win smartq5_fb_win0 = {
144 .vsync_len = 1, 142 .vsync_len = 1,
145 .xres = 800, 143 .xres = 800,
146 .yres = 480, 144 .yres = 480,
145 .refresh = 80,
147 }, 146 },
148 .max_bpp = 32, 147 .max_bpp = 32,
149 .default_bpp = 16, 148 .default_bpp = 16,
diff --git a/arch/arm/mach-s3c64xx/mach-smartq7.c b/arch/arm/mach-s3c64xx/mach-smartq7.c
index e0bc78ecb156..0ecf45137546 100644
--- a/arch/arm/mach-s3c64xx/mach-smartq7.c
+++ b/arch/arm/mach-s3c64xx/mach-smartq7.c
@@ -150,8 +150,6 @@ static struct platform_device smartq7_buttons_device = {
150 150
151static struct s3c_fb_pd_win smartq7_fb_win0 = { 151static struct s3c_fb_pd_win smartq7_fb_win0 = {
152 .win_mode = { 152 .win_mode = {
153 .pixclock = 1000000000000ULL /
154 ((3+10+5+800)*(1+3+20+480)*80),
155 .left_margin = 3, 153 .left_margin = 3,
156 .right_margin = 5, 154 .right_margin = 5,
157 .upper_margin = 1, 155 .upper_margin = 1,
@@ -160,6 +158,7 @@ static struct s3c_fb_pd_win smartq7_fb_win0 = {
160 .vsync_len = 3, 158 .vsync_len = 3,
161 .xres = 800, 159 .xres = 800,
162 .yres = 480, 160 .yres = 480,
161 .refresh = 80,
163 }, 162 },
164 .max_bpp = 32, 163 .max_bpp = 32,
165 .default_bpp = 16, 164 .default_bpp = 16,
diff --git a/arch/arm/mach-s3c64xx/mach-smdk6410.c b/arch/arm/mach-s3c64xx/mach-smdk6410.c
index d9a03555f88b..2d43128f939f 100644
--- a/arch/arm/mach-s3c64xx/mach-smdk6410.c
+++ b/arch/arm/mach-s3c64xx/mach-smdk6410.c
@@ -17,6 +17,7 @@
17#include <linux/list.h> 17#include <linux/list.h>
18#include <linux/timer.h> 18#include <linux/timer.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/input.h>
20#include <linux/serial_core.h> 21#include <linux/serial_core.h>
21#include <linux/platform_device.h> 22#include <linux/platform_device.h>
22#include <linux/io.h> 23#include <linux/io.h>
@@ -56,6 +57,7 @@
56#include <mach/regs-gpio.h> 57#include <mach/regs-gpio.h>
57#include <mach/regs-sys.h> 58#include <mach/regs-sys.h>
58#include <mach/regs-srom.h> 59#include <mach/regs-srom.h>
60#include <plat/ata.h>
59#include <plat/iic.h> 61#include <plat/iic.h>
60#include <plat/fb.h> 62#include <plat/fb.h>
61#include <plat/gpio-cfg.h> 63#include <plat/gpio-cfg.h>
@@ -66,6 +68,7 @@
66#include <plat/cpu.h> 68#include <plat/cpu.h>
67#include <plat/adc.h> 69#include <plat/adc.h>
68#include <plat/ts.h> 70#include <plat/ts.h>
71#include <plat/keypad.h>
69 72
70#define UCON S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK 73#define UCON S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK
71#define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB 74#define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
@@ -141,7 +144,6 @@ static struct platform_device smdk6410_lcd_powerdev = {
141static struct s3c_fb_pd_win smdk6410_fb_win0 = { 144static struct s3c_fb_pd_win smdk6410_fb_win0 = {
142 /* this is to ensure we use win0 */ 145 /* this is to ensure we use win0 */
143 .win_mode = { 146 .win_mode = {
144 .pixclock = 41094,
145 .left_margin = 8, 147 .left_margin = 8,
146 .right_margin = 13, 148 .right_margin = 13,
147 .upper_margin = 7, 149 .upper_margin = 7,
@@ -242,6 +244,29 @@ static struct platform_device smdk6410_b_pwr_5v = {
242}; 244};
243#endif 245#endif
244 246
247static struct s3c_ide_platdata smdk6410_ide_pdata __initdata = {
248 .setup_gpio = s3c64xx_ide_setup_gpio,
249};
250
251static uint32_t smdk6410_keymap[] __initdata = {
252 /* KEY(row, col, keycode) */
253 KEY(0, 3, KEY_1), KEY(0, 4, KEY_2), KEY(0, 5, KEY_3),
254 KEY(0, 6, KEY_4), KEY(0, 7, KEY_5),
255 KEY(1, 3, KEY_A), KEY(1, 4, KEY_B), KEY(1, 5, KEY_C),
256 KEY(1, 6, KEY_D), KEY(1, 7, KEY_E)
257};
258
259static struct matrix_keymap_data smdk6410_keymap_data __initdata = {
260 .keymap = smdk6410_keymap,
261 .keymap_size = ARRAY_SIZE(smdk6410_keymap),
262};
263
264static struct samsung_keypad_platdata smdk6410_keypad_data __initdata = {
265 .keymap_data = &smdk6410_keymap_data,
266 .rows = 2,
267 .cols = 8,
268};
269
245static struct map_desc smdk6410_iodesc[] = {}; 270static struct map_desc smdk6410_iodesc[] = {};
246 271
247static struct platform_device *smdk6410_devices[] __initdata = { 272static struct platform_device *smdk6410_devices[] __initdata = {
@@ -257,6 +282,7 @@ static struct platform_device *smdk6410_devices[] __initdata = {
257 &s3c_device_ohci, 282 &s3c_device_ohci,
258 &s3c_device_usb_hsotg, 283 &s3c_device_usb_hsotg,
259 &s3c64xx_device_iisv4, 284 &s3c64xx_device_iisv4,
285 &samsung_device_keypad,
260 286
261#ifdef CONFIG_REGULATOR 287#ifdef CONFIG_REGULATOR
262 &smdk6410_b_pwr_5v, 288 &smdk6410_b_pwr_5v,
@@ -265,6 +291,8 @@ static struct platform_device *smdk6410_devices[] __initdata = {
265 291
266 &smdk6410_smsc911x, 292 &smdk6410_smsc911x,
267 &s3c_device_adc, 293 &s3c_device_adc,
294 &s3c_device_cfcon,
295 &s3c_device_rtc,
268 &s3c_device_ts, 296 &s3c_device_ts,
269 &s3c_device_wdt, 297 &s3c_device_wdt,
270}; 298};
@@ -636,6 +664,8 @@ static void __init smdk6410_machine_init(void)
636 s3c_i2c1_set_platdata(NULL); 664 s3c_i2c1_set_platdata(NULL);
637 s3c_fb_set_platdata(&smdk6410_lcd_pdata); 665 s3c_fb_set_platdata(&smdk6410_lcd_pdata);
638 666
667 samsung_keypad_set_platdata(&smdk6410_keypad_data);
668
639 s3c24xx_ts_set_platdata(&s3c_ts_platform); 669 s3c24xx_ts_set_platdata(&s3c_ts_platform);
640 670
641 /* configure nCS1 width to 16 bits */ 671 /* configure nCS1 width to 16 bits */
@@ -665,6 +695,8 @@ static void __init smdk6410_machine_init(void)
665 i2c_register_board_info(0, i2c_devs0, ARRAY_SIZE(i2c_devs0)); 695 i2c_register_board_info(0, i2c_devs0, ARRAY_SIZE(i2c_devs0));
666 i2c_register_board_info(1, i2c_devs1, ARRAY_SIZE(i2c_devs1)); 696 i2c_register_board_info(1, i2c_devs1, ARRAY_SIZE(i2c_devs1));
667 697
698 s3c_ide_set_platdata(&smdk6410_ide_pdata);
699
668 platform_add_devices(smdk6410_devices, ARRAY_SIZE(smdk6410_devices)); 700 platform_add_devices(smdk6410_devices, ARRAY_SIZE(smdk6410_devices));
669} 701}
670 702
diff --git a/arch/arm/mach-s3c64xx/s3c6410.c b/arch/arm/mach-s3c64xx/s3c6410.c
index 014401c39f36..312aa6b115e8 100644
--- a/arch/arm/mach-s3c64xx/s3c6410.c
+++ b/arch/arm/mach-s3c64xx/s3c6410.c
@@ -37,8 +37,9 @@
37#include <plat/devs.h> 37#include <plat/devs.h>
38#include <plat/clock.h> 38#include <plat/clock.h>
39#include <plat/sdhci.h> 39#include <plat/sdhci.h>
40#include <plat/ata-core.h>
41#include <plat/adc-core.h>
40#include <plat/iic-core.h> 42#include <plat/iic-core.h>
41#include <plat/adc.h>
42#include <plat/onenand-core.h> 43#include <plat/onenand-core.h>
43#include <mach/s3c6400.h> 44#include <mach/s3c6400.h>
44#include <mach/s3c6410.h> 45#include <mach/s3c6410.h>
@@ -54,10 +55,11 @@ void __init s3c6410_map_io(void)
54 s3c_i2c0_setname("s3c2440-i2c"); 55 s3c_i2c0_setname("s3c2440-i2c");
55 s3c_i2c1_setname("s3c2440-i2c"); 56 s3c_i2c1_setname("s3c2440-i2c");
56 57
57 s3c_device_adc.name = "s3c64xx-adc"; 58 s3c_adc_setname("s3c64xx-adc");
58 s3c_device_nand.name = "s3c6400-nand"; 59 s3c_device_nand.name = "s3c6400-nand";
59 s3c_onenand_setname("s3c6410-onenand"); 60 s3c_onenand_setname("s3c6410-onenand");
60 s3c64xx_onenand1_setname("s3c6410-onenand"); 61 s3c64xx_onenand1_setname("s3c6410-onenand");
62 s3c_cfcon_setname("s3c64xx-pata");
61} 63}
62 64
63void __init s3c6410_init_clocks(int xtal) 65void __init s3c6410_init_clocks(int xtal)
diff --git a/arch/arm/mach-s3c64xx/setup-fb-24bpp.c b/arch/arm/mach-s3c64xx/setup-fb-24bpp.c
index 8e28e448dd20..000736877df2 100644
--- a/arch/arm/mach-s3c64xx/setup-fb-24bpp.c
+++ b/arch/arm/mach-s3c64xx/setup-fb-24bpp.c
@@ -15,9 +15,9 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/fb.h> 17#include <linux/fb.h>
18#include <linux/gpio.h>
18 19
19#include <mach/regs-fb.h> 20#include <mach/regs-fb.h>
20#include <mach/gpio.h>
21#include <plat/fb.h> 21#include <plat/fb.h>
22#include <plat/gpio-cfg.h> 22#include <plat/gpio-cfg.h>
23 23
diff --git a/arch/arm/mach-s3c64xx/setup-i2c0.c b/arch/arm/mach-s3c64xx/setup-i2c0.c
index d1b11e6e77e8..406192a43c6e 100644
--- a/arch/arm/mach-s3c64xx/setup-i2c0.c
+++ b/arch/arm/mach-s3c64xx/setup-i2c0.c
@@ -14,10 +14,10 @@
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/gpio.h>
17 18
18struct platform_device; /* don't need the contents */ 19struct platform_device; /* don't need the contents */
19 20
20#include <mach/gpio.h>
21#include <mach/gpio-bank-b.h> 21#include <mach/gpio-bank-b.h>
22#include <plat/iic.h> 22#include <plat/iic.h>
23#include <plat/gpio-cfg.h> 23#include <plat/gpio-cfg.h>
diff --git a/arch/arm/mach-s3c64xx/setup-i2c1.c b/arch/arm/mach-s3c64xx/setup-i2c1.c
index 2dce57d8c6f8..1ee62c97cd7f 100644
--- a/arch/arm/mach-s3c64xx/setup-i2c1.c
+++ b/arch/arm/mach-s3c64xx/setup-i2c1.c
@@ -14,10 +14,10 @@
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/gpio.h>
17 18
18struct platform_device; /* don't need the contents */ 19struct platform_device; /* don't need the contents */
19 20
20#include <mach/gpio.h>
21#include <mach/gpio-bank-b.h> 21#include <mach/gpio-bank-b.h>
22#include <plat/iic.h> 22#include <plat/iic.h>
23#include <plat/gpio-cfg.h> 23#include <plat/gpio-cfg.h>
diff --git a/arch/arm/mach-s3c64xx/setup-ide.c b/arch/arm/mach-s3c64xx/setup-ide.c
new file mode 100644
index 000000000000..c12c315f33bc
--- /dev/null
+++ b/arch/arm/mach-s3c64xx/setup-ide.c
@@ -0,0 +1,46 @@
1/* linux/arch/arm/mach-s3c64xx/setup-ide.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * S3C64XX setup information for IDE
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#include <linux/kernel.h>
14#include <linux/gpio.h>
15#include <linux/io.h>
16
17#include <mach/map.h>
18#include <mach/regs-clock.h>
19#include <plat/gpio-cfg.h>
20
21void s3c64xx_ide_setup_gpio(void)
22{
23 u32 reg;
24 u32 gpio = 0;
25
26 reg = readl(S3C_MEM_SYS_CFG) & (~0x3f);
27
28 /* Independent CF interface, CF chip select configuration */
29 writel(reg | MEM_SYS_CFG_INDEP_CF |
30 MEM_SYS_CFG_EBI_FIX_PRI_CFCON, S3C_MEM_SYS_CFG);
31
32 s3c_gpio_cfgpin(S3C64XX_GPB(4), S3C_GPIO_SFN(4));
33
34 /* Set XhiDATA[15:0] pins as CF Data[15:0] */
35 for (gpio = S3C64XX_GPK(0); gpio <= S3C64XX_GPK(15); gpio++)
36 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(5));
37
38 /* Set XhiADDR[2:0] pins as CF ADDR[2:0] */
39 for (gpio = S3C64XX_GPL(0); gpio <= S3C64XX_GPL(2); gpio++)
40 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(6));
41
42 /* Set Xhi ctrl pins as CF ctrl pins(IORDY, IOWR, IORD, CE[0:1]) */
43 s3c_gpio_cfgpin(S3C64XX_GPM(5), S3C_GPIO_SFN(1));
44 for (gpio = S3C64XX_GPM(0); gpio <= S3C64XX_GPM(4); gpio++)
45 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(6));
46}
diff --git a/arch/arm/mach-s3c64xx/setup-keypad.c b/arch/arm/mach-s3c64xx/setup-keypad.c
new file mode 100644
index 000000000000..abc34e4e1a93
--- /dev/null
+++ b/arch/arm/mach-s3c64xx/setup-keypad.c
@@ -0,0 +1,34 @@
1/* linux/arch/arm/mach-s3c64xx/setup-keypad.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * GPIO configuration for S3C64XX KeyPad device
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#include <linux/gpio.h>
14#include <plat/gpio-cfg.h>
15
16void samsung_keypad_cfg_gpio(unsigned int rows, unsigned int cols)
17{
18 unsigned int gpio;
19 unsigned int end;
20
21 /* Set all the necessary GPK pins to special-function 3: KP_ROW[x] */
22 end = S3C64XX_GPK(8 + rows);
23 for (gpio = S3C64XX_GPK(8); gpio < end; gpio++) {
24 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(3));
25 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
26 }
27
28 /* Set all the necessary GPL pins to special-function 3: KP_COL[x] */
29 end = S3C64XX_GPL(0 + cols);
30 for (gpio = S3C64XX_GPL(0); gpio < end; gpio++) {
31 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(3));
32 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
33 }
34}
diff --git a/arch/arm/mach-s3c64xx/setup-sdhci-gpio.c b/arch/arm/mach-s3c64xx/setup-sdhci-gpio.c
index a58c0cc7ba5e..322359591374 100644
--- a/arch/arm/mach-s3c64xx/setup-sdhci-gpio.c
+++ b/arch/arm/mach-s3c64xx/setup-sdhci-gpio.c
@@ -16,12 +16,14 @@
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/io.h> 18#include <linux/io.h>
19#include <linux/gpio.h>
19 20
20#include <mach/gpio.h>
21#include <plat/gpio-cfg.h> 21#include <plat/gpio-cfg.h>
22#include <plat/sdhci.h>
22 23
23void s3c64xx_setup_sdhci0_cfg_gpio(struct platform_device *dev, int width) 24void s3c64xx_setup_sdhci0_cfg_gpio(struct platform_device *dev, int width)
24{ 25{
26 struct s3c_sdhci_platdata *pdata = dev->dev.platform_data;
25 unsigned int gpio; 27 unsigned int gpio;
26 unsigned int end; 28 unsigned int end;
27 29
@@ -33,12 +35,15 @@ void s3c64xx_setup_sdhci0_cfg_gpio(struct platform_device *dev, int width)
33 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE); 35 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
34 } 36 }
35 37
36 s3c_gpio_setpull(S3C64XX_GPG(6), S3C_GPIO_PULL_UP); 38 if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) {
37 s3c_gpio_cfgpin(S3C64XX_GPG(6), S3C_GPIO_SFN(2)); 39 s3c_gpio_setpull(S3C64XX_GPG(6), S3C_GPIO_PULL_UP);
40 s3c_gpio_cfgpin(S3C64XX_GPG(6), S3C_GPIO_SFN(2));
41 }
38} 42}
39 43
40void s3c64xx_setup_sdhci1_cfg_gpio(struct platform_device *dev, int width) 44void s3c64xx_setup_sdhci1_cfg_gpio(struct platform_device *dev, int width)
41{ 45{
46 struct s3c_sdhci_platdata *pdata = dev->dev.platform_data;
42 unsigned int gpio; 47 unsigned int gpio;
43 unsigned int end; 48 unsigned int end;
44 49
@@ -50,8 +55,10 @@ void s3c64xx_setup_sdhci1_cfg_gpio(struct platform_device *dev, int width)
50 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE); 55 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
51 } 56 }
52 57
53 s3c_gpio_setpull(S3C64XX_GPG(6), S3C_GPIO_PULL_UP); 58 if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) {
54 s3c_gpio_cfgpin(S3C64XX_GPG(6), S3C_GPIO_SFN(3)); 59 s3c_gpio_setpull(S3C64XX_GPG(6), S3C_GPIO_PULL_UP);
60 s3c_gpio_cfgpin(S3C64XX_GPG(6), S3C_GPIO_SFN(3));
61 }
55} 62}
56 63
57void s3c64xx_setup_sdhci2_cfg_gpio(struct platform_device *dev, int width) 64void s3c64xx_setup_sdhci2_cfg_gpio(struct platform_device *dev, int width)
diff --git a/arch/arm/mach-s5p6440/Kconfig b/arch/arm/mach-s5p6440/Kconfig
index f066fae07c57..6a4af7f57584 100644
--- a/arch/arm/mach-s5p6440/Kconfig
+++ b/arch/arm/mach-s5p6440/Kconfig
@@ -13,13 +13,20 @@ config CPU_S5P6440
13 help 13 help
14 Enable S5P6440 CPU support 14 Enable S5P6440 CPU support
15 15
16config S5P6440_SETUP_I2C1
17 bool
18 help
19 Common setup code for i2c bus 1.
20
16config MACH_SMDK6440 21config MACH_SMDK6440
17 bool "SMDK6440" 22 bool "SMDK6440"
18 select CPU_S5P6440 23 select CPU_S5P6440
19 select SAMSUNG_DEV_TS 24 select S3C_DEV_I2C1
20 select SAMSUNG_DEV_ADC 25 select S3C_DEV_RTC
21 select S3C_DEV_WDT 26 select S3C_DEV_WDT
22 select HAVE_S3C2410_WATCHDOG 27 select SAMSUNG_DEV_ADC
28 select SAMSUNG_DEV_TS
29 select S5P6440_SETUP_I2C1
23 help 30 help
24 Machine support for the Samsung SMDK6440 31 Machine support for the Samsung SMDK6440
25 32
diff --git a/arch/arm/mach-s5p6440/Makefile b/arch/arm/mach-s5p6440/Makefile
index be3c53aab23f..c3fe4d3662a9 100644
--- a/arch/arm/mach-s5p6440/Makefile
+++ b/arch/arm/mach-s5p6440/Makefile
@@ -22,3 +22,4 @@ obj-$(CONFIG_MACH_SMDK6440) += mach-smdk6440.o
22# device support 22# device support
23obj-y += dev-audio.o 23obj-y += dev-audio.o
24obj-$(CONFIG_S3C64XX_DEV_SPI) += dev-spi.o 24obj-$(CONFIG_S3C64XX_DEV_SPI) += dev-spi.o
25obj-$(CONFIG_S5P6440_SETUP_I2C1) += setup-i2c1.o
diff --git a/arch/arm/mach-s5p6440/cpu.c b/arch/arm/mach-s5p6440/cpu.c
index b2fe6a58155a..526f33adb31d 100644
--- a/arch/arm/mach-s5p6440/cpu.c
+++ b/arch/arm/mach-s5p6440/cpu.c
@@ -37,6 +37,7 @@
37#include <plat/devs.h> 37#include <plat/devs.h>
38#include <plat/clock.h> 38#include <plat/clock.h>
39#include <plat/s5p6440.h> 39#include <plat/s5p6440.h>
40#include <plat/adc-core.h>
40 41
41static void s5p6440_idle(void) 42static void s5p6440_idle(void)
42{ 43{
@@ -61,7 +62,7 @@ static void s5p6440_idle(void)
61void __init s5p6440_map_io(void) 62void __init s5p6440_map_io(void)
62{ 63{
63 /* initialize any device information early */ 64 /* initialize any device information early */
64 s3c_device_adc.name = "s3c64xx-adc"; 65 s3c_adc_setname("s3c64xx-adc");
65} 66}
66 67
67void __init s5p6440_init_clocks(int xtal) 68void __init s5p6440_init_clocks(int xtal)
diff --git a/arch/arm/mach-s5p6440/dev-audio.c b/arch/arm/mach-s5p6440/dev-audio.c
index 0c5367962830..3ca0d2b8275d 100644
--- a/arch/arm/mach-s5p6440/dev-audio.c
+++ b/arch/arm/mach-s5p6440/dev-audio.c
@@ -10,11 +10,11 @@
10 10
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
13#include <linux/gpio.h>
13 14
14#include <plat/gpio-cfg.h> 15#include <plat/gpio-cfg.h>
15#include <plat/audio.h> 16#include <plat/audio.h>
16 17
17#include <mach/gpio.h>
18#include <mach/map.h> 18#include <mach/map.h>
19#include <mach/dma.h> 19#include <mach/dma.h>
20#include <mach/irqs.h> 20#include <mach/irqs.h>
diff --git a/arch/arm/mach-s5p6440/dev-spi.c b/arch/arm/mach-s5p6440/dev-spi.c
index 0a30280019c0..510af44d180c 100644
--- a/arch/arm/mach-s5p6440/dev-spi.c
+++ b/arch/arm/mach-s5p6440/dev-spi.c
@@ -10,11 +10,11 @@
10 10
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
13#include <linux/gpio.h>
13 14
14#include <mach/dma.h> 15#include <mach/dma.h>
15#include <mach/map.h> 16#include <mach/map.h>
16#include <mach/irqs.h> 17#include <mach/irqs.h>
17#include <mach/gpio.h>
18#include <mach/spi-clocks.h> 18#include <mach/spi-clocks.h>
19 19
20#include <plat/s3c64xx-spi.h> 20#include <plat/s3c64xx-spi.h>
diff --git a/arch/arm/mach-s5p6440/gpio.c b/arch/arm/mach-s5p6440/gpio.c
index 92efc05b1ba2..8bf6e0ce51c9 100644
--- a/arch/arm/mach-s5p6440/gpio.c
+++ b/arch/arm/mach-s5p6440/gpio.c
@@ -13,9 +13,11 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/irq.h> 14#include <linux/irq.h>
15#include <linux/io.h> 15#include <linux/io.h>
16#include <linux/gpio.h>
17
16#include <mach/map.h> 18#include <mach/map.h>
17#include <mach/gpio.h>
18#include <mach/regs-gpio.h> 19#include <mach/regs-gpio.h>
20
19#include <plat/gpio-core.h> 21#include <plat/gpio-core.h>
20#include <plat/gpio-cfg.h> 22#include <plat/gpio-cfg.h>
21#include <plat/gpio-cfg-helpers.h> 23#include <plat/gpio-cfg-helpers.h>
diff --git a/arch/arm/mach-s5p6440/include/mach/irqs.h b/arch/arm/mach-s5p6440/include/mach/irqs.h
index 911854d9ad42..16a761270de1 100644
--- a/arch/arm/mach-s5p6440/include/mach/irqs.h
+++ b/arch/arm/mach-s5p6440/include/mach/irqs.h
@@ -51,7 +51,7 @@
51#define IRQ_DISPCON3 S5P_IRQ_VIC1(19) 51#define IRQ_DISPCON3 S5P_IRQ_VIC1(19)
52#define IRQ_FIMGVG S5P_IRQ_VIC1(20) 52#define IRQ_FIMGVG S5P_IRQ_VIC1(20)
53#define IRQ_EINT_GROUPS S5P_IRQ_VIC1(21) 53#define IRQ_EINT_GROUPS S5P_IRQ_VIC1(21)
54#define IRQ_PMUIRQ S5P_IRQ_VIC1(23) 54#define IRQ_PMU S5P_IRQ_VIC1(23)
55#define IRQ_HSMMC0 S5P_IRQ_VIC1(24) 55#define IRQ_HSMMC0 S5P_IRQ_VIC1(24)
56#define IRQ_HSMMC1 S5P_IRQ_VIC1(25) 56#define IRQ_HSMMC1 S5P_IRQ_VIC1(25)
57#define IRQ_HSMMC2 IRQ_SPI1 /* shared with SPI1 */ 57#define IRQ_HSMMC2 IRQ_SPI1 /* shared with SPI1 */
diff --git a/arch/arm/mach-s5p6440/include/mach/map.h b/arch/arm/mach-s5p6440/include/mach/map.h
index 44011b91fbd1..6cc5cbc88ffb 100644
--- a/arch/arm/mach-s5p6440/include/mach/map.h
+++ b/arch/arm/mach-s5p6440/include/mach/map.h
@@ -38,7 +38,6 @@
38#define S5P_PA_TIMER S5P6440_PA_TIMER 38#define S5P_PA_TIMER S5P6440_PA_TIMER
39 39
40#define S5P6440_PA_RTC (0xEA100000) 40#define S5P6440_PA_RTC (0xEA100000)
41#define S5P_PA_RTC S5P6440_PA_RTC
42 41
43#define S5P6440_PA_WDT (0xEA200000) 42#define S5P6440_PA_WDT (0xEA200000)
44#define S5P_PA_WDT S5P6440_PA_WDT 43#define S5P_PA_WDT S5P6440_PA_WDT
@@ -53,6 +52,7 @@
53#define S5P_SZ_UART SZ_256 52#define S5P_SZ_UART SZ_256
54 53
55#define S5P6440_PA_IIC0 (0xEC104000) 54#define S5P6440_PA_IIC0 (0xEC104000)
55#define S5P6440_PA_IIC1 (0xEC20F000)
56 56
57#define S5P6440_PA_SPI0 0xEC400000 57#define S5P6440_PA_SPI0 0xEC400000
58#define S5P6440_PA_SPI1 0xEC500000 58#define S5P6440_PA_SPI1 0xEC500000
@@ -77,6 +77,8 @@
77/* compatibiltiy defines. */ 77/* compatibiltiy defines. */
78#define S3C_PA_UART S5P6440_PA_UART 78#define S3C_PA_UART S5P6440_PA_UART
79#define S3C_PA_IIC S5P6440_PA_IIC0 79#define S3C_PA_IIC S5P6440_PA_IIC0
80#define S3C_PA_RTC S5P6440_PA_RTC
81#define S3C_PA_IIC1 S5P6440_PA_IIC1
80#define S3C_PA_WDT S5P6440_PA_WDT 82#define S3C_PA_WDT S5P6440_PA_WDT
81 83
82#define SAMSUNG_PA_ADC S5P6440_PA_ADC 84#define SAMSUNG_PA_ADC S5P6440_PA_ADC
diff --git a/arch/arm/mach-s5p6440/include/mach/system.h b/arch/arm/mach-s5p6440/include/mach/system.h
index d2dd817da66a..a359ee3fa510 100644
--- a/arch/arm/mach-s5p6440/include/mach/system.h
+++ b/arch/arm/mach-s5p6440/include/mach/system.h
@@ -13,12 +13,9 @@
13#ifndef __ASM_ARCH_SYSTEM_H 13#ifndef __ASM_ARCH_SYSTEM_H
14#define __ASM_ARCH_SYSTEM_H __FILE__ 14#define __ASM_ARCH_SYSTEM_H __FILE__
15 15
16static void arch_idle(void) 16#include <plat/system-reset.h>
17{
18 /* nothing here yet */
19}
20 17
21static void arch_reset(char mode, const char *cmd) 18static void arch_idle(void)
22{ 19{
23 /* nothing here yet */ 20 /* nothing here yet */
24} 21}
diff --git a/arch/arm/mach-s5p6440/mach-smdk6440.c b/arch/arm/mach-s5p6440/mach-smdk6440.c
index 8291fecc701a..9202aaac3b56 100644
--- a/arch/arm/mach-s5p6440/mach-smdk6440.c
+++ b/arch/arm/mach-s5p6440/mach-smdk6440.c
@@ -15,6 +15,7 @@
15#include <linux/timer.h> 15#include <linux/timer.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/i2c.h>
18#include <linux/serial_core.h> 19#include <linux/serial_core.h>
19#include <linux/platform_device.h> 20#include <linux/platform_device.h>
20#include <linux/io.h> 21#include <linux/io.h>
@@ -37,20 +38,21 @@
37#include <mach/regs-clock.h> 38#include <mach/regs-clock.h>
38#include <plat/devs.h> 39#include <plat/devs.h>
39#include <plat/cpu.h> 40#include <plat/cpu.h>
41#include <plat/iic.h>
40#include <plat/pll.h> 42#include <plat/pll.h>
41#include <plat/adc.h> 43#include <plat/adc.h>
42#include <plat/ts.h> 44#include <plat/ts.h>
43 45
44#define S5P6440_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \ 46#define SMDK6440_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \
45 S3C2410_UCON_RXILEVEL | \ 47 S3C2410_UCON_RXILEVEL | \
46 S3C2410_UCON_TXIRQMODE | \ 48 S3C2410_UCON_TXIRQMODE | \
47 S3C2410_UCON_RXIRQMODE | \ 49 S3C2410_UCON_RXIRQMODE | \
48 S3C2410_UCON_RXFIFO_TOI | \ 50 S3C2410_UCON_RXFIFO_TOI | \
49 S3C2443_UCON_RXERR_IRQEN) 51 S3C2443_UCON_RXERR_IRQEN)
50 52
51#define S5P6440_ULCON_DEFAULT S3C2410_LCON_CS8 53#define SMDK6440_ULCON_DEFAULT S3C2410_LCON_CS8
52 54
53#define S5P6440_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \ 55#define SMDK6440_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \
54 S3C2440_UFCON_TXTRIG16 | \ 56 S3C2440_UFCON_TXTRIG16 | \
55 S3C2410_UFCON_RXTRIG8) 57 S3C2410_UFCON_RXTRIG8)
56 58
@@ -58,40 +60,51 @@ static struct s3c2410_uartcfg smdk6440_uartcfgs[] __initdata = {
58 [0] = { 60 [0] = {
59 .hwport = 0, 61 .hwport = 0,
60 .flags = 0, 62 .flags = 0,
61 .ucon = S5P6440_UCON_DEFAULT, 63 .ucon = SMDK6440_UCON_DEFAULT,
62 .ulcon = S5P6440_ULCON_DEFAULT, 64 .ulcon = SMDK6440_ULCON_DEFAULT,
63 .ufcon = S5P6440_UFCON_DEFAULT, 65 .ufcon = SMDK6440_UFCON_DEFAULT,
64 }, 66 },
65 [1] = { 67 [1] = {
66 .hwport = 1, 68 .hwport = 1,
67 .flags = 0, 69 .flags = 0,
68 .ucon = S5P6440_UCON_DEFAULT, 70 .ucon = SMDK6440_UCON_DEFAULT,
69 .ulcon = S5P6440_ULCON_DEFAULT, 71 .ulcon = SMDK6440_ULCON_DEFAULT,
70 .ufcon = S5P6440_UFCON_DEFAULT, 72 .ufcon = SMDK6440_UFCON_DEFAULT,
71 }, 73 },
72 [2] = { 74 [2] = {
73 .hwport = 2, 75 .hwport = 2,
74 .flags = 0, 76 .flags = 0,
75 .ucon = S5P6440_UCON_DEFAULT, 77 .ucon = SMDK6440_UCON_DEFAULT,
76 .ulcon = S5P6440_ULCON_DEFAULT, 78 .ulcon = SMDK6440_ULCON_DEFAULT,
77 .ufcon = S5P6440_UFCON_DEFAULT, 79 .ufcon = SMDK6440_UFCON_DEFAULT,
78 }, 80 },
79 [3] = { 81 [3] = {
80 .hwport = 3, 82 .hwport = 3,
81 .flags = 0, 83 .flags = 0,
82 .ucon = S5P6440_UCON_DEFAULT, 84 .ucon = SMDK6440_UCON_DEFAULT,
83 .ulcon = S5P6440_ULCON_DEFAULT, 85 .ulcon = SMDK6440_ULCON_DEFAULT,
84 .ufcon = S5P6440_UFCON_DEFAULT, 86 .ufcon = SMDK6440_UFCON_DEFAULT,
85 }, 87 },
86}; 88};
87 89
88static struct platform_device *smdk6440_devices[] __initdata = { 90static struct platform_device *smdk6440_devices[] __initdata = {
89 &s5p6440_device_iis, 91 &s5p6440_device_iis,
90 &s3c_device_adc, 92 &s3c_device_adc,
93 &s3c_device_rtc,
94 &s3c_device_i2c0,
95 &s3c_device_i2c1,
91 &s3c_device_ts, 96 &s3c_device_ts,
92 &s3c_device_wdt, 97 &s3c_device_wdt,
93}; 98};
94 99
100static struct i2c_board_info smdk6440_i2c_devs0[] __initdata = {
101 { I2C_BOARD_INFO("24c08", 0x50), },
102};
103
104static struct i2c_board_info smdk6440_i2c_devs1[] __initdata = {
105 /* To be populated */
106};
107
95static struct s3c2410_ts_mach_info s3c_ts_platform __initdata = { 108static struct s3c2410_ts_mach_info s3c_ts_platform __initdata = {
96 .delay = 10000, 109 .delay = 10000,
97 .presc = 49, 110 .presc = 49,
@@ -109,6 +122,14 @@ static void __init smdk6440_machine_init(void)
109{ 122{
110 s3c24xx_ts_set_platdata(&s3c_ts_platform); 123 s3c24xx_ts_set_platdata(&s3c_ts_platform);
111 124
125 /* I2C */
126 s3c_i2c0_set_platdata(NULL);
127 s3c_i2c1_set_platdata(NULL);
128 i2c_register_board_info(0, smdk6440_i2c_devs0,
129 ARRAY_SIZE(smdk6440_i2c_devs0));
130 i2c_register_board_info(1, smdk6440_i2c_devs1,
131 ARRAY_SIZE(smdk6440_i2c_devs1));
132
112 platform_add_devices(smdk6440_devices, ARRAY_SIZE(smdk6440_devices)); 133 platform_add_devices(smdk6440_devices, ARRAY_SIZE(smdk6440_devices));
113} 134}
114 135
diff --git a/arch/arm/mach-s5p6440/setup-i2c0.c b/arch/arm/mach-s5p6440/setup-i2c0.c
index 69e8a664aedb..2c99d14f7ac7 100644
--- a/arch/arm/mach-s5p6440/setup-i2c0.c
+++ b/arch/arm/mach-s5p6440/setup-i2c0.c
@@ -17,9 +17,14 @@
17 17
18struct platform_device; /* don't need the contents */ 18struct platform_device; /* don't need the contents */
19 19
20#include <linux/gpio.h>
21#include <plat/gpio-cfg.h>
20#include <plat/iic.h> 22#include <plat/iic.h>
21 23
22void s3c_i2c0_cfg_gpio(struct platform_device *dev) 24void s3c_i2c0_cfg_gpio(struct platform_device *dev)
23{ 25{
24 /* Will be populated later */ 26 s3c_gpio_cfgpin(S5P6440_GPB(5), S3C_GPIO_SFN(2));
27 s3c_gpio_setpull(S5P6440_GPB(5), S3C_GPIO_PULL_UP);
28 s3c_gpio_cfgpin(S5P6440_GPB(6), S3C_GPIO_SFN(2));
29 s3c_gpio_setpull(S5P6440_GPB(6), S3C_GPIO_PULL_UP);
25} 30}
diff --git a/arch/arm/mach-s5p6440/setup-i2c1.c b/arch/arm/mach-s5p6440/setup-i2c1.c
new file mode 100644
index 000000000000..9a1537f786e0
--- /dev/null
+++ b/arch/arm/mach-s5p6440/setup-i2c1.c
@@ -0,0 +1,30 @@
1/* linux/arch/arm/mach-s5p6440/setup-i2c1.c
2 *
3 * Copyright (c) 2009 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * I2C1 GPIO configuration.
7 *
8 * Based on plat-s3c64xx/setup-i2c0.c
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13*/
14
15#include <linux/kernel.h>
16#include <linux/types.h>
17#include <linux/gpio.h>
18
19struct platform_device; /* don't need the contents */
20
21#include <plat/gpio-cfg.h>
22#include <plat/iic.h>
23
24void s3c_i2c1_cfg_gpio(struct platform_device *dev)
25{
26 s3c_gpio_cfgpin(S5P6440_GPR(9), S3C_GPIO_SFN(6));
27 s3c_gpio_setpull(S5P6440_GPR(9), S3C_GPIO_PULL_UP);
28 s3c_gpio_cfgpin(S5P6440_GPR(10), S3C_GPIO_SFN(6));
29 s3c_gpio_setpull(S5P6440_GPR(10), S3C_GPIO_PULL_UP);
30}
diff --git a/arch/arm/mach-s5p6442/Kconfig b/arch/arm/mach-s5p6442/Kconfig
index 0fd41b447915..0fda0a5df968 100644
--- a/arch/arm/mach-s5p6442/Kconfig
+++ b/arch/arm/mach-s5p6442/Kconfig
@@ -19,6 +19,7 @@ config CPU_S5P6442
19config MACH_SMDK6442 19config MACH_SMDK6442
20 bool "SMDK6442" 20 bool "SMDK6442"
21 select CPU_S5P6442 21 select CPU_S5P6442
22 select S3C_DEV_WDT
22 help 23 help
23 Machine support for Samsung SMDK6442 24 Machine support for Samsung SMDK6442
24 25
diff --git a/arch/arm/mach-s5p6442/clock.c b/arch/arm/mach-s5p6442/clock.c
index 087e57f20ad5..dcd20f17212a 100644
--- a/arch/arm/mach-s5p6442/clock.c
+++ b/arch/arm/mach-s5p6442/clock.c
@@ -361,6 +361,12 @@ static struct clk init_clocks[] = {
361 .enable = s5p6442_clk_ip3_ctrl, 361 .enable = s5p6442_clk_ip3_ctrl,
362 .ctrlbit = (1<<19), 362 .ctrlbit = (1<<19),
363 }, { 363 }, {
364 .name = "watchdog",
365 .id = -1,
366 .parent = &clk_pclkd1,
367 .enable = s5p6442_clk_ip3_ctrl,
368 .ctrlbit = (1 << 22),
369 }, {
364 .name = "timers", 370 .name = "timers",
365 .id = -1, 371 .id = -1,
366 .parent = &clk_pclkd1, 372 .parent = &clk_pclkd1,
diff --git a/arch/arm/mach-s5p6442/dev-audio.c b/arch/arm/mach-s5p6442/dev-audio.c
index cb801e1f5e23..7a4e34720b7b 100644
--- a/arch/arm/mach-s5p6442/dev-audio.c
+++ b/arch/arm/mach-s5p6442/dev-audio.c
@@ -10,11 +10,11 @@
10 10
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
13#include <linux/gpio.h>
13 14
14#include <plat/gpio-cfg.h> 15#include <plat/gpio-cfg.h>
15#include <plat/audio.h> 16#include <plat/audio.h>
16 17
17#include <mach/gpio.h>
18#include <mach/map.h> 18#include <mach/map.h>
19#include <mach/dma.h> 19#include <mach/dma.h>
20#include <mach/irqs.h> 20#include <mach/irqs.h>
diff --git a/arch/arm/mach-s5p6442/dev-spi.c b/arch/arm/mach-s5p6442/dev-spi.c
index 30199525daca..e894651a88bd 100644
--- a/arch/arm/mach-s5p6442/dev-spi.c
+++ b/arch/arm/mach-s5p6442/dev-spi.c
@@ -10,11 +10,11 @@
10 10
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
13#include <linux/gpio.h>
13 14
14#include <mach/dma.h> 15#include <mach/dma.h>
15#include <mach/map.h> 16#include <mach/map.h>
16#include <mach/irqs.h> 17#include <mach/irqs.h>
17#include <mach/gpio.h>
18#include <mach/spi-clocks.h> 18#include <mach/spi-clocks.h>
19 19
20#include <plat/s3c64xx-spi.h> 20#include <plat/s3c64xx-spi.h>
diff --git a/arch/arm/mach-s5p6442/include/mach/irqs.h b/arch/arm/mach-s5p6442/include/mach/irqs.h
index 02c23749c023..3fbc6c3ad2da 100644
--- a/arch/arm/mach-s5p6442/include/mach/irqs.h
+++ b/arch/arm/mach-s5p6442/include/mach/irqs.h
@@ -32,7 +32,7 @@
32#define IRQ_GPIOINT S5P_IRQ_VIC0(30) 32#define IRQ_GPIOINT S5P_IRQ_VIC0(30)
33 33
34/* VIC1 */ 34/* VIC1 */
35#define IRQ_nPMUIRQ S5P_IRQ_VIC1(0) 35#define IRQ_PMU S5P_IRQ_VIC1(0)
36#define IRQ_ONENAND S5P_IRQ_VIC1(7) 36#define IRQ_ONENAND S5P_IRQ_VIC1(7)
37#define IRQ_UART0 S5P_IRQ_VIC1(10) 37#define IRQ_UART0 S5P_IRQ_VIC1(10)
38#define IRQ_UART1 S5P_IRQ_VIC1(11) 38#define IRQ_UART1 S5P_IRQ_VIC1(11)
diff --git a/arch/arm/mach-s5p6442/include/mach/map.h b/arch/arm/mach-s5p6442/include/mach/map.h
index 32ca424ef7f9..281d256faafb 100644
--- a/arch/arm/mach-s5p6442/include/mach/map.h
+++ b/arch/arm/mach-s5p6442/include/mach/map.h
@@ -42,6 +42,8 @@
42 42
43#define S5P6442_PA_SYSTIMER (0xEA100000) 43#define S5P6442_PA_SYSTIMER (0xEA100000)
44 44
45#define S5P6442_PA_WATCHDOG (0xEA200000)
46
45#define S5P6442_PA_UART (0xEC000000) 47#define S5P6442_PA_UART (0xEC000000)
46 48
47#define S5P_PA_UART0 (S5P6442_PA_UART + 0x0) 49#define S5P_PA_UART0 (S5P6442_PA_UART + 0x0)
@@ -65,6 +67,7 @@
65#define S5P6442_PA_PCM1 0xF2500000 67#define S5P6442_PA_PCM1 0xF2500000
66 68
67/* compatibiltiy defines. */ 69/* compatibiltiy defines. */
70#define S3C_PA_WDT S5P6442_PA_WATCHDOG
68#define S3C_PA_UART S5P6442_PA_UART 71#define S3C_PA_UART S5P6442_PA_UART
69#define S3C_PA_IIC S5P6442_PA_IIC0 72#define S3C_PA_IIC S5P6442_PA_IIC0
70 73
diff --git a/arch/arm/mach-s5p6442/include/mach/system.h b/arch/arm/mach-s5p6442/include/mach/system.h
index 8bcd8ed0c3c3..c30c1cc1b97e 100644
--- a/arch/arm/mach-s5p6442/include/mach/system.h
+++ b/arch/arm/mach-s5p6442/include/mach/system.h
@@ -13,12 +13,9 @@
13#ifndef __ASM_ARCH_SYSTEM_H 13#ifndef __ASM_ARCH_SYSTEM_H
14#define __ASM_ARCH_SYSTEM_H __FILE__ 14#define __ASM_ARCH_SYSTEM_H __FILE__
15 15
16static void arch_idle(void) 16#include <plat/system-reset.h>
17{
18 /* nothing here yet */
19}
20 17
21static void arch_reset(char mode, const char *cmd) 18static void arch_idle(void)
22{ 19{
23 /* nothing here yet */ 20 /* nothing here yet */
24} 21}
diff --git a/arch/arm/mach-s5p6442/mach-smdk6442.c b/arch/arm/mach-s5p6442/mach-smdk6442.c
index ebcf99777259..8d8d04272f85 100644
--- a/arch/arm/mach-s5p6442/mach-smdk6442.c
+++ b/arch/arm/mach-s5p6442/mach-smdk6442.c
@@ -27,16 +27,16 @@
27#include <plat/cpu.h> 27#include <plat/cpu.h>
28 28
29/* Following are default values for UCON, ULCON and UFCON UART registers */ 29/* Following are default values for UCON, ULCON and UFCON UART registers */
30#define S5P6442_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \ 30#define SMDK6442_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \
31 S3C2410_UCON_RXILEVEL | \ 31 S3C2410_UCON_RXILEVEL | \
32 S3C2410_UCON_TXIRQMODE | \ 32 S3C2410_UCON_TXIRQMODE | \
33 S3C2410_UCON_RXIRQMODE | \ 33 S3C2410_UCON_RXIRQMODE | \
34 S3C2410_UCON_RXFIFO_TOI | \ 34 S3C2410_UCON_RXFIFO_TOI | \
35 S3C2443_UCON_RXERR_IRQEN) 35 S3C2443_UCON_RXERR_IRQEN)
36 36
37#define S5P6442_ULCON_DEFAULT S3C2410_LCON_CS8 37#define SMDK6442_ULCON_DEFAULT S3C2410_LCON_CS8
38 38
39#define S5P6442_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \ 39#define SMDK6442_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \
40 S5PV210_UFCON_TXTRIG4 | \ 40 S5PV210_UFCON_TXTRIG4 | \
41 S5PV210_UFCON_RXTRIG4) 41 S5PV210_UFCON_RXTRIG4)
42 42
@@ -44,28 +44,29 @@ static struct s3c2410_uartcfg smdk6442_uartcfgs[] __initdata = {
44 [0] = { 44 [0] = {
45 .hwport = 0, 45 .hwport = 0,
46 .flags = 0, 46 .flags = 0,
47 .ucon = S5P6442_UCON_DEFAULT, 47 .ucon = SMDK6442_UCON_DEFAULT,
48 .ulcon = S5P6442_ULCON_DEFAULT, 48 .ulcon = SMDK6442_ULCON_DEFAULT,
49 .ufcon = S5P6442_UFCON_DEFAULT, 49 .ufcon = SMDK6442_UFCON_DEFAULT,
50 }, 50 },
51 [1] = { 51 [1] = {
52 .hwport = 1, 52 .hwport = 1,
53 .flags = 0, 53 .flags = 0,
54 .ucon = S5P6442_UCON_DEFAULT, 54 .ucon = SMDK6442_UCON_DEFAULT,
55 .ulcon = S5P6442_ULCON_DEFAULT, 55 .ulcon = SMDK6442_ULCON_DEFAULT,
56 .ufcon = S5P6442_UFCON_DEFAULT, 56 .ufcon = SMDK6442_UFCON_DEFAULT,
57 }, 57 },
58 [2] = { 58 [2] = {
59 .hwport = 2, 59 .hwport = 2,
60 .flags = 0, 60 .flags = 0,
61 .ucon = S5P6442_UCON_DEFAULT, 61 .ucon = SMDK6442_UCON_DEFAULT,
62 .ulcon = S5P6442_ULCON_DEFAULT, 62 .ulcon = SMDK6442_ULCON_DEFAULT,
63 .ufcon = S5P6442_UFCON_DEFAULT, 63 .ufcon = SMDK6442_UFCON_DEFAULT,
64 }, 64 },
65}; 65};
66 66
67static struct platform_device *smdk6442_devices[] __initdata = { 67static struct platform_device *smdk6442_devices[] __initdata = {
68 &s5p6442_device_iis0, 68 &s5p6442_device_iis0,
69 &s3c_device_wdt,
69}; 70};
70 71
71static void __init smdk6442_map_io(void) 72static void __init smdk6442_map_io(void)
diff --git a/arch/arm/mach-s5pc100/Kconfig b/arch/arm/mach-s5pc100/Kconfig
index b2a11dfa3399..77ae4bfb74ba 100644
--- a/arch/arm/mach-s5pc100/Kconfig
+++ b/arch/arm/mach-s5pc100/Kconfig
@@ -25,6 +25,16 @@ config S5PC100_SETUP_I2C1
25 help 25 help
26 Common setup code for i2c bus 1. 26 Common setup code for i2c bus 1.
27 27
28config S5PC100_SETUP_IDE
29 bool
30 help
31 Common setup code for S5PC100 IDE GPIO configurations
32
33config S5PC100_SETUP_KEYPAD
34 bool
35 help
36 Common setup code for KEYPAD GPIO configurations.
37
28config S5PC100_SETUP_SDHCI 38config S5PC100_SETUP_SDHCI
29 bool 39 bool
30 select S5PC100_SETUP_SDHCI_GPIO 40 select S5PC100_SETUP_SDHCI_GPIO
@@ -40,13 +50,24 @@ config MACH_SMDKC100
40 bool "SMDKC100" 50 bool "SMDKC100"
41 select CPU_S5PC100 51 select CPU_S5PC100
42 select S3C_DEV_FB 52 select S3C_DEV_FB
43 select S3C_DEV_I2C1
44 select S3C_DEV_HSMMC 53 select S3C_DEV_HSMMC
45 select S3C_DEV_HSMMC1 54 select S3C_DEV_HSMMC1
46 select S3C_DEV_HSMMC2 55 select S3C_DEV_HSMMC2
56 select S3C_DEV_I2C1
57 select S3C_DEV_RTC
58 select S3C_DEV_WDT
59 select SAMSUNG_DEV_ADC
60 select SAMSUNG_DEV_IDE
61 select SAMSUNG_DEV_KEYPAD
62 select SAMSUNG_DEV_TS
47 select S5PC100_SETUP_FB_24BPP 63 select S5PC100_SETUP_FB_24BPP
48 select S5PC100_SETUP_I2C1 64 select S5PC100_SETUP_I2C1
65 select S5PC100_SETUP_IDE
66 select S5PC100_SETUP_KEYPAD
49 select S5PC100_SETUP_SDHCI 67 select S5PC100_SETUP_SDHCI
68 select S5P_DEV_FIMC0
69 select S5P_DEV_FIMC1
70 select S5P_DEV_FIMC2
50 help 71 help
51 Machine support for the Samsung SMDKC100 72 Machine support for the Samsung SMDKC100
52 73
diff --git a/arch/arm/mach-s5pc100/Makefile b/arch/arm/mach-s5pc100/Makefile
index 543f3de5131e..a021ed1fb4b6 100644
--- a/arch/arm/mach-s5pc100/Makefile
+++ b/arch/arm/mach-s5pc100/Makefile
@@ -19,6 +19,8 @@ obj-$(CONFIG_CPU_S5PC100) += dma.o
19 19
20obj-$(CONFIG_S5PC100_SETUP_FB_24BPP) += setup-fb-24bpp.o 20obj-$(CONFIG_S5PC100_SETUP_FB_24BPP) += setup-fb-24bpp.o
21obj-$(CONFIG_S5PC100_SETUP_I2C1) += setup-i2c1.o 21obj-$(CONFIG_S5PC100_SETUP_I2C1) += setup-i2c1.o
22obj-$(CONFIG_S5PC100_SETUP_IDE) += setup-ide.o
23obj-$(CONFIG_S5PC100_SETUP_KEYPAD) += setup-keypad.o
22obj-$(CONFIG_S5PC100_SETUP_SDHCI) += setup-sdhci.o 24obj-$(CONFIG_S5PC100_SETUP_SDHCI) += setup-sdhci.o
23obj-$(CONFIG_S5PC100_SETUP_SDHCI_GPIO) += setup-sdhci-gpio.o 25obj-$(CONFIG_S5PC100_SETUP_SDHCI_GPIO) += setup-sdhci-gpio.o
24 26
diff --git a/arch/arm/mach-s5pc100/clock.c b/arch/arm/mach-s5pc100/clock.c
index e3fed4cfe7ad..084abd13b0a5 100644
--- a/arch/arm/mach-s5pc100/clock.c
+++ b/arch/arm/mach-s5pc100/clock.c
@@ -737,7 +737,7 @@ static struct clk init_clocks_disable[] = {
737 .enable = s5pc100_d1_5_ctrl, 737 .enable = s5pc100_d1_5_ctrl,
738 .ctrlbit = (1 << 7), 738 .ctrlbit = (1 << 7),
739 }, { 739 }, {
740 .name = "keyif", 740 .name = "keypad",
741 .id = -1, 741 .id = -1,
742 .parent = &clk_div_d1_bus.clk, 742 .parent = &clk_div_d1_bus.clk,
743 .enable = s5pc100_d1_5_ctrl, 743 .enable = s5pc100_d1_5_ctrl,
@@ -1078,7 +1078,7 @@ static struct clksrc_clk clksrcs[] = {
1078 .reg_div = { .reg = S5P_CLK_DIV3, .shift = 24, .size = 4 }, 1078 .reg_div = { .reg = S5P_CLK_DIV3, .shift = 24, .size = 4 },
1079 }, { 1079 }, {
1080 .clk = { 1080 .clk = {
1081 .name = "mmc_bus", 1081 .name = "sclk_mmc",
1082 .id = 0, 1082 .id = 0,
1083 .ctrlbit = (1 << 12), 1083 .ctrlbit = (1 << 12),
1084 .enable = s5pc100_sclk1_ctrl, 1084 .enable = s5pc100_sclk1_ctrl,
@@ -1089,7 +1089,7 @@ static struct clksrc_clk clksrcs[] = {
1089 .reg_div = { .reg = S5P_CLK_DIV3, .shift = 0, .size = 4 }, 1089 .reg_div = { .reg = S5P_CLK_DIV3, .shift = 0, .size = 4 },
1090 }, { 1090 }, {
1091 .clk = { 1091 .clk = {
1092 .name = "mmc_bus", 1092 .name = "sclk_mmc",
1093 .id = 1, 1093 .id = 1,
1094 .ctrlbit = (1 << 13), 1094 .ctrlbit = (1 << 13),
1095 .enable = s5pc100_sclk1_ctrl, 1095 .enable = s5pc100_sclk1_ctrl,
@@ -1100,7 +1100,7 @@ static struct clksrc_clk clksrcs[] = {
1100 .reg_div = { .reg = S5P_CLK_DIV3, .shift = 4, .size = 4 }, 1100 .reg_div = { .reg = S5P_CLK_DIV3, .shift = 4, .size = 4 },
1101 }, { 1101 }, {
1102 .clk = { 1102 .clk = {
1103 .name = "mmc_bus", 1103 .name = "sclk_mmc",
1104 .id = 2, 1104 .id = 2,
1105 .ctrlbit = (1 << 14), 1105 .ctrlbit = (1 << 14),
1106 .enable = s5pc100_sclk1_ctrl, 1106 .enable = s5pc100_sclk1_ctrl,
diff --git a/arch/arm/mach-s5pc100/cpu.c b/arch/arm/mach-s5pc100/cpu.c
index 7b5bdbc9a5df..251c92ac5b22 100644
--- a/arch/arm/mach-s5pc100/cpu.c
+++ b/arch/arm/mach-s5pc100/cpu.c
@@ -38,9 +38,12 @@
38#include <plat/cpu.h> 38#include <plat/cpu.h>
39#include <plat/devs.h> 39#include <plat/devs.h>
40#include <plat/clock.h> 40#include <plat/clock.h>
41#include <plat/ata-core.h>
41#include <plat/iic-core.h> 42#include <plat/iic-core.h>
42#include <plat/sdhci.h> 43#include <plat/sdhci.h>
44#include <plat/adc-core.h>
43#include <plat/onenand-core.h> 45#include <plat/onenand-core.h>
46#include <plat/fb-core.h>
44 47
45#include <plat/s5pc100.h> 48#include <plat/s5pc100.h>
46 49
@@ -87,11 +90,15 @@ void __init s5pc100_map_io(void)
87 s5pc100_default_sdhci1(); 90 s5pc100_default_sdhci1();
88 s5pc100_default_sdhci2(); 91 s5pc100_default_sdhci2();
89 92
93 s3c_adc_setname("s3c64xx-adc");
94
90 /* the i2c devices are directly compatible with s3c2440 */ 95 /* the i2c devices are directly compatible with s3c2440 */
91 s3c_i2c0_setname("s3c2440-i2c"); 96 s3c_i2c0_setname("s3c2440-i2c");
92 s3c_i2c1_setname("s3c2440-i2c"); 97 s3c_i2c1_setname("s3c2440-i2c");
93 98
94 s3c_onenand_setname("s5pc100-onenand"); 99 s3c_onenand_setname("s5pc100-onenand");
100 s3c_fb_setname("s5pc100-fb");
101 s3c_cfcon_setname("s5pc100-pata");
95} 102}
96 103
97void __init s5pc100_init_clocks(int xtal) 104void __init s5pc100_init_clocks(int xtal)
diff --git a/arch/arm/mach-s5pc100/dev-audio.c b/arch/arm/mach-s5pc100/dev-audio.c
index 18cfe9ae1936..a699ed6acc23 100644
--- a/arch/arm/mach-s5pc100/dev-audio.c
+++ b/arch/arm/mach-s5pc100/dev-audio.c
@@ -10,11 +10,11 @@
10 10
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
13#include <linux/gpio.h>
13 14
14#include <plat/gpio-cfg.h> 15#include <plat/gpio-cfg.h>
15#include <plat/audio.h> 16#include <plat/audio.h>
16 17
17#include <mach/gpio.h>
18#include <mach/map.h> 18#include <mach/map.h>
19#include <mach/dma.h> 19#include <mach/dma.h>
20#include <mach/irqs.h> 20#include <mach/irqs.h>
diff --git a/arch/arm/mach-s5pc100/dev-spi.c b/arch/arm/mach-s5pc100/dev-spi.c
index 14618c346057..a0ef7c302c16 100644
--- a/arch/arm/mach-s5pc100/dev-spi.c
+++ b/arch/arm/mach-s5pc100/dev-spi.c
@@ -10,10 +10,10 @@
10 10
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
13#include <linux/gpio.h>
13 14
14#include <mach/dma.h> 15#include <mach/dma.h>
15#include <mach/map.h> 16#include <mach/map.h>
16#include <mach/gpio.h>
17#include <mach/spi-clocks.h> 17#include <mach/spi-clocks.h>
18 18
19#include <plat/s3c64xx-spi.h> 19#include <plat/s3c64xx-spi.h>
diff --git a/arch/arm/mach-s5pc100/include/mach/irqs.h b/arch/arm/mach-s5pc100/include/mach/irqs.h
index 28aa551dc3a8..06513e647242 100644
--- a/arch/arm/mach-s5pc100/include/mach/irqs.h
+++ b/arch/arm/mach-s5pc100/include/mach/irqs.h
@@ -29,7 +29,7 @@
29#define IRQ_GPIOINT S5P_IRQ_VIC0(30) 29#define IRQ_GPIOINT S5P_IRQ_VIC0(30)
30 30
31/* VIC1: ARM, power, memory, connectivity */ 31/* VIC1: ARM, power, memory, connectivity */
32#define IRQ_CORTEX0 S5P_IRQ_VIC1(0) 32#define IRQ_PMU S5P_IRQ_VIC1(0)
33#define IRQ_CORTEX1 S5P_IRQ_VIC1(1) 33#define IRQ_CORTEX1 S5P_IRQ_VIC1(1)
34#define IRQ_CORTEX2 S5P_IRQ_VIC1(2) 34#define IRQ_CORTEX2 S5P_IRQ_VIC1(2)
35#define IRQ_CORTEX3 S5P_IRQ_VIC1(3) 35#define IRQ_CORTEX3 S5P_IRQ_VIC1(3)
@@ -38,7 +38,7 @@
38#define IRQ_IEMIEC S5P_IRQ_VIC1(6) 38#define IRQ_IEMIEC S5P_IRQ_VIC1(6)
39#define IRQ_ONENAND S5P_IRQ_VIC1(7) 39#define IRQ_ONENAND S5P_IRQ_VIC1(7)
40#define IRQ_NFC S5P_IRQ_VIC1(8) 40#define IRQ_NFC S5P_IRQ_VIC1(8)
41#define IRQ_CFC S5P_IRQ_VIC1(9) 41#define IRQ_CFCON S5P_IRQ_VIC1(9)
42#define IRQ_UART0 S5P_IRQ_VIC1(10) 42#define IRQ_UART0 S5P_IRQ_VIC1(10)
43#define IRQ_UART1 S5P_IRQ_VIC1(11) 43#define IRQ_UART1 S5P_IRQ_VIC1(11)
44#define IRQ_UART2 S5P_IRQ_VIC1(12) 44#define IRQ_UART2 S5P_IRQ_VIC1(12)
diff --git a/arch/arm/mach-s5pc100/include/mach/map.h b/arch/arm/mach-s5pc100/include/mach/map.h
index cadae4305688..01b9134feff0 100644
--- a/arch/arm/mach-s5pc100/include/mach/map.h
+++ b/arch/arm/mach-s5pc100/include/mach/map.h
@@ -61,6 +61,8 @@
61 61
62#define S5PC100_PA_ONENAND (0xE7100000) 62#define S5PC100_PA_ONENAND (0xE7100000)
63 63
64#define S5PC100_PA_CFCON (0xE7800000)
65
64/* DMA */ 66/* DMA */
65#define S5PC100_PA_MDMA (0xE8100000) 67#define S5PC100_PA_MDMA (0xE8100000)
66#define S5PC100_PA_PDMA0 (0xE9000000) 68#define S5PC100_PA_PDMA0 (0xE9000000)
@@ -72,6 +74,9 @@
72 74
73#define S5PC100_PA_SYSTIMER (0xEA100000) 75#define S5PC100_PA_SYSTIMER (0xEA100000)
74 76
77#define S5PC100_PA_WATCHDOG (0xEA200000)
78#define S5PC100_PA_RTC (0xEA300000)
79
75#define S5PC100_PA_UART (0xEC000000) 80#define S5PC100_PA_UART (0xEC000000)
76 81
77#define S5P_PA_UART0 (S5PC100_PA_UART + 0x0) 82#define S5P_PA_UART0 (S5PC100_PA_UART + 0x0)
@@ -94,6 +99,10 @@
94 99
95#define S5PC100_PA_FB (0xEE000000) 100#define S5PC100_PA_FB (0xEE000000)
96 101
102#define S5PC100_PA_FIMC0 (0xEE200000)
103#define S5PC100_PA_FIMC1 (0xEE300000)
104#define S5PC100_PA_FIMC2 (0xEE400000)
105
97#define S5PC100_PA_I2S0 (0xF2000000) 106#define S5PC100_PA_I2S0 (0xF2000000)
98#define S5PC100_PA_I2S1 (0xF2100000) 107#define S5PC100_PA_I2S1 (0xF2100000)
99#define S5PC100_PA_I2S2 (0xF2200000) 108#define S5PC100_PA_I2S2 (0xF2200000)
@@ -104,6 +113,8 @@
104#define S5PC100_PA_PCM0 0xF2400000 113#define S5PC100_PA_PCM0 0xF2400000
105#define S5PC100_PA_PCM1 0xF2500000 114#define S5PC100_PA_PCM1 0xF2500000
106 115
116#define S5PC100_PA_TSADC (0xF3000000)
117
107/* KEYPAD */ 118/* KEYPAD */
108#define S5PC100_PA_KEYPAD (0xF3100000) 119#define S5PC100_PA_KEYPAD (0xF3100000)
109 120
@@ -130,9 +141,19 @@
130#define S3C_PA_HSMMC1 S5PC100_PA_HSMMC(1) 141#define S3C_PA_HSMMC1 S5PC100_PA_HSMMC(1)
131#define S3C_PA_HSMMC2 S5PC100_PA_HSMMC(2) 142#define S3C_PA_HSMMC2 S5PC100_PA_HSMMC(2)
132#define S3C_PA_KEYPAD S5PC100_PA_KEYPAD 143#define S3C_PA_KEYPAD S5PC100_PA_KEYPAD
144#define S3C_PA_WDT S5PC100_PA_WATCHDOG
133#define S3C_PA_TSADC S5PC100_PA_TSADC 145#define S3C_PA_TSADC S5PC100_PA_TSADC
134#define S3C_PA_ONENAND S5PC100_PA_ONENAND 146#define S3C_PA_ONENAND S5PC100_PA_ONENAND
135#define S3C_PA_ONENAND_BUF S5PC100_PA_ONENAND_BUF 147#define S3C_PA_ONENAND_BUF S5PC100_PA_ONENAND_BUF
136#define S3C_SZ_ONENAND_BUF S5PC100_SZ_ONENAND_BUF 148#define S3C_SZ_ONENAND_BUF S5PC100_SZ_ONENAND_BUF
149#define S3C_PA_RTC S5PC100_PA_RTC
150
151#define SAMSUNG_PA_ADC S5PC100_PA_TSADC
152#define SAMSUNG_PA_CFCON S5PC100_PA_CFCON
153#define SAMSUNG_PA_KEYPAD S5PC100_PA_KEYPAD
154
155#define S5P_PA_FIMC0 S5PC100_PA_FIMC0
156#define S5P_PA_FIMC1 S5PC100_PA_FIMC1
157#define S5P_PA_FIMC2 S5PC100_PA_FIMC2
137 158
138#endif /* __ASM_ARCH_C100_MAP_H */ 159#endif /* __ASM_ARCH_C100_MAP_H */
diff --git a/arch/arm/mach-s5pc100/include/mach/regs-clock.h b/arch/arm/mach-s5pc100/include/mach/regs-clock.h
index 5d27d286d504..bc92da2e0ba2 100644
--- a/arch/arm/mach-s5pc100/include/mach/regs-clock.h
+++ b/arch/arm/mach-s5pc100/include/mach/regs-clock.h
@@ -71,7 +71,10 @@
71#define S5P_CLKDIV1_PCLKD1_SHIFT (16) 71#define S5P_CLKDIV1_PCLKD1_SHIFT (16)
72 72
73#define S5PC100_SWRESET S5PC100_REG_OTHERS(0x000) 73#define S5PC100_SWRESET S5PC100_REG_OTHERS(0x000)
74#define S5PC100_MEM_SYS_CFG S5PC100_REG_OTHERS(0x200)
74 75
75#define S5PC100_SWRESET_RESETVAL 0xc100 76#define S5PC100_SWRESET_RESETVAL 0xc100
76 77
78#define MEM_SYS_CFG_EBI_FIX_PRI_CFCON 0x30
79
77#endif /* __ASM_ARCH_REGS_CLOCK_H */ 80#endif /* __ASM_ARCH_REGS_CLOCK_H */
diff --git a/arch/arm/mach-s5pc100/include/mach/regs-fb.h b/arch/arm/mach-s5pc100/include/mach/regs-fb.h
index 1732cd28c765..4be4cc9abf75 100644
--- a/arch/arm/mach-s5pc100/include/mach/regs-fb.h
+++ b/arch/arm/mach-s5pc100/include/mach/regs-fb.h
@@ -100,40 +100,6 @@
100#define BLENDCON (0x260) 100#define BLENDCON (0x260)
101#define BLENDCON_8BIT_ALPHA (1 << 0) 101#define BLENDCON_8BIT_ALPHA (1 << 0)
102 102
103/* Per-window palette base addresses (start of palette memory).
104 * Each window palette area consists of 256 32-bit entries.
105 * START is the first address (entry 0th), END is the address of 255th entry.
106 */
107#define WIN0_PAL_BASE (0x2400)
108#define WIN0_PAL_END (0x27fc)
109#define WIN1_PAL_BASE (0x2800)
110#define WIN1_PAL_END (0x2bfc)
111#define WIN2_PAL_BASE (0x2c00)
112#define WIN2_PAL_END (0x2ffc)
113#define WIN3_PAL_BASE (0x3000)
114#define WIN3_PAL_END (0x33fc)
115#define WIN4_PAL_BASE (0x3400)
116#define WIN4_PAL_END (0x37fc)
117
118#define WIN0_PAL(_entry) (WIN0_PAL_BASE + ((_entry) * 4))
119#define WIN1_PAL(_entry) (WIN1_PAL_BASE + ((_entry) * 4))
120#define WIN2_PAL(_entry) (WIN2_PAL_BASE + ((_entry) * 4))
121#define WIN3_PAL(_entry) (WIN3_PAL_BASE + ((_entry) * 4))
122#define WIN4_PAL(_entry) (WIN4_PAL_BASE + ((_entry) * 4))
123
124static inline unsigned int s3c_fb_pal_reg(unsigned int window, int reg)
125{
126 switch (window) {
127 case 0: return WIN0_PAL(reg);
128 case 1: return WIN1_PAL(reg);
129 case 2: return WIN2_PAL(reg);
130 case 3: return WIN3_PAL(reg);
131 case 4: return WIN4_PAL(reg);
132 }
133
134 BUG();
135}
136
137 103
138#endif /* __ASM_ARCH_REGS_FB_H */ 104#endif /* __ASM_ARCH_REGS_FB_H */
139 105
diff --git a/arch/arm/mach-s5pc100/include/mach/system.h b/arch/arm/mach-s5pc100/include/mach/system.h
index 681f626a9ae1..a9ea57c06600 100644
--- a/arch/arm/mach-s5pc100/include/mach/system.h
+++ b/arch/arm/mach-s5pc100/include/mach/system.h
@@ -11,18 +11,11 @@
11#ifndef __ASM_ARCH_SYSTEM_H 11#ifndef __ASM_ARCH_SYSTEM_H
12#define __ASM_ARCH_SYSTEM_H __FILE__ 12#define __ASM_ARCH_SYSTEM_H __FILE__
13 13
14#include <linux/io.h> 14#include <plat/system-reset.h>
15#include <mach/map.h>
16#include <mach/regs-clock.h>
17 15
18static void arch_idle(void) 16static void arch_idle(void)
19{ 17{
20 /* nothing here yet */ 18 /* nothing here yet */
21} 19}
22 20
23static void arch_reset(char mode, const char *cmd)
24{
25 __raw_writel(S5PC100_SWRESET_RESETVAL, S5PC100_SWRESET);
26 return;
27}
28#endif /* __ASM_ARCH_IRQ_H */ 21#endif /* __ASM_ARCH_IRQ_H */
diff --git a/arch/arm/mach-s5pc100/mach-smdkc100.c b/arch/arm/mach-s5pc100/mach-smdkc100.c
index af22f8202a07..020c3f98f81f 100644
--- a/arch/arm/mach-s5pc100/mach-smdkc100.c
+++ b/arch/arm/mach-s5pc100/mach-smdkc100.c
@@ -22,6 +22,7 @@
22#include <linux/i2c.h> 22#include <linux/i2c.h>
23#include <linux/fb.h> 23#include <linux/fb.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/input.h>
25 26
26#include <asm/mach/arch.h> 27#include <asm/mach/arch.h>
27#include <asm/mach/map.h> 28#include <asm/mach/map.h>
@@ -42,18 +43,22 @@
42#include <plat/s5pc100.h> 43#include <plat/s5pc100.h>
43#include <plat/fb.h> 44#include <plat/fb.h>
44#include <plat/iic.h> 45#include <plat/iic.h>
46#include <plat/ata.h>
47#include <plat/adc.h>
48#include <plat/keypad.h>
49#include <plat/ts.h>
45 50
46/* Following are default values for UCON, ULCON and UFCON UART registers */ 51/* Following are default values for UCON, ULCON and UFCON UART registers */
47#define S5PC100_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \ 52#define SMDKC100_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \
48 S3C2410_UCON_RXILEVEL | \ 53 S3C2410_UCON_RXILEVEL | \
49 S3C2410_UCON_TXIRQMODE | \ 54 S3C2410_UCON_TXIRQMODE | \
50 S3C2410_UCON_RXIRQMODE | \ 55 S3C2410_UCON_RXIRQMODE | \
51 S3C2410_UCON_RXFIFO_TOI | \ 56 S3C2410_UCON_RXFIFO_TOI | \
52 S3C2443_UCON_RXERR_IRQEN) 57 S3C2443_UCON_RXERR_IRQEN)
53 58
54#define S5PC100_ULCON_DEFAULT S3C2410_LCON_CS8 59#define SMDKC100_ULCON_DEFAULT S3C2410_LCON_CS8
55 60
56#define S5PC100_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \ 61#define SMDKC100_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \
57 S3C2440_UFCON_RXTRIG8 | \ 62 S3C2440_UFCON_RXTRIG8 | \
58 S3C2440_UFCON_TXTRIG16) 63 S3C2440_UFCON_TXTRIG16)
59 64
@@ -61,30 +66,30 @@ static struct s3c2410_uartcfg smdkc100_uartcfgs[] __initdata = {
61 [0] = { 66 [0] = {
62 .hwport = 0, 67 .hwport = 0,
63 .flags = 0, 68 .flags = 0,
64 .ucon = S5PC100_UCON_DEFAULT, 69 .ucon = SMDKC100_UCON_DEFAULT,
65 .ulcon = S5PC100_ULCON_DEFAULT, 70 .ulcon = SMDKC100_ULCON_DEFAULT,
66 .ufcon = S5PC100_UFCON_DEFAULT, 71 .ufcon = SMDKC100_UFCON_DEFAULT,
67 }, 72 },
68 [1] = { 73 [1] = {
69 .hwport = 1, 74 .hwport = 1,
70 .flags = 0, 75 .flags = 0,
71 .ucon = S5PC100_UCON_DEFAULT, 76 .ucon = SMDKC100_UCON_DEFAULT,
72 .ulcon = S5PC100_ULCON_DEFAULT, 77 .ulcon = SMDKC100_ULCON_DEFAULT,
73 .ufcon = S5PC100_UFCON_DEFAULT, 78 .ufcon = SMDKC100_UFCON_DEFAULT,
74 }, 79 },
75 [2] = { 80 [2] = {
76 .hwport = 2, 81 .hwport = 2,
77 .flags = 0, 82 .flags = 0,
78 .ucon = S5PC100_UCON_DEFAULT, 83 .ucon = SMDKC100_UCON_DEFAULT,
79 .ulcon = S5PC100_ULCON_DEFAULT, 84 .ulcon = SMDKC100_ULCON_DEFAULT,
80 .ufcon = S5PC100_UFCON_DEFAULT, 85 .ufcon = SMDKC100_UFCON_DEFAULT,
81 }, 86 },
82 [3] = { 87 [3] = {
83 .hwport = 3, 88 .hwport = 3,
84 .flags = 0, 89 .flags = 0,
85 .ucon = S5PC100_UCON_DEFAULT, 90 .ucon = SMDKC100_UCON_DEFAULT,
86 .ulcon = S5PC100_ULCON_DEFAULT, 91 .ulcon = SMDKC100_ULCON_DEFAULT,
87 .ufcon = S5PC100_UFCON_DEFAULT, 92 .ufcon = SMDKC100_UFCON_DEFAULT,
88 }, 93 },
89}; 94};
90 95
@@ -128,7 +133,6 @@ static struct platform_device smdkc100_lcd_powerdev = {
128static struct s3c_fb_pd_win smdkc100_fb_win0 = { 133static struct s3c_fb_pd_win smdkc100_fb_win0 = {
129 /* this is to ensure we use win0 */ 134 /* this is to ensure we use win0 */
130 .win_mode = { 135 .win_mode = {
131 .pixclock = 1000000000000ULL / ((8+13+3+800)*(7+5+1+480)*80),
132 .left_margin = 8, 136 .left_margin = 8,
133 .right_margin = 13, 137 .right_margin = 13,
134 .upper_margin = 7, 138 .upper_margin = 7,
@@ -137,6 +141,7 @@ static struct s3c_fb_pd_win smdkc100_fb_win0 = {
137 .vsync_len = 1, 141 .vsync_len = 1,
138 .xres = 800, 142 .xres = 800,
139 .yres = 480, 143 .yres = 480,
144 .refresh = 80,
140 }, 145 },
141 .max_bpp = 32, 146 .max_bpp = 32,
142 .default_bpp = 16, 147 .default_bpp = 16,
@@ -149,16 +154,54 @@ static struct s3c_fb_platdata smdkc100_lcd_pdata __initdata = {
149 .setup_gpio = s5pc100_fb_gpio_setup_24bpp, 154 .setup_gpio = s5pc100_fb_gpio_setup_24bpp,
150}; 155};
151 156
157static struct s3c_ide_platdata smdkc100_ide_pdata __initdata = {
158 .setup_gpio = s5pc100_ide_setup_gpio,
159};
160
161static uint32_t smdkc100_keymap[] __initdata = {
162 /* KEY(row, col, keycode) */
163 KEY(0, 3, KEY_1), KEY(0, 4, KEY_2), KEY(0, 5, KEY_3),
164 KEY(0, 6, KEY_4), KEY(0, 7, KEY_5),
165 KEY(1, 3, KEY_A), KEY(1, 4, KEY_B), KEY(1, 5, KEY_C),
166 KEY(1, 6, KEY_D), KEY(1, 7, KEY_E)
167};
168
169static struct matrix_keymap_data smdkc100_keymap_data __initdata = {
170 .keymap = smdkc100_keymap,
171 .keymap_size = ARRAY_SIZE(smdkc100_keymap),
172};
173
174static struct samsung_keypad_platdata smdkc100_keypad_data __initdata = {
175 .keymap_data = &smdkc100_keymap_data,
176 .rows = 2,
177 .cols = 8,
178};
179
152static struct platform_device *smdkc100_devices[] __initdata = { 180static struct platform_device *smdkc100_devices[] __initdata = {
181 &s3c_device_adc,
182 &s3c_device_cfcon,
153 &s3c_device_i2c0, 183 &s3c_device_i2c0,
154 &s3c_device_i2c1, 184 &s3c_device_i2c1,
155 &s3c_device_fb, 185 &s3c_device_fb,
156 &s3c_device_hsmmc0, 186 &s3c_device_hsmmc0,
157 &s3c_device_hsmmc1, 187 &s3c_device_hsmmc1,
158 &s3c_device_hsmmc2, 188 &s3c_device_hsmmc2,
189 &s3c_device_ts,
190 &s3c_device_wdt,
159 &smdkc100_lcd_powerdev, 191 &smdkc100_lcd_powerdev,
160 &s5pc100_device_iis0, 192 &s5pc100_device_iis0,
193 &samsung_device_keypad,
161 &s5pc100_device_ac97, 194 &s5pc100_device_ac97,
195 &s3c_device_rtc,
196 &s5p_device_fimc0,
197 &s5p_device_fimc1,
198 &s5p_device_fimc2,
199};
200
201static struct s3c2410_ts_mach_info s3c_ts_platform __initdata = {
202 .delay = 10000,
203 .presc = 49,
204 .oversampling_shift = 2,
162}; 205};
163 206
164static void __init smdkc100_map_io(void) 207static void __init smdkc100_map_io(void)
@@ -170,6 +213,8 @@ static void __init smdkc100_map_io(void)
170 213
171static void __init smdkc100_machine_init(void) 214static void __init smdkc100_machine_init(void)
172{ 215{
216 s3c24xx_ts_set_platdata(&s3c_ts_platform);
217
173 /* I2C */ 218 /* I2C */
174 s3c_i2c0_set_platdata(NULL); 219 s3c_i2c0_set_platdata(NULL);
175 s3c_i2c1_set_platdata(NULL); 220 s3c_i2c1_set_platdata(NULL);
@@ -177,6 +222,9 @@ static void __init smdkc100_machine_init(void)
177 i2c_register_board_info(1, i2c_devs1, ARRAY_SIZE(i2c_devs1)); 222 i2c_register_board_info(1, i2c_devs1, ARRAY_SIZE(i2c_devs1));
178 223
179 s3c_fb_set_platdata(&smdkc100_lcd_pdata); 224 s3c_fb_set_platdata(&smdkc100_lcd_pdata);
225 s3c_ide_set_platdata(&smdkc100_ide_pdata);
226
227 samsung_keypad_set_platdata(&smdkc100_keypad_data);
180 228
181 /* LCD init */ 229 /* LCD init */
182 gpio_request(S5PC100_GPD(0), "GPD"); 230 gpio_request(S5PC100_GPD(0), "GPD");
diff --git a/arch/arm/mach-s5pc100/setup-ide.c b/arch/arm/mach-s5pc100/setup-ide.c
new file mode 100644
index 000000000000..83575671fb59
--- /dev/null
+++ b/arch/arm/mach-s5pc100/setup-ide.c
@@ -0,0 +1,70 @@
1/* linux/arch/arm/mach-s5pc100/setup-ide.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * S5PC100 setup information for IDE
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#include <linux/kernel.h>
14#include <linux/gpio.h>
15#include <linux/io.h>
16
17#include <mach/regs-clock.h>
18#include <plat/gpio-cfg.h>
19
20void s5pc100_ide_setup_gpio(void)
21{
22 u32 reg;
23 u32 gpio = 0;
24
25 /* Independent CF interface, CF chip select configuration */
26 reg = readl(S5PC100_MEM_SYS_CFG) & (~0x3f);
27 writel(reg | MEM_SYS_CFG_EBI_FIX_PRI_CFCON, S5PC100_MEM_SYS_CFG);
28
29 /* CF_Add[0 - 2], CF_IORDY, CF_INTRQ, CF_DMARQ, CF_DMARST, CF_DMACK */
30 for (gpio = S5PC100_GPJ0(0); gpio <= S5PC100_GPJ0(7); gpio++) {
31 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(4));
32 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
33 s5p_gpio_set_drvstr(gpio, S5P_GPIO_DRVSTR_LV4);
34 }
35
36 /*CF_Data[0 - 7] */
37 for (gpio = S5PC100_GPJ2(0); gpio <= S5PC100_GPJ2(7); gpio++) {
38 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(4));
39 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
40 s5p_gpio_set_drvstr(gpio, S5P_GPIO_DRVSTR_LV4);
41 }
42
43 /* CF_Data[8 - 15] */
44 for (gpio = S5PC100_GPJ3(0); gpio <= S5PC100_GPJ3(7); gpio++) {
45 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(4));
46 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
47 s5p_gpio_set_drvstr(gpio, S5P_GPIO_DRVSTR_LV4);
48 }
49
50 /* CF_CS0, CF_CS1, CF_IORD, CF_IOWR */
51 for (gpio = S5PC100_GPJ4(0); gpio <= S5PC100_GPJ4(3); gpio++) {
52 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(4));
53 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
54 s5p_gpio_set_drvstr(gpio, S5P_GPIO_DRVSTR_LV4);
55 }
56
57 /* EBI_OE, EBI_WE */
58 for (gpio = S5PC100_GPK0(6); gpio <= S5PC100_GPK0(7); gpio++)
59 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0));
60
61 /* CF_OE, CF_WE */
62 for (gpio = S5PC100_GPK1(6); gpio <= S5PC100_GPK1(7); gpio++) {
63 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
64 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
65 }
66
67 /* CF_CD */
68 s3c_gpio_cfgpin(S5PC100_GPK3(5), S3C_GPIO_SFN(2));
69 s3c_gpio_setpull(S5PC100_GPK3(5), S3C_GPIO_PULL_NONE);
70}
diff --git a/arch/arm/mach-s5pc100/setup-keypad.c b/arch/arm/mach-s5pc100/setup-keypad.c
new file mode 100644
index 000000000000..d0837a72a58e
--- /dev/null
+++ b/arch/arm/mach-s5pc100/setup-keypad.c
@@ -0,0 +1,34 @@
1/* linux/arch/arm/mach-s5pc100/setup-keypad.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * GPIO configuration for S5PC100 KeyPad device
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#include <linux/gpio.h>
14#include <plat/gpio-cfg.h>
15
16void samsung_keypad_cfg_gpio(unsigned int rows, unsigned int cols)
17{
18 unsigned int gpio;
19 unsigned int end;
20
21 /* Set all the necessary GPH3 pins to special-function 3: KP_ROW[x] */
22 end = S5PC100_GPH3(rows);
23 for (gpio = S5PC100_GPH3(0); gpio < end; gpio++) {
24 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(3));
25 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
26 }
27
28 /* Set all the necessary GPH2 pins to special-function 3: KP_COL[x] */
29 end = S5PC100_GPH2(cols);
30 for (gpio = S5PC100_GPH2(0); gpio < end; gpio++) {
31 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(3));
32 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
33 }
34}
diff --git a/arch/arm/mach-s5pc100/setup-sdhci-gpio.c b/arch/arm/mach-s5pc100/setup-sdhci-gpio.c
index 7769c760c9ef..dc7208c639ea 100644
--- a/arch/arm/mach-s5pc100/setup-sdhci-gpio.c
+++ b/arch/arm/mach-s5pc100/setup-sdhci-gpio.c
@@ -20,9 +20,11 @@
20 20
21#include <plat/gpio-cfg.h> 21#include <plat/gpio-cfg.h>
22#include <plat/regs-sdhci.h> 22#include <plat/regs-sdhci.h>
23#include <plat/sdhci.h>
23 24
24void s5pc100_setup_sdhci0_cfg_gpio(struct platform_device *dev, int width) 25void s5pc100_setup_sdhci0_cfg_gpio(struct platform_device *dev, int width)
25{ 26{
27 struct s3c_sdhci_platdata *pdata = dev->dev.platform_data;
26 unsigned int gpio; 28 unsigned int gpio;
27 unsigned int end; 29 unsigned int end;
28 unsigned int num; 30 unsigned int num;
@@ -47,12 +49,15 @@ void s5pc100_setup_sdhci0_cfg_gpio(struct platform_device *dev, int width)
47 } 49 }
48 } 50 }
49 51
50 s3c_gpio_setpull(S5PC100_GPG1(2), S3C_GPIO_PULL_UP); 52 if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) {
51 s3c_gpio_cfgpin(S5PC100_GPG1(2), S3C_GPIO_SFN(2)); 53 s3c_gpio_setpull(S5PC100_GPG1(2), S3C_GPIO_PULL_UP);
54 s3c_gpio_cfgpin(S5PC100_GPG1(2), S3C_GPIO_SFN(2));
55 }
52} 56}
53 57
54void s5pc100_setup_sdhci1_cfg_gpio(struct platform_device *dev, int width) 58void s5pc100_setup_sdhci1_cfg_gpio(struct platform_device *dev, int width)
55{ 59{
60 struct s3c_sdhci_platdata *pdata = dev->dev.platform_data;
56 unsigned int gpio; 61 unsigned int gpio;
57 unsigned int end; 62 unsigned int end;
58 63
@@ -64,12 +69,15 @@ void s5pc100_setup_sdhci1_cfg_gpio(struct platform_device *dev, int width)
64 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE); 69 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
65 } 70 }
66 71
67 s3c_gpio_setpull(S5PC100_GPG2(6), S3C_GPIO_PULL_UP); 72 if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) {
68 s3c_gpio_cfgpin(S5PC100_GPG2(6), S3C_GPIO_SFN(2)); 73 s3c_gpio_setpull(S5PC100_GPG2(6), S3C_GPIO_PULL_UP);
74 s3c_gpio_cfgpin(S5PC100_GPG2(6), S3C_GPIO_SFN(2));
75 }
69} 76}
70 77
71void s5pc100_setup_sdhci2_cfg_gpio(struct platform_device *dev, int width) 78void s5pc100_setup_sdhci2_cfg_gpio(struct platform_device *dev, int width)
72{ 79{
80 struct s3c_sdhci_platdata *pdata = dev->dev.platform_data;
73 unsigned int gpio; 81 unsigned int gpio;
74 unsigned int end; 82 unsigned int end;
75 83
@@ -81,6 +89,8 @@ void s5pc100_setup_sdhci2_cfg_gpio(struct platform_device *dev, int width)
81 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE); 89 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
82 } 90 }
83 91
84 s3c_gpio_setpull(S5PC100_GPG3(6), S3C_GPIO_PULL_UP); 92 if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) {
85 s3c_gpio_cfgpin(S5PC100_GPG3(6), S3C_GPIO_SFN(2)); 93 s3c_gpio_setpull(S5PC100_GPG3(6), S3C_GPIO_PULL_UP);
94 s3c_gpio_cfgpin(S5PC100_GPG3(6), S3C_GPIO_SFN(2));
95 }
86} 96}
diff --git a/arch/arm/mach-s5pc100/setup-sdhci.c b/arch/arm/mach-s5pc100/setup-sdhci.c
index ea7ff19adb95..f16946e456e9 100644
--- a/arch/arm/mach-s5pc100/setup-sdhci.c
+++ b/arch/arm/mach-s5pc100/setup-sdhci.c
@@ -26,10 +26,10 @@
26/* clock sources for the mmc bus clock, order as for the ctrl2[5..4] */ 26/* clock sources for the mmc bus clock, order as for the ctrl2[5..4] */
27 27
28char *s5pc100_hsmmc_clksrcs[4] = { 28char *s5pc100_hsmmc_clksrcs[4] = {
29 [0] = "hsmmc", 29 [0] = "hsmmc", /* HCLK */
30 [1] = "hsmmc", 30 /* [1] = "hsmmc", - duplicate HCLK entry */
31 /* [2] = "mmc_bus", not yet successfully used yet */ 31 [2] = "sclk_mmc", /* mmc_bus */
32 /* [3] = "48m", - note not successfully used yet */ 32 /* [3] = "48m", - note not successfully used yet */
33}; 33};
34 34
35 35
diff --git a/arch/arm/mach-s5pv210/Kconfig b/arch/arm/mach-s5pv210/Kconfig
index 0761eac9aaea..d3a38955c741 100644
--- a/arch/arm/mach-s5pv210/Kconfig
+++ b/arch/arm/mach-s5pv210/Kconfig
@@ -27,11 +27,21 @@ config S5PV210_SETUP_I2C2
27 help 27 help
28 Common setup code for i2c bus 2. 28 Common setup code for i2c bus 2.
29 29
30config S5PV210_SETUP_IDE
31 bool
32 help
33 Common setup code for S5PV210 IDE GPIO configurations
34
30config S5PV210_SETUP_FB_24BPP 35config S5PV210_SETUP_FB_24BPP
31 bool 36 bool
32 help 37 help
33 Common setup code for S5PV210 with an 24bpp RGB display helper. 38 Common setup code for S5PV210 with an 24bpp RGB display helper.
34 39
40config S5PV210_SETUP_KEYPAD
41 bool
42 help
43 Common setup code for keypad.
44
35config S5PV210_SETUP_SDHCI 45config S5PV210_SETUP_SDHCI
36 bool 46 bool
37 select S5PV210_SETUP_SDHCI_GPIO 47 select S5PV210_SETUP_SDHCI_GPIO
@@ -43,14 +53,27 @@ config S5PV210_SETUP_SDHCI_GPIO
43 help 53 help
44 Common setup code for SDHCI gpio. 54 Common setup code for SDHCI gpio.
45 55
46# machine support 56config S5PC110_DEV_ONENAND
57 bool
58 help
59 Compile in platform device definition for OneNAND1 controller
60
61menu "S5PC110 Machines"
47 62
48config MACH_AQUILA 63config MACH_AQUILA
49 bool "Samsung Aquila" 64 bool "Aquila"
50 select CPU_S5PV210 65 select CPU_S5PV210
51 select ARCH_SPARSEMEM_ENABLE 66 select ARCH_SPARSEMEM_ENABLE
52 select S5PV210_SETUP_FB_24BPP
53 select S3C_DEV_FB 67 select S3C_DEV_FB
68 select S5P_DEV_FIMC0
69 select S5P_DEV_FIMC1
70 select S5P_DEV_FIMC2
71 select S3C_DEV_HSMMC
72 select S3C_DEV_HSMMC1
73 select S3C_DEV_HSMMC2
74 select S5PC110_DEV_ONENAND
75 select S5PV210_SETUP_FB_24BPP
76 select S5PV210_SETUP_SDHCI
54 help 77 help
55 Machine support for the Samsung Aquila target based on S5PC110 SoC 78 Machine support for the Samsung Aquila target based on S5PC110 SoC
56 79
@@ -58,34 +81,64 @@ config MACH_GONI
58 bool "GONI" 81 bool "GONI"
59 select CPU_S5PV210 82 select CPU_S5PV210
60 select ARCH_SPARSEMEM_ENABLE 83 select ARCH_SPARSEMEM_ENABLE
84 select S3C_DEV_FB
85 select S5P_DEV_FIMC0
86 select S5P_DEV_FIMC1
87 select S5P_DEV_FIMC2
88 select S3C_DEV_HSMMC
89 select S3C_DEV_HSMMC1
90 select S3C_DEV_HSMMC2
91 select S5PC110_DEV_ONENAND
92 select S5PV210_SETUP_FB_24BPP
93 select S5PV210_SETUP_SDHCI
61 help 94 help
62 Machine support for Samsung GONI board 95 Machine support for Samsung GONI board
63 S5PC110(MCP) is one of package option of S5PV210 96 S5PC110(MCP) is one of package option of S5PV210
64 97
65config S5PC110_DEV_ONENAND 98config MACH_SMDKC110
66 bool 99 bool "SMDKC110"
100 select CPU_S5PV210
101 select ARCH_SPARSEMEM_ENABLE
102 select S3C_DEV_I2C1
103 select S3C_DEV_I2C2
104 select S3C_DEV_RTC
105 select S3C_DEV_WDT
106 select SAMSUNG_DEV_IDE
107 select S5PV210_SETUP_I2C1
108 select S5PV210_SETUP_I2C2
109 select S5PV210_SETUP_IDE
67 help 110 help
68 Compile in platform device definition for OneNAND1 controller 111 Machine support for Samsung SMDKC110
112 S5PC110(MCP) is one of package option of S5PV210
113
114endmenu
115
116menu "S5PV210 Machines"
69 117
70config MACH_SMDKV210 118config MACH_SMDKV210
71 bool "SMDKV210" 119 bool "SMDKV210"
72 select CPU_S5PV210 120 select CPU_S5PV210
73 select ARCH_SPARSEMEM_ENABLE 121 select ARCH_SPARSEMEM_ENABLE
122 select S3C_DEV_HSMMC
123 select S3C_DEV_HSMMC1
124 select S3C_DEV_HSMMC2
125 select S3C_DEV_HSMMC3
126 select S3C_DEV_I2C1
127 select S3C_DEV_I2C2
128 select S3C_DEV_RTC
129 select S3C_DEV_WDT
74 select SAMSUNG_DEV_ADC 130 select SAMSUNG_DEV_ADC
131 select SAMSUNG_DEV_IDE
132 select SAMSUNG_DEV_KEYPAD
75 select SAMSUNG_DEV_TS 133 select SAMSUNG_DEV_TS
76 select S3C_DEV_WDT 134 select S5PV210_SETUP_I2C1
77 select HAVE_S3C2410_WATCHDOG 135 select S5PV210_SETUP_I2C2
136 select S5PV210_SETUP_IDE
137 select S5PV210_SETUP_KEYPAD
138 select S5PV210_SETUP_SDHCI
78 help 139 help
79 Machine support for Samsung SMDKV210 140 Machine support for Samsung SMDKV210
80 141
81config MACH_SMDKC110 142endmenu
82 bool "SMDKC110"
83 select CPU_S5PV210
84 select ARCH_SPARSEMEM_ENABLE
85 select S3C_DEV_WDT
86 select HAVE_S3C2410_WATCHDOG
87 help
88 Machine support for Samsung SMDKC110
89 S5PC110(MCP) is one of package option of S5PV210
90 143
91endif 144endif
diff --git a/arch/arm/mach-s5pv210/Makefile b/arch/arm/mach-s5pv210/Makefile
index 30be9a6a4620..05048c5aa4c6 100644
--- a/arch/arm/mach-s5pv210/Makefile
+++ b/arch/arm/mach-s5pv210/Makefile
@@ -31,5 +31,7 @@ obj-$(CONFIG_S5PC110_DEV_ONENAND) += dev-onenand.o
31obj-$(CONFIG_S5PV210_SETUP_FB_24BPP) += setup-fb-24bpp.o 31obj-$(CONFIG_S5PV210_SETUP_FB_24BPP) += setup-fb-24bpp.o
32obj-$(CONFIG_S5PV210_SETUP_I2C1) += setup-i2c1.o 32obj-$(CONFIG_S5PV210_SETUP_I2C1) += setup-i2c1.o
33obj-$(CONFIG_S5PV210_SETUP_I2C2) += setup-i2c2.o 33obj-$(CONFIG_S5PV210_SETUP_I2C2) += setup-i2c2.o
34obj-$(CONFIG_S5PV210_SETUP_IDE) += setup-ide.o
35obj-$(CONFIG_S5PV210_SETUP_KEYPAD) += setup-keypad.o
34obj-$(CONFIG_S5PV210_SETUP_SDHCI) += setup-sdhci.o 36obj-$(CONFIG_S5PV210_SETUP_SDHCI) += setup-sdhci.o
35obj-$(CONFIG_S5PV210_SETUP_SDHCI_GPIO) += setup-sdhci-gpio.o 37obj-$(CONFIG_S5PV210_SETUP_SDHCI_GPIO) += setup-sdhci-gpio.o
diff --git a/arch/arm/mach-s5pv210/cpu.c b/arch/arm/mach-s5pv210/cpu.c
index 411a4a9cbfc7..b9f4d677cf55 100644
--- a/arch/arm/mach-s5pv210/cpu.c
+++ b/arch/arm/mach-s5pv210/cpu.c
@@ -31,9 +31,15 @@
31#include <plat/cpu.h> 31#include <plat/cpu.h>
32#include <plat/devs.h> 32#include <plat/devs.h>
33#include <plat/clock.h> 33#include <plat/clock.h>
34#include <plat/fb-core.h>
34#include <plat/s5pv210.h> 35#include <plat/s5pv210.h>
36#include <plat/adc-core.h>
37#include <plat/ata-core.h>
38#include <plat/fimc-core.h>
35#include <plat/iic-core.h> 39#include <plat/iic-core.h>
40#include <plat/keypad-core.h>
36#include <plat/sdhci.h> 41#include <plat/sdhci.h>
42#include <plat/reset.h>
37 43
38/* Initial IO mappings */ 44/* Initial IO mappings */
39 45
@@ -69,6 +75,11 @@ static void s5pv210_idle(void)
69 local_irq_enable(); 75 local_irq_enable();
70} 76}
71 77
78static void s5pv210_sw_reset(void)
79{
80 __raw_writel(0x1, S5P_SWRESET);
81}
82
72/* s5pv210_map_io 83/* s5pv210_map_io
73 * 84 *
74 * register the standard cpu IO areas 85 * register the standard cpu IO areas
@@ -76,21 +87,31 @@ static void s5pv210_idle(void)
76 87
77void __init s5pv210_map_io(void) 88void __init s5pv210_map_io(void)
78{ 89{
79#ifdef CONFIG_S3C_DEV_ADC
80 s3c_device_adc.name = "s3c64xx-adc";
81#endif
82
83 iotable_init(s5pv210_iodesc, ARRAY_SIZE(s5pv210_iodesc)); 90 iotable_init(s5pv210_iodesc, ARRAY_SIZE(s5pv210_iodesc));
84 91
85 /* initialise device information early */ 92 /* initialise device information early */
86 s5pv210_default_sdhci0(); 93 s5pv210_default_sdhci0();
87 s5pv210_default_sdhci1(); 94 s5pv210_default_sdhci1();
88 s5pv210_default_sdhci2(); 95 s5pv210_default_sdhci2();
96 s5pv210_default_sdhci3();
97
98 s3c_adc_setname("s3c64xx-adc");
99
100 s3c_cfcon_setname("s5pv210-pata");
101
102 s3c_fimc_setname(0, "s5pv210-fimc");
103 s3c_fimc_setname(1, "s5pv210-fimc");
104 s3c_fimc_setname(2, "s5pv210-fimc");
89 105
90 /* the i2c devices are directly compatible with s3c2440 */ 106 /* the i2c devices are directly compatible with s3c2440 */
91 s3c_i2c0_setname("s3c2440-i2c"); 107 s3c_i2c0_setname("s3c2440-i2c");
92 s3c_i2c1_setname("s3c2440-i2c"); 108 s3c_i2c1_setname("s3c2440-i2c");
93 s3c_i2c2_setname("s3c2440-i2c"); 109 s3c_i2c2_setname("s3c2440-i2c");
110
111 s3c_fb_setname("s5pv210-fb");
112
113 /* Use s5pv210-keypad instead of samsung-keypad */
114 samsung_keypad_setname("s5pv210-keypad");
94} 115}
95 116
96void __init s5pv210_init_clocks(int xtal) 117void __init s5pv210_init_clocks(int xtal)
@@ -138,5 +159,8 @@ int __init s5pv210_init(void)
138 /* set idle function */ 159 /* set idle function */
139 pm_idle = s5pv210_idle; 160 pm_idle = s5pv210_idle;
140 161
162 /* set sw_reset function */
163 s5p_reset_hook = s5pv210_sw_reset;
164
141 return sysdev_register(&s5pv210_sysdev); 165 return sysdev_register(&s5pv210_sysdev);
142} 166}
diff --git a/arch/arm/mach-s5pv210/dev-audio.c b/arch/arm/mach-s5pv210/dev-audio.c
index 6e215330a1be..21dc6cf955c3 100644
--- a/arch/arm/mach-s5pv210/dev-audio.c
+++ b/arch/arm/mach-s5pv210/dev-audio.c
@@ -10,11 +10,11 @@
10 10
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
13#include <linux/gpio.h>
13 14
14#include <plat/gpio-cfg.h> 15#include <plat/gpio-cfg.h>
15#include <plat/audio.h> 16#include <plat/audio.h>
16 17
17#include <mach/gpio.h>
18#include <mach/map.h> 18#include <mach/map.h>
19#include <mach/dma.h> 19#include <mach/dma.h>
20#include <mach/irqs.h> 20#include <mach/irqs.h>
diff --git a/arch/arm/mach-s5pv210/dev-onenand.c b/arch/arm/mach-s5pv210/dev-onenand.c
index 34997b752f93..f8ede33ee82b 100644
--- a/arch/arm/mach-s5pv210/dev-onenand.c
+++ b/arch/arm/mach-s5pv210/dev-onenand.c
@@ -27,9 +27,14 @@ static struct resource s5pc110_onenand_resources[] = {
27 }, 27 },
28 [1] = { 28 [1] = {
29 .start = S5PC110_PA_ONENAND_DMA, 29 .start = S5PC110_PA_ONENAND_DMA,
30 .end = S5PC110_PA_ONENAND_DMA + SZ_2K - 1, 30 .end = S5PC110_PA_ONENAND_DMA + SZ_8K - 1,
31 .flags = IORESOURCE_MEM, 31 .flags = IORESOURCE_MEM,
32 }, 32 },
33 [2] = {
34 .start = IRQ_ONENAND_AUDI,
35 .end = IRQ_ONENAND_AUDI,
36 .flags = IORESOURCE_IRQ,
37 },
33}; 38};
34 39
35struct platform_device s5pc110_device_onenand = { 40struct platform_device s5pc110_device_onenand = {
diff --git a/arch/arm/mach-s5pv210/dev-spi.c b/arch/arm/mach-s5pv210/dev-spi.c
index 337a62b57a0b..826cdbc43e20 100644
--- a/arch/arm/mach-s5pv210/dev-spi.c
+++ b/arch/arm/mach-s5pv210/dev-spi.c
@@ -10,11 +10,11 @@
10 10
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
13#include <linux/gpio.h>
13 14
14#include <mach/dma.h> 15#include <mach/dma.h>
15#include <mach/map.h> 16#include <mach/map.h>
16#include <mach/irqs.h> 17#include <mach/irqs.h>
17#include <mach/gpio.h>
18#include <mach/spi-clocks.h> 18#include <mach/spi-clocks.h>
19 19
20#include <plat/s3c64xx-spi.h> 20#include <plat/s3c64xx-spi.h>
diff --git a/arch/arm/mach-s5pv210/gpiolib.c b/arch/arm/mach-s5pv210/gpiolib.c
index 9ea8972e023d..0d459112d039 100644
--- a/arch/arm/mach-s5pv210/gpiolib.c
+++ b/arch/arm/mach-s5pv210/gpiolib.c
@@ -207,6 +207,20 @@ static struct s3c_gpio_chip s5pv210_gpio_4bit[] = {
207 .label = "MP03", 207 .label = "MP03",
208 }, 208 },
209 }, { 209 }, {
210 .config = &gpio_cfg_noint,
211 .chip = {
212 .base = S5PV210_MP04(0),
213 .ngpio = S5PV210_GPIO_MP04_NR,
214 .label = "MP04",
215 },
216 }, {
217 .config = &gpio_cfg_noint,
218 .chip = {
219 .base = S5PV210_MP05(0),
220 .ngpio = S5PV210_GPIO_MP05_NR,
221 .label = "MP05",
222 },
223 }, {
210 .base = (S5P_VA_GPIO + 0xC00), 224 .base = (S5P_VA_GPIO + 0xC00),
211 .config = &gpio_cfg_noint, 225 .config = &gpio_cfg_noint,
212 .chip = { 226 .chip = {
diff --git a/arch/arm/mach-s5pv210/include/mach/gpio.h b/arch/arm/mach-s5pv210/include/mach/gpio.h
index d6461ba2b71d..1f4b595534c2 100644
--- a/arch/arm/mach-s5pv210/include/mach/gpio.h
+++ b/arch/arm/mach-s5pv210/include/mach/gpio.h
@@ -52,6 +52,8 @@
52#define S5PV210_GPIO_MP01_NR (8) 52#define S5PV210_GPIO_MP01_NR (8)
53#define S5PV210_GPIO_MP02_NR (4) 53#define S5PV210_GPIO_MP02_NR (4)
54#define S5PV210_GPIO_MP03_NR (8) 54#define S5PV210_GPIO_MP03_NR (8)
55#define S5PV210_GPIO_MP04_NR (8)
56#define S5PV210_GPIO_MP05_NR (8)
55 57
56/* GPIO bank numbers */ 58/* GPIO bank numbers */
57 59
@@ -94,6 +96,8 @@ enum s5p_gpio_number {
94 S5PV210_GPIO_MP01_START = S5PV210_GPIO_NEXT(S5PV210_GPIO_J4), 96 S5PV210_GPIO_MP01_START = S5PV210_GPIO_NEXT(S5PV210_GPIO_J4),
95 S5PV210_GPIO_MP02_START = S5PV210_GPIO_NEXT(S5PV210_GPIO_MP01), 97 S5PV210_GPIO_MP02_START = S5PV210_GPIO_NEXT(S5PV210_GPIO_MP01),
96 S5PV210_GPIO_MP03_START = S5PV210_GPIO_NEXT(S5PV210_GPIO_MP02), 98 S5PV210_GPIO_MP03_START = S5PV210_GPIO_NEXT(S5PV210_GPIO_MP02),
99 S5PV210_GPIO_MP04_START = S5PV210_GPIO_NEXT(S5PV210_GPIO_MP03),
100 S5PV210_GPIO_MP05_START = S5PV210_GPIO_NEXT(S5PV210_GPIO_MP04),
97}; 101};
98 102
99/* S5PV210 GPIO number definitions */ 103/* S5PV210 GPIO number definitions */
@@ -127,13 +131,15 @@ enum s5p_gpio_number {
127#define S5PV210_MP01(_nr) (S5PV210_GPIO_MP01_START + (_nr)) 131#define S5PV210_MP01(_nr) (S5PV210_GPIO_MP01_START + (_nr))
128#define S5PV210_MP02(_nr) (S5PV210_GPIO_MP02_START + (_nr)) 132#define S5PV210_MP02(_nr) (S5PV210_GPIO_MP02_START + (_nr))
129#define S5PV210_MP03(_nr) (S5PV210_GPIO_MP03_START + (_nr)) 133#define S5PV210_MP03(_nr) (S5PV210_GPIO_MP03_START + (_nr))
134#define S5PV210_MP04(_nr) (S5PV210_GPIO_MP04_START + (_nr))
135#define S5PV210_MP05(_nr) (S5PV210_GPIO_MP05_START + (_nr))
130 136
131/* the end of the S5PV210 specific gpios */ 137/* the end of the S5PV210 specific gpios */
132#define S5PV210_GPIO_END (S5PV210_MP03(S5PV210_GPIO_MP03_NR) + 1) 138#define S5PV210_GPIO_END (S5PV210_MP05(S5PV210_GPIO_MP05_NR) + 1)
133#define S3C_GPIO_END S5PV210_GPIO_END 139#define S3C_GPIO_END S5PV210_GPIO_END
134 140
135/* define the number of gpios we need to the one after the MP03() range */ 141/* define the number of gpios we need to the one after the MP05() range */
136#define ARCH_NR_GPIOS (S5PV210_MP03(S5PV210_GPIO_MP03_NR) + \ 142#define ARCH_NR_GPIOS (S5PV210_MP05(S5PV210_GPIO_MP05_NR) + \
137 CONFIG_SAMSUNG_GPIO_EXTRA + 1) 143 CONFIG_SAMSUNG_GPIO_EXTRA + 1)
138 144
139#include <asm-generic/gpio.h> 145#include <asm-generic/gpio.h>
diff --git a/arch/arm/mach-s5pv210/include/mach/irqs.h b/arch/arm/mach-s5pv210/include/mach/irqs.h
index 96895378ea27..e1c020e5a49b 100644
--- a/arch/arm/mach-s5pv210/include/mach/irqs.h
+++ b/arch/arm/mach-s5pv210/include/mach/irqs.h
@@ -36,7 +36,7 @@
36 36
37/* VIC1: ARM, Power, Memory, Connectivity, Storage */ 37/* VIC1: ARM, Power, Memory, Connectivity, Storage */
38 38
39#define IRQ_CORTEX0 S5P_IRQ_VIC1(0) 39#define IRQ_PMU S5P_IRQ_VIC1(0)
40#define IRQ_CORTEX1 S5P_IRQ_VIC1(1) 40#define IRQ_CORTEX1 S5P_IRQ_VIC1(1)
41#define IRQ_CORTEX2 S5P_IRQ_VIC1(2) 41#define IRQ_CORTEX2 S5P_IRQ_VIC1(2)
42#define IRQ_CORTEX3 S5P_IRQ_VIC1(3) 42#define IRQ_CORTEX3 S5P_IRQ_VIC1(3)
@@ -45,7 +45,7 @@
45#define IRQ_IEMIEC S5P_IRQ_VIC1(6) 45#define IRQ_IEMIEC S5P_IRQ_VIC1(6)
46#define IRQ_ONENAND S5P_IRQ_VIC1(7) 46#define IRQ_ONENAND S5P_IRQ_VIC1(7)
47#define IRQ_NFC S5P_IRQ_VIC1(8) 47#define IRQ_NFC S5P_IRQ_VIC1(8)
48#define IRQ_CFC S5P_IRQ_VIC1(9) 48#define IRQ_CFCON S5P_IRQ_VIC1(9)
49#define IRQ_UART0 S5P_IRQ_VIC1(10) 49#define IRQ_UART0 S5P_IRQ_VIC1(10)
50#define IRQ_UART1 S5P_IRQ_VIC1(11) 50#define IRQ_UART1 S5P_IRQ_VIC1(11)
51#define IRQ_UART2 S5P_IRQ_VIC1(12) 51#define IRQ_UART2 S5P_IRQ_VIC1(12)
diff --git a/arch/arm/mach-s5pv210/include/mach/map.h b/arch/arm/mach-s5pv210/include/mach/map.h
index 34eb168ec950..dd4fb6bf14b5 100644
--- a/arch/arm/mach-s5pv210/include/mach/map.h
+++ b/arch/arm/mach-s5pv210/include/mach/map.h
@@ -32,6 +32,8 @@
32#define S5PV210_PA_SPI0 0xE1300000 32#define S5PV210_PA_SPI0 0xE1300000
33#define S5PV210_PA_SPI1 0xE1400000 33#define S5PV210_PA_SPI1 0xE1400000
34 34
35#define S5PV210_PA_KEYPAD (0xE1600000)
36
35#define S5PV210_PA_IIC0 (0xE1800000) 37#define S5PV210_PA_IIC0 (0xE1800000)
36#define S5PV210_PA_IIC1 (0xFAB00000) 38#define S5PV210_PA_IIC1 (0xFAB00000)
37#define S5PV210_PA_IIC2 (0xE1A00000) 39#define S5PV210_PA_IIC2 (0xE1A00000)
@@ -43,6 +45,7 @@
43 45
44#define S5PV210_PA_WATCHDOG (0xE2700000) 46#define S5PV210_PA_WATCHDOG (0xE2700000)
45 47
48#define S5PV210_PA_RTC (0xE2800000)
46#define S5PV210_PA_UART (0xE2900000) 49#define S5PV210_PA_UART (0xE2900000)
47 50
48#define S5P_PA_UART0 (S5PV210_PA_UART + 0x0) 51#define S5P_PA_UART0 (S5PV210_PA_UART + 0x0)
@@ -54,12 +57,18 @@
54 57
55#define S5PV210_PA_SROMC (0xE8000000) 58#define S5PV210_PA_SROMC (0xE8000000)
56 59
60#define S5PV210_PA_CFCON (0xE8200000)
61
57#define S5PV210_PA_MDMA 0xFA200000 62#define S5PV210_PA_MDMA 0xFA200000
58#define S5PV210_PA_PDMA0 0xE0900000 63#define S5PV210_PA_PDMA0 0xE0900000
59#define S5PV210_PA_PDMA1 0xE0A00000 64#define S5PV210_PA_PDMA1 0xE0A00000
60 65
61#define S5PV210_PA_FB (0xF8000000) 66#define S5PV210_PA_FB (0xF8000000)
62 67
68#define S5PV210_PA_FIMC0 (0xFB200000)
69#define S5PV210_PA_FIMC1 (0xFB300000)
70#define S5PV210_PA_FIMC2 (0xFB400000)
71
63#define S5PV210_PA_HSMMC(x) (0xEB000000 + ((x) * 0x100000)) 72#define S5PV210_PA_HSMMC(x) (0xEB000000 + ((x) * 0x100000))
64 73
65#define S5PV210_PA_VIC0 (0xF2000000) 74#define S5PV210_PA_VIC0 (0xF2000000)
@@ -97,12 +106,19 @@
97#define S3C_PA_HSMMC0 S5PV210_PA_HSMMC(0) 106#define S3C_PA_HSMMC0 S5PV210_PA_HSMMC(0)
98#define S3C_PA_HSMMC1 S5PV210_PA_HSMMC(1) 107#define S3C_PA_HSMMC1 S5PV210_PA_HSMMC(1)
99#define S3C_PA_HSMMC2 S5PV210_PA_HSMMC(2) 108#define S3C_PA_HSMMC2 S5PV210_PA_HSMMC(2)
109#define S3C_PA_HSMMC3 S5PV210_PA_HSMMC(3)
100#define S3C_PA_IIC S5PV210_PA_IIC0 110#define S3C_PA_IIC S5PV210_PA_IIC0
101#define S3C_PA_IIC1 S5PV210_PA_IIC1 111#define S3C_PA_IIC1 S5PV210_PA_IIC1
102#define S3C_PA_IIC2 S5PV210_PA_IIC2 112#define S3C_PA_IIC2 S5PV210_PA_IIC2
103#define S3C_PA_FB S5PV210_PA_FB 113#define S3C_PA_FB S5PV210_PA_FB
114#define S3C_PA_RTC S5PV210_PA_RTC
104#define S3C_PA_WDT S5PV210_PA_WATCHDOG 115#define S3C_PA_WDT S5PV210_PA_WATCHDOG
116#define S5P_PA_FIMC0 S5PV210_PA_FIMC0
117#define S5P_PA_FIMC1 S5PV210_PA_FIMC1
118#define S5P_PA_FIMC2 S5PV210_PA_FIMC2
105 119
106#define SAMSUNG_PA_ADC S5PV210_PA_ADC 120#define SAMSUNG_PA_ADC S5PV210_PA_ADC
121#define SAMSUNG_PA_CFCON S5PV210_PA_CFCON
122#define SAMSUNG_PA_KEYPAD S5PV210_PA_KEYPAD
107 123
108#endif /* __ASM_ARCH_MAP_H */ 124#endif /* __ASM_ARCH_MAP_H */
diff --git a/arch/arm/mach-s5pv210/include/mach/memory.h b/arch/arm/mach-s5pv210/include/mach/memory.h
index 379117e27600..d503e0c4ce4f 100644
--- a/arch/arm/mach-s5pv210/include/mach/memory.h
+++ b/arch/arm/mach-s5pv210/include/mach/memory.h
@@ -16,8 +16,13 @@
16#define PHYS_OFFSET UL(0x20000000) 16#define PHYS_OFFSET UL(0x20000000)
17#define CONSISTENT_DMA_SIZE (SZ_8M + SZ_4M + SZ_2M) 17#define CONSISTENT_DMA_SIZE (SZ_8M + SZ_4M + SZ_2M)
18 18
19/* Maximum of 256MiB in one bank */ 19/*
20#define MAX_PHYSMEM_BITS 32 20 * Sparsemem support
21 * Physical memory can be located from 0x20000000 to 0x7fffffff,
22 * so MAX_PHYSMEM_BITS is 31.
23 */
24
25#define MAX_PHYSMEM_BITS 31
21#define SECTION_SIZE_BITS 28 26#define SECTION_SIZE_BITS 28
22 27
23#endif /* __ASM_ARCH_MEMORY_H */ 28#endif /* __ASM_ARCH_MEMORY_H */
diff --git a/arch/arm/mach-s5pv210/include/mach/regs-clock.h b/arch/arm/mach-s5pv210/include/mach/regs-clock.h
index 2a25ab40c863..499aef737476 100644
--- a/arch/arm/mach-s5pv210/include/mach/regs-clock.h
+++ b/arch/arm/mach-s5pv210/include/mach/regs-clock.h
@@ -90,6 +90,8 @@
90#define S5P_CLKDIV0_PCLK66_SHIFT (28) 90#define S5P_CLKDIV0_PCLK66_SHIFT (28)
91#define S5P_CLKDIV0_PCLK66_MASK (0x7 << S5P_CLKDIV0_PCLK66_SHIFT) 91#define S5P_CLKDIV0_PCLK66_MASK (0x7 << S5P_CLKDIV0_PCLK66_SHIFT)
92 92
93#define S5P_SWRESET S5P_CLKREG(0x2000)
94
93/* Registers related to power management */ 95/* Registers related to power management */
94#define S5P_PWR_CFG S5P_CLKREG(0xC000) 96#define S5P_PWR_CFG S5P_CLKREG(0xC000)
95#define S5P_EINT_WAKEUP_MASK S5P_CLKREG(0xC004) 97#define S5P_EINT_WAKEUP_MASK S5P_CLKREG(0xC004)
diff --git a/arch/arm/mach-s5pv210/include/mach/system.h b/arch/arm/mach-s5pv210/include/mach/system.h
index 1ca04d5025b3..af8a200b2135 100644
--- a/arch/arm/mach-s5pv210/include/mach/system.h
+++ b/arch/arm/mach-s5pv210/include/mach/system.h
@@ -13,12 +13,9 @@
13#ifndef __ASM_ARCH_SYSTEM_H 13#ifndef __ASM_ARCH_SYSTEM_H
14#define __ASM_ARCH_SYSTEM_H __FILE__ 14#define __ASM_ARCH_SYSTEM_H __FILE__
15 15
16static void arch_idle(void) 16#include <plat/system-reset.h>
17{
18 /* nothing here yet */
19}
20 17
21static void arch_reset(char mode, const char *cmd) 18static void arch_idle(void)
22{ 19{
23 /* nothing here yet */ 20 /* nothing here yet */
24} 21}
diff --git a/arch/arm/mach-s5pv210/mach-aquila.c b/arch/arm/mach-s5pv210/mach-aquila.c
index 10bc76ec4025..0dda8012d6b2 100644
--- a/arch/arm/mach-s5pv210/mach-aquila.c
+++ b/arch/arm/mach-s5pv210/mach-aquila.c
@@ -13,6 +13,12 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/serial_core.h> 14#include <linux/serial_core.h>
15#include <linux/fb.h> 15#include <linux/fb.h>
16#include <linux/i2c.h>
17#include <linux/i2c-gpio.h>
18#include <linux/mfd/max8998.h>
19#include <linux/gpio_keys.h>
20#include <linux/input.h>
21#include <linux/gpio.h>
16 22
17#include <asm/mach/arch.h> 23#include <asm/mach/arch.h>
18#include <asm/mach/map.h> 24#include <asm/mach/map.h>
@@ -23,61 +29,69 @@
23#include <mach/regs-clock.h> 29#include <mach/regs-clock.h>
24#include <mach/regs-fb.h> 30#include <mach/regs-fb.h>
25 31
32#include <plat/gpio-cfg.h>
26#include <plat/regs-serial.h> 33#include <plat/regs-serial.h>
27#include <plat/s5pv210.h> 34#include <plat/s5pv210.h>
28#include <plat/devs.h> 35#include <plat/devs.h>
29#include <plat/cpu.h> 36#include <plat/cpu.h>
30#include <plat/fb.h> 37#include <plat/fb.h>
38#include <plat/fimc-core.h>
39#include <plat/sdhci.h>
31 40
32/* Following are default values for UCON, ULCON and UFCON UART registers */ 41/* Following are default values for UCON, ULCON and UFCON UART registers */
33#define S5PV210_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \ 42#define AQUILA_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \
34 S3C2410_UCON_RXILEVEL | \ 43 S3C2410_UCON_RXILEVEL | \
35 S3C2410_UCON_TXIRQMODE | \ 44 S3C2410_UCON_TXIRQMODE | \
36 S3C2410_UCON_RXIRQMODE | \ 45 S3C2410_UCON_RXIRQMODE | \
37 S3C2410_UCON_RXFIFO_TOI | \ 46 S3C2410_UCON_RXFIFO_TOI | \
38 S3C2443_UCON_RXERR_IRQEN) 47 S3C2443_UCON_RXERR_IRQEN)
39 48
40#define S5PV210_ULCON_DEFAULT S3C2410_LCON_CS8 49#define AQUILA_ULCON_DEFAULT S3C2410_LCON_CS8
41 50
42#define S5PV210_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \ 51#define AQUILA_UFCON_DEFAULT S3C2410_UFCON_FIFOMODE
43 S5PV210_UFCON_TXTRIG4 | \
44 S5PV210_UFCON_RXTRIG4)
45 52
46static struct s3c2410_uartcfg smdkv210_uartcfgs[] __initdata = { 53static struct s3c2410_uartcfg aquila_uartcfgs[] __initdata = {
47 [0] = { 54 [0] = {
48 .hwport = 0, 55 .hwport = 0,
49 .flags = 0, 56 .flags = 0,
50 .ucon = S5PV210_UCON_DEFAULT, 57 .ucon = AQUILA_UCON_DEFAULT,
51 .ulcon = S5PV210_ULCON_DEFAULT, 58 .ulcon = AQUILA_ULCON_DEFAULT,
52 .ufcon = S5PV210_UFCON_DEFAULT, 59 /*
60 * Actually UART0 can support 256 bytes fifo, but aquila board
61 * supports 128 bytes fifo because of initial chip bug
62 */
63 .ufcon = AQUILA_UFCON_DEFAULT |
64 S5PV210_UFCON_TXTRIG128 | S5PV210_UFCON_RXTRIG128,
53 }, 65 },
54 [1] = { 66 [1] = {
55 .hwport = 1, 67 .hwport = 1,
56 .flags = 0, 68 .flags = 0,
57 .ucon = S5PV210_UCON_DEFAULT, 69 .ucon = AQUILA_UCON_DEFAULT,
58 .ulcon = S5PV210_ULCON_DEFAULT, 70 .ulcon = AQUILA_ULCON_DEFAULT,
59 .ufcon = S5PV210_UFCON_DEFAULT, 71 .ufcon = AQUILA_UFCON_DEFAULT |
72 S5PV210_UFCON_TXTRIG64 | S5PV210_UFCON_RXTRIG64,
60 }, 73 },
61 [2] = { 74 [2] = {
62 .hwport = 2, 75 .hwport = 2,
63 .flags = 0, 76 .flags = 0,
64 .ucon = S5PV210_UCON_DEFAULT, 77 .ucon = AQUILA_UCON_DEFAULT,
65 .ulcon = S5PV210_ULCON_DEFAULT, 78 .ulcon = AQUILA_ULCON_DEFAULT,
66 .ufcon = S5PV210_UFCON_DEFAULT, 79 .ufcon = AQUILA_UFCON_DEFAULT |
80 S5PV210_UFCON_TXTRIG16 | S5PV210_UFCON_RXTRIG16,
67 }, 81 },
68 [3] = { 82 [3] = {
69 .hwport = 3, 83 .hwport = 3,
70 .flags = 0, 84 .flags = 0,
71 .ucon = S5PV210_UCON_DEFAULT, 85 .ucon = AQUILA_UCON_DEFAULT,
72 .ulcon = S5PV210_ULCON_DEFAULT, 86 .ulcon = AQUILA_ULCON_DEFAULT,
73 .ufcon = S5PV210_UFCON_DEFAULT, 87 .ufcon = AQUILA_UFCON_DEFAULT |
88 S5PV210_UFCON_TXTRIG16 | S5PV210_UFCON_RXTRIG16,
74 }, 89 },
75}; 90};
76 91
77/* Frame Buffer */ 92/* Frame Buffer */
78static struct s3c_fb_pd_win aquila_fb_win0 = { 93static struct s3c_fb_pd_win aquila_fb_win0 = {
79 .win_mode = { 94 .win_mode = {
80 .pixclock = 1000000000000ULL / ((16+16+2+480)*(28+3+2+800)*60),
81 .left_margin = 16, 95 .left_margin = 16,
82 .right_margin = 16, 96 .right_margin = 16,
83 .upper_margin = 3, 97 .upper_margin = 3,
@@ -93,7 +107,6 @@ static struct s3c_fb_pd_win aquila_fb_win0 = {
93 107
94static struct s3c_fb_pd_win aquila_fb_win1 = { 108static struct s3c_fb_pd_win aquila_fb_win1 = {
95 .win_mode = { 109 .win_mode = {
96 .pixclock = 1000000000000ULL / ((16+16+2+480)*(28+3+2+800)*60),
97 .left_margin = 16, 110 .left_margin = 16,
98 .right_margin = 16, 111 .right_margin = 16,
99 .upper_margin = 3, 112 .upper_margin = 3,
@@ -116,19 +129,383 @@ static struct s3c_fb_platdata aquila_lcd_pdata __initdata = {
116 .setup_gpio = s5pv210_fb_gpio_setup_24bpp, 129 .setup_gpio = s5pv210_fb_gpio_setup_24bpp,
117}; 130};
118 131
132/* MAX8998 regulators */
133#if defined(CONFIG_REGULATOR_MAX8998) || defined(CONFIG_REGULATOR_MAX8998_MODULE)
134
135static struct regulator_init_data aquila_ldo2_data = {
136 .constraints = {
137 .name = "VALIVE_1.1V",
138 .min_uV = 1100000,
139 .max_uV = 1100000,
140 .apply_uV = 1,
141 .always_on = 1,
142 .state_mem = {
143 .enabled = 1,
144 },
145 },
146};
147
148static struct regulator_init_data aquila_ldo3_data = {
149 .constraints = {
150 .name = "VUSB/MIPI_1.1V",
151 .min_uV = 1100000,
152 .max_uV = 1100000,
153 .apply_uV = 1,
154 .always_on = 1,
155 },
156};
157
158static struct regulator_init_data aquila_ldo4_data = {
159 .constraints = {
160 .name = "VDAC_3.3V",
161 .min_uV = 3300000,
162 .max_uV = 3300000,
163 .apply_uV = 1,
164 },
165};
166
167static struct regulator_init_data aquila_ldo5_data = {
168 .constraints = {
169 .name = "VTF_2.8V",
170 .min_uV = 2800000,
171 .max_uV = 2800000,
172 .apply_uV = 1,
173 },
174};
175
176static struct regulator_init_data aquila_ldo6_data = {
177 .constraints = {
178 .name = "VCC_3.3V",
179 .min_uV = 3300000,
180 .max_uV = 3300000,
181 .apply_uV = 1,
182 },
183};
184
185static struct regulator_init_data aquila_ldo7_data = {
186 .constraints = {
187 .name = "VCC_3.0V",
188 .min_uV = 3000000,
189 .max_uV = 3000000,
190 .apply_uV = 1,
191 .boot_on = 1,
192 .always_on = 1,
193 },
194};
195
196static struct regulator_init_data aquila_ldo8_data = {
197 .constraints = {
198 .name = "VUSB/VADC_3.3V",
199 .min_uV = 3300000,
200 .max_uV = 3300000,
201 .apply_uV = 1,
202 .always_on = 1,
203 },
204};
205
206static struct regulator_init_data aquila_ldo9_data = {
207 .constraints = {
208 .name = "VCC/VCAM_2.8V",
209 .min_uV = 2800000,
210 .max_uV = 2800000,
211 .apply_uV = 1,
212 .always_on = 1,
213 },
214};
215
216static struct regulator_init_data aquila_ldo10_data = {
217 .constraints = {
218 .name = "VPLL_1.1V",
219 .min_uV = 1100000,
220 .max_uV = 1100000,
221 .apply_uV = 1,
222 .boot_on = 1,
223 },
224};
225
226static struct regulator_init_data aquila_ldo11_data = {
227 .constraints = {
228 .name = "CAM_IO_2.8V",
229 .min_uV = 2800000,
230 .max_uV = 2800000,
231 .apply_uV = 1,
232 .always_on = 1,
233 },
234};
235
236static struct regulator_init_data aquila_ldo12_data = {
237 .constraints = {
238 .name = "CAM_ISP_1.2V",
239 .min_uV = 1200000,
240 .max_uV = 1200000,
241 .apply_uV = 1,
242 .always_on = 1,
243 },
244};
245
246static struct regulator_init_data aquila_ldo13_data = {
247 .constraints = {
248 .name = "CAM_A_2.8V",
249 .min_uV = 2800000,
250 .max_uV = 2800000,
251 .apply_uV = 1,
252 .always_on = 1,
253 },
254};
255
256static struct regulator_init_data aquila_ldo14_data = {
257 .constraints = {
258 .name = "CAM_CIF_1.8V",
259 .min_uV = 1800000,
260 .max_uV = 1800000,
261 .apply_uV = 1,
262 .always_on = 1,
263 },
264};
265
266static struct regulator_init_data aquila_ldo15_data = {
267 .constraints = {
268 .name = "CAM_AF_3.3V",
269 .min_uV = 3300000,
270 .max_uV = 3300000,
271 .apply_uV = 1,
272 .always_on = 1,
273 },
274};
275
276static struct regulator_init_data aquila_ldo16_data = {
277 .constraints = {
278 .name = "VMIPI_1.8V",
279 .min_uV = 1800000,
280 .max_uV = 1800000,
281 .apply_uV = 1,
282 .always_on = 1,
283 },
284};
285
286static struct regulator_init_data aquila_ldo17_data = {
287 .constraints = {
288 .name = "CAM_8M_1.8V",
289 .min_uV = 1800000,
290 .max_uV = 1800000,
291 .apply_uV = 1,
292 .always_on = 1,
293 },
294};
295
296/* BUCK */
297static struct regulator_consumer_supply buck1_consumer[] = {
298 { .supply = "vddarm", },
299};
300
301static struct regulator_consumer_supply buck2_consumer[] = {
302 { .supply = "vddint", },
303};
304
305static struct regulator_init_data aquila_buck1_data = {
306 .constraints = {
307 .name = "VARM_1.2V",
308 .min_uV = 1200000,
309 .max_uV = 1200000,
310 .apply_uV = 1,
311 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
312 REGULATOR_CHANGE_STATUS,
313 },
314 .num_consumer_supplies = ARRAY_SIZE(buck1_consumer),
315 .consumer_supplies = buck1_consumer,
316};
317
318static struct regulator_init_data aquila_buck2_data = {
319 .constraints = {
320 .name = "VINT_1.2V",
321 .min_uV = 1200000,
322 .max_uV = 1200000,
323 .apply_uV = 1,
324 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
325 REGULATOR_CHANGE_STATUS,
326 },
327 .num_consumer_supplies = ARRAY_SIZE(buck2_consumer),
328 .consumer_supplies = buck2_consumer,
329};
330
331static struct regulator_init_data aquila_buck3_data = {
332 .constraints = {
333 .name = "VCC_1.8V",
334 .min_uV = 1800000,
335 .max_uV = 1800000,
336 .apply_uV = 1,
337 .state_mem = {
338 .enabled = 1,
339 },
340 },
341};
342
343static struct regulator_init_data aquila_buck4_data = {
344 .constraints = {
345 .name = "CAM_CORE_1.2V",
346 .min_uV = 1200000,
347 .max_uV = 1200000,
348 .apply_uV = 1,
349 .always_on = 1,
350 },
351};
352
353static struct max8998_regulator_data aquila_regulators[] = {
354 { MAX8998_LDO2, &aquila_ldo2_data },
355 { MAX8998_LDO3, &aquila_ldo3_data },
356 { MAX8998_LDO4, &aquila_ldo4_data },
357 { MAX8998_LDO5, &aquila_ldo5_data },
358 { MAX8998_LDO6, &aquila_ldo6_data },
359 { MAX8998_LDO7, &aquila_ldo7_data },
360 { MAX8998_LDO8, &aquila_ldo8_data },
361 { MAX8998_LDO9, &aquila_ldo9_data },
362 { MAX8998_LDO10, &aquila_ldo10_data },
363 { MAX8998_LDO11, &aquila_ldo11_data },
364 { MAX8998_LDO12, &aquila_ldo12_data },
365 { MAX8998_LDO13, &aquila_ldo13_data },
366 { MAX8998_LDO14, &aquila_ldo14_data },
367 { MAX8998_LDO15, &aquila_ldo15_data },
368 { MAX8998_LDO16, &aquila_ldo16_data },
369 { MAX8998_LDO17, &aquila_ldo17_data },
370 { MAX8998_BUCK1, &aquila_buck1_data },
371 { MAX8998_BUCK2, &aquila_buck2_data },
372 { MAX8998_BUCK3, &aquila_buck3_data },
373 { MAX8998_BUCK4, &aquila_buck4_data },
374};
375
376static struct max8998_platform_data aquila_max8998_pdata = {
377 .num_regulators = ARRAY_SIZE(aquila_regulators),
378 .regulators = aquila_regulators,
379};
380#endif
381
382/* GPIO I2C PMIC */
383#define AP_I2C_GPIO_PMIC_BUS_4 4
384static struct i2c_gpio_platform_data aquila_i2c_gpio_pmic_data = {
385 .sda_pin = S5PV210_GPJ4(0), /* XMSMCSN */
386 .scl_pin = S5PV210_GPJ4(3), /* XMSMIRQN */
387};
388
389static struct platform_device aquila_i2c_gpio_pmic = {
390 .name = "i2c-gpio",
391 .id = AP_I2C_GPIO_PMIC_BUS_4,
392 .dev = {
393 .platform_data = &aquila_i2c_gpio_pmic_data,
394 },
395};
396
397static struct i2c_board_info i2c_gpio_pmic_devs[] __initdata = {
398#if defined(CONFIG_REGULATOR_MAX8998) || defined(CONFIG_REGULATOR_MAX8998_MODULE)
399 {
400 /* 0xCC when SRAD = 0 */
401 I2C_BOARD_INFO("max8998", 0xCC >> 1),
402 .platform_data = &aquila_max8998_pdata,
403 },
404#endif
405};
406
407/* PMIC Power button */
408static struct gpio_keys_button aquila_gpio_keys_table[] = {
409 {
410 .code = KEY_POWER,
411 .gpio = S5PV210_GPH2(6),
412 .desc = "gpio-keys: KEY_POWER",
413 .type = EV_KEY,
414 .active_low = 1,
415 .wakeup = 1,
416 .debounce_interval = 1,
417 },
418};
419
420static struct gpio_keys_platform_data aquila_gpio_keys_data = {
421 .buttons = aquila_gpio_keys_table,
422 .nbuttons = ARRAY_SIZE(aquila_gpio_keys_table),
423};
424
425static struct platform_device aquila_device_gpiokeys = {
426 .name = "gpio-keys",
427 .dev = {
428 .platform_data = &aquila_gpio_keys_data,
429 },
430};
431
432static void __init aquila_pmic_init(void)
433{
434 /* AP_PMIC_IRQ: EINT7 */
435 s3c_gpio_cfgpin(S5PV210_GPH0(7), S3C_GPIO_SFN(0xf));
436 s3c_gpio_setpull(S5PV210_GPH0(7), S3C_GPIO_PULL_UP);
437
438 /* nPower: EINT22 */
439 s3c_gpio_cfgpin(S5PV210_GPH2(6), S3C_GPIO_SFN(0xf));
440 s3c_gpio_setpull(S5PV210_GPH2(6), S3C_GPIO_PULL_UP);
441}
442
443/* MoviNAND */
444static struct s3c_sdhci_platdata aquila_hsmmc0_data __initdata = {
445 .max_width = 4,
446 .cd_type = S3C_SDHCI_CD_PERMANENT,
447};
448
449/* Wireless LAN */
450static struct s3c_sdhci_platdata aquila_hsmmc1_data __initdata = {
451 .max_width = 4,
452 .cd_type = S3C_SDHCI_CD_EXTERNAL,
453 /* ext_cd_{init,cleanup} callbacks will be added later */
454};
455
456/* External Flash */
457#define AQUILA_EXT_FLASH_EN S5PV210_MP05(4)
458#define AQUILA_EXT_FLASH_CD S5PV210_GPH3(4)
459static struct s3c_sdhci_platdata aquila_hsmmc2_data __initdata = {
460 .max_width = 4,
461 .cd_type = S3C_SDHCI_CD_GPIO,
462 .ext_cd_gpio = AQUILA_EXT_FLASH_CD,
463 .ext_cd_gpio_invert = 1,
464};
465
466static void aquila_setup_sdhci(void)
467{
468 gpio_request(AQUILA_EXT_FLASH_EN, "FLASH_EN");
469 gpio_direction_output(AQUILA_EXT_FLASH_EN, 1);
470
471 s3c_sdhci0_set_platdata(&aquila_hsmmc0_data);
472 s3c_sdhci1_set_platdata(&aquila_hsmmc1_data);
473 s3c_sdhci2_set_platdata(&aquila_hsmmc2_data);
474};
475
119static struct platform_device *aquila_devices[] __initdata = { 476static struct platform_device *aquila_devices[] __initdata = {
477 &aquila_i2c_gpio_pmic,
478 &aquila_device_gpiokeys,
120 &s3c_device_fb, 479 &s3c_device_fb,
480 &s5pc110_device_onenand,
481 &s3c_device_hsmmc0,
482 &s3c_device_hsmmc1,
483 &s3c_device_hsmmc2,
484 &s5p_device_fimc0,
485 &s5p_device_fimc1,
486 &s5p_device_fimc2,
121}; 487};
122 488
123static void __init aquila_map_io(void) 489static void __init aquila_map_io(void)
124{ 490{
125 s5p_init_io(NULL, 0, S5P_VA_CHIPID); 491 s5p_init_io(NULL, 0, S5P_VA_CHIPID);
126 s3c24xx_init_clocks(24000000); 492 s3c24xx_init_clocks(24000000);
127 s3c24xx_init_uarts(smdkv210_uartcfgs, ARRAY_SIZE(smdkv210_uartcfgs)); 493 s3c24xx_init_uarts(aquila_uartcfgs, ARRAY_SIZE(aquila_uartcfgs));
128} 494}
129 495
130static void __init aquila_machine_init(void) 496static void __init aquila_machine_init(void)
131{ 497{
498 /* PMIC */
499 aquila_pmic_init();
500 i2c_register_board_info(AP_I2C_GPIO_PMIC_BUS_4, i2c_gpio_pmic_devs,
501 ARRAY_SIZE(i2c_gpio_pmic_devs));
502 /* SDHCI */
503 aquila_setup_sdhci();
504
505 s3c_fimc_setname(0, "s5p-fimc");
506 s3c_fimc_setname(1, "s5p-fimc");
507 s3c_fimc_setname(2, "s5p-fimc");
508
132 /* FB */ 509 /* FB */
133 s3c_fb_set_platdata(&aquila_lcd_pdata); 510 s3c_fb_set_platdata(&aquila_lcd_pdata);
134 511
diff --git a/arch/arm/mach-s5pv210/mach-goni.c b/arch/arm/mach-s5pv210/mach-goni.c
index 4863b13824e4..53754d7d364e 100644
--- a/arch/arm/mach-s5pv210/mach-goni.c
+++ b/arch/arm/mach-s5pv210/mach-goni.c
@@ -12,6 +12,13 @@
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/serial_core.h> 14#include <linux/serial_core.h>
15#include <linux/fb.h>
16#include <linux/i2c.h>
17#include <linux/i2c-gpio.h>
18#include <linux/mfd/max8998.h>
19#include <linux/gpio_keys.h>
20#include <linux/input.h>
21#include <linux/gpio.h>
15 22
16#include <asm/mach/arch.h> 23#include <asm/mach/arch.h>
17#include <asm/mach/map.h> 24#include <asm/mach/map.h>
@@ -20,58 +27,444 @@
20 27
21#include <mach/map.h> 28#include <mach/map.h>
22#include <mach/regs-clock.h> 29#include <mach/regs-clock.h>
30#include <mach/regs-fb.h>
23 31
32#include <plat/gpio-cfg.h>
24#include <plat/regs-serial.h> 33#include <plat/regs-serial.h>
25#include <plat/s5pv210.h> 34#include <plat/s5pv210.h>
26#include <plat/devs.h> 35#include <plat/devs.h>
27#include <plat/cpu.h> 36#include <plat/cpu.h>
37#include <plat/fb.h>
38#include <plat/sdhci.h>
28 39
29/* Following are default values for UCON, ULCON and UFCON UART registers */ 40/* Following are default values for UCON, ULCON and UFCON UART registers */
30#define S5PV210_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \ 41#define GONI_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \
31 S3C2410_UCON_RXILEVEL | \ 42 S3C2410_UCON_RXILEVEL | \
32 S3C2410_UCON_TXIRQMODE | \ 43 S3C2410_UCON_TXIRQMODE | \
33 S3C2410_UCON_RXIRQMODE | \ 44 S3C2410_UCON_RXIRQMODE | \
34 S3C2410_UCON_RXFIFO_TOI | \ 45 S3C2410_UCON_RXFIFO_TOI | \
35 S3C2443_UCON_RXERR_IRQEN) 46 S3C2443_UCON_RXERR_IRQEN)
36 47
37#define S5PV210_ULCON_DEFAULT S3C2410_LCON_CS8 48#define GONI_ULCON_DEFAULT S3C2410_LCON_CS8
38 49
39#define S5PV210_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \ 50#define GONI_UFCON_DEFAULT S3C2410_UFCON_FIFOMODE
40 S5PV210_UFCON_TXTRIG4 | \
41 S5PV210_UFCON_RXTRIG4)
42 51
43static struct s3c2410_uartcfg goni_uartcfgs[] __initdata = { 52static struct s3c2410_uartcfg goni_uartcfgs[] __initdata = {
44 [0] = { 53 [0] = {
45 .hwport = 0, 54 .hwport = 0,
46 .flags = 0, 55 .flags = 0,
47 .ucon = S5PV210_UCON_DEFAULT, 56 .ucon = GONI_UCON_DEFAULT,
48 .ulcon = S5PV210_ULCON_DEFAULT, 57 .ulcon = GONI_ULCON_DEFAULT,
49 .ufcon = S5PV210_UFCON_DEFAULT, 58 .ufcon = GONI_UFCON_DEFAULT |
59 S5PV210_UFCON_TXTRIG256 | S5PV210_UFCON_RXTRIG256,
50 }, 60 },
51 [1] = { 61 [1] = {
52 .hwport = 1, 62 .hwport = 1,
53 .flags = 0, 63 .flags = 0,
54 .ucon = S5PV210_UCON_DEFAULT, 64 .ucon = GONI_UCON_DEFAULT,
55 .ulcon = S5PV210_ULCON_DEFAULT, 65 .ulcon = GONI_ULCON_DEFAULT,
56 .ufcon = S5PV210_UFCON_DEFAULT, 66 .ufcon = GONI_UFCON_DEFAULT |
67 S5PV210_UFCON_TXTRIG64 | S5PV210_UFCON_RXTRIG64,
57 }, 68 },
58 [2] = { 69 [2] = {
59 .hwport = 2, 70 .hwport = 2,
60 .flags = 0, 71 .flags = 0,
61 .ucon = S5PV210_UCON_DEFAULT, 72 .ucon = GONI_UCON_DEFAULT,
62 .ulcon = S5PV210_ULCON_DEFAULT, 73 .ulcon = GONI_ULCON_DEFAULT,
63 .ufcon = S5PV210_UFCON_DEFAULT, 74 .ufcon = GONI_UFCON_DEFAULT |
75 S5PV210_UFCON_TXTRIG16 | S5PV210_UFCON_RXTRIG16,
64 }, 76 },
65 [3] = { 77 [3] = {
66 .hwport = 3, 78 .hwport = 3,
67 .flags = 0, 79 .flags = 0,
68 .ucon = S5PV210_UCON_DEFAULT, 80 .ucon = GONI_UCON_DEFAULT,
69 .ulcon = S5PV210_ULCON_DEFAULT, 81 .ulcon = GONI_ULCON_DEFAULT,
70 .ufcon = S5PV210_UFCON_DEFAULT, 82 .ufcon = GONI_UFCON_DEFAULT |
83 S5PV210_UFCON_TXTRIG16 | S5PV210_UFCON_RXTRIG16,
71 }, 84 },
72}; 85};
73 86
87/* Frame Buffer */
88static struct s3c_fb_pd_win goni_fb_win0 = {
89 .win_mode = {
90 .pixclock = 1000000000000ULL / ((16+16+2+480)*(28+3+2+800)*55),
91 .left_margin = 16,
92 .right_margin = 16,
93 .upper_margin = 3,
94 .lower_margin = 28,
95 .hsync_len = 2,
96 .vsync_len = 2,
97 .xres = 480,
98 .yres = 800,
99 .refresh = 55,
100 },
101 .max_bpp = 32,
102 .default_bpp = 16,
103};
104
105static struct s3c_fb_platdata goni_lcd_pdata __initdata = {
106 .win[0] = &goni_fb_win0,
107 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB |
108 VIDCON0_CLKSEL_LCD,
109 .vidcon1 = VIDCON1_INV_VCLK | VIDCON1_INV_VDEN
110 | VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
111 .setup_gpio = s5pv210_fb_gpio_setup_24bpp,
112};
113
114/* MAX8998 regulators */
115#if defined(CONFIG_REGULATOR_MAX8998) || defined(CONFIG_REGULATOR_MAX8998_MODULE)
116
117static struct regulator_init_data goni_ldo2_data = {
118 .constraints = {
119 .name = "VALIVE_1.1V",
120 .min_uV = 1100000,
121 .max_uV = 1100000,
122 .apply_uV = 1,
123 .always_on = 1,
124 .state_mem = {
125 .enabled = 1,
126 },
127 },
128};
129
130static struct regulator_init_data goni_ldo3_data = {
131 .constraints = {
132 .name = "VUSB/MIPI_1.1V",
133 .min_uV = 1100000,
134 .max_uV = 1100000,
135 .apply_uV = 1,
136 .always_on = 1,
137 },
138};
139
140static struct regulator_init_data goni_ldo4_data = {
141 .constraints = {
142 .name = "VDAC_3.3V",
143 .min_uV = 3300000,
144 .max_uV = 3300000,
145 .apply_uV = 1,
146 },
147};
148
149static struct regulator_init_data goni_ldo5_data = {
150 .constraints = {
151 .name = "VTF_2.8V",
152 .min_uV = 2800000,
153 .max_uV = 2800000,
154 .apply_uV = 1,
155 },
156};
157
158static struct regulator_init_data goni_ldo6_data = {
159 .constraints = {
160 .name = "VCC_3.3V",
161 .min_uV = 3300000,
162 .max_uV = 3300000,
163 .apply_uV = 1,
164 },
165};
166
167static struct regulator_init_data goni_ldo7_data = {
168 .constraints = {
169 .name = "VLCD_1.8V",
170 .min_uV = 1800000,
171 .max_uV = 1800000,
172 .apply_uV = 1,
173 .always_on = 1,
174 },
175};
176
177static struct regulator_init_data goni_ldo8_data = {
178 .constraints = {
179 .name = "VUSB/VADC_3.3V",
180 .min_uV = 3300000,
181 .max_uV = 3300000,
182 .apply_uV = 1,
183 .always_on = 1,
184 },
185};
186
187static struct regulator_init_data goni_ldo9_data = {
188 .constraints = {
189 .name = "VCC/VCAM_2.8V",
190 .min_uV = 2800000,
191 .max_uV = 2800000,
192 .apply_uV = 1,
193 .always_on = 1,
194 },
195};
196
197static struct regulator_init_data goni_ldo10_data = {
198 .constraints = {
199 .name = "VPLL_1.1V",
200 .min_uV = 1100000,
201 .max_uV = 1100000,
202 .apply_uV = 1,
203 .boot_on = 1,
204 },
205};
206
207static struct regulator_init_data goni_ldo11_data = {
208 .constraints = {
209 .name = "CAM_IO_2.8V",
210 .min_uV = 2800000,
211 .max_uV = 2800000,
212 .apply_uV = 1,
213 .always_on = 1,
214 },
215};
216
217static struct regulator_init_data goni_ldo12_data = {
218 .constraints = {
219 .name = "CAM_ISP_1.2V",
220 .min_uV = 1200000,
221 .max_uV = 1200000,
222 .apply_uV = 1,
223 .always_on = 1,
224 },
225};
226
227static struct regulator_init_data goni_ldo13_data = {
228 .constraints = {
229 .name = "CAM_A_2.8V",
230 .min_uV = 2800000,
231 .max_uV = 2800000,
232 .apply_uV = 1,
233 .always_on = 1,
234 },
235};
236
237static struct regulator_init_data goni_ldo14_data = {
238 .constraints = {
239 .name = "CAM_CIF_1.8V",
240 .min_uV = 1800000,
241 .max_uV = 1800000,
242 .apply_uV = 1,
243 .always_on = 1,
244 },
245};
246
247static struct regulator_init_data goni_ldo15_data = {
248 .constraints = {
249 .name = "CAM_AF_3.3V",
250 .min_uV = 3300000,
251 .max_uV = 3300000,
252 .apply_uV = 1,
253 .always_on = 1,
254 },
255};
256
257static struct regulator_init_data goni_ldo16_data = {
258 .constraints = {
259 .name = "VMIPI_1.8V",
260 .min_uV = 1800000,
261 .max_uV = 1800000,
262 .apply_uV = 1,
263 .always_on = 1,
264 },
265};
266
267static struct regulator_init_data goni_ldo17_data = {
268 .constraints = {
269 .name = "VCC_3.0V_LCD",
270 .min_uV = 3000000,
271 .max_uV = 3000000,
272 .apply_uV = 1,
273 .always_on = 1,
274 },
275};
276
277/* BUCK */
278static struct regulator_consumer_supply buck1_consumer[] = {
279 { .supply = "vddarm", },
280};
281
282static struct regulator_consumer_supply buck2_consumer[] = {
283 { .supply = "vddint", },
284};
285
286static struct regulator_init_data goni_buck1_data = {
287 .constraints = {
288 .name = "VARM_1.2V",
289 .min_uV = 1200000,
290 .max_uV = 1200000,
291 .apply_uV = 1,
292 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
293 REGULATOR_CHANGE_STATUS,
294 },
295 .num_consumer_supplies = ARRAY_SIZE(buck1_consumer),
296 .consumer_supplies = buck1_consumer,
297};
298
299static struct regulator_init_data goni_buck2_data = {
300 .constraints = {
301 .name = "VINT_1.2V",
302 .min_uV = 1200000,
303 .max_uV = 1200000,
304 .apply_uV = 1,
305 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
306 REGULATOR_CHANGE_STATUS,
307 },
308 .num_consumer_supplies = ARRAY_SIZE(buck2_consumer),
309 .consumer_supplies = buck2_consumer,
310};
311
312static struct regulator_init_data goni_buck3_data = {
313 .constraints = {
314 .name = "VCC_1.8V",
315 .min_uV = 1800000,
316 .max_uV = 1800000,
317 .apply_uV = 1,
318 .state_mem = {
319 .enabled = 1,
320 },
321 },
322};
323
324static struct regulator_init_data goni_buck4_data = {
325 .constraints = {
326 .name = "CAM_CORE_1.2V",
327 .min_uV = 1200000,
328 .max_uV = 1200000,
329 .apply_uV = 1,
330 .always_on = 1,
331 },
332};
333
334static struct max8998_regulator_data goni_regulators[] = {
335 { MAX8998_LDO2, &goni_ldo2_data },
336 { MAX8998_LDO3, &goni_ldo3_data },
337 { MAX8998_LDO4, &goni_ldo4_data },
338 { MAX8998_LDO5, &goni_ldo5_data },
339 { MAX8998_LDO6, &goni_ldo6_data },
340 { MAX8998_LDO7, &goni_ldo7_data },
341 { MAX8998_LDO8, &goni_ldo8_data },
342 { MAX8998_LDO9, &goni_ldo9_data },
343 { MAX8998_LDO10, &goni_ldo10_data },
344 { MAX8998_LDO11, &goni_ldo11_data },
345 { MAX8998_LDO12, &goni_ldo12_data },
346 { MAX8998_LDO13, &goni_ldo13_data },
347 { MAX8998_LDO14, &goni_ldo14_data },
348 { MAX8998_LDO15, &goni_ldo15_data },
349 { MAX8998_LDO16, &goni_ldo16_data },
350 { MAX8998_LDO17, &goni_ldo17_data },
351 { MAX8998_BUCK1, &goni_buck1_data },
352 { MAX8998_BUCK2, &goni_buck2_data },
353 { MAX8998_BUCK3, &goni_buck3_data },
354 { MAX8998_BUCK4, &goni_buck4_data },
355};
356
357static struct max8998_platform_data goni_max8998_pdata = {
358 .num_regulators = ARRAY_SIZE(goni_regulators),
359 .regulators = goni_regulators,
360};
361#endif
362
363/* GPIO I2C PMIC */
364#define AP_I2C_GPIO_PMIC_BUS_4 4
365static struct i2c_gpio_platform_data goni_i2c_gpio_pmic_data = {
366 .sda_pin = S5PV210_GPJ4(0), /* XMSMCSN */
367 .scl_pin = S5PV210_GPJ4(3), /* XMSMIRQN */
368};
369
370static struct platform_device goni_i2c_gpio_pmic = {
371 .name = "i2c-gpio",
372 .id = AP_I2C_GPIO_PMIC_BUS_4,
373 .dev = {
374 .platform_data = &goni_i2c_gpio_pmic_data,
375 },
376};
377
378static struct i2c_board_info i2c_gpio_pmic_devs[] __initdata = {
379#if defined(CONFIG_REGULATOR_MAX8998) || defined(CONFIG_REGULATOR_MAX8998_MODULE)
380 {
381 /* 0xCC when SRAD = 0 */
382 I2C_BOARD_INFO("max8998", 0xCC >> 1),
383 .platform_data = &goni_max8998_pdata,
384 },
385#endif
386};
387
388/* PMIC Power button */
389static struct gpio_keys_button goni_gpio_keys_table[] = {
390 {
391 .code = KEY_POWER,
392 .gpio = S5PV210_GPH2(6),
393 .desc = "gpio-keys: KEY_POWER",
394 .type = EV_KEY,
395 .active_low = 1,
396 .wakeup = 1,
397 .debounce_interval = 1,
398 },
399};
400
401static struct gpio_keys_platform_data goni_gpio_keys_data = {
402 .buttons = goni_gpio_keys_table,
403 .nbuttons = ARRAY_SIZE(goni_gpio_keys_table),
404};
405
406static struct platform_device goni_device_gpiokeys = {
407 .name = "gpio-keys",
408 .dev = {
409 .platform_data = &goni_gpio_keys_data,
410 },
411};
412
413static void __init goni_pmic_init(void)
414{
415 /* AP_PMIC_IRQ: EINT7 */
416 s3c_gpio_cfgpin(S5PV210_GPH0(7), S3C_GPIO_SFN(0xf));
417 s3c_gpio_setpull(S5PV210_GPH0(7), S3C_GPIO_PULL_UP);
418
419 /* nPower: EINT22 */
420 s3c_gpio_cfgpin(S5PV210_GPH2(6), S3C_GPIO_SFN(0xf));
421 s3c_gpio_setpull(S5PV210_GPH2(6), S3C_GPIO_PULL_UP);
422}
423
424/* MoviNAND */
425static struct s3c_sdhci_platdata goni_hsmmc0_data __initdata = {
426 .max_width = 4,
427 .cd_type = S3C_SDHCI_CD_PERMANENT,
428};
429
430/* Wireless LAN */
431static struct s3c_sdhci_platdata goni_hsmmc1_data __initdata = {
432 .max_width = 4,
433 .cd_type = S3C_SDHCI_CD_EXTERNAL,
434 /* ext_cd_{init,cleanup} callbacks will be added later */
435};
436
437/* External Flash */
438#define GONI_EXT_FLASH_EN S5PV210_MP05(4)
439#define GONI_EXT_FLASH_CD S5PV210_GPH3(4)
440static struct s3c_sdhci_platdata goni_hsmmc2_data __initdata = {
441 .max_width = 4,
442 .cd_type = S3C_SDHCI_CD_GPIO,
443 .ext_cd_gpio = GONI_EXT_FLASH_CD,
444 .ext_cd_gpio_invert = 1,
445};
446
447static void goni_setup_sdhci(void)
448{
449 gpio_request(GONI_EXT_FLASH_EN, "FLASH_EN");
450 gpio_direction_output(GONI_EXT_FLASH_EN, 1);
451
452 s3c_sdhci0_set_platdata(&goni_hsmmc0_data);
453 s3c_sdhci1_set_platdata(&goni_hsmmc1_data);
454 s3c_sdhci2_set_platdata(&goni_hsmmc2_data);
455};
456
74static struct platform_device *goni_devices[] __initdata = { 457static struct platform_device *goni_devices[] __initdata = {
458 &s3c_device_fb,
459 &s5pc110_device_onenand,
460 &goni_i2c_gpio_pmic,
461 &goni_device_gpiokeys,
462 &s5p_device_fimc0,
463 &s5p_device_fimc1,
464 &s5p_device_fimc2,
465 &s3c_device_hsmmc0,
466 &s3c_device_hsmmc1,
467 &s3c_device_hsmmc2,
75}; 468};
76 469
77static void __init goni_map_io(void) 470static void __init goni_map_io(void)
@@ -83,6 +476,16 @@ static void __init goni_map_io(void)
83 476
84static void __init goni_machine_init(void) 477static void __init goni_machine_init(void)
85{ 478{
479 /* PMIC */
480 goni_pmic_init();
481 i2c_register_board_info(AP_I2C_GPIO_PMIC_BUS_4, i2c_gpio_pmic_devs,
482 ARRAY_SIZE(i2c_gpio_pmic_devs));
483 /* SDHCI */
484 goni_setup_sdhci();
485
486 /* FB */
487 s3c_fb_set_platdata(&goni_lcd_pdata);
488
86 platform_add_devices(goni_devices, ARRAY_SIZE(goni_devices)); 489 platform_add_devices(goni_devices, ARRAY_SIZE(goni_devices));
87} 490}
88 491
diff --git a/arch/arm/mach-s5pv210/mach-smdkc110.c b/arch/arm/mach-s5pv210/mach-smdkc110.c
index 4c8903c6d104..8211bb87c54b 100644
--- a/arch/arm/mach-s5pv210/mach-smdkc110.c
+++ b/arch/arm/mach-s5pv210/mach-smdkc110.c
@@ -12,6 +12,7 @@
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/serial_core.h> 14#include <linux/serial_core.h>
15#include <linux/i2c.h>
15 16
16#include <asm/mach/arch.h> 17#include <asm/mach/arch.h>
17#include <asm/mach/map.h> 18#include <asm/mach/map.h>
@@ -25,18 +26,20 @@
25#include <plat/s5pv210.h> 26#include <plat/s5pv210.h>
26#include <plat/devs.h> 27#include <plat/devs.h>
27#include <plat/cpu.h> 28#include <plat/cpu.h>
29#include <plat/ata.h>
30#include <plat/iic.h>
28 31
29/* Following are default values for UCON, ULCON and UFCON UART registers */ 32/* Following are default values for UCON, ULCON and UFCON UART registers */
30#define S5PV210_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \ 33#define SMDKC110_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \
31 S3C2410_UCON_RXILEVEL | \ 34 S3C2410_UCON_RXILEVEL | \
32 S3C2410_UCON_TXIRQMODE | \ 35 S3C2410_UCON_TXIRQMODE | \
33 S3C2410_UCON_RXIRQMODE | \ 36 S3C2410_UCON_RXIRQMODE | \
34 S3C2410_UCON_RXFIFO_TOI | \ 37 S3C2410_UCON_RXFIFO_TOI | \
35 S3C2443_UCON_RXERR_IRQEN) 38 S3C2443_UCON_RXERR_IRQEN)
36 39
37#define S5PV210_ULCON_DEFAULT S3C2410_LCON_CS8 40#define SMDKC110_ULCON_DEFAULT S3C2410_LCON_CS8
38 41
39#define S5PV210_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \ 42#define SMDKC110_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \
40 S5PV210_UFCON_TXTRIG4 | \ 43 S5PV210_UFCON_TXTRIG4 | \
41 S5PV210_UFCON_RXTRIG4) 44 S5PV210_UFCON_RXTRIG4)
42 45
@@ -44,39 +47,60 @@ static struct s3c2410_uartcfg smdkv210_uartcfgs[] __initdata = {
44 [0] = { 47 [0] = {
45 .hwport = 0, 48 .hwport = 0,
46 .flags = 0, 49 .flags = 0,
47 .ucon = S5PV210_UCON_DEFAULT, 50 .ucon = SMDKC110_UCON_DEFAULT,
48 .ulcon = S5PV210_ULCON_DEFAULT, 51 .ulcon = SMDKC110_ULCON_DEFAULT,
49 .ufcon = S5PV210_UFCON_DEFAULT, 52 .ufcon = SMDKC110_UFCON_DEFAULT,
50 }, 53 },
51 [1] = { 54 [1] = {
52 .hwport = 1, 55 .hwport = 1,
53 .flags = 0, 56 .flags = 0,
54 .ucon = S5PV210_UCON_DEFAULT, 57 .ucon = SMDKC110_UCON_DEFAULT,
55 .ulcon = S5PV210_ULCON_DEFAULT, 58 .ulcon = SMDKC110_ULCON_DEFAULT,
56 .ufcon = S5PV210_UFCON_DEFAULT, 59 .ufcon = SMDKC110_UFCON_DEFAULT,
57 }, 60 },
58 [2] = { 61 [2] = {
59 .hwport = 2, 62 .hwport = 2,
60 .flags = 0, 63 .flags = 0,
61 .ucon = S5PV210_UCON_DEFAULT, 64 .ucon = SMDKC110_UCON_DEFAULT,
62 .ulcon = S5PV210_ULCON_DEFAULT, 65 .ulcon = SMDKC110_ULCON_DEFAULT,
63 .ufcon = S5PV210_UFCON_DEFAULT, 66 .ufcon = SMDKC110_UFCON_DEFAULT,
64 }, 67 },
65 [3] = { 68 [3] = {
66 .hwport = 3, 69 .hwport = 3,
67 .flags = 0, 70 .flags = 0,
68 .ucon = S5PV210_UCON_DEFAULT, 71 .ucon = SMDKC110_UCON_DEFAULT,
69 .ulcon = S5PV210_ULCON_DEFAULT, 72 .ulcon = SMDKC110_ULCON_DEFAULT,
70 .ufcon = S5PV210_UFCON_DEFAULT, 73 .ufcon = SMDKC110_UFCON_DEFAULT,
71 }, 74 },
72}; 75};
73 76
77static struct s3c_ide_platdata smdkc110_ide_pdata __initdata = {
78 .setup_gpio = s5pv210_ide_setup_gpio,
79};
80
74static struct platform_device *smdkc110_devices[] __initdata = { 81static struct platform_device *smdkc110_devices[] __initdata = {
75 &s5pv210_device_iis0, 82 &s5pv210_device_iis0,
76 &s5pv210_device_ac97, 83 &s5pv210_device_ac97,
84 &s3c_device_cfcon,
85 &s3c_device_i2c0,
86 &s3c_device_i2c1,
87 &s3c_device_i2c2,
88 &s3c_device_rtc,
77 &s3c_device_wdt, 89 &s3c_device_wdt,
78}; 90};
79 91
92static struct i2c_board_info smdkc110_i2c_devs0[] __initdata = {
93 { I2C_BOARD_INFO("24c08", 0x50), }, /* Samsung S524AD0XD1 */
94};
95
96static struct i2c_board_info smdkc110_i2c_devs1[] __initdata = {
97 /* To Be Updated */
98};
99
100static struct i2c_board_info smdkc110_i2c_devs2[] __initdata = {
101 /* To Be Updated */
102};
103
80static void __init smdkc110_map_io(void) 104static void __init smdkc110_map_io(void)
81{ 105{
82 s5p_init_io(NULL, 0, S5P_VA_CHIPID); 106 s5p_init_io(NULL, 0, S5P_VA_CHIPID);
@@ -86,6 +110,18 @@ static void __init smdkc110_map_io(void)
86 110
87static void __init smdkc110_machine_init(void) 111static void __init smdkc110_machine_init(void)
88{ 112{
113 s3c_i2c0_set_platdata(NULL);
114 s3c_i2c1_set_platdata(NULL);
115 s3c_i2c2_set_platdata(NULL);
116 i2c_register_board_info(0, smdkc110_i2c_devs0,
117 ARRAY_SIZE(smdkc110_i2c_devs0));
118 i2c_register_board_info(1, smdkc110_i2c_devs1,
119 ARRAY_SIZE(smdkc110_i2c_devs1));
120 i2c_register_board_info(2, smdkc110_i2c_devs2,
121 ARRAY_SIZE(smdkc110_i2c_devs2));
122
123 s3c_ide_set_platdata(&smdkc110_ide_pdata);
124
89 platform_add_devices(smdkc110_devices, ARRAY_SIZE(smdkc110_devices)); 125 platform_add_devices(smdkc110_devices, ARRAY_SIZE(smdkc110_devices));
90} 126}
91 127
diff --git a/arch/arm/mach-s5pv210/mach-smdkv210.c b/arch/arm/mach-s5pv210/mach-smdkv210.c
index 0d4627948040..fbbc0a3c3738 100644
--- a/arch/arm/mach-s5pv210/mach-smdkv210.c
+++ b/arch/arm/mach-s5pv210/mach-smdkv210.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/i2c.h>
13#include <linux/init.h> 14#include <linux/init.h>
14#include <linux/serial_core.h> 15#include <linux/serial_core.h>
15 16
@@ -27,18 +28,21 @@
27#include <plat/cpu.h> 28#include <plat/cpu.h>
28#include <plat/adc.h> 29#include <plat/adc.h>
29#include <plat/ts.h> 30#include <plat/ts.h>
31#include <plat/ata.h>
32#include <plat/iic.h>
33#include <plat/keypad.h>
30 34
31/* Following are default values for UCON, ULCON and UFCON UART registers */ 35/* Following are default values for UCON, ULCON and UFCON UART registers */
32#define S5PV210_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \ 36#define SMDKV210_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \
33 S3C2410_UCON_RXILEVEL | \ 37 S3C2410_UCON_RXILEVEL | \
34 S3C2410_UCON_TXIRQMODE | \ 38 S3C2410_UCON_TXIRQMODE | \
35 S3C2410_UCON_RXIRQMODE | \ 39 S3C2410_UCON_RXIRQMODE | \
36 S3C2410_UCON_RXFIFO_TOI | \ 40 S3C2410_UCON_RXFIFO_TOI | \
37 S3C2443_UCON_RXERR_IRQEN) 41 S3C2443_UCON_RXERR_IRQEN)
38 42
39#define S5PV210_ULCON_DEFAULT S3C2410_LCON_CS8 43#define SMDKV210_ULCON_DEFAULT S3C2410_LCON_CS8
40 44
41#define S5PV210_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \ 45#define SMDKV210_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \
42 S5PV210_UFCON_TXTRIG4 | \ 46 S5PV210_UFCON_TXTRIG4 | \
43 S5PV210_UFCON_RXTRIG4) 47 S5PV210_UFCON_RXTRIG4)
44 48
@@ -46,41 +50,86 @@ static struct s3c2410_uartcfg smdkv210_uartcfgs[] __initdata = {
46 [0] = { 50 [0] = {
47 .hwport = 0, 51 .hwport = 0,
48 .flags = 0, 52 .flags = 0,
49 .ucon = S5PV210_UCON_DEFAULT, 53 .ucon = SMDKV210_UCON_DEFAULT,
50 .ulcon = S5PV210_ULCON_DEFAULT, 54 .ulcon = SMDKV210_ULCON_DEFAULT,
51 .ufcon = S5PV210_UFCON_DEFAULT, 55 .ufcon = SMDKV210_UFCON_DEFAULT,
52 }, 56 },
53 [1] = { 57 [1] = {
54 .hwport = 1, 58 .hwport = 1,
55 .flags = 0, 59 .flags = 0,
56 .ucon = S5PV210_UCON_DEFAULT, 60 .ucon = SMDKV210_UCON_DEFAULT,
57 .ulcon = S5PV210_ULCON_DEFAULT, 61 .ulcon = SMDKV210_ULCON_DEFAULT,
58 .ufcon = S5PV210_UFCON_DEFAULT, 62 .ufcon = SMDKV210_UFCON_DEFAULT,
59 }, 63 },
60 [2] = { 64 [2] = {
61 .hwport = 2, 65 .hwport = 2,
62 .flags = 0, 66 .flags = 0,
63 .ucon = S5PV210_UCON_DEFAULT, 67 .ucon = SMDKV210_UCON_DEFAULT,
64 .ulcon = S5PV210_ULCON_DEFAULT, 68 .ulcon = SMDKV210_ULCON_DEFAULT,
65 .ufcon = S5PV210_UFCON_DEFAULT, 69 .ufcon = SMDKV210_UFCON_DEFAULT,
66 }, 70 },
67 [3] = { 71 [3] = {
68 .hwport = 3, 72 .hwport = 3,
69 .flags = 0, 73 .flags = 0,
70 .ucon = S5PV210_UCON_DEFAULT, 74 .ucon = SMDKV210_UCON_DEFAULT,
71 .ulcon = S5PV210_ULCON_DEFAULT, 75 .ulcon = SMDKV210_ULCON_DEFAULT,
72 .ufcon = S5PV210_UFCON_DEFAULT, 76 .ufcon = SMDKV210_UFCON_DEFAULT,
73 }, 77 },
74}; 78};
75 79
80static struct s3c_ide_platdata smdkv210_ide_pdata __initdata = {
81 .setup_gpio = s5pv210_ide_setup_gpio,
82};
83
84static uint32_t smdkv210_keymap[] __initdata = {
85 /* KEY(row, col, keycode) */
86 KEY(0, 3, KEY_1), KEY(0, 4, KEY_2), KEY(0, 5, KEY_3),
87 KEY(0, 6, KEY_4), KEY(0, 7, KEY_5),
88 KEY(1, 3, KEY_A), KEY(1, 4, KEY_B), KEY(1, 5, KEY_C),
89 KEY(1, 6, KEY_D), KEY(1, 7, KEY_E)
90};
91
92static struct matrix_keymap_data smdkv210_keymap_data __initdata = {
93 .keymap = smdkv210_keymap,
94 .keymap_size = ARRAY_SIZE(smdkv210_keymap),
95};
96
97static struct samsung_keypad_platdata smdkv210_keypad_data __initdata = {
98 .keymap_data = &smdkv210_keymap_data,
99 .rows = 8,
100 .cols = 8,
101};
102
76static struct platform_device *smdkv210_devices[] __initdata = { 103static struct platform_device *smdkv210_devices[] __initdata = {
77 &s5pv210_device_iis0, 104 &s5pv210_device_iis0,
78 &s5pv210_device_ac97, 105 &s5pv210_device_ac97,
79 &s3c_device_adc, 106 &s3c_device_adc,
107 &s3c_device_cfcon,
108 &s3c_device_hsmmc0,
109 &s3c_device_hsmmc1,
110 &s3c_device_hsmmc2,
111 &s3c_device_hsmmc3,
112 &s3c_device_i2c0,
113 &s3c_device_i2c1,
114 &s3c_device_i2c2,
115 &samsung_device_keypad,
116 &s3c_device_rtc,
80 &s3c_device_ts, 117 &s3c_device_ts,
81 &s3c_device_wdt, 118 &s3c_device_wdt,
82}; 119};
83 120
121static struct i2c_board_info smdkv210_i2c_devs0[] __initdata = {
122 { I2C_BOARD_INFO("24c08", 0x50), }, /* Samsung S524AD0XD1 */
123};
124
125static struct i2c_board_info smdkv210_i2c_devs1[] __initdata = {
126 /* To Be Updated */
127};
128
129static struct i2c_board_info smdkv210_i2c_devs2[] __initdata = {
130 /* To Be Updated */
131};
132
84static struct s3c2410_ts_mach_info s3c_ts_platform __initdata = { 133static struct s3c2410_ts_mach_info s3c_ts_platform __initdata = {
85 .delay = 10000, 134 .delay = 10000,
86 .presc = 49, 135 .presc = 49,
@@ -96,7 +145,21 @@ static void __init smdkv210_map_io(void)
96 145
97static void __init smdkv210_machine_init(void) 146static void __init smdkv210_machine_init(void)
98{ 147{
148 samsung_keypad_set_platdata(&smdkv210_keypad_data);
99 s3c24xx_ts_set_platdata(&s3c_ts_platform); 149 s3c24xx_ts_set_platdata(&s3c_ts_platform);
150
151 s3c_i2c0_set_platdata(NULL);
152 s3c_i2c1_set_platdata(NULL);
153 s3c_i2c2_set_platdata(NULL);
154 i2c_register_board_info(0, smdkv210_i2c_devs0,
155 ARRAY_SIZE(smdkv210_i2c_devs0));
156 i2c_register_board_info(1, smdkv210_i2c_devs1,
157 ARRAY_SIZE(smdkv210_i2c_devs1));
158 i2c_register_board_info(2, smdkv210_i2c_devs2,
159 ARRAY_SIZE(smdkv210_i2c_devs2));
160
161 s3c_ide_set_platdata(&smdkv210_ide_pdata);
162
100 platform_add_devices(smdkv210_devices, ARRAY_SIZE(smdkv210_devices)); 163 platform_add_devices(smdkv210_devices, ARRAY_SIZE(smdkv210_devices));
101} 164}
102 165
diff --git a/arch/arm/mach-s5pv210/setup-fb-24bpp.c b/arch/arm/mach-s5pv210/setup-fb-24bpp.c
index a50cbac8720d..928cf1f125fa 100644
--- a/arch/arm/mach-s5pv210/setup-fb-24bpp.c
+++ b/arch/arm/mach-s5pv210/setup-fb-24bpp.c
@@ -13,9 +13,9 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/fb.h> 15#include <linux/fb.h>
16#include <linux/gpio.h>
16 17
17#include <mach/regs-fb.h> 18#include <mach/regs-fb.h>
18#include <mach/gpio.h>
19#include <mach/map.h> 19#include <mach/map.h>
20#include <plat/fb.h> 20#include <plat/fb.h>
21#include <mach/regs-clock.h> 21#include <mach/regs-clock.h>
diff --git a/arch/arm/mach-s5pv210/setup-i2c0.c b/arch/arm/mach-s5pv210/setup-i2c0.c
index c718253c70b8..d38f7cb7e662 100644
--- a/arch/arm/mach-s5pv210/setup-i2c0.c
+++ b/arch/arm/mach-s5pv210/setup-i2c0.c
@@ -14,10 +14,10 @@
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/gpio.h>
17 18
18struct platform_device; /* don't need the contents */ 19struct platform_device; /* don't need the contents */
19 20
20#include <mach/gpio.h>
21#include <plat/iic.h> 21#include <plat/iic.h>
22#include <plat/gpio-cfg.h> 22#include <plat/gpio-cfg.h>
23 23
diff --git a/arch/arm/mach-s5pv210/setup-i2c1.c b/arch/arm/mach-s5pv210/setup-i2c1.c
index 45e0e6ed2ed0..148bb7857d89 100644
--- a/arch/arm/mach-s5pv210/setup-i2c1.c
+++ b/arch/arm/mach-s5pv210/setup-i2c1.c
@@ -14,10 +14,10 @@
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/gpio.h>
17 18
18struct platform_device; /* don't need the contents */ 19struct platform_device; /* don't need the contents */
19 20
20#include <mach/gpio.h>
21#include <plat/iic.h> 21#include <plat/iic.h>
22#include <plat/gpio-cfg.h> 22#include <plat/gpio-cfg.h>
23 23
diff --git a/arch/arm/mach-s5pv210/setup-i2c2.c b/arch/arm/mach-s5pv210/setup-i2c2.c
index b11b4bff69ac..2396cb8c373e 100644
--- a/arch/arm/mach-s5pv210/setup-i2c2.c
+++ b/arch/arm/mach-s5pv210/setup-i2c2.c
@@ -14,10 +14,10 @@
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/gpio.h>
17 18
18struct platform_device; /* don't need the contents */ 19struct platform_device; /* don't need the contents */
19 20
20#include <mach/gpio.h>
21#include <plat/iic.h> 21#include <plat/iic.h>
22#include <plat/gpio-cfg.h> 22#include <plat/gpio-cfg.h>
23 23
diff --git a/arch/arm/mach-s5pv210/setup-ide.c b/arch/arm/mach-s5pv210/setup-ide.c
new file mode 100644
index 000000000000..b558b1cc8d60
--- /dev/null
+++ b/arch/arm/mach-s5pv210/setup-ide.c
@@ -0,0 +1,50 @@
1/* linux/arch/arm/mach-s5pv210/setup-ide.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * S5PV210 setup information for IDE
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#include <linux/kernel.h>
14#include <linux/gpio.h>
15
16#include <plat/gpio-cfg.h>
17
18void s5pv210_ide_setup_gpio(void)
19{
20 unsigned int gpio = 0;
21
22 for (gpio = S5PV210_GPJ0(0); gpio <= S5PV210_GPJ0(7); gpio++) {
23 /* CF_Add[0 - 2], CF_IORDY, CF_INTRQ, CF_DMARQ, CF_DMARST,
24 CF_DMACK */
25 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(4));
26 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
27 s5p_gpio_set_drvstr(gpio, S5P_GPIO_DRVSTR_LV4);
28 }
29
30 for (gpio = S5PV210_GPJ2(0); gpio <= S5PV210_GPJ2(7); gpio++) {
31 /*CF_Data[0 - 7] */
32 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(4));
33 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
34 s5p_gpio_set_drvstr(gpio, S5P_GPIO_DRVSTR_LV4);
35 }
36
37 for (gpio = S5PV210_GPJ3(0); gpio <= S5PV210_GPJ3(7); gpio++) {
38 /* CF_Data[8 - 15] */
39 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(4));
40 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
41 s5p_gpio_set_drvstr(gpio, S5P_GPIO_DRVSTR_LV4);
42 }
43
44 for (gpio = S5PV210_GPJ4(0); gpio <= S5PV210_GPJ4(3); gpio++) {
45 /* CF_CS0, CF_CS1, CF_IORD, CF_IOWR */
46 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(4));
47 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
48 s5p_gpio_set_drvstr(gpio, S5P_GPIO_DRVSTR_LV4);
49 }
50}
diff --git a/arch/arm/mach-s5pv210/setup-keypad.c b/arch/arm/mach-s5pv210/setup-keypad.c
new file mode 100644
index 000000000000..37b2790aafc3
--- /dev/null
+++ b/arch/arm/mach-s5pv210/setup-keypad.c
@@ -0,0 +1,34 @@
1/*
2 * linux/arch/arm/mach-s5pv210/setup-keypad.c
3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@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/gpio.h>
15#include <plat/gpio-cfg.h>
16
17void samsung_keypad_cfg_gpio(unsigned int rows, unsigned int cols)
18{
19 unsigned int gpio, end;
20
21 /* Set all the necessary GPH3 pins to special-function 3: KP_ROW[x] */
22 end = S5PV210_GPH3(rows);
23 for (gpio = S5PV210_GPH3(0); gpio < end; gpio++) {
24 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(3));
25 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
26 }
27
28 /* Set all the necessary GPH2 pins to special-function 3: KP_COL[x] */
29 end = S5PV210_GPH2(cols);
30 for (gpio = S5PV210_GPH2(0); gpio < end; gpio++) {
31 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(3));
32 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
33 }
34}
diff --git a/arch/arm/mach-s5pv210/setup-sdhci-gpio.c b/arch/arm/mach-s5pv210/setup-sdhci-gpio.c
index fe7d86dad14c..b18587b1ec58 100644
--- a/arch/arm/mach-s5pv210/setup-sdhci-gpio.c
+++ b/arch/arm/mach-s5pv210/setup-sdhci-gpio.c
@@ -15,15 +15,17 @@
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/gpio.h>
18#include <linux/mmc/host.h> 19#include <linux/mmc/host.h>
19#include <linux/mmc/card.h> 20#include <linux/mmc/card.h>
20 21
21#include <mach/gpio.h>
22#include <plat/gpio-cfg.h> 22#include <plat/gpio-cfg.h>
23#include <plat/regs-sdhci.h> 23#include <plat/regs-sdhci.h>
24#include <plat/sdhci.h>
24 25
25void s5pv210_setup_sdhci0_cfg_gpio(struct platform_device *dev, int width) 26void s5pv210_setup_sdhci0_cfg_gpio(struct platform_device *dev, int width)
26{ 27{
28 struct s3c_sdhci_platdata *pdata = dev->dev.platform_data;
27 unsigned int gpio; 29 unsigned int gpio;
28 30
29 /* Set all the necessary GPG0/GPG1 pins to special-function 2 */ 31 /* Set all the necessary GPG0/GPG1 pins to special-function 2 */
@@ -48,12 +50,15 @@ void s5pv210_setup_sdhci0_cfg_gpio(struct platform_device *dev, int width)
48 break; 50 break;
49 } 51 }
50 52
51 s3c_gpio_setpull(S5PV210_GPG0(2), S3C_GPIO_PULL_UP); 53 if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) {
52 s3c_gpio_cfgpin(S5PV210_GPG0(2), S3C_GPIO_SFN(2)); 54 s3c_gpio_setpull(S5PV210_GPG0(2), S3C_GPIO_PULL_UP);
55 s3c_gpio_cfgpin(S5PV210_GPG0(2), S3C_GPIO_SFN(2));
56 }
53} 57}
54 58
55void s5pv210_setup_sdhci1_cfg_gpio(struct platform_device *dev, int width) 59void s5pv210_setup_sdhci1_cfg_gpio(struct platform_device *dev, int width)
56{ 60{
61 struct s3c_sdhci_platdata *pdata = dev->dev.platform_data;
57 unsigned int gpio; 62 unsigned int gpio;
58 63
59 /* Set all the necessary GPG1[0:1] pins to special-function 2 */ 64 /* Set all the necessary GPG1[0:1] pins to special-function 2 */
@@ -68,12 +73,15 @@ void s5pv210_setup_sdhci1_cfg_gpio(struct platform_device *dev, int width)
68 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE); 73 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
69 } 74 }
70 75
71 s3c_gpio_setpull(S5PV210_GPG1(2), S3C_GPIO_PULL_UP); 76 if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) {
72 s3c_gpio_cfgpin(S5PV210_GPG1(2), S3C_GPIO_SFN(2)); 77 s3c_gpio_setpull(S5PV210_GPG1(2), S3C_GPIO_PULL_UP);
78 s3c_gpio_cfgpin(S5PV210_GPG1(2), S3C_GPIO_SFN(2));
79 }
73} 80}
74 81
75void s5pv210_setup_sdhci2_cfg_gpio(struct platform_device *dev, int width) 82void s5pv210_setup_sdhci2_cfg_gpio(struct platform_device *dev, int width)
76{ 83{
84 struct s3c_sdhci_platdata *pdata = dev->dev.platform_data;
77 unsigned int gpio; 85 unsigned int gpio;
78 86
79 /* Set all the necessary GPG2[0:1] pins to special-function 2 */ 87 /* Set all the necessary GPG2[0:1] pins to special-function 2 */
@@ -99,6 +107,31 @@ void s5pv210_setup_sdhci2_cfg_gpio(struct platform_device *dev, int width)
99 break; 107 break;
100 } 108 }
101 109
102 s3c_gpio_setpull(S5PV210_GPG2(2), S3C_GPIO_PULL_UP); 110 if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) {
103 s3c_gpio_cfgpin(S5PV210_GPG2(2), S3C_GPIO_SFN(2)); 111 s3c_gpio_setpull(S5PV210_GPG2(2), S3C_GPIO_PULL_UP);
112 s3c_gpio_cfgpin(S5PV210_GPG2(2), S3C_GPIO_SFN(2));
113 }
114}
115
116void s5pv210_setup_sdhci3_cfg_gpio(struct platform_device *dev, int width)
117{
118 struct s3c_sdhci_platdata *pdata = dev->dev.platform_data;
119 unsigned int gpio;
120
121 /* Set all the necessary GPG3[0:2] pins to special-function 2 */
122 for (gpio = S5PV210_GPG3(0); gpio < S5PV210_GPG3(2); gpio++) {
123 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
124 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
125 }
126
127 /* Data pin GPG3[3:6] to special-function 2 */
128 for (gpio = S5PV210_GPG3(3); gpio <= S5PV210_GPG3(6); gpio++) {
129 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
130 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
131 }
132
133 if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) {
134 s3c_gpio_setpull(S5PV210_GPG3(2), S3C_GPIO_PULL_UP);
135 s3c_gpio_cfgpin(S5PV210_GPG3(2), S3C_GPIO_SFN(2));
136 }
104} 137}
diff --git a/arch/arm/mach-s5pv210/setup-sdhci.c b/arch/arm/mach-s5pv210/setup-sdhci.c
index 51815ec60c2a..c32e202731c1 100644
--- a/arch/arm/mach-s5pv210/setup-sdhci.c
+++ b/arch/arm/mach-s5pv210/setup-sdhci.c
@@ -26,9 +26,9 @@
26 26
27char *s5pv210_hsmmc_clksrcs[4] = { 27char *s5pv210_hsmmc_clksrcs[4] = {
28 [0] = "hsmmc", /* HCLK */ 28 [0] = "hsmmc", /* HCLK */
29 [1] = "hsmmc", /* HCLK */ 29 /* [1] = "hsmmc", - duplicate HCLK entry */
30 [2] = "sclk_mmc", /* mmc_bus */ 30 [2] = "sclk_mmc", /* mmc_bus */
31 /*[4] = reserved */ 31 /* [3] = NULL, - reserved */
32}; 32};
33 33
34void s5pv210_setup_sdhci_cfg_card(struct platform_device *dev, 34void s5pv210_setup_sdhci_cfg_card(struct platform_device *dev,
diff --git a/arch/arm/mach-s5pv310/Kconfig b/arch/arm/mach-s5pv310/Kconfig
new file mode 100644
index 000000000000..331b5bd97aba
--- /dev/null
+++ b/arch/arm/mach-s5pv310/Kconfig
@@ -0,0 +1,45 @@
1# arch/arm/mach-s5pv310/Kconfig
2#
3# Copyright (c) 2010 Samsung Electronics Co., Ltd.
4# http://www.samsung.com/
5#
6# Licensed under GPLv2
7
8# Configuration options for the S5PV310
9
10if ARCH_S5PV310
11
12config CPU_S5PV310
13 bool
14 select PLAT_S5P
15 help
16 Enable S5PV310 CPU support
17
18config S5PV310_SETUP_I2C1
19 bool
20 help
21 Common setup code for i2c bus 1.
22
23config S5PV310_SETUP_I2C2
24 bool
25 help
26 Common setup code for i2c bus 2.
27
28# machine support
29
30config MACH_SMDKV310
31 bool "SMDKV310"
32 select CPU_S5PV310
33 select ARCH_SPARSEMEM_ENABLE
34 help
35 Machine support for Samsung SMDKV310
36
37config MACH_UNIVERSAL_C210
38 bool "Mobile UNIVERSAL_C210 Board"
39 select CPU_S5PV310
40 select ARCH_SPARSEMEM_ENABLE
41 help
42 Machine support for Samsung Mobile Universal S5PC210 Reference
43 Board. S5PC210(MCP) is one of package option of S5PV310
44
45endif
diff --git a/arch/arm/mach-s5pv310/Makefile b/arch/arm/mach-s5pv310/Makefile
new file mode 100644
index 000000000000..d5b51c72340f
--- /dev/null
+++ b/arch/arm/mach-s5pv310/Makefile
@@ -0,0 +1,30 @@
1# arch/arm/mach-s5pv310/Makefile
2#
3# Copyright (c) 2010 Samsung Electronics Co., Ltd.
4# http://www.samsung.com/
5#
6# Licensed under GPLv2
7
8obj-y :=
9obj-m :=
10obj-n :=
11obj- :=
12
13# Core support for S5PV310 system
14
15obj-$(CONFIG_CPU_S5PV310) += cpu.o init.o clock.o irq-combiner.o
16obj-$(CONFIG_CPU_S5PV310) += setup-i2c0.o time.o
17
18obj-$(CONFIG_SMP) += platsmp.o headsmp.o
19obj-$(CONFIG_LOCAL_TIMERS) += localtimer.o
20obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
21
22# machine support
23
24obj-$(CONFIG_MACH_SMDKV310) += mach-smdkv310.o
25obj-$(CONFIG_MACH_UNIVERSAL_C210) += mach-universal_c210.o
26
27# device support
28
29obj-$(CONFIG_S5PV310_SETUP_I2C1) += setup-i2c1.o
30obj-$(CONFIG_S5PV310_SETUP_I2C2) += setup-i2c2.o
diff --git a/arch/arm/mach-s5pv310/Makefile.boot b/arch/arm/mach-s5pv310/Makefile.boot
new file mode 100644
index 000000000000..d65956ffb43d
--- /dev/null
+++ b/arch/arm/mach-s5pv310/Makefile.boot
@@ -0,0 +1,2 @@
1 zreladdr-y := 0x40008000
2params_phys-y := 0x40000100
diff --git a/arch/arm/mach-s5pv310/clock.c b/arch/arm/mach-s5pv310/clock.c
new file mode 100644
index 000000000000..77f2b4d85e6b
--- /dev/null
+++ b/arch/arm/mach-s5pv310/clock.c
@@ -0,0 +1,544 @@
1/* linux/arch/arm/mach-s5pv310/clock.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * S5PV310 - Clock support
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#include <linux/kernel.h>
14#include <linux/err.h>
15#include <linux/io.h>
16
17#include <plat/cpu-freq.h>
18#include <plat/clock.h>
19#include <plat/cpu.h>
20#include <plat/pll.h>
21#include <plat/s5p-clock.h>
22#include <plat/clock-clksrc.h>
23
24#include <mach/map.h>
25#include <mach/regs-clock.h>
26
27static struct clk clk_sclk_hdmi27m = {
28 .name = "sclk_hdmi27m",
29 .id = -1,
30 .rate = 27000000,
31};
32
33/* Core list of CMU_CPU side */
34
35static struct clksrc_clk clk_mout_apll = {
36 .clk = {
37 .name = "mout_apll",
38 .id = -1,
39 },
40 .sources = &clk_src_apll,
41 .reg_src = { .reg = S5P_CLKSRC_CPU, .shift = 0, .size = 1 },
42 .reg_div = { .reg = S5P_CLKDIV_CPU, .shift = 24, .size = 3 },
43};
44
45static struct clksrc_clk clk_mout_epll = {
46 .clk = {
47 .name = "mout_epll",
48 .id = -1,
49 },
50 .sources = &clk_src_epll,
51 .reg_src = { .reg = S5P_CLKSRC_TOP0, .shift = 4, .size = 1 },
52};
53
54static struct clksrc_clk clk_mout_mpll = {
55 .clk = {
56 .name = "mout_mpll",
57 .id = -1,
58 },
59 .sources = &clk_src_mpll,
60 .reg_src = { .reg = S5P_CLKSRC_CPU, .shift = 8, .size = 1 },
61};
62
63static struct clk *clkset_moutcore_list[] = {
64 [0] = &clk_mout_apll.clk,
65 [1] = &clk_mout_mpll.clk,
66};
67
68static struct clksrc_sources clkset_moutcore = {
69 .sources = clkset_moutcore_list,
70 .nr_sources = ARRAY_SIZE(clkset_moutcore_list),
71};
72
73static struct clksrc_clk clk_moutcore = {
74 .clk = {
75 .name = "moutcore",
76 .id = -1,
77 },
78 .sources = &clkset_moutcore,
79 .reg_src = { .reg = S5P_CLKSRC_CPU, .shift = 16, .size = 1 },
80};
81
82static struct clksrc_clk clk_coreclk = {
83 .clk = {
84 .name = "core_clk",
85 .id = -1,
86 .parent = &clk_moutcore.clk,
87 },
88 .reg_div = { .reg = S5P_CLKDIV_CPU, .shift = 0, .size = 3 },
89};
90
91static struct clksrc_clk clk_armclk = {
92 .clk = {
93 .name = "armclk",
94 .id = -1,
95 .parent = &clk_coreclk.clk,
96 },
97};
98
99static struct clksrc_clk clk_aclk_corem0 = {
100 .clk = {
101 .name = "aclk_corem0",
102 .id = -1,
103 .parent = &clk_coreclk.clk,
104 },
105 .reg_div = { .reg = S5P_CLKDIV_CPU, .shift = 4, .size = 3 },
106};
107
108static struct clksrc_clk clk_aclk_cores = {
109 .clk = {
110 .name = "aclk_cores",
111 .id = -1,
112 .parent = &clk_coreclk.clk,
113 },
114 .reg_div = { .reg = S5P_CLKDIV_CPU, .shift = 4, .size = 3 },
115};
116
117static struct clksrc_clk clk_aclk_corem1 = {
118 .clk = {
119 .name = "aclk_corem1",
120 .id = -1,
121 .parent = &clk_coreclk.clk,
122 },
123 .reg_div = { .reg = S5P_CLKDIV_CPU, .shift = 8, .size = 3 },
124};
125
126static struct clksrc_clk clk_periphclk = {
127 .clk = {
128 .name = "periphclk",
129 .id = -1,
130 .parent = &clk_coreclk.clk,
131 },
132 .reg_div = { .reg = S5P_CLKDIV_CPU, .shift = 12, .size = 3 },
133};
134
135static struct clksrc_clk clk_atclk = {
136 .clk = {
137 .name = "atclk",
138 .id = -1,
139 .parent = &clk_moutcore.clk,
140 },
141 .reg_div = { .reg = S5P_CLKDIV_CPU, .shift = 16, .size = 3 },
142};
143
144static struct clksrc_clk clk_pclk_dbg = {
145 .clk = {
146 .name = "pclk_dbg",
147 .id = -1,
148 .parent = &clk_atclk.clk,
149 },
150 .reg_div = { .reg = S5P_CLKDIV_CPU, .shift = 20, .size = 3 },
151};
152
153/* Core list of CMU_CORE side */
154
155static struct clk *clkset_corebus_list[] = {
156 [0] = &clk_mout_mpll.clk,
157 [1] = &clk_mout_apll.clk,
158};
159
160static struct clksrc_sources clkset_mout_corebus = {
161 .sources = clkset_corebus_list,
162 .nr_sources = ARRAY_SIZE(clkset_corebus_list),
163};
164
165static struct clksrc_clk clk_mout_corebus = {
166 .clk = {
167 .name = "mout_corebus",
168 .id = -1,
169 },
170 .sources = &clkset_mout_corebus,
171 .reg_src = { .reg = S5P_CLKSRC_CORE, .shift = 4, .size = 1 },
172};
173
174static struct clksrc_clk clk_sclk_dmc = {
175 .clk = {
176 .name = "sclk_dmc",
177 .id = -1,
178 .parent = &clk_mout_corebus.clk,
179 },
180 .reg_div = { .reg = S5P_CLKDIV_CORE0, .shift = 12, .size = 3 },
181};
182
183static struct clksrc_clk clk_aclk_cored = {
184 .clk = {
185 .name = "aclk_cored",
186 .id = -1,
187 .parent = &clk_sclk_dmc.clk,
188 },
189 .reg_div = { .reg = S5P_CLKDIV_CORE0, .shift = 16, .size = 3 },
190};
191
192static struct clksrc_clk clk_aclk_corep = {
193 .clk = {
194 .name = "aclk_corep",
195 .id = -1,
196 .parent = &clk_aclk_cored.clk,
197 },
198 .reg_div = { .reg = S5P_CLKDIV_CORE0, .shift = 20, .size = 3 },
199};
200
201static struct clksrc_clk clk_aclk_acp = {
202 .clk = {
203 .name = "aclk_acp",
204 .id = -1,
205 .parent = &clk_mout_corebus.clk,
206 },
207 .reg_div = { .reg = S5P_CLKDIV_CORE0, .shift = 0, .size = 3 },
208};
209
210static struct clksrc_clk clk_pclk_acp = {
211 .clk = {
212 .name = "pclk_acp",
213 .id = -1,
214 .parent = &clk_aclk_acp.clk,
215 },
216 .reg_div = { .reg = S5P_CLKDIV_CORE0, .shift = 4, .size = 3 },
217};
218
219/* Core list of CMU_TOP side */
220
221static struct clk *clkset_aclk_top_list[] = {
222 [0] = &clk_mout_mpll.clk,
223 [1] = &clk_mout_apll.clk,
224};
225
226static struct clksrc_sources clkset_aclk_200 = {
227 .sources = clkset_aclk_top_list,
228 .nr_sources = ARRAY_SIZE(clkset_aclk_top_list),
229};
230
231static struct clksrc_clk clk_aclk_200 = {
232 .clk = {
233 .name = "aclk_200",
234 .id = -1,
235 },
236 .sources = &clkset_aclk_200,
237 .reg_src = { .reg = S5P_CLKSRC_TOP0, .shift = 12, .size = 1 },
238 .reg_div = { .reg = S5P_CLKDIV_TOP, .shift = 0, .size = 3 },
239};
240
241static struct clksrc_sources clkset_aclk_100 = {
242 .sources = clkset_aclk_top_list,
243 .nr_sources = ARRAY_SIZE(clkset_aclk_top_list),
244};
245
246static struct clksrc_clk clk_aclk_100 = {
247 .clk = {
248 .name = "aclk_100",
249 .id = -1,
250 },
251 .sources = &clkset_aclk_100,
252 .reg_src = { .reg = S5P_CLKSRC_TOP0, .shift = 16, .size = 1 },
253 .reg_div = { .reg = S5P_CLKDIV_TOP, .shift = 4, .size = 4 },
254};
255
256static struct clksrc_sources clkset_aclk_160 = {
257 .sources = clkset_aclk_top_list,
258 .nr_sources = ARRAY_SIZE(clkset_aclk_top_list),
259};
260
261static struct clksrc_clk clk_aclk_160 = {
262 .clk = {
263 .name = "aclk_160",
264 .id = -1,
265 },
266 .sources = &clkset_aclk_160,
267 .reg_src = { .reg = S5P_CLKSRC_TOP0, .shift = 20, .size = 1 },
268 .reg_div = { .reg = S5P_CLKDIV_TOP, .shift = 8, .size = 3 },
269};
270
271static struct clksrc_sources clkset_aclk_133 = {
272 .sources = clkset_aclk_top_list,
273 .nr_sources = ARRAY_SIZE(clkset_aclk_top_list),
274};
275
276static struct clksrc_clk clk_aclk_133 = {
277 .clk = {
278 .name = "aclk_133",
279 .id = -1,
280 },
281 .sources = &clkset_aclk_133,
282 .reg_src = { .reg = S5P_CLKSRC_TOP0, .shift = 24, .size = 1 },
283 .reg_div = { .reg = S5P_CLKDIV_TOP, .shift = 12, .size = 3 },
284};
285
286static struct clk *clkset_vpllsrc_list[] = {
287 [0] = &clk_fin_vpll,
288 [1] = &clk_sclk_hdmi27m,
289};
290
291static struct clksrc_sources clkset_vpllsrc = {
292 .sources = clkset_vpllsrc_list,
293 .nr_sources = ARRAY_SIZE(clkset_vpllsrc_list),
294};
295
296static struct clksrc_clk clk_vpllsrc = {
297 .clk = {
298 .name = "vpll_src",
299 .id = -1,
300 },
301 .sources = &clkset_vpllsrc,
302 .reg_src = { .reg = S5P_CLKSRC_TOP1, .shift = 0, .size = 1 },
303};
304
305static struct clk *clkset_sclk_vpll_list[] = {
306 [0] = &clk_vpllsrc.clk,
307 [1] = &clk_fout_vpll,
308};
309
310static struct clksrc_sources clkset_sclk_vpll = {
311 .sources = clkset_sclk_vpll_list,
312 .nr_sources = ARRAY_SIZE(clkset_sclk_vpll_list),
313};
314
315static struct clksrc_clk clk_sclk_vpll = {
316 .clk = {
317 .name = "sclk_vpll",
318 .id = -1,
319 },
320 .sources = &clkset_sclk_vpll,
321 .reg_src = { .reg = S5P_CLKSRC_TOP0, .shift = 8, .size = 1 },
322};
323
324static int s5pv310_clk_ip_peril_ctrl(struct clk *clk, int enable)
325{
326 return s5p_gatectrl(S5P_CLKGATE_IP_PERIL, clk, enable);
327}
328
329static struct clk init_clocks_disable[] = {
330 {
331 .name = "timers",
332 .id = -1,
333 .parent = &clk_aclk_100.clk,
334 .enable = s5pv310_clk_ip_peril_ctrl,
335 .ctrlbit = (1<<24),
336 }
337};
338
339static struct clk init_clocks[] = {
340 /* Nothing here yet */
341};
342
343static struct clk *clkset_group_list[] = {
344 [0] = &clk_ext_xtal_mux,
345 [1] = &clk_xusbxti,
346 [2] = &clk_sclk_hdmi27m,
347 [6] = &clk_mout_mpll.clk,
348 [7] = &clk_mout_epll.clk,
349 [8] = &clk_sclk_vpll.clk,
350};
351
352static struct clksrc_sources clkset_group = {
353 .sources = clkset_group_list,
354 .nr_sources = ARRAY_SIZE(clkset_group_list),
355};
356
357static struct clksrc_clk clksrcs[] = {
358 {
359 .clk = {
360 .name = "uclk1",
361 .id = 0,
362 .ctrlbit = (1 << 0),
363 .enable = s5pv310_clk_ip_peril_ctrl,
364 },
365 .sources = &clkset_group,
366 .reg_src = { .reg = S5P_CLKSRC_PERIL0, .shift = 0, .size = 4 },
367 .reg_div = { .reg = S5P_CLKDIV_PERIL0, .shift = 0, .size = 4 },
368 }, {
369 .clk = {
370 .name = "uclk1",
371 .id = 1,
372 .enable = s5pv310_clk_ip_peril_ctrl,
373 .ctrlbit = (1 << 1),
374 },
375 .sources = &clkset_group,
376 .reg_src = { .reg = S5P_CLKSRC_PERIL0, .shift = 4, .size = 4 },
377 .reg_div = { .reg = S5P_CLKDIV_PERIL0, .shift = 4, .size = 4 },
378 }, {
379 .clk = {
380 .name = "uclk1",
381 .id = 2,
382 .enable = s5pv310_clk_ip_peril_ctrl,
383 .ctrlbit = (1 << 2),
384 },
385 .sources = &clkset_group,
386 .reg_src = { .reg = S5P_CLKSRC_PERIL0, .shift = 8, .size = 4 },
387 .reg_div = { .reg = S5P_CLKDIV_PERIL0, .shift = 8, .size = 4 },
388 }, {
389 .clk = {
390 .name = "uclk1",
391 .id = 3,
392 .enable = s5pv310_clk_ip_peril_ctrl,
393 .ctrlbit = (1 << 3),
394 },
395 .sources = &clkset_group,
396 .reg_src = { .reg = S5P_CLKSRC_PERIL0, .shift = 12, .size = 4 },
397 .reg_div = { .reg = S5P_CLKDIV_PERIL0, .shift = 12, .size = 4 },
398 }, {
399 .clk = {
400 .name = "sclk_pwm",
401 .id = -1,
402 .enable = s5pv310_clk_ip_peril_ctrl,
403 .ctrlbit = (1 << 24),
404 },
405 .sources = &clkset_group,
406 .reg_src = { .reg = S5P_CLKSRC_PERIL0, .shift = 24, .size = 4 },
407 .reg_div = { .reg = S5P_CLKDIV_PERIL3, .shift = 0, .size = 4 },
408 },
409};
410
411/* Clock initialization code */
412static struct clksrc_clk *sysclks[] = {
413 &clk_mout_apll,
414 &clk_mout_epll,
415 &clk_mout_mpll,
416 &clk_moutcore,
417 &clk_coreclk,
418 &clk_armclk,
419 &clk_aclk_corem0,
420 &clk_aclk_cores,
421 &clk_aclk_corem1,
422 &clk_periphclk,
423 &clk_atclk,
424 &clk_pclk_dbg,
425 &clk_mout_corebus,
426 &clk_sclk_dmc,
427 &clk_aclk_cored,
428 &clk_aclk_corep,
429 &clk_aclk_acp,
430 &clk_pclk_acp,
431 &clk_vpllsrc,
432 &clk_sclk_vpll,
433 &clk_aclk_200,
434 &clk_aclk_100,
435 &clk_aclk_160,
436 &clk_aclk_133,
437};
438
439void __init_or_cpufreq s5pv310_setup_clocks(void)
440{
441 struct clk *xtal_clk;
442 unsigned long apll;
443 unsigned long mpll;
444 unsigned long epll;
445 unsigned long vpll;
446 unsigned long vpllsrc;
447 unsigned long xtal;
448 unsigned long armclk;
449 unsigned long aclk_corem0;
450 unsigned long aclk_cores;
451 unsigned long aclk_corem1;
452 unsigned long periphclk;
453 unsigned long sclk_dmc;
454 unsigned long aclk_cored;
455 unsigned long aclk_corep;
456 unsigned long aclk_acp;
457 unsigned long pclk_acp;
458 unsigned int ptr;
459
460 printk(KERN_DEBUG "%s: registering clocks\n", __func__);
461
462 xtal_clk = clk_get(NULL, "xtal");
463 BUG_ON(IS_ERR(xtal_clk));
464
465 xtal = clk_get_rate(xtal_clk);
466 clk_put(xtal_clk);
467
468 printk(KERN_DEBUG "%s: xtal is %ld\n", __func__, xtal);
469
470 apll = s5p_get_pll45xx(xtal, __raw_readl(S5P_APLL_CON0), pll_4508);
471 mpll = s5p_get_pll45xx(xtal, __raw_readl(S5P_MPLL_CON0), pll_4508);
472 epll = s5p_get_pll46xx(xtal, __raw_readl(S5P_EPLL_CON0),
473 __raw_readl(S5P_EPLL_CON1), pll_4500);
474
475 vpllsrc = clk_get_rate(&clk_vpllsrc.clk);
476 vpll = s5p_get_pll46xx(vpllsrc, __raw_readl(S5P_VPLL_CON0),
477 __raw_readl(S5P_VPLL_CON1), pll_4502);
478
479 clk_fout_apll.rate = apll;
480 clk_fout_mpll.rate = mpll;
481 clk_fout_epll.rate = epll;
482 clk_fout_vpll.rate = vpll;
483
484 printk(KERN_INFO "S5PV310: PLL settings, A=%ld, M=%ld, E=%ld V=%ld",
485 apll, mpll, epll, vpll);
486
487 armclk = clk_get_rate(&clk_armclk.clk);
488 aclk_corem0 = clk_get_rate(&clk_aclk_corem0.clk);
489 aclk_cores = clk_get_rate(&clk_aclk_cores.clk);
490 aclk_corem1 = clk_get_rate(&clk_aclk_corem1.clk);
491 periphclk = clk_get_rate(&clk_periphclk.clk);
492 sclk_dmc = clk_get_rate(&clk_sclk_dmc.clk);
493 aclk_cored = clk_get_rate(&clk_aclk_cored.clk);
494 aclk_corep = clk_get_rate(&clk_aclk_corep.clk);
495 aclk_acp = clk_get_rate(&clk_aclk_acp.clk);
496 pclk_acp = clk_get_rate(&clk_pclk_acp.clk);
497
498 printk(KERN_INFO "S5PV310: ARMCLK=%ld, COREM0=%ld, CORES=%ld\n"
499 "COREM1=%ld, PERI=%ld, DMC=%ld, CORED=%ld\n"
500 "COREP=%ld, ACLK_ACP=%ld, PCLK_ACP=%ld",
501 armclk, aclk_corem0, aclk_cores, aclk_corem1,
502 periphclk, sclk_dmc, aclk_cored, aclk_corep,
503 aclk_acp, pclk_acp);
504
505 clk_f.rate = armclk;
506 clk_h.rate = sclk_dmc;
507 clk_p.rate = periphclk;
508
509 for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
510 s3c_set_clksrc(&clksrcs[ptr], true);
511}
512
513static struct clk *clks[] __initdata = {
514 /* Nothing here yet */
515};
516
517void __init s5pv310_register_clocks(void)
518{
519 struct clk *clkp;
520 int ret;
521 int ptr;
522
523 ret = s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
524 if (ret > 0)
525 printk(KERN_ERR "Failed to register %u clocks\n", ret);
526
527 for (ptr = 0; ptr < ARRAY_SIZE(sysclks); ptr++)
528 s3c_register_clksrc(sysclks[ptr], 1);
529
530 s3c_register_clksrc(clksrcs, ARRAY_SIZE(clksrcs));
531 s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
532
533 clkp = init_clocks_disable;
534 for (ptr = 0; ptr < ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
535 ret = s3c24xx_register_clock(clkp);
536 if (ret < 0) {
537 printk(KERN_ERR "Failed to register clock %s (%d)\n",
538 clkp->name, ret);
539 }
540 (clkp->enable)(clkp, 0);
541 }
542
543 s3c_pwmclk_init();
544}
diff --git a/arch/arm/mach-s5pv310/cpu.c b/arch/arm/mach-s5pv310/cpu.c
new file mode 100644
index 000000000000..196c9f12ed85
--- /dev/null
+++ b/arch/arm/mach-s5pv310/cpu.c
@@ -0,0 +1,122 @@
1/* linux/arch/arm/mach-s5pv310/cpu.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.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#include <linux/sched.h>
12#include <linux/sysdev.h>
13
14#include <asm/mach/map.h>
15#include <asm/mach/irq.h>
16
17#include <asm/proc-fns.h>
18
19#include <plat/cpu.h>
20#include <plat/clock.h>
21#include <plat/s5pv310.h>
22
23#include <mach/regs-irq.h>
24
25void __iomem *gic_cpu_base_addr;
26
27extern int combiner_init(unsigned int combiner_nr, void __iomem *base,
28 unsigned int irq_start);
29extern void combiner_cascade_irq(unsigned int combiner_nr, unsigned int irq);
30
31/* Initial IO mappings */
32static struct map_desc s5pv310_iodesc[] __initdata = {
33 {
34 .virtual = (unsigned long)S5P_VA_COREPERI_BASE,
35 .pfn = __phys_to_pfn(S5PV310_PA_COREPERI),
36 .length = SZ_8K,
37 .type = MT_DEVICE,
38 }, {
39 .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
40 .pfn = __phys_to_pfn(S5PV310_PA_COMBINER),
41 .length = SZ_4K,
42 .type = MT_DEVICE,
43 }, {
44 .virtual = (unsigned long)S5P_VA_L2CC,
45 .pfn = __phys_to_pfn(S5PV310_PA_L2CC),
46 .length = SZ_4K,
47 .type = MT_DEVICE,
48 },
49};
50
51static void s5pv310_idle(void)
52{
53 if (!need_resched())
54 cpu_do_idle();
55
56 local_irq_enable();
57}
58
59/* s5pv310_map_io
60 *
61 * register the standard cpu IO areas
62*/
63void __init s5pv310_map_io(void)
64{
65 iotable_init(s5pv310_iodesc, ARRAY_SIZE(s5pv310_iodesc));
66}
67
68void __init s5pv310_init_clocks(int xtal)
69{
70 printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
71
72 s3c24xx_register_baseclocks(xtal);
73 s5p_register_clocks(xtal);
74 s5pv310_register_clocks();
75 s5pv310_setup_clocks();
76}
77
78void __init s5pv310_init_irq(void)
79{
80 int irq;
81
82 gic_cpu_base_addr = S5P_VA_GIC_CPU;
83 gic_dist_init(0, S5P_VA_GIC_DIST, IRQ_LOCALTIMER);
84 gic_cpu_init(0, S5P_VA_GIC_CPU);
85
86 for (irq = 0; irq < MAX_COMBINER_NR; irq++) {
87 combiner_init(irq, (void __iomem *)S5P_VA_COMBINER(irq),
88 COMBINER_IRQ(irq, 0));
89 combiner_cascade_irq(irq, IRQ_SPI(irq));
90 }
91
92 /* The parameters of s5p_init_irq() are for VIC init.
93 * Theses parameters should be NULL and 0 because S5PV310
94 * uses GIC instead of VIC.
95 */
96 s5p_init_irq(NULL, 0);
97}
98
99struct sysdev_class s5pv310_sysclass = {
100 .name = "s5pv310-core",
101};
102
103static struct sys_device s5pv310_sysdev = {
104 .cls = &s5pv310_sysclass,
105};
106
107static int __init s5pv310_core_init(void)
108{
109 return sysdev_class_register(&s5pv310_sysclass);
110}
111
112core_initcall(s5pv310_core_init);
113
114int __init s5pv310_init(void)
115{
116 printk(KERN_INFO "S5PV310: Initializing architecture\n");
117
118 /* set idle function */
119 pm_idle = s5pv310_idle;
120
121 return sysdev_register(&s5pv310_sysdev);
122}
diff --git a/arch/arm/mach-s5pv310/headsmp.S b/arch/arm/mach-s5pv310/headsmp.S
new file mode 100644
index 000000000000..164b7b045713
--- /dev/null
+++ b/arch/arm/mach-s5pv310/headsmp.S
@@ -0,0 +1,41 @@
1/*
2 * linux/arch/arm/mach-s5pv310/headsmp.S
3 *
4 * Cloned from linux/arch/arm/mach-realview/headsmp.S
5 *
6 * Copyright (c) 2003 ARM Limited
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#include <linux/linkage.h>
14#include <linux/init.h>
15
16 __INIT
17
18/*
19 * s5pv310 specific entry point for secondary CPUs. This provides
20 * a "holding pen" into which all secondary cores are held until we're
21 * ready for them to initialise.
22 */
23ENTRY(s5pv310_secondary_startup)
24 mrc p15, 0, r0, c0, c0, 5
25 and r0, r0, #15
26 adr r4, 1f
27 ldmia r4, {r5, r6}
28 sub r4, r4, r5
29 add r6, r6, r4
30pen: ldr r7, [r6]
31 cmp r7, r0
32 bne pen
33
34 /*
35 * we've been released from the holding pen: secondary_stack
36 * should now contain the SVC stack for this core
37 */
38 b secondary_startup
39
401: .long .
41 .long pen_release
diff --git a/arch/arm/mach-s5pv310/include/mach/debug-macro.S b/arch/arm/mach-s5pv310/include/mach/debug-macro.S
new file mode 100644
index 000000000000..6fb3893486be
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/debug-macro.S
@@ -0,0 +1,36 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/debug-macro.S
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * Based on arch/arm/mach-s3c6400/include/mach/debug-macro.S
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/* pull in the relevant register and map files. */
14
15#include <mach/map.h>
16
17 /* note, for the boot process to work we have to keep the UART
18 * virtual address aligned to an 1MiB boundary for the L1
19 * mapping the head code makes. We keep the UART virtual address
20 * aligned and add in the offset when we load the value here.
21 */
22
23 .macro addruart, rx, tmp
24 mrc p15, 0, \rx, c1, c0
25 tst \rx, #1
26 ldreq \rx, = S3C_PA_UART
27 ldrne \rx, = S3C_VA_UART
28#if CONFIG_DEBUG_S3C_UART != 0
29 add \rx, \rx, #(0x10000 * CONFIG_DEBUG_S3C_UART)
30#endif
31 .endm
32
33#define fifo_full fifo_full_s5pv210
34#define fifo_level fifo_level_s5pv210
35
36#include <plat/debug-macro.S>
diff --git a/arch/arm/mach-s5pv310/include/mach/entry-macro.S b/arch/arm/mach-s5pv310/include/mach/entry-macro.S
new file mode 100644
index 000000000000..e600e1d522df
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/entry-macro.S
@@ -0,0 +1,84 @@
1/* arch/arm/mach-s5pv310/include/mach/entry-macro.S
2 *
3 * Cloned from arch/arm/mach-realview/include/mach/entry-macro.S
4 *
5 * Low-level IRQ helper macros for S5PV310 platforms
6 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10*/
11
12#include <mach/hardware.h>
13#include <asm/hardware/gic.h>
14
15 .macro disable_fiq
16 .endm
17
18 .macro get_irqnr_preamble, base, tmp
19 ldr \base, =gic_cpu_base_addr
20 ldr \base, [\base]
21 .endm
22
23 .macro arch_ret_to_user, tmp1, tmp2
24 .endm
25
26 /*
27 * The interrupt numbering scheme is defined in the
28 * interrupt controller spec. To wit:
29 *
30 * Interrupts 0-15 are IPI
31 * 16-28 are reserved
32 * 29-31 are local. We allow 30 to be used for the watchdog.
33 * 32-1020 are global
34 * 1021-1022 are reserved
35 * 1023 is "spurious" (no interrupt)
36 *
37 * For now, we ignore all local interrupts so only return an interrupt if it's
38 * between 30 and 1020. The test_for_ipi routine below will pick up on IPIs.
39 *
40 * A simple read from the controller will tell us the number of the highest
41 * priority enabled interrupt. We then just need to check whether it is in the
42 * valid range for an IRQ (30-1020 inclusive).
43 */
44
45 .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
46
47 ldr \irqstat, [\base, #GIC_CPU_INTACK] /* bits 12-10 = src CPU, 9-0 = int # */
48
49 ldr \tmp, =1021
50
51 bic \irqnr, \irqstat, #0x1c00
52
53 cmp \irqnr, #29
54 cmpcc \irqnr, \irqnr
55 cmpne \irqnr, \tmp
56 cmpcs \irqnr, \irqnr
57 addne \irqnr, \irqnr, #32
58
59 .endm
60
61 /* We assume that irqstat (the raw value of the IRQ acknowledge
62 * register) is preserved from the macro above.
63 * If there is an IPI, we immediately signal end of interrupt on the
64 * controller, since this requires the original irqstat value which
65 * we won't easily be able to recreate later.
66 */
67
68 .macro test_for_ipi, irqnr, irqstat, base, tmp
69 bic \irqnr, \irqstat, #0x1c00
70 cmp \irqnr, #16
71 strcc \irqstat, [\base, #GIC_CPU_EOI]
72 cmpcs \irqnr, \irqnr
73 .endm
74
75 /* As above, this assumes that irqstat and base are preserved.. */
76
77 .macro test_for_ltirq, irqnr, irqstat, base, tmp
78 bic \irqnr, \irqstat, #0x1c00
79 mov \tmp, #0
80 cmp \irqnr, #29
81 moveq \tmp, #1
82 streq \irqstat, [\base, #GIC_CPU_EOI]
83 cmp \tmp, #0
84 .endm
diff --git a/arch/arm/mach-s5pv310/include/mach/gpio.h b/arch/arm/mach-s5pv310/include/mach/gpio.h
new file mode 100644
index 000000000000..20cb80c23466
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/gpio.h
@@ -0,0 +1,135 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/gpio.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * S5PV310 - GPIO lib support
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#ifndef __ASM_ARCH_GPIO_H
14#define __ASM_ARCH_GPIO_H __FILE__
15
16#define gpio_get_value __gpio_get_value
17#define gpio_set_value __gpio_set_value
18#define gpio_cansleep __gpio_cansleep
19#define gpio_to_irq __gpio_to_irq
20
21/* Practically, GPIO banks upto GPZ are the configurable gpio banks */
22
23/* GPIO bank sizes */
24#define S5PV310_GPIO_A0_NR (8)
25#define S5PV310_GPIO_A1_NR (6)
26#define S5PV310_GPIO_B_NR (8)
27#define S5PV310_GPIO_C0_NR (5)
28#define S5PV310_GPIO_C1_NR (5)
29#define S5PV310_GPIO_D0_NR (4)
30#define S5PV310_GPIO_D1_NR (4)
31#define S5PV310_GPIO_E0_NR (5)
32#define S5PV310_GPIO_E1_NR (8)
33#define S5PV310_GPIO_E2_NR (6)
34#define S5PV310_GPIO_E3_NR (8)
35#define S5PV310_GPIO_E4_NR (8)
36#define S5PV310_GPIO_F0_NR (8)
37#define S5PV310_GPIO_F1_NR (8)
38#define S5PV310_GPIO_F2_NR (8)
39#define S5PV310_GPIO_F3_NR (6)
40#define S5PV310_GPIO_J0_NR (8)
41#define S5PV310_GPIO_J1_NR (5)
42#define S5PV310_GPIO_K0_NR (7)
43#define S5PV310_GPIO_K1_NR (7)
44#define S5PV310_GPIO_K2_NR (7)
45#define S5PV310_GPIO_K3_NR (7)
46#define S5PV310_GPIO_L0_NR (8)
47#define S5PV310_GPIO_L1_NR (3)
48#define S5PV310_GPIO_L2_NR (8)
49#define S5PV310_GPIO_X0_NR (8)
50#define S5PV310_GPIO_X1_NR (8)
51#define S5PV310_GPIO_X2_NR (8)
52#define S5PV310_GPIO_X3_NR (8)
53#define S5PV310_GPIO_Z_NR (7)
54
55/* GPIO bank numbers */
56
57#define S5PV310_GPIO_NEXT(__gpio) \
58 ((__gpio##_START) + (__gpio##_NR) + CONFIG_S3C_GPIO_SPACE + 1)
59
60enum s5p_gpio_number {
61 S5PV310_GPIO_A0_START = 0,
62 S5PV310_GPIO_A1_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_A0),
63 S5PV310_GPIO_B_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_A1),
64 S5PV310_GPIO_C0_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_B),
65 S5PV310_GPIO_C1_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_C0),
66 S5PV310_GPIO_D0_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_C1),
67 S5PV310_GPIO_D1_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_D0),
68 S5PV310_GPIO_E0_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_D1),
69 S5PV310_GPIO_E1_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_E0),
70 S5PV310_GPIO_E2_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_E1),
71 S5PV310_GPIO_E3_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_E2),
72 S5PV310_GPIO_E4_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_E3),
73 S5PV310_GPIO_F0_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_E4),
74 S5PV310_GPIO_F1_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_F0),
75 S5PV310_GPIO_F2_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_F1),
76 S5PV310_GPIO_F3_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_F2),
77 S5PV310_GPIO_J0_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_F3),
78 S5PV310_GPIO_J1_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_J0),
79 S5PV310_GPIO_K0_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_J1),
80 S5PV310_GPIO_K1_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_K0),
81 S5PV310_GPIO_K2_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_K1),
82 S5PV310_GPIO_K3_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_K2),
83 S5PV310_GPIO_L0_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_K3),
84 S5PV310_GPIO_L1_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_L0),
85 S5PV310_GPIO_L2_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_L1),
86 S5PV310_GPIO_X0_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_L2),
87 S5PV310_GPIO_X1_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_X0),
88 S5PV310_GPIO_X2_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_X1),
89 S5PV310_GPIO_X3_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_X2),
90 S5PV310_GPIO_Z_START = S5PV310_GPIO_NEXT(S5PV310_GPIO_X3),
91};
92
93/* S5PV310 GPIO number definitions */
94#define S5PV310_GPA0(_nr) (S5PV310_GPIO_A0_START + (_nr))
95#define S5PV310_GPA1(_nr) (S5PV310_GPIO_A1_START + (_nr))
96#define S5PV310_GPB(_nr) (S5PV310_GPIO_B_START + (_nr))
97#define S5PV310_GPC0(_nr) (S5PV310_GPIO_C0_START + (_nr))
98#define S5PV310_GPC1(_nr) (S5PV310_GPIO_C1_START + (_nr))
99#define S5PV310_GPD0(_nr) (S5PV310_GPIO_D0_START + (_nr))
100#define S5PV310_GPD1(_nr) (S5PV310_GPIO_D1_START + (_nr))
101#define S5PV310_GPE0(_nr) (S5PV310_GPIO_E0_START + (_nr))
102#define S5PV310_GPE1(_nr) (S5PV310_GPIO_E1_START + (_nr))
103#define S5PV310_GPE2(_nr) (S5PV310_GPIO_E2_START + (_nr))
104#define S5PV310_GPE3(_nr) (S5PV310_GPIO_E3_START + (_nr))
105#define S5PV310_GPE4(_nr) (S5PV310_GPIO_E4_START + (_nr))
106#define S5PV310_GPF0(_nr) (S5PV310_GPIO_F0_START + (_nr))
107#define S5PV310_GPF1(_nr) (S5PV310_GPIO_F1_START + (_nr))
108#define S5PV310_GPF2(_nr) (S5PV310_GPIO_F2_START + (_nr))
109#define S5PV310_GPF3(_nr) (S5PV310_GPIO_F3_START + (_nr))
110#define S5PV310_GPJ0(_nr) (S5PV310_GPIO_J0_START + (_nr))
111#define S5PV310_GPJ1(_nr) (S5PV310_GPIO_J1_START + (_nr))
112#define S5PV310_GPK0(_nr) (S5PV310_GPIO_K0_START + (_nr))
113#define S5PV310_GPK1(_nr) (S5PV310_GPIO_K1_START + (_nr))
114#define S5PV310_GPK2(_nr) (S5PV310_GPIO_K2_START + (_nr))
115#define S5PV310_GPK3(_nr) (S5PV310_GPIO_K3_START + (_nr))
116#define S5PV310_GPL0(_nr) (S5PV310_GPIO_L0_START + (_nr))
117#define S5PV310_GPL1(_nr) (S5PV310_GPIO_L1_START + (_nr))
118#define S5PV310_GPL2(_nr) (S5PV310_GPIO_L2_START + (_nr))
119#define S5PV310_GPX0(_nr) (S5PV310_GPIO_X0_START + (_nr))
120#define S5PV310_GPX1(_nr) (S5PV310_GPIO_X1_START + (_nr))
121#define S5PV310_GPX2(_nr) (S5PV310_GPIO_X2_START + (_nr))
122#define S5PV310_GPX3(_nr) (S5PV310_GPIO_X3_START + (_nr))
123#define S5PV310_GPZ(_nr) (S5PV310_GPIO_Z_START + (_nr))
124
125/* the end of the S5PV310 specific gpios */
126#define S5PV310_GPIO_END (S5PV310_GPZ(S5PV310_GPIO_Z_NR) + 1)
127#define S3C_GPIO_END S5PV310_GPIO_END
128
129/* define the number of gpios we need to the one after the GPZ() range */
130#define ARCH_NR_GPIOS (S5PV310_GPZ(S5PV310_GPIO_Z_NR) + \
131 CONFIG_SAMSUNG_GPIO_EXTRA + 1)
132
133#include <asm-generic/gpio.h>
134
135#endif /* __ASM_ARCH_GPIO_H */
diff --git a/arch/arm/mach-s5pv310/include/mach/hardware.h b/arch/arm/mach-s5pv310/include/mach/hardware.h
new file mode 100644
index 000000000000..28ff9881f1a6
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/hardware.h
@@ -0,0 +1,18 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/hardware.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * S5PV310 - Hardware support
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#ifndef __ASM_ARCH_HARDWARE_H
14#define __ASM_ARCH_HARDWARE_H __FILE__
15
16/* currently nothing here, placeholder */
17
18#endif /* __ASM_ARCH_HARDWARE_H */
diff --git a/arch/arm/mach-s5pv310/include/mach/io.h b/arch/arm/mach-s5pv310/include/mach/io.h
new file mode 100644
index 000000000000..8a7f9128391f
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/io.h
@@ -0,0 +1,26 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/io.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * Copyright 2008-2010 Ben Dooks <ben-linux@fluff.org>
7 *
8 * Based on arch/arm/mach-s5p6442/include/mach/io.h
9 *
10 * Default IO routines for S5PV310
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15*/
16
17#ifndef __ASM_ARM_ARCH_IO_H
18#define __ASM_ARM_ARCH_IO_H __FILE__
19
20/* No current ISA/PCI bus support. */
21#define __io(a) __typesafe_io(a)
22#define __mem_pci(a) (a)
23
24#define IO_SPACE_LIMIT (0xFFFFFFFF)
25
26#endif /* __ASM_ARM_ARCH_IO_H */
diff --git a/arch/arm/mach-s5pv310/include/mach/irqs.h b/arch/arm/mach-s5pv310/include/mach/irqs.h
new file mode 100644
index 000000000000..56885ca3773c
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/irqs.h
@@ -0,0 +1,74 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/irqs.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * S5PV210 - IRQ definitions
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#ifndef __ASM_ARCH_IRQS_H
14#define __ASM_ARCH_IRQS_H __FILE__
15
16#include <plat/irqs.h>
17
18/* Private Peripheral Interrupt */
19#define IRQ_PPI(x) S5P_IRQ(x+16)
20
21#define IRQ_LOCALTIMER IRQ_PPI(13)
22
23/* Shared Peripheral Interrupt */
24#define IRQ_SPI(x) S5P_IRQ(x+32)
25
26#define IRQ_EINT0 IRQ_SPI(40)
27#define IRQ_EINT1 IRQ_SPI(41)
28#define IRQ_EINT2 IRQ_SPI(42)
29#define IRQ_EINT3 IRQ_SPI(43)
30#define IRQ_USB_HSOTG IRQ_SPI(44)
31#define IRQ_USB_HOST IRQ_SPI(45)
32#define IRQ_MODEM_IF IRQ_SPI(46)
33#define IRQ_ROTATOR IRQ_SPI(47)
34#define IRQ_JPEG IRQ_SPI(48)
35#define IRQ_2D IRQ_SPI(49)
36#define IRQ_PCIE IRQ_SPI(50)
37#define IRQ_SYSTEM_TIMER IRQ_SPI(51)
38#define IRQ_MFC IRQ_SPI(52)
39#define IRQ_WTD IRQ_SPI(53)
40#define IRQ_AUDIO_SS IRQ_SPI(54)
41#define IRQ_AC97 IRQ_SPI(55)
42#define IRQ_SPDIF IRQ_SPI(56)
43#define IRQ_KEYPAD IRQ_SPI(57)
44#define IRQ_INTFEEDCTRL_SSS IRQ_SPI(58)
45#define IRQ_SLIMBUS IRQ_SPI(59)
46#define IRQ_PMU IRQ_SPI(60)
47#define IRQ_TSI IRQ_SPI(61)
48#define IRQ_SATA IRQ_SPI(62)
49#define IRQ_GPS IRQ_SPI(63)
50
51#define MAX_IRQ_IN_COMBINER 8
52#define COMBINER_GROUP(x) ((x) * MAX_IRQ_IN_COMBINER + IRQ_SPI(64))
53#define COMBINER_IRQ(x, y) (COMBINER_GROUP(x) + y)
54
55#define IRQ_TIMER0_VIC COMBINER_IRQ(22, 0)
56#define IRQ_TIMER1_VIC COMBINER_IRQ(22, 1)
57#define IRQ_TIMER2_VIC COMBINER_IRQ(22, 2)
58#define IRQ_TIMER3_VIC COMBINER_IRQ(22, 3)
59#define IRQ_TIMER4_VIC COMBINER_IRQ(22, 4)
60
61#define IRQ_UART0 COMBINER_IRQ(26, 0)
62#define IRQ_UART1 COMBINER_IRQ(26, 1)
63#define IRQ_UART2 COMBINER_IRQ(26, 2)
64#define IRQ_UART3 COMBINER_IRQ(26, 3)
65#define IRQ_UART4 COMBINER_IRQ(26, 4)
66
67#define IRQ_IIC COMBINER_IRQ(27, 0)
68
69/* Set the default NR_IRQS */
70#define NR_IRQS COMBINER_IRQ(MAX_COMBINER_NR, 0)
71
72#define MAX_COMBINER_NR 39
73
74#endif /* ASM_ARCH_IRQS_H */
diff --git a/arch/arm/mach-s5pv310/include/mach/map.h b/arch/arm/mach-s5pv310/include/mach/map.h
new file mode 100644
index 000000000000..87697c9fca5b
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/map.h
@@ -0,0 +1,69 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/map.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * S5PV310 - Memory map definitions
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#ifndef __ASM_ARCH_MAP_H
14#define __ASM_ARCH_MAP_H __FILE__
15
16#include <plat/map-base.h>
17
18/*
19 * S5PV310 UART offset is 0x10000 but the older S5P SoCs are 0x400.
20 * So need to define it, and here is to avoid redefinition warning.
21 */
22#define S3C_UART_OFFSET (0x10000)
23
24#include <plat/map-s5p.h>
25
26#define S5PV310_PA_CHIPID (0x10000000)
27#define S5P_PA_CHIPID S5PV310_PA_CHIPID
28
29#define S5PV310_PA_SYSCON (0x10020000)
30#define S5P_PA_SYSCON S5PV310_PA_SYSCON
31
32#define S5PV310_PA_WATCHDOG (0x10060000)
33
34#define S5PV310_PA_COMBINER (0x10448000)
35
36#define S5PV310_PA_COREPERI (0x10500000)
37#define S5PV310_PA_GIC_CPU (0x10500100)
38#define S5PV310_PA_TWD (0x10500600)
39#define S5PV310_PA_GIC_DIST (0x10501000)
40#define S5PV310_PA_L2CC (0x10502000)
41
42#define S5PV310_PA_GPIO (0x11000000)
43#define S5P_PA_GPIO S5PV310_PA_GPIO
44
45#define S5PV310_PA_UART (0x13800000)
46
47#define S5P_PA_UART(x) (S5PV310_PA_UART + ((x) * S3C_UART_OFFSET))
48#define S5P_PA_UART0 S5P_PA_UART(0)
49#define S5P_PA_UART1 S5P_PA_UART(1)
50#define S5P_PA_UART2 S5P_PA_UART(2)
51#define S5P_PA_UART3 S5P_PA_UART(3)
52#define S5P_PA_UART4 S5P_PA_UART(4)
53
54#define S5P_SZ_UART SZ_256
55
56#define S5PV310_PA_IIC0 (0x13860000)
57
58#define S5PV310_PA_TIMER (0x139D0000)
59#define S5P_PA_TIMER S5PV310_PA_TIMER
60
61#define S5PV310_PA_SDRAM (0x40000000)
62#define S5P_PA_SDRAM S5PV310_PA_SDRAM
63
64/* compatibiltiy defines. */
65#define S3C_PA_UART S5PV310_PA_UART
66#define S3C_PA_IIC S5PV310_PA_IIC0
67#define S3C_PA_WDT S5PV310_PA_WATCHDOG
68
69#endif /* __ASM_ARCH_MAP_H */
diff --git a/arch/arm/mach-s5pv310/include/mach/memory.h b/arch/arm/mach-s5pv310/include/mach/memory.h
new file mode 100644
index 000000000000..1dffb4823245
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/memory.h
@@ -0,0 +1,22 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/memory.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * S5PV310 - Memory definitions
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#ifndef __ASM_ARCH_MEMORY_H
14#define __ASM_ARCH_MEMORY_H __FILE__
15
16#define PHYS_OFFSET UL(0x40000000)
17
18/* Maximum of 256MiB in one bank */
19#define MAX_PHYSMEM_BITS 32
20#define SECTION_SIZE_BITS 28
21
22#endif /* __ASM_ARCH_MEMORY_H */
diff --git a/arch/arm/mach-s5pv310/include/mach/pwm-clock.h b/arch/arm/mach-s5pv310/include/mach/pwm-clock.h
new file mode 100644
index 000000000000..7e6da2701088
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/pwm-clock.h
@@ -0,0 +1,70 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/pwm-clock.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * Copyright 2008 Openmoko, Inc.
7 * Copyright 2008 Simtec Electronics
8 * Ben Dooks <ben@simtec.co.uk>
9 * http://armlinux.simtec.co.uk/
10 *
11 * Based on arch/arm/mach-s3c64xx/include/mach/pwm-clock.h
12 *
13 * S5PV310 - pwm clock and timer support
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License version 2 as
17 * published by the Free Software Foundation.
18*/
19
20#ifndef __ASM_ARCH_PWMCLK_H
21#define __ASM_ARCH_PWMCLK_H __FILE__
22
23/**
24 * pwm_cfg_src_is_tclk() - return whether the given mux config is a tclk
25 * @tcfg: The timer TCFG1 register bits shifted down to 0.
26 *
27 * Return true if the given configuration from TCFG1 is a TCLK instead
28 * any of the TDIV clocks.
29 */
30static inline int pwm_cfg_src_is_tclk(unsigned long tcfg)
31{
32 return tcfg == S3C64XX_TCFG1_MUX_TCLK;
33}
34
35/**
36 * tcfg_to_divisor() - convert tcfg1 setting to a divisor
37 * @tcfg1: The tcfg1 setting, shifted down.
38 *
39 * Get the divisor value for the given tcfg1 setting. We assume the
40 * caller has already checked to see if this is not a TCLK source.
41 */
42static inline unsigned long tcfg_to_divisor(unsigned long tcfg1)
43{
44 return 1 << tcfg1;
45}
46
47/**
48 * pwm_tdiv_has_div1() - does the tdiv setting have a /1
49 *
50 * Return true if we have a /1 in the tdiv setting.
51 */
52static inline unsigned int pwm_tdiv_has_div1(void)
53{
54 return 1;
55}
56
57/**
58 * pwm_tdiv_div_bits() - calculate TCFG1 divisor value.
59 * @div: The divisor to calculate the bit information for.
60 *
61 * Turn a divisor into the necessary bit field for TCFG1.
62 */
63static inline unsigned long pwm_tdiv_div_bits(unsigned int div)
64{
65 return ilog2(div);
66}
67
68#define S3C_TCFG1_MUX_TCLK S3C64XX_TCFG1_MUX_TCLK
69
70#endif /* __ASM_ARCH_PWMCLK_H */
diff --git a/arch/arm/mach-s5pv310/include/mach/regs-clock.h b/arch/arm/mach-s5pv310/include/mach/regs-clock.h
new file mode 100644
index 000000000000..59e3a7e94d80
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/regs-clock.h
@@ -0,0 +1,62 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/regs-clock.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * S5PV310 - Clock register definitions
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#ifndef __ASM_ARCH_REGS_CLOCK_H
14#define __ASM_ARCH_REGS_CLOCK_H __FILE__
15
16#include <mach/map.h>
17
18#define S5P_CLKREG(x) (S3C_VA_SYS + (x))
19
20#define S5P_INFORM0 S5P_CLKREG(0x800)
21
22#define S5P_EPLL_CON0 S5P_CLKREG(0x1C110)
23#define S5P_EPLL_CON1 S5P_CLKREG(0x1C114)
24#define S5P_VPLL_CON0 S5P_CLKREG(0x1C120)
25#define S5P_VPLL_CON1 S5P_CLKREG(0x1C124)
26
27#define S5P_CLKSRC_TOP0 S5P_CLKREG(0x1C210)
28#define S5P_CLKSRC_TOP1 S5P_CLKREG(0x1C214)
29
30#define S5P_CLKSRC_PERIL0 S5P_CLKREG(0x1C250)
31
32#define S5P_CLKDIV_TOP S5P_CLKREG(0x1C510)
33
34#define S5P_CLKDIV_PERIL0 S5P_CLKREG(0x1C550)
35#define S5P_CLKDIV_PERIL1 S5P_CLKREG(0x1C554)
36#define S5P_CLKDIV_PERIL2 S5P_CLKREG(0x1C558)
37#define S5P_CLKDIV_PERIL3 S5P_CLKREG(0x1C55C)
38#define S5P_CLKDIV_PERIL4 S5P_CLKREG(0x1C560)
39#define S5P_CLKDIV_PERIL5 S5P_CLKREG(0x1C564)
40
41#define S5P_CLKGATE_IP_PERIL S5P_CLKREG(0x1C950)
42
43#define S5P_CLKSRC_CORE S5P_CLKREG(0x20200)
44
45#define S5P_CLKDIV_CORE0 S5P_CLKREG(0x20500)
46
47#define S5P_APLL_LOCK S5P_CLKREG(0x24000)
48#define S5P_MPLL_LOCK S5P_CLKREG(0x24004)
49#define S5P_APLL_CON0 S5P_CLKREG(0x24100)
50#define S5P_APLL_CON1 S5P_CLKREG(0x24104)
51#define S5P_MPLL_CON0 S5P_CLKREG(0x24108)
52#define S5P_MPLL_CON1 S5P_CLKREG(0x2410C)
53
54#define S5P_CLKSRC_CPU S5P_CLKREG(0x24200)
55#define S5P_CLKMUX_STATCPU S5P_CLKREG(0x24400)
56
57#define S5P_CLKDIV_CPU S5P_CLKREG(0x24500)
58#define S5P_CLKDIV_STATCPU S5P_CLKREG(0x24600)
59
60#define S5P_CLKGATE_SCLKCPU S5P_CLKREG(0x24800)
61
62#endif /* __ASM_ARCH_REGS_CLOCK_H */
diff --git a/arch/arm/mach-s5pv310/include/mach/regs-irq.h b/arch/arm/mach-s5pv310/include/mach/regs-irq.h
new file mode 100644
index 000000000000..c6e09c7f9161
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/regs-irq.h
@@ -0,0 +1,19 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/regs-irq.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * S5PV310 - IRQ register definitions
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#ifndef __ASM_ARCH_REGS_IRQ_H
14#define __ASM_ARCH_REGS_IRQ_H __FILE__
15
16#include <asm/hardware/gic.h>
17#include <mach/map.h>
18
19#endif /* __ASM_ARCH_REGS_IRQ_H */
diff --git a/arch/arm/mach-s5pv310/include/mach/smp.h b/arch/arm/mach-s5pv310/include/mach/smp.h
new file mode 100644
index 000000000000..990f3ba88a1f
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/smp.h
@@ -0,0 +1,29 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/smp.h
2 *
3 * Cloned from arch/arm/mach-realview/include/mach/smp.h
4*/
5
6#ifndef ASM_ARCH_SMP_H
7#define ASM_ARCH_SMP_H __FILE__
8
9#include <asm/hardware/gic.h>
10
11extern void __iomem *gic_cpu_base_addr;
12
13#define hard_smp_processor_id() \
14 ({ \
15 unsigned int cpunum; \
16 __asm__("mrc p15, 0, %0, c0, c0, 5" \
17 : "=r" (cpunum)); \
18 cpunum &= 0x03; \
19 })
20
21/*
22 * We use IRQ1 as the IPI
23 */
24static inline void smp_cross_call(const struct cpumask *mask)
25{
26 gic_raise_softirq(mask, 1);
27}
28
29#endif
diff --git a/arch/arm/mach-s5pv310/include/mach/system.h b/arch/arm/mach-s5pv310/include/mach/system.h
new file mode 100644
index 000000000000..d10c009cf0f1
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/system.h
@@ -0,0 +1,22 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/system.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * S5PV310 - system support header
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#ifndef __ASM_ARCH_SYSTEM_H
14#define __ASM_ARCH_SYSTEM_H __FILE__
15
16#include <plat/system-reset.h>
17
18static void arch_idle(void)
19{
20 /* nothing here yet */
21}
22#endif /* __ASM_ARCH_SYSTEM_H */
diff --git a/arch/arm/mach-s5pv310/include/mach/timex.h b/arch/arm/mach-s5pv310/include/mach/timex.h
new file mode 100644
index 000000000000..bd2359b952b4
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/timex.h
@@ -0,0 +1,29 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/timex.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * Copyright (c) 2003-2010 Simtec Electronics
7 * Ben Dooks <ben@simtec.co.uk>
8 *
9 * Based on arch/arm/mach-s5p6442/include/mach/timex.h
10 *
11 * S5PV310 - time parameters
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16*/
17
18#ifndef __ASM_ARCH_TIMEX_H
19#define __ASM_ARCH_TIMEX_H __FILE__
20
21/* CLOCK_TICK_RATE needs to be evaluatable by the cpp, so making it
22 * a variable is useless. It seems as long as we make our timers an
23 * exact multiple of HZ, any value that makes a 1->1 correspondence
24 * for the time conversion functions to/from jiffies is acceptable.
25*/
26
27#define CLOCK_TICK_RATE 12000000
28
29#endif /* __ASM_ARCH_TIMEX_H */
diff --git a/arch/arm/mach-s5pv310/include/mach/uncompress.h b/arch/arm/mach-s5pv310/include/mach/uncompress.h
new file mode 100644
index 000000000000..59593c1e2416
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/uncompress.h
@@ -0,0 +1,30 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/uncompress.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * S5PV310 - uncompress code
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#ifndef __ASM_ARCH_UNCOMPRESS_H
14#define __ASM_ARCH_UNCOMPRESS_H __FILE__
15
16#include <mach/map.h>
17#include <plat/uncompress.h>
18
19static void arch_detect_cpu(void)
20{
21 /* we do not need to do any cpu detection here at the moment. */
22
23 /*
24 * For preventing FIFO overrun or infinite loop of UART console,
25 * fifo_max should be the minimum fifo size of all of the UART channels
26 */
27 fifo_mask = S5PV210_UFSTAT_TXMASK;
28 fifo_max = 15 << S5PV210_UFSTAT_TXSHIFT;
29}
30#endif /* __ASM_ARCH_UNCOMPRESS_H */
diff --git a/arch/arm/mach-s5pv310/include/mach/vmalloc.h b/arch/arm/mach-s5pv310/include/mach/vmalloc.h
new file mode 100644
index 000000000000..3f565ebb7daa
--- /dev/null
+++ b/arch/arm/mach-s5pv310/include/mach/vmalloc.h
@@ -0,0 +1,22 @@
1/* linux/arch/arm/mach-s5pv310/include/mach/vmalloc.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * Copyright 2010 Ben Dooks <ben-linux@fluff.org>
7 *
8 * Based on arch/arm/mach-s5p6440/include/mach/vmalloc.h
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * S5PV310 vmalloc definition
15*/
16
17#ifndef __ASM_ARCH_VMALLOC_H
18#define __ASM_ARCH_VMALLOC_H __FILE__
19
20#define VMALLOC_END (0xF0000000)
21
22#endif /* __ASM_ARCH_VMALLOC_H */
diff --git a/arch/arm/mach-s5pv310/init.c b/arch/arm/mach-s5pv310/init.c
new file mode 100644
index 000000000000..182dcf42cfb4
--- /dev/null
+++ b/arch/arm/mach-s5pv310/init.c
@@ -0,0 +1,41 @@
1/* linux/arch/arm/mach-s5pv310/init.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.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#include <linux/serial_core.h>
12
13#include <plat/cpu.h>
14#include <plat/devs.h>
15#include <plat/regs-serial.h>
16
17static struct s3c24xx_uart_clksrc s5pv310_serial_clocks[] = {
18 [0] = {
19 .name = "uclk1",
20 .divisor = 1,
21 .min_baud = 0,
22 .max_baud = 0,
23 },
24};
25
26/* uart registration process */
27void __init s5pv310_common_init_uarts(struct s3c2410_uartcfg *cfg, int no)
28{
29 struct s3c2410_uartcfg *tcfg = cfg;
30 u32 ucnt;
31
32 for (ucnt = 0; ucnt < no; ucnt++, tcfg++) {
33 if (!tcfg->clocks) {
34 tcfg->has_fracval = 1;
35 tcfg->clocks = s5pv310_serial_clocks;
36 tcfg->clocks_size = ARRAY_SIZE(s5pv310_serial_clocks);
37 }
38 }
39
40 s3c24xx_init_uartdevs("s5pv210-uart", s5p_uart_resources, cfg, no);
41}
diff --git a/arch/arm/mach-s5pv310/irq-combiner.c b/arch/arm/mach-s5pv310/irq-combiner.c
new file mode 100644
index 000000000000..0f7052164f23
--- /dev/null
+++ b/arch/arm/mach-s5pv310/irq-combiner.c
@@ -0,0 +1,125 @@
1/* linux/arch/arm/mach-s5pv310/irq-combiner.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Based on arch/arm/common/gic.c
7 *
8 * IRQ COMBINER support
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13*/
14
15#include <linux/io.h>
16
17#include <asm/mach/irq.h>
18
19#define COMBINER_ENABLE_SET 0x0
20#define COMBINER_ENABLE_CLEAR 0x4
21#define COMBINER_INT_STATUS 0xC
22
23static DEFINE_SPINLOCK(irq_controller_lock);
24
25struct combiner_chip_data {
26 unsigned int irq_offset;
27 void __iomem *base;
28};
29
30static struct combiner_chip_data combiner_data[MAX_COMBINER_NR];
31
32static inline void __iomem *combiner_base(unsigned int irq)
33{
34 struct combiner_chip_data *combiner_data = get_irq_chip_data(irq);
35 return combiner_data->base;
36}
37
38static void combiner_mask_irq(unsigned int irq)
39{
40 u32 mask = 1 << (irq % 32);
41
42 __raw_writel(mask, combiner_base(irq) + COMBINER_ENABLE_CLEAR);
43}
44
45static void combiner_unmask_irq(unsigned int irq)
46{
47 u32 mask = 1 << (irq % 32);
48
49 __raw_writel(mask, combiner_base(irq) + COMBINER_ENABLE_SET);
50}
51
52static void combiner_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
53{
54 struct combiner_chip_data *chip_data = get_irq_data(irq);
55 struct irq_chip *chip = get_irq_chip(irq);
56 unsigned int cascade_irq, combiner_irq;
57 unsigned long status;
58
59 /* primary controller ack'ing */
60 chip->ack(irq);
61
62 spin_lock(&irq_controller_lock);
63 status = __raw_readl(chip_data->base + COMBINER_INT_STATUS);
64 spin_unlock(&irq_controller_lock);
65
66 if (status == 0)
67 goto out;
68
69 for (combiner_irq = 0; combiner_irq < 32; combiner_irq++) {
70 if (status & 0x1)
71 break;
72 status >>= 1;
73 }
74
75 cascade_irq = combiner_irq + (chip_data->irq_offset & ~31);
76 if (unlikely(cascade_irq >= NR_IRQS))
77 do_bad_IRQ(cascade_irq, desc);
78 else
79 generic_handle_irq(cascade_irq);
80
81 out:
82 /* primary controller unmasking */
83 chip->unmask(irq);
84}
85
86static struct irq_chip combiner_chip = {
87 .name = "COMBINER",
88 .mask = combiner_mask_irq,
89 .unmask = combiner_unmask_irq,
90};
91
92void __init combiner_cascade_irq(unsigned int combiner_nr, unsigned int irq)
93{
94 if (combiner_nr >= MAX_COMBINER_NR)
95 BUG();
96 if (set_irq_data(irq, &combiner_data[combiner_nr]) != 0)
97 BUG();
98 set_irq_chained_handler(irq, combiner_handle_cascade_irq);
99}
100
101void __init combiner_init(unsigned int combiner_nr, void __iomem *base,
102 unsigned int irq_start)
103{
104 unsigned int i;
105
106 if (combiner_nr >= MAX_COMBINER_NR)
107 BUG();
108
109 combiner_data[combiner_nr].base = base;
110 combiner_data[combiner_nr].irq_offset = irq_start;
111
112 /* Disable all interrupts */
113
114 __raw_writel(0xffffffff, base + COMBINER_ENABLE_CLEAR);
115
116 /* Setup the Linux IRQ subsystem */
117
118 for (i = irq_start; i < combiner_data[combiner_nr].irq_offset
119 + MAX_IRQ_IN_COMBINER; i++) {
120 set_irq_chip(i, &combiner_chip);
121 set_irq_chip_data(i, &combiner_data[combiner_nr]);
122 set_irq_handler(i, handle_level_irq);
123 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
124 }
125}
diff --git a/arch/arm/mach-s5pv310/localtimer.c b/arch/arm/mach-s5pv310/localtimer.c
new file mode 100644
index 000000000000..2784036cd8b1
--- /dev/null
+++ b/arch/arm/mach-s5pv310/localtimer.c
@@ -0,0 +1,25 @@
1/* linux/arch/arm/mach-s5pv310/localtimer.c
2 *
3 * Cloned from linux/arch/arm/mach-realview/localtimer.c
4 *
5 * Copyright (C) 2002 ARM Ltd.
6 * All Rights Reserved
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#include <linux/clockchips.h>
14
15#include <asm/irq.h>
16#include <asm/localtimer.h>
17
18/*
19 * Setup the local clock events for a CPU.
20 */
21void __cpuinit local_timer_setup(struct clock_event_device *evt)
22{
23 evt->irq = IRQ_LOCALTIMER;
24 twd_timer_setup(evt);
25}
diff --git a/arch/arm/mach-s5pv310/mach-smdkv310.c b/arch/arm/mach-s5pv310/mach-smdkv310.c
new file mode 100644
index 000000000000..0d6ab77709d2
--- /dev/null
+++ b/arch/arm/mach-s5pv310/mach-smdkv310.c
@@ -0,0 +1,92 @@
1/* linux/arch/arm/mach-s5pv310/mach-smdkv310.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.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#include <linux/serial_core.h>
12
13#include <asm/mach/arch.h>
14#include <asm/mach-types.h>
15#include <asm/hardware/cache-l2x0.h>
16
17#include <plat/regs-serial.h>
18#include <plat/s5pv310.h>
19#include <plat/cpu.h>
20
21#include <mach/map.h>
22
23/* Following are default values for UCON, ULCON and UFCON UART registers */
24#define SMDKV310_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \
25 S3C2410_UCON_RXILEVEL | \
26 S3C2410_UCON_TXIRQMODE | \
27 S3C2410_UCON_RXIRQMODE | \
28 S3C2410_UCON_RXFIFO_TOI | \
29 S3C2443_UCON_RXERR_IRQEN)
30
31#define SMDKV310_ULCON_DEFAULT S3C2410_LCON_CS8
32
33#define SMDKV310_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \
34 S5PV210_UFCON_TXTRIG4 | \
35 S5PV210_UFCON_RXTRIG4)
36
37static struct s3c2410_uartcfg smdkv310_uartcfgs[] __initdata = {
38 [0] = {
39 .hwport = 0,
40 .flags = 0,
41 .ucon = SMDKV310_UCON_DEFAULT,
42 .ulcon = SMDKV310_ULCON_DEFAULT,
43 .ufcon = SMDKV310_UFCON_DEFAULT,
44 },
45 [1] = {
46 .hwport = 1,
47 .flags = 0,
48 .ucon = SMDKV310_UCON_DEFAULT,
49 .ulcon = SMDKV310_ULCON_DEFAULT,
50 .ufcon = SMDKV310_UFCON_DEFAULT,
51 },
52 [2] = {
53 .hwport = 2,
54 .flags = 0,
55 .ucon = SMDKV310_UCON_DEFAULT,
56 .ulcon = SMDKV310_ULCON_DEFAULT,
57 .ufcon = SMDKV310_UFCON_DEFAULT,
58 },
59 [3] = {
60 .hwport = 3,
61 .flags = 0,
62 .ucon = SMDKV310_UCON_DEFAULT,
63 .ulcon = SMDKV310_ULCON_DEFAULT,
64 .ufcon = SMDKV310_UFCON_DEFAULT,
65 },
66};
67
68static void __init smdkv310_map_io(void)
69{
70 s5p_init_io(NULL, 0, S5P_VA_CHIPID);
71 s3c24xx_init_clocks(24000000);
72 s3c24xx_init_uarts(smdkv310_uartcfgs, ARRAY_SIZE(smdkv310_uartcfgs));
73}
74
75static void __init smdkv310_machine_init(void)
76{
77#ifdef CONFIG_CACHE_L2X0
78 l2x0_init(S5P_VA_L2CC, 1 << 28, 0xffffffff);
79#endif
80}
81
82MACHINE_START(SMDKV310, "SMDKV310")
83 /* Maintainer: Kukjin Kim <kgene.kim@samsung.com> */
84 /* Maintainer: Changhwan Youn <chaos.youn@samsung.com> */
85 .phys_io = S3C_PA_UART & 0xfff00000,
86 .io_pg_offst = (((u32)S3C_VA_UART) >> 18) & 0xfffc,
87 .boot_params = S5P_PA_SDRAM + 0x100,
88 .init_irq = s5pv310_init_irq,
89 .map_io = smdkv310_map_io,
90 .init_machine = smdkv310_machine_init,
91 .timer = &s5pv310_timer,
92MACHINE_END
diff --git a/arch/arm/mach-s5pv310/mach-universal_c210.c b/arch/arm/mach-s5pv310/mach-universal_c210.c
new file mode 100644
index 000000000000..2388cb947936
--- /dev/null
+++ b/arch/arm/mach-s5pv310/mach-universal_c210.c
@@ -0,0 +1,86 @@
1/* linux/arch/arm/mach-s5pv310/mach-universal_c210.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8*/
9
10#include <linux/serial_core.h>
11
12#include <asm/mach/arch.h>
13#include <asm/mach-types.h>
14#include <asm/hardware/cache-l2x0.h>
15
16#include <plat/regs-serial.h>
17#include <plat/s5pv310.h>
18#include <plat/cpu.h>
19
20#include <mach/map.h>
21
22/* Following are default values for UCON, ULCON and UFCON UART registers */
23#define UNIVERSAL_UCON_DEFAULT (S3C2410_UCON_TXILEVEL | \
24 S3C2410_UCON_RXILEVEL | \
25 S3C2410_UCON_TXIRQMODE | \
26 S3C2410_UCON_RXIRQMODE | \
27 S3C2410_UCON_RXFIFO_TOI | \
28 S3C2443_UCON_RXERR_IRQEN)
29
30#define UNIVERSAL_ULCON_DEFAULT S3C2410_LCON_CS8
31
32#define UNIVERSAL_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE | \
33 S5PV210_UFCON_TXTRIG256 | \
34 S5PV210_UFCON_RXTRIG256)
35
36static struct s3c2410_uartcfg universal_uartcfgs[] __initdata = {
37 [0] = {
38 .hwport = 0,
39 .ucon = UNIVERSAL_UCON_DEFAULT,
40 .ulcon = UNIVERSAL_ULCON_DEFAULT,
41 .ufcon = UNIVERSAL_UFCON_DEFAULT,
42 },
43 [1] = {
44 .hwport = 1,
45 .ucon = UNIVERSAL_UCON_DEFAULT,
46 .ulcon = UNIVERSAL_ULCON_DEFAULT,
47 .ufcon = UNIVERSAL_UFCON_DEFAULT,
48 },
49 [2] = {
50 .hwport = 2,
51 .ucon = UNIVERSAL_UCON_DEFAULT,
52 .ulcon = UNIVERSAL_ULCON_DEFAULT,
53 .ufcon = UNIVERSAL_UFCON_DEFAULT,
54 },
55 [3] = {
56 .hwport = 3,
57 .ucon = UNIVERSAL_UCON_DEFAULT,
58 .ulcon = UNIVERSAL_ULCON_DEFAULT,
59 .ufcon = UNIVERSAL_UFCON_DEFAULT,
60 },
61};
62
63static void __init universal_map_io(void)
64{
65 s5p_init_io(NULL, 0, S5P_VA_CHIPID);
66 s3c24xx_init_clocks(24000000);
67 s3c24xx_init_uarts(universal_uartcfgs, ARRAY_SIZE(universal_uartcfgs));
68}
69
70static void __init universal_machine_init(void)
71{
72#ifdef CONFIG_CACHE_L2X0
73 l2x0_init(S5P_VA_L2CC, 1 << 28, 0xffffffff);
74#endif
75}
76
77MACHINE_START(UNIVERSAL_C210, "UNIVERSAL_C210")
78 /* Maintainer: Kyungmin Park <kyungmin.park@samsung.com> */
79 .phys_io = S3C_PA_UART & 0xfff00000,
80 .io_pg_offst = (((u32)S3C_VA_UART) >> 18) & 0xfffc,
81 .boot_params = S5P_PA_SDRAM + 0x100,
82 .init_irq = s5pv310_init_irq,
83 .map_io = universal_map_io,
84 .init_machine = universal_machine_init,
85 .timer = &s5pv310_timer,
86MACHINE_END
diff --git a/arch/arm/mach-s5pv310/platsmp.c b/arch/arm/mach-s5pv310/platsmp.c
new file mode 100644
index 000000000000..fe9469abd006
--- /dev/null
+++ b/arch/arm/mach-s5pv310/platsmp.c
@@ -0,0 +1,192 @@
1/* linux/arch/arm/mach-s5pv310/platsmp.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * Cloned from linux/arch/arm/mach-vexpress/platsmp.c
7 *
8 * Copyright (C) 2002 ARM Ltd.
9 * All Rights Reserved
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14*/
15
16#include <linux/init.h>
17#include <linux/errno.h>
18#include <linux/delay.h>
19#include <linux/device.h>
20#include <linux/jiffies.h>
21#include <linux/smp.h>
22#include <linux/io.h>
23
24#include <asm/cacheflush.h>
25#include <asm/localtimer.h>
26#include <asm/smp_scu.h>
27#include <asm/unified.h>
28
29#include <mach/hardware.h>
30#include <mach/regs-clock.h>
31
32extern void s5pv310_secondary_startup(void);
33
34/*
35 * control for which core is the next to come out of the secondary
36 * boot "holding pen"
37 */
38
39volatile int __cpuinitdata pen_release = -1;
40
41static void __iomem *scu_base_addr(void)
42{
43 return (void __iomem *)(S5P_VA_SCU);
44}
45
46static DEFINE_SPINLOCK(boot_lock);
47
48void __cpuinit platform_secondary_init(unsigned int cpu)
49{
50 trace_hardirqs_off();
51
52 /*
53 * if any interrupts are already enabled for the primary
54 * core (e.g. timer irq), then they will not have been enabled
55 * for us: do so
56 */
57 gic_cpu_init(0, gic_cpu_base_addr);
58
59 /*
60 * let the primary processor know we're out of the
61 * pen, then head off into the C entry point
62 */
63 pen_release = -1;
64 smp_wmb();
65
66 /*
67 * Synchronise with the boot thread.
68 */
69 spin_lock(&boot_lock);
70 spin_unlock(&boot_lock);
71}
72
73int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
74{
75 unsigned long timeout;
76
77 /*
78 * Set synchronisation state between this boot processor
79 * and the secondary one
80 */
81 spin_lock(&boot_lock);
82
83 /*
84 * The secondary processor is waiting to be released from
85 * the holding pen - release it, then wait for it to flag
86 * that it has been released by resetting pen_release.
87 *
88 * Note that "pen_release" is the hardware CPU ID, whereas
89 * "cpu" is Linux's internal ID.
90 */
91 pen_release = cpu;
92 __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
93 outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
94
95 /*
96 * Send the secondary CPU a soft interrupt, thereby causing
97 * the boot monitor to read the system wide flags register,
98 * and branch to the address found there.
99 */
100 smp_cross_call(cpumask_of(cpu));
101
102 timeout = jiffies + (1 * HZ);
103 while (time_before(jiffies, timeout)) {
104 smp_rmb();
105 if (pen_release == -1)
106 break;
107
108 udelay(10);
109 }
110
111 /*
112 * now the secondary core is starting up let it run its
113 * calibrations, then wait for it to finish
114 */
115 spin_unlock(&boot_lock);
116
117 return pen_release != -1 ? -ENOSYS : 0;
118}
119
120/*
121 * Initialise the CPU possible map early - this describes the CPUs
122 * which may be present or become present in the system.
123 */
124
125void __init smp_init_cpus(void)
126{
127 void __iomem *scu_base = scu_base_addr();
128 unsigned int i, ncores;
129
130 ncores = scu_base ? scu_get_core_count(scu_base) : 1;
131
132 /* sanity check */
133 if (ncores == 0) {
134 printk(KERN_ERR
135 "S5PV310: strange CM count of 0? Default to 1\n");
136
137 ncores = 1;
138 }
139
140 if (ncores > NR_CPUS) {
141 printk(KERN_WARNING
142 "S5PV310: no. of cores (%d) greater than configured "
143 "maximum of %d - clipping\n",
144 ncores, NR_CPUS);
145 ncores = NR_CPUS;
146 }
147
148 for (i = 0; i < ncores; i++)
149 set_cpu_possible(i, true);
150}
151
152void __init smp_prepare_cpus(unsigned int max_cpus)
153{
154 unsigned int ncores = num_possible_cpus();
155 unsigned int cpu = smp_processor_id();
156 int i;
157
158 smp_store_cpu_info(cpu);
159
160 /* are we trying to boot more cores than exist? */
161 if (max_cpus > ncores)
162 max_cpus = ncores;
163
164 /*
165 * Initialise the present map, which describes the set of CPUs
166 * actually populated at the present time.
167 */
168 for (i = 0; i < max_cpus; i++)
169 set_cpu_present(i, true);
170
171 /*
172 * Initialise the SCU if there are more than one CPU and let
173 * them know where to start.
174 */
175 if (max_cpus > 1) {
176 /*
177 * Enable the local timer or broadcast device for the
178 * boot CPU, but only if we have more than one CPU.
179 */
180 percpu_timer_setup();
181
182 scu_enable(scu_base_addr());
183
184 /*
185 * Write the address of secondary startup into the
186 * system-wide flags register. The boot monitor waits
187 * until it receives a soft interrupt, and then the
188 * secondary CPU branches to this address.
189 */
190 __raw_writel(BSYM(virt_to_phys(s5pv310_secondary_startup)), S5P_INFORM0);
191 }
192}
diff --git a/arch/arm/mach-s5pv310/setup-i2c0.c b/arch/arm/mach-s5pv310/setup-i2c0.c
new file mode 100644
index 000000000000..436712807383
--- /dev/null
+++ b/arch/arm/mach-s5pv310/setup-i2c0.c
@@ -0,0 +1,28 @@
1/*
2 * linux/arch/arm/mach-s5pv310/setup-i2c0.c
3 *
4 * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * I2C0 GPIO configuration.
8 *
9 * Based on plat-s3c64xx/setup-i2c0.c
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14*/
15
16struct platform_device; /* don't need the contents */
17
18#include <linux/gpio.h>
19#include <plat/iic.h>
20#include <plat/gpio-cfg.h>
21
22void s3c_i2c0_cfg_gpio(struct platform_device *dev)
23{
24 s3c_gpio_cfgpin(S5PV310_GPD1(0), S3C_GPIO_SFN(2));
25 s3c_gpio_setpull(S5PV310_GPD1(0), S3C_GPIO_PULL_UP);
26 s3c_gpio_cfgpin(S5PV310_GPD1(1), S3C_GPIO_SFN(2));
27 s3c_gpio_setpull(S5PV310_GPD1(1), S3C_GPIO_PULL_UP);
28}
diff --git a/arch/arm/mach-s5pv310/setup-i2c1.c b/arch/arm/mach-s5pv310/setup-i2c1.c
new file mode 100644
index 000000000000..1ecd5bc35b5a
--- /dev/null
+++ b/arch/arm/mach-s5pv310/setup-i2c1.c
@@ -0,0 +1,25 @@
1/*
2 * linux/arch/arm/mach-s5pv310/setup-i2c1.c
3 *
4 * Copyright (C) 2010 Samsung Electronics Co., Ltd.
5 *
6 * I2C1 GPIO configuration.
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
13struct platform_device; /* don't need the contents */
14
15#include <linux/gpio.h>
16#include <plat/iic.h>
17#include <plat/gpio-cfg.h>
18
19void s3c_i2c1_cfg_gpio(struct platform_device *dev)
20{
21 s3c_gpio_cfgpin(S5PV310_GPD1(2), S3C_GPIO_SFN(2));
22 s3c_gpio_setpull(S5PV310_GPD1(2), S3C_GPIO_PULL_UP);
23 s3c_gpio_cfgpin(S5PV310_GPD1(3), S3C_GPIO_SFN(2));
24 s3c_gpio_setpull(S5PV310_GPD1(3), S3C_GPIO_PULL_UP);
25}
diff --git a/arch/arm/mach-s5pv310/setup-i2c2.c b/arch/arm/mach-s5pv310/setup-i2c2.c
new file mode 100644
index 000000000000..4c0d8def660a
--- /dev/null
+++ b/arch/arm/mach-s5pv310/setup-i2c2.c
@@ -0,0 +1,25 @@
1/*
2 * linux/arch/arm/mach-s5pv310/setup-i2c2.c
3 *
4 * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
5 *
6 * I2C2 GPIO configuration.
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
13struct platform_device; /* don't need the contents */
14
15#include <linux/gpio.h>
16#include <plat/iic.h>
17#include <plat/gpio-cfg.h>
18
19void s3c_i2c2_cfg_gpio(struct platform_device *dev)
20{
21 s3c_gpio_cfgpin(S5PV310_GPA0(6), S3C_GPIO_SFN(3));
22 s3c_gpio_setpull(S5PV310_GPA0(6), S3C_GPIO_PULL_UP);
23 s3c_gpio_cfgpin(S5PV310_GPA0(7), S3C_GPIO_SFN(3));
24 s3c_gpio_setpull(S5PV310_GPA0(7), S3C_GPIO_PULL_UP);
25}
diff --git a/arch/arm/mach-s5pv310/time.c b/arch/arm/mach-s5pv310/time.c
new file mode 100644
index 000000000000..01b012ad1bfd
--- /dev/null
+++ b/arch/arm/mach-s5pv310/time.c
@@ -0,0 +1,287 @@
1/* linux/arch/arm/mach-s5pv310/time.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * S5PV310 (and compatible) HRT support
7 * PWM 2/4 is used for this feature
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12*/
13
14#include <linux/sched.h>
15#include <linux/interrupt.h>
16#include <linux/irq.h>
17#include <linux/err.h>
18#include <linux/clk.h>
19#include <linux/clockchips.h>
20#include <linux/platform_device.h>
21
22#include <asm/smp_twd.h>
23
24#include <mach/map.h>
25#include <plat/regs-timer.h>
26#include <asm/mach/time.h>
27
28static unsigned long clock_count_per_tick;
29
30static struct clk *tin2;
31static struct clk *tin4;
32static struct clk *tdiv2;
33static struct clk *tdiv4;
34static struct clk *timerclk;
35
36static void s5pv310_pwm_stop(unsigned int pwm_id)
37{
38 unsigned long tcon;
39
40 tcon = __raw_readl(S3C2410_TCON);
41
42 switch (pwm_id) {
43 case 2:
44 tcon &= ~S3C2410_TCON_T2START;
45 break;
46 case 4:
47 tcon &= ~S3C2410_TCON_T4START;
48 break;
49 default:
50 break;
51 }
52 __raw_writel(tcon, S3C2410_TCON);
53}
54
55static void s5pv310_pwm_init(unsigned int pwm_id, unsigned long tcnt)
56{
57 unsigned long tcon;
58
59 tcon = __raw_readl(S3C2410_TCON);
60
61 /* timers reload after counting zero, so reduce the count by 1 */
62 tcnt--;
63
64 /* ensure timer is stopped... */
65 switch (pwm_id) {
66 case 2:
67 tcon &= ~(0xf<<12);
68 tcon |= S3C2410_TCON_T2MANUALUPD;
69
70 __raw_writel(tcnt, S3C2410_TCNTB(2));
71 __raw_writel(tcnt, S3C2410_TCMPB(2));
72 __raw_writel(tcon, S3C2410_TCON);
73
74 break;
75 case 4:
76 tcon &= ~(7<<20);
77 tcon |= S3C2410_TCON_T4MANUALUPD;
78
79 __raw_writel(tcnt, S3C2410_TCNTB(4));
80 __raw_writel(tcnt, S3C2410_TCMPB(4));
81 __raw_writel(tcon, S3C2410_TCON);
82
83 break;
84 default:
85 break;
86 }
87}
88
89static inline void s5pv310_pwm_start(unsigned int pwm_id, bool periodic)
90{
91 unsigned long tcon;
92
93 tcon = __raw_readl(S3C2410_TCON);
94
95 switch (pwm_id) {
96 case 2:
97 tcon |= S3C2410_TCON_T2START;
98 tcon &= ~S3C2410_TCON_T2MANUALUPD;
99
100 if (periodic)
101 tcon |= S3C2410_TCON_T2RELOAD;
102 else
103 tcon &= ~S3C2410_TCON_T2RELOAD;
104 break;
105 case 4:
106 tcon |= S3C2410_TCON_T4START;
107 tcon &= ~S3C2410_TCON_T4MANUALUPD;
108
109 if (periodic)
110 tcon |= S3C2410_TCON_T4RELOAD;
111 else
112 tcon &= ~S3C2410_TCON_T4RELOAD;
113 break;
114 default:
115 break;
116 }
117 __raw_writel(tcon, S3C2410_TCON);
118}
119
120static int s5pv310_pwm_set_next_event(unsigned long cycles,
121 struct clock_event_device *evt)
122{
123 s5pv310_pwm_init(2, cycles);
124 s5pv310_pwm_start(2, 0);
125 return 0;
126}
127
128static void s5pv310_pwm_set_mode(enum clock_event_mode mode,
129 struct clock_event_device *evt)
130{
131 s5pv310_pwm_stop(2);
132
133 switch (mode) {
134 case CLOCK_EVT_MODE_PERIODIC:
135 s5pv310_pwm_init(2, clock_count_per_tick);
136 s5pv310_pwm_start(2, 1);
137 break;
138 case CLOCK_EVT_MODE_ONESHOT:
139 break;
140 case CLOCK_EVT_MODE_UNUSED:
141 case CLOCK_EVT_MODE_SHUTDOWN:
142 case CLOCK_EVT_MODE_RESUME:
143 break;
144 }
145}
146
147static struct clock_event_device pwm_event_device = {
148 .name = "pwm_timer2",
149 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
150 .rating = 200,
151 .shift = 32,
152 .set_next_event = s5pv310_pwm_set_next_event,
153 .set_mode = s5pv310_pwm_set_mode,
154};
155
156irqreturn_t s5pv310_clock_event_isr(int irq, void *dev_id)
157{
158 struct clock_event_device *evt = &pwm_event_device;
159
160 evt->event_handler(evt);
161
162 return IRQ_HANDLED;
163}
164
165static struct irqaction s5pv310_clock_event_irq = {
166 .name = "pwm_timer2_irq",
167 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
168 .handler = s5pv310_clock_event_isr,
169};
170
171static void __init s5pv310_clockevent_init(void)
172{
173 unsigned long pclk;
174 unsigned long clock_rate;
175 struct clk *tscaler;
176
177 pclk = clk_get_rate(timerclk);
178
179 /* configure clock tick */
180
181 tscaler = clk_get_parent(tdiv2);
182
183 clk_set_rate(tscaler, pclk / 2);
184 clk_set_rate(tdiv2, pclk / 2);
185 clk_set_parent(tin2, tdiv2);
186
187 clock_rate = clk_get_rate(tin2);
188
189 clock_count_per_tick = clock_rate / HZ;
190
191 pwm_event_device.mult =
192 div_sc(clock_rate, NSEC_PER_SEC, pwm_event_device.shift);
193 pwm_event_device.max_delta_ns =
194 clockevent_delta2ns(-1, &pwm_event_device);
195 pwm_event_device.min_delta_ns =
196 clockevent_delta2ns(1, &pwm_event_device);
197
198 pwm_event_device.cpumask = cpumask_of(0);
199 clockevents_register_device(&pwm_event_device);
200
201 setup_irq(IRQ_TIMER2, &s5pv310_clock_event_irq);
202}
203
204static cycle_t s5pv310_pwm4_read(struct clocksource *cs)
205{
206 return (cycle_t) ~__raw_readl(S3C_TIMERREG(0x40));
207}
208
209struct clocksource pwm_clocksource = {
210 .name = "pwm_timer4",
211 .rating = 250,
212 .read = s5pv310_pwm4_read,
213 .mask = CLOCKSOURCE_MASK(32),
214 .shift = 20,
215 .flags = CLOCK_SOURCE_IS_CONTINUOUS ,
216};
217
218static void __init s5pv310_clocksource_init(void)
219{
220 unsigned long pclk;
221 unsigned long clock_rate;
222
223 pclk = clk_get_rate(timerclk);
224
225 clk_set_rate(tdiv4, pclk / 2);
226 clk_set_parent(tin4, tdiv4);
227
228 clock_rate = clk_get_rate(tin4);
229
230 s5pv310_pwm_init(4, ~0);
231 s5pv310_pwm_start(4, 1);
232
233 pwm_clocksource.mult =
234 clocksource_khz2mult(clock_rate/1000, pwm_clocksource.shift);
235
236 if (clocksource_register(&pwm_clocksource))
237 panic("%s: can't register clocksource\n", pwm_clocksource.name);
238}
239
240static void __init s5pv310_timer_resources(void)
241{
242 struct platform_device tmpdev;
243
244 tmpdev.dev.bus = &platform_bus_type;
245
246 timerclk = clk_get(NULL, "timers");
247 if (IS_ERR(timerclk))
248 panic("failed to get timers clock for system timer");
249
250 clk_enable(timerclk);
251
252 tmpdev.id = 2;
253 tin2 = clk_get(&tmpdev.dev, "pwm-tin");
254 if (IS_ERR(tin2))
255 panic("failed to get pwm-tin2 clock for system timer");
256
257 tdiv2 = clk_get(&tmpdev.dev, "pwm-tdiv");
258 if (IS_ERR(tdiv2))
259 panic("failed to get pwm-tdiv2 clock for system timer");
260 clk_enable(tin2);
261
262 tmpdev.id = 4;
263 tin4 = clk_get(&tmpdev.dev, "pwm-tin");
264 if (IS_ERR(tin4))
265 panic("failed to get pwm-tin4 clock for system timer");
266
267 tdiv4 = clk_get(&tmpdev.dev, "pwm-tdiv");
268 if (IS_ERR(tdiv4))
269 panic("failed to get pwm-tdiv4 clock for system timer");
270
271 clk_enable(tin4);
272}
273
274static void __init s5pv310_timer_init(void)
275{
276#ifdef CONFIG_LOCAL_TIMERS
277 twd_base = S5P_VA_TWD;
278#endif
279
280 s5pv310_timer_resources();
281 s5pv310_clockevent_init();
282 s5pv310_clocksource_init();
283}
284
285struct sys_timer s5pv310_timer = {
286 .init = s5pv310_timer_init,
287};
diff --git a/arch/arm/mach-sa1100/include/mach/irqs.h b/arch/arm/mach-sa1100/include/mach/irqs.h
index 8c8845b5ae5b..d18f21abef80 100644
--- a/arch/arm/mach-sa1100/include/mach/irqs.h
+++ b/arch/arm/mach-sa1100/include/mach/irqs.h
@@ -77,7 +77,7 @@
77 */ 77 */
78#ifdef CONFIG_SA1111 78#ifdef CONFIG_SA1111
79#define NR_IRQS (IRQ_BOARD_END + 55) 79#define NR_IRQS (IRQ_BOARD_END + 55)
80#elif defined(CONFIG_SHARPSL_LOCOMO) 80#elif defined(CONFIG_SHARP_LOCOMO)
81#define NR_IRQS (IRQ_BOARD_START + 4) 81#define NR_IRQS (IRQ_BOARD_START + 4)
82#else 82#else
83#define NR_IRQS (IRQ_BOARD_START) 83#define NR_IRQS (IRQ_BOARD_START)
diff --git a/arch/arm/mach-shmobile/Kconfig b/arch/arm/mach-shmobile/Kconfig
index 4c704b4e8b34..54b479c35ee0 100644
--- a/arch/arm/mach-shmobile/Kconfig
+++ b/arch/arm/mach-shmobile/Kconfig
@@ -7,6 +7,7 @@ config ARCH_SH7367
7 select CPU_V6 7 select CPU_V6
8 select HAVE_CLK 8 select HAVE_CLK
9 select COMMON_CLKDEV 9 select COMMON_CLKDEV
10 select SH_CLK_CPG
10 select GENERIC_CLOCKEVENTS 11 select GENERIC_CLOCKEVENTS
11 12
12config ARCH_SH7377 13config ARCH_SH7377
@@ -14,6 +15,7 @@ config ARCH_SH7377
14 select CPU_V7 15 select CPU_V7
15 select HAVE_CLK 16 select HAVE_CLK
16 select COMMON_CLKDEV 17 select COMMON_CLKDEV
18 select SH_CLK_CPG
17 select GENERIC_CLOCKEVENTS 19 select GENERIC_CLOCKEVENTS
18 20
19config ARCH_SH7372 21config ARCH_SH7372
@@ -21,6 +23,7 @@ config ARCH_SH7372
21 select CPU_V7 23 select CPU_V7
22 select HAVE_CLK 24 select HAVE_CLK
23 select COMMON_CLKDEV 25 select COMMON_CLKDEV
26 select SH_CLK_CPG
24 select GENERIC_CLOCKEVENTS 27 select GENERIC_CLOCKEVENTS
25 28
26comment "SH-Mobile Board Type" 29comment "SH-Mobile Board Type"
@@ -39,6 +42,20 @@ config MACH_AP4EVB
39 bool "AP4EVB board" 42 bool "AP4EVB board"
40 depends on ARCH_SH7372 43 depends on ARCH_SH7372
41 select ARCH_REQUIRE_GPIOLIB 44 select ARCH_REQUIRE_GPIOLIB
45 select SH_LCD_MIPI_DSI
46
47choice
48 prompt "AP4EVB LCD panel selection"
49 default AP4EVB_QHD
50 depends on MACH_AP4EVB
51
52config AP4EVB_QHD
53 bool "MIPI-DSI QHD (960x540)"
54
55config AP4EVB_WVGA
56 bool "Parallel WVGA (800x480)"
57
58endchoice
42 59
43comment "SH-Mobile System Configuration" 60comment "SH-Mobile System Configuration"
44 61
@@ -88,6 +105,15 @@ config SH_TIMER_CMT
88 help 105 help
89 This enables build of the CMT timer driver. 106 This enables build of the CMT timer driver.
90 107
108config SH_TIMER_TMU
109 bool "TMU timer driver"
110 default y
111 help
112 This enables build of the TMU timer driver.
113
91endmenu 114endmenu
92 115
116config SH_CLK_CPG
117 bool
118
93endif 119endif
diff --git a/arch/arm/mach-shmobile/Makefile b/arch/arm/mach-shmobile/Makefile
index 6d385d371c33..5e16b4c69222 100644
--- a/arch/arm/mach-shmobile/Makefile
+++ b/arch/arm/mach-shmobile/Makefile
@@ -3,12 +3,12 @@
3# 3#
4 4
5# Common objects 5# Common objects
6obj-y := timer.o console.o 6obj-y := timer.o console.o clock.o
7 7
8# CPU objects 8# CPU objects
9obj-$(CONFIG_ARCH_SH7367) += setup-sh7367.o clock-sh7367.o intc-sh7367.o 9obj-$(CONFIG_ARCH_SH7367) += setup-sh7367.o clock-sh7367.o intc-sh7367.o
10obj-$(CONFIG_ARCH_SH7377) += setup-sh7377.o clock-sh7367.o intc-sh7377.o 10obj-$(CONFIG_ARCH_SH7377) += setup-sh7377.o clock-sh7377.o intc-sh7377.o
11obj-$(CONFIG_ARCH_SH7372) += setup-sh7372.o clock-sh7367.o intc-sh7372.o 11obj-$(CONFIG_ARCH_SH7372) += setup-sh7372.o clock-sh7372.o intc-sh7372.o
12 12
13# Pinmux setup 13# Pinmux setup
14pfc-$(CONFIG_ARCH_SH7367) := pfc-sh7367.o 14pfc-$(CONFIG_ARCH_SH7367) := pfc-sh7367.o
diff --git a/arch/arm/mach-shmobile/board-ap4evb.c b/arch/arm/mach-shmobile/board-ap4evb.c
index 1c2ec96ce261..23d472f9525e 100644
--- a/arch/arm/mach-shmobile/board-ap4evb.c
+++ b/arch/arm/mach-shmobile/board-ap4evb.c
@@ -17,25 +17,45 @@
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 19 */
20#include <linux/clk.h>
20#include <linux/kernel.h> 21#include <linux/kernel.h>
21#include <linux/init.h> 22#include <linux/init.h>
22#include <linux/interrupt.h> 23#include <linux/interrupt.h>
23#include <linux/irq.h> 24#include <linux/irq.h>
24#include <linux/platform_device.h> 25#include <linux/platform_device.h>
25#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/mfd/sh_mobile_sdhi.h>
28#include <linux/mmc/host.h>
26#include <linux/mtd/mtd.h> 29#include <linux/mtd/mtd.h>
27#include <linux/mtd/partitions.h> 30#include <linux/mtd/partitions.h>
28#include <linux/mtd/physmap.h> 31#include <linux/mtd/physmap.h>
32#include <linux/mmc/host.h>
33#include <linux/mmc/sh_mmcif.h>
34#include <linux/i2c.h>
35#include <linux/i2c/tsc2007.h>
29#include <linux/io.h> 36#include <linux/io.h>
30#include <linux/smsc911x.h> 37#include <linux/smsc911x.h>
38#include <linux/sh_intc.h>
39#include <linux/sh_clk.h>
31#include <linux/gpio.h> 40#include <linux/gpio.h>
32#include <linux/input.h> 41#include <linux/input.h>
33#include <linux/input/sh_keysc.h> 42#include <linux/input/sh_keysc.h>
43#include <linux/usb/r8a66597.h>
44
45#include <sound/sh_fsi.h>
46
47#include <video/sh_mobile_hdmi.h>
48#include <video/sh_mobile_lcdc.h>
49#include <video/sh_mipi_dsi.h>
50
34#include <mach/common.h> 51#include <mach/common.h>
52#include <mach/irqs.h>
35#include <mach/sh7372.h> 53#include <mach/sh7372.h>
54
36#include <asm/mach-types.h> 55#include <asm/mach-types.h>
37#include <asm/mach/arch.h> 56#include <asm/mach/arch.h>
38#include <asm/mach/map.h> 57#include <asm/mach/map.h>
58#include <asm/mach/time.h>
39 59
40/* 60/*
41 * Address Interface BusWidth note 61 * Address Interface BusWidth note
@@ -80,12 +100,56 @@
80 */ 100 */
81 101
82/* 102/*
83 * KEYSC 103 * LCD / IRQ / KEYSC / IrDA
104 *
105 * IRQ = IRQ26 (TS), IRQ27 (VIO), IRQ28 (QHD-TouchScreen)
106 * LCD = 2nd LCDC (WVGA)
84 * 107 *
85 * SW43 KEYSC 108 * | SW43 |
86 * ------------------------- 109 * SW3 | ON | OFF |
87 * ON enable 110 * -------------+-----------------------+---------------+
88 * OFF disable 111 * ON | KEY / IrDA | LCD |
112 * OFF | KEY / IrDA / IRQ | IRQ |
113 *
114 *
115 * QHD / WVGA display
116 *
117 * You can choice display type on menuconfig.
118 * Then, check above dip-switch.
119 */
120
121/*
122 * USB
123 *
124 * J7 : 1-2 MAX3355E VBUS
125 * 2-3 DC 5.0V
126 *
127 * S39: bit2: off
128 */
129
130/*
131 * FSI/FSMI
132 *
133 * SW41 : ON : SH-Mobile AP4 Audio Mode
134 * : OFF : Bluetooth Audio Mode
135 */
136
137/*
138 * MMC0/SDHI1 (CN7)
139 *
140 * J22 : select card voltage
141 * 1-2 pin : 1.8v
142 * 2-3 pin : 3.3v
143 *
144 * SW1 | SW33
145 * | bit1 | bit2 | bit3 | bit4
146 * ------------+------+------+------+-------
147 * MMC0 OFF | OFF | ON | ON | X
148 * SDHI1 OFF | ON | X | OFF | ON
149 *
150 * voltage lebel
151 * CN7 : 1.8v
152 * CN12: 3.3v
89 */ 153 */
90 154
91/* MTD */ 155/* MTD */
@@ -148,7 +212,7 @@ static struct resource smc911x_resources[] = {
148 .end = 0x16000000 - 1, 212 .end = 0x16000000 - 1,
149 .flags = IORESOURCE_MEM, 213 .flags = IORESOURCE_MEM,
150 }, { 214 }, {
151 .start = 6, 215 .start = evt2irq(0x02c0) /* IRQ6A */,
152 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL, 216 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
153 }, 217 },
154}; 218};
@@ -169,6 +233,180 @@ static struct platform_device smc911x_device = {
169 }, 233 },
170}; 234};
171 235
236/* SH_MMCIF */
237static struct resource sh_mmcif_resources[] = {
238 [0] = {
239 .name = "SH_MMCIF",
240 .start = 0xE6BD0000,
241 .end = 0xE6BD00FF,
242 .flags = IORESOURCE_MEM,
243 },
244 [1] = {
245 /* MMC ERR */
246 .start = evt2irq(0x1ac0),
247 .flags = IORESOURCE_IRQ,
248 },
249 [2] = {
250 /* MMC NOR */
251 .start = evt2irq(0x1ae0),
252 .flags = IORESOURCE_IRQ,
253 },
254};
255
256static struct sh_mmcif_plat_data sh_mmcif_plat = {
257 .sup_pclk = 0,
258 .ocr = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
259 .caps = MMC_CAP_4_BIT_DATA |
260 MMC_CAP_8_BIT_DATA |
261 MMC_CAP_NEEDS_POLL,
262};
263
264static struct platform_device sh_mmcif_device = {
265 .name = "sh_mmcif",
266 .id = 0,
267 .dev = {
268 .dma_mask = NULL,
269 .coherent_dma_mask = 0xffffffff,
270 .platform_data = &sh_mmcif_plat,
271 },
272 .num_resources = ARRAY_SIZE(sh_mmcif_resources),
273 .resource = sh_mmcif_resources,
274};
275
276/* SDHI0 */
277static struct sh_mobile_sdhi_info sdhi0_info = {
278 .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
279 .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
280};
281
282static struct resource sdhi0_resources[] = {
283 [0] = {
284 .name = "SDHI0",
285 .start = 0xe6850000,
286 .end = 0xe68501ff,
287 .flags = IORESOURCE_MEM,
288 },
289 [1] = {
290 .start = evt2irq(0x0e00) /* SDHI0 */,
291 .flags = IORESOURCE_IRQ,
292 },
293};
294
295static struct platform_device sdhi0_device = {
296 .name = "sh_mobile_sdhi",
297 .num_resources = ARRAY_SIZE(sdhi0_resources),
298 .resource = sdhi0_resources,
299 .id = 0,
300 .dev = {
301 .platform_data = &sdhi0_info,
302 },
303};
304
305/* SDHI1 */
306static struct sh_mobile_sdhi_info sdhi1_info = {
307 .dma_slave_tx = SHDMA_SLAVE_SDHI1_TX,
308 .dma_slave_rx = SHDMA_SLAVE_SDHI1_RX,
309 .tmio_ocr_mask = MMC_VDD_165_195,
310};
311
312static struct resource sdhi1_resources[] = {
313 [0] = {
314 .name = "SDHI1",
315 .start = 0xe6860000,
316 .end = 0xe68601ff,
317 .flags = IORESOURCE_MEM,
318 },
319 [1] = {
320 .start = evt2irq(0x0e80),
321 .flags = IORESOURCE_IRQ,
322 },
323};
324
325static struct platform_device sdhi1_device = {
326 .name = "sh_mobile_sdhi",
327 .num_resources = ARRAY_SIZE(sdhi1_resources),
328 .resource = sdhi1_resources,
329 .id = 1,
330 .dev = {
331 .platform_data = &sdhi1_info,
332 },
333};
334
335/* USB1 */
336static void usb1_host_port_power(int port, int power)
337{
338 if (!power) /* only power-on supported for now */
339 return;
340
341 /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
342 __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
343}
344
345static struct r8a66597_platdata usb1_host_data = {
346 .on_chip = 1,
347 .port_power = usb1_host_port_power,
348};
349
350static struct resource usb1_host_resources[] = {
351 [0] = {
352 .name = "USBHS",
353 .start = 0xE68B0000,
354 .end = 0xE68B00E6 - 1,
355 .flags = IORESOURCE_MEM,
356 },
357 [1] = {
358 .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
359 .flags = IORESOURCE_IRQ,
360 },
361};
362
363static struct platform_device usb1_host_device = {
364 .name = "r8a66597_hcd",
365 .id = 1,
366 .dev = {
367 .dma_mask = NULL, /* not use dma */
368 .coherent_dma_mask = 0xffffffff,
369 .platform_data = &usb1_host_data,
370 },
371 .num_resources = ARRAY_SIZE(usb1_host_resources),
372 .resource = usb1_host_resources,
373};
374
375static struct sh_mobile_lcdc_info lcdc_info = {
376 .ch[0] = {
377 .chan = LCDC_CHAN_MAINLCD,
378 .bpp = 16,
379 }
380};
381
382static struct resource lcdc_resources[] = {
383 [0] = {
384 .name = "LCDC",
385 .start = 0xfe940000, /* P4-only space */
386 .end = 0xfe943fff,
387 .flags = IORESOURCE_MEM,
388 },
389 [1] = {
390 .start = intcs_evt2irq(0x580),
391 .flags = IORESOURCE_IRQ,
392 },
393};
394
395static struct platform_device lcdc_device = {
396 .name = "sh_mobile_lcdc_fb",
397 .num_resources = ARRAY_SIZE(lcdc_resources),
398 .resource = lcdc_resources,
399 .dev = {
400 .platform_data = &lcdc_info,
401 .coherent_dma_mask = ~0,
402 },
403};
404
405/*
406 * QHD display
407 */
408#ifdef CONFIG_AP4EVB_QHD
409
172/* KEYSC (Needs SW43 set to ON) */ 410/* KEYSC (Needs SW43 set to ON) */
173static struct sh_keysc_info keysc_info = { 411static struct sh_keysc_info keysc_info = {
174 .mode = SH_KEYSC_MODE_1, 412 .mode = SH_KEYSC_MODE_1,
@@ -191,7 +429,7 @@ static struct resource keysc_resources[] = {
191 .flags = IORESOURCE_MEM, 429 .flags = IORESOURCE_MEM,
192 }, 430 },
193 [1] = { 431 [1] = {
194 .start = 79, 432 .start = evt2irq(0x0be0), /* KEYSC_KEY */
195 .flags = IORESOURCE_IRQ, 433 .flags = IORESOURCE_IRQ,
196 }, 434 },
197}; 435};
@@ -206,32 +444,362 @@ static struct platform_device keysc_device = {
206 }, 444 },
207}; 445};
208 446
209/* SDHI0 */ 447/* MIPI-DSI */
210static struct resource sdhi0_resources[] = { 448static struct resource mipidsi0_resources[] = {
211 [0] = { 449 [0] = {
212 .name = "SDHI0", 450 .start = 0xffc60000,
213 .start = 0xe6850000, 451 .end = 0xffc68fff,
214 .end = 0xe68501ff,
215 .flags = IORESOURCE_MEM, 452 .flags = IORESOURCE_MEM,
216 }, 453 },
454};
455
456static struct sh_mipi_dsi_info mipidsi0_info = {
457 .data_format = MIPI_RGB888,
458 .lcd_chan = &lcdc_info.ch[0],
459};
460
461static struct platform_device mipidsi0_device = {
462 .name = "sh-mipi-dsi",
463 .num_resources = ARRAY_SIZE(mipidsi0_resources),
464 .resource = mipidsi0_resources,
465 .id = 0,
466 .dev = {
467 .platform_data = &mipidsi0_info,
468 },
469};
470
471/* This function will disappear when we switch to (runtime) PM */
472static int __init ap4evb_init_display_clk(void)
473{
474 struct clk *lcdc_clk;
475 struct clk *dsitx_clk;
476 int ret;
477
478 lcdc_clk = clk_get(&lcdc_device.dev, "sh_mobile_lcdc_fb.0");
479 if (IS_ERR(lcdc_clk))
480 return PTR_ERR(lcdc_clk);
481
482 dsitx_clk = clk_get(&mipidsi0_device.dev, "sh-mipi-dsi.0");
483 if (IS_ERR(dsitx_clk)) {
484 ret = PTR_ERR(dsitx_clk);
485 goto eclkdsitxget;
486 }
487
488 ret = clk_enable(lcdc_clk);
489 if (ret < 0)
490 goto eclklcdcon;
491
492 ret = clk_enable(dsitx_clk);
493 if (ret < 0)
494 goto eclkdsitxon;
495
496 return 0;
497
498eclkdsitxon:
499 clk_disable(lcdc_clk);
500eclklcdcon:
501 clk_put(dsitx_clk);
502eclkdsitxget:
503 clk_put(lcdc_clk);
504
505 return ret;
506}
507device_initcall(ap4evb_init_display_clk);
508
509static struct platform_device *qhd_devices[] __initdata = {
510 &mipidsi0_device,
511 &keysc_device,
512};
513#endif /* CONFIG_AP4EVB_QHD */
514
515/* FSI */
516#define IRQ_FSI evt2irq(0x1840)
517#define FSIACKCR 0xE6150018
518static void fsiackcr_init(struct clk *clk)
519{
520 u32 status = __raw_readl(clk->enable_reg);
521
522 /* use external clock */
523 status &= ~0x000000ff;
524 status |= 0x00000080;
525 __raw_writel(status, clk->enable_reg);
526}
527
528static struct clk_ops fsiackcr_clk_ops = {
529 .init = fsiackcr_init,
530};
531
532static struct clk fsiackcr_clk = {
533 .ops = &fsiackcr_clk_ops,
534 .enable_reg = (void __iomem *)FSIACKCR,
535 .rate = 0, /* unknown */
536};
537
538static struct sh_fsi_platform_info fsi_info = {
539 .porta_flags = SH_FSI_BRS_INV |
540 SH_FSI_OUT_SLAVE_MODE |
541 SH_FSI_IN_SLAVE_MODE |
542 SH_FSI_OFMT(PCM) |
543 SH_FSI_IFMT(PCM),
544};
545
546static struct resource fsi_resources[] = {
547 [0] = {
548 .name = "FSI",
549 .start = 0xFE3C0000,
550 .end = 0xFE3C0400 - 1,
551 .flags = IORESOURCE_MEM,
552 },
217 [1] = { 553 [1] = {
218 .start = 96, 554 .start = IRQ_FSI,
219 .flags = IORESOURCE_IRQ, 555 .flags = IORESOURCE_IRQ,
220 }, 556 },
221}; 557};
222 558
223static struct platform_device sdhi0_device = { 559static struct platform_device fsi_device = {
224 .name = "sh_mobile_sdhi", 560 .name = "sh_fsi2",
225 .num_resources = ARRAY_SIZE(sdhi0_resources), 561 .id = 0,
226 .resource = sdhi0_resources, 562 .num_resources = ARRAY_SIZE(fsi_resources),
227 .id = 0, 563 .resource = fsi_resources,
564 .dev = {
565 .platform_data = &fsi_info,
566 },
567};
568
569static struct sh_mobile_lcdc_info sh_mobile_lcdc1_info = {
570 .clock_source = LCDC_CLK_EXTERNAL,
571 .ch[0] = {
572 .chan = LCDC_CHAN_MAINLCD,
573 .bpp = 16,
574 .interface_type = RGB24,
575 .clock_divider = 1,
576 .flags = LCDC_FLAGS_DWPOL,
577 .lcd_cfg = {
578 .name = "HDMI",
579 /* So far only 720p is supported */
580 .xres = 1280,
581 .yres = 720,
582 /*
583 * If left and right margins are not multiples of 8,
584 * LDHAJR will be adjusted accordingly by the LCDC
585 * driver. Until we start using EDID, these values
586 * might have to be adjusted for different monitors.
587 */
588 .left_margin = 200,
589 .right_margin = 88,
590 .hsync_len = 48,
591 .upper_margin = 20,
592 .lower_margin = 5,
593 .vsync_len = 5,
594 .pixclock = 13468,
595 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
596 },
597 }
598};
599
600static struct resource lcdc1_resources[] = {
601 [0] = {
602 .name = "LCDC1",
603 .start = 0xfe944000,
604 .end = 0xfe947fff,
605 .flags = IORESOURCE_MEM,
606 },
607 [1] = {
608 .start = intcs_evt2irq(0x17a0),
609 .flags = IORESOURCE_IRQ,
610 },
611};
612
613static struct platform_device lcdc1_device = {
614 .name = "sh_mobile_lcdc_fb",
615 .num_resources = ARRAY_SIZE(lcdc1_resources),
616 .resource = lcdc1_resources,
617 .id = 1,
618 .dev = {
619 .platform_data = &sh_mobile_lcdc1_info,
620 .coherent_dma_mask = ~0,
621 },
622};
623
624static struct sh_mobile_hdmi_info hdmi_info = {
625 .lcd_chan = &sh_mobile_lcdc1_info.ch[0],
626 .lcd_dev = &lcdc1_device.dev,
627};
628
629static struct resource hdmi_resources[] = {
630 [0] = {
631 .name = "HDMI",
632 .start = 0xe6be0000,
633 .end = 0xe6be00ff,
634 .flags = IORESOURCE_MEM,
635 },
636 [1] = {
637 /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
638 .start = evt2irq(0x17e0),
639 .flags = IORESOURCE_IRQ,
640 },
641};
642
643static struct platform_device hdmi_device = {
644 .name = "sh-mobile-hdmi",
645 .num_resources = ARRAY_SIZE(hdmi_resources),
646 .resource = hdmi_resources,
647 .id = -1,
648 .dev = {
649 .platform_data = &hdmi_info,
650 },
228}; 651};
229 652
230static struct platform_device *ap4evb_devices[] __initdata = { 653static struct platform_device *ap4evb_devices[] __initdata = {
231 &nor_flash_device, 654 &nor_flash_device,
232 &smc911x_device, 655 &smc911x_device,
233 &keysc_device,
234 &sdhi0_device, 656 &sdhi0_device,
657 &sdhi1_device,
658 &usb1_host_device,
659 &fsi_device,
660 &sh_mmcif_device,
661 &lcdc1_device,
662 &lcdc_device,
663 &hdmi_device,
664};
665
666static int __init hdmi_init_pm_clock(void)
667{
668 struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
669 int ret;
670 long rate;
671
672 if (IS_ERR(hdmi_ick)) {
673 ret = PTR_ERR(hdmi_ick);
674 pr_err("Cannot get HDMI ICK: %d\n", ret);
675 goto out;
676 }
677
678 ret = clk_set_parent(&pllc2_clk, &dv_clki_div2_clk);
679 if (ret < 0) {
680 pr_err("Cannot set PLLC2 parent: %d, %d users\n", ret, pllc2_clk.usecount);
681 goto out;
682 }
683
684 pr_debug("PLLC2 initial frequency %lu\n", clk_get_rate(&pllc2_clk));
685
686 rate = clk_round_rate(&pllc2_clk, 594000000);
687 if (rate < 0) {
688 pr_err("Cannot get suitable rate: %ld\n", rate);
689 ret = rate;
690 goto out;
691 }
692
693 ret = clk_set_rate(&pllc2_clk, rate);
694 if (ret < 0) {
695 pr_err("Cannot set rate %ld: %d\n", rate, ret);
696 goto out;
697 }
698
699 pr_debug("PLLC2 set frequency %lu\n", rate);
700
701 ret = clk_set_parent(hdmi_ick, &pllc2_clk);
702 if (ret < 0) {
703 pr_err("Cannot set HDMI parent: %d\n", ret);
704 goto out;
705 }
706
707out:
708 if (!IS_ERR(hdmi_ick))
709 clk_put(hdmi_ick);
710 return ret;
711}
712
713device_initcall(hdmi_init_pm_clock);
714
715/*
716 * FIXME !!
717 *
718 * gpio_no_direction
719 * gpio_pull_up
720 * are quick_hack.
721 *
722 * current gpio frame work doesn't have
723 * the method to control only pull up/down/free.
724 * this function should be replaced by correct gpio function
725 */
726static void __init gpio_no_direction(u32 addr)
727{
728 __raw_writeb(0x00, addr);
729}
730
731static void __init gpio_pull_up(u32 addr)
732{
733 u8 data = __raw_readb(addr);
734
735 data &= 0x0F;
736 data |= 0xC0;
737 __raw_writeb(data, addr);
738}
739
740/* TouchScreen */
741#define IRQ28 evt2irq(0x3380) /* IRQ28A */
742#define IRQ7 evt2irq(0x02e0) /* IRQ7A */
743static int ts_get_pendown_state(void)
744{
745 int val1, val2;
746
747 gpio_free(GPIO_FN_IRQ28_123);
748 gpio_free(GPIO_FN_IRQ7_40);
749
750 gpio_request(GPIO_PORT123, NULL);
751 gpio_request(GPIO_PORT40, NULL);
752
753 gpio_direction_input(GPIO_PORT123);
754 gpio_direction_input(GPIO_PORT40);
755
756 val1 = gpio_get_value(GPIO_PORT123);
757 val2 = gpio_get_value(GPIO_PORT40);
758
759 gpio_request(GPIO_FN_IRQ28_123, NULL); /* for QHD */
760 gpio_request(GPIO_FN_IRQ7_40, NULL); /* for WVGA */
761
762 return val1 ^ val2;
763}
764
765#define PORT40CR 0xE6051028
766#define PORT123CR 0xE605007B
767static int ts_init(void)
768{
769 gpio_request(GPIO_FN_IRQ28_123, NULL); /* for QHD */
770 gpio_request(GPIO_FN_IRQ7_40, NULL); /* for WVGA */
771
772 gpio_pull_up(PORT40CR);
773 gpio_pull_up(PORT123CR);
774
775 return 0;
776}
777
778static struct tsc2007_platform_data tsc2007_info = {
779 .model = 2007,
780 .x_plate_ohms = 180,
781 .get_pendown_state = ts_get_pendown_state,
782 .init_platform_hw = ts_init,
783};
784
785static struct i2c_board_info tsc_device = {
786 I2C_BOARD_INFO("tsc2007", 0x48),
787 .type = "tsc2007",
788 .platform_data = &tsc2007_info,
789 /*.irq is selected on ap4evb_init */
790};
791
792/* I2C */
793static struct i2c_board_info i2c0_devices[] = {
794 {
795 I2C_BOARD_INFO("ak4643", 0x13),
796 },
797};
798
799static struct i2c_board_info i2c1_devices[] = {
800 {
801 I2C_BOARD_INFO("r2025sd", 0x32),
802 },
235}; 803};
236 804
237static struct map_desc ap4evb_io_desc[] __initdata = { 805static struct map_desc ap4evb_io_desc[] __initdata = {
@@ -250,14 +818,18 @@ static void __init ap4evb_map_io(void)
250{ 818{
251 iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc)); 819 iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc));
252 820
253 /* setup early devices, clocks and console here as well */ 821 /* setup early devices and console here as well */
254 sh7372_add_early_devices(); 822 sh7372_add_early_devices();
255 sh7367_clock_init(); /* use g3 clocks for now */
256 shmobile_setup_console(); 823 shmobile_setup_console();
257} 824}
258 825
826#define GPIO_PORT9CR 0xE6051009
827#define GPIO_PORT10CR 0xE605100A
259static void __init ap4evb_init(void) 828static void __init ap4evb_init(void)
260{ 829{
830 u32 srcr4;
831 struct clk *clk;
832
261 sh7372_pinmux_init(); 833 sh7372_pinmux_init();
262 834
263 /* enable SCIFA0 */ 835 /* enable SCIFA0 */
@@ -296,6 +868,93 @@ static void __init ap4evb_init(void)
296 gpio_export(GPIO_PORT34, 0); 868 gpio_export(GPIO_PORT34, 0);
297 gpio_export(GPIO_PORT35, 0); 869 gpio_export(GPIO_PORT35, 0);
298 870
871 /* SDHI0 */
872 gpio_request(GPIO_FN_SDHICD0, NULL);
873 gpio_request(GPIO_FN_SDHIWP0, NULL);
874 gpio_request(GPIO_FN_SDHICMD0, NULL);
875 gpio_request(GPIO_FN_SDHICLK0, NULL);
876 gpio_request(GPIO_FN_SDHID0_3, NULL);
877 gpio_request(GPIO_FN_SDHID0_2, NULL);
878 gpio_request(GPIO_FN_SDHID0_1, NULL);
879 gpio_request(GPIO_FN_SDHID0_0, NULL);
880
881 /* SDHI1 */
882 gpio_request(GPIO_FN_SDHICMD1, NULL);
883 gpio_request(GPIO_FN_SDHICLK1, NULL);
884 gpio_request(GPIO_FN_SDHID1_3, NULL);
885 gpio_request(GPIO_FN_SDHID1_2, NULL);
886 gpio_request(GPIO_FN_SDHID1_1, NULL);
887 gpio_request(GPIO_FN_SDHID1_0, NULL);
888
889 /* MMCIF */
890 gpio_request(GPIO_FN_MMCD0_0, NULL);
891 gpio_request(GPIO_FN_MMCD0_1, NULL);
892 gpio_request(GPIO_FN_MMCD0_2, NULL);
893 gpio_request(GPIO_FN_MMCD0_3, NULL);
894 gpio_request(GPIO_FN_MMCD0_4, NULL);
895 gpio_request(GPIO_FN_MMCD0_5, NULL);
896 gpio_request(GPIO_FN_MMCD0_6, NULL);
897 gpio_request(GPIO_FN_MMCD0_7, NULL);
898 gpio_request(GPIO_FN_MMCCMD0, NULL);
899 gpio_request(GPIO_FN_MMCCLK0, NULL);
900
901 /* USB enable */
902 gpio_request(GPIO_FN_VBUS0_1, NULL);
903 gpio_request(GPIO_FN_IDIN_1_18, NULL);
904 gpio_request(GPIO_FN_PWEN_1_115, NULL);
905 gpio_request(GPIO_FN_OVCN_1_114, NULL);
906 gpio_request(GPIO_FN_EXTLP_1, NULL);
907 gpio_request(GPIO_FN_OVCN2_1, NULL);
908
909 /* setup USB phy */
910 __raw_writew(0x8a0a, 0xE6058130); /* USBCR2 */
911
912 /* enable FSI2 */
913 gpio_request(GPIO_FN_FSIAIBT, NULL);
914 gpio_request(GPIO_FN_FSIAILR, NULL);
915 gpio_request(GPIO_FN_FSIAISLD, NULL);
916 gpio_request(GPIO_FN_FSIAOSLD, NULL);
917 gpio_request(GPIO_PORT161, NULL);
918 gpio_direction_output(GPIO_PORT161, 0); /* slave */
919
920 gpio_request(GPIO_PORT9, NULL);
921 gpio_request(GPIO_PORT10, NULL);
922 gpio_no_direction(GPIO_PORT9CR); /* FSIAOBT needs no direction */
923 gpio_no_direction(GPIO_PORT10CR); /* FSIAOLR needs no direction */
924
925 /* set SPU2 clock to 119.6 MHz */
926 clk = clk_get(NULL, "spu_clk");
927 if (!IS_ERR(clk)) {
928 clk_set_rate(clk, clk_round_rate(clk, 119600000));
929 clk_put(clk);
930 }
931
932 /* change parent of FSI A */
933 clk = clk_get(NULL, "fsia_clk");
934 if (!IS_ERR(clk)) {
935 clk_register(&fsiackcr_clk);
936 clk_set_parent(clk, &fsiackcr_clk);
937 clk_put(clk);
938 }
939
940 /*
941 * set irq priority, to avoid sound chopping
942 * when NFS rootfs is used
943 * FSI(3) > SMSC911X(2)
944 */
945 intc_set_priority(IRQ_FSI, 3);
946
947 i2c_register_board_info(0, i2c0_devices,
948 ARRAY_SIZE(i2c0_devices));
949
950 i2c_register_board_info(1, i2c1_devices,
951 ARRAY_SIZE(i2c1_devices));
952
953#ifdef CONFIG_AP4EVB_QHD
954 /*
955 * QHD
956 */
957
299 /* enable KEYSC */ 958 /* enable KEYSC */
300 gpio_request(GPIO_FN_KEYOUT0, NULL); 959 gpio_request(GPIO_FN_KEYOUT0, NULL);
301 gpio_request(GPIO_FN_KEYOUT1, NULL); 960 gpio_request(GPIO_FN_KEYOUT1, NULL);
@@ -308,26 +967,122 @@ static void __init ap4evb_init(void)
308 gpio_request(GPIO_FN_KEYIN3_133, NULL); 967 gpio_request(GPIO_FN_KEYIN3_133, NULL);
309 gpio_request(GPIO_FN_KEYIN4, NULL); 968 gpio_request(GPIO_FN_KEYIN4, NULL);
310 969
311 /* SDHI0 */ 970 /* enable TouchScreen */
312 gpio_request(GPIO_FN_SDHICD0, NULL); 971 set_irq_type(IRQ28, IRQ_TYPE_LEVEL_LOW);
313 gpio_request(GPIO_FN_SDHIWP0, NULL); 972
314 gpio_request(GPIO_FN_SDHICMD0, NULL); 973 tsc_device.irq = IRQ28;
315 gpio_request(GPIO_FN_SDHICLK0, NULL); 974 i2c_register_board_info(1, &tsc_device, 1);
316 gpio_request(GPIO_FN_SDHID0_3, NULL); 975
317 gpio_request(GPIO_FN_SDHID0_2, NULL); 976 /* LCDC0 */
318 gpio_request(GPIO_FN_SDHID0_1, NULL); 977 lcdc_info.clock_source = LCDC_CLK_PERIPHERAL;
319 gpio_request(GPIO_FN_SDHID0_0, NULL); 978 lcdc_info.ch[0].interface_type = RGB24;
979 lcdc_info.ch[0].clock_divider = 1;
980 lcdc_info.ch[0].flags = LCDC_FLAGS_DWPOL;
981 lcdc_info.ch[0].lcd_cfg.name = "R63302(QHD)";
982 lcdc_info.ch[0].lcd_cfg.xres = 544;
983 lcdc_info.ch[0].lcd_cfg.yres = 961;
984 lcdc_info.ch[0].lcd_cfg.left_margin = 72;
985 lcdc_info.ch[0].lcd_cfg.right_margin = 600;
986 lcdc_info.ch[0].lcd_cfg.hsync_len = 16;
987 lcdc_info.ch[0].lcd_cfg.upper_margin = 8;
988 lcdc_info.ch[0].lcd_cfg.lower_margin = 8;
989 lcdc_info.ch[0].lcd_cfg.vsync_len = 2;
990 lcdc_info.ch[0].lcd_cfg.sync = FB_SYNC_VERT_HIGH_ACT |
991 FB_SYNC_HOR_HIGH_ACT;
992 lcdc_info.ch[0].lcd_size_cfg.width = 44;
993 lcdc_info.ch[0].lcd_size_cfg.height = 79;
994
995 platform_add_devices(qhd_devices, ARRAY_SIZE(qhd_devices));
996
997#else
998 /*
999 * WVGA
1000 */
1001 gpio_request(GPIO_FN_LCDD17, NULL);
1002 gpio_request(GPIO_FN_LCDD16, NULL);
1003 gpio_request(GPIO_FN_LCDD15, NULL);
1004 gpio_request(GPIO_FN_LCDD14, NULL);
1005 gpio_request(GPIO_FN_LCDD13, NULL);
1006 gpio_request(GPIO_FN_LCDD12, NULL);
1007 gpio_request(GPIO_FN_LCDD11, NULL);
1008 gpio_request(GPIO_FN_LCDD10, NULL);
1009 gpio_request(GPIO_FN_LCDD9, NULL);
1010 gpio_request(GPIO_FN_LCDD8, NULL);
1011 gpio_request(GPIO_FN_LCDD7, NULL);
1012 gpio_request(GPIO_FN_LCDD6, NULL);
1013 gpio_request(GPIO_FN_LCDD5, NULL);
1014 gpio_request(GPIO_FN_LCDD4, NULL);
1015 gpio_request(GPIO_FN_LCDD3, NULL);
1016 gpio_request(GPIO_FN_LCDD2, NULL);
1017 gpio_request(GPIO_FN_LCDD1, NULL);
1018 gpio_request(GPIO_FN_LCDD0, NULL);
1019 gpio_request(GPIO_FN_LCDDISP, NULL);
1020 gpio_request(GPIO_FN_LCDDCK, NULL);
1021
1022 gpio_request(GPIO_PORT189, NULL); /* backlight */
1023 gpio_direction_output(GPIO_PORT189, 1);
1024
1025 gpio_request(GPIO_PORT151, NULL); /* LCDDON */
1026 gpio_direction_output(GPIO_PORT151, 1);
1027
1028 lcdc_info.clock_source = LCDC_CLK_BUS;
1029 lcdc_info.ch[0].interface_type = RGB18;
1030 lcdc_info.ch[0].clock_divider = 2;
1031 lcdc_info.ch[0].flags = 0;
1032 lcdc_info.ch[0].lcd_cfg.name = "WVGA Panel";
1033 lcdc_info.ch[0].lcd_cfg.xres = 800;
1034 lcdc_info.ch[0].lcd_cfg.yres = 480;
1035 lcdc_info.ch[0].lcd_cfg.left_margin = 220;
1036 lcdc_info.ch[0].lcd_cfg.right_margin = 110;
1037 lcdc_info.ch[0].lcd_cfg.hsync_len = 70;
1038 lcdc_info.ch[0].lcd_cfg.upper_margin = 20;
1039 lcdc_info.ch[0].lcd_cfg.lower_margin = 5;
1040 lcdc_info.ch[0].lcd_cfg.vsync_len = 5;
1041 lcdc_info.ch[0].lcd_cfg.sync = 0;
1042 lcdc_info.ch[0].lcd_size_cfg.width = 152;
1043 lcdc_info.ch[0].lcd_size_cfg.height = 91;
1044
1045 /* enable TouchScreen */
1046 set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
1047
1048 tsc_device.irq = IRQ7;
1049 i2c_register_board_info(0, &tsc_device, 1);
1050#endif /* CONFIG_AP4EVB_QHD */
320 1051
321 sh7372_add_standard_devices(); 1052 sh7372_add_standard_devices();
322 1053
1054 /* HDMI */
1055 gpio_request(GPIO_FN_HDMI_HPD, NULL);
1056 gpio_request(GPIO_FN_HDMI_CEC, NULL);
1057
1058 /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
1059#define SRCR4 0xe61580bc
1060 srcr4 = __raw_readl(SRCR4);
1061 __raw_writel(srcr4 | (1 << 13), SRCR4);
1062 udelay(50);
1063 __raw_writel(srcr4 & ~(1 << 13), SRCR4);
1064
323 platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices)); 1065 platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices));
324} 1066}
325 1067
1068static void __init ap4evb_timer_init(void)
1069{
1070 sh7372_clock_init();
1071 shmobile_timer.init();
1072
1073 /* External clock source */
1074 clk_set_rate(&dv_clki_clk, 27000000);
1075}
1076
1077static struct sys_timer ap4evb_timer = {
1078 .init = ap4evb_timer_init,
1079};
1080
326MACHINE_START(AP4EVB, "ap4evb") 1081MACHINE_START(AP4EVB, "ap4evb")
327 .phys_io = 0xe6000000, 1082 .phys_io = 0xe6000000,
328 .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc, 1083 .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc,
329 .map_io = ap4evb_map_io, 1084 .map_io = ap4evb_map_io,
330 .init_irq = sh7372_init_irq, 1085 .init_irq = sh7372_init_irq,
331 .init_machine = ap4evb_init, 1086 .init_machine = ap4evb_init,
332 .timer = &shmobile_timer, 1087 .timer = &ap4evb_timer,
333MACHINE_END 1088MACHINE_END
diff --git a/arch/arm/mach-shmobile/board-g3evm.c b/arch/arm/mach-shmobile/board-g3evm.c
index 9247503296c4..a5525901e91f 100644
--- a/arch/arm/mach-shmobile/board-g3evm.c
+++ b/arch/arm/mach-shmobile/board-g3evm.c
@@ -37,6 +37,15 @@
37#include <asm/mach-types.h> 37#include <asm/mach-types.h>
38#include <asm/mach/arch.h> 38#include <asm/mach/arch.h>
39#include <asm/mach/map.h> 39#include <asm/mach/map.h>
40#include <asm/mach/time.h>
41
42/*
43 * IrDA
44 *
45 * S67: 5bit : ON power
46 * : 6bit : ON remote control
47 * OFF IrDA
48 */
40 49
41static struct mtd_partition nor_flash_partitions[] = { 50static struct mtd_partition nor_flash_partitions[] = {
42 { 51 {
@@ -91,7 +100,7 @@ static struct platform_device nor_flash_device = {
91}; 100};
92 101
93/* USBHS */ 102/* USBHS */
94void usb_host_port_power(int port, int power) 103static void usb_host_port_power(int port, int power)
95{ 104{
96 if (!power) /* only power-on supported for now */ 105 if (!power) /* only power-on supported for now */
97 return; 106 return;
@@ -113,7 +122,7 @@ static struct resource usb_host_resources[] = {
113 .flags = IORESOURCE_MEM, 122 .flags = IORESOURCE_MEM,
114 }, 123 },
115 [1] = { 124 [1] = {
116 .start = 65, 125 .start = evt2irq(0xa20), /* USBHS_USHI0 */
117 .flags = IORESOURCE_IRQ, 126 .flags = IORESOURCE_IRQ,
118 }, 127 },
119}; 128};
@@ -153,7 +162,7 @@ static struct resource keysc_resources[] = {
153 .flags = IORESOURCE_MEM, 162 .flags = IORESOURCE_MEM,
154 }, 163 },
155 [1] = { 164 [1] = {
156 .start = 79, 165 .start = evt2irq(0xbe0), /* KEYSC_KEY */
157 .flags = IORESOURCE_IRQ, 166 .flags = IORESOURCE_IRQ,
158 }, 167 },
159}; 168};
@@ -209,11 +218,31 @@ static struct platform_device nand_flash_device = {
209 }, 218 },
210}; 219};
211 220
221static struct resource irda_resources[] = {
222 [0] = {
223 .start = 0xE6D00000,
224 .end = 0xE6D01FD4 - 1,
225 .flags = IORESOURCE_MEM,
226 },
227 [1] = {
228 .start = evt2irq(0x480), /* IRDA */
229 .flags = IORESOURCE_IRQ,
230 },
231};
232
233static struct platform_device irda_device = {
234 .name = "sh_irda",
235 .id = -1,
236 .resource = irda_resources,
237 .num_resources = ARRAY_SIZE(irda_resources),
238};
239
212static struct platform_device *g3evm_devices[] __initdata = { 240static struct platform_device *g3evm_devices[] __initdata = {
213 &nor_flash_device, 241 &nor_flash_device,
214 &usb_host_device, 242 &usb_host_device,
215 &keysc_device, 243 &keysc_device,
216 &nand_flash_device, 244 &nand_flash_device,
245 &irda_device,
217}; 246};
218 247
219static struct map_desc g3evm_io_desc[] __initdata = { 248static struct map_desc g3evm_io_desc[] __initdata = {
@@ -232,9 +261,8 @@ static void __init g3evm_map_io(void)
232{ 261{
233 iotable_init(g3evm_io_desc, ARRAY_SIZE(g3evm_io_desc)); 262 iotable_init(g3evm_io_desc, ARRAY_SIZE(g3evm_io_desc));
234 263
235 /* setup early devices, clocks and console here as well */ 264 /* setup early devices and console here as well */
236 sh7367_add_early_devices(); 265 sh7367_add_early_devices();
237 sh7367_clock_init();
238 shmobile_setup_console(); 266 shmobile_setup_console();
239} 267}
240 268
@@ -271,9 +299,6 @@ static void __init g3evm_init(void)
271 gpio_request(GPIO_FN_EXTLP, NULL); 299 gpio_request(GPIO_FN_EXTLP, NULL);
272 gpio_request(GPIO_FN_IDIN, NULL); 300 gpio_request(GPIO_FN_IDIN, NULL);
273 301
274 /* enable clock in SYMSTPCR2 */
275 __raw_writel(__raw_readl(0xe6158048) & ~(1 << 22), 0xe6158048);
276
277 /* setup USB phy */ 302 /* setup USB phy */
278 __raw_writew(0x0300, 0xe605810a); /* USBCR1 */ 303 __raw_writew(0x0300, 0xe605810a); /* USBCR1 */
279 __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */ 304 __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */
@@ -318,16 +343,32 @@ static void __init g3evm_init(void)
318 /* FOE, FCDE, FSC on dedicated pins */ 343 /* FOE, FCDE, FSC on dedicated pins */
319 __raw_writel(__raw_readl(0xe6158048) & ~(1 << 15), 0xe6158048); 344 __raw_writel(__raw_readl(0xe6158048) & ~(1 << 15), 0xe6158048);
320 345
346 /* IrDA */
347 gpio_request(GPIO_FN_IRDA_OUT, NULL);
348 gpio_request(GPIO_FN_IRDA_IN, NULL);
349 gpio_request(GPIO_FN_IRDA_FIRSEL, NULL);
350 set_irq_type(evt2irq(0x480), IRQ_TYPE_LEVEL_LOW);
351
321 sh7367_add_standard_devices(); 352 sh7367_add_standard_devices();
322 353
323 platform_add_devices(g3evm_devices, ARRAY_SIZE(g3evm_devices)); 354 platform_add_devices(g3evm_devices, ARRAY_SIZE(g3evm_devices));
324} 355}
325 356
357static void __init g3evm_timer_init(void)
358{
359 sh7367_clock_init();
360 shmobile_timer.init();
361}
362
363static struct sys_timer g3evm_timer = {
364 .init = g3evm_timer_init,
365};
366
326MACHINE_START(G3EVM, "g3evm") 367MACHINE_START(G3EVM, "g3evm")
327 .phys_io = 0xe6000000, 368 .phys_io = 0xe6000000,
328 .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc, 369 .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc,
329 .map_io = g3evm_map_io, 370 .map_io = g3evm_map_io,
330 .init_irq = sh7367_init_irq, 371 .init_irq = sh7367_init_irq,
331 .init_machine = g3evm_init, 372 .init_machine = g3evm_init,
332 .timer = &shmobile_timer, 373 .timer = &g3evm_timer,
333MACHINE_END 374MACHINE_END
diff --git a/arch/arm/mach-shmobile/board-g4evm.c b/arch/arm/mach-shmobile/board-g4evm.c
index 10673a90be52..2c3ff6f7f34c 100644
--- a/arch/arm/mach-shmobile/board-g4evm.c
+++ b/arch/arm/mach-shmobile/board-g4evm.c
@@ -30,12 +30,39 @@
30#include <linux/io.h> 30#include <linux/io.h>
31#include <linux/input.h> 31#include <linux/input.h>
32#include <linux/input/sh_keysc.h> 32#include <linux/input/sh_keysc.h>
33#include <linux/mfd/sh_mobile_sdhi.h>
33#include <linux/gpio.h> 34#include <linux/gpio.h>
34#include <mach/sh7377.h> 35#include <mach/sh7377.h>
35#include <mach/common.h> 36#include <mach/common.h>
36#include <asm/mach-types.h> 37#include <asm/mach-types.h>
37#include <asm/mach/arch.h> 38#include <asm/mach/arch.h>
38#include <asm/mach/map.h> 39#include <asm/mach/map.h>
40#include <asm/mach/time.h>
41
42/*
43 * SDHI
44 *
45 * SDHI0 : card detection is possible
46 * SDHI1 : card detection is impossible
47 *
48 * [G4-MAIN-BOARD]
49 * JP74 : short # DBG_2V8A for SDHI0
50 * JP75 : NC # DBG_3V3A for SDHI0
51 * JP76 : NC # DBG_3V3A_SD for SDHI0
52 * JP77 : NC # 3V3A_SDIO for SDHI1
53 * JP78 : short # DBG_2V8A for SDHI1
54 * JP79 : NC # DBG_3V3A for SDHI1
55 * JP80 : NC # DBG_3V3A_SD for SDHI1
56 *
57 * [G4-CORE-BOARD]
58 * S32 : all off # to dissever from G3-CORE_DBG board
59 * S33 : all off # to dissever from G3-CORE_DBG board
60 *
61 * [G3-CORE_DBG-BOARD]
62 * S1 : all off # to dissever from G3-CORE_DBG board
63 * S3 : all off # to dissever from G3-CORE_DBG board
64 * S4 : all off # to dissever from G3-CORE_DBG board
65 */
39 66
40static struct mtd_partition nor_flash_partitions[] = { 67static struct mtd_partition nor_flash_partitions[] = {
41 { 68 {
@@ -90,7 +117,7 @@ static struct platform_device nor_flash_device = {
90}; 117};
91 118
92/* USBHS */ 119/* USBHS */
93void usb_host_port_power(int port, int power) 120static void usb_host_port_power(int port, int power)
94{ 121{
95 if (!power) /* only power-on supported for now */ 122 if (!power) /* only power-on supported for now */
96 return; 123 return;
@@ -112,8 +139,7 @@ static struct resource usb_host_resources[] = {
112 .flags = IORESOURCE_MEM, 139 .flags = IORESOURCE_MEM,
113 }, 140 },
114 [1] = { 141 [1] = {
115 .start = 65, 142 .start = evt2irq(0x0a20), /* USBHS_USHI0 */
116 .end = 65,
117 .flags = IORESOURCE_IRQ, 143 .flags = IORESOURCE_IRQ,
118 }, 144 },
119}; 145};
@@ -154,7 +180,7 @@ static struct resource keysc_resources[] = {
154 .flags = IORESOURCE_MEM, 180 .flags = IORESOURCE_MEM,
155 }, 181 },
156 [1] = { 182 [1] = {
157 .start = 79, 183 .start = evt2irq(0x0be0), /* KEYSC_KEY */
158 .flags = IORESOURCE_IRQ, 184 .flags = IORESOURCE_IRQ,
159 }, 185 },
160}; 186};
@@ -169,10 +195,53 @@ static struct platform_device keysc_device = {
169 }, 195 },
170}; 196};
171 197
198/* SDHI */
199static struct resource sdhi0_resources[] = {
200 [0] = {
201 .name = "SDHI0",
202 .start = 0xe6d50000,
203 .end = 0xe6d501ff,
204 .flags = IORESOURCE_MEM,
205 },
206 [1] = {
207 .start = evt2irq(0x0e00), /* SDHI0 */
208 .flags = IORESOURCE_IRQ,
209 },
210};
211
212static struct platform_device sdhi0_device = {
213 .name = "sh_mobile_sdhi",
214 .num_resources = ARRAY_SIZE(sdhi0_resources),
215 .resource = sdhi0_resources,
216 .id = 0,
217};
218
219static struct resource sdhi1_resources[] = {
220 [0] = {
221 .name = "SDHI1",
222 .start = 0xe6d60000,
223 .end = 0xe6d601ff,
224 .flags = IORESOURCE_MEM,
225 },
226 [1] = {
227 .start = evt2irq(0x0e80), /* SDHI1 */
228 .flags = IORESOURCE_IRQ,
229 },
230};
231
232static struct platform_device sdhi1_device = {
233 .name = "sh_mobile_sdhi",
234 .num_resources = ARRAY_SIZE(sdhi1_resources),
235 .resource = sdhi1_resources,
236 .id = 1,
237};
238
172static struct platform_device *g4evm_devices[] __initdata = { 239static struct platform_device *g4evm_devices[] __initdata = {
173 &nor_flash_device, 240 &nor_flash_device,
174 &usb_host_device, 241 &usb_host_device,
175 &keysc_device, 242 &keysc_device,
243 &sdhi0_device,
244 &sdhi1_device,
176}; 245};
177 246
178static struct map_desc g4evm_io_desc[] __initdata = { 247static struct map_desc g4evm_io_desc[] __initdata = {
@@ -191,12 +260,41 @@ static void __init g4evm_map_io(void)
191{ 260{
192 iotable_init(g4evm_io_desc, ARRAY_SIZE(g4evm_io_desc)); 261 iotable_init(g4evm_io_desc, ARRAY_SIZE(g4evm_io_desc));
193 262
194 /* setup early devices, clocks and console here as well */ 263 /* setup early devices and console here as well */
195 sh7377_add_early_devices(); 264 sh7377_add_early_devices();
196 sh7367_clock_init(); /* use g3 clocks for now */
197 shmobile_setup_console(); 265 shmobile_setup_console();
198} 266}
199 267
268#define GPIO_SDHID0_D0 0xe60520fc
269#define GPIO_SDHID0_D1 0xe60520fd
270#define GPIO_SDHID0_D2 0xe60520fe
271#define GPIO_SDHID0_D3 0xe60520ff
272#define GPIO_SDHICMD0 0xe6052100
273
274#define GPIO_SDHID1_D0 0xe6052103
275#define GPIO_SDHID1_D1 0xe6052104
276#define GPIO_SDHID1_D2 0xe6052105
277#define GPIO_SDHID1_D3 0xe6052106
278#define GPIO_SDHICMD1 0xe6052107
279
280/*
281 * FIXME !!
282 *
283 * gpio_pull_up is quick_hack.
284 *
285 * current gpio frame work doesn't have
286 * the method to control only pull up/down/free.
287 * this function should be replaced by correct gpio function
288 */
289static void __init gpio_pull_up(u32 addr)
290{
291 u8 data = __raw_readb(addr);
292
293 data &= 0x0F;
294 data |= 0xC0;
295 __raw_writeb(data, addr);
296}
297
200static void __init g4evm_init(void) 298static void __init g4evm_init(void)
201{ 299{
202 sh7377_pinmux_init(); 300 sh7377_pinmux_init();
@@ -229,9 +327,6 @@ static void __init g4evm_init(void)
229 gpio_request(GPIO_FN_EXTLP, NULL); 327 gpio_request(GPIO_FN_EXTLP, NULL);
230 gpio_request(GPIO_FN_IDIN, NULL); 328 gpio_request(GPIO_FN_IDIN, NULL);
231 329
232 /* enable clock in SMSTPCR3 */
233 __raw_writel(__raw_readl(0xe615013c) & ~(1 << 22), 0xe615013c);
234
235 /* setup USB phy */ 330 /* setup USB phy */
236 __raw_writew(0x0200, 0xe605810a); /* USBCR1 */ 331 __raw_writew(0x0200, 0xe605810a); /* USBCR1 */
237 __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */ 332 __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */
@@ -253,16 +348,54 @@ static void __init g4evm_init(void)
253 gpio_request(GPIO_FN_PORT71_KEYIN5_PU, NULL); 348 gpio_request(GPIO_FN_PORT71_KEYIN5_PU, NULL);
254 gpio_request(GPIO_FN_PORT72_KEYIN6_PU, NULL); 349 gpio_request(GPIO_FN_PORT72_KEYIN6_PU, NULL);
255 350
351 /* SDHI0 */
352 gpio_request(GPIO_FN_SDHICLK0, NULL);
353 gpio_request(GPIO_FN_SDHICD0, NULL);
354 gpio_request(GPIO_FN_SDHID0_0, NULL);
355 gpio_request(GPIO_FN_SDHID0_1, NULL);
356 gpio_request(GPIO_FN_SDHID0_2, NULL);
357 gpio_request(GPIO_FN_SDHID0_3, NULL);
358 gpio_request(GPIO_FN_SDHICMD0, NULL);
359 gpio_request(GPIO_FN_SDHIWP0, NULL);
360 gpio_pull_up(GPIO_SDHID0_D0);
361 gpio_pull_up(GPIO_SDHID0_D1);
362 gpio_pull_up(GPIO_SDHID0_D2);
363 gpio_pull_up(GPIO_SDHID0_D3);
364 gpio_pull_up(GPIO_SDHICMD0);
365
366 /* SDHI1 */
367 gpio_request(GPIO_FN_SDHICLK1, NULL);
368 gpio_request(GPIO_FN_SDHID1_0, NULL);
369 gpio_request(GPIO_FN_SDHID1_1, NULL);
370 gpio_request(GPIO_FN_SDHID1_2, NULL);
371 gpio_request(GPIO_FN_SDHID1_3, NULL);
372 gpio_request(GPIO_FN_SDHICMD1, NULL);
373 gpio_pull_up(GPIO_SDHID1_D0);
374 gpio_pull_up(GPIO_SDHID1_D1);
375 gpio_pull_up(GPIO_SDHID1_D2);
376 gpio_pull_up(GPIO_SDHID1_D3);
377 gpio_pull_up(GPIO_SDHICMD1);
378
256 sh7377_add_standard_devices(); 379 sh7377_add_standard_devices();
257 380
258 platform_add_devices(g4evm_devices, ARRAY_SIZE(g4evm_devices)); 381 platform_add_devices(g4evm_devices, ARRAY_SIZE(g4evm_devices));
259} 382}
260 383
384static void __init g4evm_timer_init(void)
385{
386 sh7377_clock_init();
387 shmobile_timer.init();
388}
389
390static struct sys_timer g4evm_timer = {
391 .init = g4evm_timer_init,
392};
393
261MACHINE_START(G4EVM, "g4evm") 394MACHINE_START(G4EVM, "g4evm")
262 .phys_io = 0xe6000000, 395 .phys_io = 0xe6000000,
263 .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc, 396 .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc,
264 .map_io = g4evm_map_io, 397 .map_io = g4evm_map_io,
265 .init_irq = sh7377_init_irq, 398 .init_irq = sh7377_init_irq,
266 .init_machine = g4evm_init, 399 .init_machine = g4evm_init,
267 .timer = &shmobile_timer, 400 .timer = &g4evm_timer,
268MACHINE_END 401MACHINE_END
diff --git a/arch/arm/mach-shmobile/clock-sh7367.c b/arch/arm/mach-shmobile/clock-sh7367.c
index bb940c6e4e6c..b6454c9f2abb 100644
--- a/arch/arm/mach-shmobile/clock-sh7367.c
+++ b/arch/arm/mach-shmobile/clock-sh7367.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Preliminary clock framework support for sh7367 2 * SH7367 clock framework support
3 * 3 *
4 * Copyright (C) 2010 Magnus Damm 4 * Copyright (C) 2010 Magnus Damm
5 * 5 *
@@ -17,87 +17,342 @@
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */ 18 */
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/kernel.h> 20#include <linux/kernel.h>
22#include <linux/list.h> 21#include <linux/io.h>
23#include <linux/clk.h> 22#include <linux/sh_clk.h>
23#include <mach/common.h>
24#include <asm/clkdev.h>
25
26/* SH7367 registers */
27#define RTFRQCR 0xe6150000
28#define SYFRQCR 0xe6150004
29#define CMFRQCR 0xe61500E0
30#define VCLKCR1 0xe6150008
31#define VCLKCR2 0xe615000C
32#define VCLKCR3 0xe615001C
33#define SCLKACR 0xe6150010
34#define SCLKBCR 0xe6150014
35#define SUBUSBCKCR 0xe6158080
36#define SPUCKCR 0xe6150084
37#define MSUCKCR 0xe6150088
38#define MVI3CKCR 0xe6150090
39#define VOUCKCR 0xe6150094
40#define MFCK1CR 0xe6150098
41#define MFCK2CR 0xe615009C
42#define PLLC1CR 0xe6150028
43#define PLLC2CR 0xe615002C
44#define RTMSTPCR0 0xe6158030
45#define RTMSTPCR2 0xe6158038
46#define SYMSTPCR0 0xe6158040
47#define SYMSTPCR2 0xe6158048
48#define CMMSTPCR0 0xe615804c
24 49
25struct clk { 50/* Fixed 32 KHz root clock from EXTALR pin */
26 const char *name; 51static struct clk r_clk = {
27 unsigned long rate; 52 .rate = 32768,
28}; 53};
29 54
30#include <asm/clkdev.h> 55/*
56 * 26MHz default rate for the EXTALB1 root input clock.
57 * If needed, reset this with clk_set_rate() from the platform code.
58 */
59struct clk sh7367_extalb1_clk = {
60 .rate = 26666666,
61};
31 62
32int __clk_get(struct clk *clk) 63/*
33{ 64 * 48MHz default rate for the EXTAL2 root input clock.
34 return 1; 65 * If needed, reset this with clk_set_rate() from the platform code.
35} 66 */
36EXPORT_SYMBOL(__clk_get); 67struct clk sh7367_extal2_clk = {
68 .rate = 48000000,
69};
37 70
38void __clk_put(struct clk *clk) 71/* A fixed divide-by-2 block */
72static unsigned long div2_recalc(struct clk *clk)
39{ 73{
74 return clk->parent->rate / 2;
40} 75}
41EXPORT_SYMBOL(__clk_put);
42 76
77static struct clk_ops div2_clk_ops = {
78 .recalc = div2_recalc,
79};
80
81/* Divide extalb1 by two */
82static struct clk extalb1_div2_clk = {
83 .ops = &div2_clk_ops,
84 .parent = &sh7367_extalb1_clk,
85};
86
87/* Divide extal2 by two */
88static struct clk extal2_div2_clk = {
89 .ops = &div2_clk_ops,
90 .parent = &sh7367_extal2_clk,
91};
43 92
44int clk_enable(struct clk *clk) 93/* PLLC1 */
94static unsigned long pllc1_recalc(struct clk *clk)
45{ 95{
46 return 0; 96 unsigned long mult = 1;
97
98 if (__raw_readl(PLLC1CR) & (1 << 14))
99 mult = (((__raw_readl(RTFRQCR) >> 24) & 0x3f) + 1) * 2;
100
101 return clk->parent->rate * mult;
47} 102}
48EXPORT_SYMBOL(clk_enable);
49 103
50void clk_disable(struct clk *clk) 104static struct clk_ops pllc1_clk_ops = {
105 .recalc = pllc1_recalc,
106};
107
108static struct clk pllc1_clk = {
109 .ops = &pllc1_clk_ops,
110 .flags = CLK_ENABLE_ON_INIT,
111 .parent = &extalb1_div2_clk,
112};
113
114/* Divide PLLC1 by two */
115static struct clk pllc1_div2_clk = {
116 .ops = &div2_clk_ops,
117 .parent = &pllc1_clk,
118};
119
120/* PLLC2 */
121static unsigned long pllc2_recalc(struct clk *clk)
51{ 122{
123 unsigned long mult = 1;
124
125 if (__raw_readl(PLLC2CR) & (1 << 31))
126 mult = (((__raw_readl(PLLC2CR) >> 24) & 0x3f) + 1) * 2;
127
128 return clk->parent->rate * mult;
52} 129}
53EXPORT_SYMBOL(clk_disable);
54 130
55unsigned long clk_get_rate(struct clk *clk) 131static struct clk_ops pllc2_clk_ops = {
132 .recalc = pllc2_recalc,
133};
134
135static struct clk pllc2_clk = {
136 .ops = &pllc2_clk_ops,
137 .flags = CLK_ENABLE_ON_INIT,
138 .parent = &extalb1_div2_clk,
139};
140
141static struct clk *main_clks[] = {
142 &r_clk,
143 &sh7367_extalb1_clk,
144 &sh7367_extal2_clk,
145 &extalb1_div2_clk,
146 &extal2_div2_clk,
147 &pllc1_clk,
148 &pllc1_div2_clk,
149 &pllc2_clk,
150};
151
152static void div4_kick(struct clk *clk)
56{ 153{
57 return clk ? clk->rate : 0; 154 unsigned long value;
155
156 /* set KICK bit in SYFRQCR to update hardware setting */
157 value = __raw_readl(SYFRQCR);
158 value |= (1 << 31);
159 __raw_writel(value, SYFRQCR);
58} 160}
59EXPORT_SYMBOL(clk_get_rate);
60 161
61/* a static peripheral clock for now - enough to get sh-sci working */ 162static int divisors[] = { 2, 3, 4, 6, 8, 12, 16, 18,
62static struct clk peripheral_clk = { 163 24, 32, 36, 48, 0, 72, 0, 0 };
63 .name = "peripheral_clk", 164
64 .rate = 48000000, 165static struct clk_div_mult_table div4_div_mult_table = {
166 .divisors = divisors,
167 .nr_divisors = ARRAY_SIZE(divisors),
65}; 168};
66 169
67/* a static rclk for now - enough to get sh_cmt working */ 170static struct clk_div4_table div4_table = {
68static struct clk r_clk = { 171 .div_mult_table = &div4_div_mult_table,
69 .name = "r_clk", 172 .kick = div4_kick,
70 .rate = 32768, 173};
174
175enum { DIV4_I, DIV4_G, DIV4_S, DIV4_B,
176 DIV4_ZX, DIV4_ZT, DIV4_Z, DIV4_ZD, DIV4_HP,
177 DIV4_ZS, DIV4_ZB, DIV4_ZB3, DIV4_CP, DIV4_NR };
178
179#define DIV4(_reg, _bit, _mask, _flags) \
180 SH_CLK_DIV4(&pllc1_clk, _reg, _bit, _mask, _flags)
181
182static struct clk div4_clks[DIV4_NR] = {
183 [DIV4_I] = DIV4(RTFRQCR, 20, 0x6fff, CLK_ENABLE_ON_INIT),
184 [DIV4_G] = DIV4(RTFRQCR, 16, 0x6fff, CLK_ENABLE_ON_INIT),
185 [DIV4_S] = DIV4(RTFRQCR, 12, 0x6fff, CLK_ENABLE_ON_INIT),
186 [DIV4_B] = DIV4(RTFRQCR, 8, 0x6fff, CLK_ENABLE_ON_INIT),
187 [DIV4_ZX] = DIV4(SYFRQCR, 20, 0x6fff, 0),
188 [DIV4_ZT] = DIV4(SYFRQCR, 16, 0x6fff, 0),
189 [DIV4_Z] = DIV4(SYFRQCR, 12, 0x6fff, 0),
190 [DIV4_ZD] = DIV4(SYFRQCR, 8, 0x6fff, 0),
191 [DIV4_HP] = DIV4(SYFRQCR, 4, 0x6fff, 0),
192 [DIV4_ZS] = DIV4(CMFRQCR, 12, 0x6fff, 0),
193 [DIV4_ZB] = DIV4(CMFRQCR, 8, 0x6fff, 0),
194 [DIV4_ZB3] = DIV4(CMFRQCR, 4, 0x6fff, 0),
195 [DIV4_CP] = DIV4(CMFRQCR, 0, 0x6fff, 0),
71}; 196};
72 197
73/* a static usb0 for now - enough to get r8a66597 working */ 198enum { DIV6_SUB, DIV6_SIUA, DIV6_SIUB, DIV6_MSU, DIV6_SPU,
74static struct clk usb0_clk = { 199 DIV6_MVI3, DIV6_MF1, DIV6_MF2,
75 .name = "usb0", 200 DIV6_VCK1, DIV6_VCK2, DIV6_VCK3, DIV6_VOU,
201 DIV6_NR };
202
203static struct clk div6_clks[DIV6_NR] = {
204 [DIV6_SUB] = SH_CLK_DIV6(&sh7367_extal2_clk, SUBUSBCKCR, 0),
205 [DIV6_SIUA] = SH_CLK_DIV6(&pllc1_div2_clk, SCLKACR, 0),
206 [DIV6_SIUB] = SH_CLK_DIV6(&pllc1_div2_clk, SCLKBCR, 0),
207 [DIV6_MSU] = SH_CLK_DIV6(&pllc1_div2_clk, MSUCKCR, 0),
208 [DIV6_SPU] = SH_CLK_DIV6(&pllc1_div2_clk, SPUCKCR, 0),
209 [DIV6_MVI3] = SH_CLK_DIV6(&pllc1_div2_clk, MVI3CKCR, 0),
210 [DIV6_MF1] = SH_CLK_DIV6(&pllc1_div2_clk, MFCK1CR, 0),
211 [DIV6_MF2] = SH_CLK_DIV6(&pllc1_div2_clk, MFCK2CR, 0),
212 [DIV6_VCK1] = SH_CLK_DIV6(&pllc1_div2_clk, VCLKCR1, 0),
213 [DIV6_VCK2] = SH_CLK_DIV6(&pllc1_div2_clk, VCLKCR2, 0),
214 [DIV6_VCK3] = SH_CLK_DIV6(&pllc1_div2_clk, VCLKCR3, 0),
215 [DIV6_VOU] = SH_CLK_DIV6(&pllc1_div2_clk, VOUCKCR, 0),
76}; 216};
77 217
78/* a static keysc0 clk for now - enough to get sh_keysc working */ 218enum { RTMSTP001,
79static struct clk keysc0_clk = { 219 RTMSTP231, RTMSTP230, RTMSTP229, RTMSTP228, RTMSTP226,
80 .name = "keysc0", 220 RTMSTP216, RTMSTP206, RTMSTP205, RTMSTP201,
221 SYMSTP023, SYMSTP007, SYMSTP006, SYMSTP004,
222 SYMSTP003, SYMSTP002, SYMSTP001, SYMSTP000,
223 SYMSTP231, SYMSTP229, SYMSTP225, SYMSTP223, SYMSTP222,
224 SYMSTP215, SYMSTP214, SYMSTP213, SYMSTP211,
225 CMMSTP003,
226 MSTP_NR };
227
228#define MSTP(_parent, _reg, _bit, _flags) \
229 SH_CLK_MSTP32(_parent, _reg, _bit, _flags)
230
231static struct clk mstp_clks[MSTP_NR] = {
232 [RTMSTP001] = MSTP(&div6_clks[DIV6_SUB], RTMSTPCR0, 1, 0), /* IIC2 */
233 [RTMSTP231] = MSTP(&div4_clks[DIV4_B], RTMSTPCR2, 31, 0), /* VEU3 */
234 [RTMSTP230] = MSTP(&div4_clks[DIV4_B], RTMSTPCR2, 30, 0), /* VEU2 */
235 [RTMSTP229] = MSTP(&div4_clks[DIV4_B], RTMSTPCR2, 29, 0), /* VEU1 */
236 [RTMSTP228] = MSTP(&div4_clks[DIV4_B], RTMSTPCR2, 28, 0), /* VEU0 */
237 [RTMSTP226] = MSTP(&div4_clks[DIV4_B], RTMSTPCR2, 26, 0), /* VEU2H */
238 [RTMSTP216] = MSTP(&div6_clks[DIV6_SUB], RTMSTPCR2, 16, 0), /* IIC0 */
239 [RTMSTP206] = MSTP(&div4_clks[DIV4_B], RTMSTPCR2, 6, 0), /* JPU */
240 [RTMSTP205] = MSTP(&div6_clks[DIV6_VOU], RTMSTPCR2, 5, 0), /* VOU */
241 [RTMSTP201] = MSTP(&div4_clks[DIV4_B], RTMSTPCR2, 1, 0), /* VPU */
242 [SYMSTP023] = MSTP(&div6_clks[DIV6_SPU], SYMSTPCR0, 23, 0), /* SPU1 */
243 [SYMSTP007] = MSTP(&div6_clks[DIV6_SUB], SYMSTPCR0, 7, 0), /* SCIFA5 */
244 [SYMSTP006] = MSTP(&div6_clks[DIV6_SUB], SYMSTPCR0, 6, 0), /* SCIFB */
245 [SYMSTP004] = MSTP(&div6_clks[DIV6_SUB], SYMSTPCR0, 4, 0), /* SCIFA0 */
246 [SYMSTP003] = MSTP(&div6_clks[DIV6_SUB], SYMSTPCR0, 3, 0), /* SCIFA1 */
247 [SYMSTP002] = MSTP(&div6_clks[DIV6_SUB], SYMSTPCR0, 2, 0), /* SCIFA2 */
248 [SYMSTP001] = MSTP(&div6_clks[DIV6_SUB], SYMSTPCR0, 1, 0), /* SCIFA3 */
249 [SYMSTP000] = MSTP(&div6_clks[DIV6_SUB], SYMSTPCR0, 0, 0), /* SCIFA4 */
250 [SYMSTP231] = MSTP(&div6_clks[DIV6_SUB], SYMSTPCR2, 31, 0), /* SIU */
251 [SYMSTP229] = MSTP(&r_clk, SYMSTPCR2, 29, 0), /* CMT10 */
252 [SYMSTP225] = MSTP(&div6_clks[DIV6_SUB], SYMSTPCR2, 25, 0), /* IRDA */
253 [SYMSTP223] = MSTP(&div6_clks[DIV6_SUB], SYMSTPCR2, 23, 0), /* IIC1 */
254 [SYMSTP222] = MSTP(&div6_clks[DIV6_SUB], SYMSTPCR2, 22, 0), /* USBHS */
255 [SYMSTP215] = MSTP(&div4_clks[DIV4_HP], SYMSTPCR2, 15, 0), /* FLCTL */
256 [SYMSTP214] = MSTP(&div4_clks[DIV4_HP], SYMSTPCR2, 14, 0), /* SDHI0 */
257 [SYMSTP213] = MSTP(&div4_clks[DIV4_HP], SYMSTPCR2, 13, 0), /* SDHI1 */
258 [SYMSTP211] = MSTP(&div4_clks[DIV4_HP], SYMSTPCR2, 11, 0), /* SDHI2 */
259 [CMMSTP003] = MSTP(&r_clk, CMMSTPCR0, 3, 0), /* KEYSC */
81}; 260};
82 261
262#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
263#define CLKDEV_DEV_ID(_id, _clk) { .dev_id = _id, .clk = _clk }
264
83static struct clk_lookup lookups[] = { 265static struct clk_lookup lookups[] = {
84 { 266 /* main clocks */
85 .clk = &peripheral_clk, 267 CLKDEV_CON_ID("r_clk", &r_clk),
86 }, { 268 CLKDEV_CON_ID("extalb1", &sh7367_extalb1_clk),
87 .clk = &r_clk, 269 CLKDEV_CON_ID("extal2", &sh7367_extal2_clk),
88 }, { 270 CLKDEV_CON_ID("extalb1_div2_clk", &extalb1_div2_clk),
89 .clk = &usb0_clk, 271 CLKDEV_CON_ID("extal2_div2_clk", &extal2_div2_clk),
90 }, { 272 CLKDEV_CON_ID("pllc1_clk", &pllc1_clk),
91 .clk = &keysc0_clk, 273 CLKDEV_CON_ID("pllc1_div2_clk", &pllc1_div2_clk),
92 } 274 CLKDEV_CON_ID("pllc2_clk", &pllc2_clk),
275
276 /* DIV4 clocks */
277 CLKDEV_CON_ID("i_clk", &div4_clks[DIV4_I]),
278 CLKDEV_CON_ID("g_clk", &div4_clks[DIV4_G]),
279 CLKDEV_CON_ID("b_clk", &div4_clks[DIV4_B]),
280 CLKDEV_CON_ID("zx_clk", &div4_clks[DIV4_ZX]),
281 CLKDEV_CON_ID("zt_clk", &div4_clks[DIV4_ZT]),
282 CLKDEV_CON_ID("z_clk", &div4_clks[DIV4_Z]),
283 CLKDEV_CON_ID("zd_clk", &div4_clks[DIV4_ZD]),
284 CLKDEV_CON_ID("hp_clk", &div4_clks[DIV4_HP]),
285 CLKDEV_CON_ID("zs_clk", &div4_clks[DIV4_ZS]),
286 CLKDEV_CON_ID("zb_clk", &div4_clks[DIV4_ZB]),
287 CLKDEV_CON_ID("zb3_clk", &div4_clks[DIV4_ZB3]),
288 CLKDEV_CON_ID("cp_clk", &div4_clks[DIV4_CP]),
289
290 /* DIV6 clocks */
291 CLKDEV_CON_ID("sub_clk", &div6_clks[DIV6_SUB]),
292 CLKDEV_CON_ID("siua_clk", &div6_clks[DIV6_SIUA]),
293 CLKDEV_CON_ID("siub_clk", &div6_clks[DIV6_SIUB]),
294 CLKDEV_CON_ID("msu_clk", &div6_clks[DIV6_MSU]),
295 CLKDEV_CON_ID("spu_clk", &div6_clks[DIV6_SPU]),
296 CLKDEV_CON_ID("mvi3_clk", &div6_clks[DIV6_MVI3]),
297 CLKDEV_CON_ID("mf1_clk", &div6_clks[DIV6_MF1]),
298 CLKDEV_CON_ID("mf2_clk", &div6_clks[DIV6_MF2]),
299 CLKDEV_CON_ID("vck1_clk", &div6_clks[DIV6_VCK1]),
300 CLKDEV_CON_ID("vck2_clk", &div6_clks[DIV6_VCK2]),
301 CLKDEV_CON_ID("vck3_clk", &div6_clks[DIV6_VCK3]),
302 CLKDEV_CON_ID("vou_clk", &div6_clks[DIV6_VOU]),
303
304 /* MSTP32 clocks */
305 CLKDEV_DEV_ID("i2c-sh_mobile.2", &mstp_clks[RTMSTP001]), /* IIC2 */
306 CLKDEV_DEV_ID("uio_pdrv_genirq.4", &mstp_clks[RTMSTP231]), /* VEU3 */
307 CLKDEV_DEV_ID("uio_pdrv_genirq.3", &mstp_clks[RTMSTP230]), /* VEU2 */
308 CLKDEV_DEV_ID("uio_pdrv_genirq.2", &mstp_clks[RTMSTP229]), /* VEU1 */
309 CLKDEV_DEV_ID("uio_pdrv_genirq.1", &mstp_clks[RTMSTP228]), /* VEU0 */
310 CLKDEV_DEV_ID("uio_pdrv_genirq.5", &mstp_clks[RTMSTP226]), /* VEU2H */
311 CLKDEV_DEV_ID("i2c-sh_mobile.0", &mstp_clks[RTMSTP216]), /* IIC0 */
312 CLKDEV_DEV_ID("uio_pdrv_genirq.6", &mstp_clks[RTMSTP206]), /* JPU */
313 CLKDEV_DEV_ID("sh-vou", &mstp_clks[RTMSTP205]), /* VOU */
314 CLKDEV_DEV_ID("uio_pdrv_genirq.0", &mstp_clks[RTMSTP201]), /* VPU */
315 CLKDEV_DEV_ID("uio_pdrv_genirq.7", &mstp_clks[SYMSTP023]), /* SPU1 */
316 CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[SYMSTP007]), /* SCIFA5 */
317 CLKDEV_DEV_ID("sh-sci.6", &mstp_clks[SYMSTP006]), /* SCIFB */
318 CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[SYMSTP004]), /* SCIFA0 */
319 CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[SYMSTP003]), /* SCIFA1 */
320 CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[SYMSTP002]), /* SCIFA2 */
321 CLKDEV_DEV_ID("sh-sci.3", &mstp_clks[SYMSTP001]), /* SCIFA3 */
322 CLKDEV_DEV_ID("sh-sci.4", &mstp_clks[SYMSTP000]), /* SCIFA4 */
323 CLKDEV_DEV_ID("sh_siu", &mstp_clks[SYMSTP231]), /* SIU */
324 CLKDEV_CON_ID("cmt1", &mstp_clks[SYMSTP229]), /* CMT10 */
325 CLKDEV_DEV_ID("sh_irda", &mstp_clks[SYMSTP225]), /* IRDA */
326 CLKDEV_DEV_ID("i2c-sh_mobile.1", &mstp_clks[SYMSTP223]), /* IIC1 */
327 CLKDEV_DEV_ID("r8a66597_hcd.0", &mstp_clks[SYMSTP222]), /* USBHS */
328 CLKDEV_DEV_ID("r8a66597_udc.0", &mstp_clks[SYMSTP222]), /* USBHS */
329 CLKDEV_DEV_ID("sh_flctl", &mstp_clks[SYMSTP215]), /* FLCTL */
330 CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[SYMSTP214]), /* SDHI0 */
331 CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[SYMSTP213]), /* SDHI1 */
332 CLKDEV_DEV_ID("sh_mobile_sdhi.2", &mstp_clks[SYMSTP211]), /* SDHI2 */
333 CLKDEV_DEV_ID("sh_keysc.0", &mstp_clks[CMMSTP003]), /* KEYSC */
93}; 334};
94 335
95void __init sh7367_clock_init(void) 336void __init sh7367_clock_init(void)
96{ 337{
97 int i; 338 int k, ret = 0;
339
340 for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
341 ret = clk_register(main_clks[k]);
342
343 if (!ret)
344 ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
345
346 if (!ret)
347 ret = sh_clk_div6_register(div6_clks, DIV6_NR);
348
349 if (!ret)
350 ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);
351
352 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
98 353
99 for (i = 0; i < ARRAY_SIZE(lookups); i++) { 354 if (!ret)
100 lookups[i].con_id = lookups[i].clk->name; 355 clk_init();
101 clkdev_add(&lookups[i]); 356 else
102 } 357 panic("failed to setup sh7367 clocks\n");
103} 358}
diff --git a/arch/arm/mach-shmobile/clock-sh7372.c b/arch/arm/mach-shmobile/clock-sh7372.c
new file mode 100644
index 000000000000..fb4e9b1d788e
--- /dev/null
+++ b/arch/arm/mach-shmobile/clock-sh7372.c
@@ -0,0 +1,560 @@
1/*
2 * SH7372 clock framework support
3 *
4 * Copyright (C) 2010 Magnus Damm
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/io.h>
22#include <linux/sh_clk.h>
23#include <mach/common.h>
24#include <asm/clkdev.h>
25
26/* SH7372 registers */
27#define FRQCRA 0xe6150000
28#define FRQCRB 0xe6150004
29#define FRQCRC 0xe61500e0
30#define FRQCRD 0xe61500e4
31#define VCLKCR1 0xe6150008
32#define VCLKCR2 0xe615000c
33#define VCLKCR3 0xe615001c
34#define FMSICKCR 0xe6150010
35#define FMSOCKCR 0xe6150014
36#define FSIACKCR 0xe6150018
37#define FSIBCKCR 0xe6150090
38#define SUBCKCR 0xe6150080
39#define SPUCKCR 0xe6150084
40#define VOUCKCR 0xe6150088
41#define HDMICKCR 0xe6150094
42#define DSITCKCR 0xe6150060
43#define DSI0PCKCR 0xe6150064
44#define DSI1PCKCR 0xe6150098
45#define PLLC01CR 0xe6150028
46#define PLLC2CR 0xe615002c
47#define SMSTPCR0 0xe6150130
48#define SMSTPCR1 0xe6150134
49#define SMSTPCR2 0xe6150138
50#define SMSTPCR3 0xe615013c
51#define SMSTPCR4 0xe6150140
52
53/* Platforms must set frequency on their DV_CLKI pin */
54struct clk dv_clki_clk = {
55};
56
57/* Fixed 32 KHz root clock from EXTALR pin */
58static struct clk r_clk = {
59 .rate = 32768,
60};
61
62/*
63 * 26MHz default rate for the EXTAL1 root input clock.
64 * If needed, reset this with clk_set_rate() from the platform code.
65 */
66struct clk sh7372_extal1_clk = {
67 .rate = 26000000,
68};
69
70/*
71 * 48MHz default rate for the EXTAL2 root input clock.
72 * If needed, reset this with clk_set_rate() from the platform code.
73 */
74struct clk sh7372_extal2_clk = {
75 .rate = 48000000,
76};
77
78/* A fixed divide-by-2 block */
79static unsigned long div2_recalc(struct clk *clk)
80{
81 return clk->parent->rate / 2;
82}
83
84static struct clk_ops div2_clk_ops = {
85 .recalc = div2_recalc,
86};
87
88/* Divide dv_clki by two */
89struct clk dv_clki_div2_clk = {
90 .ops = &div2_clk_ops,
91 .parent = &dv_clki_clk,
92};
93
94/* Divide extal1 by two */
95static struct clk extal1_div2_clk = {
96 .ops = &div2_clk_ops,
97 .parent = &sh7372_extal1_clk,
98};
99
100/* Divide extal2 by two */
101static struct clk extal2_div2_clk = {
102 .ops = &div2_clk_ops,
103 .parent = &sh7372_extal2_clk,
104};
105
106/* Divide extal2 by four */
107static struct clk extal2_div4_clk = {
108 .ops = &div2_clk_ops,
109 .parent = &extal2_div2_clk,
110};
111
112/* PLLC0 and PLLC1 */
113static unsigned long pllc01_recalc(struct clk *clk)
114{
115 unsigned long mult = 1;
116
117 if (__raw_readl(PLLC01CR) & (1 << 14))
118 mult = (((__raw_readl(clk->enable_reg) >> 24) & 0x3f) + 1) * 2;
119
120 return clk->parent->rate * mult;
121}
122
123static struct clk_ops pllc01_clk_ops = {
124 .recalc = pllc01_recalc,
125};
126
127static struct clk pllc0_clk = {
128 .ops = &pllc01_clk_ops,
129 .flags = CLK_ENABLE_ON_INIT,
130 .parent = &extal1_div2_clk,
131 .enable_reg = (void __iomem *)FRQCRC,
132};
133
134static struct clk pllc1_clk = {
135 .ops = &pllc01_clk_ops,
136 .flags = CLK_ENABLE_ON_INIT,
137 .parent = &extal1_div2_clk,
138 .enable_reg = (void __iomem *)FRQCRA,
139};
140
141/* Divide PLLC1 by two */
142static struct clk pllc1_div2_clk = {
143 .ops = &div2_clk_ops,
144 .parent = &pllc1_clk,
145};
146
147/* PLLC2 */
148
149/* Indices are important - they are the actual src selecting values */
150static struct clk *pllc2_parent[] = {
151 [0] = &extal1_div2_clk,
152 [1] = &extal2_div2_clk,
153 [2] = &dv_clki_div2_clk,
154};
155
156/* Only multipliers 20 * 2 to 46 * 2 are valid, last entry for CPUFREQ_TABLE_END */
157static struct cpufreq_frequency_table pllc2_freq_table[29];
158
159static void pllc2_table_rebuild(struct clk *clk)
160{
161 int i;
162
163 /* Initialise PLLC2 frequency table */
164 for (i = 0; i < ARRAY_SIZE(pllc2_freq_table) - 2; i++) {
165 pllc2_freq_table[i].frequency = clk->parent->rate * (i + 20) * 2;
166 pllc2_freq_table[i].index = i;
167 }
168
169 /* This is a special entry - switching PLL off makes it a repeater */
170 pllc2_freq_table[i].frequency = clk->parent->rate;
171 pllc2_freq_table[i].index = i;
172
173 pllc2_freq_table[++i].frequency = CPUFREQ_TABLE_END;
174 pllc2_freq_table[i].index = i;
175}
176
177static unsigned long pllc2_recalc(struct clk *clk)
178{
179 unsigned long mult = 1;
180
181 pllc2_table_rebuild(clk);
182
183 /*
184 * If the PLL is off, mult == 1, clk->rate will be updated in
185 * pllc2_enable().
186 */
187 if (__raw_readl(PLLC2CR) & (1 << 31))
188 mult = (((__raw_readl(PLLC2CR) >> 24) & 0x3f) + 1) * 2;
189
190 return clk->parent->rate * mult;
191}
192
193static long pllc2_round_rate(struct clk *clk, unsigned long rate)
194{
195 return clk_rate_table_round(clk, clk->freq_table, rate);
196}
197
198static int pllc2_enable(struct clk *clk)
199{
200 int i;
201
202 __raw_writel(__raw_readl(PLLC2CR) | 0x80000000, PLLC2CR);
203
204 for (i = 0; i < 100; i++)
205 if (__raw_readl(PLLC2CR) & 0x80000000) {
206 clk->rate = pllc2_recalc(clk);
207 return 0;
208 }
209
210 pr_err("%s(): timeout!\n", __func__);
211
212 return -ETIMEDOUT;
213}
214
215static void pllc2_disable(struct clk *clk)
216{
217 __raw_writel(__raw_readl(PLLC2CR) & ~0x80000000, PLLC2CR);
218}
219
220static int pllc2_set_rate(struct clk *clk,
221 unsigned long rate, int algo_id)
222{
223 unsigned long value;
224 int idx;
225
226 idx = clk_rate_table_find(clk, clk->freq_table, rate);
227 if (idx < 0)
228 return idx;
229
230 if (rate == clk->parent->rate) {
231 pllc2_disable(clk);
232 return 0;
233 }
234
235 value = __raw_readl(PLLC2CR) & ~(0x3f << 24);
236
237 if (value & 0x80000000)
238 pllc2_disable(clk);
239
240 __raw_writel((value & ~0x80000000) | ((idx + 19) << 24), PLLC2CR);
241
242 if (value & 0x80000000)
243 return pllc2_enable(clk);
244
245 return 0;
246}
247
248static int pllc2_set_parent(struct clk *clk, struct clk *parent)
249{
250 u32 value;
251 int ret, i;
252
253 if (!clk->parent_table || !clk->parent_num)
254 return -EINVAL;
255
256 /* Search the parent */
257 for (i = 0; i < clk->parent_num; i++)
258 if (clk->parent_table[i] == parent)
259 break;
260
261 if (i == clk->parent_num)
262 return -ENODEV;
263
264 ret = clk_reparent(clk, parent);
265 if (ret < 0)
266 return ret;
267
268 value = __raw_readl(PLLC2CR) & ~(3 << 6);
269
270 __raw_writel(value | (i << 6), PLLC2CR);
271
272 /* Rebiuld the frequency table */
273 pllc2_table_rebuild(clk);
274
275 return 0;
276}
277
278static struct clk_ops pllc2_clk_ops = {
279 .recalc = pllc2_recalc,
280 .round_rate = pllc2_round_rate,
281 .set_rate = pllc2_set_rate,
282 .enable = pllc2_enable,
283 .disable = pllc2_disable,
284 .set_parent = pllc2_set_parent,
285};
286
287struct clk pllc2_clk = {
288 .ops = &pllc2_clk_ops,
289 .flags = CLK_ENABLE_ON_INIT,
290 .parent = &extal1_div2_clk,
291 .freq_table = pllc2_freq_table,
292 .parent_table = pllc2_parent,
293 .parent_num = ARRAY_SIZE(pllc2_parent),
294};
295
296static struct clk *main_clks[] = {
297 &dv_clki_clk,
298 &r_clk,
299 &sh7372_extal1_clk,
300 &sh7372_extal2_clk,
301 &dv_clki_div2_clk,
302 &extal1_div2_clk,
303 &extal2_div2_clk,
304 &extal2_div4_clk,
305 &pllc0_clk,
306 &pllc1_clk,
307 &pllc1_div2_clk,
308 &pllc2_clk,
309};
310
311static void div4_kick(struct clk *clk)
312{
313 unsigned long value;
314
315 /* set KICK bit in FRQCRB to update hardware setting */
316 value = __raw_readl(FRQCRB);
317 value |= (1 << 31);
318 __raw_writel(value, FRQCRB);
319}
320
321static int divisors[] = { 2, 3, 4, 6, 8, 12, 16, 18,
322 24, 32, 36, 48, 0, 72, 96, 0 };
323
324static struct clk_div_mult_table div4_div_mult_table = {
325 .divisors = divisors,
326 .nr_divisors = ARRAY_SIZE(divisors),
327};
328
329static struct clk_div4_table div4_table = {
330 .div_mult_table = &div4_div_mult_table,
331 .kick = div4_kick,
332};
333
334enum { DIV4_I, DIV4_ZG, DIV4_B, DIV4_M1, DIV4_CSIR,
335 DIV4_ZTR, DIV4_ZT, DIV4_ZX, DIV4_HP,
336 DIV4_ISPB, DIV4_S, DIV4_ZB, DIV4_ZB3, DIV4_CP,
337 DIV4_DDRP, DIV4_NR };
338
339#define DIV4(_reg, _bit, _mask, _flags) \
340 SH_CLK_DIV4(&pllc1_clk, _reg, _bit, _mask, _flags)
341
342static struct clk div4_clks[DIV4_NR] = {
343 [DIV4_I] = DIV4(FRQCRA, 20, 0x6fff, CLK_ENABLE_ON_INIT),
344 [DIV4_ZG] = DIV4(FRQCRA, 16, 0x6fff, CLK_ENABLE_ON_INIT),
345 [DIV4_B] = DIV4(FRQCRA, 8, 0x6fff, CLK_ENABLE_ON_INIT),
346 [DIV4_M1] = DIV4(FRQCRA, 4, 0x6fff, CLK_ENABLE_ON_INIT),
347 [DIV4_CSIR] = DIV4(FRQCRA, 0, 0x6fff, 0),
348 [DIV4_ZTR] = DIV4(FRQCRB, 20, 0x6fff, 0),
349 [DIV4_ZT] = DIV4(FRQCRB, 16, 0x6fff, 0),
350 [DIV4_ZX] = DIV4(FRQCRB, 12, 0x6fff, 0),
351 [DIV4_HP] = DIV4(FRQCRB, 4, 0x6fff, 0),
352 [DIV4_ISPB] = DIV4(FRQCRC, 20, 0x6fff, 0),
353 [DIV4_S] = DIV4(FRQCRC, 12, 0x6fff, 0),
354 [DIV4_ZB] = DIV4(FRQCRC, 8, 0x6fff, 0),
355 [DIV4_ZB3] = DIV4(FRQCRC, 4, 0x6fff, 0),
356 [DIV4_CP] = DIV4(FRQCRC, 0, 0x6fff, 0),
357 [DIV4_DDRP] = DIV4(FRQCRD, 0, 0x677c, 0),
358};
359
360enum { DIV6_VCK1, DIV6_VCK2, DIV6_VCK3, DIV6_FMSI, DIV6_FMSO,
361 DIV6_FSIA, DIV6_FSIB, DIV6_SUB, DIV6_SPU,
362 DIV6_VOU, DIV6_DSIT, DIV6_DSI0P, DIV6_DSI1P,
363 DIV6_NR };
364
365static struct clk div6_clks[DIV6_NR] = {
366 [DIV6_VCK1] = SH_CLK_DIV6(&pllc1_div2_clk, VCLKCR1, 0),
367 [DIV6_VCK2] = SH_CLK_DIV6(&pllc1_div2_clk, VCLKCR2, 0),
368 [DIV6_VCK3] = SH_CLK_DIV6(&pllc1_div2_clk, VCLKCR3, 0),
369 [DIV6_FMSI] = SH_CLK_DIV6(&pllc1_div2_clk, FMSICKCR, 0),
370 [DIV6_FMSO] = SH_CLK_DIV6(&pllc1_div2_clk, FMSOCKCR, 0),
371 [DIV6_FSIA] = SH_CLK_DIV6(&pllc1_div2_clk, FSIACKCR, 0),
372 [DIV6_FSIB] = SH_CLK_DIV6(&pllc1_div2_clk, FSIBCKCR, 0),
373 [DIV6_SUB] = SH_CLK_DIV6(&sh7372_extal2_clk, SUBCKCR, 0),
374 [DIV6_SPU] = SH_CLK_DIV6(&pllc1_div2_clk, SPUCKCR, 0),
375 [DIV6_VOU] = SH_CLK_DIV6(&pllc1_div2_clk, VOUCKCR, 0),
376 [DIV6_DSIT] = SH_CLK_DIV6(&pllc1_div2_clk, DSITCKCR, 0),
377 [DIV6_DSI0P] = SH_CLK_DIV6(&pllc1_div2_clk, DSI0PCKCR, 0),
378 [DIV6_DSI1P] = SH_CLK_DIV6(&pllc1_div2_clk, DSI1PCKCR, 0),
379};
380
381enum { DIV6_HDMI, DIV6_REPARENT_NR };
382
383/* Indices are important - they are the actual src selecting values */
384static struct clk *hdmi_parent[] = {
385 [0] = &pllc1_div2_clk,
386 [1] = &pllc2_clk,
387 [2] = &dv_clki_clk,
388 [3] = NULL, /* pllc2_div4 not implemented yet */
389};
390
391static struct clk div6_reparent_clks[DIV6_REPARENT_NR] = {
392 [DIV6_HDMI] = SH_CLK_DIV6_EXT(&pllc1_div2_clk, HDMICKCR, 0,
393 hdmi_parent, ARRAY_SIZE(hdmi_parent), 6, 2),
394};
395
396enum { MSTP001,
397 MSTP131, MSTP130,
398 MSTP129, MSTP128,
399 MSTP118, MSTP117, MSTP116,
400 MSTP106, MSTP101, MSTP100,
401 MSTP223,
402 MSTP207, MSTP206, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200,
403 MSTP329, MSTP328, MSTP323, MSTP322, MSTP314, MSTP313, MSTP312,
404 MSTP415, MSTP413, MSTP411, MSTP410, MSTP406, MSTP403,
405 MSTP_NR };
406
407#define MSTP(_parent, _reg, _bit, _flags) \
408 SH_CLK_MSTP32(_parent, _reg, _bit, _flags)
409
410static struct clk mstp_clks[MSTP_NR] = {
411 [MSTP001] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR0, 1, 0), /* IIC2 */
412 [MSTP131] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 31, 0), /* VEU3 */
413 [MSTP130] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 30, 0), /* VEU2 */
414 [MSTP129] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 29, 0), /* VEU1 */
415 [MSTP128] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 28, 0), /* VEU0 */
416 [MSTP118] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 18, 0), /* DSITX */
417 [MSTP117] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 17, 0), /* LCDC1 */
418 [MSTP116] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR1, 16, 0), /* IIC0 */
419 [MSTP106] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 6, 0), /* JPU */
420 [MSTP101] = MSTP(&div4_clks[DIV4_M1], SMSTPCR1, 1, 0), /* VPU */
421 [MSTP100] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 0, 0), /* LCDC0 */
422 [MSTP223] = MSTP(&div6_clks[DIV6_SPU], SMSTPCR2, 23, 0), /* SPU2 */
423 [MSTP207] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 7, 0), /* SCIFA5 */
424 [MSTP206] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 6, 0), /* SCIFB */
425 [MSTP204] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 4, 0), /* SCIFA0 */
426 [MSTP203] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 3, 0), /* SCIFA1 */
427 [MSTP202] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 2, 0), /* SCIFA2 */
428 [MSTP201] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 1, 0), /* SCIFA3 */
429 [MSTP200] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 0, 0), /* SCIFA4 */
430 [MSTP329] = MSTP(&r_clk, SMSTPCR3, 29, 0), /* CMT10 */
431 [MSTP328] = MSTP(&div6_clks[DIV6_SPU], SMSTPCR3, 28, CLK_ENABLE_ON_INIT), /* FSIA */
432 [MSTP323] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR3, 23, 0), /* IIC1 */
433 [MSTP322] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR3, 22, 0), /* USB0 */
434 [MSTP314] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 14, 0), /* SDHI0 */
435 [MSTP313] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 13, 0), /* SDHI1 */
436 [MSTP312] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 12, 0), /* MMC */
437 [MSTP415] = MSTP(&div4_clks[DIV4_HP], SMSTPCR4, 15, 0), /* SDHI2 */
438 [MSTP413] = MSTP(&pllc1_div2_clk, SMSTPCR4, 13, 0), /* HDMI */
439 [MSTP411] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR4, 11, 0), /* IIC3 */
440 [MSTP410] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR4, 10, 0), /* IIC4 */
441 [MSTP406] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR4, 6, 0), /* USB1 */
442 [MSTP403] = MSTP(&r_clk, SMSTPCR4, 3, 0), /* KEYSC */
443};
444
445#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
446#define CLKDEV_DEV_ID(_id, _clk) { .dev_id = _id, .clk = _clk }
447
448static struct clk_lookup lookups[] = {
449 /* main clocks */
450 CLKDEV_CON_ID("dv_clki_div2_clk", &dv_clki_div2_clk),
451 CLKDEV_CON_ID("r_clk", &r_clk),
452 CLKDEV_CON_ID("extal1", &sh7372_extal1_clk),
453 CLKDEV_CON_ID("extal2", &sh7372_extal2_clk),
454 CLKDEV_CON_ID("extal1_div2_clk", &extal1_div2_clk),
455 CLKDEV_CON_ID("extal2_div2_clk", &extal2_div2_clk),
456 CLKDEV_CON_ID("extal2_div4_clk", &extal2_div4_clk),
457 CLKDEV_CON_ID("pllc0_clk", &pllc0_clk),
458 CLKDEV_CON_ID("pllc1_clk", &pllc1_clk),
459 CLKDEV_CON_ID("pllc1_div2_clk", &pllc1_div2_clk),
460 CLKDEV_CON_ID("pllc2_clk", &pllc2_clk),
461
462 /* DIV4 clocks */
463 CLKDEV_CON_ID("i_clk", &div4_clks[DIV4_I]),
464 CLKDEV_CON_ID("zg_clk", &div4_clks[DIV4_ZG]),
465 CLKDEV_CON_ID("b_clk", &div4_clks[DIV4_B]),
466 CLKDEV_CON_ID("m1_clk", &div4_clks[DIV4_M1]),
467 CLKDEV_CON_ID("csir_clk", &div4_clks[DIV4_CSIR]),
468 CLKDEV_CON_ID("ztr_clk", &div4_clks[DIV4_ZTR]),
469 CLKDEV_CON_ID("zt_clk", &div4_clks[DIV4_ZT]),
470 CLKDEV_CON_ID("zx_clk", &div4_clks[DIV4_ZX]),
471 CLKDEV_CON_ID("hp_clk", &div4_clks[DIV4_HP]),
472 CLKDEV_CON_ID("ispb_clk", &div4_clks[DIV4_ISPB]),
473 CLKDEV_CON_ID("s_clk", &div4_clks[DIV4_S]),
474 CLKDEV_CON_ID("zb_clk", &div4_clks[DIV4_ZB]),
475 CLKDEV_CON_ID("zb3_clk", &div4_clks[DIV4_ZB3]),
476 CLKDEV_CON_ID("cp_clk", &div4_clks[DIV4_CP]),
477 CLKDEV_CON_ID("ddrp_clk", &div4_clks[DIV4_DDRP]),
478
479 /* DIV6 clocks */
480 CLKDEV_CON_ID("vck1_clk", &div6_clks[DIV6_VCK1]),
481 CLKDEV_CON_ID("vck2_clk", &div6_clks[DIV6_VCK2]),
482 CLKDEV_CON_ID("vck3_clk", &div6_clks[DIV6_VCK3]),
483 CLKDEV_CON_ID("fmsi_clk", &div6_clks[DIV6_FMSI]),
484 CLKDEV_CON_ID("fmso_clk", &div6_clks[DIV6_FMSO]),
485 CLKDEV_CON_ID("fsia_clk", &div6_clks[DIV6_FSIA]),
486 CLKDEV_CON_ID("fsib_clk", &div6_clks[DIV6_FSIB]),
487 CLKDEV_CON_ID("sub_clk", &div6_clks[DIV6_SUB]),
488 CLKDEV_CON_ID("spu_clk", &div6_clks[DIV6_SPU]),
489 CLKDEV_CON_ID("vou_clk", &div6_clks[DIV6_VOU]),
490 CLKDEV_CON_ID("hdmi_clk", &div6_reparent_clks[DIV6_HDMI]),
491 CLKDEV_CON_ID("dsit_clk", &div6_clks[DIV6_DSIT]),
492 CLKDEV_CON_ID("dsi0p_clk", &div6_clks[DIV6_DSI0P]),
493 CLKDEV_CON_ID("dsi1p_clk", &div6_clks[DIV6_DSI1P]),
494
495 /* MSTP32 clocks */
496 CLKDEV_DEV_ID("i2c-sh_mobile.2", &mstp_clks[MSTP001]), /* IIC2 */
497 CLKDEV_DEV_ID("uio_pdrv_genirq.4", &mstp_clks[MSTP131]), /* VEU3 */
498 CLKDEV_DEV_ID("uio_pdrv_genirq.3", &mstp_clks[MSTP130]), /* VEU2 */
499 CLKDEV_DEV_ID("uio_pdrv_genirq.2", &mstp_clks[MSTP129]), /* VEU1 */
500 CLKDEV_DEV_ID("uio_pdrv_genirq.1", &mstp_clks[MSTP128]), /* VEU0 */
501 CLKDEV_DEV_ID("sh-mipi-dsi.0", &mstp_clks[MSTP118]), /* DSITX */
502 CLKDEV_DEV_ID("sh_mobile_lcdc_fb.1", &mstp_clks[MSTP117]), /* LCDC1 */
503 CLKDEV_DEV_ID("i2c-sh_mobile.0", &mstp_clks[MSTP116]), /* IIC0 */
504 CLKDEV_DEV_ID("uio_pdrv_genirq.5", &mstp_clks[MSTP106]), /* JPU */
505 CLKDEV_DEV_ID("uio_pdrv_genirq.0", &mstp_clks[MSTP101]), /* VPU */
506 CLKDEV_DEV_ID("sh_mobile_lcdc_fb.0", &mstp_clks[MSTP100]), /* LCDC0 */
507 CLKDEV_DEV_ID("uio_pdrv_genirq.6", &mstp_clks[MSTP223]), /* SPU2DSP0 */
508 CLKDEV_DEV_ID("uio_pdrv_genirq.7", &mstp_clks[MSTP223]), /* SPU2DSP1 */
509 CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP207]), /* SCIFA5 */
510 CLKDEV_DEV_ID("sh-sci.6", &mstp_clks[MSTP206]), /* SCIFB */
511 CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP204]), /* SCIFA0 */
512 CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP203]), /* SCIFA1 */
513 CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP202]), /* SCIFA2 */
514 CLKDEV_DEV_ID("sh-sci.3", &mstp_clks[MSTP201]), /* SCIFA3 */
515 CLKDEV_DEV_ID("sh-sci.4", &mstp_clks[MSTP200]), /* SCIFA4 */
516 CLKDEV_CON_ID("cmt1", &mstp_clks[MSTP329]), /* CMT10 */
517 CLKDEV_DEV_ID("sh_fsi2", &mstp_clks[MSTP328]), /* FSI2 */
518 CLKDEV_DEV_ID("i2c-sh_mobile.1", &mstp_clks[MSTP323]), /* IIC1 */
519 CLKDEV_DEV_ID("r8a66597_hcd.0", &mstp_clks[MSTP323]), /* USB0 */
520 CLKDEV_DEV_ID("r8a66597_udc.0", &mstp_clks[MSTP323]), /* USB0 */
521 CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP314]), /* SDHI0 */
522 CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[MSTP313]), /* SDHI1 */
523 CLKDEV_DEV_ID("sh_mmcif.0", &mstp_clks[MSTP312]), /* MMC */
524 CLKDEV_DEV_ID("sh_mobile_sdhi.2", &mstp_clks[MSTP415]), /* SDHI2 */
525 CLKDEV_DEV_ID("sh-mobile-hdmi", &mstp_clks[MSTP413]), /* HDMI */
526 CLKDEV_DEV_ID("i2c-sh_mobile.3", &mstp_clks[MSTP411]), /* IIC3 */
527 CLKDEV_DEV_ID("i2c-sh_mobile.4", &mstp_clks[MSTP410]), /* IIC4 */
528 CLKDEV_DEV_ID("r8a66597_hcd.1", &mstp_clks[MSTP406]), /* USB1 */
529 CLKDEV_DEV_ID("r8a66597_udc.1", &mstp_clks[MSTP406]), /* USB1 */
530 CLKDEV_DEV_ID("sh_keysc.0", &mstp_clks[MSTP403]), /* KEYSC */
531 {.con_id = "ick", .dev_id = "sh-mobile-hdmi", .clk = &div6_reparent_clks[DIV6_HDMI]},
532};
533
534void __init sh7372_clock_init(void)
535{
536 int k, ret = 0;
537
538 for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
539 ret = clk_register(main_clks[k]);
540
541 if (!ret)
542 ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
543
544 if (!ret)
545 ret = sh_clk_div6_register(div6_clks, DIV6_NR);
546
547 if (!ret)
548 ret = sh_clk_div6_reparent_register(div6_reparent_clks, DIV6_NR);
549
550 if (!ret)
551 ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);
552
553 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
554
555 if (!ret)
556 clk_init();
557 else
558 panic("failed to setup sh7372 clocks\n");
559
560}
diff --git a/arch/arm/mach-shmobile/clock-sh7377.c b/arch/arm/mach-shmobile/clock-sh7377.c
new file mode 100644
index 000000000000..e007c28cf0a8
--- /dev/null
+++ b/arch/arm/mach-shmobile/clock-sh7377.c
@@ -0,0 +1,369 @@
1/*
2 * SH7377 clock framework support
3 *
4 * Copyright (C) 2010 Magnus Damm
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/io.h>
22#include <linux/sh_clk.h>
23#include <mach/common.h>
24#include <asm/clkdev.h>
25
26/* SH7377 registers */
27#define RTFRQCR 0xe6150000
28#define SYFRQCR 0xe6150004
29#define CMFRQCR 0xe61500E0
30#define VCLKCR1 0xe6150008
31#define VCLKCR2 0xe615000C
32#define VCLKCR3 0xe615001C
33#define FMSICKCR 0xe6150010
34#define FMSOCKCR 0xe6150014
35#define FSICKCR 0xe6150018
36#define PLLC1CR 0xe6150028
37#define PLLC2CR 0xe615002C
38#define SUBUSBCKCR 0xe6150080
39#define SPUCKCR 0xe6150084
40#define MSUCKCR 0xe6150088
41#define MVI3CKCR 0xe6150090
42#define HDMICKCR 0xe6150094
43#define MFCK1CR 0xe6150098
44#define MFCK2CR 0xe615009C
45#define DSITCKCR 0xe6150060
46#define DSIPCKCR 0xe6150064
47#define SMSTPCR0 0xe6150130
48#define SMSTPCR1 0xe6150134
49#define SMSTPCR2 0xe6150138
50#define SMSTPCR3 0xe615013C
51#define SMSTPCR4 0xe6150140
52
53/* Fixed 32 KHz root clock from EXTALR pin */
54static struct clk r_clk = {
55 .rate = 32768,
56};
57
58/*
59 * 26MHz default rate for the EXTALC1 root input clock.
60 * If needed, reset this with clk_set_rate() from the platform code.
61 */
62struct clk sh7377_extalc1_clk = {
63 .rate = 26666666,
64};
65
66/*
67 * 48MHz default rate for the EXTAL2 root input clock.
68 * If needed, reset this with clk_set_rate() from the platform code.
69 */
70struct clk sh7377_extal2_clk = {
71 .rate = 48000000,
72};
73
74/* A fixed divide-by-2 block */
75static unsigned long div2_recalc(struct clk *clk)
76{
77 return clk->parent->rate / 2;
78}
79
80static struct clk_ops div2_clk_ops = {
81 .recalc = div2_recalc,
82};
83
84/* Divide extalc1 by two */
85static struct clk extalc1_div2_clk = {
86 .ops = &div2_clk_ops,
87 .parent = &sh7377_extalc1_clk,
88};
89
90/* Divide extal2 by two */
91static struct clk extal2_div2_clk = {
92 .ops = &div2_clk_ops,
93 .parent = &sh7377_extal2_clk,
94};
95
96/* Divide extal2 by four */
97static struct clk extal2_div4_clk = {
98 .ops = &div2_clk_ops,
99 .parent = &extal2_div2_clk,
100};
101
102/* PLLC1 */
103static unsigned long pllc1_recalc(struct clk *clk)
104{
105 unsigned long mult = 1;
106
107 if (__raw_readl(PLLC1CR) & (1 << 14))
108 mult = (((__raw_readl(RTFRQCR) >> 24) & 0x3f) + 1) * 2;
109
110 return clk->parent->rate * mult;
111}
112
113static struct clk_ops pllc1_clk_ops = {
114 .recalc = pllc1_recalc,
115};
116
117static struct clk pllc1_clk = {
118 .ops = &pllc1_clk_ops,
119 .flags = CLK_ENABLE_ON_INIT,
120 .parent = &extalc1_div2_clk,
121};
122
123/* Divide PLLC1 by two */
124static struct clk pllc1_div2_clk = {
125 .ops = &div2_clk_ops,
126 .parent = &pllc1_clk,
127};
128
129/* PLLC2 */
130static unsigned long pllc2_recalc(struct clk *clk)
131{
132 unsigned long mult = 1;
133
134 if (__raw_readl(PLLC2CR) & (1 << 31))
135 mult = (((__raw_readl(PLLC2CR) >> 24) & 0x3f) + 1) * 2;
136
137 return clk->parent->rate * mult;
138}
139
140static struct clk_ops pllc2_clk_ops = {
141 .recalc = pllc2_recalc,
142};
143
144static struct clk pllc2_clk = {
145 .ops = &pllc2_clk_ops,
146 .flags = CLK_ENABLE_ON_INIT,
147 .parent = &extalc1_div2_clk,
148};
149
150static struct clk *main_clks[] = {
151 &r_clk,
152 &sh7377_extalc1_clk,
153 &sh7377_extal2_clk,
154 &extalc1_div2_clk,
155 &extal2_div2_clk,
156 &extal2_div4_clk,
157 &pllc1_clk,
158 &pllc1_div2_clk,
159 &pllc2_clk,
160};
161
162static void div4_kick(struct clk *clk)
163{
164 unsigned long value;
165
166 /* set KICK bit in SYFRQCR to update hardware setting */
167 value = __raw_readl(SYFRQCR);
168 value |= (1 << 31);
169 __raw_writel(value, SYFRQCR);
170}
171
172static int divisors[] = { 2, 3, 4, 6, 8, 12, 16, 18,
173 24, 32, 36, 48, 0, 72, 96, 0 };
174
175static struct clk_div_mult_table div4_div_mult_table = {
176 .divisors = divisors,
177 .nr_divisors = ARRAY_SIZE(divisors),
178};
179
180static struct clk_div4_table div4_table = {
181 .div_mult_table = &div4_div_mult_table,
182 .kick = div4_kick,
183};
184
185enum { DIV4_I, DIV4_ZG, DIV4_B, DIV4_M1, DIV4_CSIR,
186 DIV4_ZTR, DIV4_ZT, DIV4_Z, DIV4_HP,
187 DIV4_ZS, DIV4_ZB, DIV4_ZB3, DIV4_CP, DIV4_NR };
188
189#define DIV4(_reg, _bit, _mask, _flags) \
190 SH_CLK_DIV4(&pllc1_clk, _reg, _bit, _mask, _flags)
191
192static struct clk div4_clks[DIV4_NR] = {
193 [DIV4_I] = DIV4(RTFRQCR, 20, 0x6fff, CLK_ENABLE_ON_INIT),
194 [DIV4_ZG] = DIV4(RTFRQCR, 16, 0x6fff, CLK_ENABLE_ON_INIT),
195 [DIV4_B] = DIV4(RTFRQCR, 8, 0x6fff, CLK_ENABLE_ON_INIT),
196 [DIV4_M1] = DIV4(RTFRQCR, 4, 0x6fff, CLK_ENABLE_ON_INIT),
197 [DIV4_CSIR] = DIV4(RTFRQCR, 0, 0x6fff, 0),
198 [DIV4_ZTR] = DIV4(SYFRQCR, 20, 0x6fff, 0),
199 [DIV4_ZT] = DIV4(SYFRQCR, 16, 0x6fff, 0),
200 [DIV4_Z] = DIV4(SYFRQCR, 12, 0x6fff, 0),
201 [DIV4_HP] = DIV4(SYFRQCR, 4, 0x6fff, 0),
202 [DIV4_ZS] = DIV4(CMFRQCR, 12, 0x6fff, 0),
203 [DIV4_ZB] = DIV4(CMFRQCR, 8, 0x6fff, 0),
204 [DIV4_ZB3] = DIV4(CMFRQCR, 4, 0x6fff, 0),
205 [DIV4_CP] = DIV4(CMFRQCR, 0, 0x6fff, 0),
206};
207
208enum { DIV6_VCK1, DIV6_VCK2, DIV6_VCK3, DIV6_FMSI, DIV6_FMSO,
209 DIV6_FSI, DIV6_SUB, DIV6_SPU, DIV6_MSU, DIV6_MVI3, DIV6_HDMI,
210 DIV6_MF1, DIV6_MF2, DIV6_DSIT, DIV6_DSIP,
211 DIV6_NR };
212
213static struct clk div6_clks[] = {
214 [DIV6_VCK1] = SH_CLK_DIV6(&pllc1_div2_clk, VCLKCR1, 0),
215 [DIV6_VCK2] = SH_CLK_DIV6(&pllc1_div2_clk, VCLKCR2, 0),
216 [DIV6_VCK3] = SH_CLK_DIV6(&pllc1_div2_clk, VCLKCR3, 0),
217 [DIV6_FMSI] = SH_CLK_DIV6(&pllc1_div2_clk, FMSICKCR, 0),
218 [DIV6_FMSO] = SH_CLK_DIV6(&pllc1_div2_clk, FMSOCKCR, 0),
219 [DIV6_FSI] = SH_CLK_DIV6(&pllc1_div2_clk, FSICKCR, 0),
220 [DIV6_SUB] = SH_CLK_DIV6(&sh7377_extal2_clk, SUBUSBCKCR, 0),
221 [DIV6_SPU] = SH_CLK_DIV6(&pllc1_div2_clk, SPUCKCR, 0),
222 [DIV6_MSU] = SH_CLK_DIV6(&pllc1_div2_clk, MSUCKCR, 0),
223 [DIV6_MVI3] = SH_CLK_DIV6(&pllc1_div2_clk, MVI3CKCR, 0),
224 [DIV6_HDMI] = SH_CLK_DIV6(&pllc1_div2_clk, HDMICKCR, 0),
225 [DIV6_MF1] = SH_CLK_DIV6(&pllc1_div2_clk, MFCK1CR, 0),
226 [DIV6_MF2] = SH_CLK_DIV6(&pllc1_div2_clk, MFCK2CR, 0),
227 [DIV6_DSIT] = SH_CLK_DIV6(&pllc1_div2_clk, DSITCKCR, 0),
228 [DIV6_DSIP] = SH_CLK_DIV6(&pllc1_div2_clk, DSIPCKCR, 0),
229};
230
231enum { MSTP001,
232 MSTP131, MSTP130, MSTP129, MSTP128, MSTP116, MSTP106, MSTP101,
233 MSTP223, MSTP207, MSTP206, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200,
234 MSTP331, MSTP329, MSTP325, MSTP323, MSTP322,
235 MSTP315, MSTP314, MSTP313,
236 MSTP403,
237 MSTP_NR };
238
239#define MSTP(_parent, _reg, _bit, _flags) \
240 SH_CLK_MSTP32(_parent, _reg, _bit, _flags)
241
242static struct clk mstp_clks[] = {
243 [MSTP001] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR0, 1, 0), /* IIC2 */
244 [MSTP131] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 31, 0), /* VEU3 */
245 [MSTP130] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 30, 0), /* VEU2 */
246 [MSTP129] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 29, 0), /* VEU1 */
247 [MSTP128] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 28, 0), /* VEU0 */
248 [MSTP116] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR1, 16, 0), /* IIC0 */
249 [MSTP106] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 6, 0), /* JPU */
250 [MSTP101] = MSTP(&div4_clks[DIV4_M1], SMSTPCR1, 1, 0), /* VPU */
251 [MSTP223] = MSTP(&div6_clks[DIV6_SPU], SMSTPCR2, 23, 0), /* SPU2 */
252 [MSTP207] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 7, 0), /* SCIFA5 */
253 [MSTP206] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 6, 0), /* SCIFB */
254 [MSTP204] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 4, 0), /* SCIFA0 */
255 [MSTP203] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 3, 0), /* SCIFA1 */
256 [MSTP202] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 2, 0), /* SCIFA2 */
257 [MSTP201] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 1, 0), /* SCIFA3 */
258 [MSTP200] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 0, 0), /* SCIFA4 */
259 [MSTP331] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR3, 31, 0), /* SCIFA6 */
260 [MSTP329] = MSTP(&r_clk, SMSTPCR3, 29, 0), /* CMT10 */
261 [MSTP325] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR3, 25, 0), /* IRDA */
262 [MSTP323] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR3, 23, 0), /* IIC1 */
263 [MSTP322] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR3, 22, 0), /* USB0 */
264 [MSTP315] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 15, 0), /* FLCTL */
265 [MSTP314] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 14, 0), /* SDHI0 */
266 [MSTP313] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 13, 0), /* SDHI1 */
267 [MSTP403] = MSTP(&r_clk, SMSTPCR4, 3, 0), /* KEYSC */
268};
269
270#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
271#define CLKDEV_DEV_ID(_id, _clk) { .dev_id = _id, .clk = _clk }
272
273static struct clk_lookup lookups[] = {
274 /* main clocks */
275 CLKDEV_CON_ID("r_clk", &r_clk),
276 CLKDEV_CON_ID("extalc1", &sh7377_extalc1_clk),
277 CLKDEV_CON_ID("extal2", &sh7377_extal2_clk),
278 CLKDEV_CON_ID("extalc1_div2_clk", &extalc1_div2_clk),
279 CLKDEV_CON_ID("extal2_div2_clk", &extal2_div2_clk),
280 CLKDEV_CON_ID("extal2_div4_clk", &extal2_div4_clk),
281 CLKDEV_CON_ID("pllc1_clk", &pllc1_clk),
282 CLKDEV_CON_ID("pllc1_div2_clk", &pllc1_div2_clk),
283 CLKDEV_CON_ID("pllc2_clk", &pllc2_clk),
284
285 /* DIV4 clocks */
286 CLKDEV_CON_ID("i_clk", &div4_clks[DIV4_I]),
287 CLKDEV_CON_ID("zg_clk", &div4_clks[DIV4_ZG]),
288 CLKDEV_CON_ID("b_clk", &div4_clks[DIV4_B]),
289 CLKDEV_CON_ID("m1_clk", &div4_clks[DIV4_M1]),
290 CLKDEV_CON_ID("csir_clk", &div4_clks[DIV4_CSIR]),
291 CLKDEV_CON_ID("ztr_clk", &div4_clks[DIV4_ZTR]),
292 CLKDEV_CON_ID("zt_clk", &div4_clks[DIV4_ZT]),
293 CLKDEV_CON_ID("z_clk", &div4_clks[DIV4_Z]),
294 CLKDEV_CON_ID("hp_clk", &div4_clks[DIV4_HP]),
295 CLKDEV_CON_ID("zs_clk", &div4_clks[DIV4_ZS]),
296 CLKDEV_CON_ID("zb_clk", &div4_clks[DIV4_ZB]),
297 CLKDEV_CON_ID("zb3_clk", &div4_clks[DIV4_ZB3]),
298 CLKDEV_CON_ID("cp_clk", &div4_clks[DIV4_CP]),
299
300 /* DIV6 clocks */
301 CLKDEV_CON_ID("vck1_clk", &div6_clks[DIV6_VCK1]),
302 CLKDEV_CON_ID("vck2_clk", &div6_clks[DIV6_VCK2]),
303 CLKDEV_CON_ID("vck3_clk", &div6_clks[DIV6_VCK3]),
304 CLKDEV_CON_ID("fmsi_clk", &div6_clks[DIV6_FMSI]),
305 CLKDEV_CON_ID("fmso_clk", &div6_clks[DIV6_FMSO]),
306 CLKDEV_CON_ID("fsi_clk", &div6_clks[DIV6_FSI]),
307 CLKDEV_CON_ID("sub_clk", &div6_clks[DIV6_SUB]),
308 CLKDEV_CON_ID("spu_clk", &div6_clks[DIV6_SPU]),
309 CLKDEV_CON_ID("msu_clk", &div6_clks[DIV6_MSU]),
310 CLKDEV_CON_ID("mvi3_clk", &div6_clks[DIV6_MVI3]),
311 CLKDEV_CON_ID("hdmi_clk", &div6_clks[DIV6_HDMI]),
312 CLKDEV_CON_ID("mf1_clk", &div6_clks[DIV6_MF1]),
313 CLKDEV_CON_ID("mf2_clk", &div6_clks[DIV6_MF2]),
314 CLKDEV_CON_ID("dsit_clk", &div6_clks[DIV6_DSIT]),
315 CLKDEV_CON_ID("dsip_clk", &div6_clks[DIV6_DSIP]),
316
317 /* MSTP32 clocks */
318 CLKDEV_DEV_ID("i2c-sh_mobile.2", &mstp_clks[MSTP001]), /* IIC2 */
319 CLKDEV_DEV_ID("uio_pdrv_genirq.4", &mstp_clks[MSTP131]), /* VEU3 */
320 CLKDEV_DEV_ID("uio_pdrv_genirq.3", &mstp_clks[MSTP130]), /* VEU2 */
321 CLKDEV_DEV_ID("uio_pdrv_genirq.2", &mstp_clks[MSTP129]), /* VEU1 */
322 CLKDEV_DEV_ID("uio_pdrv_genirq.1", &mstp_clks[MSTP128]), /* VEU0 */
323 CLKDEV_DEV_ID("i2c-sh_mobile.0", &mstp_clks[MSTP116]), /* IIC0 */
324 CLKDEV_DEV_ID("uio_pdrv_genirq.5", &mstp_clks[MSTP106]), /* JPU */
325 CLKDEV_DEV_ID("uio_pdrv_genirq.0", &mstp_clks[MSTP101]), /* VPU */
326 CLKDEV_DEV_ID("uio_pdrv_genirq.6", &mstp_clks[MSTP223]), /* SPU2DSP0 */
327 CLKDEV_DEV_ID("uio_pdrv_genirq.7", &mstp_clks[MSTP223]), /* SPU2DSP1 */
328 CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP207]), /* SCIFA5 */
329 CLKDEV_DEV_ID("sh-sci.7", &mstp_clks[MSTP206]), /* SCIFB */
330 CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP204]), /* SCIFA0 */
331 CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP203]), /* SCIFA1 */
332 CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP202]), /* SCIFA2 */
333 CLKDEV_DEV_ID("sh-sci.3", &mstp_clks[MSTP201]), /* SCIFA3 */
334 CLKDEV_DEV_ID("sh-sci.4", &mstp_clks[MSTP200]), /* SCIFA4 */
335 CLKDEV_DEV_ID("sh-sci.6", &mstp_clks[MSTP331]), /* SCIFA6 */
336 CLKDEV_CON_ID("cmt1", &mstp_clks[MSTP329]), /* CMT10 */
337 CLKDEV_DEV_ID("sh_irda", &mstp_clks[MSTP325]), /* IRDA */
338 CLKDEV_DEV_ID("i2c-sh_mobile.1", &mstp_clks[MSTP323]), /* IIC1 */
339 CLKDEV_DEV_ID("r8a66597_hcd.0", &mstp_clks[MSTP322]), /* USBHS */
340 CLKDEV_DEV_ID("r8a66597_udc.0", &mstp_clks[MSTP322]), /* USBHS */
341 CLKDEV_DEV_ID("sh_flctl", &mstp_clks[MSTP315]), /* FLCTL */
342 CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP314]), /* SDHI0 */
343 CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[MSTP313]), /* SDHI1 */
344 CLKDEV_DEV_ID("sh_keysc.0", &mstp_clks[MSTP403]), /* KEYSC */
345};
346
347void __init sh7377_clock_init(void)
348{
349 int k, ret = 0;
350
351 for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
352 ret = clk_register(main_clks[k]);
353
354 if (!ret)
355 ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
356
357 if (!ret)
358 ret = sh_clk_div6_register(div6_clks, DIV6_NR);
359
360 if (!ret)
361 ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);
362
363 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
364
365 if (!ret)
366 clk_init();
367 else
368 panic("failed to setup sh7377 clocks\n");
369}
diff --git a/arch/arm/mach-shmobile/clock.c b/arch/arm/mach-shmobile/clock.c
new file mode 100644
index 000000000000..b7c705a213a2
--- /dev/null
+++ b/arch/arm/mach-shmobile/clock.c
@@ -0,0 +1,44 @@
1/*
2 * SH-Mobile Timer
3 *
4 * Copyright (C) 2010 Magnus Damm
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/sh_clk.h>
23
24int __init clk_init(void)
25{
26 /* Kick the child clocks.. */
27 recalculate_root_clocks();
28
29 /* Enable the necessary init clocks */
30 clk_enable_init_clocks();
31
32 return 0;
33}
34
35int __clk_get(struct clk *clk)
36{
37 return 1;
38}
39EXPORT_SYMBOL(__clk_get);
40
41void __clk_put(struct clk *clk)
42{
43}
44EXPORT_SYMBOL(__clk_put);
diff --git a/arch/arm/mach-shmobile/include/mach/common.h b/arch/arm/mach-shmobile/include/mach/common.h
index 57903605cc51..efeef778a875 100644
--- a/arch/arm/mach-shmobile/include/mach/common.h
+++ b/arch/arm/mach-shmobile/include/mach/common.h
@@ -3,21 +3,31 @@
3 3
4extern struct sys_timer shmobile_timer; 4extern struct sys_timer shmobile_timer;
5extern void shmobile_setup_console(void); 5extern void shmobile_setup_console(void);
6struct clk;
7extern int clk_init(void);
6 8
7extern void sh7367_init_irq(void); 9extern void sh7367_init_irq(void);
8extern void sh7367_add_early_devices(void); 10extern void sh7367_add_early_devices(void);
9extern void sh7367_add_standard_devices(void); 11extern void sh7367_add_standard_devices(void);
10extern void sh7367_clock_init(void); 12extern void sh7367_clock_init(void);
11extern void sh7367_pinmux_init(void); 13extern void sh7367_pinmux_init(void);
14extern struct clk sh7367_extalb1_clk;
15extern struct clk sh7367_extal2_clk;
12 16
13extern void sh7377_init_irq(void); 17extern void sh7377_init_irq(void);
14extern void sh7377_add_early_devices(void); 18extern void sh7377_add_early_devices(void);
15extern void sh7377_add_standard_devices(void); 19extern void sh7377_add_standard_devices(void);
20extern void sh7377_clock_init(void);
16extern void sh7377_pinmux_init(void); 21extern void sh7377_pinmux_init(void);
22extern struct clk sh7377_extalc1_clk;
23extern struct clk sh7377_extal2_clk;
17 24
18extern void sh7372_init_irq(void); 25extern void sh7372_init_irq(void);
19extern void sh7372_add_early_devices(void); 26extern void sh7372_add_early_devices(void);
20extern void sh7372_add_standard_devices(void); 27extern void sh7372_add_standard_devices(void);
28extern void sh7372_clock_init(void);
21extern void sh7372_pinmux_init(void); 29extern void sh7372_pinmux_init(void);
30extern struct clk sh7372_extal1_clk;
31extern struct clk sh7372_extal2_clk;
22 32
23#endif /* __ARCH_MACH_COMMON_H */ 33#endif /* __ARCH_MACH_COMMON_H */
diff --git a/arch/arm/mach-shmobile/include/mach/irqs.h b/arch/arm/mach-shmobile/include/mach/irqs.h
index 132256bb8c81..fa15b5f8a001 100644
--- a/arch/arm/mach-shmobile/include/mach/irqs.h
+++ b/arch/arm/mach-shmobile/include/mach/irqs.h
@@ -3,7 +3,13 @@
3 3
4#define NR_IRQS 512 4#define NR_IRQS 512
5 5
6/* INTCA */
6#define evt2irq(evt) (((evt) >> 5) - 16) 7#define evt2irq(evt) (((evt) >> 5) - 16)
7#define irq2evt(irq) (((irq) + 16) << 5) 8#define irq2evt(irq) (((irq) + 16) << 5)
8 9
10/* INTCS */
11#define INTCS_VECT_BASE 0x2200
12#define INTCS_VECT(n, vect) INTC_VECT((n), INTCS_VECT_BASE + (vect))
13#define intcs_evt2irq(evt) evt2irq(INTCS_VECT_BASE + (evt))
14
9#endif /* __ASM_MACH_IRQS_H */ 15#endif /* __ASM_MACH_IRQS_H */
diff --git a/arch/arm/mach-shmobile/include/mach/memory.h b/arch/arm/mach-shmobile/include/mach/memory.h
index e188183f4dce..377584e57e03 100644
--- a/arch/arm/mach-shmobile/include/mach/memory.h
+++ b/arch/arm/mach-shmobile/include/mach/memory.h
@@ -4,4 +4,7 @@
4#define PHYS_OFFSET UL(CONFIG_MEMORY_START) 4#define PHYS_OFFSET UL(CONFIG_MEMORY_START)
5#define MEM_SIZE UL(CONFIG_MEMORY_SIZE) 5#define MEM_SIZE UL(CONFIG_MEMORY_SIZE)
6 6
7/* DMA memory at 0xf6000000 - 0xffdfffff */
8#define CONSISTENT_DMA_SIZE (158 << 20)
9
7#endif /* __ASM_MACH_MEMORY_H */ 10#endif /* __ASM_MACH_MEMORY_H */
diff --git a/arch/arm/mach-shmobile/include/mach/sh7372.h b/arch/arm/mach-shmobile/include/mach/sh7372.h
index dc34f00c56b8..33e9700ded7e 100644
--- a/arch/arm/mach-shmobile/include/mach/sh7372.h
+++ b/arch/arm/mach-shmobile/include/mach/sh7372.h
@@ -11,6 +11,8 @@
11#ifndef __ASM_SH7372_H__ 11#ifndef __ASM_SH7372_H__
12#define __ASM_SH7372_H__ 12#define __ASM_SH7372_H__
13 13
14#include <linux/sh_clk.h>
15
14/* 16/*
15 * Pin Function Controller: 17 * Pin Function Controller:
16 * GPIO_FN_xx - GPIO used to select pin function 18 * GPIO_FN_xx - GPIO used to select pin function
@@ -431,4 +433,32 @@ enum {
431 GPIO_FN_SDENC_DV_CLKI, 433 GPIO_FN_SDENC_DV_CLKI,
432}; 434};
433 435
436/* DMA slave IDs */
437enum {
438 SHDMA_SLAVE_SCIF0_TX,
439 SHDMA_SLAVE_SCIF0_RX,
440 SHDMA_SLAVE_SCIF1_TX,
441 SHDMA_SLAVE_SCIF1_RX,
442 SHDMA_SLAVE_SCIF2_TX,
443 SHDMA_SLAVE_SCIF2_RX,
444 SHDMA_SLAVE_SCIF3_TX,
445 SHDMA_SLAVE_SCIF3_RX,
446 SHDMA_SLAVE_SCIF4_TX,
447 SHDMA_SLAVE_SCIF4_RX,
448 SHDMA_SLAVE_SCIF5_TX,
449 SHDMA_SLAVE_SCIF5_RX,
450 SHDMA_SLAVE_SCIF6_TX,
451 SHDMA_SLAVE_SCIF6_RX,
452 SHDMA_SLAVE_SDHI0_RX,
453 SHDMA_SLAVE_SDHI0_TX,
454 SHDMA_SLAVE_SDHI1_RX,
455 SHDMA_SLAVE_SDHI1_TX,
456 SHDMA_SLAVE_SDHI2_RX,
457 SHDMA_SLAVE_SDHI2_TX,
458};
459
460extern struct clk dv_clki_clk;
461extern struct clk dv_clki_div2_clk;
462extern struct clk pllc2_clk;
463
434#endif /* __ASM_SH7372_H__ */ 464#endif /* __ASM_SH7372_H__ */
diff --git a/arch/arm/mach-shmobile/include/mach/vmalloc.h b/arch/arm/mach-shmobile/include/mach/vmalloc.h
index fb3c4f1ab252..4aecf6e3a859 100644
--- a/arch/arm/mach-shmobile/include/mach/vmalloc.h
+++ b/arch/arm/mach-shmobile/include/mach/vmalloc.h
@@ -1,6 +1,7 @@
1#ifndef __ASM_MACH_VMALLOC_H 1#ifndef __ASM_MACH_VMALLOC_H
2#define __ASM_MACH_VMALLOC_H 2#define __ASM_MACH_VMALLOC_H
3 3
4#define VMALLOC_END (PAGE_OFFSET + 0x24000000) 4/* Vmalloc at ... - 0xe5ffffff */
5#define VMALLOC_END 0xe6000000
5 6
6#endif /* __ASM_MACH_VMALLOC_H */ 7#endif /* __ASM_MACH_VMALLOC_H */
diff --git a/arch/arm/mach-shmobile/intc-sh7367.c b/arch/arm/mach-shmobile/intc-sh7367.c
index 5ff70cadfc32..1a20c489b20d 100644
--- a/arch/arm/mach-shmobile/intc-sh7367.c
+++ b/arch/arm/mach-shmobile/intc-sh7367.c
@@ -75,7 +75,7 @@ enum {
75 ETM11, ARM11, USBHS, FLCTL, IIC1 75 ETM11, ARM11, USBHS, FLCTL, IIC1
76}; 76};
77 77
78static struct intc_vect intca_vectors[] = { 78static struct intc_vect intca_vectors[] __initdata = {
79 INTC_VECT(IRQ0A, 0x0200), INTC_VECT(IRQ1A, 0x0220), 79 INTC_VECT(IRQ0A, 0x0200), INTC_VECT(IRQ1A, 0x0220),
80 INTC_VECT(IRQ2A, 0x0240), INTC_VECT(IRQ3A, 0x0260), 80 INTC_VECT(IRQ2A, 0x0240), INTC_VECT(IRQ3A, 0x0260),
81 INTC_VECT(IRQ4A, 0x0280), INTC_VECT(IRQ5A, 0x02a0), 81 INTC_VECT(IRQ4A, 0x0280), INTC_VECT(IRQ5A, 0x02a0),
@@ -162,7 +162,7 @@ static struct intc_group intca_groups[] __initdata = {
162 INTC_GROUP(IIC1, IIC1_ALI1, IIC1_TACKI1, IIC1_WAITI1, IIC1_DTEI1), 162 INTC_GROUP(IIC1, IIC1_ALI1, IIC1_TACKI1, IIC1_WAITI1, IIC1_DTEI1),
163}; 163};
164 164
165static struct intc_mask_reg intca_mask_registers[] = { 165static struct intc_mask_reg intca_mask_registers[] __initdata = {
166 { 0xe6900040, 0xe6900060, 8, /* INTMSK00A / INTMSKCLR00A */ 166 { 0xe6900040, 0xe6900060, 8, /* INTMSK00A / INTMSKCLR00A */
167 { IRQ0A, IRQ1A, IRQ2A, IRQ3A, IRQ4A, IRQ5A, IRQ6A, IRQ7A } }, 167 { IRQ0A, IRQ1A, IRQ2A, IRQ3A, IRQ4A, IRQ5A, IRQ6A, IRQ7A } },
168 { 0xe6900044, 0xe6900064, 8, /* INTMSK10A / INTMSKCLR10A */ 168 { 0xe6900044, 0xe6900064, 8, /* INTMSK10A / INTMSKCLR10A */
@@ -211,7 +211,7 @@ static struct intc_mask_reg intca_mask_registers[] = {
211 MISTY, CMT3, RWDT1, RWDT0 } }, 211 MISTY, CMT3, RWDT1, RWDT0 } },
212}; 212};
213 213
214static struct intc_prio_reg intca_prio_registers[] = { 214static struct intc_prio_reg intca_prio_registers[] __initdata = {
215 { 0xe6900010, 0, 32, 4, /* INTPRI00A */ 215 { 0xe6900010, 0, 32, 4, /* INTPRI00A */
216 { IRQ0A, IRQ1A, IRQ2A, IRQ3A, IRQ4A, IRQ5A, IRQ6A, IRQ7A } }, 216 { IRQ0A, IRQ1A, IRQ2A, IRQ3A, IRQ4A, IRQ5A, IRQ6A, IRQ7A } },
217 { 0xe6900014, 0, 32, 4, /* INTPRI10A */ 217 { 0xe6900014, 0, 32, 4, /* INTPRI10A */
@@ -263,8 +263,178 @@ static struct intc_desc intca_desc __initdata = {
263 intca_sense_registers, intca_ack_registers), 263 intca_sense_registers, intca_ack_registers),
264}; 264};
265 265
266enum {
267 UNUSED_INTCS = 0,
268
269 INTCS,
270
271 /* interrupt sources INTCS */
272 VIO2_VEU0, VIO2_VEU1, VIO2_VEU2, VIO2_VEU3,
273 VIO3_VOU,
274 RTDMAC_1_DEI0, RTDMAC_1_DEI1, RTDMAC_1_DEI2, RTDMAC_1_DEI3,
275 VIO1_CEU, VIO1_BEU0, VIO1_BEU1, VIO1_BEU2,
276 VPU,
277 SGX530,
278 _2DDMAC_2DDM0, _2DDMAC_2DDM1, _2DDMAC_2DDM2, _2DDMAC_2DDM3,
279 IIC2_ALI2, IIC2_TACKI2, IIC2_WAITI2, IIC2_DTEI2,
280 IPMMU_IPMMUB, IPMMU_IPMMUS,
281 RTDMAC_2_DEI4, RTDMAC_2_DEI5, RTDMAC_2_DADERR,
282 MSIOF,
283 IIC0_ALI0, IIC0_TACKI0, IIC0_WAITI0, IIC0_DTEI0,
284 TMU_TUNI0, TMU_TUNI1, TMU_TUNI2,
285 CMT,
286 TSIF,
287 IPMMUI,
288 MVI3,
289 ICB,
290 PEP,
291 ASA,
292 BEM,
293 VE2HO,
294 HQE,
295 JPEG,
296 LCDC,
297
298 /* interrupt groups INTCS */
299 _2DDMAC, RTDMAC_1, RTDMAC_2, VEU, BEU, IIC0, IPMMU, IIC2,
300};
301
302static struct intc_vect intcs_vectors[] = {
303 INTCS_VECT(VIO2_VEU0, 0x700), INTCS_VECT(VIO2_VEU1, 0x720),
304 INTCS_VECT(VIO2_VEU2, 0x740), INTCS_VECT(VIO2_VEU3, 0x760),
305 INTCS_VECT(VIO3_VOU, 0x780),
306 INTCS_VECT(RTDMAC_1_DEI0, 0x800), INTCS_VECT(RTDMAC_1_DEI1, 0x820),
307 INTCS_VECT(RTDMAC_1_DEI2, 0x840), INTCS_VECT(RTDMAC_1_DEI3, 0x860),
308 INTCS_VECT(VIO1_CEU, 0x880), INTCS_VECT(VIO1_BEU0, 0x8a0),
309 INTCS_VECT(VIO1_BEU1, 0x8c0), INTCS_VECT(VIO1_BEU2, 0x8e0),
310 INTCS_VECT(VPU, 0x980),
311 INTCS_VECT(SGX530, 0x9e0),
312 INTCS_VECT(_2DDMAC_2DDM0, 0xa00), INTCS_VECT(_2DDMAC_2DDM1, 0xa20),
313 INTCS_VECT(_2DDMAC_2DDM2, 0xa40), INTCS_VECT(_2DDMAC_2DDM3, 0xa60),
314 INTCS_VECT(IIC2_ALI2, 0xa80), INTCS_VECT(IIC2_TACKI2, 0xaa0),
315 INTCS_VECT(IIC2_WAITI2, 0xac0), INTCS_VECT(IIC2_DTEI2, 0xae0),
316 INTCS_VECT(IPMMU_IPMMUB, 0xb20), INTCS_VECT(IPMMU_IPMMUS, 0xb60),
317 INTCS_VECT(RTDMAC_2_DEI4, 0xb80), INTCS_VECT(RTDMAC_2_DEI5, 0xba0),
318 INTCS_VECT(RTDMAC_2_DADERR, 0xbc0),
319 INTCS_VECT(MSIOF, 0xd20),
320 INTCS_VECT(IIC0_ALI0, 0xe00), INTCS_VECT(IIC0_TACKI0, 0xe20),
321 INTCS_VECT(IIC0_WAITI0, 0xe40), INTCS_VECT(IIC0_DTEI0, 0xe60),
322 INTCS_VECT(TMU_TUNI0, 0xe80), INTCS_VECT(TMU_TUNI1, 0xea0),
323 INTCS_VECT(TMU_TUNI2, 0xec0),
324 INTCS_VECT(CMT, 0xf00),
325 INTCS_VECT(TSIF, 0xf20),
326 INTCS_VECT(IPMMUI, 0xf60),
327 INTCS_VECT(MVI3, 0x420),
328 INTCS_VECT(ICB, 0x480),
329 INTCS_VECT(PEP, 0x4a0),
330 INTCS_VECT(ASA, 0x4c0),
331 INTCS_VECT(BEM, 0x4e0),
332 INTCS_VECT(VE2HO, 0x520),
333 INTCS_VECT(HQE, 0x540),
334 INTCS_VECT(JPEG, 0x560),
335 INTCS_VECT(LCDC, 0x580),
336
337 INTC_VECT(INTCS, 0xf80),
338};
339
340static struct intc_group intcs_groups[] __initdata = {
341 INTC_GROUP(_2DDMAC, _2DDMAC_2DDM0, _2DDMAC_2DDM1,
342 _2DDMAC_2DDM2, _2DDMAC_2DDM3),
343 INTC_GROUP(RTDMAC_1, RTDMAC_1_DEI0, RTDMAC_1_DEI1,
344 RTDMAC_1_DEI2, RTDMAC_1_DEI3),
345 INTC_GROUP(RTDMAC_2, RTDMAC_2_DEI4, RTDMAC_2_DEI5, RTDMAC_2_DADERR),
346 INTC_GROUP(VEU, VIO2_VEU0, VIO2_VEU1, VIO2_VEU2, VIO2_VEU3),
347 INTC_GROUP(BEU, VIO1_BEU0, VIO1_BEU1, VIO1_BEU2),
348 INTC_GROUP(IIC0, IIC0_ALI0, IIC0_TACKI0, IIC0_WAITI0, IIC0_DTEI0),
349 INTC_GROUP(IPMMU, IPMMU_IPMMUS, IPMMU_IPMMUB),
350 INTC_GROUP(IIC2, IIC2_ALI2, IIC2_TACKI2, IIC2_WAITI2, IIC2_DTEI2),
351};
352
353static struct intc_mask_reg intcs_mask_registers[] = {
354 { 0xffd20184, 0xffd201c4, 8, /* IMR1SA / IMCR1SA */
355 { VIO1_BEU2, VIO1_BEU1, VIO1_BEU0, VIO1_CEU,
356 VIO2_VEU3, VIO2_VEU2, VIO2_VEU1, VIO2_VEU0 } },
357 { 0xffd20188, 0xffd201c8, 8, /* IMR2SA / IMCR2SA */
358 { VIO3_VOU, 0, VE2HO, VPU,
359 0, 0, 0, 0 } },
360 { 0xffd2018c, 0xffd201cc, 8, /* IMR3SA / IMCR3SA */
361 { _2DDMAC_2DDM3, _2DDMAC_2DDM2, _2DDMAC_2DDM1, _2DDMAC_2DDM0,
362 BEM, ASA, PEP, ICB } },
363 { 0xffd20190, 0xffd201d0, 8, /* IMR4SA / IMCR4SA */
364 { 0, 0, MVI3, 0,
365 JPEG, HQE, 0, LCDC } },
366 { 0xffd20194, 0xffd201d4, 8, /* IMR5SA / IMCR5SA */
367 { 0, RTDMAC_2_DADERR, RTDMAC_2_DEI5, RTDMAC_2_DEI4,
368 RTDMAC_1_DEI3, RTDMAC_1_DEI2, RTDMAC_1_DEI1, RTDMAC_1_DEI0 } },
369 { 0xffd20198, 0xffd201d8, 8, /* IMR6SA / IMCR6SA */
370 { 0, 0, MSIOF, 0,
371 SGX530, 0, 0, 0 } },
372 { 0xffd2019c, 0xffd201dc, 8, /* IMR7SA / IMCR7SA */
373 { 0, TMU_TUNI2, TMU_TUNI1, TMU_TUNI0,
374 0, 0, 0, 0 } },
375 { 0xffd201a4, 0xffd201e4, 8, /* IMR9SA / IMCR9SA */
376 { 0, 0, 0, CMT,
377 IIC2_DTEI2, IIC2_WAITI2, IIC2_TACKI2, IIC2_ALI2 } },
378 { 0xffd201a8, 0xffd201e8, 8, /* IMR10SA / IMCR10SA */
379 { IPMMU_IPMMUS, 0, IPMMU_IPMMUB, 0,
380 0, 0, 0, 0 } },
381 { 0xffd201ac, 0xffd201ec, 8, /* IMR11SA / IMCR11SA */
382 { IIC0_DTEI0, IIC0_WAITI0, IIC0_TACKI0, IIC0_ALI0,
383 0, 0, IPMMUI, TSIF } },
384 { 0xffd20104, 0, 16, /* INTAMASK */
385 { 0, 0, 0, 0, 0, 0, 0, 0,
386 0, 0, 0, 0, 0, 0, 0, INTCS } },
387};
388
389/* Priority is needed for INTCA to receive the INTCS interrupt */
390static struct intc_prio_reg intcs_prio_registers[] = {
391 { 0xffd20000, 0, 16, 4, /* IPRAS */ { 0, MVI3, _2DDMAC, ICB } },
392 { 0xffd20004, 0, 16, 4, /* IPRBS */ { JPEG, LCDC, 0, 0 } },
393 { 0xffd20008, 0, 16, 4, /* IPRCS */ { BBIF2, 0, 0, 0 } },
394 { 0xffd20010, 0, 16, 4, /* IPRES */ { RTDMAC_1, VIO1_CEU, 0, VPU } },
395 { 0xffd20014, 0, 16, 4, /* IPRFS */ { 0, RTDMAC_2, 0, CMT } },
396 { 0xffd20018, 0, 16, 4, /* IPRGS */ { TMU_TUNI0, TMU_TUNI1,
397 TMU_TUNI2, 0 } },
398 { 0xffd2001c, 0, 16, 4, /* IPRHS */ { 0, VIO3_VOU, VEU, BEU } },
399 { 0xffd20020, 0, 16, 4, /* IPRIS */ { 0, MSIOF, TSIF, IIC0 } },
400 { 0xffd20024, 0, 16, 4, /* IPRJS */ { 0, SGX530, 0, 0 } },
401 { 0xffd20028, 0, 16, 4, /* IPRKS */ { BEM, ASA, IPMMUI, PEP } },
402 { 0xffd2002c, 0, 16, 4, /* IPRLS */ { IPMMU, 0, VE2HO, HQE } },
403 { 0xffd20030, 0, 16, 4, /* IPRMS */ { IIC2, 0, 0, 0 } },
404};
405
406static struct resource intcs_resources[] __initdata = {
407 [0] = {
408 .start = 0xffd20000,
409 .end = 0xffd2ffff,
410 .flags = IORESOURCE_MEM,
411 }
412};
413
414static struct intc_desc intcs_desc __initdata = {
415 .name = "sh7367-intcs",
416 .resource = intcs_resources,
417 .num_resources = ARRAY_SIZE(intcs_resources),
418 .hw = INTC_HW_DESC(intcs_vectors, intcs_groups, intcs_mask_registers,
419 intcs_prio_registers, NULL, NULL),
420};
421
422static void intcs_demux(unsigned int irq, struct irq_desc *desc)
423{
424 void __iomem *reg = (void *)get_irq_data(irq);
425 unsigned int evtcodeas = ioread32(reg);
426
427 generic_handle_irq(intcs_evt2irq(evtcodeas));
428}
429
266void __init sh7367_init_irq(void) 430void __init sh7367_init_irq(void)
267{ 431{
268 /* INTCA */ 432 void __iomem *intevtsa = ioremap_nocache(0xffd20100, PAGE_SIZE);
433
269 register_intc_controller(&intca_desc); 434 register_intc_controller(&intca_desc);
435 register_intc_controller(&intcs_desc);
436
437 /* demux using INTEVTSA */
438 set_irq_data(evt2irq(0xf80), (void *)intevtsa);
439 set_irq_chained_handler(evt2irq(0xf80), intcs_demux);
270} 440}
diff --git a/arch/arm/mach-shmobile/intc-sh7372.c b/arch/arm/mach-shmobile/intc-sh7372.c
index 3ce9d9bd5899..e3551b56cd03 100644
--- a/arch/arm/mach-shmobile/intc-sh7372.c
+++ b/arch/arm/mach-shmobile/intc-sh7372.c
@@ -319,17 +319,17 @@ static struct intc_prio_reg intca_prio_registers[] __initdata = {
319 { 0xe6950034, 0, 16, 4, /* IPRNA3 */ { AP_ARM2, 0, 0, 0 } }, 319 { 0xe6950034, 0, 16, 4, /* IPRNA3 */ { AP_ARM2, 0, 0, 0 } },
320 { 0xe6950038, 0, 16, 4, /* IPROA3 */ { MFIS2, CPORTR2S, 320 { 0xe6950038, 0, 16, 4, /* IPROA3 */ { MFIS2, CPORTR2S,
321 CMT14, CMT15 } }, 321 CMT14, CMT15 } },
322 { 0xe694003c, 0, 16, 4, /* IPRPA3 */ { 0, 0, 322 { 0xe695003c, 0, 16, 4, /* IPRPA3 */ { 0, 0,
323 MMC_MMC_ERR, MMC_MMC_NOR } }, 323 MMC_MMC_ERR, MMC_MMC_NOR } },
324 { 0xe6940040, 0, 16, 4, /* IPRQA3 */ { IIC4_ALI4, IIC4_TACKI4, 324 { 0xe6950040, 0, 16, 4, /* IPRQA3 */ { IIC4_ALI4, IIC4_TACKI4,
325 IIC4_WAITI4, IIC4_DTEI4 } }, 325 IIC4_WAITI4, IIC4_DTEI4 } },
326 { 0xe6940044, 0, 16, 4, /* IPRRA3 */ { IIC3_ALI3, IIC3_TACKI3, 326 { 0xe6950044, 0, 16, 4, /* IPRRA3 */ { IIC3_ALI3, IIC3_TACKI3,
327 IIC3_WAITI3, IIC3_DTEI3 } }, 327 IIC3_WAITI3, IIC3_DTEI3 } },
328 { 0xe6940048, 0, 16, 4, /* IPRSA3 */ { 0/*ERI*/, 0/*RXI*/, 328 { 0xe6950048, 0, 16, 4, /* IPRSA3 */ { 0/*ERI*/, 0/*RXI*/,
329 0/*TXI*/, 0/*TEI*/} }, 329 0/*TXI*/, 0/*TEI*/} },
330 { 0xe694004c, 0, 16, 4, /* IPRTA3 */ { USB0_USB0I1, USB0_USB0I0, 330 { 0xe695004c, 0, 16, 4, /* IPRTA3 */ { USB0_USB0I1, USB0_USB0I0,
331 USB1_USB1I1, USB1_USB1I0 } }, 331 USB1_USB1I1, USB1_USB1I0 } },
332 { 0xe6940050, 0, 16, 4, /* IPRUA3 */ { USBHSDMAC1_USHDMI, 0, 0, 0 } }, 332 { 0xe6950050, 0, 16, 4, /* IPRUA3 */ { USBHSDMAC1_USHDMI, 0, 0, 0 } },
333}; 333};
334 334
335static struct intc_sense_reg intca_sense_registers[] __initdata = { 335static struct intc_sense_reg intca_sense_registers[] __initdata = {
@@ -363,7 +363,227 @@ static struct intc_desc intca_desc __initdata = {
363 intca_sense_registers, intca_ack_registers), 363 intca_sense_registers, intca_ack_registers),
364}; 364};
365 365
366enum {
367 UNUSED_INTCS = 0,
368
369 INTCS,
370
371 /* interrupt sources INTCS */
372 VEU_VEU0, VEU_VEU1, VEU_VEU2, VEU_VEU3,
373 RTDMAC_1_DEI0, RTDMAC_1_DEI1, RTDMAC_1_DEI2, RTDMAC_1_DEI3,
374 CEU, BEU_BEU0, BEU_BEU1, BEU_BEU2,
375 VPU,
376 TSIF1,
377 _3DG_SGX530,
378 _2DDMAC,
379 IIC2_ALI2, IIC2_TACKI2, IIC2_WAITI2, IIC2_DTEI2,
380 IPMMU_IPMMUR, IPMMU_IPMMUR2,
381 RTDMAC_2_DEI4, RTDMAC_2_DEI5, RTDMAC_2_DADERR,
382 MSIOF,
383 IIC0_ALI0, IIC0_TACKI0, IIC0_WAITI0, IIC0_DTEI0,
384 TMU_TUNI0, TMU_TUNI1, TMU_TUNI2,
385 CMT0,
386 TSIF0,
387 LMB,
388 CTI,
389 ICB,
390 JPU_JPEG,
391 LCDC,
392 LCRC,
393 RTDMAC2_1_DEI0, RTDMAC2_1_DEI1, RTDMAC2_1_DEI2, RTDMAC2_1_DEI3,
394 RTDMAC2_2_DEI4, RTDMAC2_2_DEI5, RTDMAC2_2_DADERR,
395 ISP,
396 LCDC1,
397 CSIRX,
398 DSITX_DSITX0,
399 DSITX_DSITX1,
400 TMU1_TUNI0, TMU1_TUNI1, TMU1_TUNI2,
401 CMT4,
402 DSITX1_DSITX1_0,
403 DSITX1_DSITX1_1,
404 CPORTS2R,
405 JPU6E,
406
407 /* interrupt groups INTCS */
408 RTDMAC_1, RTDMAC_2, VEU, BEU, IIC0, IPMMU, IIC2,
409 RTDMAC2_1, RTDMAC2_2, TMU1, DSITX,
410};
411
412static struct intc_vect intcs_vectors[] = {
413 INTCS_VECT(VEU_VEU0, 0x700), INTCS_VECT(VEU_VEU1, 0x720),
414 INTCS_VECT(VEU_VEU2, 0x740), INTCS_VECT(VEU_VEU3, 0x760),
415 INTCS_VECT(RTDMAC_1_DEI0, 0x800), INTCS_VECT(RTDMAC_1_DEI1, 0x820),
416 INTCS_VECT(RTDMAC_1_DEI2, 0x840), INTCS_VECT(RTDMAC_1_DEI3, 0x860),
417 INTCS_VECT(CEU, 0x880), INTCS_VECT(BEU_BEU0, 0x8a0),
418 INTCS_VECT(BEU_BEU1, 0x8c0), INTCS_VECT(BEU_BEU2, 0x8e0),
419 INTCS_VECT(VPU, 0x980),
420 INTCS_VECT(TSIF1, 0x9a0),
421 INTCS_VECT(_3DG_SGX530, 0x9e0),
422 INTCS_VECT(_2DDMAC, 0xa00),
423 INTCS_VECT(IIC2_ALI2, 0xa80), INTCS_VECT(IIC2_TACKI2, 0xaa0),
424 INTCS_VECT(IIC2_WAITI2, 0xac0), INTCS_VECT(IIC2_DTEI2, 0xae0),
425 INTCS_VECT(IPMMU_IPMMUR, 0xb00), INTCS_VECT(IPMMU_IPMMUR2, 0xb20),
426 INTCS_VECT(RTDMAC_2_DEI4, 0xb80), INTCS_VECT(RTDMAC_2_DEI5, 0xba0),
427 INTCS_VECT(RTDMAC_2_DADERR, 0xbc0),
428 INTCS_VECT(IIC0_ALI0, 0xe00), INTCS_VECT(IIC0_TACKI0, 0xe20),
429 INTCS_VECT(IIC0_WAITI0, 0xe40), INTCS_VECT(IIC0_DTEI0, 0xe60),
430 INTCS_VECT(TMU_TUNI0, 0xe80), INTCS_VECT(TMU_TUNI1, 0xea0),
431 INTCS_VECT(TMU_TUNI2, 0xec0),
432 INTCS_VECT(CMT0, 0xf00),
433 INTCS_VECT(TSIF0, 0xf20),
434 INTCS_VECT(LMB, 0xf60),
435 INTCS_VECT(CTI, 0x400),
436 INTCS_VECT(ICB, 0x480),
437 INTCS_VECT(JPU_JPEG, 0x560),
438 INTCS_VECT(LCDC, 0x580),
439 INTCS_VECT(LCRC, 0x5a0),
440 INTCS_VECT(RTDMAC2_1_DEI0, 0x1300), INTCS_VECT(RTDMAC2_1_DEI1, 0x1320),
441 INTCS_VECT(RTDMAC2_1_DEI2, 0x1340), INTCS_VECT(RTDMAC2_1_DEI3, 0x1360),
442 INTCS_VECT(RTDMAC2_2_DEI4, 0x1380), INTCS_VECT(RTDMAC2_2_DEI5, 0x13a0),
443 INTCS_VECT(RTDMAC2_2_DADERR, 0x13c0),
444 INTCS_VECT(ISP, 0x1720),
445 INTCS_VECT(LCDC1, 0x1780),
446 INTCS_VECT(CSIRX, 0x17a0),
447 INTCS_VECT(DSITX_DSITX0, 0x17c0),
448 INTCS_VECT(DSITX_DSITX1, 0x17e0),
449 INTCS_VECT(TMU1_TUNI0, 0x1900), INTCS_VECT(TMU1_TUNI1, 0x1920),
450 INTCS_VECT(TMU1_TUNI2, 0x1940),
451 INTCS_VECT(CMT4, 0x1980),
452 INTCS_VECT(DSITX1_DSITX1_0, 0x19a0),
453 INTCS_VECT(DSITX1_DSITX1_1, 0x19c0),
454 INTCS_VECT(CPORTS2R, 0x1a20),
455 INTCS_VECT(JPU6E, 0x1a80),
456
457 INTC_VECT(INTCS, 0xf80),
458};
459
460static struct intc_group intcs_groups[] __initdata = {
461 INTC_GROUP(RTDMAC_1, RTDMAC_1_DEI0, RTDMAC_1_DEI1,
462 RTDMAC_1_DEI2, RTDMAC_1_DEI3),
463 INTC_GROUP(RTDMAC_2, RTDMAC_2_DEI4, RTDMAC_2_DEI5, RTDMAC_2_DADERR),
464 INTC_GROUP(VEU, VEU_VEU0, VEU_VEU1, VEU_VEU2, VEU_VEU3),
465 INTC_GROUP(BEU, BEU_BEU0, BEU_BEU1, BEU_BEU2),
466 INTC_GROUP(IIC0, IIC0_ALI0, IIC0_TACKI0, IIC0_WAITI0, IIC0_DTEI0),
467 INTC_GROUP(IPMMU, IPMMU_IPMMUR, IPMMU_IPMMUR2),
468 INTC_GROUP(IIC2, IIC2_ALI2, IIC2_TACKI2, IIC2_WAITI2, IIC2_DTEI2),
469 INTC_GROUP(RTDMAC2_1, RTDMAC2_1_DEI0, RTDMAC2_1_DEI1,
470 RTDMAC2_1_DEI2, RTDMAC2_1_DEI3),
471 INTC_GROUP(RTDMAC2_2, RTDMAC2_2_DEI4,
472 RTDMAC2_2_DEI5, RTDMAC2_2_DADERR),
473 INTC_GROUP(TMU1, TMU1_TUNI2, TMU1_TUNI1, TMU1_TUNI0),
474 INTC_GROUP(DSITX, DSITX_DSITX0, DSITX_DSITX1),
475};
476
477static struct intc_mask_reg intcs_mask_registers[] = {
478 { 0xffd20184, 0xffd201c4, 8, /* IMR1SA / IMCR1SA */
479 { BEU_BEU2, BEU_BEU1, BEU_BEU0, CEU,
480 VEU_VEU3, VEU_VEU2, VEU_VEU1, VEU_VEU0 } },
481 { 0xffd20188, 0xffd201c8, 8, /* IMR2SA / IMCR2SA */
482 { 0, 0, 0, VPU,
483 0, 0, 0, 0 } },
484 { 0xffd2018c, 0xffd201cc, 8, /* IMR3SA / IMCR3SA */
485 { 0, 0, 0, _2DDMAC,
486 0, 0, 0, ICB } },
487 { 0xffd20190, 0xffd201d0, 8, /* IMR4SA / IMCR4SA */
488 { 0, 0, 0, CTI,
489 JPU_JPEG, 0, LCRC, LCDC } },
490 { 0xffd20194, 0xffd201d4, 8, /* IMR5SA / IMCR5SA */
491 { 0, RTDMAC_2_DADERR, RTDMAC_2_DEI5, RTDMAC_2_DEI4,
492 RTDMAC_1_DEI3, RTDMAC_1_DEI2, RTDMAC_1_DEI1, RTDMAC_1_DEI0 } },
493 { 0xffd20198, 0xffd201d8, 8, /* IMR6SA / IMCR6SA */
494 { 0, 0, MSIOF, 0,
495 _3DG_SGX530, 0, 0, 0 } },
496 { 0xffd2019c, 0xffd201dc, 8, /* IMR7SA / IMCR7SA */
497 { 0, TMU_TUNI2, TMU_TUNI1, TMU_TUNI0,
498 0, 0, 0, 0 } },
499 { 0xffd201a4, 0xffd201e4, 8, /* IMR9SA / IMCR9SA */
500 { 0, 0, 0, CMT0,
501 IIC2_DTEI2, IIC2_WAITI2, IIC2_TACKI2, IIC2_ALI2 } },
502 { 0xffd201a8, 0xffd201e8, 8, /* IMR10SA / IMCR10SA */
503 { 0, 0, IPMMU_IPMMUR2, IPMMU_IPMMUR,
504 0, 0, 0, 0 } },
505 { 0xffd201ac, 0xffd201ec, 8, /* IMR11SA / IMCR11SA */
506 { IIC0_DTEI0, IIC0_WAITI0, IIC0_TACKI0, IIC0_ALI0,
507 0, TSIF1, LMB, TSIF0 } },
508 { 0xffd50180, 0xffd501c0, 8, /* IMR0SA3 / IMCR0SA3 */
509 { 0, RTDMAC2_2_DADERR, RTDMAC2_2_DEI5, RTDMAC2_2_DEI4,
510 RTDMAC2_1_DEI3, RTDMAC2_1_DEI2, RTDMAC2_1_DEI1, RTDMAC2_1_DEI0 } },
511 { 0xffd50190, 0xffd501d0, 8, /* IMR4SA3 / IMCR4SA3 */
512 { 0, ISP, 0, 0,
513 LCDC1, CSIRX, DSITX_DSITX0, DSITX_DSITX1 } },
514 { 0xffd50198, 0xffd501d8, 8, /* IMR6SA3 / IMCR6SA3 */
515 { 0, TMU1_TUNI2, TMU1_TUNI1, TMU1_TUNI0,
516 CMT4, DSITX1_DSITX1_0, DSITX1_DSITX1_1, 0 } },
517 { 0xffd5019c, 0xffd501dc, 8, /* IMR7SA3 / IMCR7SA3 */
518 { 0, CPORTS2R, 0, 0,
519 JPU6E, 0, 0, 0 } },
520 { 0xffd20104, 0, 16, /* INTAMASK */
521 { 0, 0, 0, 0, 0, 0, 0, 0,
522 0, 0, 0, 0, 0, 0, 0, INTCS } },
523};
524
525/* Priority is needed for INTCA to receive the INTCS interrupt */
526static struct intc_prio_reg intcs_prio_registers[] = {
527 { 0xffd20000, 0, 16, 4, /* IPRAS */ { CTI, 0, _2DDMAC, ICB } },
528 { 0xffd20004, 0, 16, 4, /* IPRBS */ { JPU_JPEG, LCDC, 0, LCRC } },
529 { 0xffd20010, 0, 16, 4, /* IPRES */ { RTDMAC_1, CEU, 0, VPU } },
530 { 0xffd20014, 0, 16, 4, /* IPRFS */ { 0, RTDMAC_2, 0, CMT0 } },
531 { 0xffd20018, 0, 16, 4, /* IPRGS */ { TMU_TUNI0, TMU_TUNI1,
532 TMU_TUNI2, TSIF1 } },
533 { 0xffd2001c, 0, 16, 4, /* IPRHS */ { 0, 0, VEU, BEU } },
534 { 0xffd20020, 0, 16, 4, /* IPRIS */ { 0, MSIOF, TSIF0, IIC0 } },
535 { 0xffd20024, 0, 16, 4, /* IPRJS */ { 0, _3DG_SGX530, 0, 0 } },
536 { 0xffd20028, 0, 16, 4, /* IPRKS */ { 0, 0, LMB, 0 } },
537 { 0xffd2002c, 0, 16, 4, /* IPRLS */ { IPMMU, 0, 0, 0 } },
538 { 0xffd20030, 0, 16, 4, /* IPRMS */ { IIC2, 0, 0, 0 } },
539 { 0xffd50000, 0, 16, 4, /* IPRAS3 */ { RTDMAC2_1, 0, 0, 0 } },
540 { 0xffd50004, 0, 16, 4, /* IPRBS3 */ { RTDMAC2_2, 0, 0, 0 } },
541 { 0xffd50020, 0, 16, 4, /* IPRIS3 */ { 0, ISP, 0, 0 } },
542 { 0xffd50024, 0, 16, 4, /* IPRJS3 */ { LCDC1, CSIRX, DSITX, 0 } },
543 { 0xffd50030, 0, 16, 4, /* IPRMS3 */ { TMU1, 0, 0, 0 } },
544 { 0xffd50034, 0, 16, 4, /* IPRNS3 */ { CMT4, DSITX1_DSITX1_0,
545 DSITX1_DSITX1_1, 0 } },
546 { 0xffd50038, 0, 16, 4, /* IPROS3 */ { 0, CPORTS2R, 0, 0 } },
547 { 0xffd5003c, 0, 16, 4, /* IPRPS3 */ { JPU6E, 0, 0, 0 } },
548};
549
550static struct resource intcs_resources[] __initdata = {
551 [0] = {
552 .start = 0xffd20000,
553 .end = 0xffd201ff,
554 .flags = IORESOURCE_MEM,
555 },
556 [1] = {
557 .start = 0xffd50000,
558 .end = 0xffd501ff,
559 .flags = IORESOURCE_MEM,
560 }
561};
562
563static struct intc_desc intcs_desc __initdata = {
564 .name = "sh7372-intcs",
565 .resource = intcs_resources,
566 .num_resources = ARRAY_SIZE(intcs_resources),
567 .hw = INTC_HW_DESC(intcs_vectors, intcs_groups, intcs_mask_registers,
568 intcs_prio_registers, NULL, NULL),
569};
570
571static void intcs_demux(unsigned int irq, struct irq_desc *desc)
572{
573 void __iomem *reg = (void *)get_irq_data(irq);
574 unsigned int evtcodeas = ioread32(reg);
575
576 generic_handle_irq(intcs_evt2irq(evtcodeas));
577}
578
366void __init sh7372_init_irq(void) 579void __init sh7372_init_irq(void)
367{ 580{
581 void __iomem *intevtsa = ioremap_nocache(0xffd20100, PAGE_SIZE);
582
368 register_intc_controller(&intca_desc); 583 register_intc_controller(&intca_desc);
584 register_intc_controller(&intcs_desc);
585
586 /* demux using INTEVTSA */
587 set_irq_data(evt2irq(0xf80), (void *)intevtsa);
588 set_irq_chained_handler(evt2irq(0xf80), intcs_demux);
369} 589}
diff --git a/arch/arm/mach-shmobile/intc-sh7377.c b/arch/arm/mach-shmobile/intc-sh7377.c
index 5c781e2d1897..2cdeb8ccd821 100644
--- a/arch/arm/mach-shmobile/intc-sh7377.c
+++ b/arch/arm/mach-shmobile/intc-sh7377.c
@@ -90,7 +90,7 @@ enum {
90 ICUSB, ICUDMC 90 ICUSB, ICUDMC
91}; 91};
92 92
93static struct intc_vect intca_vectors[] = { 93static struct intc_vect intca_vectors[] __initdata = {
94 INTC_VECT(IRQ0A, 0x0200), INTC_VECT(IRQ1A, 0x0220), 94 INTC_VECT(IRQ0A, 0x0200), INTC_VECT(IRQ1A, 0x0220),
95 INTC_VECT(IRQ2A, 0x0240), INTC_VECT(IRQ3A, 0x0260), 95 INTC_VECT(IRQ2A, 0x0240), INTC_VECT(IRQ3A, 0x0260),
96 INTC_VECT(IRQ4A, 0x0280), INTC_VECT(IRQ5A, 0x02a0), 96 INTC_VECT(IRQ4A, 0x0280), INTC_VECT(IRQ5A, 0x02a0),
@@ -202,7 +202,7 @@ static struct intc_group intca_groups[] __initdata = {
202 INTC_GROUP(ICUDMC, ICUDMC_ICUDMC1, ICUDMC_ICUDMC2), 202 INTC_GROUP(ICUDMC, ICUDMC_ICUDMC1, ICUDMC_ICUDMC2),
203}; 203};
204 204
205static struct intc_mask_reg intca_mask_registers[] = { 205static struct intc_mask_reg intca_mask_registers[] __initdata = {
206 { 0xe6900040, 0xe6900060, 8, /* INTMSK00A / INTMSKCLR00A */ 206 { 0xe6900040, 0xe6900060, 8, /* INTMSK00A / INTMSKCLR00A */
207 { IRQ0A, IRQ1A, IRQ2A, IRQ3A, IRQ4A, IRQ5A, IRQ6A, IRQ7A } }, 207 { IRQ0A, IRQ1A, IRQ2A, IRQ3A, IRQ4A, IRQ5A, IRQ6A, IRQ7A } },
208 { 0xe6900044, 0xe6900064, 8, /* INTMSK10A / INTMSKCLR10A */ 208 { 0xe6900044, 0xe6900064, 8, /* INTMSK10A / INTMSKCLR10A */
@@ -272,7 +272,7 @@ static struct intc_mask_reg intca_mask_registers[] = {
272 SCIFA6, 0, 0, 0 } }, 272 SCIFA6, 0, 0, 0 } },
273}; 273};
274 274
275static struct intc_prio_reg intca_prio_registers[] = { 275static struct intc_prio_reg intca_prio_registers[] __initdata = {
276 { 0xe6900010, 0, 32, 4, /* INTPRI00A */ 276 { 0xe6900010, 0, 32, 4, /* INTPRI00A */
277 { IRQ0A, IRQ1A, IRQ2A, IRQ3A, IRQ4A, IRQ5A, IRQ6A, IRQ7A } }, 277 { IRQ0A, IRQ1A, IRQ2A, IRQ3A, IRQ4A, IRQ5A, IRQ6A, IRQ7A } },
278 { 0xe6900014, 0, 32, 4, /* INTPRI10A */ 278 { 0xe6900014, 0, 32, 4, /* INTPRI10A */
@@ -346,7 +346,301 @@ static struct intc_desc intca_desc __initdata = {
346 intca_sense_registers, intca_ack_registers), 346 intca_sense_registers, intca_ack_registers),
347}; 347};
348 348
349/* this macro ignore entry which is also in INTCA */
350#define __IGNORE(a...)
351#define __IGNORE0(a...) 0
352
353enum {
354 UNUSED_INTCS = 0,
355
356 INTCS,
357
358 /* interrupt sources INTCS */
359 VEU_VEU0, VEU_VEU1, VEU_VEU2, VEU_VEU3,
360 RTDMAC1_1_DEI0, RTDMAC1_1_DEI1, RTDMAC1_1_DEI2, RTDMAC1_1_DEI3,
361 CEU,
362 BEU_BEU0, BEU_BEU1, BEU_BEU2,
363 __IGNORE(MFI)
364 __IGNORE(BBIF2)
365 VPU,
366 TSIF1,
367 __IGNORE(SGX540)
368 _2DDMAC,
369 IIC2_ALI2, IIC2_TACKI2, IIC2_WAITI2, IIC2_DTEI2,
370 IPMMU_IPMMUR, IPMMU_IPMMUR2,
371 RTDMAC1_2_DEI4, RTDMAC1_2_DEI5, RTDMAC1_2_DADERR,
372 __IGNORE(KEYSC)
373 __IGNORE(TTI20)
374 __IGNORE(MSIOF)
375 IIC0_ALI0, IIC0_TACKI0, IIC0_WAITI0, IIC0_DTEI0,
376 TMU_TUNI0, TMU_TUNI1, TMU_TUNI2,
377 CMT0,
378 TSIF0,
379 __IGNORE(CMT2)
380 LMB,
381 __IGNORE(MSUG)
382 __IGNORE(MSU_MSU, MSU_MSU2)
383 __IGNORE(CTI)
384 MVI3,
385 __IGNORE(RWDT0)
386 __IGNORE(RWDT1)
387 ICB,
388 PEP,
389 ASA,
390 __IGNORE(_2DG)
391 HQE,
392 JPU,
393 LCDC0,
394 __IGNORE(LCRC)
395 RTDMAC2_1_DEI0, RTDMAC2_1_DEI1, RTDMAC2_1_DEI2, RTDMAC2_1_DEI3,
396 RTDMAC2_2_DEI4, RTDMAC2_2_DEI5, RTDMAC2_2_DADERR,
397 FRC,
398 LCDC1,
399 CSIRX,
400 DSITX_DSITX0, DSITX_DSITX1,
401 __IGNORE(SPU2_SPU0, SPU2_SPU1)
402 __IGNORE(FSI)
403 __IGNORE(FMSI)
404 __IGNORE(SCUV)
405 TMU1_TUNI10, TMU1_TUNI11, TMU1_TUNI12,
406 TSIF2,
407 CMT4,
408 __IGNORE(MFIS2)
409 CPORTS2R,
410
411 /* interrupt groups INTCS */
412 RTDMAC1_1, RTDMAC1_2, VEU, BEU, IIC0, __IGNORE(MSU) IPMMU,
413 IIC2, RTDMAC2_1, RTDMAC2_2, DSITX, __IGNORE(SPU2) TMU1,
414};
415
416#define INTCS_INTVECT 0x0F80
417static struct intc_vect intcs_vectors[] __initdata = {
418 INTCS_VECT(VEU_VEU0, 0x0700), INTCS_VECT(VEU_VEU1, 0x0720),
419 INTCS_VECT(VEU_VEU2, 0x0740), INTCS_VECT(VEU_VEU3, 0x0760),
420 INTCS_VECT(RTDMAC1_1_DEI0, 0x0800), INTCS_VECT(RTDMAC1_1_DEI1, 0x0820),
421 INTCS_VECT(RTDMAC1_1_DEI2, 0x0840), INTCS_VECT(RTDMAC1_1_DEI3, 0x0860),
422 INTCS_VECT(CEU, 0x0880),
423 INTCS_VECT(BEU_BEU0, 0x08A0),
424 INTCS_VECT(BEU_BEU1, 0x08C0),
425 INTCS_VECT(BEU_BEU2, 0x08E0),
426 __IGNORE(INTCS_VECT(MFI, 0x0900))
427 __IGNORE(INTCS_VECT(BBIF2, 0x0960))
428 INTCS_VECT(VPU, 0x0980),
429 INTCS_VECT(TSIF1, 0x09A0),
430 __IGNORE(INTCS_VECT(SGX540, 0x09E0))
431 INTCS_VECT(_2DDMAC, 0x0A00),
432 INTCS_VECT(IIC2_ALI2, 0x0A80), INTCS_VECT(IIC2_TACKI2, 0x0AA0),
433 INTCS_VECT(IIC2_WAITI2, 0x0AC0), INTCS_VECT(IIC2_DTEI2, 0x0AE0),
434 INTCS_VECT(IPMMU_IPMMUR, 0x0B00), INTCS_VECT(IPMMU_IPMMUR2, 0x0B20),
435 INTCS_VECT(RTDMAC1_2_DEI4, 0x0B80),
436 INTCS_VECT(RTDMAC1_2_DEI5, 0x0BA0),
437 INTCS_VECT(RTDMAC1_2_DADERR, 0x0BC0),
438 __IGNORE(INTCS_VECT(KEYSC 0x0BE0))
439 __IGNORE(INTCS_VECT(TTI20, 0x0C80))
440 __IGNORE(INTCS_VECT(MSIOF, 0x0D20))
441 INTCS_VECT(IIC0_ALI0, 0x0E00), INTCS_VECT(IIC0_TACKI0, 0x0E20),
442 INTCS_VECT(IIC0_WAITI0, 0x0E40), INTCS_VECT(IIC0_DTEI0, 0x0E60),
443 INTCS_VECT(TMU_TUNI0, 0x0E80),
444 INTCS_VECT(TMU_TUNI1, 0x0EA0),
445 INTCS_VECT(TMU_TUNI2, 0x0EC0),
446 INTCS_VECT(CMT0, 0x0F00),
447 INTCS_VECT(TSIF0, 0x0F20),
448 __IGNORE(INTCS_VECT(CMT2, 0x0F40))
449 INTCS_VECT(LMB, 0x0F60),
450 __IGNORE(INTCS_VECT(MSUG, 0x0F80))
451 __IGNORE(INTCS_VECT(MSU_MSU, 0x0FA0))
452 __IGNORE(INTCS_VECT(MSU_MSU2, 0x0FC0))
453 __IGNORE(INTCS_VECT(CTI, 0x0400))
454 INTCS_VECT(MVI3, 0x0420),
455 __IGNORE(INTCS_VECT(RWDT0, 0x0440))
456 __IGNORE(INTCS_VECT(RWDT1, 0x0460))
457 INTCS_VECT(ICB, 0x0480),
458 INTCS_VECT(PEP, 0x04A0),
459 INTCS_VECT(ASA, 0x04C0),
460 __IGNORE(INTCS_VECT(_2DG, 0x04E0))
461 INTCS_VECT(HQE, 0x0540),
462 INTCS_VECT(JPU, 0x0560),
463 INTCS_VECT(LCDC0, 0x0580),
464 __IGNORE(INTCS_VECT(LCRC, 0x05A0))
465 INTCS_VECT(RTDMAC2_1_DEI0, 0x1300), INTCS_VECT(RTDMAC2_1_DEI1, 0x1320),
466 INTCS_VECT(RTDMAC2_1_DEI2, 0x1340), INTCS_VECT(RTDMAC2_1_DEI3, 0x1360),
467 INTCS_VECT(RTDMAC2_2_DEI4, 0x1380), INTCS_VECT(RTDMAC2_2_DEI5, 0x13A0),
468 INTCS_VECT(RTDMAC2_2_DADERR, 0x13C0),
469 INTCS_VECT(FRC, 0x1700),
470 INTCS_VECT(LCDC1, 0x1780),
471 INTCS_VECT(CSIRX, 0x17A0),
472 INTCS_VECT(DSITX_DSITX0, 0x17C0), INTCS_VECT(DSITX_DSITX1, 0x17E0),
473 __IGNORE(INTCS_VECT(SPU2_SPU0, 0x1800))
474 __IGNORE(INTCS_VECT(SPU2_SPU1, 0x1820))
475 __IGNORE(INTCS_VECT(FSI, 0x1840))
476 __IGNORE(INTCS_VECT(FMSI, 0x1860))
477 __IGNORE(INTCS_VECT(SCUV, 0x1880))
478 INTCS_VECT(TMU1_TUNI10, 0x1900), INTCS_VECT(TMU1_TUNI11, 0x1920),
479 INTCS_VECT(TMU1_TUNI12, 0x1940),
480 INTCS_VECT(TSIF2, 0x1960),
481 INTCS_VECT(CMT4, 0x1980),
482 __IGNORE(INTCS_VECT(MFIS2, 0x1A00))
483 INTCS_VECT(CPORTS2R, 0x1A20),
484
485 INTC_VECT(INTCS, INTCS_INTVECT),
486};
487
488static struct intc_group intcs_groups[] __initdata = {
489 INTC_GROUP(RTDMAC1_1,
490 RTDMAC1_1_DEI0, RTDMAC1_1_DEI1,
491 RTDMAC1_1_DEI2, RTDMAC1_1_DEI3),
492 INTC_GROUP(RTDMAC1_2,
493 RTDMAC1_2_DEI4, RTDMAC1_2_DEI5, RTDMAC1_2_DADERR),
494 INTC_GROUP(VEU, VEU_VEU0, VEU_VEU1, VEU_VEU2, VEU_VEU3),
495 INTC_GROUP(BEU, BEU_BEU0, BEU_BEU1, BEU_BEU2),
496 INTC_GROUP(IIC0, IIC0_ALI0, IIC0_TACKI0, IIC0_WAITI0, IIC0_DTEI0),
497 __IGNORE(INTC_GROUP(MSU, MSU_MSU, MSU_MSU2))
498 INTC_GROUP(IPMMU, IPMMU_IPMMUR, IPMMU_IPMMUR2),
499 INTC_GROUP(IIC2, IIC2_ALI2, IIC2_TACKI2, IIC2_WAITI2, IIC2_DTEI2),
500 INTC_GROUP(RTDMAC2_1,
501 RTDMAC2_1_DEI0, RTDMAC2_1_DEI1,
502 RTDMAC2_1_DEI2, RTDMAC2_1_DEI3),
503 INTC_GROUP(RTDMAC2_2, RTDMAC2_2_DEI4, RTDMAC2_2_DEI5, RTDMAC2_2_DADERR),
504 INTC_GROUP(DSITX, DSITX_DSITX0, DSITX_DSITX1),
505 __IGNORE(INTC_GROUP(SPU2, SPU2_SPU0, SPU2_SPU1))
506 INTC_GROUP(TMU1, TMU1_TUNI10, TMU1_TUNI11, TMU1_TUNI12),
507};
508
509static struct intc_mask_reg intcs_mask_registers[] __initdata = {
510 { 0xE6940184, 0xE69401C4, 8, /* IMR1AS / IMCR1AS */
511 { BEU_BEU2, BEU_BEU1, BEU_BEU0, CEU,
512 VEU_VEU3, VEU_VEU2, VEU_VEU1, VEU_VEU0 } },
513 { 0xE6940188, 0xE69401C8, 8, /* IMR2AS / IMCR2AS */
514 { 0, 0, 0, VPU,
515 __IGNORE0(BBIF2), 0, 0, __IGNORE0(MFI) } },
516 { 0xE694018C, 0xE69401CC, 8, /* IMR3AS / IMCR3AS */
517 { 0, 0, 0, _2DDMAC,
518 __IGNORE0(_2DG), ASA, PEP, ICB } },
519 { 0xE6940190, 0xE69401D0, 8, /* IMR4AS / IMCR4AS */
520 { 0, 0, MVI3, __IGNORE0(CTI),
521 JPU, HQE, __IGNORE0(LCRC), LCDC0 } },
522 { 0xE6940194, 0xE69401D4, 8, /* IMR5AS / IMCR5AS */
523 { __IGNORE0(KEYSC), RTDMAC1_2_DADERR, RTDMAC1_2_DEI5, RTDMAC1_2_DEI4,
524 RTDMAC1_1_DEI3, RTDMAC1_1_DEI2, RTDMAC1_1_DEI1, RTDMAC1_1_DEI0 } },
525 __IGNORE({ 0xE6940198, 0xE69401D8, 8, /* IMR6AS / IMCR6AS */
526 { 0, 0, MSIOF, 0,
527 SGX540, 0, TTI20, 0 } })
528 { 0xE694019C, 0xE69401DC, 8, /* IMR7AS / IMCR7AS */
529 { 0, TMU_TUNI2, TMU_TUNI1, TMU_TUNI0,
530 0, 0, 0, 0 } },
531 __IGNORE({ 0xE69401A0, 0xE69401E0, 8, /* IMR8AS / IMCR8AS */
532 { 0, 0, 0, 0,
533 0, MSU_MSU, MSU_MSU2, MSUG } })
534 { 0xE69401A4, 0xE69401E4, 8, /* IMR9AS / IMCR9AS */
535 { __IGNORE0(RWDT1), __IGNORE0(RWDT0), __IGNORE0(CMT2), CMT0,
536 IIC2_DTEI2, IIC2_WAITI2, IIC2_TACKI2, IIC2_ALI2 } },
537 { 0xE69401A8, 0xE69401E8, 8, /* IMR10AS / IMCR10AS */
538 { 0, 0, IPMMU_IPMMUR, IPMMU_IPMMUR2,
539 0, 0, 0, 0 } },
540 { 0xE69401AC, 0xE69401EC, 8, /* IMR11AS / IMCR11AS */
541 { IIC0_DTEI0, IIC0_WAITI0, IIC0_TACKI0, IIC0_ALI0,
542 0, TSIF1, LMB, TSIF0 } },
543 { 0xE6950180, 0xE69501C0, 8, /* IMR0AS3 / IMCR0AS3 */
544 { RTDMAC2_1_DEI0, RTDMAC2_1_DEI1, RTDMAC2_1_DEI2, RTDMAC2_1_DEI3,
545 RTDMAC2_2_DEI4, RTDMAC2_2_DEI5, RTDMAC2_2_DADERR, 0 } },
546 { 0xE6950190, 0xE69501D0, 8, /* IMR4AS3 / IMCR4AS3 */
547 { FRC, 0, 0, 0,
548 LCDC1, CSIRX, DSITX_DSITX0, DSITX_DSITX1 } },
549 __IGNORE({ 0xE6950194, 0xE69501D4, 8, /* IMR5AS3 / IMCR5AS3 */
550 {SPU2_SPU0, SPU2_SPU1, FSI, FMSI,
551 SCUV, 0, 0, 0 } })
552 { 0xE6950198, 0xE69501D8, 8, /* IMR6AS3 / IMCR6AS3 */
553 { TMU1_TUNI10, TMU1_TUNI11, TMU1_TUNI12, TSIF2,
554 CMT4, 0, 0, 0 } },
555 { 0xE695019C, 0xE69501DC, 8, /* IMR7AS3 / IMCR7AS3 */
556 { __IGNORE0(MFIS2), CPORTS2R, 0, 0,
557 0, 0, 0, 0 } },
558 { 0xFFD20104, 0, 16, /* INTAMASK */
559 { 0, 0, 0, 0, 0, 0, 0, 0,
560 0, 0, 0, 0, 0, 0, 0, INTCS } }
561};
562
563static struct intc_prio_reg intcs_prio_registers[] __initdata = {
564 /* IPRAS */
565 { 0xFFD20000, 0, 16, 4, { __IGNORE0(CTI), MVI3, _2DDMAC, ICB } },
566 /* IPRBS */
567 { 0xFFD20004, 0, 16, 4, { JPU, LCDC0, 0, __IGNORE0(LCRC) } },
568 /* IPRCS */
569 __IGNORE({ 0xFFD20008, 0, 16, 4, { BBIF2, 0, 0, 0 } })
570 /* IPRES */
571 { 0xFFD20010, 0, 16, 4, { RTDMAC1_1, CEU, __IGNORE0(MFI), VPU } },
572 /* IPRFS */
573 { 0xFFD20014, 0, 16, 4,
574 { __IGNORE0(KEYSC), RTDMAC1_2, __IGNORE0(CMT2), CMT0 } },
575 /* IPRGS */
576 { 0xFFD20018, 0, 16, 4, { TMU_TUNI0, TMU_TUNI1, TMU_TUNI2, TSIF1 } },
577 /* IPRHS */
578 { 0xFFD2001C, 0, 16, 4, { __IGNORE0(TTI20), 0, VEU, BEU } },
579 /* IPRIS */
580 { 0xFFD20020, 0, 16, 4, { 0, __IGNORE0(MSIOF), TSIF0, IIC0 } },
581 /* IPRJS */
582 __IGNORE({ 0xFFD20024, 0, 16, 4, { 0, SGX540, MSUG, MSU } })
583 /* IPRKS */
584 { 0xFFD20028, 0, 16, 4, { __IGNORE0(_2DG), ASA, LMB, PEP } },
585 /* IPRLS */
586 { 0xFFD2002C, 0, 16, 4, { IPMMU, 0, 0, HQE } },
587 /* IPRMS */
588 { 0xFFD20030, 0, 16, 4,
589 { IIC2, 0, __IGNORE0(RWDT1), __IGNORE0(RWDT0) } },
590 /* IPRAS3 */
591 { 0xFFD50000, 0, 16, 4, { RTDMAC2_1, 0, 0, 0 } },
592 /* IPRBS3 */
593 { 0xFFD50004, 0, 16, 4, { RTDMAC2_2, 0, 0, 0 } },
594 /* IPRIS3 */
595 { 0xFFD50020, 0, 16, 4, { FRC, 0, 0, 0 } },
596 /* IPRJS3 */
597 { 0xFFD50024, 0, 16, 4, { LCDC1, CSIRX, DSITX, 0 } },
598 /* IPRKS3 */
599 __IGNORE({ 0xFFD50028, 0, 16, 4, { SPU2, 0, FSI, FMSI } })
600 /* IPRLS3 */
601 __IGNORE({ 0xFFD5002C, 0, 16, 4, { SCUV, 0, 0, 0 } })
602 /* IPRMS3 */
603 { 0xFFD50030, 0, 16, 4, { TMU1, 0, 0, TSIF2 } },
604 /* IPRNS3 */
605 { 0xFFD50034, 0, 16, 4, { CMT4, 0, 0, 0 } },
606 /* IPROS3 */
607 { 0xFFD50038, 0, 16, 4, { __IGNORE0(MFIS2), CPORTS2R, 0, 0 } },
608};
609
610static struct resource intcs_resources[] __initdata = {
611 [0] = {
612 .start = 0xffd20000,
613 .end = 0xffd500ff,
614 .flags = IORESOURCE_MEM,
615 }
616};
617
618static struct intc_desc intcs_desc __initdata = {
619 .name = "sh7377-intcs",
620 .resource = intcs_resources,
621 .num_resources = ARRAY_SIZE(intcs_resources),
622 .hw = INTC_HW_DESC(intcs_vectors, intcs_groups,
623 intcs_mask_registers, intcs_prio_registers,
624 NULL, NULL),
625};
626
627static void intcs_demux(unsigned int irq, struct irq_desc *desc)
628{
629 void __iomem *reg = (void *)get_irq_data(irq);
630 unsigned int evtcodeas = ioread32(reg);
631
632 generic_handle_irq(intcs_evt2irq(evtcodeas));
633}
634
635#define INTEVTSA 0xFFD20100
349void __init sh7377_init_irq(void) 636void __init sh7377_init_irq(void)
350{ 637{
638 void __iomem *intevtsa = ioremap_nocache(INTEVTSA, PAGE_SIZE);
639
351 register_intc_controller(&intca_desc); 640 register_intc_controller(&intca_desc);
641 register_intc_controller(&intcs_desc);
642
643 /* demux using INTEVTSA */
644 set_irq_data(evt2irq(INTCS_INTVECT), (void *)intevtsa);
645 set_irq_chained_handler(evt2irq(INTCS_INTVECT), intcs_demux);
352} 646}
diff --git a/arch/arm/mach-shmobile/pfc-sh7372.c b/arch/arm/mach-shmobile/pfc-sh7372.c
index 9557d0964d73..ec420353f8e3 100644
--- a/arch/arm/mach-shmobile/pfc-sh7372.c
+++ b/arch/arm/mach-shmobile/pfc-sh7372.c
@@ -1160,6 +1160,9 @@ static struct pinmux_gpio pinmux_gpios[] = {
1160 GPIO_FN(LCDD18), GPIO_FN(LCDD19), GPIO_FN(LCDD20), 1160 GPIO_FN(LCDD18), GPIO_FN(LCDD19), GPIO_FN(LCDD20),
1161 GPIO_FN(LCDD21), GPIO_FN(LCDD22), GPIO_FN(LCDD23), 1161 GPIO_FN(LCDD21), GPIO_FN(LCDD22), GPIO_FN(LCDD23),
1162 1162
1163 GPIO_FN(LCDC0_SELECT),
1164 GPIO_FN(LCDC1_SELECT),
1165
1163 /* IRDA */ 1166 /* IRDA */
1164 GPIO_FN(IRDA_OUT), GPIO_FN(IRDA_IN), GPIO_FN(IRDA_FIRSEL), 1167 GPIO_FN(IRDA_OUT), GPIO_FN(IRDA_IN), GPIO_FN(IRDA_FIRSEL),
1165 GPIO_FN(IROUT_139), GPIO_FN(IROUT_140), 1168 GPIO_FN(IROUT_139), GPIO_FN(IROUT_140),
diff --git a/arch/arm/mach-shmobile/setup-sh7367.c b/arch/arm/mach-shmobile/setup-sh7367.c
index eca90716140e..3148c11a550e 100644
--- a/arch/arm/mach-shmobile/setup-sh7367.c
+++ b/arch/arm/mach-shmobile/setup-sh7367.c
@@ -31,11 +31,13 @@
31#include <asm/mach-types.h> 31#include <asm/mach-types.h>
32#include <asm/mach/arch.h> 32#include <asm/mach/arch.h>
33 33
34/* SCIFA0 */
34static struct plat_sci_port scif0_platform_data = { 35static struct plat_sci_port scif0_platform_data = {
35 .mapbase = 0xe6c40000, 36 .mapbase = 0xe6c40000,
36 .flags = UPF_BOOT_AUTOCONF, 37 .flags = UPF_BOOT_AUTOCONF,
37 .type = PORT_SCIF, 38 .type = PORT_SCIF,
38 .irqs = { 80, 80, 80, 80 }, 39 .irqs = { evt2irq(0xc00), evt2irq(0xc00),
40 evt2irq(0xc00), evt2irq(0xc00) },
39}; 41};
40 42
41static struct platform_device scif0_device = { 43static struct platform_device scif0_device = {
@@ -46,11 +48,13 @@ static struct platform_device scif0_device = {
46 }, 48 },
47}; 49};
48 50
51/* SCIFA1 */
49static struct plat_sci_port scif1_platform_data = { 52static struct plat_sci_port scif1_platform_data = {
50 .mapbase = 0xe6c50000, 53 .mapbase = 0xe6c50000,
51 .flags = UPF_BOOT_AUTOCONF, 54 .flags = UPF_BOOT_AUTOCONF,
52 .type = PORT_SCIF, 55 .type = PORT_SCIF,
53 .irqs = { 81, 81, 81, 81 }, 56 .irqs = { evt2irq(0xc20), evt2irq(0xc20),
57 evt2irq(0xc20), evt2irq(0xc20) },
54}; 58};
55 59
56static struct platform_device scif1_device = { 60static struct platform_device scif1_device = {
@@ -61,11 +65,13 @@ static struct platform_device scif1_device = {
61 }, 65 },
62}; 66};
63 67
68/* SCIFA2 */
64static struct plat_sci_port scif2_platform_data = { 69static struct plat_sci_port scif2_platform_data = {
65 .mapbase = 0xe6c60000, 70 .mapbase = 0xe6c60000,
66 .flags = UPF_BOOT_AUTOCONF, 71 .flags = UPF_BOOT_AUTOCONF,
67 .type = PORT_SCIF, 72 .type = PORT_SCIF,
68 .irqs = { 82, 82, 82, 82 }, 73 .irqs = { evt2irq(0xc40), evt2irq(0xc40),
74 evt2irq(0xc40), evt2irq(0xc40) },
69}; 75};
70 76
71static struct platform_device scif2_device = { 77static struct platform_device scif2_device = {
@@ -76,11 +82,13 @@ static struct platform_device scif2_device = {
76 }, 82 },
77}; 83};
78 84
85/* SCIFA3 */
79static struct plat_sci_port scif3_platform_data = { 86static struct plat_sci_port scif3_platform_data = {
80 .mapbase = 0xe6c70000, 87 .mapbase = 0xe6c70000,
81 .flags = UPF_BOOT_AUTOCONF, 88 .flags = UPF_BOOT_AUTOCONF,
82 .type = PORT_SCIF, 89 .type = PORT_SCIF,
83 .irqs = { 83, 83, 83, 83 }, 90 .irqs = { evt2irq(0xc60), evt2irq(0xc60),
91 evt2irq(0xc60), evt2irq(0xc60) },
84}; 92};
85 93
86static struct platform_device scif3_device = { 94static struct platform_device scif3_device = {
@@ -91,11 +99,13 @@ static struct platform_device scif3_device = {
91 }, 99 },
92}; 100};
93 101
102/* SCIFA4 */
94static struct plat_sci_port scif4_platform_data = { 103static struct plat_sci_port scif4_platform_data = {
95 .mapbase = 0xe6c80000, 104 .mapbase = 0xe6c80000,
96 .flags = UPF_BOOT_AUTOCONF, 105 .flags = UPF_BOOT_AUTOCONF,
97 .type = PORT_SCIF, 106 .type = PORT_SCIF,
98 .irqs = { 89, 89, 89, 89 }, 107 .irqs = { evt2irq(0xd20), evt2irq(0xd20),
108 evt2irq(0xd20), evt2irq(0xd20) },
99}; 109};
100 110
101static struct platform_device scif4_device = { 111static struct platform_device scif4_device = {
@@ -106,11 +116,13 @@ static struct platform_device scif4_device = {
106 }, 116 },
107}; 117};
108 118
119/* SCIFA5 */
109static struct plat_sci_port scif5_platform_data = { 120static struct plat_sci_port scif5_platform_data = {
110 .mapbase = 0xe6cb0000, 121 .mapbase = 0xe6cb0000,
111 .flags = UPF_BOOT_AUTOCONF, 122 .flags = UPF_BOOT_AUTOCONF,
112 .type = PORT_SCIF, 123 .type = PORT_SCIF,
113 .irqs = { 90, 90, 90, 90 }, 124 .irqs = { evt2irq(0xd40), evt2irq(0xd40),
125 evt2irq(0xd40), evt2irq(0xd40) },
114}; 126};
115 127
116static struct platform_device scif5_device = { 128static struct platform_device scif5_device = {
@@ -121,11 +133,13 @@ static struct platform_device scif5_device = {
121 }, 133 },
122}; 134};
123 135
136/* SCIFB */
124static struct plat_sci_port scif6_platform_data = { 137static struct plat_sci_port scif6_platform_data = {
125 .mapbase = 0xe6c30000, 138 .mapbase = 0xe6c30000,
126 .flags = UPF_BOOT_AUTOCONF, 139 .flags = UPF_BOOT_AUTOCONF,
127 .type = PORT_SCIF, 140 .type = PORT_SCIF,
128 .irqs = { 91, 91, 91, 91 }, 141 .irqs = { evt2irq(0xd60), evt2irq(0xd60),
142 evt2irq(0xd60), evt2irq(0xd60) },
129}; 143};
130 144
131static struct platform_device scif6_device = { 145static struct platform_device scif6_device = {
@@ -153,7 +167,7 @@ static struct resource cmt10_resources[] = {
153 .flags = IORESOURCE_MEM, 167 .flags = IORESOURCE_MEM,
154 }, 168 },
155 [1] = { 169 [1] = {
156 .start = 72, 170 .start = evt2irq(0xb00), /* CMT1_CMT10 */
157 .flags = IORESOURCE_IRQ, 171 .flags = IORESOURCE_IRQ,
158 }, 172 },
159}; 173};
diff --git a/arch/arm/mach-shmobile/setup-sh7372.c b/arch/arm/mach-shmobile/setup-sh7372.c
index 1d1153290f59..e26686c9d0b6 100644
--- a/arch/arm/mach-shmobile/setup-sh7372.c
+++ b/arch/arm/mach-shmobile/setup-sh7372.c
@@ -26,17 +26,21 @@
26#include <linux/input.h> 26#include <linux/input.h>
27#include <linux/io.h> 27#include <linux/io.h>
28#include <linux/serial_sci.h> 28#include <linux/serial_sci.h>
29#include <linux/sh_dma.h>
29#include <linux/sh_intc.h> 30#include <linux/sh_intc.h>
30#include <linux/sh_timer.h> 31#include <linux/sh_timer.h>
31#include <mach/hardware.h> 32#include <mach/hardware.h>
33#include <mach/sh7372.h>
32#include <asm/mach-types.h> 34#include <asm/mach-types.h>
33#include <asm/mach/arch.h> 35#include <asm/mach/arch.h>
34 36
37/* SCIFA0 */
35static struct plat_sci_port scif0_platform_data = { 38static struct plat_sci_port scif0_platform_data = {
36 .mapbase = 0xe6c40000, 39 .mapbase = 0xe6c40000,
37 .flags = UPF_BOOT_AUTOCONF, 40 .flags = UPF_BOOT_AUTOCONF,
38 .type = PORT_SCIF, 41 .type = PORT_SCIFA,
39 .irqs = { 80, 80, 80, 80 }, 42 .irqs = { evt2irq(0x0c00), evt2irq(0x0c00),
43 evt2irq(0x0c00), evt2irq(0x0c00) },
40}; 44};
41 45
42static struct platform_device scif0_device = { 46static struct platform_device scif0_device = {
@@ -47,11 +51,13 @@ static struct platform_device scif0_device = {
47 }, 51 },
48}; 52};
49 53
54/* SCIFA1 */
50static struct plat_sci_port scif1_platform_data = { 55static struct plat_sci_port scif1_platform_data = {
51 .mapbase = 0xe6c50000, 56 .mapbase = 0xe6c50000,
52 .flags = UPF_BOOT_AUTOCONF, 57 .flags = UPF_BOOT_AUTOCONF,
53 .type = PORT_SCIF, 58 .type = PORT_SCIFA,
54 .irqs = { 81, 81, 81, 81 }, 59 .irqs = { evt2irq(0x0c20), evt2irq(0x0c20),
60 evt2irq(0x0c20), evt2irq(0x0c20) },
55}; 61};
56 62
57static struct platform_device scif1_device = { 63static struct platform_device scif1_device = {
@@ -62,11 +68,13 @@ static struct platform_device scif1_device = {
62 }, 68 },
63}; 69};
64 70
71/* SCIFA2 */
65static struct plat_sci_port scif2_platform_data = { 72static struct plat_sci_port scif2_platform_data = {
66 .mapbase = 0xe6c60000, 73 .mapbase = 0xe6c60000,
67 .flags = UPF_BOOT_AUTOCONF, 74 .flags = UPF_BOOT_AUTOCONF,
68 .type = PORT_SCIF, 75 .type = PORT_SCIFA,
69 .irqs = { 82, 82, 82, 82 }, 76 .irqs = { evt2irq(0x0c40), evt2irq(0x0c40),
77 evt2irq(0x0c40), evt2irq(0x0c40) },
70}; 78};
71 79
72static struct platform_device scif2_device = { 80static struct platform_device scif2_device = {
@@ -77,11 +85,13 @@ static struct platform_device scif2_device = {
77 }, 85 },
78}; 86};
79 87
88/* SCIFA3 */
80static struct plat_sci_port scif3_platform_data = { 89static struct plat_sci_port scif3_platform_data = {
81 .mapbase = 0xe6c70000, 90 .mapbase = 0xe6c70000,
82 .flags = UPF_BOOT_AUTOCONF, 91 .flags = UPF_BOOT_AUTOCONF,
83 .type = PORT_SCIF, 92 .type = PORT_SCIFA,
84 .irqs = { 83, 83, 83, 83 }, 93 .irqs = { evt2irq(0x0c60), evt2irq(0x0c60),
94 evt2irq(0x0c60), evt2irq(0x0c60) },
85}; 95};
86 96
87static struct platform_device scif3_device = { 97static struct platform_device scif3_device = {
@@ -92,11 +102,13 @@ static struct platform_device scif3_device = {
92 }, 102 },
93}; 103};
94 104
105/* SCIFA4 */
95static struct plat_sci_port scif4_platform_data = { 106static struct plat_sci_port scif4_platform_data = {
96 .mapbase = 0xe6c80000, 107 .mapbase = 0xe6c80000,
97 .flags = UPF_BOOT_AUTOCONF, 108 .flags = UPF_BOOT_AUTOCONF,
98 .type = PORT_SCIF, 109 .type = PORT_SCIFA,
99 .irqs = { 89, 89, 89, 89 }, 110 .irqs = { evt2irq(0x0d20), evt2irq(0x0d20),
111 evt2irq(0x0d20), evt2irq(0x0d20) },
100}; 112};
101 113
102static struct platform_device scif4_device = { 114static struct platform_device scif4_device = {
@@ -107,11 +119,13 @@ static struct platform_device scif4_device = {
107 }, 119 },
108}; 120};
109 121
122/* SCIFA5 */
110static struct plat_sci_port scif5_platform_data = { 123static struct plat_sci_port scif5_platform_data = {
111 .mapbase = 0xe6cb0000, 124 .mapbase = 0xe6cb0000,
112 .flags = UPF_BOOT_AUTOCONF, 125 .flags = UPF_BOOT_AUTOCONF,
113 .type = PORT_SCIF, 126 .type = PORT_SCIFA,
114 .irqs = { 90, 90, 90, 90 }, 127 .irqs = { evt2irq(0x0d40), evt2irq(0x0d40),
128 evt2irq(0x0d40), evt2irq(0x0d40) },
115}; 129};
116 130
117static struct platform_device scif5_device = { 131static struct platform_device scif5_device = {
@@ -122,11 +136,13 @@ static struct platform_device scif5_device = {
122 }, 136 },
123}; 137};
124 138
139/* SCIFB */
125static struct plat_sci_port scif6_platform_data = { 140static struct plat_sci_port scif6_platform_data = {
126 .mapbase = 0xe6c30000, 141 .mapbase = 0xe6c30000,
127 .flags = UPF_BOOT_AUTOCONF, 142 .flags = UPF_BOOT_AUTOCONF,
128 .type = PORT_SCIF, 143 .type = PORT_SCIFB,
129 .irqs = { 91, 91, 91, 91 }, 144 .irqs = { evt2irq(0x0d60), evt2irq(0x0d60),
145 evt2irq(0x0d60), evt2irq(0x0d60) },
130}; 146};
131 147
132static struct platform_device scif6_device = { 148static struct platform_device scif6_device = {
@@ -137,11 +153,12 @@ static struct platform_device scif6_device = {
137 }, 153 },
138}; 154};
139 155
156/* CMT */
140static struct sh_timer_config cmt10_platform_data = { 157static struct sh_timer_config cmt10_platform_data = {
141 .name = "CMT10", 158 .name = "CMT10",
142 .channel_offset = 0x10, 159 .channel_offset = 0x10,
143 .timer_bit = 0, 160 .timer_bit = 0,
144 .clk = "r_clk", 161 .clk = "cmt1",
145 .clockevent_rating = 125, 162 .clockevent_rating = 125,
146 .clocksource_rating = 125, 163 .clocksource_rating = 125,
147}; 164};
@@ -154,7 +171,7 @@ static struct resource cmt10_resources[] = {
154 .flags = IORESOURCE_MEM, 171 .flags = IORESOURCE_MEM,
155 }, 172 },
156 [1] = { 173 [1] = {
157 .start = 72, 174 .start = evt2irq(0x0b00), /* CMT1_CMT10 */
158 .flags = IORESOURCE_IRQ, 175 .flags = IORESOURCE_IRQ,
159 }, 176 },
160}; 177};
@@ -169,6 +186,337 @@ static struct platform_device cmt10_device = {
169 .num_resources = ARRAY_SIZE(cmt10_resources), 186 .num_resources = ARRAY_SIZE(cmt10_resources),
170}; 187};
171 188
189/* I2C */
190static struct resource iic0_resources[] = {
191 [0] = {
192 .name = "IIC0",
193 .start = 0xFFF20000,
194 .end = 0xFFF20425 - 1,
195 .flags = IORESOURCE_MEM,
196 },
197 [1] = {
198 .start = intcs_evt2irq(0xe00), /* IIC0_ALI0 */
199 .end = intcs_evt2irq(0xe60), /* IIC0_DTEI0 */
200 .flags = IORESOURCE_IRQ,
201 },
202};
203
204static struct platform_device iic0_device = {
205 .name = "i2c-sh_mobile",
206 .id = 0, /* "i2c0" clock */
207 .num_resources = ARRAY_SIZE(iic0_resources),
208 .resource = iic0_resources,
209};
210
211static struct resource iic1_resources[] = {
212 [0] = {
213 .name = "IIC1",
214 .start = 0xE6C20000,
215 .end = 0xE6C20425 - 1,
216 .flags = IORESOURCE_MEM,
217 },
218 [1] = {
219 .start = evt2irq(0x780), /* IIC1_ALI1 */
220 .end = evt2irq(0x7e0), /* IIC1_DTEI1 */
221 .flags = IORESOURCE_IRQ,
222 },
223};
224
225static struct platform_device iic1_device = {
226 .name = "i2c-sh_mobile",
227 .id = 1, /* "i2c1" clock */
228 .num_resources = ARRAY_SIZE(iic1_resources),
229 .resource = iic1_resources,
230};
231
232/* DMA */
233/* Transmit sizes and respective CHCR register values */
234enum {
235 XMIT_SZ_8BIT = 0,
236 XMIT_SZ_16BIT = 1,
237 XMIT_SZ_32BIT = 2,
238 XMIT_SZ_64BIT = 7,
239 XMIT_SZ_128BIT = 3,
240 XMIT_SZ_256BIT = 4,
241 XMIT_SZ_512BIT = 5,
242};
243
244/* log2(size / 8) - used to calculate number of transfers */
245#define TS_SHIFT { \
246 [XMIT_SZ_8BIT] = 0, \
247 [XMIT_SZ_16BIT] = 1, \
248 [XMIT_SZ_32BIT] = 2, \
249 [XMIT_SZ_64BIT] = 3, \
250 [XMIT_SZ_128BIT] = 4, \
251 [XMIT_SZ_256BIT] = 5, \
252 [XMIT_SZ_512BIT] = 6, \
253}
254
255#define TS_INDEX2VAL(i) ((((i) & 3) << 3) | \
256 (((i) & 0xc) << (20 - 2)))
257
258static const struct sh_dmae_slave_config sh7372_dmae_slaves[] = {
259 {
260 .slave_id = SHDMA_SLAVE_SCIF0_TX,
261 .addr = 0xe6c40020,
262 .chcr = DM_FIX | SM_INC | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
263 .mid_rid = 0x21,
264 }, {
265 .slave_id = SHDMA_SLAVE_SCIF0_RX,
266 .addr = 0xe6c40024,
267 .chcr = DM_INC | SM_FIX | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
268 .mid_rid = 0x22,
269 }, {
270 .slave_id = SHDMA_SLAVE_SCIF1_TX,
271 .addr = 0xe6c50020,
272 .chcr = DM_FIX | SM_INC | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
273 .mid_rid = 0x25,
274 }, {
275 .slave_id = SHDMA_SLAVE_SCIF1_RX,
276 .addr = 0xe6c50024,
277 .chcr = DM_INC | SM_FIX | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
278 .mid_rid = 0x26,
279 }, {
280 .slave_id = SHDMA_SLAVE_SCIF2_TX,
281 .addr = 0xe6c60020,
282 .chcr = DM_FIX | SM_INC | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
283 .mid_rid = 0x29,
284 }, {
285 .slave_id = SHDMA_SLAVE_SCIF2_RX,
286 .addr = 0xe6c60024,
287 .chcr = DM_INC | SM_FIX | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
288 .mid_rid = 0x2a,
289 }, {
290 .slave_id = SHDMA_SLAVE_SCIF3_TX,
291 .addr = 0xe6c70020,
292 .chcr = DM_FIX | SM_INC | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
293 .mid_rid = 0x2d,
294 }, {
295 .slave_id = SHDMA_SLAVE_SCIF3_RX,
296 .addr = 0xe6c70024,
297 .chcr = DM_INC | SM_FIX | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
298 .mid_rid = 0x2e,
299 }, {
300 .slave_id = SHDMA_SLAVE_SCIF4_TX,
301 .addr = 0xe6c80020,
302 .chcr = DM_FIX | SM_INC | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
303 .mid_rid = 0x39,
304 }, {
305 .slave_id = SHDMA_SLAVE_SCIF4_RX,
306 .addr = 0xe6c80024,
307 .chcr = DM_INC | SM_FIX | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
308 .mid_rid = 0x3a,
309 }, {
310 .slave_id = SHDMA_SLAVE_SCIF5_TX,
311 .addr = 0xe6cb0020,
312 .chcr = DM_FIX | SM_INC | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
313 .mid_rid = 0x35,
314 }, {
315 .slave_id = SHDMA_SLAVE_SCIF5_RX,
316 .addr = 0xe6cb0024,
317 .chcr = DM_INC | SM_FIX | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
318 .mid_rid = 0x36,
319 }, {
320 .slave_id = SHDMA_SLAVE_SCIF6_TX,
321 .addr = 0xe6c30040,
322 .chcr = DM_FIX | SM_INC | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
323 .mid_rid = 0x3d,
324 }, {
325 .slave_id = SHDMA_SLAVE_SCIF6_RX,
326 .addr = 0xe6c30060,
327 .chcr = DM_INC | SM_FIX | 0x800 | TS_INDEX2VAL(XMIT_SZ_8BIT),
328 .mid_rid = 0x3e,
329 }, {
330 .slave_id = SHDMA_SLAVE_SDHI0_TX,
331 .addr = 0xe6850030,
332 .chcr = DM_FIX | SM_INC | 0x800 | TS_INDEX2VAL(XMIT_SZ_16BIT),
333 .mid_rid = 0xc1,
334 }, {
335 .slave_id = SHDMA_SLAVE_SDHI0_RX,
336 .addr = 0xe6850030,
337 .chcr = DM_INC | SM_FIX | 0x800 | TS_INDEX2VAL(XMIT_SZ_16BIT),
338 .mid_rid = 0xc2,
339 }, {
340 .slave_id = SHDMA_SLAVE_SDHI1_TX,
341 .addr = 0xe6860030,
342 .chcr = DM_FIX | SM_INC | 0x800 | TS_INDEX2VAL(XMIT_SZ_16BIT),
343 .mid_rid = 0xc9,
344 }, {
345 .slave_id = SHDMA_SLAVE_SDHI1_RX,
346 .addr = 0xe6860030,
347 .chcr = DM_INC | SM_FIX | 0x800 | TS_INDEX2VAL(XMIT_SZ_16BIT),
348 .mid_rid = 0xca,
349 }, {
350 .slave_id = SHDMA_SLAVE_SDHI2_TX,
351 .addr = 0xe6870030,
352 .chcr = DM_FIX | SM_INC | 0x800 | TS_INDEX2VAL(XMIT_SZ_16BIT),
353 .mid_rid = 0xcd,
354 }, {
355 .slave_id = SHDMA_SLAVE_SDHI2_RX,
356 .addr = 0xe6870030,
357 .chcr = DM_INC | SM_FIX | 0x800 | TS_INDEX2VAL(XMIT_SZ_16BIT),
358 .mid_rid = 0xce,
359 },
360};
361
362static const struct sh_dmae_channel sh7372_dmae_channels[] = {
363 {
364 .offset = 0,
365 .dmars = 0,
366 .dmars_bit = 0,
367 }, {
368 .offset = 0x10,
369 .dmars = 0,
370 .dmars_bit = 8,
371 }, {
372 .offset = 0x20,
373 .dmars = 4,
374 .dmars_bit = 0,
375 }, {
376 .offset = 0x30,
377 .dmars = 4,
378 .dmars_bit = 8,
379 }, {
380 .offset = 0x50,
381 .dmars = 8,
382 .dmars_bit = 0,
383 }, {
384 .offset = 0x60,
385 .dmars = 8,
386 .dmars_bit = 8,
387 }
388};
389
390static const unsigned int ts_shift[] = TS_SHIFT;
391
392static struct sh_dmae_pdata dma_platform_data = {
393 .slave = sh7372_dmae_slaves,
394 .slave_num = ARRAY_SIZE(sh7372_dmae_slaves),
395 .channel = sh7372_dmae_channels,
396 .channel_num = ARRAY_SIZE(sh7372_dmae_channels),
397 .ts_low_shift = 3,
398 .ts_low_mask = 0x18,
399 .ts_high_shift = (20 - 2), /* 2 bits for shifted low TS */
400 .ts_high_mask = 0x00300000,
401 .ts_shift = ts_shift,
402 .ts_shift_num = ARRAY_SIZE(ts_shift),
403 .dmaor_init = DMAOR_DME,
404};
405
406/* Resource order important! */
407static struct resource sh7372_dmae0_resources[] = {
408 {
409 /* Channel registers and DMAOR */
410 .start = 0xfe008020,
411 .end = 0xfe00808f,
412 .flags = IORESOURCE_MEM,
413 },
414 {
415 /* DMARSx */
416 .start = 0xfe009000,
417 .end = 0xfe00900b,
418 .flags = IORESOURCE_MEM,
419 },
420 {
421 /* DMA error IRQ */
422 .start = 246,
423 .end = 246,
424 .flags = IORESOURCE_IRQ,
425 },
426 {
427 /* IRQ for channels 0-5 */
428 .start = 240,
429 .end = 245,
430 .flags = IORESOURCE_IRQ,
431 },
432};
433
434/* Resource order important! */
435static struct resource sh7372_dmae1_resources[] = {
436 {
437 /* Channel registers and DMAOR */
438 .start = 0xfe018020,
439 .end = 0xfe01808f,
440 .flags = IORESOURCE_MEM,
441 },
442 {
443 /* DMARSx */
444 .start = 0xfe019000,
445 .end = 0xfe01900b,
446 .flags = IORESOURCE_MEM,
447 },
448 {
449 /* DMA error IRQ */
450 .start = 254,
451 .end = 254,
452 .flags = IORESOURCE_IRQ,
453 },
454 {
455 /* IRQ for channels 0-5 */
456 .start = 248,
457 .end = 253,
458 .flags = IORESOURCE_IRQ,
459 },
460};
461
462/* Resource order important! */
463static struct resource sh7372_dmae2_resources[] = {
464 {
465 /* Channel registers and DMAOR */
466 .start = 0xfe028020,
467 .end = 0xfe02808f,
468 .flags = IORESOURCE_MEM,
469 },
470 {
471 /* DMARSx */
472 .start = 0xfe029000,
473 .end = 0xfe02900b,
474 .flags = IORESOURCE_MEM,
475 },
476 {
477 /* DMA error IRQ */
478 .start = 262,
479 .end = 262,
480 .flags = IORESOURCE_IRQ,
481 },
482 {
483 /* IRQ for channels 0-5 */
484 .start = 256,
485 .end = 261,
486 .flags = IORESOURCE_IRQ,
487 },
488};
489
490static struct platform_device dma0_device = {
491 .name = "sh-dma-engine",
492 .id = 0,
493 .resource = sh7372_dmae0_resources,
494 .num_resources = ARRAY_SIZE(sh7372_dmae0_resources),
495 .dev = {
496 .platform_data = &dma_platform_data,
497 },
498};
499
500static struct platform_device dma1_device = {
501 .name = "sh-dma-engine",
502 .id = 1,
503 .resource = sh7372_dmae1_resources,
504 .num_resources = ARRAY_SIZE(sh7372_dmae1_resources),
505 .dev = {
506 .platform_data = &dma_platform_data,
507 },
508};
509
510static struct platform_device dma2_device = {
511 .name = "sh-dma-engine",
512 .id = 2,
513 .resource = sh7372_dmae2_resources,
514 .num_resources = ARRAY_SIZE(sh7372_dmae2_resources),
515 .dev = {
516 .platform_data = &dma_platform_data,
517 },
518};
519
172static struct platform_device *sh7372_early_devices[] __initdata = { 520static struct platform_device *sh7372_early_devices[] __initdata = {
173 &scif0_device, 521 &scif0_device,
174 &scif1_device, 522 &scif1_device,
@@ -178,6 +526,11 @@ static struct platform_device *sh7372_early_devices[] __initdata = {
178 &scif5_device, 526 &scif5_device,
179 &scif6_device, 527 &scif6_device,
180 &cmt10_device, 528 &cmt10_device,
529 &iic0_device,
530 &iic1_device,
531 &dma0_device,
532 &dma1_device,
533 &dma2_device,
181}; 534};
182 535
183void __init sh7372_add_standard_devices(void) 536void __init sh7372_add_standard_devices(void)
@@ -186,14 +539,8 @@ void __init sh7372_add_standard_devices(void)
186 ARRAY_SIZE(sh7372_early_devices)); 539 ARRAY_SIZE(sh7372_early_devices));
187} 540}
188 541
189#define SMSTPCR3 0xe615013c
190#define SMSTPCR3_CMT1 (1 << 29)
191
192void __init sh7372_add_early_devices(void) 542void __init sh7372_add_early_devices(void)
193{ 543{
194 /* enable clock to CMT1 */
195 __raw_writel(__raw_readl(SMSTPCR3) & ~SMSTPCR3_CMT1, SMSTPCR3);
196
197 early_platform_add_devices(sh7372_early_devices, 544 early_platform_add_devices(sh7372_early_devices,
198 ARRAY_SIZE(sh7372_early_devices)); 545 ARRAY_SIZE(sh7372_early_devices));
199} 546}
diff --git a/arch/arm/mach-shmobile/setup-sh7377.c b/arch/arm/mach-shmobile/setup-sh7377.c
index 60e37774c35c..bb4adf17dbf4 100644
--- a/arch/arm/mach-shmobile/setup-sh7377.c
+++ b/arch/arm/mach-shmobile/setup-sh7377.c
@@ -32,11 +32,13 @@
32#include <asm/mach-types.h> 32#include <asm/mach-types.h>
33#include <asm/mach/arch.h> 33#include <asm/mach/arch.h>
34 34
35/* SCIFA0 */
35static struct plat_sci_port scif0_platform_data = { 36static struct plat_sci_port scif0_platform_data = {
36 .mapbase = 0xe6c40000, 37 .mapbase = 0xe6c40000,
37 .flags = UPF_BOOT_AUTOCONF, 38 .flags = UPF_BOOT_AUTOCONF,
38 .type = PORT_SCIF, 39 .type = PORT_SCIF,
39 .irqs = { 80, 80, 80, 80 }, 40 .irqs = { evt2irq(0xc00), evt2irq(0xc00),
41 evt2irq(0xc00), evt2irq(0xc00) },
40}; 42};
41 43
42static struct platform_device scif0_device = { 44static struct platform_device scif0_device = {
@@ -47,11 +49,13 @@ static struct platform_device scif0_device = {
47 }, 49 },
48}; 50};
49 51
52/* SCIFA1 */
50static struct plat_sci_port scif1_platform_data = { 53static struct plat_sci_port scif1_platform_data = {
51 .mapbase = 0xe6c50000, 54 .mapbase = 0xe6c50000,
52 .flags = UPF_BOOT_AUTOCONF, 55 .flags = UPF_BOOT_AUTOCONF,
53 .type = PORT_SCIF, 56 .type = PORT_SCIF,
54 .irqs = { 81, 81, 81, 81 }, 57 .irqs = { evt2irq(0xc20), evt2irq(0xc20),
58 evt2irq(0xc20), evt2irq(0xc20) },
55}; 59};
56 60
57static struct platform_device scif1_device = { 61static struct platform_device scif1_device = {
@@ -62,11 +66,13 @@ static struct platform_device scif1_device = {
62 }, 66 },
63}; 67};
64 68
69/* SCIFA2 */
65static struct plat_sci_port scif2_platform_data = { 70static struct plat_sci_port scif2_platform_data = {
66 .mapbase = 0xe6c60000, 71 .mapbase = 0xe6c60000,
67 .flags = UPF_BOOT_AUTOCONF, 72 .flags = UPF_BOOT_AUTOCONF,
68 .type = PORT_SCIF, 73 .type = PORT_SCIF,
69 .irqs = { 82, 82, 82, 82 }, 74 .irqs = { evt2irq(0xc40), evt2irq(0xc40),
75 evt2irq(0xc40), evt2irq(0xc40) },
70}; 76};
71 77
72static struct platform_device scif2_device = { 78static struct platform_device scif2_device = {
@@ -77,11 +83,13 @@ static struct platform_device scif2_device = {
77 }, 83 },
78}; 84};
79 85
86/* SCIFA3 */
80static struct plat_sci_port scif3_platform_data = { 87static struct plat_sci_port scif3_platform_data = {
81 .mapbase = 0xe6c70000, 88 .mapbase = 0xe6c70000,
82 .flags = UPF_BOOT_AUTOCONF, 89 .flags = UPF_BOOT_AUTOCONF,
83 .type = PORT_SCIF, 90 .type = PORT_SCIF,
84 .irqs = { 83, 83, 83, 83 }, 91 .irqs = { evt2irq(0xc60), evt2irq(0xc60),
92 evt2irq(0xc60), evt2irq(0xc60) },
85}; 93};
86 94
87static struct platform_device scif3_device = { 95static struct platform_device scif3_device = {
@@ -92,11 +100,13 @@ static struct platform_device scif3_device = {
92 }, 100 },
93}; 101};
94 102
103/* SCIFA4 */
95static struct plat_sci_port scif4_platform_data = { 104static struct plat_sci_port scif4_platform_data = {
96 .mapbase = 0xe6c80000, 105 .mapbase = 0xe6c80000,
97 .flags = UPF_BOOT_AUTOCONF, 106 .flags = UPF_BOOT_AUTOCONF,
98 .type = PORT_SCIF, 107 .type = PORT_SCIF,
99 .irqs = { 89, 89, 89, 89 }, 108 .irqs = { evt2irq(0xd20), evt2irq(0xd20),
109 evt2irq(0xd20), evt2irq(0xd20) },
100}; 110};
101 111
102static struct platform_device scif4_device = { 112static struct platform_device scif4_device = {
@@ -107,11 +117,13 @@ static struct platform_device scif4_device = {
107 }, 117 },
108}; 118};
109 119
120/* SCIFA5 */
110static struct plat_sci_port scif5_platform_data = { 121static struct plat_sci_port scif5_platform_data = {
111 .mapbase = 0xe6cb0000, 122 .mapbase = 0xe6cb0000,
112 .flags = UPF_BOOT_AUTOCONF, 123 .flags = UPF_BOOT_AUTOCONF,
113 .type = PORT_SCIF, 124 .type = PORT_SCIF,
114 .irqs = { 90, 90, 90, 90 }, 125 .irqs = { evt2irq(0xd40), evt2irq(0xd40),
126 evt2irq(0xd40), evt2irq(0xd40) },
115}; 127};
116 128
117static struct platform_device scif5_device = { 129static struct platform_device scif5_device = {
@@ -122,11 +134,13 @@ static struct platform_device scif5_device = {
122 }, 134 },
123}; 135};
124 136
137/* SCIFA6 */
125static struct plat_sci_port scif6_platform_data = { 138static struct plat_sci_port scif6_platform_data = {
126 .mapbase = 0xe6cc0000, 139 .mapbase = 0xe6cc0000,
127 .flags = UPF_BOOT_AUTOCONF, 140 .flags = UPF_BOOT_AUTOCONF,
128 .type = PORT_SCIF, 141 .type = PORT_SCIF,
129 .irqs = { 196, 196, 196, 196 }, 142 .irqs = { intcs_evt2irq(0x1a80), intcs_evt2irq(0x1a80),
143 intcs_evt2irq(0x1a80), intcs_evt2irq(0x1a80) },
130}; 144};
131 145
132static struct platform_device scif6_device = { 146static struct platform_device scif6_device = {
@@ -137,11 +151,13 @@ static struct platform_device scif6_device = {
137 }, 151 },
138}; 152};
139 153
154/* SCIFB */
140static struct plat_sci_port scif7_platform_data = { 155static struct plat_sci_port scif7_platform_data = {
141 .mapbase = 0xe6c30000, 156 .mapbase = 0xe6c30000,
142 .flags = UPF_BOOT_AUTOCONF, 157 .flags = UPF_BOOT_AUTOCONF,
143 .type = PORT_SCIF, 158 .type = PORT_SCIF,
144 .irqs = { 91, 91, 91, 91 }, 159 .irqs = { evt2irq(0xd60), evt2irq(0xd60),
160 evt2irq(0xd60), evt2irq(0xd60) },
145}; 161};
146 162
147static struct platform_device scif7_device = { 163static struct platform_device scif7_device = {
@@ -169,7 +185,7 @@ static struct resource cmt10_resources[] = {
169 .flags = IORESOURCE_MEM, 185 .flags = IORESOURCE_MEM,
170 }, 186 },
171 [1] = { 187 [1] = {
172 .start = 72, 188 .start = evt2irq(0xb00), /* CMT1_CMT10 */
173 .flags = IORESOURCE_IRQ, 189 .flags = IORESOURCE_IRQ,
174 }, 190 },
175}; 191};
diff --git a/arch/arm/mach-u300/clock.c b/arch/arm/mach-u300/clock.c
index 5d12d547789e..60acf9e708ae 100644
--- a/arch/arm/mach-u300/clock.c
+++ b/arch/arm/mach-u300/clock.c
@@ -947,6 +947,10 @@ static struct clk fast_clk = {
947 .lock = __SPIN_LOCK_UNLOCKED(fast_clk.lock), 947 .lock = __SPIN_LOCK_UNLOCKED(fast_clk.lock),
948}; 948};
949 949
950/*
951 * The MMCI apb_pclk is hardwired to the same terminal as the
952 * external MCI clock. Thus this will be referenced twice.
953 */
950static struct clk mmcsd_clk = { 954static struct clk mmcsd_clk = {
951 .name = "MCLK", 955 .name = "MCLK",
952 .parent = &fast_clk, 956 .parent = &fast_clk,
@@ -1024,6 +1028,10 @@ static struct clk i2c1_clk = {
1024 .lock = __SPIN_LOCK_UNLOCKED(i2c1_clk.lock), 1028 .lock = __SPIN_LOCK_UNLOCKED(i2c1_clk.lock),
1025}; 1029};
1026 1030
1031/*
1032 * The SPI apb_pclk is hardwired to the same terminal as the
1033 * external SPI clock. Thus this will be referenced twice.
1034 */
1027static struct clk spi_clk = { 1035static struct clk spi_clk = {
1028 .name = "SPI", 1036 .name = "SPI",
1029 .parent = &fast_clk, 1037 .parent = &fast_clk,
@@ -1040,10 +1048,9 @@ static struct clk spi_clk = {
1040}; 1048};
1041 1049
1042#ifdef CONFIG_MACH_U300_BS335 1050#ifdef CONFIG_MACH_U300_BS335
1043static struct clk uart1_clk = { 1051static struct clk uart1_pclk = {
1044 .name = "UART1", 1052 .name = "UART1_PCLK",
1045 .parent = &fast_clk, 1053 .parent = &fast_clk,
1046 .rate = 13000000,
1047 .hw_ctrld = false, 1054 .hw_ctrld = false,
1048 .reset = true, 1055 .reset = true,
1049 .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RFR, 1056 .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RFR,
@@ -1051,6 +1058,14 @@ static struct clk uart1_clk = {
1051 .clk_val = U300_SYSCON_SBCER_UART1_CLK_EN, 1058 .clk_val = U300_SYSCON_SBCER_UART1_CLK_EN,
1052 .enable = syscon_clk_enable, 1059 .enable = syscon_clk_enable,
1053 .disable = syscon_clk_disable, 1060 .disable = syscon_clk_disable,
1061 .lock = __SPIN_LOCK_UNLOCKED(uart1_pclk.lock),
1062};
1063
1064/* This one is hardwired to PLL13 */
1065static struct clk uart1_clk = {
1066 .name = "UART1_CLK",
1067 .rate = 13000000,
1068 .hw_ctrld = true,
1054 .lock = __SPIN_LOCK_UNLOCKED(uart1_clk.lock), 1069 .lock = __SPIN_LOCK_UNLOCKED(uart1_clk.lock),
1055}; 1070};
1056#endif 1071#endif
@@ -1085,11 +1100,9 @@ static struct clk wdog_clk = {
1085 .lock = __SPIN_LOCK_UNLOCKED(wdog_clk.lock), 1100 .lock = __SPIN_LOCK_UNLOCKED(wdog_clk.lock),
1086}; 1101};
1087 1102
1088/* This one is hardwired to PLL13 */ 1103static struct clk uart0_pclk = {
1089static struct clk uart_clk = { 1104 .name = "UART0_PCLK",
1090 .name = "UARTCLK",
1091 .parent = &slow_clk, 1105 .parent = &slow_clk,
1092 .rate = 13000000,
1093 .hw_ctrld = false, 1106 .hw_ctrld = false,
1094 .reset = true, 1107 .reset = true,
1095 .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR, 1108 .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR,
@@ -1097,7 +1110,16 @@ static struct clk uart_clk = {
1097 .clk_val = U300_SYSCON_SBCER_UART_CLK_EN, 1110 .clk_val = U300_SYSCON_SBCER_UART_CLK_EN,
1098 .enable = syscon_clk_enable, 1111 .enable = syscon_clk_enable,
1099 .disable = syscon_clk_disable, 1112 .disable = syscon_clk_disable,
1100 .lock = __SPIN_LOCK_UNLOCKED(uart_clk.lock), 1113 .lock = __SPIN_LOCK_UNLOCKED(uart0_pclk.lock),
1114};
1115
1116/* This one is hardwired to PLL13 */
1117static struct clk uart0_clk = {
1118 .name = "UART0_CLK",
1119 .parent = &slow_clk,
1120 .rate = 13000000,
1121 .hw_ctrld = true,
1122 .lock = __SPIN_LOCK_UNLOCKED(uart0_clk.lock),
1101}; 1123};
1102 1124
1103static struct clk keypad_clk = { 1125static struct clk keypad_clk = {
@@ -1182,10 +1204,14 @@ static struct clk timer_clk = {
1182 .lock = __SPIN_LOCK_UNLOCKED(timer_clk.lock), 1204 .lock = __SPIN_LOCK_UNLOCKED(timer_clk.lock),
1183}; 1205};
1184 1206
1207/*
1208 * There is a binary divider in the hardware that divides
1209 * the 13MHz PLL by 13 down to 1 MHz.
1210 */
1185static struct clk app_timer_clk = { 1211static struct clk app_timer_clk = {
1186 .name = "TIMER_APP", 1212 .name = "TIMER_APP",
1187 .parent = &slow_clk, 1213 .parent = &slow_clk,
1188 .rate = 13000000, 1214 .rate = 1000000,
1189 .hw_ctrld = true, 1215 .hw_ctrld = true,
1190 .reset = true, 1216 .reset = true,
1191 .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR, 1217 .res_reg = U300_SYSCON_VBASE + U300_SYSCON_RSR,
@@ -1212,23 +1238,24 @@ static struct clk ppm_clk = {
1212}; 1238};
1213#endif 1239#endif
1214 1240
1215static struct clk dummy_apb_pclk;
1216
1217#define DEF_LOOKUP(devid, clkref) \ 1241#define DEF_LOOKUP(devid, clkref) \
1218 { \ 1242 { \
1219 .dev_id = devid, \ 1243 .dev_id = devid, \
1220 .clk = clkref, \ 1244 .clk = clkref, \
1221 } 1245 }
1222 1246
1247#define DEF_LOOKUP_CON(devid, conid, clkref) \
1248 { \
1249 .dev_id = devid, \
1250 .con_id = conid, \
1251 .clk = clkref, \
1252 }
1253
1223/* 1254/*
1224 * Here we only define clocks that are meaningful to 1255 * Here we only define clocks that are meaningful to
1225 * look up through clockdevice. 1256 * look up through clockdevice.
1226 */ 1257 */
1227static struct clk_lookup lookups[] = { 1258static struct clk_lookup lookups[] = {
1228 {
1229 .con_id = "apb_pclk",
1230 .clk = &dummy_apb_pclk,
1231 },
1232 /* Connected directly to the AMBA bus */ 1259 /* Connected directly to the AMBA bus */
1233 DEF_LOOKUP("amba", &amba_clk), 1260 DEF_LOOKUP("amba", &amba_clk),
1234 DEF_LOOKUP("cpu", &cpu_clk), 1261 DEF_LOOKUP("cpu", &cpu_clk),
@@ -1247,11 +1274,14 @@ static struct clk_lookup lookups[] = {
1247 /* AHB bridge clocks */ 1274 /* AHB bridge clocks */
1248 DEF_LOOKUP("ahb_subsys", &ahb_subsys_clk), 1275 DEF_LOOKUP("ahb_subsys", &ahb_subsys_clk),
1249 DEF_LOOKUP("intcon", &intcon_clk), 1276 DEF_LOOKUP("intcon", &intcon_clk),
1277 DEF_LOOKUP_CON("intcon", "apb_pclk", &intcon_clk),
1250 DEF_LOOKUP("mspro", &mspro_clk), 1278 DEF_LOOKUP("mspro", &mspro_clk),
1251 DEF_LOOKUP("pl172", &emif_clk), 1279 DEF_LOOKUP("pl172", &emif_clk),
1280 DEF_LOOKUP_CON("pl172", "apb_pclk", &emif_clk),
1252 /* FAST bridge clocks */ 1281 /* FAST bridge clocks */
1253 DEF_LOOKUP("fast", &fast_clk), 1282 DEF_LOOKUP("fast", &fast_clk),
1254 DEF_LOOKUP("mmci", &mmcsd_clk), 1283 DEF_LOOKUP("mmci", &mmcsd_clk),
1284 DEF_LOOKUP_CON("mmci", "apb_pclk", &mmcsd_clk),
1255 /* 1285 /*
1256 * The .0 and .1 identifiers on these comes from the platform device 1286 * The .0 and .1 identifiers on these comes from the platform device
1257 * .id field and are assigned when the platform devices are registered. 1287 * .id field and are assigned when the platform devices are registered.
@@ -1261,13 +1291,16 @@ static struct clk_lookup lookups[] = {
1261 DEF_LOOKUP("stu300.0", &i2c0_clk), 1291 DEF_LOOKUP("stu300.0", &i2c0_clk),
1262 DEF_LOOKUP("stu300.1", &i2c1_clk), 1292 DEF_LOOKUP("stu300.1", &i2c1_clk),
1263 DEF_LOOKUP("pl022", &spi_clk), 1293 DEF_LOOKUP("pl022", &spi_clk),
1294 DEF_LOOKUP_CON("pl022", "apb_pclk", &spi_clk),
1264#ifdef CONFIG_MACH_U300_BS335 1295#ifdef CONFIG_MACH_U300_BS335
1265 DEF_LOOKUP("uart1", &uart1_clk), 1296 DEF_LOOKUP("uart1", &uart1_clk),
1297 DEF_LOOKUP_CON("uart1", "apb_pclk", &uart1_pclk),
1266#endif 1298#endif
1267 /* SLOW bridge clocks */ 1299 /* SLOW bridge clocks */
1268 DEF_LOOKUP("slow", &slow_clk), 1300 DEF_LOOKUP("slow", &slow_clk),
1269 DEF_LOOKUP("coh901327_wdog", &wdog_clk), 1301 DEF_LOOKUP("coh901327_wdog", &wdog_clk),
1270 DEF_LOOKUP("uart0", &uart_clk), 1302 DEF_LOOKUP("uart0", &uart0_clk),
1303 DEF_LOOKUP_CON("uart0", "apb_pclk", &uart0_pclk),
1271 DEF_LOOKUP("apptimer", &app_timer_clk), 1304 DEF_LOOKUP("apptimer", &app_timer_clk),
1272 DEF_LOOKUP("coh901461-keypad", &keypad_clk), 1305 DEF_LOOKUP("coh901461-keypad", &keypad_clk),
1273 DEF_LOOKUP("u300-gpio", &gpio_clk), 1306 DEF_LOOKUP("u300-gpio", &gpio_clk),
@@ -1286,64 +1319,6 @@ static void __init clk_register(void)
1286 clkdev_add_table(lookups, ARRAY_SIZE(lookups)); 1319 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
1287} 1320}
1288 1321
1289/*
1290 * These are the clocks for cells registered as primecell drivers
1291 * on the AMBA bus. These must be on during AMBA device registration
1292 * since the bus probe will attempt to read magic configuration
1293 * registers for these devices. If they are deactivated these probes
1294 * will fail.
1295 *
1296 *
1297 * Please note that on emif, both RAM and NAND is connected in dual
1298 * RAM phones. On single RAM phones, ram is on semi and NAND on emif.
1299 *
1300 */
1301void u300_clock_primecells(void)
1302{
1303 clk_enable(&intcon_clk);
1304 clk_enable(&uart_clk);
1305#ifdef CONFIG_MACH_U300_BS335
1306 clk_enable(&uart1_clk);
1307#endif
1308 clk_enable(&spi_clk);
1309
1310 clk_enable(&mmcsd_clk);
1311
1312}
1313EXPORT_SYMBOL(u300_clock_primecells);
1314
1315void u300_unclock_primecells(void)
1316{
1317
1318 clk_disable(&intcon_clk);
1319 clk_disable(&uart_clk);
1320#ifdef CONFIG_MACH_U300_BS335
1321 clk_disable(&uart1_clk);
1322#endif
1323 clk_disable(&spi_clk);
1324 clk_disable(&mmcsd_clk);
1325
1326}
1327EXPORT_SYMBOL(u300_unclock_primecells);
1328
1329/*
1330 * The interrupt controller is enabled before the clock API is registered.
1331 */
1332void u300_enable_intcon_clock(void)
1333{
1334 clk_enable(&intcon_clk);
1335}
1336EXPORT_SYMBOL(u300_enable_intcon_clock);
1337
1338/*
1339 * The timer is enabled before the clock API is registered.
1340 */
1341void u300_enable_timer_clock(void)
1342{
1343 clk_enable(&app_timer_clk);
1344}
1345EXPORT_SYMBOL(u300_enable_timer_clock);
1346
1347#if (defined(CONFIG_DEBUG_FS) && defined(CONFIG_U300_DEBUG)) 1322#if (defined(CONFIG_DEBUG_FS) && defined(CONFIG_U300_DEBUG))
1348/* 1323/*
1349 * The following makes it possible to view the status (especially 1324 * The following makes it possible to view the status (especially
@@ -1385,11 +1360,13 @@ static struct clk *clks[] = {
1385 &spi_clk, 1360 &spi_clk,
1386#ifdef CONFIG_MACH_U300_BS335 1361#ifdef CONFIG_MACH_U300_BS335
1387 &uart1_clk, 1362 &uart1_clk,
1363 &uart1_pclk,
1388#endif 1364#endif
1389 /* SLOW bridge clocks */ 1365 /* SLOW bridge clocks */
1390 &slow_clk, 1366 &slow_clk,
1391 &wdog_clk, 1367 &wdog_clk,
1392 &uart_clk, 1368 &uart0_clk,
1369 &uart0_pclk,
1393 &app_timer_clk, 1370 &app_timer_clk,
1394 &keypad_clk, 1371 &keypad_clk,
1395 &gpio_clk, 1372 &gpio_clk,
@@ -1430,7 +1407,7 @@ static int u300_clocks_show(struct seq_file *s, void *data)
1430 chars++; 1407 chars++;
1431 } 1408 }
1432 cdp[32] = '\0'; 1409 cdp[32] = '\0';
1433 if (clk->get_rate) 1410 if (clk->get_rate || clk->rate != 0)
1434 seq_printf(s, 1411 seq_printf(s,
1435 "%s%s\t%s\t%d\t%s\t%lu Hz\n", 1412 "%s%s\t%s\t%d\t%s\t%lu Hz\n",
1436 &cdp[0], 1413 &cdp[0],
@@ -1439,7 +1416,7 @@ static int u300_clocks_show(struct seq_file *s, void *data)
1439 clk->usecount ? "ON" : "OFF", 1416 clk->usecount ? "ON" : "OFF",
1440 clk->usecount, 1417 clk->usecount,
1441 clk->hw_ctrld ? "YES" : "NO ", 1418 clk->hw_ctrld ? "YES" : "NO ",
1442 clk->get_rate(clk)); 1419 clk_get_rate(clk));
1443 else 1420 else
1444 seq_printf(s, 1421 seq_printf(s,
1445 "%s%s\t%s\t%d\t%s\t" \ 1422 "%s%s\t%s\t%d\t%s\t" \
@@ -1483,7 +1460,7 @@ static int __init init_clk_read_debugfs(void)
1483module_init(init_clk_read_debugfs); 1460module_init(init_clk_read_debugfs);
1484#endif 1461#endif
1485 1462
1486static int __init u300_clock_init(void) 1463int __init u300_clock_init(void)
1487{ 1464{
1488 u16 val; 1465 u16 val;
1489 1466
@@ -1520,10 +1497,8 @@ static int __init u300_clock_init(void)
1520 */ 1497 */
1521 syscon_block_reset_disable(&semi_clk); 1498 syscon_block_reset_disable(&semi_clk);
1522 syscon_block_reset_disable(&emif_clk); 1499 syscon_block_reset_disable(&emif_clk);
1523 semi_clk.enable(&semi_clk); 1500 clk_enable(&semi_clk);
1524 emif_clk.enable(&emif_clk); 1501 clk_enable(&emif_clk);
1525 1502
1526 return 0; 1503 return 0;
1527} 1504}
1528/* initialize clocking early to be available later in the boot */
1529core_initcall(u300_clock_init);
diff --git a/arch/arm/mach-u300/clock.h b/arch/arm/mach-u300/clock.h
index fc6d9ccfe7e3..c34f3ea3017c 100644
--- a/arch/arm/mach-u300/clock.h
+++ b/arch/arm/mach-u300/clock.h
@@ -45,9 +45,6 @@ struct clk {
45 void (*disable) (struct clk *); 45 void (*disable) (struct clk *);
46}; 46};
47 47
48void u300_clock_primecells(void); 48int u300_clock_init(void);
49void u300_unclock_primecells(void);
50void u300_enable_intcon_clock(void);
51void u300_enable_timer_clock(void);
52 49
53#endif 50#endif
diff --git a/arch/arm/mach-u300/core.c b/arch/arm/mach-u300/core.c
index 653b3e0ab7ba..ea41c236be0f 100644
--- a/arch/arm/mach-u300/core.c
+++ b/arch/arm/mach-u300/core.c
@@ -19,6 +19,8 @@
19#include <linux/amba/bus.h> 19#include <linux/amba/bus.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/gpio.h> 21#include <linux/gpio.h>
22#include <linux/clk.h>
23#include <linux/err.h>
22#include <mach/coh901318.h> 24#include <mach/coh901318.h>
23 25
24#include <asm/types.h> 26#include <asm/types.h>
@@ -1477,11 +1479,19 @@ static struct platform_device *platform_devs[] __initdata = {
1477void __init u300_init_irq(void) 1479void __init u300_init_irq(void)
1478{ 1480{
1479 u32 mask[2] = {0, 0}; 1481 u32 mask[2] = {0, 0};
1482 struct clk *clk;
1480 int i; 1483 int i;
1481 1484
1485 /* initialize clocking early, we want to clock the INTCON */
1486 u300_clock_init();
1487
1488 /* Clock the interrupt controller */
1489 clk = clk_get_sys("intcon", NULL);
1490 BUG_ON(IS_ERR(clk));
1491 clk_enable(clk);
1492
1482 for (i = 0; i < NR_IRQS; i++) 1493 for (i = 0; i < NR_IRQS; i++)
1483 set_bit(i, (unsigned long *) &mask[0]); 1494 set_bit(i, (unsigned long *) &mask[0]);
1484 u300_enable_intcon_clock();
1485 vic_init((void __iomem *) U300_INTCON0_VBASE, 0, mask[0], mask[0]); 1495 vic_init((void __iomem *) U300_INTCON0_VBASE, 0, mask[0], mask[0]);
1486 vic_init((void __iomem *) U300_INTCON1_VBASE, 32, mask[1], mask[1]); 1496 vic_init((void __iomem *) U300_INTCON1_VBASE, 32, mask[1], mask[1]);
1487} 1497}
@@ -1635,12 +1645,10 @@ void __init u300_init_devices(void)
1635 u300_spi_init(&pl022_device); 1645 u300_spi_init(&pl022_device);
1636 1646
1637 /* Register the AMBA devices in the AMBA bus abstraction layer */ 1647 /* Register the AMBA devices in the AMBA bus abstraction layer */
1638 u300_clock_primecells();
1639 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { 1648 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
1640 struct amba_device *d = amba_devs[i]; 1649 struct amba_device *d = amba_devs[i];
1641 amba_device_register(d, &iomem_resource); 1650 amba_device_register(d, &iomem_resource);
1642 } 1651 }
1643 u300_unclock_primecells();
1644 1652
1645 u300_assign_physmem(); 1653 u300_assign_physmem();
1646 1654
diff --git a/arch/arm/mach-u300/mmc.c b/arch/arm/mach-u300/mmc.c
index 88506d030596..de1ac9ad2213 100644
--- a/arch/arm/mach-u300/mmc.c
+++ b/arch/arm/mach-u300/mmc.c
@@ -74,16 +74,16 @@ static void _mmci_callback(struct work_struct *ws)
74 74
75 mdelay(20); 75 mdelay(20);
76 76
77 mmci_card->mmc_inserted = !!gpio_get_value(U300_GPIO_PIN_MMC_CD); 77 mmci_card->mmc_inserted = !gpio_get_value(U300_GPIO_PIN_MMC_CD);
78 78
79 input_report_switch(mmci_card->mmc_input, KEY_INSERT, 79 input_report_switch(mmci_card->mmc_input, KEY_INSERT,
80 !mmci_card->mmc_inserted); 80 mmci_card->mmc_inserted);
81 input_sync(mmci_card->mmc_input); 81 input_sync(mmci_card->mmc_input);
82 82
83 pr_debug("MMC/SD card was %s\n", 83 pr_debug("MMC/SD card was %s\n",
84 mmci_card->mmc_inserted ? "removed" : "inserted"); 84 mmci_card->mmc_inserted ? "inserted" : "removed");
85 85
86 enable_irq_on_gpio_pin(U300_GPIO_PIN_MMC_CD, !mmci_card->mmc_inserted); 86 enable_irq_on_gpio_pin(U300_GPIO_PIN_MMC_CD, mmci_card->mmc_inserted);
87} 87}
88 88
89int __devinit mmc_init(struct amba_device *adev) 89int __devinit mmc_init(struct amba_device *adev)
diff --git a/arch/arm/mach-u300/timer.c b/arch/arm/mach-u300/timer.c
index 26d26f5100fe..3fc4472719be 100644
--- a/arch/arm/mach-u300/timer.c
+++ b/arch/arm/mach-u300/timer.c
@@ -15,6 +15,8 @@
15#include <linux/clocksource.h> 15#include <linux/clocksource.h>
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/clk.h>
19#include <linux/err.h>
18 20
19#include <mach/hardware.h> 21#include <mach/hardware.h>
20 22
@@ -23,7 +25,8 @@
23#include <asm/mach/time.h> 25#include <asm/mach/time.h>
24#include <asm/mach/irq.h> 26#include <asm/mach/irq.h>
25 27
26#include "clock.h" 28/* Be able to sleep for atleast 4 seconds (usually more) */
29#define APPTIMER_MIN_RANGE 4
27 30
28/* 31/*
29 * APP side special timer registers 32 * APP side special timer registers
@@ -307,8 +310,6 @@ static struct clock_event_device clockevent_u300_1mhz = {
307 .name = "GPT1", 310 .name = "GPT1",
308 .rating = 300, /* Reasonably fast and accurate clock event */ 311 .rating = 300, /* Reasonably fast and accurate clock event */
309 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, 312 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
310 /* 22 calculated using the algorithm in arch/mips/kernel/time.c */
311 .shift = 22,
312 .set_next_event = u300_set_next_event, 313 .set_next_event = u300_set_next_event,
313 .set_mode = u300_set_mode, 314 .set_mode = u300_set_mode,
314}; 315};
@@ -341,8 +342,6 @@ static struct clocksource clocksource_u300_1mhz = {
341 .rating = 300, /* Reasonably fast and accurate clock source */ 342 .rating = 300, /* Reasonably fast and accurate clock source */
342 .read = u300_get_cycles, 343 .read = u300_get_cycles,
343 .mask = CLOCKSOURCE_MASK(32), /* 32 bits */ 344 .mask = CLOCKSOURCE_MASK(32), /* 32 bits */
344 /* 22 calculated using the algorithm in arch/mips/kernel/time.c */
345 .shift = 22,
346 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 345 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
347}; 346};
348 347
@@ -367,7 +366,15 @@ unsigned long long notrace sched_clock(void)
367 */ 366 */
368static void __init u300_timer_init(void) 367static void __init u300_timer_init(void)
369{ 368{
370 u300_enable_timer_clock(); 369 struct clk *clk;
370 unsigned long rate;
371
372 /* Clock the interrupt controller */
373 clk = clk_get_sys("apptimer", NULL);
374 BUG_ON(IS_ERR(clk));
375 clk_enable(clk);
376 rate = clk_get_rate(clk);
377
371 /* 378 /*
372 * Disable the "OS" and "DD" timers - these are designed for Symbian! 379 * Disable the "OS" and "DD" timers - these are designed for Symbian!
373 * Example usage in cnh1601578 cpu subsystem pd_timer_app.c 380 * Example usage in cnh1601578 cpu subsystem pd_timer_app.c
@@ -405,15 +412,14 @@ static void __init u300_timer_init(void)
405 writel(U300_TIMER_APP_EGPT2_TIMER_ENABLE, 412 writel(U300_TIMER_APP_EGPT2_TIMER_ENABLE,
406 U300_TIMER_APP_VBASE + U300_TIMER_APP_EGPT2); 413 U300_TIMER_APP_VBASE + U300_TIMER_APP_EGPT2);
407 414
408 /* This is a pure microsecond clock source */ 415 clocksource_calc_mult_shift(&clocksource_u300_1mhz,
409 clocksource_u300_1mhz.mult = 416 rate, APPTIMER_MIN_RANGE);
410 clocksource_khz2mult(1000, clocksource_u300_1mhz.shift);
411 if (clocksource_register(&clocksource_u300_1mhz)) 417 if (clocksource_register(&clocksource_u300_1mhz))
412 printk(KERN_ERR "timer: failed to initialize clock " 418 printk(KERN_ERR "timer: failed to initialize clock "
413 "source %s\n", clocksource_u300_1mhz.name); 419 "source %s\n", clocksource_u300_1mhz.name);
414 420
415 clockevent_u300_1mhz.mult = 421 clockevents_calc_mult_shift(&clockevent_u300_1mhz,
416 div_sc(1000000, NSEC_PER_SEC, clockevent_u300_1mhz.shift); 422 rate, APPTIMER_MIN_RANGE);
417 /* 32bit counter, so 32bits delta is max */ 423 /* 32bit counter, so 32bits delta is max */
418 clockevent_u300_1mhz.max_delta_ns = 424 clockevent_u300_1mhz.max_delta_ns =
419 clockevent_delta2ns(0xffffffff, &clockevent_u300_1mhz); 425 clockevent_delta2ns(0xffffffff, &clockevent_u300_1mhz);
diff --git a/arch/arm/mach-versatile/include/mach/hardware.h b/arch/arm/mach-versatile/include/mach/hardware.h
index 4f8f99aac938..b5e75bb44965 100644
--- a/arch/arm/mach-versatile/include/mach/hardware.h
+++ b/arch/arm/mach-versatile/include/mach/hardware.h
@@ -30,15 +30,6 @@
30#define VERSATILE_PCI_VIRT_BASE (void __iomem *)0xe8000000ul 30#define VERSATILE_PCI_VIRT_BASE (void __iomem *)0xe8000000ul
31#define VERSATILE_PCI_CFG_VIRT_BASE (void __iomem *)0xe9000000ul 31#define VERSATILE_PCI_CFG_VIRT_BASE (void __iomem *)0xe9000000ul
32 32
33#if 0
34#define VERSATILE_PCI_VIRT_MEM_BASE0 0xf4000000
35#define VERSATILE_PCI_VIRT_MEM_BASE1 0xf5000000
36#define VERSATILE_PCI_VIRT_MEM_BASE2 0xf6000000
37
38#define PCIO_BASE VERSATILE_PCI_VIRT_MEM_BASE0
39#define PCIMEM_BASE VERSATILE_PCI_VIRT_MEM_BASE1
40#endif
41
42/* CIK guesswork */ 33/* CIK guesswork */
43#define PCIBIOS_MIN_IO 0x44000000 34#define PCIBIOS_MIN_IO 0x44000000
44#define PCIBIOS_MIN_MEM 0x50000000 35#define PCIBIOS_MIN_MEM 0x50000000
diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
index e1fd98fff8fa..33c3f570aaa0 100644
--- a/arch/arm/mm/Kconfig
+++ b/arch/arm/mm/Kconfig
@@ -771,8 +771,8 @@ config CACHE_L2X0
771 bool "Enable the L2x0 outer cache controller" 771 bool "Enable the L2x0 outer cache controller"
772 depends on REALVIEW_EB_ARM11MP || MACH_REALVIEW_PB11MP || MACH_REALVIEW_PB1176 || \ 772 depends on REALVIEW_EB_ARM11MP || MACH_REALVIEW_PB11MP || MACH_REALVIEW_PB1176 || \
773 REALVIEW_EB_A9MP || ARCH_MX35 || ARCH_MX31 || MACH_REALVIEW_PBX || \ 773 REALVIEW_EB_A9MP || ARCH_MX35 || ARCH_MX31 || MACH_REALVIEW_PBX || \
774 ARCH_NOMADIK || ARCH_OMAP4 || ARCH_U8500 || ARCH_VEXPRESS_CA9X4 || \ 774 ARCH_NOMADIK || ARCH_OMAP4 || ARCH_S5PV310 || ARCH_TEGRA || \
775 ARCH_TEGRA 775 ARCH_U8500 || ARCH_VEXPRESS_CA9X4
776 default y 776 default y
777 select OUTER_CACHE 777 select OUTER_CACHE
778 select OUTER_CACHE_SYNC 778 select OUTER_CACHE_SYNC
diff --git a/arch/arm/plat-mxc/include/mach/gpio.h b/arch/arm/plat-mxc/include/mach/gpio.h
index 661fbc605759..af33b74f569e 100644
--- a/arch/arm/plat-mxc/include/mach/gpio.h
+++ b/arch/arm/plat-mxc/include/mach/gpio.h
@@ -19,6 +19,7 @@
19#ifndef __ASM_ARCH_MXC_GPIO_H__ 19#ifndef __ASM_ARCH_MXC_GPIO_H__
20#define __ASM_ARCH_MXC_GPIO_H__ 20#define __ASM_ARCH_MXC_GPIO_H__
21 21
22#include <linux/spinlock.h>
22#include <mach/hardware.h> 23#include <mach/hardware.h>
23#include <asm-generic/gpio.h> 24#include <asm-generic/gpio.h>
24 25
diff --git a/arch/arm/plat-omap/include/plat/mmc.h b/arch/arm/plat-omap/include/plat/mmc.h
index c835f1e994c6..9b89ec601ee2 100644
--- a/arch/arm/plat-omap/include/plat/mmc.h
+++ b/arch/arm/plat-omap/include/plat/mmc.h
@@ -122,6 +122,8 @@ struct omap_mmc_platform_data {
122 /* Call back after enabling / disabling regulators */ 122 /* Call back after enabling / disabling regulators */
123 void (*after_set_reg)(struct device *dev, int slot, 123 void (*after_set_reg)(struct device *dev, int slot,
124 int power_on, int vdd); 124 int power_on, int vdd);
125 /* if we have special card, init it using this callback */
126 void (*init_card)(struct mmc_card *card);
125 127
126 /* return MMC cover switch state, can be NULL if not supported. 128 /* return MMC cover switch state, can be NULL if not supported.
127 * 129 *
diff --git a/arch/arm/plat-pxa/Makefile b/arch/arm/plat-pxa/Makefile
index a17cc0c6a6b0..4aacdd12c9cc 100644
--- a/arch/arm/plat-pxa/Makefile
+++ b/arch/arm/plat-pxa/Makefile
@@ -4,7 +4,6 @@
4 4
5obj-y := dma.o 5obj-y := dma.o
6 6
7obj-$(CONFIG_ARCH_PXA) += pmu.o
8obj-$(CONFIG_GENERIC_GPIO) += gpio.o 7obj-$(CONFIG_GENERIC_GPIO) += gpio.o
9obj-$(CONFIG_PXA3xx) += mfp.o 8obj-$(CONFIG_PXA3xx) += mfp.o
10obj-$(CONFIG_ARCH_MMP) += mfp.o 9obj-$(CONFIG_ARCH_MMP) += mfp.o
diff --git a/arch/arm/plat-pxa/pmu.c b/arch/arm/plat-pxa/pmu.c
deleted file mode 100644
index 267ceb6feb2f..000000000000
--- a/arch/arm/plat-pxa/pmu.c
+++ /dev/null
@@ -1,33 +0,0 @@
1/*
2 * PMU IRQ registration for the PXA xscale PMU families.
3 * Copyright (C) 2010 Will Deacon, ARM Ltd.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 */
10
11#include <linux/platform_device.h>
12#include <asm/pmu.h>
13#include <mach/irqs.h>
14
15static struct resource pmu_resource = {
16 .start = IRQ_PMU,
17 .end = IRQ_PMU,
18 .flags = IORESOURCE_IRQ,
19};
20
21static struct platform_device pmu_device = {
22 .name = "arm-pmu",
23 .id = ARM_PMU_DEVICE_CPU,
24 .resource = &pmu_resource,
25 .num_resources = 1,
26};
27
28static int __init pxa_pmu_init(void)
29{
30 platform_device_register(&pmu_device);
31 return 0;
32}
33arch_initcall(pxa_pmu_init);
diff --git a/arch/arm/plat-s5p/Kconfig b/arch/arm/plat-s5p/Kconfig
index 11d6a1bbd90d..c6a855db2fb6 100644
--- a/arch/arm/plat-s5p/Kconfig
+++ b/arch/arm/plat-s5p/Kconfig
@@ -7,9 +7,10 @@
7 7
8config PLAT_S5P 8config PLAT_S5P
9 bool 9 bool
10 depends on (ARCH_S5P6440 || ARCH_S5P6442 || ARCH_S5PC100 || ARCH_S5PV210) 10 depends on (ARCH_S5P6440 || ARCH_S5P6442 || ARCH_S5PC100 || ARCH_S5PV210 || ARCH_S5PV310)
11 default y 11 default y
12 select ARM_VIC 12 select ARM_VIC if !ARCH_S5PV310
13 select ARM_GIC if ARCH_S5PV310
13 select NO_IOPORT 14 select NO_IOPORT
14 select ARCH_REQUIRE_GPIOLIB 15 select ARCH_REQUIRE_GPIOLIB
15 select S3C_GPIO_TRACK 16 select S3C_GPIO_TRACK
@@ -30,3 +31,18 @@ config S5P_EXT_INT
30 help 31 help
31 Use the external interrupts (other than GPIO interrupts.) 32 Use the external interrupts (other than GPIO interrupts.)
32 Note: Do not choose this for S5P6440. 33 Note: Do not choose this for S5P6440.
34
35config S5P_DEV_FIMC0
36 bool
37 help
38 Compile in platform device definitions for FIMC controller 0
39
40config S5P_DEV_FIMC1
41 bool
42 help
43 Compile in platform device definitions for FIMC controller 1
44
45config S5P_DEV_FIMC2
46 bool
47 help
48 Compile in platform device definitions for FIMC controller 2
diff --git a/arch/arm/plat-s5p/Makefile b/arch/arm/plat-s5p/Makefile
index 39c242bb9d58..b2e029673950 100644
--- a/arch/arm/plat-s5p/Makefile
+++ b/arch/arm/plat-s5p/Makefile
@@ -12,9 +12,15 @@ obj- :=
12 12
13# Core files 13# Core files
14 14
15obj-y += dev-pmu.o
15obj-y += dev-uart.o 16obj-y += dev-uart.o
16obj-y += cpu.o 17obj-y += cpu.o
17obj-y += clock.o 18obj-y += clock.o
18obj-y += irq.o 19obj-y += irq.o
19obj-$(CONFIG_S5P_EXT_INT) += irq-eint.o 20obj-$(CONFIG_S5P_EXT_INT) += irq-eint.o
20 21
22# devices
23
24obj-$(CONFIG_S5P_DEV_FIMC0) += dev-fimc0.o
25obj-$(CONFIG_S5P_DEV_FIMC1) += dev-fimc1.o
26obj-$(CONFIG_S5P_DEV_FIMC2) += dev-fimc2.o
diff --git a/arch/arm/plat-s5p/cpu.c b/arch/arm/plat-s5p/cpu.c
index 75cb8c37ca2c..b07a078fd284 100644
--- a/arch/arm/plat-s5p/cpu.c
+++ b/arch/arm/plat-s5p/cpu.c
@@ -21,6 +21,7 @@
21#include <plat/s5p6442.h> 21#include <plat/s5p6442.h>
22#include <plat/s5pc100.h> 22#include <plat/s5pc100.h>
23#include <plat/s5pv210.h> 23#include <plat/s5pv210.h>
24#include <plat/s5pv310.h>
24 25
25/* table of supported CPUs */ 26/* table of supported CPUs */
26 27
@@ -28,6 +29,7 @@ static const char name_s5p6440[] = "S5P6440";
28static const char name_s5p6442[] = "S5P6442"; 29static const char name_s5p6442[] = "S5P6442";
29static const char name_s5pc100[] = "S5PC100"; 30static const char name_s5pc100[] = "S5PC100";
30static const char name_s5pv210[] = "S5PV210/S5PC110"; 31static const char name_s5pv210[] = "S5PV210/S5PC110";
32static const char name_s5pv310[] = "S5PV310";
31 33
32static struct cpu_table cpu_ids[] __initdata = { 34static struct cpu_table cpu_ids[] __initdata = {
33 { 35 {
@@ -62,6 +64,14 @@ static struct cpu_table cpu_ids[] __initdata = {
62 .init_uarts = s5pv210_init_uarts, 64 .init_uarts = s5pv210_init_uarts,
63 .init = s5pv210_init, 65 .init = s5pv210_init,
64 .name = name_s5pv210, 66 .name = name_s5pv210,
67 }, {
68 .idcode = 0x43200000,
69 .idmask = 0xfffff000,
70 .map_io = s5pv310_map_io,
71 .init_clocks = s5pv310_init_clocks,
72 .init_uarts = s5pv310_init_uarts,
73 .init = s5pv310_init,
74 .name = name_s5pv310,
65 }, 75 },
66}; 76};
67 77
@@ -81,8 +91,9 @@ static struct map_desc s5p_iodesc[] __initdata = {
81 }, { 91 }, {
82 .virtual = (unsigned long)S3C_VA_UART, 92 .virtual = (unsigned long)S3C_VA_UART,
83 .pfn = __phys_to_pfn(S3C_PA_UART), 93 .pfn = __phys_to_pfn(S3C_PA_UART),
84 .length = SZ_4K, 94 .length = SZ_512K,
85 .type = MT_DEVICE, 95 .type = MT_DEVICE,
96#ifdef CONFIG_ARM_VIC
86 }, { 97 }, {
87 .virtual = (unsigned long)VA_VIC0, 98 .virtual = (unsigned long)VA_VIC0,
88 .pfn = __phys_to_pfn(S5P_PA_VIC0), 99 .pfn = __phys_to_pfn(S5P_PA_VIC0),
@@ -93,6 +104,7 @@ static struct map_desc s5p_iodesc[] __initdata = {
93 .pfn = __phys_to_pfn(S5P_PA_VIC1), 104 .pfn = __phys_to_pfn(S5P_PA_VIC1),
94 .length = SZ_16K, 105 .length = SZ_16K,
95 .type = MT_DEVICE, 106 .type = MT_DEVICE,
107#endif
96 }, { 108 }, {
97 .virtual = (unsigned long)S3C_VA_TIMER, 109 .virtual = (unsigned long)S3C_VA_TIMER,
98 .pfn = __phys_to_pfn(S5P_PA_TIMER), 110 .pfn = __phys_to_pfn(S5P_PA_TIMER),
@@ -103,6 +115,11 @@ static struct map_desc s5p_iodesc[] __initdata = {
103 .pfn = __phys_to_pfn(S5P_PA_GPIO), 115 .pfn = __phys_to_pfn(S5P_PA_GPIO),
104 .length = SZ_4K, 116 .length = SZ_4K,
105 .type = MT_DEVICE, 117 .type = MT_DEVICE,
118 }, {
119 .virtual = (unsigned long)S3C_VA_WATCHDOG,
120 .pfn = __phys_to_pfn(S3C_PA_WDT),
121 .length = SZ_4K,
122 .type = MT_DEVICE,
106 }, 123 },
107}; 124};
108 125
diff --git a/arch/arm/plat-s5p/dev-fimc0.c b/arch/arm/plat-s5p/dev-fimc0.c
new file mode 100644
index 000000000000..d3f1a9b5d2b5
--- /dev/null
+++ b/arch/arm/plat-s5p/dev-fimc0.c
@@ -0,0 +1,36 @@
1/* linux/arch/arm/plat-s5p/dev-fimc0.c
2 *
3 * Copyright (c) 2010 Samsung Electronics
4 *
5 * Base S5P FIMC0 resource and device definitions
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/platform_device.h>
14#include <linux/interrupt.h>
15#include <linux/ioport.h>
16#include <mach/map.h>
17
18static struct resource s5p_fimc0_resource[] = {
19 [0] = {
20 .start = S5P_PA_FIMC0,
21 .end = S5P_PA_FIMC0 + SZ_1M - 1,
22 .flags = IORESOURCE_MEM,
23 },
24 [1] = {
25 .start = IRQ_FIMC0,
26 .end = IRQ_FIMC0,
27 .flags = IORESOURCE_IRQ,
28 },
29};
30
31struct platform_device s5p_device_fimc0 = {
32 .name = "s5p-fimc",
33 .id = 0,
34 .num_resources = ARRAY_SIZE(s5p_fimc0_resource),
35 .resource = s5p_fimc0_resource,
36};
diff --git a/arch/arm/plat-s5p/dev-fimc1.c b/arch/arm/plat-s5p/dev-fimc1.c
new file mode 100644
index 000000000000..41bd6986d0ad
--- /dev/null
+++ b/arch/arm/plat-s5p/dev-fimc1.c
@@ -0,0 +1,36 @@
1/* linux/arch/arm/plat-s5p/dev-fimc1.c
2 *
3 * Copyright (c) 2010 Samsung Electronics
4 *
5 * Base S5P FIMC1 resource and device definitions
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/platform_device.h>
14#include <linux/interrupt.h>
15#include <linux/ioport.h>
16#include <mach/map.h>
17
18static struct resource s5p_fimc1_resource[] = {
19 [0] = {
20 .start = S5P_PA_FIMC1,
21 .end = S5P_PA_FIMC1 + SZ_1M - 1,
22 .flags = IORESOURCE_MEM,
23 },
24 [1] = {
25 .start = IRQ_FIMC1,
26 .end = IRQ_FIMC1,
27 .flags = IORESOURCE_IRQ,
28 },
29};
30
31struct platform_device s5p_device_fimc1 = {
32 .name = "s5p-fimc",
33 .id = 1,
34 .num_resources = ARRAY_SIZE(s5p_fimc1_resource),
35 .resource = s5p_fimc1_resource,
36};
diff --git a/arch/arm/plat-s5p/dev-fimc2.c b/arch/arm/plat-s5p/dev-fimc2.c
new file mode 100644
index 000000000000..dfddeda6d4a3
--- /dev/null
+++ b/arch/arm/plat-s5p/dev-fimc2.c
@@ -0,0 +1,36 @@
1/* linux/arch/arm/plat-s5p/dev-fimc2.c
2 *
3 * Copyright (c) 2010 Samsung Electronics
4 *
5 * Base S5P FIMC2 resource and device definitions
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/platform_device.h>
14#include <linux/interrupt.h>
15#include <linux/ioport.h>
16#include <mach/map.h>
17
18static struct resource s5p_fimc2_resource[] = {
19 [0] = {
20 .start = S5P_PA_FIMC2,
21 .end = S5P_PA_FIMC2 + SZ_1M - 1,
22 .flags = IORESOURCE_MEM,
23 },
24 [1] = {
25 .start = IRQ_FIMC2,
26 .end = IRQ_FIMC2,
27 .flags = IORESOURCE_IRQ,
28 },
29};
30
31struct platform_device s5p_device_fimc2 = {
32 .name = "s5p-fimc",
33 .id = 2,
34 .num_resources = ARRAY_SIZE(s5p_fimc2_resource),
35 .resource = s5p_fimc2_resource,
36};
diff --git a/arch/arm/plat-s5p/dev-pmu.c b/arch/arm/plat-s5p/dev-pmu.c
new file mode 100644
index 000000000000..a08576da72b0
--- /dev/null
+++ b/arch/arm/plat-s5p/dev-pmu.c
@@ -0,0 +1,36 @@
1/*
2 * linux/arch/arm/plat-s5p/dev-pmu.c
3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@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/platform_device.h>
15#include <asm/pmu.h>
16#include <mach/irqs.h>
17
18static struct resource s5p_pmu_resource = {
19 .start = IRQ_PMU,
20 .end = IRQ_PMU,
21 .flags = IORESOURCE_IRQ,
22};
23
24struct platform_device s5p_device_pmu = {
25 .name = "arm-pmu",
26 .id = ARM_PMU_DEVICE_CPU,
27 .num_resources = 1,
28 .resource = &s5p_pmu_resource,
29};
30
31static int __init s5p_pmu_init(void)
32{
33 platform_device_register(&s5p_device_pmu);
34 return 0;
35}
36arch_initcall(s5p_pmu_init);
diff --git a/arch/arm/plat-s5p/include/plat/map-s5p.h b/arch/arm/plat-s5p/include/plat/map-s5p.h
index 14828521f70c..54e9fb9d315e 100644
--- a/arch/arm/plat-s5p/include/plat/map-s5p.h
+++ b/arch/arm/plat-s5p/include/plat/map-s5p.h
@@ -18,12 +18,27 @@
18#define S5P_VA_SYSTIMER S3C_ADDR(0x01200000) 18#define S5P_VA_SYSTIMER S3C_ADDR(0x01200000)
19#define S5P_VA_SROMC S3C_ADDR(0x01100000) 19#define S5P_VA_SROMC S3C_ADDR(0x01100000)
20 20
21#define S5P_VA_UART0 (S3C_VA_UART + 0x0) 21#define S5P_VA_COMBINER_BASE S3C_ADDR(0x00600000)
22#define S5P_VA_UART1 (S3C_VA_UART + 0x400) 22#define S5P_VA_COMBINER(x) (S5P_VA_COMBINER_BASE + ((x) >> 2) * 0x10)
23#define S5P_VA_UART2 (S3C_VA_UART + 0x800)
24#define S5P_VA_UART3 (S3C_VA_UART + 0xC00)
25 23
24#define S5P_VA_COREPERI_BASE S3C_ADDR(0x00800000)
25#define S5P_VA_COREPERI(x) (S5P_VA_COREPERI_BASE + (x))
26#define S5P_VA_SCU S5P_VA_COREPERI(0x0)
27#define S5P_VA_GIC_CPU S5P_VA_COREPERI(0x100)
28#define S5P_VA_TWD S5P_VA_COREPERI(0x600)
29#define S5P_VA_GIC_DIST S5P_VA_COREPERI(0x1000)
30
31#define S5P_VA_L2CC S3C_ADDR(0x00900000)
32
33#define S5P_VA_UART(x) (S3C_VA_UART + ((x) * S3C_UART_OFFSET))
34#define S5P_VA_UART0 S5P_VA_UART(0)
35#define S5P_VA_UART1 S5P_VA_UART(1)
36#define S5P_VA_UART2 S5P_VA_UART(2)
37#define S5P_VA_UART3 S5P_VA_UART(3)
38
39#ifndef S3C_UART_OFFSET
26#define S3C_UART_OFFSET (0x400) 40#define S3C_UART_OFFSET (0x400)
41#endif
27 42
28#define VA_VIC(x) (S3C_VA_IRQ + ((x) * 0x10000)) 43#define VA_VIC(x) (S3C_VA_IRQ + ((x) * 0x10000))
29#define VA_VIC0 VA_VIC(0) 44#define VA_VIC0 VA_VIC(0)
diff --git a/arch/arm/plat-s5p/include/plat/pll.h b/arch/arm/plat-s5p/include/plat/pll.h
index 7db322726bc2..4e8fe08cb70d 100644
--- a/arch/arm/plat-s5p/include/plat/pll.h
+++ b/arch/arm/plat-s5p/include/plat/pll.h
@@ -46,6 +46,47 @@ static inline unsigned long s5p_get_pll45xx(unsigned long baseclk, u32 pll_con,
46 return (unsigned long)fvco; 46 return (unsigned long)fvco;
47} 47}
48 48
49#define PLL46XX_KDIV_MASK (0xFFFF)
50#define PLL46XX_MDIV_MASK (0x1FF)
51#define PLL46XX_PDIV_MASK (0x3F)
52#define PLL46XX_SDIV_MASK (0x7)
53#define PLL46XX_MDIV_SHIFT (16)
54#define PLL46XX_PDIV_SHIFT (8)
55#define PLL46XX_SDIV_SHIFT (0)
56
57enum pll46xx_type_t {
58 pll_4600,
59 pll_4650,
60};
61
62static inline unsigned long s5p_get_pll46xx(unsigned long baseclk,
63 u32 pll_con0, u32 pll_con1,
64 enum pll46xx_type_t pll_type)
65{
66 unsigned long result;
67 u32 mdiv, pdiv, sdiv, kdiv;
68 u64 tmp;
69
70 mdiv = (pll_con0 >> PLL46XX_MDIV_SHIFT) & PLL46XX_MDIV_MASK;
71 pdiv = (pll_con0 >> PLL46XX_PDIV_SHIFT) & PLL46XX_PDIV_MASK;
72 sdiv = (pll_con0 >> PLL46XX_SDIV_SHIFT) & PLL46XX_SDIV_MASK;
73 kdiv = pll_con1 & PLL46XX_KDIV_MASK;
74
75 tmp = baseclk;
76
77 if (pll_type == pll_4600) {
78 tmp *= (mdiv << 16) + kdiv;
79 do_div(tmp, (pdiv << sdiv));
80 result = tmp >> 16;
81 } else {
82 tmp *= (mdiv << 10) + kdiv;
83 do_div(tmp, (pdiv << sdiv));
84 result = tmp >> 10;
85 }
86
87 return result;
88}
89
49#define PLL90XX_MDIV_MASK (0xFF) 90#define PLL90XX_MDIV_MASK (0xFF)
50#define PLL90XX_PDIV_MASK (0x3F) 91#define PLL90XX_PDIV_MASK (0x3F)
51#define PLL90XX_SDIV_MASK (0x7) 92#define PLL90XX_SDIV_MASK (0x7)
diff --git a/arch/arm/plat-s5p/include/plat/reset.h b/arch/arm/plat-s5p/include/plat/reset.h
new file mode 100644
index 000000000000..335e97812eed
--- /dev/null
+++ b/arch/arm/plat-s5p/include/plat/reset.h
@@ -0,0 +1,16 @@
1/* linux/arch/arm/plat-s5p/include/plat/reset.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9*/
10
11#ifndef __ASM_PLAT_S5P_RESET_H
12#define __ASM_PLAT_S5P_RESET_H __FILE__
13
14extern void (*s5p_reset_hook)(void);
15
16#endif /* __ASM_PLAT_S5P_RESET_H */
diff --git a/arch/arm/plat-s5p/include/plat/s5pv310.h b/arch/arm/plat-s5p/include/plat/s5pv310.h
new file mode 100644
index 000000000000..769c991ceb37
--- /dev/null
+++ b/arch/arm/plat-s5p/include/plat/s5pv310.h
@@ -0,0 +1,34 @@
1/* linux/arch/arm/plat-s5p/include/plat/s5pv310.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * Header file for s5pv310 cpu support
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/* Common init code for S5PV310 related SoCs */
14
15extern void s5pv310_common_init_uarts(struct s3c2410_uartcfg *cfg, int no);
16extern void s5pv310_register_clocks(void);
17extern void s5pv310_setup_clocks(void);
18
19#ifdef CONFIG_CPU_S5PV310
20
21extern int s5pv310_init(void);
22extern void s5pv310_init_irq(void);
23extern void s5pv310_map_io(void);
24extern void s5pv310_init_clocks(int xtal);
25extern struct sys_timer s5pv310_timer;
26
27#define s5pv310_init_uarts s5pv310_common_init_uarts
28
29#else
30#define s5pv310_init_clocks NULL
31#define s5pv310_init_uarts NULL
32#define s5pv310_map_io NULL
33#define s5pv310_init NULL
34#endif
diff --git a/arch/arm/plat-s5p/include/plat/system-reset.h b/arch/arm/plat-s5p/include/plat/system-reset.h
new file mode 100644
index 000000000000..f307f34e6422
--- /dev/null
+++ b/arch/arm/plat-s5p/include/plat/system-reset.h
@@ -0,0 +1,31 @@
1/* linux/arch/arm/plat-s5p/include/plat/system-reset.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Based on arch/arm/mach-s3c2410/include/mach/system-reset.h
7 *
8 * S5P - System define for arch_reset()
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13*/
14
15#include <plat/watchdog-reset.h>
16
17void (*s5p_reset_hook)(void);
18
19static void arch_reset(char mode, const char *cmd)
20{
21 /* SWRESET support in s5p_reset_hook() */
22
23 if (s5p_reset_hook)
24 s5p_reset_hook();
25
26 /* Perform reset using Watchdog reset
27 * if there is no s5p_reset_hook()
28 */
29
30 arch_wdt_reset();
31}
diff --git a/arch/arm/plat-s5p/irq.c b/arch/arm/plat-s5p/irq.c
index 25e1eb6de59e..5560b12035d1 100644
--- a/arch/arm/plat-s5p/irq.c
+++ b/arch/arm/plat-s5p/irq.c
@@ -56,11 +56,13 @@ static struct s3c_uart_irq uart_irqs[] = {
56 56
57void __init s5p_init_irq(u32 *vic, u32 num_vic) 57void __init s5p_init_irq(u32 *vic, u32 num_vic)
58{ 58{
59#ifdef CONFIG_ARM_VIC
59 int irq; 60 int irq;
60 61
61 /* initialize the VICs */ 62 /* initialize the VICs */
62 for (irq = 0; irq < num_vic; irq++) 63 for (irq = 0; irq < num_vic; irq++)
63 vic_init(VA_VIC(irq), VIC_BASE(irq), vic[irq], 0); 64 vic_init(VA_VIC(irq), VIC_BASE(irq), vic[irq], 0);
65#endif
64 66
65 s3c_init_vic_timer_irq(IRQ_TIMER0_VIC, IRQ_TIMER0); 67 s3c_init_vic_timer_irq(IRQ_TIMER0_VIC, IRQ_TIMER0);
66 s3c_init_vic_timer_irq(IRQ_TIMER1_VIC, IRQ_TIMER1); 68 s3c_init_vic_timer_irq(IRQ_TIMER1_VIC, IRQ_TIMER1);
diff --git a/arch/arm/plat-samsung/Kconfig b/arch/arm/plat-samsung/Kconfig
index 2753fb3e4f73..4529dd6232bc 100644
--- a/arch/arm/plat-samsung/Kconfig
+++ b/arch/arm/plat-samsung/Kconfig
@@ -160,6 +160,11 @@ config S3C_DEV_HSMMC2
160 help 160 help
161 Compile in platform device definitions for HSMMC channel 2 161 Compile in platform device definitions for HSMMC channel 2
162 162
163config S3C_DEV_HSMMC3
164 bool
165 help
166 Compile in platform device definitions for HSMMC channel 3
167
163config S3C_DEV_HWMON 168config S3C_DEV_HWMON
164 bool 169 bool
165 help 170 help
@@ -216,6 +221,11 @@ config SAMSUNG_DEV_ADC
216 help 221 help
217 Compile in platform device definition for ADC controller 222 Compile in platform device definition for ADC controller
218 223
224config SAMSUNG_DEV_IDE
225 bool
226 help
227 Compile in platform device definitions for IDE
228
219config S3C64XX_DEV_SPI 229config S3C64XX_DEV_SPI
220 bool 230 bool
221 help 231 help
@@ -227,6 +237,11 @@ config SAMSUNG_DEV_TS
227 help 237 help
228 Common in platform device definitions for touchscreen device 238 Common in platform device definitions for touchscreen device
229 239
240config SAMSUNG_DEV_KEYPAD
241 bool
242 help
243 Compile in platform device definitions for keypad
244
230# DMA 245# DMA
231 246
232config S3C_DMA 247config S3C_DMA
diff --git a/arch/arm/plat-samsung/Makefile b/arch/arm/plat-samsung/Makefile
index b1d82cc5e716..4d8ff923207a 100644
--- a/arch/arm/plat-samsung/Makefile
+++ b/arch/arm/plat-samsung/Makefile
@@ -12,7 +12,7 @@ obj- :=
12# Objects we always build independent of SoC choice 12# Objects we always build independent of SoC choice
13 13
14obj-y += init.o 14obj-y += init.o
15obj-y += time.o 15obj-$(CONFIG_ARCH_USES_GETTIMEOFFSET) += time.o
16obj-y += clock.o 16obj-y += clock.o
17obj-y += pwm-clock.o 17obj-y += pwm-clock.o
18obj-y += gpio.o 18obj-y += gpio.o
@@ -30,9 +30,12 @@ obj-$(CONFIG_S3C_ADC) += adc.o
30 30
31# devices 31# devices
32 32
33obj-y += platformdata.o
34
33obj-$(CONFIG_S3C_DEV_HSMMC) += dev-hsmmc.o 35obj-$(CONFIG_S3C_DEV_HSMMC) += dev-hsmmc.o
34obj-$(CONFIG_S3C_DEV_HSMMC1) += dev-hsmmc1.o 36obj-$(CONFIG_S3C_DEV_HSMMC1) += dev-hsmmc1.o
35obj-$(CONFIG_S3C_DEV_HSMMC2) += dev-hsmmc2.o 37obj-$(CONFIG_S3C_DEV_HSMMC2) += dev-hsmmc2.o
38obj-$(CONFIG_S3C_DEV_HSMMC3) += dev-hsmmc3.o
36obj-$(CONFIG_S3C_DEV_HWMON) += dev-hwmon.o 39obj-$(CONFIG_S3C_DEV_HWMON) += dev-hwmon.o
37obj-y += dev-i2c0.o 40obj-y += dev-i2c0.o
38obj-$(CONFIG_S3C_DEV_I2C1) += dev-i2c1.o 41obj-$(CONFIG_S3C_DEV_I2C1) += dev-i2c1.o
@@ -47,7 +50,9 @@ obj-$(CONFIG_S3C_DEV_ONENAND) += dev-onenand.o
47obj-$(CONFIG_S3C_DEV_RTC) += dev-rtc.o 50obj-$(CONFIG_S3C_DEV_RTC) += dev-rtc.o
48 51
49obj-$(CONFIG_SAMSUNG_DEV_ADC) += dev-adc.o 52obj-$(CONFIG_SAMSUNG_DEV_ADC) += dev-adc.o
53obj-$(CONFIG_SAMSUNG_DEV_IDE) += dev-ide.o
50obj-$(CONFIG_SAMSUNG_DEV_TS) += dev-ts.o 54obj-$(CONFIG_SAMSUNG_DEV_TS) += dev-ts.o
55obj-$(CONFIG_SAMSUNG_DEV_KEYPAD) += dev-keypad.o
51 56
52# DMA support 57# DMA support
53 58
diff --git a/arch/arm/plat-samsung/dev-hsmmc.c b/arch/arm/plat-samsung/dev-hsmmc.c
index 4c05b39810e2..b0f93f11e281 100644
--- a/arch/arm/plat-samsung/dev-hsmmc.c
+++ b/arch/arm/plat-samsung/dev-hsmmc.c
@@ -60,6 +60,11 @@ void s3c_sdhci0_set_platdata(struct s3c_sdhci_platdata *pd)
60 struct s3c_sdhci_platdata *set = &s3c_hsmmc0_def_platdata; 60 struct s3c_sdhci_platdata *set = &s3c_hsmmc0_def_platdata;
61 61
62 set->max_width = pd->max_width; 62 set->max_width = pd->max_width;
63 set->cd_type = pd->cd_type;
64 set->ext_cd_init = pd->ext_cd_init;
65 set->ext_cd_cleanup = pd->ext_cd_cleanup;
66 set->ext_cd_gpio = pd->ext_cd_gpio;
67 set->ext_cd_gpio_invert = pd->ext_cd_gpio_invert;
63 68
64 if (pd->cfg_gpio) 69 if (pd->cfg_gpio)
65 set->cfg_gpio = pd->cfg_gpio; 70 set->cfg_gpio = pd->cfg_gpio;
diff --git a/arch/arm/plat-samsung/dev-hsmmc1.c b/arch/arm/plat-samsung/dev-hsmmc1.c
index e49bc4cd0ee6..1504fd802865 100644
--- a/arch/arm/plat-samsung/dev-hsmmc1.c
+++ b/arch/arm/plat-samsung/dev-hsmmc1.c
@@ -60,6 +60,11 @@ void s3c_sdhci1_set_platdata(struct s3c_sdhci_platdata *pd)
60 struct s3c_sdhci_platdata *set = &s3c_hsmmc1_def_platdata; 60 struct s3c_sdhci_platdata *set = &s3c_hsmmc1_def_platdata;
61 61
62 set->max_width = pd->max_width; 62 set->max_width = pd->max_width;
63 set->cd_type = pd->cd_type;
64 set->ext_cd_init = pd->ext_cd_init;
65 set->ext_cd_cleanup = pd->ext_cd_cleanup;
66 set->ext_cd_gpio = pd->ext_cd_gpio;
67 set->ext_cd_gpio_invert = pd->ext_cd_gpio_invert;
63 68
64 if (pd->cfg_gpio) 69 if (pd->cfg_gpio)
65 set->cfg_gpio = pd->cfg_gpio; 70 set->cfg_gpio = pd->cfg_gpio;
diff --git a/arch/arm/plat-samsung/dev-hsmmc2.c b/arch/arm/plat-samsung/dev-hsmmc2.c
index 824580bc0e06..b28ef173444d 100644
--- a/arch/arm/plat-samsung/dev-hsmmc2.c
+++ b/arch/arm/plat-samsung/dev-hsmmc2.c
@@ -61,6 +61,11 @@ void s3c_sdhci2_set_platdata(struct s3c_sdhci_platdata *pd)
61 struct s3c_sdhci_platdata *set = &s3c_hsmmc2_def_platdata; 61 struct s3c_sdhci_platdata *set = &s3c_hsmmc2_def_platdata;
62 62
63 set->max_width = pd->max_width; 63 set->max_width = pd->max_width;
64 set->cd_type = pd->cd_type;
65 set->ext_cd_init = pd->ext_cd_init;
66 set->ext_cd_cleanup = pd->ext_cd_cleanup;
67 set->ext_cd_gpio = pd->ext_cd_gpio;
68 set->ext_cd_gpio_invert = pd->ext_cd_gpio_invert;
64 69
65 if (pd->cfg_gpio) 70 if (pd->cfg_gpio)
66 set->cfg_gpio = pd->cfg_gpio; 71 set->cfg_gpio = pd->cfg_gpio;
diff --git a/arch/arm/plat-samsung/dev-hsmmc3.c b/arch/arm/plat-samsung/dev-hsmmc3.c
new file mode 100644
index 000000000000..85aaf0f2842f
--- /dev/null
+++ b/arch/arm/plat-samsung/dev-hsmmc3.c
@@ -0,0 +1,77 @@
1/* linux/arch/arm/plat-samsung/dev-hsmmc3.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Copyright (c) 2008 Simtec Electronics
7 * Ben Dooks <ben@simtec.co.uk>
8 * http://armlinux.simtec.co.uk/
9 *
10 * Based on arch/arm/plat-samsung/dev-hsmmc1.c
11 *
12 * Samsung device definition for hsmmc device 3
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17*/
18
19#include <linux/kernel.h>
20#include <linux/platform_device.h>
21#include <linux/mmc/host.h>
22
23#include <mach/map.h>
24#include <plat/sdhci.h>
25#include <plat/devs.h>
26
27#define S3C_SZ_HSMMC (0x1000)
28
29static struct resource s3c_hsmmc3_resource[] = {
30 [0] = {
31 .start = S3C_PA_HSMMC3,
32 .end = S3C_PA_HSMMC3 + S3C_SZ_HSMMC - 1,
33 .flags = IORESOURCE_MEM,
34 },
35 [1] = {
36 .start = IRQ_MMC3,
37 .end = IRQ_MMC3,
38 .flags = IORESOURCE_IRQ,
39 }
40};
41
42static u64 s3c_device_hsmmc3_dmamask = 0xffffffffUL;
43
44struct s3c_sdhci_platdata s3c_hsmmc3_def_platdata = {
45 .max_width = 4,
46 .host_caps = (MMC_CAP_4_BIT_DATA |
47 MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
48};
49
50struct platform_device s3c_device_hsmmc3 = {
51 .name = "s3c-sdhci",
52 .id = 3,
53 .num_resources = ARRAY_SIZE(s3c_hsmmc3_resource),
54 .resource = s3c_hsmmc3_resource,
55 .dev = {
56 .dma_mask = &s3c_device_hsmmc3_dmamask,
57 .coherent_dma_mask = 0xffffffffUL,
58 .platform_data = &s3c_hsmmc3_def_platdata,
59 },
60};
61
62void s3c_sdhci3_set_platdata(struct s3c_sdhci_platdata *pd)
63{
64 struct s3c_sdhci_platdata *set = &s3c_hsmmc3_def_platdata;
65
66 set->max_width = pd->max_width;
67 set->cd_type = pd->cd_type;
68 set->ext_cd_init = pd->ext_cd_init;
69 set->ext_cd_cleanup = pd->ext_cd_cleanup;
70 set->ext_cd_gpio = pd->ext_cd_gpio;
71 set->ext_cd_gpio_invert = pd->ext_cd_gpio_invert;
72
73 if (pd->cfg_gpio)
74 set->cfg_gpio = pd->cfg_gpio;
75 if (pd->cfg_card)
76 set->cfg_card = pd->cfg_card;
77}
diff --git a/arch/arm/plat-samsung/dev-ide.c b/arch/arm/plat-samsung/dev-ide.c
new file mode 100644
index 000000000000..b497982795a7
--- /dev/null
+++ b/arch/arm/plat-samsung/dev-ide.c
@@ -0,0 +1,44 @@
1/* linux/arch/arm/plat-samsung/dev-ide.c
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Samsung CF-ATA device definition.
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#include <linux/kernel.h>
14#include <linux/interrupt.h>
15#include <linux/platform_device.h>
16
17#include <mach/map.h>
18#include <plat/ata.h>
19#include <plat/devs.h>
20
21static struct resource s3c_cfcon_resource[] = {
22 [0] = {
23 .start = SAMSUNG_PA_CFCON,
24 .end = SAMSUNG_PA_CFCON + SZ_16K - 1,
25 .flags = IORESOURCE_MEM,
26 },
27 [1] = {
28 .start = IRQ_CFCON,
29 .end = IRQ_CFCON,
30 .flags = IORESOURCE_IRQ,
31 },
32};
33
34struct platform_device s3c_device_cfcon = {
35 .id = 0,
36 .num_resources = ARRAY_SIZE(s3c_cfcon_resource),
37 .resource = s3c_cfcon_resource,
38};
39
40void s3c_ide_set_platdata(struct s3c_ide_platdata *pdata)
41{
42 s3c_set_platdata(pdata, sizeof(struct s3c_ide_platdata),
43 &s3c_device_cfcon);
44}
diff --git a/arch/arm/plat-samsung/dev-keypad.c b/arch/arm/plat-samsung/dev-keypad.c
new file mode 100644
index 000000000000..677c2d731b65
--- /dev/null
+++ b/arch/arm/plat-samsung/dev-keypad.c
@@ -0,0 +1,50 @@
1/*
2 * linux/arch/arm/plat-samsung/dev-keypad.c
3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@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/platform_device.h>
15#include <mach/irqs.h>
16#include <mach/map.h>
17#include <plat/cpu.h>
18#include <plat/devs.h>
19#include <plat/keypad.h>
20
21static struct resource samsung_keypad_resources[] = {
22 [0] = {
23 .start = SAMSUNG_PA_KEYPAD,
24 .end = SAMSUNG_PA_KEYPAD + 0x20 - 1,
25 .flags = IORESOURCE_MEM,
26 },
27 [1] = {
28 .start = IRQ_KEYPAD,
29 .end = IRQ_KEYPAD,
30 .flags = IORESOURCE_IRQ,
31 },
32};
33
34struct platform_device samsung_device_keypad = {
35 .name = "samsung-keypad",
36 .id = -1,
37 .num_resources = ARRAY_SIZE(samsung_keypad_resources),
38 .resource = samsung_keypad_resources,
39};
40
41void __init samsung_keypad_set_platdata(struct samsung_keypad_platdata *pd)
42{
43 struct samsung_keypad_platdata *npd;
44
45 npd = s3c_set_platdata(pd, sizeof(struct samsung_keypad_platdata),
46 &samsung_device_keypad);
47
48 if (!npd->cfg_gpio)
49 npd->cfg_gpio = samsung_keypad_cfg_gpio;
50}
diff --git a/arch/arm/plat-samsung/dev-wdt.c b/arch/arm/plat-samsung/dev-wdt.c
index 5efca87cddbd..019b5b8cf14c 100644
--- a/arch/arm/plat-samsung/dev-wdt.c
+++ b/arch/arm/plat-samsung/dev-wdt.c
@@ -21,7 +21,7 @@
21static struct resource s3c_wdt_resource[] = { 21static struct resource s3c_wdt_resource[] = {
22 [0] = { 22 [0] = {
23 .start = S3C_PA_WDT, 23 .start = S3C_PA_WDT,
24 .end = S3C_PA_WDT + SZ_1M - 1, 24 .end = S3C_PA_WDT + SZ_1K,
25 .flags = IORESOURCE_MEM, 25 .flags = IORESOURCE_MEM,
26 }, 26 },
27 [1] = { 27 [1] = {
diff --git a/arch/arm/plat-samsung/gpiolib.c b/arch/arm/plat-samsung/gpiolib.c
index 8a8ba8bc1d96..c354089254fc 100644
--- a/arch/arm/plat-samsung/gpiolib.c
+++ b/arch/arm/plat-samsung/gpiolib.c
@@ -18,7 +18,7 @@
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/irq.h> 19#include <linux/irq.h>
20#include <linux/io.h> 20#include <linux/io.h>
21#include <mach/gpio.h> 21#include <linux/gpio.h>
22#include <plat/gpio-core.h> 22#include <plat/gpio-core.h>
23#include <plat/gpio-cfg.h> 23#include <plat/gpio-cfg.h>
24#include <plat/gpio-cfg-helpers.h> 24#include <plat/gpio-cfg-helpers.h>
diff --git a/arch/arm/plat-samsung/include/plat/adc-core.h b/arch/arm/plat-samsung/include/plat/adc-core.h
new file mode 100644
index 000000000000..a281568d5856
--- /dev/null
+++ b/arch/arm/plat-samsung/include/plat/adc-core.h
@@ -0,0 +1,28 @@
1/* linux/arch/arm/plat-samsung/include/plat/adc-core.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * Samsung ADC Controller core functions
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#ifndef __ASM_PLAT_ADC_CORE_H
14#define __ASM_PLAT_ADC_CORE_H __FILE__
15
16/* These functions are only for use with the core support code, such as
17 * the cpu specific initialisation code
18 */
19
20/* re-define device name depending on support. */
21static inline void s3c_adc_setname(char *name)
22{
23#ifdef CONFIG_SAMSUNG_DEV_ADC
24 s3c_device_adc.name = name;
25#endif
26}
27
28#endif /* __ASM_PLAT_ADC_CORE_H */
diff --git a/arch/arm/plat-samsung/include/plat/ata-core.h b/arch/arm/plat-samsung/include/plat/ata-core.h
new file mode 100644
index 000000000000..f5a4ec7141b1
--- /dev/null
+++ b/arch/arm/plat-samsung/include/plat/ata-core.h
@@ -0,0 +1,28 @@
1/* linux/arch/arm/plat-samsung/include/plat/ata-core.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Samsung CF-ATA Controller core functions
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#ifndef __ASM_PLAT_ATA_CORE_H
14#define __ASM_PLAT_ATA_CORE_H __FILE__
15
16/* These functions are only for use with the core support code, such as
17 * the cpu specific initialisation code
18*/
19
20/* re-define device name depending on support. */
21static inline void s3c_cfcon_setname(char *name)
22{
23#ifdef CONFIG_SAMSUNG_DEV_IDE
24 s3c_device_cfcon.name = name;
25#endif
26}
27
28#endif /* __ASM_PLAT_ATA_CORE_H */
diff --git a/arch/arm/plat-samsung/include/plat/ata.h b/arch/arm/plat-samsung/include/plat/ata.h
new file mode 100644
index 000000000000..2a3855a8372a
--- /dev/null
+++ b/arch/arm/plat-samsung/include/plat/ata.h
@@ -0,0 +1,36 @@
1/* linux/arch/arm/plat-samsung/include/plat/ata.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Samsung CF-ATA platform_device info
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#ifndef __ASM_PLAT_ATA_H
14#define __ASM_PLAT_ATA_H __FILE__
15
16/**
17 * struct s3c_ide_platdata - S3C IDE driver platform data.
18 * @setup_gpio: Setup the external GPIO pins to the right state for data
19 * transfer in true-ide mode.
20 */
21struct s3c_ide_platdata {
22 void (*setup_gpio)(void);
23};
24
25/*
26 * s3c_ide_set_platdata() - Setup the platform specifc data for IDE driver.
27 * @pdata: Platform data for IDE driver.
28 */
29extern void s3c_ide_set_platdata(struct s3c_ide_platdata *pdata);
30
31/* architecture-specific IDE configuration */
32extern void s3c64xx_ide_setup_gpio(void);
33extern void s5pc100_ide_setup_gpio(void);
34extern void s5pv210_ide_setup_gpio(void);
35
36#endif /*__ASM_PLAT_ATA_H */
diff --git a/arch/arm/plat-samsung/include/plat/devs.h b/arch/arm/plat-samsung/include/plat/devs.h
index e6144e4b9118..85f6f23a510f 100644
--- a/arch/arm/plat-samsung/include/plat/devs.h
+++ b/arch/arm/plat-samsung/include/plat/devs.h
@@ -54,6 +54,8 @@ extern struct platform_device s3c_device_hwmon;
54extern struct platform_device s3c_device_hsmmc0; 54extern struct platform_device s3c_device_hsmmc0;
55extern struct platform_device s3c_device_hsmmc1; 55extern struct platform_device s3c_device_hsmmc1;
56extern struct platform_device s3c_device_hsmmc2; 56extern struct platform_device s3c_device_hsmmc2;
57extern struct platform_device s3c_device_hsmmc3;
58extern struct platform_device s3c_device_cfcon;
57 59
58extern struct platform_device s3c_device_spi0; 60extern struct platform_device s3c_device_spi0;
59extern struct platform_device s3c_device_spi1; 61extern struct platform_device s3c_device_spi1;
@@ -100,6 +102,12 @@ extern struct platform_device s5pc100_device_iis0;
100extern struct platform_device s5pc100_device_iis1; 102extern struct platform_device s5pc100_device_iis1;
101extern struct platform_device s5pc100_device_iis2; 103extern struct platform_device s5pc100_device_iis2;
102 104
105extern struct platform_device samsung_device_keypad;
106
107extern struct platform_device s5p_device_fimc0;
108extern struct platform_device s5p_device_fimc1;
109extern struct platform_device s5p_device_fimc2;
110
103/* s3c2440 specific devices */ 111/* s3c2440 specific devices */
104 112
105#ifdef CONFIG_CPU_S3C2440 113#ifdef CONFIG_CPU_S3C2440
@@ -108,3 +116,15 @@ extern struct platform_device s3c_device_camif;
108extern struct platform_device s3c_device_ac97; 116extern struct platform_device s3c_device_ac97;
109 117
110#endif 118#endif
119
120/**
121 * s3c_set_platdata() - helper for setting platform data
122 * @pd: The default platform data for this device.
123 * @pdsize: The size of the platform data.
124 * @pdev: Pointer to the device to fill in.
125 *
126 * This helper replaces a number of calls that copy and then set the
127 * platform data of the device.
128 */
129extern void *s3c_set_platdata(void *pd, size_t pdsize,
130 struct platform_device *pdev);
diff --git a/arch/arm/plat-samsung/include/plat/fb-core.h b/arch/arm/plat-samsung/include/plat/fb-core.h
new file mode 100644
index 000000000000..bca383efcf6d
--- /dev/null
+++ b/arch/arm/plat-samsung/include/plat/fb-core.h
@@ -0,0 +1,29 @@
1/*
2 * arch/arm/plat-samsung/include/plat/fb-core.h
3 *
4 * Copyright 2010 Samsung Electronics Co., Ltd.
5 * Pawel Osciak <p.osciak@samsung.com>
6 *
7 * Samsung framebuffer driver core functions
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#ifndef __ASM_PLAT_FB_CORE_H
14#define __ASM_PLAT_FB_CORE_H __FILE__
15
16/*
17 * These functions are only for use with the core support code, such as
18 * the CPU-specific initialization code.
19 */
20
21/* Re-define device name depending on support. */
22static inline void s3c_fb_setname(char *name)
23{
24#ifdef CONFIG_S3C_DEV_FB
25 s3c_device_fb.name = name;
26#endif
27}
28
29#endif /* __ASM_PLAT_FB_CORE_H */
diff --git a/arch/arm/plat-samsung/include/plat/fb.h b/arch/arm/plat-samsung/include/plat/fb.h
index 27d3b497b55b..cb3ca3adc685 100644
--- a/arch/arm/plat-samsung/include/plat/fb.h
+++ b/arch/arm/plat-samsung/include/plat/fb.h
@@ -42,6 +42,7 @@ struct s3c_fb_pd_win {
42 * @setup_gpio: Setup the external GPIO pins to the right state to transfer 42 * @setup_gpio: Setup the external GPIO pins to the right state to transfer
43 * the data from the display system to the connected display 43 * the data from the display system to the connected display
44 * device. 44 * device.
45 * @default_win: default window layer number to be used for UI layer.
45 * @vidcon0: The base vidcon0 values to control the panel data format. 46 * @vidcon0: The base vidcon0 values to control the panel data format.
46 * @vidcon1: The base vidcon1 values to control the panel data output. 47 * @vidcon1: The base vidcon1 values to control the panel data output.
47 * @win: The setup data for each hardware window, or NULL for unused. 48 * @win: The setup data for each hardware window, or NULL for unused.
@@ -58,6 +59,8 @@ struct s3c_fb_platdata {
58 59
59 struct s3c_fb_pd_win *win[S3C_FB_MAX_WIN]; 60 struct s3c_fb_pd_win *win[S3C_FB_MAX_WIN];
60 61
62 u32 default_win;
63
61 u32 vidcon0; 64 u32 vidcon0;
62 u32 vidcon1; 65 u32 vidcon1;
63}; 66};
diff --git a/arch/arm/plat-samsung/include/plat/fimc-core.h b/arch/arm/plat-samsung/include/plat/fimc-core.h
new file mode 100644
index 000000000000..81a3bfeeccad
--- /dev/null
+++ b/arch/arm/plat-samsung/include/plat/fimc-core.h
@@ -0,0 +1,44 @@
1/*
2 * arch/arm/plat-samsung/include/plat/fimc-core.h
3 *
4 * Copyright 2010 Samsung Electronics Co., Ltd.
5 * Sylwester Nawrocki <s.nawrocki@samsung.com>
6 *
7 * Samsung camera interface driver core functions
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#ifndef __ASM_PLAT_FIMC_CORE_H
15#define __ASM_PLAT_FIMC_CORE_H __FILE__
16
17/*
18 * These functions are only for use with the core support code, such as
19 * the CPU-specific initialization code.
20 */
21
22/* Re-define device name to differentiate the subsystem in various SoCs. */
23static inline void s3c_fimc_setname(int id, char *name)
24{
25 switch (id) {
26#ifdef CONFIG_S5P_DEV_FIMC0
27 case 0:
28 s5p_device_fimc0.name = name;
29 break;
30#endif
31#ifdef CONFIG_S5P_DEV_FIMC1
32 case 1:
33 s5p_device_fimc1.name = name;
34 break;
35#endif
36#ifdef CONFIG_S5P_DEV_FIMC2
37 case 2:
38 s5p_device_fimc2.name = name;
39 break;
40#endif
41 }
42}
43
44#endif /* __ASM_PLAT_FIMC_CORE_H */
diff --git a/arch/arm/plat-samsung/include/plat/keypad-core.h b/arch/arm/plat-samsung/include/plat/keypad-core.h
new file mode 100644
index 000000000000..d513e1b3a31e
--- /dev/null
+++ b/arch/arm/plat-samsung/include/plat/keypad-core.h
@@ -0,0 +1,31 @@
1/*
2 * linux/arch/arm/plat-samsung/include/plat/keypad-core.h
3 *
4 * Copyright (C) 2010 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
6 *
7 * Samsung keypad controller core function
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 */
15
16#ifndef __ASM_ARCH_KEYPAD_CORE_H
17#define __ASM_ARCH_KEYPAD_CORE_H
18
19/* These function are only for use with the core support code, such as
20 * the cpu specific initialisation code
21 */
22
23/* re-define device name depending on support. */
24static inline void samsung_keypad_setname(char *name)
25{
26#ifdef CONFIG_SAMSUNG_DEV_KEYPAD
27 samsung_device_keypad.name = name;
28#endif
29}
30
31#endif /* __ASM_ARCH_KEYPAD_CORE_H */
diff --git a/arch/arm/plat-samsung/include/plat/keypad.h b/arch/arm/plat-samsung/include/plat/keypad.h
index 3a70c125fe51..b59a6483cd8a 100644
--- a/arch/arm/plat-samsung/include/plat/keypad.h
+++ b/arch/arm/plat-samsung/include/plat/keypad.h
@@ -40,4 +40,17 @@ struct samsung_keypad_platdata {
40 void (*cfg_gpio)(unsigned int rows, unsigned int cols); 40 void (*cfg_gpio)(unsigned int rows, unsigned int cols);
41}; 41};
42 42
43/**
44 * samsung_keypad_set_platdata - Set platform data for Samsung Keypad device.
45 * @pd: Platform data to register to device.
46 *
47 * Register the given platform data for use with Samsung Keypad device.
48 * The call will copy the platform data, so the board definitions can
49 * make the structure itself __initdata.
50 */
51extern void samsung_keypad_set_platdata(struct samsung_keypad_platdata *pd);
52
53/* defined by architecture to configure gpio. */
54extern void samsung_keypad_cfg_gpio(unsigned int rows, unsigned int cols);
55
43#endif /* __PLAT_SAMSUNG_KEYPAD_H */ 56#endif /* __PLAT_SAMSUNG_KEYPAD_H */
diff --git a/arch/arm/plat-samsung/include/plat/regs-ata.h b/arch/arm/plat-samsung/include/plat/regs-ata.h
new file mode 100644
index 000000000000..f5df92fdae26
--- /dev/null
+++ b/arch/arm/plat-samsung/include/plat/regs-ata.h
@@ -0,0 +1,56 @@
1/* linux/arch/arm/plat-samsung/include/plat/regs-ata.h
2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Samsung CF-ATA register definitions
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#ifndef __ASM_PLAT_REGS_ATA_H
14#define __ASM_PLAT_REGS_ATA_H __FILE__
15
16#define S3C_CFATA_REG(x) (x)
17
18#define S3C_CFATA_MUX S3C_CFATA_REG(0x0)
19
20#define S3C_ATA_CTRL S3C_CFATA_REG(0x0)
21#define S3C_ATA_STATUS S3C_CFATA_REG(0x4)
22#define S3C_ATA_CMD S3C_CFATA_REG(0x8)
23#define S3C_ATA_SWRST S3C_CFATA_REG(0xc)
24#define S3C_ATA_IRQ S3C_CFATA_REG(0x10)
25#define S3C_ATA_IRQ_MSK S3C_CFATA_REG(0x14)
26#define S3C_ATA_CFG S3C_CFATA_REG(0x18)
27
28#define S3C_ATA_MDMA_TIME S3C_CFATA_REG(0x28)
29#define S3C_ATA_PIO_TIME S3C_CFATA_REG(0x2c)
30#define S3C_ATA_UDMA_TIME S3C_CFATA_REG(0x30)
31#define S3C_ATA_XFR_NUM S3C_CFATA_REG(0x34)
32#define S3C_ATA_XFR_CNT S3C_CFATA_REG(0x38)
33#define S3C_ATA_TBUF_START S3C_CFATA_REG(0x3c)
34#define S3C_ATA_TBUF_SIZE S3C_CFATA_REG(0x40)
35#define S3C_ATA_SBUF_START S3C_CFATA_REG(0x44)
36#define S3C_ATA_SBUF_SIZE S3C_CFATA_REG(0x48)
37#define S3C_ATA_CADR_TBUF S3C_CFATA_REG(0x4c)
38#define S3C_ATA_CADR_SBUF S3C_CFATA_REG(0x50)
39#define S3C_ATA_PIO_DTR S3C_CFATA_REG(0x54)
40#define S3C_ATA_PIO_FED S3C_CFATA_REG(0x58)
41#define S3C_ATA_PIO_SCR S3C_CFATA_REG(0x5c)
42#define S3C_ATA_PIO_LLR S3C_CFATA_REG(0x60)
43#define S3C_ATA_PIO_LMR S3C_CFATA_REG(0x64)
44#define S3C_ATA_PIO_LHR S3C_CFATA_REG(0x68)
45#define S3C_ATA_PIO_DVR S3C_CFATA_REG(0x6c)
46#define S3C_ATA_PIO_CSD S3C_CFATA_REG(0x70)
47#define S3C_ATA_PIO_DAD S3C_CFATA_REG(0x74)
48#define S3C_ATA_PIO_READY S3C_CFATA_REG(0x78)
49#define S3C_ATA_PIO_RDATA S3C_CFATA_REG(0x7c)
50
51#define S3C_CFATA_MUX_TRUEIDE 0x01
52
53#define S3C_ATA_CFG_SWAP 0x40
54#define S3C_ATA_CFG_IORDYEN 0x02
55
56#endif /* __ASM_PLAT_REGS_ATA_H */
diff --git a/arch/arm/plat-samsung/include/plat/regs-fb-v4.h b/arch/arm/plat-samsung/include/plat/regs-fb-v4.h
index 0f43599248ad..4c3647f80057 100644
--- a/arch/arm/plat-samsung/include/plat/regs-fb-v4.h
+++ b/arch/arm/plat-samsung/include/plat/regs-fb-v4.h
@@ -40,16 +40,10 @@
40 40
41/* OSD1 and OSD4 do not have register D */ 41/* OSD1 and OSD4 do not have register D */
42 42
43#define VIDOSD_A(_win) (0x40 + ((_win) * 16)) 43#define VIDOSD_BASE (0x40)
44#define VIDOSD_B(_win) (0x44 + ((_win) * 16))
45#define VIDOSD_C(_win) (0x48 + ((_win) * 16))
46#define VIDOSD_D(_win) (0x4C + ((_win) * 16))
47
48 44
49#define VIDINTCON0 (0x130) 45#define VIDINTCON0 (0x130)
50 46
51#define WxKEYCONy(_win, _con) ((0x140 + ((_win) * 8)) + ((_con) * 4))
52
53/* WINCONx */ 47/* WINCONx */
54 48
55#define WINCONx_CSCWIDTH_MASK (0x3 << 26) 49#define WINCONx_CSCWIDTH_MASK (0x3 << 26)
@@ -143,76 +137,6 @@
143#define WPALCON_W2PAL_16BPP_A555 (1 << 6) 137#define WPALCON_W2PAL_16BPP_A555 (1 << 6)
144 138
145 139
146/* system specific implementation code for palette sizes, and other
147 * information that changes depending on which architecture is being
148 * compiled.
149*/
150
151/* return true if window _win has OSD register D */
152#define s3c_fb_has_osd_d(_win) ((_win) != 4 && (_win) != 0)
153
154static inline unsigned int s3c_fb_win_pal_size(unsigned int win)
155{
156 if (win < 2)
157 return 256;
158 if (win < 4)
159 return 16;
160 if (win == 4)
161 return 4;
162
163 BUG(); /* shouldn't get here */
164}
165
166static inline int s3c_fb_validate_win_bpp(unsigned int win, unsigned int bpp)
167{
168 /* all windows can do 1/2 bpp */
169
170 if ((bpp == 25 || bpp == 19) && win == 0)
171 return 0; /* win 0 does not have 19 or 25bpp modes */
172
173 if (bpp == 4 && win == 4)
174 return 0;
175
176 if (bpp == 8 && (win >= 3))
177 return 0; /* win 3/4 cannot do 8bpp in any mode */
178
179 return 1;
180}
181
182static inline int s3c_fb_pal_is16(unsigned int window)
183{
184 return window > 1;
185}
186
187struct s3c_fb_palette {
188 struct fb_bitfield r;
189 struct fb_bitfield g;
190 struct fb_bitfield b;
191 struct fb_bitfield a;
192};
193
194static inline void s3c_fb_init_palette(unsigned int window,
195 struct s3c_fb_palette *palette)
196{
197 if (window < 2) {
198 /* Windows 0/1 are 8/8/8 or A/8/8/8 */
199 palette->r.offset = 16;
200 palette->r.length = 8;
201 palette->g.offset = 8;
202 palette->g.length = 8;
203 palette->b.offset = 0;
204 palette->b.length = 8;
205 } else {
206 /* currently we assume RGB 5/6/5 */
207 palette->r.offset = 11;
208 palette->r.length = 5;
209 palette->g.offset = 5;
210 palette->g.length = 6;
211 palette->b.offset = 0;
212 palette->b.length = 5;
213 }
214}
215
216/* Notes on per-window bpp settings 140/* Notes on per-window bpp settings
217 * 141 *
218 * Value Win0 Win1 Win2 Win3 Win 4 142 * Value Win0 Win1 Win2 Win3 Win 4
diff --git a/arch/arm/plat-samsung/include/plat/regs-fb.h b/arch/arm/plat-samsung/include/plat/regs-fb.h
index 0ef806e50344..8f39aa5b26ea 100644
--- a/arch/arm/plat-samsung/include/plat/regs-fb.h
+++ b/arch/arm/plat-samsung/include/plat/regs-fb.h
@@ -112,6 +112,13 @@
112#define VIDCON2_ORGYCbCr (1 << 8) 112#define VIDCON2_ORGYCbCr (1 << 8)
113#define VIDCON2_YUVORDCrCb (1 << 7) 113#define VIDCON2_YUVORDCrCb (1 << 7)
114 114
115/* PRTCON (S3C6410, S5PC100)
116 * Might not be present in the S3C6410 documentation,
117 * but tests prove it's there almost for sure; shouldn't hurt in any case.
118 */
119#define PRTCON (0x0c)
120#define PRTCON_PROTECT (1 << 11)
121
115/* VIDTCON0 */ 122/* VIDTCON0 */
116 123
117#define VIDTCON0_VBPDE_MASK (0xff << 24) 124#define VIDTCON0_VBPDE_MASK (0xff << 24)
@@ -173,6 +180,7 @@
173#define WINCONx_BITSWP (1 << 18) 180#define WINCONx_BITSWP (1 << 18)
174#define WINCONx_BYTSWP (1 << 17) 181#define WINCONx_BYTSWP (1 << 17)
175#define WINCONx_HAWSWP (1 << 16) 182#define WINCONx_HAWSWP (1 << 16)
183#define WINCONx_WSWP (1 << 15)
176#define WINCONx_BURSTLEN_MASK (0x3 << 9) 184#define WINCONx_BURSTLEN_MASK (0x3 << 9)
177#define WINCONx_BURSTLEN_SHIFT (9) 185#define WINCONx_BURSTLEN_SHIFT (9)
178#define WINCONx_BURSTLEN_16WORD (0x0 << 9) 186#define WINCONx_BURSTLEN_16WORD (0x0 << 9)
@@ -212,6 +220,13 @@
212#define WINCON1_BPPMODE_25BPP_A1888 (0xd << 2) 220#define WINCON1_BPPMODE_25BPP_A1888 (0xd << 2)
213#define WINCON1_BPPMODE_28BPP_A4888 (0xd << 2) 221#define WINCON1_BPPMODE_28BPP_A4888 (0xd << 2)
214 222
223/* S5PV210 */
224#define SHADOWCON (0x34)
225#define SHADOWCON_WINx_PROTECT(_win) (1 << (10 + (_win)))
226/* DMA channels (all windows) */
227#define SHADOWCON_CHx_ENABLE(_win) (1 << (_win))
228/* Local input channels (windows 0-2) */
229#define SHADOWCON_CHx_LOCAL_ENABLE(_win) (1 << (5 + (_win)))
215 230
216#define VIDOSDxA_TOPLEFT_X_MASK (0x7ff << 11) 231#define VIDOSDxA_TOPLEFT_X_MASK (0x7ff << 11)
217#define VIDOSDxA_TOPLEFT_X_SHIFT (11) 232#define VIDOSDxA_TOPLEFT_X_SHIFT (11)
@@ -291,11 +306,12 @@
291#define VIDINTCON0_FRAMESEL0_ACTIVE (0x2 << 15) 306#define VIDINTCON0_FRAMESEL0_ACTIVE (0x2 << 15)
292#define VIDINTCON0_FRAMESEL0_FRONTPORCH (0x3 << 15) 307#define VIDINTCON0_FRAMESEL0_FRONTPORCH (0x3 << 15)
293 308
294#define VIDINTCON0_FRAMESEL1 (1 << 14) 309#define VIDINTCON0_FRAMESEL1 (1 << 13)
295#define VIDINTCON0_FRAMESEL1_NONE (0x0 << 14) 310#define VIDINTCON0_FRAMESEL1_MASK (0x3 << 13)
296#define VIDINTCON0_FRAMESEL1_BACKPORCH (0x1 << 14) 311#define VIDINTCON0_FRAMESEL1_NONE (0x0 << 13)
297#define VIDINTCON0_FRAMESEL1_VSYNC (0x2 << 14) 312#define VIDINTCON0_FRAMESEL1_BACKPORCH (0x1 << 13)
298#define VIDINTCON0_FRAMESEL1_FRONTPORCH (0x3 << 14) 313#define VIDINTCON0_FRAMESEL1_VSYNC (0x2 << 13)
314#define VIDINTCON0_FRAMESEL1_FRONTPORCH (0x3 << 13)
299 315
300#define VIDINTCON0_INT_FRAME (1 << 12) 316#define VIDINTCON0_INT_FRAME (1 << 12)
301#define VIDINTCON0_FIFIOSEL_MASK (0x7f << 5) 317#define VIDINTCON0_FIFIOSEL_MASK (0x7f << 5)
@@ -321,6 +337,10 @@
321#define VIDINTCON1_INT_FIFO (1 << 0) 337#define VIDINTCON1_INT_FIFO (1 << 0)
322 338
323/* Window colour-key control registers */ 339/* Window colour-key control registers */
340#define WKEYCON (0x140) /* 6410,V210 */
341
342#define WKEYCON0 (0x00)
343#define WKEYCON1 (0x04)
324 344
325#define WxKEYCON0_KEYBL_EN (1 << 26) 345#define WxKEYCON0_KEYBL_EN (1 << 26)
326#define WxKEYCON0_KEYEN_F (1 << 25) 346#define WxKEYCON0_KEYEN_F (1 << 25)
diff --git a/arch/arm/plat-samsung/include/plat/regs-rtc.h b/arch/arm/plat-samsung/include/plat/regs-rtc.h
index 65c190d142dd..30b7cc14cef5 100644
--- a/arch/arm/plat-samsung/include/plat/regs-rtc.h
+++ b/arch/arm/plat-samsung/include/plat/regs-rtc.h
@@ -14,6 +14,9 @@
14#define __ASM_ARCH_REGS_RTC_H __FILE__ 14#define __ASM_ARCH_REGS_RTC_H __FILE__
15 15
16#define S3C2410_RTCREG(x) (x) 16#define S3C2410_RTCREG(x) (x)
17#define S3C2410_INTP S3C2410_RTCREG(0x30)
18#define S3C2410_INTP_ALM (1 << 1)
19#define S3C2410_INTP_TIC (1 << 0)
17 20
18#define S3C2410_RTCCON S3C2410_RTCREG(0x40) 21#define S3C2410_RTCCON S3C2410_RTCREG(0x40)
19#define S3C2410_RTCCON_RTCEN (1<<0) 22#define S3C2410_RTCCON_RTCEN (1<<0)
diff --git a/arch/arm/plat-samsung/include/plat/regs-serial.h b/arch/arm/plat-samsung/include/plat/regs-serial.h
index a6eba8496b24..788837e99cb3 100644
--- a/arch/arm/plat-samsung/include/plat/regs-serial.h
+++ b/arch/arm/plat-samsung/include/plat/regs-serial.h
@@ -259,6 +259,8 @@ struct s3c2410_uartcfg {
259 unsigned short flags; 259 unsigned short flags;
260 upf_t uart_flags; /* default uart flags */ 260 upf_t uart_flags; /* default uart flags */
261 261
262 unsigned int has_fracval;
263
262 unsigned long ucon; /* value of ucon for port */ 264 unsigned long ucon; /* value of ucon for port */
263 unsigned long ulcon; /* value of ulcon for port */ 265 unsigned long ulcon; /* value of ulcon for port */
264 unsigned long ufcon; /* value of ufcon for port */ 266 unsigned long ufcon; /* value of ufcon for port */
diff --git a/arch/arm/plat-samsung/include/plat/sdhci.h b/arch/arm/plat-samsung/include/plat/sdhci.h
index 016674fa20dd..30844c263d03 100644
--- a/arch/arm/plat-samsung/include/plat/sdhci.h
+++ b/arch/arm/plat-samsung/include/plat/sdhci.h
@@ -20,10 +20,31 @@ struct mmc_host;
20struct mmc_card; 20struct mmc_card;
21struct mmc_ios; 21struct mmc_ios;
22 22
23enum cd_types {
24 S3C_SDHCI_CD_INTERNAL, /* use mmc internal CD line */
25 S3C_SDHCI_CD_EXTERNAL, /* use external callback */
26 S3C_SDHCI_CD_GPIO, /* use external gpio pin for CD line */
27 S3C_SDHCI_CD_NONE, /* no CD line, use polling to detect card */
28 S3C_SDHCI_CD_PERMANENT, /* no CD line, card permanently wired to host */
29};
30
23/** 31/**
24 * struct s3c_sdhci_platdata() - Platform device data for Samsung SDHCI 32 * struct s3c_sdhci_platdata() - Platform device data for Samsung SDHCI
25 * @max_width: The maximum number of data bits supported. 33 * @max_width: The maximum number of data bits supported.
26 * @host_caps: Standard MMC host capabilities bit field. 34 * @host_caps: Standard MMC host capabilities bit field.
35 * @cd_type: Type of Card Detection method (see cd_types enum above)
36 * @ext_cd_init: Initialize external card detect subsystem. Called on
37 * sdhci-s3c driver probe when cd_type == S3C_SDHCI_CD_EXTERNAL.
38 * notify_func argument is a callback to the sdhci-s3c driver
39 * that triggers the card detection event. Callback arguments:
40 * dev is pointer to platform device of the host controller,
41 * state is new state of the card (0 - removed, 1 - inserted).
42 * @ext_cd_cleanup: Cleanup external card detect subsystem. Called on
43 * sdhci-s3c driver remove when cd_type == S3C_SDHCI_CD_EXTERNAL.
44 * notify_func argument is the same callback as for ext_cd_init.
45 * @ext_cd_gpio: gpio pin used for external CD line, valid only if
46 * cd_type == S3C_SDHCI_CD_GPIO
47 * @ext_cd_gpio_invert: invert values for external CD gpio line
27 * @cfg_gpio: Configure the GPIO for a specific card bit-width 48 * @cfg_gpio: Configure the GPIO for a specific card bit-width
28 * @cfg_card: Configure the interface for a specific card and speed. This 49 * @cfg_card: Configure the interface for a specific card and speed. This
29 * is necessary the controllers and/or GPIO blocks require the 50 * is necessary the controllers and/or GPIO blocks require the
@@ -37,9 +58,17 @@ struct mmc_ios;
37struct s3c_sdhci_platdata { 58struct s3c_sdhci_platdata {
38 unsigned int max_width; 59 unsigned int max_width;
39 unsigned int host_caps; 60 unsigned int host_caps;
61 enum cd_types cd_type;
40 62
41 char **clocks; /* set of clock sources */ 63 char **clocks; /* set of clock sources */
42 64
65 int ext_cd_gpio;
66 bool ext_cd_gpio_invert;
67 int (*ext_cd_init)(void (*notify_func)(struct platform_device *,
68 int state));
69 int (*ext_cd_cleanup)(void (*notify_func)(struct platform_device *,
70 int state));
71
43 void (*cfg_gpio)(struct platform_device *dev, int width); 72 void (*cfg_gpio)(struct platform_device *dev, int width);
44 void (*cfg_card)(struct platform_device *dev, 73 void (*cfg_card)(struct platform_device *dev,
45 void __iomem *regbase, 74 void __iomem *regbase,
@@ -58,6 +87,7 @@ struct s3c_sdhci_platdata {
58extern void s3c_sdhci0_set_platdata(struct s3c_sdhci_platdata *pd); 87extern void s3c_sdhci0_set_platdata(struct s3c_sdhci_platdata *pd);
59extern void s3c_sdhci1_set_platdata(struct s3c_sdhci_platdata *pd); 88extern void s3c_sdhci1_set_platdata(struct s3c_sdhci_platdata *pd);
60extern void s3c_sdhci2_set_platdata(struct s3c_sdhci_platdata *pd); 89extern void s3c_sdhci2_set_platdata(struct s3c_sdhci_platdata *pd);
90extern void s3c_sdhci3_set_platdata(struct s3c_sdhci_platdata *pd);
61 91
62/* Default platform data, exported so that per-cpu initialisation can 92/* Default platform data, exported so that per-cpu initialisation can
63 * set the correct one when there are more than one cpu type selected. 93 * set the correct one when there are more than one cpu type selected.
@@ -66,6 +96,7 @@ extern void s3c_sdhci2_set_platdata(struct s3c_sdhci_platdata *pd);
66extern struct s3c_sdhci_platdata s3c_hsmmc0_def_platdata; 96extern struct s3c_sdhci_platdata s3c_hsmmc0_def_platdata;
67extern struct s3c_sdhci_platdata s3c_hsmmc1_def_platdata; 97extern struct s3c_sdhci_platdata s3c_hsmmc1_def_platdata;
68extern struct s3c_sdhci_platdata s3c_hsmmc2_def_platdata; 98extern struct s3c_sdhci_platdata s3c_hsmmc2_def_platdata;
99extern struct s3c_sdhci_platdata s3c_hsmmc3_def_platdata;
69 100
70/* Helper function availablity */ 101/* Helper function availablity */
71 102
@@ -78,13 +109,13 @@ extern void s3c64xx_setup_sdhci2_cfg_gpio(struct platform_device *, int w);
78extern void s5pv210_setup_sdhci0_cfg_gpio(struct platform_device *, int w); 109extern void s5pv210_setup_sdhci0_cfg_gpio(struct platform_device *, int w);
79extern void s5pv210_setup_sdhci1_cfg_gpio(struct platform_device *, int w); 110extern void s5pv210_setup_sdhci1_cfg_gpio(struct platform_device *, int w);
80extern void s5pv210_setup_sdhci2_cfg_gpio(struct platform_device *, int w); 111extern void s5pv210_setup_sdhci2_cfg_gpio(struct platform_device *, int w);
112extern void s5pv210_setup_sdhci3_cfg_gpio(struct platform_device *, int w);
81 113
82/* S3C6400 SDHCI setup */ 114/* S3C64XX SDHCI setup */
83 115
84#ifdef CONFIG_S3C64XX_SETUP_SDHCI 116#ifdef CONFIG_S3C64XX_SETUP_SDHCI
85extern char *s3c64xx_hsmmc_clksrcs[4]; 117extern char *s3c64xx_hsmmc_clksrcs[4];
86 118
87#ifdef CONFIG_S3C_DEV_HSMMC
88extern void s3c6400_setup_sdhci_cfg_card(struct platform_device *dev, 119extern void s3c6400_setup_sdhci_cfg_card(struct platform_device *dev,
89 void __iomem *r, 120 void __iomem *r,
90 struct mmc_ios *ios, 121 struct mmc_ios *ios,
@@ -92,76 +123,62 @@ extern void s3c6400_setup_sdhci_cfg_card(struct platform_device *dev,
92 123
93static inline void s3c6400_default_sdhci0(void) 124static inline void s3c6400_default_sdhci0(void)
94{ 125{
126#ifdef CONFIG_S3C_DEV_HSMMC
95 s3c_hsmmc0_def_platdata.clocks = s3c64xx_hsmmc_clksrcs; 127 s3c_hsmmc0_def_platdata.clocks = s3c64xx_hsmmc_clksrcs;
96 s3c_hsmmc0_def_platdata.cfg_gpio = s3c64xx_setup_sdhci0_cfg_gpio; 128 s3c_hsmmc0_def_platdata.cfg_gpio = s3c64xx_setup_sdhci0_cfg_gpio;
97 s3c_hsmmc0_def_platdata.cfg_card = s3c6400_setup_sdhci_cfg_card; 129 s3c_hsmmc0_def_platdata.cfg_card = s3c6400_setup_sdhci_cfg_card;
130#endif
98} 131}
99 132
100#else
101static inline void s3c6400_default_sdhci0(void) { }
102#endif /* CONFIG_S3C_DEV_HSMMC */
103
104#ifdef CONFIG_S3C_DEV_HSMMC1
105static inline void s3c6400_default_sdhci1(void) 133static inline void s3c6400_default_sdhci1(void)
106{ 134{
135#ifdef CONFIG_S3C_DEV_HSMMC1
107 s3c_hsmmc1_def_platdata.clocks = s3c64xx_hsmmc_clksrcs; 136 s3c_hsmmc1_def_platdata.clocks = s3c64xx_hsmmc_clksrcs;
108 s3c_hsmmc1_def_platdata.cfg_gpio = s3c64xx_setup_sdhci1_cfg_gpio; 137 s3c_hsmmc1_def_platdata.cfg_gpio = s3c64xx_setup_sdhci1_cfg_gpio;
109 s3c_hsmmc1_def_platdata.cfg_card = s3c6400_setup_sdhci_cfg_card; 138 s3c_hsmmc1_def_platdata.cfg_card = s3c6400_setup_sdhci_cfg_card;
139#endif
110} 140}
111#else
112static inline void s3c6400_default_sdhci1(void) { }
113#endif /* CONFIG_S3C_DEV_HSMMC1 */
114 141
115#ifdef CONFIG_S3C_DEV_HSMMC2
116static inline void s3c6400_default_sdhci2(void) 142static inline void s3c6400_default_sdhci2(void)
117{ 143{
144#ifdef CONFIG_S3C_DEV_HSMMC2
118 s3c_hsmmc2_def_platdata.clocks = s3c64xx_hsmmc_clksrcs; 145 s3c_hsmmc2_def_platdata.clocks = s3c64xx_hsmmc_clksrcs;
119 s3c_hsmmc2_def_platdata.cfg_gpio = s3c64xx_setup_sdhci2_cfg_gpio; 146 s3c_hsmmc2_def_platdata.cfg_gpio = s3c64xx_setup_sdhci2_cfg_gpio;
120 s3c_hsmmc2_def_platdata.cfg_card = s3c6400_setup_sdhci_cfg_card; 147 s3c_hsmmc2_def_platdata.cfg_card = s3c6400_setup_sdhci_cfg_card;
148#endif
121} 149}
122#else
123static inline void s3c6400_default_sdhci2(void) { }
124#endif /* CONFIG_S3C_DEV_HSMMC2 */
125
126/* S3C6410 SDHCI setup */
127 150
128extern void s3c6410_setup_sdhci_cfg_card(struct platform_device *dev, 151extern void s3c6410_setup_sdhci_cfg_card(struct platform_device *dev,
129 void __iomem *r, 152 void __iomem *r,
130 struct mmc_ios *ios, 153 struct mmc_ios *ios,
131 struct mmc_card *card); 154 struct mmc_card *card);
132 155
133#ifdef CONFIG_S3C_DEV_HSMMC
134static inline void s3c6410_default_sdhci0(void) 156static inline void s3c6410_default_sdhci0(void)
135{ 157{
158#ifdef CONFIG_S3C_DEV_HSMMC
136 s3c_hsmmc0_def_platdata.clocks = s3c64xx_hsmmc_clksrcs; 159 s3c_hsmmc0_def_platdata.clocks = s3c64xx_hsmmc_clksrcs;
137 s3c_hsmmc0_def_platdata.cfg_gpio = s3c64xx_setup_sdhci0_cfg_gpio; 160 s3c_hsmmc0_def_platdata.cfg_gpio = s3c64xx_setup_sdhci0_cfg_gpio;
138 s3c_hsmmc0_def_platdata.cfg_card = s3c6410_setup_sdhci_cfg_card; 161 s3c_hsmmc0_def_platdata.cfg_card = s3c6410_setup_sdhci_cfg_card;
162#endif
139} 163}
140#else
141static inline void s3c6410_default_sdhci0(void) { }
142#endif /* CONFIG_S3C_DEV_HSMMC */
143 164
144#ifdef CONFIG_S3C_DEV_HSMMC1
145static inline void s3c6410_default_sdhci1(void) 165static inline void s3c6410_default_sdhci1(void)
146{ 166{
167#ifdef CONFIG_S3C_DEV_HSMMC1
147 s3c_hsmmc1_def_platdata.clocks = s3c64xx_hsmmc_clksrcs; 168 s3c_hsmmc1_def_platdata.clocks = s3c64xx_hsmmc_clksrcs;
148 s3c_hsmmc1_def_platdata.cfg_gpio = s3c64xx_setup_sdhci1_cfg_gpio; 169 s3c_hsmmc1_def_platdata.cfg_gpio = s3c64xx_setup_sdhci1_cfg_gpio;
149 s3c_hsmmc1_def_platdata.cfg_card = s3c6410_setup_sdhci_cfg_card; 170 s3c_hsmmc1_def_platdata.cfg_card = s3c6410_setup_sdhci_cfg_card;
171#endif
150} 172}
151#else
152static inline void s3c6410_default_sdhci1(void) { }
153#endif /* CONFIG_S3C_DEV_HSMMC1 */
154 173
155#ifdef CONFIG_S3C_DEV_HSMMC2
156static inline void s3c6410_default_sdhci2(void) 174static inline void s3c6410_default_sdhci2(void)
157{ 175{
176#ifdef CONFIG_S3C_DEV_HSMMC2
158 s3c_hsmmc2_def_platdata.clocks = s3c64xx_hsmmc_clksrcs; 177 s3c_hsmmc2_def_platdata.clocks = s3c64xx_hsmmc_clksrcs;
159 s3c_hsmmc2_def_platdata.cfg_gpio = s3c64xx_setup_sdhci2_cfg_gpio; 178 s3c_hsmmc2_def_platdata.cfg_gpio = s3c64xx_setup_sdhci2_cfg_gpio;
160 s3c_hsmmc2_def_platdata.cfg_card = s3c6410_setup_sdhci_cfg_card; 179 s3c_hsmmc2_def_platdata.cfg_card = s3c6410_setup_sdhci_cfg_card;
180#endif
161} 181}
162#else
163static inline void s3c6410_default_sdhci2(void) { }
164#endif /* CONFIG_S3C_DEV_HSMMC2 */
165 182
166#else 183#else
167static inline void s3c6410_default_sdhci0(void) { } 184static inline void s3c6410_default_sdhci0(void) { }
@@ -183,48 +200,42 @@ extern void s5pc100_setup_sdhci0_cfg_card(struct platform_device *dev,
183 struct mmc_ios *ios, 200 struct mmc_ios *ios,
184 struct mmc_card *card); 201 struct mmc_card *card);
185 202
186#ifdef CONFIG_S3C_DEV_HSMMC
187static inline void s5pc100_default_sdhci0(void) 203static inline void s5pc100_default_sdhci0(void)
188{ 204{
205#ifdef CONFIG_S3C_DEV_HSMMC
189 s3c_hsmmc0_def_platdata.clocks = s5pc100_hsmmc_clksrcs; 206 s3c_hsmmc0_def_platdata.clocks = s5pc100_hsmmc_clksrcs;
190 s3c_hsmmc0_def_platdata.cfg_gpio = s5pc100_setup_sdhci0_cfg_gpio; 207 s3c_hsmmc0_def_platdata.cfg_gpio = s5pc100_setup_sdhci0_cfg_gpio;
191 s3c_hsmmc0_def_platdata.cfg_card = s5pc100_setup_sdhci0_cfg_card; 208 s3c_hsmmc0_def_platdata.cfg_card = s5pc100_setup_sdhci0_cfg_card;
209#endif
192} 210}
193#else
194static inline void s5pc100_default_sdhci0(void) { }
195#endif /* CONFIG_S3C_DEV_HSMMC */
196 211
197#ifdef CONFIG_S3C_DEV_HSMMC1
198static inline void s5pc100_default_sdhci1(void) 212static inline void s5pc100_default_sdhci1(void)
199{ 213{
214#ifdef CONFIG_S3C_DEV_HSMMC1
200 s3c_hsmmc1_def_platdata.clocks = s5pc100_hsmmc_clksrcs; 215 s3c_hsmmc1_def_platdata.clocks = s5pc100_hsmmc_clksrcs;
201 s3c_hsmmc1_def_platdata.cfg_gpio = s5pc100_setup_sdhci1_cfg_gpio; 216 s3c_hsmmc1_def_platdata.cfg_gpio = s5pc100_setup_sdhci1_cfg_gpio;
202 s3c_hsmmc1_def_platdata.cfg_card = s5pc100_setup_sdhci0_cfg_card; 217 s3c_hsmmc1_def_platdata.cfg_card = s5pc100_setup_sdhci0_cfg_card;
218#endif
203} 219}
204#else
205static inline void s5pc100_default_sdhci1(void) { }
206#endif /* CONFIG_S3C_DEV_HSMMC1 */
207 220
208#ifdef CONFIG_S3C_DEV_HSMMC2
209static inline void s5pc100_default_sdhci2(void) 221static inline void s5pc100_default_sdhci2(void)
210{ 222{
223#ifdef CONFIG_S3C_DEV_HSMMC2
211 s3c_hsmmc2_def_platdata.clocks = s5pc100_hsmmc_clksrcs; 224 s3c_hsmmc2_def_platdata.clocks = s5pc100_hsmmc_clksrcs;
212 s3c_hsmmc2_def_platdata.cfg_gpio = s5pc100_setup_sdhci2_cfg_gpio; 225 s3c_hsmmc2_def_platdata.cfg_gpio = s5pc100_setup_sdhci2_cfg_gpio;
213 s3c_hsmmc2_def_platdata.cfg_card = s5pc100_setup_sdhci0_cfg_card; 226 s3c_hsmmc2_def_platdata.cfg_card = s5pc100_setup_sdhci0_cfg_card;
227#endif
214} 228}
215#else
216static inline void s5pc100_default_sdhci2(void) { }
217#endif /* CONFIG_S3C_DEV_HSMMC1 */
218
219 229
220#else 230#else
221static inline void s5pc100_default_sdhci0(void) { } 231static inline void s5pc100_default_sdhci0(void) { }
222static inline void s5pc100_default_sdhci1(void) { } 232static inline void s5pc100_default_sdhci1(void) { }
223static inline void s5pc100_default_sdhci2(void) { } 233static inline void s5pc100_default_sdhci2(void) { }
234
224#endif /* CONFIG_S5PC100_SETUP_SDHCI */ 235#endif /* CONFIG_S5PC100_SETUP_SDHCI */
225 236
237/* S5PV210 SDHCI setup */
226 238
227/* S5PC110 SDHCI setup */
228#ifdef CONFIG_S5PV210_SETUP_SDHCI 239#ifdef CONFIG_S5PV210_SETUP_SDHCI
229extern char *s5pv210_hsmmc_clksrcs[4]; 240extern char *s5pv210_hsmmc_clksrcs[4];
230 241
@@ -233,46 +244,48 @@ extern void s5pv210_setup_sdhci_cfg_card(struct platform_device *dev,
233 struct mmc_ios *ios, 244 struct mmc_ios *ios,
234 struct mmc_card *card); 245 struct mmc_card *card);
235 246
236#ifdef CONFIG_S3C_DEV_HSMMC
237static inline void s5pv210_default_sdhci0(void) 247static inline void s5pv210_default_sdhci0(void)
238{ 248{
249#ifdef CONFIG_S3C_DEV_HSMMC
239 s3c_hsmmc0_def_platdata.clocks = s5pv210_hsmmc_clksrcs; 250 s3c_hsmmc0_def_platdata.clocks = s5pv210_hsmmc_clksrcs;
240 s3c_hsmmc0_def_platdata.cfg_gpio = s5pv210_setup_sdhci0_cfg_gpio; 251 s3c_hsmmc0_def_platdata.cfg_gpio = s5pv210_setup_sdhci0_cfg_gpio;
241 s3c_hsmmc0_def_platdata.cfg_card = s5pv210_setup_sdhci_cfg_card; 252 s3c_hsmmc0_def_platdata.cfg_card = s5pv210_setup_sdhci_cfg_card;
253#endif
242} 254}
243#else
244static inline void s5pv210_default_sdhci0(void) { }
245#endif /* CONFIG_S3C_DEV_HSMMC */
246 255
247#ifdef CONFIG_S3C_DEV_HSMMC1
248static inline void s5pv210_default_sdhci1(void) 256static inline void s5pv210_default_sdhci1(void)
249{ 257{
258#ifdef CONFIG_S3C_DEV_HSMMC1
250 s3c_hsmmc1_def_platdata.clocks = s5pv210_hsmmc_clksrcs; 259 s3c_hsmmc1_def_platdata.clocks = s5pv210_hsmmc_clksrcs;
251 s3c_hsmmc1_def_platdata.cfg_gpio = s5pv210_setup_sdhci1_cfg_gpio; 260 s3c_hsmmc1_def_platdata.cfg_gpio = s5pv210_setup_sdhci1_cfg_gpio;
252 s3c_hsmmc1_def_platdata.cfg_card = s5pv210_setup_sdhci_cfg_card; 261 s3c_hsmmc1_def_platdata.cfg_card = s5pv210_setup_sdhci_cfg_card;
262#endif
253} 263}
254#else
255static inline void s5pv210_default_sdhci1(void) { }
256#endif /* CONFIG_S3C_DEV_HSMMC1 */
257 264
258#ifdef CONFIG_S3C_DEV_HSMMC2
259static inline void s5pv210_default_sdhci2(void) 265static inline void s5pv210_default_sdhci2(void)
260{ 266{
267#ifdef CONFIG_S3C_DEV_HSMMC2
261 s3c_hsmmc2_def_platdata.clocks = s5pv210_hsmmc_clksrcs; 268 s3c_hsmmc2_def_platdata.clocks = s5pv210_hsmmc_clksrcs;
262 s3c_hsmmc2_def_platdata.cfg_gpio = s5pv210_setup_sdhci2_cfg_gpio; 269 s3c_hsmmc2_def_platdata.cfg_gpio = s5pv210_setup_sdhci2_cfg_gpio;
263 s3c_hsmmc2_def_platdata.cfg_card = s5pv210_setup_sdhci_cfg_card; 270 s3c_hsmmc2_def_platdata.cfg_card = s5pv210_setup_sdhci_cfg_card;
271#endif
272}
273
274static inline void s5pv210_default_sdhci3(void)
275{
276#ifdef CONFIG_S3C_DEV_HSMMC3
277 s3c_hsmmc3_def_platdata.clocks = s5pv210_hsmmc_clksrcs;
278 s3c_hsmmc3_def_platdata.cfg_gpio = s5pv210_setup_sdhci3_cfg_gpio;
279 s3c_hsmmc3_def_platdata.cfg_card = s5pv210_setup_sdhci_cfg_card;
280#endif
264} 281}
265#else
266static inline void s5pv210_default_sdhci2(void) { }
267#endif /* CONFIG_S3C_DEV_HSMMC2 */
268 282
269#else 283#else
270static inline void s5pv210_default_sdhci0(void) { } 284static inline void s5pv210_default_sdhci0(void) { }
271static inline void s5pv210_default_sdhci1(void) { } 285static inline void s5pv210_default_sdhci1(void) { }
272static inline void s5pv210_default_sdhci2(void) { } 286static inline void s5pv210_default_sdhci2(void) { }
273#endif /* CONFIG_S5PC100_SETUP_SDHCI */ 287static inline void s5pv210_default_sdhci3(void) { }
274
275
276 288
289#endif /* CONFIG_S5PV210_SETUP_SDHCI */
277 290
278#endif /* __PLAT_S3C_SDHCI_H */ 291#endif /* __PLAT_S3C_SDHCI_H */
diff --git a/arch/arm/plat-samsung/platformdata.c b/arch/arm/plat-samsung/platformdata.c
new file mode 100644
index 000000000000..7cf2e1e3b20f
--- /dev/null
+++ b/arch/arm/plat-samsung/platformdata.c
@@ -0,0 +1,37 @@
1/* linux/arch/arm/plat-samsung/platformdata.c
2 *
3 * Copyright 2010 Ben Dooks <ben-linux <at> fluff.org>
4 *
5 * Helper for platform data setting
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10*/
11
12#include <linux/kernel.h>
13#include <linux/string.h>
14#include <linux/platform_device.h>
15
16#include <plat/devs.h>
17
18void __init *s3c_set_platdata(void *pd, size_t pdsize,
19 struct platform_device *pdev)
20{
21 void *npd;
22
23 if (!pd) {
24 /* too early to use dev_name(), may not be registered */
25 printk(KERN_ERR "%s: no platform data supplied\n", pdev->name);
26 return NULL;
27 }
28
29 npd = kmemdup(pd, pdsize, GFP_KERNEL);
30 if (!npd) {
31 printk(KERN_ERR "%s: cannot clone platform data\n", pdev->name);
32 return NULL;
33 }
34
35 pdev->dev.platform_data = npd;
36 return npd;
37}
diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
index d3cf35ab11ab..c3a58a189a91 100644
--- a/arch/avr32/include/asm/cache.h
+++ b/arch/avr32/include/asm/cache.h
@@ -11,7 +11,7 @@
11 * cache before the transfer is done, causing old data to be seen by 11 * cache before the transfer is done, causing old data to be seen by
12 * the CPU. 12 * the CPU.
13 */ 13 */
14#define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES 14#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
15 15
16#ifndef __ASSEMBLER__ 16#ifndef __ASSEMBLER__
17struct cache_info { 17struct cache_info {
diff --git a/arch/avr32/include/asm/dma-mapping.h b/arch/avr32/include/asm/dma-mapping.h
index 0399359ab5d8..aaf5199d8fcb 100644
--- a/arch/avr32/include/asm/dma-mapping.h
+++ b/arch/avr32/include/asm/dma-mapping.h
@@ -336,14 +336,4 @@ dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
336#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 336#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
337#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) 337#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
338 338
339static inline int dma_is_consistent(struct device *dev, dma_addr_t dma_addr)
340{
341 return 1;
342}
343
344static inline int dma_get_cache_alignment(void)
345{
346 return boot_cpu_data.dcache.linesz;
347}
348
349#endif /* __ASM_AVR32_DMA_MAPPING_H */ 339#endif /* __ASM_AVR32_DMA_MAPPING_H */
diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
index 93f6c634fdf4..bd0641a267f1 100644
--- a/arch/blackfin/include/asm/cache.h
+++ b/arch/blackfin/include/asm/cache.h
@@ -15,7 +15,7 @@
15#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) 15#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16#define SMP_CACHE_BYTES L1_CACHE_BYTES 16#define SMP_CACHE_BYTES L1_CACHE_BYTES
17 17
18#define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES 18#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
19 19
20#ifdef CONFIG_SMP 20#ifdef CONFIG_SMP
21#define __cacheline_aligned 21#define __cacheline_aligned
diff --git a/arch/blackfin/include/asm/dma-mapping.h b/arch/blackfin/include/asm/dma-mapping.h
index 212cb80fd74b..bbf461076a0a 100644
--- a/arch/blackfin/include/asm/dma-mapping.h
+++ b/arch/blackfin/include/asm/dma-mapping.h
@@ -21,8 +21,6 @@ void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
21#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 21#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
22#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) 22#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
23#define dma_supported(d, m) (1) 23#define dma_supported(d, m) (1)
24#define dma_get_cache_alignment() (32)
25#define dma_is_consistent(d, h) (1)
26 24
27static inline int 25static inline int
28dma_set_mask(struct device *dev, u64 dma_mask) 26dma_set_mask(struct device *dev, u64 dma_mask)
diff --git a/arch/cris/include/asm/dma-mapping.h b/arch/cris/include/asm/dma-mapping.h
index da8ef8e8f842..8588b2ccf854 100644
--- a/arch/cris/include/asm/dma-mapping.h
+++ b/arch/cris/include/asm/dma-mapping.h
@@ -152,14 +152,6 @@ dma_set_mask(struct device *dev, u64 mask)
152 return 0; 152 return 0;
153} 153}
154 154
155static inline int
156dma_get_cache_alignment(void)
157{
158 return (1 << INTERNODE_CACHE_SHIFT);
159}
160
161#define dma_is_consistent(d, h) (1)
162
163static inline void 155static inline void
164dma_cache_sync(struct device *dev, void *vaddr, size_t size, 156dma_cache_sync(struct device *dev, void *vaddr, size_t size,
165 enum dma_data_direction direction) 157 enum dma_data_direction direction)
diff --git a/arch/cris/include/asm/pgtable.h b/arch/cris/include/asm/pgtable.h
index 99ea6cd1b143..f63d6fccbc6c 100644
--- a/arch/cris/include/asm/pgtable.h
+++ b/arch/cris/include/asm/pgtable.h
@@ -260,6 +260,9 @@ static inline pgd_t * pgd_offset(const struct mm_struct *mm, unsigned long addre
260#define pgd_ERROR(e) \ 260#define pgd_ERROR(e) \
261 printk("%s:%d: bad pgd %p(%08lx).\n", __FILE__, __LINE__, &(e), pgd_val(e)) 261 printk("%s:%d: bad pgd %p(%08lx).\n", __FILE__, __LINE__, &(e), pgd_val(e))
262 262
263#define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
264 remap_pfn_range(vma, vaddr, pfn, size, prot)
265
263 266
264extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; /* defined in head.S */ 267extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; /* defined in head.S */
265 268
diff --git a/arch/frv/include/asm/dma-mapping.h b/arch/frv/include/asm/dma-mapping.h
index 6af5d83e2fb2..dfb811002c64 100644
--- a/arch/frv/include/asm/dma-mapping.h
+++ b/arch/frv/include/asm/dma-mapping.h
@@ -126,14 +126,6 @@ int dma_set_mask(struct device *dev, u64 mask)
126} 126}
127 127
128static inline 128static inline
129int dma_get_cache_alignment(void)
130{
131 return 1 << L1_CACHE_SHIFT;
132}
133
134#define dma_is_consistent(d, h) (1)
135
136static inline
137void dma_cache_sync(struct device *dev, void *vaddr, size_t size, 129void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
138 enum dma_data_direction direction) 130 enum dma_data_direction direction)
139{ 131{
diff --git a/arch/frv/include/asm/mem-layout.h b/arch/frv/include/asm/mem-layout.h
index ccae981876fa..e9a0ec85a402 100644
--- a/arch/frv/include/asm/mem-layout.h
+++ b/arch/frv/include/asm/mem-layout.h
@@ -35,7 +35,7 @@
35 * the slab must be aligned such that load- and store-double instructions don't 35 * the slab must be aligned such that load- and store-double instructions don't
36 * fault if used 36 * fault if used
37 */ 37 */
38#define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES 38#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
39#define ARCH_SLAB_MINALIGN L1_CACHE_BYTES 39#define ARCH_SLAB_MINALIGN L1_CACHE_BYTES
40 40
41/*****************************************************************************/ 41/*****************************************************************************/
diff --git a/arch/ia64/include/asm/dma-mapping.h b/arch/ia64/include/asm/dma-mapping.h
index 7d09a09cdaad..a2e7368a0150 100644
--- a/arch/ia64/include/asm/dma-mapping.h
+++ b/arch/ia64/include/asm/dma-mapping.h
@@ -86,8 +86,6 @@ static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
86 return daddr; 86 return daddr;
87} 87}
88 88
89extern int dma_get_cache_alignment(void);
90
91static inline void 89static inline void
92dma_cache_sync (struct device *dev, void *vaddr, size_t size, 90dma_cache_sync (struct device *dev, void *vaddr, size_t size,
93 enum dma_data_direction dir) 91 enum dma_data_direction dir)
@@ -99,6 +97,4 @@ dma_cache_sync (struct device *dev, void *vaddr, size_t size,
99 mb(); 97 mb();
100} 98}
101 99
102#define dma_is_consistent(d, h) (1) /* all we do is coherent memory... */
103
104#endif /* _ASM_IA64_DMA_MAPPING_H */ 100#endif /* _ASM_IA64_DMA_MAPPING_H */
diff --git a/arch/ia64/include/asm/rwsem.h b/arch/ia64/include/asm/rwsem.h
index e8762688e8e3..215d5454c7d3 100644
--- a/arch/ia64/include/asm/rwsem.h
+++ b/arch/ia64/include/asm/rwsem.h
@@ -40,9 +40,9 @@ struct rw_semaphore {
40}; 40};
41 41
42#define RWSEM_UNLOCKED_VALUE __IA64_UL_CONST(0x0000000000000000) 42#define RWSEM_UNLOCKED_VALUE __IA64_UL_CONST(0x0000000000000000)
43#define RWSEM_ACTIVE_BIAS __IA64_UL_CONST(0x0000000000000001) 43#define RWSEM_ACTIVE_BIAS (1L)
44#define RWSEM_ACTIVE_MASK __IA64_UL_CONST(0x00000000ffffffff) 44#define RWSEM_ACTIVE_MASK (0xffffffffL)
45#define RWSEM_WAITING_BIAS -__IA64_UL_CONST(0x0000000100000000) 45#define RWSEM_WAITING_BIAS (-0x100000000L)
46#define RWSEM_ACTIVE_READ_BIAS RWSEM_ACTIVE_BIAS 46#define RWSEM_ACTIVE_READ_BIAS RWSEM_ACTIVE_BIAS
47#define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS) 47#define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)
48 48
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index 744329072f33..cce050e85c73 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -2191,8 +2191,15 @@ pfmfs_delete_dentry(struct dentry *dentry)
2191 return 1; 2191 return 1;
2192} 2192}
2193 2193
2194static char *pfmfs_dname(struct dentry *dentry, char *buffer, int buflen)
2195{
2196 return dynamic_dname(dentry, buffer, buflen, "pfm:[%lu]",
2197 dentry->d_inode->i_ino);
2198}
2199
2194static const struct dentry_operations pfmfs_dentry_operations = { 2200static const struct dentry_operations pfmfs_dentry_operations = {
2195 .d_delete = pfmfs_delete_dentry, 2201 .d_delete = pfmfs_delete_dentry,
2202 .d_dname = pfmfs_dname,
2196}; 2203};
2197 2204
2198 2205
@@ -2202,8 +2209,7 @@ pfm_alloc_file(pfm_context_t *ctx)
2202 struct file *file; 2209 struct file *file;
2203 struct inode *inode; 2210 struct inode *inode;
2204 struct path path; 2211 struct path path;
2205 char name[32]; 2212 struct qstr this = { .name = "" };
2206 struct qstr this;
2207 2213
2208 /* 2214 /*
2209 * allocate a new inode 2215 * allocate a new inode
@@ -2218,11 +2224,6 @@ pfm_alloc_file(pfm_context_t *ctx)
2218 inode->i_uid = current_fsuid(); 2224 inode->i_uid = current_fsuid();
2219 inode->i_gid = current_fsgid(); 2225 inode->i_gid = current_fsgid();
2220 2226
2221 sprintf(name, "[%lu]", inode->i_ino);
2222 this.name = name;
2223 this.len = strlen(name);
2224 this.hash = inode->i_ino;
2225
2226 /* 2227 /*
2227 * allocate a new dcache entry 2228 * allocate a new dcache entry
2228 */ 2229 */
diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c
index 41ae6a596b50..8fb958abf8d0 100644
--- a/arch/ia64/kernel/setup.c
+++ b/arch/ia64/kernel/setup.c
@@ -98,12 +98,6 @@ static struct resource bss_resource = {
98 98
99unsigned long ia64_max_cacheline_size; 99unsigned long ia64_max_cacheline_size;
100 100
101int dma_get_cache_alignment(void)
102{
103 return ia64_max_cacheline_size;
104}
105EXPORT_SYMBOL(dma_get_cache_alignment);
106
107unsigned long ia64_iobase; /* virtual address for I/O accesses */ 101unsigned long ia64_iobase; /* virtual address for I/O accesses */
108EXPORT_SYMBOL(ia64_iobase); 102EXPORT_SYMBOL(ia64_iobase);
109struct io_space io_space[MAX_IO_SPACES]; 103struct io_space io_space[MAX_IO_SPACES];
diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
index ecafbe1718c3..0395c51e46a6 100644
--- a/arch/m68k/include/asm/cache.h
+++ b/arch/m68k/include/asm/cache.h
@@ -8,6 +8,6 @@
8#define L1_CACHE_SHIFT 4 8#define L1_CACHE_SHIFT 4
9#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT) 9#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
10 10
11#define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES 11#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
12 12
13#endif 13#endif
diff --git a/arch/m68k/include/asm/dma-mapping.h b/arch/m68k/include/asm/dma-mapping.h
index 26f505488c11..17f7a45948ea 100644
--- a/arch/m68k/include/asm/dma-mapping.h
+++ b/arch/m68k/include/asm/dma-mapping.h
@@ -16,16 +16,6 @@ static inline int dma_set_mask(struct device *dev, u64 mask)
16 return 0; 16 return 0;
17} 17}
18 18
19static inline int dma_get_cache_alignment(void)
20{
21 return 1 << L1_CACHE_SHIFT;
22}
23
24static inline int dma_is_consistent(struct device *dev, dma_addr_t dma_addr)
25{
26 return 0;
27}
28
29extern void *dma_alloc_coherent(struct device *, size_t, 19extern void *dma_alloc_coherent(struct device *, size_t,
30 dma_addr_t *, gfp_t); 20 dma_addr_t *, gfp_t);
31extern void dma_free_coherent(struct device *, size_t, 21extern void dma_free_coherent(struct device *, size_t,
diff --git a/arch/microblaze/include/asm/dma-mapping.h b/arch/microblaze/include/asm/dma-mapping.h
index 507389580709..8fbb0ec10233 100644
--- a/arch/microblaze/include/asm/dma-mapping.h
+++ b/arch/microblaze/include/asm/dma-mapping.h
@@ -106,7 +106,6 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
106 106
107#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 107#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
108#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) 108#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
109#define dma_is_consistent(d, h) (1)
110 109
111static inline void *dma_alloc_coherent(struct device *dev, size_t size, 110static inline void *dma_alloc_coherent(struct device *dev, size_t size,
112 dma_addr_t *dma_handle, gfp_t flag) 111 dma_addr_t *dma_handle, gfp_t flag)
@@ -132,11 +131,6 @@ static inline void dma_free_coherent(struct device *dev, size_t size,
132 ops->free_coherent(dev, size, cpu_addr, dma_handle); 131 ops->free_coherent(dev, size, cpu_addr, dma_handle);
133} 132}
134 133
135static inline int dma_get_cache_alignment(void)
136{
137 return L1_CACHE_BYTES;
138}
139
140static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, 134static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
141 enum dma_data_direction direction) 135 enum dma_data_direction direction)
142{ 136{
diff --git a/arch/microblaze/include/asm/page.h b/arch/microblaze/include/asm/page.h
index 4f268faa0126..cf377d91da71 100644
--- a/arch/microblaze/include/asm/page.h
+++ b/arch/microblaze/include/asm/page.h
@@ -40,7 +40,7 @@
40#ifndef __ASSEMBLY__ 40#ifndef __ASSEMBLY__
41 41
42/* MS be sure that SLAB allocates aligned objects */ 42/* MS be sure that SLAB allocates aligned objects */
43#define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES 43#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
44 44
45#define ARCH_SLAB_MINALIGN L1_CACHE_BYTES 45#define ARCH_SLAB_MINALIGN L1_CACHE_BYTES
46 46
diff --git a/arch/mips/include/asm/dma-mapping.h b/arch/mips/include/asm/dma-mapping.h
index 664ba53dc32a..18fbf7af8e93 100644
--- a/arch/mips/include/asm/dma-mapping.h
+++ b/arch/mips/include/asm/dma-mapping.h
@@ -62,15 +62,6 @@ dma_set_mask(struct device *dev, u64 mask)
62 return 0; 62 return 0;
63} 63}
64 64
65static inline int
66dma_get_cache_alignment(void)
67{
68 /* XXX Largest on any MIPS */
69 return 128;
70}
71
72extern int dma_is_consistent(struct device *dev, dma_addr_t dma_addr);
73
74extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size, 65extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
75 enum dma_data_direction direction); 66 enum dma_data_direction direction);
76 67
diff --git a/arch/mips/include/asm/mach-generic/kmalloc.h b/arch/mips/include/asm/mach-generic/kmalloc.h
index b8e6deba352f..a5d669086ed9 100644
--- a/arch/mips/include/asm/mach-generic/kmalloc.h
+++ b/arch/mips/include/asm/mach-generic/kmalloc.h
@@ -7,7 +7,7 @@
7 * Total overkill for most systems but need as a safe default. 7 * Total overkill for most systems but need as a safe default.
8 * Set this one if any device in the system might do non-coherent DMA. 8 * Set this one if any device in the system might do non-coherent DMA.
9 */ 9 */
10#define ARCH_KMALLOC_MINALIGN 128 10#define ARCH_DMA_MINALIGN 128
11#endif 11#endif
12 12
13#endif /* __ASM_MACH_GENERIC_KMALLOC_H */ 13#endif /* __ASM_MACH_GENERIC_KMALLOC_H */
diff --git a/arch/mips/include/asm/mach-ip27/kmalloc.h b/arch/mips/include/asm/mach-ip27/kmalloc.h
index 426bd049b2d7..82c23ce2afa7 100644
--- a/arch/mips/include/asm/mach-ip27/kmalloc.h
+++ b/arch/mips/include/asm/mach-ip27/kmalloc.h
@@ -2,7 +2,7 @@
2#define __ASM_MACH_IP27_KMALLOC_H 2#define __ASM_MACH_IP27_KMALLOC_H
3 3
4/* 4/*
5 * All happy, no need to define ARCH_KMALLOC_MINALIGN 5 * All happy, no need to define ARCH_DMA_MINALIGN
6 */ 6 */
7 7
8#endif /* __ASM_MACH_IP27_KMALLOC_H */ 8#endif /* __ASM_MACH_IP27_KMALLOC_H */
diff --git a/arch/mips/include/asm/mach-ip32/kmalloc.h b/arch/mips/include/asm/mach-ip32/kmalloc.h
index b1e0be60f720..042ca926c48f 100644
--- a/arch/mips/include/asm/mach-ip32/kmalloc.h
+++ b/arch/mips/include/asm/mach-ip32/kmalloc.h
@@ -3,9 +3,9 @@
3 3
4 4
5#if defined(CONFIG_CPU_R5000) || defined(CONFIG_CPU_RM7000) 5#if defined(CONFIG_CPU_R5000) || defined(CONFIG_CPU_RM7000)
6#define ARCH_KMALLOC_MINALIGN 32 6#define ARCH_DMA_MINALIGN 32
7#else 7#else
8#define ARCH_KMALLOC_MINALIGN 128 8#define ARCH_DMA_MINALIGN 128
9#endif 9#endif
10 10
11#endif /* __ASM_MACH_IP32_KMALLOC_H */ 11#endif /* __ASM_MACH_IP32_KMALLOC_H */
diff --git a/arch/mips/mm/dma-default.c b/arch/mips/mm/dma-default.c
index 9547bc0cf188..7ba890860d98 100644
--- a/arch/mips/mm/dma-default.c
+++ b/arch/mips/mm/dma-default.c
@@ -357,13 +357,6 @@ int dma_supported(struct device *dev, u64 mask)
357 357
358EXPORT_SYMBOL(dma_supported); 358EXPORT_SYMBOL(dma_supported);
359 359
360int dma_is_consistent(struct device *dev, dma_addr_t dma_addr)
361{
362 return plat_device_is_coherent(dev);
363}
364
365EXPORT_SYMBOL(dma_is_consistent);
366
367void dma_cache_sync(struct device *dev, void *vaddr, size_t size, 360void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
368 enum dma_data_direction direction) 361 enum dma_data_direction direction)
369{ 362{
diff --git a/arch/mn10300/boot/compressed/misc.c b/arch/mn10300/boot/compressed/misc.c
index f673383518e4..42cbd77bd439 100644
--- a/arch/mn10300/boot/compressed/misc.c
+++ b/arch/mn10300/boot/compressed/misc.c
@@ -167,6 +167,7 @@ static uch *high_buffer_start /* = (uch *)(((ulg)&end) + HEAP_SIZE)*/;
167static char *vidmem = (char *)0xb8000; 167static char *vidmem = (char *)0xb8000;
168static int lines, cols; 168static int lines, cols;
169 169
170#define BOOTLOADER_INFLATE
170#include "../../../../lib/inflate.c" 171#include "../../../../lib/inflate.c"
171 172
172static inline void scroll(void) 173static inline void scroll(void)
diff --git a/arch/mn10300/include/asm/cache.h b/arch/mn10300/include/asm/cache.h
index 6e2fe28dde4e..781bf613366d 100644
--- a/arch/mn10300/include/asm/cache.h
+++ b/arch/mn10300/include/asm/cache.h
@@ -21,7 +21,7 @@
21#define L1_CACHE_DISPARITY L1_CACHE_NENTRIES * L1_CACHE_BYTES 21#define L1_CACHE_DISPARITY L1_CACHE_NENTRIES * L1_CACHE_BYTES
22#endif 22#endif
23 23
24#define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES 24#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
25 25
26/* data cache purge registers 26/* data cache purge registers
27 * - read from the register to unconditionally purge that cache line 27 * - read from the register to unconditionally purge that cache line
diff --git a/arch/mn10300/include/asm/dma-mapping.h b/arch/mn10300/include/asm/dma-mapping.h
index 4ed1522b38d2..c1be4397b1ed 100644
--- a/arch/mn10300/include/asm/dma-mapping.h
+++ b/arch/mn10300/include/asm/dma-mapping.h
@@ -162,14 +162,6 @@ int dma_set_mask(struct device *dev, u64 mask)
162} 162}
163 163
164static inline 164static inline
165int dma_get_cache_alignment(void)
166{
167 return 1 << L1_CACHE_SHIFT;
168}
169
170#define dma_is_consistent(d) (1)
171
172static inline
173void dma_cache_sync(void *vaddr, size_t size, 165void dma_cache_sync(void *vaddr, size_t size,
174 enum dma_data_direction direction) 166 enum dma_data_direction direction)
175{ 167{
diff --git a/arch/mn10300/include/asm/gdb-stub.h b/arch/mn10300/include/asm/gdb-stub.h
index 556cce992548..41ed26763964 100644
--- a/arch/mn10300/include/asm/gdb-stub.h
+++ b/arch/mn10300/include/asm/gdb-stub.h
@@ -157,25 +157,25 @@ void gdbstub_printk(const char *fmt, ...)
157#ifdef CONFIG_GDBSTUB_DEBUG_ENTRY 157#ifdef CONFIG_GDBSTUB_DEBUG_ENTRY
158#define gdbstub_entry(FMT, ...) gdbstub_printk(FMT, ##__VA_ARGS__) 158#define gdbstub_entry(FMT, ...) gdbstub_printk(FMT, ##__VA_ARGS__)
159#else 159#else
160#define gdbstub_entry(FMT, ...) ({ 0; }) 160#define gdbstub_entry(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
161#endif 161#endif
162 162
163#ifdef CONFIG_GDBSTUB_DEBUG_PROTOCOL 163#ifdef CONFIG_GDBSTUB_DEBUG_PROTOCOL
164#define gdbstub_proto(FMT, ...) gdbstub_printk(FMT, ##__VA_ARGS__) 164#define gdbstub_proto(FMT, ...) gdbstub_printk(FMT, ##__VA_ARGS__)
165#else 165#else
166#define gdbstub_proto(FMT, ...) ({ 0; }) 166#define gdbstub_proto(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
167#endif 167#endif
168 168
169#ifdef CONFIG_GDBSTUB_DEBUG_IO 169#ifdef CONFIG_GDBSTUB_DEBUG_IO
170#define gdbstub_io(FMT, ...) gdbstub_printk(FMT, ##__VA_ARGS__) 170#define gdbstub_io(FMT, ...) gdbstub_printk(FMT, ##__VA_ARGS__)
171#else 171#else
172#define gdbstub_io(FMT, ...) ({ 0; }) 172#define gdbstub_io(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
173#endif 173#endif
174 174
175#ifdef CONFIG_GDBSTUB_DEBUG_BREAKPOINT 175#ifdef CONFIG_GDBSTUB_DEBUG_BREAKPOINT
176#define gdbstub_bkpt(FMT, ...) gdbstub_printk(FMT, ##__VA_ARGS__) 176#define gdbstub_bkpt(FMT, ...) gdbstub_printk(FMT, ##__VA_ARGS__)
177#else 177#else
178#define gdbstub_bkpt(FMT, ...) ({ 0; }) 178#define gdbstub_bkpt(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
179#endif 179#endif
180 180
181#endif /* !__ASSEMBLY__ */ 181#endif /* !__ASSEMBLY__ */
diff --git a/arch/mn10300/include/asm/posix_types.h b/arch/mn10300/include/asm/posix_types.h
index 077567c37798..56ffbc158798 100644
--- a/arch/mn10300/include/asm/posix_types.h
+++ b/arch/mn10300/include/asm/posix_types.h
@@ -25,8 +25,13 @@ typedef int __kernel_pid_t;
25typedef unsigned short __kernel_ipc_pid_t; 25typedef unsigned short __kernel_ipc_pid_t;
26typedef unsigned short __kernel_uid_t; 26typedef unsigned short __kernel_uid_t;
27typedef unsigned short __kernel_gid_t; 27typedef unsigned short __kernel_gid_t;
28#if __GNUC__ == 4
29typedef unsigned int __kernel_size_t;
30typedef signed int __kernel_ssize_t;
31#else
28typedef unsigned long __kernel_size_t; 32typedef unsigned long __kernel_size_t;
29typedef long __kernel_ssize_t; 33typedef signed long __kernel_ssize_t;
34#endif
30typedef int __kernel_ptrdiff_t; 35typedef int __kernel_ptrdiff_t;
31typedef long __kernel_time_t; 36typedef long __kernel_time_t;
32typedef long __kernel_suseconds_t; 37typedef long __kernel_suseconds_t;
diff --git a/arch/mn10300/kernel/mn10300-serial.c b/arch/mn10300/kernel/mn10300-serial.c
index ef34d5a0f8bd..9d49073e827a 100644
--- a/arch/mn10300/kernel/mn10300-serial.c
+++ b/arch/mn10300/kernel/mn10300-serial.c
@@ -44,11 +44,6 @@ static const char serial_revdate[] = "2007-11-06";
44#include <unit/timex.h> 44#include <unit/timex.h>
45#include "mn10300-serial.h" 45#include "mn10300-serial.h"
46 46
47static inline __attribute__((format(printf, 1, 2)))
48void no_printk(const char *fmt, ...)
49{
50}
51
52#define kenter(FMT, ...) \ 47#define kenter(FMT, ...) \
53 printk(KERN_DEBUG "-->%s(" FMT ")\n", __func__, ##__VA_ARGS__) 48 printk(KERN_DEBUG "-->%s(" FMT ")\n", __func__, ##__VA_ARGS__)
54#define _enter(FMT, ...) \ 49#define _enter(FMT, ...) \
diff --git a/arch/mn10300/kernel/rtc.c b/arch/mn10300/kernel/rtc.c
index 815a933aafa8..4eef0e7224f6 100644
--- a/arch/mn10300/kernel/rtc.c
+++ b/arch/mn10300/kernel/rtc.c
@@ -20,9 +20,6 @@
20DEFINE_SPINLOCK(rtc_lock); 20DEFINE_SPINLOCK(rtc_lock);
21EXPORT_SYMBOL(rtc_lock); 21EXPORT_SYMBOL(rtc_lock);
22 22
23/* last time the RTC got updated */
24static long last_rtc_update;
25
26/* time for RTC to update itself in ioclks */ 23/* time for RTC to update itself in ioclks */
27static unsigned long mn10300_rtc_update_period; 24static unsigned long mn10300_rtc_update_period;
28 25
@@ -110,7 +107,7 @@ static int set_rtc_mmss(unsigned long nowtime)
110 107
111int update_persistent_clock(struct timespec now) 108int update_persistent_clock(struct timespec now)
112{ 109{
113 return set_rtc_mms(now.tv_sec); 110 return set_rtc_mmss(now.tv_sec);
114} 111}
115 112
116/* 113/*
diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
index 45effe6978fa..039880e7d2c9 100644
--- a/arch/parisc/include/asm/cache.h
+++ b/arch/parisc/include/asm/cache.h
@@ -28,6 +28,8 @@
28 28
29#define SMP_CACHE_BYTES L1_CACHE_BYTES 29#define SMP_CACHE_BYTES L1_CACHE_BYTES
30 30
31#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
32
31#define __read_mostly __attribute__((__section__(".data..read_mostly"))) 33#define __read_mostly __attribute__((__section__(".data..read_mostly")))
32 34
33void parisc_cache_init(void); /* initializes cache-flushing */ 35void parisc_cache_init(void); /* initializes cache-flushing */
diff --git a/arch/parisc/include/asm/dma-mapping.h b/arch/parisc/include/asm/dma-mapping.h
index da6943380908..4ef73b09b168 100644
--- a/arch/parisc/include/asm/dma-mapping.h
+++ b/arch/parisc/include/asm/dma-mapping.h
@@ -184,18 +184,6 @@ dma_set_mask(struct device *dev, u64 mask)
184 return 0; 184 return 0;
185} 185}
186 186
187static inline int
188dma_get_cache_alignment(void)
189{
190 return dcache_stride;
191}
192
193static inline int
194dma_is_consistent(struct device *dev, dma_addr_t dma_addr)
195{
196 return (hppa_dma_ops->dma_sync_single_for_cpu == NULL);
197}
198
199static inline void 187static inline void
200dma_cache_sync(struct device *dev, void *vaddr, size_t size, 188dma_cache_sync(struct device *dev, void *vaddr, size_t size,
201 enum dma_data_direction direction) 189 enum dma_data_direction direction)
diff --git a/arch/parisc/mm/ioremap.c b/arch/parisc/mm/ioremap.c
index 92d496ad07c9..838d0259cd27 100644
--- a/arch/parisc/mm/ioremap.c
+++ b/arch/parisc/mm/ioremap.c
@@ -71,7 +71,7 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l
71 */ 71 */
72 offset = phys_addr & ~PAGE_MASK; 72 offset = phys_addr & ~PAGE_MASK;
73 phys_addr &= PAGE_MASK; 73 phys_addr &= PAGE_MASK;
74 size = PAGE_ALIGN(last_addr) - phys_addr; 74 size = PAGE_ALIGN(last_addr + 1) - phys_addr;
75 75
76 /* 76 /*
77 * Ok, go for it.. 77 * Ok, go for it..
diff --git a/arch/powerpc/boot/dts/p4080ds.dts b/arch/powerpc/boot/dts/p4080ds.dts
index 6b29eab05362..2f0de24e3822 100644
--- a/arch/powerpc/boot/dts/p4080ds.dts
+++ b/arch/powerpc/boot/dts/p4080ds.dts
@@ -280,6 +280,8 @@
280 reg = <0x114000 0x1000>; 280 reg = <0x114000 0x1000>;
281 interrupts = <48 2>; 281 interrupts = <48 2>;
282 interrupt-parent = <&mpic>; 282 interrupt-parent = <&mpic>;
283 voltage-ranges = <3300 3300>;
284 sdhci,auto-cmd12;
283 }; 285 };
284 286
285 i2c@118000 { 287 i2c@118000 {
diff --git a/arch/powerpc/include/asm/dma-mapping.h b/arch/powerpc/include/asm/dma-mapping.h
index c85ef230135b..8c9c6ad2004e 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -209,26 +209,6 @@ static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
209 209
210#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 210#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
211#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) 211#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
212#ifdef CONFIG_NOT_COHERENT_CACHE
213#define dma_is_consistent(d, h) (0)
214#else
215#define dma_is_consistent(d, h) (1)
216#endif
217
218static inline int dma_get_cache_alignment(void)
219{
220#ifdef CONFIG_PPC64
221 /* no easy way to get cache size on all processors, so return
222 * the maximum possible, to be safe */
223 return (1 << INTERNODE_CACHE_SHIFT);
224#else
225 /*
226 * Each processor family will define its own L1_CACHE_SHIFT,
227 * L1_CACHE_BYTES wraps to this, so this is always safe.
228 */
229 return L1_CACHE_BYTES;
230#endif
231}
232 212
233static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, 213static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
234 enum dma_data_direction direction) 214 enum dma_data_direction direction)
diff --git a/arch/powerpc/include/asm/page_32.h b/arch/powerpc/include/asm/page_32.h
index bd0849dbcaaa..68d73b2a7bfc 100644
--- a/arch/powerpc/include/asm/page_32.h
+++ b/arch/powerpc/include/asm/page_32.h
@@ -10,7 +10,7 @@
10#define VM_DATA_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS32 10#define VM_DATA_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS32
11 11
12#ifdef CONFIG_NOT_COHERENT_CACHE 12#ifdef CONFIG_NOT_COHERENT_CACHE
13#define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES 13#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
14#endif 14#endif
15 15
16#ifdef CONFIG_PTE_64BIT 16#ifdef CONFIG_PTE_64BIT
diff --git a/arch/powerpc/platforms/83xx/mpc837x_mds.c b/arch/powerpc/platforms/83xx/mpc837x_mds.c
index 51df7e754698..f9751c8905be 100644
--- a/arch/powerpc/platforms/83xx/mpc837x_mds.c
+++ b/arch/powerpc/platforms/83xx/mpc837x_mds.c
@@ -102,7 +102,7 @@ static struct of_device_id mpc837x_ids[] = {
102 102
103static int __init mpc837x_declare_of_platform_devices(void) 103static int __init mpc837x_declare_of_platform_devices(void)
104{ 104{
105 /* Publish of_device */ 105 /* Publish platform_device */
106 of_platform_bus_probe(NULL, mpc837x_ids, NULL); 106 of_platform_bus_probe(NULL, mpc837x_ids, NULL);
107 107
108 return 0; 108 return 0;
diff --git a/arch/powerpc/platforms/83xx/mpc837x_rdb.c b/arch/powerpc/platforms/83xx/mpc837x_rdb.c
index e00801c42540..910caa6b5810 100644
--- a/arch/powerpc/platforms/83xx/mpc837x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc837x_rdb.c
@@ -78,7 +78,7 @@ static struct of_device_id mpc837x_ids[] = {
78 78
79static int __init mpc837x_declare_of_platform_devices(void) 79static int __init mpc837x_declare_of_platform_devices(void)
80{ 80{
81 /* Publish of_device */ 81 /* Publish platform_device */
82 of_platform_bus_probe(NULL, mpc837x_ids, NULL); 82 of_platform_bus_probe(NULL, mpc837x_ids, NULL);
83 83
84 return 0; 84 return 0;
diff --git a/arch/powerpc/sysdev/fsl_rio.c b/arch/powerpc/sysdev/fsl_rio.c
index 8bd86530ee25..6425abe5b7db 100644
--- a/arch/powerpc/sysdev/fsl_rio.c
+++ b/arch/powerpc/sysdev/fsl_rio.c
@@ -1332,7 +1332,7 @@ static inline void fsl_rio_info(struct device *dev, u32 ccsr)
1332 1332
1333/** 1333/**
1334 * fsl_rio_setup - Setup Freescale PowerPC RapidIO interface 1334 * fsl_rio_setup - Setup Freescale PowerPC RapidIO interface
1335 * @dev: of_device pointer 1335 * @dev: platform_device pointer
1336 * 1336 *
1337 * Initializes MPC85xx RapidIO hardware interface, configures 1337 * Initializes MPC85xx RapidIO hardware interface, configures
1338 * master port with system-specific info, and registers the 1338 * master port with system-specific info, and registers the
diff --git a/arch/s390/appldata/appldata_net_sum.c b/arch/s390/appldata/appldata_net_sum.c
index f02e89ce4df1..5da7c562a90b 100644
--- a/arch/s390/appldata/appldata_net_sum.c
+++ b/arch/s390/appldata/appldata_net_sum.c
@@ -85,9 +85,10 @@ static void appldata_get_net_sum_data(void *data)
85 85
86 rcu_read_lock(); 86 rcu_read_lock();
87 for_each_netdev_rcu(&init_net, dev) { 87 for_each_netdev_rcu(&init_net, dev) {
88 const struct rtnl_link_stats64 *stats;
88 struct rtnl_link_stats64 temp; 89 struct rtnl_link_stats64 temp;
89 const struct net_device_stats *stats = dev_get_stats(dev, &temp);
90 90
91 stats = dev_get_stats(dev, &temp);
91 rx_packets += stats->rx_packets; 92 rx_packets += stats->rx_packets;
92 tx_packets += stats->tx_packets; 93 tx_packets += stats->tx_packets;
93 rx_bytes += stats->rx_bytes; 94 rx_bytes += stats->rx_bytes;
diff --git a/arch/s390/include/asm/unistd.h b/arch/s390/include/asm/unistd.h
index 5f0075150a65..1049ef27c15e 100644
--- a/arch/s390/include/asm/unistd.h
+++ b/arch/s390/include/asm/unistd.h
@@ -269,7 +269,10 @@
269#define __NR_pwritev 329 269#define __NR_pwritev 329
270#define __NR_rt_tgsigqueueinfo 330 270#define __NR_rt_tgsigqueueinfo 330
271#define __NR_perf_event_open 331 271#define __NR_perf_event_open 331
272#define NR_syscalls 332 272#define __NR_fanotify_init 332
273#define __NR_fanotify_mark 333
274#define __NR_prlimit64 334
275#define NR_syscalls 335
273 276
274/* 277/*
275 * There are some system calls that are not present on 64 bit, some 278 * There are some system calls that are not present on 64 bit, some
diff --git a/arch/s390/kernel/compat_wrapper.S b/arch/s390/kernel/compat_wrapper.S
index 672ce52341b4..8e60fb23b90d 100644
--- a/arch/s390/kernel/compat_wrapper.S
+++ b/arch/s390/kernel/compat_wrapper.S
@@ -614,7 +614,7 @@ sys32_sysfs_wrapper:
614 614
615 .globl sys32_personality_wrapper 615 .globl sys32_personality_wrapper
616sys32_personality_wrapper: 616sys32_personality_wrapper:
617 llgfr %r2,%r2 # unsigned long 617 llgfr %r2,%r2 # unsigned int
618 jg sys_s390_personality # branch to system call 618 jg sys_s390_personality # branch to system call
619 619
620 .globl sys32_setfsuid16_wrapper 620 .globl sys32_setfsuid16_wrapper
@@ -1853,3 +1853,27 @@ sys32_execve_wrapper:
1853 llgtr %r3,%r3 # compat_uptr_t * 1853 llgtr %r3,%r3 # compat_uptr_t *
1854 llgtr %r4,%r4 # compat_uptr_t * 1854 llgtr %r4,%r4 # compat_uptr_t *
1855 jg sys32_execve # branch to system call 1855 jg sys32_execve # branch to system call
1856
1857 .globl sys_fanotify_init_wrapper
1858sys_fanotify_init_wrapper:
1859 llgfr %r2,%r2 # unsigned int
1860 llgfr %r3,%r3 # unsigned int
1861 jg sys_fanotify_init # branch to system call
1862
1863 .globl sys_fanotify_mark_wrapper
1864sys_fanotify_mark_wrapper:
1865 lgfr %r2,%r2 # int
1866 llgfr %r3,%r3 # unsigned int
1867 sllg %r4,%r4,32 # get high word of 64bit mask
1868 lr %r4,%r5 # get low word of 64bit mask
1869 llgfr %r5,%r6 # unsigned int
1870 llgt %r6,164(%r15) # char *
1871 jg sys_fanotify_mark # branch to system call
1872
1873 .globl sys_prlimit64_wrapper
1874sys_prlimit64_wrapper:
1875 lgfr %r2,%r2 # pid_t
1876 llgfr %r3,%r3 # unsigned int
1877 llgtr %r4,%r4 # const struct rlimit64 __user *
1878 llgtr %r5,%r5 # struct rlimit64 __user *
1879 jg sys_prlimit64 # branch to system call
diff --git a/arch/s390/kernel/entry.h b/arch/s390/kernel/entry.h
index eb15c12ec158..5bb1e6b5db26 100644
--- a/arch/s390/kernel/entry.h
+++ b/arch/s390/kernel/entry.h
@@ -31,7 +31,7 @@ struct old_sigaction;
31long sys_mmap2(struct s390_mmap_arg_struct __user *arg); 31long sys_mmap2(struct s390_mmap_arg_struct __user *arg);
32long sys_s390_ipc(uint call, int first, unsigned long second, 32long sys_s390_ipc(uint call, int first, unsigned long second,
33 unsigned long third, void __user *ptr); 33 unsigned long third, void __user *ptr);
34long sys_s390_personality(unsigned long personality); 34long sys_s390_personality(unsigned int personality);
35long sys_s390_fadvise64(int fd, u32 offset_high, u32 offset_low, 35long sys_s390_fadvise64(int fd, u32 offset_high, u32 offset_low,
36 size_t len, int advice); 36 size_t len, int advice);
37long sys_s390_fadvise64_64(struct fadvise64_64_args __user *args); 37long sys_s390_fadvise64_64(struct fadvise64_64_args __user *args);
diff --git a/arch/s390/kernel/sys_s390.c b/arch/s390/kernel/sys_s390.c
index 7b6b0f81a283..476081440df9 100644
--- a/arch/s390/kernel/sys_s390.c
+++ b/arch/s390/kernel/sys_s390.c
@@ -131,9 +131,9 @@ SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second,
131} 131}
132 132
133#ifdef CONFIG_64BIT 133#ifdef CONFIG_64BIT
134SYSCALL_DEFINE1(s390_personality, unsigned long, personality) 134SYSCALL_DEFINE1(s390_personality, unsigned int, personality)
135{ 135{
136 int ret; 136 unsigned int ret;
137 137
138 if (current->personality == PER_LINUX32 && personality == PER_LINUX) 138 if (current->personality == PER_LINUX32 && personality == PER_LINUX)
139 personality = PER_LINUX32; 139 personality = PER_LINUX32;
diff --git a/arch/s390/kernel/syscalls.S b/arch/s390/kernel/syscalls.S
index 201ce6bed34e..a8fee1b14395 100644
--- a/arch/s390/kernel/syscalls.S
+++ b/arch/s390/kernel/syscalls.S
@@ -340,3 +340,6 @@ SYSCALL(sys_preadv,sys_preadv,compat_sys_preadv_wrapper)
340SYSCALL(sys_pwritev,sys_pwritev,compat_sys_pwritev_wrapper) 340SYSCALL(sys_pwritev,sys_pwritev,compat_sys_pwritev_wrapper)
341SYSCALL(sys_rt_tgsigqueueinfo,sys_rt_tgsigqueueinfo,compat_sys_rt_tgsigqueueinfo_wrapper) /* 330 */ 341SYSCALL(sys_rt_tgsigqueueinfo,sys_rt_tgsigqueueinfo,compat_sys_rt_tgsigqueueinfo_wrapper) /* 330 */
342SYSCALL(sys_perf_event_open,sys_perf_event_open,sys_perf_event_open_wrapper) 342SYSCALL(sys_perf_event_open,sys_perf_event_open,sys_perf_event_open_wrapper)
343SYSCALL(sys_fanotify_init,sys_fanotify_init,sys_fanotify_init_wrapper)
344SYSCALL(sys_fanotify_mark,sys_fanotify_mark,sys_fanotify_mark_wrapper)
345SYSCALL(sys_prlimit64,sys_prlimit64,sys_prlimit64_wrapper)
diff --git a/arch/score/mm/tlb-score.c b/arch/score/mm/tlb-score.c
index 4fa5aa5afecc..6fdb100244c8 100644
--- a/arch/score/mm/tlb-score.c
+++ b/arch/score/mm/tlb-score.c
@@ -158,7 +158,7 @@ void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
158 158
159void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page) 159void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
160{ 160{
161 if (!vma || vma->vm_mm->context != 0) { 161 if (vma && vma->vm_mm->context != 0) {
162 unsigned long flags; 162 unsigned long flags;
163 int oldpid, newpid, idx; 163 int oldpid, newpid, idx;
164 unsigned long vma_ASID = vma->vm_mm->context; 164 unsigned long vma_ASID = vma->vm_mm->context;
diff --git a/arch/sh/boards/mach-ap325rxa/setup.c b/arch/sh/boards/mach-ap325rxa/setup.c
index de375b64e410..3da116f47f01 100644
--- a/arch/sh/boards/mach-ap325rxa/setup.c
+++ b/arch/sh/boards/mach-ap325rxa/setup.c
@@ -154,7 +154,7 @@ static struct platform_device nand_flash_device = {
154#define PORT_DRVCRA 0xA405018A 154#define PORT_DRVCRA 0xA405018A
155#define PORT_DRVCRB 0xA405018C 155#define PORT_DRVCRB 0xA405018C
156 156
157static void ap320_wvga_power_on(void *board_data) 157static void ap320_wvga_power_on(void *board_data, struct fb_info *info)
158{ 158{
159 msleep(100); 159 msleep(100);
160 160
diff --git a/arch/sh/boards/mach-kfr2r09/Makefile b/arch/sh/boards/mach-kfr2r09/Makefile
index 4e577a3bf658..60dd63f4a427 100644
--- a/arch/sh/boards/mach-kfr2r09/Makefile
+++ b/arch/sh/boards/mach-kfr2r09/Makefile
@@ -1,2 +1,4 @@
1obj-y := setup.o sdram.o 1obj-y := setup.o sdram.o
2obj-$(CONFIG_FB_SH_MOBILE_LCDC) += lcd_wqvga.o 2ifneq ($(CONFIG_FB_SH_MOBILE_LCDC),)
3obj-y += lcd_wqvga.o
4endif
diff --git a/arch/sh/boards/mach-kfr2r09/lcd_wqvga.c b/arch/sh/boards/mach-kfr2r09/lcd_wqvga.c
index e9b970846c41..25e145fb7087 100644
--- a/arch/sh/boards/mach-kfr2r09/lcd_wqvga.c
+++ b/arch/sh/boards/mach-kfr2r09/lcd_wqvga.c
@@ -327,7 +327,7 @@ static int kfr2r09_lcd_backlight(int on)
327 return 0; 327 return 0;
328} 328}
329 329
330void kfr2r09_lcd_on(void *board_data) 330void kfr2r09_lcd_on(void *board_data, struct fb_info *info)
331{ 331{
332 kfr2r09_lcd_backlight(1); 332 kfr2r09_lcd_backlight(1);
333} 333}
diff --git a/arch/sh/include/asm/dma-mapping.h b/arch/sh/include/asm/dma-mapping.h
index bea3337a426a..1a73c3e759a7 100644
--- a/arch/sh/include/asm/dma-mapping.h
+++ b/arch/sh/include/asm/dma-mapping.h
@@ -42,21 +42,6 @@ void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
42#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 42#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
43#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) 43#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
44 44
45#ifdef CONFIG_DMA_COHERENT
46#define dma_is_consistent(d, h) (1)
47#else
48#define dma_is_consistent(d, h) (0)
49#endif
50
51static inline int dma_get_cache_alignment(void)
52{
53 /*
54 * Each processor family will define its own L1_CACHE_SHIFT,
55 * L1_CACHE_BYTES wraps to this, so this is always safe.
56 */
57 return L1_CACHE_BYTES;
58}
59
60static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) 45static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
61{ 46{
62 struct dma_map_ops *ops = get_dma_ops(dev); 47 struct dma_map_ops *ops = get_dma_ops(dev);
diff --git a/arch/sh/include/asm/page.h b/arch/sh/include/asm/page.h
index fb703d120d09..c4e0b3d472b9 100644
--- a/arch/sh/include/asm/page.h
+++ b/arch/sh/include/asm/page.h
@@ -180,7 +180,7 @@ typedef struct page *pgtable_t;
180 * Some drivers need to perform DMA into kmalloc'ed buffers 180 * Some drivers need to perform DMA into kmalloc'ed buffers
181 * and so we have to increase the kmalloc minalign for this. 181 * and so we have to increase the kmalloc minalign for this.
182 */ 182 */
183#define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES 183#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
184 184
185#ifdef CONFIG_SUPERH64 185#ifdef CONFIG_SUPERH64
186/* 186/*
diff --git a/arch/sh/include/mach-kfr2r09/mach/kfr2r09.h b/arch/sh/include/mach-kfr2r09/mach/kfr2r09.h
index 484ef42c2fb5..07e635b0e04c 100644
--- a/arch/sh/include/mach-kfr2r09/mach/kfr2r09.h
+++ b/arch/sh/include/mach-kfr2r09/mach/kfr2r09.h
@@ -3,23 +3,23 @@
3 3
4#include <video/sh_mobile_lcdc.h> 4#include <video/sh_mobile_lcdc.h>
5 5
6#ifdef CONFIG_FB_SH_MOBILE_LCDC 6#if defined(CONFIG_FB_SH_MOBILE_LCDC) || defined(CONFIG_FB_SH_MOBILE_LCDC_MODULE)
7void kfr2r09_lcd_on(void *board_data); 7void kfr2r09_lcd_on(void *board_data, struct fb_info *info);
8void kfr2r09_lcd_off(void *board_data); 8void kfr2r09_lcd_off(void *board_data);
9int kfr2r09_lcd_setup(void *board_data, void *sys_ops_handle, 9int kfr2r09_lcd_setup(void *board_data, void *sys_ops_handle,
10 struct sh_mobile_lcdc_sys_bus_ops *sys_ops); 10 struct sh_mobile_lcdc_sys_bus_ops *sys_ops);
11void kfr2r09_lcd_start(void *board_data, void *sys_ops_handle, 11void kfr2r09_lcd_start(void *board_data, void *sys_ops_handle,
12 struct sh_mobile_lcdc_sys_bus_ops *sys_ops); 12 struct sh_mobile_lcdc_sys_bus_ops *sys_ops);
13#else 13#else
14static inline void kfr2r09_lcd_on(void *board_data) {} 14static void kfr2r09_lcd_on(void *board_data) {}
15static inline void kfr2r09_lcd_off(void *board_data) {} 15static void kfr2r09_lcd_off(void *board_data) {}
16static inline int kfr2r09_lcd_setup(void *board_data, void *sys_ops_handle, 16static int kfr2r09_lcd_setup(void *board_data, void *sys_ops_handle,
17 struct sh_mobile_lcdc_sys_bus_ops *sys_ops) 17 struct sh_mobile_lcdc_sys_bus_ops *sys_ops)
18{ 18{
19 return -ENODEV; 19 return -ENODEV;
20} 20}
21static inline void kfr2r09_lcd_start(void *board_data, void *sys_ops_handle, 21static void kfr2r09_lcd_start(void *board_data, void *sys_ops_handle,
22 struct sh_mobile_lcdc_sys_bus_ops *sys_ops) 22 struct sh_mobile_lcdc_sys_bus_ops *sys_ops)
23{ 23{
24} 24}
25#endif 25#endif
diff --git a/arch/sparc/include/asm/dma-mapping.h b/arch/sparc/include/asm/dma-mapping.h
index 4b4a0c0b0ccd..8c0e4f7bb204 100644
--- a/arch/sparc/include/asm/dma-mapping.h
+++ b/arch/sparc/include/asm/dma-mapping.h
@@ -11,7 +11,6 @@ extern int dma_supported(struct device *dev, u64 mask);
11 11
12#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 12#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
13#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) 13#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
14#define dma_is_consistent(d, h) (1)
15 14
16extern struct dma_map_ops *dma_ops, pci32_dma_ops; 15extern struct dma_map_ops *dma_ops, pci32_dma_ops;
17extern struct bus_type pci_bus_type; 16extern struct bus_type pci_bus_type;
@@ -52,15 +51,6 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
52 return (dma_addr == DMA_ERROR_CODE); 51 return (dma_addr == DMA_ERROR_CODE);
53} 52}
54 53
55static inline int dma_get_cache_alignment(void)
56{
57 /*
58 * no easy way to get cache size on all processors, so return
59 * the maximum possible, to be safe
60 */
61 return (1 << INTERNODE_CACHE_SHIFT);
62}
63
64static inline int dma_set_mask(struct device *dev, u64 mask) 54static inline int dma_set_mask(struct device *dev, u64 mask)
65{ 55{
66#ifdef CONFIG_PCI 56#ifdef CONFIG_PCI
diff --git a/arch/tile/include/asm/dma-mapping.h b/arch/tile/include/asm/dma-mapping.h
index cf466b39aa13..15e1dceecc64 100644
--- a/arch/tile/include/asm/dma-mapping.h
+++ b/arch/tile/include/asm/dma-mapping.h
@@ -90,13 +90,4 @@ dma_set_mask(struct device *dev, u64 mask)
90 return 0; 90 return 0;
91} 91}
92 92
93static inline int
94dma_get_cache_alignment(void)
95{
96 return L2_CACHE_BYTES;
97}
98
99#define dma_is_consistent(d, h) (1)
100
101
102#endif /* _ASM_TILE_DMA_MAPPING_H */ 93#endif /* _ASM_TILE_DMA_MAPPING_H */
diff --git a/arch/um/drivers/hostaudio_kern.c b/arch/um/drivers/hostaudio_kern.c
index 68142df76608..0c46e398cd8f 100644
--- a/arch/um/drivers/hostaudio_kern.c
+++ b/arch/um/drivers/hostaudio_kern.c
@@ -187,7 +187,9 @@ static int hostaudio_open(struct inode *inode, struct file *file)
187 int ret; 187 int ret;
188 188
189#ifdef DEBUG 189#ifdef DEBUG
190 kparam_block_sysfs_write(dsp);
190 printk(KERN_DEBUG "hostaudio: open called (host: %s)\n", dsp); 191 printk(KERN_DEBUG "hostaudio: open called (host: %s)\n", dsp);
192 kparam_unblock_sysfs_write(dsp);
191#endif 193#endif
192 194
193 state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL); 195 state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL);
@@ -199,9 +201,11 @@ static int hostaudio_open(struct inode *inode, struct file *file)
199 if (file->f_mode & FMODE_WRITE) 201 if (file->f_mode & FMODE_WRITE)
200 w = 1; 202 w = 1;
201 203
204 kparam_block_sysfs_write(dsp);
202 lock_kernel(); 205 lock_kernel();
203 ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0); 206 ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0);
204 unlock_kernel(); 207 unlock_kernel();
208 kparam_unblock_sysfs_write(dsp);
205 209
206 if (ret < 0) { 210 if (ret < 0) {
207 kfree(state); 211 kfree(state);
@@ -258,13 +262,17 @@ static int hostmixer_open_mixdev(struct inode *inode, struct file *file)
258 if (file->f_mode & FMODE_WRITE) 262 if (file->f_mode & FMODE_WRITE)
259 w = 1; 263 w = 1;
260 264
265 kparam_block_sysfs_write(mixer);
261 lock_kernel(); 266 lock_kernel();
262 ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0); 267 ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0);
263 unlock_kernel(); 268 unlock_kernel();
269 kparam_unblock_sysfs_write(mixer);
264 270
265 if (ret < 0) { 271 if (ret < 0) {
272 kparam_block_sysfs_write(dsp);
266 printk(KERN_ERR "hostaudio_open_mixdev failed to open '%s', " 273 printk(KERN_ERR "hostaudio_open_mixdev failed to open '%s', "
267 "err = %d\n", dsp, -ret); 274 "err = %d\n", dsp, -ret);
275 kparam_unblock_sysfs_write(dsp);
268 kfree(state); 276 kfree(state);
269 return ret; 277 return ret;
270 } 278 }
@@ -320,8 +328,10 @@ MODULE_LICENSE("GPL");
320 328
321static int __init hostaudio_init_module(void) 329static int __init hostaudio_init_module(void)
322{ 330{
331 __kernel_param_lock();
323 printk(KERN_INFO "UML Audio Relay (host dsp = %s, host mixer = %s)\n", 332 printk(KERN_INFO "UML Audio Relay (host dsp = %s, host mixer = %s)\n",
324 dsp, mixer); 333 dsp, mixer);
334 __kernel_param_unlock();
325 335
326 module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1); 336 module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1);
327 if (module_data.dev_audio < 0) { 337 if (module_data.dev_audio < 0) {
diff --git a/arch/um/include/asm/dma-mapping.h b/arch/um/include/asm/dma-mapping.h
index b948c14a7867..17a2cb5a4178 100644
--- a/arch/um/include/asm/dma-mapping.h
+++ b/arch/um/include/asm/dma-mapping.h
@@ -94,7 +94,6 @@ dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
94 94
95#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 95#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
96#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) 96#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
97#define dma_is_consistent(d, h) (1)
98 97
99static inline int 98static inline int
100dma_get_cache_alignment(void) 99dma_get_cache_alignment(void)
diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
index ac91eed21061..d4c419f883a0 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -54,7 +54,6 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
54 54
55#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 55#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
56#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) 56#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
57#define dma_is_consistent(d, h) (1)
58 57
59extern int dma_supported(struct device *hwdev, u64 mask); 58extern int dma_supported(struct device *hwdev, u64 mask);
60extern int dma_set_mask(struct device *dev, u64 mask); 59extern int dma_set_mask(struct device *dev, u64 mask);
@@ -87,13 +86,6 @@ dma_cache_sync(struct device *dev, void *vaddr, size_t size,
87 flush_write_buffers(); 86 flush_write_buffers();
88} 87}
89 88
90static inline int dma_get_cache_alignment(void)
91{
92 /* no easy way to get cache size on all x86, so return the
93 * maximum possible, to be safe */
94 return boot_cpu_data.x86_clflush_size;
95}
96
97static inline unsigned long dma_alloc_coherent_mask(struct device *dev, 89static inline unsigned long dma_alloc_coherent_mask(struct device *dev,
98 gfp_t gfp) 90 gfp_t gfp)
99{ 91{
diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
index 625c3f0e741a..8ca82839288a 100644
--- a/arch/x86/include/asm/page.h
+++ b/arch/x86/include/asm/page.h
@@ -37,6 +37,13 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
37#define __pa_nodebug(x) __phys_addr_nodebug((unsigned long)(x)) 37#define __pa_nodebug(x) __phys_addr_nodebug((unsigned long)(x))
38/* __pa_symbol should be used for C visible symbols. 38/* __pa_symbol should be used for C visible symbols.
39 This seems to be the official gcc blessed way to do such arithmetic. */ 39 This seems to be the official gcc blessed way to do such arithmetic. */
40/*
41 * We need __phys_reloc_hide() here because gcc may assume that there is no
42 * overflow during __pa() calculation and can optimize it unexpectedly.
43 * Newer versions of gcc provide -fno-strict-overflow switch to handle this
44 * case properly. Once all supported versions of gcc understand it, we can
45 * remove this Voodoo magic stuff. (i.e. once gcc3.x is deprecated)
46 */
40#define __pa_symbol(x) __pa(__phys_reloc_hide((unsigned long)(x))) 47#define __pa_symbol(x) __pa(__phys_reloc_hide((unsigned long)(x)))
41 48
42#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) 49#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
diff --git a/arch/x86/include/asm/uv/uv_bau.h b/arch/x86/include/asm/uv/uv_bau.h
index aa558ac0306e..42d412fd8b02 100644
--- a/arch/x86/include/asm/uv/uv_bau.h
+++ b/arch/x86/include/asm/uv/uv_bau.h
@@ -34,6 +34,7 @@
34 */ 34 */
35 35
36#define UV_ITEMS_PER_DESCRIPTOR 8 36#define UV_ITEMS_PER_DESCRIPTOR 8
37/* the 'throttle' to prevent the hardware stay-busy bug */
37#define MAX_BAU_CONCURRENT 3 38#define MAX_BAU_CONCURRENT 3
38#define UV_CPUS_PER_ACT_STATUS 32 39#define UV_CPUS_PER_ACT_STATUS 32
39#define UV_ACT_STATUS_MASK 0x3 40#define UV_ACT_STATUS_MASK 0x3
@@ -45,10 +46,26 @@
45#define UV_DESC_BASE_PNODE_SHIFT 49 46#define UV_DESC_BASE_PNODE_SHIFT 49
46#define UV_PAYLOADQ_PNODE_SHIFT 49 47#define UV_PAYLOADQ_PNODE_SHIFT 49
47#define UV_PTC_BASENAME "sgi_uv/ptc_statistics" 48#define UV_PTC_BASENAME "sgi_uv/ptc_statistics"
49#define UV_BAU_BASENAME "sgi_uv/bau_tunables"
50#define UV_BAU_TUNABLES_DIR "sgi_uv"
51#define UV_BAU_TUNABLES_FILE "bau_tunables"
52#define WHITESPACE " \t\n"
48#define uv_physnodeaddr(x) ((__pa((unsigned long)(x)) & uv_mmask)) 53#define uv_physnodeaddr(x) ((__pa((unsigned long)(x)) & uv_mmask))
49#define UV_ENABLE_INTD_SOFT_ACK_MODE_SHIFT 15 54#define UV_ENABLE_INTD_SOFT_ACK_MODE_SHIFT 15
50#define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHIFT 16 55#define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHIFT 16
51#define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD 0x000000000bUL 56#define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD 0x0000000009UL
57/* [19:16] SOFT_ACK timeout period 19: 1 is urgency 7 17:16 1 is multiplier */
58#define BAU_MISC_CONTROL_MULT_MASK 3
59
60#define UVH_AGING_PRESCALE_SEL 0x000000b000UL
61/* [30:28] URGENCY_7 an index into a table of times */
62#define BAU_URGENCY_7_SHIFT 28
63#define BAU_URGENCY_7_MASK 7
64
65#define UVH_TRANSACTION_TIMEOUT 0x000000b200UL
66/* [45:40] BAU - BAU transaction timeout select - a multiplier */
67#define BAU_TRANS_SHIFT 40
68#define BAU_TRANS_MASK 0x3f
52 69
53/* 70/*
54 * bits in UVH_LB_BAU_SB_ACTIVATION_STATUS_0/1 71 * bits in UVH_LB_BAU_SB_ACTIVATION_STATUS_0/1
@@ -59,24 +76,21 @@
59#define DESC_STATUS_SOURCE_TIMEOUT 3 76#define DESC_STATUS_SOURCE_TIMEOUT 3
60 77
61/* 78/*
62 * source side threshholds at which message retries print a warning 79 * delay for 'plugged' timeout retries, in microseconds
63 */
64#define SOURCE_TIMEOUT_LIMIT 20
65#define DESTINATION_TIMEOUT_LIMIT 20
66
67/*
68 * misc. delays, in microseconds
69 */ 80 */
70#define THROTTLE_DELAY 10 81#define PLUGGED_DELAY 10
71#define TIMEOUT_DELAY 10
72#define BIOS_TO 1000
73/* BIOS is assumed to set the destination timeout to 1003520 nanoseconds */
74 82
75/* 83/*
76 * threshholds at which to use IPI to free resources 84 * threshholds at which to use IPI to free resources
77 */ 85 */
86/* after this # consecutive 'plugged' timeouts, use IPI to release resources */
78#define PLUGSB4RESET 100 87#define PLUGSB4RESET 100
79#define TIMEOUTSB4RESET 100 88/* after this many consecutive timeouts, use IPI to release resources */
89#define TIMEOUTSB4RESET 1
90/* at this number uses of IPI to release resources, giveup the request */
91#define IPI_RESET_LIMIT 1
92/* after this # consecutive successes, bump up the throttle if it was lowered */
93#define COMPLETE_THRESHOLD 5
80 94
81/* 95/*
82 * number of entries in the destination side payload queue 96 * number of entries in the destination side payload queue
@@ -96,6 +110,13 @@
96#define FLUSH_COMPLETE 4 110#define FLUSH_COMPLETE 4
97 111
98/* 112/*
113 * tuning the action when the numalink network is extremely delayed
114 */
115#define CONGESTED_RESPONSE_US 1000 /* 'long' response time, in microseconds */
116#define CONGESTED_REPS 10 /* long delays averaged over this many broadcasts */
117#define CONGESTED_PERIOD 30 /* time for the bau to be disabled, in seconds */
118
119/*
99 * Distribution: 32 bytes (256 bits) (bytes 0-0x1f of descriptor) 120 * Distribution: 32 bytes (256 bits) (bytes 0-0x1f of descriptor)
100 * If the 'multilevel' flag in the header portion of the descriptor 121 * If the 'multilevel' flag in the header portion of the descriptor
101 * has been set to 0, then endpoint multi-unicast mode is selected. 122 * has been set to 0, then endpoint multi-unicast mode is selected.
@@ -300,37 +321,16 @@ struct bau_payload_queue_entry {
300 /* bytes 24-31 */ 321 /* bytes 24-31 */
301}; 322};
302 323
303/* 324struct msg_desc {
304 * one per-cpu; to locate the software tables 325 struct bau_payload_queue_entry *msg;
305 */ 326 int msg_slot;
306struct bau_control { 327 int sw_ack_slot;
307 struct bau_desc *descriptor_base;
308 struct bau_payload_queue_entry *va_queue_first; 328 struct bau_payload_queue_entry *va_queue_first;
309 struct bau_payload_queue_entry *va_queue_last; 329 struct bau_payload_queue_entry *va_queue_last;
310 struct bau_payload_queue_entry *bau_msg_head; 330};
311 struct bau_control *uvhub_master; 331
312 struct bau_control *socket_master; 332struct reset_args {
313 unsigned long timeout_interval; 333 int sender;
314 atomic_t active_descriptor_count;
315 int max_concurrent;
316 int max_concurrent_constant;
317 int retry_message_scans;
318 int plugged_tries;
319 int timeout_tries;
320 int ipi_attempts;
321 int conseccompletes;
322 short cpu;
323 short uvhub_cpu;
324 short uvhub;
325 short cpus_in_socket;
326 short cpus_in_uvhub;
327 unsigned short message_number;
328 unsigned short uvhub_quiesce;
329 short socket_acknowledge_count[DEST_Q_SIZE];
330 cycles_t send_message;
331 spinlock_t masks_lock;
332 spinlock_t uvhub_lock;
333 spinlock_t queue_lock;
334}; 334};
335 335
336/* 336/*
@@ -344,18 +344,25 @@ struct ptc_stats {
344 unsigned long s_dtimeout; /* destination side timeouts */ 344 unsigned long s_dtimeout; /* destination side timeouts */
345 unsigned long s_time; /* time spent in sending side */ 345 unsigned long s_time; /* time spent in sending side */
346 unsigned long s_retriesok; /* successful retries */ 346 unsigned long s_retriesok; /* successful retries */
347 unsigned long s_ntargcpu; /* number of cpus targeted */ 347 unsigned long s_ntargcpu; /* total number of cpu's targeted */
348 unsigned long s_ntarguvhub; /* number of uvhubs targeted */ 348 unsigned long s_ntargself; /* times the sending cpu was targeted */
349 unsigned long s_ntarguvhub16; /* number of times >= 16 target hubs */ 349 unsigned long s_ntarglocals; /* targets of cpus on the local blade */
350 unsigned long s_ntarguvhub8; /* number of times >= 8 target hubs */ 350 unsigned long s_ntargremotes; /* targets of cpus on remote blades */
351 unsigned long s_ntarguvhub4; /* number of times >= 4 target hubs */ 351 unsigned long s_ntarglocaluvhub; /* targets of the local hub */
352 unsigned long s_ntarguvhub2; /* number of times >= 2 target hubs */ 352 unsigned long s_ntargremoteuvhub; /* remotes hubs targeted */
353 unsigned long s_ntarguvhub1; /* number of times == 1 target hub */ 353 unsigned long s_ntarguvhub; /* total number of uvhubs targeted */
354 unsigned long s_ntarguvhub16; /* number of times target hubs >= 16*/
355 unsigned long s_ntarguvhub8; /* number of times target hubs >= 8 */
356 unsigned long s_ntarguvhub4; /* number of times target hubs >= 4 */
357 unsigned long s_ntarguvhub2; /* number of times target hubs >= 2 */
358 unsigned long s_ntarguvhub1; /* number of times target hubs == 1 */
354 unsigned long s_resets_plug; /* ipi-style resets from plug state */ 359 unsigned long s_resets_plug; /* ipi-style resets from plug state */
355 unsigned long s_resets_timeout; /* ipi-style resets from timeouts */ 360 unsigned long s_resets_timeout; /* ipi-style resets from timeouts */
356 unsigned long s_busy; /* status stayed busy past s/w timer */ 361 unsigned long s_busy; /* status stayed busy past s/w timer */
357 unsigned long s_throttles; /* waits in throttle */ 362 unsigned long s_throttles; /* waits in throttle */
358 unsigned long s_retry_messages; /* retry broadcasts */ 363 unsigned long s_retry_messages; /* retry broadcasts */
364 unsigned long s_bau_reenabled; /* for bau enable/disable */
365 unsigned long s_bau_disabled; /* for bau enable/disable */
359 /* destination statistics */ 366 /* destination statistics */
360 unsigned long d_alltlb; /* times all tlb's on this cpu were flushed */ 367 unsigned long d_alltlb; /* times all tlb's on this cpu were flushed */
361 unsigned long d_onetlb; /* times just one tlb on this cpu was flushed */ 368 unsigned long d_onetlb; /* times just one tlb on this cpu was flushed */
@@ -370,6 +377,52 @@ struct ptc_stats {
370 unsigned long d_rcanceled; /* number of messages canceled by resets */ 377 unsigned long d_rcanceled; /* number of messages canceled by resets */
371}; 378};
372 379
380/*
381 * one per-cpu; to locate the software tables
382 */
383struct bau_control {
384 struct bau_desc *descriptor_base;
385 struct bau_payload_queue_entry *va_queue_first;
386 struct bau_payload_queue_entry *va_queue_last;
387 struct bau_payload_queue_entry *bau_msg_head;
388 struct bau_control *uvhub_master;
389 struct bau_control *socket_master;
390 struct ptc_stats *statp;
391 unsigned long timeout_interval;
392 unsigned long set_bau_on_time;
393 atomic_t active_descriptor_count;
394 int plugged_tries;
395 int timeout_tries;
396 int ipi_attempts;
397 int conseccompletes;
398 int baudisabled;
399 int set_bau_off;
400 short cpu;
401 short uvhub_cpu;
402 short uvhub;
403 short cpus_in_socket;
404 short cpus_in_uvhub;
405 unsigned short message_number;
406 unsigned short uvhub_quiesce;
407 short socket_acknowledge_count[DEST_Q_SIZE];
408 cycles_t send_message;
409 spinlock_t uvhub_lock;
410 spinlock_t queue_lock;
411 /* tunables */
412 int max_bau_concurrent;
413 int max_bau_concurrent_constant;
414 int plugged_delay;
415 int plugsb4reset;
416 int timeoutsb4reset;
417 int ipi_reset_limit;
418 int complete_threshold;
419 int congested_response_us;
420 int congested_reps;
421 int congested_period;
422 cycles_t period_time;
423 long period_requests;
424};
425
373static inline int bau_uvhub_isset(int uvhub, struct bau_target_uvhubmask *dstp) 426static inline int bau_uvhub_isset(int uvhub, struct bau_target_uvhubmask *dstp)
374{ 427{
375 return constant_test_bit(uvhub, &dstp->bits[0]); 428 return constant_test_bit(uvhub, &dstp->bits[0]);
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index 018a0a400799..bf5f7d32bd08 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -112,13 +112,9 @@ static inline xpaddr_t machine_to_phys(xmaddr_t machine)
112 */ 112 */
113static inline unsigned long mfn_to_local_pfn(unsigned long mfn) 113static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
114{ 114{
115 extern unsigned long max_mapnr;
116 unsigned long pfn = mfn_to_pfn(mfn); 115 unsigned long pfn = mfn_to_pfn(mfn);
117 if ((pfn < max_mapnr) 116 if (get_phys_to_machine(pfn) != mfn)
118 && !xen_feature(XENFEAT_auto_translated_physmap) 117 return -1; /* force !pfn_valid() */
119 && (get_phys_to_machine(pfn) != mfn))
120 return max_mapnr; /* force !pfn_valid() */
121 /* XXX fixme; not true with sparsemem */
122 return pfn; 118 return pfn;
123} 119}
124 120
diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h
new file mode 100644
index 000000000000..1be1ab7d6a41
--- /dev/null
+++ b/arch/x86/include/asm/xen/swiotlb-xen.h
@@ -0,0 +1,14 @@
1#ifndef _ASM_X86_SWIOTLB_XEN_H
2#define _ASM_X86_SWIOTLB_XEN_H
3
4#ifdef CONFIG_SWIOTLB_XEN
5extern int xen_swiotlb;
6extern int __init pci_xen_swiotlb_detect(void);
7extern void __init pci_xen_swiotlb_init(void);
8#else
9#define xen_swiotlb (0)
10static inline int __init pci_xen_swiotlb_detect(void) { return 0; }
11static inline void __init pci_xen_swiotlb_init(void) { }
12#endif
13
14#endif /* _ASM_X86_SWIOTLB_XEN_H */
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 980508c79082..e3b534cda49a 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1606,7 +1606,7 @@ void __init init_apic_mappings(void)
1606 * acpi lapic path already maps that address in 1606 * acpi lapic path already maps that address in
1607 * acpi_register_lapic_address() 1607 * acpi_register_lapic_address()
1608 */ 1608 */
1609 if (!acpi_lapic) 1609 if (!acpi_lapic && !smp_found_config)
1610 set_fixmap_nocache(FIX_APIC_BASE, apic_phys); 1610 set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
1611 1611
1612 apic_printk(APIC_VERBOSE, "mapped APIC to %08lx (%08lx)\n", 1612 apic_printk(APIC_VERBOSE, "mapped APIC to %08lx (%08lx)\n",
diff --git a/arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.c b/arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.c
index a36de5bbb622..994230d4dc4e 100644
--- a/arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.c
+++ b/arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.c
@@ -110,7 +110,7 @@ struct pcc_cpu {
110 u32 output_offset; 110 u32 output_offset;
111}; 111};
112 112
113static struct pcc_cpu *pcc_cpu_info; 113static struct pcc_cpu __percpu *pcc_cpu_info;
114 114
115static int pcc_cpufreq_verify(struct cpufreq_policy *policy) 115static int pcc_cpufreq_verify(struct cpufreq_policy *policy)
116{ 116{
diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c
index 107711bf0ee8..febb12cea795 100644
--- a/arch/x86/kernel/cpu/perf_event_p4.c
+++ b/arch/x86/kernel/cpu/perf_event_p4.c
@@ -656,6 +656,7 @@ static int p4_pmu_handle_irq(struct pt_regs *regs)
656 cpuc = &__get_cpu_var(cpu_hw_events); 656 cpuc = &__get_cpu_var(cpu_hw_events);
657 657
658 for (idx = 0; idx < x86_pmu.num_counters; idx++) { 658 for (idx = 0; idx < x86_pmu.num_counters; idx++) {
659 int overflow;
659 660
660 if (!test_bit(idx, cpuc->active_mask)) 661 if (!test_bit(idx, cpuc->active_mask))
661 continue; 662 continue;
@@ -666,12 +667,14 @@ static int p4_pmu_handle_irq(struct pt_regs *regs)
666 WARN_ON_ONCE(hwc->idx != idx); 667 WARN_ON_ONCE(hwc->idx != idx);
667 668
668 /* it might be unflagged overflow */ 669 /* it might be unflagged overflow */
669 handled = p4_pmu_clear_cccr_ovf(hwc); 670 overflow = p4_pmu_clear_cccr_ovf(hwc);
670 671
671 val = x86_perf_event_update(event); 672 val = x86_perf_event_update(event);
672 if (!handled && (val & (1ULL << (x86_pmu.cntval_bits - 1)))) 673 if (!overflow && (val & (1ULL << (x86_pmu.cntval_bits - 1))))
673 continue; 674 continue;
674 675
676 handled += overflow;
677
675 /* event overflow for sure */ 678 /* event overflow for sure */
676 data.period = event->hw.last_period; 679 data.period = event->hw.last_period;
677 680
@@ -687,7 +690,7 @@ static int p4_pmu_handle_irq(struct pt_regs *regs)
687 inc_irq_stat(apic_perf_irqs); 690 inc_irq_stat(apic_perf_irqs);
688 } 691 }
689 692
690 return handled; 693 return handled > 0;
691} 694}
692 695
693/* 696/*
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index 33dbcc4ec5ff..351f9c0fea1f 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -582,7 +582,7 @@ static void init_one_hpet_msi_clockevent(struct hpet_dev *hdev, int cpu)
582 * scaled math multiplication factor for nanosecond to hpet tick 582 * scaled math multiplication factor for nanosecond to hpet tick
583 * conversion. 583 * conversion.
584 */ 584 */
585 hpet_freq = 1000000000000000ULL; 585 hpet_freq = FSEC_PER_SEC;
586 do_div(hpet_freq, hpet_period); 586 do_div(hpet_freq, hpet_period);
587 evt->mult = div_sc((unsigned long) hpet_freq, 587 evt->mult = div_sc((unsigned long) hpet_freq,
588 NSEC_PER_SEC, evt->shift); 588 NSEC_PER_SEC, evt->shift);
@@ -837,7 +837,7 @@ static int hpet_clocksource_register(void)
837 * cyc/sec = FSEC_PER_SEC/hpet_period(fsec/cyc) 837 * cyc/sec = FSEC_PER_SEC/hpet_period(fsec/cyc)
838 * cyc/sec = (FSEC_PER_NSEC * NSEC_PER_SEC)/hpet_period 838 * cyc/sec = (FSEC_PER_NSEC * NSEC_PER_SEC)/hpet_period
839 */ 839 */
840 hpet_freq = FSEC_PER_NSEC * NSEC_PER_SEC; 840 hpet_freq = FSEC_PER_SEC;
841 do_div(hpet_freq, hpet_period); 841 do_div(hpet_freq, hpet_period);
842 clocksource_register_hz(&clocksource_hpet, (u32)hpet_freq); 842 clocksource_register_hz(&clocksource_hpet, (u32)hpet_freq);
843 843
diff --git a/arch/x86/kernel/mpparse.c b/arch/x86/kernel/mpparse.c
index d86dbf7e54be..d7b6f7fb4fec 100644
--- a/arch/x86/kernel/mpparse.c
+++ b/arch/x86/kernel/mpparse.c
@@ -274,6 +274,18 @@ static void __init smp_dump_mptable(struct mpc_table *mpc, unsigned char *mpt)
274 274
275void __init default_smp_read_mpc_oem(struct mpc_table *mpc) { } 275void __init default_smp_read_mpc_oem(struct mpc_table *mpc) { }
276 276
277static void __init smp_register_lapic_address(unsigned long address)
278{
279 mp_lapic_addr = address;
280
281 set_fixmap_nocache(FIX_APIC_BASE, address);
282 if (boot_cpu_physical_apicid == -1U) {
283 boot_cpu_physical_apicid = read_apic_id();
284 apic_version[boot_cpu_physical_apicid] =
285 GET_APIC_VERSION(apic_read(APIC_LVR));
286 }
287}
288
277static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early) 289static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
278{ 290{
279 char str[16]; 291 char str[16];
@@ -295,6 +307,10 @@ static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
295 if (early) 307 if (early)
296 return 1; 308 return 1;
297 309
310 /* Initialize the lapic mapping */
311 if (!acpi_lapic)
312 smp_register_lapic_address(mpc->lapic);
313
298 if (mpc->oemptr) 314 if (mpc->oemptr)
299 x86_init.mpparse.smp_read_mpc_oem(mpc); 315 x86_init.mpparse.smp_read_mpc_oem(mpc);
300 316
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 4b7e3d8b01dd..9f07cfcbd3a5 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -13,6 +13,7 @@
13#include <asm/calgary.h> 13#include <asm/calgary.h>
14#include <asm/amd_iommu.h> 14#include <asm/amd_iommu.h>
15#include <asm/x86_init.h> 15#include <asm/x86_init.h>
16#include <asm/xen/swiotlb-xen.h>
16 17
17static int forbid_dac __read_mostly; 18static int forbid_dac __read_mostly;
18 19
@@ -132,7 +133,7 @@ void __init pci_iommu_alloc(void)
132 /* free the range so iommu could get some range less than 4G */ 133 /* free the range so iommu could get some range less than 4G */
133 dma32_free_bootmem(); 134 dma32_free_bootmem();
134 135
135 if (pci_swiotlb_detect()) 136 if (pci_xen_swiotlb_detect() || pci_swiotlb_detect())
136 goto out; 137 goto out;
137 138
138 gart_iommu_hole_init(); 139 gart_iommu_hole_init();
@@ -144,6 +145,8 @@ void __init pci_iommu_alloc(void)
144 /* needs to be called after gart_iommu_hole_init */ 145 /* needs to be called after gart_iommu_hole_init */
145 amd_iommu_detect(); 146 amd_iommu_detect();
146out: 147out:
148 pci_xen_swiotlb_init();
149
147 pci_swiotlb_init(); 150 pci_swiotlb_init();
148} 151}
149 152
@@ -296,7 +299,7 @@ static int __init pci_iommu_init(void)
296#endif 299#endif
297 x86_init.iommu.iommu_init(); 300 x86_init.iommu.iommu_init();
298 301
299 if (swiotlb) { 302 if (swiotlb || xen_swiotlb) {
300 printk(KERN_INFO "PCI-DMA: " 303 printk(KERN_INFO "PCI-DMA: "
301 "Using software bounce buffering for IO (SWIOTLB)\n"); 304 "Using software bounce buffering for IO (SWIOTLB)\n");
302 swiotlb_print_info(); 305 swiotlb_print_info();
diff --git a/arch/x86/kernel/tlb_uv.c b/arch/x86/kernel/tlb_uv.c
index 7fea555929e2..59efb5390b37 100644
--- a/arch/x86/kernel/tlb_uv.c
+++ b/arch/x86/kernel/tlb_uv.c
@@ -8,6 +8,7 @@
8 */ 8 */
9#include <linux/seq_file.h> 9#include <linux/seq_file.h>
10#include <linux/proc_fs.h> 10#include <linux/proc_fs.h>
11#include <linux/debugfs.h>
11#include <linux/kernel.h> 12#include <linux/kernel.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
13 14
@@ -22,19 +23,37 @@
22#include <asm/irq_vectors.h> 23#include <asm/irq_vectors.h>
23#include <asm/timer.h> 24#include <asm/timer.h>
24 25
25struct msg_desc { 26/* timeouts in nanoseconds (indexed by UVH_AGING_PRESCALE_SEL urgency7 30:28) */
26 struct bau_payload_queue_entry *msg; 27static int timeout_base_ns[] = {
27 int msg_slot; 28 20,
28 int sw_ack_slot; 29 160,
29 struct bau_payload_queue_entry *va_queue_first; 30 1280,
30 struct bau_payload_queue_entry *va_queue_last; 31 10240,
32 81920,
33 655360,
34 5242880,
35 167772160
31}; 36};
32 37static int timeout_us;
33#define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD 0x000000000bUL
34
35static int uv_bau_max_concurrent __read_mostly;
36
37static int nobau; 38static int nobau;
39static int baudisabled;
40static spinlock_t disable_lock;
41static cycles_t congested_cycles;
42
43/* tunables: */
44static int max_bau_concurrent = MAX_BAU_CONCURRENT;
45static int max_bau_concurrent_constant = MAX_BAU_CONCURRENT;
46static int plugged_delay = PLUGGED_DELAY;
47static int plugsb4reset = PLUGSB4RESET;
48static int timeoutsb4reset = TIMEOUTSB4RESET;
49static int ipi_reset_limit = IPI_RESET_LIMIT;
50static int complete_threshold = COMPLETE_THRESHOLD;
51static int congested_response_us = CONGESTED_RESPONSE_US;
52static int congested_reps = CONGESTED_REPS;
53static int congested_period = CONGESTED_PERIOD;
54static struct dentry *tunables_dir;
55static struct dentry *tunables_file;
56
38static int __init setup_nobau(char *arg) 57static int __init setup_nobau(char *arg)
39{ 58{
40 nobau = 1; 59 nobau = 1;
@@ -52,10 +71,6 @@ static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
52static DEFINE_PER_CPU(struct bau_control, bau_control); 71static DEFINE_PER_CPU(struct bau_control, bau_control);
53static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask); 72static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
54 73
55struct reset_args {
56 int sender;
57};
58
59/* 74/*
60 * Determine the first node on a uvhub. 'Nodes' are used for kernel 75 * Determine the first node on a uvhub. 'Nodes' are used for kernel
61 * memory allocation. 76 * memory allocation.
@@ -126,7 +141,7 @@ static inline void uv_bau_process_retry_msg(struct msg_desc *mdp,
126 struct ptc_stats *stat; 141 struct ptc_stats *stat;
127 142
128 msg = mdp->msg; 143 msg = mdp->msg;
129 stat = &per_cpu(ptcstats, bcp->cpu); 144 stat = bcp->statp;
130 stat->d_retries++; 145 stat->d_retries++;
131 /* 146 /*
132 * cancel any message from msg+1 to the retry itself 147 * cancel any message from msg+1 to the retry itself
@@ -146,15 +161,14 @@ static inline void uv_bau_process_retry_msg(struct msg_desc *mdp,
146 slot2 = msg2 - mdp->va_queue_first; 161 slot2 = msg2 - mdp->va_queue_first;
147 mmr = uv_read_local_mmr 162 mmr = uv_read_local_mmr
148 (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE); 163 (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
149 msg_res = ((msg2->sw_ack_vector << 8) | 164 msg_res = msg2->sw_ack_vector;
150 msg2->sw_ack_vector);
151 /* 165 /*
152 * This is a message retry; clear the resources held 166 * This is a message retry; clear the resources held
153 * by the previous message only if they timed out. 167 * by the previous message only if they timed out.
154 * If it has not timed out we have an unexpected 168 * If it has not timed out we have an unexpected
155 * situation to report. 169 * situation to report.
156 */ 170 */
157 if (mmr & (msg_res << 8)) { 171 if (mmr & (msg_res << UV_SW_ACK_NPENDING)) {
158 /* 172 /*
159 * is the resource timed out? 173 * is the resource timed out?
160 * make everyone ignore the cancelled message. 174 * make everyone ignore the cancelled message.
@@ -164,9 +178,9 @@ static inline void uv_bau_process_retry_msg(struct msg_desc *mdp,
164 cancel_count++; 178 cancel_count++;
165 uv_write_local_mmr( 179 uv_write_local_mmr(
166 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, 180 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
167 (msg_res << 8) | msg_res); 181 (msg_res << UV_SW_ACK_NPENDING) |
168 } else 182 msg_res);
169 printk(KERN_INFO "note bau retry: no effect\n"); 183 }
170 } 184 }
171 } 185 }
172 if (!cancel_count) 186 if (!cancel_count)
@@ -190,7 +204,7 @@ static void uv_bau_process_message(struct msg_desc *mdp,
190 * This must be a normal message, or retry of a normal message 204 * This must be a normal message, or retry of a normal message
191 */ 205 */
192 msg = mdp->msg; 206 msg = mdp->msg;
193 stat = &per_cpu(ptcstats, bcp->cpu); 207 stat = bcp->statp;
194 if (msg->address == TLB_FLUSH_ALL) { 208 if (msg->address == TLB_FLUSH_ALL) {
195 local_flush_tlb(); 209 local_flush_tlb();
196 stat->d_alltlb++; 210 stat->d_alltlb++;
@@ -274,7 +288,7 @@ uv_do_reset(void *ptr)
274 288
275 bcp = &per_cpu(bau_control, smp_processor_id()); 289 bcp = &per_cpu(bau_control, smp_processor_id());
276 rap = (struct reset_args *)ptr; 290 rap = (struct reset_args *)ptr;
277 stat = &per_cpu(ptcstats, bcp->cpu); 291 stat = bcp->statp;
278 stat->d_resets++; 292 stat->d_resets++;
279 293
280 /* 294 /*
@@ -302,13 +316,13 @@ uv_do_reset(void *ptr)
302 */ 316 */
303 mmr = uv_read_local_mmr 317 mmr = uv_read_local_mmr
304 (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE); 318 (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
305 msg_res = ((msg->sw_ack_vector << 8) | 319 msg_res = msg->sw_ack_vector;
306 msg->sw_ack_vector);
307 if (mmr & msg_res) { 320 if (mmr & msg_res) {
308 stat->d_rcanceled++; 321 stat->d_rcanceled++;
309 uv_write_local_mmr( 322 uv_write_local_mmr(
310 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, 323 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
311 msg_res); 324 (msg_res << UV_SW_ACK_NPENDING) |
325 msg_res);
312 } 326 }
313 } 327 }
314 } 328 }
@@ -386,17 +400,12 @@ static int uv_wait_completion(struct bau_desc *bau_desc,
386 unsigned long mmr_offset, int right_shift, int this_cpu, 400 unsigned long mmr_offset, int right_shift, int this_cpu,
387 struct bau_control *bcp, struct bau_control *smaster, long try) 401 struct bau_control *bcp, struct bau_control *smaster, long try)
388{ 402{
389 int relaxes = 0;
390 unsigned long descriptor_status; 403 unsigned long descriptor_status;
391 unsigned long mmr;
392 unsigned long mask;
393 cycles_t ttime; 404 cycles_t ttime;
394 cycles_t timeout_time; 405 struct ptc_stats *stat = bcp->statp;
395 struct ptc_stats *stat = &per_cpu(ptcstats, this_cpu);
396 struct bau_control *hmaster; 406 struct bau_control *hmaster;
397 407
398 hmaster = bcp->uvhub_master; 408 hmaster = bcp->uvhub_master;
399 timeout_time = get_cycles() + bcp->timeout_interval;
400 409
401 /* spin on the status MMR, waiting for it to go idle */ 410 /* spin on the status MMR, waiting for it to go idle */
402 while ((descriptor_status = (((unsigned long) 411 while ((descriptor_status = (((unsigned long)
@@ -423,7 +432,8 @@ static int uv_wait_completion(struct bau_desc *bau_desc,
423 * pending. In that case hardware returns the 432 * pending. In that case hardware returns the
424 * ERROR that looks like a destination timeout. 433 * ERROR that looks like a destination timeout.
425 */ 434 */
426 if (cycles_2_us(ttime - bcp->send_message) < BIOS_TO) { 435 if (cycles_2_us(ttime - bcp->send_message) <
436 timeout_us) {
427 bcp->conseccompletes = 0; 437 bcp->conseccompletes = 0;
428 return FLUSH_RETRY_PLUGGED; 438 return FLUSH_RETRY_PLUGGED;
429 } 439 }
@@ -435,26 +445,6 @@ static int uv_wait_completion(struct bau_desc *bau_desc,
435 * descriptor_status is still BUSY 445 * descriptor_status is still BUSY
436 */ 446 */
437 cpu_relax(); 447 cpu_relax();
438 relaxes++;
439 if (relaxes >= 10000) {
440 relaxes = 0;
441 if (get_cycles() > timeout_time) {
442 quiesce_local_uvhub(hmaster);
443
444 /* single-thread the register change */
445 spin_lock(&hmaster->masks_lock);
446 mmr = uv_read_local_mmr(mmr_offset);
447 mask = 0UL;
448 mask |= (3UL < right_shift);
449 mask = ~mask;
450 mmr &= mask;
451 uv_write_local_mmr(mmr_offset, mmr);
452 spin_unlock(&hmaster->masks_lock);
453 end_uvhub_quiesce(hmaster);
454 stat->s_busy++;
455 return FLUSH_GIVEUP;
456 }
457 }
458 } 448 }
459 } 449 }
460 bcp->conseccompletes++; 450 bcp->conseccompletes++;
@@ -494,56 +484,116 @@ static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
494 return 1; 484 return 1;
495} 485}
496 486
487/*
488 * Our retries are blocked by all destination swack resources being
489 * in use, and a timeout is pending. In that case hardware immediately
490 * returns the ERROR that looks like a destination timeout.
491 */
492static void
493destination_plugged(struct bau_desc *bau_desc, struct bau_control *bcp,
494 struct bau_control *hmaster, struct ptc_stats *stat)
495{
496 udelay(bcp->plugged_delay);
497 bcp->plugged_tries++;
498 if (bcp->plugged_tries >= bcp->plugsb4reset) {
499 bcp->plugged_tries = 0;
500 quiesce_local_uvhub(hmaster);
501 spin_lock(&hmaster->queue_lock);
502 uv_reset_with_ipi(&bau_desc->distribution, bcp->cpu);
503 spin_unlock(&hmaster->queue_lock);
504 end_uvhub_quiesce(hmaster);
505 bcp->ipi_attempts++;
506 stat->s_resets_plug++;
507 }
508}
509
510static void
511destination_timeout(struct bau_desc *bau_desc, struct bau_control *bcp,
512 struct bau_control *hmaster, struct ptc_stats *stat)
513{
514 hmaster->max_bau_concurrent = 1;
515 bcp->timeout_tries++;
516 if (bcp->timeout_tries >= bcp->timeoutsb4reset) {
517 bcp->timeout_tries = 0;
518 quiesce_local_uvhub(hmaster);
519 spin_lock(&hmaster->queue_lock);
520 uv_reset_with_ipi(&bau_desc->distribution, bcp->cpu);
521 spin_unlock(&hmaster->queue_lock);
522 end_uvhub_quiesce(hmaster);
523 bcp->ipi_attempts++;
524 stat->s_resets_timeout++;
525 }
526}
527
528/*
529 * Completions are taking a very long time due to a congested numalink
530 * network.
531 */
532static void
533disable_for_congestion(struct bau_control *bcp, struct ptc_stats *stat)
534{
535 int tcpu;
536 struct bau_control *tbcp;
537
538 /* let only one cpu do this disabling */
539 spin_lock(&disable_lock);
540 if (!baudisabled && bcp->period_requests &&
541 ((bcp->period_time / bcp->period_requests) > congested_cycles)) {
542 /* it becomes this cpu's job to turn on the use of the
543 BAU again */
544 baudisabled = 1;
545 bcp->set_bau_off = 1;
546 bcp->set_bau_on_time = get_cycles() +
547 sec_2_cycles(bcp->congested_period);
548 stat->s_bau_disabled++;
549 for_each_present_cpu(tcpu) {
550 tbcp = &per_cpu(bau_control, tcpu);
551 tbcp->baudisabled = 1;
552 }
553 }
554 spin_unlock(&disable_lock);
555}
556
497/** 557/**
498 * uv_flush_send_and_wait 558 * uv_flush_send_and_wait
499 * 559 *
500 * Send a broadcast and wait for it to complete. 560 * Send a broadcast and wait for it to complete.
501 * 561 *
502 * The flush_mask contains the cpus the broadcast is to be sent to, plus 562 * The flush_mask contains the cpus the broadcast is to be sent to including
503 * cpus that are on the local uvhub. 563 * cpus that are on the local uvhub.
504 * 564 *
505 * Returns NULL if all flushing represented in the mask was done. The mask 565 * Returns 0 if all flushing represented in the mask was done.
506 * is zeroed. 566 * Returns 1 if it gives up entirely and the original cpu mask is to be
507 * Returns @flush_mask if some remote flushing remains to be done. The 567 * returned to the kernel.
508 * mask will have some bits still set, representing any cpus on the local
509 * uvhub (not current cpu) and any on remote uvhubs if the broadcast failed.
510 */ 568 */
511const struct cpumask *uv_flush_send_and_wait(struct bau_desc *bau_desc, 569int uv_flush_send_and_wait(struct bau_desc *bau_desc,
512 struct cpumask *flush_mask, 570 struct cpumask *flush_mask, struct bau_control *bcp)
513 struct bau_control *bcp)
514{ 571{
515 int right_shift; 572 int right_shift;
516 int uvhub;
517 int bit;
518 int completion_status = 0; 573 int completion_status = 0;
519 int seq_number = 0; 574 int seq_number = 0;
520 long try = 0; 575 long try = 0;
521 int cpu = bcp->uvhub_cpu; 576 int cpu = bcp->uvhub_cpu;
522 int this_cpu = bcp->cpu; 577 int this_cpu = bcp->cpu;
523 int this_uvhub = bcp->uvhub;
524 unsigned long mmr_offset; 578 unsigned long mmr_offset;
525 unsigned long index; 579 unsigned long index;
526 cycles_t time1; 580 cycles_t time1;
527 cycles_t time2; 581 cycles_t time2;
528 struct ptc_stats *stat = &per_cpu(ptcstats, bcp->cpu); 582 cycles_t elapsed;
583 struct ptc_stats *stat = bcp->statp;
529 struct bau_control *smaster = bcp->socket_master; 584 struct bau_control *smaster = bcp->socket_master;
530 struct bau_control *hmaster = bcp->uvhub_master; 585 struct bau_control *hmaster = bcp->uvhub_master;
531 586
532 /*
533 * Spin here while there are hmaster->max_concurrent or more active
534 * descriptors. This is the per-uvhub 'throttle'.
535 */
536 if (!atomic_inc_unless_ge(&hmaster->uvhub_lock, 587 if (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
537 &hmaster->active_descriptor_count, 588 &hmaster->active_descriptor_count,
538 hmaster->max_concurrent)) { 589 hmaster->max_bau_concurrent)) {
539 stat->s_throttles++; 590 stat->s_throttles++;
540 do { 591 do {
541 cpu_relax(); 592 cpu_relax();
542 } while (!atomic_inc_unless_ge(&hmaster->uvhub_lock, 593 } while (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
543 &hmaster->active_descriptor_count, 594 &hmaster->active_descriptor_count,
544 hmaster->max_concurrent)); 595 hmaster->max_bau_concurrent));
545 } 596 }
546
547 while (hmaster->uvhub_quiesce) 597 while (hmaster->uvhub_quiesce)
548 cpu_relax(); 598 cpu_relax();
549 599
@@ -557,23 +607,10 @@ const struct cpumask *uv_flush_send_and_wait(struct bau_desc *bau_desc,
557 } 607 }
558 time1 = get_cycles(); 608 time1 = get_cycles();
559 do { 609 do {
560 /*
561 * Every message from any given cpu gets a unique message
562 * sequence number. But retries use that same number.
563 * Our message may have timed out at the destination because
564 * all sw-ack resources are in use and there is a timeout
565 * pending there. In that case, our last send never got
566 * placed into the queue and we need to persist until it
567 * does.
568 *
569 * Make any retry a type MSG_RETRY so that the destination will
570 * free any resource held by a previous message from this cpu.
571 */
572 if (try == 0) { 610 if (try == 0) {
573 /* use message type set by the caller the first time */ 611 bau_desc->header.msg_type = MSG_REGULAR;
574 seq_number = bcp->message_number++; 612 seq_number = bcp->message_number++;
575 } else { 613 } else {
576 /* use RETRY type on all the rest; same sequence */
577 bau_desc->header.msg_type = MSG_RETRY; 614 bau_desc->header.msg_type = MSG_RETRY;
578 stat->s_retry_messages++; 615 stat->s_retry_messages++;
579 } 616 }
@@ -581,50 +618,17 @@ const struct cpumask *uv_flush_send_and_wait(struct bau_desc *bau_desc,
581 index = (1UL << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) | 618 index = (1UL << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) |
582 bcp->uvhub_cpu; 619 bcp->uvhub_cpu;
583 bcp->send_message = get_cycles(); 620 bcp->send_message = get_cycles();
584
585 uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index); 621 uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index);
586
587 try++; 622 try++;
588 completion_status = uv_wait_completion(bau_desc, mmr_offset, 623 completion_status = uv_wait_completion(bau_desc, mmr_offset,
589 right_shift, this_cpu, bcp, smaster, try); 624 right_shift, this_cpu, bcp, smaster, try);
590 625
591 if (completion_status == FLUSH_RETRY_PLUGGED) { 626 if (completion_status == FLUSH_RETRY_PLUGGED) {
592 /* 627 destination_plugged(bau_desc, bcp, hmaster, stat);
593 * Our retries may be blocked by all destination swack
594 * resources being consumed, and a timeout pending. In
595 * that case hardware immediately returns the ERROR
596 * that looks like a destination timeout.
597 */
598 udelay(TIMEOUT_DELAY);
599 bcp->plugged_tries++;
600 if (bcp->plugged_tries >= PLUGSB4RESET) {
601 bcp->plugged_tries = 0;
602 quiesce_local_uvhub(hmaster);
603 spin_lock(&hmaster->queue_lock);
604 uv_reset_with_ipi(&bau_desc->distribution,
605 this_cpu);
606 spin_unlock(&hmaster->queue_lock);
607 end_uvhub_quiesce(hmaster);
608 bcp->ipi_attempts++;
609 stat->s_resets_plug++;
610 }
611 } else if (completion_status == FLUSH_RETRY_TIMEOUT) { 628 } else if (completion_status == FLUSH_RETRY_TIMEOUT) {
612 hmaster->max_concurrent = 1; 629 destination_timeout(bau_desc, bcp, hmaster, stat);
613 bcp->timeout_tries++;
614 udelay(TIMEOUT_DELAY);
615 if (bcp->timeout_tries >= TIMEOUTSB4RESET) {
616 bcp->timeout_tries = 0;
617 quiesce_local_uvhub(hmaster);
618 spin_lock(&hmaster->queue_lock);
619 uv_reset_with_ipi(&bau_desc->distribution,
620 this_cpu);
621 spin_unlock(&hmaster->queue_lock);
622 end_uvhub_quiesce(hmaster);
623 bcp->ipi_attempts++;
624 stat->s_resets_timeout++;
625 }
626 } 630 }
627 if (bcp->ipi_attempts >= 3) { 631 if (bcp->ipi_attempts >= bcp->ipi_reset_limit) {
628 bcp->ipi_attempts = 0; 632 bcp->ipi_attempts = 0;
629 completion_status = FLUSH_GIVEUP; 633 completion_status = FLUSH_GIVEUP;
630 break; 634 break;
@@ -633,49 +637,36 @@ const struct cpumask *uv_flush_send_and_wait(struct bau_desc *bau_desc,
633 } while ((completion_status == FLUSH_RETRY_PLUGGED) || 637 } while ((completion_status == FLUSH_RETRY_PLUGGED) ||
634 (completion_status == FLUSH_RETRY_TIMEOUT)); 638 (completion_status == FLUSH_RETRY_TIMEOUT));
635 time2 = get_cycles(); 639 time2 = get_cycles();
636 640 bcp->plugged_tries = 0;
637 if ((completion_status == FLUSH_COMPLETE) && (bcp->conseccompletes > 5) 641 bcp->timeout_tries = 0;
638 && (hmaster->max_concurrent < hmaster->max_concurrent_constant)) 642 if ((completion_status == FLUSH_COMPLETE) &&
639 hmaster->max_concurrent++; 643 (bcp->conseccompletes > bcp->complete_threshold) &&
640 644 (hmaster->max_bau_concurrent <
641 /* 645 hmaster->max_bau_concurrent_constant))
642 * hold any cpu not timing out here; no other cpu currently held by 646 hmaster->max_bau_concurrent++;
643 * the 'throttle' should enter the activation code
644 */
645 while (hmaster->uvhub_quiesce) 647 while (hmaster->uvhub_quiesce)
646 cpu_relax(); 648 cpu_relax();
647 atomic_dec(&hmaster->active_descriptor_count); 649 atomic_dec(&hmaster->active_descriptor_count);
648 650 if (time2 > time1) {
649 /* guard against cycles wrap */ 651 elapsed = time2 - time1;
650 if (time2 > time1) 652 stat->s_time += elapsed;
651 stat->s_time += (time2 - time1); 653 if ((completion_status == FLUSH_COMPLETE) && (try == 1)) {
652 else 654 bcp->period_requests++;
653 stat->s_requestor--; /* don't count this one */ 655 bcp->period_time += elapsed;
656 if ((elapsed > congested_cycles) &&
657 (bcp->period_requests > bcp->congested_reps)) {
658 disable_for_congestion(bcp, stat);
659 }
660 }
661 } else
662 stat->s_requestor--;
654 if (completion_status == FLUSH_COMPLETE && try > 1) 663 if (completion_status == FLUSH_COMPLETE && try > 1)
655 stat->s_retriesok++; 664 stat->s_retriesok++;
656 else if (completion_status == FLUSH_GIVEUP) { 665 else if (completion_status == FLUSH_GIVEUP) {
657 /*
658 * Cause the caller to do an IPI-style TLB shootdown on
659 * the target cpu's, all of which are still in the mask.
660 */
661 stat->s_giveup++; 666 stat->s_giveup++;
662 return flush_mask; 667 return 1;
663 }
664
665 /*
666 * Success, so clear the remote cpu's from the mask so we don't
667 * use the IPI method of shootdown on them.
668 */
669 for_each_cpu(bit, flush_mask) {
670 uvhub = uv_cpu_to_blade_id(bit);
671 if (uvhub == this_uvhub)
672 continue;
673 cpumask_clear_cpu(bit, flush_mask);
674 } 668 }
675 if (!cpumask_empty(flush_mask)) 669 return 0;
676 return flush_mask;
677
678 return NULL;
679} 670}
680 671
681/** 672/**
@@ -707,70 +698,89 @@ const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
707 struct mm_struct *mm, 698 struct mm_struct *mm,
708 unsigned long va, unsigned int cpu) 699 unsigned long va, unsigned int cpu)
709{ 700{
710 int remotes;
711 int tcpu; 701 int tcpu;
712 int uvhub; 702 int uvhub;
713 int locals = 0; 703 int locals = 0;
704 int remotes = 0;
705 int hubs = 0;
714 struct bau_desc *bau_desc; 706 struct bau_desc *bau_desc;
715 struct cpumask *flush_mask; 707 struct cpumask *flush_mask;
716 struct ptc_stats *stat; 708 struct ptc_stats *stat;
717 struct bau_control *bcp; 709 struct bau_control *bcp;
710 struct bau_control *tbcp;
718 711
712 /* kernel was booted 'nobau' */
719 if (nobau) 713 if (nobau)
720 return cpumask; 714 return cpumask;
721 715
722 bcp = &per_cpu(bau_control, cpu); 716 bcp = &per_cpu(bau_control, cpu);
717 stat = bcp->statp;
718
719 /* bau was disabled due to slow response */
720 if (bcp->baudisabled) {
721 /* the cpu that disabled it must re-enable it */
722 if (bcp->set_bau_off) {
723 if (get_cycles() >= bcp->set_bau_on_time) {
724 stat->s_bau_reenabled++;
725 baudisabled = 0;
726 for_each_present_cpu(tcpu) {
727 tbcp = &per_cpu(bau_control, tcpu);
728 tbcp->baudisabled = 0;
729 tbcp->period_requests = 0;
730 tbcp->period_time = 0;
731 }
732 }
733 }
734 return cpumask;
735 }
736
723 /* 737 /*
724 * Each sending cpu has a per-cpu mask which it fills from the caller's 738 * Each sending cpu has a per-cpu mask which it fills from the caller's
725 * cpu mask. Only remote cpus are converted to uvhubs and copied. 739 * cpu mask. All cpus are converted to uvhubs and copied to the
740 * activation descriptor.
726 */ 741 */
727 flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu); 742 flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
728 /* 743 /* don't actually do a shootdown of the local cpu */
729 * copy cpumask to flush_mask, removing current cpu
730 * (current cpu should already have been flushed by the caller and
731 * should never be returned if we return flush_mask)
732 */
733 cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu)); 744 cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
734 if (cpu_isset(cpu, *cpumask)) 745 if (cpu_isset(cpu, *cpumask))
735 locals++; /* current cpu was targeted */ 746 stat->s_ntargself++;
736 747
737 bau_desc = bcp->descriptor_base; 748 bau_desc = bcp->descriptor_base;
738 bau_desc += UV_ITEMS_PER_DESCRIPTOR * bcp->uvhub_cpu; 749 bau_desc += UV_ITEMS_PER_DESCRIPTOR * bcp->uvhub_cpu;
739
740 bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE); 750 bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
741 remotes = 0; 751
752 /* cpu statistics */
742 for_each_cpu(tcpu, flush_mask) { 753 for_each_cpu(tcpu, flush_mask) {
743 uvhub = uv_cpu_to_blade_id(tcpu); 754 uvhub = uv_cpu_to_blade_id(tcpu);
744 if (uvhub == bcp->uvhub) {
745 locals++;
746 continue;
747 }
748 bau_uvhub_set(uvhub, &bau_desc->distribution); 755 bau_uvhub_set(uvhub, &bau_desc->distribution);
749 remotes++; 756 if (uvhub == bcp->uvhub)
750 } 757 locals++;
751 if (remotes == 0) {
752 /*
753 * No off_hub flushing; return status for local hub.
754 * Return the caller's mask if all were local (the current
755 * cpu may be in that mask).
756 */
757 if (locals)
758 return cpumask;
759 else 758 else
760 return NULL; 759 remotes++;
761 } 760 }
762 stat = &per_cpu(ptcstats, cpu); 761 if ((locals + remotes) == 0)
762 return NULL;
763 stat->s_requestor++; 763 stat->s_requestor++;
764 stat->s_ntargcpu += remotes; 764 stat->s_ntargcpu += remotes + locals;
765 stat->s_ntargremotes += remotes;
766 stat->s_ntarglocals += locals;
765 remotes = bau_uvhub_weight(&bau_desc->distribution); 767 remotes = bau_uvhub_weight(&bau_desc->distribution);
766 stat->s_ntarguvhub += remotes; 768
767 if (remotes >= 16) 769 /* uvhub statistics */
770 hubs = bau_uvhub_weight(&bau_desc->distribution);
771 if (locals) {
772 stat->s_ntarglocaluvhub++;
773 stat->s_ntargremoteuvhub += (hubs - 1);
774 } else
775 stat->s_ntargremoteuvhub += hubs;
776 stat->s_ntarguvhub += hubs;
777 if (hubs >= 16)
768 stat->s_ntarguvhub16++; 778 stat->s_ntarguvhub16++;
769 else if (remotes >= 8) 779 else if (hubs >= 8)
770 stat->s_ntarguvhub8++; 780 stat->s_ntarguvhub8++;
771 else if (remotes >= 4) 781 else if (hubs >= 4)
772 stat->s_ntarguvhub4++; 782 stat->s_ntarguvhub4++;
773 else if (remotes >= 2) 783 else if (hubs >= 2)
774 stat->s_ntarguvhub2++; 784 stat->s_ntarguvhub2++;
775 else 785 else
776 stat->s_ntarguvhub1++; 786 stat->s_ntarguvhub1++;
@@ -779,10 +789,13 @@ const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
779 bau_desc->payload.sending_cpu = cpu; 789 bau_desc->payload.sending_cpu = cpu;
780 790
781 /* 791 /*
782 * uv_flush_send_and_wait returns null if all cpu's were messaged, or 792 * uv_flush_send_and_wait returns 0 if all cpu's were messaged,
783 * the adjusted flush_mask if any cpu's were not messaged. 793 * or 1 if it gave up and the original cpumask should be returned.
784 */ 794 */
785 return uv_flush_send_and_wait(bau_desc, flush_mask, bcp); 795 if (!uv_flush_send_and_wait(bau_desc, flush_mask, bcp))
796 return NULL;
797 else
798 return cpumask;
786} 799}
787 800
788/* 801/*
@@ -810,7 +823,7 @@ void uv_bau_message_interrupt(struct pt_regs *regs)
810 823
811 time_start = get_cycles(); 824 time_start = get_cycles();
812 bcp = &per_cpu(bau_control, smp_processor_id()); 825 bcp = &per_cpu(bau_control, smp_processor_id());
813 stat = &per_cpu(ptcstats, smp_processor_id()); 826 stat = bcp->statp;
814 msgdesc.va_queue_first = bcp->va_queue_first; 827 msgdesc.va_queue_first = bcp->va_queue_first;
815 msgdesc.va_queue_last = bcp->va_queue_last; 828 msgdesc.va_queue_last = bcp->va_queue_last;
816 msg = bcp->bau_msg_head; 829 msg = bcp->bau_msg_head;
@@ -908,12 +921,12 @@ static void uv_ptc_seq_stop(struct seq_file *file, void *data)
908} 921}
909 922
910static inline unsigned long long 923static inline unsigned long long
911millisec_2_cycles(unsigned long millisec) 924microsec_2_cycles(unsigned long microsec)
912{ 925{
913 unsigned long ns; 926 unsigned long ns;
914 unsigned long long cyc; 927 unsigned long long cyc;
915 928
916 ns = millisec * 1000; 929 ns = microsec * 1000;
917 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id())); 930 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
918 return cyc; 931 return cyc;
919} 932}
@@ -931,15 +944,19 @@ static int uv_ptc_seq_show(struct seq_file *file, void *data)
931 944
932 if (!cpu) { 945 if (!cpu) {
933 seq_printf(file, 946 seq_printf(file,
934 "# cpu sent stime numuvhubs numuvhubs16 numuvhubs8 "); 947 "# cpu sent stime self locals remotes ncpus localhub ");
935 seq_printf(file, 948 seq_printf(file,
936 "numuvhubs4 numuvhubs2 numuvhubs1 numcpus dto "); 949 "remotehub numuvhubs numuvhubs16 numuvhubs8 ");
950 seq_printf(file,
951 "numuvhubs4 numuvhubs2 numuvhubs1 dto ");
937 seq_printf(file, 952 seq_printf(file,
938 "retries rok resetp resett giveup sto bz throt "); 953 "retries rok resetp resett giveup sto bz throt ");
939 seq_printf(file, 954 seq_printf(file,
940 "sw_ack recv rtime all "); 955 "sw_ack recv rtime all ");
941 seq_printf(file, 956 seq_printf(file,
942 "one mult none retry canc nocan reset rcan\n"); 957 "one mult none retry canc nocan reset rcan ");
958 seq_printf(file,
959 "disable enable\n");
943 } 960 }
944 if (cpu < num_possible_cpus() && cpu_online(cpu)) { 961 if (cpu < num_possible_cpus() && cpu_online(cpu)) {
945 stat = &per_cpu(ptcstats, cpu); 962 stat = &per_cpu(ptcstats, cpu);
@@ -947,18 +964,23 @@ static int uv_ptc_seq_show(struct seq_file *file, void *data)
947 seq_printf(file, 964 seq_printf(file,
948 "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ", 965 "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
949 cpu, stat->s_requestor, cycles_2_us(stat->s_time), 966 cpu, stat->s_requestor, cycles_2_us(stat->s_time),
950 stat->s_ntarguvhub, stat->s_ntarguvhub16, 967 stat->s_ntargself, stat->s_ntarglocals,
968 stat->s_ntargremotes, stat->s_ntargcpu,
969 stat->s_ntarglocaluvhub, stat->s_ntargremoteuvhub,
970 stat->s_ntarguvhub, stat->s_ntarguvhub16);
971 seq_printf(file, "%ld %ld %ld %ld %ld ",
951 stat->s_ntarguvhub8, stat->s_ntarguvhub4, 972 stat->s_ntarguvhub8, stat->s_ntarguvhub4,
952 stat->s_ntarguvhub2, stat->s_ntarguvhub1, 973 stat->s_ntarguvhub2, stat->s_ntarguvhub1,
953 stat->s_ntargcpu, stat->s_dtimeout); 974 stat->s_dtimeout);
954 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ", 975 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
955 stat->s_retry_messages, stat->s_retriesok, 976 stat->s_retry_messages, stat->s_retriesok,
956 stat->s_resets_plug, stat->s_resets_timeout, 977 stat->s_resets_plug, stat->s_resets_timeout,
957 stat->s_giveup, stat->s_stimeout, 978 stat->s_giveup, stat->s_stimeout,
958 stat->s_busy, stat->s_throttles); 979 stat->s_busy, stat->s_throttles);
980
959 /* destination side statistics */ 981 /* destination side statistics */
960 seq_printf(file, 982 seq_printf(file,
961 "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\n", 983 "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
962 uv_read_global_mmr64(uv_cpu_to_pnode(cpu), 984 uv_read_global_mmr64(uv_cpu_to_pnode(cpu),
963 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE), 985 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE),
964 stat->d_requestee, cycles_2_us(stat->d_time), 986 stat->d_requestee, cycles_2_us(stat->d_time),
@@ -966,15 +988,36 @@ static int uv_ptc_seq_show(struct seq_file *file, void *data)
966 stat->d_nomsg, stat->d_retries, stat->d_canceled, 988 stat->d_nomsg, stat->d_retries, stat->d_canceled,
967 stat->d_nocanceled, stat->d_resets, 989 stat->d_nocanceled, stat->d_resets,
968 stat->d_rcanceled); 990 stat->d_rcanceled);
991 seq_printf(file, "%ld %ld\n",
992 stat->s_bau_disabled, stat->s_bau_reenabled);
969 } 993 }
970 994
971 return 0; 995 return 0;
972} 996}
973 997
974/* 998/*
999 * Display the tunables thru debugfs
1000 */
1001static ssize_t tunables_read(struct file *file, char __user *userbuf,
1002 size_t count, loff_t *ppos)
1003{
1004 char buf[300];
1005 int ret;
1006
1007 ret = snprintf(buf, 300, "%s %s %s\n%d %d %d %d %d %d %d %d %d\n",
1008 "max_bau_concurrent plugged_delay plugsb4reset",
1009 "timeoutsb4reset ipi_reset_limit complete_threshold",
1010 "congested_response_us congested_reps congested_period",
1011 max_bau_concurrent, plugged_delay, plugsb4reset,
1012 timeoutsb4reset, ipi_reset_limit, complete_threshold,
1013 congested_response_us, congested_reps, congested_period);
1014
1015 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
1016}
1017
1018/*
975 * -1: resetf the statistics 1019 * -1: resetf the statistics
976 * 0: display meaning of the statistics 1020 * 0: display meaning of the statistics
977 * >0: maximum concurrent active descriptors per uvhub (throttle)
978 */ 1021 */
979static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user, 1022static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
980 size_t count, loff_t *data) 1023 size_t count, loff_t *data)
@@ -983,7 +1026,6 @@ static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
983 long input_arg; 1026 long input_arg;
984 char optstr[64]; 1027 char optstr[64];
985 struct ptc_stats *stat; 1028 struct ptc_stats *stat;
986 struct bau_control *bcp;
987 1029
988 if (count == 0 || count > sizeof(optstr)) 1030 if (count == 0 || count > sizeof(optstr))
989 return -EINVAL; 1031 return -EINVAL;
@@ -1059,29 +1101,158 @@ static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
1059 "reset: number of ipi-style reset requests processed\n"); 1101 "reset: number of ipi-style reset requests processed\n");
1060 printk(KERN_DEBUG 1102 printk(KERN_DEBUG
1061 "rcan: number messages canceled by reset requests\n"); 1103 "rcan: number messages canceled by reset requests\n");
1104 printk(KERN_DEBUG
1105 "disable: number times use of the BAU was disabled\n");
1106 printk(KERN_DEBUG
1107 "enable: number times use of the BAU was re-enabled\n");
1062 } else if (input_arg == -1) { 1108 } else if (input_arg == -1) {
1063 for_each_present_cpu(cpu) { 1109 for_each_present_cpu(cpu) {
1064 stat = &per_cpu(ptcstats, cpu); 1110 stat = &per_cpu(ptcstats, cpu);
1065 memset(stat, 0, sizeof(struct ptc_stats)); 1111 memset(stat, 0, sizeof(struct ptc_stats));
1066 } 1112 }
1067 } else { 1113 }
1068 uv_bau_max_concurrent = input_arg; 1114
1069 bcp = &per_cpu(bau_control, smp_processor_id()); 1115 return count;
1070 if (uv_bau_max_concurrent < 1 || 1116}
1071 uv_bau_max_concurrent > bcp->cpus_in_uvhub) { 1117
1072 printk(KERN_DEBUG 1118static int local_atoi(const char *name)
1073 "Error: BAU max concurrent %d; %d is invalid\n", 1119{
1074 bcp->max_concurrent, uv_bau_max_concurrent); 1120 int val = 0;
1075 return -EINVAL; 1121
1076 } 1122 for (;; name++) {
1077 printk(KERN_DEBUG "Set BAU max concurrent:%d\n", 1123 switch (*name) {
1078 uv_bau_max_concurrent); 1124 case '0' ... '9':
1079 for_each_present_cpu(cpu) { 1125 val = 10*val+(*name-'0');
1080 bcp = &per_cpu(bau_control, cpu); 1126 break;
1081 bcp->max_concurrent = uv_bau_max_concurrent; 1127 default:
1128 return val;
1082 } 1129 }
1083 } 1130 }
1131}
1132
1133/*
1134 * set the tunables
1135 * 0 values reset them to defaults
1136 */
1137static ssize_t tunables_write(struct file *file, const char __user *user,
1138 size_t count, loff_t *data)
1139{
1140 int cpu;
1141 int cnt = 0;
1142 int val;
1143 char *p;
1144 char *q;
1145 char instr[64];
1146 struct bau_control *bcp;
1147
1148 if (count == 0 || count > sizeof(instr)-1)
1149 return -EINVAL;
1150 if (copy_from_user(instr, user, count))
1151 return -EFAULT;
1152
1153 instr[count] = '\0';
1154 /* count the fields */
1155 p = instr + strspn(instr, WHITESPACE);
1156 q = p;
1157 for (; *p; p = q + strspn(q, WHITESPACE)) {
1158 q = p + strcspn(p, WHITESPACE);
1159 cnt++;
1160 if (q == p)
1161 break;
1162 }
1163 if (cnt != 9) {
1164 printk(KERN_INFO "bau tunable error: should be 9 numbers\n");
1165 return -EINVAL;
1166 }
1084 1167
1168 p = instr + strspn(instr, WHITESPACE);
1169 q = p;
1170 for (cnt = 0; *p; p = q + strspn(q, WHITESPACE), cnt++) {
1171 q = p + strcspn(p, WHITESPACE);
1172 val = local_atoi(p);
1173 switch (cnt) {
1174 case 0:
1175 if (val == 0) {
1176 max_bau_concurrent = MAX_BAU_CONCURRENT;
1177 max_bau_concurrent_constant =
1178 MAX_BAU_CONCURRENT;
1179 continue;
1180 }
1181 bcp = &per_cpu(bau_control, smp_processor_id());
1182 if (val < 1 || val > bcp->cpus_in_uvhub) {
1183 printk(KERN_DEBUG
1184 "Error: BAU max concurrent %d is invalid\n",
1185 val);
1186 return -EINVAL;
1187 }
1188 max_bau_concurrent = val;
1189 max_bau_concurrent_constant = val;
1190 continue;
1191 case 1:
1192 if (val == 0)
1193 plugged_delay = PLUGGED_DELAY;
1194 else
1195 plugged_delay = val;
1196 continue;
1197 case 2:
1198 if (val == 0)
1199 plugsb4reset = PLUGSB4RESET;
1200 else
1201 plugsb4reset = val;
1202 continue;
1203 case 3:
1204 if (val == 0)
1205 timeoutsb4reset = TIMEOUTSB4RESET;
1206 else
1207 timeoutsb4reset = val;
1208 continue;
1209 case 4:
1210 if (val == 0)
1211 ipi_reset_limit = IPI_RESET_LIMIT;
1212 else
1213 ipi_reset_limit = val;
1214 continue;
1215 case 5:
1216 if (val == 0)
1217 complete_threshold = COMPLETE_THRESHOLD;
1218 else
1219 complete_threshold = val;
1220 continue;
1221 case 6:
1222 if (val == 0)
1223 congested_response_us = CONGESTED_RESPONSE_US;
1224 else
1225 congested_response_us = val;
1226 continue;
1227 case 7:
1228 if (val == 0)
1229 congested_reps = CONGESTED_REPS;
1230 else
1231 congested_reps = val;
1232 continue;
1233 case 8:
1234 if (val == 0)
1235 congested_period = CONGESTED_PERIOD;
1236 else
1237 congested_period = val;
1238 continue;
1239 }
1240 if (q == p)
1241 break;
1242 }
1243 for_each_present_cpu(cpu) {
1244 bcp = &per_cpu(bau_control, cpu);
1245 bcp->max_bau_concurrent = max_bau_concurrent;
1246 bcp->max_bau_concurrent_constant = max_bau_concurrent;
1247 bcp->plugged_delay = plugged_delay;
1248 bcp->plugsb4reset = plugsb4reset;
1249 bcp->timeoutsb4reset = timeoutsb4reset;
1250 bcp->ipi_reset_limit = ipi_reset_limit;
1251 bcp->complete_threshold = complete_threshold;
1252 bcp->congested_response_us = congested_response_us;
1253 bcp->congested_reps = congested_reps;
1254 bcp->congested_period = congested_period;
1255 }
1085 return count; 1256 return count;
1086} 1257}
1087 1258
@@ -1097,6 +1268,11 @@ static int uv_ptc_proc_open(struct inode *inode, struct file *file)
1097 return seq_open(file, &uv_ptc_seq_ops); 1268 return seq_open(file, &uv_ptc_seq_ops);
1098} 1269}
1099 1270
1271static int tunables_open(struct inode *inode, struct file *file)
1272{
1273 return 0;
1274}
1275
1100static const struct file_operations proc_uv_ptc_operations = { 1276static const struct file_operations proc_uv_ptc_operations = {
1101 .open = uv_ptc_proc_open, 1277 .open = uv_ptc_proc_open,
1102 .read = seq_read, 1278 .read = seq_read,
@@ -1105,6 +1281,12 @@ static const struct file_operations proc_uv_ptc_operations = {
1105 .release = seq_release, 1281 .release = seq_release,
1106}; 1282};
1107 1283
1284static const struct file_operations tunables_fops = {
1285 .open = tunables_open,
1286 .read = tunables_read,
1287 .write = tunables_write,
1288};
1289
1108static int __init uv_ptc_init(void) 1290static int __init uv_ptc_init(void)
1109{ 1291{
1110 struct proc_dir_entry *proc_uv_ptc; 1292 struct proc_dir_entry *proc_uv_ptc;
@@ -1119,6 +1301,20 @@ static int __init uv_ptc_init(void)
1119 UV_PTC_BASENAME); 1301 UV_PTC_BASENAME);
1120 return -EINVAL; 1302 return -EINVAL;
1121 } 1303 }
1304
1305 tunables_dir = debugfs_create_dir(UV_BAU_TUNABLES_DIR, NULL);
1306 if (!tunables_dir) {
1307 printk(KERN_ERR "unable to create debugfs directory %s\n",
1308 UV_BAU_TUNABLES_DIR);
1309 return -EINVAL;
1310 }
1311 tunables_file = debugfs_create_file(UV_BAU_TUNABLES_FILE, 0600,
1312 tunables_dir, NULL, &tunables_fops);
1313 if (!tunables_file) {
1314 printk(KERN_ERR "unable to create debugfs file %s\n",
1315 UV_BAU_TUNABLES_FILE);
1316 return -EINVAL;
1317 }
1122 return 0; 1318 return 0;
1123} 1319}
1124 1320
@@ -1259,15 +1455,44 @@ static void __init uv_init_uvhub(int uvhub, int vector)
1259} 1455}
1260 1456
1261/* 1457/*
1458 * We will set BAU_MISC_CONTROL with a timeout period.
1459 * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
1460 * So the destination timeout period has be be calculated from them.
1461 */
1462static int
1463calculate_destination_timeout(void)
1464{
1465 unsigned long mmr_image;
1466 int mult1;
1467 int mult2;
1468 int index;
1469 int base;
1470 int ret;
1471 unsigned long ts_ns;
1472
1473 mult1 = UV_INTD_SOFT_ACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK;
1474 mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
1475 index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK;
1476 mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT);
1477 mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK;
1478 base = timeout_base_ns[index];
1479 ts_ns = base * mult1 * mult2;
1480 ret = ts_ns / 1000;
1481 return ret;
1482}
1483
1484/*
1262 * initialize the bau_control structure for each cpu 1485 * initialize the bau_control structure for each cpu
1263 */ 1486 */
1264static void uv_init_per_cpu(int nuvhubs) 1487static void uv_init_per_cpu(int nuvhubs)
1265{ 1488{
1266 int i, j, k; 1489 int i;
1267 int cpu; 1490 int cpu;
1268 int pnode; 1491 int pnode;
1269 int uvhub; 1492 int uvhub;
1270 short socket = 0; 1493 short socket = 0;
1494 unsigned short socket_mask;
1495 unsigned int uvhub_mask;
1271 struct bau_control *bcp; 1496 struct bau_control *bcp;
1272 struct uvhub_desc *bdp; 1497 struct uvhub_desc *bdp;
1273 struct socket_desc *sdp; 1498 struct socket_desc *sdp;
@@ -1278,7 +1503,7 @@ static void uv_init_per_cpu(int nuvhubs)
1278 short cpu_number[16]; 1503 short cpu_number[16];
1279 }; 1504 };
1280 struct uvhub_desc { 1505 struct uvhub_desc {
1281 short num_sockets; 1506 unsigned short socket_mask;
1282 short num_cpus; 1507 short num_cpus;
1283 short uvhub; 1508 short uvhub;
1284 short pnode; 1509 short pnode;
@@ -1286,57 +1511,83 @@ static void uv_init_per_cpu(int nuvhubs)
1286 }; 1511 };
1287 struct uvhub_desc *uvhub_descs; 1512 struct uvhub_desc *uvhub_descs;
1288 1513
1514 timeout_us = calculate_destination_timeout();
1515
1289 uvhub_descs = (struct uvhub_desc *) 1516 uvhub_descs = (struct uvhub_desc *)
1290 kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL); 1517 kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
1291 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc)); 1518 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
1292 for_each_present_cpu(cpu) { 1519 for_each_present_cpu(cpu) {
1293 bcp = &per_cpu(bau_control, cpu); 1520 bcp = &per_cpu(bau_control, cpu);
1294 memset(bcp, 0, sizeof(struct bau_control)); 1521 memset(bcp, 0, sizeof(struct bau_control));
1295 spin_lock_init(&bcp->masks_lock);
1296 bcp->max_concurrent = uv_bau_max_concurrent;
1297 pnode = uv_cpu_hub_info(cpu)->pnode; 1522 pnode = uv_cpu_hub_info(cpu)->pnode;
1298 uvhub = uv_cpu_hub_info(cpu)->numa_blade_id; 1523 uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
1524 uvhub_mask |= (1 << uvhub);
1299 bdp = &uvhub_descs[uvhub]; 1525 bdp = &uvhub_descs[uvhub];
1300 bdp->num_cpus++; 1526 bdp->num_cpus++;
1301 bdp->uvhub = uvhub; 1527 bdp->uvhub = uvhub;
1302 bdp->pnode = pnode; 1528 bdp->pnode = pnode;
1303 /* time interval to catch a hardware stay-busy bug */ 1529 /* kludge: 'assuming' one node per socket, and assuming that
1304 bcp->timeout_interval = millisec_2_cycles(3); 1530 disabling a socket just leaves a gap in node numbers */
1305 /* kludge: assume uv_hub.h is constant */ 1531 socket = (cpu_to_node(cpu) & 1);;
1306 socket = (cpu_physical_id(cpu)>>5)&1; 1532 bdp->socket_mask |= (1 << socket);
1307 if (socket >= bdp->num_sockets)
1308 bdp->num_sockets = socket+1;
1309 sdp = &bdp->socket[socket]; 1533 sdp = &bdp->socket[socket];
1310 sdp->cpu_number[sdp->num_cpus] = cpu; 1534 sdp->cpu_number[sdp->num_cpus] = cpu;
1311 sdp->num_cpus++; 1535 sdp->num_cpus++;
1312 } 1536 }
1313 socket = 0; 1537 uvhub = 0;
1314 for_each_possible_blade(uvhub) { 1538 while (uvhub_mask) {
1539 if (!(uvhub_mask & 1))
1540 goto nexthub;
1315 bdp = &uvhub_descs[uvhub]; 1541 bdp = &uvhub_descs[uvhub];
1316 for (i = 0; i < bdp->num_sockets; i++) { 1542 socket_mask = bdp->socket_mask;
1317 sdp = &bdp->socket[i]; 1543 socket = 0;
1318 for (j = 0; j < sdp->num_cpus; j++) { 1544 while (socket_mask) {
1319 cpu = sdp->cpu_number[j]; 1545 if (!(socket_mask & 1))
1546 goto nextsocket;
1547 sdp = &bdp->socket[socket];
1548 for (i = 0; i < sdp->num_cpus; i++) {
1549 cpu = sdp->cpu_number[i];
1320 bcp = &per_cpu(bau_control, cpu); 1550 bcp = &per_cpu(bau_control, cpu);
1321 bcp->cpu = cpu; 1551 bcp->cpu = cpu;
1322 if (j == 0) { 1552 if (i == 0) {
1323 smaster = bcp; 1553 smaster = bcp;
1324 if (i == 0) 1554 if (socket == 0)
1325 hmaster = bcp; 1555 hmaster = bcp;
1326 } 1556 }
1327 bcp->cpus_in_uvhub = bdp->num_cpus; 1557 bcp->cpus_in_uvhub = bdp->num_cpus;
1328 bcp->cpus_in_socket = sdp->num_cpus; 1558 bcp->cpus_in_socket = sdp->num_cpus;
1329 bcp->socket_master = smaster; 1559 bcp->socket_master = smaster;
1560 bcp->uvhub = bdp->uvhub;
1330 bcp->uvhub_master = hmaster; 1561 bcp->uvhub_master = hmaster;
1331 for (k = 0; k < DEST_Q_SIZE; k++) 1562 bcp->uvhub_cpu = uv_cpu_hub_info(cpu)->
1332 bcp->socket_acknowledge_count[k] = 0; 1563 blade_processor_id;
1333 bcp->uvhub_cpu =
1334 uv_cpu_hub_info(cpu)->blade_processor_id;
1335 } 1564 }
1565nextsocket:
1336 socket++; 1566 socket++;
1567 socket_mask = (socket_mask >> 1);
1337 } 1568 }
1569nexthub:
1570 uvhub++;
1571 uvhub_mask = (uvhub_mask >> 1);
1338 } 1572 }
1339 kfree(uvhub_descs); 1573 kfree(uvhub_descs);
1574 for_each_present_cpu(cpu) {
1575 bcp = &per_cpu(bau_control, cpu);
1576 bcp->baudisabled = 0;
1577 bcp->statp = &per_cpu(ptcstats, cpu);
1578 /* time interval to catch a hardware stay-busy bug */
1579 bcp->timeout_interval = microsec_2_cycles(2*timeout_us);
1580 bcp->max_bau_concurrent = max_bau_concurrent;
1581 bcp->max_bau_concurrent_constant = max_bau_concurrent;
1582 bcp->plugged_delay = plugged_delay;
1583 bcp->plugsb4reset = plugsb4reset;
1584 bcp->timeoutsb4reset = timeoutsb4reset;
1585 bcp->ipi_reset_limit = ipi_reset_limit;
1586 bcp->complete_threshold = complete_threshold;
1587 bcp->congested_response_us = congested_response_us;
1588 bcp->congested_reps = congested_reps;
1589 bcp->congested_period = congested_period;
1590 }
1340} 1591}
1341 1592
1342/* 1593/*
@@ -1361,10 +1612,11 @@ static int __init uv_bau_init(void)
1361 zalloc_cpumask_var_node(&per_cpu(uv_flush_tlb_mask, cur_cpu), 1612 zalloc_cpumask_var_node(&per_cpu(uv_flush_tlb_mask, cur_cpu),
1362 GFP_KERNEL, cpu_to_node(cur_cpu)); 1613 GFP_KERNEL, cpu_to_node(cur_cpu));
1363 1614
1364 uv_bau_max_concurrent = MAX_BAU_CONCURRENT;
1365 uv_nshift = uv_hub_info->m_val; 1615 uv_nshift = uv_hub_info->m_val;
1366 uv_mmask = (1UL << uv_hub_info->m_val) - 1; 1616 uv_mmask = (1UL << uv_hub_info->m_val) - 1;
1367 nuvhubs = uv_num_possible_blades(); 1617 nuvhubs = uv_num_possible_blades();
1618 spin_lock_init(&disable_lock);
1619 congested_cycles = microsec_2_cycles(congested_response_us);
1368 1620
1369 uv_init_per_cpu(nuvhubs); 1621 uv_init_per_cpu(nuvhubs);
1370 1622
@@ -1383,15 +1635,19 @@ static int __init uv_bau_init(void)
1383 alloc_intr_gate(vector, uv_bau_message_intr1); 1635 alloc_intr_gate(vector, uv_bau_message_intr1);
1384 1636
1385 for_each_possible_blade(uvhub) { 1637 for_each_possible_blade(uvhub) {
1386 pnode = uv_blade_to_pnode(uvhub); 1638 if (uv_blade_nr_possible_cpus(uvhub)) {
1387 /* INIT the bau */ 1639 pnode = uv_blade_to_pnode(uvhub);
1388 uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_ACTIVATION_CONTROL, 1640 /* INIT the bau */
1389 ((unsigned long)1 << 63)); 1641 uv_write_global_mmr64(pnode,
1390 mmr = 1; /* should be 1 to broadcast to both sockets */ 1642 UVH_LB_BAU_SB_ACTIVATION_CONTROL,
1391 uv_write_global_mmr64(pnode, UVH_BAU_DATA_BROADCAST, mmr); 1643 ((unsigned long)1 << 63));
1644 mmr = 1; /* should be 1 to broadcast to both sockets */
1645 uv_write_global_mmr64(pnode, UVH_BAU_DATA_BROADCAST,
1646 mmr);
1647 }
1392 } 1648 }
1393 1649
1394 return 0; 1650 return 0;
1395} 1651}
1396core_initcall(uv_bau_init); 1652core_initcall(uv_bau_init);
1397core_initcall(uv_ptc_init); 1653fs_initcall(uv_ptc_init);
diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
index 4a5979aa6883..2cda60a06e65 100644
--- a/arch/x86/lib/atomic64_386_32.S
+++ b/arch/x86/lib/atomic64_386_32.S
@@ -25,150 +25,172 @@
25 CFI_ADJUST_CFA_OFFSET -4 25 CFI_ADJUST_CFA_OFFSET -4
26.endm 26.endm
27 27
28.macro BEGIN func reg 28#define BEGIN(op) \
29$v = \reg 29.macro endp; \
30 30 CFI_ENDPROC; \
31ENTRY(atomic64_\func\()_386) 31ENDPROC(atomic64_##op##_386); \
32 CFI_STARTPROC 32.purgem endp; \
33 LOCK $v 33.endm; \
34 34ENTRY(atomic64_##op##_386); \
35.macro RETURN 35 CFI_STARTPROC; \
36 UNLOCK $v 36 LOCK v;
37
38#define ENDP endp
39
40#define RET \
41 UNLOCK v; \
37 ret 42 ret
38.endm
39
40.macro END_
41 CFI_ENDPROC
42ENDPROC(atomic64_\func\()_386)
43.purgem RETURN
44.purgem END_
45.purgem END
46.endm
47
48.macro END
49RETURN
50END_
51.endm
52.endm
53 43
54BEGIN read %ecx 44#define RET_ENDP \
55 movl ($v), %eax 45 RET; \
56 movl 4($v), %edx 46 ENDP
57END 47
58 48#define v %ecx
59BEGIN set %esi 49BEGIN(read)
60 movl %ebx, ($v) 50 movl (v), %eax
61 movl %ecx, 4($v) 51 movl 4(v), %edx
62END 52RET_ENDP
63 53#undef v
64BEGIN xchg %esi 54
65 movl ($v), %eax 55#define v %esi
66 movl 4($v), %edx 56BEGIN(set)
67 movl %ebx, ($v) 57 movl %ebx, (v)
68 movl %ecx, 4($v) 58 movl %ecx, 4(v)
69END 59RET_ENDP
70 60#undef v
71BEGIN add %ecx 61
72 addl %eax, ($v) 62#define v %esi
73 adcl %edx, 4($v) 63BEGIN(xchg)
74END 64 movl (v), %eax
75 65 movl 4(v), %edx
76BEGIN add_return %ecx 66 movl %ebx, (v)
77 addl ($v), %eax 67 movl %ecx, 4(v)
78 adcl 4($v), %edx 68RET_ENDP
79 movl %eax, ($v) 69#undef v
80 movl %edx, 4($v) 70
81END 71#define v %ecx
82 72BEGIN(add)
83BEGIN sub %ecx 73 addl %eax, (v)
84 subl %eax, ($v) 74 adcl %edx, 4(v)
85 sbbl %edx, 4($v) 75RET_ENDP
86END 76#undef v
87 77
88BEGIN sub_return %ecx 78#define v %ecx
79BEGIN(add_return)
80 addl (v), %eax
81 adcl 4(v), %edx
82 movl %eax, (v)
83 movl %edx, 4(v)
84RET_ENDP
85#undef v
86
87#define v %ecx
88BEGIN(sub)
89 subl %eax, (v)
90 sbbl %edx, 4(v)
91RET_ENDP
92#undef v
93
94#define v %ecx
95BEGIN(sub_return)
89 negl %edx 96 negl %edx
90 negl %eax 97 negl %eax
91 sbbl $0, %edx 98 sbbl $0, %edx
92 addl ($v), %eax 99 addl (v), %eax
93 adcl 4($v), %edx 100 adcl 4(v), %edx
94 movl %eax, ($v) 101 movl %eax, (v)
95 movl %edx, 4($v) 102 movl %edx, 4(v)
96END 103RET_ENDP
97 104#undef v
98BEGIN inc %esi 105
99 addl $1, ($v) 106#define v %esi
100 adcl $0, 4($v) 107BEGIN(inc)
101END 108 addl $1, (v)
102 109 adcl $0, 4(v)
103BEGIN inc_return %esi 110RET_ENDP
104 movl ($v), %eax 111#undef v
105 movl 4($v), %edx 112
113#define v %esi
114BEGIN(inc_return)
115 movl (v), %eax
116 movl 4(v), %edx
106 addl $1, %eax 117 addl $1, %eax
107 adcl $0, %edx 118 adcl $0, %edx
108 movl %eax, ($v) 119 movl %eax, (v)
109 movl %edx, 4($v) 120 movl %edx, 4(v)
110END 121RET_ENDP
111 122#undef v
112BEGIN dec %esi 123
113 subl $1, ($v) 124#define v %esi
114 sbbl $0, 4($v) 125BEGIN(dec)
115END 126 subl $1, (v)
116 127 sbbl $0, 4(v)
117BEGIN dec_return %esi 128RET_ENDP
118 movl ($v), %eax 129#undef v
119 movl 4($v), %edx 130
131#define v %esi
132BEGIN(dec_return)
133 movl (v), %eax
134 movl 4(v), %edx
120 subl $1, %eax 135 subl $1, %eax
121 sbbl $0, %edx 136 sbbl $0, %edx
122 movl %eax, ($v) 137 movl %eax, (v)
123 movl %edx, 4($v) 138 movl %edx, 4(v)
124END 139RET_ENDP
140#undef v
125 141
126BEGIN add_unless %ecx 142#define v %ecx
143BEGIN(add_unless)
127 addl %eax, %esi 144 addl %eax, %esi
128 adcl %edx, %edi 145 adcl %edx, %edi
129 addl ($v), %eax 146 addl (v), %eax
130 adcl 4($v), %edx 147 adcl 4(v), %edx
131 cmpl %eax, %esi 148 cmpl %eax, %esi
132 je 3f 149 je 3f
1331: 1501:
134 movl %eax, ($v) 151 movl %eax, (v)
135 movl %edx, 4($v) 152 movl %edx, 4(v)
136 movl $1, %eax 153 movl $1, %eax
1372: 1542:
138RETURN 155 RET
1393: 1563:
140 cmpl %edx, %edi 157 cmpl %edx, %edi
141 jne 1b 158 jne 1b
142 xorl %eax, %eax 159 xorl %eax, %eax
143 jmp 2b 160 jmp 2b
144END_ 161ENDP
162#undef v
145 163
146BEGIN inc_not_zero %esi 164#define v %esi
147 movl ($v), %eax 165BEGIN(inc_not_zero)
148 movl 4($v), %edx 166 movl (v), %eax
167 movl 4(v), %edx
149 testl %eax, %eax 168 testl %eax, %eax
150 je 3f 169 je 3f
1511: 1701:
152 addl $1, %eax 171 addl $1, %eax
153 adcl $0, %edx 172 adcl $0, %edx
154 movl %eax, ($v) 173 movl %eax, (v)
155 movl %edx, 4($v) 174 movl %edx, 4(v)
156 movl $1, %eax 175 movl $1, %eax
1572: 1762:
158RETURN 177 RET
1593: 1783:
160 testl %edx, %edx 179 testl %edx, %edx
161 jne 1b 180 jne 1b
162 jmp 2b 181 jmp 2b
163END_ 182ENDP
183#undef v
164 184
165BEGIN dec_if_positive %esi 185#define v %esi
166 movl ($v), %eax 186BEGIN(dec_if_positive)
167 movl 4($v), %edx 187 movl (v), %eax
188 movl 4(v), %edx
168 subl $1, %eax 189 subl $1, %eax
169 sbbl $0, %edx 190 sbbl $0, %edx
170 js 1f 191 js 1f
171 movl %eax, ($v) 192 movl %eax, (v)
172 movl %edx, 4($v) 193 movl %edx, 4(v)
1731: 1941:
174END 195RET_ENDP
196#undef v
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index f62777940dfb..4c4508e8a204 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -802,8 +802,10 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
802 up_read(&mm->mmap_sem); 802 up_read(&mm->mmap_sem);
803 803
804 /* Kernel mode? Handle exceptions or die: */ 804 /* Kernel mode? Handle exceptions or die: */
805 if (!(error_code & PF_USER)) 805 if (!(error_code & PF_USER)) {
806 no_context(regs, error_code, address); 806 no_context(regs, error_code, address);
807 return;
808 }
807 809
808 /* User-space => ok to do another page fault: */ 810 /* User-space => ok to do another page fault: */
809 if (is_prefetch(regs, error_code, address)) 811 if (is_prefetch(regs, error_code, address))
diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
index 1ba67dc8006a..f6b48f6c5951 100644
--- a/arch/x86/oprofile/nmi_int.c
+++ b/arch/x86/oprofile/nmi_int.c
@@ -668,6 +668,7 @@ static int __init ppro_init(char **cpu_type)
668 *cpu_type = "i386/core_2"; 668 *cpu_type = "i386/core_2";
669 break; 669 break;
670 case 0x1a: 670 case 0x1a:
671 case 0x1e:
671 case 0x2e: 672 case 0x2e:
672 spec = &op_arch_perfmon_spec; 673 spec = &op_arch_perfmon_spec;
673 *cpu_type = "i386/core_i7"; 674 *cpu_type = "i386/core_i7";
diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile
index 930954685980..779385158915 100644
--- a/arch/x86/xen/Makefile
+++ b/arch/x86/xen/Makefile
@@ -18,3 +18,4 @@ obj-$(CONFIG_SMP) += smp.o
18obj-$(CONFIG_PARAVIRT_SPINLOCKS)+= spinlock.o 18obj-$(CONFIG_PARAVIRT_SPINLOCKS)+= spinlock.o
19obj-$(CONFIG_XEN_DEBUG_FS) += debugfs.o 19obj-$(CONFIG_XEN_DEBUG_FS) += debugfs.o
20 20
21obj-$(CONFIG_SWIOTLB_XEN) += pci-swiotlb-xen.o
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index d4ff5e83621d..7d46c8441418 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -1172,6 +1172,10 @@ asmlinkage void __init xen_start_kernel(void)
1172 1172
1173 pgd = (pgd_t *)xen_start_info->pt_base; 1173 pgd = (pgd_t *)xen_start_info->pt_base;
1174 1174
1175 if (!xen_initial_domain())
1176 __supported_pte_mask &= ~(_PAGE_PWT | _PAGE_PCD);
1177
1178 __supported_pte_mask |= _PAGE_IOMAP;
1175 /* Don't do the full vcpu_info placement stuff until we have a 1179 /* Don't do the full vcpu_info placement stuff until we have a
1176 possible map and a non-dummy shared_info. */ 1180 possible map and a non-dummy shared_info. */
1177 per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0]; 1181 per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0];
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
index 413b19b3d0fe..42086ac406af 100644
--- a/arch/x86/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
@@ -42,6 +42,7 @@
42#include <linux/highmem.h> 42#include <linux/highmem.h>
43#include <linux/debugfs.h> 43#include <linux/debugfs.h>
44#include <linux/bug.h> 44#include <linux/bug.h>
45#include <linux/vmalloc.h>
45#include <linux/module.h> 46#include <linux/module.h>
46#include <linux/gfp.h> 47#include <linux/gfp.h>
47 48
@@ -51,15 +52,19 @@
51#include <asm/mmu_context.h> 52#include <asm/mmu_context.h>
52#include <asm/setup.h> 53#include <asm/setup.h>
53#include <asm/paravirt.h> 54#include <asm/paravirt.h>
55#include <asm/e820.h>
54#include <asm/linkage.h> 56#include <asm/linkage.h>
57#include <asm/page.h>
55 58
56#include <asm/xen/hypercall.h> 59#include <asm/xen/hypercall.h>
57#include <asm/xen/hypervisor.h> 60#include <asm/xen/hypervisor.h>
58 61
62#include <xen/xen.h>
59#include <xen/page.h> 63#include <xen/page.h>
60#include <xen/interface/xen.h> 64#include <xen/interface/xen.h>
61#include <xen/interface/hvm/hvm_op.h> 65#include <xen/interface/hvm/hvm_op.h>
62#include <xen/interface/version.h> 66#include <xen/interface/version.h>
67#include <xen/interface/memory.h>
63#include <xen/hvc-console.h> 68#include <xen/hvc-console.h>
64 69
65#include "multicalls.h" 70#include "multicalls.h"
@@ -68,6 +73,13 @@
68 73
69#define MMU_UPDATE_HISTO 30 74#define MMU_UPDATE_HISTO 30
70 75
76/*
77 * Protects atomic reservation decrease/increase against concurrent increases.
78 * Also protects non-atomic updates of current_pages and driver_pages, and
79 * balloon lists.
80 */
81DEFINE_SPINLOCK(xen_reservation_lock);
82
71#ifdef CONFIG_XEN_DEBUG_FS 83#ifdef CONFIG_XEN_DEBUG_FS
72 84
73static struct { 85static struct {
@@ -378,6 +390,28 @@ static bool xen_page_pinned(void *ptr)
378 return PagePinned(page); 390 return PagePinned(page);
379} 391}
380 392
393static bool xen_iomap_pte(pte_t pte)
394{
395 return pte_flags(pte) & _PAGE_IOMAP;
396}
397
398static void xen_set_iomap_pte(pte_t *ptep, pte_t pteval)
399{
400 struct multicall_space mcs;
401 struct mmu_update *u;
402
403 mcs = xen_mc_entry(sizeof(*u));
404 u = mcs.args;
405
406 /* ptep might be kmapped when using 32-bit HIGHPTE */
407 u->ptr = arbitrary_virt_to_machine(ptep).maddr;
408 u->val = pte_val_ma(pteval);
409
410 MULTI_mmu_update(mcs.mc, mcs.args, 1, NULL, DOMID_IO);
411
412 xen_mc_issue(PARAVIRT_LAZY_MMU);
413}
414
381static void xen_extend_mmu_update(const struct mmu_update *update) 415static void xen_extend_mmu_update(const struct mmu_update *update)
382{ 416{
383 struct multicall_space mcs; 417 struct multicall_space mcs;
@@ -454,6 +488,11 @@ void set_pte_mfn(unsigned long vaddr, unsigned long mfn, pgprot_t flags)
454void xen_set_pte_at(struct mm_struct *mm, unsigned long addr, 488void xen_set_pte_at(struct mm_struct *mm, unsigned long addr,
455 pte_t *ptep, pte_t pteval) 489 pte_t *ptep, pte_t pteval)
456{ 490{
491 if (xen_iomap_pte(pteval)) {
492 xen_set_iomap_pte(ptep, pteval);
493 goto out;
494 }
495
457 ADD_STATS(set_pte_at, 1); 496 ADD_STATS(set_pte_at, 1);
458// ADD_STATS(set_pte_at_pinned, xen_page_pinned(ptep)); 497// ADD_STATS(set_pte_at_pinned, xen_page_pinned(ptep));
459 ADD_STATS(set_pte_at_current, mm == current->mm); 498 ADD_STATS(set_pte_at_current, mm == current->mm);
@@ -524,8 +563,25 @@ static pteval_t pte_pfn_to_mfn(pteval_t val)
524 return val; 563 return val;
525} 564}
526 565
566static pteval_t iomap_pte(pteval_t val)
567{
568 if (val & _PAGE_PRESENT) {
569 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
570 pteval_t flags = val & PTE_FLAGS_MASK;
571
572 /* We assume the pte frame number is a MFN, so
573 just use it as-is. */
574 val = ((pteval_t)pfn << PAGE_SHIFT) | flags;
575 }
576
577 return val;
578}
579
527pteval_t xen_pte_val(pte_t pte) 580pteval_t xen_pte_val(pte_t pte)
528{ 581{
582 if (xen_initial_domain() && (pte.pte & _PAGE_IOMAP))
583 return pte.pte;
584
529 return pte_mfn_to_pfn(pte.pte); 585 return pte_mfn_to_pfn(pte.pte);
530} 586}
531PV_CALLEE_SAVE_REGS_THUNK(xen_pte_val); 587PV_CALLEE_SAVE_REGS_THUNK(xen_pte_val);
@@ -538,7 +594,22 @@ PV_CALLEE_SAVE_REGS_THUNK(xen_pgd_val);
538 594
539pte_t xen_make_pte(pteval_t pte) 595pte_t xen_make_pte(pteval_t pte)
540{ 596{
541 pte = pte_pfn_to_mfn(pte); 597 phys_addr_t addr = (pte & PTE_PFN_MASK);
598
599 /*
600 * Unprivileged domains are allowed to do IOMAPpings for
601 * PCI passthrough, but not map ISA space. The ISA
602 * mappings are just dummy local mappings to keep other
603 * parts of the kernel happy.
604 */
605 if (unlikely(pte & _PAGE_IOMAP) &&
606 (xen_initial_domain() || addr >= ISA_END_ADDRESS)) {
607 pte = iomap_pte(pte);
608 } else {
609 pte &= ~_PAGE_IOMAP;
610 pte = pte_pfn_to_mfn(pte);
611 }
612
542 return native_make_pte(pte); 613 return native_make_pte(pte);
543} 614}
544PV_CALLEE_SAVE_REGS_THUNK(xen_make_pte); 615PV_CALLEE_SAVE_REGS_THUNK(xen_make_pte);
@@ -594,6 +665,11 @@ void xen_set_pud(pud_t *ptr, pud_t val)
594 665
595void xen_set_pte(pte_t *ptep, pte_t pte) 666void xen_set_pte(pte_t *ptep, pte_t pte)
596{ 667{
668 if (xen_iomap_pte(pte)) {
669 xen_set_iomap_pte(ptep, pte);
670 return;
671 }
672
597 ADD_STATS(pte_update, 1); 673 ADD_STATS(pte_update, 1);
598// ADD_STATS(pte_update_pinned, xen_page_pinned(ptep)); 674// ADD_STATS(pte_update_pinned, xen_page_pinned(ptep));
599 ADD_STATS(pte_update_batched, paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU); 675 ADD_STATS(pte_update_batched, paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU);
@@ -610,6 +686,11 @@ void xen_set_pte(pte_t *ptep, pte_t pte)
610#ifdef CONFIG_X86_PAE 686#ifdef CONFIG_X86_PAE
611void xen_set_pte_atomic(pte_t *ptep, pte_t pte) 687void xen_set_pte_atomic(pte_t *ptep, pte_t pte)
612{ 688{
689 if (xen_iomap_pte(pte)) {
690 xen_set_iomap_pte(ptep, pte);
691 return;
692 }
693
613 set_64bit((u64 *)ptep, native_pte_val(pte)); 694 set_64bit((u64 *)ptep, native_pte_val(pte));
614} 695}
615 696
@@ -936,8 +1017,6 @@ static int xen_pin_page(struct mm_struct *mm, struct page *page,
936 read-only, and can be pinned. */ 1017 read-only, and can be pinned. */
937static void __xen_pgd_pin(struct mm_struct *mm, pgd_t *pgd) 1018static void __xen_pgd_pin(struct mm_struct *mm, pgd_t *pgd)
938{ 1019{
939 vm_unmap_aliases();
940
941 xen_mc_batch(); 1020 xen_mc_batch();
942 1021
943 if (__xen_pgd_walk(mm, pgd, xen_pin_page, USER_LIMIT)) { 1022 if (__xen_pgd_walk(mm, pgd, xen_pin_page, USER_LIMIT)) {
@@ -1501,7 +1580,6 @@ static void xen_alloc_ptpage(struct mm_struct *mm, unsigned long pfn, unsigned l
1501 if (PagePinned(virt_to_page(mm->pgd))) { 1580 if (PagePinned(virt_to_page(mm->pgd))) {
1502 SetPagePinned(page); 1581 SetPagePinned(page);
1503 1582
1504 vm_unmap_aliases();
1505 if (!PageHighMem(page)) { 1583 if (!PageHighMem(page)) {
1506 make_lowmem_page_readonly(__va(PFN_PHYS((unsigned long)pfn))); 1584 make_lowmem_page_readonly(__va(PFN_PHYS((unsigned long)pfn)));
1507 if (level == PT_PTE && USE_SPLIT_PTLOCKS) 1585 if (level == PT_PTE && USE_SPLIT_PTLOCKS)
@@ -1812,9 +1890,16 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
1812 pte = pfn_pte(phys, prot); 1890 pte = pfn_pte(phys, prot);
1813 break; 1891 break;
1814 1892
1815 default: 1893 case FIX_PARAVIRT_BOOTMAP:
1894 /* This is an MFN, but it isn't an IO mapping from the
1895 IO domain */
1816 pte = mfn_pte(phys, prot); 1896 pte = mfn_pte(phys, prot);
1817 break; 1897 break;
1898
1899 default:
1900 /* By default, set_fixmap is used for hardware mappings */
1901 pte = mfn_pte(phys, __pgprot(pgprot_val(prot) | _PAGE_IOMAP));
1902 break;
1818 } 1903 }
1819 1904
1820 __native_set_fixmap(idx, pte); 1905 __native_set_fixmap(idx, pte);
@@ -1940,7 +2025,205 @@ void __init xen_init_mmu_ops(void)
1940 x86_init.paging.pagetable_setup_start = xen_pagetable_setup_start; 2025 x86_init.paging.pagetable_setup_start = xen_pagetable_setup_start;
1941 x86_init.paging.pagetable_setup_done = xen_pagetable_setup_done; 2026 x86_init.paging.pagetable_setup_done = xen_pagetable_setup_done;
1942 pv_mmu_ops = xen_mmu_ops; 2027 pv_mmu_ops = xen_mmu_ops;
2028
2029 vmap_lazy_unmap = false;
2030}
2031
2032/* Protected by xen_reservation_lock. */
2033#define MAX_CONTIG_ORDER 9 /* 2MB */
2034static unsigned long discontig_frames[1<<MAX_CONTIG_ORDER];
2035
2036#define VOID_PTE (mfn_pte(0, __pgprot(0)))
2037static void xen_zap_pfn_range(unsigned long vaddr, unsigned int order,
2038 unsigned long *in_frames,
2039 unsigned long *out_frames)
2040{
2041 int i;
2042 struct multicall_space mcs;
2043
2044 xen_mc_batch();
2045 for (i = 0; i < (1UL<<order); i++, vaddr += PAGE_SIZE) {
2046 mcs = __xen_mc_entry(0);
2047
2048 if (in_frames)
2049 in_frames[i] = virt_to_mfn(vaddr);
2050
2051 MULTI_update_va_mapping(mcs.mc, vaddr, VOID_PTE, 0);
2052 set_phys_to_machine(virt_to_pfn(vaddr), INVALID_P2M_ENTRY);
2053
2054 if (out_frames)
2055 out_frames[i] = virt_to_pfn(vaddr);
2056 }
2057 xen_mc_issue(0);
2058}
2059
2060/*
2061 * Update the pfn-to-mfn mappings for a virtual address range, either to
2062 * point to an array of mfns, or contiguously from a single starting
2063 * mfn.
2064 */
2065static void xen_remap_exchanged_ptes(unsigned long vaddr, int order,
2066 unsigned long *mfns,
2067 unsigned long first_mfn)
2068{
2069 unsigned i, limit;
2070 unsigned long mfn;
2071
2072 xen_mc_batch();
2073
2074 limit = 1u << order;
2075 for (i = 0; i < limit; i++, vaddr += PAGE_SIZE) {
2076 struct multicall_space mcs;
2077 unsigned flags;
2078
2079 mcs = __xen_mc_entry(0);
2080 if (mfns)
2081 mfn = mfns[i];
2082 else
2083 mfn = first_mfn + i;
2084
2085 if (i < (limit - 1))
2086 flags = 0;
2087 else {
2088 if (order == 0)
2089 flags = UVMF_INVLPG | UVMF_ALL;
2090 else
2091 flags = UVMF_TLB_FLUSH | UVMF_ALL;
2092 }
2093
2094 MULTI_update_va_mapping(mcs.mc, vaddr,
2095 mfn_pte(mfn, PAGE_KERNEL), flags);
2096
2097 set_phys_to_machine(virt_to_pfn(vaddr), mfn);
2098 }
2099
2100 xen_mc_issue(0);
2101}
2102
2103/*
2104 * Perform the hypercall to exchange a region of our pfns to point to
2105 * memory with the required contiguous alignment. Takes the pfns as
2106 * input, and populates mfns as output.
2107 *
2108 * Returns a success code indicating whether the hypervisor was able to
2109 * satisfy the request or not.
2110 */
2111static int xen_exchange_memory(unsigned long extents_in, unsigned int order_in,
2112 unsigned long *pfns_in,
2113 unsigned long extents_out,
2114 unsigned int order_out,
2115 unsigned long *mfns_out,
2116 unsigned int address_bits)
2117{
2118 long rc;
2119 int success;
2120
2121 struct xen_memory_exchange exchange = {
2122 .in = {
2123 .nr_extents = extents_in,
2124 .extent_order = order_in,
2125 .extent_start = pfns_in,
2126 .domid = DOMID_SELF
2127 },
2128 .out = {
2129 .nr_extents = extents_out,
2130 .extent_order = order_out,
2131 .extent_start = mfns_out,
2132 .address_bits = address_bits,
2133 .domid = DOMID_SELF
2134 }
2135 };
2136
2137 BUG_ON(extents_in << order_in != extents_out << order_out);
2138
2139 rc = HYPERVISOR_memory_op(XENMEM_exchange, &exchange);
2140 success = (exchange.nr_exchanged == extents_in);
2141
2142 BUG_ON(!success && ((exchange.nr_exchanged != 0) || (rc == 0)));
2143 BUG_ON(success && (rc != 0));
2144
2145 return success;
2146}
2147
2148int xen_create_contiguous_region(unsigned long vstart, unsigned int order,
2149 unsigned int address_bits)
2150{
2151 unsigned long *in_frames = discontig_frames, out_frame;
2152 unsigned long flags;
2153 int success;
2154
2155 /*
2156 * Currently an auto-translated guest will not perform I/O, nor will
2157 * it require PAE page directories below 4GB. Therefore any calls to
2158 * this function are redundant and can be ignored.
2159 */
2160
2161 if (xen_feature(XENFEAT_auto_translated_physmap))
2162 return 0;
2163
2164 if (unlikely(order > MAX_CONTIG_ORDER))
2165 return -ENOMEM;
2166
2167 memset((void *) vstart, 0, PAGE_SIZE << order);
2168
2169 spin_lock_irqsave(&xen_reservation_lock, flags);
2170
2171 /* 1. Zap current PTEs, remembering MFNs. */
2172 xen_zap_pfn_range(vstart, order, in_frames, NULL);
2173
2174 /* 2. Get a new contiguous memory extent. */
2175 out_frame = virt_to_pfn(vstart);
2176 success = xen_exchange_memory(1UL << order, 0, in_frames,
2177 1, order, &out_frame,
2178 address_bits);
2179
2180 /* 3. Map the new extent in place of old pages. */
2181 if (success)
2182 xen_remap_exchanged_ptes(vstart, order, NULL, out_frame);
2183 else
2184 xen_remap_exchanged_ptes(vstart, order, in_frames, 0);
2185
2186 spin_unlock_irqrestore(&xen_reservation_lock, flags);
2187
2188 return success ? 0 : -ENOMEM;
2189}
2190EXPORT_SYMBOL_GPL(xen_create_contiguous_region);
2191
2192void xen_destroy_contiguous_region(unsigned long vstart, unsigned int order)
2193{
2194 unsigned long *out_frames = discontig_frames, in_frame;
2195 unsigned long flags;
2196 int success;
2197
2198 if (xen_feature(XENFEAT_auto_translated_physmap))
2199 return;
2200
2201 if (unlikely(order > MAX_CONTIG_ORDER))
2202 return;
2203
2204 memset((void *) vstart, 0, PAGE_SIZE << order);
2205
2206 spin_lock_irqsave(&xen_reservation_lock, flags);
2207
2208 /* 1. Find start MFN of contiguous extent. */
2209 in_frame = virt_to_mfn(vstart);
2210
2211 /* 2. Zap current PTEs. */
2212 xen_zap_pfn_range(vstart, order, NULL, out_frames);
2213
2214 /* 3. Do the exchange for non-contiguous MFNs. */
2215 success = xen_exchange_memory(1, order, &in_frame, 1UL << order,
2216 0, out_frames, 0);
2217
2218 /* 4. Map new pages in place of old pages. */
2219 if (success)
2220 xen_remap_exchanged_ptes(vstart, order, out_frames, 0);
2221 else
2222 xen_remap_exchanged_ptes(vstart, order, NULL, in_frame);
2223
2224 spin_unlock_irqrestore(&xen_reservation_lock, flags);
1943} 2225}
2226EXPORT_SYMBOL_GPL(xen_destroy_contiguous_region);
1944 2227
1945#ifdef CONFIG_XEN_PVHVM 2228#ifdef CONFIG_XEN_PVHVM
1946static void xen_hvm_exit_mmap(struct mm_struct *mm) 2229static void xen_hvm_exit_mmap(struct mm_struct *mm)
diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
new file mode 100644
index 000000000000..a013ec9d0c54
--- /dev/null
+++ b/arch/x86/xen/pci-swiotlb-xen.c
@@ -0,0 +1,58 @@
1/* Glue code to lib/swiotlb-xen.c */
2
3#include <linux/dma-mapping.h>
4#include <xen/swiotlb-xen.h>
5
6#include <asm/xen/hypervisor.h>
7#include <xen/xen.h>
8
9int xen_swiotlb __read_mostly;
10
11static struct dma_map_ops xen_swiotlb_dma_ops = {
12 .mapping_error = xen_swiotlb_dma_mapping_error,
13 .alloc_coherent = xen_swiotlb_alloc_coherent,
14 .free_coherent = xen_swiotlb_free_coherent,
15 .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
16 .sync_single_for_device = xen_swiotlb_sync_single_for_device,
17 .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu,
18 .sync_sg_for_device = xen_swiotlb_sync_sg_for_device,
19 .map_sg = xen_swiotlb_map_sg_attrs,
20 .unmap_sg = xen_swiotlb_unmap_sg_attrs,
21 .map_page = xen_swiotlb_map_page,
22 .unmap_page = xen_swiotlb_unmap_page,
23 .dma_supported = xen_swiotlb_dma_supported,
24};
25
26/*
27 * pci_xen_swiotlb_detect - set xen_swiotlb to 1 if necessary
28 *
29 * This returns non-zero if we are forced to use xen_swiotlb (by the boot
30 * option).
31 */
32int __init pci_xen_swiotlb_detect(void)
33{
34
35 /* If running as PV guest, either iommu=soft, or swiotlb=force will
36 * activate this IOMMU. If running as PV privileged, activate it
37 * irregardlesss.
38 */
39 if ((xen_initial_domain() || swiotlb || swiotlb_force) &&
40 (xen_pv_domain()))
41 xen_swiotlb = 1;
42
43 /* If we are running under Xen, we MUST disable the native SWIOTLB.
44 * Don't worry about swiotlb_force flag activating the native, as
45 * the 'swiotlb' flag is the only one turning it on. */
46 if (xen_pv_domain())
47 swiotlb = 0;
48
49 return xen_swiotlb;
50}
51
52void __init pci_xen_swiotlb_init(void)
53{
54 if (xen_swiotlb) {
55 xen_swiotlb_init(1);
56 dma_ops = &xen_swiotlb_dma_ops;
57 }
58}
diff --git a/arch/xtensa/include/asm/cache.h b/arch/xtensa/include/asm/cache.h
index ed8cd3cbd499..d2fd932fdb4d 100644
--- a/arch/xtensa/include/asm/cache.h
+++ b/arch/xtensa/include/asm/cache.h
@@ -29,6 +29,6 @@
29# define CACHE_WAY_SIZE ICACHE_WAY_SIZE 29# define CACHE_WAY_SIZE ICACHE_WAY_SIZE
30#endif 30#endif
31 31
32#define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES 32#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
33 33
34#endif /* _XTENSA_CACHE_H */ 34#endif /* _XTENSA_CACHE_H */
diff --git a/arch/xtensa/include/asm/dma-mapping.h b/arch/xtensa/include/asm/dma-mapping.h
index 51882ae3db4d..492c95790ad5 100644
--- a/arch/xtensa/include/asm/dma-mapping.h
+++ b/arch/xtensa/include/asm/dma-mapping.h
@@ -161,14 +161,6 @@ dma_set_mask(struct device *dev, u64 mask)
161 return 0; 161 return 0;
162} 162}
163 163
164static inline int
165dma_get_cache_alignment(void)
166{
167 return L1_CACHE_BYTES;
168}
169
170#define dma_is_consistent(d, h) (1)
171
172static inline void 164static inline void
173dma_cache_sync(struct device *dev, void *vaddr, size_t size, 165dma_cache_sync(struct device *dev, void *vaddr, size_t size,
174 enum dma_data_direction direction) 166 enum dma_data_direction direction)
diff --git a/block/blk-core.c b/block/blk-core.c
index 7da630e25ae7..ee1a1e7e63cc 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1514,7 +1514,10 @@ static inline void __generic_make_request(struct bio *bio)
1514 if (bio_check_eod(bio, nr_sectors)) 1514 if (bio_check_eod(bio, nr_sectors))
1515 goto end_io; 1515 goto end_io;
1516 1516
1517 if ((bio->bi_rw & REQ_DISCARD) && !blk_queue_discard(q)) { 1517 if ((bio->bi_rw & REQ_DISCARD) &&
1518 (!blk_queue_discard(q) ||
1519 ((bio->bi_rw & REQ_SECURE) &&
1520 !blk_queue_secdiscard(q)))) {
1518 err = -EOPNOTSUPP; 1521 err = -EOPNOTSUPP;
1519 goto end_io; 1522 goto end_io;
1520 } 1523 }
diff --git a/block/blk-lib.c b/block/blk-lib.c
index c1fc55a83ba1..c392029a104e 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -62,6 +62,12 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
62 max_discard_sectors &= ~(disc_sects - 1); 62 max_discard_sectors &= ~(disc_sects - 1);
63 } 63 }
64 64
65 if (flags & BLKDEV_IFL_SECURE) {
66 if (!blk_queue_secdiscard(q))
67 return -EOPNOTSUPP;
68 type |= DISCARD_SECURE;
69 }
70
65 while (nr_sects && !ret) { 71 while (nr_sects && !ret) {
66 bio = bio_alloc(gfp_mask, 1); 72 bio = bio_alloc(gfp_mask, 1);
67 if (!bio) { 73 if (!bio) {
diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
index d53085637731..119f07b74dc0 100644
--- a/block/compat_ioctl.c
+++ b/block/compat_ioctl.c
@@ -703,6 +703,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
703 case BLKFLSBUF: 703 case BLKFLSBUF:
704 case BLKROSET: 704 case BLKROSET:
705 case BLKDISCARD: 705 case BLKDISCARD:
706 case BLKSECDISCARD:
706 /* 707 /*
707 * the ones below are implemented in blkdev_locked_ioctl, 708 * the ones below are implemented in blkdev_locked_ioctl,
708 * but we call blkdev_ioctl, which gets the lock for us 709 * but we call blkdev_ioctl, which gets the lock for us
diff --git a/block/elevator.c b/block/elevator.c
index 816a7c8d6394..ec585c9554d3 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -83,6 +83,12 @@ int elv_rq_merge_ok(struct request *rq, struct bio *bio)
83 return 0; 83 return 0;
84 84
85 /* 85 /*
86 * Don't merge discard requests and secure discard requests
87 */
88 if ((bio->bi_rw & REQ_SECURE) != (rq->bio->bi_rw & REQ_SECURE))
89 return 0;
90
91 /*
86 * different data direction or already started, don't merge 92 * different data direction or already started, don't merge
87 */ 93 */
88 if (bio_data_dir(bio) != rq_data_dir(rq)) 94 if (bio_data_dir(bio) != rq_data_dir(rq))
diff --git a/block/ioctl.c b/block/ioctl.c
index 09fd7f1ef23a..d8052f0dabd3 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -114,8 +114,10 @@ static int blkdev_reread_part(struct block_device *bdev)
114} 114}
115 115
116static int blk_ioctl_discard(struct block_device *bdev, uint64_t start, 116static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,
117 uint64_t len) 117 uint64_t len, int secure)
118{ 118{
119 unsigned long flags = BLKDEV_IFL_WAIT;
120
119 if (start & 511) 121 if (start & 511)
120 return -EINVAL; 122 return -EINVAL;
121 if (len & 511) 123 if (len & 511)
@@ -125,8 +127,9 @@ static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,
125 127
126 if (start + len > (bdev->bd_inode->i_size >> 9)) 128 if (start + len > (bdev->bd_inode->i_size >> 9))
127 return -EINVAL; 129 return -EINVAL;
128 return blkdev_issue_discard(bdev, start, len, GFP_KERNEL, 130 if (secure)
129 BLKDEV_IFL_WAIT); 131 flags |= BLKDEV_IFL_SECURE;
132 return blkdev_issue_discard(bdev, start, len, GFP_KERNEL, flags);
130} 133}
131 134
132static int put_ushort(unsigned long arg, unsigned short val) 135static int put_ushort(unsigned long arg, unsigned short val)
@@ -213,7 +216,8 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
213 set_device_ro(bdev, n); 216 set_device_ro(bdev, n);
214 return 0; 217 return 0;
215 218
216 case BLKDISCARD: { 219 case BLKDISCARD:
220 case BLKSECDISCARD: {
217 uint64_t range[2]; 221 uint64_t range[2];
218 222
219 if (!(mode & FMODE_WRITE)) 223 if (!(mode & FMODE_WRITE))
@@ -222,7 +226,8 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
222 if (copy_from_user(range, (void __user *)arg, sizeof(range))) 226 if (copy_from_user(range, (void __user *)arg, sizeof(range)))
223 return -EFAULT; 227 return -EFAULT;
224 228
225 return blk_ioctl_discard(bdev, range[0], range[1]); 229 return blk_ioctl_discard(bdev, range[0], range[1],
230 cmd == BLKSECDISCARD);
226 } 231 }
227 232
228 case HDIO_GETGEO: { 233 case HDIO_GETGEO: {
diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c
index 864dd46c346f..18645f4e83cd 100644
--- a/drivers/acpi/apei/erst.c
+++ b/drivers/acpi/apei/erst.c
@@ -33,6 +33,7 @@
33#include <linux/uaccess.h> 33#include <linux/uaccess.h>
34#include <linux/cper.h> 34#include <linux/cper.h>
35#include <linux/nmi.h> 35#include <linux/nmi.h>
36#include <linux/hardirq.h>
36#include <acpi/apei.h> 37#include <acpi/apei.h>
37 38
38#include "apei-internal.h" 39#include "apei-internal.h"
diff --git a/drivers/acpi/debug.c b/drivers/acpi/debug.c
index 146135e7a6a1..295dbfa2db9c 100644
--- a/drivers/acpi/debug.c
+++ b/drivers/acpi/debug.c
@@ -96,7 +96,8 @@ static const struct acpi_dlevel acpi_debug_levels[] = {
96/* -------------------------------------------------------------------------- 96/* --------------------------------------------------------------------------
97 FS Interface (/sys) 97 FS Interface (/sys)
98 -------------------------------------------------------------------------- */ 98 -------------------------------------------------------------------------- */
99static int param_get_debug_layer(char *buffer, struct kernel_param *kp) { 99static int param_get_debug_layer(char *buffer, const struct kernel_param *kp)
100{
100 int result = 0; 101 int result = 0;
101 int i; 102 int i;
102 103
@@ -118,7 +119,8 @@ static int param_get_debug_layer(char *buffer, struct kernel_param *kp) {
118 return result; 119 return result;
119} 120}
120 121
121static int param_get_debug_level(char *buffer, struct kernel_param *kp) { 122static int param_get_debug_level(char *buffer, const struct kernel_param *kp)
123{
122 int result = 0; 124 int result = 0;
123 int i; 125 int i;
124 126
@@ -137,8 +139,18 @@ static int param_get_debug_level(char *buffer, struct kernel_param *kp) {
137 return result; 139 return result;
138} 140}
139 141
140module_param_call(debug_layer, param_set_uint, param_get_debug_layer, &acpi_dbg_layer, 0644); 142static struct kernel_param_ops acpi_debug_layer_ops = {
141module_param_call(debug_level, param_set_uint, param_get_debug_level, &acpi_dbg_level, 0644); 143 .set = param_set_uint,
144 .get = param_get_debug_layer,
145};
146
147static struct kernel_param_ops acpi_debug_level_ops = {
148 .set = param_set_uint,
149 .get = param_get_debug_level,
150};
151
152module_param_cb(debug_layer, &acpi_debug_layer_ops, &acpi_dbg_layer, 0644);
153module_param_cb(debug_level, &acpi_debug_level_ops, &acpi_dbg_level, 0644);
142 154
143static char trace_method_name[6]; 155static char trace_method_name[6];
144module_param_string(trace_method_name, trace_method_name, 6, 0644); 156module_param_string(trace_method_name, trace_method_name, 6, 0644);
@@ -147,7 +159,7 @@ module_param(trace_debug_layer, uint, 0644);
147static unsigned int trace_debug_level; 159static unsigned int trace_debug_level;
148module_param(trace_debug_level, uint, 0644); 160module_param(trace_debug_level, uint, 0644);
149 161
150static int param_set_trace_state(const char *val, struct kernel_param *kp) 162static int param_set_trace_state(const char *val, const struct kernel_param *kp)
151{ 163{
152 int result = 0; 164 int result = 0;
153 165
@@ -181,7 +193,7 @@ exit:
181 return result; 193 return result;
182} 194}
183 195
184static int param_get_trace_state(char *buffer, struct kernel_param *kp) 196static int param_get_trace_state(char *buffer, const struct kernel_param *kp)
185{ 197{
186 if (!acpi_gbl_trace_method_name) 198 if (!acpi_gbl_trace_method_name)
187 return sprintf(buffer, "disable"); 199 return sprintf(buffer, "disable");
@@ -194,8 +206,12 @@ static int param_get_trace_state(char *buffer, struct kernel_param *kp)
194 return 0; 206 return 0;
195} 207}
196 208
197module_param_call(trace_state, param_set_trace_state, param_get_trace_state, 209static struct kernel_param_ops param_ops_trace_state = {
198 NULL, 0644); 210 .set = param_set_trace_state,
211 .get = param_get_trace_state,
212};
213
214module_param_cb(trace_state, &param_ops_trace_state, NULL, 0644);
199 215
200/* -------------------------------------------------------------------------- 216/* --------------------------------------------------------------------------
201 DebugFS Interface 217 DebugFS Interface
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 8fae6afd6a3d..65e3e2708371 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -651,6 +651,17 @@ config PATA_VIA
651 651
652 If unsure, say N. 652 If unsure, say N.
653 653
654config PATA_PXA
655 tristate "PXA DMA-capable PATA support"
656 depends on ARCH_PXA
657 help
658 This option enables support for harddrive attached to PXA CPU's bus.
659
660 NOTE: This driver utilizes PXA DMA controller, in case your hardware
661 is not capable of doing MWDMA, use pata_platform instead.
662
663 If unsure, say N.
664
654config PATA_WINBOND 665config PATA_WINBOND
655 tristate "Winbond SL82C105 PATA support" 666 tristate "Winbond SL82C105 PATA support"
656 depends on PCI 667 depends on PCI
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile
index 6540632bda08..158eaa961b1e 100644
--- a/drivers/ata/Makefile
+++ b/drivers/ata/Makefile
@@ -91,6 +91,8 @@ obj-$(CONFIG_PATA_RZ1000) += pata_rz1000.o
91obj-$(CONFIG_PATA_SAMSUNG_CF) += pata_samsung_cf.o 91obj-$(CONFIG_PATA_SAMSUNG_CF) += pata_samsung_cf.o
92obj-$(CONFIG_PATA_WINBOND_VLB) += pata_winbond.o 92obj-$(CONFIG_PATA_WINBOND_VLB) += pata_winbond.o
93 93
94obj-$(CONFIG_PATA_PXA) += pata_pxa.o
95
94# Should be last but two libata driver 96# Should be last but two libata driver
95obj-$(CONFIG_PATA_ACPI) += pata_acpi.o 97obj-$(CONFIG_PATA_ACPI) += pata_acpi.o
96# Should be last but one libata driver 98# Should be last but one libata driver
diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
index f087ab55b1df..8cc536e49a0a 100644
--- a/drivers/ata/pata_mpc52xx.c
+++ b/drivers/ata/pata_mpc52xx.c
@@ -680,7 +680,7 @@ mpc52xx_ata_remove_one(struct device *dev)
680/* ======================================================================== */ 680/* ======================================================================== */
681 681
682static int __devinit 682static int __devinit
683mpc52xx_ata_probe(struct of_device *op, const struct of_device_id *match) 683mpc52xx_ata_probe(struct platform_device *op, const struct of_device_id *match)
684{ 684{
685 unsigned int ipb_freq; 685 unsigned int ipb_freq;
686 struct resource res_mem; 686 struct resource res_mem;
@@ -821,7 +821,7 @@ mpc52xx_ata_probe(struct of_device *op, const struct of_device_id *match)
821} 821}
822 822
823static int 823static int
824mpc52xx_ata_remove(struct of_device *op) 824mpc52xx_ata_remove(struct platform_device *op)
825{ 825{
826 struct mpc52xx_ata_priv *priv; 826 struct mpc52xx_ata_priv *priv;
827 int task_irq; 827 int task_irq;
@@ -848,7 +848,7 @@ mpc52xx_ata_remove(struct of_device *op)
848#ifdef CONFIG_PM 848#ifdef CONFIG_PM
849 849
850static int 850static int
851mpc52xx_ata_suspend(struct of_device *op, pm_message_t state) 851mpc52xx_ata_suspend(struct platform_device *op, pm_message_t state)
852{ 852{
853 struct ata_host *host = dev_get_drvdata(&op->dev); 853 struct ata_host *host = dev_get_drvdata(&op->dev);
854 854
@@ -856,7 +856,7 @@ mpc52xx_ata_suspend(struct of_device *op, pm_message_t state)
856} 856}
857 857
858static int 858static int
859mpc52xx_ata_resume(struct of_device *op) 859mpc52xx_ata_resume(struct platform_device *op)
860{ 860{
861 struct ata_host *host = dev_get_drvdata(&op->dev); 861 struct ata_host *host = dev_get_drvdata(&op->dev);
862 struct mpc52xx_ata_priv *priv = host->private_data; 862 struct mpc52xx_ata_priv *priv = host->private_data;
diff --git a/drivers/ata/pata_of_platform.c b/drivers/ata/pata_of_platform.c
index 5a1b82c08be9..480e043ce6b8 100644
--- a/drivers/ata/pata_of_platform.c
+++ b/drivers/ata/pata_of_platform.c
@@ -14,7 +14,7 @@
14#include <linux/of_platform.h> 14#include <linux/of_platform.h>
15#include <linux/ata_platform.h> 15#include <linux/ata_platform.h>
16 16
17static int __devinit pata_of_platform_probe(struct of_device *ofdev, 17static int __devinit pata_of_platform_probe(struct platform_device *ofdev,
18 const struct of_device_id *match) 18 const struct of_device_id *match)
19{ 19{
20 int ret; 20 int ret;
@@ -78,7 +78,7 @@ static int __devinit pata_of_platform_probe(struct of_device *ofdev,
78 reg_shift, pio_mask); 78 reg_shift, pio_mask);
79} 79}
80 80
81static int __devexit pata_of_platform_remove(struct of_device *ofdev) 81static int __devexit pata_of_platform_remove(struct platform_device *ofdev)
82{ 82{
83 return __pata_platform_remove(&ofdev->dev); 83 return __pata_platform_remove(&ofdev->dev);
84} 84}
diff --git a/drivers/ata/pata_pxa.c b/drivers/ata/pata_pxa.c
new file mode 100644
index 000000000000..1898c6ed4b4e
--- /dev/null
+++ b/drivers/ata/pata_pxa.c
@@ -0,0 +1,411 @@
1/*
2 * Generic PXA PATA driver
3 *
4 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/blkdev.h>
25#include <linux/ata.h>
26#include <linux/libata.h>
27#include <linux/platform_device.h>
28#include <linux/gpio.h>
29#include <linux/slab.h>
30#include <linux/completion.h>
31
32#include <scsi/scsi_host.h>
33
34#include <mach/pxa2xx-regs.h>
35#include <mach/pata_pxa.h>
36#include <mach/dma.h>
37
38#define DRV_NAME "pata_pxa"
39#define DRV_VERSION "0.1"
40
41struct pata_pxa_data {
42 uint32_t dma_channel;
43 struct pxa_dma_desc *dma_desc;
44 dma_addr_t dma_desc_addr;
45 uint32_t dma_desc_id;
46
47 /* DMA IO physical address */
48 uint32_t dma_io_addr;
49 /* PXA DREQ<0:2> pin selector */
50 uint32_t dma_dreq;
51 /* DMA DCSR register value */
52 uint32_t dma_dcsr;
53
54 struct completion dma_done;
55};
56
57/*
58 * Setup the DMA descriptors. The size is transfer capped at 4k per descriptor,
59 * if the transfer is longer, it is split into multiple chained descriptors.
60 */
61static void pxa_load_dmac(struct scatterlist *sg, struct ata_queued_cmd *qc)
62{
63 struct pata_pxa_data *pd = qc->ap->private_data;
64
65 uint32_t cpu_len, seg_len;
66 dma_addr_t cpu_addr;
67
68 cpu_addr = sg_dma_address(sg);
69 cpu_len = sg_dma_len(sg);
70
71 do {
72 seg_len = (cpu_len > 0x1000) ? 0x1000 : cpu_len;
73
74 pd->dma_desc[pd->dma_desc_id].ddadr = pd->dma_desc_addr +
75 ((pd->dma_desc_id + 1) * sizeof(struct pxa_dma_desc));
76
77 pd->dma_desc[pd->dma_desc_id].dcmd = DCMD_BURST32 |
78 DCMD_WIDTH2 | (DCMD_LENGTH & seg_len);
79
80 if (qc->tf.flags & ATA_TFLAG_WRITE) {
81 pd->dma_desc[pd->dma_desc_id].dsadr = cpu_addr;
82 pd->dma_desc[pd->dma_desc_id].dtadr = pd->dma_io_addr;
83 pd->dma_desc[pd->dma_desc_id].dcmd |= DCMD_INCSRCADDR |
84 DCMD_FLOWTRG;
85 } else {
86 pd->dma_desc[pd->dma_desc_id].dsadr = pd->dma_io_addr;
87 pd->dma_desc[pd->dma_desc_id].dtadr = cpu_addr;
88 pd->dma_desc[pd->dma_desc_id].dcmd |= DCMD_INCTRGADDR |
89 DCMD_FLOWSRC;
90 }
91
92 cpu_len -= seg_len;
93 cpu_addr += seg_len;
94 pd->dma_desc_id++;
95
96 } while (cpu_len);
97
98 /* Should not happen */
99 if (seg_len & 0x1f)
100 DALGN |= (1 << pd->dma_dreq);
101}
102
103/*
104 * Prepare taskfile for submission.
105 */
106static void pxa_qc_prep(struct ata_queued_cmd *qc)
107{
108 struct pata_pxa_data *pd = qc->ap->private_data;
109 int si = 0;
110 struct scatterlist *sg;
111
112 if (!(qc->flags & ATA_QCFLAG_DMAMAP))
113 return;
114
115 pd->dma_desc_id = 0;
116
117 DCSR(pd->dma_channel) = 0;
118 DALGN &= ~(1 << pd->dma_dreq);
119
120 for_each_sg(qc->sg, sg, qc->n_elem, si)
121 pxa_load_dmac(sg, qc);
122
123 pd->dma_desc[pd->dma_desc_id - 1].ddadr = DDADR_STOP;
124
125 /* Fire IRQ only at the end of last block */
126 pd->dma_desc[pd->dma_desc_id - 1].dcmd |= DCMD_ENDIRQEN;
127
128 DDADR(pd->dma_channel) = pd->dma_desc_addr;
129 DRCMR(pd->dma_dreq) = DRCMR_MAPVLD | pd->dma_channel;
130
131}
132
133/*
134 * Configure the DMA controller, load the DMA descriptors, but don't start the
135 * DMA controller yet. Only issue the ATA command.
136 */
137static void pxa_bmdma_setup(struct ata_queued_cmd *qc)
138{
139 qc->ap->ops->sff_exec_command(qc->ap, &qc->tf);
140}
141
142/*
143 * Execute the DMA transfer.
144 */
145static void pxa_bmdma_start(struct ata_queued_cmd *qc)
146{
147 struct pata_pxa_data *pd = qc->ap->private_data;
148 init_completion(&pd->dma_done);
149 DCSR(pd->dma_channel) = DCSR_RUN;
150}
151
152/*
153 * Wait until the DMA transfer completes, then stop the DMA controller.
154 */
155static void pxa_bmdma_stop(struct ata_queued_cmd *qc)
156{
157 struct pata_pxa_data *pd = qc->ap->private_data;
158
159 if ((DCSR(pd->dma_channel) & DCSR_RUN) &&
160 wait_for_completion_timeout(&pd->dma_done, HZ))
161 dev_err(qc->ap->dev, "Timeout waiting for DMA completion!");
162
163 DCSR(pd->dma_channel) = 0;
164}
165
166/*
167 * Read DMA status. The bmdma_stop() will take care of properly finishing the
168 * DMA transfer so we always have DMA-complete interrupt here.
169 */
170static unsigned char pxa_bmdma_status(struct ata_port *ap)
171{
172 struct pata_pxa_data *pd = ap->private_data;
173 unsigned char ret = ATA_DMA_INTR;
174
175 if (pd->dma_dcsr & DCSR_BUSERR)
176 ret |= ATA_DMA_ERR;
177
178 return ret;
179}
180
181/*
182 * No IRQ register present so we do nothing.
183 */
184static void pxa_irq_clear(struct ata_port *ap)
185{
186}
187
188/*
189 * Check for ATAPI DMA. ATAPI DMA is unsupported by this driver. It's still
190 * unclear why ATAPI has DMA issues.
191 */
192static int pxa_check_atapi_dma(struct ata_queued_cmd *qc)
193{
194 return -EOPNOTSUPP;
195}
196
197static struct scsi_host_template pxa_ata_sht = {
198 ATA_BMDMA_SHT(DRV_NAME),
199};
200
201static struct ata_port_operations pxa_ata_port_ops = {
202 .inherits = &ata_bmdma_port_ops,
203 .cable_detect = ata_cable_40wire,
204
205 .bmdma_setup = pxa_bmdma_setup,
206 .bmdma_start = pxa_bmdma_start,
207 .bmdma_stop = pxa_bmdma_stop,
208 .bmdma_status = pxa_bmdma_status,
209
210 .check_atapi_dma = pxa_check_atapi_dma,
211
212 .sff_irq_clear = pxa_irq_clear,
213
214 .qc_prep = pxa_qc_prep,
215};
216
217/*
218 * DMA interrupt handler.
219 */
220static void pxa_ata_dma_irq(int dma, void *port)
221{
222 struct ata_port *ap = port;
223 struct pata_pxa_data *pd = ap->private_data;
224
225 pd->dma_dcsr = DCSR(dma);
226 DCSR(dma) = pd->dma_dcsr;
227
228 if (pd->dma_dcsr & DCSR_STOPSTATE)
229 complete(&pd->dma_done);
230}
231
232static int __devinit pxa_ata_probe(struct platform_device *pdev)
233{
234 struct ata_host *host;
235 struct ata_port *ap;
236 struct pata_pxa_data *data;
237 struct resource *cmd_res;
238 struct resource *ctl_res;
239 struct resource *dma_res;
240 struct resource *irq_res;
241 struct pata_pxa_pdata *pdata = pdev->dev.platform_data;
242 int ret = 0;
243
244 /*
245 * Resource validation, three resources are needed:
246 * - CMD port base address
247 * - CTL port base address
248 * - DMA port base address
249 * - IRQ pin
250 */
251 if (pdev->num_resources != 4) {
252 dev_err(&pdev->dev, "invalid number of resources\n");
253 return -EINVAL;
254 }
255
256 /*
257 * CMD port base address
258 */
259 cmd_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
260 if (unlikely(cmd_res == NULL))
261 return -EINVAL;
262
263 /*
264 * CTL port base address
265 */
266 ctl_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
267 if (unlikely(ctl_res == NULL))
268 return -EINVAL;
269
270 /*
271 * DMA port base address
272 */
273 dma_res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
274 if (unlikely(dma_res == NULL))
275 return -EINVAL;
276
277 /*
278 * IRQ pin
279 */
280 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
281 if (unlikely(irq_res == NULL))
282 return -EINVAL;
283
284 /*
285 * Allocate the host
286 */
287 host = ata_host_alloc(&pdev->dev, 1);
288 if (!host)
289 return -ENOMEM;
290
291 ap = host->ports[0];
292 ap->ops = &pxa_ata_port_ops;
293 ap->pio_mask = ATA_PIO4;
294 ap->mwdma_mask = ATA_MWDMA2;
295 ap->flags = ATA_FLAG_MMIO;
296
297 ap->ioaddr.cmd_addr = devm_ioremap(&pdev->dev, cmd_res->start,
298 resource_size(cmd_res));
299 ap->ioaddr.ctl_addr = devm_ioremap(&pdev->dev, ctl_res->start,
300 resource_size(ctl_res));
301 ap->ioaddr.bmdma_addr = devm_ioremap(&pdev->dev, dma_res->start,
302 resource_size(dma_res));
303
304 /*
305 * Adjust register offsets
306 */
307 ap->ioaddr.altstatus_addr = ap->ioaddr.ctl_addr;
308 ap->ioaddr.data_addr = ap->ioaddr.cmd_addr +
309 (ATA_REG_DATA << pdata->reg_shift);
310 ap->ioaddr.error_addr = ap->ioaddr.cmd_addr +
311 (ATA_REG_ERR << pdata->reg_shift);
312 ap->ioaddr.feature_addr = ap->ioaddr.cmd_addr +
313 (ATA_REG_FEATURE << pdata->reg_shift);
314 ap->ioaddr.nsect_addr = ap->ioaddr.cmd_addr +
315 (ATA_REG_NSECT << pdata->reg_shift);
316 ap->ioaddr.lbal_addr = ap->ioaddr.cmd_addr +
317 (ATA_REG_LBAL << pdata->reg_shift);
318 ap->ioaddr.lbam_addr = ap->ioaddr.cmd_addr +
319 (ATA_REG_LBAM << pdata->reg_shift);
320 ap->ioaddr.lbah_addr = ap->ioaddr.cmd_addr +
321 (ATA_REG_LBAH << pdata->reg_shift);
322 ap->ioaddr.device_addr = ap->ioaddr.cmd_addr +
323 (ATA_REG_DEVICE << pdata->reg_shift);
324 ap->ioaddr.status_addr = ap->ioaddr.cmd_addr +
325 (ATA_REG_STATUS << pdata->reg_shift);
326 ap->ioaddr.command_addr = ap->ioaddr.cmd_addr +
327 (ATA_REG_CMD << pdata->reg_shift);
328
329 /*
330 * Allocate and load driver's internal data structure
331 */
332 data = devm_kzalloc(&pdev->dev, sizeof(struct pata_pxa_data),
333 GFP_KERNEL);
334 if (!data)
335 return -ENOMEM;
336
337 ap->private_data = data;
338 data->dma_dreq = pdata->dma_dreq;
339 data->dma_io_addr = dma_res->start;
340
341 /*
342 * Allocate space for the DMA descriptors
343 */
344 data->dma_desc = dmam_alloc_coherent(&pdev->dev, PAGE_SIZE,
345 &data->dma_desc_addr, GFP_KERNEL);
346 if (!data->dma_desc)
347 return -EINVAL;
348
349 /*
350 * Request the DMA channel
351 */
352 data->dma_channel = pxa_request_dma(DRV_NAME, DMA_PRIO_LOW,
353 pxa_ata_dma_irq, ap);
354 if (data->dma_channel < 0)
355 return -EBUSY;
356
357 /*
358 * Stop and clear the DMA channel
359 */
360 DCSR(data->dma_channel) = 0;
361
362 /*
363 * Activate the ATA host
364 */
365 ret = ata_host_activate(host, irq_res->start, ata_sff_interrupt,
366 pdata->irq_flags, &pxa_ata_sht);
367 if (ret)
368 pxa_free_dma(data->dma_channel);
369
370 return ret;
371}
372
373static int __devexit pxa_ata_remove(struct platform_device *pdev)
374{
375 struct ata_host *host = dev_get_drvdata(&pdev->dev);
376 struct pata_pxa_data *data = host->ports[0]->private_data;
377
378 pxa_free_dma(data->dma_channel);
379
380 ata_host_detach(host);
381
382 return 0;
383}
384
385static struct platform_driver pxa_ata_driver = {
386 .probe = pxa_ata_probe,
387 .remove = __devexit_p(pxa_ata_remove),
388 .driver = {
389 .name = DRV_NAME,
390 .owner = THIS_MODULE,
391 },
392};
393
394static int __init pxa_ata_init(void)
395{
396 return platform_driver_register(&pxa_ata_driver);
397}
398
399static void __exit pxa_ata_exit(void)
400{
401 platform_driver_unregister(&pxa_ata_driver);
402}
403
404module_init(pxa_ata_init);
405module_exit(pxa_ata_exit);
406
407MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
408MODULE_DESCRIPTION("DMA-capable driver for PATA on PXA CPU");
409MODULE_LICENSE("GPL");
410MODULE_VERSION(DRV_VERSION);
411MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
index 18c986dbb7f1..7325f77480dc 100644
--- a/drivers/ata/sata_fsl.c
+++ b/drivers/ata/sata_fsl.c
@@ -1296,7 +1296,7 @@ static const struct ata_port_info sata_fsl_port_info[] = {
1296 }, 1296 },
1297}; 1297};
1298 1298
1299static int sata_fsl_probe(struct of_device *ofdev, 1299static int sata_fsl_probe(struct platform_device *ofdev,
1300 const struct of_device_id *match) 1300 const struct of_device_id *match)
1301{ 1301{
1302 int retval = -ENXIO; 1302 int retval = -ENXIO;
@@ -1370,7 +1370,7 @@ error_exit_with_cleanup:
1370 return retval; 1370 return retval;
1371} 1371}
1372 1372
1373static int sata_fsl_remove(struct of_device *ofdev) 1373static int sata_fsl_remove(struct platform_device *ofdev)
1374{ 1374{
1375 struct ata_host *host = dev_get_drvdata(&ofdev->dev); 1375 struct ata_host *host = dev_get_drvdata(&ofdev->dev);
1376 struct sata_fsl_host_priv *host_priv = host->private_data; 1376 struct sata_fsl_host_priv *host_priv = host->private_data;
@@ -1387,13 +1387,13 @@ static int sata_fsl_remove(struct of_device *ofdev)
1387} 1387}
1388 1388
1389#ifdef CONFIG_PM 1389#ifdef CONFIG_PM
1390static int sata_fsl_suspend(struct of_device *op, pm_message_t state) 1390static int sata_fsl_suspend(struct platform_device *op, pm_message_t state)
1391{ 1391{
1392 struct ata_host *host = dev_get_drvdata(&op->dev); 1392 struct ata_host *host = dev_get_drvdata(&op->dev);
1393 return ata_host_suspend(host, state); 1393 return ata_host_suspend(host, state);
1394} 1394}
1395 1395
1396static int sata_fsl_resume(struct of_device *op) 1396static int sata_fsl_resume(struct platform_device *op)
1397{ 1397{
1398 struct ata_host *host = dev_get_drvdata(&op->dev); 1398 struct ata_host *host = dev_get_drvdata(&op->dev);
1399 struct sata_fsl_host_priv *host_priv = host->private_data; 1399 struct sata_fsl_host_priv *host_priv = host->private_data;
diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
index b7385e077717..c8fc69c85a06 100644
--- a/drivers/atm/fore200e.c
+++ b/drivers/atm/fore200e.c
@@ -674,7 +674,7 @@ static void fore200e_sba_write(u32 val, volatile u32 __iomem *addr)
674 674
675static u32 fore200e_sba_dma_map(struct fore200e *fore200e, void* virt_addr, int size, int direction) 675static u32 fore200e_sba_dma_map(struct fore200e *fore200e, void* virt_addr, int size, int direction)
676{ 676{
677 struct of_device *op = fore200e->bus_dev; 677 struct platform_device *op = fore200e->bus_dev;
678 u32 dma_addr; 678 u32 dma_addr;
679 679
680 dma_addr = dma_map_single(&op->dev, virt_addr, size, direction); 680 dma_addr = dma_map_single(&op->dev, virt_addr, size, direction);
@@ -687,7 +687,7 @@ static u32 fore200e_sba_dma_map(struct fore200e *fore200e, void* virt_addr, int
687 687
688static void fore200e_sba_dma_unmap(struct fore200e *fore200e, u32 dma_addr, int size, int direction) 688static void fore200e_sba_dma_unmap(struct fore200e *fore200e, u32 dma_addr, int size, int direction)
689{ 689{
690 struct of_device *op = fore200e->bus_dev; 690 struct platform_device *op = fore200e->bus_dev;
691 691
692 DPRINTK(3, "SBUS DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d,\n", 692 DPRINTK(3, "SBUS DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d,\n",
693 dma_addr, size, direction); 693 dma_addr, size, direction);
@@ -697,7 +697,7 @@ static void fore200e_sba_dma_unmap(struct fore200e *fore200e, u32 dma_addr, int
697 697
698static void fore200e_sba_dma_sync_for_cpu(struct fore200e *fore200e, u32 dma_addr, int size, int direction) 698static void fore200e_sba_dma_sync_for_cpu(struct fore200e *fore200e, u32 dma_addr, int size, int direction)
699{ 699{
700 struct of_device *op = fore200e->bus_dev; 700 struct platform_device *op = fore200e->bus_dev;
701 701
702 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction); 702 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
703 703
@@ -706,7 +706,7 @@ static void fore200e_sba_dma_sync_for_cpu(struct fore200e *fore200e, u32 dma_add
706 706
707static void fore200e_sba_dma_sync_for_device(struct fore200e *fore200e, u32 dma_addr, int size, int direction) 707static void fore200e_sba_dma_sync_for_device(struct fore200e *fore200e, u32 dma_addr, int size, int direction)
708{ 708{
709 struct of_device *op = fore200e->bus_dev; 709 struct platform_device *op = fore200e->bus_dev;
710 710
711 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction); 711 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
712 712
@@ -719,7 +719,7 @@ static void fore200e_sba_dma_sync_for_device(struct fore200e *fore200e, u32 dma_
719static int fore200e_sba_dma_chunk_alloc(struct fore200e *fore200e, struct chunk *chunk, 719static int fore200e_sba_dma_chunk_alloc(struct fore200e *fore200e, struct chunk *chunk,
720 int size, int nbr, int alignment) 720 int size, int nbr, int alignment)
721{ 721{
722 struct of_device *op = fore200e->bus_dev; 722 struct platform_device *op = fore200e->bus_dev;
723 723
724 chunk->alloc_size = chunk->align_size = size * nbr; 724 chunk->alloc_size = chunk->align_size = size * nbr;
725 725
@@ -738,7 +738,7 @@ static int fore200e_sba_dma_chunk_alloc(struct fore200e *fore200e, struct chunk
738/* free a DVMA consistent chunk of memory */ 738/* free a DVMA consistent chunk of memory */
739static void fore200e_sba_dma_chunk_free(struct fore200e *fore200e, struct chunk *chunk) 739static void fore200e_sba_dma_chunk_free(struct fore200e *fore200e, struct chunk *chunk)
740{ 740{
741 struct of_device *op = fore200e->bus_dev; 741 struct platform_device *op = fore200e->bus_dev;
742 742
743 dma_free_coherent(&op->dev, chunk->alloc_size, 743 dma_free_coherent(&op->dev, chunk->alloc_size,
744 chunk->alloc_addr, chunk->dma_addr); 744 chunk->alloc_addr, chunk->dma_addr);
@@ -770,7 +770,7 @@ static void fore200e_sba_reset(struct fore200e *fore200e)
770 770
771static int __init fore200e_sba_map(struct fore200e *fore200e) 771static int __init fore200e_sba_map(struct fore200e *fore200e)
772{ 772{
773 struct of_device *op = fore200e->bus_dev; 773 struct platform_device *op = fore200e->bus_dev;
774 unsigned int bursts; 774 unsigned int bursts;
775 775
776 /* gain access to the SBA specific registers */ 776 /* gain access to the SBA specific registers */
@@ -800,7 +800,7 @@ static int __init fore200e_sba_map(struct fore200e *fore200e)
800 800
801static void fore200e_sba_unmap(struct fore200e *fore200e) 801static void fore200e_sba_unmap(struct fore200e *fore200e)
802{ 802{
803 struct of_device *op = fore200e->bus_dev; 803 struct platform_device *op = fore200e->bus_dev;
804 804
805 of_iounmap(&op->resource[0], fore200e->regs.sba.hcr, SBA200E_HCR_LENGTH); 805 of_iounmap(&op->resource[0], fore200e->regs.sba.hcr, SBA200E_HCR_LENGTH);
806 of_iounmap(&op->resource[1], fore200e->regs.sba.bsr, SBA200E_BSR_LENGTH); 806 of_iounmap(&op->resource[1], fore200e->regs.sba.bsr, SBA200E_BSR_LENGTH);
@@ -816,7 +816,7 @@ static int __init fore200e_sba_configure(struct fore200e *fore200e)
816 816
817static int __init fore200e_sba_prom_read(struct fore200e *fore200e, struct prom_data *prom) 817static int __init fore200e_sba_prom_read(struct fore200e *fore200e, struct prom_data *prom)
818{ 818{
819 struct of_device *op = fore200e->bus_dev; 819 struct platform_device *op = fore200e->bus_dev;
820 const u8 *prop; 820 const u8 *prop;
821 int len; 821 int len;
822 822
@@ -840,7 +840,7 @@ static int __init fore200e_sba_prom_read(struct fore200e *fore200e, struct prom_
840 840
841static int fore200e_sba_proc_read(struct fore200e *fore200e, char *page) 841static int fore200e_sba_proc_read(struct fore200e *fore200e, char *page)
842{ 842{
843 struct of_device *op = fore200e->bus_dev; 843 struct platform_device *op = fore200e->bus_dev;
844 const struct linux_prom_registers *regs; 844 const struct linux_prom_registers *regs;
845 845
846 regs = of_get_property(op->dev.of_node, "reg", NULL); 846 regs = of_get_property(op->dev.of_node, "reg", NULL);
@@ -2513,7 +2513,7 @@ fore200e_load_and_start_fw(struct fore200e* fore200e)
2513 device = &((struct pci_dev *) fore200e->bus_dev)->dev; 2513 device = &((struct pci_dev *) fore200e->bus_dev)->dev;
2514#ifdef CONFIG_SBUS 2514#ifdef CONFIG_SBUS
2515 else if (strcmp(fore200e->bus->model_name, "SBA-200E") == 0) 2515 else if (strcmp(fore200e->bus->model_name, "SBA-200E") == 0)
2516 device = &((struct of_device *) fore200e->bus_dev)->dev; 2516 device = &((struct platform_device *) fore200e->bus_dev)->dev;
2517#endif 2517#endif
2518 else 2518 else
2519 return err; 2519 return err;
@@ -2643,7 +2643,7 @@ fore200e_init(struct fore200e* fore200e)
2643} 2643}
2644 2644
2645#ifdef CONFIG_SBUS 2645#ifdef CONFIG_SBUS
2646static int __devinit fore200e_sba_probe(struct of_device *op, 2646static int __devinit fore200e_sba_probe(struct platform_device *op,
2647 const struct of_device_id *match) 2647 const struct of_device_id *match)
2648{ 2648{
2649 const struct fore200e_bus *bus = match->data; 2649 const struct fore200e_bus *bus = match->data;
@@ -2675,7 +2675,7 @@ static int __devinit fore200e_sba_probe(struct of_device *op,
2675 return 0; 2675 return 0;
2676} 2676}
2677 2677
2678static int __devexit fore200e_sba_remove(struct of_device *op) 2678static int __devexit fore200e_sba_remove(struct platform_device *op)
2679{ 2679{
2680 struct fore200e *fore200e = dev_get_drvdata(&op->dev); 2680 struct fore200e *fore200e = dev_get_drvdata(&op->dev);
2681 2681
diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c
index b71888b909a0..2982b3ee9465 100644
--- a/drivers/block/xsysace.c
+++ b/drivers/block/xsysace.c
@@ -1194,7 +1194,7 @@ static struct platform_driver ace_platform_driver = {
1194 1194
1195#if defined(CONFIG_OF) 1195#if defined(CONFIG_OF)
1196static int __devinit 1196static int __devinit
1197ace_of_probe(struct of_device *op, const struct of_device_id *match) 1197ace_of_probe(struct platform_device *op, const struct of_device_id *match)
1198{ 1198{
1199 struct resource res; 1199 struct resource res;
1200 resource_size_t physaddr; 1200 resource_size_t physaddr;
@@ -1226,7 +1226,7 @@ ace_of_probe(struct of_device *op, const struct of_device_id *match)
1226 return ace_alloc(&op->dev, id ? *id : 0, physaddr, irq, bus_width); 1226 return ace_alloc(&op->dev, id ? *id : 0, physaddr, irq, bus_width);
1227} 1227}
1228 1228
1229static int __devexit ace_of_remove(struct of_device *op) 1229static int __devexit ace_of_remove(struct platform_device *op)
1230{ 1230{
1231 ace_free(&op->dev); 1231 ace_free(&op->dev);
1232 return 0; 1232 return 0;
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 7cfcc629a7fd..3d44ec724c17 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -1002,7 +1002,7 @@ config SCx200_GPIO
1002 1002
1003config PC8736x_GPIO 1003config PC8736x_GPIO
1004 tristate "NatSemi PC8736x GPIO Support" 1004 tristate "NatSemi PC8736x GPIO Support"
1005 depends on X86 1005 depends on X86_32
1006 default SCx200_GPIO # mostly N 1006 default SCx200_GPIO # mostly N
1007 select NSC_GPIO # needed for support routines 1007 select NSC_GPIO # needed for support routines
1008 help 1008 help
diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c
index 5a80ad68ef22..7b01bc609de3 100644
--- a/drivers/char/hvc_iucv.c
+++ b/drivers/char/hvc_iucv.c
@@ -1149,7 +1149,7 @@ out_err:
1149 * Note: If it is called early in the boot process, @val is stored and 1149 * Note: If it is called early in the boot process, @val is stored and
1150 * parsed later in hvc_iucv_init(). 1150 * parsed later in hvc_iucv_init().
1151 */ 1151 */
1152static int param_set_vmidfilter(const char *val, struct kernel_param *kp) 1152static int param_set_vmidfilter(const char *val, const struct kernel_param *kp)
1153{ 1153{
1154 int rc; 1154 int rc;
1155 1155
@@ -1176,7 +1176,7 @@ static int param_set_vmidfilter(const char *val, struct kernel_param *kp)
1176 * The function stores the filter as a comma-separated list of z/VM user IDs 1176 * The function stores the filter as a comma-separated list of z/VM user IDs
1177 * in @buffer. Typically, sysfs routines call this function for attr show. 1177 * in @buffer. Typically, sysfs routines call this function for attr show.
1178 */ 1178 */
1179static int param_get_vmidfilter(char *buffer, struct kernel_param *kp) 1179static int param_get_vmidfilter(char *buffer, const struct kernel_param *kp)
1180{ 1180{
1181 int rc; 1181 int rc;
1182 size_t index, len; 1182 size_t index, len;
@@ -1203,6 +1203,11 @@ static int param_get_vmidfilter(char *buffer, struct kernel_param *kp)
1203 1203
1204#define param_check_vmidfilter(name, p) __param_check(name, p, void) 1204#define param_check_vmidfilter(name, p) __param_check(name, p, void)
1205 1205
1206static struct kernel_param_ops param_ops_vmidfilter = {
1207 .set = param_set_vmidfilter,
1208 .get = param_get_vmidfilter,
1209};
1210
1206/** 1211/**
1207 * hvc_iucv_init() - z/VM IUCV HVC device driver initialization 1212 * hvc_iucv_init() - z/VM IUCV HVC device driver initialization
1208 */ 1213 */
diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c
index 7a4f080f8356..1acdb2509511 100644
--- a/drivers/char/hw_random/n2-drv.c
+++ b/drivers/char/hw_random/n2-drv.c
@@ -619,7 +619,7 @@ static void __devinit n2rng_driver_version(void)
619 pr_info("%s", version); 619 pr_info("%s", version);
620} 620}
621 621
622static int __devinit n2rng_probe(struct of_device *op, 622static int __devinit n2rng_probe(struct platform_device *op,
623 const struct of_device_id *match) 623 const struct of_device_id *match)
624{ 624{
625 int victoria_falls = (match->data != NULL); 625 int victoria_falls = (match->data != NULL);
@@ -714,7 +714,7 @@ out:
714 return err; 714 return err;
715} 715}
716 716
717static int __devexit n2rng_remove(struct of_device *op) 717static int __devexit n2rng_remove(struct platform_device *op)
718{ 718{
719 struct n2rng *np = dev_get_drvdata(&op->dev); 719 struct n2rng *np = dev_get_drvdata(&op->dev);
720 720
diff --git a/drivers/char/hw_random/n2rng.h b/drivers/char/hw_random/n2rng.h
index a2b81e7bfc18..4bea07f30978 100644
--- a/drivers/char/hw_random/n2rng.h
+++ b/drivers/char/hw_random/n2rng.h
@@ -65,7 +65,7 @@ struct n2rng_unit {
65}; 65};
66 66
67struct n2rng { 67struct n2rng {
68 struct of_device *op; 68 struct platform_device *op;
69 69
70 unsigned long flags; 70 unsigned long flags;
71#define N2RNG_FLAG_VF 0x00000001 /* Victoria Falls RNG, else N2 */ 71#define N2RNG_FLAG_VF 0x00000001 /* Victoria Falls RNG, else N2 */
diff --git a/drivers/char/hw_random/pasemi-rng.c b/drivers/char/hw_random/pasemi-rng.c
index 261ba8f22b8b..a31c830ca8cd 100644
--- a/drivers/char/hw_random/pasemi-rng.c
+++ b/drivers/char/hw_random/pasemi-rng.c
@@ -94,7 +94,7 @@ static struct hwrng pasemi_rng = {
94 .data_read = pasemi_rng_data_read, 94 .data_read = pasemi_rng_data_read,
95}; 95};
96 96
97static int __devinit rng_probe(struct of_device *ofdev, 97static int __devinit rng_probe(struct platform_device *ofdev,
98 const struct of_device_id *match) 98 const struct of_device_id *match)
99{ 99{
100 void __iomem *rng_regs; 100 void __iomem *rng_regs;
@@ -123,7 +123,7 @@ static int __devinit rng_probe(struct of_device *ofdev,
123 return err; 123 return err;
124} 124}
125 125
126static int __devexit rng_remove(struct of_device *dev) 126static int __devexit rng_remove(struct platform_device *dev)
127{ 127{
128 void __iomem *rng_regs = (void __iomem *)pasemi_rng.priv; 128 void __iomem *rng_regs = (void __iomem *)pasemi_rng.priv;
129 129
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index ff68e7c34ce7..3822b4f49c84 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -1804,9 +1804,12 @@ static int hotmod_handler(const char *val, struct kernel_param *kp)
1804 info->irq_setup = std_irq_setup; 1804 info->irq_setup = std_irq_setup;
1805 info->slave_addr = ipmb; 1805 info->slave_addr = ipmb;
1806 1806
1807 if (!add_smi(info)) 1807 if (!add_smi(info)) {
1808 if (try_smi_init(info)) 1808 if (try_smi_init(info))
1809 cleanup_one_si(info); 1809 cleanup_one_si(info);
1810 } else {
1811 kfree(info);
1812 }
1810 } else { 1813 } else {
1811 /* remove */ 1814 /* remove */
1812 struct smi_info *e, *tmp_e; 1815 struct smi_info *e, *tmp_e;
@@ -1890,9 +1893,12 @@ static __devinit void hardcode_find_bmc(void)
1890 info->irq_setup = std_irq_setup; 1893 info->irq_setup = std_irq_setup;
1891 info->slave_addr = slave_addrs[i]; 1894 info->slave_addr = slave_addrs[i];
1892 1895
1893 if (!add_smi(info)) 1896 if (!add_smi(info)) {
1894 if (try_smi_init(info)) 1897 if (try_smi_init(info))
1895 cleanup_one_si(info); 1898 cleanup_one_si(info);
1899 } else {
1900 kfree(info);
1901 }
1896 } 1902 }
1897} 1903}
1898 1904
@@ -1965,8 +1971,8 @@ static int acpi_gpe_irq_setup(struct smi_info *info)
1965 1971
1966/* 1972/*
1967 * Defined at 1973 * Defined at
1968 * http://h21007.www2.hp.com/dspp/files/unprotected/devresource/ 1974 * http://h21007.www2.hp.com/portal/download/files
1969 * Docs/TechPapers/IA64/hpspmi.pdf 1975 * /unprot/hpspmi.pdf
1970 */ 1976 */
1971struct SPMITable { 1977struct SPMITable {
1972 s8 Signature[4]; 1978 s8 Signature[4];
@@ -2013,18 +2019,12 @@ struct SPMITable {
2013static __devinit int try_init_spmi(struct SPMITable *spmi) 2019static __devinit int try_init_spmi(struct SPMITable *spmi)
2014{ 2020{
2015 struct smi_info *info; 2021 struct smi_info *info;
2016 u8 addr_space;
2017 2022
2018 if (spmi->IPMIlegacy != 1) { 2023 if (spmi->IPMIlegacy != 1) {
2019 printk(KERN_INFO PFX "Bad SPMI legacy %d\n", spmi->IPMIlegacy); 2024 printk(KERN_INFO PFX "Bad SPMI legacy %d\n", spmi->IPMIlegacy);
2020 return -ENODEV; 2025 return -ENODEV;
2021 } 2026 }
2022 2027
2023 if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
2024 addr_space = IPMI_MEM_ADDR_SPACE;
2025 else
2026 addr_space = IPMI_IO_ADDR_SPACE;
2027
2028 info = kzalloc(sizeof(*info), GFP_KERNEL); 2028 info = kzalloc(sizeof(*info), GFP_KERNEL);
2029 if (!info) { 2029 if (!info) {
2030 printk(KERN_ERR PFX "Could not allocate SI data (3)\n"); 2030 printk(KERN_ERR PFX "Could not allocate SI data (3)\n");
@@ -2088,7 +2088,13 @@ static __devinit int try_init_spmi(struct SPMITable *spmi)
2088 } 2088 }
2089 info->io.addr_data = spmi->addr.address; 2089 info->io.addr_data = spmi->addr.address;
2090 2090
2091 add_smi(info); 2091 pr_info("ipmi_si: SPMI: %s %#lx regsize %d spacing %d irq %d\n",
2092 (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem",
2093 info->io.addr_data, info->io.regsize, info->io.regspacing,
2094 info->irq);
2095
2096 if (add_smi(info))
2097 kfree(info);
2092 2098
2093 return 0; 2099 return 0;
2094} 2100}
@@ -2204,7 +2210,10 @@ static int __devinit ipmi_pnp_probe(struct pnp_dev *dev,
2204 res, info->io.regsize, info->io.regspacing, 2210 res, info->io.regsize, info->io.regspacing,
2205 info->irq); 2211 info->irq);
2206 2212
2207 return add_smi(info); 2213 if (add_smi(info))
2214 goto err_free;
2215
2216 return 0;
2208 2217
2209err_free: 2218err_free:
2210 kfree(info); 2219 kfree(info);
@@ -2362,7 +2371,13 @@ static __devinit void try_init_dmi(struct dmi_ipmi_data *ipmi_data)
2362 if (info->irq) 2371 if (info->irq)
2363 info->irq_setup = std_irq_setup; 2372 info->irq_setup = std_irq_setup;
2364 2373
2365 add_smi(info); 2374 pr_info("ipmi_si: SMBIOS: %s %#lx regsize %d spacing %d irq %d\n",
2375 (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem",
2376 info->io.addr_data, info->io.regsize, info->io.regspacing,
2377 info->irq);
2378
2379 if (add_smi(info))
2380 kfree(info);
2366} 2381}
2367 2382
2368static void __devinit dmi_find_bmc(void) 2383static void __devinit dmi_find_bmc(void)
@@ -2468,7 +2483,10 @@ static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
2468 &pdev->resource[0], info->io.regsize, info->io.regspacing, 2483 &pdev->resource[0], info->io.regsize, info->io.regspacing,
2469 info->irq); 2484 info->irq);
2470 2485
2471 return add_smi(info); 2486 if (add_smi(info))
2487 kfree(info);
2488
2489 return 0;
2472} 2490}
2473 2491
2474static void __devexit ipmi_pci_remove(struct pci_dev *pdev) 2492static void __devexit ipmi_pci_remove(struct pci_dev *pdev)
@@ -2510,7 +2528,7 @@ static struct pci_driver ipmi_pci_driver = {
2510 2528
2511 2529
2512#ifdef CONFIG_PPC_OF 2530#ifdef CONFIG_PPC_OF
2513static int __devinit ipmi_of_probe(struct of_device *dev, 2531static int __devinit ipmi_of_probe(struct platform_device *dev,
2514 const struct of_device_id *match) 2532 const struct of_device_id *match)
2515{ 2533{
2516 struct smi_info *info; 2534 struct smi_info *info;
@@ -2581,10 +2599,15 @@ static int __devinit ipmi_of_probe(struct of_device *dev,
2581 2599
2582 dev_set_drvdata(&dev->dev, info); 2600 dev_set_drvdata(&dev->dev, info);
2583 2601
2584 return add_smi(info); 2602 if (add_smi(info)) {
2603 kfree(info);
2604 return -EBUSY;
2605 }
2606
2607 return 0;
2585} 2608}
2586 2609
2587static int __devexit ipmi_of_remove(struct of_device *dev) 2610static int __devexit ipmi_of_remove(struct platform_device *dev)
2588{ 2611{
2589 cleanup_one_si(dev_get_drvdata(&dev->dev)); 2612 cleanup_one_si(dev_get_drvdata(&dev->dev));
2590 return 0; 2613 return 0;
@@ -3014,6 +3037,8 @@ static __devinit void default_find_bmc(void)
3014 info->io.addr_data); 3037 info->io.addr_data);
3015 } else 3038 } else
3016 cleanup_one_si(info); 3039 cleanup_one_si(info);
3040 } else {
3041 kfree(info);
3017 } 3042 }
3018 } 3043 }
3019} 3044}
@@ -3041,7 +3066,7 @@ static int add_smi(struct smi_info *new_smi)
3041 si_to_str[new_smi->si_type]); 3066 si_to_str[new_smi->si_type]);
3042 mutex_lock(&smi_infos_lock); 3067 mutex_lock(&smi_infos_lock);
3043 if (!is_new_interface(new_smi)) { 3068 if (!is_new_interface(new_smi)) {
3044 printk(KERN_CONT PFX "duplicate interface\n"); 3069 printk(KERN_CONT " duplicate interface\n");
3045 rv = -EBUSY; 3070 rv = -EBUSY;
3046 goto out_err; 3071 goto out_err;
3047 } 3072 }
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 82bcdb262a3a..654d566ca57c 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -196,7 +196,7 @@ static void ipmi_unregister_watchdog(int ipmi_intf);
196 */ 196 */
197static int start_now; 197static int start_now;
198 198
199static int set_param_int(const char *val, struct kernel_param *kp) 199static int set_param_timeout(const char *val, const struct kernel_param *kp)
200{ 200{
201 char *endp; 201 char *endp;
202 int l; 202 int l;
@@ -215,10 +215,11 @@ static int set_param_int(const char *val, struct kernel_param *kp)
215 return rv; 215 return rv;
216} 216}
217 217
218static int get_param_int(char *buffer, struct kernel_param *kp) 218static struct kernel_param_ops param_ops_timeout = {
219{ 219 .set = set_param_timeout,
220 return sprintf(buffer, "%i", *((int *)kp->arg)); 220 .get = param_get_int,
221} 221};
222#define param_check_timeout param_check_int
222 223
223typedef int (*action_fn)(const char *intval, char *outval); 224typedef int (*action_fn)(const char *intval, char *outval);
224 225
@@ -227,7 +228,7 @@ static int preaction_op(const char *inval, char *outval);
227static int preop_op(const char *inval, char *outval); 228static int preop_op(const char *inval, char *outval);
228static void check_parms(void); 229static void check_parms(void);
229 230
230static int set_param_str(const char *val, struct kernel_param *kp) 231static int set_param_str(const char *val, const struct kernel_param *kp)
231{ 232{
232 action_fn fn = (action_fn) kp->arg; 233 action_fn fn = (action_fn) kp->arg;
233 int rv = 0; 234 int rv = 0;
@@ -251,7 +252,7 @@ static int set_param_str(const char *val, struct kernel_param *kp)
251 return rv; 252 return rv;
252} 253}
253 254
254static int get_param_str(char *buffer, struct kernel_param *kp) 255static int get_param_str(char *buffer, const struct kernel_param *kp)
255{ 256{
256 action_fn fn = (action_fn) kp->arg; 257 action_fn fn = (action_fn) kp->arg;
257 int rv; 258 int rv;
@@ -263,7 +264,7 @@ static int get_param_str(char *buffer, struct kernel_param *kp)
263} 264}
264 265
265 266
266static int set_param_wdog_ifnum(const char *val, struct kernel_param *kp) 267static int set_param_wdog_ifnum(const char *val, const struct kernel_param *kp)
267{ 268{
268 int rv = param_set_int(val, kp); 269 int rv = param_set_int(val, kp);
269 if (rv) 270 if (rv)
@@ -276,27 +277,38 @@ static int set_param_wdog_ifnum(const char *val, struct kernel_param *kp)
276 return 0; 277 return 0;
277} 278}
278 279
279module_param_call(ifnum_to_use, set_param_wdog_ifnum, get_param_int, 280static struct kernel_param_ops param_ops_wdog_ifnum = {
280 &ifnum_to_use, 0644); 281 .set = set_param_wdog_ifnum,
282 .get = param_get_int,
283};
284
285#define param_check_wdog_ifnum param_check_int
286
287static struct kernel_param_ops param_ops_str = {
288 .set = set_param_str,
289 .get = get_param_str,
290};
291
292module_param(ifnum_to_use, wdog_ifnum, 0644);
281MODULE_PARM_DESC(ifnum_to_use, "The interface number to use for the watchdog " 293MODULE_PARM_DESC(ifnum_to_use, "The interface number to use for the watchdog "
282 "timer. Setting to -1 defaults to the first registered " 294 "timer. Setting to -1 defaults to the first registered "
283 "interface"); 295 "interface");
284 296
285module_param_call(timeout, set_param_int, get_param_int, &timeout, 0644); 297module_param(timeout, timeout, 0644);
286MODULE_PARM_DESC(timeout, "Timeout value in seconds."); 298MODULE_PARM_DESC(timeout, "Timeout value in seconds.");
287 299
288module_param_call(pretimeout, set_param_int, get_param_int, &pretimeout, 0644); 300module_param(pretimeout, timeout, 0644);
289MODULE_PARM_DESC(pretimeout, "Pretimeout value in seconds."); 301MODULE_PARM_DESC(pretimeout, "Pretimeout value in seconds.");
290 302
291module_param_call(action, set_param_str, get_param_str, action_op, 0644); 303module_param_cb(action, &param_ops_str, action_op, 0644);
292MODULE_PARM_DESC(action, "Timeout action. One of: " 304MODULE_PARM_DESC(action, "Timeout action. One of: "
293 "reset, none, power_cycle, power_off."); 305 "reset, none, power_cycle, power_off.");
294 306
295module_param_call(preaction, set_param_str, get_param_str, preaction_op, 0644); 307module_param_cb(preaction, &param_ops_str, preaction_op, 0644);
296MODULE_PARM_DESC(preaction, "Pretimeout action. One of: " 308MODULE_PARM_DESC(preaction, "Pretimeout action. One of: "
297 "pre_none, pre_smi, pre_nmi, pre_int."); 309 "pre_none, pre_smi, pre_nmi, pre_int.");
298 310
299module_param_call(preop, set_param_str, get_param_str, preop_op, 0644); 311module_param_cb(preop, &param_ops_str, preop_op, 0644);
300MODULE_PARM_DESC(preop, "Pretimeout driver operation. One of: " 312MODULE_PARM_DESC(preop, "Pretimeout driver operation. One of: "
301 "preop_none, preop_panic, preop_give_data."); 313 "preop_none, preop_panic, preop_give_data.");
302 314
diff --git a/drivers/char/n_gsm.c b/drivers/char/n_gsm.c
index 099105e0894e..04ef3ef0a422 100644
--- a/drivers/char/n_gsm.c
+++ b/drivers/char/n_gsm.c
@@ -919,7 +919,7 @@ static void gsm_dlci_data_sweep(struct gsm_mux *gsm)
919 else 919 else
920 len = gsm_dlci_data_output_framed(gsm, dlci); 920 len = gsm_dlci_data_output_framed(gsm, dlci);
921 if (len < 0) 921 if (len < 0)
922 return; 922 break;
923 /* DLCI empty - try the next */ 923 /* DLCI empty - try the next */
924 if (len == 0) 924 if (len == 0)
925 i++; 925 i++;
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
index 18af923093c3..817169cbb245 100644
--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -1743,8 +1743,7 @@ static int ntty_write_room(struct tty_struct *tty)
1743 if (dc) { 1743 if (dc) {
1744 mutex_lock(&port->tty_sem); 1744 mutex_lock(&port->tty_sem);
1745 if (port->port.count) 1745 if (port->port.count)
1746 room = port->fifo_ul.size - 1746 room = kfifo_avail(&port->fifo_ul);
1747 kfifo_len(&port->fifo_ul);
1748 mutex_unlock(&port->tty_sem); 1747 mutex_unlock(&port->tty_sem);
1749 } 1748 }
1750 return room; 1749 return room;
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index 95acb8c880f4..dfa8b3062fda 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -961,7 +961,7 @@ static int __init rtc_init(void)
961#endif 961#endif
962#ifdef CONFIG_SPARC32 962#ifdef CONFIG_SPARC32
963 struct device_node *ebus_dp; 963 struct device_node *ebus_dp;
964 struct of_device *op; 964 struct platform_device *op;
965#else 965#else
966 void *r; 966 void *r;
967#ifdef RTC_IRQ 967#ifdef RTC_IRQ
diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index ed8a9cec2a05..0ed763cd2e77 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -761,7 +761,7 @@ static struct platform_driver hwicap_platform_driver = {
761 761
762#if defined(CONFIG_OF) 762#if defined(CONFIG_OF)
763static int __devinit 763static int __devinit
764hwicap_of_probe(struct of_device *op, const struct of_device_id *match) 764hwicap_of_probe(struct platform_device *op, const struct of_device_id *match)
765{ 765{
766 struct resource res; 766 struct resource res;
767 const unsigned int *id; 767 const unsigned int *id;
@@ -798,7 +798,7 @@ hwicap_of_probe(struct of_device *op, const struct of_device_id *match)
798 regs); 798 regs);
799} 799}
800 800
801static int __devexit hwicap_of_remove(struct of_device *op) 801static int __devexit hwicap_of_remove(struct platform_device *op)
802{ 802{
803 return hwicap_remove(&op->dev); 803 return hwicap_remove(&op->dev);
804} 804}
diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index fbf94cf496f0..ea0b3863ad0f 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -77,7 +77,7 @@ config ZCRYPT
77 77
78config ZCRYPT_MONOLITHIC 78config ZCRYPT_MONOLITHIC
79 bool "Monolithic zcrypt module" 79 bool "Monolithic zcrypt module"
80 depends on ZCRYPT="m" 80 depends on ZCRYPT
81 help 81 help
82 Select this option if you want to have a single module z90crypt, 82 Select this option if you want to have a single module z90crypt,
83 that contains all parts of the crypto device driver (ap bus, 83 that contains all parts of the crypto device driver (ap bus,
diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
index 983530ba04a7..2b1baee525bc 100644
--- a/drivers/crypto/amcc/crypto4xx_core.c
+++ b/drivers/crypto/amcc/crypto4xx_core.c
@@ -1150,7 +1150,7 @@ struct crypto4xx_alg_common crypto4xx_alg[] = {
1150/** 1150/**
1151 * Module Initialization Routine 1151 * Module Initialization Routine
1152 */ 1152 */
1153static int __init crypto4xx_probe(struct of_device *ofdev, 1153static int __init crypto4xx_probe(struct platform_device *ofdev,
1154 const struct of_device_id *match) 1154 const struct of_device_id *match)
1155{ 1155{
1156 int rc; 1156 int rc;
@@ -1258,7 +1258,7 @@ err_alloc_dev:
1258 return rc; 1258 return rc;
1259} 1259}
1260 1260
1261static int __exit crypto4xx_remove(struct of_device *ofdev) 1261static int __exit crypto4xx_remove(struct platform_device *ofdev)
1262{ 1262{
1263 struct device *dev = &ofdev->dev; 1263 struct device *dev = &ofdev->dev;
1264 struct crypto4xx_core_device *core_dev = dev_get_drvdata(dev); 1264 struct crypto4xx_core_device *core_dev = dev_get_drvdata(dev);
diff --git a/drivers/crypto/amcc/crypto4xx_core.h b/drivers/crypto/amcc/crypto4xx_core.h
index da9cbe3b9fc3..bac0bdeb4b5f 100644
--- a/drivers/crypto/amcc/crypto4xx_core.h
+++ b/drivers/crypto/amcc/crypto4xx_core.h
@@ -104,7 +104,7 @@ struct crypto4xx_device {
104 104
105struct crypto4xx_core_device { 105struct crypto4xx_core_device {
106 struct device *device; 106 struct device *device;
107 struct of_device *ofdev; 107 struct platform_device *ofdev;
108 struct crypto4xx_device *dev; 108 struct crypto4xx_device *dev;
109 u32 int_status; 109 u32 int_status;
110 u32 irq; 110 u32 irq;
diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index f17ddf37a1ed..0d662213c066 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -97,8 +97,13 @@
97 97
98struct buffer_desc { 98struct buffer_desc {
99 u32 phys_next; 99 u32 phys_next;
100#ifdef __ARMEB__
100 u16 buf_len; 101 u16 buf_len;
101 u16 pkt_len; 102 u16 pkt_len;
103#else
104 u16 pkt_len;
105 u16 buf_len;
106#endif
102 u32 phys_addr; 107 u32 phys_addr;
103 u32 __reserved[4]; 108 u32 __reserved[4];
104 struct buffer_desc *next; 109 struct buffer_desc *next;
@@ -106,17 +111,30 @@ struct buffer_desc {
106}; 111};
107 112
108struct crypt_ctl { 113struct crypt_ctl {
114#ifdef __ARMEB__
109 u8 mode; /* NPE_OP_* operation mode */ 115 u8 mode; /* NPE_OP_* operation mode */
110 u8 init_len; 116 u8 init_len;
111 u16 reserved; 117 u16 reserved;
118#else
119 u16 reserved;
120 u8 init_len;
121 u8 mode; /* NPE_OP_* operation mode */
122#endif
112 u8 iv[MAX_IVLEN]; /* IV for CBC mode or CTR IV for CTR mode */ 123 u8 iv[MAX_IVLEN]; /* IV for CBC mode or CTR IV for CTR mode */
113 u32 icv_rev_aes; /* icv or rev aes */ 124 u32 icv_rev_aes; /* icv or rev aes */
114 u32 src_buf; 125 u32 src_buf;
115 u32 dst_buf; 126 u32 dst_buf;
127#ifdef __ARMEB__
116 u16 auth_offs; /* Authentication start offset */ 128 u16 auth_offs; /* Authentication start offset */
117 u16 auth_len; /* Authentication data length */ 129 u16 auth_len; /* Authentication data length */
118 u16 crypt_offs; /* Cryption start offset */ 130 u16 crypt_offs; /* Cryption start offset */
119 u16 crypt_len; /* Cryption data length */ 131 u16 crypt_len; /* Cryption data length */
132#else
133 u16 auth_len; /* Authentication data length */
134 u16 auth_offs; /* Authentication start offset */
135 u16 crypt_len; /* Cryption data length */
136 u16 crypt_offs; /* Cryption start offset */
137#endif
120 u32 aadAddr; /* Additional Auth Data Addr for CCM mode */ 138 u32 aadAddr; /* Additional Auth Data Addr for CCM mode */
121 u32 crypto_ctx; /* NPE Crypto Param structure address */ 139 u32 crypto_ctx; /* NPE Crypto Param structure address */
122 140
@@ -652,6 +670,9 @@ static int setup_auth(struct crypto_tfm *tfm, int encrypt, unsigned authsize,
652 670
653 /* write cfg word to cryptinfo */ 671 /* write cfg word to cryptinfo */
654 cfgword = algo->cfgword | ( authsize << 6); /* (authsize/4) << 8 */ 672 cfgword = algo->cfgword | ( authsize << 6); /* (authsize/4) << 8 */
673#ifndef __ARMEB__
674 cfgword ^= 0xAA000000; /* change the "byte swap" flags */
675#endif
655 *(u32*)cinfo = cpu_to_be32(cfgword); 676 *(u32*)cinfo = cpu_to_be32(cfgword);
656 cinfo += sizeof(cfgword); 677 cinfo += sizeof(cfgword);
657 678
diff --git a/drivers/crypto/n2_core.c b/drivers/crypto/n2_core.c
index 26af2dd5d831..88ee01510ec0 100644
--- a/drivers/crypto/n2_core.c
+++ b/drivers/crypto/n2_core.c
@@ -1552,7 +1552,7 @@ static void __exit n2_unregister_algs(void)
1552 1552
1553/* To map CWQ queues to interrupt sources, the hypervisor API provides 1553/* To map CWQ queues to interrupt sources, the hypervisor API provides
1554 * a devino. This isn't very useful to us because all of the 1554 * a devino. This isn't very useful to us because all of the
1555 * interrupts listed in the of_device node have been translated to 1555 * interrupts listed in the device_node have been translated to
1556 * Linux virtual IRQ cookie numbers. 1556 * Linux virtual IRQ cookie numbers.
1557 * 1557 *
1558 * So we have to back-translate, going through the 'intr' and 'ino' 1558 * So we have to back-translate, going through the 'intr' and 'ino'
@@ -1560,7 +1560,7 @@ static void __exit n2_unregister_algs(void)
1560 * 'interrupts' property entries, in order to to figure out which 1560 * 'interrupts' property entries, in order to to figure out which
1561 * devino goes to which already-translated IRQ. 1561 * devino goes to which already-translated IRQ.
1562 */ 1562 */
1563static int find_devino_index(struct of_device *dev, struct spu_mdesc_info *ip, 1563static int find_devino_index(struct platform_device *dev, struct spu_mdesc_info *ip,
1564 unsigned long dev_ino) 1564 unsigned long dev_ino)
1565{ 1565{
1566 const unsigned int *dev_intrs; 1566 const unsigned int *dev_intrs;
@@ -1580,7 +1580,7 @@ static int find_devino_index(struct of_device *dev, struct spu_mdesc_info *ip,
1580 if (!dev_intrs) 1580 if (!dev_intrs)
1581 return -ENODEV; 1581 return -ENODEV;
1582 1582
1583 for (i = 0; i < dev->num_irqs; i++) { 1583 for (i = 0; i < dev->archdata.num_irqs; i++) {
1584 if (dev_intrs[i] == intr) 1584 if (dev_intrs[i] == intr)
1585 return i; 1585 return i;
1586 } 1586 }
@@ -1588,7 +1588,7 @@ static int find_devino_index(struct of_device *dev, struct spu_mdesc_info *ip,
1588 return -ENODEV; 1588 return -ENODEV;
1589} 1589}
1590 1590
1591static int spu_map_ino(struct of_device *dev, struct spu_mdesc_info *ip, 1591static int spu_map_ino(struct platform_device *dev, struct spu_mdesc_info *ip,
1592 const char *irq_name, struct spu_queue *p, 1592 const char *irq_name, struct spu_queue *p,
1593 irq_handler_t handler) 1593 irq_handler_t handler)
1594{ 1594{
@@ -1603,7 +1603,7 @@ static int spu_map_ino(struct of_device *dev, struct spu_mdesc_info *ip,
1603 if (index < 0) 1603 if (index < 0)
1604 return index; 1604 return index;
1605 1605
1606 p->irq = dev->irqs[index]; 1606 p->irq = dev->archdata.irqs[index];
1607 1607
1608 sprintf(p->irq_name, "%s-%d", irq_name, index); 1608 sprintf(p->irq_name, "%s-%d", irq_name, index);
1609 1609
@@ -1736,7 +1736,7 @@ static void spu_list_destroy(struct list_head *list)
1736 * gathering cpu membership information. 1736 * gathering cpu membership information.
1737 */ 1737 */
1738static int spu_mdesc_walk_arcs(struct mdesc_handle *mdesc, 1738static int spu_mdesc_walk_arcs(struct mdesc_handle *mdesc,
1739 struct of_device *dev, 1739 struct platform_device *dev,
1740 u64 node, struct spu_queue *p, 1740 u64 node, struct spu_queue *p,
1741 struct spu_queue **table) 1741 struct spu_queue **table)
1742{ 1742{
@@ -1763,7 +1763,7 @@ static int spu_mdesc_walk_arcs(struct mdesc_handle *mdesc,
1763 1763
1764/* Process an 'exec-unit' MDESC node of type 'cwq'. */ 1764/* Process an 'exec-unit' MDESC node of type 'cwq'. */
1765static int handle_exec_unit(struct spu_mdesc_info *ip, struct list_head *list, 1765static int handle_exec_unit(struct spu_mdesc_info *ip, struct list_head *list,
1766 struct of_device *dev, struct mdesc_handle *mdesc, 1766 struct platform_device *dev, struct mdesc_handle *mdesc,
1767 u64 node, const char *iname, unsigned long q_type, 1767 u64 node, const char *iname, unsigned long q_type,
1768 irq_handler_t handler, struct spu_queue **table) 1768 irq_handler_t handler, struct spu_queue **table)
1769{ 1769{
@@ -1794,7 +1794,7 @@ static int handle_exec_unit(struct spu_mdesc_info *ip, struct list_head *list,
1794 return spu_map_ino(dev, ip, iname, p, handler); 1794 return spu_map_ino(dev, ip, iname, p, handler);
1795} 1795}
1796 1796
1797static int spu_mdesc_scan(struct mdesc_handle *mdesc, struct of_device *dev, 1797static int spu_mdesc_scan(struct mdesc_handle *mdesc, struct platform_device *dev,
1798 struct spu_mdesc_info *ip, struct list_head *list, 1798 struct spu_mdesc_info *ip, struct list_head *list,
1799 const char *exec_name, unsigned long q_type, 1799 const char *exec_name, unsigned long q_type,
1800 irq_handler_t handler, struct spu_queue **table) 1800 irq_handler_t handler, struct spu_queue **table)
@@ -1855,7 +1855,7 @@ static int __devinit get_irq_props(struct mdesc_handle *mdesc, u64 node,
1855} 1855}
1856 1856
1857static int __devinit grab_mdesc_irq_props(struct mdesc_handle *mdesc, 1857static int __devinit grab_mdesc_irq_props(struct mdesc_handle *mdesc,
1858 struct of_device *dev, 1858 struct platform_device *dev,
1859 struct spu_mdesc_info *ip, 1859 struct spu_mdesc_info *ip,
1860 const char *node_name) 1860 const char *node_name)
1861{ 1861{
@@ -2004,7 +2004,7 @@ static void __devinit n2_spu_driver_version(void)
2004 pr_info("%s", version); 2004 pr_info("%s", version);
2005} 2005}
2006 2006
2007static int __devinit n2_crypto_probe(struct of_device *dev, 2007static int __devinit n2_crypto_probe(struct platform_device *dev,
2008 const struct of_device_id *match) 2008 const struct of_device_id *match)
2009{ 2009{
2010 struct mdesc_handle *mdesc; 2010 struct mdesc_handle *mdesc;
@@ -2081,7 +2081,7 @@ out_free_n2cp:
2081 return err; 2081 return err;
2082} 2082}
2083 2083
2084static int __devexit n2_crypto_remove(struct of_device *dev) 2084static int __devexit n2_crypto_remove(struct platform_device *dev)
2085{ 2085{
2086 struct n2_crypto *np = dev_get_drvdata(&dev->dev); 2086 struct n2_crypto *np = dev_get_drvdata(&dev->dev);
2087 2087
@@ -2116,7 +2116,7 @@ static void free_ncp(struct n2_mau *mp)
2116 kfree(mp); 2116 kfree(mp);
2117} 2117}
2118 2118
2119static int __devinit n2_mau_probe(struct of_device *dev, 2119static int __devinit n2_mau_probe(struct platform_device *dev,
2120 const struct of_device_id *match) 2120 const struct of_device_id *match)
2121{ 2121{
2122 struct mdesc_handle *mdesc; 2122 struct mdesc_handle *mdesc;
@@ -2184,7 +2184,7 @@ out_free_ncp:
2184 return err; 2184 return err;
2185} 2185}
2186 2186
2187static int __devexit n2_mau_remove(struct of_device *dev) 2187static int __devexit n2_mau_remove(struct platform_device *dev)
2188{ 2188{
2189 struct n2_mau *mp = dev_get_drvdata(&dev->dev); 2189 struct n2_mau *mp = dev_get_drvdata(&dev->dev);
2190 2190
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 97f4af1d8a64..4bcd825b5739 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -118,7 +118,7 @@ struct talitos_channel {
118 118
119struct talitos_private { 119struct talitos_private {
120 struct device *dev; 120 struct device *dev;
121 struct of_device *ofdev; 121 struct platform_device *ofdev;
122 void __iomem *reg; 122 void __iomem *reg;
123 int irq; 123 int irq;
124 124
@@ -2308,7 +2308,7 @@ static int hw_supports(struct device *dev, __be32 desc_hdr_template)
2308 return ret; 2308 return ret;
2309} 2309}
2310 2310
2311static int talitos_remove(struct of_device *ofdev) 2311static int talitos_remove(struct platform_device *ofdev)
2312{ 2312{
2313 struct device *dev = &ofdev->dev; 2313 struct device *dev = &ofdev->dev;
2314 struct talitos_private *priv = dev_get_drvdata(dev); 2314 struct talitos_private *priv = dev_get_drvdata(dev);
@@ -2401,7 +2401,7 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
2401 return t_alg; 2401 return t_alg;
2402} 2402}
2403 2403
2404static int talitos_probe(struct of_device *ofdev, 2404static int talitos_probe(struct platform_device *ofdev,
2405 const struct of_device_id *match) 2405 const struct of_device_id *match)
2406{ 2406{
2407 struct device *dev = &ofdev->dev; 2407 struct device *dev = &ofdev->dev;
diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
index fed57634b6c1..9520cf02edc8 100644
--- a/drivers/dma/Kconfig
+++ b/drivers/dma/Kconfig
@@ -141,7 +141,7 @@ config TXX9_DMAC
141 141
142config SH_DMAE 142config SH_DMAE
143 tristate "Renesas SuperH DMAC support" 143 tristate "Renesas SuperH DMAC support"
144 depends on SUPERH && SH_DMA 144 depends on (SUPERH && SH_DMA) || (ARM && ARCH_SHMOBILE)
145 depends on !SH_DMA_API 145 depends on !SH_DMA_API
146 select DMA_ENGINE 146 select DMA_ENGINE
147 help 147 help
diff --git a/drivers/dma/fsldma.c b/drivers/dma/fsldma.c
index f0fd6db6063c..cea08bed9cf9 100644
--- a/drivers/dma/fsldma.c
+++ b/drivers/dma/fsldma.c
@@ -1297,7 +1297,7 @@ static void fsl_dma_chan_remove(struct fsldma_chan *chan)
1297 kfree(chan); 1297 kfree(chan);
1298} 1298}
1299 1299
1300static int __devinit fsldma_of_probe(struct of_device *op, 1300static int __devinit fsldma_of_probe(struct platform_device *op,
1301 const struct of_device_id *match) 1301 const struct of_device_id *match)
1302{ 1302{
1303 struct fsldma_device *fdev; 1303 struct fsldma_device *fdev;
@@ -1382,7 +1382,7 @@ out_return:
1382 return err; 1382 return err;
1383} 1383}
1384 1384
1385static int fsldma_of_remove(struct of_device *op) 1385static int fsldma_of_remove(struct platform_device *op)
1386{ 1386{
1387 struct fsldma_device *fdev; 1387 struct fsldma_device *fdev;
1388 unsigned int i; 1388 unsigned int i;
diff --git a/drivers/dma/mpc512x_dma.c b/drivers/dma/mpc512x_dma.c
index 14a8c0f1698e..4e9cbf300594 100644
--- a/drivers/dma/mpc512x_dma.c
+++ b/drivers/dma/mpc512x_dma.c
@@ -627,7 +627,7 @@ mpc_dma_prep_memcpy(struct dma_chan *chan, dma_addr_t dst, dma_addr_t src,
627 return &mdesc->desc; 627 return &mdesc->desc;
628} 628}
629 629
630static int __devinit mpc_dma_probe(struct of_device *op, 630static int __devinit mpc_dma_probe(struct platform_device *op,
631 const struct of_device_id *match) 631 const struct of_device_id *match)
632{ 632{
633 struct device_node *dn = op->dev.of_node; 633 struct device_node *dn = op->dev.of_node;
@@ -753,7 +753,7 @@ static int __devinit mpc_dma_probe(struct of_device *op,
753 return retval; 753 return retval;
754} 754}
755 755
756static int __devexit mpc_dma_remove(struct of_device *op) 756static int __devexit mpc_dma_remove(struct platform_device *op)
757{ 757{
758 struct device *dev = &op->dev; 758 struct device *dev = &op->dev;
759 struct mpc_dma *mdma = dev_get_drvdata(dev); 759 struct mpc_dma *mdma = dev_get_drvdata(dev);
diff --git a/drivers/dma/ppc4xx/adma.c b/drivers/dma/ppc4xx/adma.c
index 7c3747902a37..0d58a4a4487f 100644
--- a/drivers/dma/ppc4xx/adma.c
+++ b/drivers/dma/ppc4xx/adma.c
@@ -4257,11 +4257,11 @@ static int ppc440spe_adma_setup_irqs(struct ppc440spe_adma_device *adev,
4257 struct ppc440spe_adma_chan *chan, 4257 struct ppc440spe_adma_chan *chan,
4258 int *initcode) 4258 int *initcode)
4259{ 4259{
4260 struct of_device *ofdev; 4260 struct platform_device *ofdev;
4261 struct device_node *np; 4261 struct device_node *np;
4262 int ret; 4262 int ret;
4263 4263
4264 ofdev = container_of(adev->dev, struct of_device, dev); 4264 ofdev = container_of(adev->dev, struct platform_device, dev);
4265 np = ofdev->dev.of_node; 4265 np = ofdev->dev.of_node;
4266 if (adev->id != PPC440SPE_XOR_ID) { 4266 if (adev->id != PPC440SPE_XOR_ID) {
4267 adev->err_irq = irq_of_parse_and_map(np, 1); 4267 adev->err_irq = irq_of_parse_and_map(np, 1);
@@ -4393,7 +4393,7 @@ static void ppc440spe_adma_release_irqs(struct ppc440spe_adma_device *adev,
4393/** 4393/**
4394 * ppc440spe_adma_probe - probe the asynch device 4394 * ppc440spe_adma_probe - probe the asynch device
4395 */ 4395 */
4396static int __devinit ppc440spe_adma_probe(struct of_device *ofdev, 4396static int __devinit ppc440spe_adma_probe(struct platform_device *ofdev,
4397 const struct of_device_id *match) 4397 const struct of_device_id *match)
4398{ 4398{
4399 struct device_node *np = ofdev->dev.of_node; 4399 struct device_node *np = ofdev->dev.of_node;
@@ -4625,7 +4625,7 @@ out:
4625/** 4625/**
4626 * ppc440spe_adma_remove - remove the asynch device 4626 * ppc440spe_adma_remove - remove the asynch device
4627 */ 4627 */
4628static int __devexit ppc440spe_adma_remove(struct of_device *ofdev) 4628static int __devexit ppc440spe_adma_remove(struct platform_device *ofdev)
4629{ 4629{
4630 struct ppc440spe_adma_device *adev = dev_get_drvdata(&ofdev->dev); 4630 struct ppc440spe_adma_device *adev = dev_get_drvdata(&ofdev->dev);
4631 struct device_node *np = ofdev->dev.of_node; 4631 struct device_node *np = ofdev->dev.of_node;
diff --git a/drivers/dma/shdma.c b/drivers/dma/shdma.c
index a2a519fd2a24..fb64cf36ba61 100644
--- a/drivers/dma/shdma.c
+++ b/drivers/dma/shdma.c
@@ -816,7 +816,7 @@ static irqreturn_t sh_dmae_interrupt(int irq, void *data)
816 return ret; 816 return ret;
817} 817}
818 818
819#if defined(CONFIG_CPU_SH4) 819#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE)
820static irqreturn_t sh_dmae_err(int irq, void *data) 820static irqreturn_t sh_dmae_err(int irq, void *data)
821{ 821{
822 struct sh_dmae_device *shdev = (struct sh_dmae_device *)data; 822 struct sh_dmae_device *shdev = (struct sh_dmae_device *)data;
@@ -1057,7 +1057,7 @@ static int __init sh_dmae_probe(struct platform_device *pdev)
1057 /* Default transfer size of 32 bytes requires 32-byte alignment */ 1057 /* Default transfer size of 32 bytes requires 32-byte alignment */
1058 shdev->common.copy_align = LOG2_DEFAULT_XFER_SIZE; 1058 shdev->common.copy_align = LOG2_DEFAULT_XFER_SIZE;
1059 1059
1060#if defined(CONFIG_CPU_SH4) 1060#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE)
1061 chanirq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 1); 1061 chanirq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
1062 1062
1063 if (!chanirq_res) 1063 if (!chanirq_res)
@@ -1082,7 +1082,7 @@ static int __init sh_dmae_probe(struct platform_device *pdev)
1082 1082
1083#else 1083#else
1084 chanirq_res = errirq_res; 1084 chanirq_res = errirq_res;
1085#endif /* CONFIG_CPU_SH4 */ 1085#endif /* CONFIG_CPU_SH4 || CONFIG_ARCH_SHMOBILE */
1086 1086
1087 if (chanirq_res->start == chanirq_res->end && 1087 if (chanirq_res->start == chanirq_res->end &&
1088 !platform_get_resource(pdev, IORESOURCE_IRQ, 1)) { 1088 !platform_get_resource(pdev, IORESOURCE_IRQ, 1)) {
@@ -1129,7 +1129,7 @@ static int __init sh_dmae_probe(struct platform_device *pdev)
1129chan_probe_err: 1129chan_probe_err:
1130 sh_dmae_chan_remove(shdev); 1130 sh_dmae_chan_remove(shdev);
1131eirqres: 1131eirqres:
1132#if defined(CONFIG_CPU_SH4) 1132#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE)
1133 free_irq(errirq, shdev); 1133 free_irq(errirq, shdev);
1134eirq_err: 1134eirq_err:
1135#endif 1135#endif
diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
index 996c1bdb5a34..a5cefab8d65d 100644
--- a/drivers/edac/i5000_edac.c
+++ b/drivers/edac/i5000_edac.c
@@ -1482,7 +1482,7 @@ static int __devinit i5000_init_one(struct pci_dev *pdev,
1482 1482
1483 /* wake up device */ 1483 /* wake up device */
1484 rc = pci_enable_device(pdev); 1484 rc = pci_enable_device(pdev);
1485 if (rc == -EIO) 1485 if (rc)
1486 return rc; 1486 return rc;
1487 1487
1488 /* now probe and enable the device */ 1488 /* now probe and enable the device */
diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
index 010c1d6526f5..38a9be9e1c7c 100644
--- a/drivers/edac/i5400_edac.c
+++ b/drivers/edac/i5400_edac.c
@@ -1348,7 +1348,7 @@ static int __devinit i5400_init_one(struct pci_dev *pdev,
1348 1348
1349 /* wake up device */ 1349 /* wake up device */
1350 rc = pci_enable_device(pdev); 1350 rc = pci_enable_device(pdev);
1351 if (rc == -EIO) 1351 if (rc)
1352 return rc; 1352 return rc;
1353 1353
1354 /* now probe and enable the device */ 1354 /* now probe and enable the device */
diff --git a/drivers/edac/mpc85xx_edac.c b/drivers/edac/mpc85xx_edac.c
index 1052340e6802..b123bb308a4a 100644
--- a/drivers/edac/mpc85xx_edac.c
+++ b/drivers/edac/mpc85xx_edac.c
@@ -43,7 +43,7 @@ static u32 orig_pci_err_en;
43#endif 43#endif
44 44
45static u32 orig_l2_err_disable; 45static u32 orig_l2_err_disable;
46#ifdef CONFIG_MPC85xx 46#ifdef CONFIG_FSL_SOC_BOOKE
47static u32 orig_hid1[2]; 47static u32 orig_hid1[2];
48#endif 48#endif
49 49
@@ -200,7 +200,7 @@ static irqreturn_t mpc85xx_pci_isr(int irq, void *dev_id)
200 return IRQ_HANDLED; 200 return IRQ_HANDLED;
201} 201}
202 202
203static int __devinit mpc85xx_pci_err_probe(struct of_device *op, 203static int __devinit mpc85xx_pci_err_probe(struct platform_device *op,
204 const struct of_device_id *match) 204 const struct of_device_id *match)
205{ 205{
206 struct edac_pci_ctl_info *pci; 206 struct edac_pci_ctl_info *pci;
@@ -305,7 +305,7 @@ err:
305 return res; 305 return res;
306} 306}
307 307
308static int mpc85xx_pci_err_remove(struct of_device *op) 308static int mpc85xx_pci_err_remove(struct platform_device *op)
309{ 309{
310 struct edac_pci_ctl_info *pci = dev_get_drvdata(&op->dev); 310 struct edac_pci_ctl_info *pci = dev_get_drvdata(&op->dev);
311 struct mpc85xx_pci_pdata *pdata = pci->pvt_info; 311 struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
@@ -503,7 +503,7 @@ static irqreturn_t mpc85xx_l2_isr(int irq, void *dev_id)
503 return IRQ_HANDLED; 503 return IRQ_HANDLED;
504} 504}
505 505
506static int __devinit mpc85xx_l2_err_probe(struct of_device *op, 506static int __devinit mpc85xx_l2_err_probe(struct platform_device *op,
507 const struct of_device_id *match) 507 const struct of_device_id *match)
508{ 508{
509 struct edac_device_ctl_info *edac_dev; 509 struct edac_device_ctl_info *edac_dev;
@@ -613,7 +613,7 @@ err:
613 return res; 613 return res;
614} 614}
615 615
616static int mpc85xx_l2_err_remove(struct of_device *op) 616static int mpc85xx_l2_err_remove(struct platform_device *op)
617{ 617{
618 struct edac_device_ctl_info *edac_dev = dev_get_drvdata(&op->dev); 618 struct edac_device_ctl_info *edac_dev = dev_get_drvdata(&op->dev);
619 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info; 619 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
@@ -647,7 +647,10 @@ static struct of_device_id mpc85xx_l2_err_of_match[] = {
647 { .compatible = "fsl,mpc8555-l2-cache-controller", }, 647 { .compatible = "fsl,mpc8555-l2-cache-controller", },
648 { .compatible = "fsl,mpc8560-l2-cache-controller", }, 648 { .compatible = "fsl,mpc8560-l2-cache-controller", },
649 { .compatible = "fsl,mpc8568-l2-cache-controller", }, 649 { .compatible = "fsl,mpc8568-l2-cache-controller", },
650 { .compatible = "fsl,mpc8569-l2-cache-controller", },
650 { .compatible = "fsl,mpc8572-l2-cache-controller", }, 651 { .compatible = "fsl,mpc8572-l2-cache-controller", },
652 { .compatible = "fsl,p1020-l2-cache-controller", },
653 { .compatible = "fsl,p1021-l2-cache-controller", },
651 { .compatible = "fsl,p2020-l2-cache-controller", }, 654 { .compatible = "fsl,p2020-l2-cache-controller", },
652 {}, 655 {},
653}; 656};
@@ -953,7 +956,7 @@ static void __devinit mpc85xx_init_csrows(struct mem_ctl_info *mci)
953 } 956 }
954} 957}
955 958
956static int __devinit mpc85xx_mc_err_probe(struct of_device *op, 959static int __devinit mpc85xx_mc_err_probe(struct platform_device *op,
957 const struct of_device_id *match) 960 const struct of_device_id *match)
958{ 961{
959 struct mem_ctl_info *mci; 962 struct mem_ctl_info *mci;
@@ -1085,7 +1088,7 @@ err:
1085 return res; 1088 return res;
1086} 1089}
1087 1090
1088static int mpc85xx_mc_err_remove(struct of_device *op) 1091static int mpc85xx_mc_err_remove(struct platform_device *op)
1089{ 1092{
1090 struct mem_ctl_info *mci = dev_get_drvdata(&op->dev); 1093 struct mem_ctl_info *mci = dev_get_drvdata(&op->dev);
1091 struct mpc85xx_mc_pdata *pdata = mci->pvt_info; 1094 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
@@ -1125,7 +1128,10 @@ static struct of_device_id mpc85xx_mc_err_of_match[] = {
1125 { .compatible = "fsl,mpc8569-memory-controller", }, 1128 { .compatible = "fsl,mpc8569-memory-controller", },
1126 { .compatible = "fsl,mpc8572-memory-controller", }, 1129 { .compatible = "fsl,mpc8572-memory-controller", },
1127 { .compatible = "fsl,mpc8349-memory-controller", }, 1130 { .compatible = "fsl,mpc8349-memory-controller", },
1131 { .compatible = "fsl,p1020-memory-controller", },
1132 { .compatible = "fsl,p1021-memory-controller", },
1128 { .compatible = "fsl,p2020-memory-controller", }, 1133 { .compatible = "fsl,p2020-memory-controller", },
1134 { .compatible = "fsl,p4080-memory-controller", },
1129 {}, 1135 {},
1130}; 1136};
1131MODULE_DEVICE_TABLE(of, mpc85xx_mc_err_of_match); 1137MODULE_DEVICE_TABLE(of, mpc85xx_mc_err_of_match);
@@ -1140,7 +1146,7 @@ static struct of_platform_driver mpc85xx_mc_err_driver = {
1140 }, 1146 },
1141}; 1147};
1142 1148
1143#ifdef CONFIG_MPC85xx 1149#ifdef CONFIG_FSL_SOC_BOOKE
1144static void __init mpc85xx_mc_clear_rfxe(void *data) 1150static void __init mpc85xx_mc_clear_rfxe(void *data)
1145{ 1151{
1146 orig_hid1[smp_processor_id()] = mfspr(SPRN_HID1); 1152 orig_hid1[smp_processor_id()] = mfspr(SPRN_HID1);
@@ -1179,7 +1185,7 @@ static int __init mpc85xx_mc_init(void)
1179 printk(KERN_WARNING EDAC_MOD_STR "PCI fails to register\n"); 1185 printk(KERN_WARNING EDAC_MOD_STR "PCI fails to register\n");
1180#endif 1186#endif
1181 1187
1182#ifdef CONFIG_MPC85xx 1188#ifdef CONFIG_FSL_SOC_BOOKE
1183 /* 1189 /*
1184 * need to clear HID1[RFXE] to disable machine check int 1190 * need to clear HID1[RFXE] to disable machine check int
1185 * so we can catch it 1191 * so we can catch it
@@ -1193,7 +1199,7 @@ static int __init mpc85xx_mc_init(void)
1193 1199
1194module_init(mpc85xx_mc_init); 1200module_init(mpc85xx_mc_init);
1195 1201
1196#ifdef CONFIG_MPC85xx 1202#ifdef CONFIG_FSL_SOC_BOOKE
1197static void __exit mpc85xx_mc_restore_hid1(void *data) 1203static void __exit mpc85xx_mc_restore_hid1(void *data)
1198{ 1204{
1199 mtspr(SPRN_HID1, orig_hid1[smp_processor_id()]); 1205 mtspr(SPRN_HID1, orig_hid1[smp_processor_id()]);
@@ -1202,7 +1208,7 @@ static void __exit mpc85xx_mc_restore_hid1(void *data)
1202 1208
1203static void __exit mpc85xx_mc_exit(void) 1209static void __exit mpc85xx_mc_exit(void)
1204{ 1210{
1205#ifdef CONFIG_MPC85xx 1211#ifdef CONFIG_FSL_SOC_BOOKE
1206 on_each_cpu(mpc85xx_mc_restore_hid1, NULL, 0); 1212 on_each_cpu(mpc85xx_mc_restore_hid1, NULL, 0);
1207#endif 1213#endif
1208#ifdef CONFIG_PCI 1214#ifdef CONFIG_PCI
diff --git a/drivers/edac/ppc4xx_edac.c b/drivers/edac/ppc4xx_edac.c
index e78839e89a06..070cea41b661 100644
--- a/drivers/edac/ppc4xx_edac.c
+++ b/drivers/edac/ppc4xx_edac.c
@@ -184,9 +184,9 @@ struct ppc4xx_ecc_status {
184 184
185/* Function Prototypes */ 185/* Function Prototypes */
186 186
187static int ppc4xx_edac_probe(struct of_device *device, 187static int ppc4xx_edac_probe(struct platform_device *device,
188 const struct of_device_id *device_id); 188 const struct of_device_id *device_id);
189static int ppc4xx_edac_remove(struct of_device *device); 189static int ppc4xx_edac_remove(struct platform_device *device);
190 190
191/* Global Variables */ 191/* Global Variables */
192 192
@@ -1014,7 +1014,7 @@ ppc4xx_edac_init_csrows(struct mem_ctl_info *mci, u32 mcopt1)
1014 */ 1014 */
1015static int __devinit 1015static int __devinit
1016ppc4xx_edac_mc_init(struct mem_ctl_info *mci, 1016ppc4xx_edac_mc_init(struct mem_ctl_info *mci,
1017 struct of_device *op, 1017 struct platform_device *op,
1018 const struct of_device_id *match, 1018 const struct of_device_id *match,
1019 const dcr_host_t *dcr_host, 1019 const dcr_host_t *dcr_host,
1020 u32 mcopt1) 1020 u32 mcopt1)
@@ -1108,7 +1108,7 @@ ppc4xx_edac_mc_init(struct mem_ctl_info *mci,
1108 * mapped and assigned. 1108 * mapped and assigned.
1109 */ 1109 */
1110static int __devinit 1110static int __devinit
1111ppc4xx_edac_register_irq(struct of_device *op, struct mem_ctl_info *mci) 1111ppc4xx_edac_register_irq(struct platform_device *op, struct mem_ctl_info *mci)
1112{ 1112{
1113 int status = 0; 1113 int status = 0;
1114 int ded_irq, sec_irq; 1114 int ded_irq, sec_irq;
@@ -1238,7 +1238,7 @@ ppc4xx_edac_map_dcrs(const struct device_node *np, dcr_host_t *dcr_host)
1238 * driver; otherwise, < 0 on error. 1238 * driver; otherwise, < 0 on error.
1239 */ 1239 */
1240static int __devinit 1240static int __devinit
1241ppc4xx_edac_probe(struct of_device *op, const struct of_device_id *match) 1241ppc4xx_edac_probe(struct platform_device *op, const struct of_device_id *match)
1242{ 1242{
1243 int status = 0; 1243 int status = 0;
1244 u32 mcopt1, memcheck; 1244 u32 mcopt1, memcheck;
@@ -1359,7 +1359,7 @@ ppc4xx_edac_probe(struct of_device *op, const struct of_device_id *match)
1359 * Unconditionally returns 0. 1359 * Unconditionally returns 0.
1360 */ 1360 */
1361static int 1361static int
1362ppc4xx_edac_remove(struct of_device *op) 1362ppc4xx_edac_remove(struct platform_device *op)
1363{ 1363{
1364 struct mem_ctl_info *mci = dev_get_drvdata(&op->dev); 1364 struct mem_ctl_info *mci = dev_get_drvdata(&op->dev);
1365 struct ppc4xx_edac_pdata *pdata = mci->pvt_info; 1365 struct ppc4xx_edac_pdata *pdata = mci->pvt_info;
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 7face915b963..510aa2054544 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -195,6 +195,24 @@ config GPIO_PCF857X
195 This driver provides an in-kernel interface to those GPIOs using 195 This driver provides an in-kernel interface to those GPIOs using
196 platform-neutral GPIO calls. 196 platform-neutral GPIO calls.
197 197
198config GPIO_SX150X
199 bool "Semtech SX150x I2C GPIO expander"
200 depends on I2C=y
201 default n
202 help
203 Say yes here to provide support for Semtech SX150-series I2C
204 GPIO expanders. Compatible models include:
205
206 8 bits: sx1508q
207 16 bits: sx1509q
208
209config GPIO_STMPE
210 bool "STMPE GPIOs"
211 depends on MFD_STMPE
212 help
213 This enables support for the GPIOs found on the STMPE I/O
214 Expanders.
215
198config GPIO_TC35892 216config GPIO_TC35892
199 bool "TC35892 GPIOs" 217 bool "TC35892 GPIOs"
200 depends on MFD_TC35892 218 depends on MFD_TC35892
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index e53dcff49b4f..fc6019d93720 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o
20obj-$(CONFIG_GPIO_PCA953X) += pca953x.o 20obj-$(CONFIG_GPIO_PCA953X) += pca953x.o
21obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o 21obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o
22obj-$(CONFIG_GPIO_PL061) += pl061.o 22obj-$(CONFIG_GPIO_PL061) += pl061.o
23obj-$(CONFIG_GPIO_STMPE) += stmpe-gpio.o
23obj-$(CONFIG_GPIO_TC35892) += tc35892-gpio.o 24obj-$(CONFIG_GPIO_TC35892) += tc35892-gpio.o
24obj-$(CONFIG_GPIO_TIMBERDALE) += timbgpio.o 25obj-$(CONFIG_GPIO_TIMBERDALE) += timbgpio.o
25obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o 26obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o
@@ -35,3 +36,4 @@ obj-$(CONFIG_GPIO_WM8994) += wm8994-gpio.o
35obj-$(CONFIG_GPIO_SCH) += sch_gpio.o 36obj-$(CONFIG_GPIO_SCH) += sch_gpio.o
36obj-$(CONFIG_GPIO_RDC321X) += rdc321x-gpio.o 37obj-$(CONFIG_GPIO_RDC321X) += rdc321x-gpio.o
37obj-$(CONFIG_GPIO_JANZ_TTL) += janz-ttl.o 38obj-$(CONFIG_GPIO_JANZ_TTL) += janz-ttl.o
39obj-$(CONFIG_GPIO_SX150X) += sx150x.o
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 6a6bd569e1f8..21da9c19a0cb 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -57,9 +57,9 @@ struct gpio_desc {
57#define FLAG_TRIG_RISE 6 /* trigger on rising edge */ 57#define FLAG_TRIG_RISE 6 /* trigger on rising edge */
58#define FLAG_ACTIVE_LOW 7 /* sysfs value has active low */ 58#define FLAG_ACTIVE_LOW 7 /* sysfs value has active low */
59 59
60#define PDESC_ID_SHIFT 16 /* add new flags before this one */ 60#define ID_SHIFT 16 /* add new flags before this one */
61 61
62#define GPIO_FLAGS_MASK ((1 << PDESC_ID_SHIFT) - 1) 62#define GPIO_FLAGS_MASK ((1 << ID_SHIFT) - 1)
63#define GPIO_TRIGGER_MASK (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE)) 63#define GPIO_TRIGGER_MASK (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE))
64 64
65#ifdef CONFIG_DEBUG_FS 65#ifdef CONFIG_DEBUG_FS
@@ -69,12 +69,7 @@ struct gpio_desc {
69static struct gpio_desc gpio_desc[ARCH_NR_GPIOS]; 69static struct gpio_desc gpio_desc[ARCH_NR_GPIOS];
70 70
71#ifdef CONFIG_GPIO_SYSFS 71#ifdef CONFIG_GPIO_SYSFS
72struct poll_desc { 72static DEFINE_IDR(dirent_idr);
73 struct work_struct work;
74 struct sysfs_dirent *value_sd;
75};
76
77static struct idr pdesc_idr;
78#endif 73#endif
79 74
80static inline void desc_set_label(struct gpio_desc *d, const char *label) 75static inline void desc_set_label(struct gpio_desc *d, const char *label)
@@ -325,24 +320,16 @@ static const DEVICE_ATTR(value, 0644,
325 320
326static irqreturn_t gpio_sysfs_irq(int irq, void *priv) 321static irqreturn_t gpio_sysfs_irq(int irq, void *priv)
327{ 322{
328 struct work_struct *work = priv; 323 struct sysfs_dirent *value_sd = priv;
329 324
330 schedule_work(work); 325 sysfs_notify_dirent(value_sd);
331 return IRQ_HANDLED; 326 return IRQ_HANDLED;
332} 327}
333 328
334static void gpio_notify_sysfs(struct work_struct *work)
335{
336 struct poll_desc *pdesc;
337
338 pdesc = container_of(work, struct poll_desc, work);
339 sysfs_notify_dirent(pdesc->value_sd);
340}
341
342static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev, 329static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev,
343 unsigned long gpio_flags) 330 unsigned long gpio_flags)
344{ 331{
345 struct poll_desc *pdesc; 332 struct sysfs_dirent *value_sd;
346 unsigned long irq_flags; 333 unsigned long irq_flags;
347 int ret, irq, id; 334 int ret, irq, id;
348 335
@@ -353,18 +340,16 @@ static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev,
353 if (irq < 0) 340 if (irq < 0)
354 return -EIO; 341 return -EIO;
355 342
356 id = desc->flags >> PDESC_ID_SHIFT; 343 id = desc->flags >> ID_SHIFT;
357 pdesc = idr_find(&pdesc_idr, id); 344 value_sd = idr_find(&dirent_idr, id);
358 if (pdesc) { 345 if (value_sd)
359 free_irq(irq, &pdesc->work); 346 free_irq(irq, value_sd);
360 cancel_work_sync(&pdesc->work);
361 }
362 347
363 desc->flags &= ~GPIO_TRIGGER_MASK; 348 desc->flags &= ~GPIO_TRIGGER_MASK;
364 349
365 if (!gpio_flags) { 350 if (!gpio_flags) {
366 ret = 0; 351 ret = 0;
367 goto free_sd; 352 goto free_id;
368 } 353 }
369 354
370 irq_flags = IRQF_SHARED; 355 irq_flags = IRQF_SHARED;
@@ -375,55 +360,46 @@ static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev,
375 irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? 360 irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ?
376 IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; 361 IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
377 362
378 if (!pdesc) { 363 if (!value_sd) {
379 pdesc = kmalloc(sizeof(*pdesc), GFP_KERNEL); 364 value_sd = sysfs_get_dirent(dev->kobj.sd, NULL, "value");
380 if (!pdesc) { 365 if (!value_sd) {
381 ret = -ENOMEM; 366 ret = -ENODEV;
382 goto err_out; 367 goto err_out;
383 } 368 }
384 369
385 do { 370 do {
386 ret = -ENOMEM; 371 ret = -ENOMEM;
387 if (idr_pre_get(&pdesc_idr, GFP_KERNEL)) 372 if (idr_pre_get(&dirent_idr, GFP_KERNEL))
388 ret = idr_get_new_above(&pdesc_idr, 373 ret = idr_get_new_above(&dirent_idr, value_sd,
389 pdesc, 1, &id); 374 1, &id);
390 } while (ret == -EAGAIN); 375 } while (ret == -EAGAIN);
391 376
392 if (ret) 377 if (ret)
393 goto free_mem; 378 goto free_sd;
394 379
395 desc->flags &= GPIO_FLAGS_MASK; 380 desc->flags &= GPIO_FLAGS_MASK;
396 desc->flags |= (unsigned long)id << PDESC_ID_SHIFT; 381 desc->flags |= (unsigned long)id << ID_SHIFT;
397 382
398 if (desc->flags >> PDESC_ID_SHIFT != id) { 383 if (desc->flags >> ID_SHIFT != id) {
399 ret = -ERANGE; 384 ret = -ERANGE;
400 goto free_id; 385 goto free_id;
401 } 386 }
402
403 pdesc->value_sd = sysfs_get_dirent(dev->kobj.sd, NULL, "value");
404 if (!pdesc->value_sd) {
405 ret = -ENODEV;
406 goto free_id;
407 }
408 INIT_WORK(&pdesc->work, gpio_notify_sysfs);
409 } 387 }
410 388
411 ret = request_irq(irq, gpio_sysfs_irq, irq_flags, 389 ret = request_any_context_irq(irq, gpio_sysfs_irq, irq_flags,
412 "gpiolib", &pdesc->work); 390 "gpiolib", value_sd);
413 if (ret) 391 if (ret < 0)
414 goto free_sd; 392 goto free_id;
415 393
416 desc->flags |= gpio_flags; 394 desc->flags |= gpio_flags;
417 return 0; 395 return 0;
418 396
419free_sd:
420 if (pdesc)
421 sysfs_put(pdesc->value_sd);
422free_id: 397free_id:
423 idr_remove(&pdesc_idr, id); 398 idr_remove(&dirent_idr, id);
424 desc->flags &= GPIO_FLAGS_MASK; 399 desc->flags &= GPIO_FLAGS_MASK;
425free_mem: 400free_sd:
426 kfree(pdesc); 401 if (value_sd)
402 sysfs_put(value_sd);
427err_out: 403err_out:
428 return ret; 404 return ret;
429} 405}
@@ -994,8 +970,6 @@ static int __init gpiolib_sysfs_init(void)
994 unsigned long flags; 970 unsigned long flags;
995 unsigned gpio; 971 unsigned gpio;
996 972
997 idr_init(&pdesc_idr);
998
999 status = class_register(&gpio_class); 973 status = class_register(&gpio_class);
1000 if (status < 0) 974 if (status < 0)
1001 return status; 975 return status;
@@ -1272,7 +1246,7 @@ void gpio_free(unsigned gpio)
1272 if (chip && test_bit(FLAG_REQUESTED, &desc->flags)) { 1246 if (chip && test_bit(FLAG_REQUESTED, &desc->flags)) {
1273 if (chip->free) { 1247 if (chip->free) {
1274 spin_unlock_irqrestore(&gpio_lock, flags); 1248 spin_unlock_irqrestore(&gpio_lock, flags);
1275 might_sleep_if(extra_checks && chip->can_sleep); 1249 might_sleep_if(chip->can_sleep);
1276 chip->free(chip, gpio - chip->base); 1250 chip->free(chip, gpio - chip->base);
1277 spin_lock_irqsave(&gpio_lock, flags); 1251 spin_lock_irqsave(&gpio_lock, flags);
1278 } 1252 }
@@ -1410,7 +1384,7 @@ int gpio_direction_input(unsigned gpio)
1410 1384
1411 spin_unlock_irqrestore(&gpio_lock, flags); 1385 spin_unlock_irqrestore(&gpio_lock, flags);
1412 1386
1413 might_sleep_if(extra_checks && chip->can_sleep); 1387 might_sleep_if(chip->can_sleep);
1414 1388
1415 if (status) { 1389 if (status) {
1416 status = chip->request(chip, gpio); 1390 status = chip->request(chip, gpio);
@@ -1463,7 +1437,7 @@ int gpio_direction_output(unsigned gpio, int value)
1463 1437
1464 spin_unlock_irqrestore(&gpio_lock, flags); 1438 spin_unlock_irqrestore(&gpio_lock, flags);
1465 1439
1466 might_sleep_if(extra_checks && chip->can_sleep); 1440 might_sleep_if(chip->can_sleep);
1467 1441
1468 if (status) { 1442 if (status) {
1469 status = chip->request(chip, gpio); 1443 status = chip->request(chip, gpio);
@@ -1521,7 +1495,7 @@ int gpio_set_debounce(unsigned gpio, unsigned debounce)
1521 1495
1522 spin_unlock_irqrestore(&gpio_lock, flags); 1496 spin_unlock_irqrestore(&gpio_lock, flags);
1523 1497
1524 might_sleep_if(extra_checks && chip->can_sleep); 1498 might_sleep_if(chip->can_sleep);
1525 1499
1526 return chip->set_debounce(chip, gpio, debounce); 1500 return chip->set_debounce(chip, gpio, debounce);
1527 1501
@@ -1571,7 +1545,7 @@ int __gpio_get_value(unsigned gpio)
1571 struct gpio_chip *chip; 1545 struct gpio_chip *chip;
1572 1546
1573 chip = gpio_to_chip(gpio); 1547 chip = gpio_to_chip(gpio);
1574 WARN_ON(extra_checks && chip->can_sleep); 1548 WARN_ON(chip->can_sleep);
1575 return chip->get ? chip->get(chip, gpio - chip->base) : 0; 1549 return chip->get ? chip->get(chip, gpio - chip->base) : 0;
1576} 1550}
1577EXPORT_SYMBOL_GPL(__gpio_get_value); 1551EXPORT_SYMBOL_GPL(__gpio_get_value);
@@ -1590,7 +1564,7 @@ void __gpio_set_value(unsigned gpio, int value)
1590 struct gpio_chip *chip; 1564 struct gpio_chip *chip;
1591 1565
1592 chip = gpio_to_chip(gpio); 1566 chip = gpio_to_chip(gpio);
1593 WARN_ON(extra_checks && chip->can_sleep); 1567 WARN_ON(chip->can_sleep);
1594 chip->set(chip, gpio - chip->base, value); 1568 chip->set(chip, gpio - chip->base, value);
1595} 1569}
1596EXPORT_SYMBOL_GPL(__gpio_set_value); 1570EXPORT_SYMBOL_GPL(__gpio_set_value);
diff --git a/drivers/gpio/max730x.c b/drivers/gpio/max730x.c
index 7696a5625d58..94ce773f95f8 100644
--- a/drivers/gpio/max730x.c
+++ b/drivers/gpio/max730x.c
@@ -54,7 +54,7 @@ static int max7301_direction_input(struct gpio_chip *chip, unsigned offset)
54{ 54{
55 struct max7301 *ts = container_of(chip, struct max7301, chip); 55 struct max7301 *ts = container_of(chip, struct max7301, chip);
56 u8 *config; 56 u8 *config;
57 u8 offset_bits; 57 u8 offset_bits, pin_config;
58 int ret; 58 int ret;
59 59
60 /* First 4 pins are unused in the controller */ 60 /* First 4 pins are unused in the controller */
@@ -63,12 +63,15 @@ static int max7301_direction_input(struct gpio_chip *chip, unsigned offset)
63 63
64 config = &ts->port_config[offset >> 2]; 64 config = &ts->port_config[offset >> 2];
65 65
66 if (ts->input_pullup_active & BIT(offset))
67 pin_config = PIN_CONFIG_IN_PULLUP;
68 else
69 pin_config = PIN_CONFIG_IN_WO_PULLUP;
70
66 mutex_lock(&ts->lock); 71 mutex_lock(&ts->lock);
67 72
68 /* Standard GPIO API doesn't support pull-ups, has to be extended.
69 * Hard-coding no pollup for now. */
70 *config = (*config & ~(PIN_CONFIG_MASK << offset_bits)) 73 *config = (*config & ~(PIN_CONFIG_MASK << offset_bits))
71 | (PIN_CONFIG_IN_WO_PULLUP << offset_bits); 74 | (pin_config << offset_bits);
72 75
73 ret = ts->write(ts->dev, 0x08 + (offset >> 2), *config); 76 ret = ts->write(ts->dev, 0x08 + (offset >> 2), *config);
74 77
@@ -177,6 +180,7 @@ int __devinit __max730x_probe(struct max7301 *ts)
177 /* Power up the chip and disable IRQ output */ 180 /* Power up the chip and disable IRQ output */
178 ts->write(dev, 0x04, 0x01); 181 ts->write(dev, 0x04, 0x01);
179 182
183 ts->input_pullup_active = pdata->input_pullup_active;
180 ts->chip.label = dev->driver->name; 184 ts->chip.label = dev->driver->name;
181 185
182 ts->chip.direction_input = max7301_direction_input; 186 ts->chip.direction_input = max7301_direction_input;
@@ -191,13 +195,17 @@ int __devinit __max730x_probe(struct max7301 *ts)
191 ts->chip.owner = THIS_MODULE; 195 ts->chip.owner = THIS_MODULE;
192 196
193 /* 197 /*
194 * tristate all pins in hardware and cache the 198 * initialize pullups according to platform data and cache the
195 * register values for later use. 199 * register values for later use.
196 */ 200 */
197 for (i = 1; i < 8; i++) { 201 for (i = 1; i < 8; i++) {
198 int j; 202 int j;
199 /* 0xAA means input with internal pullup disabled */ 203 /*
200 ts->write(dev, 0x08 + i, 0xAA); 204 * initialize port_config with "0xAA", which means
205 * input with internal pullup disabled. This is needed
206 * to avoid writing zeros (in the inner for loop),
207 * which is not allowed according to the datasheet.
208 */
201 ts->port_config[i] = 0xAA; 209 ts->port_config[i] = 0xAA;
202 for (j = 0; j < 4; j++) { 210 for (j = 0; j < 4; j++) {
203 int offset = (i - 1) * 4 + j; 211 int offset = (i - 1) * 4 + j;
diff --git a/drivers/gpio/pcf857x.c b/drivers/gpio/pcf857x.c
index 29f19ce3e80f..879b473aab5a 100644
--- a/drivers/gpio/pcf857x.c
+++ b/drivers/gpio/pcf857x.c
@@ -190,7 +190,6 @@ static int pcf857x_probe(struct i2c_client *client,
190 pdata = client->dev.platform_data; 190 pdata = client->dev.platform_data;
191 if (!pdata) { 191 if (!pdata) {
192 dev_dbg(&client->dev, "no platform data\n"); 192 dev_dbg(&client->dev, "no platform data\n");
193 return -EINVAL;
194 } 193 }
195 194
196 /* Allocate, initialize, and register this gpio_chip. */ 195 /* Allocate, initialize, and register this gpio_chip. */
@@ -200,7 +199,7 @@ static int pcf857x_probe(struct i2c_client *client,
200 199
201 mutex_init(&gpio->lock); 200 mutex_init(&gpio->lock);
202 201
203 gpio->chip.base = pdata->gpio_base; 202 gpio->chip.base = pdata ? pdata->gpio_base : -1;
204 gpio->chip.can_sleep = 1; 203 gpio->chip.can_sleep = 1;
205 gpio->chip.dev = &client->dev; 204 gpio->chip.dev = &client->dev;
206 gpio->chip.owner = THIS_MODULE; 205 gpio->chip.owner = THIS_MODULE;
@@ -278,7 +277,7 @@ static int pcf857x_probe(struct i2c_client *client,
278 * to zero, our software copy of the "latch" then matches the chip's 277 * to zero, our software copy of the "latch" then matches the chip's
279 * all-ones reset state. Otherwise it flags pins to be driven low. 278 * all-ones reset state. Otherwise it flags pins to be driven low.
280 */ 279 */
281 gpio->out = ~pdata->n_latch; 280 gpio->out = pdata ? ~pdata->n_latch : ~0;
282 281
283 status = gpiochip_add(&gpio->chip); 282 status = gpiochip_add(&gpio->chip);
284 if (status < 0) 283 if (status < 0)
@@ -299,7 +298,7 @@ static int pcf857x_probe(struct i2c_client *client,
299 /* Let platform code set up the GPIOs and their users. 298 /* Let platform code set up the GPIOs and their users.
300 * Now is the first time anyone could use them. 299 * Now is the first time anyone could use them.
301 */ 300 */
302 if (pdata->setup) { 301 if (pdata && pdata->setup) {
303 status = pdata->setup(client, 302 status = pdata->setup(client,
304 gpio->chip.base, gpio->chip.ngpio, 303 gpio->chip.base, gpio->chip.ngpio,
305 pdata->context); 304 pdata->context);
@@ -322,7 +321,7 @@ static int pcf857x_remove(struct i2c_client *client)
322 struct pcf857x *gpio = i2c_get_clientdata(client); 321 struct pcf857x *gpio = i2c_get_clientdata(client);
323 int status = 0; 322 int status = 0;
324 323
325 if (pdata->teardown) { 324 if (pdata && pdata->teardown) {
326 status = pdata->teardown(client, 325 status = pdata->teardown(client,
327 gpio->chip.base, gpio->chip.ngpio, 326 gpio->chip.base, gpio->chip.ngpio,
328 pdata->context); 327 pdata->context);
diff --git a/drivers/gpio/stmpe-gpio.c b/drivers/gpio/stmpe-gpio.c
new file mode 100644
index 000000000000..4e1f1b9d5e67
--- /dev/null
+++ b/drivers/gpio/stmpe-gpio.c
@@ -0,0 +1,399 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
6 */
7
8#include <linux/module.h>
9#include <linux/init.h>
10#include <linux/platform_device.h>
11#include <linux/slab.h>
12#include <linux/gpio.h>
13#include <linux/irq.h>
14#include <linux/interrupt.h>
15#include <linux/mfd/stmpe.h>
16
17/*
18 * These registers are modified under the irq bus lock and cached to avoid
19 * unnecessary writes in bus_sync_unlock.
20 */
21enum { REG_RE, REG_FE, REG_IE };
22
23#define CACHE_NR_REGS 3
24#define CACHE_NR_BANKS (STMPE_NR_GPIOS / 8)
25
26struct stmpe_gpio {
27 struct gpio_chip chip;
28 struct stmpe *stmpe;
29 struct device *dev;
30 struct mutex irq_lock;
31
32 int irq_base;
33
34 /* Caches of interrupt control registers for bus_lock */
35 u8 regs[CACHE_NR_REGS][CACHE_NR_BANKS];
36 u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS];
37};
38
39static inline struct stmpe_gpio *to_stmpe_gpio(struct gpio_chip *chip)
40{
41 return container_of(chip, struct stmpe_gpio, chip);
42}
43
44static int stmpe_gpio_get(struct gpio_chip *chip, unsigned offset)
45{
46 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
47 struct stmpe *stmpe = stmpe_gpio->stmpe;
48 u8 reg = stmpe->regs[STMPE_IDX_GPMR_LSB] - (offset / 8);
49 u8 mask = 1 << (offset % 8);
50 int ret;
51
52 ret = stmpe_reg_read(stmpe, reg);
53 if (ret < 0)
54 return ret;
55
56 return ret & mask;
57}
58
59static void stmpe_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
60{
61 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
62 struct stmpe *stmpe = stmpe_gpio->stmpe;
63 int which = val ? STMPE_IDX_GPSR_LSB : STMPE_IDX_GPCR_LSB;
64 u8 reg = stmpe->regs[which] - (offset / 8);
65 u8 mask = 1 << (offset % 8);
66
67 stmpe_reg_write(stmpe, reg, mask);
68}
69
70static int stmpe_gpio_direction_output(struct gpio_chip *chip,
71 unsigned offset, int val)
72{
73 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
74 struct stmpe *stmpe = stmpe_gpio->stmpe;
75 u8 reg = stmpe->regs[STMPE_IDX_GPDR_LSB] - (offset / 8);
76 u8 mask = 1 << (offset % 8);
77
78 stmpe_gpio_set(chip, offset, val);
79
80 return stmpe_set_bits(stmpe, reg, mask, mask);
81}
82
83static int stmpe_gpio_direction_input(struct gpio_chip *chip,
84 unsigned offset)
85{
86 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
87 struct stmpe *stmpe = stmpe_gpio->stmpe;
88 u8 reg = stmpe->regs[STMPE_IDX_GPDR_LSB] - (offset / 8);
89 u8 mask = 1 << (offset % 8);
90
91 return stmpe_set_bits(stmpe, reg, mask, 0);
92}
93
94static int stmpe_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
95{
96 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
97
98 return stmpe_gpio->irq_base + offset;
99}
100
101static int stmpe_gpio_request(struct gpio_chip *chip, unsigned offset)
102{
103 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
104 struct stmpe *stmpe = stmpe_gpio->stmpe;
105
106 return stmpe_set_altfunc(stmpe, 1 << offset, STMPE_BLOCK_GPIO);
107}
108
109static struct gpio_chip template_chip = {
110 .label = "stmpe",
111 .owner = THIS_MODULE,
112 .direction_input = stmpe_gpio_direction_input,
113 .get = stmpe_gpio_get,
114 .direction_output = stmpe_gpio_direction_output,
115 .set = stmpe_gpio_set,
116 .to_irq = stmpe_gpio_to_irq,
117 .request = stmpe_gpio_request,
118 .can_sleep = 1,
119};
120
121static int stmpe_gpio_irq_set_type(unsigned int irq, unsigned int type)
122{
123 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq);
124 int offset = irq - stmpe_gpio->irq_base;
125 int regoffset = offset / 8;
126 int mask = 1 << (offset % 8);
127
128 if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH)
129 return -EINVAL;
130
131 if (type == IRQ_TYPE_EDGE_RISING)
132 stmpe_gpio->regs[REG_RE][regoffset] |= mask;
133 else
134 stmpe_gpio->regs[REG_RE][regoffset] &= ~mask;
135
136 if (type == IRQ_TYPE_EDGE_FALLING)
137 stmpe_gpio->regs[REG_FE][regoffset] |= mask;
138 else
139 stmpe_gpio->regs[REG_FE][regoffset] &= ~mask;
140
141 return 0;
142}
143
144static void stmpe_gpio_irq_lock(unsigned int irq)
145{
146 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq);
147
148 mutex_lock(&stmpe_gpio->irq_lock);
149}
150
151static void stmpe_gpio_irq_sync_unlock(unsigned int irq)
152{
153 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq);
154 struct stmpe *stmpe = stmpe_gpio->stmpe;
155 int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8);
156 static const u8 regmap[] = {
157 [REG_RE] = STMPE_IDX_GPRER_LSB,
158 [REG_FE] = STMPE_IDX_GPFER_LSB,
159 [REG_IE] = STMPE_IDX_IEGPIOR_LSB,
160 };
161 int i, j;
162
163 for (i = 0; i < CACHE_NR_REGS; i++) {
164 for (j = 0; j < num_banks; j++) {
165 u8 old = stmpe_gpio->oldregs[i][j];
166 u8 new = stmpe_gpio->regs[i][j];
167
168 if (new == old)
169 continue;
170
171 stmpe_gpio->oldregs[i][j] = new;
172 stmpe_reg_write(stmpe, stmpe->regs[regmap[i]] - j, new);
173 }
174 }
175
176 mutex_unlock(&stmpe_gpio->irq_lock);
177}
178
179static void stmpe_gpio_irq_mask(unsigned int irq)
180{
181 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq);
182 int offset = irq - stmpe_gpio->irq_base;
183 int regoffset = offset / 8;
184 int mask = 1 << (offset % 8);
185
186 stmpe_gpio->regs[REG_IE][regoffset] &= ~mask;
187}
188
189static void stmpe_gpio_irq_unmask(unsigned int irq)
190{
191 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq);
192 int offset = irq - stmpe_gpio->irq_base;
193 int regoffset = offset / 8;
194 int mask = 1 << (offset % 8);
195
196 stmpe_gpio->regs[REG_IE][regoffset] |= mask;
197}
198
199static struct irq_chip stmpe_gpio_irq_chip = {
200 .name = "stmpe-gpio",
201 .bus_lock = stmpe_gpio_irq_lock,
202 .bus_sync_unlock = stmpe_gpio_irq_sync_unlock,
203 .mask = stmpe_gpio_irq_mask,
204 .unmask = stmpe_gpio_irq_unmask,
205 .set_type = stmpe_gpio_irq_set_type,
206};
207
208static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
209{
210 struct stmpe_gpio *stmpe_gpio = dev;
211 struct stmpe *stmpe = stmpe_gpio->stmpe;
212 u8 statmsbreg = stmpe->regs[STMPE_IDX_ISGPIOR_MSB];
213 int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8);
214 u8 status[num_banks];
215 int ret;
216 int i;
217
218 ret = stmpe_block_read(stmpe, statmsbreg, num_banks, status);
219 if (ret < 0)
220 return IRQ_NONE;
221
222 for (i = 0; i < num_banks; i++) {
223 int bank = num_banks - i - 1;
224 unsigned int enabled = stmpe_gpio->regs[REG_IE][bank];
225 unsigned int stat = status[i];
226
227 stat &= enabled;
228 if (!stat)
229 continue;
230
231 while (stat) {
232 int bit = __ffs(stat);
233 int line = bank * 8 + bit;
234
235 handle_nested_irq(stmpe_gpio->irq_base + line);
236 stat &= ~(1 << bit);
237 }
238
239 stmpe_reg_write(stmpe, statmsbreg + i, status[i]);
240 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_GPEDR_MSB] + i,
241 status[i]);
242 }
243
244 return IRQ_HANDLED;
245}
246
247static int __devinit stmpe_gpio_irq_init(struct stmpe_gpio *stmpe_gpio)
248{
249 int base = stmpe_gpio->irq_base;
250 int irq;
251
252 for (irq = base; irq < base + stmpe_gpio->chip.ngpio; irq++) {
253 set_irq_chip_data(irq, stmpe_gpio);
254 set_irq_chip_and_handler(irq, &stmpe_gpio_irq_chip,
255 handle_simple_irq);
256 set_irq_nested_thread(irq, 1);
257#ifdef CONFIG_ARM
258 set_irq_flags(irq, IRQF_VALID);
259#else
260 set_irq_noprobe(irq);
261#endif
262 }
263
264 return 0;
265}
266
267static void stmpe_gpio_irq_remove(struct stmpe_gpio *stmpe_gpio)
268{
269 int base = stmpe_gpio->irq_base;
270 int irq;
271
272 for (irq = base; irq < base + stmpe_gpio->chip.ngpio; irq++) {
273#ifdef CONFIG_ARM
274 set_irq_flags(irq, 0);
275#endif
276 set_irq_chip_and_handler(irq, NULL, NULL);
277 set_irq_chip_data(irq, NULL);
278 }
279}
280
281static int __devinit stmpe_gpio_probe(struct platform_device *pdev)
282{
283 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
284 struct stmpe_gpio_platform_data *pdata;
285 struct stmpe_gpio *stmpe_gpio;
286 int ret;
287 int irq;
288
289 pdata = stmpe->pdata->gpio;
290 if (!pdata)
291 return -ENODEV;
292
293 irq = platform_get_irq(pdev, 0);
294 if (irq < 0)
295 return irq;
296
297 stmpe_gpio = kzalloc(sizeof(struct stmpe_gpio), GFP_KERNEL);
298 if (!stmpe_gpio)
299 return -ENOMEM;
300
301 mutex_init(&stmpe_gpio->irq_lock);
302
303 stmpe_gpio->dev = &pdev->dev;
304 stmpe_gpio->stmpe = stmpe;
305
306 stmpe_gpio->chip = template_chip;
307 stmpe_gpio->chip.ngpio = stmpe->num_gpios;
308 stmpe_gpio->chip.dev = &pdev->dev;
309 stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1;
310
311 stmpe_gpio->irq_base = stmpe->irq_base + STMPE_INT_GPIO(0);
312
313 ret = stmpe_enable(stmpe, STMPE_BLOCK_GPIO);
314 if (ret)
315 return ret;
316
317 ret = stmpe_gpio_irq_init(stmpe_gpio);
318 if (ret)
319 goto out_free;
320
321 ret = request_threaded_irq(irq, NULL, stmpe_gpio_irq, IRQF_ONESHOT,
322 "stmpe-gpio", stmpe_gpio);
323 if (ret) {
324 dev_err(&pdev->dev, "unable to get irq: %d\n", ret);
325 goto out_removeirq;
326 }
327
328 ret = gpiochip_add(&stmpe_gpio->chip);
329 if (ret) {
330 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
331 goto out_freeirq;
332 }
333
334 if (pdata && pdata->setup)
335 pdata->setup(stmpe, stmpe_gpio->chip.base);
336
337 platform_set_drvdata(pdev, stmpe_gpio);
338
339 return 0;
340
341out_freeirq:
342 free_irq(irq, stmpe_gpio);
343out_removeirq:
344 stmpe_gpio_irq_remove(stmpe_gpio);
345out_free:
346 kfree(stmpe_gpio);
347 return ret;
348}
349
350static int __devexit stmpe_gpio_remove(struct platform_device *pdev)
351{
352 struct stmpe_gpio *stmpe_gpio = platform_get_drvdata(pdev);
353 struct stmpe *stmpe = stmpe_gpio->stmpe;
354 struct stmpe_gpio_platform_data *pdata = stmpe->pdata->gpio;
355 int irq = platform_get_irq(pdev, 0);
356 int ret;
357
358 if (pdata && pdata->remove)
359 pdata->remove(stmpe, stmpe_gpio->chip.base);
360
361 ret = gpiochip_remove(&stmpe_gpio->chip);
362 if (ret < 0) {
363 dev_err(stmpe_gpio->dev,
364 "unable to remove gpiochip: %d\n", ret);
365 return ret;
366 }
367
368 stmpe_disable(stmpe, STMPE_BLOCK_GPIO);
369
370 free_irq(irq, stmpe_gpio);
371 stmpe_gpio_irq_remove(stmpe_gpio);
372 platform_set_drvdata(pdev, NULL);
373 kfree(stmpe_gpio);
374
375 return 0;
376}
377
378static struct platform_driver stmpe_gpio_driver = {
379 .driver.name = "stmpe-gpio",
380 .driver.owner = THIS_MODULE,
381 .probe = stmpe_gpio_probe,
382 .remove = __devexit_p(stmpe_gpio_remove),
383};
384
385static int __init stmpe_gpio_init(void)
386{
387 return platform_driver_register(&stmpe_gpio_driver);
388}
389subsys_initcall(stmpe_gpio_init);
390
391static void __exit stmpe_gpio_exit(void)
392{
393 platform_driver_unregister(&stmpe_gpio_driver);
394}
395module_exit(stmpe_gpio_exit);
396
397MODULE_LICENSE("GPL v2");
398MODULE_DESCRIPTION("STMPExxxx GPIO driver");
399MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");
diff --git a/drivers/gpio/sx150x.c b/drivers/gpio/sx150x.c
new file mode 100644
index 000000000000..b42f42ca70c3
--- /dev/null
+++ b/drivers/gpio/sx150x.c
@@ -0,0 +1,645 @@
1/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17#include <linux/gpio.h>
18#include <linux/i2c.h>
19#include <linux/init.h>
20#include <linux/interrupt.h>
21#include <linux/irq.h>
22#include <linux/module.h>
23#include <linux/mutex.h>
24#include <linux/slab.h>
25#include <linux/workqueue.h>
26#include <linux/i2c/sx150x.h>
27
28struct sx150x_device_data {
29 u8 reg_pullup;
30 u8 reg_pulldn;
31 u8 reg_drain;
32 u8 reg_polarity;
33 u8 reg_dir;
34 u8 reg_data;
35 u8 reg_irq_mask;
36 u8 reg_irq_src;
37 u8 reg_sense;
38 u8 reg_clock;
39 u8 reg_misc;
40 u8 reg_reset;
41 u8 ngpios;
42};
43
44struct sx150x_chip {
45 struct gpio_chip gpio_chip;
46 struct i2c_client *client;
47 const struct sx150x_device_data *dev_cfg;
48 int irq_summary;
49 int irq_base;
50 u32 irq_sense;
51 unsigned long irq_set_type_pending;
52 struct irq_chip irq_chip;
53 struct mutex lock;
54};
55
56static const struct sx150x_device_data sx150x_devices[] = {
57 [0] = { /* sx1508q */
58 .reg_pullup = 0x03,
59 .reg_pulldn = 0x04,
60 .reg_drain = 0x05,
61 .reg_polarity = 0x06,
62 .reg_dir = 0x07,
63 .reg_data = 0x08,
64 .reg_irq_mask = 0x09,
65 .reg_irq_src = 0x0c,
66 .reg_sense = 0x0b,
67 .reg_clock = 0x0f,
68 .reg_misc = 0x10,
69 .reg_reset = 0x7d,
70 .ngpios = 8
71 },
72 [1] = { /* sx1509q */
73 .reg_pullup = 0x07,
74 .reg_pulldn = 0x09,
75 .reg_drain = 0x0b,
76 .reg_polarity = 0x0d,
77 .reg_dir = 0x0f,
78 .reg_data = 0x11,
79 .reg_irq_mask = 0x13,
80 .reg_irq_src = 0x19,
81 .reg_sense = 0x17,
82 .reg_clock = 0x1e,
83 .reg_misc = 0x1f,
84 .reg_reset = 0x7d,
85 .ngpios = 16
86 },
87};
88
89static const struct i2c_device_id sx150x_id[] = {
90 {"sx1508q", 0},
91 {"sx1509q", 1},
92 {}
93};
94MODULE_DEVICE_TABLE(i2c, sx150x_id);
95
96static s32 sx150x_i2c_write(struct i2c_client *client, u8 reg, u8 val)
97{
98 s32 err = i2c_smbus_write_byte_data(client, reg, val);
99
100 if (err < 0)
101 dev_warn(&client->dev,
102 "i2c write fail: can't write %02x to %02x: %d\n",
103 val, reg, err);
104 return err;
105}
106
107static s32 sx150x_i2c_read(struct i2c_client *client, u8 reg, u8 *val)
108{
109 s32 err = i2c_smbus_read_byte_data(client, reg);
110
111 if (err >= 0)
112 *val = err;
113 else
114 dev_warn(&client->dev,
115 "i2c read fail: can't read from %02x: %d\n",
116 reg, err);
117 return err;
118}
119
120static inline bool offset_is_oscio(struct sx150x_chip *chip, unsigned offset)
121{
122 return (chip->dev_cfg->ngpios == offset);
123}
124
125/*
126 * These utility functions solve the common problem of locating and setting
127 * configuration bits. Configuration bits are grouped into registers
128 * whose indexes increase downwards. For example, with eight-bit registers,
129 * sixteen gpios would have their config bits grouped in the following order:
130 * REGISTER N-1 [ f e d c b a 9 8 ]
131 * N [ 7 6 5 4 3 2 1 0 ]
132 *
133 * For multi-bit configurations, the pattern gets wider:
134 * REGISTER N-3 [ f f e e d d c c ]
135 * N-2 [ b b a a 9 9 8 8 ]
136 * N-1 [ 7 7 6 6 5 5 4 4 ]
137 * N [ 3 3 2 2 1 1 0 0 ]
138 *
139 * Given the address of the starting register 'N', the index of the gpio
140 * whose configuration we seek to change, and the width in bits of that
141 * configuration, these functions allow us to locate the correct
142 * register and mask the correct bits.
143 */
144static inline void sx150x_find_cfg(u8 offset, u8 width,
145 u8 *reg, u8 *mask, u8 *shift)
146{
147 *reg -= offset * width / 8;
148 *mask = (1 << width) - 1;
149 *shift = (offset * width) % 8;
150 *mask <<= *shift;
151}
152
153static s32 sx150x_write_cfg(struct sx150x_chip *chip,
154 u8 offset, u8 width, u8 reg, u8 val)
155{
156 u8 mask;
157 u8 data;
158 u8 shift;
159 s32 err;
160
161 sx150x_find_cfg(offset, width, &reg, &mask, &shift);
162 err = sx150x_i2c_read(chip->client, reg, &data);
163 if (err < 0)
164 return err;
165
166 data &= ~mask;
167 data |= (val << shift) & mask;
168 return sx150x_i2c_write(chip->client, reg, data);
169}
170
171static int sx150x_get_io(struct sx150x_chip *chip, unsigned offset)
172{
173 u8 reg = chip->dev_cfg->reg_data;
174 u8 mask;
175 u8 data;
176 u8 shift;
177 s32 err;
178
179 sx150x_find_cfg(offset, 1, &reg, &mask, &shift);
180 err = sx150x_i2c_read(chip->client, reg, &data);
181 if (err >= 0)
182 err = (data & mask) != 0 ? 1 : 0;
183
184 return err;
185}
186
187static void sx150x_set_oscio(struct sx150x_chip *chip, int val)
188{
189 sx150x_i2c_write(chip->client,
190 chip->dev_cfg->reg_clock,
191 (val ? 0x1f : 0x10));
192}
193
194static void sx150x_set_io(struct sx150x_chip *chip, unsigned offset, int val)
195{
196 sx150x_write_cfg(chip,
197 offset,
198 1,
199 chip->dev_cfg->reg_data,
200 (val ? 1 : 0));
201}
202
203static int sx150x_io_input(struct sx150x_chip *chip, unsigned offset)
204{
205 return sx150x_write_cfg(chip,
206 offset,
207 1,
208 chip->dev_cfg->reg_dir,
209 1);
210}
211
212static int sx150x_io_output(struct sx150x_chip *chip, unsigned offset, int val)
213{
214 int err;
215
216 err = sx150x_write_cfg(chip,
217 offset,
218 1,
219 chip->dev_cfg->reg_data,
220 (val ? 1 : 0));
221 if (err >= 0)
222 err = sx150x_write_cfg(chip,
223 offset,
224 1,
225 chip->dev_cfg->reg_dir,
226 0);
227 return err;
228}
229
230static int sx150x_gpio_get(struct gpio_chip *gc, unsigned offset)
231{
232 struct sx150x_chip *chip;
233 int status = -EINVAL;
234
235 chip = container_of(gc, struct sx150x_chip, gpio_chip);
236
237 if (!offset_is_oscio(chip, offset)) {
238 mutex_lock(&chip->lock);
239 status = sx150x_get_io(chip, offset);
240 mutex_unlock(&chip->lock);
241 }
242
243 return status;
244}
245
246static void sx150x_gpio_set(struct gpio_chip *gc, unsigned offset, int val)
247{
248 struct sx150x_chip *chip;
249
250 chip = container_of(gc, struct sx150x_chip, gpio_chip);
251
252 mutex_lock(&chip->lock);
253 if (offset_is_oscio(chip, offset))
254 sx150x_set_oscio(chip, val);
255 else
256 sx150x_set_io(chip, offset, val);
257 mutex_unlock(&chip->lock);
258}
259
260static int sx150x_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
261{
262 struct sx150x_chip *chip;
263 int status = -EINVAL;
264
265 chip = container_of(gc, struct sx150x_chip, gpio_chip);
266
267 if (!offset_is_oscio(chip, offset)) {
268 mutex_lock(&chip->lock);
269 status = sx150x_io_input(chip, offset);
270 mutex_unlock(&chip->lock);
271 }
272 return status;
273}
274
275static int sx150x_gpio_direction_output(struct gpio_chip *gc,
276 unsigned offset,
277 int val)
278{
279 struct sx150x_chip *chip;
280 int status = 0;
281
282 chip = container_of(gc, struct sx150x_chip, gpio_chip);
283
284 if (!offset_is_oscio(chip, offset)) {
285 mutex_lock(&chip->lock);
286 status = sx150x_io_output(chip, offset, val);
287 mutex_unlock(&chip->lock);
288 }
289 return status;
290}
291
292static int sx150x_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
293{
294 struct sx150x_chip *chip;
295
296 chip = container_of(gc, struct sx150x_chip, gpio_chip);
297
298 if (offset >= chip->dev_cfg->ngpios)
299 return -EINVAL;
300
301 if (chip->irq_base < 0)
302 return -EINVAL;
303
304 return chip->irq_base + offset;
305}
306
307static void sx150x_irq_mask(unsigned int irq)
308{
309 struct irq_chip *ic = get_irq_chip(irq);
310 struct sx150x_chip *chip;
311 unsigned n;
312
313 chip = container_of(ic, struct sx150x_chip, irq_chip);
314 n = irq - chip->irq_base;
315
316 sx150x_write_cfg(chip, n, 1, chip->dev_cfg->reg_irq_mask, 1);
317 sx150x_write_cfg(chip, n, 2, chip->dev_cfg->reg_sense, 0);
318}
319
320static void sx150x_irq_unmask(unsigned int irq)
321{
322 struct irq_chip *ic = get_irq_chip(irq);
323 struct sx150x_chip *chip;
324 unsigned n;
325
326 chip = container_of(ic, struct sx150x_chip, irq_chip);
327 n = irq - chip->irq_base;
328
329 sx150x_write_cfg(chip, n, 1, chip->dev_cfg->reg_irq_mask, 0);
330 sx150x_write_cfg(chip, n, 2, chip->dev_cfg->reg_sense,
331 chip->irq_sense >> (n * 2));
332}
333
334static int sx150x_irq_set_type(unsigned int irq, unsigned int flow_type)
335{
336 struct irq_chip *ic = get_irq_chip(irq);
337 struct sx150x_chip *chip;
338 unsigned n, val = 0;
339
340 if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW))
341 return -EINVAL;
342
343 chip = container_of(ic, struct sx150x_chip, irq_chip);
344 n = irq - chip->irq_base;
345
346 if (flow_type & IRQ_TYPE_EDGE_RISING)
347 val |= 0x1;
348 if (flow_type & IRQ_TYPE_EDGE_FALLING)
349 val |= 0x2;
350
351 chip->irq_sense &= ~(3UL << (n * 2));
352 chip->irq_sense |= val << (n * 2);
353 chip->irq_set_type_pending |= BIT(n);
354 return 0;
355}
356
357static irqreturn_t sx150x_irq_thread_fn(int irq, void *dev_id)
358{
359 struct sx150x_chip *chip = (struct sx150x_chip *)dev_id;
360 unsigned nhandled = 0;
361 unsigned sub_irq;
362 unsigned n;
363 s32 err;
364 u8 val;
365 int i;
366
367 for (i = (chip->dev_cfg->ngpios / 8) - 1; i >= 0; --i) {
368 err = sx150x_i2c_read(chip->client,
369 chip->dev_cfg->reg_irq_src - i,
370 &val);
371 if (err < 0)
372 continue;
373
374 sx150x_i2c_write(chip->client,
375 chip->dev_cfg->reg_irq_src - i,
376 val);
377 for (n = 0; n < 8; ++n) {
378 if (val & (1 << n)) {
379 sub_irq = chip->irq_base + (i * 8) + n;
380 handle_nested_irq(sub_irq);
381 ++nhandled;
382 }
383 }
384 }
385
386 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
387}
388
389static void sx150x_irq_bus_lock(unsigned int irq)
390{
391 struct irq_chip *ic = get_irq_chip(irq);
392 struct sx150x_chip *chip;
393
394 chip = container_of(ic, struct sx150x_chip, irq_chip);
395
396 mutex_lock(&chip->lock);
397}
398
399static void sx150x_irq_bus_sync_unlock(unsigned int irq)
400{
401 struct irq_chip *ic = get_irq_chip(irq);
402 struct sx150x_chip *chip;
403 unsigned n;
404
405 chip = container_of(ic, struct sx150x_chip, irq_chip);
406
407 while (chip->irq_set_type_pending) {
408 n = __ffs(chip->irq_set_type_pending);
409 chip->irq_set_type_pending &= ~BIT(n);
410 if (!(irq_to_desc(n + chip->irq_base)->status & IRQ_MASKED))
411 sx150x_write_cfg(chip, n, 2,
412 chip->dev_cfg->reg_sense,
413 chip->irq_sense >> (n * 2));
414 }
415
416 mutex_unlock(&chip->lock);
417}
418
419static void sx150x_init_chip(struct sx150x_chip *chip,
420 struct i2c_client *client,
421 kernel_ulong_t driver_data,
422 struct sx150x_platform_data *pdata)
423{
424 mutex_init(&chip->lock);
425
426 chip->client = client;
427 chip->dev_cfg = &sx150x_devices[driver_data];
428 chip->gpio_chip.label = client->name;
429 chip->gpio_chip.direction_input = sx150x_gpio_direction_input;
430 chip->gpio_chip.direction_output = sx150x_gpio_direction_output;
431 chip->gpio_chip.get = sx150x_gpio_get;
432 chip->gpio_chip.set = sx150x_gpio_set;
433 chip->gpio_chip.to_irq = sx150x_gpio_to_irq;
434 chip->gpio_chip.base = pdata->gpio_base;
435 chip->gpio_chip.can_sleep = 1;
436 chip->gpio_chip.ngpio = chip->dev_cfg->ngpios;
437 if (pdata->oscio_is_gpo)
438 ++chip->gpio_chip.ngpio;
439
440 chip->irq_chip.name = client->name;
441 chip->irq_chip.mask = sx150x_irq_mask;
442 chip->irq_chip.unmask = sx150x_irq_unmask;
443 chip->irq_chip.set_type = sx150x_irq_set_type;
444 chip->irq_chip.bus_lock = sx150x_irq_bus_lock;
445 chip->irq_chip.bus_sync_unlock = sx150x_irq_bus_sync_unlock;
446 chip->irq_summary = -1;
447 chip->irq_base = -1;
448 chip->irq_sense = 0;
449 chip->irq_set_type_pending = 0;
450}
451
452static int sx150x_init_io(struct sx150x_chip *chip, u8 base, u16 cfg)
453{
454 int err = 0;
455 unsigned n;
456
457 for (n = 0; err >= 0 && n < (chip->dev_cfg->ngpios / 8); ++n)
458 err = sx150x_i2c_write(chip->client, base - n, cfg >> (n * 8));
459 return err;
460}
461
462static int sx150x_init_hw(struct sx150x_chip *chip,
463 struct sx150x_platform_data *pdata)
464{
465 int err = 0;
466
467 err = i2c_smbus_write_word_data(chip->client,
468 chip->dev_cfg->reg_reset,
469 0x3412);
470 if (err < 0)
471 return err;
472
473 err = sx150x_i2c_write(chip->client,
474 chip->dev_cfg->reg_misc,
475 0x01);
476 if (err < 0)
477 return err;
478
479 err = sx150x_init_io(chip, chip->dev_cfg->reg_pullup,
480 pdata->io_pullup_ena);
481 if (err < 0)
482 return err;
483
484 err = sx150x_init_io(chip, chip->dev_cfg->reg_pulldn,
485 pdata->io_pulldn_ena);
486 if (err < 0)
487 return err;
488
489 err = sx150x_init_io(chip, chip->dev_cfg->reg_drain,
490 pdata->io_open_drain_ena);
491 if (err < 0)
492 return err;
493
494 err = sx150x_init_io(chip, chip->dev_cfg->reg_polarity,
495 pdata->io_polarity);
496 if (err < 0)
497 return err;
498
499 if (pdata->oscio_is_gpo)
500 sx150x_set_oscio(chip, 0);
501
502 return err;
503}
504
505static int sx150x_install_irq_chip(struct sx150x_chip *chip,
506 int irq_summary,
507 int irq_base)
508{
509 int err;
510 unsigned n;
511 unsigned irq;
512
513 chip->irq_summary = irq_summary;
514 chip->irq_base = irq_base;
515
516 for (n = 0; n < chip->dev_cfg->ngpios; ++n) {
517 irq = irq_base + n;
518 set_irq_chip_and_handler(irq, &chip->irq_chip, handle_edge_irq);
519 set_irq_nested_thread(irq, 1);
520#ifdef CONFIG_ARM
521 set_irq_flags(irq, IRQF_VALID);
522#else
523 set_irq_noprobe(irq);
524#endif
525 }
526
527 err = request_threaded_irq(irq_summary,
528 NULL,
529 sx150x_irq_thread_fn,
530 IRQF_SHARED | IRQF_TRIGGER_FALLING,
531 chip->irq_chip.name,
532 chip);
533 if (err < 0) {
534 chip->irq_summary = -1;
535 chip->irq_base = -1;
536 }
537
538 return err;
539}
540
541static void sx150x_remove_irq_chip(struct sx150x_chip *chip)
542{
543 unsigned n;
544 unsigned irq;
545
546 free_irq(chip->irq_summary, chip);
547
548 for (n = 0; n < chip->dev_cfg->ngpios; ++n) {
549 irq = chip->irq_base + n;
550 set_irq_handler(irq, NULL);
551 set_irq_chip(irq, NULL);
552 }
553}
554
555static int __devinit sx150x_probe(struct i2c_client *client,
556 const struct i2c_device_id *id)
557{
558 static const u32 i2c_funcs = I2C_FUNC_SMBUS_BYTE_DATA |
559 I2C_FUNC_SMBUS_WRITE_WORD_DATA;
560 struct sx150x_platform_data *pdata;
561 struct sx150x_chip *chip;
562 int rc;
563
564 pdata = client->dev.platform_data;
565 if (!pdata)
566 return -EINVAL;
567
568 if (!i2c_check_functionality(client->adapter, i2c_funcs))
569 return -ENOSYS;
570
571 chip = kzalloc(sizeof(struct sx150x_chip), GFP_KERNEL);
572 if (!chip)
573 return -ENOMEM;
574
575 sx150x_init_chip(chip, client, id->driver_data, pdata);
576 rc = sx150x_init_hw(chip, pdata);
577 if (rc < 0)
578 goto probe_fail_pre_gpiochip_add;
579
580 rc = gpiochip_add(&chip->gpio_chip);
581 if (rc < 0)
582 goto probe_fail_pre_gpiochip_add;
583
584 if (pdata->irq_summary >= 0) {
585 rc = sx150x_install_irq_chip(chip,
586 pdata->irq_summary,
587 pdata->irq_base);
588 if (rc < 0)
589 goto probe_fail_post_gpiochip_add;
590 }
591
592 i2c_set_clientdata(client, chip);
593
594 return 0;
595probe_fail_post_gpiochip_add:
596 WARN_ON(gpiochip_remove(&chip->gpio_chip) < 0);
597probe_fail_pre_gpiochip_add:
598 kfree(chip);
599 return rc;
600}
601
602static int __devexit sx150x_remove(struct i2c_client *client)
603{
604 struct sx150x_chip *chip;
605 int rc;
606
607 chip = i2c_get_clientdata(client);
608 rc = gpiochip_remove(&chip->gpio_chip);
609 if (rc < 0)
610 return rc;
611
612 if (chip->irq_summary >= 0)
613 sx150x_remove_irq_chip(chip);
614
615 kfree(chip);
616
617 return 0;
618}
619
620static struct i2c_driver sx150x_driver = {
621 .driver = {
622 .name = "sx150x",
623 .owner = THIS_MODULE
624 },
625 .probe = sx150x_probe,
626 .remove = __devexit_p(sx150x_remove),
627 .id_table = sx150x_id,
628};
629
630static int __init sx150x_init(void)
631{
632 return i2c_add_driver(&sx150x_driver);
633}
634subsys_initcall(sx150x_init);
635
636static void __exit sx150x_exit(void)
637{
638 return i2c_del_driver(&sx150x_driver);
639}
640module_exit(sx150x_exit);
641
642MODULE_AUTHOR("Gregory Bean <gbean@codeaurora.org>");
643MODULE_DESCRIPTION("Driver for Semtech SX150X I2C GPIO Expanders");
644MODULE_LICENSE("GPL v2");
645MODULE_ALIAS("i2c:sx150x");
diff --git a/drivers/gpio/wm831x-gpio.c b/drivers/gpio/wm831x-gpio.c
index 1fa449a1a4cb..309644cf4d9b 100644
--- a/drivers/gpio/wm831x-gpio.c
+++ b/drivers/gpio/wm831x-gpio.c
@@ -108,6 +108,37 @@ static int wm831x_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
108 return wm831x->irq_base + WM831X_IRQ_GPIO_1 + offset; 108 return wm831x->irq_base + WM831X_IRQ_GPIO_1 + offset;
109} 109}
110 110
111static int wm831x_gpio_set_debounce(struct gpio_chip *chip, unsigned offset,
112 unsigned debounce)
113{
114 struct wm831x_gpio *wm831x_gpio = to_wm831x_gpio(chip);
115 struct wm831x *wm831x = wm831x_gpio->wm831x;
116 int reg = WM831X_GPIO1_CONTROL + offset;
117 int ret, fn;
118
119 ret = wm831x_reg_read(wm831x, reg);
120 if (ret < 0)
121 return ret;
122
123 switch (ret & WM831X_GPN_FN_MASK) {
124 case 0:
125 case 1:
126 break;
127 default:
128 /* Not in GPIO mode */
129 return -EBUSY;
130 }
131
132 if (debounce >= 32 && debounce <= 64)
133 fn = 0;
134 else if (debounce >= 4000 && debounce <= 8000)
135 fn = 1;
136 else
137 return -EINVAL;
138
139 return wm831x_set_bits(wm831x, reg, WM831X_GPN_FN_MASK, fn);
140}
141
111#ifdef CONFIG_DEBUG_FS 142#ifdef CONFIG_DEBUG_FS
112static void wm831x_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) 143static void wm831x_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
113{ 144{
@@ -208,6 +239,7 @@ static struct gpio_chip template_chip = {
208 .direction_output = wm831x_gpio_direction_out, 239 .direction_output = wm831x_gpio_direction_out,
209 .set = wm831x_gpio_set, 240 .set = wm831x_gpio_set,
210 .to_irq = wm831x_gpio_to_irq, 241 .to_irq = wm831x_gpio_to_irq,
242 .set_debounce = wm831x_gpio_set_debounce,
211 .dbg_show = wm831x_gpio_dbg_show, 243 .dbg_show = wm831x_gpio_dbg_show,
212 .can_sleep = 1, 244 .can_sleep = 1,
213}; 245};
diff --git a/drivers/gpu/drm/ati_pcigart.c b/drivers/gpu/drm/ati_pcigart.c
index 17be051b7aa3..1c3649242208 100644
--- a/drivers/gpu/drm/ati_pcigart.c
+++ b/drivers/gpu/drm/ati_pcigart.c
@@ -152,7 +152,7 @@ int drm_ati_pcigart_init(struct drm_device *dev, struct drm_ati_pcigart_info *ga
152 /* we need to support large memory configurations */ 152 /* we need to support large memory configurations */
153 entry->busaddr[i] = pci_map_page(dev->pdev, entry->pagelist[i], 153 entry->busaddr[i] = pci_map_page(dev->pdev, entry->pagelist[i],
154 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 154 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
155 if (entry->busaddr[i] == 0) { 155 if (pci_dma_mapping_error(dev->pdev, entry->busaddr[i])) {
156 DRM_ERROR("unable to map PCIGART pages!\n"); 156 DRM_ERROR("unable to map PCIGART pages!\n");
157 drm_ati_pcigart_cleanup(dev, gart_info); 157 drm_ati_pcigart_cleanup(dev, gart_info);
158 address = NULL; 158 address = NULL;
diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index a5c9ce93bbcb..3e257a50bf56 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -328,14 +328,13 @@ static int drm_addmap_core(struct drm_device * dev, resource_size_t offset,
328 return -EINVAL; 328 return -EINVAL;
329 } 329 }
330 330
331 list = kmalloc(sizeof(*list), GFP_KERNEL); 331 list = kzalloc(sizeof(*list), GFP_KERNEL);
332 if (!list) { 332 if (!list) {
333 if (map->type == _DRM_REGISTERS) 333 if (map->type == _DRM_REGISTERS)
334 iounmap(map->handle); 334 iounmap(map->handle);
335 kfree(map); 335 kfree(map);
336 return -EINVAL; 336 return -EINVAL;
337 } 337 }
338 memset(list, 0, sizeof(*list));
339 list->map = map; 338 list->map = map;
340 339
341 mutex_lock(&dev->struct_mutex); 340 mutex_lock(&dev->struct_mutex);
@@ -678,13 +677,12 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)
678 return -EINVAL; 677 return -EINVAL;
679 } 678 }
680 679
681 entry->buflist = kmalloc(count * sizeof(*entry->buflist), GFP_KERNEL); 680 entry->buflist = kzalloc(count * sizeof(*entry->buflist), GFP_KERNEL);
682 if (!entry->buflist) { 681 if (!entry->buflist) {
683 mutex_unlock(&dev->struct_mutex); 682 mutex_unlock(&dev->struct_mutex);
684 atomic_dec(&dev->buf_alloc); 683 atomic_dec(&dev->buf_alloc);
685 return -ENOMEM; 684 return -ENOMEM;
686 } 685 }
687 memset(entry->buflist, 0, count * sizeof(*entry->buflist));
688 686
689 entry->buf_size = size; 687 entry->buf_size = size;
690 entry->page_order = page_order; 688 entry->page_order = page_order;
@@ -708,7 +706,7 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)
708 buf->file_priv = NULL; 706 buf->file_priv = NULL;
709 707
710 buf->dev_priv_size = dev->driver->dev_priv_size; 708 buf->dev_priv_size = dev->driver->dev_priv_size;
711 buf->dev_private = kmalloc(buf->dev_priv_size, GFP_KERNEL); 709 buf->dev_private = kzalloc(buf->dev_priv_size, GFP_KERNEL);
712 if (!buf->dev_private) { 710 if (!buf->dev_private) {
713 /* Set count correctly so we free the proper amount. */ 711 /* Set count correctly so we free the proper amount. */
714 entry->buf_count = count; 712 entry->buf_count = count;
@@ -717,7 +715,6 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)
717 atomic_dec(&dev->buf_alloc); 715 atomic_dec(&dev->buf_alloc);
718 return -ENOMEM; 716 return -ENOMEM;
719 } 717 }
720 memset(buf->dev_private, 0, buf->dev_priv_size);
721 718
722 DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address); 719 DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
723 720
@@ -832,22 +829,20 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)
832 return -EINVAL; 829 return -EINVAL;
833 } 830 }
834 831
835 entry->buflist = kmalloc(count * sizeof(*entry->buflist), GFP_KERNEL); 832 entry->buflist = kzalloc(count * sizeof(*entry->buflist), GFP_KERNEL);
836 if (!entry->buflist) { 833 if (!entry->buflist) {
837 mutex_unlock(&dev->struct_mutex); 834 mutex_unlock(&dev->struct_mutex);
838 atomic_dec(&dev->buf_alloc); 835 atomic_dec(&dev->buf_alloc);
839 return -ENOMEM; 836 return -ENOMEM;
840 } 837 }
841 memset(entry->buflist, 0, count * sizeof(*entry->buflist));
842 838
843 entry->seglist = kmalloc(count * sizeof(*entry->seglist), GFP_KERNEL); 839 entry->seglist = kzalloc(count * sizeof(*entry->seglist), GFP_KERNEL);
844 if (!entry->seglist) { 840 if (!entry->seglist) {
845 kfree(entry->buflist); 841 kfree(entry->buflist);
846 mutex_unlock(&dev->struct_mutex); 842 mutex_unlock(&dev->struct_mutex);
847 atomic_dec(&dev->buf_alloc); 843 atomic_dec(&dev->buf_alloc);
848 return -ENOMEM; 844 return -ENOMEM;
849 } 845 }
850 memset(entry->seglist, 0, count * sizeof(*entry->seglist));
851 846
852 /* Keep the original pagelist until we know all the allocations 847 /* Keep the original pagelist until we know all the allocations
853 * have succeeded 848 * have succeeded
@@ -911,8 +906,8 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)
911 buf->file_priv = NULL; 906 buf->file_priv = NULL;
912 907
913 buf->dev_priv_size = dev->driver->dev_priv_size; 908 buf->dev_priv_size = dev->driver->dev_priv_size;
914 buf->dev_private = kmalloc(buf->dev_priv_size, 909 buf->dev_private = kzalloc(buf->dev_priv_size,
915 GFP_KERNEL); 910 GFP_KERNEL);
916 if (!buf->dev_private) { 911 if (!buf->dev_private) {
917 /* Set count correctly so we free the proper amount. */ 912 /* Set count correctly so we free the proper amount. */
918 entry->buf_count = count; 913 entry->buf_count = count;
@@ -923,7 +918,6 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)
923 atomic_dec(&dev->buf_alloc); 918 atomic_dec(&dev->buf_alloc);
924 return -ENOMEM; 919 return -ENOMEM;
925 } 920 }
926 memset(buf->dev_private, 0, buf->dev_priv_size);
927 921
928 DRM_DEBUG("buffer %d @ %p\n", 922 DRM_DEBUG("buffer %d @ %p\n",
929 entry->buf_count, buf->address); 923 entry->buf_count, buf->address);
@@ -1048,14 +1042,13 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request
1048 return -EINVAL; 1042 return -EINVAL;
1049 } 1043 }
1050 1044
1051 entry->buflist = kmalloc(count * sizeof(*entry->buflist), 1045 entry->buflist = kzalloc(count * sizeof(*entry->buflist),
1052 GFP_KERNEL); 1046 GFP_KERNEL);
1053 if (!entry->buflist) { 1047 if (!entry->buflist) {
1054 mutex_unlock(&dev->struct_mutex); 1048 mutex_unlock(&dev->struct_mutex);
1055 atomic_dec(&dev->buf_alloc); 1049 atomic_dec(&dev->buf_alloc);
1056 return -ENOMEM; 1050 return -ENOMEM;
1057 } 1051 }
1058 memset(entry->buflist, 0, count * sizeof(*entry->buflist));
1059 1052
1060 entry->buf_size = size; 1053 entry->buf_size = size;
1061 entry->page_order = page_order; 1054 entry->page_order = page_order;
@@ -1080,7 +1073,7 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request
1080 buf->file_priv = NULL; 1073 buf->file_priv = NULL;
1081 1074
1082 buf->dev_priv_size = dev->driver->dev_priv_size; 1075 buf->dev_priv_size = dev->driver->dev_priv_size;
1083 buf->dev_private = kmalloc(buf->dev_priv_size, GFP_KERNEL); 1076 buf->dev_private = kzalloc(buf->dev_priv_size, GFP_KERNEL);
1084 if (!buf->dev_private) { 1077 if (!buf->dev_private) {
1085 /* Set count correctly so we free the proper amount. */ 1078 /* Set count correctly so we free the proper amount. */
1086 entry->buf_count = count; 1079 entry->buf_count = count;
@@ -1090,8 +1083,6 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request
1090 return -ENOMEM; 1083 return -ENOMEM;
1091 } 1084 }
1092 1085
1093 memset(buf->dev_private, 0, buf->dev_priv_size);
1094
1095 DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address); 1086 DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
1096 1087
1097 offset += alignment; 1088 offset += alignment;
@@ -1209,14 +1200,13 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request
1209 return -EINVAL; 1200 return -EINVAL;
1210 } 1201 }
1211 1202
1212 entry->buflist = kmalloc(count * sizeof(*entry->buflist), 1203 entry->buflist = kzalloc(count * sizeof(*entry->buflist),
1213 GFP_KERNEL); 1204 GFP_KERNEL);
1214 if (!entry->buflist) { 1205 if (!entry->buflist) {
1215 mutex_unlock(&dev->struct_mutex); 1206 mutex_unlock(&dev->struct_mutex);
1216 atomic_dec(&dev->buf_alloc); 1207 atomic_dec(&dev->buf_alloc);
1217 return -ENOMEM; 1208 return -ENOMEM;
1218 } 1209 }
1219 memset(entry->buflist, 0, count * sizeof(*entry->buflist));
1220 1210
1221 entry->buf_size = size; 1211 entry->buf_size = size;
1222 entry->page_order = page_order; 1212 entry->page_order = page_order;
@@ -1240,7 +1230,7 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request
1240 buf->file_priv = NULL; 1230 buf->file_priv = NULL;
1241 1231
1242 buf->dev_priv_size = dev->driver->dev_priv_size; 1232 buf->dev_priv_size = dev->driver->dev_priv_size;
1243 buf->dev_private = kmalloc(buf->dev_priv_size, GFP_KERNEL); 1233 buf->dev_private = kzalloc(buf->dev_priv_size, GFP_KERNEL);
1244 if (!buf->dev_private) { 1234 if (!buf->dev_private) {
1245 /* Set count correctly so we free the proper amount. */ 1235 /* Set count correctly so we free the proper amount. */
1246 entry->buf_count = count; 1236 entry->buf_count = count;
@@ -1249,7 +1239,6 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request
1249 atomic_dec(&dev->buf_alloc); 1239 atomic_dec(&dev->buf_alloc);
1250 return -ENOMEM; 1240 return -ENOMEM;
1251 } 1241 }
1252 memset(buf->dev_private, 0, buf->dev_priv_size);
1253 1242
1254 DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address); 1243 DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
1255 1244
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 4c68f76993d8..37e0b4fa482a 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -1682,9 +1682,9 @@ int drm_mode_addfb(struct drm_device *dev,
1682 /* TODO setup destructor callback */ 1682 /* TODO setup destructor callback */
1683 1683
1684 fb = dev->mode_config.funcs->fb_create(dev, file_priv, r); 1684 fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);
1685 if (!fb) { 1685 if (IS_ERR(fb)) {
1686 DRM_ERROR("could not create framebuffer\n"); 1686 DRM_ERROR("could not create framebuffer\n");
1687 ret = -EINVAL; 1687 ret = PTR_ERR(fb);
1688 goto out; 1688 goto out;
1689 } 1689 }
1690 1690
@@ -2541,7 +2541,7 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2541 goto out; 2541 goto out;
2542 } 2542 }
2543 2543
2544 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, crtc->gamma_size); 2544 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
2545 2545
2546out: 2546out:
2547 mutex_unlock(&dev->mode_config.mutex); 2547 mutex_unlock(&dev->mode_config.mutex);
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index b9e4dbfa0533..7e31d4348340 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -817,12 +817,12 @@ int drm_helper_resume_force_mode(struct drm_device *dev)
817 if (encoder_funcs->dpms) 817 if (encoder_funcs->dpms)
818 (*encoder_funcs->dpms) (encoder, 818 (*encoder_funcs->dpms) (encoder,
819 drm_helper_choose_encoder_dpms(encoder)); 819 drm_helper_choose_encoder_dpms(encoder));
820
821 crtc_funcs = crtc->helper_private;
822 if (crtc_funcs->dpms)
823 (*crtc_funcs->dpms) (crtc,
824 drm_helper_choose_crtc_dpms(crtc));
825 } 820 }
821
822 crtc_funcs = crtc->helper_private;
823 if (crtc_funcs->dpms)
824 (*crtc_funcs->dpms) (crtc,
825 drm_helper_choose_crtc_dpms(crtc));
826 } 826 }
827 } 827 }
828 /* disable the unused connectors while restoring the modesetting */ 828 /* disable the unused connectors while restoring the modesetting */
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index dce5c4a97f8d..96e963108225 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -33,6 +33,11 @@
33#include <linux/i2c-algo-bit.h> 33#include <linux/i2c-algo-bit.h>
34#include "drmP.h" 34#include "drmP.h"
35#include "drm_edid.h" 35#include "drm_edid.h"
36#include "drm_edid_modes.h"
37
38#define version_greater(edid, maj, min) \
39 (((edid)->version > (maj)) || \
40 ((edid)->version == (maj) && (edid)->revision > (min)))
36 41
37#define EDID_EST_TIMINGS 16 42#define EDID_EST_TIMINGS 16
38#define EDID_STD_TIMINGS 8 43#define EDID_STD_TIMINGS 8
@@ -62,6 +67,13 @@
62/* use +hsync +vsync for detailed mode */ 67/* use +hsync +vsync for detailed mode */
63#define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6) 68#define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
64 69
70struct detailed_mode_closure {
71 struct drm_connector *connector;
72 struct edid *edid;
73 bool preferred;
74 u32 quirks;
75 int modes;
76};
65 77
66#define LEVEL_DMT 0 78#define LEVEL_DMT 0
67#define LEVEL_GTF 1 79#define LEVEL_GTF 1
@@ -375,7 +387,6 @@ static u32 edid_get_quirks(struct edid *edid)
375#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay) 387#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
376#define MODE_REFRESH_DIFF(m,r) (abs((m)->vrefresh - target_refresh)) 388#define MODE_REFRESH_DIFF(m,r) (abs((m)->vrefresh - target_refresh))
377 389
378
379/** 390/**
380 * edid_fixup_preferred - set preferred modes based on quirk list 391 * edid_fixup_preferred - set preferred modes based on quirk list
381 * @connector: has mode list to fix up 392 * @connector: has mode list to fix up
@@ -422,245 +433,6 @@ static void edid_fixup_preferred(struct drm_connector *connector,
422 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED; 433 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
423} 434}
424 435
425/*
426 * Add the Autogenerated from the DMT spec.
427 * This table is copied from xfree86/modes/xf86EdidModes.c.
428 * But the mode with Reduced blank feature is deleted.
429 */
430static struct drm_display_mode drm_dmt_modes[] = {
431 /* 640x350@85Hz */
432 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
433 736, 832, 0, 350, 382, 385, 445, 0,
434 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
435 /* 640x400@85Hz */
436 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
437 736, 832, 0, 400, 401, 404, 445, 0,
438 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
439 /* 720x400@85Hz */
440 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
441 828, 936, 0, 400, 401, 404, 446, 0,
442 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
443 /* 640x480@60Hz */
444 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
445 752, 800, 0, 480, 489, 492, 525, 0,
446 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
447 /* 640x480@72Hz */
448 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
449 704, 832, 0, 480, 489, 492, 520, 0,
450 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
451 /* 640x480@75Hz */
452 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
453 720, 840, 0, 480, 481, 484, 500, 0,
454 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
455 /* 640x480@85Hz */
456 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
457 752, 832, 0, 480, 481, 484, 509, 0,
458 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
459 /* 800x600@56Hz */
460 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
461 896, 1024, 0, 600, 601, 603, 625, 0,
462 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
463 /* 800x600@60Hz */
464 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
465 968, 1056, 0, 600, 601, 605, 628, 0,
466 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
467 /* 800x600@72Hz */
468 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
469 976, 1040, 0, 600, 637, 643, 666, 0,
470 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
471 /* 800x600@75Hz */
472 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
473 896, 1056, 0, 600, 601, 604, 625, 0,
474 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
475 /* 800x600@85Hz */
476 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
477 896, 1048, 0, 600, 601, 604, 631, 0,
478 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
479 /* 848x480@60Hz */
480 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
481 976, 1088, 0, 480, 486, 494, 517, 0,
482 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
483 /* 1024x768@43Hz, interlace */
484 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
485 1208, 1264, 0, 768, 768, 772, 817, 0,
486 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
487 DRM_MODE_FLAG_INTERLACE) },
488 /* 1024x768@60Hz */
489 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
490 1184, 1344, 0, 768, 771, 777, 806, 0,
491 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
492 /* 1024x768@70Hz */
493 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
494 1184, 1328, 0, 768, 771, 777, 806, 0,
495 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
496 /* 1024x768@75Hz */
497 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
498 1136, 1312, 0, 768, 769, 772, 800, 0,
499 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
500 /* 1024x768@85Hz */
501 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
502 1168, 1376, 0, 768, 769, 772, 808, 0,
503 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
504 /* 1152x864@75Hz */
505 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
506 1344, 1600, 0, 864, 865, 868, 900, 0,
507 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
508 /* 1280x768@60Hz */
509 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
510 1472, 1664, 0, 768, 771, 778, 798, 0,
511 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
512 /* 1280x768@75Hz */
513 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
514 1488, 1696, 0, 768, 771, 778, 805, 0,
515 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
516 /* 1280x768@85Hz */
517 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
518 1496, 1712, 0, 768, 771, 778, 809, 0,
519 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
520 /* 1280x800@60Hz */
521 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
522 1480, 1680, 0, 800, 803, 809, 831, 0,
523 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
524 /* 1280x800@75Hz */
525 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
526 1488, 1696, 0, 800, 803, 809, 838, 0,
527 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
528 /* 1280x800@85Hz */
529 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
530 1496, 1712, 0, 800, 803, 809, 843, 0,
531 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
532 /* 1280x960@60Hz */
533 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
534 1488, 1800, 0, 960, 961, 964, 1000, 0,
535 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
536 /* 1280x960@85Hz */
537 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
538 1504, 1728, 0, 960, 961, 964, 1011, 0,
539 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
540 /* 1280x1024@60Hz */
541 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
542 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
543 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
544 /* 1280x1024@75Hz */
545 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
546 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
547 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
548 /* 1280x1024@85Hz */
549 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
550 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
551 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
552 /* 1360x768@60Hz */
553 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
554 1536, 1792, 0, 768, 771, 777, 795, 0,
555 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
556 /* 1440x1050@60Hz */
557 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
558 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
559 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
560 /* 1440x1050@75Hz */
561 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
562 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
563 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
564 /* 1440x1050@85Hz */
565 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
566 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
567 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
568 /* 1440x900@60Hz */
569 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
570 1672, 1904, 0, 900, 903, 909, 934, 0,
571 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
572 /* 1440x900@75Hz */
573 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
574 1688, 1936, 0, 900, 903, 909, 942, 0,
575 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
576 /* 1440x900@85Hz */
577 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
578 1696, 1952, 0, 900, 903, 909, 948, 0,
579 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
580 /* 1600x1200@60Hz */
581 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
582 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
583 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
584 /* 1600x1200@65Hz */
585 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
586 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
587 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
588 /* 1600x1200@70Hz */
589 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
590 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
591 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
592 /* 1600x1200@75Hz */
593 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
594 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
595 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
596 /* 1600x1200@85Hz */
597 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
598 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
599 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
600 /* 1680x1050@60Hz */
601 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
602 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
603 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
604 /* 1680x1050@75Hz */
605 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
606 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
607 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
608 /* 1680x1050@85Hz */
609 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
610 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
611 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
612 /* 1792x1344@60Hz */
613 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
614 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
615 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
616 /* 1729x1344@75Hz */
617 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
618 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
619 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
620 /* 1853x1392@60Hz */
621 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
622 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
623 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
624 /* 1856x1392@75Hz */
625 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
626 2208, 2560, 0, 1392, 1395, 1399, 1500, 0,
627 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
628 /* 1920x1200@60Hz */
629 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
630 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
631 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
632 /* 1920x1200@75Hz */
633 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
634 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
635 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
636 /* 1920x1200@85Hz */
637 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
638 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
639 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
640 /* 1920x1440@60Hz */
641 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
642 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
643 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
644 /* 1920x1440@75Hz */
645 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
646 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
647 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
648 /* 2560x1600@60Hz */
649 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
650 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
651 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
652 /* 2560x1600@75HZ */
653 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
654 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
655 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
656 /* 2560x1600@85HZ */
657 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
658 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
659 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
660};
661static const int drm_num_dmt_modes =
662 sizeof(drm_dmt_modes) / sizeof(struct drm_display_mode);
663
664struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, 436struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
665 int hsize, int vsize, int fresh) 437 int hsize, int vsize, int fresh)
666{ 438{
@@ -685,6 +457,46 @@ EXPORT_SYMBOL(drm_mode_find_dmt);
685typedef void detailed_cb(struct detailed_timing *timing, void *closure); 457typedef void detailed_cb(struct detailed_timing *timing, void *closure);
686 458
687static void 459static void
460cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
461{
462 int i, n = 0;
463 u8 rev = ext[0x01], d = ext[0x02];
464 u8 *det_base = ext + d;
465
466 switch (rev) {
467 case 0:
468 /* can't happen */
469 return;
470 case 1:
471 /* have to infer how many blocks we have, check pixel clock */
472 for (i = 0; i < 6; i++)
473 if (det_base[18*i] || det_base[18*i+1])
474 n++;
475 break;
476 default:
477 /* explicit count */
478 n = min(ext[0x03] & 0x0f, 6);
479 break;
480 }
481
482 for (i = 0; i < n; i++)
483 cb((struct detailed_timing *)(det_base + 18 * i), closure);
484}
485
486static void
487vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
488{
489 unsigned int i, n = min((int)ext[0x02], 6);
490 u8 *det_base = ext + 5;
491
492 if (ext[0x01] != 1)
493 return; /* unknown version */
494
495 for (i = 0; i < n; i++)
496 cb((struct detailed_timing *)(det_base + 18 * i), closure);
497}
498
499static void
688drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure) 500drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
689{ 501{
690 int i; 502 int i;
@@ -696,7 +508,19 @@ drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
696 for (i = 0; i < EDID_DETAILED_TIMINGS; i++) 508 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
697 cb(&(edid->detailed_timings[i]), closure); 509 cb(&(edid->detailed_timings[i]), closure);
698 510
699 /* XXX extension block walk */ 511 for (i = 1; i <= raw_edid[0x7e]; i++) {
512 u8 *ext = raw_edid + (i * EDID_LENGTH);
513 switch (*ext) {
514 case CEA_EXT:
515 cea_for_each_detailed_block(ext, cb, closure);
516 break;
517 case VTB_EXT:
518 vtb_for_each_detailed_block(ext, cb, closure);
519 break;
520 default:
521 break;
522 }
523 }
700} 524}
701 525
702static void 526static void
@@ -1047,117 +871,6 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
1047 return mode; 871 return mode;
1048} 872}
1049 873
1050/*
1051 * Detailed mode info for the EDID "established modes" data to use.
1052 */
1053static struct drm_display_mode edid_est_modes[] = {
1054 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
1055 968, 1056, 0, 600, 601, 605, 628, 0,
1056 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
1057 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
1058 896, 1024, 0, 600, 601, 603, 625, 0,
1059 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
1060 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
1061 720, 840, 0, 480, 481, 484, 500, 0,
1062 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
1063 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
1064 704, 832, 0, 480, 489, 491, 520, 0,
1065 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
1066 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
1067 768, 864, 0, 480, 483, 486, 525, 0,
1068 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
1069 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25200, 640, 656,
1070 752, 800, 0, 480, 490, 492, 525, 0,
1071 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
1072 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
1073 846, 900, 0, 400, 421, 423, 449, 0,
1074 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
1075 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
1076 846, 900, 0, 400, 412, 414, 449, 0,
1077 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
1078 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
1079 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
1080 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
1081 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78800, 1024, 1040,
1082 1136, 1312, 0, 768, 769, 772, 800, 0,
1083 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
1084 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
1085 1184, 1328, 0, 768, 771, 777, 806, 0,
1086 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
1087 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
1088 1184, 1344, 0, 768, 771, 777, 806, 0,
1089 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
1090 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
1091 1208, 1264, 0, 768, 768, 776, 817, 0,
1092 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
1093 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
1094 928, 1152, 0, 624, 625, 628, 667, 0,
1095 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
1096 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
1097 896, 1056, 0, 600, 601, 604, 625, 0,
1098 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
1099 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
1100 976, 1040, 0, 600, 637, 643, 666, 0,
1101 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
1102 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
1103 1344, 1600, 0, 864, 865, 868, 900, 0,
1104 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
1105};
1106
1107/**
1108 * add_established_modes - get est. modes from EDID and add them
1109 * @edid: EDID block to scan
1110 *
1111 * Each EDID block contains a bitmap of the supported "established modes" list
1112 * (defined above). Tease them out and add them to the global modes list.
1113 */
1114static int add_established_modes(struct drm_connector *connector, struct edid *edid)
1115{
1116 struct drm_device *dev = connector->dev;
1117 unsigned long est_bits = edid->established_timings.t1 |
1118 (edid->established_timings.t2 << 8) |
1119 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
1120 int i, modes = 0;
1121
1122 for (i = 0; i <= EDID_EST_TIMINGS; i++)
1123 if (est_bits & (1<<i)) {
1124 struct drm_display_mode *newmode;
1125 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
1126 if (newmode) {
1127 drm_mode_probed_add(connector, newmode);
1128 modes++;
1129 }
1130 }
1131
1132 return modes;
1133}
1134
1135/**
1136 * add_standard_modes - get std. modes from EDID and add them
1137 * @edid: EDID block to scan
1138 *
1139 * Standard modes can be calculated using the CVT standard. Grab them from
1140 * @edid, calculate them, and add them to the list.
1141 */
1142static int add_standard_modes(struct drm_connector *connector, struct edid *edid)
1143{
1144 int i, modes = 0;
1145
1146 for (i = 0; i < EDID_STD_TIMINGS; i++) {
1147 struct drm_display_mode *newmode;
1148
1149 newmode = drm_mode_std(connector, edid,
1150 &edid->standard_timings[i],
1151 edid->revision);
1152 if (newmode) {
1153 drm_mode_probed_add(connector, newmode);
1154 modes++;
1155 }
1156 }
1157
1158 return modes;
1159}
1160
1161static bool 874static bool
1162mode_is_rb(struct drm_display_mode *mode) 875mode_is_rb(struct drm_display_mode *mode)
1163{ 876{
@@ -1267,113 +980,33 @@ drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
1267 return modes; 980 return modes;
1268} 981}
1269 982
1270static int drm_cvt_modes(struct drm_connector *connector, 983static void
1271 struct detailed_timing *timing) 984do_inferred_modes(struct detailed_timing *timing, void *c)
1272{ 985{
1273 int i, j, modes = 0; 986 struct detailed_mode_closure *closure = c;
1274 struct drm_display_mode *newmode; 987 struct detailed_non_pixel *data = &timing->data.other_data;
1275 struct drm_device *dev = connector->dev; 988 int gtf = (closure->edid->features & DRM_EDID_FEATURE_DEFAULT_GTF);
1276 struct cvt_timing *cvt;
1277 const int rates[] = { 60, 85, 75, 60, 50 };
1278 const u8 empty[3] = { 0, 0, 0 };
1279
1280 for (i = 0; i < 4; i++) {
1281 int uninitialized_var(width), height;
1282 cvt = &(timing->data.other_data.data.cvt[i]);
1283 989
1284 if (!memcmp(cvt->code, empty, 3)) 990 if (gtf && data->type == EDID_DETAIL_MONITOR_RANGE)
1285 continue; 991 closure->modes += drm_gtf_modes_for_range(closure->connector,
992 closure->edid,
993 timing);
994}
1286 995
1287 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2; 996static int
1288 switch (cvt->code[1] & 0x0c) { 997add_inferred_modes(struct drm_connector *connector, struct edid *edid)
1289 case 0x00: 998{
1290 width = height * 4 / 3; 999 struct detailed_mode_closure closure = {
1291 break; 1000 connector, edid, 0, 0, 0
1292 case 0x04: 1001 };
1293 width = height * 16 / 9;
1294 break;
1295 case 0x08:
1296 width = height * 16 / 10;
1297 break;
1298 case 0x0c:
1299 width = height * 15 / 9;
1300 break;
1301 }
1302 1002
1303 for (j = 1; j < 5; j++) { 1003 if (version_greater(edid, 1, 0))
1304 if (cvt->code[2] & (1 << j)) { 1004 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
1305 newmode = drm_cvt_mode(dev, width, height, 1005 &closure);
1306 rates[j], j == 0,
1307 false, false);
1308 if (newmode) {
1309 drm_mode_probed_add(connector, newmode);
1310 modes++;
1311 }
1312 }
1313 }
1314 }
1315 1006
1316 return modes; 1007 return closure.modes;
1317} 1008}
1318 1009
1319static const struct {
1320 short w;
1321 short h;
1322 short r;
1323 short rb;
1324} est3_modes[] = {
1325 /* byte 6 */
1326 { 640, 350, 85, 0 },
1327 { 640, 400, 85, 0 },
1328 { 720, 400, 85, 0 },
1329 { 640, 480, 85, 0 },
1330 { 848, 480, 60, 0 },
1331 { 800, 600, 85, 0 },
1332 { 1024, 768, 85, 0 },
1333 { 1152, 864, 75, 0 },
1334 /* byte 7 */
1335 { 1280, 768, 60, 1 },
1336 { 1280, 768, 60, 0 },
1337 { 1280, 768, 75, 0 },
1338 { 1280, 768, 85, 0 },
1339 { 1280, 960, 60, 0 },
1340 { 1280, 960, 85, 0 },
1341 { 1280, 1024, 60, 0 },
1342 { 1280, 1024, 85, 0 },
1343 /* byte 8 */
1344 { 1360, 768, 60, 0 },
1345 { 1440, 900, 60, 1 },
1346 { 1440, 900, 60, 0 },
1347 { 1440, 900, 75, 0 },
1348 { 1440, 900, 85, 0 },
1349 { 1400, 1050, 60, 1 },
1350 { 1400, 1050, 60, 0 },
1351 { 1400, 1050, 75, 0 },
1352 /* byte 9 */
1353 { 1400, 1050, 85, 0 },
1354 { 1680, 1050, 60, 1 },
1355 { 1680, 1050, 60, 0 },
1356 { 1680, 1050, 75, 0 },
1357 { 1680, 1050, 85, 0 },
1358 { 1600, 1200, 60, 0 },
1359 { 1600, 1200, 65, 0 },
1360 { 1600, 1200, 70, 0 },
1361 /* byte 10 */
1362 { 1600, 1200, 75, 0 },
1363 { 1600, 1200, 85, 0 },
1364 { 1792, 1344, 60, 0 },
1365 { 1792, 1344, 85, 0 },
1366 { 1856, 1392, 60, 0 },
1367 { 1856, 1392, 75, 0 },
1368 { 1920, 1200, 60, 1 },
1369 { 1920, 1200, 60, 0 },
1370 /* byte 11 */
1371 { 1920, 1200, 75, 0 },
1372 { 1920, 1200, 85, 0 },
1373 { 1920, 1440, 60, 0 },
1374 { 1920, 1440, 75, 0 },
1375};
1376
1377static int 1010static int
1378drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing) 1011drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
1379{ 1012{
@@ -1403,37 +1036,63 @@ drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
1403 return modes; 1036 return modes;
1404} 1037}
1405 1038
1406static int add_detailed_modes(struct drm_connector *connector, 1039static void
1407 struct detailed_timing *timing, 1040do_established_modes(struct detailed_timing *timing, void *c)
1408 struct edid *edid, u32 quirks, int preferred)
1409{ 1041{
1410 int i, modes = 0; 1042 struct detailed_mode_closure *closure = c;
1411 struct detailed_non_pixel *data = &timing->data.other_data; 1043 struct detailed_non_pixel *data = &timing->data.other_data;
1412 int gtf = (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF);
1413 struct drm_display_mode *newmode;
1414 struct drm_device *dev = connector->dev;
1415 1044
1416 if (timing->pixel_clock) { 1045 if (data->type == EDID_DETAIL_EST_TIMINGS)
1417 newmode = drm_mode_detailed(dev, edid, timing, quirks); 1046 closure->modes += drm_est3_modes(closure->connector, timing);
1418 if (!newmode) 1047}
1419 return 0;
1420 1048
1421 if (preferred) 1049/**
1422 newmode->type |= DRM_MODE_TYPE_PREFERRED; 1050 * add_established_modes - get est. modes from EDID and add them
1051 * @edid: EDID block to scan
1052 *
1053 * Each EDID block contains a bitmap of the supported "established modes" list
1054 * (defined above). Tease them out and add them to the global modes list.
1055 */
1056static int
1057add_established_modes(struct drm_connector *connector, struct edid *edid)
1058{
1059 struct drm_device *dev = connector->dev;
1060 unsigned long est_bits = edid->established_timings.t1 |
1061 (edid->established_timings.t2 << 8) |
1062 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
1063 int i, modes = 0;
1064 struct detailed_mode_closure closure = {
1065 connector, edid, 0, 0, 0
1066 };
1423 1067
1424 drm_mode_probed_add(connector, newmode); 1068 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
1425 return 1; 1069 if (est_bits & (1<<i)) {
1070 struct drm_display_mode *newmode;
1071 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
1072 if (newmode) {
1073 drm_mode_probed_add(connector, newmode);
1074 modes++;
1075 }
1076 }
1426 } 1077 }
1427 1078
1428 /* other timing types */ 1079 if (version_greater(edid, 1, 0))
1429 switch (data->type) { 1080 drm_for_each_detailed_block((u8 *)edid,
1430 case EDID_DETAIL_MONITOR_RANGE: 1081 do_established_modes, &closure);
1431 if (gtf) 1082
1432 modes += drm_gtf_modes_for_range(connector, edid, 1083 return modes + closure.modes;
1433 timing); 1084}
1434 break; 1085
1435 case EDID_DETAIL_STD_MODES: 1086static void
1436 /* Six modes per detailed section */ 1087do_standard_modes(struct detailed_timing *timing, void *c)
1088{
1089 struct detailed_mode_closure *closure = c;
1090 struct detailed_non_pixel *data = &timing->data.other_data;
1091 struct drm_connector *connector = closure->connector;
1092 struct edid *edid = closure->edid;
1093
1094 if (data->type == EDID_DETAIL_STD_MODES) {
1095 int i;
1437 for (i = 0; i < 6; i++) { 1096 for (i = 0; i < 6; i++) {
1438 struct std_timing *std; 1097 struct std_timing *std;
1439 struct drm_display_mode *newmode; 1098 struct drm_display_mode *newmode;
@@ -1443,108 +1102,169 @@ static int add_detailed_modes(struct drm_connector *connector,
1443 edid->revision); 1102 edid->revision);
1444 if (newmode) { 1103 if (newmode) {
1445 drm_mode_probed_add(connector, newmode); 1104 drm_mode_probed_add(connector, newmode);
1446 modes++; 1105 closure->modes++;
1447 } 1106 }
1448 } 1107 }
1449 break;
1450 case EDID_DETAIL_CVT_3BYTE:
1451 modes += drm_cvt_modes(connector, timing);
1452 break;
1453 case EDID_DETAIL_EST_TIMINGS:
1454 modes += drm_est3_modes(connector, timing);
1455 break;
1456 default:
1457 break;
1458 } 1108 }
1459
1460 return modes;
1461} 1109}
1462 1110
1463/** 1111/**
1464 * add_detailed_info - get detailed mode info from EDID data 1112 * add_standard_modes - get std. modes from EDID and add them
1465 * @connector: attached connector
1466 * @edid: EDID block to scan 1113 * @edid: EDID block to scan
1467 * @quirks: quirks to apply
1468 * 1114 *
1469 * Some of the detailed timing sections may contain mode information. Grab 1115 * Standard modes can be calculated using the appropriate standard (DMT,
1470 * it and add it to the list. 1116 * GTF or CVT. Grab them from @edid and add them to the list.
1471 */ 1117 */
1472static int add_detailed_info(struct drm_connector *connector, 1118static int
1473 struct edid *edid, u32 quirks) 1119add_standard_modes(struct drm_connector *connector, struct edid *edid)
1474{ 1120{
1475 int i, modes = 0; 1121 int i, modes = 0;
1122 struct detailed_mode_closure closure = {
1123 connector, edid, 0, 0, 0
1124 };
1125
1126 for (i = 0; i < EDID_STD_TIMINGS; i++) {
1127 struct drm_display_mode *newmode;
1128
1129 newmode = drm_mode_std(connector, edid,
1130 &edid->standard_timings[i],
1131 edid->revision);
1132 if (newmode) {
1133 drm_mode_probed_add(connector, newmode);
1134 modes++;
1135 }
1136 }
1137
1138 if (version_greater(edid, 1, 0))
1139 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
1140 &closure);
1141
1142 /* XXX should also look for standard codes in VTB blocks */
1143
1144 return modes + closure.modes;
1145}
1476 1146
1477 for (i = 0; i < EDID_DETAILED_TIMINGS; i++) { 1147static int drm_cvt_modes(struct drm_connector *connector,
1478 struct detailed_timing *timing = &edid->detailed_timings[i]; 1148 struct detailed_timing *timing)
1479 int preferred = (i == 0); 1149{
1150 int i, j, modes = 0;
1151 struct drm_display_mode *newmode;
1152 struct drm_device *dev = connector->dev;
1153 struct cvt_timing *cvt;
1154 const int rates[] = { 60, 85, 75, 60, 50 };
1155 const u8 empty[3] = { 0, 0, 0 };
1480 1156
1481 if (preferred && edid->version == 1 && edid->revision < 4) 1157 for (i = 0; i < 4; i++) {
1482 preferred = (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING); 1158 int uninitialized_var(width), height;
1159 cvt = &(timing->data.other_data.data.cvt[i]);
1483 1160
1484 /* In 1.0, only timings are allowed */ 1161 if (!memcmp(cvt->code, empty, 3))
1485 if (!timing->pixel_clock && edid->version == 1 &&
1486 edid->revision == 0)
1487 continue; 1162 continue;
1488 1163
1489 modes += add_detailed_modes(connector, timing, edid, quirks, 1164 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
1490 preferred); 1165 switch (cvt->code[1] & 0x0c) {
1166 case 0x00:
1167 width = height * 4 / 3;
1168 break;
1169 case 0x04:
1170 width = height * 16 / 9;
1171 break;
1172 case 0x08:
1173 width = height * 16 / 10;
1174 break;
1175 case 0x0c:
1176 width = height * 15 / 9;
1177 break;
1178 }
1179
1180 for (j = 1; j < 5; j++) {
1181 if (cvt->code[2] & (1 << j)) {
1182 newmode = drm_cvt_mode(dev, width, height,
1183 rates[j], j == 0,
1184 false, false);
1185 if (newmode) {
1186 drm_mode_probed_add(connector, newmode);
1187 modes++;
1188 }
1189 }
1190 }
1491 } 1191 }
1492 1192
1493 return modes; 1193 return modes;
1494} 1194}
1495 1195
1496/** 1196static void
1497 * add_detailed_mode_eedid - get detailed mode info from addtional timing 1197do_cvt_mode(struct detailed_timing *timing, void *c)
1498 * EDID block
1499 * @connector: attached connector
1500 * @edid: EDID block to scan(It is only to get addtional timing EDID block)
1501 * @quirks: quirks to apply
1502 *
1503 * Some of the detailed timing sections may contain mode information. Grab
1504 * it and add it to the list.
1505 */
1506static int add_detailed_info_eedid(struct drm_connector *connector,
1507 struct edid *edid, u32 quirks)
1508{ 1198{
1509 int i, modes = 0; 1199 struct detailed_mode_closure *closure = c;
1510 char *edid_ext = NULL; 1200 struct detailed_non_pixel *data = &timing->data.other_data;
1511 struct detailed_timing *timing;
1512 int start_offset, end_offset;
1513 1201
1514 if (edid->version == 1 && edid->revision < 3) 1202 if (data->type == EDID_DETAIL_CVT_3BYTE)
1515 return 0; 1203 closure->modes += drm_cvt_modes(closure->connector, timing);
1516 if (!edid->extensions) 1204}
1517 return 0;
1518 1205
1519 /* Find CEA extension */ 1206static int
1520 for (i = 0; i < edid->extensions; i++) { 1207add_cvt_modes(struct drm_connector *connector, struct edid *edid)
1521 edid_ext = (char *)edid + EDID_LENGTH * (i + 1); 1208{
1522 if (edid_ext[0] == 0x02) 1209 struct detailed_mode_closure closure = {
1523 break; 1210 connector, edid, 0, 0, 0
1524 } 1211 };
1525 1212
1526 if (i == edid->extensions) 1213 if (version_greater(edid, 1, 2))
1527 return 0; 1214 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
1528 1215
1529 /* Get the start offset of detailed timing block */ 1216 /* XXX should also look for CVT codes in VTB blocks */
1530 start_offset = edid_ext[2];
1531 if (start_offset == 0) {
1532 /* If the start_offset is zero, it means that neither detailed
1533 * info nor data block exist. In such case it is also
1534 * unnecessary to parse the detailed timing info.
1535 */
1536 return 0;
1537 }
1538 1217
1539 end_offset = EDID_LENGTH; 1218 return closure.modes;
1540 end_offset -= sizeof(struct detailed_timing); 1219}
1541 for (i = start_offset; i < end_offset; 1220
1542 i += sizeof(struct detailed_timing)) { 1221static void
1543 timing = (struct detailed_timing *)(edid_ext + i); 1222do_detailed_mode(struct detailed_timing *timing, void *c)
1544 modes += add_detailed_modes(connector, timing, edid, quirks, 0); 1223{
1224 struct detailed_mode_closure *closure = c;
1225 struct drm_display_mode *newmode;
1226
1227 if (timing->pixel_clock) {
1228 newmode = drm_mode_detailed(closure->connector->dev,
1229 closure->edid, timing,
1230 closure->quirks);
1231 if (!newmode)
1232 return;
1233
1234 if (closure->preferred)
1235 newmode->type |= DRM_MODE_TYPE_PREFERRED;
1236
1237 drm_mode_probed_add(closure->connector, newmode);
1238 closure->modes++;
1239 closure->preferred = 0;
1545 } 1240 }
1241}
1546 1242
1547 return modes; 1243/*
1244 * add_detailed_modes - Add modes from detailed timings
1245 * @connector: attached connector
1246 * @edid: EDID block to scan
1247 * @quirks: quirks to apply
1248 */
1249static int
1250add_detailed_modes(struct drm_connector *connector, struct edid *edid,
1251 u32 quirks)
1252{
1253 struct detailed_mode_closure closure = {
1254 connector,
1255 edid,
1256 1,
1257 quirks,
1258 0
1259 };
1260
1261 if (closure.preferred && !version_greater(edid, 1, 3))
1262 closure.preferred =
1263 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
1264
1265 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
1266
1267 return closure.modes;
1548} 1268}
1549 1269
1550#define HDMI_IDENTIFIER 0x000C03 1270#define HDMI_IDENTIFIER 0x000C03
@@ -1640,35 +1360,21 @@ int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
1640 * - established timing codes 1360 * - established timing codes
1641 * - modes inferred from GTF or CVT range information 1361 * - modes inferred from GTF or CVT range information
1642 * 1362 *
1643 * We don't quite implement this yet, but we're close. 1363 * We get this pretty much right.
1644 * 1364 *
1645 * XXX order for additional mode types in extension blocks? 1365 * XXX order for additional mode types in extension blocks?
1646 */ 1366 */
1647 num_modes += add_detailed_info(connector, edid, quirks); 1367 num_modes += add_detailed_modes(connector, edid, quirks);
1648 num_modes += add_detailed_info_eedid(connector, edid, quirks); 1368 num_modes += add_cvt_modes(connector, edid);
1649 num_modes += add_standard_modes(connector, edid); 1369 num_modes += add_standard_modes(connector, edid);
1650 num_modes += add_established_modes(connector, edid); 1370 num_modes += add_established_modes(connector, edid);
1371 num_modes += add_inferred_modes(connector, edid);
1651 1372
1652 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75)) 1373 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
1653 edid_fixup_preferred(connector, quirks); 1374 edid_fixup_preferred(connector, quirks);
1654 1375
1655 connector->display_info.serration_vsync = (edid->input & DRM_EDID_INPUT_SERRATION_VSYNC) ? 1 : 0;
1656 connector->display_info.sync_on_green = (edid->input & DRM_EDID_INPUT_SYNC_ON_GREEN) ? 1 : 0;
1657 connector->display_info.composite_sync = (edid->input & DRM_EDID_INPUT_COMPOSITE_SYNC) ? 1 : 0;
1658 connector->display_info.separate_syncs = (edid->input & DRM_EDID_INPUT_SEPARATE_SYNCS) ? 1 : 0;
1659 connector->display_info.blank_to_black = (edid->input & DRM_EDID_INPUT_BLANK_TO_BLACK) ? 1 : 0;
1660 connector->display_info.video_level = (edid->input & DRM_EDID_INPUT_VIDEO_LEVEL) >> 5;
1661 connector->display_info.digital = (edid->input & DRM_EDID_INPUT_DIGITAL) ? 1 : 0;
1662 connector->display_info.width_mm = edid->width_cm * 10; 1376 connector->display_info.width_mm = edid->width_cm * 10;
1663 connector->display_info.height_mm = edid->height_cm * 10; 1377 connector->display_info.height_mm = edid->height_cm * 10;
1664 connector->display_info.gamma = edid->gamma;
1665 connector->display_info.gtf_supported = (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF) ? 1 : 0;
1666 connector->display_info.standard_color = (edid->features & DRM_EDID_FEATURE_STANDARD_COLOR) ? 1 : 0;
1667 connector->display_info.display_type = (edid->features & DRM_EDID_FEATURE_DISPLAY_TYPE) >> 3;
1668 connector->display_info.active_off_supported = (edid->features & DRM_EDID_FEATURE_PM_ACTIVE_OFF) ? 1 : 0;
1669 connector->display_info.suspend_supported = (edid->features & DRM_EDID_FEATURE_PM_SUSPEND) ? 1 : 0;
1670 connector->display_info.standby_supported = (edid->features & DRM_EDID_FEATURE_PM_STANDBY) ? 1 : 0;
1671 connector->display_info.gamma = edid->gamma;
1672 1378
1673 return num_modes; 1379 return num_modes;
1674} 1380}
diff --git a/drivers/gpu/drm/drm_edid_modes.h b/drivers/gpu/drm/drm_edid_modes.h
new file mode 100644
index 000000000000..6eb7592e152f
--- /dev/null
+++ b/drivers/gpu/drm/drm_edid_modes.h
@@ -0,0 +1,380 @@
1/*
2 * Copyright (c) 2007-2008 Intel Corporation
3 * Jesse Barnes <jesse.barnes@intel.com>
4 * Copyright 2010 Red Hat, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sub license,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26#include <linux/kernel.h>
27#include "drmP.h"
28#include "drm_edid.h"
29
30/*
31 * Autogenerated from the DMT spec.
32 * This table is copied from xfree86/modes/xf86EdidModes.c.
33 * But the mode with Reduced blank feature is deleted.
34 */
35static struct drm_display_mode drm_dmt_modes[] = {
36 /* 640x350@85Hz */
37 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
38 736, 832, 0, 350, 382, 385, 445, 0,
39 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
40 /* 640x400@85Hz */
41 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
42 736, 832, 0, 400, 401, 404, 445, 0,
43 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
44 /* 720x400@85Hz */
45 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
46 828, 936, 0, 400, 401, 404, 446, 0,
47 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
48 /* 640x480@60Hz */
49 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
50 752, 800, 0, 480, 489, 492, 525, 0,
51 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
52 /* 640x480@72Hz */
53 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
54 704, 832, 0, 480, 489, 492, 520, 0,
55 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
56 /* 640x480@75Hz */
57 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
58 720, 840, 0, 480, 481, 484, 500, 0,
59 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
60 /* 640x480@85Hz */
61 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
62 752, 832, 0, 480, 481, 484, 509, 0,
63 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
64 /* 800x600@56Hz */
65 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
66 896, 1024, 0, 600, 601, 603, 625, 0,
67 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
68 /* 800x600@60Hz */
69 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
70 968, 1056, 0, 600, 601, 605, 628, 0,
71 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
72 /* 800x600@72Hz */
73 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
74 976, 1040, 0, 600, 637, 643, 666, 0,
75 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
76 /* 800x600@75Hz */
77 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
78 896, 1056, 0, 600, 601, 604, 625, 0,
79 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
80 /* 800x600@85Hz */
81 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
82 896, 1048, 0, 600, 601, 604, 631, 0,
83 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
84 /* 848x480@60Hz */
85 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
86 976, 1088, 0, 480, 486, 494, 517, 0,
87 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
88 /* 1024x768@43Hz, interlace */
89 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
90 1208, 1264, 0, 768, 768, 772, 817, 0,
91 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
92 DRM_MODE_FLAG_INTERLACE) },
93 /* 1024x768@60Hz */
94 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
95 1184, 1344, 0, 768, 771, 777, 806, 0,
96 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
97 /* 1024x768@70Hz */
98 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
99 1184, 1328, 0, 768, 771, 777, 806, 0,
100 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
101 /* 1024x768@75Hz */
102 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
103 1136, 1312, 0, 768, 769, 772, 800, 0,
104 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
105 /* 1024x768@85Hz */
106 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
107 1168, 1376, 0, 768, 769, 772, 808, 0,
108 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
109 /* 1152x864@75Hz */
110 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
111 1344, 1600, 0, 864, 865, 868, 900, 0,
112 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
113 /* 1280x768@60Hz */
114 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
115 1472, 1664, 0, 768, 771, 778, 798, 0,
116 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
117 /* 1280x768@75Hz */
118 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
119 1488, 1696, 0, 768, 771, 778, 805, 0,
120 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
121 /* 1280x768@85Hz */
122 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
123 1496, 1712, 0, 768, 771, 778, 809, 0,
124 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
125 /* 1280x800@60Hz */
126 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
127 1480, 1680, 0, 800, 803, 809, 831, 0,
128 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
129 /* 1280x800@75Hz */
130 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
131 1488, 1696, 0, 800, 803, 809, 838, 0,
132 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
133 /* 1280x800@85Hz */
134 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
135 1496, 1712, 0, 800, 803, 809, 843, 0,
136 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
137 /* 1280x960@60Hz */
138 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
139 1488, 1800, 0, 960, 961, 964, 1000, 0,
140 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
141 /* 1280x960@85Hz */
142 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
143 1504, 1728, 0, 960, 961, 964, 1011, 0,
144 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
145 /* 1280x1024@60Hz */
146 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
147 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
148 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
149 /* 1280x1024@75Hz */
150 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
151 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
152 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
153 /* 1280x1024@85Hz */
154 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
155 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
156 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
157 /* 1360x768@60Hz */
158 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
159 1536, 1792, 0, 768, 771, 777, 795, 0,
160 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
161 /* 1440x1050@60Hz */
162 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
163 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
164 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
165 /* 1440x1050@75Hz */
166 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
167 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
168 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
169 /* 1440x1050@85Hz */
170 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
171 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
172 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
173 /* 1440x900@60Hz */
174 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
175 1672, 1904, 0, 900, 903, 909, 934, 0,
176 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
177 /* 1440x900@75Hz */
178 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
179 1688, 1936, 0, 900, 903, 909, 942, 0,
180 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
181 /* 1440x900@85Hz */
182 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
183 1696, 1952, 0, 900, 903, 909, 948, 0,
184 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
185 /* 1600x1200@60Hz */
186 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
187 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
188 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
189 /* 1600x1200@65Hz */
190 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
191 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
192 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
193 /* 1600x1200@70Hz */
194 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
195 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
196 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
197 /* 1600x1200@75Hz */
198 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
199 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
200 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
201 /* 1600x1200@85Hz */
202 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
203 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
204 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
205 /* 1680x1050@60Hz */
206 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
207 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
208 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
209 /* 1680x1050@75Hz */
210 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
211 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
212 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
213 /* 1680x1050@85Hz */
214 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
215 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
216 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
217 /* 1792x1344@60Hz */
218 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
219 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
220 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
221 /* 1729x1344@75Hz */
222 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
223 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
224 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
225 /* 1853x1392@60Hz */
226 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
227 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
228 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
229 /* 1856x1392@75Hz */
230 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
231 2208, 2560, 0, 1392, 1395, 1399, 1500, 0,
232 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
233 /* 1920x1200@60Hz */
234 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
235 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
236 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
237 /* 1920x1200@75Hz */
238 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
239 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
240 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
241 /* 1920x1200@85Hz */
242 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
243 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
244 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
245 /* 1920x1440@60Hz */
246 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
247 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
248 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
249 /* 1920x1440@75Hz */
250 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
251 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
252 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
253 /* 2560x1600@60Hz */
254 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
255 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
256 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
257 /* 2560x1600@75HZ */
258 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
259 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
260 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
261 /* 2560x1600@85HZ */
262 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
263 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
264 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
265};
266static const int drm_num_dmt_modes =
267 sizeof(drm_dmt_modes) / sizeof(struct drm_display_mode);
268
269static struct drm_display_mode edid_est_modes[] = {
270 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
271 968, 1056, 0, 600, 601, 605, 628, 0,
272 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
273 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
274 896, 1024, 0, 600, 601, 603, 625, 0,
275 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
276 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
277 720, 840, 0, 480, 481, 484, 500, 0,
278 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
279 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
280 704, 832, 0, 480, 489, 491, 520, 0,
281 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
282 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
283 768, 864, 0, 480, 483, 486, 525, 0,
284 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
285 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25200, 640, 656,
286 752, 800, 0, 480, 490, 492, 525, 0,
287 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
288 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
289 846, 900, 0, 400, 421, 423, 449, 0,
290 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
291 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
292 846, 900, 0, 400, 412, 414, 449, 0,
293 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
294 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
295 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
296 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
297 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78800, 1024, 1040,
298 1136, 1312, 0, 768, 769, 772, 800, 0,
299 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
300 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
301 1184, 1328, 0, 768, 771, 777, 806, 0,
302 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
303 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
304 1184, 1344, 0, 768, 771, 777, 806, 0,
305 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
306 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
307 1208, 1264, 0, 768, 768, 776, 817, 0,
308 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
309 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
310 928, 1152, 0, 624, 625, 628, 667, 0,
311 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
312 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
313 896, 1056, 0, 600, 601, 604, 625, 0,
314 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
315 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
316 976, 1040, 0, 600, 637, 643, 666, 0,
317 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
318 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
319 1344, 1600, 0, 864, 865, 868, 900, 0,
320 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
321};
322
323static const struct {
324 short w;
325 short h;
326 short r;
327 short rb;
328} est3_modes[] = {
329 /* byte 6 */
330 { 640, 350, 85, 0 },
331 { 640, 400, 85, 0 },
332 { 720, 400, 85, 0 },
333 { 640, 480, 85, 0 },
334 { 848, 480, 60, 0 },
335 { 800, 600, 85, 0 },
336 { 1024, 768, 85, 0 },
337 { 1152, 864, 75, 0 },
338 /* byte 7 */
339 { 1280, 768, 60, 1 },
340 { 1280, 768, 60, 0 },
341 { 1280, 768, 75, 0 },
342 { 1280, 768, 85, 0 },
343 { 1280, 960, 60, 0 },
344 { 1280, 960, 85, 0 },
345 { 1280, 1024, 60, 0 },
346 { 1280, 1024, 85, 0 },
347 /* byte 8 */
348 { 1360, 768, 60, 0 },
349 { 1440, 900, 60, 1 },
350 { 1440, 900, 60, 0 },
351 { 1440, 900, 75, 0 },
352 { 1440, 900, 85, 0 },
353 { 1400, 1050, 60, 1 },
354 { 1400, 1050, 60, 0 },
355 { 1400, 1050, 75, 0 },
356 /* byte 9 */
357 { 1400, 1050, 85, 0 },
358 { 1680, 1050, 60, 1 },
359 { 1680, 1050, 60, 0 },
360 { 1680, 1050, 75, 0 },
361 { 1680, 1050, 85, 0 },
362 { 1600, 1200, 60, 0 },
363 { 1600, 1200, 65, 0 },
364 { 1600, 1200, 70, 0 },
365 /* byte 10 */
366 { 1600, 1200, 75, 0 },
367 { 1600, 1200, 85, 0 },
368 { 1792, 1344, 60, 0 },
369 { 1792, 1344, 85, 0 },
370 { 1856, 1392, 60, 0 },
371 { 1856, 1392, 75, 0 },
372 { 1920, 1200, 60, 1 },
373 { 1920, 1200, 60, 0 },
374 /* byte 11 */
375 { 1920, 1200, 75, 0 },
376 { 1920, 1200, 85, 0 },
377 { 1920, 1440, 60, 0 },
378 { 1920, 1440, 75, 0 },
379};
380static const int num_est3_modes = sizeof(est3_modes) / sizeof(est3_modes[0]);
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index 2ca8df8b6102..3a652a65546f 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -135,15 +135,9 @@ int drm_open(struct inode *inode, struct file *filp)
135 retcode = drm_open_helper(inode, filp, dev); 135 retcode = drm_open_helper(inode, filp, dev);
136 if (!retcode) { 136 if (!retcode) {
137 atomic_inc(&dev->counts[_DRM_STAT_OPENS]); 137 atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
138 spin_lock(&dev->count_lock); 138 if (!dev->open_count++)
139 if (!dev->open_count++) {
140 spin_unlock(&dev->count_lock);
141 retcode = drm_setup(dev); 139 retcode = drm_setup(dev);
142 goto out;
143 }
144 spin_unlock(&dev->count_lock);
145 } 140 }
146out:
147 if (!retcode) { 141 if (!retcode) {
148 mutex_lock(&dev->struct_mutex); 142 mutex_lock(&dev->struct_mutex);
149 if (minor->type == DRM_MINOR_LEGACY) { 143 if (minor->type == DRM_MINOR_LEGACY) {
@@ -570,18 +564,14 @@ int drm_release(struct inode *inode, struct file *filp)
570 */ 564 */
571 565
572 atomic_inc(&dev->counts[_DRM_STAT_CLOSES]); 566 atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
573 spin_lock(&dev->count_lock);
574 if (!--dev->open_count) { 567 if (!--dev->open_count) {
575 if (atomic_read(&dev->ioctl_count)) { 568 if (atomic_read(&dev->ioctl_count)) {
576 DRM_ERROR("Device busy: %d\n", 569 DRM_ERROR("Device busy: %d\n",
577 atomic_read(&dev->ioctl_count)); 570 atomic_read(&dev->ioctl_count));
578 retcode = -EBUSY; 571 retcode = -EBUSY;
579 goto out; 572 } else
580 } 573 retcode = drm_lastclose(dev);
581 retcode = drm_lastclose(dev);
582 } 574 }
583out:
584 spin_unlock(&dev->count_lock);
585 mutex_unlock(&drm_global_mutex); 575 mutex_unlock(&drm_global_mutex);
586 576
587 return retcode; 577 return retcode;
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 4f1b86714489..bf92d07510df 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -322,7 +322,7 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data,
322 322
323 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 323 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
324 if (obj == NULL) 324 if (obj == NULL)
325 return -EBADF; 325 return -ENOENT;
326 326
327again: 327again:
328 if (idr_pre_get(&dev->object_name_idr, GFP_KERNEL) == 0) { 328 if (idr_pre_get(&dev->object_name_idr, GFP_KERNEL) == 0) {
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index 7b03b197fc00..47db4df37a69 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -392,6 +392,7 @@ int drm_setversion(struct drm_device *dev, void *data, struct drm_file *file_pri
392 if (sv->drm_di_minor >= 1) { 392 if (sv->drm_di_minor >= 1) {
393 /* 393 /*
394 * Version 1.1 includes tying of DRM to specific device 394 * Version 1.1 includes tying of DRM to specific device
395 * Version 1.4 has proper PCI domain support
395 */ 396 */
396 retcode = drm_set_busid(dev, file_priv); 397 retcode = drm_set_busid(dev, file_priv);
397 if (retcode) 398 if (retcode)
diff --git a/drivers/gpu/drm/i2c/ch7006_drv.c b/drivers/gpu/drm/i2c/ch7006_drv.c
index 833b35f44a77..08792a740f18 100644
--- a/drivers/gpu/drm/i2c/ch7006_drv.c
+++ b/drivers/gpu/drm/i2c/ch7006_drv.c
@@ -470,6 +470,7 @@ static int ch7006_encoder_init(struct i2c_client *client,
470 priv->hmargin = 50; 470 priv->hmargin = 50;
471 priv->vmargin = 50; 471 priv->vmargin = 50;
472 priv->last_dpms = -1; 472 priv->last_dpms = -1;
473 priv->chip_version = ch7006_read(client, CH7006_VERSION_ID);
473 474
474 if (ch7006_tv_norm) { 475 if (ch7006_tv_norm) {
475 for (i = 0; i < NUM_TV_NORMS; i++) { 476 for (i = 0; i < NUM_TV_NORMS; i++) {
diff --git a/drivers/gpu/drm/i2c/ch7006_mode.c b/drivers/gpu/drm/i2c/ch7006_mode.c
index e447dfb63890..c860f24a5afc 100644
--- a/drivers/gpu/drm/i2c/ch7006_mode.c
+++ b/drivers/gpu/drm/i2c/ch7006_mode.c
@@ -316,7 +316,10 @@ void ch7006_setup_power_state(struct drm_encoder *encoder)
316 } 316 }
317 317
318 } else { 318 } else {
319 *power |= bitfs(CH7006_POWER_LEVEL, FULL_POWER_OFF); 319 if (priv->chip_version >= 0x20)
320 *power |= bitfs(CH7006_POWER_LEVEL, FULL_POWER_OFF);
321 else
322 *power |= bitfs(CH7006_POWER_LEVEL, POWER_OFF);
320 } 323 }
321} 324}
322 325
diff --git a/drivers/gpu/drm/i2c/ch7006_priv.h b/drivers/gpu/drm/i2c/ch7006_priv.h
index 1c6d2e3bd96f..17667b7d57e7 100644
--- a/drivers/gpu/drm/i2c/ch7006_priv.h
+++ b/drivers/gpu/drm/i2c/ch7006_priv.h
@@ -95,6 +95,7 @@ struct ch7006_priv {
95 int flicker; 95 int flicker;
96 int scale; 96 int scale;
97 97
98 int chip_version;
98 int last_dpms; 99 int last_dpms;
99}; 100};
100 101
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 2a4ed7ca8b4e..0758c7802e6b 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -456,7 +456,7 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
456 456
457 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 457 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
458 if (obj == NULL) 458 if (obj == NULL)
459 return -EBADF; 459 return -ENOENT;
460 obj_priv = to_intel_bo(obj); 460 obj_priv = to_intel_bo(obj);
461 461
462 /* Bounds check source. 462 /* Bounds check source.
@@ -919,7 +919,7 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
919 919
920 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 920 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
921 if (obj == NULL) 921 if (obj == NULL)
922 return -EBADF; 922 return -ENOENT;
923 obj_priv = to_intel_bo(obj); 923 obj_priv = to_intel_bo(obj);
924 924
925 /* Bounds check destination. 925 /* Bounds check destination.
@@ -1002,7 +1002,7 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
1002 1002
1003 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 1003 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
1004 if (obj == NULL) 1004 if (obj == NULL)
1005 return -EBADF; 1005 return -ENOENT;
1006 obj_priv = to_intel_bo(obj); 1006 obj_priv = to_intel_bo(obj);
1007 1007
1008 mutex_lock(&dev->struct_mutex); 1008 mutex_lock(&dev->struct_mutex);
@@ -1060,7 +1060,7 @@ i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
1060 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 1060 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
1061 if (obj == NULL) { 1061 if (obj == NULL) {
1062 mutex_unlock(&dev->struct_mutex); 1062 mutex_unlock(&dev->struct_mutex);
1063 return -EBADF; 1063 return -ENOENT;
1064 } 1064 }
1065 1065
1066#if WATCH_BUF 1066#if WATCH_BUF
@@ -1099,7 +1099,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
1099 1099
1100 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 1100 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
1101 if (obj == NULL) 1101 if (obj == NULL)
1102 return -EBADF; 1102 return -ENOENT;
1103 1103
1104 offset = args->offset; 1104 offset = args->offset;
1105 1105
@@ -1373,7 +1373,7 @@ i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
1373 1373
1374 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 1374 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
1375 if (obj == NULL) 1375 if (obj == NULL)
1376 return -EBADF; 1376 return -ENOENT;
1377 1377
1378 mutex_lock(&dev->struct_mutex); 1378 mutex_lock(&dev->struct_mutex);
1379 1379
@@ -3364,7 +3364,7 @@ i915_gem_object_pin_and_relocate(struct drm_gem_object *obj,
3364 reloc->target_handle); 3364 reloc->target_handle);
3365 if (target_obj == NULL) { 3365 if (target_obj == NULL) {
3366 i915_gem_object_unpin(obj); 3366 i915_gem_object_unpin(obj);
3367 return -EBADF; 3367 return -ENOENT;
3368 } 3368 }
3369 target_obj_priv = to_intel_bo(target_obj); 3369 target_obj_priv = to_intel_bo(target_obj);
3370 3370
@@ -3781,7 +3781,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
3781 exec_list[i].handle, i); 3781 exec_list[i].handle, i);
3782 /* prevent error path from reading uninitialized data */ 3782 /* prevent error path from reading uninitialized data */
3783 args->buffer_count = i + 1; 3783 args->buffer_count = i + 1;
3784 ret = -EBADF; 3784 ret = -ENOENT;
3785 goto err; 3785 goto err;
3786 } 3786 }
3787 3787
@@ -3791,7 +3791,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
3791 object_list[i]); 3791 object_list[i]);
3792 /* prevent error path from reading uninitialized data */ 3792 /* prevent error path from reading uninitialized data */
3793 args->buffer_count = i + 1; 3793 args->buffer_count = i + 1;
3794 ret = -EBADF; 3794 ret = -EINVAL;
3795 goto err; 3795 goto err;
3796 } 3796 }
3797 obj_priv->in_execbuffer = true; 3797 obj_priv->in_execbuffer = true;
@@ -4265,7 +4265,7 @@ i915_gem_pin_ioctl(struct drm_device *dev, void *data,
4265 DRM_ERROR("Bad handle in i915_gem_pin_ioctl(): %d\n", 4265 DRM_ERROR("Bad handle in i915_gem_pin_ioctl(): %d\n",
4266 args->handle); 4266 args->handle);
4267 mutex_unlock(&dev->struct_mutex); 4267 mutex_unlock(&dev->struct_mutex);
4268 return -EBADF; 4268 return -ENOENT;
4269 } 4269 }
4270 obj_priv = to_intel_bo(obj); 4270 obj_priv = to_intel_bo(obj);
4271 4271
@@ -4321,7 +4321,7 @@ i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
4321 DRM_ERROR("Bad handle in i915_gem_unpin_ioctl(): %d\n", 4321 DRM_ERROR("Bad handle in i915_gem_unpin_ioctl(): %d\n",
4322 args->handle); 4322 args->handle);
4323 mutex_unlock(&dev->struct_mutex); 4323 mutex_unlock(&dev->struct_mutex);
4324 return -EBADF; 4324 return -ENOENT;
4325 } 4325 }
4326 4326
4327 obj_priv = to_intel_bo(obj); 4327 obj_priv = to_intel_bo(obj);
@@ -4355,7 +4355,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,
4355 if (obj == NULL) { 4355 if (obj == NULL) {
4356 DRM_ERROR("Bad handle in i915_gem_busy_ioctl(): %d\n", 4356 DRM_ERROR("Bad handle in i915_gem_busy_ioctl(): %d\n",
4357 args->handle); 4357 args->handle);
4358 return -EBADF; 4358 return -ENOENT;
4359 } 4359 }
4360 4360
4361 mutex_lock(&dev->struct_mutex); 4361 mutex_lock(&dev->struct_mutex);
@@ -4408,7 +4408,7 @@ i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
4408 if (obj == NULL) { 4408 if (obj == NULL) {
4409 DRM_ERROR("Bad handle in i915_gem_madvise_ioctl(): %d\n", 4409 DRM_ERROR("Bad handle in i915_gem_madvise_ioctl(): %d\n",
4410 args->handle); 4410 args->handle);
4411 return -EBADF; 4411 return -ENOENT;
4412 } 4412 }
4413 4413
4414 mutex_lock(&dev->struct_mutex); 4414 mutex_lock(&dev->struct_mutex);
diff --git a/drivers/gpu/drm/i915/i915_gem_tiling.c b/drivers/gpu/drm/i915/i915_gem_tiling.c
index 155719e4d16f..710eca70b323 100644
--- a/drivers/gpu/drm/i915/i915_gem_tiling.c
+++ b/drivers/gpu/drm/i915/i915_gem_tiling.c
@@ -275,7 +275,7 @@ i915_gem_set_tiling(struct drm_device *dev, void *data,
275 275
276 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 276 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
277 if (obj == NULL) 277 if (obj == NULL)
278 return -EINVAL; 278 return -ENOENT;
279 obj_priv = to_intel_bo(obj); 279 obj_priv = to_intel_bo(obj);
280 280
281 if (!i915_tiling_ok(dev, args->stride, obj->size, args->tiling_mode)) { 281 if (!i915_tiling_ok(dev, args->stride, obj->size, args->tiling_mode)) {
@@ -362,7 +362,7 @@ i915_gem_get_tiling(struct drm_device *dev, void *data,
362 362
363 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 363 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
364 if (obj == NULL) 364 if (obj == NULL)
365 return -EINVAL; 365 return -ENOENT;
366 obj_priv = to_intel_bo(obj); 366 obj_priv = to_intel_bo(obj);
367 367
368 mutex_lock(&dev->struct_mutex); 368 mutex_lock(&dev->struct_mutex);
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 1e5e0d379fa9..5ec10e02341b 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -4429,15 +4429,12 @@ void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
4429} 4429}
4430 4430
4431static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, 4431static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
4432 u16 *blue, uint32_t size) 4432 u16 *blue, uint32_t start, uint32_t size)
4433{ 4433{
4434 int end = (start + size > 256) ? 256 : start + size, i;
4434 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 4435 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4435 int i;
4436
4437 if (size != 256)
4438 return;
4439 4436
4440 for (i = 0; i < 256; i++) { 4437 for (i = start; i < end; i++) {
4441 intel_crtc->lut_r[i] = red[i] >> 8; 4438 intel_crtc->lut_r[i] = red[i] >> 8;
4442 intel_crtc->lut_g[i] = green[i] >> 8; 4439 intel_crtc->lut_g[i] = green[i] >> 8;
4443 intel_crtc->lut_b[i] = blue[i] >> 8; 4440 intel_crtc->lut_b[i] = blue[i] >> 8;
@@ -5412,18 +5409,18 @@ intel_user_framebuffer_create(struct drm_device *dev,
5412 5409
5413 obj = drm_gem_object_lookup(dev, filp, mode_cmd->handle); 5410 obj = drm_gem_object_lookup(dev, filp, mode_cmd->handle);
5414 if (!obj) 5411 if (!obj)
5415 return NULL; 5412 return ERR_PTR(-ENOENT);
5416 5413
5417 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); 5414 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
5418 if (!intel_fb) 5415 if (!intel_fb)
5419 return NULL; 5416 return ERR_PTR(-ENOMEM);
5420 5417
5421 ret = intel_framebuffer_init(dev, intel_fb, 5418 ret = intel_framebuffer_init(dev, intel_fb,
5422 mode_cmd, obj); 5419 mode_cmd, obj);
5423 if (ret) { 5420 if (ret) {
5424 drm_gem_object_unreference_unlocked(obj); 5421 drm_gem_object_unreference_unlocked(obj);
5425 kfree(intel_fb); 5422 kfree(intel_fb);
5426 return NULL; 5423 return ERR_PTR(ret);
5427 } 5424 }
5428 5425
5429 return &intel_fb->base; 5426 return &intel_fb->base;
diff --git a/drivers/gpu/drm/i915/intel_fb.c b/drivers/gpu/drm/i915/intel_fb.c
index a79525f434a8..7bdc96256bf5 100644
--- a/drivers/gpu/drm/i915/intel_fb.c
+++ b/drivers/gpu/drm/i915/intel_fb.c
@@ -121,7 +121,9 @@ static int intelfb_create(struct intel_fbdev *ifbdev,
121 121
122 info->par = ifbdev; 122 info->par = ifbdev;
123 123
124 intel_framebuffer_init(dev, &ifbdev->ifb, &mode_cmd, fbo); 124 ret = intel_framebuffer_init(dev, &ifbdev->ifb, &mode_cmd, fbo);
125 if (ret)
126 goto out_unpin;
125 127
126 fb = &ifbdev->ifb.base; 128 fb = &ifbdev->ifb.base;
127 129
diff --git a/drivers/gpu/drm/nouveau/Makefile b/drivers/gpu/drm/nouveau/Makefile
index 2405d5ef0ca7..e9b06e4ef2a2 100644
--- a/drivers/gpu/drm/nouveau/Makefile
+++ b/drivers/gpu/drm/nouveau/Makefile
@@ -12,12 +12,12 @@ nouveau-y := nouveau_drv.o nouveau_state.o nouveau_channel.o nouveau_mem.o \
12 nouveau_dp.o \ 12 nouveau_dp.o \
13 nv04_timer.o \ 13 nv04_timer.o \
14 nv04_mc.o nv40_mc.o nv50_mc.o \ 14 nv04_mc.o nv40_mc.o nv50_mc.o \
15 nv04_fb.o nv10_fb.o nv30_fb.o nv40_fb.o nv50_fb.o \ 15 nv04_fb.o nv10_fb.o nv30_fb.o nv40_fb.o nv50_fb.o nvc0_fb.o \
16 nv04_fifo.o nv10_fifo.o nv40_fifo.o nv50_fifo.o \ 16 nv04_fifo.o nv10_fifo.o nv40_fifo.o nv50_fifo.o nvc0_fifo.o \
17 nv04_graph.o nv10_graph.o nv20_graph.o \ 17 nv04_graph.o nv10_graph.o nv20_graph.o \
18 nv40_graph.o nv50_graph.o \ 18 nv40_graph.o nv50_graph.o nvc0_graph.o \
19 nv40_grctx.o nv50_grctx.o \ 19 nv40_grctx.o nv50_grctx.o \
20 nv04_instmem.o nv50_instmem.o \ 20 nv04_instmem.o nv50_instmem.o nvc0_instmem.o \
21 nv50_crtc.o nv50_dac.o nv50_sor.o \ 21 nv50_crtc.o nv50_dac.o nv50_sor.o \
22 nv50_cursor.o nv50_display.o nv50_fbcon.o \ 22 nv50_cursor.o nv50_display.o nv50_fbcon.o \
23 nv04_dac.o nv04_dfp.o nv04_tv.o nv17_tv.o nv17_tv_modes.o \ 23 nv04_dac.o nv04_dfp.o nv04_tv.o nv17_tv.o nv17_tv_modes.o \
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
index 7369b5e73649..0b69a9628c95 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
@@ -1928,6 +1928,31 @@ init_condition_time(struct nvbios *bios, uint16_t offset,
1928} 1928}
1929 1929
1930static int 1930static int
1931init_ltime(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1932{
1933 /*
1934 * INIT_LTIME opcode: 0x57 ('V')
1935 *
1936 * offset (8 bit): opcode
1937 * offset + 1 (16 bit): time
1938 *
1939 * Sleep for "time" miliseconds.
1940 */
1941
1942 unsigned time = ROM16(bios->data[offset + 1]);
1943
1944 if (!iexec->execute)
1945 return 3;
1946
1947 BIOSLOG(bios, "0x%04X: Sleeping for 0x%04X miliseconds\n",
1948 offset, time);
1949
1950 msleep(time);
1951
1952 return 3;
1953}
1954
1955static int
1931init_zm_reg_sequence(struct nvbios *bios, uint16_t offset, 1956init_zm_reg_sequence(struct nvbios *bios, uint16_t offset,
1932 struct init_exec *iexec) 1957 struct init_exec *iexec)
1933{ 1958{
@@ -1995,6 +2020,64 @@ init_sub_direct(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1995} 2020}
1996 2021
1997static int 2022static int
2023init_i2c_if(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2024{
2025 /*
2026 * INIT_I2C_IF opcode: 0x5E ('^')
2027 *
2028 * offset (8 bit): opcode
2029 * offset + 1 (8 bit): DCB I2C table entry index
2030 * offset + 2 (8 bit): I2C slave address
2031 * offset + 3 (8 bit): I2C register
2032 * offset + 4 (8 bit): mask
2033 * offset + 5 (8 bit): data
2034 *
2035 * Read the register given by "I2C register" on the device addressed
2036 * by "I2C slave address" on the I2C bus given by "DCB I2C table
2037 * entry index". Compare the result AND "mask" to "data".
2038 * If they're not equal, skip subsequent opcodes until condition is
2039 * inverted (INIT_NOT), or we hit INIT_RESUME
2040 */
2041
2042 uint8_t i2c_index = bios->data[offset + 1];
2043 uint8_t i2c_address = bios->data[offset + 2] >> 1;
2044 uint8_t reg = bios->data[offset + 3];
2045 uint8_t mask = bios->data[offset + 4];
2046 uint8_t data = bios->data[offset + 5];
2047 struct nouveau_i2c_chan *chan;
2048 union i2c_smbus_data val;
2049 int ret;
2050
2051 /* no execute check by design */
2052
2053 BIOSLOG(bios, "0x%04X: DCBI2CIndex: 0x%02X, I2CAddress: 0x%02X\n",
2054 offset, i2c_index, i2c_address);
2055
2056 chan = init_i2c_device_find(bios->dev, i2c_index);
2057 if (!chan)
2058 return -ENODEV;
2059
2060 ret = i2c_smbus_xfer(&chan->adapter, i2c_address, 0,
2061 I2C_SMBUS_READ, reg,
2062 I2C_SMBUS_BYTE_DATA, &val);
2063 if (ret < 0) {
2064 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Value: [no device], "
2065 "Mask: 0x%02X, Data: 0x%02X\n",
2066 offset, reg, mask, data);
2067 iexec->execute = 0;
2068 return 6;
2069 }
2070
2071 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Value: 0x%02X, "
2072 "Mask: 0x%02X, Data: 0x%02X\n",
2073 offset, reg, val.byte, mask, data);
2074
2075 iexec->execute = ((val.byte & mask) == data);
2076
2077 return 6;
2078}
2079
2080static int
1998init_copy_nv_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2081init_copy_nv_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1999{ 2082{
2000 /* 2083 /*
@@ -2083,9 +2166,10 @@ peek_fb(struct drm_device *dev, struct io_mapping *fb,
2083 uint32_t val = 0; 2166 uint32_t val = 0;
2084 2167
2085 if (off < pci_resource_len(dev->pdev, 1)) { 2168 if (off < pci_resource_len(dev->pdev, 1)) {
2086 uint32_t __iomem *p = io_mapping_map_atomic_wc(fb, off, KM_USER0); 2169 uint32_t __iomem *p =
2170 io_mapping_map_atomic_wc(fb, off & PAGE_MASK, KM_USER0);
2087 2171
2088 val = ioread32(p); 2172 val = ioread32(p + (off & ~PAGE_MASK));
2089 2173
2090 io_mapping_unmap_atomic(p, KM_USER0); 2174 io_mapping_unmap_atomic(p, KM_USER0);
2091 } 2175 }
@@ -2098,9 +2182,10 @@ poke_fb(struct drm_device *dev, struct io_mapping *fb,
2098 uint32_t off, uint32_t val) 2182 uint32_t off, uint32_t val)
2099{ 2183{
2100 if (off < pci_resource_len(dev->pdev, 1)) { 2184 if (off < pci_resource_len(dev->pdev, 1)) {
2101 uint32_t __iomem *p = io_mapping_map_atomic_wc(fb, off, KM_USER0); 2185 uint32_t __iomem *p =
2186 io_mapping_map_atomic_wc(fb, off & PAGE_MASK, KM_USER0);
2102 2187
2103 iowrite32(val, p); 2188 iowrite32(val, p + (off & ~PAGE_MASK));
2104 wmb(); 2189 wmb();
2105 2190
2106 io_mapping_unmap_atomic(p, KM_USER0); 2191 io_mapping_unmap_atomic(p, KM_USER0);
@@ -2165,7 +2250,7 @@ nv04_init_compute_mem(struct nvbios *bios)
2165 NV04_PFB_BOOT_0_RAM_AMOUNT, 2250 NV04_PFB_BOOT_0_RAM_AMOUNT,
2166 NV04_PFB_BOOT_0_RAM_AMOUNT_4MB); 2251 NV04_PFB_BOOT_0_RAM_AMOUNT_4MB);
2167 2252
2168 } else if (peek_fb(dev, fb, 0) == patt) { 2253 } else if (peek_fb(dev, fb, 0) != patt) {
2169 if (read_back_fb(dev, fb, 0x800000, patt)) 2254 if (read_back_fb(dev, fb, 0x800000, patt))
2170 bios_md32(bios, NV04_PFB_BOOT_0, 2255 bios_md32(bios, NV04_PFB_BOOT_0,
2171 NV04_PFB_BOOT_0_RAM_AMOUNT, 2256 NV04_PFB_BOOT_0_RAM_AMOUNT,
@@ -2593,7 +2678,7 @@ init_configure_preinit(struct nvbios *bios, uint16_t offset,
2593 /* no iexec->execute check by design */ 2678 /* no iexec->execute check by design */
2594 2679
2595 uint32_t straps = bios_rd32(bios, NV_PEXTDEV_BOOT_0); 2680 uint32_t straps = bios_rd32(bios, NV_PEXTDEV_BOOT_0);
2596 uint8_t cr3c = ((straps << 2) & 0xf0) | (straps & (1 << 6)); 2681 uint8_t cr3c = ((straps << 2) & 0xf0) | (straps & 0x40) >> 6;
2597 2682
2598 if (bios->major_version > 2) 2683 if (bios->major_version > 2)
2599 return 0; 2684 return 0;
@@ -3140,7 +3225,7 @@ init_gpio(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
3140 const uint32_t nv50_gpio_ctl[2] = { 0xe100, 0xe28c }; 3225 const uint32_t nv50_gpio_ctl[2] = { 0xe100, 0xe28c };
3141 int i; 3226 int i;
3142 3227
3143 if (dev_priv->card_type != NV_50) { 3228 if (dev_priv->card_type < NV_50) {
3144 NV_ERROR(bios->dev, "INIT_GPIO on unsupported chipset\n"); 3229 NV_ERROR(bios->dev, "INIT_GPIO on unsupported chipset\n");
3145 return 1; 3230 return 1;
3146 } 3231 }
@@ -3490,6 +3575,69 @@ init_zm_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
3490 return len; 3575 return len;
3491} 3576}
3492 3577
3578static int
3579init_i2c_long_if(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
3580{
3581 /*
3582 * INIT_I2C_LONG_IF opcode: 0x9A ('')
3583 *
3584 * offset (8 bit): opcode
3585 * offset + 1 (8 bit): DCB I2C table entry index
3586 * offset + 2 (8 bit): I2C slave address
3587 * offset + 3 (16 bit): I2C register
3588 * offset + 5 (8 bit): mask
3589 * offset + 6 (8 bit): data
3590 *
3591 * Read the register given by "I2C register" on the device addressed
3592 * by "I2C slave address" on the I2C bus given by "DCB I2C table
3593 * entry index". Compare the result AND "mask" to "data".
3594 * If they're not equal, skip subsequent opcodes until condition is
3595 * inverted (INIT_NOT), or we hit INIT_RESUME
3596 */
3597
3598 uint8_t i2c_index = bios->data[offset + 1];
3599 uint8_t i2c_address = bios->data[offset + 2] >> 1;
3600 uint8_t reglo = bios->data[offset + 3];
3601 uint8_t reghi = bios->data[offset + 4];
3602 uint8_t mask = bios->data[offset + 5];
3603 uint8_t data = bios->data[offset + 6];
3604 struct nouveau_i2c_chan *chan;
3605 uint8_t buf0[2] = { reghi, reglo };
3606 uint8_t buf1[1];
3607 struct i2c_msg msg[2] = {
3608 { i2c_address, 0, 1, buf0 },
3609 { i2c_address, I2C_M_RD, 1, buf1 },
3610 };
3611 int ret;
3612
3613 /* no execute check by design */
3614
3615 BIOSLOG(bios, "0x%04X: DCBI2CIndex: 0x%02X, I2CAddress: 0x%02X\n",
3616 offset, i2c_index, i2c_address);
3617
3618 chan = init_i2c_device_find(bios->dev, i2c_index);
3619 if (!chan)
3620 return -ENODEV;
3621
3622
3623 ret = i2c_transfer(&chan->adapter, msg, 2);
3624 if (ret < 0) {
3625 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X:0x%02X, Value: [no device], "
3626 "Mask: 0x%02X, Data: 0x%02X\n",
3627 offset, reghi, reglo, mask, data);
3628 iexec->execute = 0;
3629 return 7;
3630 }
3631
3632 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X:0x%02X, Value: 0x%02X, "
3633 "Mask: 0x%02X, Data: 0x%02X\n",
3634 offset, reghi, reglo, buf1[0], mask, data);
3635
3636 iexec->execute = ((buf1[0] & mask) == data);
3637
3638 return 7;
3639}
3640
3493static struct init_tbl_entry itbl_entry[] = { 3641static struct init_tbl_entry itbl_entry[] = {
3494 /* command name , id , length , offset , mult , command handler */ 3642 /* command name , id , length , offset , mult , command handler */
3495 /* INIT_PROG (0x31, 15, 10, 4) removed due to no example of use */ 3643 /* INIT_PROG (0x31, 15, 10, 4) removed due to no example of use */
@@ -3516,9 +3664,11 @@ static struct init_tbl_entry itbl_entry[] = {
3516 { "INIT_ZM_CR" , 0x53, init_zm_cr }, 3664 { "INIT_ZM_CR" , 0x53, init_zm_cr },
3517 { "INIT_ZM_CR_GROUP" , 0x54, init_zm_cr_group }, 3665 { "INIT_ZM_CR_GROUP" , 0x54, init_zm_cr_group },
3518 { "INIT_CONDITION_TIME" , 0x56, init_condition_time }, 3666 { "INIT_CONDITION_TIME" , 0x56, init_condition_time },
3667 { "INIT_LTIME" , 0x57, init_ltime },
3519 { "INIT_ZM_REG_SEQUENCE" , 0x58, init_zm_reg_sequence }, 3668 { "INIT_ZM_REG_SEQUENCE" , 0x58, init_zm_reg_sequence },
3520 /* INIT_INDIRECT_REG (0x5A, 7, 0, 0) removed due to no example of use */ 3669 /* INIT_INDIRECT_REG (0x5A, 7, 0, 0) removed due to no example of use */
3521 { "INIT_SUB_DIRECT" , 0x5B, init_sub_direct }, 3670 { "INIT_SUB_DIRECT" , 0x5B, init_sub_direct },
3671 { "INIT_I2C_IF" , 0x5E, init_i2c_if },
3522 { "INIT_COPY_NV_REG" , 0x5F, init_copy_nv_reg }, 3672 { "INIT_COPY_NV_REG" , 0x5F, init_copy_nv_reg },
3523 { "INIT_ZM_INDEX_IO" , 0x62, init_zm_index_io }, 3673 { "INIT_ZM_INDEX_IO" , 0x62, init_zm_index_io },
3524 { "INIT_COMPUTE_MEM" , 0x63, init_compute_mem }, 3674 { "INIT_COMPUTE_MEM" , 0x63, init_compute_mem },
@@ -3552,6 +3702,7 @@ static struct init_tbl_entry itbl_entry[] = {
3552 { "INIT_97" , 0x97, init_97 }, 3702 { "INIT_97" , 0x97, init_97 },
3553 { "INIT_AUXCH" , 0x98, init_auxch }, 3703 { "INIT_AUXCH" , 0x98, init_auxch },
3554 { "INIT_ZM_AUXCH" , 0x99, init_zm_auxch }, 3704 { "INIT_ZM_AUXCH" , 0x99, init_zm_auxch },
3705 { "INIT_I2C_LONG_IF" , 0x9A, init_i2c_long_if },
3555 { NULL , 0 , NULL } 3706 { NULL , 0 , NULL }
3556}; 3707};
3557 3708
@@ -4410,7 +4561,7 @@ nouveau_bios_run_display_table(struct drm_device *dev, struct dcb_entry *dcbent,
4410 bios->display.script_table_ptr, 4561 bios->display.script_table_ptr,
4411 table[2], table[3], table[0] >= 0x21); 4562 table[2], table[3], table[0] >= 0x21);
4412 if (!otable) { 4563 if (!otable) {
4413 NV_ERROR(dev, "Couldn't find matching output script table\n"); 4564 NV_DEBUG_KMS(dev, "failed to match any output table\n");
4414 return 1; 4565 return 1;
4415 } 4566 }
4416 4567
@@ -4467,7 +4618,7 @@ nouveau_bios_run_display_table(struct drm_device *dev, struct dcb_entry *dcbent,
4467 if (script) 4618 if (script)
4468 script = clkcmptable(bios, script, pxclk); 4619 script = clkcmptable(bios, script, pxclk);
4469 if (!script) { 4620 if (!script) {
4470 NV_ERROR(dev, "clock script 0 not found\n"); 4621 NV_DEBUG_KMS(dev, "clock script 0 not found\n");
4471 return 1; 4622 return 1;
4472 } 4623 }
4473 4624
@@ -4826,7 +4977,7 @@ int get_pll_limits(struct drm_device *dev, uint32_t limit_match, struct pll_lims
4826 pll_lim->min_p = record[12]; 4977 pll_lim->min_p = record[12];
4827 pll_lim->max_p = record[13]; 4978 pll_lim->max_p = record[13];
4828 /* where did this go to?? */ 4979 /* where did this go to?? */
4829 if (limit_match == 0x00614100 || limit_match == 0x00614900) 4980 if ((entry[0] & 0xf0) == 0x80)
4830 pll_lim->refclk = 27000; 4981 pll_lim->refclk = 27000;
4831 else 4982 else
4832 pll_lim->refclk = 100000; 4983 pll_lim->refclk = 100000;
@@ -5852,7 +6003,7 @@ static void fabricate_vga_output(struct dcb_table *dcb, int i2c, int heads)
5852 entry->i2c_index = i2c; 6003 entry->i2c_index = i2c;
5853 entry->heads = heads; 6004 entry->heads = heads;
5854 entry->location = DCB_LOC_ON_CHIP; 6005 entry->location = DCB_LOC_ON_CHIP;
5855 /* "or" mostly unused in early gen crt modesetting, 0 is fine */ 6006 entry->or = 1;
5856} 6007}
5857 6008
5858static void fabricate_dvi_i_output(struct dcb_table *dcb, bool twoHeads) 6009static void fabricate_dvi_i_output(struct dcb_table *dcb, bool twoHeads)
@@ -5980,7 +6131,13 @@ parse_dcb20_entry(struct drm_device *dev, struct dcb_table *dcb,
5980 } 6131 }
5981 break; 6132 break;
5982 case OUTPUT_TMDS: 6133 case OUTPUT_TMDS:
5983 entry->tmdsconf.sor.link = (conf & 0x00000030) >> 4; 6134 if (dcb->version >= 0x40)
6135 entry->tmdsconf.sor.link = (conf & 0x00000030) >> 4;
6136 else if (dcb->version >= 0x30)
6137 entry->tmdsconf.slave_addr = (conf & 0x00000700) >> 8;
6138 else if (dcb->version >= 0x22)
6139 entry->tmdsconf.slave_addr = (conf & 0x00000070) >> 4;
6140
5984 break; 6141 break;
5985 case 0xe: 6142 case 0xe:
5986 /* weird g80 mobile type that "nv" treats as a terminator */ 6143 /* weird g80 mobile type that "nv" treats as a terminator */
@@ -6270,6 +6427,19 @@ parse_dcb_table(struct drm_device *dev, struct nvbios *bios, bool twoHeads)
6270 dcb->i2c_table = &bios->data[i2ctabptr]; 6427 dcb->i2c_table = &bios->data[i2ctabptr];
6271 if (dcb->version >= 0x30) 6428 if (dcb->version >= 0x30)
6272 dcb->i2c_default_indices = dcb->i2c_table[4]; 6429 dcb->i2c_default_indices = dcb->i2c_table[4];
6430
6431 /*
6432 * Parse the "management" I2C bus, used for hardware
6433 * monitoring and some external TMDS transmitters.
6434 */
6435 if (dcb->version >= 0x22) {
6436 int idx = (dcb->version >= 0x40 ?
6437 dcb->i2c_default_indices & 0xf :
6438 2);
6439
6440 read_dcb_i2c_entry(dev, dcb->version, dcb->i2c_table,
6441 idx, &dcb->i2c[idx]);
6442 }
6273 } 6443 }
6274 6444
6275 if (entries > DCB_MAX_NUM_ENTRIES) 6445 if (entries > DCB_MAX_NUM_ENTRIES)
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.h b/drivers/gpu/drm/nouveau/nouveau_bios.h
index 024458a8d060..fd14dfd3d780 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.h
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.h
@@ -131,6 +131,7 @@ struct dcb_entry {
131 } dpconf; 131 } dpconf;
132 struct { 132 struct {
133 struct sor_conf sor; 133 struct sor_conf sor;
134 int slave_addr;
134 } tmdsconf; 135 } tmdsconf;
135 }; 136 };
136 bool i2c_upper_default; 137 bool i2c_upper_default;
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 3ca8343c15df..84f85183d041 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -51,9 +51,6 @@ nouveau_bo_del_ttm(struct ttm_buffer_object *bo)
51 if (nvbo->tile) 51 if (nvbo->tile)
52 nv10_mem_expire_tiling(dev, nvbo->tile, NULL); 52 nv10_mem_expire_tiling(dev, nvbo->tile, NULL);
53 53
54 spin_lock(&dev_priv->ttm.bo_list_lock);
55 list_del(&nvbo->head);
56 spin_unlock(&dev_priv->ttm.bo_list_lock);
57 kfree(nvbo); 54 kfree(nvbo);
58} 55}
59 56
@@ -166,9 +163,6 @@ nouveau_bo_new(struct drm_device *dev, struct nouveau_channel *chan,
166 } 163 }
167 nvbo->channel = NULL; 164 nvbo->channel = NULL;
168 165
169 spin_lock(&dev_priv->ttm.bo_list_lock);
170 list_add_tail(&nvbo->head, &dev_priv->ttm.bo_list);
171 spin_unlock(&dev_priv->ttm.bo_list_lock);
172 *pnvbo = nvbo; 166 *pnvbo = nvbo;
173 return 0; 167 return 0;
174} 168}
diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c
index 734e92635e83..b1b22baf1428 100644
--- a/drivers/gpu/drm/nouveau/nouveau_connector.c
+++ b/drivers/gpu/drm/nouveau/nouveau_connector.c
@@ -37,12 +37,6 @@
37#include "nouveau_connector.h" 37#include "nouveau_connector.h"
38#include "nouveau_hw.h" 38#include "nouveau_hw.h"
39 39
40static inline struct drm_encoder_slave_funcs *
41get_slave_funcs(struct nouveau_encoder *enc)
42{
43 return to_encoder_slave(to_drm_encoder(enc))->slave_funcs;
44}
45
46static struct nouveau_encoder * 40static struct nouveau_encoder *
47find_encoder_by_type(struct drm_connector *connector, int type) 41find_encoder_by_type(struct drm_connector *connector, int type)
48{ 42{
@@ -360,6 +354,7 @@ nouveau_connector_set_property(struct drm_connector *connector,
360{ 354{
361 struct nouveau_connector *nv_connector = nouveau_connector(connector); 355 struct nouveau_connector *nv_connector = nouveau_connector(connector);
362 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; 356 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
357 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
363 struct drm_device *dev = connector->dev; 358 struct drm_device *dev = connector->dev;
364 int ret; 359 int ret;
365 360
@@ -432,8 +427,8 @@ nouveau_connector_set_property(struct drm_connector *connector,
432 } 427 }
433 428
434 if (nv_encoder && nv_encoder->dcb->type == OUTPUT_TV) 429 if (nv_encoder && nv_encoder->dcb->type == OUTPUT_TV)
435 return get_slave_funcs(nv_encoder)-> 430 return get_slave_funcs(encoder)->set_property(
436 set_property(to_drm_encoder(nv_encoder), connector, property, value); 431 encoder, connector, property, value);
437 432
438 return -EINVAL; 433 return -EINVAL;
439} 434}
@@ -545,6 +540,7 @@ nouveau_connector_get_modes(struct drm_connector *connector)
545 struct drm_nouveau_private *dev_priv = dev->dev_private; 540 struct drm_nouveau_private *dev_priv = dev->dev_private;
546 struct nouveau_connector *nv_connector = nouveau_connector(connector); 541 struct nouveau_connector *nv_connector = nouveau_connector(connector);
547 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; 542 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
543 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
548 int ret = 0; 544 int ret = 0;
549 545
550 /* destroy the native mode, the attached monitor could have changed. 546 /* destroy the native mode, the attached monitor could have changed.
@@ -580,8 +576,7 @@ nouveau_connector_get_modes(struct drm_connector *connector)
580 } 576 }
581 577
582 if (nv_encoder->dcb->type == OUTPUT_TV) 578 if (nv_encoder->dcb->type == OUTPUT_TV)
583 ret = get_slave_funcs(nv_encoder)-> 579 ret = get_slave_funcs(encoder)->get_modes(encoder, connector);
584 get_modes(to_drm_encoder(nv_encoder), connector);
585 580
586 if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS || 581 if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS ||
587 nv_connector->dcb->type == DCB_CONNECTOR_eDP) 582 nv_connector->dcb->type == DCB_CONNECTOR_eDP)
@@ -597,6 +592,7 @@ nouveau_connector_mode_valid(struct drm_connector *connector,
597 struct drm_nouveau_private *dev_priv = connector->dev->dev_private; 592 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
598 struct nouveau_connector *nv_connector = nouveau_connector(connector); 593 struct nouveau_connector *nv_connector = nouveau_connector(connector);
599 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; 594 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
595 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
600 unsigned min_clock = 25000, max_clock = min_clock; 596 unsigned min_clock = 25000, max_clock = min_clock;
601 unsigned clock = mode->clock; 597 unsigned clock = mode->clock;
602 598
@@ -623,8 +619,7 @@ nouveau_connector_mode_valid(struct drm_connector *connector,
623 max_clock = 350000; 619 max_clock = 350000;
624 break; 620 break;
625 case OUTPUT_TV: 621 case OUTPUT_TV:
626 return get_slave_funcs(nv_encoder)-> 622 return get_slave_funcs(encoder)->mode_valid(encoder, mode);
627 mode_valid(to_drm_encoder(nv_encoder), mode);
628 case OUTPUT_DP: 623 case OUTPUT_DP:
629 if (nv_encoder->dp.link_bw == DP_LINK_BW_2_7) 624 if (nv_encoder->dp.link_bw == DP_LINK_BW_2_7)
630 max_clock = nv_encoder->dp.link_nr * 270000; 625 max_clock = nv_encoder->dp.link_nr * 270000;
diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c b/drivers/gpu/drm/nouveau/nouveau_display.c
index 74e6b4ed12c0..2e11fd65b4dd 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -84,16 +84,16 @@ nouveau_user_framebuffer_create(struct drm_device *dev,
84 84
85 gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle); 85 gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle);
86 if (!gem) 86 if (!gem)
87 return NULL; 87 return ERR_PTR(-ENOENT);
88 88
89 nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL); 89 nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL);
90 if (!nouveau_fb) 90 if (!nouveau_fb)
91 return NULL; 91 return ERR_PTR(-ENOMEM);
92 92
93 ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem)); 93 ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem));
94 if (ret) { 94 if (ret) {
95 drm_gem_object_unreference(gem); 95 drm_gem_object_unreference(gem);
96 return NULL; 96 return ERR_PTR(ret);
97 } 97 }
98 98
99 return &nouveau_fb->base; 99 return &nouveau_fb->base;
diff --git a/drivers/gpu/drm/nouveau/nouveau_dp.c b/drivers/gpu/drm/nouveau/nouveau_dp.c
index 33742b11188b..8a1b188b4cd1 100644
--- a/drivers/gpu/drm/nouveau/nouveau_dp.c
+++ b/drivers/gpu/drm/nouveau/nouveau_dp.c
@@ -572,47 +572,64 @@ out:
572 return ret ? ret : (stat & NV50_AUXCH_STAT_REPLY); 572 return ret ? ret : (stat & NV50_AUXCH_STAT_REPLY);
573} 573}
574 574
575int 575static int
576nouveau_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, 576nouveau_dp_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
577 uint8_t write_byte, uint8_t *read_byte)
578{ 577{
579 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; 578 struct nouveau_i2c_chan *auxch = (struct nouveau_i2c_chan *)adap;
580 struct nouveau_i2c_chan *auxch = (struct nouveau_i2c_chan *)adapter;
581 struct drm_device *dev = auxch->dev; 579 struct drm_device *dev = auxch->dev;
582 int ret = 0, cmd, addr = algo_data->address; 580 struct i2c_msg *msg = msgs;
583 uint8_t *buf; 581 int ret, mcnt = num;
584
585 if (mode == MODE_I2C_READ) {
586 cmd = AUX_I2C_READ;
587 buf = read_byte;
588 } else {
589 cmd = (mode & MODE_I2C_READ) ? AUX_I2C_READ : AUX_I2C_WRITE;
590 buf = &write_byte;
591 }
592 582
593 if (!(mode & MODE_I2C_STOP)) 583 while (mcnt--) {
594 cmd |= AUX_I2C_MOT; 584 u8 remaining = msg->len;
585 u8 *ptr = msg->buf;
595 586
596 if (mode & MODE_I2C_START) 587 while (remaining) {
597 return 1; 588 u8 cnt = (remaining > 16) ? 16 : remaining;
589 u8 cmd;
598 590
599 for (;;) { 591 if (msg->flags & I2C_M_RD)
600 ret = nouveau_dp_auxch(auxch, cmd, addr, buf, 1); 592 cmd = AUX_I2C_READ;
601 if (ret < 0) 593 else
602 return ret; 594 cmd = AUX_I2C_WRITE;
603 595
604 switch (ret & NV50_AUXCH_STAT_REPLY_I2C) { 596 if (mcnt || remaining > 16)
605 case NV50_AUXCH_STAT_REPLY_I2C_ACK: 597 cmd |= AUX_I2C_MOT;
606 return 1; 598
607 case NV50_AUXCH_STAT_REPLY_I2C_NACK: 599 ret = nouveau_dp_auxch(auxch, cmd, msg->addr, ptr, cnt);
608 return -EREMOTEIO; 600 if (ret < 0)
609 case NV50_AUXCH_STAT_REPLY_I2C_DEFER: 601 return ret;
610 udelay(100); 602
611 break; 603 switch (ret & NV50_AUXCH_STAT_REPLY_I2C) {
612 default: 604 case NV50_AUXCH_STAT_REPLY_I2C_ACK:
613 NV_ERROR(dev, "invalid auxch status: 0x%08x\n", ret); 605 break;
614 return -EREMOTEIO; 606 case NV50_AUXCH_STAT_REPLY_I2C_NACK:
607 return -EREMOTEIO;
608 case NV50_AUXCH_STAT_REPLY_I2C_DEFER:
609 udelay(100);
610 continue;
611 default:
612 NV_ERROR(dev, "bad auxch reply: 0x%08x\n", ret);
613 return -EREMOTEIO;
614 }
615
616 ptr += cnt;
617 remaining -= cnt;
615 } 618 }
619
620 msg++;
616 } 621 }
622
623 return num;
624}
625
626static u32
627nouveau_dp_i2c_func(struct i2c_adapter *adap)
628{
629 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
617} 630}
618 631
632const struct i2c_algorithm nouveau_dp_i2c_algo = {
633 .master_xfer = nouveau_dp_i2c_xfer,
634 .functionality = nouveau_dp_i2c_func
635};
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
index e15db15dca77..e424bf74d706 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
@@ -410,7 +410,7 @@ enum nv04_fp_display_regs {
410 410
411struct nv04_crtc_reg { 411struct nv04_crtc_reg {
412 unsigned char MiscOutReg; /* */ 412 unsigned char MiscOutReg; /* */
413 uint8_t CRTC[0x9f]; 413 uint8_t CRTC[0xa0];
414 uint8_t CR58[0x10]; 414 uint8_t CR58[0x10];
415 uint8_t Sequencer[5]; 415 uint8_t Sequencer[5];
416 uint8_t Graphics[9]; 416 uint8_t Graphics[9];
@@ -509,6 +509,7 @@ enum nouveau_card_type {
509 NV_30 = 0x30, 509 NV_30 = 0x30,
510 NV_40 = 0x40, 510 NV_40 = 0x40,
511 NV_50 = 0x50, 511 NV_50 = 0x50,
512 NV_C0 = 0xc0,
512}; 513};
513 514
514struct drm_nouveau_private { 515struct drm_nouveau_private {
@@ -536,8 +537,6 @@ struct drm_nouveau_private {
536 struct drm_global_reference mem_global_ref; 537 struct drm_global_reference mem_global_ref;
537 struct ttm_bo_global_ref bo_global_ref; 538 struct ttm_bo_global_ref bo_global_ref;
538 struct ttm_bo_device bdev; 539 struct ttm_bo_device bdev;
539 spinlock_t bo_list_lock;
540 struct list_head bo_list;
541 atomic_t validate_sequence; 540 atomic_t validate_sequence;
542 } ttm; 541 } ttm;
543 542
@@ -931,6 +930,10 @@ extern void nv40_fb_set_region_tiling(struct drm_device *, int, uint32_t,
931extern int nv50_fb_init(struct drm_device *); 930extern int nv50_fb_init(struct drm_device *);
932extern void nv50_fb_takedown(struct drm_device *); 931extern void nv50_fb_takedown(struct drm_device *);
933 932
933/* nvc0_fb.c */
934extern int nvc0_fb_init(struct drm_device *);
935extern void nvc0_fb_takedown(struct drm_device *);
936
934/* nv04_fifo.c */ 937/* nv04_fifo.c */
935extern int nv04_fifo_init(struct drm_device *); 938extern int nv04_fifo_init(struct drm_device *);
936extern void nv04_fifo_disable(struct drm_device *); 939extern void nv04_fifo_disable(struct drm_device *);
@@ -968,6 +971,20 @@ extern void nv50_fifo_destroy_context(struct nouveau_channel *);
968extern int nv50_fifo_load_context(struct nouveau_channel *); 971extern int nv50_fifo_load_context(struct nouveau_channel *);
969extern int nv50_fifo_unload_context(struct drm_device *); 972extern int nv50_fifo_unload_context(struct drm_device *);
970 973
974/* nvc0_fifo.c */
975extern int nvc0_fifo_init(struct drm_device *);
976extern void nvc0_fifo_takedown(struct drm_device *);
977extern void nvc0_fifo_disable(struct drm_device *);
978extern void nvc0_fifo_enable(struct drm_device *);
979extern bool nvc0_fifo_reassign(struct drm_device *, bool);
980extern bool nvc0_fifo_cache_flush(struct drm_device *);
981extern bool nvc0_fifo_cache_pull(struct drm_device *, bool);
982extern int nvc0_fifo_channel_id(struct drm_device *);
983extern int nvc0_fifo_create_context(struct nouveau_channel *);
984extern void nvc0_fifo_destroy_context(struct nouveau_channel *);
985extern int nvc0_fifo_load_context(struct nouveau_channel *);
986extern int nvc0_fifo_unload_context(struct drm_device *);
987
971/* nv04_graph.c */ 988/* nv04_graph.c */
972extern struct nouveau_pgraph_object_class nv04_graph_grclass[]; 989extern struct nouveau_pgraph_object_class nv04_graph_grclass[];
973extern int nv04_graph_init(struct drm_device *); 990extern int nv04_graph_init(struct drm_device *);
@@ -1032,6 +1049,16 @@ extern int nv50_graph_unload_context(struct drm_device *);
1032extern void nv50_graph_context_switch(struct drm_device *); 1049extern void nv50_graph_context_switch(struct drm_device *);
1033extern int nv50_grctx_init(struct nouveau_grctx *); 1050extern int nv50_grctx_init(struct nouveau_grctx *);
1034 1051
1052/* nvc0_graph.c */
1053extern int nvc0_graph_init(struct drm_device *);
1054extern void nvc0_graph_takedown(struct drm_device *);
1055extern void nvc0_graph_fifo_access(struct drm_device *, bool);
1056extern struct nouveau_channel *nvc0_graph_channel(struct drm_device *);
1057extern int nvc0_graph_create_context(struct nouveau_channel *);
1058extern void nvc0_graph_destroy_context(struct nouveau_channel *);
1059extern int nvc0_graph_load_context(struct nouveau_channel *);
1060extern int nvc0_graph_unload_context(struct drm_device *);
1061
1035/* nv04_instmem.c */ 1062/* nv04_instmem.c */
1036extern int nv04_instmem_init(struct drm_device *); 1063extern int nv04_instmem_init(struct drm_device *);
1037extern void nv04_instmem_takedown(struct drm_device *); 1064extern void nv04_instmem_takedown(struct drm_device *);
@@ -1058,6 +1085,18 @@ extern void nv50_instmem_flush(struct drm_device *);
1058extern void nv84_instmem_flush(struct drm_device *); 1085extern void nv84_instmem_flush(struct drm_device *);
1059extern void nv50_vm_flush(struct drm_device *, int engine); 1086extern void nv50_vm_flush(struct drm_device *, int engine);
1060 1087
1088/* nvc0_instmem.c */
1089extern int nvc0_instmem_init(struct drm_device *);
1090extern void nvc0_instmem_takedown(struct drm_device *);
1091extern int nvc0_instmem_suspend(struct drm_device *);
1092extern void nvc0_instmem_resume(struct drm_device *);
1093extern int nvc0_instmem_populate(struct drm_device *, struct nouveau_gpuobj *,
1094 uint32_t *size);
1095extern void nvc0_instmem_clear(struct drm_device *, struct nouveau_gpuobj *);
1096extern int nvc0_instmem_bind(struct drm_device *, struct nouveau_gpuobj *);
1097extern int nvc0_instmem_unbind(struct drm_device *, struct nouveau_gpuobj *);
1098extern void nvc0_instmem_flush(struct drm_device *);
1099
1061/* nv04_mc.c */ 1100/* nv04_mc.c */
1062extern int nv04_mc_init(struct drm_device *); 1101extern int nv04_mc_init(struct drm_device *);
1063extern void nv04_mc_takedown(struct drm_device *); 1102extern void nv04_mc_takedown(struct drm_device *);
diff --git a/drivers/gpu/drm/nouveau/nouveau_encoder.h b/drivers/gpu/drm/nouveau/nouveau_encoder.h
index a1a0d48ae70c..7c82d68bc155 100644
--- a/drivers/gpu/drm/nouveau/nouveau_encoder.h
+++ b/drivers/gpu/drm/nouveau/nouveau_encoder.h
@@ -71,6 +71,12 @@ static inline struct drm_encoder *to_drm_encoder(struct nouveau_encoder *enc)
71 return &enc->base.base; 71 return &enc->base.base;
72} 72}
73 73
74static inline struct drm_encoder_slave_funcs *
75get_slave_funcs(struct drm_encoder *enc)
76{
77 return to_encoder_slave(enc)->slave_funcs;
78}
79
74struct nouveau_connector * 80struct nouveau_connector *
75nouveau_encoder_connector_get(struct nouveau_encoder *encoder); 81nouveau_encoder_connector_get(struct nouveau_encoder *encoder);
76int nv50_sor_create(struct drm_connector *, struct dcb_entry *); 82int nv50_sor_create(struct drm_connector *, struct dcb_entry *);
diff --git a/drivers/gpu/drm/nouveau/nouveau_fbcon.c b/drivers/gpu/drm/nouveau/nouveau_fbcon.c
index 099f637264aa..dbd30b2e43fd 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fbcon.c
+++ b/drivers/gpu/drm/nouveau/nouveau_fbcon.c
@@ -281,6 +281,8 @@ nouveau_fbcon_create(struct nouveau_fbdev *nfbdev,
281 281
282 if (dev_priv->channel && !nouveau_nofbaccel) { 282 if (dev_priv->channel && !nouveau_nofbaccel) {
283 switch (dev_priv->card_type) { 283 switch (dev_priv->card_type) {
284 case NV_C0:
285 break;
284 case NV_50: 286 case NV_50:
285 nv50_fbcon_accel_init(info); 287 nv50_fbcon_accel_init(info);
286 info->fbops = &nv50_fbcon_ops; 288 info->fbops = &nv50_fbcon_ops;
diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index 547f2c24c1e7..0f417ac1b696 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -284,7 +284,7 @@ retry:
284 if (!gem) { 284 if (!gem) {
285 NV_ERROR(dev, "Unknown handle 0x%08x\n", b->handle); 285 NV_ERROR(dev, "Unknown handle 0x%08x\n", b->handle);
286 validate_fini(op, NULL); 286 validate_fini(op, NULL);
287 return -EINVAL; 287 return -ENOENT;
288 } 288 }
289 nvbo = gem->driver_private; 289 nvbo = gem->driver_private;
290 290
@@ -759,7 +759,7 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,
759 759
760 gem = drm_gem_object_lookup(dev, file_priv, req->handle); 760 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
761 if (!gem) 761 if (!gem)
762 return ret; 762 return -ENOENT;
763 nvbo = nouveau_gem_object(gem); 763 nvbo = nouveau_gem_object(gem);
764 764
765 if (nvbo->cpu_filp) { 765 if (nvbo->cpu_filp) {
@@ -797,7 +797,7 @@ nouveau_gem_ioctl_cpu_fini(struct drm_device *dev, void *data,
797 797
798 gem = drm_gem_object_lookup(dev, file_priv, req->handle); 798 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
799 if (!gem) 799 if (!gem)
800 return ret; 800 return -ENOENT;
801 nvbo = nouveau_gem_object(gem); 801 nvbo = nouveau_gem_object(gem);
802 802
803 if (nvbo->cpu_filp != file_priv) 803 if (nvbo->cpu_filp != file_priv)
@@ -822,7 +822,7 @@ nouveau_gem_ioctl_info(struct drm_device *dev, void *data,
822 822
823 gem = drm_gem_object_lookup(dev, file_priv, req->handle); 823 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
824 if (!gem) 824 if (!gem)
825 return -EINVAL; 825 return -ENOENT;
826 826
827 ret = nouveau_gem_info(gem, req); 827 ret = nouveau_gem_info(gem, req);
828 drm_gem_object_unreference_unlocked(gem); 828 drm_gem_object_unreference_unlocked(gem);
diff --git a/drivers/gpu/drm/nouveau/nouveau_hw.c b/drivers/gpu/drm/nouveau/nouveau_hw.c
index 7855b35effc3..7b613682e400 100644
--- a/drivers/gpu/drm/nouveau/nouveau_hw.c
+++ b/drivers/gpu/drm/nouveau/nouveau_hw.c
@@ -865,8 +865,12 @@ nv_save_state_ext(struct drm_device *dev, int head,
865 rd_cio_state(dev, head, regp, NV_CIO_CRE_FF_INDEX); 865 rd_cio_state(dev, head, regp, NV_CIO_CRE_FF_INDEX);
866 rd_cio_state(dev, head, regp, NV_CIO_CRE_FFLWM__INDEX); 866 rd_cio_state(dev, head, regp, NV_CIO_CRE_FFLWM__INDEX);
867 rd_cio_state(dev, head, regp, NV_CIO_CRE_21); 867 rd_cio_state(dev, head, regp, NV_CIO_CRE_21);
868 if (dev_priv->card_type >= NV_30) 868
869 if (dev_priv->card_type >= NV_30) {
869 rd_cio_state(dev, head, regp, NV_CIO_CRE_47); 870 rd_cio_state(dev, head, regp, NV_CIO_CRE_47);
871 rd_cio_state(dev, head, regp, 0x9f);
872 }
873
870 rd_cio_state(dev, head, regp, NV_CIO_CRE_49); 874 rd_cio_state(dev, head, regp, NV_CIO_CRE_49);
871 rd_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR0_INDEX); 875 rd_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR0_INDEX);
872 rd_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR1_INDEX); 876 rd_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR1_INDEX);
@@ -971,8 +975,11 @@ nv_load_state_ext(struct drm_device *dev, int head,
971 wr_cio_state(dev, head, regp, NV_CIO_CRE_ENH_INDEX); 975 wr_cio_state(dev, head, regp, NV_CIO_CRE_ENH_INDEX);
972 wr_cio_state(dev, head, regp, NV_CIO_CRE_FF_INDEX); 976 wr_cio_state(dev, head, regp, NV_CIO_CRE_FF_INDEX);
973 wr_cio_state(dev, head, regp, NV_CIO_CRE_FFLWM__INDEX); 977 wr_cio_state(dev, head, regp, NV_CIO_CRE_FFLWM__INDEX);
974 if (dev_priv->card_type >= NV_30) 978
979 if (dev_priv->card_type >= NV_30) {
975 wr_cio_state(dev, head, regp, NV_CIO_CRE_47); 980 wr_cio_state(dev, head, regp, NV_CIO_CRE_47);
981 wr_cio_state(dev, head, regp, 0x9f);
982 }
976 983
977 wr_cio_state(dev, head, regp, NV_CIO_CRE_49); 984 wr_cio_state(dev, head, regp, NV_CIO_CRE_49);
978 wr_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR0_INDEX); 985 wr_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR0_INDEX);
diff --git a/drivers/gpu/drm/nouveau/nouveau_i2c.c b/drivers/gpu/drm/nouveau/nouveau_i2c.c
index cb0cb34440c6..0bd407ca3d42 100644
--- a/drivers/gpu/drm/nouveau/nouveau_i2c.c
+++ b/drivers/gpu/drm/nouveau/nouveau_i2c.c
@@ -163,7 +163,7 @@ nouveau_i2c_init(struct drm_device *dev, struct dcb_i2c_entry *entry, int index)
163 if (entry->chan) 163 if (entry->chan)
164 return -EEXIST; 164 return -EEXIST;
165 165
166 if (dev_priv->card_type == NV_50 && entry->read >= NV50_I2C_PORTS) { 166 if (dev_priv->card_type == NV_C0 && entry->read >= NV50_I2C_PORTS) {
167 NV_ERROR(dev, "unknown i2c port %d\n", entry->read); 167 NV_ERROR(dev, "unknown i2c port %d\n", entry->read);
168 return -EINVAL; 168 return -EINVAL;
169 } 169 }
@@ -174,26 +174,26 @@ nouveau_i2c_init(struct drm_device *dev, struct dcb_i2c_entry *entry, int index)
174 174
175 switch (entry->port_type) { 175 switch (entry->port_type) {
176 case 0: 176 case 0:
177 i2c->algo.bit.setsda = nv04_i2c_setsda; 177 i2c->bit.setsda = nv04_i2c_setsda;
178 i2c->algo.bit.setscl = nv04_i2c_setscl; 178 i2c->bit.setscl = nv04_i2c_setscl;
179 i2c->algo.bit.getsda = nv04_i2c_getsda; 179 i2c->bit.getsda = nv04_i2c_getsda;
180 i2c->algo.bit.getscl = nv04_i2c_getscl; 180 i2c->bit.getscl = nv04_i2c_getscl;
181 i2c->rd = entry->read; 181 i2c->rd = entry->read;
182 i2c->wr = entry->write; 182 i2c->wr = entry->write;
183 break; 183 break;
184 case 4: 184 case 4:
185 i2c->algo.bit.setsda = nv4e_i2c_setsda; 185 i2c->bit.setsda = nv4e_i2c_setsda;
186 i2c->algo.bit.setscl = nv4e_i2c_setscl; 186 i2c->bit.setscl = nv4e_i2c_setscl;
187 i2c->algo.bit.getsda = nv4e_i2c_getsda; 187 i2c->bit.getsda = nv4e_i2c_getsda;
188 i2c->algo.bit.getscl = nv4e_i2c_getscl; 188 i2c->bit.getscl = nv4e_i2c_getscl;
189 i2c->rd = 0x600800 + entry->read; 189 i2c->rd = 0x600800 + entry->read;
190 i2c->wr = 0x600800 + entry->write; 190 i2c->wr = 0x600800 + entry->write;
191 break; 191 break;
192 case 5: 192 case 5:
193 i2c->algo.bit.setsda = nv50_i2c_setsda; 193 i2c->bit.setsda = nv50_i2c_setsda;
194 i2c->algo.bit.setscl = nv50_i2c_setscl; 194 i2c->bit.setscl = nv50_i2c_setscl;
195 i2c->algo.bit.getsda = nv50_i2c_getsda; 195 i2c->bit.getsda = nv50_i2c_getsda;
196 i2c->algo.bit.getscl = nv50_i2c_getscl; 196 i2c->bit.getscl = nv50_i2c_getscl;
197 i2c->rd = nv50_i2c_port[entry->read]; 197 i2c->rd = nv50_i2c_port[entry->read];
198 i2c->wr = i2c->rd; 198 i2c->wr = i2c->rd;
199 break; 199 break;
@@ -216,17 +216,14 @@ nouveau_i2c_init(struct drm_device *dev, struct dcb_i2c_entry *entry, int index)
216 i2c_set_adapdata(&i2c->adapter, i2c); 216 i2c_set_adapdata(&i2c->adapter, i2c);
217 217
218 if (entry->port_type < 6) { 218 if (entry->port_type < 6) {
219 i2c->adapter.algo_data = &i2c->algo.bit; 219 i2c->adapter.algo_data = &i2c->bit;
220 i2c->algo.bit.udelay = 40; 220 i2c->bit.udelay = 40;
221 i2c->algo.bit.timeout = usecs_to_jiffies(5000); 221 i2c->bit.timeout = usecs_to_jiffies(5000);
222 i2c->algo.bit.data = i2c; 222 i2c->bit.data = i2c;
223 ret = i2c_bit_add_bus(&i2c->adapter); 223 ret = i2c_bit_add_bus(&i2c->adapter);
224 } else { 224 } else {
225 i2c->adapter.algo_data = &i2c->algo.dp; 225 i2c->adapter.algo = &nouveau_dp_i2c_algo;
226 i2c->algo.dp.running = false; 226 ret = i2c_add_adapter(&i2c->adapter);
227 i2c->algo.dp.address = 0;
228 i2c->algo.dp.aux_ch = nouveau_dp_i2c_aux_ch;
229 ret = i2c_dp_aux_add_bus(&i2c->adapter);
230 } 227 }
231 228
232 if (ret) { 229 if (ret) {
diff --git a/drivers/gpu/drm/nouveau/nouveau_i2c.h b/drivers/gpu/drm/nouveau/nouveau_i2c.h
index 6dd2f8713cd1..f71cb32f7571 100644
--- a/drivers/gpu/drm/nouveau/nouveau_i2c.h
+++ b/drivers/gpu/drm/nouveau/nouveau_i2c.h
@@ -33,10 +33,7 @@ struct dcb_i2c_entry;
33struct nouveau_i2c_chan { 33struct nouveau_i2c_chan {
34 struct i2c_adapter adapter; 34 struct i2c_adapter adapter;
35 struct drm_device *dev; 35 struct drm_device *dev;
36 union { 36 struct i2c_algo_bit_data bit;
37 struct i2c_algo_bit_data bit;
38 struct i2c_algo_dp_aux_data dp;
39 } algo;
40 unsigned rd; 37 unsigned rd;
41 unsigned wr; 38 unsigned wr;
42 unsigned data; 39 unsigned data;
@@ -49,7 +46,6 @@ bool nouveau_probe_i2c_addr(struct nouveau_i2c_chan *i2c, int addr);
49int nouveau_i2c_identify(struct drm_device *dev, const char *what, 46int nouveau_i2c_identify(struct drm_device *dev, const char *what,
50 struct i2c_board_info *info, int index); 47 struct i2c_board_info *info, int index);
51 48
52int nouveau_dp_i2c_aux_ch(struct i2c_adapter *, int mode, uint8_t write_byte, 49extern const struct i2c_algorithm nouveau_dp_i2c_algo;
53 uint8_t *read_byte);
54 50
55#endif /* __NOUVEAU_I2C_H__ */ 51#endif /* __NOUVEAU_I2C_H__ */
diff --git a/drivers/gpu/drm/nouveau/nouveau_irq.c b/drivers/gpu/drm/nouveau/nouveau_irq.c
index 53360f156063..794b0ee30cf6 100644
--- a/drivers/gpu/drm/nouveau/nouveau_irq.c
+++ b/drivers/gpu/drm/nouveau/nouveau_irq.c
@@ -49,7 +49,7 @@ nouveau_irq_preinstall(struct drm_device *dev)
49 /* Master disable */ 49 /* Master disable */
50 nv_wr32(dev, NV03_PMC_INTR_EN_0, 0); 50 nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
51 51
52 if (dev_priv->card_type == NV_50) { 52 if (dev_priv->card_type >= NV_50) {
53 INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh); 53 INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh);
54 INIT_WORK(&dev_priv->hpd_work, nv50_display_irq_hotplug_bh); 54 INIT_WORK(&dev_priv->hpd_work, nv50_display_irq_hotplug_bh);
55 INIT_LIST_HEAD(&dev_priv->vbl_waiting); 55 INIT_LIST_HEAD(&dev_priv->vbl_waiting);
@@ -586,11 +586,11 @@ nouveau_pgraph_irq_handler(struct drm_device *dev)
586 } 586 }
587 587
588 if (status & NV_PGRAPH_INTR_CONTEXT_SWITCH) { 588 if (status & NV_PGRAPH_INTR_CONTEXT_SWITCH) {
589 nouveau_pgraph_intr_context_switch(dev);
590
591 status &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH; 589 status &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
592 nv_wr32(dev, NV03_PGRAPH_INTR, 590 nv_wr32(dev, NV03_PGRAPH_INTR,
593 NV_PGRAPH_INTR_CONTEXT_SWITCH); 591 NV_PGRAPH_INTR_CONTEXT_SWITCH);
592
593 nouveau_pgraph_intr_context_switch(dev);
594 } 594 }
595 595
596 if (status) { 596 if (status) {
diff --git a/drivers/gpu/drm/nouveau/nouveau_mem.c b/drivers/gpu/drm/nouveau/nouveau_mem.c
index a9f36ab256b7..9689d4147686 100644
--- a/drivers/gpu/drm/nouveau/nouveau_mem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_mem.c
@@ -320,7 +320,8 @@ nouveau_mem_detect(struct drm_device *dev)
320 if (dev_priv->card_type < NV_50) { 320 if (dev_priv->card_type < NV_50) {
321 dev_priv->vram_size = nv_rd32(dev, NV04_PFB_FIFO_DATA); 321 dev_priv->vram_size = nv_rd32(dev, NV04_PFB_FIFO_DATA);
322 dev_priv->vram_size &= NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK; 322 dev_priv->vram_size &= NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK;
323 } else { 323 } else
324 if (dev_priv->card_type < NV_C0) {
324 dev_priv->vram_size = nv_rd32(dev, NV04_PFB_FIFO_DATA); 325 dev_priv->vram_size = nv_rd32(dev, NV04_PFB_FIFO_DATA);
325 dev_priv->vram_size |= (dev_priv->vram_size & 0xff) << 32; 326 dev_priv->vram_size |= (dev_priv->vram_size & 0xff) << 32;
326 dev_priv->vram_size &= 0xffffffff00ll; 327 dev_priv->vram_size &= 0xffffffff00ll;
@@ -328,6 +329,9 @@ nouveau_mem_detect(struct drm_device *dev)
328 dev_priv->vram_sys_base = nv_rd32(dev, 0x100e10); 329 dev_priv->vram_sys_base = nv_rd32(dev, 0x100e10);
329 dev_priv->vram_sys_base <<= 12; 330 dev_priv->vram_sys_base <<= 12;
330 } 331 }
332 } else {
333 dev_priv->vram_size = nv_rd32(dev, 0x10f20c) << 20;
334 dev_priv->vram_size *= nv_rd32(dev, 0x121c74);
331 } 335 }
332 336
333 NV_INFO(dev, "Detected %dMiB VRAM\n", (int)(dev_priv->vram_size >> 20)); 337 NV_INFO(dev, "Detected %dMiB VRAM\n", (int)(dev_priv->vram_size >> 20));
@@ -351,7 +355,7 @@ nouveau_mem_reset_agp(struct drm_device *dev)
351 /* First of all, disable fast writes, otherwise if it's 355 /* First of all, disable fast writes, otherwise if it's
352 * already enabled in the AGP bridge and we disable the card's 356 * already enabled in the AGP bridge and we disable the card's
353 * AGP controller we might be locking ourselves out of it. */ 357 * AGP controller we might be locking ourselves out of it. */
354 if (dev->agp->acquired) { 358 if (nv_rd32(dev, NV04_PBUS_PCI_NV_19) & PCI_AGP_COMMAND_FW) {
355 struct drm_agp_info info; 359 struct drm_agp_info info;
356 struct drm_agp_mode mode; 360 struct drm_agp_mode mode;
357 361
@@ -359,7 +363,7 @@ nouveau_mem_reset_agp(struct drm_device *dev)
359 if (ret) 363 if (ret)
360 return ret; 364 return ret;
361 365
362 mode.mode = info.mode & ~0x10; 366 mode.mode = info.mode & ~PCI_AGP_COMMAND_FW;
363 ret = drm_agp_enable(dev, mode); 367 ret = drm_agp_enable(dev, mode);
364 if (ret) 368 if (ret)
365 return ret; 369 return ret;
@@ -405,6 +409,8 @@ nouveau_mem_init_agp(struct drm_device *dev)
405 } 409 }
406 } 410 }
407 411
412 nouveau_mem_reset_agp(dev);
413
408 ret = drm_agp_info(dev, &info); 414 ret = drm_agp_info(dev, &info);
409 if (ret) { 415 if (ret) {
410 NV_ERROR(dev, "Unable to get AGP info: %d\n", ret); 416 NV_ERROR(dev, "Unable to get AGP info: %d\n", ret);
@@ -459,8 +465,6 @@ nouveau_mem_init(struct drm_device *dev)
459 return ret; 465 return ret;
460 } 466 }
461 467
462 INIT_LIST_HEAD(&dev_priv->ttm.bo_list);
463 spin_lock_init(&dev_priv->ttm.bo_list_lock);
464 spin_lock_init(&dev_priv->tile.lock); 468 spin_lock_init(&dev_priv->tile.lock);
465 469
466 dev_priv->fb_available_size = dev_priv->vram_size; 470 dev_priv->fb_available_size = dev_priv->vram_size;
@@ -494,7 +498,6 @@ nouveau_mem_init(struct drm_device *dev)
494 /* GART */ 498 /* GART */
495#if !defined(__powerpc__) && !defined(__ia64__) 499#if !defined(__powerpc__) && !defined(__ia64__)
496 if (drm_device_is_agp(dev) && dev->agp && !nouveau_noagp) { 500 if (drm_device_is_agp(dev) && dev->agp && !nouveau_noagp) {
497 nouveau_mem_reset_agp(dev);
498 ret = nouveau_mem_init_agp(dev); 501 ret = nouveau_mem_init_agp(dev);
499 if (ret) 502 if (ret)
500 NV_ERROR(dev, "Error initialising AGP: %d\n", ret); 503 NV_ERROR(dev, "Error initialising AGP: %d\n", ret);
diff --git a/drivers/gpu/drm/nouveau/nouveau_reg.h b/drivers/gpu/drm/nouveau/nouveau_reg.h
index 9c1056cb8a90..21a6e453b975 100644
--- a/drivers/gpu/drm/nouveau/nouveau_reg.h
+++ b/drivers/gpu/drm/nouveau/nouveau_reg.h
@@ -220,28 +220,21 @@
220# define NV_PGRAPH_INTR_ERROR (1<<20) 220# define NV_PGRAPH_INTR_ERROR (1<<20)
221#define NV10_PGRAPH_CTX_CONTROL 0x00400144 221#define NV10_PGRAPH_CTX_CONTROL 0x00400144
222#define NV10_PGRAPH_CTX_USER 0x00400148 222#define NV10_PGRAPH_CTX_USER 0x00400148
223#define NV10_PGRAPH_CTX_SWITCH1 0x0040014C 223#define NV10_PGRAPH_CTX_SWITCH(i) (0x0040014C + 0x4*(i))
224#define NV10_PGRAPH_CTX_SWITCH2 0x00400150
225#define NV10_PGRAPH_CTX_SWITCH3 0x00400154
226#define NV10_PGRAPH_CTX_SWITCH4 0x00400158
227#define NV10_PGRAPH_CTX_SWITCH5 0x0040015C
228#define NV04_PGRAPH_CTX_SWITCH1 0x00400160 224#define NV04_PGRAPH_CTX_SWITCH1 0x00400160
229#define NV10_PGRAPH_CTX_CACHE1 0x00400160 225#define NV10_PGRAPH_CTX_CACHE(i, j) (0x00400160 \
226 + 0x4*(i) + 0x20*(j))
230#define NV04_PGRAPH_CTX_SWITCH2 0x00400164 227#define NV04_PGRAPH_CTX_SWITCH2 0x00400164
231#define NV04_PGRAPH_CTX_SWITCH3 0x00400168 228#define NV04_PGRAPH_CTX_SWITCH3 0x00400168
232#define NV04_PGRAPH_CTX_SWITCH4 0x0040016C 229#define NV04_PGRAPH_CTX_SWITCH4 0x0040016C
233#define NV04_PGRAPH_CTX_CONTROL 0x00400170 230#define NV04_PGRAPH_CTX_CONTROL 0x00400170
234#define NV04_PGRAPH_CTX_USER 0x00400174 231#define NV04_PGRAPH_CTX_USER 0x00400174
235#define NV04_PGRAPH_CTX_CACHE1 0x00400180 232#define NV04_PGRAPH_CTX_CACHE1 0x00400180
236#define NV10_PGRAPH_CTX_CACHE2 0x00400180
237#define NV03_PGRAPH_CTX_CONTROL 0x00400190 233#define NV03_PGRAPH_CTX_CONTROL 0x00400190
238#define NV03_PGRAPH_CTX_USER 0x00400194 234#define NV03_PGRAPH_CTX_USER 0x00400194
239#define NV04_PGRAPH_CTX_CACHE2 0x004001A0 235#define NV04_PGRAPH_CTX_CACHE2 0x004001A0
240#define NV10_PGRAPH_CTX_CACHE3 0x004001A0
241#define NV04_PGRAPH_CTX_CACHE3 0x004001C0 236#define NV04_PGRAPH_CTX_CACHE3 0x004001C0
242#define NV10_PGRAPH_CTX_CACHE4 0x004001C0
243#define NV04_PGRAPH_CTX_CACHE4 0x004001E0 237#define NV04_PGRAPH_CTX_CACHE4 0x004001E0
244#define NV10_PGRAPH_CTX_CACHE5 0x004001E0
245#define NV40_PGRAPH_CTXCTL_0304 0x00400304 238#define NV40_PGRAPH_CTXCTL_0304 0x00400304
246#define NV40_PGRAPH_CTXCTL_0304_XFER_CTX 0x00000001 239#define NV40_PGRAPH_CTXCTL_0304_XFER_CTX 0x00000001
247#define NV40_PGRAPH_CTXCTL_UCODE_STAT 0x00400308 240#define NV40_PGRAPH_CTXCTL_UCODE_STAT 0x00400308
@@ -356,9 +349,12 @@
356#define NV04_PGRAPH_FFINTFC_ST2 0x00400754 349#define NV04_PGRAPH_FFINTFC_ST2 0x00400754
357#define NV10_PGRAPH_RDI_DATA 0x00400754 350#define NV10_PGRAPH_RDI_DATA 0x00400754
358#define NV04_PGRAPH_DMA_PITCH 0x00400760 351#define NV04_PGRAPH_DMA_PITCH 0x00400760
359#define NV10_PGRAPH_FFINTFC_ST2 0x00400764 352#define NV10_PGRAPH_FFINTFC_FIFO_PTR 0x00400760
360#define NV04_PGRAPH_DVD_COLORFMT 0x00400764 353#define NV04_PGRAPH_DVD_COLORFMT 0x00400764
354#define NV10_PGRAPH_FFINTFC_ST2 0x00400764
361#define NV04_PGRAPH_SCALED_FORMAT 0x00400768 355#define NV04_PGRAPH_SCALED_FORMAT 0x00400768
356#define NV10_PGRAPH_FFINTFC_ST2_DL 0x00400768
357#define NV10_PGRAPH_FFINTFC_ST2_DH 0x0040076c
362#define NV10_PGRAPH_DMA_PITCH 0x00400770 358#define NV10_PGRAPH_DMA_PITCH 0x00400770
363#define NV10_PGRAPH_DVD_COLORFMT 0x00400774 359#define NV10_PGRAPH_DVD_COLORFMT 0x00400774
364#define NV10_PGRAPH_SCALED_FORMAT 0x00400778 360#define NV10_PGRAPH_SCALED_FORMAT 0x00400778
diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
index ee3729e7823b..989322be3728 100644
--- a/drivers/gpu/drm/nouveau/nouveau_state.c
+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
@@ -359,6 +359,54 @@ static int nouveau_init_engine_ptrs(struct drm_device *dev)
359 engine->gpio.set = nv50_gpio_set; 359 engine->gpio.set = nv50_gpio_set;
360 engine->gpio.irq_enable = nv50_gpio_irq_enable; 360 engine->gpio.irq_enable = nv50_gpio_irq_enable;
361 break; 361 break;
362 case 0xC0:
363 engine->instmem.init = nvc0_instmem_init;
364 engine->instmem.takedown = nvc0_instmem_takedown;
365 engine->instmem.suspend = nvc0_instmem_suspend;
366 engine->instmem.resume = nvc0_instmem_resume;
367 engine->instmem.populate = nvc0_instmem_populate;
368 engine->instmem.clear = nvc0_instmem_clear;
369 engine->instmem.bind = nvc0_instmem_bind;
370 engine->instmem.unbind = nvc0_instmem_unbind;
371 engine->instmem.flush = nvc0_instmem_flush;
372 engine->mc.init = nv50_mc_init;
373 engine->mc.takedown = nv50_mc_takedown;
374 engine->timer.init = nv04_timer_init;
375 engine->timer.read = nv04_timer_read;
376 engine->timer.takedown = nv04_timer_takedown;
377 engine->fb.init = nvc0_fb_init;
378 engine->fb.takedown = nvc0_fb_takedown;
379 engine->graph.grclass = NULL; //nvc0_graph_grclass;
380 engine->graph.init = nvc0_graph_init;
381 engine->graph.takedown = nvc0_graph_takedown;
382 engine->graph.fifo_access = nvc0_graph_fifo_access;
383 engine->graph.channel = nvc0_graph_channel;
384 engine->graph.create_context = nvc0_graph_create_context;
385 engine->graph.destroy_context = nvc0_graph_destroy_context;
386 engine->graph.load_context = nvc0_graph_load_context;
387 engine->graph.unload_context = nvc0_graph_unload_context;
388 engine->fifo.channels = 128;
389 engine->fifo.init = nvc0_fifo_init;
390 engine->fifo.takedown = nvc0_fifo_takedown;
391 engine->fifo.disable = nvc0_fifo_disable;
392 engine->fifo.enable = nvc0_fifo_enable;
393 engine->fifo.reassign = nvc0_fifo_reassign;
394 engine->fifo.channel_id = nvc0_fifo_channel_id;
395 engine->fifo.create_context = nvc0_fifo_create_context;
396 engine->fifo.destroy_context = nvc0_fifo_destroy_context;
397 engine->fifo.load_context = nvc0_fifo_load_context;
398 engine->fifo.unload_context = nvc0_fifo_unload_context;
399 engine->display.early_init = nv50_display_early_init;
400 engine->display.late_takedown = nv50_display_late_takedown;
401 engine->display.create = nv50_display_create;
402 engine->display.init = nv50_display_init;
403 engine->display.destroy = nv50_display_destroy;
404 engine->gpio.init = nv50_gpio_init;
405 engine->gpio.takedown = nouveau_stub_takedown;
406 engine->gpio.get = nv50_gpio_get;
407 engine->gpio.set = nv50_gpio_set;
408 engine->gpio.irq_enable = nv50_gpio_irq_enable;
409 break;
362 default: 410 default:
363 NV_ERROR(dev, "NV%02x unsupported\n", dev_priv->chipset); 411 NV_ERROR(dev, "NV%02x unsupported\n", dev_priv->chipset);
364 return 1; 412 return 1;
@@ -739,8 +787,10 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
739 int ret; 787 int ret;
740 788
741 dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL); 789 dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
742 if (!dev_priv) 790 if (!dev_priv) {
743 return -ENOMEM; 791 ret = -ENOMEM;
792 goto err_out;
793 }
744 dev->dev_private = dev_priv; 794 dev->dev_private = dev_priv;
745 dev_priv->dev = dev; 795 dev_priv->dev = dev;
746 796
@@ -750,8 +800,10 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
750 dev->pci_vendor, dev->pci_device, dev->pdev->class); 800 dev->pci_vendor, dev->pci_device, dev->pdev->class);
751 801
752 dev_priv->wq = create_workqueue("nouveau"); 802 dev_priv->wq = create_workqueue("nouveau");
753 if (!dev_priv->wq) 803 if (!dev_priv->wq) {
754 return -EINVAL; 804 ret = -EINVAL;
805 goto err_priv;
806 }
755 807
756 /* resource 0 is mmio regs */ 808 /* resource 0 is mmio regs */
757 /* resource 1 is linear FB */ 809 /* resource 1 is linear FB */
@@ -764,7 +816,8 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
764 if (!dev_priv->mmio) { 816 if (!dev_priv->mmio) {
765 NV_ERROR(dev, "Unable to initialize the mmio mapping. " 817 NV_ERROR(dev, "Unable to initialize the mmio mapping. "
766 "Please report your setup to " DRIVER_EMAIL "\n"); 818 "Please report your setup to " DRIVER_EMAIL "\n");
767 return -EINVAL; 819 ret = -EINVAL;
820 goto err_wq;
768 } 821 }
769 NV_DEBUG(dev, "regs mapped ok at 0x%llx\n", 822 NV_DEBUG(dev, "regs mapped ok at 0x%llx\n",
770 (unsigned long long)mmio_start_offs); 823 (unsigned long long)mmio_start_offs);
@@ -810,9 +863,13 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
810 case 0xa0: 863 case 0xa0:
811 dev_priv->card_type = NV_50; 864 dev_priv->card_type = NV_50;
812 break; 865 break;
866 case 0xc0:
867 dev_priv->card_type = NV_C0;
868 break;
813 default: 869 default:
814 NV_INFO(dev, "Unsupported chipset 0x%08x\n", reg0); 870 NV_INFO(dev, "Unsupported chipset 0x%08x\n", reg0);
815 return -EINVAL; 871 ret = -EINVAL;
872 goto err_mmio;
816 } 873 }
817 874
818 NV_INFO(dev, "Detected an NV%2x generation card (0x%08x)\n", 875 NV_INFO(dev, "Detected an NV%2x generation card (0x%08x)\n",
@@ -820,7 +877,7 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
820 877
821 ret = nouveau_remove_conflicting_drivers(dev); 878 ret = nouveau_remove_conflicting_drivers(dev);
822 if (ret) 879 if (ret)
823 return ret; 880 goto err_mmio;
824 881
825 /* Map PRAMIN BAR, or on older cards, the aperture withing BAR0 */ 882 /* Map PRAMIN BAR, or on older cards, the aperture withing BAR0 */
826 if (dev_priv->card_type >= NV_40) { 883 if (dev_priv->card_type >= NV_40) {
@@ -834,7 +891,8 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
834 dev_priv->ramin_size); 891 dev_priv->ramin_size);
835 if (!dev_priv->ramin) { 892 if (!dev_priv->ramin) {
836 NV_ERROR(dev, "Failed to PRAMIN BAR"); 893 NV_ERROR(dev, "Failed to PRAMIN BAR");
837 return -ENOMEM; 894 ret = -ENOMEM;
895 goto err_mmio;
838 } 896 }
839 } else { 897 } else {
840 dev_priv->ramin_size = 1 * 1024 * 1024; 898 dev_priv->ramin_size = 1 * 1024 * 1024;
@@ -842,7 +900,8 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
842 dev_priv->ramin_size); 900 dev_priv->ramin_size);
843 if (!dev_priv->ramin) { 901 if (!dev_priv->ramin) {
844 NV_ERROR(dev, "Failed to map BAR0 PRAMIN.\n"); 902 NV_ERROR(dev, "Failed to map BAR0 PRAMIN.\n");
845 return -ENOMEM; 903 ret = -ENOMEM;
904 goto err_mmio;
846 } 905 }
847 } 906 }
848 907
@@ -857,9 +916,21 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
857 /* For kernel modesetting, init card now and bring up fbcon */ 916 /* For kernel modesetting, init card now and bring up fbcon */
858 ret = nouveau_card_init(dev); 917 ret = nouveau_card_init(dev);
859 if (ret) 918 if (ret)
860 return ret; 919 goto err_ramin;
861 920
862 return 0; 921 return 0;
922
923err_ramin:
924 iounmap(dev_priv->ramin);
925err_mmio:
926 iounmap(dev_priv->mmio);
927err_wq:
928 destroy_workqueue(dev_priv->wq);
929err_priv:
930 kfree(dev_priv);
931 dev->dev_private = NULL;
932err_out:
933 return ret;
863} 934}
864 935
865void nouveau_lastclose(struct drm_device *dev) 936void nouveau_lastclose(struct drm_device *dev)
diff --git a/drivers/gpu/drm/nouveau/nv04_crtc.c b/drivers/gpu/drm/nouveau/nv04_crtc.c
index 1c20c08ce67c..497df8765f28 100644
--- a/drivers/gpu/drm/nouveau/nv04_crtc.c
+++ b/drivers/gpu/drm/nouveau/nv04_crtc.c
@@ -542,6 +542,9 @@ nv_crtc_mode_set_regs(struct drm_crtc *crtc, struct drm_display_mode * mode)
542 * 1 << 30 on 0x60.830), for no apparent reason */ 542 * 1 << 30 on 0x60.830), for no apparent reason */
543 regp->CRTC[NV_CIO_CRE_59] = off_chip_digital; 543 regp->CRTC[NV_CIO_CRE_59] = off_chip_digital;
544 544
545 if (dev_priv->card_type >= NV_30)
546 regp->CRTC[0x9f] = off_chip_digital ? 0x11 : 0x1;
547
545 regp->crtc_830 = mode->crtc_vdisplay - 3; 548 regp->crtc_830 = mode->crtc_vdisplay - 3;
546 regp->crtc_834 = mode->crtc_vdisplay - 1; 549 regp->crtc_834 = mode->crtc_vdisplay - 1;
547 550
@@ -739,15 +742,13 @@ nv_crtc_gamma_load(struct drm_crtc *crtc)
739} 742}
740 743
741static void 744static void
742nv_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, uint32_t size) 745nv_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, uint32_t start,
746 uint32_t size)
743{ 747{
748 int end = (start + size > 256) ? 256 : start + size, i;
744 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); 749 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
745 int i;
746 750
747 if (size != 256) 751 for (i = start; i < end; i++) {
748 return;
749
750 for (i = 0; i < 256; i++) {
751 nv_crtc->lut.r[i] = r[i]; 752 nv_crtc->lut.r[i] = r[i];
752 nv_crtc->lut.g[i] = g[i]; 753 nv_crtc->lut.g[i] = g[i];
753 nv_crtc->lut.b[i] = b[i]; 754 nv_crtc->lut.b[i] = b[i];
@@ -914,7 +915,7 @@ nv04_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
914 915
915 gem = drm_gem_object_lookup(dev, file_priv, buffer_handle); 916 gem = drm_gem_object_lookup(dev, file_priv, buffer_handle);
916 if (!gem) 917 if (!gem)
917 return -EINVAL; 918 return -ENOENT;
918 cursor = nouveau_gem_object(gem); 919 cursor = nouveau_gem_object(gem);
919 920
920 ret = nouveau_bo_map(cursor); 921 ret = nouveau_bo_map(cursor);
diff --git a/drivers/gpu/drm/nouveau/nv04_dfp.c b/drivers/gpu/drm/nouveau/nv04_dfp.c
index 3311f3a8c818..a5dcf7685800 100644
--- a/drivers/gpu/drm/nouveau/nv04_dfp.c
+++ b/drivers/gpu/drm/nouveau/nv04_dfp.c
@@ -34,6 +34,8 @@
34#include "nouveau_hw.h" 34#include "nouveau_hw.h"
35#include "nvreg.h" 35#include "nvreg.h"
36 36
37#include "i2c/sil164.h"
38
37#define FP_TG_CONTROL_ON (NV_PRAMDAC_FP_TG_CONTROL_DISPEN_POS | \ 39#define FP_TG_CONTROL_ON (NV_PRAMDAC_FP_TG_CONTROL_DISPEN_POS | \
38 NV_PRAMDAC_FP_TG_CONTROL_HSYNC_POS | \ 40 NV_PRAMDAC_FP_TG_CONTROL_HSYNC_POS | \
39 NV_PRAMDAC_FP_TG_CONTROL_VSYNC_POS) 41 NV_PRAMDAC_FP_TG_CONTROL_VSYNC_POS)
@@ -144,6 +146,36 @@ void nv04_dfp_update_fp_control(struct drm_encoder *encoder, int mode)
144 } 146 }
145} 147}
146 148
149static struct drm_encoder *get_tmds_slave(struct drm_encoder *encoder)
150{
151 struct drm_device *dev = encoder->dev;
152 struct dcb_entry *dcb = nouveau_encoder(encoder)->dcb;
153 struct drm_encoder *slave;
154
155 if (dcb->type != OUTPUT_TMDS || dcb->location == DCB_LOC_ON_CHIP)
156 return NULL;
157
158 /* Some BIOSes (e.g. the one in a Quadro FX1000) report several
159 * TMDS transmitters at the same I2C address, in the same I2C
160 * bus. This can still work because in that case one of them is
161 * always hard-wired to a reasonable configuration using straps,
162 * and the other one needs to be programmed.
163 *
164 * I don't think there's a way to know which is which, even the
165 * blob programs the one exposed via I2C for *both* heads, so
166 * let's do the same.
167 */
168 list_for_each_entry(slave, &dev->mode_config.encoder_list, head) {
169 struct dcb_entry *slave_dcb = nouveau_encoder(slave)->dcb;
170
171 if (slave_dcb->type == OUTPUT_TMDS && get_slave_funcs(slave) &&
172 slave_dcb->tmdsconf.slave_addr == dcb->tmdsconf.slave_addr)
173 return slave;
174 }
175
176 return NULL;
177}
178
147static bool nv04_dfp_mode_fixup(struct drm_encoder *encoder, 179static bool nv04_dfp_mode_fixup(struct drm_encoder *encoder,
148 struct drm_display_mode *mode, 180 struct drm_display_mode *mode,
149 struct drm_display_mode *adjusted_mode) 181 struct drm_display_mode *adjusted_mode)
@@ -429,6 +461,11 @@ static void nv04_dfp_commit(struct drm_encoder *encoder)
429 else 461 else
430 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_TEST_CONTROL + nv04_dac_output_offset(encoder), 0x00100000); 462 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_TEST_CONTROL + nv04_dac_output_offset(encoder), 0x00100000);
431 463
464 /* Init external transmitters */
465 if (get_tmds_slave(encoder))
466 get_slave_funcs(get_tmds_slave(encoder))->mode_set(
467 encoder, &nv_encoder->mode, &nv_encoder->mode);
468
432 helper->dpms(encoder, DRM_MODE_DPMS_ON); 469 helper->dpms(encoder, DRM_MODE_DPMS_ON);
433 470
434 NV_INFO(dev, "Output %s is running on CRTC %d using output %c\n", 471 NV_INFO(dev, "Output %s is running on CRTC %d using output %c\n",
@@ -550,10 +587,42 @@ static void nv04_dfp_destroy(struct drm_encoder *encoder)
550 587
551 NV_DEBUG_KMS(encoder->dev, "\n"); 588 NV_DEBUG_KMS(encoder->dev, "\n");
552 589
590 if (get_slave_funcs(encoder))
591 get_slave_funcs(encoder)->destroy(encoder);
592
553 drm_encoder_cleanup(encoder); 593 drm_encoder_cleanup(encoder);
554 kfree(nv_encoder); 594 kfree(nv_encoder);
555} 595}
556 596
597static void nv04_tmds_slave_init(struct drm_encoder *encoder)
598{
599 struct drm_device *dev = encoder->dev;
600 struct dcb_entry *dcb = nouveau_encoder(encoder)->dcb;
601 struct nouveau_i2c_chan *i2c = nouveau_i2c_find(dev, 2);
602 struct i2c_board_info info[] = {
603 {
604 .type = "sil164",
605 .addr = (dcb->tmdsconf.slave_addr == 0x7 ? 0x3a : 0x38),
606 .platform_data = &(struct sil164_encoder_params) {
607 SIL164_INPUT_EDGE_RISING
608 }
609 },
610 { }
611 };
612 int type;
613
614 if (!nv_gf4_disp_arch(dev) || !i2c ||
615 get_tmds_slave(encoder))
616 return;
617
618 type = nouveau_i2c_identify(dev, "TMDS transmitter", info, 2);
619 if (type < 0)
620 return;
621
622 drm_i2c_encoder_init(dev, to_encoder_slave(encoder),
623 &i2c->adapter, &info[type]);
624}
625
557static const struct drm_encoder_helper_funcs nv04_lvds_helper_funcs = { 626static const struct drm_encoder_helper_funcs nv04_lvds_helper_funcs = {
558 .dpms = nv04_lvds_dpms, 627 .dpms = nv04_lvds_dpms,
559 .save = nv04_dfp_save, 628 .save = nv04_dfp_save,
@@ -616,6 +685,10 @@ nv04_dfp_create(struct drm_connector *connector, struct dcb_entry *entry)
616 encoder->possible_crtcs = entry->heads; 685 encoder->possible_crtcs = entry->heads;
617 encoder->possible_clones = 0; 686 encoder->possible_clones = 0;
618 687
688 if (entry->type == OUTPUT_TMDS &&
689 entry->location != DCB_LOC_ON_CHIP)
690 nv04_tmds_slave_init(encoder);
691
619 drm_mode_connector_attach_encoder(connector, encoder); 692 drm_mode_connector_attach_encoder(connector, encoder);
620 return 0; 693 return 0;
621} 694}
diff --git a/drivers/gpu/drm/nouveau/nv04_tv.c b/drivers/gpu/drm/nouveau/nv04_tv.c
index 94e299cef0b2..0b5d012d7c28 100644
--- a/drivers/gpu/drm/nouveau/nv04_tv.c
+++ b/drivers/gpu/drm/nouveau/nv04_tv.c
@@ -89,7 +89,7 @@ static void nv04_tv_dpms(struct drm_encoder *encoder, int mode)
89 89
90 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_PLL_COEFF_SELECT, state->pllsel); 90 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_PLL_COEFF_SELECT, state->pllsel);
91 91
92 to_encoder_slave(encoder)->slave_funcs->dpms(encoder, mode); 92 get_slave_funcs(encoder)->dpms(encoder, mode);
93} 93}
94 94
95static void nv04_tv_bind(struct drm_device *dev, int head, bool bind) 95static void nv04_tv_bind(struct drm_device *dev, int head, bool bind)
@@ -152,7 +152,7 @@ static void nv04_tv_mode_set(struct drm_encoder *encoder,
152 regp->tv_vskew = 1; 152 regp->tv_vskew = 1;
153 regp->tv_vsync_delay = 1; 153 regp->tv_vsync_delay = 1;
154 154
155 to_encoder_slave(encoder)->slave_funcs->mode_set(encoder, mode, adjusted_mode); 155 get_slave_funcs(encoder)->mode_set(encoder, mode, adjusted_mode);
156} 156}
157 157
158static void nv04_tv_commit(struct drm_encoder *encoder) 158static void nv04_tv_commit(struct drm_encoder *encoder)
@@ -171,8 +171,7 @@ static void nv04_tv_commit(struct drm_encoder *encoder)
171 171
172static void nv04_tv_destroy(struct drm_encoder *encoder) 172static void nv04_tv_destroy(struct drm_encoder *encoder)
173{ 173{
174 to_encoder_slave(encoder)->slave_funcs->destroy(encoder); 174 get_slave_funcs(encoder)->destroy(encoder);
175
176 drm_encoder_cleanup(encoder); 175 drm_encoder_cleanup(encoder);
177 176
178 kfree(encoder->helper_private); 177 kfree(encoder->helper_private);
@@ -229,7 +228,7 @@ nv04_tv_create(struct drm_connector *connector, struct dcb_entry *entry)
229 goto fail_cleanup; 228 goto fail_cleanup;
230 229
231 /* Fill the function pointers */ 230 /* Fill the function pointers */
232 sfuncs = to_encoder_slave(encoder)->slave_funcs; 231 sfuncs = get_slave_funcs(encoder);
233 232
234 *hfuncs = (struct drm_encoder_helper_funcs) { 233 *hfuncs = (struct drm_encoder_helper_funcs) {
235 .dpms = nv04_tv_dpms, 234 .dpms = nv04_tv_dpms,
@@ -243,7 +242,6 @@ nv04_tv_create(struct drm_connector *connector, struct dcb_entry *entry)
243 }; 242 };
244 243
245 /* Attach it to the specified connector. */ 244 /* Attach it to the specified connector. */
246 sfuncs->set_config(encoder, nv04_tv_encoder_info[type].platform_data);
247 sfuncs->create_resources(encoder, connector); 245 sfuncs->create_resources(encoder, connector);
248 drm_mode_connector_attach_encoder(connector, encoder); 246 drm_mode_connector_attach_encoder(connector, encoder);
249 247
diff --git a/drivers/gpu/drm/nouveau/nv10_graph.c b/drivers/gpu/drm/nouveau/nv10_graph.c
index fcf2cdd19493..b2f6a57c0cc5 100644
--- a/drivers/gpu/drm/nouveau/nv10_graph.c
+++ b/drivers/gpu/drm/nouveau/nv10_graph.c
@@ -43,51 +43,51 @@ struct pipe_state {
43}; 43};
44 44
45static int nv10_graph_ctx_regs[] = { 45static int nv10_graph_ctx_regs[] = {
46 NV10_PGRAPH_CTX_SWITCH1, 46 NV10_PGRAPH_CTX_SWITCH(0),
47 NV10_PGRAPH_CTX_SWITCH2, 47 NV10_PGRAPH_CTX_SWITCH(1),
48 NV10_PGRAPH_CTX_SWITCH3, 48 NV10_PGRAPH_CTX_SWITCH(2),
49 NV10_PGRAPH_CTX_SWITCH4, 49 NV10_PGRAPH_CTX_SWITCH(3),
50 NV10_PGRAPH_CTX_SWITCH5, 50 NV10_PGRAPH_CTX_SWITCH(4),
51 NV10_PGRAPH_CTX_CACHE1, /* 8 values from 0x400160 to 0x40017c */ 51 NV10_PGRAPH_CTX_CACHE(0, 0),
52 NV10_PGRAPH_CTX_CACHE2, /* 8 values from 0x400180 to 0x40019c */ 52 NV10_PGRAPH_CTX_CACHE(0, 1),
53 NV10_PGRAPH_CTX_CACHE3, /* 8 values from 0x4001a0 to 0x4001bc */ 53 NV10_PGRAPH_CTX_CACHE(0, 2),
54 NV10_PGRAPH_CTX_CACHE4, /* 8 values from 0x4001c0 to 0x4001dc */ 54 NV10_PGRAPH_CTX_CACHE(0, 3),
55 NV10_PGRAPH_CTX_CACHE5, /* 8 values from 0x4001e0 to 0x4001fc */ 55 NV10_PGRAPH_CTX_CACHE(0, 4),
56 0x00400164, 56 NV10_PGRAPH_CTX_CACHE(1, 0),
57 0x00400184, 57 NV10_PGRAPH_CTX_CACHE(1, 1),
58 0x004001a4, 58 NV10_PGRAPH_CTX_CACHE(1, 2),
59 0x004001c4, 59 NV10_PGRAPH_CTX_CACHE(1, 3),
60 0x004001e4, 60 NV10_PGRAPH_CTX_CACHE(1, 4),
61 0x00400168, 61 NV10_PGRAPH_CTX_CACHE(2, 0),
62 0x00400188, 62 NV10_PGRAPH_CTX_CACHE(2, 1),
63 0x004001a8, 63 NV10_PGRAPH_CTX_CACHE(2, 2),
64 0x004001c8, 64 NV10_PGRAPH_CTX_CACHE(2, 3),
65 0x004001e8, 65 NV10_PGRAPH_CTX_CACHE(2, 4),
66 0x0040016c, 66 NV10_PGRAPH_CTX_CACHE(3, 0),
67 0x0040018c, 67 NV10_PGRAPH_CTX_CACHE(3, 1),
68 0x004001ac, 68 NV10_PGRAPH_CTX_CACHE(3, 2),
69 0x004001cc, 69 NV10_PGRAPH_CTX_CACHE(3, 3),
70 0x004001ec, 70 NV10_PGRAPH_CTX_CACHE(3, 4),
71 0x00400170, 71 NV10_PGRAPH_CTX_CACHE(4, 0),
72 0x00400190, 72 NV10_PGRAPH_CTX_CACHE(4, 1),
73 0x004001b0, 73 NV10_PGRAPH_CTX_CACHE(4, 2),
74 0x004001d0, 74 NV10_PGRAPH_CTX_CACHE(4, 3),
75 0x004001f0, 75 NV10_PGRAPH_CTX_CACHE(4, 4),
76 0x00400174, 76 NV10_PGRAPH_CTX_CACHE(5, 0),
77 0x00400194, 77 NV10_PGRAPH_CTX_CACHE(5, 1),
78 0x004001b4, 78 NV10_PGRAPH_CTX_CACHE(5, 2),
79 0x004001d4, 79 NV10_PGRAPH_CTX_CACHE(5, 3),
80 0x004001f4, 80 NV10_PGRAPH_CTX_CACHE(5, 4),
81 0x00400178, 81 NV10_PGRAPH_CTX_CACHE(6, 0),
82 0x00400198, 82 NV10_PGRAPH_CTX_CACHE(6, 1),
83 0x004001b8, 83 NV10_PGRAPH_CTX_CACHE(6, 2),
84 0x004001d8, 84 NV10_PGRAPH_CTX_CACHE(6, 3),
85 0x004001f8, 85 NV10_PGRAPH_CTX_CACHE(6, 4),
86 0x0040017c, 86 NV10_PGRAPH_CTX_CACHE(7, 0),
87 0x0040019c, 87 NV10_PGRAPH_CTX_CACHE(7, 1),
88 0x004001bc, 88 NV10_PGRAPH_CTX_CACHE(7, 2),
89 0x004001dc, 89 NV10_PGRAPH_CTX_CACHE(7, 3),
90 0x004001fc, 90 NV10_PGRAPH_CTX_CACHE(7, 4),
91 NV10_PGRAPH_CTX_USER, 91 NV10_PGRAPH_CTX_USER,
92 NV04_PGRAPH_DMA_START_0, 92 NV04_PGRAPH_DMA_START_0,
93 NV04_PGRAPH_DMA_START_1, 93 NV04_PGRAPH_DMA_START_1,
@@ -653,6 +653,78 @@ static int nv17_graph_ctx_regs_find_offset(struct drm_device *dev, int reg)
653 return -1; 653 return -1;
654} 654}
655 655
656static void nv10_graph_load_dma_vtxbuf(struct nouveau_channel *chan,
657 uint32_t inst)
658{
659 struct drm_device *dev = chan->dev;
660 struct drm_nouveau_private *dev_priv = dev->dev_private;
661 struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
662 uint32_t st2, st2_dl, st2_dh, fifo_ptr, fifo[0x60/4];
663 uint32_t ctx_user, ctx_switch[5];
664 int i, subchan = -1;
665
666 /* NV10TCL_DMA_VTXBUF (method 0x18c) modifies hidden state
667 * that cannot be restored via MMIO. Do it through the FIFO
668 * instead.
669 */
670
671 /* Look for a celsius object */
672 for (i = 0; i < 8; i++) {
673 int class = nv_rd32(dev, NV10_PGRAPH_CTX_CACHE(i, 0)) & 0xfff;
674
675 if (class == 0x56 || class == 0x96 || class == 0x99) {
676 subchan = i;
677 break;
678 }
679 }
680
681 if (subchan < 0 || !inst)
682 return;
683
684 /* Save the current ctx object */
685 ctx_user = nv_rd32(dev, NV10_PGRAPH_CTX_USER);
686 for (i = 0; i < 5; i++)
687 ctx_switch[i] = nv_rd32(dev, NV10_PGRAPH_CTX_SWITCH(i));
688
689 /* Save the FIFO state */
690 st2 = nv_rd32(dev, NV10_PGRAPH_FFINTFC_ST2);
691 st2_dl = nv_rd32(dev, NV10_PGRAPH_FFINTFC_ST2_DL);
692 st2_dh = nv_rd32(dev, NV10_PGRAPH_FFINTFC_ST2_DH);
693 fifo_ptr = nv_rd32(dev, NV10_PGRAPH_FFINTFC_FIFO_PTR);
694
695 for (i = 0; i < ARRAY_SIZE(fifo); i++)
696 fifo[i] = nv_rd32(dev, 0x4007a0 + 4 * i);
697
698 /* Switch to the celsius subchannel */
699 for (i = 0; i < 5; i++)
700 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(i),
701 nv_rd32(dev, NV10_PGRAPH_CTX_CACHE(subchan, i)));
702 nv_mask(dev, NV10_PGRAPH_CTX_USER, 0xe000, subchan << 13);
703
704 /* Inject NV10TCL_DMA_VTXBUF */
705 nv_wr32(dev, NV10_PGRAPH_FFINTFC_FIFO_PTR, 0);
706 nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2,
707 0x2c000000 | chan->id << 20 | subchan << 16 | 0x18c);
708 nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2_DL, inst);
709 nv_mask(dev, NV10_PGRAPH_CTX_CONTROL, 0, 0x10000);
710 pgraph->fifo_access(dev, true);
711 pgraph->fifo_access(dev, false);
712
713 /* Restore the FIFO state */
714 for (i = 0; i < ARRAY_SIZE(fifo); i++)
715 nv_wr32(dev, 0x4007a0 + 4 * i, fifo[i]);
716
717 nv_wr32(dev, NV10_PGRAPH_FFINTFC_FIFO_PTR, fifo_ptr);
718 nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2, st2);
719 nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2_DL, st2_dl);
720 nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2_DH, st2_dh);
721
722 /* Restore the current ctx object */
723 for (i = 0; i < 5; i++)
724 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(i), ctx_switch[i]);
725 nv_wr32(dev, NV10_PGRAPH_CTX_USER, ctx_user);
726}
727
656int nv10_graph_load_context(struct nouveau_channel *chan) 728int nv10_graph_load_context(struct nouveau_channel *chan)
657{ 729{
658 struct drm_device *dev = chan->dev; 730 struct drm_device *dev = chan->dev;
@@ -670,6 +742,8 @@ int nv10_graph_load_context(struct nouveau_channel *chan)
670 } 742 }
671 743
672 nv10_graph_load_pipe(chan); 744 nv10_graph_load_pipe(chan);
745 nv10_graph_load_dma_vtxbuf(chan, (nv_rd32(dev, NV10_PGRAPH_GLOBALSTATE1)
746 & 0xffff));
673 747
674 nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10010100); 748 nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10010100);
675 tmp = nv_rd32(dev, NV10_PGRAPH_CTX_USER); 749 tmp = nv_rd32(dev, NV10_PGRAPH_CTX_USER);
@@ -856,11 +930,12 @@ int nv10_graph_init(struct drm_device *dev)
856 for (i = 0; i < NV10_PFB_TILE__SIZE; i++) 930 for (i = 0; i < NV10_PFB_TILE__SIZE; i++)
857 nv10_graph_set_region_tiling(dev, i, 0, 0, 0); 931 nv10_graph_set_region_tiling(dev, i, 0, 0, 0);
858 932
859 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH1, 0x00000000); 933 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(0), 0x00000000);
860 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH2, 0x00000000); 934 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(1), 0x00000000);
861 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH3, 0x00000000); 935 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(2), 0x00000000);
862 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH4, 0x00000000); 936 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(3), 0x00000000);
863 nv_wr32(dev, NV10_PGRAPH_STATE , 0xFFFFFFFF); 937 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(4), 0x00000000);
938 nv_wr32(dev, NV10_PGRAPH_STATE, 0xFFFFFFFF);
864 939
865 tmp = nv_rd32(dev, NV10_PGRAPH_CTX_USER) & 0x00ffffff; 940 tmp = nv_rd32(dev, NV10_PGRAPH_CTX_USER) & 0x00ffffff;
866 tmp |= (dev_priv->engine.fifo.channels - 1) << 24; 941 tmp |= (dev_priv->engine.fifo.channels - 1) << 24;
diff --git a/drivers/gpu/drm/nouveau/nv30_fb.c b/drivers/gpu/drm/nouveau/nv30_fb.c
index 9d35c8b3b839..4a3f2f095128 100644
--- a/drivers/gpu/drm/nouveau/nv30_fb.c
+++ b/drivers/gpu/drm/nouveau/nv30_fb.c
@@ -30,15 +30,25 @@
30#include "nouveau_drm.h" 30#include "nouveau_drm.h"
31 31
32static int 32static int
33calc_ref(int b, int l, int i) 33calc_bias(struct drm_device *dev, int k, int i, int j)
34{
35 struct drm_nouveau_private *dev_priv = dev->dev_private;
36 int b = (dev_priv->chipset > 0x30 ?
37 nv_rd32(dev, 0x122c + 0x10 * k + 0x4 * j) >> (4 * (i ^ 1)) :
38 0) & 0xf;
39
40 return 2 * (b & 0x8 ? b - 0x10 : b);
41}
42
43static int
44calc_ref(struct drm_device *dev, int l, int k, int i)
34{ 45{
35 int j, x = 0; 46 int j, x = 0;
36 47
37 for (j = 0; j < 4; j++) { 48 for (j = 0; j < 4; j++) {
38 int n = (b >> (8 * j) & 0xf); 49 int m = (l >> (8 * i) & 0xff) + calc_bias(dev, k, i, j);
39 int m = (l >> (8 * i) & 0xff) + 2 * (n & 0x8 ? n - 0x10 : n);
40 50
41 x |= (0x80 | (m & 0x1f)) << (8 * j); 51 x |= (0x80 | clamp(m, 0, 0x1f)) << (8 * j);
42 } 52 }
43 53
44 return x; 54 return x;
@@ -63,18 +73,16 @@ nv30_fb_init(struct drm_device *dev)
63 dev_priv->chipset == 0x35) { 73 dev_priv->chipset == 0x35) {
64 /* Related to ROP count */ 74 /* Related to ROP count */
65 int n = (dev_priv->chipset == 0x31 ? 2 : 4); 75 int n = (dev_priv->chipset == 0x31 ? 2 : 4);
66 int b = (dev_priv->chipset > 0x30 ?
67 nv_rd32(dev, 0x122c) & 0xf : 0);
68 int l = nv_rd32(dev, 0x1003d0); 76 int l = nv_rd32(dev, 0x1003d0);
69 77
70 for (i = 0; i < n; i++) { 78 for (i = 0; i < n; i++) {
71 for (j = 0; j < 3; j++) 79 for (j = 0; j < 3; j++)
72 nv_wr32(dev, 0x10037c + 0xc * i + 0x4 * j, 80 nv_wr32(dev, 0x10037c + 0xc * i + 0x4 * j,
73 calc_ref(b, l, j)); 81 calc_ref(dev, l, 0, j));
74 82
75 for (j = 0; j < 2; j++) 83 for (j = 0; j < 2; j++)
76 nv_wr32(dev, 0x1003ac + 0x8 * i + 0x4 * j, 84 nv_wr32(dev, 0x1003ac + 0x8 * i + 0x4 * j,
77 calc_ref(b, l, j)); 85 calc_ref(dev, l, 1, j));
78 } 86 }
79 } 87 }
80 88
diff --git a/drivers/gpu/drm/nouveau/nv50_crtc.c b/drivers/gpu/drm/nouveau/nv50_crtc.c
index 5d11ea101666..bfd4ca2fe7ef 100644
--- a/drivers/gpu/drm/nouveau/nv50_crtc.c
+++ b/drivers/gpu/drm/nouveau/nv50_crtc.c
@@ -264,11 +264,16 @@ nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, int scaling_mode, bool update)
264int 264int
265nv50_crtc_set_clock(struct drm_device *dev, int head, int pclk) 265nv50_crtc_set_clock(struct drm_device *dev, int head, int pclk)
266{ 266{
267 uint32_t reg = NV50_PDISPLAY_CRTC_CLK_CTRL1(head); 267 struct drm_nouveau_private *dev_priv = dev->dev_private;
268 struct pll_lims pll; 268 struct pll_lims pll;
269 uint32_t reg1, reg2; 269 uint32_t reg, reg1, reg2;
270 int ret, N1, M1, N2, M2, P; 270 int ret, N1, M1, N2, M2, P;
271 271
272 if (dev_priv->chipset < NV_C0)
273 reg = NV50_PDISPLAY_CRTC_CLK_CTRL1(head);
274 else
275 reg = 0x614140 + (head * 0x800);
276
272 ret = get_pll_limits(dev, reg, &pll); 277 ret = get_pll_limits(dev, reg, &pll);
273 if (ret) 278 if (ret)
274 return ret; 279 return ret;
@@ -286,7 +291,8 @@ nv50_crtc_set_clock(struct drm_device *dev, int head, int pclk)
286 nv_wr32(dev, reg, 0x10000611); 291 nv_wr32(dev, reg, 0x10000611);
287 nv_wr32(dev, reg + 4, reg1 | (M1 << 16) | N1); 292 nv_wr32(dev, reg + 4, reg1 | (M1 << 16) | N1);
288 nv_wr32(dev, reg + 8, reg2 | (P << 28) | (M2 << 16) | N2); 293 nv_wr32(dev, reg + 8, reg2 | (P << 28) | (M2 << 16) | N2);
289 } else { 294 } else
295 if (dev_priv->chipset < NV_C0) {
290 ret = nv50_calc_pll2(dev, &pll, pclk, &N1, &N2, &M1, &P); 296 ret = nv50_calc_pll2(dev, &pll, pclk, &N1, &N2, &M1, &P);
291 if (ret <= 0) 297 if (ret <= 0)
292 return 0; 298 return 0;
@@ -298,6 +304,17 @@ nv50_crtc_set_clock(struct drm_device *dev, int head, int pclk)
298 nv_wr32(dev, reg, 0x50000610); 304 nv_wr32(dev, reg, 0x50000610);
299 nv_wr32(dev, reg + 4, reg1 | (P << 16) | (M1 << 8) | N1); 305 nv_wr32(dev, reg + 4, reg1 | (P << 16) | (M1 << 8) | N1);
300 nv_wr32(dev, reg + 8, N2); 306 nv_wr32(dev, reg + 8, N2);
307 } else {
308 ret = nv50_calc_pll2(dev, &pll, pclk, &N1, &N2, &M1, &P);
309 if (ret <= 0)
310 return 0;
311
312 NV_DEBUG(dev, "pclk %d out %d N %d fN 0x%04x M %d P %d\n",
313 pclk, ret, N1, N2, M1, P);
314
315 nv_mask(dev, reg + 0x0c, 0x00000000, 0x00000100);
316 nv_wr32(dev, reg + 0x04, (P << 16) | (N1 << 8) | M1);
317 nv_wr32(dev, reg + 0x10, N2 << 16);
301 } 318 }
302 319
303 return 0; 320 return 0;
@@ -348,7 +365,7 @@ nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
348 365
349 gem = drm_gem_object_lookup(dev, file_priv, buffer_handle); 366 gem = drm_gem_object_lookup(dev, file_priv, buffer_handle);
350 if (!gem) 367 if (!gem)
351 return -EINVAL; 368 return -ENOENT;
352 cursor = nouveau_gem_object(gem); 369 cursor = nouveau_gem_object(gem);
353 370
354 ret = nouveau_bo_map(cursor); 371 ret = nouveau_bo_map(cursor);
@@ -381,15 +398,12 @@ nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
381 398
382static void 399static void
383nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, 400nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
384 uint32_t size) 401 uint32_t start, uint32_t size)
385{ 402{
403 int end = (start + size > 256) ? 256 : start + size, i;
386 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); 404 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
387 int i;
388
389 if (size != 256)
390 return;
391 405
392 for (i = 0; i < 256; i++) { 406 for (i = start; i < end; i++) {
393 nv_crtc->lut.r[i] = r[i]; 407 nv_crtc->lut.r[i] = r[i];
394 nv_crtc->lut.g[i] = g[i]; 408 nv_crtc->lut.g[i] = g[i];
395 nv_crtc->lut.b[i] = b[i]; 409 nv_crtc->lut.b[i] = b[i];
diff --git a/drivers/gpu/drm/nouveau/nv50_display.c b/drivers/gpu/drm/nouveau/nv50_display.c
index f13ad0de9c8f..612fa6d6a0cb 100644
--- a/drivers/gpu/drm/nouveau/nv50_display.c
+++ b/drivers/gpu/drm/nouveau/nv50_display.c
@@ -76,7 +76,10 @@ nv50_evo_dmaobj_new(struct nouveau_channel *evo, uint32_t class, uint32_t name,
76 nv_wo32(dev, obj, 2, offset); 76 nv_wo32(dev, obj, 2, offset);
77 nv_wo32(dev, obj, 3, 0x00000000); 77 nv_wo32(dev, obj, 3, 0x00000000);
78 nv_wo32(dev, obj, 4, 0x00000000); 78 nv_wo32(dev, obj, 4, 0x00000000);
79 nv_wo32(dev, obj, 5, 0x00010000); 79 if (dev_priv->card_type < NV_C0)
80 nv_wo32(dev, obj, 5, 0x00010000);
81 else
82 nv_wo32(dev, obj, 5, 0x00020000);
80 dev_priv->engine.instmem.flush(dev); 83 dev_priv->engine.instmem.flush(dev);
81 84
82 return 0; 85 return 0;
diff --git a/drivers/gpu/drm/nouveau/nvc0_fb.c b/drivers/gpu/drm/nouveau/nvc0_fb.c
new file mode 100644
index 000000000000..26a996025dd2
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/nvc0_fb.c
@@ -0,0 +1,38 @@
1/*
2 * Copyright 2010 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
25#include "drmP.h"
26
27#include "nouveau_drv.h"
28
29int
30nvc0_fb_init(struct drm_device *dev)
31{
32 return 0;
33}
34
35void
36nvc0_fb_takedown(struct drm_device *dev)
37{
38}
diff --git a/drivers/gpu/drm/nouveau/nvc0_fifo.c b/drivers/gpu/drm/nouveau/nvc0_fifo.c
new file mode 100644
index 000000000000..d64375871979
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/nvc0_fifo.c
@@ -0,0 +1,96 @@
1/*
2 * Copyright 2010 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
25#include "drmP.h"
26
27#include "nouveau_drv.h"
28
29void
30nvc0_fifo_disable(struct drm_device *dev)
31{
32}
33
34void
35nvc0_fifo_enable(struct drm_device *dev)
36{
37}
38
39bool
40nvc0_fifo_reassign(struct drm_device *dev, bool enable)
41{
42 return false;
43}
44
45bool
46nvc0_fifo_cache_flush(struct drm_device *dev)
47{
48 return true;
49}
50
51bool
52nvc0_fifo_cache_pull(struct drm_device *dev, bool enable)
53{
54 return false;
55}
56
57int
58nvc0_fifo_channel_id(struct drm_device *dev)
59{
60 return 127;
61}
62
63int
64nvc0_fifo_create_context(struct nouveau_channel *chan)
65{
66 return 0;
67}
68
69void
70nvc0_fifo_destroy_context(struct nouveau_channel *chan)
71{
72}
73
74int
75nvc0_fifo_load_context(struct nouveau_channel *chan)
76{
77 return 0;
78}
79
80int
81nvc0_fifo_unload_context(struct drm_device *dev)
82{
83 return 0;
84}
85
86void
87nvc0_fifo_takedown(struct drm_device *dev)
88{
89}
90
91int
92nvc0_fifo_init(struct drm_device *dev)
93{
94 return 0;
95}
96
diff --git a/drivers/gpu/drm/nouveau/nvc0_graph.c b/drivers/gpu/drm/nouveau/nvc0_graph.c
new file mode 100644
index 000000000000..717a5177a8d8
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/nvc0_graph.c
@@ -0,0 +1,75 @@
1/*
2 * Copyright 2010 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
25#include "drmP.h"
26
27#include "nouveau_drv.h"
28
29void
30nvc0_graph_fifo_access(struct drm_device *dev, bool enabled)
31{
32}
33
34struct nouveau_channel *
35nvc0_graph_channel(struct drm_device *dev)
36{
37 return NULL;
38}
39
40int
41nvc0_graph_create_context(struct nouveau_channel *chan)
42{
43 return 0;
44}
45
46void
47nvc0_graph_destroy_context(struct nouveau_channel *chan)
48{
49}
50
51int
52nvc0_graph_load_context(struct nouveau_channel *chan)
53{
54 return 0;
55}
56
57int
58nvc0_graph_unload_context(struct drm_device *dev)
59{
60 return 0;
61}
62
63void
64nvc0_graph_takedown(struct drm_device *dev)
65{
66}
67
68int
69nvc0_graph_init(struct drm_device *dev)
70{
71 struct drm_nouveau_private *dev_priv = dev->dev_private;
72 dev_priv->engine.graph.accel_blocked = true;
73 return 0;
74}
75
diff --git a/drivers/gpu/drm/nouveau/nvc0_instmem.c b/drivers/gpu/drm/nouveau/nvc0_instmem.c
new file mode 100644
index 000000000000..3ab3cdc42173
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/nvc0_instmem.c
@@ -0,0 +1,232 @@
1/*
2 * Copyright 2010 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
25#include "drmP.h"
26
27#include "nouveau_drv.h"
28
29int
30nvc0_instmem_populate(struct drm_device *dev, struct nouveau_gpuobj *gpuobj,
31 uint32_t *size)
32{
33 int ret;
34
35 *size = ALIGN(*size, 4096);
36 if (*size == 0)
37 return -EINVAL;
38
39 ret = nouveau_bo_new(dev, NULL, *size, 0, TTM_PL_FLAG_VRAM, 0, 0x0000,
40 true, false, &gpuobj->im_backing);
41 if (ret) {
42 NV_ERROR(dev, "error getting PRAMIN backing pages: %d\n", ret);
43 return ret;
44 }
45
46 ret = nouveau_bo_pin(gpuobj->im_backing, TTM_PL_FLAG_VRAM);
47 if (ret) {
48 NV_ERROR(dev, "error pinning PRAMIN backing VRAM: %d\n", ret);
49 nouveau_bo_ref(NULL, &gpuobj->im_backing);
50 return ret;
51 }
52
53 gpuobj->im_backing_start = gpuobj->im_backing->bo.mem.mm_node->start;
54 gpuobj->im_backing_start <<= PAGE_SHIFT;
55 return 0;
56}
57
58void
59nvc0_instmem_clear(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
60{
61 struct drm_nouveau_private *dev_priv = dev->dev_private;
62
63 if (gpuobj && gpuobj->im_backing) {
64 if (gpuobj->im_bound)
65 dev_priv->engine.instmem.unbind(dev, gpuobj);
66 nouveau_bo_unpin(gpuobj->im_backing);
67 nouveau_bo_ref(NULL, &gpuobj->im_backing);
68 gpuobj->im_backing = NULL;
69 }
70}
71
72int
73nvc0_instmem_bind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
74{
75 struct drm_nouveau_private *dev_priv = dev->dev_private;
76 uint32_t pte, pte_end;
77 uint64_t vram;
78
79 if (!gpuobj->im_backing || !gpuobj->im_pramin || gpuobj->im_bound)
80 return -EINVAL;
81
82 NV_DEBUG(dev, "st=0x%lx sz=0x%lx\n",
83 gpuobj->im_pramin->start, gpuobj->im_pramin->size);
84
85 pte = gpuobj->im_pramin->start >> 12;
86 pte_end = (gpuobj->im_pramin->size >> 12) + pte;
87 vram = gpuobj->im_backing_start;
88
89 NV_DEBUG(dev, "pramin=0x%lx, pte=%d, pte_end=%d\n",
90 gpuobj->im_pramin->start, pte, pte_end);
91 NV_DEBUG(dev, "first vram page: 0x%08x\n", gpuobj->im_backing_start);
92
93 while (pte < pte_end) {
94 nv_wr32(dev, 0x702000 + (pte * 8), (vram >> 8) | 1);
95 nv_wr32(dev, 0x702004 + (pte * 8), 0);
96 vram += 4096;
97 pte++;
98 }
99 dev_priv->engine.instmem.flush(dev);
100
101 if (1) {
102 u32 chan = nv_rd32(dev, 0x1700) << 16;
103 nv_wr32(dev, 0x100cb8, (chan + 0x1000) >> 8);
104 nv_wr32(dev, 0x100cbc, 0x80000005);
105 }
106
107 gpuobj->im_bound = 1;
108 return 0;
109}
110
111int
112nvc0_instmem_unbind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
113{
114 struct drm_nouveau_private *dev_priv = dev->dev_private;
115 uint32_t pte, pte_end;
116
117 if (gpuobj->im_bound == 0)
118 return -EINVAL;
119
120 pte = gpuobj->im_pramin->start >> 12;
121 pte_end = (gpuobj->im_pramin->size >> 12) + pte;
122 while (pte < pte_end) {
123 nv_wr32(dev, 0x702000 + (pte * 8), 0);
124 nv_wr32(dev, 0x702004 + (pte * 8), 0);
125 pte++;
126 }
127 dev_priv->engine.instmem.flush(dev);
128
129 gpuobj->im_bound = 0;
130 return 0;
131}
132
133void
134nvc0_instmem_flush(struct drm_device *dev)
135{
136 nv_wr32(dev, 0x070000, 1);
137 if (!nv_wait(0x070000, 0x00000002, 0x00000000))
138 NV_ERROR(dev, "PRAMIN flush timeout\n");
139}
140
141int
142nvc0_instmem_suspend(struct drm_device *dev)
143{
144 struct drm_nouveau_private *dev_priv = dev->dev_private;
145 int i;
146
147 dev_priv->susres.ramin_copy = vmalloc(65536);
148 if (!dev_priv->susres.ramin_copy)
149 return -ENOMEM;
150
151 for (i = 0x700000; i < 0x710000; i += 4)
152 dev_priv->susres.ramin_copy[i/4] = nv_rd32(dev, i);
153 return 0;
154}
155
156void
157nvc0_instmem_resume(struct drm_device *dev)
158{
159 struct drm_nouveau_private *dev_priv = dev->dev_private;
160 u64 chan;
161 int i;
162
163 chan = dev_priv->vram_size - dev_priv->ramin_rsvd_vram;
164 nv_wr32(dev, 0x001700, chan >> 16);
165
166 for (i = 0x700000; i < 0x710000; i += 4)
167 nv_wr32(dev, i, dev_priv->susres.ramin_copy[i/4]);
168 vfree(dev_priv->susres.ramin_copy);
169 dev_priv->susres.ramin_copy = NULL;
170
171 nv_wr32(dev, 0x001714, 0xc0000000 | (chan >> 12));
172}
173
174int
175nvc0_instmem_init(struct drm_device *dev)
176{
177 struct drm_nouveau_private *dev_priv = dev->dev_private;
178 u64 chan, pgt3, imem, lim3 = dev_priv->ramin_size - 1;
179 int ret, i;
180
181 dev_priv->ramin_rsvd_vram = 1 * 1024 * 1024;
182 chan = dev_priv->vram_size - dev_priv->ramin_rsvd_vram;
183 imem = 4096 + 4096 + 32768;
184
185 nv_wr32(dev, 0x001700, chan >> 16);
186
187 /* channel setup */
188 nv_wr32(dev, 0x700200, lower_32_bits(chan + 0x1000));
189 nv_wr32(dev, 0x700204, upper_32_bits(chan + 0x1000));
190 nv_wr32(dev, 0x700208, lower_32_bits(lim3));
191 nv_wr32(dev, 0x70020c, upper_32_bits(lim3));
192
193 /* point pgd -> pgt */
194 nv_wr32(dev, 0x701000, 0);
195 nv_wr32(dev, 0x701004, ((chan + 0x2000) >> 8) | 1);
196
197 /* point pgt -> physical vram for channel */
198 pgt3 = 0x2000;
199 for (i = 0; i < dev_priv->ramin_rsvd_vram; i += 4096, pgt3 += 8) {
200 nv_wr32(dev, 0x700000 + pgt3, ((chan + i) >> 8) | 1);
201 nv_wr32(dev, 0x700004 + pgt3, 0);
202 }
203
204 /* clear rest of pgt */
205 for (; i < dev_priv->ramin_size; i += 4096, pgt3 += 8) {
206 nv_wr32(dev, 0x700000 + pgt3, 0);
207 nv_wr32(dev, 0x700004 + pgt3, 0);
208 }
209
210 /* point bar3 at the channel */
211 nv_wr32(dev, 0x001714, 0xc0000000 | (chan >> 12));
212
213 /* Global PRAMIN heap */
214 ret = drm_mm_init(&dev_priv->ramin_heap, imem,
215 dev_priv->ramin_size - imem);
216 if (ret) {
217 NV_ERROR(dev, "Failed to init RAMIN heap\n");
218 return -ENOMEM;
219 }
220
221 /*XXX: incorrect, but needed to make hash func "work" */
222 dev_priv->ramht_offset = 0x10000;
223 dev_priv->ramht_bits = 9;
224 dev_priv->ramht_size = (1 << dev_priv->ramht_bits);
225 return 0;
226}
227
228void
229nvc0_instmem_takedown(struct drm_device *dev)
230{
231}
232
diff --git a/drivers/gpu/drm/radeon/r600_cp.c b/drivers/gpu/drm/radeon/r600_cp.c
index 68e6f4349309..4f4cd8b286d5 100644
--- a/drivers/gpu/drm/radeon/r600_cp.c
+++ b/drivers/gpu/drm/radeon/r600_cp.c
@@ -200,7 +200,7 @@ int r600_page_table_init(struct drm_device *dev)
200 entry->pagelist[i], 0, 200 entry->pagelist[i], 0,
201 PAGE_SIZE, 201 PAGE_SIZE,
202 PCI_DMA_BIDIRECTIONAL); 202 PCI_DMA_BIDIRECTIONAL);
203 if (entry->busaddr[i] == 0) { 203 if (pci_dma_mapping_error(dev->pdev, entry->busaddr[i])) {
204 DRM_ERROR("unable to map PCIGART pages!\n"); 204 DRM_ERROR("unable to map PCIGART pages!\n");
205 r600_page_table_cleanup(dev, gart_info); 205 r600_page_table_cleanup(dev, gart_info);
206 goto done; 206 goto done;
diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
index c3ea212e0c3c..d8864949e387 100644
--- a/drivers/gpu/drm/radeon/r600_cs.c
+++ b/drivers/gpu/drm/radeon/r600_cs.c
@@ -133,6 +133,7 @@ static inline int r600_bpe_from_format(u32 *bpe, u32 format)
133 case V_038004_FMT_GB_GR: 133 case V_038004_FMT_GB_GR:
134 case V_038004_FMT_BG_RG: 134 case V_038004_FMT_BG_RG:
135 case V_038004_COLOR_INVALID: 135 case V_038004_COLOR_INVALID:
136 default:
136 *bpe = 16; 137 *bpe = 16;
137 return -EINVAL; 138 return -EINVAL;
138 } 139 }
@@ -174,7 +175,7 @@ static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i)
174 dev_warn(p->dev, "FMASK or CMASK buffer are not supported by this kernel\n"); 175 dev_warn(p->dev, "FMASK or CMASK buffer are not supported by this kernel\n");
175 return -EINVAL; 176 return -EINVAL;
176 } 177 }
177 size = radeon_bo_size(track->cb_color_bo[i]); 178 size = radeon_bo_size(track->cb_color_bo[i]) - track->cb_color_bo_offset[i];
178 if (r600_bpe_from_format(&bpe, G_0280A0_FORMAT(track->cb_color_info[i]))) { 179 if (r600_bpe_from_format(&bpe, G_0280A0_FORMAT(track->cb_color_info[i]))) {
179 dev_warn(p->dev, "%s:%d cb invalid format %d for %d (0x%08X)\n", 180 dev_warn(p->dev, "%s:%d cb invalid format %d for %d (0x%08X)\n",
180 __func__, __LINE__, G_0280A0_FORMAT(track->cb_color_info[i]), 181 __func__, __LINE__, G_0280A0_FORMAT(track->cb_color_info[i]),
@@ -327,7 +328,6 @@ static int r600_cs_track_check(struct radeon_cs_parser *p)
327 dev_warn(p->dev, "z/stencil buffer size not set\n"); 328 dev_warn(p->dev, "z/stencil buffer size not set\n");
328 return -EINVAL; 329 return -EINVAL;
329 } 330 }
330 printk_once(KERN_WARNING "You have old & broken userspace please consider updating mesa\n");
331 tmp = radeon_bo_size(track->db_bo) - track->db_offset; 331 tmp = radeon_bo_size(track->db_bo) - track->db_offset;
332 tmp = (tmp / bpe) >> 6; 332 tmp = (tmp / bpe) >> 6;
333 if (!tmp) { 333 if (!tmp) {
@@ -882,8 +882,6 @@ static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx
882 return -EINVAL; 882 return -EINVAL;
883 } 883 }
884 ib[idx] = track->cb_color_base_last[tmp]; 884 ib[idx] = track->cb_color_base_last[tmp];
885 printk_once(KERN_WARNING "You have old & broken userspace "
886 "please consider updating mesa & xf86-video-ati\n");
887 track->cb_color_frag_bo[tmp] = track->cb_color_bo[tmp]; 885 track->cb_color_frag_bo[tmp] = track->cb_color_bo[tmp];
888 } else { 886 } else {
889 r = r600_cs_packet_next_reloc(p, &reloc); 887 r = r600_cs_packet_next_reloc(p, &reloc);
@@ -910,8 +908,6 @@ static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx
910 return -EINVAL; 908 return -EINVAL;
911 } 909 }
912 ib[idx] = track->cb_color_base_last[tmp]; 910 ib[idx] = track->cb_color_base_last[tmp];
913 printk_once(KERN_WARNING "You have old & broken userspace "
914 "please consider updating mesa & xf86-video-ati\n");
915 track->cb_color_tile_bo[tmp] = track->cb_color_bo[tmp]; 911 track->cb_color_tile_bo[tmp] = track->cb_color_bo[tmp];
916 } else { 912 } else {
917 r = r600_cs_packet_next_reloc(p, &reloc); 913 r = r600_cs_packet_next_reloc(p, &reloc);
@@ -938,7 +934,7 @@ static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx
938 return -EINVAL; 934 return -EINVAL;
939 } 935 }
940 tmp = (reg - CB_COLOR0_BASE) / 4; 936 tmp = (reg - CB_COLOR0_BASE) / 4;
941 track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx); 937 track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx) << 8;
942 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 938 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
943 track->cb_color_base_last[tmp] = ib[idx]; 939 track->cb_color_base_last[tmp] = ib[idx];
944 track->cb_color_bo[tmp] = reloc->robj; 940 track->cb_color_bo[tmp] = reloc->robj;
@@ -950,7 +946,7 @@ static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx
950 "0x%04X\n", reg); 946 "0x%04X\n", reg);
951 return -EINVAL; 947 return -EINVAL;
952 } 948 }
953 track->db_offset = radeon_get_ib_value(p, idx); 949 track->db_offset = radeon_get_ib_value(p, idx) << 8;
954 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 950 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
955 track->db_bo = reloc->robj; 951 track->db_bo = reloc->robj;
956 break; 952 break;
@@ -1055,10 +1051,10 @@ static void r600_texture_size(unsigned nfaces, unsigned blevel, unsigned nlevels
1055 } 1051 }
1056 *l0_size = ALIGN((w0 * bpe), pitch_align) * h0 * d0; 1052 *l0_size = ALIGN((w0 * bpe), pitch_align) * h0 * d0;
1057 *mipmap_size = offset; 1053 *mipmap_size = offset;
1058 if (!blevel)
1059 *mipmap_size -= *l0_size;
1060 if (!nlevels) 1054 if (!nlevels)
1061 *mipmap_size = *l0_size; 1055 *mipmap_size = *l0_size;
1056 if (!blevel)
1057 *mipmap_size -= *l0_size;
1062} 1058}
1063 1059
1064/** 1060/**
@@ -1165,14 +1161,14 @@ static inline int r600_check_texture_resource(struct radeon_cs_parser *p, u32 i
1165 (pitch_align * bpe), 1161 (pitch_align * bpe),
1166 &l0_size, &mipmap_size); 1162 &l0_size, &mipmap_size);
1167 /* using get ib will give us the offset into the texture bo */ 1163 /* using get ib will give us the offset into the texture bo */
1168 word0 = radeon_get_ib_value(p, idx + 2); 1164 word0 = radeon_get_ib_value(p, idx + 2) << 8;
1169 if ((l0_size + word0) > radeon_bo_size(texture)) { 1165 if ((l0_size + word0) > radeon_bo_size(texture)) {
1170 dev_warn(p->dev, "texture bo too small (%d %d %d %d -> %d have %ld)\n", 1166 dev_warn(p->dev, "texture bo too small (%d %d %d %d -> %d have %ld)\n",
1171 w0, h0, bpe, word0, l0_size, radeon_bo_size(texture)); 1167 w0, h0, bpe, word0, l0_size, radeon_bo_size(texture));
1172 return -EINVAL; 1168 return -EINVAL;
1173 } 1169 }
1174 /* using get ib will give us the offset into the mipmap bo */ 1170 /* using get ib will give us the offset into the mipmap bo */
1175 word0 = radeon_get_ib_value(p, idx + 3); 1171 word0 = radeon_get_ib_value(p, idx + 3) << 8;
1176 if ((mipmap_size + word0) > radeon_bo_size(mipmap)) { 1172 if ((mipmap_size + word0) > radeon_bo_size(mipmap)) {
1177 dev_warn(p->dev, "mipmap bo too small (%d %d %d %d %d %d -> %d have %ld)\n", 1173 dev_warn(p->dev, "mipmap bo too small (%d %d %d %d %d %d -> %d have %ld)\n",
1178 w0, h0, bpe, blevel, nlevels, word0, mipmap_size, radeon_bo_size(texture)); 1174 w0, h0, bpe, blevel, nlevels, word0, mipmap_size, radeon_bo_size(texture));
@@ -1366,7 +1362,7 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
1366 } 1362 }
1367 for (i = 0; i < (pkt->count / 7); i++) { 1363 for (i = 0; i < (pkt->count / 7); i++) {
1368 struct radeon_bo *texture, *mipmap; 1364 struct radeon_bo *texture, *mipmap;
1369 u32 size, offset; 1365 u32 size, offset, base_offset, mip_offset;
1370 1366
1371 switch (G__SQ_VTX_CONSTANT_TYPE(radeon_get_ib_value(p, idx+(i*7)+6+1))) { 1367 switch (G__SQ_VTX_CONSTANT_TYPE(radeon_get_ib_value(p, idx+(i*7)+6+1))) {
1372 case SQ_TEX_VTX_VALID_TEXTURE: 1368 case SQ_TEX_VTX_VALID_TEXTURE:
@@ -1376,7 +1372,7 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
1376 DRM_ERROR("bad SET_RESOURCE\n"); 1372 DRM_ERROR("bad SET_RESOURCE\n");
1377 return -EINVAL; 1373 return -EINVAL;
1378 } 1374 }
1379 ib[idx+1+(i*7)+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 1375 base_offset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1380 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) 1376 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
1381 ib[idx+1+(i*7)+0] |= S_038000_TILE_MODE(V_038000_ARRAY_2D_TILED_THIN1); 1377 ib[idx+1+(i*7)+0] |= S_038000_TILE_MODE(V_038000_ARRAY_2D_TILED_THIN1);
1382 else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) 1378 else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
@@ -1388,12 +1384,14 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
1388 DRM_ERROR("bad SET_RESOURCE\n"); 1384 DRM_ERROR("bad SET_RESOURCE\n");
1389 return -EINVAL; 1385 return -EINVAL;
1390 } 1386 }
1391 ib[idx+1+(i*7)+3] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 1387 mip_offset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1392 mipmap = reloc->robj; 1388 mipmap = reloc->robj;
1393 r = r600_check_texture_resource(p, idx+(i*7)+1, 1389 r = r600_check_texture_resource(p, idx+(i*7)+1,
1394 texture, mipmap, reloc->lobj.tiling_flags); 1390 texture, mipmap, reloc->lobj.tiling_flags);
1395 if (r) 1391 if (r)
1396 return r; 1392 return r;
1393 ib[idx+1+(i*7)+2] += base_offset;
1394 ib[idx+1+(i*7)+3] += mip_offset;
1397 break; 1395 break;
1398 case SQ_TEX_VTX_VALID_BUFFER: 1396 case SQ_TEX_VTX_VALID_BUFFER:
1399 /* vtx base */ 1397 /* vtx base */
@@ -1403,10 +1401,11 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
1403 return -EINVAL; 1401 return -EINVAL;
1404 } 1402 }
1405 offset = radeon_get_ib_value(p, idx+1+(i*7)+0); 1403 offset = radeon_get_ib_value(p, idx+1+(i*7)+0);
1406 size = radeon_get_ib_value(p, idx+1+(i*7)+1); 1404 size = radeon_get_ib_value(p, idx+1+(i*7)+1) + 1;
1407 if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) { 1405 if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) {
1408 /* force size to size of the buffer */ 1406 /* force size to size of the buffer */
1409 dev_warn(p->dev, "vbo resource seems too big for the bo\n"); 1407 dev_warn(p->dev, "vbo resource seems too big (%d) for the bo (%ld)\n",
1408 size + offset, radeon_bo_size(reloc->robj));
1410 ib[idx+1+(i*7)+1] = radeon_bo_size(reloc->robj); 1409 ib[idx+1+(i*7)+1] = radeon_bo_size(reloc->robj);
1411 } 1410 }
1412 ib[idx+1+(i*7)+0] += (u32)((reloc->lobj.gpu_offset) & 0xffffffff); 1411 ib[idx+1+(i*7)+0] += (u32)((reloc->lobj.gpu_offset) & 0xffffffff);
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 3cd1c470b777..3dfcfa3ca425 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -1100,6 +1100,8 @@ struct radeon_device {
1100 struct notifier_block acpi_nb; 1100 struct notifier_block acpi_nb;
1101 /* only one userspace can use Hyperz features at a time */ 1101 /* only one userspace can use Hyperz features at a time */
1102 struct drm_file *hyperz_filp; 1102 struct drm_file *hyperz_filp;
1103 /* i2c buses */
1104 struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
1103}; 1105};
1104 1106
1105int radeon_device_init(struct radeon_device *rdev, 1107int radeon_device_init(struct radeon_device *rdev,
diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
index 3bc2bcdf5308..6d30868744ee 100644
--- a/drivers/gpu/drm/radeon/radeon_atombios.c
+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
@@ -48,7 +48,8 @@ radeon_add_atom_connector(struct drm_device *dev,
48 struct radeon_i2c_bus_rec *i2c_bus, 48 struct radeon_i2c_bus_rec *i2c_bus,
49 bool linkb, uint32_t igp_lane_info, 49 bool linkb, uint32_t igp_lane_info,
50 uint16_t connector_object_id, 50 uint16_t connector_object_id,
51 struct radeon_hpd *hpd); 51 struct radeon_hpd *hpd,
52 struct radeon_router *router);
52 53
53/* from radeon_legacy_encoder.c */ 54/* from radeon_legacy_encoder.c */
54extern void 55extern void
@@ -114,7 +115,8 @@ static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_dev
114 115
115 i2c.i2c_id = gpio->sucI2cId.ucAccess; 116 i2c.i2c_id = gpio->sucI2cId.ucAccess;
116 117
117 i2c.valid = true; 118 if (i2c.mask_clk_reg)
119 i2c.valid = true;
118 break; 120 break;
119 } 121 }
120 } 122 }
@@ -123,6 +125,66 @@ static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_dev
123 return i2c; 125 return i2c;
124} 126}
125 127
128void radeon_atombios_i2c_init(struct radeon_device *rdev)
129{
130 struct atom_context *ctx = rdev->mode_info.atom_context;
131 ATOM_GPIO_I2C_ASSIGMENT *gpio;
132 struct radeon_i2c_bus_rec i2c;
133 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
134 struct _ATOM_GPIO_I2C_INFO *i2c_info;
135 uint16_t data_offset, size;
136 int i, num_indices;
137 char stmp[32];
138
139 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
140
141 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
142 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
143
144 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
145 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
146
147 for (i = 0; i < num_indices; i++) {
148 gpio = &i2c_info->asGPIO_Info[i];
149 i2c.valid = false;
150 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
151 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
152 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
153 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
154 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
155 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
156 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
157 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
158 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
159 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
160 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
161 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
162 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
163 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
164 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
165 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
166
167 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
168 i2c.hw_capable = true;
169 else
170 i2c.hw_capable = false;
171
172 if (gpio->sucI2cId.ucAccess == 0xa0)
173 i2c.mm_i2c = true;
174 else
175 i2c.mm_i2c = false;
176
177 i2c.i2c_id = gpio->sucI2cId.ucAccess;
178
179 if (i2c.mask_clk_reg) {
180 i2c.valid = true;
181 sprintf(stmp, "0x%x", i2c.i2c_id);
182 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
183 }
184 }
185 }
186}
187
126static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev, 188static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
127 u8 id) 189 u8 id)
128{ 190{
@@ -206,6 +268,7 @@ static bool radeon_atom_apply_quirks(struct drm_device *dev,
206 uint16_t *line_mux, 268 uint16_t *line_mux,
207 struct radeon_hpd *hpd) 269 struct radeon_hpd *hpd)
208{ 270{
271 struct radeon_device *rdev = dev->dev_private;
209 272
210 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */ 273 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
211 if ((dev->pdev->device == 0x791e) && 274 if ((dev->pdev->device == 0x791e) &&
@@ -308,13 +371,22 @@ static bool radeon_atom_apply_quirks(struct drm_device *dev,
308 } 371 }
309 } 372 }
310 373
311 /* Acer laptop reports DVI-D as DVI-I */ 374 /* Acer laptop reports DVI-D as DVI-I and hpd pins reversed */
312 if ((dev->pdev->device == 0x95c4) && 375 if ((dev->pdev->device == 0x95c4) &&
313 (dev->pdev->subsystem_vendor == 0x1025) && 376 (dev->pdev->subsystem_vendor == 0x1025) &&
314 (dev->pdev->subsystem_device == 0x013c)) { 377 (dev->pdev->subsystem_device == 0x013c)) {
378 struct radeon_gpio_rec gpio;
379
315 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) && 380 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
316 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) 381 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
382 gpio = radeon_lookup_gpio(rdev, 6);
383 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
317 *connector_type = DRM_MODE_CONNECTOR_DVID; 384 *connector_type = DRM_MODE_CONNECTOR_DVID;
385 } else if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
386 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
387 gpio = radeon_lookup_gpio(rdev, 7);
388 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
389 }
318 } 390 }
319 391
320 /* XFX Pine Group device rv730 reports no VGA DDC lines 392 /* XFX Pine Group device rv730 reports no VGA DDC lines
@@ -399,13 +471,15 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
399 u16 size, data_offset; 471 u16 size, data_offset;
400 u8 frev, crev; 472 u8 frev, crev;
401 ATOM_CONNECTOR_OBJECT_TABLE *con_obj; 473 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
474 ATOM_OBJECT_TABLE *router_obj;
402 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj; 475 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
403 ATOM_OBJECT_HEADER *obj_header; 476 ATOM_OBJECT_HEADER *obj_header;
404 int i, j, path_size, device_support; 477 int i, j, k, path_size, device_support;
405 int connector_type; 478 int connector_type;
406 u16 igp_lane_info, conn_id, connector_object_id; 479 u16 igp_lane_info, conn_id, connector_object_id;
407 bool linkb; 480 bool linkb;
408 struct radeon_i2c_bus_rec ddc_bus; 481 struct radeon_i2c_bus_rec ddc_bus;
482 struct radeon_router router;
409 struct radeon_gpio_rec gpio; 483 struct radeon_gpio_rec gpio;
410 struct radeon_hpd hpd; 484 struct radeon_hpd hpd;
411 485
@@ -415,6 +489,8 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
415 if (crev < 2) 489 if (crev < 2)
416 return false; 490 return false;
417 491
492 router.valid = false;
493
418 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset); 494 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
419 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *) 495 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
420 (ctx->bios + data_offset + 496 (ctx->bios + data_offset +
@@ -422,6 +498,9 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
422 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *) 498 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
423 (ctx->bios + data_offset + 499 (ctx->bios + data_offset +
424 le16_to_cpu(obj_header->usConnectorObjectTableOffset)); 500 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
501 router_obj = (ATOM_OBJECT_TABLE *)
502 (ctx->bios + data_offset +
503 le16_to_cpu(obj_header->usRouterObjectTableOffset));
425 device_support = le16_to_cpu(obj_header->usDeviceSupport); 504 device_support = le16_to_cpu(obj_header->usDeviceSupport);
426 505
427 path_size = 0; 506 path_size = 0;
@@ -508,33 +587,86 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
508 if (connector_type == DRM_MODE_CONNECTOR_Unknown) 587 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
509 continue; 588 continue;
510 589
511 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); 590 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
512 j++) { 591 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
513 uint8_t enc_obj_id, enc_obj_num, enc_obj_type;
514 592
515 enc_obj_id = 593 grph_obj_id =
516 (le16_to_cpu(path->usGraphicObjIds[j]) & 594 (le16_to_cpu(path->usGraphicObjIds[j]) &
517 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT; 595 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
518 enc_obj_num = 596 grph_obj_num =
519 (le16_to_cpu(path->usGraphicObjIds[j]) & 597 (le16_to_cpu(path->usGraphicObjIds[j]) &
520 ENUM_ID_MASK) >> ENUM_ID_SHIFT; 598 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
521 enc_obj_type = 599 grph_obj_type =
522 (le16_to_cpu(path->usGraphicObjIds[j]) & 600 (le16_to_cpu(path->usGraphicObjIds[j]) &
523 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT; 601 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
524 602
525 /* FIXME: add support for router objects */ 603 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
526 if (enc_obj_type == GRAPH_OBJECT_TYPE_ENCODER) { 604 if (grph_obj_num == 2)
527 if (enc_obj_num == 2)
528 linkb = true; 605 linkb = true;
529 else 606 else
530 linkb = false; 607 linkb = false;
531 608
532 radeon_add_atom_encoder(dev, 609 radeon_add_atom_encoder(dev,
533 enc_obj_id, 610 grph_obj_id,
534 le16_to_cpu 611 le16_to_cpu
535 (path-> 612 (path->
536 usDeviceTag)); 613 usDeviceTag));
537 614
615 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
616 router.valid = false;
617 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
618 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[j].usObjectID);
619 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
620 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
621 (ctx->bios + data_offset +
622 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
623 ATOM_I2C_RECORD *i2c_record;
624 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
625 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
626 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
627 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
628 (ctx->bios + data_offset +
629 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
630 int enum_id;
631
632 router.router_id = router_obj_id;
633 for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
634 enum_id++) {
635 if (le16_to_cpu(path->usConnObjectId) ==
636 le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
637 break;
638 }
639
640 while (record->ucRecordType > 0 &&
641 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
642 switch (record->ucRecordType) {
643 case ATOM_I2C_RECORD_TYPE:
644 i2c_record =
645 (ATOM_I2C_RECORD *)
646 record;
647 i2c_config =
648 (ATOM_I2C_ID_CONFIG_ACCESS *)
649 &i2c_record->sucI2cId;
650 router.i2c_info =
651 radeon_lookup_i2c_gpio(rdev,
652 i2c_config->
653 ucAccess);
654 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
655 break;
656 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
657 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
658 record;
659 router.valid = true;
660 router.mux_type = ddc_path->ucMuxType;
661 router.mux_control_pin = ddc_path->ucMuxControlPin;
662 router.mux_state = ddc_path->ucMuxState[enum_id];
663 break;
664 }
665 record = (ATOM_COMMON_RECORD_HEADER *)
666 ((char *)record + record->ucRecordSize);
667 }
668 }
669 }
538 } 670 }
539 } 671 }
540 672
@@ -614,7 +746,8 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
614 connector_type, &ddc_bus, 746 connector_type, &ddc_bus,
615 linkb, igp_lane_info, 747 linkb, igp_lane_info,
616 connector_object_id, 748 connector_object_id,
617 &hpd); 749 &hpd,
750 &router);
618 751
619 } 752 }
620 } 753 }
@@ -691,6 +824,9 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
691 int i, j, max_device; 824 int i, j, max_device;
692 struct bios_connector *bios_connectors; 825 struct bios_connector *bios_connectors;
693 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE; 826 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
827 struct radeon_router router;
828
829 router.valid = false;
694 830
695 bios_connectors = kzalloc(bc_size, GFP_KERNEL); 831 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
696 if (!bios_connectors) 832 if (!bios_connectors)
@@ -862,7 +998,8 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
862 &bios_connectors[i].ddc_bus, 998 &bios_connectors[i].ddc_bus,
863 false, 0, 999 false, 0,
864 connector_object_id, 1000 connector_object_id,
865 &bios_connectors[i].hpd); 1001 &bios_connectors[i].hpd,
1002 &router);
866 } 1003 }
867 } 1004 }
868 1005
@@ -1521,7 +1658,7 @@ void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1521 thermal_controller_names[power_info->info.ucOverdriveThermalController], 1658 thermal_controller_names[power_info->info.ucOverdriveThermalController],
1522 power_info->info.ucOverdriveControllerAddress >> 1); 1659 power_info->info.ucOverdriveControllerAddress >> 1);
1523 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine); 1660 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
1524 rdev->pm.i2c_bus = radeon_i2c_create(rdev->ddev, &i2c_bus, "Thermal"); 1661 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1525 if (rdev->pm.i2c_bus) { 1662 if (rdev->pm.i2c_bus) {
1526 struct i2c_board_info info = { }; 1663 struct i2c_board_info info = { };
1527 const char *name = thermal_controller_names[power_info->info. 1664 const char *name = thermal_controller_names[power_info->info.
@@ -1814,7 +1951,7 @@ void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1814 (controller->ucFanParameters & 1951 (controller->ucFanParameters &
1815 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with"); 1952 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
1816 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine); 1953 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
1817 rdev->pm.i2c_bus = radeon_i2c_create(rdev->ddev, &i2c_bus, "Thermal"); 1954 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1818 if (rdev->pm.i2c_bus) { 1955 if (rdev->pm.i2c_bus) {
1819 struct i2c_board_info info = { }; 1956 struct i2c_board_info info = { };
1820 const char *name = pp_lib_thermal_controller_names[controller->ucType]; 1957 const char *name = pp_lib_thermal_controller_names[controller->ucType];
@@ -1927,6 +2064,11 @@ void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1927 rdev->pm.power_state[state_index].type = 2064 rdev->pm.power_state[state_index].type =
1928 POWER_STATE_TYPE_PERFORMANCE; 2065 POWER_STATE_TYPE_PERFORMANCE;
1929 break; 2066 break;
2067 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2068 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2069 rdev->pm.power_state[state_index].type =
2070 POWER_STATE_TYPE_PERFORMANCE;
2071 break;
1930 } 2072 }
1931 rdev->pm.power_state[state_index].flags = 0; 2073 rdev->pm.power_state[state_index].flags = 0;
1932 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) 2074 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
diff --git a/drivers/gpu/drm/radeon/radeon_clocks.c b/drivers/gpu/drm/radeon/radeon_clocks.c
index f64936cc4dd9..14448a740ba6 100644
--- a/drivers/gpu/drm/radeon/radeon_clocks.c
+++ b/drivers/gpu/drm/radeon/radeon_clocks.c
@@ -91,6 +91,85 @@ uint32_t radeon_legacy_get_memory_clock(struct radeon_device *rdev)
91 return mclk; 91 return mclk;
92} 92}
93 93
94#ifdef CONFIG_OF
95/*
96 * Read XTAL (ref clock), SCLK and MCLK from Open Firmware device
97 * tree. Hopefully, ATI OF driver is kind enough to fill these
98 */
99static bool __devinit radeon_read_clocks_OF(struct drm_device *dev)
100{
101 struct radeon_device *rdev = dev->dev_private;
102 struct device_node *dp = rdev->pdev->dev.of_node;
103 const u32 *val;
104 struct radeon_pll *p1pll = &rdev->clock.p1pll;
105 struct radeon_pll *p2pll = &rdev->clock.p2pll;
106 struct radeon_pll *spll = &rdev->clock.spll;
107 struct radeon_pll *mpll = &rdev->clock.mpll;
108
109 if (dp == NULL)
110 return false;
111 val = of_get_property(dp, "ATY,RefCLK", NULL);
112 if (!val || !*val) {
113 printk(KERN_WARNING "radeonfb: No ATY,RefCLK property !\n");
114 return false;
115 }
116 p1pll->reference_freq = p2pll->reference_freq = (*val) / 10;
117 p1pll->reference_div = RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
118 if (p1pll->reference_div < 2)
119 p1pll->reference_div = 12;
120 p2pll->reference_div = p1pll->reference_div;
121
122 /* These aren't in the device-tree */
123 if (rdev->family >= CHIP_R420) {
124 p1pll->pll_in_min = 100;
125 p1pll->pll_in_max = 1350;
126 p1pll->pll_out_min = 20000;
127 p1pll->pll_out_max = 50000;
128 p2pll->pll_in_min = 100;
129 p2pll->pll_in_max = 1350;
130 p2pll->pll_out_min = 20000;
131 p2pll->pll_out_max = 50000;
132 } else {
133 p1pll->pll_in_min = 40;
134 p1pll->pll_in_max = 500;
135 p1pll->pll_out_min = 12500;
136 p1pll->pll_out_max = 35000;
137 p2pll->pll_in_min = 40;
138 p2pll->pll_in_max = 500;
139 p2pll->pll_out_min = 12500;
140 p2pll->pll_out_max = 35000;
141 }
142
143 spll->reference_freq = mpll->reference_freq = p1pll->reference_freq;
144 spll->reference_div = mpll->reference_div =
145 RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) &
146 RADEON_M_SPLL_REF_DIV_MASK;
147
148 val = of_get_property(dp, "ATY,SCLK", NULL);
149 if (val && *val)
150 rdev->clock.default_sclk = (*val) / 10;
151 else
152 rdev->clock.default_sclk =
153 radeon_legacy_get_engine_clock(rdev);
154
155 val = of_get_property(dp, "ATY,MCLK", NULL);
156 if (val && *val)
157 rdev->clock.default_mclk = (*val) / 10;
158 else
159 rdev->clock.default_mclk =
160 radeon_legacy_get_memory_clock(rdev);
161
162 DRM_INFO("Using device-tree clock info\n");
163
164 return true;
165}
166#else
167static bool __devinit radeon_read_clocks_OF(struct drm_device *dev)
168{
169 return false;
170}
171#endif /* CONFIG_OF */
172
94void radeon_get_clock_info(struct drm_device *dev) 173void radeon_get_clock_info(struct drm_device *dev)
95{ 174{
96 struct radeon_device *rdev = dev->dev_private; 175 struct radeon_device *rdev = dev->dev_private;
@@ -105,6 +184,8 @@ void radeon_get_clock_info(struct drm_device *dev)
105 ret = radeon_atom_get_clock_info(dev); 184 ret = radeon_atom_get_clock_info(dev);
106 else 185 else
107 ret = radeon_combios_get_clock_info(dev); 186 ret = radeon_combios_get_clock_info(dev);
187 if (!ret)
188 ret = radeon_read_clocks_OF(dev);
108 189
109 if (ret) { 190 if (ret) {
110 if (p1pll->reference_div < 2) { 191 if (p1pll->reference_div < 2) {
diff --git a/drivers/gpu/drm/radeon/radeon_combios.c b/drivers/gpu/drm/radeon/radeon_combios.c
index 5e1474cde4b4..885dcfac1838 100644
--- a/drivers/gpu/drm/radeon/radeon_combios.c
+++ b/drivers/gpu/drm/radeon/radeon_combios.c
@@ -480,9 +480,66 @@ radeon_combios_get_hardcoded_edid(struct radeon_device *rdev)
480} 480}
481 481
482static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev, 482static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev,
483 int ddc_line) 483 enum radeon_combios_ddc ddc,
484 u32 clk_mask,
485 u32 data_mask)
484{ 486{
485 struct radeon_i2c_bus_rec i2c; 487 struct radeon_i2c_bus_rec i2c;
488 int ddc_line = 0;
489
490 /* ddc id = mask reg
491 * DDC_NONE_DETECTED = none
492 * DDC_DVI = RADEON_GPIO_DVI_DDC
493 * DDC_VGA = RADEON_GPIO_VGA_DDC
494 * DDC_LCD = RADEON_GPIOPAD_MASK
495 * DDC_GPIO = RADEON_MDGPIO_MASK
496 * r1xx/r2xx
497 * DDC_MONID = RADEON_GPIO_MONID
498 * DDC_CRT2 = RADEON_GPIO_CRT2_DDC
499 * r3xx
500 * DDC_MONID = RADEON_GPIO_MONID
501 * DDC_CRT2 = RADEON_GPIO_DVI_DDC
502 * rs3xx/rs4xx
503 * DDC_MONID = RADEON_GPIOPAD_MASK
504 * DDC_CRT2 = RADEON_GPIO_MONID
505 */
506 switch (ddc) {
507 case DDC_NONE_DETECTED:
508 default:
509 ddc_line = 0;
510 break;
511 case DDC_DVI:
512 ddc_line = RADEON_GPIO_DVI_DDC;
513 break;
514 case DDC_VGA:
515 ddc_line = RADEON_GPIO_VGA_DDC;
516 break;
517 case DDC_LCD:
518 ddc_line = RADEON_GPIOPAD_MASK;
519 break;
520 case DDC_GPIO:
521 ddc_line = RADEON_MDGPIO_MASK;
522 break;
523 case DDC_MONID:
524 if (rdev->family == CHIP_RS300 ||
525 rdev->family == CHIP_RS400 ||
526 rdev->family == CHIP_RS480)
527 ddc_line = RADEON_GPIOPAD_MASK;
528 else
529 ddc_line = RADEON_GPIO_MONID;
530 break;
531 case DDC_CRT2:
532 if (rdev->family == CHIP_RS300 ||
533 rdev->family == CHIP_RS400 ||
534 rdev->family == CHIP_RS480)
535 ddc_line = RADEON_GPIO_MONID;
536 else if (rdev->family >= CHIP_R300) {
537 ddc_line = RADEON_GPIO_DVI_DDC;
538 ddc = DDC_DVI;
539 } else
540 ddc_line = RADEON_GPIO_CRT2_DDC;
541 break;
542 }
486 543
487 if (ddc_line == RADEON_GPIOPAD_MASK) { 544 if (ddc_line == RADEON_GPIOPAD_MASK) {
488 i2c.mask_clk_reg = RADEON_GPIOPAD_MASK; 545 i2c.mask_clk_reg = RADEON_GPIOPAD_MASK;
@@ -503,15 +560,6 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
503 i2c.y_clk_reg = RADEON_MDGPIO_Y; 560 i2c.y_clk_reg = RADEON_MDGPIO_Y;
504 i2c.y_data_reg = RADEON_MDGPIO_Y; 561 i2c.y_data_reg = RADEON_MDGPIO_Y;
505 } else { 562 } else {
506 i2c.mask_clk_mask = RADEON_GPIO_EN_1;
507 i2c.mask_data_mask = RADEON_GPIO_EN_0;
508 i2c.a_clk_mask = RADEON_GPIO_A_1;
509 i2c.a_data_mask = RADEON_GPIO_A_0;
510 i2c.en_clk_mask = RADEON_GPIO_EN_1;
511 i2c.en_data_mask = RADEON_GPIO_EN_0;
512 i2c.y_clk_mask = RADEON_GPIO_Y_1;
513 i2c.y_data_mask = RADEON_GPIO_Y_0;
514
515 i2c.mask_clk_reg = ddc_line; 563 i2c.mask_clk_reg = ddc_line;
516 i2c.mask_data_reg = ddc_line; 564 i2c.mask_data_reg = ddc_line;
517 i2c.a_clk_reg = ddc_line; 565 i2c.a_clk_reg = ddc_line;
@@ -522,6 +570,26 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
522 i2c.y_data_reg = ddc_line; 570 i2c.y_data_reg = ddc_line;
523 } 571 }
524 572
573 if (clk_mask && data_mask) {
574 i2c.mask_clk_mask = clk_mask;
575 i2c.mask_data_mask = data_mask;
576 i2c.a_clk_mask = clk_mask;
577 i2c.a_data_mask = data_mask;
578 i2c.en_clk_mask = clk_mask;
579 i2c.en_data_mask = data_mask;
580 i2c.y_clk_mask = clk_mask;
581 i2c.y_data_mask = data_mask;
582 } else {
583 i2c.mask_clk_mask = RADEON_GPIO_EN_1;
584 i2c.mask_data_mask = RADEON_GPIO_EN_0;
585 i2c.a_clk_mask = RADEON_GPIO_A_1;
586 i2c.a_data_mask = RADEON_GPIO_A_0;
587 i2c.en_clk_mask = RADEON_GPIO_EN_1;
588 i2c.en_data_mask = RADEON_GPIO_EN_0;
589 i2c.y_clk_mask = RADEON_GPIO_Y_1;
590 i2c.y_data_mask = RADEON_GPIO_Y_0;
591 }
592
525 switch (rdev->family) { 593 switch (rdev->family) {
526 case CHIP_R100: 594 case CHIP_R100:
527 case CHIP_RV100: 595 case CHIP_RV100:
@@ -599,7 +667,8 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
599 break; 667 break;
600 } 668 }
601 i2c.mm_i2c = false; 669 i2c.mm_i2c = false;
602 i2c.i2c_id = 0; 670
671 i2c.i2c_id = ddc;
603 i2c.hpd = RADEON_HPD_NONE; 672 i2c.hpd = RADEON_HPD_NONE;
604 673
605 if (ddc_line) 674 if (ddc_line)
@@ -610,6 +679,62 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
610 return i2c; 679 return i2c;
611} 680}
612 681
682void radeon_combios_i2c_init(struct radeon_device *rdev)
683{
684 struct drm_device *dev = rdev->ddev;
685 struct radeon_i2c_bus_rec i2c;
686
687
688 i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
689 rdev->i2c_bus[0] = radeon_i2c_create(dev, &i2c, "DVI_DDC");
690
691 i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
692 rdev->i2c_bus[1] = radeon_i2c_create(dev, &i2c, "VGA_DDC");
693
694 i2c.valid = true;
695 i2c.hw_capable = true;
696 i2c.mm_i2c = true;
697 i2c.i2c_id = 0xa0;
698 rdev->i2c_bus[2] = radeon_i2c_create(dev, &i2c, "MM_I2C");
699
700 if (rdev->family == CHIP_RS300 ||
701 rdev->family == CHIP_RS400 ||
702 rdev->family == CHIP_RS480) {
703 u16 offset;
704 u8 id, blocks, clk, data;
705 int i;
706
707 i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
708 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
709
710 offset = combios_get_table_offset(dev, COMBIOS_I2C_INFO_TABLE);
711 if (offset) {
712 blocks = RBIOS8(offset + 2);
713 for (i = 0; i < blocks; i++) {
714 id = RBIOS8(offset + 3 + (i * 5) + 0);
715 if (id == 136) {
716 clk = RBIOS8(offset + 3 + (i * 5) + 3);
717 data = RBIOS8(offset + 3 + (i * 5) + 4);
718 i2c = combios_setup_i2c_bus(rdev, DDC_MONID,
719 clk, data);
720 rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "GPIOPAD_MASK");
721 break;
722 }
723 }
724 }
725
726 } else if (rdev->family >= CHIP_R300) {
727 i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
728 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
729 } else {
730 i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
731 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
732
733 i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
734 rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "CRT2_DDC");
735 }
736}
737
613bool radeon_combios_get_clock_info(struct drm_device *dev) 738bool radeon_combios_get_clock_info(struct drm_device *dev)
614{ 739{
615 struct radeon_device *rdev = dev->dev_private; 740 struct radeon_device *rdev = dev->dev_private;
@@ -1247,8 +1372,8 @@ bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
1247 struct radeon_i2c_bus_rec i2c_bus; 1372 struct radeon_i2c_bus_rec i2c_bus;
1248 1373
1249 /* default for macs */ 1374 /* default for macs */
1250 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID); 1375 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
1251 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO"); 1376 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1252 1377
1253 /* XXX some macs have duallink chips */ 1378 /* XXX some macs have duallink chips */
1254 switch (rdev->mode_info.connector_table) { 1379 switch (rdev->mode_info.connector_table) {
@@ -1269,47 +1394,16 @@ bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder
1269 struct drm_device *dev = encoder->base.dev; 1394 struct drm_device *dev = encoder->base.dev;
1270 struct radeon_device *rdev = dev->dev_private; 1395 struct radeon_device *rdev = dev->dev_private;
1271 uint16_t offset; 1396 uint16_t offset;
1272 uint8_t ver, id, blocks, clk, data; 1397 uint8_t ver;
1273 int i;
1274 enum radeon_combios_ddc gpio; 1398 enum radeon_combios_ddc gpio;
1275 struct radeon_i2c_bus_rec i2c_bus; 1399 struct radeon_i2c_bus_rec i2c_bus;
1276 1400
1277 tmds->i2c_bus = NULL; 1401 tmds->i2c_bus = NULL;
1278 if (rdev->flags & RADEON_IS_IGP) { 1402 if (rdev->flags & RADEON_IS_IGP) {
1279 offset = combios_get_table_offset(dev, COMBIOS_I2C_INFO_TABLE); 1403 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
1280 if (offset) { 1404 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1281 ver = RBIOS8(offset); 1405 tmds->dvo_chip = DVO_SIL164;
1282 DRM_INFO("GPIO Table revision: %d\n", ver); 1406 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
1283 blocks = RBIOS8(offset + 2);
1284 for (i = 0; i < blocks; i++) {
1285 id = RBIOS8(offset + 3 + (i * 5) + 0);
1286 if (id == 136) {
1287 clk = RBIOS8(offset + 3 + (i * 5) + 3);
1288 data = RBIOS8(offset + 3 + (i * 5) + 4);
1289 i2c_bus.valid = true;
1290 i2c_bus.mask_clk_mask = (1 << clk);
1291 i2c_bus.mask_data_mask = (1 << data);
1292 i2c_bus.a_clk_mask = (1 << clk);
1293 i2c_bus.a_data_mask = (1 << data);
1294 i2c_bus.en_clk_mask = (1 << clk);
1295 i2c_bus.en_data_mask = (1 << data);
1296 i2c_bus.y_clk_mask = (1 << clk);
1297 i2c_bus.y_data_mask = (1 << data);
1298 i2c_bus.mask_clk_reg = RADEON_GPIOPAD_MASK;
1299 i2c_bus.mask_data_reg = RADEON_GPIOPAD_MASK;
1300 i2c_bus.a_clk_reg = RADEON_GPIOPAD_A;
1301 i2c_bus.a_data_reg = RADEON_GPIOPAD_A;
1302 i2c_bus.en_clk_reg = RADEON_GPIOPAD_EN;
1303 i2c_bus.en_data_reg = RADEON_GPIOPAD_EN;
1304 i2c_bus.y_clk_reg = RADEON_GPIOPAD_Y;
1305 i2c_bus.y_data_reg = RADEON_GPIOPAD_Y;
1306 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1307 tmds->dvo_chip = DVO_SIL164;
1308 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
1309 break;
1310 }
1311 }
1312 }
1313 } else { 1407 } else {
1314 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE); 1408 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
1315 if (offset) { 1409 if (offset) {
@@ -1318,37 +1412,15 @@ bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder
1318 tmds->slave_addr = RBIOS8(offset + 4 + 2); 1412 tmds->slave_addr = RBIOS8(offset + 4 + 2);
1319 tmds->slave_addr >>= 1; /* 7 bit addressing */ 1413 tmds->slave_addr >>= 1; /* 7 bit addressing */
1320 gpio = RBIOS8(offset + 4 + 3); 1414 gpio = RBIOS8(offset + 4 + 3);
1321 switch (gpio) { 1415 if (gpio == DDC_LCD) {
1322 case DDC_MONID: 1416 /* MM i2c */
1323 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
1324 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1325 break;
1326 case DDC_DVI:
1327 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
1328 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1329 break;
1330 case DDC_VGA:
1331 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
1332 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1333 break;
1334 case DDC_CRT2:
1335 /* R3xx+ chips don't have GPIO_CRT2_DDC gpio pad */
1336 if (rdev->family >= CHIP_R300)
1337 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
1338 else
1339 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
1340 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1341 break;
1342 case DDC_LCD: /* MM i2c */
1343 i2c_bus.valid = true; 1417 i2c_bus.valid = true;
1344 i2c_bus.hw_capable = true; 1418 i2c_bus.hw_capable = true;
1345 i2c_bus.mm_i2c = true; 1419 i2c_bus.mm_i2c = true;
1346 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO"); 1420 i2c_bus.i2c_id = 0xa0;
1347 break; 1421 } else
1348 default: 1422 i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
1349 DRM_ERROR("Unsupported gpio %d\n", gpio); 1423 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1350 break;
1351 }
1352 } 1424 }
1353 } 1425 }
1354 1426
@@ -1430,7 +1502,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1430 /* these are the most common settings */ 1502 /* these are the most common settings */
1431 if (rdev->flags & RADEON_SINGLE_CRTC) { 1503 if (rdev->flags & RADEON_SINGLE_CRTC) {
1432 /* VGA - primary dac */ 1504 /* VGA - primary dac */
1433 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1505 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1434 hpd.hpd = RADEON_HPD_NONE; 1506 hpd.hpd = RADEON_HPD_NONE;
1435 radeon_add_legacy_encoder(dev, 1507 radeon_add_legacy_encoder(dev,
1436 radeon_get_encoder_id(dev, 1508 radeon_get_encoder_id(dev,
@@ -1445,7 +1517,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1445 &hpd); 1517 &hpd);
1446 } else if (rdev->flags & RADEON_IS_MOBILITY) { 1518 } else if (rdev->flags & RADEON_IS_MOBILITY) {
1447 /* LVDS */ 1519 /* LVDS */
1448 ddc_i2c = combios_setup_i2c_bus(rdev, 0); 1520 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
1449 hpd.hpd = RADEON_HPD_NONE; 1521 hpd.hpd = RADEON_HPD_NONE;
1450 radeon_add_legacy_encoder(dev, 1522 radeon_add_legacy_encoder(dev,
1451 radeon_get_encoder_id(dev, 1523 radeon_get_encoder_id(dev,
@@ -1460,7 +1532,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1460 &hpd); 1532 &hpd);
1461 1533
1462 /* VGA - primary dac */ 1534 /* VGA - primary dac */
1463 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1535 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1464 hpd.hpd = RADEON_HPD_NONE; 1536 hpd.hpd = RADEON_HPD_NONE;
1465 radeon_add_legacy_encoder(dev, 1537 radeon_add_legacy_encoder(dev,
1466 radeon_get_encoder_id(dev, 1538 radeon_get_encoder_id(dev,
@@ -1475,7 +1547,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1475 &hpd); 1547 &hpd);
1476 } else { 1548 } else {
1477 /* DVI-I - tv dac, int tmds */ 1549 /* DVI-I - tv dac, int tmds */
1478 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 1550 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
1479 hpd.hpd = RADEON_HPD_1; 1551 hpd.hpd = RADEON_HPD_1;
1480 radeon_add_legacy_encoder(dev, 1552 radeon_add_legacy_encoder(dev,
1481 radeon_get_encoder_id(dev, 1553 radeon_get_encoder_id(dev,
@@ -1496,7 +1568,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1496 &hpd); 1568 &hpd);
1497 1569
1498 /* VGA - primary dac */ 1570 /* VGA - primary dac */
1499 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1571 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1500 hpd.hpd = RADEON_HPD_NONE; 1572 hpd.hpd = RADEON_HPD_NONE;
1501 radeon_add_legacy_encoder(dev, 1573 radeon_add_legacy_encoder(dev,
1502 radeon_get_encoder_id(dev, 1574 radeon_get_encoder_id(dev,
@@ -1532,7 +1604,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1532 DRM_INFO("Connector Table: %d (ibook)\n", 1604 DRM_INFO("Connector Table: %d (ibook)\n",
1533 rdev->mode_info.connector_table); 1605 rdev->mode_info.connector_table);
1534 /* LVDS */ 1606 /* LVDS */
1535 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 1607 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
1536 hpd.hpd = RADEON_HPD_NONE; 1608 hpd.hpd = RADEON_HPD_NONE;
1537 radeon_add_legacy_encoder(dev, 1609 radeon_add_legacy_encoder(dev,
1538 radeon_get_encoder_id(dev, 1610 radeon_get_encoder_id(dev,
@@ -1544,7 +1616,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1544 CONNECTOR_OBJECT_ID_LVDS, 1616 CONNECTOR_OBJECT_ID_LVDS,
1545 &hpd); 1617 &hpd);
1546 /* VGA - TV DAC */ 1618 /* VGA - TV DAC */
1547 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1619 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1548 hpd.hpd = RADEON_HPD_NONE; 1620 hpd.hpd = RADEON_HPD_NONE;
1549 radeon_add_legacy_encoder(dev, 1621 radeon_add_legacy_encoder(dev,
1550 radeon_get_encoder_id(dev, 1622 radeon_get_encoder_id(dev,
@@ -1573,7 +1645,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1573 DRM_INFO("Connector Table: %d (powerbook external tmds)\n", 1645 DRM_INFO("Connector Table: %d (powerbook external tmds)\n",
1574 rdev->mode_info.connector_table); 1646 rdev->mode_info.connector_table);
1575 /* LVDS */ 1647 /* LVDS */
1576 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 1648 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
1577 hpd.hpd = RADEON_HPD_NONE; 1649 hpd.hpd = RADEON_HPD_NONE;
1578 radeon_add_legacy_encoder(dev, 1650 radeon_add_legacy_encoder(dev,
1579 radeon_get_encoder_id(dev, 1651 radeon_get_encoder_id(dev,
@@ -1585,7 +1657,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1585 CONNECTOR_OBJECT_ID_LVDS, 1657 CONNECTOR_OBJECT_ID_LVDS,
1586 &hpd); 1658 &hpd);
1587 /* DVI-I - primary dac, ext tmds */ 1659 /* DVI-I - primary dac, ext tmds */
1588 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1660 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1589 hpd.hpd = RADEON_HPD_2; /* ??? */ 1661 hpd.hpd = RADEON_HPD_2; /* ??? */
1590 radeon_add_legacy_encoder(dev, 1662 radeon_add_legacy_encoder(dev,
1591 radeon_get_encoder_id(dev, 1663 radeon_get_encoder_id(dev,
@@ -1622,7 +1694,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1622 DRM_INFO("Connector Table: %d (powerbook internal tmds)\n", 1694 DRM_INFO("Connector Table: %d (powerbook internal tmds)\n",
1623 rdev->mode_info.connector_table); 1695 rdev->mode_info.connector_table);
1624 /* LVDS */ 1696 /* LVDS */
1625 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 1697 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
1626 hpd.hpd = RADEON_HPD_NONE; 1698 hpd.hpd = RADEON_HPD_NONE;
1627 radeon_add_legacy_encoder(dev, 1699 radeon_add_legacy_encoder(dev,
1628 radeon_get_encoder_id(dev, 1700 radeon_get_encoder_id(dev,
@@ -1634,7 +1706,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1634 CONNECTOR_OBJECT_ID_LVDS, 1706 CONNECTOR_OBJECT_ID_LVDS,
1635 &hpd); 1707 &hpd);
1636 /* DVI-I - primary dac, int tmds */ 1708 /* DVI-I - primary dac, int tmds */
1637 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1709 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1638 hpd.hpd = RADEON_HPD_1; /* ??? */ 1710 hpd.hpd = RADEON_HPD_1; /* ??? */
1639 radeon_add_legacy_encoder(dev, 1711 radeon_add_legacy_encoder(dev,
1640 radeon_get_encoder_id(dev, 1712 radeon_get_encoder_id(dev,
@@ -1670,7 +1742,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1670 DRM_INFO("Connector Table: %d (powerbook vga)\n", 1742 DRM_INFO("Connector Table: %d (powerbook vga)\n",
1671 rdev->mode_info.connector_table); 1743 rdev->mode_info.connector_table);
1672 /* LVDS */ 1744 /* LVDS */
1673 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 1745 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
1674 hpd.hpd = RADEON_HPD_NONE; 1746 hpd.hpd = RADEON_HPD_NONE;
1675 radeon_add_legacy_encoder(dev, 1747 radeon_add_legacy_encoder(dev,
1676 radeon_get_encoder_id(dev, 1748 radeon_get_encoder_id(dev,
@@ -1682,7 +1754,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1682 CONNECTOR_OBJECT_ID_LVDS, 1754 CONNECTOR_OBJECT_ID_LVDS,
1683 &hpd); 1755 &hpd);
1684 /* VGA - primary dac */ 1756 /* VGA - primary dac */
1685 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1757 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1686 hpd.hpd = RADEON_HPD_NONE; 1758 hpd.hpd = RADEON_HPD_NONE;
1687 radeon_add_legacy_encoder(dev, 1759 radeon_add_legacy_encoder(dev,
1688 radeon_get_encoder_id(dev, 1760 radeon_get_encoder_id(dev,
@@ -1711,7 +1783,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1711 DRM_INFO("Connector Table: %d (mini external tmds)\n", 1783 DRM_INFO("Connector Table: %d (mini external tmds)\n",
1712 rdev->mode_info.connector_table); 1784 rdev->mode_info.connector_table);
1713 /* DVI-I - tv dac, ext tmds */ 1785 /* DVI-I - tv dac, ext tmds */
1714 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC); 1786 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
1715 hpd.hpd = RADEON_HPD_2; /* ??? */ 1787 hpd.hpd = RADEON_HPD_2; /* ??? */
1716 radeon_add_legacy_encoder(dev, 1788 radeon_add_legacy_encoder(dev,
1717 radeon_get_encoder_id(dev, 1789 radeon_get_encoder_id(dev,
@@ -1748,7 +1820,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1748 DRM_INFO("Connector Table: %d (mini internal tmds)\n", 1820 DRM_INFO("Connector Table: %d (mini internal tmds)\n",
1749 rdev->mode_info.connector_table); 1821 rdev->mode_info.connector_table);
1750 /* DVI-I - tv dac, int tmds */ 1822 /* DVI-I - tv dac, int tmds */
1751 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC); 1823 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
1752 hpd.hpd = RADEON_HPD_1; /* ??? */ 1824 hpd.hpd = RADEON_HPD_1; /* ??? */
1753 radeon_add_legacy_encoder(dev, 1825 radeon_add_legacy_encoder(dev,
1754 radeon_get_encoder_id(dev, 1826 radeon_get_encoder_id(dev,
@@ -1784,7 +1856,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1784 DRM_INFO("Connector Table: %d (imac g5 isight)\n", 1856 DRM_INFO("Connector Table: %d (imac g5 isight)\n",
1785 rdev->mode_info.connector_table); 1857 rdev->mode_info.connector_table);
1786 /* DVI-D - int tmds */ 1858 /* DVI-D - int tmds */
1787 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID); 1859 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
1788 hpd.hpd = RADEON_HPD_1; /* ??? */ 1860 hpd.hpd = RADEON_HPD_1; /* ??? */
1789 radeon_add_legacy_encoder(dev, 1861 radeon_add_legacy_encoder(dev,
1790 radeon_get_encoder_id(dev, 1862 radeon_get_encoder_id(dev,
@@ -1796,7 +1868,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1796 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D, 1868 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
1797 &hpd); 1869 &hpd);
1798 /* VGA - tv dac */ 1870 /* VGA - tv dac */
1799 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 1871 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
1800 hpd.hpd = RADEON_HPD_NONE; 1872 hpd.hpd = RADEON_HPD_NONE;
1801 radeon_add_legacy_encoder(dev, 1873 radeon_add_legacy_encoder(dev,
1802 radeon_get_encoder_id(dev, 1874 radeon_get_encoder_id(dev,
@@ -1825,7 +1897,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1825 DRM_INFO("Connector Table: %d (emac)\n", 1897 DRM_INFO("Connector Table: %d (emac)\n",
1826 rdev->mode_info.connector_table); 1898 rdev->mode_info.connector_table);
1827 /* VGA - primary dac */ 1899 /* VGA - primary dac */
1828 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1900 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1829 hpd.hpd = RADEON_HPD_NONE; 1901 hpd.hpd = RADEON_HPD_NONE;
1830 radeon_add_legacy_encoder(dev, 1902 radeon_add_legacy_encoder(dev,
1831 radeon_get_encoder_id(dev, 1903 radeon_get_encoder_id(dev,
@@ -1837,7 +1909,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1837 CONNECTOR_OBJECT_ID_VGA, 1909 CONNECTOR_OBJECT_ID_VGA,
1838 &hpd); 1910 &hpd);
1839 /* VGA - tv dac */ 1911 /* VGA - tv dac */
1840 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC); 1912 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
1841 hpd.hpd = RADEON_HPD_NONE; 1913 hpd.hpd = RADEON_HPD_NONE;
1842 radeon_add_legacy_encoder(dev, 1914 radeon_add_legacy_encoder(dev,
1843 radeon_get_encoder_id(dev, 1915 radeon_get_encoder_id(dev,
@@ -1866,7 +1938,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1866 DRM_INFO("Connector Table: %d (rn50-power)\n", 1938 DRM_INFO("Connector Table: %d (rn50-power)\n",
1867 rdev->mode_info.connector_table); 1939 rdev->mode_info.connector_table);
1868 /* VGA - primary dac */ 1940 /* VGA - primary dac */
1869 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1941 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1870 hpd.hpd = RADEON_HPD_NONE; 1942 hpd.hpd = RADEON_HPD_NONE;
1871 radeon_add_legacy_encoder(dev, 1943 radeon_add_legacy_encoder(dev,
1872 radeon_get_encoder_id(dev, 1944 radeon_get_encoder_id(dev,
@@ -1877,7 +1949,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1877 DRM_MODE_CONNECTOR_VGA, &ddc_i2c, 1949 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
1878 CONNECTOR_OBJECT_ID_VGA, 1950 CONNECTOR_OBJECT_ID_VGA,
1879 &hpd); 1951 &hpd);
1880 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC); 1952 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
1881 hpd.hpd = RADEON_HPD_NONE; 1953 hpd.hpd = RADEON_HPD_NONE;
1882 radeon_add_legacy_encoder(dev, 1954 radeon_add_legacy_encoder(dev,
1883 radeon_get_encoder_id(dev, 1955 radeon_get_encoder_id(dev,
@@ -1907,31 +1979,6 @@ static bool radeon_apply_legacy_quirks(struct drm_device *dev,
1907 struct radeon_i2c_bus_rec *ddc_i2c, 1979 struct radeon_i2c_bus_rec *ddc_i2c,
1908 struct radeon_hpd *hpd) 1980 struct radeon_hpd *hpd)
1909{ 1981{
1910 struct radeon_device *rdev = dev->dev_private;
1911
1912 /* XPRESS DDC quirks */
1913 if ((rdev->family == CHIP_RS400 ||
1914 rdev->family == CHIP_RS480) &&
1915 ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
1916 *ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
1917 else if ((rdev->family == CHIP_RS400 ||
1918 rdev->family == CHIP_RS480) &&
1919 ddc_i2c->mask_clk_reg == RADEON_GPIO_MONID) {
1920 *ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIOPAD_MASK);
1921 ddc_i2c->mask_clk_mask = (0x20 << 8);
1922 ddc_i2c->mask_data_mask = 0x80;
1923 ddc_i2c->a_clk_mask = (0x20 << 8);
1924 ddc_i2c->a_data_mask = 0x80;
1925 ddc_i2c->en_clk_mask = (0x20 << 8);
1926 ddc_i2c->en_data_mask = 0x80;
1927 ddc_i2c->y_clk_mask = (0x20 << 8);
1928 ddc_i2c->y_data_mask = 0x80;
1929 }
1930
1931 /* R3xx+ chips don't have GPIO_CRT2_DDC gpio pad */
1932 if ((rdev->family >= CHIP_R300) &&
1933 ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
1934 *ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
1935 1982
1936 /* Certain IBM chipset RN50s have a BIOS reporting two VGAs, 1983 /* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
1937 one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */ 1984 one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
@@ -2035,27 +2082,7 @@ bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2035 connector = (tmp >> 12) & 0xf; 2082 connector = (tmp >> 12) & 0xf;
2036 2083
2037 ddc_type = (tmp >> 8) & 0xf; 2084 ddc_type = (tmp >> 8) & 0xf;
2038 switch (ddc_type) { 2085 ddc_i2c = combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
2039 case DDC_MONID:
2040 ddc_i2c =
2041 combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
2042 break;
2043 case DDC_DVI:
2044 ddc_i2c =
2045 combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
2046 break;
2047 case DDC_VGA:
2048 ddc_i2c =
2049 combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
2050 break;
2051 case DDC_CRT2:
2052 ddc_i2c =
2053 combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
2054 break;
2055 default:
2056 ddc_i2c.valid = false;
2057 break;
2058 }
2059 2086
2060 switch (connector) { 2087 switch (connector) {
2061 case CONNECTOR_PROPRIETARY_LEGACY: 2088 case CONNECTOR_PROPRIETARY_LEGACY:
@@ -2225,7 +2252,7 @@ bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2225 0), 2252 0),
2226 ATOM_DEVICE_DFP1_SUPPORT); 2253 ATOM_DEVICE_DFP1_SUPPORT);
2227 2254
2228 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 2255 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2229 hpd.hpd = RADEON_HPD_1; 2256 hpd.hpd = RADEON_HPD_1;
2230 radeon_add_legacy_connector(dev, 2257 radeon_add_legacy_connector(dev,
2231 0, 2258 0,
@@ -2245,7 +2272,7 @@ bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2245 ATOM_DEVICE_CRT1_SUPPORT, 2272 ATOM_DEVICE_CRT1_SUPPORT,
2246 1), 2273 1),
2247 ATOM_DEVICE_CRT1_SUPPORT); 2274 ATOM_DEVICE_CRT1_SUPPORT);
2248 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 2275 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
2249 hpd.hpd = RADEON_HPD_NONE; 2276 hpd.hpd = RADEON_HPD_NONE;
2250 radeon_add_legacy_connector(dev, 2277 radeon_add_legacy_connector(dev,
2251 0, 2278 0,
@@ -2278,70 +2305,25 @@ bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2278 if (lcd_ddc_info) { 2305 if (lcd_ddc_info) {
2279 ddc_type = RBIOS8(lcd_ddc_info + 2); 2306 ddc_type = RBIOS8(lcd_ddc_info + 2);
2280 switch (ddc_type) { 2307 switch (ddc_type) {
2281 case DDC_MONID:
2282 ddc_i2c =
2283 combios_setup_i2c_bus
2284 (rdev, RADEON_GPIO_MONID);
2285 break;
2286 case DDC_DVI:
2287 ddc_i2c =
2288 combios_setup_i2c_bus
2289 (rdev, RADEON_GPIO_DVI_DDC);
2290 break;
2291 case DDC_VGA:
2292 ddc_i2c =
2293 combios_setup_i2c_bus
2294 (rdev, RADEON_GPIO_VGA_DDC);
2295 break;
2296 case DDC_CRT2:
2297 ddc_i2c =
2298 combios_setup_i2c_bus
2299 (rdev, RADEON_GPIO_CRT2_DDC);
2300 break;
2301 case DDC_LCD: 2308 case DDC_LCD:
2302 ddc_i2c = 2309 ddc_i2c =
2303 combios_setup_i2c_bus 2310 combios_setup_i2c_bus(rdev,
2304 (rdev, RADEON_GPIOPAD_MASK); 2311 DDC_LCD,
2305 ddc_i2c.mask_clk_mask = 2312 RBIOS32(lcd_ddc_info + 3),
2306 RBIOS32(lcd_ddc_info + 3); 2313 RBIOS32(lcd_ddc_info + 7));
2307 ddc_i2c.mask_data_mask = 2314 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
2308 RBIOS32(lcd_ddc_info + 7);
2309 ddc_i2c.a_clk_mask =
2310 RBIOS32(lcd_ddc_info + 3);
2311 ddc_i2c.a_data_mask =
2312 RBIOS32(lcd_ddc_info + 7);
2313 ddc_i2c.en_clk_mask =
2314 RBIOS32(lcd_ddc_info + 3);
2315 ddc_i2c.en_data_mask =
2316 RBIOS32(lcd_ddc_info + 7);
2317 ddc_i2c.y_clk_mask =
2318 RBIOS32(lcd_ddc_info + 3);
2319 ddc_i2c.y_data_mask =
2320 RBIOS32(lcd_ddc_info + 7);
2321 break; 2315 break;
2322 case DDC_GPIO: 2316 case DDC_GPIO:
2323 ddc_i2c = 2317 ddc_i2c =
2324 combios_setup_i2c_bus 2318 combios_setup_i2c_bus(rdev,
2325 (rdev, RADEON_MDGPIO_MASK); 2319 DDC_GPIO,
2326 ddc_i2c.mask_clk_mask = 2320 RBIOS32(lcd_ddc_info + 3),
2327 RBIOS32(lcd_ddc_info + 3); 2321 RBIOS32(lcd_ddc_info + 7));
2328 ddc_i2c.mask_data_mask = 2322 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
2329 RBIOS32(lcd_ddc_info + 7);
2330 ddc_i2c.a_clk_mask =
2331 RBIOS32(lcd_ddc_info + 3);
2332 ddc_i2c.a_data_mask =
2333 RBIOS32(lcd_ddc_info + 7);
2334 ddc_i2c.en_clk_mask =
2335 RBIOS32(lcd_ddc_info + 3);
2336 ddc_i2c.en_data_mask =
2337 RBIOS32(lcd_ddc_info + 7);
2338 ddc_i2c.y_clk_mask =
2339 RBIOS32(lcd_ddc_info + 3);
2340 ddc_i2c.y_data_mask =
2341 RBIOS32(lcd_ddc_info + 7);
2342 break; 2323 break;
2343 default: 2324 default:
2344 ddc_i2c.valid = false; 2325 ddc_i2c =
2326 combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
2345 break; 2327 break;
2346 } 2328 }
2347 DRM_DEBUG_KMS("LCD DDC Info Table found!\n"); 2329 DRM_DEBUG_KMS("LCD DDC Info Table found!\n");
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index 2395c8600cf4..47c4b276d30c 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -518,8 +518,6 @@ static void radeon_connector_destroy(struct drm_connector *connector)
518{ 518{
519 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 519 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
520 520
521 if (radeon_connector->ddc_bus)
522 radeon_i2c_destroy(radeon_connector->ddc_bus);
523 if (radeon_connector->edid) 521 if (radeon_connector->edid)
524 kfree(radeon_connector->edid); 522 kfree(radeon_connector->edid);
525 kfree(radeon_connector->con_priv); 523 kfree(radeon_connector->con_priv);
@@ -955,8 +953,6 @@ static void radeon_dp_connector_destroy(struct drm_connector *connector)
955 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 953 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
956 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv; 954 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
957 955
958 if (radeon_connector->ddc_bus)
959 radeon_i2c_destroy(radeon_connector->ddc_bus);
960 if (radeon_connector->edid) 956 if (radeon_connector->edid)
961 kfree(radeon_connector->edid); 957 kfree(radeon_connector->edid);
962 if (radeon_dig_connector->dp_i2c_bus) 958 if (radeon_dig_connector->dp_i2c_bus)
@@ -1044,7 +1040,8 @@ radeon_add_atom_connector(struct drm_device *dev,
1044 bool linkb, 1040 bool linkb,
1045 uint32_t igp_lane_info, 1041 uint32_t igp_lane_info,
1046 uint16_t connector_object_id, 1042 uint16_t connector_object_id,
1047 struct radeon_hpd *hpd) 1043 struct radeon_hpd *hpd,
1044 struct radeon_router *router)
1048{ 1045{
1049 struct radeon_device *rdev = dev->dev_private; 1046 struct radeon_device *rdev = dev->dev_private;
1050 struct drm_connector *connector; 1047 struct drm_connector *connector;
@@ -1069,6 +1066,11 @@ radeon_add_atom_connector(struct drm_device *dev,
1069 radeon_connector->shared_ddc = true; 1066 radeon_connector->shared_ddc = true;
1070 shared_ddc = true; 1067 shared_ddc = true;
1071 } 1068 }
1069 if (radeon_connector->router_bus && router->valid &&
1070 (radeon_connector->router.router_id == router->router_id)) {
1071 radeon_connector->shared_ddc = false;
1072 shared_ddc = false;
1073 }
1072 } 1074 }
1073 } 1075 }
1074 1076
@@ -1083,12 +1085,18 @@ radeon_add_atom_connector(struct drm_device *dev,
1083 radeon_connector->shared_ddc = shared_ddc; 1085 radeon_connector->shared_ddc = shared_ddc;
1084 radeon_connector->connector_object_id = connector_object_id; 1086 radeon_connector->connector_object_id = connector_object_id;
1085 radeon_connector->hpd = *hpd; 1087 radeon_connector->hpd = *hpd;
1088 radeon_connector->router = *router;
1089 if (router->valid) {
1090 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1091 if (!radeon_connector->router_bus)
1092 goto failed;
1093 }
1086 switch (connector_type) { 1094 switch (connector_type) {
1087 case DRM_MODE_CONNECTOR_VGA: 1095 case DRM_MODE_CONNECTOR_VGA:
1088 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1096 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1089 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 1097 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1090 if (i2c_bus->valid) { 1098 if (i2c_bus->valid) {
1091 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA"); 1099 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1092 if (!radeon_connector->ddc_bus) 1100 if (!radeon_connector->ddc_bus)
1093 goto failed; 1101 goto failed;
1094 } 1102 }
@@ -1104,7 +1112,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1104 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1112 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1105 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 1113 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1106 if (i2c_bus->valid) { 1114 if (i2c_bus->valid) {
1107 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); 1115 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1108 if (!radeon_connector->ddc_bus) 1116 if (!radeon_connector->ddc_bus)
1109 goto failed; 1117 goto failed;
1110 } 1118 }
@@ -1126,7 +1134,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1126 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type); 1134 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1127 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); 1135 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1128 if (i2c_bus->valid) { 1136 if (i2c_bus->valid) {
1129 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); 1137 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1130 if (!radeon_connector->ddc_bus) 1138 if (!radeon_connector->ddc_bus)
1131 goto failed; 1139 goto failed;
1132 } 1140 }
@@ -1156,7 +1164,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1156 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type); 1164 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1157 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); 1165 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1158 if (i2c_bus->valid) { 1166 if (i2c_bus->valid) {
1159 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI"); 1167 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1160 if (!radeon_connector->ddc_bus) 1168 if (!radeon_connector->ddc_bus)
1161 goto failed; 1169 goto failed;
1162 } 1170 }
@@ -1187,10 +1195,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1187 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch"); 1195 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1188 if (!radeon_dig_connector->dp_i2c_bus) 1196 if (!radeon_dig_connector->dp_i2c_bus)
1189 goto failed; 1197 goto failed;
1190 if (connector_type == DRM_MODE_CONNECTOR_eDP) 1198 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1191 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "eDP");
1192 else
1193 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
1194 if (!radeon_connector->ddc_bus) 1199 if (!radeon_connector->ddc_bus)
1195 goto failed; 1200 goto failed;
1196 } 1201 }
@@ -1230,7 +1235,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1230 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type); 1235 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1231 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs); 1236 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1232 if (i2c_bus->valid) { 1237 if (i2c_bus->valid) {
1233 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS"); 1238 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1234 if (!radeon_connector->ddc_bus) 1239 if (!radeon_connector->ddc_bus)
1235 goto failed; 1240 goto failed;
1236 } 1241 }
@@ -1252,8 +1257,6 @@ radeon_add_atom_connector(struct drm_device *dev,
1252 return; 1257 return;
1253 1258
1254failed: 1259failed:
1255 if (radeon_connector->ddc_bus)
1256 radeon_i2c_destroy(radeon_connector->ddc_bus);
1257 drm_connector_cleanup(connector); 1260 drm_connector_cleanup(connector);
1258 kfree(connector); 1261 kfree(connector);
1259} 1262}
@@ -1300,7 +1303,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
1300 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1303 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1301 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 1304 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1302 if (i2c_bus->valid) { 1305 if (i2c_bus->valid) {
1303 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA"); 1306 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1304 if (!radeon_connector->ddc_bus) 1307 if (!radeon_connector->ddc_bus)
1305 goto failed; 1308 goto failed;
1306 } 1309 }
@@ -1316,7 +1319,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
1316 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1319 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1317 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 1320 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1318 if (i2c_bus->valid) { 1321 if (i2c_bus->valid) {
1319 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); 1322 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1320 if (!radeon_connector->ddc_bus) 1323 if (!radeon_connector->ddc_bus)
1321 goto failed; 1324 goto failed;
1322 } 1325 }
@@ -1332,7 +1335,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
1332 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type); 1335 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1333 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); 1336 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1334 if (i2c_bus->valid) { 1337 if (i2c_bus->valid) {
1335 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); 1338 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1336 if (!radeon_connector->ddc_bus) 1339 if (!radeon_connector->ddc_bus)
1337 goto failed; 1340 goto failed;
1338 } 1341 }
@@ -1372,7 +1375,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
1372 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type); 1375 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1373 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs); 1376 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1374 if (i2c_bus->valid) { 1377 if (i2c_bus->valid) {
1375 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS"); 1378 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1376 if (!radeon_connector->ddc_bus) 1379 if (!radeon_connector->ddc_bus)
1377 goto failed; 1380 goto failed;
1378 } 1381 }
@@ -1393,8 +1396,6 @@ radeon_add_legacy_connector(struct drm_device *dev,
1393 return; 1396 return;
1394 1397
1395failed: 1398failed:
1396 if (radeon_connector->ddc_bus)
1397 radeon_i2c_destroy(radeon_connector->ddc_bus);
1398 drm_connector_cleanup(connector); 1399 drm_connector_cleanup(connector);
1399 kfree(connector); 1400 kfree(connector);
1400} 1401}
diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index ae0fb7356e62..fcc79b5d22d1 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -72,7 +72,7 @@ int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
72 if (p->relocs[i].gobj == NULL) { 72 if (p->relocs[i].gobj == NULL) {
73 DRM_ERROR("gem object lookup failed 0x%x\n", 73 DRM_ERROR("gem object lookup failed 0x%x\n",
74 r->handle); 74 r->handle);
75 return -EINVAL; 75 return -ENOENT;
76 } 76 }
77 p->relocs_ptr[i] = &p->relocs[i]; 77 p->relocs_ptr[i] = &p->relocs[i];
78 p->relocs[i].robj = p->relocs[i].gobj->driver_private; 78 p->relocs[i].robj = p->relocs[i].gobj->driver_private;
diff --git a/drivers/gpu/drm/radeon/radeon_cursor.c b/drivers/gpu/drm/radeon/radeon_cursor.c
index 4eb67c0e0996..5731fc9b1ae3 100644
--- a/drivers/gpu/drm/radeon/radeon_cursor.c
+++ b/drivers/gpu/drm/radeon/radeon_cursor.c
@@ -170,7 +170,7 @@ int radeon_crtc_cursor_set(struct drm_crtc *crtc,
170 obj = drm_gem_object_lookup(crtc->dev, file_priv, handle); 170 obj = drm_gem_object_lookup(crtc->dev, file_priv, handle);
171 if (!obj) { 171 if (!obj) {
172 DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, radeon_crtc->crtc_id); 172 DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, radeon_crtc->crtc_id);
173 return -EINVAL; 173 return -ENOENT;
174 } 174 }
175 175
176 ret = radeon_gem_object_pin(obj, RADEON_GEM_DOMAIN_VRAM, &gpu_addr); 176 ret = radeon_gem_object_pin(obj, RADEON_GEM_DOMAIN_VRAM, &gpu_addr);
diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index a64811a94519..4f7a170d1566 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -347,7 +347,8 @@ int radeon_dummy_page_init(struct radeon_device *rdev)
347 return -ENOMEM; 347 return -ENOMEM;
348 rdev->dummy_page.addr = pci_map_page(rdev->pdev, rdev->dummy_page.page, 348 rdev->dummy_page.addr = pci_map_page(rdev->pdev, rdev->dummy_page.page,
349 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 349 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
350 if (!rdev->dummy_page.addr) { 350 if (pci_dma_mapping_error(rdev->pdev, rdev->dummy_page.addr)) {
351 dev_err(&rdev->pdev->dev, "Failed to DMA MAP the dummy page\n");
351 __free_page(rdev->dummy_page.page); 352 __free_page(rdev->dummy_page.page);
352 rdev->dummy_page.page = NULL; 353 rdev->dummy_page.page = NULL;
353 return -ENOMEM; 354 return -ENOMEM;
diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index 74dac9635d70..5764f4d3b4f1 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -161,17 +161,13 @@ void radeon_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
161} 161}
162 162
163static void radeon_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, 163static void radeon_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
164 u16 *blue, uint32_t size) 164 u16 *blue, uint32_t start, uint32_t size)
165{ 165{
166 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 166 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
167 int i; 167 int end = (start + size > 256) ? 256 : start + size, i;
168
169 if (size != 256) {
170 return;
171 }
172 168
173 /* userspace palettes are always correct as is */ 169 /* userspace palettes are always correct as is */
174 for (i = 0; i < 256; i++) { 170 for (i = start; i < end; i++) {
175 radeon_crtc->lut_r[i] = red[i] >> 6; 171 radeon_crtc->lut_r[i] = red[i] >> 6;
176 radeon_crtc->lut_g[i] = green[i] >> 6; 172 radeon_crtc->lut_g[i] = green[i] >> 6;
177 radeon_crtc->lut_b[i] = blue[i] >> 6; 173 radeon_crtc->lut_b[i] = blue[i] >> 6;
@@ -319,6 +315,10 @@ static void radeon_print_display_setup(struct drm_device *dev)
319 radeon_connector->ddc_bus->rec.en_data_reg, 315 radeon_connector->ddc_bus->rec.en_data_reg,
320 radeon_connector->ddc_bus->rec.y_clk_reg, 316 radeon_connector->ddc_bus->rec.y_clk_reg,
321 radeon_connector->ddc_bus->rec.y_data_reg); 317 radeon_connector->ddc_bus->rec.y_data_reg);
318 if (radeon_connector->router_bus)
319 DRM_INFO(" DDC Router 0x%x/0x%x\n",
320 radeon_connector->router.mux_control_pin,
321 radeon_connector->router.mux_state);
322 } else { 322 } else {
323 if (connector->connector_type == DRM_MODE_CONNECTOR_VGA || 323 if (connector->connector_type == DRM_MODE_CONNECTOR_VGA ||
324 connector->connector_type == DRM_MODE_CONNECTOR_DVII || 324 connector->connector_type == DRM_MODE_CONNECTOR_DVII ||
@@ -395,6 +395,10 @@ int radeon_ddc_get_modes(struct radeon_connector *radeon_connector)
395 struct radeon_device *rdev = dev->dev_private; 395 struct radeon_device *rdev = dev->dev_private;
396 int ret = 0; 396 int ret = 0;
397 397
398 /* on hw with routers, select right port */
399 if (radeon_connector->router.valid)
400 radeon_router_select_port(radeon_connector);
401
398 if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) || 402 if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
399 (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)) { 403 (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)) {
400 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv; 404 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
@@ -425,6 +429,10 @@ static int radeon_ddc_dump(struct drm_connector *connector)
425 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 429 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
426 int ret = 0; 430 int ret = 0;
427 431
432 /* on hw with routers, select right port */
433 if (radeon_connector->router.valid)
434 radeon_router_select_port(radeon_connector);
435
428 if (!radeon_connector->ddc_bus) 436 if (!radeon_connector->ddc_bus)
429 return -1; 437 return -1;
430 edid = drm_get_edid(connector, &radeon_connector->ddc_bus->adapter); 438 edid = drm_get_edid(connector, &radeon_connector->ddc_bus->adapter);
@@ -876,13 +884,12 @@ radeon_user_framebuffer_create(struct drm_device *dev,
876 if (obj == NULL) { 884 if (obj == NULL) {
877 dev_err(&dev->pdev->dev, "No GEM object associated to handle 0x%08X, " 885 dev_err(&dev->pdev->dev, "No GEM object associated to handle 0x%08X, "
878 "can't create framebuffer\n", mode_cmd->handle); 886 "can't create framebuffer\n", mode_cmd->handle);
879 return NULL; 887 return ERR_PTR(-ENOENT);
880 } 888 }
881 889
882 radeon_fb = kzalloc(sizeof(*radeon_fb), GFP_KERNEL); 890 radeon_fb = kzalloc(sizeof(*radeon_fb), GFP_KERNEL);
883 if (radeon_fb == NULL) { 891 if (radeon_fb == NULL)
884 return NULL; 892 return ERR_PTR(-ENOMEM);
885 }
886 893
887 radeon_framebuffer_init(dev, radeon_fb, mode_cmd, obj); 894 radeon_framebuffer_init(dev, radeon_fb, mode_cmd, obj);
888 895
@@ -1040,6 +1047,9 @@ int radeon_modeset_init(struct radeon_device *rdev)
1040 return ret; 1047 return ret;
1041 } 1048 }
1042 1049
1050 /* init i2c buses */
1051 radeon_i2c_init(rdev);
1052
1043 /* check combios for a valid hardcoded EDID - Sun servers */ 1053 /* check combios for a valid hardcoded EDID - Sun servers */
1044 if (!rdev->is_atom_bios) { 1054 if (!rdev->is_atom_bios) {
1045 /* check for hardcoded EDID in BIOS */ 1055 /* check for hardcoded EDID in BIOS */
@@ -1080,6 +1090,8 @@ void radeon_modeset_fini(struct radeon_device *rdev)
1080 drm_mode_config_cleanup(rdev->ddev); 1090 drm_mode_config_cleanup(rdev->ddev);
1081 rdev->mode_info.mode_config_initialized = false; 1091 rdev->mode_info.mode_config_initialized = false;
1082 } 1092 }
1093 /* free i2c buses */
1094 radeon_i2c_fini(rdev);
1083} 1095}
1084 1096
1085bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc, 1097bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc,
diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
index a72a3ee5d69b..c578f265b24c 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -226,7 +226,7 @@ int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
226 /* just do a BO wait for now */ 226 /* just do a BO wait for now */
227 gobj = drm_gem_object_lookup(dev, filp, args->handle); 227 gobj = drm_gem_object_lookup(dev, filp, args->handle);
228 if (gobj == NULL) { 228 if (gobj == NULL) {
229 return -EINVAL; 229 return -ENOENT;
230 } 230 }
231 robj = gobj->driver_private; 231 robj = gobj->driver_private;
232 232
@@ -245,7 +245,7 @@ int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
245 245
246 gobj = drm_gem_object_lookup(dev, filp, args->handle); 246 gobj = drm_gem_object_lookup(dev, filp, args->handle);
247 if (gobj == NULL) { 247 if (gobj == NULL) {
248 return -EINVAL; 248 return -ENOENT;
249 } 249 }
250 robj = gobj->driver_private; 250 robj = gobj->driver_private;
251 args->addr_ptr = radeon_bo_mmap_offset(robj); 251 args->addr_ptr = radeon_bo_mmap_offset(robj);
@@ -264,7 +264,7 @@ int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
264 264
265 gobj = drm_gem_object_lookup(dev, filp, args->handle); 265 gobj = drm_gem_object_lookup(dev, filp, args->handle);
266 if (gobj == NULL) { 266 if (gobj == NULL) {
267 return -EINVAL; 267 return -ENOENT;
268 } 268 }
269 robj = gobj->driver_private; 269 robj = gobj->driver_private;
270 r = radeon_bo_wait(robj, &cur_placement, true); 270 r = radeon_bo_wait(robj, &cur_placement, true);
@@ -294,7 +294,7 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
294 294
295 gobj = drm_gem_object_lookup(dev, filp, args->handle); 295 gobj = drm_gem_object_lookup(dev, filp, args->handle);
296 if (gobj == NULL) { 296 if (gobj == NULL) {
297 return -EINVAL; 297 return -ENOENT;
298 } 298 }
299 robj = gobj->driver_private; 299 robj = gobj->driver_private;
300 r = radeon_bo_wait(robj, NULL, false); 300 r = radeon_bo_wait(robj, NULL, false);
@@ -316,7 +316,7 @@ int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
316 DRM_DEBUG("%d \n", args->handle); 316 DRM_DEBUG("%d \n", args->handle);
317 gobj = drm_gem_object_lookup(dev, filp, args->handle); 317 gobj = drm_gem_object_lookup(dev, filp, args->handle);
318 if (gobj == NULL) 318 if (gobj == NULL)
319 return -EINVAL; 319 return -ENOENT;
320 robj = gobj->driver_private; 320 robj = gobj->driver_private;
321 r = radeon_bo_set_tiling_flags(robj, args->tiling_flags, args->pitch); 321 r = radeon_bo_set_tiling_flags(robj, args->tiling_flags, args->pitch);
322 drm_gem_object_unreference_unlocked(gobj); 322 drm_gem_object_unreference_unlocked(gobj);
@@ -334,7 +334,7 @@ int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
334 DRM_DEBUG("\n"); 334 DRM_DEBUG("\n");
335 gobj = drm_gem_object_lookup(dev, filp, args->handle); 335 gobj = drm_gem_object_lookup(dev, filp, args->handle);
336 if (gobj == NULL) 336 if (gobj == NULL)
337 return -EINVAL; 337 return -ENOENT;
338 rbo = gobj->driver_private; 338 rbo = gobj->driver_private;
339 r = radeon_bo_reserve(rbo, false); 339 r = radeon_bo_reserve(rbo, false);
340 if (unlikely(r != 0)) 340 if (unlikely(r != 0))
diff --git a/drivers/gpu/drm/radeon/radeon_i2c.c b/drivers/gpu/drm/radeon/radeon_i2c.c
index 5def6f5dff38..bfd2ce5f5372 100644
--- a/drivers/gpu/drm/radeon/radeon_i2c.c
+++ b/drivers/gpu/drm/radeon/radeon_i2c.c
@@ -52,6 +52,10 @@ bool radeon_ddc_probe(struct radeon_connector *radeon_connector)
52 } 52 }
53 }; 53 };
54 54
55 /* on hw with routers, select right port */
56 if (radeon_connector->router.valid)
57 radeon_router_select_port(radeon_connector);
58
55 ret = i2c_transfer(&radeon_connector->ddc_bus->adapter, msgs, 2); 59 ret = i2c_transfer(&radeon_connector->ddc_bus->adapter, msgs, 2);
56 if (ret == 2) 60 if (ret == 2)
57 return true; 61 return true;
@@ -960,6 +964,59 @@ void radeon_i2c_destroy(struct radeon_i2c_chan *i2c)
960 kfree(i2c); 964 kfree(i2c);
961} 965}
962 966
967/* Add the default buses */
968void radeon_i2c_init(struct radeon_device *rdev)
969{
970 if (rdev->is_atom_bios)
971 radeon_atombios_i2c_init(rdev);
972 else
973 radeon_combios_i2c_init(rdev);
974}
975
976/* remove all the buses */
977void radeon_i2c_fini(struct radeon_device *rdev)
978{
979 int i;
980
981 for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
982 if (rdev->i2c_bus[i]) {
983 radeon_i2c_destroy(rdev->i2c_bus[i]);
984 rdev->i2c_bus[i] = NULL;
985 }
986 }
987}
988
989/* Add additional buses */
990void radeon_i2c_add(struct radeon_device *rdev,
991 struct radeon_i2c_bus_rec *rec,
992 const char *name)
993{
994 struct drm_device *dev = rdev->ddev;
995 int i;
996
997 for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
998 if (!rdev->i2c_bus[i]) {
999 rdev->i2c_bus[i] = radeon_i2c_create(dev, rec, name);
1000 return;
1001 }
1002 }
1003}
1004
1005/* looks up bus based on id */
1006struct radeon_i2c_chan *radeon_i2c_lookup(struct radeon_device *rdev,
1007 struct radeon_i2c_bus_rec *i2c_bus)
1008{
1009 int i;
1010
1011 for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
1012 if (rdev->i2c_bus[i] &&
1013 (rdev->i2c_bus[i]->rec.i2c_id == i2c_bus->i2c_id)) {
1014 return rdev->i2c_bus[i];
1015 }
1016 }
1017 return NULL;
1018}
1019
963struct drm_encoder *radeon_best_encoder(struct drm_connector *connector) 1020struct drm_encoder *radeon_best_encoder(struct drm_connector *connector)
964{ 1021{
965 return NULL; 1022 return NULL;
@@ -1020,3 +1077,28 @@ void radeon_i2c_put_byte(struct radeon_i2c_chan *i2c_bus,
1020 addr, val); 1077 addr, val);
1021} 1078}
1022 1079
1080/* router switching */
1081void radeon_router_select_port(struct radeon_connector *radeon_connector)
1082{
1083 u8 val;
1084
1085 if (!radeon_connector->router.valid)
1086 return;
1087
1088 radeon_i2c_get_byte(radeon_connector->router_bus,
1089 radeon_connector->router.i2c_addr,
1090 0x3, &val);
1091 val &= radeon_connector->router.mux_control_pin;
1092 radeon_i2c_put_byte(radeon_connector->router_bus,
1093 radeon_connector->router.i2c_addr,
1094 0x3, val);
1095 radeon_i2c_get_byte(radeon_connector->router_bus,
1096 radeon_connector->router.i2c_addr,
1097 0x1, &val);
1098 val &= radeon_connector->router.mux_control_pin;
1099 val |= radeon_connector->router.mux_state;
1100 radeon_i2c_put_byte(radeon_connector->router_bus,
1101 radeon_connector->router.i2c_addr,
1102 0x1, val);
1103}
1104
diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c
index ddcd3b13f151..b1c8ace5f080 100644
--- a/drivers/gpu/drm/radeon/radeon_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_kms.c
@@ -112,7 +112,9 @@ int radeon_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
112 112
113 info = data; 113 info = data;
114 value_ptr = (uint32_t *)((unsigned long)info->value); 114 value_ptr = (uint32_t *)((unsigned long)info->value);
115 value = *value_ptr; 115 if (DRM_COPY_FROM_USER(&value, value_ptr, sizeof(value)))
116 return -EFAULT;
117
116 switch (info->request) { 118 switch (info->request) {
117 case RADEON_INFO_DEVICE_ID: 119 case RADEON_INFO_DEVICE_ID:
118 value = dev->pci_device; 120 value = dev->pci_device;
@@ -160,13 +162,27 @@ int radeon_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
160 return -EINVAL; 162 return -EINVAL;
161 } 163 }
162 case RADEON_INFO_WANT_HYPERZ: 164 case RADEON_INFO_WANT_HYPERZ:
165 /* The "value" here is both an input and output parameter.
166 * If the input value is 1, filp requests hyper-z access.
167 * If the input value is 0, filp revokes its hyper-z access.
168 *
169 * When returning, the value is 1 if filp owns hyper-z access,
170 * 0 otherwise. */
171 if (value >= 2) {
172 DRM_DEBUG_KMS("WANT_HYPERZ: invalid value %d\n", value);
173 return -EINVAL;
174 }
163 mutex_lock(&dev->struct_mutex); 175 mutex_lock(&dev->struct_mutex);
164 if (rdev->hyperz_filp) 176 if (value == 1) {
165 value = 0; 177 /* wants hyper-z */
166 else { 178 if (!rdev->hyperz_filp)
167 rdev->hyperz_filp = filp; 179 rdev->hyperz_filp = filp;
168 value = 1; 180 } else if (value == 0) {
181 /* revokes hyper-z */
182 if (rdev->hyperz_filp == filp)
183 rdev->hyperz_filp = NULL;
169 } 184 }
185 value = rdev->hyperz_filp == filp ? 1 : 0;
170 mutex_unlock(&dev->struct_mutex); 186 mutex_unlock(&dev->struct_mutex);
171 break; 187 break;
172 default: 188 default:
diff --git a/drivers/gpu/drm/radeon/radeon_mode.h b/drivers/gpu/drm/radeon/radeon_mode.h
index 71aea4037e90..5bbc086b9267 100644
--- a/drivers/gpu/drm/radeon/radeon_mode.h
+++ b/drivers/gpu/drm/radeon/radeon_mode.h
@@ -82,6 +82,8 @@ enum radeon_hpd_id {
82 RADEON_HPD_NONE = 0xff, 82 RADEON_HPD_NONE = 0xff,
83}; 83};
84 84
85#define RADEON_MAX_I2C_BUS 16
86
85/* radeon gpio-based i2c 87/* radeon gpio-based i2c
86 * 1. "mask" reg and bits 88 * 1. "mask" reg and bits
87 * grabs the gpio pins for software use 89 * grabs the gpio pins for software use
@@ -398,6 +400,16 @@ struct radeon_hpd {
398 struct radeon_gpio_rec gpio; 400 struct radeon_gpio_rec gpio;
399}; 401};
400 402
403struct radeon_router {
404 bool valid;
405 u32 router_id;
406 struct radeon_i2c_bus_rec i2c_info;
407 u8 i2c_addr;
408 u8 mux_type;
409 u8 mux_control_pin;
410 u8 mux_state;
411};
412
401struct radeon_connector { 413struct radeon_connector {
402 struct drm_connector base; 414 struct drm_connector base;
403 uint32_t connector_id; 415 uint32_t connector_id;
@@ -413,6 +425,8 @@ struct radeon_connector {
413 bool dac_load_detect; 425 bool dac_load_detect;
414 uint16_t connector_object_id; 426 uint16_t connector_object_id;
415 struct radeon_hpd hpd; 427 struct radeon_hpd hpd;
428 struct radeon_router router;
429 struct radeon_i2c_chan *router_bus;
416}; 430};
417 431
418struct radeon_framebuffer { 432struct radeon_framebuffer {
@@ -445,6 +459,15 @@ extern void atombios_dig_transmitter_setup(struct drm_encoder *encoder,
445extern int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, 459extern int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
446 uint8_t write_byte, uint8_t *read_byte); 460 uint8_t write_byte, uint8_t *read_byte);
447 461
462extern void radeon_i2c_init(struct radeon_device *rdev);
463extern void radeon_i2c_fini(struct radeon_device *rdev);
464extern void radeon_combios_i2c_init(struct radeon_device *rdev);
465extern void radeon_atombios_i2c_init(struct radeon_device *rdev);
466extern void radeon_i2c_add(struct radeon_device *rdev,
467 struct radeon_i2c_bus_rec *rec,
468 const char *name);
469extern struct radeon_i2c_chan *radeon_i2c_lookup(struct radeon_device *rdev,
470 struct radeon_i2c_bus_rec *i2c_bus);
448extern struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev, 471extern struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev,
449 struct radeon_i2c_bus_rec *rec, 472 struct radeon_i2c_bus_rec *rec,
450 const char *name); 473 const char *name);
@@ -460,6 +483,7 @@ extern void radeon_i2c_put_byte(struct radeon_i2c_chan *i2c,
460 u8 slave_addr, 483 u8 slave_addr,
461 u8 addr, 484 u8 addr,
462 u8 val); 485 u8 val);
486extern void radeon_router_select_port(struct radeon_connector *radeon_connector);
463extern bool radeon_ddc_probe(struct radeon_connector *radeon_connector); 487extern bool radeon_ddc_probe(struct radeon_connector *radeon_connector);
464extern int radeon_ddc_get_modes(struct radeon_connector *radeon_connector); 488extern int radeon_ddc_get_modes(struct radeon_connector *radeon_connector);
465 489
diff --git a/drivers/gpu/drm/radeon/radeon_pm.c b/drivers/gpu/drm/radeon/radeon_pm.c
index 95f8b3a3c43d..58038f5cab38 100644
--- a/drivers/gpu/drm/radeon/radeon_pm.c
+++ b/drivers/gpu/drm/radeon/radeon_pm.c
@@ -472,9 +472,9 @@ static const struct attribute_group hwmon_attrgroup = {
472 .attrs = hwmon_attributes, 472 .attrs = hwmon_attributes,
473}; 473};
474 474
475static void radeon_hwmon_init(struct radeon_device *rdev) 475static int radeon_hwmon_init(struct radeon_device *rdev)
476{ 476{
477 int err; 477 int err = 0;
478 478
479 rdev->pm.int_hwmon_dev = NULL; 479 rdev->pm.int_hwmon_dev = NULL;
480 480
@@ -483,15 +483,26 @@ static void radeon_hwmon_init(struct radeon_device *rdev)
483 case THERMAL_TYPE_RV770: 483 case THERMAL_TYPE_RV770:
484 case THERMAL_TYPE_EVERGREEN: 484 case THERMAL_TYPE_EVERGREEN:
485 rdev->pm.int_hwmon_dev = hwmon_device_register(rdev->dev); 485 rdev->pm.int_hwmon_dev = hwmon_device_register(rdev->dev);
486 if (IS_ERR(rdev->pm.int_hwmon_dev)) {
487 err = PTR_ERR(rdev->pm.int_hwmon_dev);
488 dev_err(rdev->dev,
489 "Unable to register hwmon device: %d\n", err);
490 break;
491 }
486 dev_set_drvdata(rdev->pm.int_hwmon_dev, rdev->ddev); 492 dev_set_drvdata(rdev->pm.int_hwmon_dev, rdev->ddev);
487 err = sysfs_create_group(&rdev->pm.int_hwmon_dev->kobj, 493 err = sysfs_create_group(&rdev->pm.int_hwmon_dev->kobj,
488 &hwmon_attrgroup); 494 &hwmon_attrgroup);
489 if (err) 495 if (err) {
490 DRM_ERROR("Unable to create hwmon sysfs file: %d\n", err); 496 dev_err(rdev->dev,
497 "Unable to create hwmon sysfs file: %d\n", err);
498 hwmon_device_unregister(rdev->dev);
499 }
491 break; 500 break;
492 default: 501 default:
493 break; 502 break;
494 } 503 }
504
505 return err;
495} 506}
496 507
497static void radeon_hwmon_fini(struct radeon_device *rdev) 508static void radeon_hwmon_fini(struct radeon_device *rdev)
@@ -540,6 +551,7 @@ void radeon_pm_resume(struct radeon_device *rdev)
540int radeon_pm_init(struct radeon_device *rdev) 551int radeon_pm_init(struct radeon_device *rdev)
541{ 552{
542 int ret; 553 int ret;
554
543 /* default to profile method */ 555 /* default to profile method */
544 rdev->pm.pm_method = PM_METHOD_PROFILE; 556 rdev->pm.pm_method = PM_METHOD_PROFILE;
545 rdev->pm.profile = PM_PROFILE_DEFAULT; 557 rdev->pm.profile = PM_PROFILE_DEFAULT;
@@ -561,7 +573,9 @@ int radeon_pm_init(struct radeon_device *rdev)
561 } 573 }
562 574
563 /* set up the internal thermal sensor if applicable */ 575 /* set up the internal thermal sensor if applicable */
564 radeon_hwmon_init(rdev); 576 ret = radeon_hwmon_init(rdev);
577 if (ret)
578 return ret;
565 if (rdev->pm.num_power_states > 1) { 579 if (rdev->pm.num_power_states > 1) {
566 /* where's the best place to put these? */ 580 /* where's the best place to put these? */
567 ret = device_create_file(rdev->dev, &dev_attr_power_profile); 581 ret = device_create_file(rdev->dev, &dev_attr_power_profile);
diff --git a/drivers/gpu/drm/radeon/reg_srcs/rv515 b/drivers/gpu/drm/radeon/reg_srcs/rv515
index 8293855f5f0d..b3f9f1d92005 100644
--- a/drivers/gpu/drm/radeon/reg_srcs/rv515
+++ b/drivers/gpu/drm/radeon/reg_srcs/rv515
@@ -316,6 +316,7 @@ rv515 0x6d40
3160x4BD0 FG_FOG_COLOR_B 3160x4BD0 FG_FOG_COLOR_B
3170x4BD4 FG_ALPHA_FUNC 3170x4BD4 FG_ALPHA_FUNC
3180x4BD8 FG_DEPTH_SRC 3180x4BD8 FG_DEPTH_SRC
3190x4BE0 FG_ALPHA_VALUE
3190x4C00 US_ALU_CONST_R_0 3200x4C00 US_ALU_CONST_R_0
3200x4C04 US_ALU_CONST_G_0 3210x4C04 US_ALU_CONST_G_0
3210x4C08 US_ALU_CONST_B_0 3220x4C08 US_ALU_CONST_B_0
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 437ac786277a..64d7f47df868 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -737,7 +737,7 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
737 737
738 if (ret) { 738 if (ret) {
739 DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret); 739 DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret);
740 return NULL; 740 return ERR_PTR(ret);
741 } 741 }
742 return &vfb->base; 742 return &vfb->base;
743 743
@@ -747,7 +747,7 @@ try_dmabuf:
747 ret = vmw_user_dmabuf_lookup(tfile, mode_cmd->handle, &bo); 747 ret = vmw_user_dmabuf_lookup(tfile, mode_cmd->handle, &bo);
748 if (ret) { 748 if (ret) {
749 DRM_ERROR("failed to find buffer: %i\n", ret); 749 DRM_ERROR("failed to find buffer: %i\n", ret);
750 return NULL; 750 return ERR_PTR(-ENOENT);
751 } 751 }
752 752
753 ret = vmw_kms_new_framebuffer_dmabuf(dev_priv, bo, &vfb, 753 ret = vmw_kms_new_framebuffer_dmabuf(dev_priv, bo, &vfb,
@@ -758,7 +758,7 @@ try_dmabuf:
758 758
759 if (ret) { 759 if (ret) {
760 DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret); 760 DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret);
761 return NULL; 761 return ERR_PTR(ret);
762 } 762 }
763 763
764 return &vfb->base; 764 return &vfb->base;
@@ -768,7 +768,7 @@ err_not_scanout:
768 /* vmw_user_surface_lookup takes one ref */ 768 /* vmw_user_surface_lookup takes one ref */
769 vmw_surface_unreference(&surface); 769 vmw_surface_unreference(&surface);
770 770
771 return NULL; 771 return ERR_PTR(-EINVAL);
772} 772}
773 773
774static struct drm_mode_config_funcs vmw_kms_funcs = { 774static struct drm_mode_config_funcs vmw_kms_funcs = {
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
index cfaf690a5b2f..2ff5cf78235f 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
@@ -79,7 +79,7 @@ static void vmw_ldu_crtc_restore(struct drm_crtc *crtc)
79 79
80static void vmw_ldu_crtc_gamma_set(struct drm_crtc *crtc, 80static void vmw_ldu_crtc_gamma_set(struct drm_crtc *crtc,
81 u16 *r, u16 *g, u16 *b, 81 u16 *r, u16 *g, u16 *b,
82 uint32_t size) 82 uint32_t start, uint32_t size)
83{ 83{
84} 84}
85 85
diff --git a/drivers/hwmon/ams/ams.h b/drivers/hwmon/ams/ams.h
index b28d7e27a031..90f094d45450 100644
--- a/drivers/hwmon/ams/ams.h
+++ b/drivers/hwmon/ams/ams.h
@@ -23,7 +23,7 @@ struct ams {
23 23
24 /* General properties */ 24 /* General properties */
25 struct device_node *of_node; 25 struct device_node *of_node;
26 struct of_device *of_dev; 26 struct platform_device *of_dev;
27 char has_device; 27 char has_device;
28 char vflag; 28 char vflag;
29 u32 orient1; 29 u32 orient1;
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index a92e28a35767..c070c9714cbe 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -501,13 +501,10 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
501 501
502 switch (action) { 502 switch (action) {
503 case CPU_ONLINE: 503 case CPU_ONLINE:
504 case CPU_ONLINE_FROZEN:
505 case CPU_DOWN_FAILED: 504 case CPU_DOWN_FAILED:
506 case CPU_DOWN_FAILED_FROZEN:
507 coretemp_device_add(cpu); 505 coretemp_device_add(cpu);
508 break; 506 break;
509 case CPU_DOWN_PREPARE: 507 case CPU_DOWN_PREPARE:
510 case CPU_DOWN_PREPARE_FROZEN:
511 coretemp_device_remove(cpu); 508 coretemp_device_remove(cpu);
512 break; 509 break;
513 } 510 }
diff --git a/drivers/hwmon/mc13783-adc.c b/drivers/hwmon/mc13783-adc.c
index ce3c7bc81814..d5226c9e1201 100644
--- a/drivers/hwmon/mc13783-adc.c
+++ b/drivers/hwmon/mc13783-adc.c
@@ -18,7 +18,7 @@
18 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 19 */
20 20
21#include <linux/mfd/mc13783-private.h> 21#include <linux/mfd/mc13783.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/hwmon-sysfs.h> 23#include <linux/hwmon-sysfs.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
@@ -144,6 +144,14 @@ static const struct attribute_group mc13783_group_ts = {
144 .attrs = mc13783_attr_ts, 144 .attrs = mc13783_attr_ts,
145}; 145};
146 146
147static int mc13783_adc_use_touchscreen(struct platform_device *pdev)
148{
149 struct mc13783_adc_priv *priv = platform_get_drvdata(pdev);
150 unsigned flags = mc13783_get_flags(priv->mc13783);
151
152 return flags & MC13783_USE_TOUCHSCREEN;
153}
154
147static int __init mc13783_adc_probe(struct platform_device *pdev) 155static int __init mc13783_adc_probe(struct platform_device *pdev)
148{ 156{
149 struct mc13783_adc_priv *priv; 157 struct mc13783_adc_priv *priv;
@@ -162,10 +170,11 @@ static int __init mc13783_adc_probe(struct platform_device *pdev)
162 if (ret) 170 if (ret)
163 goto out_err_create1; 171 goto out_err_create1;
164 172
165 if (!(priv->mc13783->flags & MC13783_USE_TOUCHSCREEN)) 173 if (!mc13783_adc_use_touchscreen(pdev)) {
166 ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group_ts); 174 ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group_ts);
167 if (ret) 175 if (ret)
168 goto out_err_create2; 176 goto out_err_create2;
177 }
169 178
170 priv->hwmon_dev = hwmon_device_register(&pdev->dev); 179 priv->hwmon_dev = hwmon_device_register(&pdev->dev);
171 if (IS_ERR(priv->hwmon_dev)) { 180 if (IS_ERR(priv->hwmon_dev)) {
@@ -180,7 +189,7 @@ static int __init mc13783_adc_probe(struct platform_device *pdev)
180 189
181out_err_register: 190out_err_register:
182 191
183 if (!(priv->mc13783->flags & MC13783_USE_TOUCHSCREEN)) 192 if (!mc13783_adc_use_touchscreen(pdev))
184 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts); 193 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts);
185out_err_create2: 194out_err_create2:
186 195
@@ -199,7 +208,7 @@ static int __devexit mc13783_adc_remove(struct platform_device *pdev)
199 208
200 hwmon_device_unregister(priv->hwmon_dev); 209 hwmon_device_unregister(priv->hwmon_dev);
201 210
202 if (!(priv->mc13783->flags & MC13783_USE_TOUCHSCREEN)) 211 if (!mc13783_adc_use_touchscreen(pdev))
203 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts); 212 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts);
204 213
205 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group); 214 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group);
diff --git a/drivers/hwmon/ultra45_env.c b/drivers/hwmon/ultra45_env.c
index 89643261ccdb..d863e13a50b8 100644
--- a/drivers/hwmon/ultra45_env.c
+++ b/drivers/hwmon/ultra45_env.c
@@ -234,7 +234,7 @@ static const struct attribute_group env_group = {
234 .attrs = env_attributes, 234 .attrs = env_attributes,
235}; 235};
236 236
237static int __devinit env_probe(struct of_device *op, 237static int __devinit env_probe(struct platform_device *op,
238 const struct of_device_id *match) 238 const struct of_device_id *match)
239{ 239{
240 struct env *p = kzalloc(sizeof(*p), GFP_KERNEL); 240 struct env *p = kzalloc(sizeof(*p), GFP_KERNEL);
@@ -276,7 +276,7 @@ out_free:
276 goto out; 276 goto out;
277} 277}
278 278
279static int __devexit env_remove(struct of_device *op) 279static int __devexit env_remove(struct platform_device *op)
280{ 280{
281 struct env *p = dev_get_drvdata(&op->dev); 281 struct env *p = dev_get_drvdata(&op->dev);
282 282
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index d06083fdffbb..30f06e956bfb 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -47,6 +47,19 @@ config I2C_CHARDEV
47 This support is also available as a module. If so, the module 47 This support is also available as a module. If so, the module
48 will be called i2c-dev. 48 will be called i2c-dev.
49 49
50config I2C_MUX
51 tristate "I2C bus multiplexing support"
52 depends on EXPERIMENTAL
53 help
54 Say Y here if you want the I2C core to support the ability to
55 handle multiplexed I2C bus topologies, by presenting each
56 multiplexed segment as a I2C adapter.
57
58 This support is also available as a module. If so, the module
59 will be called i2c-mux.
60
61source drivers/i2c/muxes/Kconfig
62
50config I2C_HELPER_AUTO 63config I2C_HELPER_AUTO
51 bool "Autoselect pertinent helper modules" 64 bool "Autoselect pertinent helper modules"
52 default y 65 default y
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index a7d9b4be9bb3..c00fd66388f5 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -6,7 +6,8 @@ obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o
6obj-$(CONFIG_I2C) += i2c-core.o 6obj-$(CONFIG_I2C) += i2c-core.o
7obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o 7obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o
8obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o 8obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o
9obj-y += algos/ busses/ 9obj-$(CONFIG_I2C_MUX) += i2c-mux.o
10obj-y += algos/ busses/ muxes/
10 11
11ifeq ($(CONFIG_I2C_DEBUG_CORE),y) 12ifeq ($(CONFIG_I2C_DEBUG_CORE),y)
12EXTRA_CFLAGS += -DDEBUG 13EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index bceafbfa7268..15a9702e2941 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -521,12 +521,19 @@ config I2C_PXA_SLAVE
521 is necessary for systems where the PXA may be a target on the 521 is necessary for systems where the PXA may be a target on the
522 I2C bus. 522 I2C bus.
523 523
524config HAVE_S3C2410_I2C
525 bool
526 help
527 This will include I2C support for Samsung SoCs. If you want to
528 include I2C support for any machine, kindly select this in the
529 respective Kconfig file.
530
524config I2C_S3C2410 531config I2C_S3C2410
525 tristate "S3C2410 I2C Driver" 532 tristate "S3C2410 I2C Driver"
526 depends on ARCH_S3C2410 || ARCH_S3C64XX 533 depends on HAVE_S3C2410_I2C
527 help 534 help
528 Say Y here to include support for I2C controller in the 535 Say Y here to include support for I2C controller in the
529 Samsung S3C2410 based System-on-Chip devices. 536 Samsung SoCs.
530 537
531config I2C_S6000 538config I2C_S6000
532 tristate "S6000 I2C support" 539 tristate "S6000 I2C support"
@@ -549,7 +556,7 @@ config I2C_SH7760
549 556
550config I2C_SH_MOBILE 557config I2C_SH_MOBILE
551 tristate "SuperH Mobile I2C Controller" 558 tristate "SuperH Mobile I2C Controller"
552 depends on SUPERH 559 depends on SUPERH || ARCH_SHMOBILE
553 help 560 help
554 If you say yes to this option, support will be included for the 561 If you say yes to this option, support will be included for the
555 built-in I2C interface on the Renesas SH-Mobile processor. 562 built-in I2C interface on the Renesas SH-Mobile processor.
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index e591de1bc704..f7bd2613cecc 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -105,7 +105,7 @@ struct i2c_reg {
105 105
106struct cpm_i2c { 106struct cpm_i2c {
107 char *base; 107 char *base;
108 struct of_device *ofdev; 108 struct platform_device *ofdev;
109 struct i2c_adapter adap; 109 struct i2c_adapter adap;
110 uint dp_addr; 110 uint dp_addr;
111 int version; /* CPM1=1, CPM2=2 */ 111 int version; /* CPM1=1, CPM2=2 */
@@ -428,7 +428,7 @@ static const struct i2c_adapter cpm_ops = {
428 428
429static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm) 429static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm)
430{ 430{
431 struct of_device *ofdev = cpm->ofdev; 431 struct platform_device *ofdev = cpm->ofdev;
432 const u32 *data; 432 const u32 *data;
433 int len, ret, i; 433 int len, ret, i;
434 void __iomem *i2c_base; 434 void __iomem *i2c_base;
@@ -634,7 +634,7 @@ static void cpm_i2c_shutdown(struct cpm_i2c *cpm)
634 cpm_muram_free(cpm->i2c_addr); 634 cpm_muram_free(cpm->i2c_addr);
635} 635}
636 636
637static int __devinit cpm_i2c_probe(struct of_device *ofdev, 637static int __devinit cpm_i2c_probe(struct platform_device *ofdev,
638 const struct of_device_id *match) 638 const struct of_device_id *match)
639{ 639{
640 int result, len; 640 int result, len;
@@ -687,7 +687,7 @@ out_free:
687 return result; 687 return result;
688} 688}
689 689
690static int __devexit cpm_i2c_remove(struct of_device *ofdev) 690static int __devexit cpm_i2c_remove(struct platform_device *ofdev)
691{ 691{
692 struct cpm_i2c *cpm = dev_get_drvdata(&ofdev->dev); 692 struct cpm_i2c *cpm = dev_get_drvdata(&ofdev->dev);
693 693
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 1168d61418c9..43ca32fddde2 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -661,7 +661,7 @@ static inline u8 iic_clckdiv(unsigned int opb)
661 return (u8)((opb + 9) / 10 - 1); 661 return (u8)((opb + 9) / 10 - 1);
662} 662}
663 663
664static int __devinit iic_request_irq(struct of_device *ofdev, 664static int __devinit iic_request_irq(struct platform_device *ofdev,
665 struct ibm_iic_private *dev) 665 struct ibm_iic_private *dev)
666{ 666{
667 struct device_node *np = ofdev->dev.of_node; 667 struct device_node *np = ofdev->dev.of_node;
@@ -692,7 +692,7 @@ static int __devinit iic_request_irq(struct of_device *ofdev,
692/* 692/*
693 * Register single IIC interface 693 * Register single IIC interface
694 */ 694 */
695static int __devinit iic_probe(struct of_device *ofdev, 695static int __devinit iic_probe(struct platform_device *ofdev,
696 const struct of_device_id *match) 696 const struct of_device_id *match)
697{ 697{
698 struct device_node *np = ofdev->dev.of_node; 698 struct device_node *np = ofdev->dev.of_node;
@@ -780,7 +780,7 @@ error_cleanup:
780/* 780/*
781 * Cleanup initialized IIC interface 781 * Cleanup initialized IIC interface
782 */ 782 */
783static int __devexit iic_remove(struct of_device *ofdev) 783static int __devexit iic_remove(struct platform_device *ofdev)
784{ 784{
785 struct ibm_iic_private *dev = dev_get_drvdata(&ofdev->dev); 785 struct ibm_iic_private *dev = dev_get_drvdata(&ofdev->dev);
786 786
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 6545d1c99b61..a1c419a716af 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -560,7 +560,7 @@ static struct i2c_adapter mpc_ops = {
560 .timeout = HZ, 560 .timeout = HZ,
561}; 561};
562 562
563static int __devinit fsl_i2c_probe(struct of_device *op, 563static int __devinit fsl_i2c_probe(struct platform_device *op,
564 const struct of_device_id *match) 564 const struct of_device_id *match)
565{ 565{
566 struct mpc_i2c *i2c; 566 struct mpc_i2c *i2c;
@@ -646,7 +646,7 @@ static int __devinit fsl_i2c_probe(struct of_device *op,
646 return result; 646 return result;
647}; 647};
648 648
649static int __devexit fsl_i2c_remove(struct of_device *op) 649static int __devexit fsl_i2c_remove(struct platform_device *op)
650{ 650{
651 struct mpc_i2c *i2c = dev_get_drvdata(&op->dev); 651 struct mpc_i2c *i2c = dev_get_drvdata(&op->dev);
652 652
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index ffb405d7c6f2..598c49acaeb5 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -119,8 +119,10 @@ struct sh_mobile_i2c_data {
119 struct i2c_adapter adap; 119 struct i2c_adapter adap;
120 120
121 struct clk *clk; 121 struct clk *clk;
122 u_int8_t icic;
122 u_int8_t iccl; 123 u_int8_t iccl;
123 u_int8_t icch; 124 u_int8_t icch;
125 u_int8_t flags;
124 126
125 spinlock_t lock; 127 spinlock_t lock;
126 wait_queue_head_t wait; 128 wait_queue_head_t wait;
@@ -129,15 +131,17 @@ struct sh_mobile_i2c_data {
129 int sr; 131 int sr;
130}; 132};
131 133
134#define IIC_FLAG_HAS_ICIC67 (1 << 0)
135
132#define NORMAL_SPEED 100000 /* FAST_SPEED 400000 */ 136#define NORMAL_SPEED 100000 /* FAST_SPEED 400000 */
133 137
134/* Register offsets */ 138/* Register offsets */
135#define ICDR(pd) (pd->reg + 0x00) 139#define ICDR 0x00
136#define ICCR(pd) (pd->reg + 0x04) 140#define ICCR 0x04
137#define ICSR(pd) (pd->reg + 0x08) 141#define ICSR 0x08
138#define ICIC(pd) (pd->reg + 0x0c) 142#define ICIC 0x0c
139#define ICCL(pd) (pd->reg + 0x10) 143#define ICCL 0x10
140#define ICCH(pd) (pd->reg + 0x14) 144#define ICCH 0x14
141 145
142/* Register bits */ 146/* Register bits */
143#define ICCR_ICE 0x80 147#define ICCR_ICE 0x80
@@ -155,11 +159,32 @@ struct sh_mobile_i2c_data {
155#define ICSR_WAIT 0x02 159#define ICSR_WAIT 0x02
156#define ICSR_DTE 0x01 160#define ICSR_DTE 0x01
157 161
162#define ICIC_ICCLB8 0x80
163#define ICIC_ICCHB8 0x40
158#define ICIC_ALE 0x08 164#define ICIC_ALE 0x08
159#define ICIC_TACKE 0x04 165#define ICIC_TACKE 0x04
160#define ICIC_WAITE 0x02 166#define ICIC_WAITE 0x02
161#define ICIC_DTEE 0x01 167#define ICIC_DTEE 0x01
162 168
169static void iic_wr(struct sh_mobile_i2c_data *pd, int offs, unsigned char data)
170{
171 if (offs == ICIC)
172 data |= pd->icic;
173
174 iowrite8(data, pd->reg + offs);
175}
176
177static unsigned char iic_rd(struct sh_mobile_i2c_data *pd, int offs)
178{
179 return ioread8(pd->reg + offs);
180}
181
182static void iic_set_clr(struct sh_mobile_i2c_data *pd, int offs,
183 unsigned char set, unsigned char clr)
184{
185 iic_wr(pd, offs, (iic_rd(pd, offs) | set) & ~clr);
186}
187
163static void activate_ch(struct sh_mobile_i2c_data *pd) 188static void activate_ch(struct sh_mobile_i2c_data *pd)
164{ 189{
165 unsigned long i2c_clk; 190 unsigned long i2c_clk;
@@ -187,6 +212,14 @@ static void activate_ch(struct sh_mobile_i2c_data *pd)
187 else 212 else
188 pd->iccl = (u_int8_t)(num/denom); 213 pd->iccl = (u_int8_t)(num/denom);
189 214
215 /* one more bit of ICCL in ICIC */
216 if (pd->flags & IIC_FLAG_HAS_ICIC67) {
217 if ((num/denom) > 0xff)
218 pd->icic |= ICIC_ICCLB8;
219 else
220 pd->icic &= ~ICIC_ICCLB8;
221 }
222
190 /* Calculate the value for icch. From the data sheet: 223 /* Calculate the value for icch. From the data sheet:
191 icch = (p clock / transfer rate) * (H / (L + H)) */ 224 icch = (p clock / transfer rate) * (H / (L + H)) */
192 num = i2c_clk * 4; 225 num = i2c_clk * 4;
@@ -196,25 +229,33 @@ static void activate_ch(struct sh_mobile_i2c_data *pd)
196 else 229 else
197 pd->icch = (u_int8_t)(num/denom); 230 pd->icch = (u_int8_t)(num/denom);
198 231
232 /* one more bit of ICCH in ICIC */
233 if (pd->flags & IIC_FLAG_HAS_ICIC67) {
234 if ((num/denom) > 0xff)
235 pd->icic |= ICIC_ICCHB8;
236 else
237 pd->icic &= ~ICIC_ICCHB8;
238 }
239
199 /* Enable channel and configure rx ack */ 240 /* Enable channel and configure rx ack */
200 iowrite8(ioread8(ICCR(pd)) | ICCR_ICE, ICCR(pd)); 241 iic_set_clr(pd, ICCR, ICCR_ICE, 0);
201 242
202 /* Mask all interrupts */ 243 /* Mask all interrupts */
203 iowrite8(0, ICIC(pd)); 244 iic_wr(pd, ICIC, 0);
204 245
205 /* Set the clock */ 246 /* Set the clock */
206 iowrite8(pd->iccl, ICCL(pd)); 247 iic_wr(pd, ICCL, pd->iccl);
207 iowrite8(pd->icch, ICCH(pd)); 248 iic_wr(pd, ICCH, pd->icch);
208} 249}
209 250
210static void deactivate_ch(struct sh_mobile_i2c_data *pd) 251static void deactivate_ch(struct sh_mobile_i2c_data *pd)
211{ 252{
212 /* Clear/disable interrupts */ 253 /* Clear/disable interrupts */
213 iowrite8(0, ICSR(pd)); 254 iic_wr(pd, ICSR, 0);
214 iowrite8(0, ICIC(pd)); 255 iic_wr(pd, ICIC, 0);
215 256
216 /* Disable channel */ 257 /* Disable channel */
217 iowrite8(ioread8(ICCR(pd)) & ~ICCR_ICE, ICCR(pd)); 258 iic_set_clr(pd, ICCR, 0, ICCR_ICE);
218 259
219 /* Disable clock and mark device as idle */ 260 /* Disable clock and mark device as idle */
220 clk_disable(pd->clk); 261 clk_disable(pd->clk);
@@ -233,35 +274,35 @@ static unsigned char i2c_op(struct sh_mobile_i2c_data *pd,
233 274
234 switch (op) { 275 switch (op) {
235 case OP_START: /* issue start and trigger DTE interrupt */ 276 case OP_START: /* issue start and trigger DTE interrupt */
236 iowrite8(0x94, ICCR(pd)); 277 iic_wr(pd, ICCR, 0x94);
237 break; 278 break;
238 case OP_TX_FIRST: /* disable DTE interrupt and write data */ 279 case OP_TX_FIRST: /* disable DTE interrupt and write data */
239 iowrite8(ICIC_WAITE | ICIC_ALE | ICIC_TACKE, ICIC(pd)); 280 iic_wr(pd, ICIC, ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
240 iowrite8(data, ICDR(pd)); 281 iic_wr(pd, ICDR, data);
241 break; 282 break;
242 case OP_TX: /* write data */ 283 case OP_TX: /* write data */
243 iowrite8(data, ICDR(pd)); 284 iic_wr(pd, ICDR, data);
244 break; 285 break;
245 case OP_TX_STOP: /* write data and issue a stop afterwards */ 286 case OP_TX_STOP: /* write data and issue a stop afterwards */
246 iowrite8(data, ICDR(pd)); 287 iic_wr(pd, ICDR, data);
247 iowrite8(0x90, ICCR(pd)); 288 iic_wr(pd, ICCR, 0x90);
248 break; 289 break;
249 case OP_TX_TO_RX: /* select read mode */ 290 case OP_TX_TO_RX: /* select read mode */
250 iowrite8(0x81, ICCR(pd)); 291 iic_wr(pd, ICCR, 0x81);
251 break; 292 break;
252 case OP_RX: /* just read data */ 293 case OP_RX: /* just read data */
253 ret = ioread8(ICDR(pd)); 294 ret = iic_rd(pd, ICDR);
254 break; 295 break;
255 case OP_RX_STOP: /* enable DTE interrupt, issue stop */ 296 case OP_RX_STOP: /* enable DTE interrupt, issue stop */
256 iowrite8(ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE, 297 iic_wr(pd, ICIC,
257 ICIC(pd)); 298 ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
258 iowrite8(0xc0, ICCR(pd)); 299 iic_wr(pd, ICCR, 0xc0);
259 break; 300 break;
260 case OP_RX_STOP_DATA: /* enable DTE interrupt, read data, issue stop */ 301 case OP_RX_STOP_DATA: /* enable DTE interrupt, read data, issue stop */
261 iowrite8(ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE, 302 iic_wr(pd, ICIC,
262 ICIC(pd)); 303 ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
263 ret = ioread8(ICDR(pd)); 304 ret = iic_rd(pd, ICDR);
264 iowrite8(0xc0, ICCR(pd)); 305 iic_wr(pd, ICCR, 0xc0);
265 break; 306 break;
266 } 307 }
267 308
@@ -367,7 +408,7 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
367 unsigned char sr; 408 unsigned char sr;
368 int wakeup; 409 int wakeup;
369 410
370 sr = ioread8(ICSR(pd)); 411 sr = iic_rd(pd, ICSR);
371 pd->sr |= sr; /* remember state */ 412 pd->sr |= sr; /* remember state */
372 413
373 dev_dbg(pd->dev, "i2c_isr 0x%02x 0x%02x %s %d %d!\n", sr, pd->sr, 414 dev_dbg(pd->dev, "i2c_isr 0x%02x 0x%02x %s %d %d!\n", sr, pd->sr,
@@ -376,7 +417,7 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
376 417
377 if (sr & (ICSR_AL | ICSR_TACK)) { 418 if (sr & (ICSR_AL | ICSR_TACK)) {
378 /* don't interrupt transaction - continue to issue stop */ 419 /* don't interrupt transaction - continue to issue stop */
379 iowrite8(sr & ~(ICSR_AL | ICSR_TACK), ICSR(pd)); 420 iic_wr(pd, ICSR, sr & ~(ICSR_AL | ICSR_TACK));
380 wakeup = 0; 421 wakeup = 0;
381 } else if (pd->msg->flags & I2C_M_RD) 422 } else if (pd->msg->flags & I2C_M_RD)
382 wakeup = sh_mobile_i2c_isr_rx(pd); 423 wakeup = sh_mobile_i2c_isr_rx(pd);
@@ -384,7 +425,7 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
384 wakeup = sh_mobile_i2c_isr_tx(pd); 425 wakeup = sh_mobile_i2c_isr_tx(pd);
385 426
386 if (sr & ICSR_WAIT) /* TODO: add delay here to support slow acks */ 427 if (sr & ICSR_WAIT) /* TODO: add delay here to support slow acks */
387 iowrite8(sr & ~ICSR_WAIT, ICSR(pd)); 428 iic_wr(pd, ICSR, sr & ~ICSR_WAIT);
388 429
389 if (wakeup) { 430 if (wakeup) {
390 pd->sr |= SW_DONE; 431 pd->sr |= SW_DONE;
@@ -402,21 +443,21 @@ static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg)
402 } 443 }
403 444
404 /* Initialize channel registers */ 445 /* Initialize channel registers */
405 iowrite8(ioread8(ICCR(pd)) & ~ICCR_ICE, ICCR(pd)); 446 iic_set_clr(pd, ICCR, 0, ICCR_ICE);
406 447
407 /* Enable channel and configure rx ack */ 448 /* Enable channel and configure rx ack */
408 iowrite8(ioread8(ICCR(pd)) | ICCR_ICE, ICCR(pd)); 449 iic_set_clr(pd, ICCR, ICCR_ICE, 0);
409 450
410 /* Set the clock */ 451 /* Set the clock */
411 iowrite8(pd->iccl, ICCL(pd)); 452 iic_wr(pd, ICCL, pd->iccl);
412 iowrite8(pd->icch, ICCH(pd)); 453 iic_wr(pd, ICCH, pd->icch);
413 454
414 pd->msg = usr_msg; 455 pd->msg = usr_msg;
415 pd->pos = -1; 456 pd->pos = -1;
416 pd->sr = 0; 457 pd->sr = 0;
417 458
418 /* Enable all interrupts to begin with */ 459 /* Enable all interrupts to begin with */
419 iowrite8(ICIC_WAITE | ICIC_ALE | ICIC_TACKE | ICIC_DTEE, ICIC(pd)); 460 iic_wr(pd, ICIC, ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
420 return 0; 461 return 0;
421} 462}
422 463
@@ -451,7 +492,7 @@ static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
451 492
452 retry_count = 1000; 493 retry_count = 1000;
453again: 494again:
454 val = ioread8(ICSR(pd)); 495 val = iic_rd(pd, ICSR);
455 496
456 dev_dbg(pd->dev, "val 0x%02x pd->sr 0x%02x\n", val, pd->sr); 497 dev_dbg(pd->dev, "val 0x%02x pd->sr 0x%02x\n", val, pd->sr);
457 498
@@ -576,6 +617,12 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
576 goto err_irq; 617 goto err_irq;
577 } 618 }
578 619
620 /* The IIC blocks on SH-Mobile ARM processors
621 * come with two new bits in ICIC.
622 */
623 if (size > 0x17)
624 pd->flags |= IIC_FLAG_HAS_ICIC67;
625
579 /* Enable Runtime PM for this device. 626 /* Enable Runtime PM for this device.
580 * 627 *
581 * Also tell the Runtime PM core to ignore children 628 * Also tell the Runtime PM core to ignore children
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index df937df845eb..6649176de940 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -20,7 +20,9 @@
20/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>. 20/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>.
21 All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> 21 All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
22 SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and 22 SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and
23 Jean Delvare <khali@linux-fr.org> */ 23 Jean Delvare <khali@linux-fr.org>
24 Mux support by Rodolfo Giometti <giometti@enneenne.com> and
25 Michael Lawnick <michael.lawnick.ext@nsn.com> */
24 26
25#include <linux/module.h> 27#include <linux/module.h>
26#include <linux/kernel.h> 28#include <linux/kernel.h>
@@ -423,11 +425,87 @@ static int __i2c_check_addr_busy(struct device *dev, void *addrp)
423 return 0; 425 return 0;
424} 426}
425 427
428/* walk up mux tree */
429static int i2c_check_mux_parents(struct i2c_adapter *adapter, int addr)
430{
431 int result;
432
433 result = device_for_each_child(&adapter->dev, &addr,
434 __i2c_check_addr_busy);
435
436 if (!result && i2c_parent_is_i2c_adapter(adapter))
437 result = i2c_check_mux_parents(
438 to_i2c_adapter(adapter->dev.parent), addr);
439
440 return result;
441}
442
443/* recurse down mux tree */
444static int i2c_check_mux_children(struct device *dev, void *addrp)
445{
446 int result;
447
448 if (dev->type == &i2c_adapter_type)
449 result = device_for_each_child(dev, addrp,
450 i2c_check_mux_children);
451 else
452 result = __i2c_check_addr_busy(dev, addrp);
453
454 return result;
455}
456
426static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) 457static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr)
427{ 458{
428 return device_for_each_child(&adapter->dev, &addr, 459 int result = 0;
429 __i2c_check_addr_busy); 460
461 if (i2c_parent_is_i2c_adapter(adapter))
462 result = i2c_check_mux_parents(
463 to_i2c_adapter(adapter->dev.parent), addr);
464
465 if (!result)
466 result = device_for_each_child(&adapter->dev, &addr,
467 i2c_check_mux_children);
468
469 return result;
470}
471
472/**
473 * i2c_lock_adapter - Get exclusive access to an I2C bus segment
474 * @adapter: Target I2C bus segment
475 */
476void i2c_lock_adapter(struct i2c_adapter *adapter)
477{
478 if (i2c_parent_is_i2c_adapter(adapter))
479 i2c_lock_adapter(to_i2c_adapter(adapter->dev.parent));
480 else
481 rt_mutex_lock(&adapter->bus_lock);
482}
483EXPORT_SYMBOL_GPL(i2c_lock_adapter);
484
485/**
486 * i2c_trylock_adapter - Try to get exclusive access to an I2C bus segment
487 * @adapter: Target I2C bus segment
488 */
489static int i2c_trylock_adapter(struct i2c_adapter *adapter)
490{
491 if (i2c_parent_is_i2c_adapter(adapter))
492 return i2c_trylock_adapter(to_i2c_adapter(adapter->dev.parent));
493 else
494 return rt_mutex_trylock(&adapter->bus_lock);
495}
496
497/**
498 * i2c_unlock_adapter - Release exclusive access to an I2C bus segment
499 * @adapter: Target I2C bus segment
500 */
501void i2c_unlock_adapter(struct i2c_adapter *adapter)
502{
503 if (i2c_parent_is_i2c_adapter(adapter))
504 i2c_unlock_adapter(to_i2c_adapter(adapter->dev.parent));
505 else
506 rt_mutex_unlock(&adapter->bus_lock);
430} 507}
508EXPORT_SYMBOL_GPL(i2c_unlock_adapter);
431 509
432/** 510/**
433 * i2c_new_device - instantiate an i2c device 511 * i2c_new_device - instantiate an i2c device
@@ -633,9 +711,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
633 return -EINVAL; 711 return -EINVAL;
634 712
635 /* Keep track of the added device */ 713 /* Keep track of the added device */
636 i2c_lock_adapter(adap); 714 mutex_lock(&adap->userspace_clients_lock);
637 list_add_tail(&client->detected, &adap->userspace_clients); 715 list_add_tail(&client->detected, &adap->userspace_clients);
638 i2c_unlock_adapter(adap); 716 mutex_unlock(&adap->userspace_clients_lock);
639 dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device", 717 dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device",
640 info.type, info.addr); 718 info.type, info.addr);
641 719
@@ -674,7 +752,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
674 752
675 /* Make sure the device was added through sysfs */ 753 /* Make sure the device was added through sysfs */
676 res = -ENOENT; 754 res = -ENOENT;
677 i2c_lock_adapter(adap); 755 mutex_lock(&adap->userspace_clients_lock);
678 list_for_each_entry_safe(client, next, &adap->userspace_clients, 756 list_for_each_entry_safe(client, next, &adap->userspace_clients,
679 detected) { 757 detected) {
680 if (client->addr == addr) { 758 if (client->addr == addr) {
@@ -687,7 +765,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
687 break; 765 break;
688 } 766 }
689 } 767 }
690 i2c_unlock_adapter(adap); 768 mutex_unlock(&adap->userspace_clients_lock);
691 769
692 if (res < 0) 770 if (res < 0)
693 dev_err(dev, "%s: Can't find device in list\n", 771 dev_err(dev, "%s: Can't find device in list\n",
@@ -714,10 +792,11 @@ static const struct attribute_group *i2c_adapter_attr_groups[] = {
714 NULL 792 NULL
715}; 793};
716 794
717static struct device_type i2c_adapter_type = { 795struct device_type i2c_adapter_type = {
718 .groups = i2c_adapter_attr_groups, 796 .groups = i2c_adapter_attr_groups,
719 .release = i2c_adapter_dev_release, 797 .release = i2c_adapter_dev_release,
720}; 798};
799EXPORT_SYMBOL_GPL(i2c_adapter_type);
721 800
722#ifdef CONFIG_I2C_COMPAT 801#ifdef CONFIG_I2C_COMPAT
723static struct class_compat *i2c_adapter_compat_class; 802static struct class_compat *i2c_adapter_compat_class;
@@ -760,7 +839,7 @@ static int __process_new_adapter(struct device_driver *d, void *data)
760 839
761static int i2c_register_adapter(struct i2c_adapter *adap) 840static int i2c_register_adapter(struct i2c_adapter *adap)
762{ 841{
763 int res = 0, dummy; 842 int res = 0;
764 843
765 /* Can't register until after driver model init */ 844 /* Can't register until after driver model init */
766 if (unlikely(WARN_ON(!i2c_bus_type.p))) { 845 if (unlikely(WARN_ON(!i2c_bus_type.p))) {
@@ -769,6 +848,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
769 } 848 }
770 849
771 rt_mutex_init(&adap->bus_lock); 850 rt_mutex_init(&adap->bus_lock);
851 mutex_init(&adap->userspace_clients_lock);
772 INIT_LIST_HEAD(&adap->userspace_clients); 852 INIT_LIST_HEAD(&adap->userspace_clients);
773 853
774 /* Set default timeout to 1 second if not already set */ 854 /* Set default timeout to 1 second if not already set */
@@ -801,8 +881,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
801 881
802 /* Notify drivers */ 882 /* Notify drivers */
803 mutex_lock(&core_lock); 883 mutex_lock(&core_lock);
804 dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap, 884 bus_for_each_drv(&i2c_bus_type, NULL, adap, __process_new_adapter);
805 __process_new_adapter);
806 mutex_unlock(&core_lock); 885 mutex_unlock(&core_lock);
807 886
808 return 0; 887 return 0;
@@ -975,7 +1054,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
975 return res; 1054 return res;
976 1055
977 /* Remove devices instantiated from sysfs */ 1056 /* Remove devices instantiated from sysfs */
978 i2c_lock_adapter(adap); 1057 mutex_lock(&adap->userspace_clients_lock);
979 list_for_each_entry_safe(client, next, &adap->userspace_clients, 1058 list_for_each_entry_safe(client, next, &adap->userspace_clients,
980 detected) { 1059 detected) {
981 dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name, 1060 dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name,
@@ -983,7 +1062,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
983 list_del(&client->detected); 1062 list_del(&client->detected);
984 i2c_unregister_device(client); 1063 i2c_unregister_device(client);
985 } 1064 }
986 i2c_unlock_adapter(adap); 1065 mutex_unlock(&adap->userspace_clients_lock);
987 1066
988 /* Detach any active clients. This can't fail, thus we do not 1067 /* Detach any active clients. This can't fail, thus we do not
989 checking the returned value. */ 1068 checking the returned value. */
@@ -1238,12 +1317,12 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1238#endif 1317#endif
1239 1318
1240 if (in_atomic() || irqs_disabled()) { 1319 if (in_atomic() || irqs_disabled()) {
1241 ret = rt_mutex_trylock(&adap->bus_lock); 1320 ret = i2c_trylock_adapter(adap);
1242 if (!ret) 1321 if (!ret)
1243 /* I2C activity is ongoing. */ 1322 /* I2C activity is ongoing. */
1244 return -EAGAIN; 1323 return -EAGAIN;
1245 } else { 1324 } else {
1246 rt_mutex_lock(&adap->bus_lock); 1325 i2c_lock_adapter(adap);
1247 } 1326 }
1248 1327
1249 /* Retry automatically on arbitration loss */ 1328 /* Retry automatically on arbitration loss */
@@ -1255,7 +1334,7 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1255 if (time_after(jiffies, orig_jiffies + adap->timeout)) 1334 if (time_after(jiffies, orig_jiffies + adap->timeout))
1256 break; 1335 break;
1257 } 1336 }
1258 rt_mutex_unlock(&adap->bus_lock); 1337 i2c_unlock_adapter(adap);
1259 1338
1260 return ret; 1339 return ret;
1261 } else { 1340 } else {
@@ -1350,13 +1429,17 @@ static int i2c_default_probe(struct i2c_adapter *adap, unsigned short addr)
1350 I2C_SMBUS_BYTE_DATA, &dummy); 1429 I2C_SMBUS_BYTE_DATA, &dummy);
1351 else 1430 else
1352#endif 1431#endif
1353 if ((addr & ~0x07) == 0x30 || (addr & ~0x0f) == 0x50 1432 if (!((addr & ~0x07) == 0x30 || (addr & ~0x0f) == 0x50)
1354 || !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) 1433 && i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK))
1355 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0,
1356 I2C_SMBUS_BYTE, &dummy);
1357 else
1358 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_WRITE, 0, 1434 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_WRITE, 0,
1359 I2C_SMBUS_QUICK, NULL); 1435 I2C_SMBUS_QUICK, NULL);
1436 else if (i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE))
1437 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0,
1438 I2C_SMBUS_BYTE, &dummy);
1439 else {
1440 dev_warn(&adap->dev, "No suitable probing method supported\n");
1441 err = -EOPNOTSUPP;
1442 }
1360 1443
1361 return err >= 0; 1444 return err >= 0;
1362} 1445}
@@ -1437,16 +1520,6 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
1437 if (!(adapter->class & driver->class)) 1520 if (!(adapter->class & driver->class))
1438 goto exit_free; 1521 goto exit_free;
1439 1522
1440 /* Stop here if the bus doesn't support probing */
1441 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE)) {
1442 if (address_list[0] == I2C_CLIENT_END)
1443 goto exit_free;
1444
1445 dev_warn(&adapter->dev, "Probing not supported\n");
1446 err = -EOPNOTSUPP;
1447 goto exit_free;
1448 }
1449
1450 for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) { 1523 for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) {
1451 dev_dbg(&adapter->dev, "found normal entry for adapter %d, " 1524 dev_dbg(&adapter->dev, "found normal entry for adapter %d, "
1452 "addr 0x%02x\n", adap_id, address_list[i]); 1525 "addr 0x%02x\n", adap_id, address_list[i]);
@@ -1461,18 +1534,23 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
1461 return err; 1534 return err;
1462} 1535}
1463 1536
1537int i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr)
1538{
1539 return i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0,
1540 I2C_SMBUS_QUICK, NULL) >= 0;
1541}
1542EXPORT_SYMBOL_GPL(i2c_probe_func_quick_read);
1543
1464struct i2c_client * 1544struct i2c_client *
1465i2c_new_probed_device(struct i2c_adapter *adap, 1545i2c_new_probed_device(struct i2c_adapter *adap,
1466 struct i2c_board_info *info, 1546 struct i2c_board_info *info,
1467 unsigned short const *addr_list) 1547 unsigned short const *addr_list,
1548 int (*probe)(struct i2c_adapter *, unsigned short addr))
1468{ 1549{
1469 int i; 1550 int i;
1470 1551
1471 /* Stop here if the bus doesn't support probing */ 1552 if (!probe)
1472 if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) { 1553 probe = i2c_default_probe;
1473 dev_err(&adap->dev, "Probing not supported\n");
1474 return NULL;
1475 }
1476 1554
1477 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { 1555 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) {
1478 /* Check address validity */ 1556 /* Check address validity */
@@ -1490,7 +1568,7 @@ i2c_new_probed_device(struct i2c_adapter *adap,
1490 } 1568 }
1491 1569
1492 /* Test address responsiveness */ 1570 /* Test address responsiveness */
1493 if (i2c_default_probe(adap, addr_list[i])) 1571 if (probe(adap, addr_list[i]))
1494 break; 1572 break;
1495 } 1573 }
1496 1574
@@ -2002,7 +2080,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
2002 flags &= I2C_M_TEN | I2C_CLIENT_PEC; 2080 flags &= I2C_M_TEN | I2C_CLIENT_PEC;
2003 2081
2004 if (adapter->algo->smbus_xfer) { 2082 if (adapter->algo->smbus_xfer) {
2005 rt_mutex_lock(&adapter->bus_lock); 2083 i2c_lock_adapter(adapter);
2006 2084
2007 /* Retry automatically on arbitration loss */ 2085 /* Retry automatically on arbitration loss */
2008 orig_jiffies = jiffies; 2086 orig_jiffies = jiffies;
@@ -2016,7 +2094,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
2016 orig_jiffies + adapter->timeout)) 2094 orig_jiffies + adapter->timeout))
2017 break; 2095 break;
2018 } 2096 }
2019 rt_mutex_unlock(&adapter->bus_lock); 2097 i2c_unlock_adapter(adapter);
2020 } else 2098 } else
2021 res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, 2099 res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write,
2022 command, protocol, data); 2100 command, protocol, data);
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index e0694e4d86c7..5f3a52d517c3 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -167,13 +167,9 @@ static ssize_t i2cdev_write(struct file *file, const char __user *buf,
167 if (count > 8192) 167 if (count > 8192)
168 count = 8192; 168 count = 8192;
169 169
170 tmp = kmalloc(count, GFP_KERNEL); 170 tmp = memdup_user(buf, count);
171 if (tmp == NULL) 171 if (IS_ERR(tmp))
172 return -ENOMEM; 172 return PTR_ERR(tmp);
173 if (copy_from_user(tmp, buf, count)) {
174 kfree(tmp);
175 return -EFAULT;
176 }
177 173
178 pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n", 174 pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n",
179 iminor(file->f_path.dentry->d_inode), count); 175 iminor(file->f_path.dentry->d_inode), count);
@@ -193,12 +189,50 @@ static int i2cdev_check(struct device *dev, void *addrp)
193 return dev->driver ? -EBUSY : 0; 189 return dev->driver ? -EBUSY : 0;
194} 190}
195 191
192/* walk up mux tree */
193static int i2cdev_check_mux_parents(struct i2c_adapter *adapter, int addr)
194{
195 int result;
196
197 result = device_for_each_child(&adapter->dev, &addr, i2cdev_check);
198
199 if (!result && i2c_parent_is_i2c_adapter(adapter))
200 result = i2cdev_check_mux_parents(
201 to_i2c_adapter(adapter->dev.parent), addr);
202
203 return result;
204}
205
206/* recurse down mux tree */
207static int i2cdev_check_mux_children(struct device *dev, void *addrp)
208{
209 int result;
210
211 if (dev->type == &i2c_adapter_type)
212 result = device_for_each_child(dev, addrp,
213 i2cdev_check_mux_children);
214 else
215 result = i2cdev_check(dev, addrp);
216
217 return result;
218}
219
196/* This address checking function differs from the one in i2c-core 220/* This address checking function differs from the one in i2c-core
197 in that it considers an address with a registered device, but no 221 in that it considers an address with a registered device, but no
198 driver bound to it, as NOT busy. */ 222 driver bound to it, as NOT busy. */
199static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr) 223static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr)
200{ 224{
201 return device_for_each_child(&adapter->dev, &addr, i2cdev_check); 225 int result = 0;
226
227 if (i2c_parent_is_i2c_adapter(adapter))
228 result = i2cdev_check_mux_parents(
229 to_i2c_adapter(adapter->dev.parent), addr);
230
231 if (!result)
232 result = device_for_each_child(&adapter->dev, &addr,
233 i2cdev_check_mux_children);
234
235 return result;
202} 236}
203 237
204static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client, 238static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
@@ -219,9 +253,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
219 if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) 253 if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
220 return -EINVAL; 254 return -EINVAL;
221 255
222 rdwr_pa = (struct i2c_msg *) 256 rdwr_pa = kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), GFP_KERNEL);
223 kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg),
224 GFP_KERNEL);
225 if (!rdwr_pa) 257 if (!rdwr_pa)
226 return -ENOMEM; 258 return -ENOMEM;
227 259
@@ -247,15 +279,9 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
247 break; 279 break;
248 } 280 }
249 data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf; 281 data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
250 rdwr_pa[i].buf = kmalloc(rdwr_pa[i].len, GFP_KERNEL); 282 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
251 if (rdwr_pa[i].buf == NULL) { 283 if (IS_ERR(rdwr_pa[i].buf)) {
252 res = -ENOMEM; 284 res = PTR_ERR(rdwr_pa[i].buf);
253 break;
254 }
255 if (copy_from_user(rdwr_pa[i].buf, data_ptrs[i],
256 rdwr_pa[i].len)) {
257 ++i; /* Needs to be kfreed too */
258 res = -EFAULT;
259 break; 285 break;
260 } 286 }
261 } 287 }
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
new file mode 100644
index 000000000000..d32a4843fc3a
--- /dev/null
+++ b/drivers/i2c/i2c-mux.c
@@ -0,0 +1,165 @@
1/*
2 * Multiplexed I2C bus driver.
3 *
4 * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it>
5 * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it>
6 * Copyright (c) 2009-2010 NSN GmbH & Co KG <michael.lawnick.ext@nsn.com>
7 *
8 * Simplifies access to complex multiplexed I2C bus topologies, by presenting
9 * each multiplexed bus segment as an additional I2C adapter.
10 * Supports multi-level mux'ing (mux behind a mux).
11 *
12 * Based on:
13 * i2c-virt.c from Kumar Gala <galak@kernel.crashing.org>
14 * i2c-virtual.c from Ken Harrenstien, Copyright (c) 2004 Google, Inc.
15 * i2c-virtual.c from Brian Kuschak <bkuschak@yahoo.com>
16 *
17 * This file is licensed under the terms of the GNU General Public
18 * License version 2. This program is licensed "as is" without any
19 * warranty of any kind, whether express or implied.
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/slab.h>
25#include <linux/i2c.h>
26#include <linux/i2c-mux.h>
27
28/* multiplexer per channel data */
29struct i2c_mux_priv {
30 struct i2c_adapter adap;
31 struct i2c_algorithm algo;
32
33 struct i2c_adapter *parent;
34 void *mux_dev; /* the mux chip/device */
35 u32 chan_id; /* the channel id */
36
37 int (*select)(struct i2c_adapter *, void *mux_dev, u32 chan_id);
38 int (*deselect)(struct i2c_adapter *, void *mux_dev, u32 chan_id);
39};
40
41static int i2c_mux_master_xfer(struct i2c_adapter *adap,
42 struct i2c_msg msgs[], int num)
43{
44 struct i2c_mux_priv *priv = adap->algo_data;
45 struct i2c_adapter *parent = priv->parent;
46 int ret;
47
48 /* Switch to the right mux port and perform the transfer. */
49
50 ret = priv->select(parent, priv->mux_dev, priv->chan_id);
51 if (ret >= 0)
52 ret = parent->algo->master_xfer(parent, msgs, num);
53 if (priv->deselect)
54 priv->deselect(parent, priv->mux_dev, priv->chan_id);
55
56 return ret;
57}
58
59static int i2c_mux_smbus_xfer(struct i2c_adapter *adap,
60 u16 addr, unsigned short flags,
61 char read_write, u8 command,
62 int size, union i2c_smbus_data *data)
63{
64 struct i2c_mux_priv *priv = adap->algo_data;
65 struct i2c_adapter *parent = priv->parent;
66 int ret;
67
68 /* Select the right mux port and perform the transfer. */
69
70 ret = priv->select(parent, priv->mux_dev, priv->chan_id);
71 if (ret >= 0)
72 ret = parent->algo->smbus_xfer(parent, addr, flags,
73 read_write, command, size, data);
74 if (priv->deselect)
75 priv->deselect(parent, priv->mux_dev, priv->chan_id);
76
77 return ret;
78}
79
80/* Return the parent's functionality */
81static u32 i2c_mux_functionality(struct i2c_adapter *adap)
82{
83 struct i2c_mux_priv *priv = adap->algo_data;
84 struct i2c_adapter *parent = priv->parent;
85
86 return parent->algo->functionality(parent);
87}
88
89struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
90 void *mux_dev, u32 force_nr, u32 chan_id,
91 int (*select) (struct i2c_adapter *,
92 void *, u32),
93 int (*deselect) (struct i2c_adapter *,
94 void *, u32))
95{
96 struct i2c_mux_priv *priv;
97 int ret;
98
99 priv = kzalloc(sizeof(struct i2c_mux_priv), GFP_KERNEL);
100 if (!priv)
101 return NULL;
102
103 /* Set up private adapter data */
104 priv->parent = parent;
105 priv->mux_dev = mux_dev;
106 priv->chan_id = chan_id;
107 priv->select = select;
108 priv->deselect = deselect;
109
110 /* Need to do algo dynamically because we don't know ahead
111 * of time what sort of physical adapter we'll be dealing with.
112 */
113 if (parent->algo->master_xfer)
114 priv->algo.master_xfer = i2c_mux_master_xfer;
115 if (parent->algo->smbus_xfer)
116 priv->algo.smbus_xfer = i2c_mux_smbus_xfer;
117 priv->algo.functionality = i2c_mux_functionality;
118
119 /* Now fill out new adapter structure */
120 snprintf(priv->adap.name, sizeof(priv->adap.name),
121 "i2c-%d-mux (chan_id %d)", i2c_adapter_id(parent), chan_id);
122 priv->adap.owner = THIS_MODULE;
123 priv->adap.id = parent->id;
124 priv->adap.algo = &priv->algo;
125 priv->adap.algo_data = priv;
126 priv->adap.dev.parent = &parent->dev;
127
128 if (force_nr) {
129 priv->adap.nr = force_nr;
130 ret = i2c_add_numbered_adapter(&priv->adap);
131 } else {
132 ret = i2c_add_adapter(&priv->adap);
133 }
134 if (ret < 0) {
135 dev_err(&parent->dev,
136 "failed to add mux-adapter (error=%d)\n",
137 ret);
138 kfree(priv);
139 return NULL;
140 }
141
142 dev_info(&parent->dev, "Added multiplexed i2c bus %d\n",
143 i2c_adapter_id(&priv->adap));
144
145 return &priv->adap;
146}
147EXPORT_SYMBOL_GPL(i2c_add_mux_adapter);
148
149int i2c_del_mux_adapter(struct i2c_adapter *adap)
150{
151 struct i2c_mux_priv *priv = adap->algo_data;
152 int ret;
153
154 ret = i2c_del_adapter(adap);
155 if (ret < 0)
156 return ret;
157 kfree(priv);
158
159 return 0;
160}
161EXPORT_SYMBOL_GPL(i2c_del_mux_adapter);
162
163MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
164MODULE_DESCRIPTION("I2C driver for multiplexed I2C busses");
165MODULE_LICENSE("GPL v2");
diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig
new file mode 100644
index 000000000000..4c9a99c4fcb0
--- /dev/null
+++ b/drivers/i2c/muxes/Kconfig
@@ -0,0 +1,18 @@
1#
2# Multiplexer I2C chip drivers configuration
3#
4
5menu "Multiplexer I2C Chip support"
6 depends on I2C_MUX
7
8config I2C_MUX_PCA954x
9 tristate "Philips PCA954x I2C Mux/switches"
10 depends on EXPERIMENTAL
11 help
12 If you say yes here you get support for the Philips PCA954x
13 I2C mux/switch devices.
14
15 This driver can also be built as a module. If so, the module
16 will be called pca954x.
17
18endmenu
diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile
new file mode 100644
index 000000000000..bd83b5274815
--- /dev/null
+++ b/drivers/i2c/muxes/Makefile
@@ -0,0 +1,8 @@
1#
2# Makefile for multiplexer I2C chip drivers.
3
4obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o
5
6ifeq ($(CONFIG_I2C_DEBUG_BUS),y)
7EXTRA_CFLAGS += -DDEBUG
8endif
diff --git a/drivers/i2c/muxes/pca954x.c b/drivers/i2c/muxes/pca954x.c
new file mode 100644
index 000000000000..6f9accf3189d
--- /dev/null
+++ b/drivers/i2c/muxes/pca954x.c
@@ -0,0 +1,301 @@
1/*
2 * I2C multiplexer
3 *
4 * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it>
5 * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it>
6 *
7 * This module supports the PCA954x series of I2C multiplexer/switch chips
8 * made by Philips Semiconductors.
9 * This includes the:
10 * PCA9540, PCA9542, PCA9543, PCA9544, PCA9545, PCA9546, PCA9547
11 * and PCA9548.
12 *
13 * These chips are all controlled via the I2C bus itself, and all have a
14 * single 8-bit register. The upstream "parent" bus fans out to two,
15 * four, or eight downstream busses or channels; which of these
16 * are selected is determined by the chip type and register contents. A
17 * mux can select only one sub-bus at a time; a switch can select any
18 * combination simultaneously.
19 *
20 * Based on:
21 * pca954x.c from Kumar Gala <galak@kernel.crashing.org>
22 * Copyright (C) 2006
23 *
24 * Based on:
25 * pca954x.c from Ken Harrenstien
26 * Copyright (C) 2004 Google, Inc. (Ken Harrenstien)
27 *
28 * Based on:
29 * i2c-virtual_cb.c from Brian Kuschak <bkuschak@yahoo.com>
30 * and
31 * pca9540.c from Jean Delvare <khali@linux-fr.org>.
32 *
33 * This file is licensed under the terms of the GNU General Public
34 * License version 2. This program is licensed "as is" without any
35 * warranty of any kind, whether express or implied.
36 */
37
38#include <linux/module.h>
39#include <linux/init.h>
40#include <linux/slab.h>
41#include <linux/device.h>
42#include <linux/i2c.h>
43#include <linux/i2c-mux.h>
44
45#include <linux/i2c/pca954x.h>
46
47#define PCA954X_MAX_NCHANS 8
48
49enum pca_type {
50 pca_9540,
51 pca_9542,
52 pca_9543,
53 pca_9544,
54 pca_9545,
55 pca_9546,
56 pca_9547,
57 pca_9548,
58};
59
60struct pca954x {
61 enum pca_type type;
62 struct i2c_adapter *virt_adaps[PCA954X_MAX_NCHANS];
63
64 u8 last_chan; /* last register value */
65};
66
67struct chip_desc {
68 u8 nchans;
69 u8 enable; /* used for muxes only */
70 enum muxtype {
71 pca954x_ismux = 0,
72 pca954x_isswi
73 } muxtype;
74};
75
76/* Provide specs for the PCA954x types we know about */
77static const struct chip_desc chips[] = {
78 [pca_9540] = {
79 .nchans = 2,
80 .enable = 0x4,
81 .muxtype = pca954x_ismux,
82 },
83 [pca_9543] = {
84 .nchans = 2,
85 .muxtype = pca954x_isswi,
86 },
87 [pca_9544] = {
88 .nchans = 4,
89 .enable = 0x4,
90 .muxtype = pca954x_ismux,
91 },
92 [pca_9545] = {
93 .nchans = 4,
94 .muxtype = pca954x_isswi,
95 },
96 [pca_9547] = {
97 .nchans = 8,
98 .enable = 0x8,
99 .muxtype = pca954x_ismux,
100 },
101 [pca_9548] = {
102 .nchans = 8,
103 .muxtype = pca954x_isswi,
104 },
105};
106
107static const struct i2c_device_id pca954x_id[] = {
108 { "pca9540", pca_9540 },
109 { "pca9542", pca_9540 },
110 { "pca9543", pca_9543 },
111 { "pca9544", pca_9544 },
112 { "pca9545", pca_9545 },
113 { "pca9546", pca_9545 },
114 { "pca9547", pca_9547 },
115 { "pca9548", pca_9548 },
116 { }
117};
118MODULE_DEVICE_TABLE(i2c, pca954x_id);
119
120/* Write to mux register. Don't use i2c_transfer()/i2c_smbus_xfer()
121 for this as they will try to lock adapter a second time */
122static int pca954x_reg_write(struct i2c_adapter *adap,
123 struct i2c_client *client, u8 val)
124{
125 int ret = -ENODEV;
126
127 if (adap->algo->master_xfer) {
128 struct i2c_msg msg;
129 char buf[1];
130
131 msg.addr = client->addr;
132 msg.flags = 0;
133 msg.len = 1;
134 buf[0] = val;
135 msg.buf = buf;
136 ret = adap->algo->master_xfer(adap, &msg, 1);
137 } else {
138 union i2c_smbus_data data;
139 ret = adap->algo->smbus_xfer(adap, client->addr,
140 client->flags,
141 I2C_SMBUS_WRITE,
142 val, I2C_SMBUS_BYTE, &data);
143 }
144
145 return ret;
146}
147
148static int pca954x_select_chan(struct i2c_adapter *adap,
149 void *client, u32 chan)
150{
151 struct pca954x *data = i2c_get_clientdata(client);
152 const struct chip_desc *chip = &chips[data->type];
153 u8 regval;
154 int ret = 0;
155
156 /* we make switches look like muxes, not sure how to be smarter */
157 if (chip->muxtype == pca954x_ismux)
158 regval = chan | chip->enable;
159 else
160 regval = 1 << chan;
161
162 /* Only select the channel if its different from the last channel */
163 if (data->last_chan != regval) {
164 ret = pca954x_reg_write(adap, client, regval);
165 data->last_chan = regval;
166 }
167
168 return ret;
169}
170
171static int pca954x_deselect_mux(struct i2c_adapter *adap,
172 void *client, u32 chan)
173{
174 struct pca954x *data = i2c_get_clientdata(client);
175
176 /* Deselect active channel */
177 data->last_chan = 0;
178 return pca954x_reg_write(adap, client, data->last_chan);
179}
180
181/*
182 * I2C init/probing/exit functions
183 */
184static int __devinit pca954x_probe(struct i2c_client *client,
185 const struct i2c_device_id *id)
186{
187 struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent);
188 struct pca954x_platform_data *pdata = client->dev.platform_data;
189 int num, force;
190 struct pca954x *data;
191 int ret = -ENODEV;
192
193 if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE))
194 goto err;
195
196 data = kzalloc(sizeof(struct pca954x), GFP_KERNEL);
197 if (!data) {
198 ret = -ENOMEM;
199 goto err;
200 }
201
202 i2c_set_clientdata(client, data);
203
204 /* Read the mux register at addr to verify
205 * that the mux is in fact present.
206 */
207 if (i2c_smbus_read_byte(client) < 0) {
208 dev_warn(&client->dev, "probe failed\n");
209 goto exit_free;
210 }
211
212 data->type = id->driver_data;
213 data->last_chan = 0; /* force the first selection */
214
215 /* Now create an adapter for each channel */
216 for (num = 0; num < chips[data->type].nchans; num++) {
217 force = 0; /* dynamic adap number */
218 if (pdata) {
219 if (num < pdata->num_modes)
220 /* force static number */
221 force = pdata->modes[num].adap_id;
222 else
223 /* discard unconfigured channels */
224 break;
225 }
226
227 data->virt_adaps[num] =
228 i2c_add_mux_adapter(adap, client,
229 force, num, pca954x_select_chan,
230 (pdata && pdata->modes[num].deselect_on_exit)
231 ? pca954x_deselect_mux : NULL);
232
233 if (data->virt_adaps[num] == NULL) {
234 ret = -ENODEV;
235 dev_err(&client->dev,
236 "failed to register multiplexed adapter"
237 " %d as bus %d\n", num, force);
238 goto virt_reg_failed;
239 }
240 }
241
242 dev_info(&client->dev,
243 "registered %d multiplexed busses for I2C %s %s\n",
244 num, chips[data->type].muxtype == pca954x_ismux
245 ? "mux" : "switch", client->name);
246
247 return 0;
248
249virt_reg_failed:
250 for (num--; num >= 0; num--)
251 i2c_del_mux_adapter(data->virt_adaps[num]);
252exit_free:
253 kfree(data);
254err:
255 return ret;
256}
257
258static int __devexit pca954x_remove(struct i2c_client *client)
259{
260 struct pca954x *data = i2c_get_clientdata(client);
261 const struct chip_desc *chip = &chips[data->type];
262 int i, err;
263
264 for (i = 0; i < chip->nchans; ++i)
265 if (data->virt_adaps[i]) {
266 err = i2c_del_mux_adapter(data->virt_adaps[i]);
267 if (err)
268 return err;
269 data->virt_adaps[i] = NULL;
270 }
271
272 kfree(data);
273 return 0;
274}
275
276static struct i2c_driver pca954x_driver = {
277 .driver = {
278 .name = "pca954x",
279 .owner = THIS_MODULE,
280 },
281 .probe = pca954x_probe,
282 .remove = __devexit_p(pca954x_remove),
283 .id_table = pca954x_id,
284};
285
286static int __init pca954x_init(void)
287{
288 return i2c_add_driver(&pca954x_driver);
289}
290
291static void __exit pca954x_exit(void)
292{
293 i2c_del_driver(&pca954x_driver);
294}
295
296module_init(pca954x_init);
297module_exit(pca954x_exit);
298
299MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
300MODULE_DESCRIPTION("PCA954x I2C mux/switch driver");
301MODULE_LICENSE("GPL v2");
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 3cb9c4e056ff..fa896210ed7b 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -177,7 +177,7 @@ EXPORT_SYMBOL_GPL(ide_pci_clk);
177module_param_named(pci_clock, ide_pci_clk, int, 0); 177module_param_named(pci_clock, ide_pci_clk, int, 0);
178MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)"); 178MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)");
179 179
180static int ide_set_dev_param_mask(const char *s, struct kernel_param *kp) 180static int ide_set_dev_param_mask(const char *s, const struct kernel_param *kp)
181{ 181{
182 int a, b, i, j = 1; 182 int a, b, i, j = 1;
183 unsigned int *dev_param_mask = (unsigned int *)kp->arg; 183 unsigned int *dev_param_mask = (unsigned int *)kp->arg;
@@ -200,34 +200,40 @@ static int ide_set_dev_param_mask(const char *s, struct kernel_param *kp)
200 return 0; 200 return 0;
201} 201}
202 202
203static struct kernel_param_ops param_ops_ide_dev_mask = {
204 .set = ide_set_dev_param_mask
205};
206
207#define param_check_ide_dev_mask(name, p) param_check_uint(name, p)
208
203static unsigned int ide_nodma; 209static unsigned int ide_nodma;
204 210
205module_param_call(nodma, ide_set_dev_param_mask, NULL, &ide_nodma, 0); 211module_param_named(nodma, ide_nodma, ide_dev_mask, 0);
206MODULE_PARM_DESC(nodma, "disallow DMA for a device"); 212MODULE_PARM_DESC(nodma, "disallow DMA for a device");
207 213
208static unsigned int ide_noflush; 214static unsigned int ide_noflush;
209 215
210module_param_call(noflush, ide_set_dev_param_mask, NULL, &ide_noflush, 0); 216module_param_named(noflush, ide_noflush, ide_dev_mask, 0);
211MODULE_PARM_DESC(noflush, "disable flush requests for a device"); 217MODULE_PARM_DESC(noflush, "disable flush requests for a device");
212 218
213static unsigned int ide_nohpa; 219static unsigned int ide_nohpa;
214 220
215module_param_call(nohpa, ide_set_dev_param_mask, NULL, &ide_nohpa, 0); 221module_param_named(nohpa, ide_nohpa, ide_dev_mask, 0);
216MODULE_PARM_DESC(nohpa, "disable Host Protected Area for a device"); 222MODULE_PARM_DESC(nohpa, "disable Host Protected Area for a device");
217 223
218static unsigned int ide_noprobe; 224static unsigned int ide_noprobe;
219 225
220module_param_call(noprobe, ide_set_dev_param_mask, NULL, &ide_noprobe, 0); 226module_param_named(noprobe, ide_noprobe, ide_dev_mask, 0);
221MODULE_PARM_DESC(noprobe, "skip probing for a device"); 227MODULE_PARM_DESC(noprobe, "skip probing for a device");
222 228
223static unsigned int ide_nowerr; 229static unsigned int ide_nowerr;
224 230
225module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0); 231module_param_named(nowerr, ide_nowerr, ide_dev_mask, 0);
226MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device"); 232MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device");
227 233
228static unsigned int ide_cdroms; 234static unsigned int ide_cdroms;
229 235
230module_param_call(cdrom, ide_set_dev_param_mask, NULL, &ide_cdroms, 0); 236module_param_named(cdrom, ide_cdroms, ide_dev_mask, 0);
231MODULE_PARM_DESC(cdrom, "force device as a CD-ROM"); 237MODULE_PARM_DESC(cdrom, "force device as a CD-ROM");
232 238
233struct chs_geom { 239struct chs_geom {
diff --git a/drivers/infiniband/hw/ehca/ehca_classes.h b/drivers/infiniband/hw/ehca/ehca_classes.h
index 0136abd50dd4..aaf6023a4835 100644
--- a/drivers/infiniband/hw/ehca/ehca_classes.h
+++ b/drivers/infiniband/hw/ehca/ehca_classes.h
@@ -112,7 +112,7 @@ struct ehca_sport {
112 112
113struct ehca_shca { 113struct ehca_shca {
114 struct ib_device ib_device; 114 struct ib_device ib_device;
115 struct of_device *ofdev; 115 struct platform_device *ofdev;
116 u8 num_ports; 116 u8 num_ports;
117 int hw_level; 117 int hw_level;
118 struct list_head shca_list; 118 struct list_head shca_list;
diff --git a/drivers/infiniband/hw/ehca/ehca_main.c b/drivers/infiniband/hw/ehca/ehca_main.c
index cfc4de7a5da4..c240e9972cb0 100644
--- a/drivers/infiniband/hw/ehca/ehca_main.c
+++ b/drivers/infiniband/hw/ehca/ehca_main.c
@@ -713,7 +713,7 @@ static struct attribute_group ehca_dev_attr_grp = {
713 .attrs = ehca_dev_attrs 713 .attrs = ehca_dev_attrs
714}; 714};
715 715
716static int __devinit ehca_probe(struct of_device *dev, 716static int __devinit ehca_probe(struct platform_device *dev,
717 const struct of_device_id *id) 717 const struct of_device_id *id)
718{ 718{
719 struct ehca_shca *shca; 719 struct ehca_shca *shca;
@@ -879,7 +879,7 @@ probe1:
879 return -EINVAL; 879 return -EINVAL;
880} 880}
881 881
882static int __devexit ehca_remove(struct of_device *dev) 882static int __devexit ehca_remove(struct platform_device *dev)
883{ 883{
884 struct ehca_shca *shca = dev_get_drvdata(&dev->dev); 884 struct ehca_shca *shca = dev_get_drvdata(&dev->dev);
885 unsigned long flags; 885 unsigned long flags;
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index b171f63fe4d7..9cc488d21490 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -395,6 +395,16 @@ config KEYBOARD_SH_KEYSC
395 To compile this driver as a module, choose M here: the 395 To compile this driver as a module, choose M here: the
396 module will be called sh_keysc. 396 module will be called sh_keysc.
397 397
398config KEYBOARD_STMPE
399 tristate "STMPE keypad support"
400 depends on MFD_STMPE
401 help
402 Say Y here if you want to use the keypad controller on STMPE I/O
403 expanders.
404
405 To compile this driver as a module, choose M here: the module will be
406 called stmpe-keypad.
407
398config KEYBOARD_DAVINCI 408config KEYBOARD_DAVINCI
399 tristate "TI DaVinci Key Scan" 409 tristate "TI DaVinci Key Scan"
400 depends on ARCH_DAVINCI_DM365 410 depends on ARCH_DAVINCI_DM365
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 1a66d5f1ca8b..504b591be0cd 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -35,6 +35,7 @@ obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o
35obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o 35obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o
36obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o 36obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o
37obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o 37obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o
38obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o
38obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o 39obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o
39obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o 40obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o
40obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o 41obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o
diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c
new file mode 100644
index 000000000000..ab7610ca10eb
--- /dev/null
+++ b/drivers/input/keyboard/stmpe-keypad.c
@@ -0,0 +1,386 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
6 */
7
8#include <linux/module.h>
9#include <linux/init.h>
10#include <linux/slab.h>
11#include <linux/input.h>
12#include <linux/interrupt.h>
13#include <linux/platform_device.h>
14#include <linux/input/matrix_keypad.h>
15#include <linux/mfd/stmpe.h>
16
17/* These are at the same addresses in all STMPE variants */
18#define STMPE_KPC_COL 0x60
19#define STMPE_KPC_ROW_MSB 0x61
20#define STMPE_KPC_ROW_LSB 0x62
21#define STMPE_KPC_CTRL_MSB 0x63
22#define STMPE_KPC_CTRL_LSB 0x64
23#define STMPE_KPC_COMBI_KEY_0 0x65
24#define STMPE_KPC_COMBI_KEY_1 0x66
25#define STMPE_KPC_COMBI_KEY_2 0x67
26#define STMPE_KPC_DATA_BYTE0 0x68
27#define STMPE_KPC_DATA_BYTE1 0x69
28#define STMPE_KPC_DATA_BYTE2 0x6a
29#define STMPE_KPC_DATA_BYTE3 0x6b
30#define STMPE_KPC_DATA_BYTE4 0x6c
31
32#define STMPE_KPC_CTRL_LSB_SCAN (0x1 << 0)
33#define STMPE_KPC_CTRL_LSB_DEBOUNCE (0x7f << 1)
34#define STMPE_KPC_CTRL_MSB_SCAN_COUNT (0xf << 4)
35
36#define STMPE_KPC_ROW_MSB_ROWS 0xff
37
38#define STMPE_KPC_DATA_UP (0x1 << 7)
39#define STMPE_KPC_DATA_ROW (0xf << 3)
40#define STMPE_KPC_DATA_COL (0x7 << 0)
41#define STMPE_KPC_DATA_NOKEY_MASK 0x78
42
43#define STMPE_KEYPAD_MAX_DEBOUNCE 127
44#define STMPE_KEYPAD_MAX_SCAN_COUNT 15
45
46#define STMPE_KEYPAD_MAX_ROWS 8
47#define STMPE_KEYPAD_MAX_COLS 8
48#define STMPE_KEYPAD_ROW_SHIFT 3
49#define STMPE_KEYPAD_KEYMAP_SIZE \
50 (STMPE_KEYPAD_MAX_ROWS * STMPE_KEYPAD_MAX_COLS)
51
52/**
53 * struct stmpe_keypad_variant - model-specific attributes
54 * @auto_increment: whether the KPC_DATA_BYTE register address
55 * auto-increments on multiple read
56 * @num_data: number of data bytes
57 * @num_normal_data: number of normal keys' data bytes
58 * @max_cols: maximum number of columns supported
59 * @max_rows: maximum number of rows supported
60 * @col_gpios: bitmask of gpios which can be used for columns
61 * @row_gpios: bitmask of gpios which can be used for rows
62 */
63struct stmpe_keypad_variant {
64 bool auto_increment;
65 int num_data;
66 int num_normal_data;
67 int max_cols;
68 int max_rows;
69 unsigned int col_gpios;
70 unsigned int row_gpios;
71};
72
73static const struct stmpe_keypad_variant stmpe_keypad_variants[] = {
74 [STMPE1601] = {
75 .auto_increment = true,
76 .num_data = 5,
77 .num_normal_data = 3,
78 .max_cols = 8,
79 .max_rows = 8,
80 .col_gpios = 0x000ff, /* GPIO 0 - 7 */
81 .row_gpios = 0x0ff00, /* GPIO 8 - 15 */
82 },
83 [STMPE2401] = {
84 .auto_increment = false,
85 .num_data = 3,
86 .num_normal_data = 2,
87 .max_cols = 8,
88 .max_rows = 12,
89 .col_gpios = 0x0000ff, /* GPIO 0 - 7*/
90 .row_gpios = 0x1fef00, /* GPIO 8-14, 16-20 */
91 },
92 [STMPE2403] = {
93 .auto_increment = true,
94 .num_data = 5,
95 .num_normal_data = 3,
96 .max_cols = 8,
97 .max_rows = 12,
98 .col_gpios = 0x0000ff, /* GPIO 0 - 7*/
99 .row_gpios = 0x1fef00, /* GPIO 8-14, 16-20 */
100 },
101};
102
103struct stmpe_keypad {
104 struct stmpe *stmpe;
105 struct input_dev *input;
106 const struct stmpe_keypad_variant *variant;
107 const struct stmpe_keypad_platform_data *plat;
108
109 unsigned int rows;
110 unsigned int cols;
111
112 unsigned short keymap[STMPE_KEYPAD_KEYMAP_SIZE];
113};
114
115static int stmpe_keypad_read_data(struct stmpe_keypad *keypad, u8 *data)
116{
117 const struct stmpe_keypad_variant *variant = keypad->variant;
118 struct stmpe *stmpe = keypad->stmpe;
119 int ret;
120 int i;
121
122 if (variant->auto_increment)
123 return stmpe_block_read(stmpe, STMPE_KPC_DATA_BYTE0,
124 variant->num_data, data);
125
126 for (i = 0; i < variant->num_data; i++) {
127 ret = stmpe_reg_read(stmpe, STMPE_KPC_DATA_BYTE0 + i);
128 if (ret < 0)
129 return ret;
130
131 data[i] = ret;
132 }
133
134 return 0;
135}
136
137static irqreturn_t stmpe_keypad_irq(int irq, void *dev)
138{
139 struct stmpe_keypad *keypad = dev;
140 struct input_dev *input = keypad->input;
141 const struct stmpe_keypad_variant *variant = keypad->variant;
142 u8 fifo[variant->num_data];
143 int ret;
144 int i;
145
146 ret = stmpe_keypad_read_data(keypad, fifo);
147 if (ret < 0)
148 return IRQ_NONE;
149
150 for (i = 0; i < variant->num_normal_data; i++) {
151 u8 data = fifo[i];
152 int row = (data & STMPE_KPC_DATA_ROW) >> 3;
153 int col = data & STMPE_KPC_DATA_COL;
154 int code = MATRIX_SCAN_CODE(row, col, STMPE_KEYPAD_ROW_SHIFT);
155 bool up = data & STMPE_KPC_DATA_UP;
156
157 if ((data & STMPE_KPC_DATA_NOKEY_MASK)
158 == STMPE_KPC_DATA_NOKEY_MASK)
159 continue;
160
161 input_event(input, EV_MSC, MSC_SCAN, code);
162 input_report_key(input, keypad->keymap[code], !up);
163 input_sync(input);
164 }
165
166 return IRQ_HANDLED;
167}
168
169static int __devinit stmpe_keypad_altfunc_init(struct stmpe_keypad *keypad)
170{
171 const struct stmpe_keypad_variant *variant = keypad->variant;
172 unsigned int col_gpios = variant->col_gpios;
173 unsigned int row_gpios = variant->row_gpios;
174 struct stmpe *stmpe = keypad->stmpe;
175 unsigned int pins = 0;
176 int i;
177
178 /*
179 * Figure out which pins need to be set to the keypad alternate
180 * function.
181 *
182 * {cols,rows}_gpios are bitmasks of which pins on the chip can be used
183 * for the keypad.
184 *
185 * keypad->{cols,rows} are a bitmask of which pins (of the ones useable
186 * for the keypad) are used on the board.
187 */
188
189 for (i = 0; i < variant->max_cols; i++) {
190 int num = __ffs(col_gpios);
191
192 if (keypad->cols & (1 << i))
193 pins |= 1 << num;
194
195 col_gpios &= ~(1 << num);
196 }
197
198 for (i = 0; i < variant->max_rows; i++) {
199 int num = __ffs(row_gpios);
200
201 if (keypad->rows & (1 << i))
202 pins |= 1 << num;
203
204 row_gpios &= ~(1 << num);
205 }
206
207 return stmpe_set_altfunc(stmpe, pins, STMPE_BLOCK_KEYPAD);
208}
209
210static int __devinit stmpe_keypad_chip_init(struct stmpe_keypad *keypad)
211{
212 const struct stmpe_keypad_platform_data *plat = keypad->plat;
213 const struct stmpe_keypad_variant *variant = keypad->variant;
214 struct stmpe *stmpe = keypad->stmpe;
215 int ret;
216
217 if (plat->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE)
218 return -EINVAL;
219
220 if (plat->scan_count > STMPE_KEYPAD_MAX_SCAN_COUNT)
221 return -EINVAL;
222
223 ret = stmpe_enable(stmpe, STMPE_BLOCK_KEYPAD);
224 if (ret < 0)
225 return ret;
226
227 ret = stmpe_keypad_altfunc_init(keypad);
228 if (ret < 0)
229 return ret;
230
231 ret = stmpe_reg_write(stmpe, STMPE_KPC_COL, keypad->cols);
232 if (ret < 0)
233 return ret;
234
235 ret = stmpe_reg_write(stmpe, STMPE_KPC_ROW_LSB, keypad->rows);
236 if (ret < 0)
237 return ret;
238
239 if (variant->max_rows > 8) {
240 ret = stmpe_set_bits(stmpe, STMPE_KPC_ROW_MSB,
241 STMPE_KPC_ROW_MSB_ROWS,
242 keypad->rows >> 8);
243 if (ret < 0)
244 return ret;
245 }
246
247 ret = stmpe_set_bits(stmpe, STMPE_KPC_CTRL_MSB,
248 STMPE_KPC_CTRL_MSB_SCAN_COUNT,
249 plat->scan_count << 4);
250 if (ret < 0)
251 return ret;
252
253 return stmpe_set_bits(stmpe, STMPE_KPC_CTRL_LSB,
254 STMPE_KPC_CTRL_LSB_SCAN |
255 STMPE_KPC_CTRL_LSB_DEBOUNCE,
256 STMPE_KPC_CTRL_LSB_SCAN |
257 (plat->debounce_ms << 1));
258}
259
260static int __devinit stmpe_keypad_probe(struct platform_device *pdev)
261{
262 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
263 struct stmpe_keypad_platform_data *plat;
264 struct stmpe_keypad *keypad;
265 struct input_dev *input;
266 int ret;
267 int irq;
268 int i;
269
270 plat = stmpe->pdata->keypad;
271 if (!plat)
272 return -ENODEV;
273
274 irq = platform_get_irq(pdev, 0);
275 if (irq < 0)
276 return irq;
277
278 keypad = kzalloc(sizeof(struct stmpe_keypad), GFP_KERNEL);
279 if (!keypad)
280 return -ENOMEM;
281
282 input = input_allocate_device();
283 if (!input) {
284 ret = -ENOMEM;
285 goto out_freekeypad;
286 }
287
288 input->name = "STMPE keypad";
289 input->id.bustype = BUS_I2C;
290 input->dev.parent = &pdev->dev;
291
292 input_set_capability(input, EV_MSC, MSC_SCAN);
293
294 __set_bit(EV_KEY, input->evbit);
295 if (!plat->no_autorepeat)
296 __set_bit(EV_REP, input->evbit);
297
298 input->keycode = keypad->keymap;
299 input->keycodesize = sizeof(keypad->keymap[0]);
300 input->keycodemax = ARRAY_SIZE(keypad->keymap);
301
302 matrix_keypad_build_keymap(plat->keymap_data, STMPE_KEYPAD_ROW_SHIFT,
303 input->keycode, input->keybit);
304
305 for (i = 0; i < plat->keymap_data->keymap_size; i++) {
306 unsigned int key = plat->keymap_data->keymap[i];
307
308 keypad->cols |= 1 << KEY_COL(key);
309 keypad->rows |= 1 << KEY_ROW(key);
310 }
311
312 keypad->stmpe = stmpe;
313 keypad->plat = plat;
314 keypad->input = input;
315 keypad->variant = &stmpe_keypad_variants[stmpe->partnum];
316
317 ret = stmpe_keypad_chip_init(keypad);
318 if (ret < 0)
319 goto out_freeinput;
320
321 ret = input_register_device(input);
322 if (ret) {
323 dev_err(&pdev->dev,
324 "unable to register input device: %d\n", ret);
325 goto out_freeinput;
326 }
327
328 ret = request_threaded_irq(irq, NULL, stmpe_keypad_irq, IRQF_ONESHOT,
329 "stmpe-keypad", keypad);
330 if (ret) {
331 dev_err(&pdev->dev, "unable to get irq: %d\n", ret);
332 goto out_unregisterinput;
333 }
334
335 platform_set_drvdata(pdev, keypad);
336
337 return 0;
338
339out_unregisterinput:
340 input_unregister_device(input);
341 input = NULL;
342out_freeinput:
343 input_free_device(input);
344out_freekeypad:
345 kfree(keypad);
346 return ret;
347}
348
349static int __devexit stmpe_keypad_remove(struct platform_device *pdev)
350{
351 struct stmpe_keypad *keypad = platform_get_drvdata(pdev);
352 struct stmpe *stmpe = keypad->stmpe;
353 int irq = platform_get_irq(pdev, 0);
354
355 stmpe_disable(stmpe, STMPE_BLOCK_KEYPAD);
356
357 free_irq(irq, keypad);
358 input_unregister_device(keypad->input);
359 platform_set_drvdata(pdev, NULL);
360 kfree(keypad);
361
362 return 0;
363}
364
365static struct platform_driver stmpe_keypad_driver = {
366 .driver.name = "stmpe-keypad",
367 .driver.owner = THIS_MODULE,
368 .probe = stmpe_keypad_probe,
369 .remove = __devexit_p(stmpe_keypad_remove),
370};
371
372static int __init stmpe_keypad_init(void)
373{
374 return platform_driver_register(&stmpe_keypad_driver);
375}
376module_init(stmpe_keypad_init);
377
378static void __exit stmpe_keypad_exit(void)
379{
380 platform_driver_unregister(&stmpe_keypad_driver);
381}
382module_exit(stmpe_keypad_exit);
383
384MODULE_LICENSE("GPL v2");
385MODULE_DESCRIPTION("STMPExxxx keypad driver");
386MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index e148749b5851..23257652b8e8 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -38,7 +38,8 @@ enum {
38}; 38};
39 39
40static int ati_remote2_set_mask(const char *val, 40static int ati_remote2_set_mask(const char *val,
41 struct kernel_param *kp, unsigned int max) 41 const struct kernel_param *kp,
42 unsigned int max)
42{ 43{
43 unsigned long mask; 44 unsigned long mask;
44 int ret; 45 int ret;
@@ -59,28 +60,31 @@ static int ati_remote2_set_mask(const char *val,
59} 60}
60 61
61static int ati_remote2_set_channel_mask(const char *val, 62static int ati_remote2_set_channel_mask(const char *val,
62 struct kernel_param *kp) 63 const struct kernel_param *kp)
63{ 64{
64 pr_debug("%s()\n", __func__); 65 pr_debug("%s()\n", __func__);
65 66
66 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK); 67 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK);
67} 68}
68 69
69static int ati_remote2_get_channel_mask(char *buffer, struct kernel_param *kp) 70static int ati_remote2_get_channel_mask(char *buffer,
71 const struct kernel_param *kp)
70{ 72{
71 pr_debug("%s()\n", __func__); 73 pr_debug("%s()\n", __func__);
72 74
73 return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg); 75 return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg);
74} 76}
75 77
76static int ati_remote2_set_mode_mask(const char *val, struct kernel_param *kp) 78static int ati_remote2_set_mode_mask(const char *val,
79 const struct kernel_param *kp)
77{ 80{
78 pr_debug("%s()\n", __func__); 81 pr_debug("%s()\n", __func__);
79 82
80 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK); 83 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK);
81} 84}
82 85
83static int ati_remote2_get_mode_mask(char *buffer, struct kernel_param *kp) 86static int ati_remote2_get_mode_mask(char *buffer,
87 const struct kernel_param *kp)
84{ 88{
85 pr_debug("%s()\n", __func__); 89 pr_debug("%s()\n", __func__);
86 90
@@ -89,15 +93,19 @@ static int ati_remote2_get_mode_mask(char *buffer, struct kernel_param *kp)
89 93
90static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK; 94static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK;
91#define param_check_channel_mask(name, p) __param_check(name, p, unsigned int) 95#define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
92#define param_set_channel_mask ati_remote2_set_channel_mask 96static struct kernel_param_ops param_ops_channel_mask = {
93#define param_get_channel_mask ati_remote2_get_channel_mask 97 .set = ati_remote2_set_channel_mask,
98 .get = ati_remote2_get_channel_mask,
99};
94module_param(channel_mask, channel_mask, 0644); 100module_param(channel_mask, channel_mask, 0644);
95MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>"); 101MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
96 102
97static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK; 103static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK;
98#define param_check_mode_mask(name, p) __param_check(name, p, unsigned int) 104#define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
99#define param_set_mode_mask ati_remote2_set_mode_mask 105static struct kernel_param_ops param_ops_mode_mask = {
100#define param_get_mode_mask ati_remote2_get_mode_mask 106 .set = ati_remote2_set_mode_mask,
107 .get = ati_remote2_get_mode_mask,
108};
101module_param(mode_mask, mode_mask, 0644); 109module_param(mode_mask, mode_mask, 0644);
102MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>"); 110MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
103 111
diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
index f3bb92e9755f..8e130bf7d32b 100644
--- a/drivers/input/misc/sparcspkr.c
+++ b/drivers/input/misc/sparcspkr.c
@@ -173,7 +173,7 @@ static int __devinit sparcspkr_probe(struct device *dev)
173 return 0; 173 return 0;
174} 174}
175 175
176static int sparcspkr_shutdown(struct of_device *dev) 176static int sparcspkr_shutdown(struct platform_device *dev)
177{ 177{
178 struct sparcspkr_state *state = dev_get_drvdata(&dev->dev); 178 struct sparcspkr_state *state = dev_get_drvdata(&dev->dev);
179 struct input_dev *input_dev = state->input_dev; 179 struct input_dev *input_dev = state->input_dev;
@@ -184,7 +184,7 @@ static int sparcspkr_shutdown(struct of_device *dev)
184 return 0; 184 return 0;
185} 185}
186 186
187static int __devinit bbc_beep_probe(struct of_device *op, const struct of_device_id *match) 187static int __devinit bbc_beep_probe(struct platform_device *op, const struct of_device_id *match)
188{ 188{
189 struct sparcspkr_state *state; 189 struct sparcspkr_state *state;
190 struct bbc_beep_info *info; 190 struct bbc_beep_info *info;
@@ -231,7 +231,7 @@ out_err:
231 return err; 231 return err;
232} 232}
233 233
234static int __devexit bbc_remove(struct of_device *op) 234static int __devexit bbc_remove(struct platform_device *op)
235{ 235{
236 struct sparcspkr_state *state = dev_get_drvdata(&op->dev); 236 struct sparcspkr_state *state = dev_get_drvdata(&op->dev);
237 struct input_dev *input_dev = state->input_dev; 237 struct input_dev *input_dev = state->input_dev;
@@ -269,7 +269,7 @@ static struct of_platform_driver bbc_beep_driver = {
269 .shutdown = sparcspkr_shutdown, 269 .shutdown = sparcspkr_shutdown,
270}; 270};
271 271
272static int __devinit grover_beep_probe(struct of_device *op, const struct of_device_id *match) 272static int __devinit grover_beep_probe(struct platform_device *op, const struct of_device_id *match)
273{ 273{
274 struct sparcspkr_state *state; 274 struct sparcspkr_state *state;
275 struct grover_beep_info *info; 275 struct grover_beep_info *info;
@@ -312,7 +312,7 @@ out_err:
312 return err; 312 return err;
313} 313}
314 314
315static int __devexit grover_remove(struct of_device *op) 315static int __devexit grover_remove(struct platform_device *op)
316{ 316{
317 struct sparcspkr_state *state = dev_get_drvdata(&op->dev); 317 struct sparcspkr_state *state = dev_get_drvdata(&op->dev);
318 struct grover_beep_info *info = &state->u.grover; 318 struct grover_beep_info *info = &state->u.grover;
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 979c50215282..73a7af2542a8 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -39,11 +39,13 @@ MODULE_DESCRIPTION(DRIVER_DESC);
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40 40
41static unsigned int psmouse_max_proto = PSMOUSE_AUTO; 41static unsigned int psmouse_max_proto = PSMOUSE_AUTO;
42static int psmouse_set_maxproto(const char *val, struct kernel_param *kp); 42static int psmouse_set_maxproto(const char *val, const struct kernel_param *);
43static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp); 43static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp);
44static struct kernel_param_ops param_ops_proto_abbrev = {
45 .set = psmouse_set_maxproto,
46 .get = psmouse_get_maxproto,
47};
44#define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int) 48#define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int)
45#define param_set_proto_abbrev psmouse_set_maxproto
46#define param_get_proto_abbrev psmouse_get_maxproto
47module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644); 49module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644);
48MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches."); 50MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches.");
49 51
@@ -1679,7 +1681,7 @@ static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data,
1679} 1681}
1680 1682
1681 1683
1682static int psmouse_set_maxproto(const char *val, struct kernel_param *kp) 1684static int psmouse_set_maxproto(const char *val, const struct kernel_param *kp)
1683{ 1685{
1684 const struct psmouse_protocol *proto; 1686 const struct psmouse_protocol *proto;
1685 1687
@@ -1696,7 +1698,7 @@ static int psmouse_set_maxproto(const char *val, struct kernel_param *kp)
1696 return 0; 1698 return 0;
1697} 1699}
1698 1700
1699static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp) 1701static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp)
1700{ 1702{
1701 int type = *((unsigned int *)kp->arg); 1703 int type = *((unsigned int *)kp->arg);
1702 1704
diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
index cb2a24b94746..c5cc4508d6df 100644
--- a/drivers/input/serio/i8042-sparcio.h
+++ b/drivers/input/serio/i8042-sparcio.h
@@ -49,7 +49,7 @@ static inline void i8042_write_command(int val)
49#define OBP_PS2MS_NAME1 "kdmouse" 49#define OBP_PS2MS_NAME1 "kdmouse"
50#define OBP_PS2MS_NAME2 "mouse" 50#define OBP_PS2MS_NAME2 "mouse"
51 51
52static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_device_id *match) 52static int __devinit sparc_i8042_probe(struct platform_device *op, const struct of_device_id *match)
53{ 53{
54 struct device_node *dp = op->dev.of_node; 54 struct device_node *dp = op->dev.of_node;
55 55
@@ -57,7 +57,7 @@ static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_dev
57 while (dp) { 57 while (dp) {
58 if (!strcmp(dp->name, OBP_PS2KBD_NAME1) || 58 if (!strcmp(dp->name, OBP_PS2KBD_NAME1) ||
59 !strcmp(dp->name, OBP_PS2KBD_NAME2)) { 59 !strcmp(dp->name, OBP_PS2KBD_NAME2)) {
60 struct of_device *kbd = of_find_device_by_node(dp); 60 struct platform_device *kbd = of_find_device_by_node(dp);
61 unsigned int irq = kbd->archdata.irqs[0]; 61 unsigned int irq = kbd->archdata.irqs[0];
62 if (irq == 0xffffffff) 62 if (irq == 0xffffffff)
63 irq = op->archdata.irqs[0]; 63 irq = op->archdata.irqs[0];
@@ -67,7 +67,7 @@ static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_dev
67 kbd_res = &kbd->resource[0]; 67 kbd_res = &kbd->resource[0];
68 } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) || 68 } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) ||
69 !strcmp(dp->name, OBP_PS2MS_NAME2)) { 69 !strcmp(dp->name, OBP_PS2MS_NAME2)) {
70 struct of_device *ms = of_find_device_by_node(dp); 70 struct platform_device *ms = of_find_device_by_node(dp);
71 unsigned int irq = ms->archdata.irqs[0]; 71 unsigned int irq = ms->archdata.irqs[0];
72 if (irq == 0xffffffff) 72 if (irq == 0xffffffff)
73 irq = op->archdata.irqs[0]; 73 irq = op->archdata.irqs[0];
@@ -80,7 +80,7 @@ static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_dev
80 return 0; 80 return 0;
81} 81}
82 82
83static int __devexit sparc_i8042_remove(struct of_device *op) 83static int __devexit sparc_i8042_remove(struct platform_device *op)
84{ 84{
85 of_iounmap(kbd_res, kbd_iobase, 8); 85 of_iounmap(kbd_res, kbd_iobase, 8);
86 86
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index 258b98b9d7c2..46e4ba0b9246 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -61,10 +61,6 @@ static bool i8042_noloop;
61module_param_named(noloop, i8042_noloop, bool, 0); 61module_param_named(noloop, i8042_noloop, bool, 0);
62MODULE_PARM_DESC(noloop, "Disable the AUX Loopback command while probing for the AUX port"); 62MODULE_PARM_DESC(noloop, "Disable the AUX Loopback command while probing for the AUX port");
63 63
64static unsigned int i8042_blink_frequency = 500;
65module_param_named(panicblink, i8042_blink_frequency, uint, 0600);
66MODULE_PARM_DESC(panicblink, "Frequency with which keyboard LEDs should blink when kernel panics");
67
68#ifdef CONFIG_X86 64#ifdef CONFIG_X86
69static bool i8042_dritek; 65static bool i8042_dritek;
70module_param_named(dritek, i8042_dritek, bool, 0); 66module_param_named(dritek, i8042_dritek, bool, 0);
@@ -1030,8 +1026,8 @@ static void i8042_controller_reset(void)
1030 1026
1031 1027
1032/* 1028/*
1033 * i8042_panic_blink() will flash the keyboard LEDs and is called when 1029 * i8042_panic_blink() will turn the keyboard LEDs on or off and is called
1034 * kernel panics. Flashing LEDs is useful for users running X who may 1030 * when kernel panics. Flashing LEDs is useful for users running X who may
1035 * not see the console and will help distingushing panics from "real" 1031 * not see the console and will help distingushing panics from "real"
1036 * lockups. 1032 * lockups.
1037 * 1033 *
@@ -1041,22 +1037,12 @@ static void i8042_controller_reset(void)
1041 1037
1042#define DELAY do { mdelay(1); if (++delay > 10) return delay; } while(0) 1038#define DELAY do { mdelay(1); if (++delay > 10) return delay; } while(0)
1043 1039
1044static long i8042_panic_blink(long count) 1040static long i8042_panic_blink(int state)
1045{ 1041{
1046 long delay = 0; 1042 long delay = 0;
1047 static long last_blink; 1043 char led;
1048 static char led;
1049
1050 /*
1051 * We expect frequency to be about 1/2s. KDB uses about 1s.
1052 * Make sure they are different.
1053 */
1054 if (!i8042_blink_frequency)
1055 return 0;
1056 if (count - last_blink < i8042_blink_frequency)
1057 return 0;
1058 1044
1059 led ^= 0x01 | 0x04; 1045 led = (state) ? 0x01 | 0x04 : 0;
1060 while (i8042_read_status() & I8042_STR_IBF) 1046 while (i8042_read_status() & I8042_STR_IBF)
1061 DELAY; 1047 DELAY;
1062 dbg("%02x -> i8042 (panic blink)", 0xed); 1048 dbg("%02x -> i8042 (panic blink)", 0xed);
@@ -1069,7 +1055,6 @@ static long i8042_panic_blink(long count)
1069 dbg("%02x -> i8042 (panic blink)", led); 1055 dbg("%02x -> i8042 (panic blink)", led);
1070 i8042_write_data(led); 1056 i8042_write_data(led);
1071 DELAY; 1057 DELAY;
1072 last_blink = count;
1073 return delay; 1058 return delay;
1074} 1059}
1075 1060
diff --git a/drivers/input/serio/xilinx_ps2.c b/drivers/input/serio/xilinx_ps2.c
index e2c028d2638f..bb14449fb022 100644
--- a/drivers/input/serio/xilinx_ps2.c
+++ b/drivers/input/serio/xilinx_ps2.c
@@ -232,7 +232,7 @@ static void sxps2_close(struct serio *pserio)
232 * It returns 0, if the driver is bound to the PS/2 device, or a negative 232 * It returns 0, if the driver is bound to the PS/2 device, or a negative
233 * value if there is an error. 233 * value if there is an error.
234 */ 234 */
235static int __devinit xps2_of_probe(struct of_device *ofdev, 235static int __devinit xps2_of_probe(struct platform_device *ofdev,
236 const struct of_device_id *match) 236 const struct of_device_id *match)
237{ 237{
238 struct resource r_irq; /* Interrupt resources */ 238 struct resource r_irq; /* Interrupt resources */
@@ -332,7 +332,7 @@ failed1:
332 * if the driver module is being unloaded. It frees any resources allocated to 332 * if the driver module is being unloaded. It frees any resources allocated to
333 * the device. 333 * the device.
334 */ 334 */
335static int __devexit xps2_of_remove(struct of_device *of_dev) 335static int __devexit xps2_of_remove(struct platform_device *of_dev)
336{ 336{
337 struct device *dev = &of_dev->dev; 337 struct device *dev = &of_dev->dev;
338 struct xps2data *drvdata = dev_get_drvdata(dev); 338 struct xps2data *drvdata = dev_get_drvdata(dev);
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 61f35184f76c..0069d9703fda 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -628,4 +628,14 @@ config TOUCHSCREEN_TPS6507X
628 To compile this driver as a module, choose M here: the 628 To compile this driver as a module, choose M here: the
629 module will be called tps6507x_ts. 629 module will be called tps6507x_ts.
630 630
631config TOUCHSCREEN_STMPE
632 tristate "STMicroelectronics STMPE touchscreens"
633 depends on MFD_STMPE
634 help
635 Say Y here if you want support for STMicroelectronics
636 STMPE touchscreen controllers.
637
638 To compile this driver as a module, choose M here: the
639 module will be called stmpe-ts.
640
631endif 641endif
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index bd6f30b4ff70..28217e1dcafd 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o
36obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o 36obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o
37obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o 37obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o
38obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o 38obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o
39obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o
39obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o 40obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o
40obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o 41obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
41obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o 42obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
diff --git a/drivers/input/touchscreen/stmpe-ts.c b/drivers/input/touchscreen/stmpe-ts.c
new file mode 100644
index 000000000000..656148ec0027
--- /dev/null
+++ b/drivers/input/touchscreen/stmpe-ts.c
@@ -0,0 +1,397 @@
1/* STMicroelectronics STMPE811 Touchscreen Driver
2 *
3 * (C) 2010 Luotao Fu <l.fu@pengutronix.de>
4 * All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/sched.h>
16#include <linux/interrupt.h>
17#include <linux/init.h>
18#include <linux/device.h>
19#include <linux/platform_device.h>
20#include <linux/input.h>
21#include <linux/slab.h>
22#include <linux/delay.h>
23#include <linux/i2c.h>
24#include <linux/workqueue.h>
25
26#include <linux/mfd/stmpe.h>
27
28/* Register layouts and functionalities are identical on all stmpexxx variants
29 * with touchscreen controller
30 */
31#define STMPE_REG_INT_STA 0x0B
32#define STMPE_REG_ADC_CTRL1 0x20
33#define STMPE_REG_ADC_CTRL2 0x21
34#define STMPE_REG_TSC_CTRL 0x40
35#define STMPE_REG_TSC_CFG 0x41
36#define STMPE_REG_FIFO_TH 0x4A
37#define STMPE_REG_FIFO_STA 0x4B
38#define STMPE_REG_FIFO_SIZE 0x4C
39#define STMPE_REG_TSC_DATA_XYZ 0x52
40#define STMPE_REG_TSC_FRACTION_Z 0x56
41#define STMPE_REG_TSC_I_DRIVE 0x58
42
43#define OP_MOD_XYZ 0
44
45#define STMPE_TSC_CTRL_TSC_EN (1<<0)
46
47#define STMPE_FIFO_STA_RESET (1<<0)
48
49#define STMPE_IRQ_TOUCH_DET 0
50
51#define SAMPLE_TIME(x) ((x & 0xf) << 4)
52#define MOD_12B(x) ((x & 0x1) << 3)
53#define REF_SEL(x) ((x & 0x1) << 1)
54#define ADC_FREQ(x) (x & 0x3)
55#define AVE_CTRL(x) ((x & 0x3) << 6)
56#define DET_DELAY(x) ((x & 0x7) << 3)
57#define SETTLING(x) (x & 0x7)
58#define FRACTION_Z(x) (x & 0x7)
59#define I_DRIVE(x) (x & 0x1)
60#define OP_MODE(x) ((x & 0x7) << 1)
61
62#define STMPE_TS_NAME "stmpe-ts"
63#define XY_MASK 0xfff
64
65struct stmpe_touch {
66 struct stmpe *stmpe;
67 struct input_dev *idev;
68 struct delayed_work work;
69 struct device *dev;
70 u8 sample_time;
71 u8 mod_12b;
72 u8 ref_sel;
73 u8 adc_freq;
74 u8 ave_ctrl;
75 u8 touch_det_delay;
76 u8 settling;
77 u8 fraction_z;
78 u8 i_drive;
79};
80
81static int __stmpe_reset_fifo(struct stmpe *stmpe)
82{
83 int ret;
84
85 ret = stmpe_set_bits(stmpe, STMPE_REG_FIFO_STA,
86 STMPE_FIFO_STA_RESET, STMPE_FIFO_STA_RESET);
87 if (ret)
88 return ret;
89
90 return stmpe_set_bits(stmpe, STMPE_REG_FIFO_STA,
91 STMPE_FIFO_STA_RESET, 0);
92}
93
94static void stmpe_work(struct work_struct *work)
95{
96 int int_sta;
97 u32 timeout = 40;
98
99 struct stmpe_touch *ts =
100 container_of(work, struct stmpe_touch, work.work);
101
102 int_sta = stmpe_reg_read(ts->stmpe, STMPE_REG_INT_STA);
103
104 /*
105 * touch_det sometimes get desasserted or just get stuck. This appears
106 * to be a silicon bug, We still have to clearify this with the
107 * manufacture. As a workaround We release the key anyway if the
108 * touch_det keeps coming in after 4ms, while the FIFO contains no value
109 * during the whole time.
110 */
111 while ((int_sta & (1 << STMPE_IRQ_TOUCH_DET)) && (timeout > 0)) {
112 timeout--;
113 int_sta = stmpe_reg_read(ts->stmpe, STMPE_REG_INT_STA);
114 udelay(100);
115 }
116
117 /* reset the FIFO before we report release event */
118 __stmpe_reset_fifo(ts->stmpe);
119
120 input_report_abs(ts->idev, ABS_PRESSURE, 0);
121 input_sync(ts->idev);
122}
123
124static irqreturn_t stmpe_ts_handler(int irq, void *data)
125{
126 u8 data_set[4];
127 int x, y, z;
128 struct stmpe_touch *ts = data;
129
130 /*
131 * Cancel scheduled polling for release if we have new value
132 * available. Wait if the polling is already running.
133 */
134 cancel_delayed_work_sync(&ts->work);
135
136 /*
137 * The FIFO sometimes just crashes and stops generating interrupts. This
138 * appears to be a silicon bug. We still have to clearify this with
139 * the manufacture. As a workaround we disable the TSC while we are
140 * collecting data and flush the FIFO after reading
141 */
142 stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
143 STMPE_TSC_CTRL_TSC_EN, 0);
144
145 stmpe_block_read(ts->stmpe, STMPE_REG_TSC_DATA_XYZ, 4, data_set);
146
147 x = (data_set[0] << 4) | (data_set[1] >> 4);
148 y = ((data_set[1] & 0xf) << 8) | data_set[2];
149 z = data_set[3];
150
151 input_report_abs(ts->idev, ABS_X, x);
152 input_report_abs(ts->idev, ABS_Y, y);
153 input_report_abs(ts->idev, ABS_PRESSURE, z);
154 input_sync(ts->idev);
155
156 /* flush the FIFO after we have read out our values. */
157 __stmpe_reset_fifo(ts->stmpe);
158
159 /* reenable the tsc */
160 stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
161 STMPE_TSC_CTRL_TSC_EN, STMPE_TSC_CTRL_TSC_EN);
162
163 /* start polling for touch_det to detect release */
164 schedule_delayed_work(&ts->work, HZ / 50);
165
166 return IRQ_HANDLED;
167}
168
169static int __devinit stmpe_init_hw(struct stmpe_touch *ts)
170{
171 int ret;
172 u8 adc_ctrl1, adc_ctrl1_mask, tsc_cfg, tsc_cfg_mask;
173 struct stmpe *stmpe = ts->stmpe;
174 struct device *dev = ts->dev;
175
176 ret = stmpe_enable(stmpe, STMPE_BLOCK_TOUCHSCREEN | STMPE_BLOCK_ADC);
177 if (ret) {
178 dev_err(dev, "Could not enable clock for ADC and TS\n");
179 return ret;
180 }
181
182 adc_ctrl1 = SAMPLE_TIME(ts->sample_time) | MOD_12B(ts->mod_12b) |
183 REF_SEL(ts->ref_sel);
184 adc_ctrl1_mask = SAMPLE_TIME(0xff) | MOD_12B(0xff) | REF_SEL(0xff);
185
186 ret = stmpe_set_bits(stmpe, STMPE_REG_ADC_CTRL1,
187 adc_ctrl1_mask, adc_ctrl1);
188 if (ret) {
189 dev_err(dev, "Could not setup ADC\n");
190 return ret;
191 }
192
193 ret = stmpe_set_bits(stmpe, STMPE_REG_ADC_CTRL2,
194 ADC_FREQ(0xff), ADC_FREQ(ts->adc_freq));
195 if (ret) {
196 dev_err(dev, "Could not setup ADC\n");
197 return ret;
198 }
199
200 tsc_cfg = AVE_CTRL(ts->ave_ctrl) | DET_DELAY(ts->touch_det_delay) |
201 SETTLING(ts->settling);
202 tsc_cfg_mask = AVE_CTRL(0xff) | DET_DELAY(0xff) | SETTLING(0xff);
203
204 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_CFG, tsc_cfg_mask, tsc_cfg);
205 if (ret) {
206 dev_err(dev, "Could not config touch\n");
207 return ret;
208 }
209
210 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_FRACTION_Z,
211 FRACTION_Z(0xff), FRACTION_Z(ts->fraction_z));
212 if (ret) {
213 dev_err(dev, "Could not config touch\n");
214 return ret;
215 }
216
217 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_I_DRIVE,
218 I_DRIVE(0xff), I_DRIVE(ts->i_drive));
219 if (ret) {
220 dev_err(dev, "Could not config touch\n");
221 return ret;
222 }
223
224 /* set FIFO to 1 for single point reading */
225 ret = stmpe_reg_write(stmpe, STMPE_REG_FIFO_TH, 1);
226 if (ret) {
227 dev_err(dev, "Could not set FIFO\n");
228 return ret;
229 }
230
231 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_CTRL,
232 OP_MODE(0xff), OP_MODE(OP_MOD_XYZ));
233 if (ret) {
234 dev_err(dev, "Could not set mode\n");
235 return ret;
236 }
237
238 return 0;
239}
240
241static int stmpe_ts_open(struct input_dev *dev)
242{
243 struct stmpe_touch *ts = input_get_drvdata(dev);
244 int ret = 0;
245
246 ret = __stmpe_reset_fifo(ts->stmpe);
247 if (ret)
248 return ret;
249
250 return stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
251 STMPE_TSC_CTRL_TSC_EN, STMPE_TSC_CTRL_TSC_EN);
252}
253
254static void stmpe_ts_close(struct input_dev *dev)
255{
256 struct stmpe_touch *ts = input_get_drvdata(dev);
257
258 cancel_delayed_work_sync(&ts->work);
259
260 stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
261 STMPE_TSC_CTRL_TSC_EN, 0);
262}
263
264static int __devinit stmpe_input_probe(struct platform_device *pdev)
265{
266 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
267 struct stmpe_platform_data *pdata = stmpe->pdata;
268 struct stmpe_touch *ts;
269 struct input_dev *idev;
270 struct stmpe_ts_platform_data *ts_pdata = NULL;
271 int ret = 0;
272 int ts_irq;
273
274 ts_irq = platform_get_irq_byname(pdev, "FIFO_TH");
275 if (ts_irq < 0)
276 return ts_irq;
277
278 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
279 if (!ts)
280 goto err_out;
281
282 idev = input_allocate_device();
283 if (!idev)
284 goto err_free_ts;
285
286 platform_set_drvdata(pdev, ts);
287 ts->stmpe = stmpe;
288 ts->idev = idev;
289 ts->dev = &pdev->dev;
290
291 if (pdata)
292 ts_pdata = pdata->ts;
293
294 if (ts_pdata) {
295 ts->sample_time = ts_pdata->sample_time;
296 ts->mod_12b = ts_pdata->mod_12b;
297 ts->ref_sel = ts_pdata->ref_sel;
298 ts->adc_freq = ts_pdata->adc_freq;
299 ts->ave_ctrl = ts_pdata->ave_ctrl;
300 ts->touch_det_delay = ts_pdata->touch_det_delay;
301 ts->settling = ts_pdata->settling;
302 ts->fraction_z = ts_pdata->fraction_z;
303 ts->i_drive = ts_pdata->i_drive;
304 }
305
306 INIT_DELAYED_WORK(&ts->work, stmpe_work);
307
308 ret = request_threaded_irq(ts_irq, NULL, stmpe_ts_handler,
309 IRQF_ONESHOT, STMPE_TS_NAME, ts);
310 if (ret) {
311 dev_err(&pdev->dev, "Failed to request IRQ %d\n", ts_irq);
312 goto err_free_input;
313 }
314
315 ret = stmpe_init_hw(ts);
316 if (ret)
317 goto err_free_irq;
318
319 idev->name = STMPE_TS_NAME;
320 idev->id.bustype = BUS_I2C;
321 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
322 idev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
323
324 idev->open = stmpe_ts_open;
325 idev->close = stmpe_ts_close;
326
327 input_set_drvdata(idev, ts);
328
329 input_set_abs_params(idev, ABS_X, 0, XY_MASK, 0, 0);
330 input_set_abs_params(idev, ABS_Y, 0, XY_MASK, 0, 0);
331 input_set_abs_params(idev, ABS_PRESSURE, 0x0, 0xff, 0, 0);
332
333 ret = input_register_device(idev);
334 if (ret) {
335 dev_err(&pdev->dev, "Could not register input device\n");
336 goto err_free_irq;
337 }
338
339 return ret;
340
341err_free_irq:
342 free_irq(ts_irq, ts);
343err_free_input:
344 input_free_device(idev);
345 platform_set_drvdata(pdev, NULL);
346err_free_ts:
347 kfree(ts);
348err_out:
349 return ret;
350}
351
352static int __devexit stmpe_ts_remove(struct platform_device *pdev)
353{
354 struct stmpe_touch *ts = platform_get_drvdata(pdev);
355 unsigned int ts_irq = platform_get_irq_byname(pdev, "FIFO_TH");
356
357 stmpe_disable(ts->stmpe, STMPE_BLOCK_TOUCHSCREEN);
358
359 free_irq(ts_irq, ts);
360
361 platform_set_drvdata(pdev, NULL);
362
363 input_unregister_device(ts->idev);
364 input_free_device(ts->idev);
365
366 kfree(ts);
367
368 return 0;
369}
370
371static struct platform_driver stmpe_ts_driver = {
372 .driver = {
373 .name = STMPE_TS_NAME,
374 .owner = THIS_MODULE,
375 },
376 .probe = stmpe_input_probe,
377 .remove = __devexit_p(stmpe_ts_remove),
378};
379
380static int __init stmpe_ts_init(void)
381{
382 return platform_driver_register(&stmpe_ts_driver);
383}
384
385module_init(stmpe_ts_init);
386
387static void __exit stmpe_ts_exit(void)
388{
389 platform_driver_unregister(&stmpe_ts_driver);
390}
391
392module_exit(stmpe_ts_exit);
393
394MODULE_AUTHOR("Luotao Fu <l.fu@pengutronix.de>");
395MODULE_DESCRIPTION("STMPEXXX touchscreen driver");
396MODULE_LICENSE("GPL");
397MODULE_ALIAS("platform:" STMPE_TS_NAME);
diff --git a/drivers/isdn/hardware/avm/c4.c b/drivers/isdn/hardware/avm/c4.c
index 7715d3242ec8..d3530f6e8115 100644
--- a/drivers/isdn/hardware/avm/c4.c
+++ b/drivers/isdn/hardware/avm/c4.c
@@ -1273,6 +1273,7 @@ static int __devinit c4_probe(struct pci_dev *dev,
1273 if (retval != 0) { 1273 if (retval != 0) {
1274 printk(KERN_ERR "c4: no AVM-C%d at i/o %#x, irq %d detected, mem %#x\n", 1274 printk(KERN_ERR "c4: no AVM-C%d at i/o %#x, irq %d detected, mem %#x\n",
1275 nr, param.port, param.irq, param.membase); 1275 nr, param.port, param.irq, param.membase);
1276 pci_disable_device(dev);
1276 return -ENODEV; 1277 return -ENODEV;
1277 } 1278 }
1278 return 0; 1279 return 0;
diff --git a/drivers/isdn/hardware/avm/t1pci.c b/drivers/isdn/hardware/avm/t1pci.c
index 5a3f83098018..a79eb5afb92d 100644
--- a/drivers/isdn/hardware/avm/t1pci.c
+++ b/drivers/isdn/hardware/avm/t1pci.c
@@ -210,6 +210,7 @@ static int __devinit t1pci_probe(struct pci_dev *dev,
210 if (retval != 0) { 210 if (retval != 0) {
211 printk(KERN_ERR "t1pci: no AVM-T1-PCI at i/o %#x, irq %d detected, mem %#x\n", 211 printk(KERN_ERR "t1pci: no AVM-T1-PCI at i/o %#x, irq %d detected, mem %#x\n",
212 param.port, param.irq, param.membase); 212 param.port, param.irq, param.membase);
213 pci_disable_device(dev);
213 return -ENODEV; 214 return -ENODEV;
214 } 215 }
215 return 0; 216 return 0;
diff --git a/drivers/isdn/hardware/mISDN/mISDNinfineon.c b/drivers/isdn/hardware/mISDN/mISDNinfineon.c
index d2dd61d65d51..af25e1f3efd4 100644
--- a/drivers/isdn/hardware/mISDN/mISDNinfineon.c
+++ b/drivers/isdn/hardware/mISDN/mISDNinfineon.c
@@ -1094,6 +1094,7 @@ inf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1094 pr_info("mISDN: do not have informations about adapter at %s\n", 1094 pr_info("mISDN: do not have informations about adapter at %s\n",
1095 pci_name(pdev)); 1095 pci_name(pdev));
1096 kfree(card); 1096 kfree(card);
1097 pci_disable_device(pdev);
1097 return -EINVAL; 1098 return -EINVAL;
1098 } else 1099 } else
1099 pr_notice("mISDN: found adapter %s at %s\n", 1100 pr_notice("mISDN: found adapter %s at %s\n",
@@ -1103,7 +1104,7 @@ inf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1103 pci_set_drvdata(pdev, card); 1104 pci_set_drvdata(pdev, card);
1104 err = setup_instance(card); 1105 err = setup_instance(card);
1105 if (err) { 1106 if (err) {
1106 pci_disable_device(card->pdev); 1107 pci_disable_device(pdev);
1107 kfree(card); 1108 kfree(card);
1108 pci_set_drvdata(pdev, NULL); 1109 pci_set_drvdata(pdev, NULL);
1109 } else if (ent->driver_data == INF_SCT_1) { 1110 } else if (ent->driver_data == INF_SCT_1) {
@@ -1114,6 +1115,7 @@ inf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1114 sc = kzalloc(sizeof(struct inf_hw), GFP_KERNEL); 1115 sc = kzalloc(sizeof(struct inf_hw), GFP_KERNEL);
1115 if (!sc) { 1116 if (!sc) {
1116 release_card(card); 1117 release_card(card);
1118 pci_disable_device(pdev);
1117 return -ENOMEM; 1119 return -ENOMEM;
1118 } 1120 }
1119 sc->irq = card->irq; 1121 sc->irq = card->irq;
@@ -1121,6 +1123,7 @@ inf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1121 sc->ci = card->ci + i; 1123 sc->ci = card->ci + i;
1122 err = setup_instance(sc); 1124 err = setup_instance(sc);
1123 if (err) { 1125 if (err) {
1126 pci_disable_device(pdev);
1124 kfree(sc); 1127 kfree(sc);
1125 release_card(card); 1128 release_card(card);
1126 break; 1129 break;
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index cc22eeefa10b..ea57e05d08f3 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -224,7 +224,7 @@ struct gpio_led_of_platform_data {
224 struct gpio_led_data led_data[]; 224 struct gpio_led_data led_data[];
225}; 225};
226 226
227static int __devinit of_gpio_leds_probe(struct of_device *ofdev, 227static int __devinit of_gpio_leds_probe(struct platform_device *ofdev,
228 const struct of_device_id *match) 228 const struct of_device_id *match)
229{ 229{
230 struct device_node *np = ofdev->dev.of_node, *child; 230 struct device_node *np = ofdev->dev.of_node, *child;
@@ -283,7 +283,7 @@ err:
283 return ret; 283 return ret;
284} 284}
285 285
286static int __devexit of_gpio_leds_remove(struct of_device *ofdev) 286static int __devexit of_gpio_leds_remove(struct platform_device *ofdev)
287{ 287{
288 struct gpio_led_of_platform_data *pdata = dev_get_drvdata(&ofdev->dev); 288 struct gpio_led_of_platform_data *pdata = dev_get_drvdata(&ofdev->dev);
289 int i; 289 int i;
diff --git a/drivers/macintosh/macio_sysfs.c b/drivers/macintosh/macio_sysfs.c
index 6024038a5b9d..8eb40afbd0f5 100644
--- a/drivers/macintosh/macio_sysfs.c
+++ b/drivers/macintosh/macio_sysfs.c
@@ -15,7 +15,7 @@ field##_show (struct device *dev, struct device_attribute *attr, \
15static ssize_t 15static ssize_t
16compatible_show (struct device *dev, struct device_attribute *attr, char *buf) 16compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
17{ 17{
18 struct of_device *of; 18 struct platform_device *of;
19 const char *compat; 19 const char *compat;
20 int cplen; 20 int cplen;
21 int length = 0; 21 int length = 0;
@@ -52,9 +52,9 @@ static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
52static ssize_t devspec_show(struct device *dev, 52static ssize_t devspec_show(struct device *dev,
53 struct device_attribute *attr, char *buf) 53 struct device_attribute *attr, char *buf)
54{ 54{
55 struct of_device *ofdev; 55 struct platform_device *ofdev;
56 56
57 ofdev = to_of_device(dev); 57 ofdev = to_platform_device(dev);
58 return sprintf(buf, "%s\n", ofdev->dev.of_node->full_name); 58 return sprintf(buf, "%s\n", ofdev->dev.of_node->full_name);
59} 59}
60 60
diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index 2506c957712e..e58c3d33e035 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -75,7 +75,7 @@ struct smu_cmd_buf {
75struct smu_device { 75struct smu_device {
76 spinlock_t lock; 76 spinlock_t lock;
77 struct device_node *of_node; 77 struct device_node *of_node;
78 struct of_device *of_dev; 78 struct platform_device *of_dev;
79 int doorbell; /* doorbell gpio */ 79 int doorbell; /* doorbell gpio */
80 u32 __iomem *db_buf; /* doorbell buffer */ 80 u32 __iomem *db_buf; /* doorbell buffer */
81 struct device_node *db_node; 81 struct device_node *db_node;
@@ -645,7 +645,7 @@ static void smu_expose_childs(struct work_struct *unused)
645 645
646static DECLARE_WORK(smu_expose_childs_work, smu_expose_childs); 646static DECLARE_WORK(smu_expose_childs_work, smu_expose_childs);
647 647
648static int smu_platform_probe(struct of_device* dev, 648static int smu_platform_probe(struct platform_device* dev,
649 const struct of_device_id *match) 649 const struct of_device_id *match)
650{ 650{
651 if (!smu) 651 if (!smu)
@@ -695,7 +695,7 @@ static int __init smu_init_sysfs(void)
695 695
696device_initcall(smu_init_sysfs); 696device_initcall(smu_init_sysfs);
697 697
698struct of_device *smu_get_ofdev(void) 698struct platform_device *smu_get_ofdev(void)
699{ 699{
700 if (!smu) 700 if (!smu)
701 return NULL; 701 return NULL;
diff --git a/drivers/macintosh/therm_adt746x.c b/drivers/macintosh/therm_adt746x.c
index c42eeb43042d..d0d221332db0 100644
--- a/drivers/macintosh/therm_adt746x.c
+++ b/drivers/macintosh/therm_adt746x.c
@@ -84,7 +84,7 @@ struct thermostat {
84 84
85static enum {ADT7460, ADT7467} therm_type; 85static enum {ADT7460, ADT7467} therm_type;
86static int therm_bus, therm_address; 86static int therm_bus, therm_address;
87static struct of_device * of_dev; 87static struct platform_device * of_dev;
88static struct thermostat* thermostat; 88static struct thermostat* thermostat;
89static struct task_struct *thread_therm = NULL; 89static struct task_struct *thread_therm = NULL;
90 90
diff --git a/drivers/macintosh/therm_pm72.c b/drivers/macintosh/therm_pm72.c
index e60605bd0ea9..44549272333c 100644
--- a/drivers/macintosh/therm_pm72.c
+++ b/drivers/macintosh/therm_pm72.c
@@ -148,7 +148,7 @@
148 * Driver statics 148 * Driver statics
149 */ 149 */
150 150
151static struct of_device * of_dev; 151static struct platform_device * of_dev;
152static struct i2c_adapter * u3_0; 152static struct i2c_adapter * u3_0;
153static struct i2c_adapter * u3_1; 153static struct i2c_adapter * u3_1;
154static struct i2c_adapter * k2; 154static struct i2c_adapter * k2;
@@ -2210,7 +2210,7 @@ static void fcu_lookup_fans(struct device_node *fcu_node)
2210 } 2210 }
2211} 2211}
2212 2212
2213static int fcu_of_probe(struct of_device* dev, const struct of_device_id *match) 2213static int fcu_of_probe(struct platform_device* dev, const struct of_device_id *match)
2214{ 2214{
2215 state = state_detached; 2215 state = state_detached;
2216 2216
@@ -2221,7 +2221,7 @@ static int fcu_of_probe(struct of_device* dev, const struct of_device_id *match)
2221 return i2c_add_driver(&therm_pm72_driver); 2221 return i2c_add_driver(&therm_pm72_driver);
2222} 2222}
2223 2223
2224static int fcu_of_remove(struct of_device* dev) 2224static int fcu_of_remove(struct platform_device* dev)
2225{ 2225{
2226 i2c_del_driver(&therm_pm72_driver); 2226 i2c_del_driver(&therm_pm72_driver);
2227 2227
diff --git a/drivers/macintosh/therm_windtunnel.c b/drivers/macintosh/therm_windtunnel.c
index 5c9367acf0cf..c89f396e4c53 100644
--- a/drivers/macintosh/therm_windtunnel.c
+++ b/drivers/macintosh/therm_windtunnel.c
@@ -52,7 +52,7 @@ static struct {
52 struct task_struct *poll_task; 52 struct task_struct *poll_task;
53 53
54 struct mutex lock; 54 struct mutex lock;
55 struct of_device *of_dev; 55 struct platform_device *of_dev;
56 56
57 struct i2c_client *thermostat; 57 struct i2c_client *thermostat;
58 struct i2c_client *fan; 58 struct i2c_client *fan;
@@ -322,10 +322,10 @@ do_attach( struct i2c_adapter *adapter )
322 322
323 memset(&info, 0, sizeof(struct i2c_board_info)); 323 memset(&info, 0, sizeof(struct i2c_board_info));
324 strlcpy(info.type, "therm_ds1775", I2C_NAME_SIZE); 324 strlcpy(info.type, "therm_ds1775", I2C_NAME_SIZE);
325 i2c_new_probed_device(adapter, &info, scan_ds1775); 325 i2c_new_probed_device(adapter, &info, scan_ds1775, NULL);
326 326
327 strlcpy(info.type, "therm_adm1030", I2C_NAME_SIZE); 327 strlcpy(info.type, "therm_adm1030", I2C_NAME_SIZE);
328 i2c_new_probed_device(adapter, &info, scan_adm1030); 328 i2c_new_probed_device(adapter, &info, scan_adm1030, NULL);
329 329
330 if( x.thermostat && x.fan ) { 330 if( x.thermostat && x.fan ) {
331 x.running = 1; 331 x.running = 1;
@@ -444,13 +444,13 @@ static struct i2c_driver g4fan_driver = {
444/************************************************************************/ 444/************************************************************************/
445 445
446static int 446static int
447therm_of_probe( struct of_device *dev, const struct of_device_id *match ) 447therm_of_probe( struct platform_device *dev, const struct of_device_id *match )
448{ 448{
449 return i2c_add_driver( &g4fan_driver ); 449 return i2c_add_driver( &g4fan_driver );
450} 450}
451 451
452static int 452static int
453therm_of_remove( struct of_device *dev ) 453therm_of_remove( struct platform_device *dev )
454{ 454{
455 i2c_del_driver( &g4fan_driver ); 455 i2c_del_driver( &g4fan_driver );
456 return 0; 456 return 0;
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 3bdbb6115702..368e8e98f705 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -107,11 +107,10 @@ struct crypt_config {
107 struct workqueue_struct *io_queue; 107 struct workqueue_struct *io_queue;
108 struct workqueue_struct *crypt_queue; 108 struct workqueue_struct *crypt_queue;
109 109
110 /* 110 char *cipher;
111 * crypto related data 111 char *cipher_mode;
112 */ 112
113 struct crypt_iv_operations *iv_gen_ops; 113 struct crypt_iv_operations *iv_gen_ops;
114 char *iv_mode;
115 union { 114 union {
116 struct iv_essiv_private essiv; 115 struct iv_essiv_private essiv;
117 struct iv_benbi_private benbi; 116 struct iv_benbi_private benbi;
@@ -135,8 +134,6 @@ struct crypt_config {
135 unsigned int dmreq_start; 134 unsigned int dmreq_start;
136 struct ablkcipher_request *req; 135 struct ablkcipher_request *req;
137 136
138 char cipher[CRYPTO_MAX_ALG_NAME];
139 char chainmode[CRYPTO_MAX_ALG_NAME];
140 struct crypto_ablkcipher *tfm; 137 struct crypto_ablkcipher *tfm;
141 unsigned long flags; 138 unsigned long flags;
142 unsigned int key_size; 139 unsigned int key_size;
@@ -999,82 +996,135 @@ static int crypt_wipe_key(struct crypt_config *cc)
999 return crypto_ablkcipher_setkey(cc->tfm, cc->key, cc->key_size); 996 return crypto_ablkcipher_setkey(cc->tfm, cc->key, cc->key_size);
1000} 997}
1001 998
1002/* 999static void crypt_dtr(struct dm_target *ti)
1003 * Construct an encryption mapping:
1004 * <cipher> <key> <iv_offset> <dev_path> <start>
1005 */
1006static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1007{ 1000{
1008 struct crypt_config *cc; 1001 struct crypt_config *cc = ti->private;
1009 struct crypto_ablkcipher *tfm;
1010 char *tmp;
1011 char *cipher;
1012 char *chainmode;
1013 char *ivmode;
1014 char *ivopts;
1015 unsigned int key_size;
1016 unsigned long long tmpll;
1017 1002
1018 if (argc != 5) { 1003 ti->private = NULL;
1019 ti->error = "Not enough arguments"; 1004
1005 if (!cc)
1006 return;
1007
1008 if (cc->io_queue)
1009 destroy_workqueue(cc->io_queue);
1010 if (cc->crypt_queue)
1011 destroy_workqueue(cc->crypt_queue);
1012
1013 if (cc->bs)
1014 bioset_free(cc->bs);
1015
1016 if (cc->page_pool)
1017 mempool_destroy(cc->page_pool);
1018 if (cc->req_pool)
1019 mempool_destroy(cc->req_pool);
1020 if (cc->io_pool)
1021 mempool_destroy(cc->io_pool);
1022
1023 if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
1024 cc->iv_gen_ops->dtr(cc);
1025
1026 if (cc->tfm && !IS_ERR(cc->tfm))
1027 crypto_free_ablkcipher(cc->tfm);
1028
1029 if (cc->dev)
1030 dm_put_device(ti, cc->dev);
1031
1032 kzfree(cc->cipher);
1033 kzfree(cc->cipher_mode);
1034
1035 /* Must zero key material before freeing */
1036 kzfree(cc);
1037}
1038
1039static int crypt_ctr_cipher(struct dm_target *ti,
1040 char *cipher_in, char *key)
1041{
1042 struct crypt_config *cc = ti->private;
1043 char *tmp, *cipher, *chainmode, *ivmode, *ivopts;
1044 char *cipher_api = NULL;
1045 int ret = -EINVAL;
1046
1047 /* Convert to crypto api definition? */
1048 if (strchr(cipher_in, '(')) {
1049 ti->error = "Bad cipher specification";
1020 return -EINVAL; 1050 return -EINVAL;
1021 } 1051 }
1022 1052
1023 tmp = argv[0]; 1053 /*
1054 * Legacy dm-crypt cipher specification
1055 * cipher-mode-iv:ivopts
1056 */
1057 tmp = cipher_in;
1024 cipher = strsep(&tmp, "-"); 1058 cipher = strsep(&tmp, "-");
1059
1060 cc->cipher = kstrdup(cipher, GFP_KERNEL);
1061 if (!cc->cipher)
1062 goto bad_mem;
1063
1064 if (tmp) {
1065 cc->cipher_mode = kstrdup(tmp, GFP_KERNEL);
1066 if (!cc->cipher_mode)
1067 goto bad_mem;
1068 }
1069
1025 chainmode = strsep(&tmp, "-"); 1070 chainmode = strsep(&tmp, "-");
1026 ivopts = strsep(&tmp, "-"); 1071 ivopts = strsep(&tmp, "-");
1027 ivmode = strsep(&ivopts, ":"); 1072 ivmode = strsep(&ivopts, ":");
1028 1073
1029 if (tmp) 1074 if (tmp)
1030 DMWARN("Unexpected additional cipher options"); 1075 DMWARN("Ignoring unexpected additional cipher options");
1031
1032 key_size = strlen(argv[1]) >> 1;
1033
1034 cc = kzalloc(sizeof(*cc) + key_size * sizeof(u8), GFP_KERNEL);
1035 if (cc == NULL) {
1036 ti->error =
1037 "Cannot allocate transparent encryption context";
1038 return -ENOMEM;
1039 }
1040 1076
1041 /* Compatibility mode for old dm-crypt cipher strings */ 1077 /* Compatibility mode for old dm-crypt mappings */
1042 if (!chainmode || (strcmp(chainmode, "plain") == 0 && !ivmode)) { 1078 if (!chainmode || (!strcmp(chainmode, "plain") && !ivmode)) {
1079 kfree(cc->cipher_mode);
1080 cc->cipher_mode = kstrdup("cbc-plain", GFP_KERNEL);
1043 chainmode = "cbc"; 1081 chainmode = "cbc";
1044 ivmode = "plain"; 1082 ivmode = "plain";
1045 } 1083 }
1046 1084
1047 if (strcmp(chainmode, "ecb") && !ivmode) { 1085 if (strcmp(chainmode, "ecb") && !ivmode) {
1048 ti->error = "This chaining mode requires an IV mechanism"; 1086 ti->error = "IV mechanism required";
1049 goto bad_cipher; 1087 return -EINVAL;
1050 } 1088 }
1051 1089
1052 if (snprintf(cc->cipher, CRYPTO_MAX_ALG_NAME, "%s(%s)", 1090 cipher_api = kmalloc(CRYPTO_MAX_ALG_NAME, GFP_KERNEL);
1053 chainmode, cipher) >= CRYPTO_MAX_ALG_NAME) { 1091 if (!cipher_api)
1054 ti->error = "Chain mode + cipher name is too long"; 1092 goto bad_mem;
1055 goto bad_cipher; 1093
1094 ret = snprintf(cipher_api, CRYPTO_MAX_ALG_NAME,
1095 "%s(%s)", chainmode, cipher);
1096 if (ret < 0) {
1097 kfree(cipher_api);
1098 goto bad_mem;
1056 } 1099 }
1057 1100
1058 tfm = crypto_alloc_ablkcipher(cc->cipher, 0, 0); 1101 /* Allocate cipher */
1059 if (IS_ERR(tfm)) { 1102 cc->tfm = crypto_alloc_ablkcipher(cipher_api, 0, 0);
1103 if (IS_ERR(cc->tfm)) {
1104 ret = PTR_ERR(cc->tfm);
1060 ti->error = "Error allocating crypto tfm"; 1105 ti->error = "Error allocating crypto tfm";
1061 goto bad_cipher; 1106 goto bad;
1062 } 1107 }
1063 1108
1064 strcpy(cc->cipher, cipher); 1109 /* Initialize and set key */
1065 strcpy(cc->chainmode, chainmode); 1110 ret = crypt_set_key(cc, key);
1066 cc->tfm = tfm; 1111 if (ret < 0) {
1067
1068 if (crypt_set_key(cc, argv[1]) < 0) {
1069 ti->error = "Error decoding and setting key"; 1112 ti->error = "Error decoding and setting key";
1070 goto bad_ivmode; 1113 goto bad;
1071 } 1114 }
1072 1115
1073 /* 1116 /* Initialize IV */
1074 * Choose ivmode. Valid modes: "plain", "essiv:<esshash>", "benbi". 1117 cc->iv_size = crypto_ablkcipher_ivsize(cc->tfm);
1075 * See comments at iv code 1118 if (cc->iv_size)
1076 */ 1119 /* at least a 64 bit sector number should fit in our buffer */
1120 cc->iv_size = max(cc->iv_size,
1121 (unsigned int)(sizeof(u64) / sizeof(u8)));
1122 else if (ivmode) {
1123 DMWARN("Selected cipher does not support IVs");
1124 ivmode = NULL;
1125 }
1077 1126
1127 /* Choose ivmode, see comments at iv code. */
1078 if (ivmode == NULL) 1128 if (ivmode == NULL)
1079 cc->iv_gen_ops = NULL; 1129 cc->iv_gen_ops = NULL;
1080 else if (strcmp(ivmode, "plain") == 0) 1130 else if (strcmp(ivmode, "plain") == 0)
@@ -1088,159 +1138,138 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1088 else if (strcmp(ivmode, "null") == 0) 1138 else if (strcmp(ivmode, "null") == 0)
1089 cc->iv_gen_ops = &crypt_iv_null_ops; 1139 cc->iv_gen_ops = &crypt_iv_null_ops;
1090 else { 1140 else {
1141 ret = -EINVAL;
1091 ti->error = "Invalid IV mode"; 1142 ti->error = "Invalid IV mode";
1092 goto bad_ivmode; 1143 goto bad;
1093 } 1144 }
1094 1145
1095 if (cc->iv_gen_ops && cc->iv_gen_ops->ctr && 1146 /* Allocate IV */
1096 cc->iv_gen_ops->ctr(cc, ti, ivopts) < 0) 1147 if (cc->iv_gen_ops && cc->iv_gen_ops->ctr) {
1097 goto bad_ivmode; 1148 ret = cc->iv_gen_ops->ctr(cc, ti, ivopts);
1098 1149 if (ret < 0) {
1099 if (cc->iv_gen_ops && cc->iv_gen_ops->init && 1150 ti->error = "Error creating IV";
1100 cc->iv_gen_ops->init(cc) < 0) { 1151 goto bad;
1101 ti->error = "Error initialising IV"; 1152 }
1102 goto bad_slab_pool;
1103 } 1153 }
1104 1154
1105 cc->iv_size = crypto_ablkcipher_ivsize(tfm); 1155 /* Initialize IV (set keys for ESSIV etc) */
1106 if (cc->iv_size) 1156 if (cc->iv_gen_ops && cc->iv_gen_ops->init) {
1107 /* at least a 64 bit sector number should fit in our buffer */ 1157 ret = cc->iv_gen_ops->init(cc);
1108 cc->iv_size = max(cc->iv_size, 1158 if (ret < 0) {
1109 (unsigned int)(sizeof(u64) / sizeof(u8))); 1159 ti->error = "Error initialising IV";
1110 else { 1160 goto bad;
1111 if (cc->iv_gen_ops) {
1112 DMWARN("Selected cipher does not support IVs");
1113 if (cc->iv_gen_ops->dtr)
1114 cc->iv_gen_ops->dtr(cc);
1115 cc->iv_gen_ops = NULL;
1116 } 1161 }
1117 } 1162 }
1118 1163
1164 ret = 0;
1165bad:
1166 kfree(cipher_api);
1167 return ret;
1168
1169bad_mem:
1170 ti->error = "Cannot allocate cipher strings";
1171 return -ENOMEM;
1172}
1173
1174/*
1175 * Construct an encryption mapping:
1176 * <cipher> <key> <iv_offset> <dev_path> <start>
1177 */
1178static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1179{
1180 struct crypt_config *cc;
1181 unsigned int key_size;
1182 unsigned long long tmpll;
1183 int ret;
1184
1185 if (argc != 5) {
1186 ti->error = "Not enough arguments";
1187 return -EINVAL;
1188 }
1189
1190 key_size = strlen(argv[1]) >> 1;
1191
1192 cc = kzalloc(sizeof(*cc) + key_size * sizeof(u8), GFP_KERNEL);
1193 if (!cc) {
1194 ti->error = "Cannot allocate encryption context";
1195 return -ENOMEM;
1196 }
1197
1198 ti->private = cc;
1199 ret = crypt_ctr_cipher(ti, argv[0], argv[1]);
1200 if (ret < 0)
1201 goto bad;
1202
1203 ret = -ENOMEM;
1119 cc->io_pool = mempool_create_slab_pool(MIN_IOS, _crypt_io_pool); 1204 cc->io_pool = mempool_create_slab_pool(MIN_IOS, _crypt_io_pool);
1120 if (!cc->io_pool) { 1205 if (!cc->io_pool) {
1121 ti->error = "Cannot allocate crypt io mempool"; 1206 ti->error = "Cannot allocate crypt io mempool";
1122 goto bad_slab_pool; 1207 goto bad;
1123 } 1208 }
1124 1209
1125 cc->dmreq_start = sizeof(struct ablkcipher_request); 1210 cc->dmreq_start = sizeof(struct ablkcipher_request);
1126 cc->dmreq_start += crypto_ablkcipher_reqsize(tfm); 1211 cc->dmreq_start += crypto_ablkcipher_reqsize(cc->tfm);
1127 cc->dmreq_start = ALIGN(cc->dmreq_start, crypto_tfm_ctx_alignment()); 1212 cc->dmreq_start = ALIGN(cc->dmreq_start, crypto_tfm_ctx_alignment());
1128 cc->dmreq_start += crypto_ablkcipher_alignmask(tfm) & 1213 cc->dmreq_start += crypto_ablkcipher_alignmask(cc->tfm) &
1129 ~(crypto_tfm_ctx_alignment() - 1); 1214 ~(crypto_tfm_ctx_alignment() - 1);
1130 1215
1131 cc->req_pool = mempool_create_kmalloc_pool(MIN_IOS, cc->dmreq_start + 1216 cc->req_pool = mempool_create_kmalloc_pool(MIN_IOS, cc->dmreq_start +
1132 sizeof(struct dm_crypt_request) + cc->iv_size); 1217 sizeof(struct dm_crypt_request) + cc->iv_size);
1133 if (!cc->req_pool) { 1218 if (!cc->req_pool) {
1134 ti->error = "Cannot allocate crypt request mempool"; 1219 ti->error = "Cannot allocate crypt request mempool";
1135 goto bad_req_pool; 1220 goto bad;
1136 } 1221 }
1137 cc->req = NULL; 1222 cc->req = NULL;
1138 1223
1139 cc->page_pool = mempool_create_page_pool(MIN_POOL_PAGES, 0); 1224 cc->page_pool = mempool_create_page_pool(MIN_POOL_PAGES, 0);
1140 if (!cc->page_pool) { 1225 if (!cc->page_pool) {
1141 ti->error = "Cannot allocate page mempool"; 1226 ti->error = "Cannot allocate page mempool";
1142 goto bad_page_pool; 1227 goto bad;
1143 } 1228 }
1144 1229
1145 cc->bs = bioset_create(MIN_IOS, 0); 1230 cc->bs = bioset_create(MIN_IOS, 0);
1146 if (!cc->bs) { 1231 if (!cc->bs) {
1147 ti->error = "Cannot allocate crypt bioset"; 1232 ti->error = "Cannot allocate crypt bioset";
1148 goto bad_bs; 1233 goto bad;
1149 } 1234 }
1150 1235
1236 ret = -EINVAL;
1151 if (sscanf(argv[2], "%llu", &tmpll) != 1) { 1237 if (sscanf(argv[2], "%llu", &tmpll) != 1) {
1152 ti->error = "Invalid iv_offset sector"; 1238 ti->error = "Invalid iv_offset sector";
1153 goto bad_device; 1239 goto bad;
1154 } 1240 }
1155 cc->iv_offset = tmpll; 1241 cc->iv_offset = tmpll;
1156 1242
1157 if (sscanf(argv[4], "%llu", &tmpll) != 1) {
1158 ti->error = "Invalid device sector";
1159 goto bad_device;
1160 }
1161 cc->start = tmpll;
1162
1163 if (dm_get_device(ti, argv[3], dm_table_get_mode(ti->table), &cc->dev)) { 1243 if (dm_get_device(ti, argv[3], dm_table_get_mode(ti->table), &cc->dev)) {
1164 ti->error = "Device lookup failed"; 1244 ti->error = "Device lookup failed";
1165 goto bad_device; 1245 goto bad;
1166 } 1246 }
1167 1247
1168 if (ivmode && cc->iv_gen_ops) { 1248 if (sscanf(argv[4], "%llu", &tmpll) != 1) {
1169 if (ivopts) 1249 ti->error = "Invalid device sector";
1170 *(ivopts - 1) = ':'; 1250 goto bad;
1171 cc->iv_mode = kmalloc(strlen(ivmode) + 1, GFP_KERNEL); 1251 }
1172 if (!cc->iv_mode) { 1252 cc->start = tmpll;
1173 ti->error = "Error kmallocing iv_mode string";
1174 goto bad_ivmode_string;
1175 }
1176 strcpy(cc->iv_mode, ivmode);
1177 } else
1178 cc->iv_mode = NULL;
1179 1253
1254 ret = -ENOMEM;
1180 cc->io_queue = create_singlethread_workqueue("kcryptd_io"); 1255 cc->io_queue = create_singlethread_workqueue("kcryptd_io");
1181 if (!cc->io_queue) { 1256 if (!cc->io_queue) {
1182 ti->error = "Couldn't create kcryptd io queue"; 1257 ti->error = "Couldn't create kcryptd io queue";
1183 goto bad_io_queue; 1258 goto bad;
1184 } 1259 }
1185 1260
1186 cc->crypt_queue = create_singlethread_workqueue("kcryptd"); 1261 cc->crypt_queue = create_singlethread_workqueue("kcryptd");
1187 if (!cc->crypt_queue) { 1262 if (!cc->crypt_queue) {
1188 ti->error = "Couldn't create kcryptd queue"; 1263 ti->error = "Couldn't create kcryptd queue";
1189 goto bad_crypt_queue; 1264 goto bad;
1190 } 1265 }
1191 1266
1192 ti->num_flush_requests = 1; 1267 ti->num_flush_requests = 1;
1193 ti->private = cc;
1194 return 0; 1268 return 0;
1195 1269
1196bad_crypt_queue: 1270bad:
1197 destroy_workqueue(cc->io_queue); 1271 crypt_dtr(ti);
1198bad_io_queue: 1272 return ret;
1199 kfree(cc->iv_mode);
1200bad_ivmode_string:
1201 dm_put_device(ti, cc->dev);
1202bad_device:
1203 bioset_free(cc->bs);
1204bad_bs:
1205 mempool_destroy(cc->page_pool);
1206bad_page_pool:
1207 mempool_destroy(cc->req_pool);
1208bad_req_pool:
1209 mempool_destroy(cc->io_pool);
1210bad_slab_pool:
1211 if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
1212 cc->iv_gen_ops->dtr(cc);
1213bad_ivmode:
1214 crypto_free_ablkcipher(tfm);
1215bad_cipher:
1216 /* Must zero key material before freeing */
1217 kzfree(cc);
1218 return -EINVAL;
1219}
1220
1221static void crypt_dtr(struct dm_target *ti)
1222{
1223 struct crypt_config *cc = (struct crypt_config *) ti->private;
1224
1225 destroy_workqueue(cc->io_queue);
1226 destroy_workqueue(cc->crypt_queue);
1227
1228 if (cc->req)
1229 mempool_free(cc->req, cc->req_pool);
1230
1231 bioset_free(cc->bs);
1232 mempool_destroy(cc->page_pool);
1233 mempool_destroy(cc->req_pool);
1234 mempool_destroy(cc->io_pool);
1235
1236 kfree(cc->iv_mode);
1237 if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
1238 cc->iv_gen_ops->dtr(cc);
1239 crypto_free_ablkcipher(cc->tfm);
1240 dm_put_device(ti, cc->dev);
1241
1242 /* Must zero key material before freeing */
1243 kzfree(cc);
1244} 1273}
1245 1274
1246static int crypt_map(struct dm_target *ti, struct bio *bio, 1275static int crypt_map(struct dm_target *ti, struct bio *bio,
@@ -1255,7 +1284,7 @@ static int crypt_map(struct dm_target *ti, struct bio *bio,
1255 return DM_MAPIO_REMAPPED; 1284 return DM_MAPIO_REMAPPED;
1256 } 1285 }
1257 1286
1258 io = crypt_io_alloc(ti, bio, bio->bi_sector - ti->begin); 1287 io = crypt_io_alloc(ti, bio, dm_target_offset(ti, bio->bi_sector));
1259 1288
1260 if (bio_data_dir(io->base_bio) == READ) 1289 if (bio_data_dir(io->base_bio) == READ)
1261 kcryptd_queue_io(io); 1290 kcryptd_queue_io(io);
@@ -1268,7 +1297,7 @@ static int crypt_map(struct dm_target *ti, struct bio *bio,
1268static int crypt_status(struct dm_target *ti, status_type_t type, 1297static int crypt_status(struct dm_target *ti, status_type_t type,
1269 char *result, unsigned int maxlen) 1298 char *result, unsigned int maxlen)
1270{ 1299{
1271 struct crypt_config *cc = (struct crypt_config *) ti->private; 1300 struct crypt_config *cc = ti->private;
1272 unsigned int sz = 0; 1301 unsigned int sz = 0;
1273 1302
1274 switch (type) { 1303 switch (type) {
@@ -1277,11 +1306,10 @@ static int crypt_status(struct dm_target *ti, status_type_t type,
1277 break; 1306 break;
1278 1307
1279 case STATUSTYPE_TABLE: 1308 case STATUSTYPE_TABLE:
1280 if (cc->iv_mode) 1309 if (cc->cipher_mode)
1281 DMEMIT("%s-%s-%s ", cc->cipher, cc->chainmode, 1310 DMEMIT("%s-%s ", cc->cipher, cc->cipher_mode);
1282 cc->iv_mode);
1283 else 1311 else
1284 DMEMIT("%s-%s ", cc->cipher, cc->chainmode); 1312 DMEMIT("%s ", cc->cipher);
1285 1313
1286 if (cc->key_size > 0) { 1314 if (cc->key_size > 0) {
1287 if ((maxlen - sz) < ((cc->key_size << 1) + 1)) 1315 if ((maxlen - sz) < ((cc->key_size << 1) + 1))
@@ -1378,7 +1406,7 @@ static int crypt_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
1378 return max_size; 1406 return max_size;
1379 1407
1380 bvm->bi_bdev = cc->dev->bdev; 1408 bvm->bi_bdev = cc->dev->bdev;
1381 bvm->bi_sector = cc->start + bvm->bi_sector - ti->begin; 1409 bvm->bi_sector = cc->start + dm_target_offset(ti, bvm->bi_sector);
1382 1410
1383 return min(max_size, q->merge_bvec_fn(q, bvm, biovec)); 1411 return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
1384} 1412}
diff --git a/drivers/md/dm-delay.c b/drivers/md/dm-delay.c
index 852052880d7a..baa11912cc94 100644
--- a/drivers/md/dm-delay.c
+++ b/drivers/md/dm-delay.c
@@ -198,6 +198,7 @@ out:
198 atomic_set(&dc->may_delay, 1); 198 atomic_set(&dc->may_delay, 1);
199 199
200 ti->num_flush_requests = 1; 200 ti->num_flush_requests = 1;
201 ti->num_discard_requests = 1;
201 ti->private = dc; 202 ti->private = dc;
202 return 0; 203 return 0;
203 204
@@ -281,14 +282,13 @@ static int delay_map(struct dm_target *ti, struct bio *bio,
281 bio->bi_bdev = dc->dev_write->bdev; 282 bio->bi_bdev = dc->dev_write->bdev;
282 if (bio_sectors(bio)) 283 if (bio_sectors(bio))
283 bio->bi_sector = dc->start_write + 284 bio->bi_sector = dc->start_write +
284 (bio->bi_sector - ti->begin); 285 dm_target_offset(ti, bio->bi_sector);
285 286
286 return delay_bio(dc, dc->write_delay, bio); 287 return delay_bio(dc, dc->write_delay, bio);
287 } 288 }
288 289
289 bio->bi_bdev = dc->dev_read->bdev; 290 bio->bi_bdev = dc->dev_read->bdev;
290 bio->bi_sector = dc->start_read + 291 bio->bi_sector = dc->start_read + dm_target_offset(ti, bio->bi_sector);
291 (bio->bi_sector - ti->begin);
292 292
293 return delay_bio(dc, dc->read_delay, bio); 293 return delay_bio(dc, dc->read_delay, bio);
294} 294}
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c
index 2b7907b6dd09..0bdb201c2c2a 100644
--- a/drivers/md/dm-exception-store.c
+++ b/drivers/md/dm-exception-store.c
@@ -173,7 +173,9 @@ int dm_exception_store_set_chunk_size(struct dm_exception_store *store,
173 173
174 /* Validate the chunk size against the device block size */ 174 /* Validate the chunk size against the device block size */
175 if (chunk_size % 175 if (chunk_size %
176 (bdev_logical_block_size(dm_snap_cow(store->snap)->bdev) >> 9)) { 176 (bdev_logical_block_size(dm_snap_cow(store->snap)->bdev) >> 9) ||
177 chunk_size %
178 (bdev_logical_block_size(dm_snap_origin(store->snap)->bdev) >> 9)) {
177 *error = "Chunk size is not a multiple of device blocksize"; 179 *error = "Chunk size is not a multiple of device blocksize";
178 return -EINVAL; 180 return -EINVAL;
179 } 181 }
diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h
index e8dfa06af3ba..0b2536247cf5 100644
--- a/drivers/md/dm-exception-store.h
+++ b/drivers/md/dm-exception-store.h
@@ -126,8 +126,9 @@ struct dm_exception_store {
126}; 126};
127 127
128/* 128/*
129 * Obtain the cow device used by a given snapshot. 129 * Obtain the origin or cow device used by a given snapshot.
130 */ 130 */
131struct dm_dev *dm_snap_origin(struct dm_snapshot *snap);
131struct dm_dev *dm_snap_cow(struct dm_snapshot *snap); 132struct dm_dev *dm_snap_cow(struct dm_snapshot *snap);
132 133
133/* 134/*
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index d7500e1c26f2..3e39193e5036 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -249,55 +249,66 @@ static void __hash_remove(struct hash_cell *hc)
249 249
250static void dm_hash_remove_all(int keep_open_devices) 250static void dm_hash_remove_all(int keep_open_devices)
251{ 251{
252 int i, dev_skipped, dev_removed; 252 int i, dev_skipped;
253 struct hash_cell *hc; 253 struct hash_cell *hc;
254 struct list_head *tmp, *n; 254 struct mapped_device *md;
255
256retry:
257 dev_skipped = 0;
255 258
256 down_write(&_hash_lock); 259 down_write(&_hash_lock);
257 260
258retry:
259 dev_skipped = dev_removed = 0;
260 for (i = 0; i < NUM_BUCKETS; i++) { 261 for (i = 0; i < NUM_BUCKETS; i++) {
261 list_for_each_safe (tmp, n, _name_buckets + i) { 262 list_for_each_entry(hc, _name_buckets + i, name_list) {
262 hc = list_entry(tmp, struct hash_cell, name_list); 263 md = hc->md;
264 dm_get(md);
263 265
264 if (keep_open_devices && 266 if (keep_open_devices && dm_lock_for_deletion(md)) {
265 dm_lock_for_deletion(hc->md)) { 267 dm_put(md);
266 dev_skipped++; 268 dev_skipped++;
267 continue; 269 continue;
268 } 270 }
271
269 __hash_remove(hc); 272 __hash_remove(hc);
270 dev_removed = 1;
271 }
272 }
273 273
274 /* 274 up_write(&_hash_lock);
275 * Some mapped devices may be using other mapped devices, so if any
276 * still exist, repeat until we make no further progress.
277 */
278 if (dev_skipped) {
279 if (dev_removed)
280 goto retry;
281 275
282 DMWARN("remove_all left %d open device(s)", dev_skipped); 276 dm_put(md);
277 if (likely(keep_open_devices))
278 dm_destroy(md);
279 else
280 dm_destroy_immediate(md);
281
282 /*
283 * Some mapped devices may be using other mapped
284 * devices, so repeat until we make no further
285 * progress. If a new mapped device is created
286 * here it will also get removed.
287 */
288 goto retry;
289 }
283 } 290 }
284 291
285 up_write(&_hash_lock); 292 up_write(&_hash_lock);
293
294 if (dev_skipped)
295 DMWARN("remove_all left %d open device(s)", dev_skipped);
286} 296}
287 297
288static int dm_hash_rename(uint32_t cookie, uint32_t *flags, const char *old, 298static struct mapped_device *dm_hash_rename(struct dm_ioctl *param,
289 const char *new) 299 const char *new)
290{ 300{
291 char *new_name, *old_name; 301 char *new_name, *old_name;
292 struct hash_cell *hc; 302 struct hash_cell *hc;
293 struct dm_table *table; 303 struct dm_table *table;
304 struct mapped_device *md;
294 305
295 /* 306 /*
296 * duplicate new. 307 * duplicate new.
297 */ 308 */
298 new_name = kstrdup(new, GFP_KERNEL); 309 new_name = kstrdup(new, GFP_KERNEL);
299 if (!new_name) 310 if (!new_name)
300 return -ENOMEM; 311 return ERR_PTR(-ENOMEM);
301 312
302 down_write(&_hash_lock); 313 down_write(&_hash_lock);
303 314
@@ -306,24 +317,24 @@ static int dm_hash_rename(uint32_t cookie, uint32_t *flags, const char *old,
306 */ 317 */
307 hc = __get_name_cell(new); 318 hc = __get_name_cell(new);
308 if (hc) { 319 if (hc) {
309 DMWARN("asked to rename to an already existing name %s -> %s", 320 DMWARN("asked to rename to an already-existing name %s -> %s",
310 old, new); 321 param->name, new);
311 dm_put(hc->md); 322 dm_put(hc->md);
312 up_write(&_hash_lock); 323 up_write(&_hash_lock);
313 kfree(new_name); 324 kfree(new_name);
314 return -EBUSY; 325 return ERR_PTR(-EBUSY);
315 } 326 }
316 327
317 /* 328 /*
318 * Is there such a device as 'old' ? 329 * Is there such a device as 'old' ?
319 */ 330 */
320 hc = __get_name_cell(old); 331 hc = __get_name_cell(param->name);
321 if (!hc) { 332 if (!hc) {
322 DMWARN("asked to rename a non existent device %s -> %s", 333 DMWARN("asked to rename a non-existent device %s -> %s",
323 old, new); 334 param->name, new);
324 up_write(&_hash_lock); 335 up_write(&_hash_lock);
325 kfree(new_name); 336 kfree(new_name);
326 return -ENXIO; 337 return ERR_PTR(-ENXIO);
327 } 338 }
328 339
329 /* 340 /*
@@ -345,13 +356,14 @@ static int dm_hash_rename(uint32_t cookie, uint32_t *flags, const char *old,
345 dm_table_put(table); 356 dm_table_put(table);
346 } 357 }
347 358
348 if (!dm_kobject_uevent(hc->md, KOBJ_CHANGE, cookie)) 359 if (!dm_kobject_uevent(hc->md, KOBJ_CHANGE, param->event_nr))
349 *flags |= DM_UEVENT_GENERATED_FLAG; 360 param->flags |= DM_UEVENT_GENERATED_FLAG;
350 361
351 dm_put(hc->md); 362 md = hc->md;
352 up_write(&_hash_lock); 363 up_write(&_hash_lock);
353 kfree(old_name); 364 kfree(old_name);
354 return 0; 365
366 return md;
355} 367}
356 368
357/*----------------------------------------------------------------- 369/*-----------------------------------------------------------------
@@ -573,7 +585,7 @@ static struct dm_table *dm_get_live_or_inactive_table(struct mapped_device *md,
573 * Fills in a dm_ioctl structure, ready for sending back to 585 * Fills in a dm_ioctl structure, ready for sending back to
574 * userland. 586 * userland.
575 */ 587 */
576static int __dev_status(struct mapped_device *md, struct dm_ioctl *param) 588static void __dev_status(struct mapped_device *md, struct dm_ioctl *param)
577{ 589{
578 struct gendisk *disk = dm_disk(md); 590 struct gendisk *disk = dm_disk(md);
579 struct dm_table *table; 591 struct dm_table *table;
@@ -617,8 +629,6 @@ static int __dev_status(struct mapped_device *md, struct dm_ioctl *param)
617 dm_table_put(table); 629 dm_table_put(table);
618 } 630 }
619 } 631 }
620
621 return 0;
622} 632}
623 633
624static int dev_create(struct dm_ioctl *param, size_t param_size) 634static int dev_create(struct dm_ioctl *param, size_t param_size)
@@ -640,15 +650,17 @@ static int dev_create(struct dm_ioctl *param, size_t param_size)
640 r = dm_hash_insert(param->name, *param->uuid ? param->uuid : NULL, md); 650 r = dm_hash_insert(param->name, *param->uuid ? param->uuid : NULL, md);
641 if (r) { 651 if (r) {
642 dm_put(md); 652 dm_put(md);
653 dm_destroy(md);
643 return r; 654 return r;
644 } 655 }
645 656
646 param->flags &= ~DM_INACTIVE_PRESENT_FLAG; 657 param->flags &= ~DM_INACTIVE_PRESENT_FLAG;
647 658
648 r = __dev_status(md, param); 659 __dev_status(md, param);
660
649 dm_put(md); 661 dm_put(md);
650 662
651 return r; 663 return 0;
652} 664}
653 665
654/* 666/*
@@ -742,6 +754,7 @@ static int dev_remove(struct dm_ioctl *param, size_t param_size)
742 param->flags |= DM_UEVENT_GENERATED_FLAG; 754 param->flags |= DM_UEVENT_GENERATED_FLAG;
743 755
744 dm_put(md); 756 dm_put(md);
757 dm_destroy(md);
745 return 0; 758 return 0;
746} 759}
747 760
@@ -762,6 +775,7 @@ static int dev_rename(struct dm_ioctl *param, size_t param_size)
762{ 775{
763 int r; 776 int r;
764 char *new_name = (char *) param + param->data_start; 777 char *new_name = (char *) param + param->data_start;
778 struct mapped_device *md;
765 779
766 if (new_name < param->data || 780 if (new_name < param->data ||
767 invalid_str(new_name, (void *) param + param_size) || 781 invalid_str(new_name, (void *) param + param_size) ||
@@ -774,10 +788,14 @@ static int dev_rename(struct dm_ioctl *param, size_t param_size)
774 if (r) 788 if (r)
775 return r; 789 return r;
776 790
777 param->data_size = 0; 791 md = dm_hash_rename(param, new_name);
792 if (IS_ERR(md))
793 return PTR_ERR(md);
794
795 __dev_status(md, param);
796 dm_put(md);
778 797
779 return dm_hash_rename(param->event_nr, &param->flags, param->name, 798 return 0;
780 new_name);
781} 799}
782 800
783static int dev_set_geometry(struct dm_ioctl *param, size_t param_size) 801static int dev_set_geometry(struct dm_ioctl *param, size_t param_size)
@@ -818,8 +836,6 @@ static int dev_set_geometry(struct dm_ioctl *param, size_t param_size)
818 geometry.start = indata[3]; 836 geometry.start = indata[3];
819 837
820 r = dm_set_geometry(md, &geometry); 838 r = dm_set_geometry(md, &geometry);
821 if (!r)
822 r = __dev_status(md, param);
823 839
824 param->data_size = 0; 840 param->data_size = 0;
825 841
@@ -843,13 +859,17 @@ static int do_suspend(struct dm_ioctl *param)
843 if (param->flags & DM_NOFLUSH_FLAG) 859 if (param->flags & DM_NOFLUSH_FLAG)
844 suspend_flags |= DM_SUSPEND_NOFLUSH_FLAG; 860 suspend_flags |= DM_SUSPEND_NOFLUSH_FLAG;
845 861
846 if (!dm_suspended_md(md)) 862 if (!dm_suspended_md(md)) {
847 r = dm_suspend(md, suspend_flags); 863 r = dm_suspend(md, suspend_flags);
864 if (r)
865 goto out;
866 }
848 867
849 if (!r) 868 __dev_status(md, param);
850 r = __dev_status(md, param);
851 869
870out:
852 dm_put(md); 871 dm_put(md);
872
853 return r; 873 return r;
854} 874}
855 875
@@ -911,7 +931,7 @@ static int do_resume(struct dm_ioctl *param)
911 dm_table_destroy(old_map); 931 dm_table_destroy(old_map);
912 932
913 if (!r) 933 if (!r)
914 r = __dev_status(md, param); 934 __dev_status(md, param);
915 935
916 dm_put(md); 936 dm_put(md);
917 return r; 937 return r;
@@ -935,16 +955,16 @@ static int dev_suspend(struct dm_ioctl *param, size_t param_size)
935 */ 955 */
936static int dev_status(struct dm_ioctl *param, size_t param_size) 956static int dev_status(struct dm_ioctl *param, size_t param_size)
937{ 957{
938 int r;
939 struct mapped_device *md; 958 struct mapped_device *md;
940 959
941 md = find_device(param); 960 md = find_device(param);
942 if (!md) 961 if (!md)
943 return -ENXIO; 962 return -ENXIO;
944 963
945 r = __dev_status(md, param); 964 __dev_status(md, param);
946 dm_put(md); 965 dm_put(md);
947 return r; 966
967 return 0;
948} 968}
949 969
950/* 970/*
@@ -1019,7 +1039,7 @@ static void retrieve_status(struct dm_table *table,
1019 */ 1039 */
1020static int dev_wait(struct dm_ioctl *param, size_t param_size) 1040static int dev_wait(struct dm_ioctl *param, size_t param_size)
1021{ 1041{
1022 int r; 1042 int r = 0;
1023 struct mapped_device *md; 1043 struct mapped_device *md;
1024 struct dm_table *table; 1044 struct dm_table *table;
1025 1045
@@ -1040,9 +1060,7 @@ static int dev_wait(struct dm_ioctl *param, size_t param_size)
1040 * changed to trigger the event, so we may as well tell 1060 * changed to trigger the event, so we may as well tell
1041 * him and save an ioctl. 1061 * him and save an ioctl.
1042 */ 1062 */
1043 r = __dev_status(md, param); 1063 __dev_status(md, param);
1044 if (r)
1045 goto out;
1046 1064
1047 table = dm_get_live_or_inactive_table(md, param); 1065 table = dm_get_live_or_inactive_table(md, param);
1048 if (table) { 1066 if (table) {
@@ -1050,8 +1068,9 @@ static int dev_wait(struct dm_ioctl *param, size_t param_size)
1050 dm_table_put(table); 1068 dm_table_put(table);
1051 } 1069 }
1052 1070
1053 out: 1071out:
1054 dm_put(md); 1072 dm_put(md);
1073
1055 return r; 1074 return r;
1056} 1075}
1057 1076
@@ -1112,28 +1131,9 @@ static int populate_table(struct dm_table *table,
1112 next = spec->next; 1131 next = spec->next;
1113 } 1132 }
1114 1133
1115 r = dm_table_set_type(table);
1116 if (r) {
1117 DMWARN("unable to set table type");
1118 return r;
1119 }
1120
1121 return dm_table_complete(table); 1134 return dm_table_complete(table);
1122} 1135}
1123 1136
1124static int table_prealloc_integrity(struct dm_table *t,
1125 struct mapped_device *md)
1126{
1127 struct list_head *devices = dm_table_get_devices(t);
1128 struct dm_dev_internal *dd;
1129
1130 list_for_each_entry(dd, devices, list)
1131 if (bdev_get_integrity(dd->dm_dev.bdev))
1132 return blk_integrity_register(dm_disk(md), NULL);
1133
1134 return 0;
1135}
1136
1137static int table_load(struct dm_ioctl *param, size_t param_size) 1137static int table_load(struct dm_ioctl *param, size_t param_size)
1138{ 1138{
1139 int r; 1139 int r;
@@ -1155,21 +1155,30 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
1155 goto out; 1155 goto out;
1156 } 1156 }
1157 1157
1158 r = table_prealloc_integrity(t, md); 1158 /* Protect md->type and md->queue against concurrent table loads. */
1159 if (r) { 1159 dm_lock_md_type(md);
1160 DMERR("%s: could not register integrity profile.", 1160 if (dm_get_md_type(md) == DM_TYPE_NONE)
1161 dm_device_name(md)); 1161 /* Initial table load: acquire type of table. */
1162 dm_set_md_type(md, dm_table_get_type(t));
1163 else if (dm_get_md_type(md) != dm_table_get_type(t)) {
1164 DMWARN("can't change device type after initial table load.");
1162 dm_table_destroy(t); 1165 dm_table_destroy(t);
1166 dm_unlock_md_type(md);
1167 r = -EINVAL;
1163 goto out; 1168 goto out;
1164 } 1169 }
1165 1170
1166 r = dm_table_alloc_md_mempools(t); 1171 /* setup md->queue to reflect md's type (may block) */
1172 r = dm_setup_md_queue(md);
1167 if (r) { 1173 if (r) {
1168 DMWARN("unable to allocate mempools for this table"); 1174 DMWARN("unable to set up device queue for new table.");
1169 dm_table_destroy(t); 1175 dm_table_destroy(t);
1176 dm_unlock_md_type(md);
1170 goto out; 1177 goto out;
1171 } 1178 }
1179 dm_unlock_md_type(md);
1172 1180
1181 /* stage inactive table */
1173 down_write(&_hash_lock); 1182 down_write(&_hash_lock);
1174 hc = dm_get_mdptr(md); 1183 hc = dm_get_mdptr(md);
1175 if (!hc || hc->md != md) { 1184 if (!hc || hc->md != md) {
@@ -1186,7 +1195,7 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
1186 up_write(&_hash_lock); 1195 up_write(&_hash_lock);
1187 1196
1188 param->flags |= DM_INACTIVE_PRESENT_FLAG; 1197 param->flags |= DM_INACTIVE_PRESENT_FLAG;
1189 r = __dev_status(md, param); 1198 __dev_status(md, param);
1190 1199
1191out: 1200out:
1192 dm_put(md); 1201 dm_put(md);
@@ -1196,7 +1205,6 @@ out:
1196 1205
1197static int table_clear(struct dm_ioctl *param, size_t param_size) 1206static int table_clear(struct dm_ioctl *param, size_t param_size)
1198{ 1207{
1199 int r;
1200 struct hash_cell *hc; 1208 struct hash_cell *hc;
1201 struct mapped_device *md; 1209 struct mapped_device *md;
1202 1210
@@ -1216,11 +1224,12 @@ static int table_clear(struct dm_ioctl *param, size_t param_size)
1216 1224
1217 param->flags &= ~DM_INACTIVE_PRESENT_FLAG; 1225 param->flags &= ~DM_INACTIVE_PRESENT_FLAG;
1218 1226
1219 r = __dev_status(hc->md, param); 1227 __dev_status(hc->md, param);
1220 md = hc->md; 1228 md = hc->md;
1221 up_write(&_hash_lock); 1229 up_write(&_hash_lock);
1222 dm_put(md); 1230 dm_put(md);
1223 return r; 1231
1232 return 0;
1224} 1233}
1225 1234
1226/* 1235/*
@@ -1265,7 +1274,6 @@ static void retrieve_deps(struct dm_table *table,
1265 1274
1266static int table_deps(struct dm_ioctl *param, size_t param_size) 1275static int table_deps(struct dm_ioctl *param, size_t param_size)
1267{ 1276{
1268 int r = 0;
1269 struct mapped_device *md; 1277 struct mapped_device *md;
1270 struct dm_table *table; 1278 struct dm_table *table;
1271 1279
@@ -1273,9 +1281,7 @@ static int table_deps(struct dm_ioctl *param, size_t param_size)
1273 if (!md) 1281 if (!md)
1274 return -ENXIO; 1282 return -ENXIO;
1275 1283
1276 r = __dev_status(md, param); 1284 __dev_status(md, param);
1277 if (r)
1278 goto out;
1279 1285
1280 table = dm_get_live_or_inactive_table(md, param); 1286 table = dm_get_live_or_inactive_table(md, param);
1281 if (table) { 1287 if (table) {
@@ -1283,9 +1289,9 @@ static int table_deps(struct dm_ioctl *param, size_t param_size)
1283 dm_table_put(table); 1289 dm_table_put(table);
1284 } 1290 }
1285 1291
1286 out:
1287 dm_put(md); 1292 dm_put(md);
1288 return r; 1293
1294 return 0;
1289} 1295}
1290 1296
1291/* 1297/*
@@ -1294,7 +1300,6 @@ static int table_deps(struct dm_ioctl *param, size_t param_size)
1294 */ 1300 */
1295static int table_status(struct dm_ioctl *param, size_t param_size) 1301static int table_status(struct dm_ioctl *param, size_t param_size)
1296{ 1302{
1297 int r;
1298 struct mapped_device *md; 1303 struct mapped_device *md;
1299 struct dm_table *table; 1304 struct dm_table *table;
1300 1305
@@ -1302,9 +1307,7 @@ static int table_status(struct dm_ioctl *param, size_t param_size)
1302 if (!md) 1307 if (!md)
1303 return -ENXIO; 1308 return -ENXIO;
1304 1309
1305 r = __dev_status(md, param); 1310 __dev_status(md, param);
1306 if (r)
1307 goto out;
1308 1311
1309 table = dm_get_live_or_inactive_table(md, param); 1312 table = dm_get_live_or_inactive_table(md, param);
1310 if (table) { 1313 if (table) {
@@ -1312,9 +1315,9 @@ static int table_status(struct dm_ioctl *param, size_t param_size)
1312 dm_table_put(table); 1315 dm_table_put(table);
1313 } 1316 }
1314 1317
1315out:
1316 dm_put(md); 1318 dm_put(md);
1317 return r; 1319
1320 return 0;
1318} 1321}
1319 1322
1320/* 1323/*
@@ -1333,10 +1336,6 @@ static int target_message(struct dm_ioctl *param, size_t param_size)
1333 if (!md) 1336 if (!md)
1334 return -ENXIO; 1337 return -ENXIO;
1335 1338
1336 r = __dev_status(md, param);
1337 if (r)
1338 goto out;
1339
1340 if (tmsg < (struct dm_target_msg *) param->data || 1339 if (tmsg < (struct dm_target_msg *) param->data ||
1341 invalid_str(tmsg->message, (void *) param + param_size)) { 1340 invalid_str(tmsg->message, (void *) param + param_size)) {
1342 DMWARN("Invalid target message parameters."); 1341 DMWARN("Invalid target message parameters.");
@@ -1593,18 +1592,22 @@ static long dm_compat_ctl_ioctl(struct file *file, uint command, ulong u)
1593#endif 1592#endif
1594 1593
1595static const struct file_operations _ctl_fops = { 1594static const struct file_operations _ctl_fops = {
1595 .open = nonseekable_open,
1596 .unlocked_ioctl = dm_ctl_ioctl, 1596 .unlocked_ioctl = dm_ctl_ioctl,
1597 .compat_ioctl = dm_compat_ctl_ioctl, 1597 .compat_ioctl = dm_compat_ctl_ioctl,
1598 .owner = THIS_MODULE, 1598 .owner = THIS_MODULE,
1599}; 1599};
1600 1600
1601static struct miscdevice _dm_misc = { 1601static struct miscdevice _dm_misc = {
1602 .minor = MISC_DYNAMIC_MINOR, 1602 .minor = MAPPER_CTRL_MINOR,
1603 .name = DM_NAME, 1603 .name = DM_NAME,
1604 .nodename = "mapper/control", 1604 .nodename = DM_DIR "/" DM_CONTROL_NODE,
1605 .fops = &_ctl_fops 1605 .fops = &_ctl_fops
1606}; 1606};
1607 1607
1608MODULE_ALIAS_MISCDEV(MAPPER_CTRL_MINOR);
1609MODULE_ALIAS("devname:" DM_DIR "/" DM_CONTROL_NODE);
1610
1608/* 1611/*
1609 * Create misc character device and link to DM_DIR/control. 1612 * Create misc character device and link to DM_DIR/control.
1610 */ 1613 */
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index 9200dbf2391a..3921e3bb43c1 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -53,6 +53,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
53 } 53 }
54 54
55 ti->num_flush_requests = 1; 55 ti->num_flush_requests = 1;
56 ti->num_discard_requests = 1;
56 ti->private = lc; 57 ti->private = lc;
57 return 0; 58 return 0;
58 59
@@ -73,7 +74,7 @@ static sector_t linear_map_sector(struct dm_target *ti, sector_t bi_sector)
73{ 74{
74 struct linear_c *lc = ti->private; 75 struct linear_c *lc = ti->private;
75 76
76 return lc->start + (bi_sector - ti->begin); 77 return lc->start + dm_target_offset(ti, bi_sector);
77} 78}
78 79
79static void linear_map_bio(struct dm_target *ti, struct bio *bio) 80static void linear_map_bio(struct dm_target *ti, struct bio *bio)
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 826bce7343b3..487ecda90ad4 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -706,6 +706,7 @@ static struct priority_group *parse_priority_group(struct arg_set *as,
706 706
707 if (as->argc < nr_params) { 707 if (as->argc < nr_params) {
708 ti->error = "not enough path parameters"; 708 ti->error = "not enough path parameters";
709 r = -EINVAL;
709 goto bad; 710 goto bad;
710 } 711 }
711 712
@@ -892,6 +893,7 @@ static int multipath_ctr(struct dm_target *ti, unsigned int argc,
892 } 893 }
893 894
894 ti->num_flush_requests = 1; 895 ti->num_flush_requests = 1;
896 ti->num_discard_requests = 1;
895 897
896 return 0; 898 return 0;
897 899
@@ -1271,6 +1273,15 @@ static int do_end_io(struct multipath *m, struct request *clone,
1271 if (error == -EOPNOTSUPP) 1273 if (error == -EOPNOTSUPP)
1272 return error; 1274 return error;
1273 1275
1276 if (clone->cmd_flags & REQ_DISCARD)
1277 /*
1278 * Pass all discard request failures up.
1279 * FIXME: only fail_path if the discard failed due to a
1280 * transport problem. This requires precise understanding
1281 * of the underlying failure (e.g. the SCSI sense).
1282 */
1283 return error;
1284
1274 if (mpio->pgpath) 1285 if (mpio->pgpath)
1275 fail_path(mpio->pgpath); 1286 fail_path(mpio->pgpath);
1276 1287
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index 74136262d654..7c081bcbc3cf 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -445,7 +445,7 @@ static sector_t map_sector(struct mirror *m, struct bio *bio)
445{ 445{
446 if (unlikely(!bio->bi_size)) 446 if (unlikely(!bio->bi_size))
447 return 0; 447 return 0;
448 return m->offset + (bio->bi_sector - m->ms->ti->begin); 448 return m->offset + dm_target_offset(m->ms->ti, bio->bi_sector);
449} 449}
450 450
451static void map_bio(struct mirror *m, struct bio *bio) 451static void map_bio(struct mirror *m, struct bio *bio)
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
index c097d8a4823d..cc2bdb83f9ad 100644
--- a/drivers/md/dm-snap-persistent.c
+++ b/drivers/md/dm-snap-persistent.c
@@ -266,7 +266,7 @@ static int chunk_io(struct pstore *ps, void *area, chunk_t chunk, int rw,
266 */ 266 */
267static chunk_t area_location(struct pstore *ps, chunk_t area) 267static chunk_t area_location(struct pstore *ps, chunk_t area)
268{ 268{
269 return 1 + ((ps->exceptions_per_area + 1) * area); 269 return NUM_SNAPSHOT_HDR_CHUNKS + ((ps->exceptions_per_area + 1) * area);
270} 270}
271 271
272/* 272/*
@@ -780,8 +780,8 @@ static int persistent_commit_merge(struct dm_exception_store *store,
780 * ps->current_area does not get reduced by prepare_merge() until 780 * ps->current_area does not get reduced by prepare_merge() until
781 * after commit_merge() has removed the nr_merged previous exceptions. 781 * after commit_merge() has removed the nr_merged previous exceptions.
782 */ 782 */
783 ps->next_free = (area_location(ps, ps->current_area) - 1) + 783 ps->next_free = area_location(ps, ps->current_area) +
784 (ps->current_committed + 1) + NUM_SNAPSHOT_HDR_CHUNKS; 784 ps->current_committed + 1;
785 785
786 return 0; 786 return 0;
787} 787}
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index 54853773510c..5974d3094d97 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -148,6 +148,12 @@ struct dm_snapshot {
148#define RUNNING_MERGE 0 148#define RUNNING_MERGE 0
149#define SHUTDOWN_MERGE 1 149#define SHUTDOWN_MERGE 1
150 150
151struct dm_dev *dm_snap_origin(struct dm_snapshot *s)
152{
153 return s->origin;
154}
155EXPORT_SYMBOL(dm_snap_origin);
156
151struct dm_dev *dm_snap_cow(struct dm_snapshot *s) 157struct dm_dev *dm_snap_cow(struct dm_snapshot *s)
152{ 158{
153 return s->cow; 159 return s->cow;
@@ -1065,10 +1071,6 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1065 origin_mode = FMODE_WRITE; 1071 origin_mode = FMODE_WRITE;
1066 } 1072 }
1067 1073
1068 origin_path = argv[0];
1069 argv++;
1070 argc--;
1071
1072 s = kmalloc(sizeof(*s), GFP_KERNEL); 1074 s = kmalloc(sizeof(*s), GFP_KERNEL);
1073 if (!s) { 1075 if (!s) {
1074 ti->error = "Cannot allocate snapshot context private " 1076 ti->error = "Cannot allocate snapshot context private "
@@ -1077,6 +1079,16 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1077 goto bad; 1079 goto bad;
1078 } 1080 }
1079 1081
1082 origin_path = argv[0];
1083 argv++;
1084 argc--;
1085
1086 r = dm_get_device(ti, origin_path, origin_mode, &s->origin);
1087 if (r) {
1088 ti->error = "Cannot get origin device";
1089 goto bad_origin;
1090 }
1091
1080 cow_path = argv[0]; 1092 cow_path = argv[0];
1081 argv++; 1093 argv++;
1082 argc--; 1094 argc--;
@@ -1097,12 +1109,6 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1097 argv += args_used; 1109 argv += args_used;
1098 argc -= args_used; 1110 argc -= args_used;
1099 1111
1100 r = dm_get_device(ti, origin_path, origin_mode, &s->origin);
1101 if (r) {
1102 ti->error = "Cannot get origin device";
1103 goto bad_origin;
1104 }
1105
1106 s->ti = ti; 1112 s->ti = ti;
1107 s->valid = 1; 1113 s->valid = 1;
1108 s->active = 0; 1114 s->active = 0;
@@ -1212,15 +1218,15 @@ bad_kcopyd:
1212 dm_exception_table_exit(&s->complete, exception_cache); 1218 dm_exception_table_exit(&s->complete, exception_cache);
1213 1219
1214bad_hash_tables: 1220bad_hash_tables:
1215 dm_put_device(ti, s->origin);
1216
1217bad_origin:
1218 dm_exception_store_destroy(s->store); 1221 dm_exception_store_destroy(s->store);
1219 1222
1220bad_store: 1223bad_store:
1221 dm_put_device(ti, s->cow); 1224 dm_put_device(ti, s->cow);
1222 1225
1223bad_cow: 1226bad_cow:
1227 dm_put_device(ti, s->origin);
1228
1229bad_origin:
1224 kfree(s); 1230 kfree(s);
1225 1231
1226bad: 1232bad:
@@ -1314,12 +1320,12 @@ static void snapshot_dtr(struct dm_target *ti)
1314 1320
1315 mempool_destroy(s->pending_pool); 1321 mempool_destroy(s->pending_pool);
1316 1322
1317 dm_put_device(ti, s->origin);
1318
1319 dm_exception_store_destroy(s->store); 1323 dm_exception_store_destroy(s->store);
1320 1324
1321 dm_put_device(ti, s->cow); 1325 dm_put_device(ti, s->cow);
1322 1326
1327 dm_put_device(ti, s->origin);
1328
1323 kfree(s); 1329 kfree(s);
1324} 1330}
1325 1331
@@ -1686,7 +1692,7 @@ static int snapshot_merge_map(struct dm_target *ti, struct bio *bio,
1686 chunk_t chunk; 1692 chunk_t chunk;
1687 1693
1688 if (unlikely(bio_empty_barrier(bio))) { 1694 if (unlikely(bio_empty_barrier(bio))) {
1689 if (!map_context->flush_request) 1695 if (!map_context->target_request_nr)
1690 bio->bi_bdev = s->origin->bdev; 1696 bio->bi_bdev = s->origin->bdev;
1691 else 1697 else
1692 bio->bi_bdev = s->cow->bdev; 1698 bio->bi_bdev = s->cow->bdev;
@@ -1899,8 +1905,14 @@ static int snapshot_iterate_devices(struct dm_target *ti,
1899 iterate_devices_callout_fn fn, void *data) 1905 iterate_devices_callout_fn fn, void *data)
1900{ 1906{
1901 struct dm_snapshot *snap = ti->private; 1907 struct dm_snapshot *snap = ti->private;
1908 int r;
1909
1910 r = fn(ti, snap->origin, 0, ti->len, data);
1911
1912 if (!r)
1913 r = fn(ti, snap->cow, 0, get_dev_size(snap->cow->bdev), data);
1902 1914
1903 return fn(ti, snap->origin, 0, ti->len, data); 1915 return r;
1904} 1916}
1905 1917
1906 1918
@@ -2159,6 +2171,21 @@ static int origin_status(struct dm_target *ti, status_type_t type, char *result,
2159 return 0; 2171 return 0;
2160} 2172}
2161 2173
2174static int origin_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
2175 struct bio_vec *biovec, int max_size)
2176{
2177 struct dm_dev *dev = ti->private;
2178 struct request_queue *q = bdev_get_queue(dev->bdev);
2179
2180 if (!q->merge_bvec_fn)
2181 return max_size;
2182
2183 bvm->bi_bdev = dev->bdev;
2184 bvm->bi_sector = bvm->bi_sector;
2185
2186 return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
2187}
2188
2162static int origin_iterate_devices(struct dm_target *ti, 2189static int origin_iterate_devices(struct dm_target *ti,
2163 iterate_devices_callout_fn fn, void *data) 2190 iterate_devices_callout_fn fn, void *data)
2164{ 2191{
@@ -2176,6 +2203,7 @@ static struct target_type origin_target = {
2176 .map = origin_map, 2203 .map = origin_map,
2177 .resume = origin_resume, 2204 .resume = origin_resume,
2178 .status = origin_status, 2205 .status = origin_status,
2206 .merge = origin_merge,
2179 .iterate_devices = origin_iterate_devices, 2207 .iterate_devices = origin_iterate_devices,
2180}; 2208};
2181 2209
diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
index d6e28d732b4d..c297f6da91ea 100644
--- a/drivers/md/dm-stripe.c
+++ b/drivers/md/dm-stripe.c
@@ -25,6 +25,8 @@ struct stripe {
25 25
26struct stripe_c { 26struct stripe_c {
27 uint32_t stripes; 27 uint32_t stripes;
28 int stripes_shift;
29 sector_t stripes_mask;
28 30
29 /* The size of this target / num. stripes */ 31 /* The size of this target / num. stripes */
30 sector_t stripe_width; 32 sector_t stripe_width;
@@ -162,16 +164,22 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
162 164
163 /* Set pointer to dm target; used in trigger_event */ 165 /* Set pointer to dm target; used in trigger_event */
164 sc->ti = ti; 166 sc->ti = ti;
165
166 sc->stripes = stripes; 167 sc->stripes = stripes;
167 sc->stripe_width = width; 168 sc->stripe_width = width;
169
170 if (stripes & (stripes - 1))
171 sc->stripes_shift = -1;
172 else {
173 sc->stripes_shift = ffs(stripes) - 1;
174 sc->stripes_mask = ((sector_t) stripes) - 1;
175 }
176
168 ti->split_io = chunk_size; 177 ti->split_io = chunk_size;
169 ti->num_flush_requests = stripes; 178 ti->num_flush_requests = stripes;
179 ti->num_discard_requests = stripes;
170 180
181 sc->chunk_shift = ffs(chunk_size) - 1;
171 sc->chunk_mask = ((sector_t) chunk_size) - 1; 182 sc->chunk_mask = ((sector_t) chunk_size) - 1;
172 for (sc->chunk_shift = 0; chunk_size; sc->chunk_shift++)
173 chunk_size >>= 1;
174 sc->chunk_shift--;
175 183
176 /* 184 /*
177 * Get the stripe destinations. 185 * Get the stripe destinations.
@@ -207,26 +215,79 @@ static void stripe_dtr(struct dm_target *ti)
207 kfree(sc); 215 kfree(sc);
208} 216}
209 217
218static void stripe_map_sector(struct stripe_c *sc, sector_t sector,
219 uint32_t *stripe, sector_t *result)
220{
221 sector_t offset = dm_target_offset(sc->ti, sector);
222 sector_t chunk = offset >> sc->chunk_shift;
223
224 if (sc->stripes_shift < 0)
225 *stripe = sector_div(chunk, sc->stripes);
226 else {
227 *stripe = chunk & sc->stripes_mask;
228 chunk >>= sc->stripes_shift;
229 }
230
231 *result = (chunk << sc->chunk_shift) | (offset & sc->chunk_mask);
232}
233
234static void stripe_map_range_sector(struct stripe_c *sc, sector_t sector,
235 uint32_t target_stripe, sector_t *result)
236{
237 uint32_t stripe;
238
239 stripe_map_sector(sc, sector, &stripe, result);
240 if (stripe == target_stripe)
241 return;
242 *result &= ~sc->chunk_mask; /* round down */
243 if (target_stripe < stripe)
244 *result += sc->chunk_mask + 1; /* next chunk */
245}
246
247static int stripe_map_discard(struct stripe_c *sc, struct bio *bio,
248 uint32_t target_stripe)
249{
250 sector_t begin, end;
251
252 stripe_map_range_sector(sc, bio->bi_sector, target_stripe, &begin);
253 stripe_map_range_sector(sc, bio->bi_sector + bio_sectors(bio),
254 target_stripe, &end);
255 if (begin < end) {
256 bio->bi_bdev = sc->stripe[target_stripe].dev->bdev;
257 bio->bi_sector = begin + sc->stripe[target_stripe].physical_start;
258 bio->bi_size = to_bytes(end - begin);
259 return DM_MAPIO_REMAPPED;
260 } else {
261 /* The range doesn't map to the target stripe */
262 bio_endio(bio, 0);
263 return DM_MAPIO_SUBMITTED;
264 }
265}
266
210static int stripe_map(struct dm_target *ti, struct bio *bio, 267static int stripe_map(struct dm_target *ti, struct bio *bio,
211 union map_info *map_context) 268 union map_info *map_context)
212{ 269{
213 struct stripe_c *sc = (struct stripe_c *) ti->private; 270 struct stripe_c *sc = ti->private;
214 sector_t offset, chunk;
215 uint32_t stripe; 271 uint32_t stripe;
272 unsigned target_request_nr;
216 273
217 if (unlikely(bio_empty_barrier(bio))) { 274 if (unlikely(bio_empty_barrier(bio))) {
218 BUG_ON(map_context->flush_request >= sc->stripes); 275 target_request_nr = map_context->target_request_nr;
219 bio->bi_bdev = sc->stripe[map_context->flush_request].dev->bdev; 276 BUG_ON(target_request_nr >= sc->stripes);
277 bio->bi_bdev = sc->stripe[target_request_nr].dev->bdev;
220 return DM_MAPIO_REMAPPED; 278 return DM_MAPIO_REMAPPED;
221 } 279 }
280 if (unlikely(bio->bi_rw & REQ_DISCARD)) {
281 target_request_nr = map_context->target_request_nr;
282 BUG_ON(target_request_nr >= sc->stripes);
283 return stripe_map_discard(sc, bio, target_request_nr);
284 }
222 285
223 offset = bio->bi_sector - ti->begin; 286 stripe_map_sector(sc, bio->bi_sector, &stripe, &bio->bi_sector);
224 chunk = offset >> sc->chunk_shift;
225 stripe = sector_div(chunk, sc->stripes);
226 287
288 bio->bi_sector += sc->stripe[stripe].physical_start;
227 bio->bi_bdev = sc->stripe[stripe].dev->bdev; 289 bio->bi_bdev = sc->stripe[stripe].dev->bdev;
228 bio->bi_sector = sc->stripe[stripe].physical_start + 290
229 (chunk << sc->chunk_shift) + (offset & sc->chunk_mask);
230 return DM_MAPIO_REMAPPED; 291 return DM_MAPIO_REMAPPED;
231} 292}
232 293
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 9924ea23032d..f9fc07d7a4b9 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -54,6 +54,8 @@ struct dm_table {
54 sector_t *highs; 54 sector_t *highs;
55 struct dm_target *targets; 55 struct dm_target *targets;
56 56
57 unsigned discards_supported:1;
58
57 /* 59 /*
58 * Indicates the rw permissions for the new logical 60 * Indicates the rw permissions for the new logical
59 * device. This should be a combination of FMODE_READ 61 * device. This should be a combination of FMODE_READ
@@ -203,6 +205,7 @@ int dm_table_create(struct dm_table **result, fmode_t mode,
203 205
204 INIT_LIST_HEAD(&t->devices); 206 INIT_LIST_HEAD(&t->devices);
205 atomic_set(&t->holders, 0); 207 atomic_set(&t->holders, 0);
208 t->discards_supported = 1;
206 209
207 if (!num_targets) 210 if (!num_targets)
208 num_targets = KEYS_PER_NODE; 211 num_targets = KEYS_PER_NODE;
@@ -245,7 +248,7 @@ void dm_table_destroy(struct dm_table *t)
245 msleep(1); 248 msleep(1);
246 smp_mb(); 249 smp_mb();
247 250
248 /* free the indexes (see dm_table_complete) */ 251 /* free the indexes */
249 if (t->depth >= 2) 252 if (t->depth >= 2)
250 vfree(t->index[t->depth - 2]); 253 vfree(t->index[t->depth - 2]);
251 254
@@ -770,6 +773,9 @@ int dm_table_add_target(struct dm_table *t, const char *type,
770 773
771 t->highs[t->num_targets++] = tgt->begin + tgt->len - 1; 774 t->highs[t->num_targets++] = tgt->begin + tgt->len - 1;
772 775
776 if (!tgt->num_discard_requests)
777 t->discards_supported = 0;
778
773 return 0; 779 return 0;
774 780
775 bad: 781 bad:
@@ -778,7 +784,7 @@ int dm_table_add_target(struct dm_table *t, const char *type,
778 return r; 784 return r;
779} 785}
780 786
781int dm_table_set_type(struct dm_table *t) 787static int dm_table_set_type(struct dm_table *t)
782{ 788{
783 unsigned i; 789 unsigned i;
784 unsigned bio_based = 0, request_based = 0; 790 unsigned bio_based = 0, request_based = 0;
@@ -900,7 +906,7 @@ static int setup_indexes(struct dm_table *t)
900/* 906/*
901 * Builds the btree to index the map. 907 * Builds the btree to index the map.
902 */ 908 */
903int dm_table_complete(struct dm_table *t) 909static int dm_table_build_index(struct dm_table *t)
904{ 910{
905 int r = 0; 911 int r = 0;
906 unsigned int leaf_nodes; 912 unsigned int leaf_nodes;
@@ -919,6 +925,55 @@ int dm_table_complete(struct dm_table *t)
919 return r; 925 return r;
920} 926}
921 927
928/*
929 * Register the mapped device for blk_integrity support if
930 * the underlying devices support it.
931 */
932static int dm_table_prealloc_integrity(struct dm_table *t, struct mapped_device *md)
933{
934 struct list_head *devices = dm_table_get_devices(t);
935 struct dm_dev_internal *dd;
936
937 list_for_each_entry(dd, devices, list)
938 if (bdev_get_integrity(dd->dm_dev.bdev))
939 return blk_integrity_register(dm_disk(md), NULL);
940
941 return 0;
942}
943
944/*
945 * Prepares the table for use by building the indices,
946 * setting the type, and allocating mempools.
947 */
948int dm_table_complete(struct dm_table *t)
949{
950 int r;
951
952 r = dm_table_set_type(t);
953 if (r) {
954 DMERR("unable to set table type");
955 return r;
956 }
957
958 r = dm_table_build_index(t);
959 if (r) {
960 DMERR("unable to build btrees");
961 return r;
962 }
963
964 r = dm_table_prealloc_integrity(t, t->md);
965 if (r) {
966 DMERR("could not register integrity profile.");
967 return r;
968 }
969
970 r = dm_table_alloc_md_mempools(t);
971 if (r)
972 DMERR("unable to allocate mempools");
973
974 return r;
975}
976
922static DEFINE_MUTEX(_event_lock); 977static DEFINE_MUTEX(_event_lock);
923void dm_table_event_callback(struct dm_table *t, 978void dm_table_event_callback(struct dm_table *t,
924 void (*fn)(void *), void *context) 979 void (*fn)(void *), void *context)
@@ -1086,6 +1141,11 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
1086 else 1141 else
1087 queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, q); 1142 queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, q);
1088 1143
1144 if (!dm_table_supports_discards(t))
1145 queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, q);
1146 else
1147 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
1148
1089 dm_table_set_integrity(t); 1149 dm_table_set_integrity(t);
1090 1150
1091 /* 1151 /*
@@ -1232,6 +1292,39 @@ struct mapped_device *dm_table_get_md(struct dm_table *t)
1232 return t->md; 1292 return t->md;
1233} 1293}
1234 1294
1295static int device_discard_capable(struct dm_target *ti, struct dm_dev *dev,
1296 sector_t start, sector_t len, void *data)
1297{
1298 struct request_queue *q = bdev_get_queue(dev->bdev);
1299
1300 return q && blk_queue_discard(q);
1301}
1302
1303bool dm_table_supports_discards(struct dm_table *t)
1304{
1305 struct dm_target *ti;
1306 unsigned i = 0;
1307
1308 if (!t->discards_supported)
1309 return 0;
1310
1311 /*
1312 * Ensure that at least one underlying device supports discards.
1313 * t->devices includes internal dm devices such as mirror logs
1314 * so we need to use iterate_devices here, which targets
1315 * supporting discard must provide.
1316 */
1317 while (i < dm_table_get_num_targets(t)) {
1318 ti = dm_table_get_target(t, i++);
1319
1320 if (ti->type->iterate_devices &&
1321 ti->type->iterate_devices(ti, device_discard_capable, NULL))
1322 return 1;
1323 }
1324
1325 return 0;
1326}
1327
1235EXPORT_SYMBOL(dm_vcalloc); 1328EXPORT_SYMBOL(dm_vcalloc);
1236EXPORT_SYMBOL(dm_get_device); 1329EXPORT_SYMBOL(dm_get_device);
1237EXPORT_SYMBOL(dm_put_device); 1330EXPORT_SYMBOL(dm_put_device);
diff --git a/drivers/md/dm-target.c b/drivers/md/dm-target.c
index 11dea11dc0b6..8da366cf381c 100644
--- a/drivers/md/dm-target.c
+++ b/drivers/md/dm-target.c
@@ -113,6 +113,11 @@ void dm_unregister_target(struct target_type *tt)
113 */ 113 */
114static int io_err_ctr(struct dm_target *tt, unsigned int argc, char **args) 114static int io_err_ctr(struct dm_target *tt, unsigned int argc, char **args)
115{ 115{
116 /*
117 * Return error for discards instead of -EOPNOTSUPP
118 */
119 tt->num_discard_requests = 1;
120
116 return 0; 121 return 0;
117} 122}
118 123
diff --git a/drivers/md/dm-zero.c b/drivers/md/dm-zero.c
index bbc97030c0c2..cc2b3cb81946 100644
--- a/drivers/md/dm-zero.c
+++ b/drivers/md/dm-zero.c
@@ -22,6 +22,11 @@ static int zero_ctr(struct dm_target *ti, unsigned int argc, char **argv)
22 return -EINVAL; 22 return -EINVAL;
23 } 23 }
24 24
25 /*
26 * Silently drop discards, avoiding -EOPNOTSUPP.
27 */
28 ti->num_discard_requests = 1;
29
25 return 0; 30 return 0;
26} 31}
27 32
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index a3f21dc02bd8..ac384b2a6a33 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -20,6 +20,7 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/idr.h> 21#include <linux/idr.h>
22#include <linux/hdreg.h> 22#include <linux/hdreg.h>
23#include <linux/delay.h>
23 24
24#include <trace/events/block.h> 25#include <trace/events/block.h>
25 26
@@ -124,6 +125,10 @@ struct mapped_device {
124 unsigned long flags; 125 unsigned long flags;
125 126
126 struct request_queue *queue; 127 struct request_queue *queue;
128 unsigned type;
129 /* Protect queue and type against concurrent access. */
130 struct mutex type_lock;
131
127 struct gendisk *disk; 132 struct gendisk *disk;
128 char name[16]; 133 char name[16];
129 134
@@ -638,8 +643,14 @@ static void dec_pending(struct dm_io *io, int error)
638 * There can be just one barrier request so we use 643 * There can be just one barrier request so we use
639 * a per-device variable for error reporting. 644 * a per-device variable for error reporting.
640 * Note that you can't touch the bio after end_io_acct 645 * Note that you can't touch the bio after end_io_acct
646 *
647 * We ignore -EOPNOTSUPP for empty flush reported by
648 * underlying devices. We assume that if the device
649 * doesn't support empty barriers, it doesn't need
650 * cache flushing commands.
641 */ 651 */
642 if (!md->barrier_error && io_error != -EOPNOTSUPP) 652 if (!md->barrier_error &&
653 !(bio_empty_barrier(bio) && io_error == -EOPNOTSUPP))
643 md->barrier_error = io_error; 654 md->barrier_error = io_error;
644 end_io_acct(io); 655 end_io_acct(io);
645 free_io(md, io); 656 free_io(md, io);
@@ -1019,17 +1030,27 @@ static void end_clone_request(struct request *clone, int error)
1019 dm_complete_request(clone, error); 1030 dm_complete_request(clone, error);
1020} 1031}
1021 1032
1022static sector_t max_io_len(struct mapped_device *md, 1033/*
1023 sector_t sector, struct dm_target *ti) 1034 * Return maximum size of I/O possible at the supplied sector up to the current
1035 * target boundary.
1036 */
1037static sector_t max_io_len_target_boundary(sector_t sector, struct dm_target *ti)
1038{
1039 sector_t target_offset = dm_target_offset(ti, sector);
1040
1041 return ti->len - target_offset;
1042}
1043
1044static sector_t max_io_len(sector_t sector, struct dm_target *ti)
1024{ 1045{
1025 sector_t offset = sector - ti->begin; 1046 sector_t len = max_io_len_target_boundary(sector, ti);
1026 sector_t len = ti->len - offset;
1027 1047
1028 /* 1048 /*
1029 * Does the target need to split even further ? 1049 * Does the target need to split even further ?
1030 */ 1050 */
1031 if (ti->split_io) { 1051 if (ti->split_io) {
1032 sector_t boundary; 1052 sector_t boundary;
1053 sector_t offset = dm_target_offset(ti, sector);
1033 boundary = ((offset + ti->split_io) & ~(ti->split_io - 1)) 1054 boundary = ((offset + ti->split_io) & ~(ti->split_io - 1))
1034 - offset; 1055 - offset;
1035 if (len > boundary) 1056 if (len > boundary)
@@ -1171,36 +1192,96 @@ static struct dm_target_io *alloc_tio(struct clone_info *ci,
1171 return tio; 1192 return tio;
1172} 1193}
1173 1194
1174static void __flush_target(struct clone_info *ci, struct dm_target *ti, 1195static void __issue_target_request(struct clone_info *ci, struct dm_target *ti,
1175 unsigned flush_nr) 1196 unsigned request_nr, sector_t len)
1176{ 1197{
1177 struct dm_target_io *tio = alloc_tio(ci, ti); 1198 struct dm_target_io *tio = alloc_tio(ci, ti);
1178 struct bio *clone; 1199 struct bio *clone;
1179 1200
1180 tio->info.flush_request = flush_nr; 1201 tio->info.target_request_nr = request_nr;
1181 1202
1182 clone = bio_alloc_bioset(GFP_NOIO, 0, ci->md->bs); 1203 /*
1204 * Discard requests require the bio's inline iovecs be initialized.
1205 * ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush
1206 * and discard, so no need for concern about wasted bvec allocations.
1207 */
1208 clone = bio_alloc_bioset(GFP_NOIO, ci->bio->bi_max_vecs, ci->md->bs);
1183 __bio_clone(clone, ci->bio); 1209 __bio_clone(clone, ci->bio);
1184 clone->bi_destructor = dm_bio_destructor; 1210 clone->bi_destructor = dm_bio_destructor;
1211 if (len) {
1212 clone->bi_sector = ci->sector;
1213 clone->bi_size = to_bytes(len);
1214 }
1185 1215
1186 __map_bio(ti, clone, tio); 1216 __map_bio(ti, clone, tio);
1187} 1217}
1188 1218
1219static void __issue_target_requests(struct clone_info *ci, struct dm_target *ti,
1220 unsigned num_requests, sector_t len)
1221{
1222 unsigned request_nr;
1223
1224 for (request_nr = 0; request_nr < num_requests; request_nr++)
1225 __issue_target_request(ci, ti, request_nr, len);
1226}
1227
1189static int __clone_and_map_empty_barrier(struct clone_info *ci) 1228static int __clone_and_map_empty_barrier(struct clone_info *ci)
1190{ 1229{
1191 unsigned target_nr = 0, flush_nr; 1230 unsigned target_nr = 0;
1192 struct dm_target *ti; 1231 struct dm_target *ti;
1193 1232
1194 while ((ti = dm_table_get_target(ci->map, target_nr++))) 1233 while ((ti = dm_table_get_target(ci->map, target_nr++)))
1195 for (flush_nr = 0; flush_nr < ti->num_flush_requests; 1234 __issue_target_requests(ci, ti, ti->num_flush_requests, 0);
1196 flush_nr++)
1197 __flush_target(ci, ti, flush_nr);
1198 1235
1199 ci->sector_count = 0; 1236 ci->sector_count = 0;
1200 1237
1201 return 0; 1238 return 0;
1202} 1239}
1203 1240
1241/*
1242 * Perform all io with a single clone.
1243 */
1244static void __clone_and_map_simple(struct clone_info *ci, struct dm_target *ti)
1245{
1246 struct bio *clone, *bio = ci->bio;
1247 struct dm_target_io *tio;
1248
1249 tio = alloc_tio(ci, ti);
1250 clone = clone_bio(bio, ci->sector, ci->idx,
1251 bio->bi_vcnt - ci->idx, ci->sector_count,
1252 ci->md->bs);
1253 __map_bio(ti, clone, tio);
1254 ci->sector_count = 0;
1255}
1256
1257static int __clone_and_map_discard(struct clone_info *ci)
1258{
1259 struct dm_target *ti;
1260 sector_t len;
1261
1262 do {
1263 ti = dm_table_find_target(ci->map, ci->sector);
1264 if (!dm_target_is_valid(ti))
1265 return -EIO;
1266
1267 /*
1268 * Even though the device advertised discard support,
1269 * reconfiguration might have changed that since the
1270 * check was performed.
1271 */
1272 if (!ti->num_discard_requests)
1273 return -EOPNOTSUPP;
1274
1275 len = min(ci->sector_count, max_io_len_target_boundary(ci->sector, ti));
1276
1277 __issue_target_requests(ci, ti, ti->num_discard_requests, len);
1278
1279 ci->sector += len;
1280 } while (ci->sector_count -= len);
1281
1282 return 0;
1283}
1284
1204static int __clone_and_map(struct clone_info *ci) 1285static int __clone_and_map(struct clone_info *ci)
1205{ 1286{
1206 struct bio *clone, *bio = ci->bio; 1287 struct bio *clone, *bio = ci->bio;
@@ -1211,27 +1292,21 @@ static int __clone_and_map(struct clone_info *ci)
1211 if (unlikely(bio_empty_barrier(bio))) 1292 if (unlikely(bio_empty_barrier(bio)))
1212 return __clone_and_map_empty_barrier(ci); 1293 return __clone_and_map_empty_barrier(ci);
1213 1294
1295 if (unlikely(bio->bi_rw & REQ_DISCARD))
1296 return __clone_and_map_discard(ci);
1297
1214 ti = dm_table_find_target(ci->map, ci->sector); 1298 ti = dm_table_find_target(ci->map, ci->sector);
1215 if (!dm_target_is_valid(ti)) 1299 if (!dm_target_is_valid(ti))
1216 return -EIO; 1300 return -EIO;
1217 1301
1218 max = max_io_len(ci->md, ci->sector, ti); 1302 max = max_io_len(ci->sector, ti);
1219
1220 /*
1221 * Allocate a target io object.
1222 */
1223 tio = alloc_tio(ci, ti);
1224 1303
1225 if (ci->sector_count <= max) { 1304 if (ci->sector_count <= max) {
1226 /* 1305 /*
1227 * Optimise for the simple case where we can do all of 1306 * Optimise for the simple case where we can do all of
1228 * the remaining io with a single clone. 1307 * the remaining io with a single clone.
1229 */ 1308 */
1230 clone = clone_bio(bio, ci->sector, ci->idx, 1309 __clone_and_map_simple(ci, ti);
1231 bio->bi_vcnt - ci->idx, ci->sector_count,
1232 ci->md->bs);
1233 __map_bio(ti, clone, tio);
1234 ci->sector_count = 0;
1235 1310
1236 } else if (to_sector(bio->bi_io_vec[ci->idx].bv_len) <= max) { 1311 } else if (to_sector(bio->bi_io_vec[ci->idx].bv_len) <= max) {
1237 /* 1312 /*
@@ -1252,6 +1327,7 @@ static int __clone_and_map(struct clone_info *ci)
1252 len += bv_len; 1327 len += bv_len;
1253 } 1328 }
1254 1329
1330 tio = alloc_tio(ci, ti);
1255 clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len, 1331 clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len,
1256 ci->md->bs); 1332 ci->md->bs);
1257 __map_bio(ti, clone, tio); 1333 __map_bio(ti, clone, tio);
@@ -1274,13 +1350,12 @@ static int __clone_and_map(struct clone_info *ci)
1274 if (!dm_target_is_valid(ti)) 1350 if (!dm_target_is_valid(ti))
1275 return -EIO; 1351 return -EIO;
1276 1352
1277 max = max_io_len(ci->md, ci->sector, ti); 1353 max = max_io_len(ci->sector, ti);
1278
1279 tio = alloc_tio(ci, ti);
1280 } 1354 }
1281 1355
1282 len = min(remaining, max); 1356 len = min(remaining, max);
1283 1357
1358 tio = alloc_tio(ci, ti);
1284 clone = split_bvec(bio, ci->sector, ci->idx, 1359 clone = split_bvec(bio, ci->sector, ci->idx,
1285 bv->bv_offset + offset, len, 1360 bv->bv_offset + offset, len,
1286 ci->md->bs); 1361 ci->md->bs);
@@ -1362,7 +1437,7 @@ static int dm_merge_bvec(struct request_queue *q,
1362 /* 1437 /*
1363 * Find maximum amount of I/O that won't need splitting 1438 * Find maximum amount of I/O that won't need splitting
1364 */ 1439 */
1365 max_sectors = min(max_io_len(md, bvm->bi_sector, ti), 1440 max_sectors = min(max_io_len(bvm->bi_sector, ti),
1366 (sector_t) BIO_MAX_SECTORS); 1441 (sector_t) BIO_MAX_SECTORS);
1367 max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size; 1442 max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size;
1368 if (max_size < 0) 1443 if (max_size < 0)
@@ -1845,6 +1920,28 @@ static const struct block_device_operations dm_blk_dops;
1845static void dm_wq_work(struct work_struct *work); 1920static void dm_wq_work(struct work_struct *work);
1846static void dm_rq_barrier_work(struct work_struct *work); 1921static void dm_rq_barrier_work(struct work_struct *work);
1847 1922
1923static void dm_init_md_queue(struct mapped_device *md)
1924{
1925 /*
1926 * Request-based dm devices cannot be stacked on top of bio-based dm
1927 * devices. The type of this dm device has not been decided yet.
1928 * The type is decided at the first table loading time.
1929 * To prevent problematic device stacking, clear the queue flag
1930 * for request stacking support until then.
1931 *
1932 * This queue is new, so no concurrency on the queue_flags.
1933 */
1934 queue_flag_clear_unlocked(QUEUE_FLAG_STACKABLE, md->queue);
1935
1936 md->queue->queuedata = md;
1937 md->queue->backing_dev_info.congested_fn = dm_any_congested;
1938 md->queue->backing_dev_info.congested_data = md;
1939 blk_queue_make_request(md->queue, dm_request);
1940 blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
1941 md->queue->unplug_fn = dm_unplug_all;
1942 blk_queue_merge_bvec(md->queue, dm_merge_bvec);
1943}
1944
1848/* 1945/*
1849 * Allocate and initialise a blank device with a given minor. 1946 * Allocate and initialise a blank device with a given minor.
1850 */ 1947 */
@@ -1870,8 +1967,10 @@ static struct mapped_device *alloc_dev(int minor)
1870 if (r < 0) 1967 if (r < 0)
1871 goto bad_minor; 1968 goto bad_minor;
1872 1969
1970 md->type = DM_TYPE_NONE;
1873 init_rwsem(&md->io_lock); 1971 init_rwsem(&md->io_lock);
1874 mutex_init(&md->suspend_lock); 1972 mutex_init(&md->suspend_lock);
1973 mutex_init(&md->type_lock);
1875 spin_lock_init(&md->deferred_lock); 1974 spin_lock_init(&md->deferred_lock);
1876 spin_lock_init(&md->barrier_error_lock); 1975 spin_lock_init(&md->barrier_error_lock);
1877 rwlock_init(&md->map_lock); 1976 rwlock_init(&md->map_lock);
@@ -1882,33 +1981,11 @@ static struct mapped_device *alloc_dev(int minor)
1882 INIT_LIST_HEAD(&md->uevent_list); 1981 INIT_LIST_HEAD(&md->uevent_list);
1883 spin_lock_init(&md->uevent_lock); 1982 spin_lock_init(&md->uevent_lock);
1884 1983
1885 md->queue = blk_init_queue(dm_request_fn, NULL); 1984 md->queue = blk_alloc_queue(GFP_KERNEL);
1886 if (!md->queue) 1985 if (!md->queue)
1887 goto bad_queue; 1986 goto bad_queue;
1888 1987
1889 /* 1988 dm_init_md_queue(md);
1890 * Request-based dm devices cannot be stacked on top of bio-based dm
1891 * devices. The type of this dm device has not been decided yet,
1892 * although we initialized the queue using blk_init_queue().
1893 * The type is decided at the first table loading time.
1894 * To prevent problematic device stacking, clear the queue flag
1895 * for request stacking support until then.
1896 *
1897 * This queue is new, so no concurrency on the queue_flags.
1898 */
1899 queue_flag_clear_unlocked(QUEUE_FLAG_STACKABLE, md->queue);
1900 md->saved_make_request_fn = md->queue->make_request_fn;
1901 md->queue->queuedata = md;
1902 md->queue->backing_dev_info.congested_fn = dm_any_congested;
1903 md->queue->backing_dev_info.congested_data = md;
1904 blk_queue_make_request(md->queue, dm_request);
1905 blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
1906 md->queue->unplug_fn = dm_unplug_all;
1907 blk_queue_merge_bvec(md->queue, dm_merge_bvec);
1908 blk_queue_softirq_done(md->queue, dm_softirq_done);
1909 blk_queue_prep_rq(md->queue, dm_prep_fn);
1910 blk_queue_lld_busy(md->queue, dm_lld_busy);
1911 blk_queue_ordered(md->queue, QUEUE_ORDERED_DRAIN_FLUSH);
1912 1989
1913 md->disk = alloc_disk(1); 1990 md->disk = alloc_disk(1);
1914 if (!md->disk) 1991 if (!md->disk)
@@ -2123,6 +2200,72 @@ int dm_create(int minor, struct mapped_device **result)
2123 return 0; 2200 return 0;
2124} 2201}
2125 2202
2203/*
2204 * Functions to manage md->type.
2205 * All are required to hold md->type_lock.
2206 */
2207void dm_lock_md_type(struct mapped_device *md)
2208{
2209 mutex_lock(&md->type_lock);
2210}
2211
2212void dm_unlock_md_type(struct mapped_device *md)
2213{
2214 mutex_unlock(&md->type_lock);
2215}
2216
2217void dm_set_md_type(struct mapped_device *md, unsigned type)
2218{
2219 md->type = type;
2220}
2221
2222unsigned dm_get_md_type(struct mapped_device *md)
2223{
2224 return md->type;
2225}
2226
2227/*
2228 * Fully initialize a request-based queue (->elevator, ->request_fn, etc).
2229 */
2230static int dm_init_request_based_queue(struct mapped_device *md)
2231{
2232 struct request_queue *q = NULL;
2233
2234 if (md->queue->elevator)
2235 return 1;
2236
2237 /* Fully initialize the queue */
2238 q = blk_init_allocated_queue(md->queue, dm_request_fn, NULL);
2239 if (!q)
2240 return 0;
2241
2242 md->queue = q;
2243 md->saved_make_request_fn = md->queue->make_request_fn;
2244 dm_init_md_queue(md);
2245 blk_queue_softirq_done(md->queue, dm_softirq_done);
2246 blk_queue_prep_rq(md->queue, dm_prep_fn);
2247 blk_queue_lld_busy(md->queue, dm_lld_busy);
2248 blk_queue_ordered(md->queue, QUEUE_ORDERED_DRAIN_FLUSH);
2249
2250 elv_register_queue(md->queue);
2251
2252 return 1;
2253}
2254
2255/*
2256 * Setup the DM device's queue based on md's type
2257 */
2258int dm_setup_md_queue(struct mapped_device *md)
2259{
2260 if ((dm_get_md_type(md) == DM_TYPE_REQUEST_BASED) &&
2261 !dm_init_request_based_queue(md)) {
2262 DMWARN("Cannot initialize queue for request-based mapped device");
2263 return -EINVAL;
2264 }
2265
2266 return 0;
2267}
2268
2126static struct mapped_device *dm_find_md(dev_t dev) 2269static struct mapped_device *dm_find_md(dev_t dev)
2127{ 2270{
2128 struct mapped_device *md; 2271 struct mapped_device *md;
@@ -2136,6 +2279,7 @@ static struct mapped_device *dm_find_md(dev_t dev)
2136 md = idr_find(&_minor_idr, minor); 2279 md = idr_find(&_minor_idr, minor);
2137 if (md && (md == MINOR_ALLOCED || 2280 if (md && (md == MINOR_ALLOCED ||
2138 (MINOR(disk_devt(dm_disk(md))) != minor) || 2281 (MINOR(disk_devt(dm_disk(md))) != minor) ||
2282 dm_deleting_md(md) ||
2139 test_bit(DMF_FREEING, &md->flags))) { 2283 test_bit(DMF_FREEING, &md->flags))) {
2140 md = NULL; 2284 md = NULL;
2141 goto out; 2285 goto out;
@@ -2170,6 +2314,7 @@ void dm_set_mdptr(struct mapped_device *md, void *ptr)
2170void dm_get(struct mapped_device *md) 2314void dm_get(struct mapped_device *md)
2171{ 2315{
2172 atomic_inc(&md->holders); 2316 atomic_inc(&md->holders);
2317 BUG_ON(test_bit(DMF_FREEING, &md->flags));
2173} 2318}
2174 2319
2175const char *dm_device_name(struct mapped_device *md) 2320const char *dm_device_name(struct mapped_device *md)
@@ -2178,27 +2323,55 @@ const char *dm_device_name(struct mapped_device *md)
2178} 2323}
2179EXPORT_SYMBOL_GPL(dm_device_name); 2324EXPORT_SYMBOL_GPL(dm_device_name);
2180 2325
2181void dm_put(struct mapped_device *md) 2326static void __dm_destroy(struct mapped_device *md, bool wait)
2182{ 2327{
2183 struct dm_table *map; 2328 struct dm_table *map;
2184 2329
2185 BUG_ON(test_bit(DMF_FREEING, &md->flags)); 2330 might_sleep();
2186 2331
2187 if (atomic_dec_and_lock(&md->holders, &_minor_lock)) { 2332 spin_lock(&_minor_lock);
2188 map = dm_get_live_table(md); 2333 map = dm_get_live_table(md);
2189 idr_replace(&_minor_idr, MINOR_ALLOCED, 2334 idr_replace(&_minor_idr, MINOR_ALLOCED, MINOR(disk_devt(dm_disk(md))));
2190 MINOR(disk_devt(dm_disk(md)))); 2335 set_bit(DMF_FREEING, &md->flags);
2191 set_bit(DMF_FREEING, &md->flags); 2336 spin_unlock(&_minor_lock);
2192 spin_unlock(&_minor_lock); 2337
2193 if (!dm_suspended_md(md)) { 2338 if (!dm_suspended_md(md)) {
2194 dm_table_presuspend_targets(map); 2339 dm_table_presuspend_targets(map);
2195 dm_table_postsuspend_targets(map); 2340 dm_table_postsuspend_targets(map);
2196 }
2197 dm_sysfs_exit(md);
2198 dm_table_put(map);
2199 dm_table_destroy(__unbind(md));
2200 free_dev(md);
2201 } 2341 }
2342
2343 /*
2344 * Rare, but there may be I/O requests still going to complete,
2345 * for example. Wait for all references to disappear.
2346 * No one should increment the reference count of the mapped_device,
2347 * after the mapped_device state becomes DMF_FREEING.
2348 */
2349 if (wait)
2350 while (atomic_read(&md->holders))
2351 msleep(1);
2352 else if (atomic_read(&md->holders))
2353 DMWARN("%s: Forcibly removing mapped_device still in use! (%d users)",
2354 dm_device_name(md), atomic_read(&md->holders));
2355
2356 dm_sysfs_exit(md);
2357 dm_table_put(map);
2358 dm_table_destroy(__unbind(md));
2359 free_dev(md);
2360}
2361
2362void dm_destroy(struct mapped_device *md)
2363{
2364 __dm_destroy(md, true);
2365}
2366
2367void dm_destroy_immediate(struct mapped_device *md)
2368{
2369 __dm_destroy(md, false);
2370}
2371
2372void dm_put(struct mapped_device *md)
2373{
2374 atomic_dec(&md->holders);
2202} 2375}
2203EXPORT_SYMBOL_GPL(dm_put); 2376EXPORT_SYMBOL_GPL(dm_put);
2204 2377
@@ -2253,7 +2426,12 @@ static void process_barrier(struct mapped_device *md, struct bio *bio)
2253 2426
2254 if (!bio_empty_barrier(bio)) { 2427 if (!bio_empty_barrier(bio)) {
2255 __split_and_process_bio(md, bio); 2428 __split_and_process_bio(md, bio);
2256 dm_flush(md); 2429 /*
2430 * If the request isn't supported, don't waste time with
2431 * the second flush.
2432 */
2433 if (md->barrier_error != -EOPNOTSUPP)
2434 dm_flush(md);
2257 } 2435 }
2258 2436
2259 if (md->barrier_error != DM_ENDIO_REQUEUE) 2437 if (md->barrier_error != DM_ENDIO_REQUEUE)
@@ -2310,11 +2488,11 @@ static void dm_queue_flush(struct mapped_device *md)
2310 queue_work(md->wq, &md->work); 2488 queue_work(md->wq, &md->work);
2311} 2489}
2312 2490
2313static void dm_rq_set_flush_nr(struct request *clone, unsigned flush_nr) 2491static void dm_rq_set_target_request_nr(struct request *clone, unsigned request_nr)
2314{ 2492{
2315 struct dm_rq_target_io *tio = clone->end_io_data; 2493 struct dm_rq_target_io *tio = clone->end_io_data;
2316 2494
2317 tio->info.flush_request = flush_nr; 2495 tio->info.target_request_nr = request_nr;
2318} 2496}
2319 2497
2320/* Issue barrier requests to targets and wait for their completion. */ 2498/* Issue barrier requests to targets and wait for their completion. */
@@ -2332,7 +2510,7 @@ static int dm_rq_barrier(struct mapped_device *md)
2332 ti = dm_table_get_target(map, i); 2510 ti = dm_table_get_target(map, i);
2333 for (j = 0; j < ti->num_flush_requests; j++) { 2511 for (j = 0; j < ti->num_flush_requests; j++) {
2334 clone = clone_rq(md->flush_request, md, GFP_NOIO); 2512 clone = clone_rq(md->flush_request, md, GFP_NOIO);
2335 dm_rq_set_flush_nr(clone, j); 2513 dm_rq_set_target_request_nr(clone, j);
2336 atomic_inc(&md->pending[rq_data_dir(clone)]); 2514 atomic_inc(&md->pending[rq_data_dir(clone)]);
2337 map_request(ti, clone, md); 2515 map_request(ti, clone, md);
2338 } 2516 }
@@ -2398,13 +2576,6 @@ struct dm_table *dm_swap_table(struct mapped_device *md, struct dm_table *table)
2398 goto out; 2576 goto out;
2399 } 2577 }
2400 2578
2401 /* cannot change the device type, once a table is bound */
2402 if (md->map &&
2403 (dm_table_get_type(md->map) != dm_table_get_type(table))) {
2404 DMWARN("can't change the device type after a table is bound");
2405 goto out;
2406 }
2407
2408 map = __bind(md, table, &limits); 2579 map = __bind(md, table, &limits);
2409 2580
2410out: 2581out:
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index bad1724d4869..0c2dd5f4af76 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -59,13 +59,20 @@ void dm_table_postsuspend_targets(struct dm_table *t);
59int dm_table_resume_targets(struct dm_table *t); 59int dm_table_resume_targets(struct dm_table *t);
60int dm_table_any_congested(struct dm_table *t, int bdi_bits); 60int dm_table_any_congested(struct dm_table *t, int bdi_bits);
61int dm_table_any_busy_target(struct dm_table *t); 61int dm_table_any_busy_target(struct dm_table *t);
62int dm_table_set_type(struct dm_table *t);
63unsigned dm_table_get_type(struct dm_table *t); 62unsigned dm_table_get_type(struct dm_table *t);
64bool dm_table_request_based(struct dm_table *t); 63bool dm_table_request_based(struct dm_table *t);
64bool dm_table_supports_discards(struct dm_table *t);
65int dm_table_alloc_md_mempools(struct dm_table *t); 65int dm_table_alloc_md_mempools(struct dm_table *t);
66void dm_table_free_md_mempools(struct dm_table *t); 66void dm_table_free_md_mempools(struct dm_table *t);
67struct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t); 67struct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t);
68 68
69void dm_lock_md_type(struct mapped_device *md);
70void dm_unlock_md_type(struct mapped_device *md);
71void dm_set_md_type(struct mapped_device *md, unsigned type);
72unsigned dm_get_md_type(struct mapped_device *md);
73
74int dm_setup_md_queue(struct mapped_device *md);
75
69/* 76/*
70 * To check the return value from dm_table_find_target(). 77 * To check the return value from dm_table_find_target().
71 */ 78 */
@@ -122,6 +129,11 @@ void dm_linear_exit(void);
122int dm_stripe_init(void); 129int dm_stripe_init(void);
123void dm_stripe_exit(void); 130void dm_stripe_exit(void);
124 131
132/*
133 * mapped_device operations
134 */
135void dm_destroy(struct mapped_device *md);
136void dm_destroy_immediate(struct mapped_device *md);
125int dm_open_count(struct mapped_device *md); 137int dm_open_count(struct mapped_device *md);
126int dm_lock_for_deletion(struct mapped_device *md); 138int dm_lock_for_deletion(struct mapped_device *md);
127 139
diff --git a/drivers/media/IR/Kconfig b/drivers/media/IR/Kconfig
index 30e04915a256..490c57cc4cfe 100644
--- a/drivers/media/IR/Kconfig
+++ b/drivers/media/IR/Kconfig
@@ -2,14 +2,21 @@ menuconfig IR_CORE
2 tristate "Infrared remote controller adapters" 2 tristate "Infrared remote controller adapters"
3 depends on INPUT 3 depends on INPUT
4 default INPUT 4 default INPUT
5 ---help---
6 Enable support for Remote Controllers on Linux. This is
7 needed in order to support several video capture adapters.
5 8
6if IR_CORE 9 Enable this option if you have a video capture board even
10 if you don't need IR, as otherwise, you may not be able to
11 compile the driver for your adapter.
7 12
8config VIDEO_IR 13config VIDEO_IR
9 tristate 14 tristate
10 depends on IR_CORE 15 depends on IR_CORE
11 default IR_CORE 16 default IR_CORE
12 17
18if IR_CORE
19
13config LIRC 20config LIRC
14 tristate 21 tristate
15 default y 22 default y
diff --git a/drivers/media/dvb/dm1105/Kconfig b/drivers/media/dvb/dm1105/Kconfig
index 695239227cb7..a6ceb08f1183 100644
--- a/drivers/media/dvb/dm1105/Kconfig
+++ b/drivers/media/dvb/dm1105/Kconfig
@@ -9,7 +9,7 @@ config DVB_DM1105
9 select DVB_CX24116 if !DVB_FE_CUSTOMISE 9 select DVB_CX24116 if !DVB_FE_CUSTOMISE
10 select DVB_SI21XX if !DVB_FE_CUSTOMISE 10 select DVB_SI21XX if !DVB_FE_CUSTOMISE
11 select DVB_DS3000 if !DVB_FE_CUSTOMISE 11 select DVB_DS3000 if !DVB_FE_CUSTOMISE
12 select VIDEO_IR 12 depends on VIDEO_IR
13 help 13 help
14 Support for cards based on the SDMC DM1105 PCI chip like 14 Support for cards based on the SDMC DM1105 PCI chip like
15 DvbWorld 2002 15 DvbWorld 2002
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index 553b48ac1919..fdc19bba2128 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -1,6 +1,6 @@
1config DVB_USB 1config DVB_USB
2 tristate "Support for various USB DVB devices" 2 tristate "Support for various USB DVB devices"
3 depends on DVB_CORE && USB && I2C && INPUT 3 depends on DVB_CORE && USB && I2C && IR_CORE
4 help 4 help
5 By enabling this you will be able to choose the various supported 5 By enabling this you will be able to choose the various supported
6 USB1.1 and USB2.0 DVB devices. 6 USB1.1 and USB2.0 DVB devices.
diff --git a/drivers/media/dvb/siano/Kconfig b/drivers/media/dvb/siano/Kconfig
index 85a222c4eaa0..e520bceee0af 100644
--- a/drivers/media/dvb/siano/Kconfig
+++ b/drivers/media/dvb/siano/Kconfig
@@ -4,7 +4,7 @@
4 4
5config SMS_SIANO_MDTV 5config SMS_SIANO_MDTV
6 tristate "Siano SMS1xxx based MDTV receiver" 6 tristate "Siano SMS1xxx based MDTV receiver"
7 depends on DVB_CORE && INPUT && HAS_DMA 7 depends on DVB_CORE && IR_CORE && HAS_DMA
8 ---help--- 8 ---help---
9 Choose Y or M here if you have MDTV receiver with a Siano chipset. 9 Choose Y or M here if you have MDTV receiver with a Siano chipset.
10 10
diff --git a/drivers/media/dvb/ttpci/Kconfig b/drivers/media/dvb/ttpci/Kconfig
index 32a7ec65ec42..debea8d1d31c 100644
--- a/drivers/media/dvb/ttpci/Kconfig
+++ b/drivers/media/dvb/ttpci/Kconfig
@@ -98,7 +98,7 @@ config DVB_BUDGET_CI
98 select DVB_LNBP21 if !DVB_FE_CUSTOMISE 98 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
99 select DVB_TDA10023 if !DVB_FE_CUSTOMISE 99 select DVB_TDA10023 if !DVB_FE_CUSTOMISE
100 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE 100 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE
101 select VIDEO_IR 101 depends on VIDEO_IR
102 help 102 help
103 Support for simple SAA7146 based DVB cards 103 Support for simple SAA7146 based DVB cards
104 (so called Budget- or Nova-PCI cards) without onboard 104 (so called Budget- or Nova-PCI cards) without onboard
diff --git a/drivers/media/video/bt8xx/Kconfig b/drivers/media/video/bt8xx/Kconfig
index 3077c45015f5..1a4a89fdf767 100644
--- a/drivers/media/video/bt8xx/Kconfig
+++ b/drivers/media/video/bt8xx/Kconfig
@@ -4,7 +4,7 @@ config VIDEO_BT848
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select VIDEO_BTCX 5 select VIDEO_BTCX
6 select VIDEOBUF_DMA_SG 6 select VIDEOBUF_DMA_SG
7 select VIDEO_IR 7 depends on VIDEO_IR
8 select VIDEO_TUNER 8 select VIDEO_TUNER
9 select VIDEO_TVEEPROM 9 select VIDEO_TVEEPROM
10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO 10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO
diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c
index 407fa61e4cda..685d6597ee79 100644
--- a/drivers/media/video/bt8xx/bttv-i2c.c
+++ b/drivers/media/video/bt8xx/bttv-i2c.c
@@ -411,7 +411,7 @@ void __devinit init_bttv_i2c_ir(struct bttv *btv)
411 411
412 memset(&info, 0, sizeof(struct i2c_board_info)); 412 memset(&info, 0, sizeof(struct i2c_board_info));
413 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 413 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
414 i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list); 414 i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL);
415 } 415 }
416} 416}
417 417
diff --git a/drivers/media/video/cx18/Kconfig b/drivers/media/video/cx18/Kconfig
index baf7e91ee0f5..76c054d1eef9 100644
--- a/drivers/media/video/cx18/Kconfig
+++ b/drivers/media/video/cx18/Kconfig
@@ -3,7 +3,7 @@ config VIDEO_CX18
3 depends on VIDEO_V4L2 && DVB_CORE && PCI && I2C && EXPERIMENTAL 3 depends on VIDEO_V4L2 && DVB_CORE && PCI && I2C && EXPERIMENTAL
4 depends on INPUT # due to VIDEO_IR 4 depends on INPUT # due to VIDEO_IR
5 select I2C_ALGOBIT 5 select I2C_ALGOBIT
6 select VIDEO_IR 6 depends on VIDEO_IR
7 select VIDEO_TUNER 7 select VIDEO_TUNER
8 select VIDEO_TVEEPROM 8 select VIDEO_TVEEPROM
9 select VIDEO_CX2341X 9 select VIDEO_CX2341X
diff --git a/drivers/media/video/cx18/cx18-i2c.c b/drivers/media/video/cx18/cx18-i2c.c
index 809f7d37129c..73ce90c2f577 100644
--- a/drivers/media/video/cx18/cx18-i2c.c
+++ b/drivers/media/video/cx18/cx18-i2c.c
@@ -117,7 +117,8 @@ static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw,
117 break; 117 break;
118 } 118 }
119 119
120 return i2c_new_probed_device(adap, &info, addr_list) == NULL ? -1 : 0; 120 return i2c_new_probed_device(adap, &info, addr_list, NULL) == NULL ?
121 -1 : 0;
121} 122}
122 123
123int cx18_i2c_register(struct cx18 *cx, unsigned idx) 124int cx18_i2c_register(struct cx18 *cx, unsigned idx)
diff --git a/drivers/media/video/cx231xx/Kconfig b/drivers/media/video/cx231xx/Kconfig
index 477d4ab5e9ac..5ac7eceececa 100644
--- a/drivers/media/video/cx231xx/Kconfig
+++ b/drivers/media/video/cx231xx/Kconfig
@@ -3,7 +3,7 @@ config VIDEO_CX231XX
3 depends on VIDEO_DEV && I2C && INPUT 3 depends on VIDEO_DEV && I2C && INPUT
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_TVEEPROM 5 select VIDEO_TVEEPROM
6 select VIDEO_IR 6 depends on VIDEO_IR
7 select VIDEOBUF_VMALLOC 7 select VIDEOBUF_VMALLOC
8 select VIDEO_CX25840 8 select VIDEO_CX25840
9 9
diff --git a/drivers/media/video/cx23885/Kconfig b/drivers/media/video/cx23885/Kconfig
index 768f000e4b21..e1367b35647a 100644
--- a/drivers/media/video/cx23885/Kconfig
+++ b/drivers/media/video/cx23885/Kconfig
@@ -5,7 +5,7 @@ config VIDEO_CX23885
5 select VIDEO_BTCX 5 select VIDEO_BTCX
6 select VIDEO_TUNER 6 select VIDEO_TUNER
7 select VIDEO_TVEEPROM 7 select VIDEO_TVEEPROM
8 select IR_CORE 8 depends on IR_CORE
9 select VIDEOBUF_DVB 9 select VIDEOBUF_DVB
10 select VIDEOBUF_DMA_SG 10 select VIDEOBUF_DMA_SG
11 select VIDEO_CX25840 11 select VIDEO_CX25840
diff --git a/drivers/media/video/cx23885/cx23885-i2c.c b/drivers/media/video/cx23885/cx23885-i2c.c
index 1a391486e551..ed3d8f55029b 100644
--- a/drivers/media/video/cx23885/cx23885-i2c.c
+++ b/drivers/media/video/cx23885/cx23885-i2c.c
@@ -364,17 +364,10 @@ int cx23885_i2c_register(struct cx23885_i2c *bus)
364 364
365 memset(&info, 0, sizeof(struct i2c_board_info)); 365 memset(&info, 0, sizeof(struct i2c_board_info));
366 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 366 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
367 /* 367 /* Use quick read command for probe, some IR chips don't
368 * We can't call i2c_new_probed_device() because it uses 368 * support writes */
369 * quick writes for probing and the IR receiver device only 369 i2c_new_probed_device(&bus->i2c_adap, &info, addr_list,
370 * replies to reads. 370 i2c_probe_func_quick_read);
371 */
372 if (i2c_smbus_xfer(&bus->i2c_adap, addr_list[0], 0,
373 I2C_SMBUS_READ, 0, I2C_SMBUS_QUICK,
374 NULL) >= 0) {
375 info.addr = addr_list[0];
376 i2c_new_device(&bus->i2c_adap, &info);
377 }
378 } 371 }
379 372
380 return bus->i2c_rc; 373 return bus->i2c_rc;
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index c7e5851d3486..99dbae117591 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -6,7 +6,7 @@ config VIDEO_CX88
6 select VIDEOBUF_DMA_SG 6 select VIDEOBUF_DMA_SG
7 select VIDEO_TUNER 7 select VIDEO_TUNER
8 select VIDEO_TVEEPROM 8 select VIDEO_TVEEPROM
9 select VIDEO_IR 9 depends on VIDEO_IR
10 select VIDEO_WM8775 if VIDEO_HELPER_CHIPS_AUTO 10 select VIDEO_WM8775 if VIDEO_HELPER_CHIPS_AUTO
11 ---help--- 11 ---help---
12 This is a video4linux driver for Conexant 2388x based 12 This is a video4linux driver for Conexant 2388x based
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index 375ad53f7961..82db555b22dd 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -193,24 +193,13 @@ void cx88_i2c_init_ir(struct cx88_core *core)
193 0x18, 0x6b, 0x71, 193 0x18, 0x6b, 0x71,
194 I2C_CLIENT_END 194 I2C_CLIENT_END
195 }; 195 };
196 const unsigned short *addrp;
197 196
198 memset(&info, 0, sizeof(struct i2c_board_info)); 197 memset(&info, 0, sizeof(struct i2c_board_info));
199 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 198 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
200 /* 199 /* Use quick read command for probe, some IR chips don't
201 * We can't call i2c_new_probed_device() because it uses 200 * support writes */
202 * quick writes for probing and at least some R receiver 201 i2c_new_probed_device(&core->i2c_adap, &info, addr_list,
203 * devices only reply to reads. 202 i2c_probe_func_quick_read);
204 */
205 for (addrp = addr_list; *addrp != I2C_CLIENT_END; addrp++) {
206 if (i2c_smbus_xfer(&core->i2c_adap, *addrp, 0,
207 I2C_SMBUS_READ, 0,
208 I2C_SMBUS_QUICK, NULL) >= 0) {
209 info.addr = *addrp;
210 i2c_new_device(&core->i2c_adap, &info);
211 break;
212 }
213 }
214 } 203 }
215} 204}
216 205
diff --git a/drivers/media/video/em28xx/Kconfig b/drivers/media/video/em28xx/Kconfig
index c7be0e097828..66aefd6eef55 100644
--- a/drivers/media/video/em28xx/Kconfig
+++ b/drivers/media/video/em28xx/Kconfig
@@ -3,7 +3,7 @@ config VIDEO_EM28XX
3 depends on VIDEO_DEV && I2C && INPUT 3 depends on VIDEO_DEV && I2C && INPUT
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_TVEEPROM 5 select VIDEO_TVEEPROM
6 select VIDEO_IR 6 depends on VIDEO_IR
7 select VIDEOBUF_VMALLOC 7 select VIDEOBUF_VMALLOC
8 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO 8 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO
9 select VIDEO_TVP5150 if VIDEO_HELPER_CHIPS_AUTO 9 select VIDEO_TVP5150 if VIDEO_HELPER_CHIPS_AUTO
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index ffbe544e30f4..e7efb4bffabd 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -2385,7 +2385,7 @@ void em28xx_register_i2c_ir(struct em28xx *dev)
2385 2385
2386 if (dev->init_data.name) 2386 if (dev->init_data.name)
2387 info.platform_data = &dev->init_data; 2387 info.platform_data = &dev->init_data;
2388 i2c_new_probed_device(&dev->i2c_adap, &info, addr_list); 2388 i2c_new_probed_device(&dev->i2c_adap, &info, addr_list, NULL);
2389} 2389}
2390 2390
2391void em28xx_card_setup(struct em28xx *dev) 2391void em28xx_card_setup(struct em28xx *dev)
diff --git a/drivers/media/video/fsl-viu.c b/drivers/media/video/fsl-viu.c
index 8f1c94f7e00c..43d208f1f586 100644
--- a/drivers/media/video/fsl-viu.c
+++ b/drivers/media/video/fsl-viu.c
@@ -1418,7 +1418,7 @@ static struct video_device viu_template = {
1418 .current_norm = V4L2_STD_NTSC_M, 1418 .current_norm = V4L2_STD_NTSC_M,
1419}; 1419};
1420 1420
1421static int __devinit viu_of_probe(struct of_device *op, 1421static int __devinit viu_of_probe(struct platform_device *op,
1422 const struct of_device_id *match) 1422 const struct of_device_id *match)
1423{ 1423{
1424 struct viu_dev *viu_dev; 1424 struct viu_dev *viu_dev;
@@ -1549,7 +1549,7 @@ err:
1549 return ret; 1549 return ret;
1550} 1550}
1551 1551
1552static int __devexit viu_of_remove(struct of_device *op) 1552static int __devexit viu_of_remove(struct platform_device *op)
1553{ 1553{
1554 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev); 1554 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev);
1555 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev); 1555 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev);
@@ -1570,7 +1570,7 @@ static int __devexit viu_of_remove(struct of_device *op)
1570} 1570}
1571 1571
1572#ifdef CONFIG_PM 1572#ifdef CONFIG_PM
1573static int viu_suspend(struct of_device *op, pm_message_t state) 1573static int viu_suspend(struct platform_device *op, pm_message_t state)
1574{ 1574{
1575 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev); 1575 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev);
1576 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev); 1576 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev);
@@ -1579,7 +1579,7 @@ static int viu_suspend(struct of_device *op, pm_message_t state)
1579 return 0; 1579 return 0;
1580} 1580}
1581 1581
1582static int viu_resume(struct of_device *op) 1582static int viu_resume(struct platform_device *op)
1583{ 1583{
1584 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev); 1584 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev);
1585 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev); 1585 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev);
diff --git a/drivers/media/video/ivtv/Kconfig b/drivers/media/video/ivtv/Kconfig
index c46bfb1569e3..be4af1fa557e 100644
--- a/drivers/media/video/ivtv/Kconfig
+++ b/drivers/media/video/ivtv/Kconfig
@@ -3,7 +3,7 @@ config VIDEO_IVTV
3 depends on VIDEO_V4L2 && PCI && I2C 3 depends on VIDEO_V4L2 && PCI && I2C
4 depends on INPUT # due to VIDEO_IR 4 depends on INPUT # due to VIDEO_IR
5 select I2C_ALGOBIT 5 select I2C_ALGOBIT
6 select VIDEO_IR 6 depends on VIDEO_IR
7 select VIDEO_TUNER 7 select VIDEO_TUNER
8 select VIDEO_TVEEPROM 8 select VIDEO_TVEEPROM
9 select VIDEO_CX2341X 9 select VIDEO_CX2341X
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index d391bbdb0b8a..a74fa099c565 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -183,8 +183,8 @@ static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr)
183 return -1; 183 return -1;
184 memset(&info, 0, sizeof(struct i2c_board_info)); 184 memset(&info, 0, sizeof(struct i2c_board_info));
185 strlcpy(info.type, type, I2C_NAME_SIZE); 185 strlcpy(info.type, type, I2C_NAME_SIZE);
186 return i2c_new_probed_device(adap, &info, addr_list) == NULL 186 return i2c_new_probed_device(adap, &info, addr_list, NULL)
187 ? -1 : 0; 187 == NULL ? -1 : 0;
188 } 188 }
189 189
190 /* Only allow one IR receiver to be registered per board */ 190 /* Only allow one IR receiver to be registered per board */
@@ -221,7 +221,8 @@ static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr)
221 info.platform_data = init_data; 221 info.platform_data = init_data;
222 strlcpy(info.type, type, I2C_NAME_SIZE); 222 strlcpy(info.type, type, I2C_NAME_SIZE);
223 223
224 return i2c_new_probed_device(adap, &info, addr_list) == NULL ? -1 : 0; 224 return i2c_new_probed_device(adap, &info, addr_list, NULL) == NULL ?
225 -1 : 0;
225} 226}
226 227
227/* Instantiate the IR receiver device using probing -- undesirable */ 228/* Instantiate the IR receiver device using probing -- undesirable */
@@ -249,7 +250,7 @@ struct i2c_client *ivtv_i2c_new_ir_legacy(struct ivtv *itv)
249 250
250 memset(&info, 0, sizeof(struct i2c_board_info)); 251 memset(&info, 0, sizeof(struct i2c_board_info));
251 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 252 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
252 return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list); 253 return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list, NULL);
253} 254}
254 255
255int ivtv_i2c_register(struct ivtv *itv, unsigned idx) 256int ivtv_i2c_register(struct ivtv *itv, unsigned idx)
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index 22bfd62c9551..fda005e01670 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -2,7 +2,7 @@ config VIDEO_SAA7134
2 tristate "Philips SAA7134 support" 2 tristate "Philips SAA7134 support"
3 depends on VIDEO_DEV && PCI && I2C && INPUT 3 depends on VIDEO_DEV && PCI && I2C && INPUT
4 select VIDEOBUF_DMA_SG 4 select VIDEOBUF_DMA_SG
5 select VIDEO_IR 5 depends on VIDEO_IR
6 select VIDEO_TUNER 6 select VIDEO_TUNER
7 select VIDEO_TVEEPROM 7 select VIDEO_TVEEPROM
8 select CRC32 8 select CRC32
diff --git a/drivers/media/video/tlg2300/Kconfig b/drivers/media/video/tlg2300/Kconfig
index 2c29ec659b4e..1686ebfa6951 100644
--- a/drivers/media/video/tlg2300/Kconfig
+++ b/drivers/media/video/tlg2300/Kconfig
@@ -3,7 +3,7 @@ config VIDEO_TLG2300
3 depends on VIDEO_DEV && I2C && INPUT && SND && DVB_CORE 3 depends on VIDEO_DEV && I2C && INPUT && SND && DVB_CORE
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_TVEEPROM 5 select VIDEO_TVEEPROM
6 select VIDEO_IR 6 depends on VIDEO_IR
7 select VIDEOBUF_VMALLOC 7 select VIDEOBUF_VMALLOC
8 select SND_PCM 8 select SND_PCM
9 select VIDEOBUF_DVB 9 select VIDEOBUF_DVB
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 3ce7c64e5789..8ee1179be926 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -381,7 +381,8 @@ struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
381 381
382 /* Create the i2c client */ 382 /* Create the i2c client */
383 if (info->addr == 0 && probe_addrs) 383 if (info->addr == 0 && probe_addrs)
384 client = i2c_new_probed_device(adapter, info, probe_addrs); 384 client = i2c_new_probed_device(adapter, info, probe_addrs,
385 NULL);
385 else 386 else
386 client = i2c_new_device(adapter, info); 387 client = i2c_new_device(adapter, info);
387 388
diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c
index 84c1a53a727a..ea8d32cd425d 100644
--- a/drivers/media/video/v4l2-ctrls.c
+++ b/drivers/media/video/v4l2-ctrls.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <linux/ctype.h> 21#include <linux/ctype.h>
22#include <linux/slab.h>
22#include <media/v4l2-ioctl.h> 23#include <media/v4l2-ioctl.h>
23#include <media/v4l2-device.h> 24#include <media/v4l2-device.h>
24#include <media/v4l2-ctrls.h> 25#include <media/v4l2-ctrls.h>
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index eef78a068fd1..d3f1a087eced 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -1048,6 +1048,7 @@ static int mspro_block_read_attributes(struct memstick_dev *card)
1048 snprintf(s_attr->name, sizeof(s_attr->name), 1048 snprintf(s_attr->name, sizeof(s_attr->name),
1049 "attr_x%02x", attr->entries[cnt].id); 1049 "attr_x%02x", attr->entries[cnt].id);
1050 1050
1051 sysfs_attr_init(&s_attr->dev_attr.attr);
1051 s_attr->dev_attr.attr.name = s_attr->name; 1052 s_attr->dev_attr.attr.name = s_attr->name;
1052 s_attr->dev_attr.attr.mode = S_IRUGO; 1053 s_attr->dev_attr.attr.mode = S_IRUGO;
1053 s_attr->dev_attr.show = mspro_block_attr_show(s_attr->id); 1054 s_attr->dev_attr.show = mspro_block_attr_show(s_attr->id);
@@ -1338,13 +1339,14 @@ static void mspro_block_remove(struct memstick_dev *card)
1338 struct mspro_block_data *msb = memstick_get_drvdata(card); 1339 struct mspro_block_data *msb = memstick_get_drvdata(card);
1339 unsigned long flags; 1340 unsigned long flags;
1340 1341
1341 del_gendisk(msb->disk);
1342 dev_dbg(&card->dev, "mspro block remove\n");
1343 spin_lock_irqsave(&msb->q_lock, flags); 1342 spin_lock_irqsave(&msb->q_lock, flags);
1344 msb->eject = 1; 1343 msb->eject = 1;
1345 blk_start_queue(msb->queue); 1344 blk_start_queue(msb->queue);
1346 spin_unlock_irqrestore(&msb->q_lock, flags); 1345 spin_unlock_irqrestore(&msb->q_lock, flags);
1347 1346
1347 del_gendisk(msb->disk);
1348 dev_dbg(&card->dev, "mspro block remove\n");
1349
1348 blk_cleanup_queue(msb->queue); 1350 blk_cleanup_queue(msb->queue);
1349 msb->queue = NULL; 1351 msb->queue = NULL;
1350 1352
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index b88a244a1edd..b8f1719d7c02 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -50,6 +50,7 @@
50#include <linux/module.h> 50#include <linux/module.h>
51#include <linux/errno.h> 51#include <linux/errno.h>
52#include <linux/init.h> 52#include <linux/init.h>
53#include <linux/seq_file.h>
53#include <linux/slab.h> 54#include <linux/slab.h>
54#include <linux/types.h> 55#include <linux/types.h>
55#include <linux/pci.h> 56#include <linux/pci.h>
@@ -109,8 +110,7 @@ MODULE_PARM_DESC(mpt_debug_level, " debug level - refer to mptdebug.h \
109 110
110int mpt_fwfault_debug; 111int mpt_fwfault_debug;
111EXPORT_SYMBOL(mpt_fwfault_debug); 112EXPORT_SYMBOL(mpt_fwfault_debug);
112module_param_call(mpt_fwfault_debug, param_set_int, param_get_int, 113module_param(mpt_fwfault_debug, int, 0600);
113 &mpt_fwfault_debug, 0600);
114MODULE_PARM_DESC(mpt_fwfault_debug, "Enable detection of Firmware fault" 114MODULE_PARM_DESC(mpt_fwfault_debug, "Enable detection of Firmware fault"
115 " and halt Firmware on fault - (default=0)"); 115 " and halt Firmware on fault - (default=0)");
116 116
@@ -200,12 +200,9 @@ static int mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_valu
200static int mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init); 200static int mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init);
201 201
202#ifdef CONFIG_PROC_FS 202#ifdef CONFIG_PROC_FS
203static int procmpt_summary_read(char *buf, char **start, off_t offset, 203static const struct file_operations mpt_summary_proc_fops;
204 int request, int *eof, void *data); 204static const struct file_operations mpt_version_proc_fops;
205static int procmpt_version_read(char *buf, char **start, off_t offset, 205static const struct file_operations mpt_iocinfo_proc_fops;
206 int request, int *eof, void *data);
207static int procmpt_iocinfo_read(char *buf, char **start, off_t offset,
208 int request, int *eof, void *data);
209#endif 206#endif
210static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc); 207static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
211 208
@@ -1725,7 +1722,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1725 u8 pcixcmd; 1722 u8 pcixcmd;
1726 static int mpt_ids = 0; 1723 static int mpt_ids = 0;
1727#ifdef CONFIG_PROC_FS 1724#ifdef CONFIG_PROC_FS
1728 struct proc_dir_entry *dent, *ent; 1725 struct proc_dir_entry *dent;
1729#endif 1726#endif
1730 1727
1731 ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC); 1728 ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
@@ -1980,16 +1977,8 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1980 */ 1977 */
1981 dent = proc_mkdir(ioc->name, mpt_proc_root_dir); 1978 dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
1982 if (dent) { 1979 if (dent) {
1983 ent = create_proc_entry("info", S_IFREG|S_IRUGO, dent); 1980 proc_create_data("info", S_IRUGO, dent, &mpt_iocinfo_proc_fops, ioc);
1984 if (ent) { 1981 proc_create_data("summary", S_IRUGO, dent, &mpt_summary_proc_fops, ioc);
1985 ent->read_proc = procmpt_iocinfo_read;
1986 ent->data = ioc;
1987 }
1988 ent = create_proc_entry("summary", S_IFREG|S_IRUGO, dent);
1989 if (ent) {
1990 ent->read_proc = procmpt_summary_read;
1991 ent->data = ioc;
1992 }
1993 } 1982 }
1994#endif 1983#endif
1995 1984
@@ -6546,20 +6535,12 @@ mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
6546static int 6535static int
6547procmpt_create(void) 6536procmpt_create(void)
6548{ 6537{
6549 struct proc_dir_entry *ent;
6550
6551 mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL); 6538 mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
6552 if (mpt_proc_root_dir == NULL) 6539 if (mpt_proc_root_dir == NULL)
6553 return -ENOTDIR; 6540 return -ENOTDIR;
6554 6541
6555 ent = create_proc_entry("summary", S_IFREG|S_IRUGO, mpt_proc_root_dir); 6542 proc_create("summary", S_IRUGO, mpt_proc_root_dir, &mpt_summary_proc_fops);
6556 if (ent) 6543 proc_create("version", S_IRUGO, mpt_proc_root_dir, &mpt_version_proc_fops);
6557 ent->read_proc = procmpt_summary_read;
6558
6559 ent = create_proc_entry("version", S_IFREG|S_IRUGO, mpt_proc_root_dir);
6560 if (ent)
6561 ent->read_proc = procmpt_version_read;
6562
6563 return 0; 6544 return 0;
6564} 6545}
6565 6546
@@ -6579,70 +6560,46 @@ procmpt_destroy(void)
6579 6560
6580/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 6561/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6581/** 6562/**
6582 * procmpt_summary_read - Handle read request of a summary file
6583 * @buf: Pointer to area to write information
6584 * @start: Pointer to start pointer
6585 * @offset: Offset to start writing
6586 * @request: Amount of read data requested
6587 * @eof: Pointer to EOF integer
6588 * @data: Pointer
6589 *
6590 * Handles read request from /proc/mpt/summary or /proc/mpt/iocN/summary. 6563 * Handles read request from /proc/mpt/summary or /proc/mpt/iocN/summary.
6591 * Returns number of characters written to process performing the read.
6592 */ 6564 */
6593static int 6565static void seq_mpt_print_ioc_summary(MPT_ADAPTER *ioc, struct seq_file *m, int showlan);
6594procmpt_summary_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
6595{
6596 MPT_ADAPTER *ioc;
6597 char *out = buf;
6598 int len;
6599 6566
6600 if (data) { 6567static int mpt_summary_proc_show(struct seq_file *m, void *v)
6601 int more = 0; 6568{
6602 6569 MPT_ADAPTER *ioc = m->private;
6603 ioc = data;
6604 mpt_print_ioc_summary(ioc, out, &more, 0, 1);
6605 6570
6606 out += more; 6571 if (ioc) {
6572 seq_mpt_print_ioc_summary(ioc, m, 1);
6607 } else { 6573 } else {
6608 list_for_each_entry(ioc, &ioc_list, list) { 6574 list_for_each_entry(ioc, &ioc_list, list) {
6609 int more = 0; 6575 seq_mpt_print_ioc_summary(ioc, m, 1);
6610
6611 mpt_print_ioc_summary(ioc, out, &more, 0, 1);
6612
6613 out += more;
6614 if ((out-buf) >= request)
6615 break;
6616 } 6576 }
6617 } 6577 }
6618 6578
6619 len = out - buf; 6579 return 0;
6580}
6620 6581
6621 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len); 6582static int mpt_summary_proc_open(struct inode *inode, struct file *file)
6583{
6584 return single_open(file, mpt_summary_proc_show, PDE(inode)->data);
6622} 6585}
6623 6586
6624/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 6587static const struct file_operations mpt_summary_proc_fops = {
6625/** 6588 .owner = THIS_MODULE,
6626 * procmpt_version_read - Handle read request from /proc/mpt/version. 6589 .open = mpt_summary_proc_open,
6627 * @buf: Pointer to area to write information 6590 .read = seq_read,
6628 * @start: Pointer to start pointer 6591 .llseek = seq_lseek,
6629 * @offset: Offset to start writing 6592 .release = single_release,
6630 * @request: Amount of read data requested 6593};
6631 * @eof: Pointer to EOF integer 6594
6632 * @data: Pointer 6595static int mpt_version_proc_show(struct seq_file *m, void *v)
6633 *
6634 * Returns number of characters written to process performing the read.
6635 */
6636static int
6637procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
6638{ 6596{
6639 u8 cb_idx; 6597 u8 cb_idx;
6640 int scsi, fc, sas, lan, ctl, targ, dmp; 6598 int scsi, fc, sas, lan, ctl, targ, dmp;
6641 char *drvname; 6599 char *drvname;
6642 int len;
6643 6600
6644 len = sprintf(buf, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON); 6601 seq_printf(m, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
6645 len += sprintf(buf+len, " Fusion MPT base driver\n"); 6602 seq_printf(m, " Fusion MPT base driver\n");
6646 6603
6647 scsi = fc = sas = lan = ctl = targ = dmp = 0; 6604 scsi = fc = sas = lan = ctl = targ = dmp = 0;
6648 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) { 6605 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
@@ -6670,98 +6627,97 @@ procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eo
6670 } 6627 }
6671 6628
6672 if (drvname) 6629 if (drvname)
6673 len += sprintf(buf+len, " Fusion MPT %s driver\n", drvname); 6630 seq_printf(m, " Fusion MPT %s driver\n", drvname);
6674 } 6631 }
6675 } 6632 }
6676 6633
6677 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len); 6634 return 0;
6678} 6635}
6679 6636
6680/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 6637static int mpt_version_proc_open(struct inode *inode, struct file *file)
6681/** 6638{
6682 * procmpt_iocinfo_read - Handle read request from /proc/mpt/iocN/info. 6639 return single_open(file, mpt_version_proc_show, NULL);
6683 * @buf: Pointer to area to write information 6640}
6684 * @start: Pointer to start pointer 6641
6685 * @offset: Offset to start writing 6642static const struct file_operations mpt_version_proc_fops = {
6686 * @request: Amount of read data requested 6643 .owner = THIS_MODULE,
6687 * @eof: Pointer to EOF integer 6644 .open = mpt_version_proc_open,
6688 * @data: Pointer 6645 .read = seq_read,
6689 * 6646 .llseek = seq_lseek,
6690 * Returns number of characters written to process performing the read. 6647 .release = single_release,
6691 */ 6648};
6692static int 6649
6693procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eof, void *data) 6650static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
6694{ 6651{
6695 MPT_ADAPTER *ioc = data; 6652 MPT_ADAPTER *ioc = m->private;
6696 int len;
6697 char expVer[32]; 6653 char expVer[32];
6698 int sz; 6654 int sz;
6699 int p; 6655 int p;
6700 6656
6701 mpt_get_fw_exp_ver(expVer, ioc); 6657 mpt_get_fw_exp_ver(expVer, ioc);
6702 6658
6703 len = sprintf(buf, "%s:", ioc->name); 6659 seq_printf(m, "%s:", ioc->name);
6704 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT) 6660 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
6705 len += sprintf(buf+len, " (f/w download boot flag set)"); 6661 seq_printf(m, " (f/w download boot flag set)");
6706// if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL) 6662// if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
6707// len += sprintf(buf+len, " CONFIG_CHECKSUM_FAIL!"); 6663// seq_printf(m, " CONFIG_CHECKSUM_FAIL!");
6708 6664
6709 len += sprintf(buf+len, "\n ProductID = 0x%04x (%s)\n", 6665 seq_printf(m, "\n ProductID = 0x%04x (%s)\n",
6710 ioc->facts.ProductID, 6666 ioc->facts.ProductID,
6711 ioc->prod_name); 6667 ioc->prod_name);
6712 len += sprintf(buf+len, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer); 6668 seq_printf(m, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
6713 if (ioc->facts.FWImageSize) 6669 if (ioc->facts.FWImageSize)
6714 len += sprintf(buf+len, " (fw_size=%d)", ioc->facts.FWImageSize); 6670 seq_printf(m, " (fw_size=%d)", ioc->facts.FWImageSize);
6715 len += sprintf(buf+len, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion); 6671 seq_printf(m, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
6716 len += sprintf(buf+len, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit); 6672 seq_printf(m, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
6717 len += sprintf(buf+len, " EventState = 0x%02x\n", ioc->facts.EventState); 6673 seq_printf(m, " EventState = 0x%02x\n", ioc->facts.EventState);
6718 6674
6719 len += sprintf(buf+len, " CurrentHostMfaHighAddr = 0x%08x\n", 6675 seq_printf(m, " CurrentHostMfaHighAddr = 0x%08x\n",
6720 ioc->facts.CurrentHostMfaHighAddr); 6676 ioc->facts.CurrentHostMfaHighAddr);
6721 len += sprintf(buf+len, " CurrentSenseBufferHighAddr = 0x%08x\n", 6677 seq_printf(m, " CurrentSenseBufferHighAddr = 0x%08x\n",
6722 ioc->facts.CurrentSenseBufferHighAddr); 6678 ioc->facts.CurrentSenseBufferHighAddr);
6723 6679
6724 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth); 6680 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
6725 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize); 6681 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
6726 6682
6727 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", 6683 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
6728 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma); 6684 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
6729 /* 6685 /*
6730 * Rounding UP to nearest 4-kB boundary here... 6686 * Rounding UP to nearest 4-kB boundary here...
6731 */ 6687 */
6732 sz = (ioc->req_sz * ioc->req_depth) + 128; 6688 sz = (ioc->req_sz * ioc->req_depth) + 128;
6733 sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000; 6689 sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
6734 len += sprintf(buf+len, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n", 6690 seq_printf(m, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
6735 ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz); 6691 ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
6736 len += sprintf(buf+len, " {MaxReqSz=%d} {MaxReqDepth=%d}\n", 6692 seq_printf(m, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
6737 4*ioc->facts.RequestFrameSize, 6693 4*ioc->facts.RequestFrameSize,
6738 ioc->facts.GlobalCredits); 6694 ioc->facts.GlobalCredits);
6739 6695
6740 len += sprintf(buf+len, " Frames @ 0x%p (Dma @ 0x%p)\n", 6696 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
6741 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma); 6697 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
6742 sz = (ioc->reply_sz * ioc->reply_depth) + 128; 6698 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
6743 len += sprintf(buf+len, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n", 6699 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
6744 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz); 6700 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
6745 len += sprintf(buf+len, " {MaxRepSz=%d} {MaxRepDepth=%d}\n", 6701 seq_printf(m, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
6746 ioc->facts.CurReplyFrameSize, 6702 ioc->facts.CurReplyFrameSize,
6747 ioc->facts.ReplyQueueDepth); 6703 ioc->facts.ReplyQueueDepth);
6748 6704
6749 len += sprintf(buf+len, " MaxDevices = %d\n", 6705 seq_printf(m, " MaxDevices = %d\n",
6750 (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices); 6706 (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
6751 len += sprintf(buf+len, " MaxBuses = %d\n", ioc->facts.MaxBuses); 6707 seq_printf(m, " MaxBuses = %d\n", ioc->facts.MaxBuses);
6752 6708
6753 /* per-port info */ 6709 /* per-port info */
6754 for (p=0; p < ioc->facts.NumberOfPorts; p++) { 6710 for (p=0; p < ioc->facts.NumberOfPorts; p++) {
6755 len += sprintf(buf+len, " PortNumber = %d (of %d)\n", 6711 seq_printf(m, " PortNumber = %d (of %d)\n",
6756 p+1, 6712 p+1,
6757 ioc->facts.NumberOfPorts); 6713 ioc->facts.NumberOfPorts);
6758 if (ioc->bus_type == FC) { 6714 if (ioc->bus_type == FC) {
6759 if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) { 6715 if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
6760 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow; 6716 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
6761 len += sprintf(buf+len, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n", 6717 seq_printf(m, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
6762 a[5], a[4], a[3], a[2], a[1], a[0]); 6718 a[5], a[4], a[3], a[2], a[1], a[0]);
6763 } 6719 }
6764 len += sprintf(buf+len, " WWN = %08X%08X:%08X%08X\n", 6720 seq_printf(m, " WWN = %08X%08X:%08X%08X\n",
6765 ioc->fc_port_page0[p].WWNN.High, 6721 ioc->fc_port_page0[p].WWNN.High,
6766 ioc->fc_port_page0[p].WWNN.Low, 6722 ioc->fc_port_page0[p].WWNN.Low,
6767 ioc->fc_port_page0[p].WWPN.High, 6723 ioc->fc_port_page0[p].WWPN.High,
@@ -6769,9 +6725,21 @@ procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eo
6769 } 6725 }
6770 } 6726 }
6771 6727
6772 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len); 6728 return 0;
6773} 6729}
6774 6730
6731static int mpt_iocinfo_proc_open(struct inode *inode, struct file *file)
6732{
6733 return single_open(file, mpt_iocinfo_proc_show, PDE(inode)->data);
6734}
6735
6736static const struct file_operations mpt_iocinfo_proc_fops = {
6737 .owner = THIS_MODULE,
6738 .open = mpt_iocinfo_proc_open,
6739 .read = seq_read,
6740 .llseek = seq_lseek,
6741 .release = single_release,
6742};
6775#endif /* CONFIG_PROC_FS } */ 6743#endif /* CONFIG_PROC_FS } */
6776 6744
6777/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 6745/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -6837,6 +6805,39 @@ mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int sh
6837 6805
6838 *size = y; 6806 *size = y;
6839} 6807}
6808
6809static void seq_mpt_print_ioc_summary(MPT_ADAPTER *ioc, struct seq_file *m, int showlan)
6810{
6811 char expVer[32];
6812
6813 mpt_get_fw_exp_ver(expVer, ioc);
6814
6815 /*
6816 * Shorter summary of attached ioc's...
6817 */
6818 seq_printf(m, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
6819 ioc->name,
6820 ioc->prod_name,
6821 MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
6822 ioc->facts.FWVersion.Word,
6823 expVer,
6824 ioc->facts.NumberOfPorts,
6825 ioc->req_depth);
6826
6827 if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
6828 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
6829 seq_printf(m, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
6830 a[5], a[4], a[3], a[2], a[1], a[0]);
6831 }
6832
6833 seq_printf(m, ", IRQ=%d", ioc->pci_irq);
6834
6835 if (!ioc->active)
6836 seq_printf(m, " (disabled)");
6837
6838 seq_putc(m, '\n');
6839}
6840
6840/** 6841/**
6841 * mpt_set_taskmgmt_in_progress_flag - set flags associated with task management 6842 * mpt_set_taskmgmt_in_progress_flag - set flags associated with task management
6842 * @ioc: Pointer to MPT_ADAPTER structure 6843 * @ioc: Pointer to MPT_ADAPTER structure
@@ -6922,7 +6923,6 @@ EXPORT_SYMBOL(mpt_halt_firmware);
6922 * mpt_SoftResetHandler - Issues a less expensive reset 6923 * mpt_SoftResetHandler - Issues a less expensive reset
6923 * @ioc: Pointer to MPT_ADAPTER structure 6924 * @ioc: Pointer to MPT_ADAPTER structure
6924 * @sleepFlag: Indicates if sleep or schedule must be called. 6925 * @sleepFlag: Indicates if sleep or schedule must be called.
6925
6926 * 6926 *
6927 * Returns 0 for SUCCESS or -1 if FAILED. 6927 * Returns 0 for SUCCESS or -1 if FAILED.
6928 * 6928 *
@@ -7067,7 +7067,6 @@ mpt_SoftResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
7067 * mpt_Soft_Hard_ResetHandler - Try less expensive reset 7067 * mpt_Soft_Hard_ResetHandler - Try less expensive reset
7068 * @ioc: Pointer to MPT_ADAPTER structure 7068 * @ioc: Pointer to MPT_ADAPTER structure
7069 * @sleepFlag: Indicates if sleep or schedule must be called. 7069 * @sleepFlag: Indicates if sleep or schedule must be called.
7070
7071 * 7070 *
7072 * Returns 0 for SUCCESS or -1 if FAILED. 7071 * Returns 0 for SUCCESS or -1 if FAILED.
7073 * Try for softreset first, only if it fails go for expensive 7072 * Try for softreset first, only if it fails go for expensive
diff --git a/drivers/message/fusion/mptbase.h b/drivers/message/fusion/mptbase.h
index 23ed3dec72a5..f71f22948477 100644
--- a/drivers/message/fusion/mptbase.h
+++ b/drivers/message/fusion/mptbase.h
@@ -420,31 +420,6 @@ typedef struct _VirtDevice {
420#define MPT_TARGET_FLAGS_LED_ON 0x80 420#define MPT_TARGET_FLAGS_LED_ON 0x80
421 421
422/* 422/*
423 * /proc/mpt interface
424 */
425typedef struct {
426 const char *name;
427 mode_t mode;
428 int pad;
429 read_proc_t *read_proc;
430 write_proc_t *write_proc;
431} mpt_proc_entry_t;
432
433#define MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len) \
434do { \
435 len -= offset; \
436 if (len < request) { \
437 *eof = 1; \
438 if (len <= 0) \
439 return 0; \
440 } else \
441 len = request; \
442 *start = buf + offset; \
443 return len; \
444} while (0)
445
446
447/*
448 * IOCTL structure and associated defines 423 * IOCTL structure and associated defines
449 */ 424 */
450 425
diff --git a/drivers/message/i2o/exec-osm.c b/drivers/message/i2o/exec-osm.c
index 06c655c55587..a3970e56ae53 100644
--- a/drivers/message/i2o/exec-osm.c
+++ b/drivers/message/i2o/exec-osm.c
@@ -389,12 +389,16 @@ static int i2o_exec_lct_notify(struct i2o_controller *c, u32 change_ind)
389 dev = &c->pdev->dev; 389 dev = &c->pdev->dev;
390 390
391 if (i2o_dma_realloc(dev, &c->dlct, 391 if (i2o_dma_realloc(dev, &c->dlct,
392 le32_to_cpu(sb->expected_lct_size))) 392 le32_to_cpu(sb->expected_lct_size))) {
393 mutex_unlock(&c->lct_lock);
393 return -ENOMEM; 394 return -ENOMEM;
395 }
394 396
395 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET); 397 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
396 if (IS_ERR(msg)) 398 if (IS_ERR(msg)) {
399 mutex_unlock(&c->lct_lock);
397 return PTR_ERR(msg); 400 return PTR_ERR(msg);
401 }
398 402
399 msg->u.head[0] = cpu_to_le32(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_6); 403 msg->u.head[0] = cpu_to_le32(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_6);
400 msg->u.head[1] = cpu_to_le32(I2O_CMD_LCT_NOTIFY << 24 | HOST_TID << 12 | 404 msg->u.head[1] = cpu_to_le32(I2O_CMD_LCT_NOTIFY << 24 | HOST_TID << 12 |
diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c
index e6733bc99724..f0f1e667000f 100644
--- a/drivers/message/i2o/i2o_block.c
+++ b/drivers/message/i2o/i2o_block.c
@@ -727,7 +727,7 @@ static int i2o_block_transfer(struct request *req)
727{ 727{
728 struct i2o_block_device *dev = req->rq_disk->private_data; 728 struct i2o_block_device *dev = req->rq_disk->private_data;
729 struct i2o_controller *c; 729 struct i2o_controller *c;
730 u32 tid = dev->i2o_dev->lct_data.tid; 730 u32 tid;
731 struct i2o_message *msg; 731 struct i2o_message *msg;
732 u32 *mptr; 732 u32 *mptr;
733 struct i2o_block_request *ireq = req->special; 733 struct i2o_block_request *ireq = req->special;
@@ -743,6 +743,7 @@ static int i2o_block_transfer(struct request *req)
743 goto exit; 743 goto exit;
744 } 744 }
745 745
746 tid = dev->i2o_dev->lct_data.tid;
746 c = dev->i2o_dev->iop; 747 c = dev->i2o_dev->iop;
747 748
748 msg = i2o_msg_get(c); 749 msg = i2o_msg_get(c);
diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
index c4b117f5fb70..068ba0785bb4 100644
--- a/drivers/message/i2o/i2o_config.c
+++ b/drivers/message/i2o/i2o_config.c
@@ -111,11 +111,11 @@ static int i2o_cfg_gethrt(unsigned long arg)
111 111
112 len = 8 + ((hrt->entry_len * hrt->num_entries) << 2); 112 len = 8 + ((hrt->entry_len * hrt->num_entries) << 2);
113 113
114 /* We did a get user...so assuming mem is ok...is this bad? */ 114 if (put_user(len, kcmd.reslen))
115 put_user(len, kcmd.reslen); 115 ret = -EFAULT;
116 if (len > reslen) 116 else if (len > reslen)
117 ret = -ENOBUFS; 117 ret = -ENOBUFS;
118 if (copy_to_user(kcmd.resbuf, (void *)hrt, len)) 118 else if (copy_to_user(kcmd.resbuf, (void *)hrt, len))
119 ret = -EFAULT; 119 ret = -EFAULT;
120 120
121 return ret; 121 return ret;
@@ -147,8 +147,9 @@ static int i2o_cfg_getlct(unsigned long arg)
147 lct = (i2o_lct *) c->lct; 147 lct = (i2o_lct *) c->lct;
148 148
149 len = (unsigned int)lct->table_size << 2; 149 len = (unsigned int)lct->table_size << 2;
150 put_user(len, kcmd.reslen); 150 if (put_user(len, kcmd.reslen))
151 if (len > reslen) 151 ret = -EFAULT;
152 else if (len > reslen)
152 ret = -ENOBUFS; 153 ret = -ENOBUFS;
153 else if (copy_to_user(kcmd.resbuf, lct, len)) 154 else if (copy_to_user(kcmd.resbuf, lct, len))
154 ret = -EFAULT; 155 ret = -EFAULT;
@@ -208,8 +209,9 @@ static int i2o_cfg_parms(unsigned long arg, unsigned int type)
208 return -EAGAIN; 209 return -EAGAIN;
209 } 210 }
210 211
211 put_user(len, kcmd.reslen); 212 if (put_user(len, kcmd.reslen))
212 if (len > reslen) 213 ret = -EFAULT;
214 else if (len > reslen)
213 ret = -ENOBUFS; 215 ret = -ENOBUFS;
214 else if (copy_to_user(kcmd.resbuf, res, len)) 216 else if (copy_to_user(kcmd.resbuf, res, len))
215 ret = -EFAULT; 217 ret = -EFAULT;
diff --git a/drivers/message/i2o/i2o_scsi.c b/drivers/message/i2o/i2o_scsi.c
index 3d45817e6dcd..ea6b2197da8a 100644
--- a/drivers/message/i2o/i2o_scsi.c
+++ b/drivers/message/i2o/i2o_scsi.c
@@ -528,7 +528,6 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
528 * Do the incoming paperwork 528 * Do the incoming paperwork
529 */ 529 */
530 i2o_dev = SCpnt->device->hostdata; 530 i2o_dev = SCpnt->device->hostdata;
531 c = i2o_dev->iop;
532 531
533 SCpnt->scsi_done = done; 532 SCpnt->scsi_done = done;
534 533
@@ -538,7 +537,7 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
538 done(SCpnt); 537 done(SCpnt);
539 goto exit; 538 goto exit;
540 } 539 }
541 540 c = i2o_dev->iop;
542 tid = i2o_dev->lct_data.tid; 541 tid = i2o_dev->lct_data.tid;
543 542
544 osm_debug("qcmd: Tid = %03x\n", tid); 543 osm_debug("qcmd: Tid = %03x\n", tid);
diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c
index 2c65a2c57294..07933f3f7e4c 100644
--- a/drivers/mfd/88pm860x-core.c
+++ b/drivers/mfd/88pm860x-core.c
@@ -74,12 +74,12 @@ static struct mfd_cell backlight_devs[] = {
74} 74}
75 75
76static struct resource led_resources[] = { 76static struct resource led_resources[] = {
77 PM8606_LED_RESOURCE(PM8606_LED1_RED, RGB2B), 77 PM8606_LED_RESOURCE(PM8606_LED1_RED, RGB1B),
78 PM8606_LED_RESOURCE(PM8606_LED1_GREEN, RGB2C), 78 PM8606_LED_RESOURCE(PM8606_LED1_GREEN, RGB1C),
79 PM8606_LED_RESOURCE(PM8606_LED1_BLUE, RGB2D), 79 PM8606_LED_RESOURCE(PM8606_LED1_BLUE, RGB1D),
80 PM8606_LED_RESOURCE(PM8606_LED2_RED, RGB1B), 80 PM8606_LED_RESOURCE(PM8606_LED2_RED, RGB2B),
81 PM8606_LED_RESOURCE(PM8606_LED2_GREEN, RGB1C), 81 PM8606_LED_RESOURCE(PM8606_LED2_GREEN, RGB2C),
82 PM8606_LED_RESOURCE(PM8606_LED2_BLUE, RGB1D), 82 PM8606_LED_RESOURCE(PM8606_LED2_BLUE, RGB2D),
83}; 83};
84 84
85#define PM8606_LED_DEVS(_i) \ 85#define PM8606_LED_DEVS(_i) \
@@ -428,52 +428,44 @@ static int __devinit device_gpadc_init(struct pm860x_chip *chip,
428{ 428{
429 struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \ 429 struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
430 : chip->companion; 430 : chip->companion;
431 int use_gpadc = 0, data, ret; 431 int data;
432 int ret;
432 433
433 /* initialize GPADC without activating it */ 434 /* initialize GPADC without activating it */
434 435
435 if (pdata && pdata->touch) { 436 if (!pdata || !pdata->touch)
436 /* set GPADC MISC1 register */ 437 return -EINVAL;
437 data = 0;
438 data |= (pdata->touch->gpadc_prebias << 1)
439 & PM8607_GPADC_PREBIAS_MASK;
440 data |= (pdata->touch->slot_cycle << 3)
441 & PM8607_GPADC_SLOT_CYCLE_MASK;
442 data |= (pdata->touch->off_scale << 5)
443 & PM8607_GPADC_OFF_SCALE_MASK;
444 data |= (pdata->touch->sw_cal << 7)
445 & PM8607_GPADC_SW_CAL_MASK;
446 if (data) {
447 ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
448 if (ret < 0)
449 goto out;
450 }
451 /* set tsi prebias time */
452 if (pdata->touch->tsi_prebias) {
453 data = pdata->touch->tsi_prebias;
454 ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
455 if (ret < 0)
456 goto out;
457 }
458 /* set prebias & prechg time of pen detect */
459 data = 0;
460 data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK;
461 data |= (pdata->touch->pen_prechg << 5)
462 & PM8607_PD_PRECHG_MASK;
463 if (data) {
464 ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
465 if (ret < 0)
466 goto out;
467 }
468 438
469 use_gpadc = 1; 439 /* set GPADC MISC1 register */
440 data = 0;
441 data |= (pdata->touch->gpadc_prebias << 1) & PM8607_GPADC_PREBIAS_MASK;
442 data |= (pdata->touch->slot_cycle << 3) & PM8607_GPADC_SLOT_CYCLE_MASK;
443 data |= (pdata->touch->off_scale << 5) & PM8607_GPADC_OFF_SCALE_MASK;
444 data |= (pdata->touch->sw_cal << 7) & PM8607_GPADC_SW_CAL_MASK;
445 if (data) {
446 ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
447 if (ret < 0)
448 goto out;
470 } 449 }
471 450 /* set tsi prebias time */
472 /* turn on GPADC */ 451 if (pdata->touch->tsi_prebias) {
473 if (use_gpadc) { 452 data = pdata->touch->tsi_prebias;
474 ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1, 453 ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
475 PM8607_GPADC_EN, PM8607_GPADC_EN); 454 if (ret < 0)
455 goto out;
476 } 456 }
457 /* set prebias & prechg time of pen detect */
458 data = 0;
459 data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK;
460 data |= (pdata->touch->pen_prechg << 5) & PM8607_PD_PRECHG_MASK;
461 if (data) {
462 ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
463 if (ret < 0)
464 goto out;
465 }
466
467 ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1,
468 PM8607_GPADC_EN, PM8607_GPADC_EN);
477out: 469out:
478 return ret; 470 return ret;
479} 471}
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 9da0e504bbe9..db51ea1c6082 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -7,7 +7,16 @@ menuconfig MFD_SUPPORT
7 depends on HAS_IOMEM 7 depends on HAS_IOMEM
8 default y 8 default y
9 help 9 help
10 Configure MFD device drivers. 10 Multifunction devices embed several functions (e.g. GPIOs,
11 touchscreens, keyboards, current regulators, power management chips,
12 etc...) in one single integrated circuit. They usually talk to the
13 main CPU through one or more IRQ lines and low speed data busses (SPI,
14 I2C, etc..). They appear as one single device to the main system
15 through the data bus and the MFD framework allows for sub devices
16 (a.k.a. functions) to appear as discrete platform devices.
17 MFDs are typically found on embedded platforms.
18
19 This option alone does not add any kernel code.
11 20
12if MFD_SUPPORT 21if MFD_SUPPORT
13 22
@@ -177,6 +186,38 @@ config TWL4030_CODEC
177 select MFD_CORE 186 select MFD_CORE
178 default n 187 default n
179 188
189config TWL6030_PWM
190 tristate "TWL6030 PWM (Pulse Width Modulator) Support"
191 depends on TWL4030_CORE
192 select HAVE_PWM
193 default n
194 help
195 Say yes here if you want support for TWL6030 PWM.
196 This is used to control charging LED brightness.
197
198config MFD_STMPE
199 bool "Support STMicroelectronics STMPE"
200 depends on I2C=y && GENERIC_HARDIRQS
201 select MFD_CORE
202 help
203 Support for the STMPE family of I/O Expanders from
204 STMicroelectronics.
205
206 Currently supported devices are:
207
208 STMPE811: GPIO, Touchscreen
209 STMPE1601: GPIO, Keypad
210 STMPE2401: GPIO, Keypad
211 STMPE2403: GPIO, Keypad
212
213 This driver provides common support for accessing the device,
214 additional drivers must be enabled in order to use the functionality
215 of the device. Currently available sub drivers are:
216
217 GPIO: stmpe-gpio
218 Keypad: stmpe-keypad
219 Touchscreen: stmpe-ts
220
180config MFD_TC35892 221config MFD_TC35892
181 bool "Support Toshiba TC35892" 222 bool "Support Toshiba TC35892"
182 depends on I2C=y && GENERIC_HARDIRQS 223 depends on I2C=y && GENERIC_HARDIRQS
@@ -252,6 +293,16 @@ config MFD_MAX8925
252 accessing the device, additional drivers must be enabled in order 293 accessing the device, additional drivers must be enabled in order
253 to use the functionality of the device. 294 to use the functionality of the device.
254 295
296config MFD_MAX8998
297 bool "Maxim Semiconductor MAX8998 PMIC Support"
298 depends on I2C=y
299 select MFD_CORE
300 help
301 Say yes here to support for Maxim Semiconductor MAX8998. This is
302 a Power Management IC. This driver provies common support for
303 accessing the device, additional drivers must be enabled in order
304 to use the functionality of the device.
305
255config MFD_WM8400 306config MFD_WM8400
256 tristate "Support Wolfson Microelectronics WM8400" 307 tristate "Support Wolfson Microelectronics WM8400"
257 select MFD_CORE 308 select MFD_CORE
@@ -482,6 +533,28 @@ config MFD_JANZ_CMODIO
482 host many different types of MODULbus daughterboards, including 533 host many different types of MODULbus daughterboards, including
483 CAN and GPIO controllers. 534 CAN and GPIO controllers.
484 535
536config MFD_JZ4740_ADC
537 tristate "Support for the JZ4740 SoC ADC core"
538 select MFD_CORE
539 depends on MACH_JZ4740
540 help
541 Say yes here if you want support for the ADC unit in the JZ4740 SoC.
542 This driver is necessary for jz4740-battery and jz4740-hwmon driver.
543
544config MFD_TPS6586X
545 tristate "TPS6586x Power Management chips"
546 depends on I2C && GPIOLIB
547 select MFD_CORE
548 help
549 If you say yes here you get support for the TPS6586X series of
550 Power Management chips.
551 This driver provides common support for accessing the device,
552 additional drivers must be enabled in order to use the
553 functionality of the device.
554
555 This driver can also be built as a module. If so, the module
556 will be called tps6586x.
557
485endif # MFD_SUPPORT 558endif # MFD_SUPPORT
486 559
487menu "Multimedia Capabilities Port drivers" 560menu "Multimedia Capabilities Port drivers"
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index fb503e77dc60..feaeeaeeddb7 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_HTC_I2CPLD) += htc-i2cpld.o
15obj-$(CONFIG_MFD_DAVINCI_VOICECODEC) += davinci_voicecodec.o 15obj-$(CONFIG_MFD_DAVINCI_VOICECODEC) += davinci_voicecodec.o
16obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o 16obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o
17 17
18obj-$(CONFIG_MFD_STMPE) += stmpe.o
18obj-$(CONFIG_MFD_TC35892) += tc35892.o 19obj-$(CONFIG_MFD_TC35892) += tc35892.o
19obj-$(CONFIG_MFD_T7L66XB) += t7l66xb.o tmio_core.o 20obj-$(CONFIG_MFD_T7L66XB) += t7l66xb.o tmio_core.o
20obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o tmio_core.o 21obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o tmio_core.o
@@ -36,6 +37,7 @@ obj-$(CONFIG_MENELAUS) += menelaus.o
36obj-$(CONFIG_TWL4030_CORE) += twl-core.o twl4030-irq.o twl6030-irq.o 37obj-$(CONFIG_TWL4030_CORE) += twl-core.o twl4030-irq.o twl6030-irq.o
37obj-$(CONFIG_TWL4030_POWER) += twl4030-power.o 38obj-$(CONFIG_TWL4030_POWER) += twl4030-power.o
38obj-$(CONFIG_TWL4030_CODEC) += twl4030-codec.o 39obj-$(CONFIG_TWL4030_CODEC) += twl4030-codec.o
40obj-$(CONFIG_TWL6030_PWM) += twl6030-pwm.o
39 41
40obj-$(CONFIG_MFD_MC13783) += mc13783-core.o 42obj-$(CONFIG_MFD_MC13783) += mc13783-core.o
41 43
@@ -56,6 +58,7 @@ obj-$(CONFIG_UCB1400_CORE) += ucb1400_core.o
56obj-$(CONFIG_PMIC_DA903X) += da903x.o 58obj-$(CONFIG_PMIC_DA903X) += da903x.o
57max8925-objs := max8925-core.o max8925-i2c.o 59max8925-objs := max8925-core.o max8925-i2c.o
58obj-$(CONFIG_MFD_MAX8925) += max8925.o 60obj-$(CONFIG_MFD_MAX8925) += max8925.o
61obj-$(CONFIG_MFD_MAX8998) += max8998.o
59 62
60pcf50633-objs := pcf50633-core.o pcf50633-irq.o 63pcf50633-objs := pcf50633-core.o pcf50633-irq.o
61obj-$(CONFIG_MFD_PCF50633) += pcf50633.o 64obj-$(CONFIG_MFD_PCF50633) += pcf50633.o
@@ -71,3 +74,5 @@ obj-$(CONFIG_PMIC_ADP5520) += adp5520.o
71obj-$(CONFIG_LPC_SCH) += lpc_sch.o 74obj-$(CONFIG_LPC_SCH) += lpc_sch.o
72obj-$(CONFIG_MFD_RDC321X) += rdc321x-southbridge.o 75obj-$(CONFIG_MFD_RDC321X) += rdc321x-southbridge.o
73obj-$(CONFIG_MFD_JANZ_CMODIO) += janz-cmodio.o 76obj-$(CONFIG_MFD_JANZ_CMODIO) += janz-cmodio.o
77obj-$(CONFIG_MFD_JZ4740_ADC) += jz4740-adc.o
78obj-$(CONFIG_MFD_TPS6586X) += tps6586x.o
diff --git a/drivers/mfd/ab3100-otp.c b/drivers/mfd/ab3100-otp.c
index 63d2b727ddbb..8440010eb2b8 100644
--- a/drivers/mfd/ab3100-otp.c
+++ b/drivers/mfd/ab3100-otp.c
@@ -199,7 +199,7 @@ static int __init ab3100_otp_probe(struct platform_device *pdev)
199 199
200 err = ab3100_otp_read(otp); 200 err = ab3100_otp_read(otp);
201 if (err) 201 if (err)
202 return err; 202 goto err_otp_read;
203 203
204 dev_info(&pdev->dev, "AB3100 OTP readout registered\n"); 204 dev_info(&pdev->dev, "AB3100 OTP readout registered\n");
205 205
@@ -208,21 +208,21 @@ static int __init ab3100_otp_probe(struct platform_device *pdev)
208 err = device_create_file(&pdev->dev, 208 err = device_create_file(&pdev->dev,
209 &ab3100_otp_attrs[i]); 209 &ab3100_otp_attrs[i]);
210 if (err) 210 if (err)
211 goto out_no_sysfs; 211 goto err_create_file;
212 } 212 }
213 213
214 /* debugfs entries */ 214 /* debugfs entries */
215 err = ab3100_otp_init_debugfs(&pdev->dev, otp); 215 err = ab3100_otp_init_debugfs(&pdev->dev, otp);
216 if (err) 216 if (err)
217 goto out_no_debugfs; 217 goto err_init_debugfs;
218 218
219 return 0; 219 return 0;
220 220
221out_no_sysfs: 221err_init_debugfs:
222 for (i = 0; i < ARRAY_SIZE(ab3100_otp_attrs); i++) 222err_create_file:
223 device_remove_file(&pdev->dev, 223 while (--i >= 0)
224 &ab3100_otp_attrs[i]); 224 device_remove_file(&pdev->dev, &ab3100_otp_attrs[i]);
225out_no_debugfs: 225err_otp_read:
226 kfree(otp); 226 kfree(otp);
227 return err; 227 return err;
228} 228}
diff --git a/drivers/mfd/ab3550-core.c b/drivers/mfd/ab3550-core.c
index f54ab62e7bc6..8a98739e6d9c 100644
--- a/drivers/mfd/ab3550-core.c
+++ b/drivers/mfd/ab3550-core.c
@@ -589,16 +589,16 @@ static bool reg_read_allowed(const struct ab3550_reg_ranges *ranges, u8 reg)
589} 589}
590 590
591/* 591/*
592 * The exported register access functionality. 592 * The register access functionality.
593 */ 593 */
594int ab3550_get_chip_id(struct device *dev) 594static int ab3550_get_chip_id(struct device *dev)
595{ 595{
596 struct ab3550 *ab = dev_get_drvdata(dev->parent); 596 struct ab3550 *ab = dev_get_drvdata(dev->parent);
597 return (int)ab->chip_id; 597 return (int)ab->chip_id;
598} 598}
599 599
600int ab3550_mask_and_set_register_interruptible(struct device *dev, u8 bank, 600static int ab3550_mask_and_set_register_interruptible(struct device *dev,
601 u8 reg, u8 bitmask, u8 bitvalues) 601 u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
602{ 602{
603 struct ab3550 *ab; 603 struct ab3550 *ab;
604 struct platform_device *pdev = to_platform_device(dev); 604 struct platform_device *pdev = to_platform_device(dev);
@@ -612,15 +612,15 @@ int ab3550_mask_and_set_register_interruptible(struct device *dev, u8 bank,
612 bitmask, bitvalues); 612 bitmask, bitvalues);
613} 613}
614 614
615int ab3550_set_register_interruptible(struct device *dev, u8 bank, u8 reg, 615static int ab3550_set_register_interruptible(struct device *dev, u8 bank,
616 u8 value) 616 u8 reg, u8 value)
617{ 617{
618 return ab3550_mask_and_set_register_interruptible(dev, bank, reg, 0xFF, 618 return ab3550_mask_and_set_register_interruptible(dev, bank, reg, 0xFF,
619 value); 619 value);
620} 620}
621 621
622int ab3550_get_register_interruptible(struct device *dev, u8 bank, u8 reg, 622static int ab3550_get_register_interruptible(struct device *dev, u8 bank,
623 u8 *value) 623 u8 reg, u8 *value)
624{ 624{
625 struct ab3550 *ab; 625 struct ab3550 *ab;
626 struct platform_device *pdev = to_platform_device(dev); 626 struct platform_device *pdev = to_platform_device(dev);
@@ -633,7 +633,7 @@ int ab3550_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
633 return get_register_interruptible(ab, bank, reg, value); 633 return get_register_interruptible(ab, bank, reg, value);
634} 634}
635 635
636int ab3550_get_register_page_interruptible(struct device *dev, u8 bank, 636static int ab3550_get_register_page_interruptible(struct device *dev, u8 bank,
637 u8 first_reg, u8 *regvals, u8 numregs) 637 u8 first_reg, u8 *regvals, u8 numregs)
638{ 638{
639 struct ab3550 *ab; 639 struct ab3550 *ab;
@@ -649,7 +649,8 @@ int ab3550_get_register_page_interruptible(struct device *dev, u8 bank,
649 numregs); 649 numregs);
650} 650}
651 651
652int ab3550_event_registers_startup_state_get(struct device *dev, u8 *event) 652static int ab3550_event_registers_startup_state_get(struct device *dev,
653 u8 *event)
653{ 654{
654 struct ab3550 *ab; 655 struct ab3550 *ab;
655 656
@@ -661,7 +662,7 @@ int ab3550_event_registers_startup_state_get(struct device *dev, u8 *event)
661 return 0; 662 return 0;
662} 663}
663 664
664int ab3550_startup_irq_enabled(struct device *dev, unsigned int irq) 665static int ab3550_startup_irq_enabled(struct device *dev, unsigned int irq)
665{ 666{
666 struct ab3550 *ab; 667 struct ab3550 *ab;
667 struct ab3550_platform_data *plf_data; 668 struct ab3550_platform_data *plf_data;
diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index f3d26fa9c34d..defa786dee34 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -16,6 +16,7 @@
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/mfd/core.h> 17#include <linux/mfd/core.h>
18#include <linux/mfd/ab8500.h> 18#include <linux/mfd/ab8500.h>
19#include <linux/regulator/ab8500.h>
19 20
20/* 21/*
21 * Interrupt register offsets 22 * Interrupt register offsets
@@ -352,6 +353,7 @@ static struct mfd_cell ab8500_devs[] = {
352 { .name = "ab8500-audio", }, 353 { .name = "ab8500-audio", },
353 { .name = "ab8500-usb", }, 354 { .name = "ab8500-usb", },
354 { .name = "ab8500-pwm", }, 355 { .name = "ab8500-pwm", },
356 { .name = "ab8500-regulator", },
355}; 357};
356 358
357int __devinit ab8500_init(struct ab8500 *ab8500) 359int __devinit ab8500_init(struct ab8500 *ab8500)
@@ -411,7 +413,7 @@ int __devinit ab8500_init(struct ab8500 *ab8500)
411 goto out_removeirq; 413 goto out_removeirq;
412 } 414 }
413 415
414 ret = mfd_add_devices(ab8500->dev, -1, ab8500_devs, 416 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
415 ARRAY_SIZE(ab8500_devs), NULL, 417 ARRAY_SIZE(ab8500_devs), NULL,
416 ab8500->irq_base); 418 ab8500->irq_base);
417 if (ret) 419 if (ret)
diff --git a/drivers/mfd/ab8500-spi.c b/drivers/mfd/ab8500-spi.c
index b81d4f768ef6..e1c8b62b086d 100644
--- a/drivers/mfd/ab8500-spi.c
+++ b/drivers/mfd/ab8500-spi.c
@@ -68,7 +68,12 @@ static int ab8500_spi_read(struct ab8500 *ab8500, u16 addr)
68 68
69 ret = spi_sync(spi, &msg); 69 ret = spi_sync(spi, &msg);
70 if (!ret) 70 if (!ret)
71 ret = ab8500->rx_buf[0]; 71 /*
72 * Only the 8 lowermost bytes are
73 * defined with value, the rest may
74 * vary depending on chip/board noise.
75 */
76 ret = ab8500->rx_buf[0] & 0xFFU;
72 77
73 return ret; 78 return ret;
74} 79}
diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
index 3b3b97ec32a7..f12720dbe126 100644
--- a/drivers/mfd/abx500-core.c
+++ b/drivers/mfd/abx500-core.c
@@ -36,7 +36,7 @@ int abx500_register_ops(struct device *dev, struct abx500_ops *ops)
36 struct abx500_device_entry *dev_entry; 36 struct abx500_device_entry *dev_entry;
37 37
38 dev_entry = kzalloc(sizeof(struct abx500_device_entry), GFP_KERNEL); 38 dev_entry = kzalloc(sizeof(struct abx500_device_entry), GFP_KERNEL);
39 if (IS_ERR(dev_entry)) { 39 if (!dev_entry) {
40 dev_err(dev, "register_ops kzalloc failed"); 40 dev_err(dev, "register_ops kzalloc failed");
41 return -ENOMEM; 41 return -ENOMEM;
42 } 42 }
diff --git a/drivers/mfd/davinci_voicecodec.c b/drivers/mfd/davinci_voicecodec.c
index 3e75f02e4778..33c923d215c7 100644
--- a/drivers/mfd/davinci_voicecodec.c
+++ b/drivers/mfd/davinci_voicecodec.c
@@ -94,7 +94,8 @@ static int __init davinci_vc_probe(struct platform_device *pdev)
94 res = platform_get_resource(pdev, IORESOURCE_DMA, 0); 94 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
95 if (!res) { 95 if (!res) {
96 dev_err(&pdev->dev, "no DMA resource\n"); 96 dev_err(&pdev->dev, "no DMA resource\n");
97 return -ENXIO; 97 ret = -ENXIO;
98 goto fail4;
98 } 99 }
99 100
100 davinci_vc->davinci_vcif.dma_tx_channel = res->start; 101 davinci_vc->davinci_vcif.dma_tx_channel = res->start;
@@ -104,7 +105,8 @@ static int __init davinci_vc_probe(struct platform_device *pdev)
104 res = platform_get_resource(pdev, IORESOURCE_DMA, 1); 105 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
105 if (!res) { 106 if (!res) {
106 dev_err(&pdev->dev, "no DMA resource\n"); 107 dev_err(&pdev->dev, "no DMA resource\n");
107 return -ENXIO; 108 ret = -ENXIO;
109 goto fail4;
108 } 110 }
109 111
110 davinci_vc->davinci_vcif.dma_rx_channel = res->start; 112 davinci_vc->davinci_vcif.dma_rx_channel = res->start;
diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
index 9ed630799acc..36a166bcdb08 100644
--- a/drivers/mfd/janz-cmodio.c
+++ b/drivers/mfd/janz-cmodio.c
@@ -18,6 +18,7 @@
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/slab.h>
21#include <linux/mfd/core.h> 22#include <linux/mfd/core.h>
22 23
23#include <linux/mfd/janz.h> 24#include <linux/mfd/janz.h>
diff --git a/drivers/mfd/jz4740-adc.c b/drivers/mfd/jz4740-adc.c
new file mode 100644
index 000000000000..3ad492cb6c41
--- /dev/null
+++ b/drivers/mfd/jz4740-adc.c
@@ -0,0 +1,394 @@
1/*
2 * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
3 * JZ4740 SoC ADC driver
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * You should have received a copy of the GNU General Public License along
11 * with this program; if not, write to the Free Software Foundation, Inc.,
12 * 675 Mass Ave, Cambridge, MA 02139, USA.
13 *
14 * This driver synchronizes access to the JZ4740 ADC core between the
15 * JZ4740 battery and hwmon drivers.
16 */
17
18#include <linux/err.h>
19#include <linux/irq.h>
20#include <linux/interrupt.h>
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/platform_device.h>
24#include <linux/slab.h>
25#include <linux/spinlock.h>
26
27#include <linux/clk.h>
28#include <linux/mfd/core.h>
29
30#include <linux/jz4740-adc.h>
31
32
33#define JZ_REG_ADC_ENABLE 0x00
34#define JZ_REG_ADC_CFG 0x04
35#define JZ_REG_ADC_CTRL 0x08
36#define JZ_REG_ADC_STATUS 0x0c
37
38#define JZ_REG_ADC_TOUCHSCREEN_BASE 0x10
39#define JZ_REG_ADC_BATTERY_BASE 0x1c
40#define JZ_REG_ADC_HWMON_BASE 0x20
41
42#define JZ_ADC_ENABLE_TOUCH BIT(2)
43#define JZ_ADC_ENABLE_BATTERY BIT(1)
44#define JZ_ADC_ENABLE_ADCIN BIT(0)
45
46enum {
47 JZ_ADC_IRQ_ADCIN = 0,
48 JZ_ADC_IRQ_BATTERY,
49 JZ_ADC_IRQ_TOUCH,
50 JZ_ADC_IRQ_PENUP,
51 JZ_ADC_IRQ_PENDOWN,
52};
53
54struct jz4740_adc {
55 struct resource *mem;
56 void __iomem *base;
57
58 int irq;
59 int irq_base;
60
61 struct clk *clk;
62 atomic_t clk_ref;
63
64 spinlock_t lock;
65};
66
67static inline void jz4740_adc_irq_set_masked(struct jz4740_adc *adc, int irq,
68 bool masked)
69{
70 unsigned long flags;
71 uint8_t val;
72
73 irq -= adc->irq_base;
74
75 spin_lock_irqsave(&adc->lock, flags);
76
77 val = readb(adc->base + JZ_REG_ADC_CTRL);
78 if (masked)
79 val |= BIT(irq);
80 else
81 val &= ~BIT(irq);
82 writeb(val, adc->base + JZ_REG_ADC_CTRL);
83
84 spin_unlock_irqrestore(&adc->lock, flags);
85}
86
87static void jz4740_adc_irq_mask(unsigned int irq)
88{
89 struct jz4740_adc *adc = get_irq_chip_data(irq);
90 jz4740_adc_irq_set_masked(adc, irq, true);
91}
92
93static void jz4740_adc_irq_unmask(unsigned int irq)
94{
95 struct jz4740_adc *adc = get_irq_chip_data(irq);
96 jz4740_adc_irq_set_masked(adc, irq, false);
97}
98
99static void jz4740_adc_irq_ack(unsigned int irq)
100{
101 struct jz4740_adc *adc = get_irq_chip_data(irq);
102
103 irq -= adc->irq_base;
104 writeb(BIT(irq), adc->base + JZ_REG_ADC_STATUS);
105}
106
107static struct irq_chip jz4740_adc_irq_chip = {
108 .name = "jz4740-adc",
109 .mask = jz4740_adc_irq_mask,
110 .unmask = jz4740_adc_irq_unmask,
111 .ack = jz4740_adc_irq_ack,
112};
113
114static void jz4740_adc_irq_demux(unsigned int irq, struct irq_desc *desc)
115{
116 struct jz4740_adc *adc = get_irq_desc_data(desc);
117 uint8_t status;
118 unsigned int i;
119
120 status = readb(adc->base + JZ_REG_ADC_STATUS);
121
122 for (i = 0; i < 5; ++i) {
123 if (status & BIT(i))
124 generic_handle_irq(adc->irq_base + i);
125 }
126}
127
128
129/* Refcounting for the ADC clock is done in here instead of in the clock
130 * framework, because it is the only clock which is shared between multiple
131 * devices and thus is the only clock which needs refcounting */
132static inline void jz4740_adc_clk_enable(struct jz4740_adc *adc)
133{
134 if (atomic_inc_return(&adc->clk_ref) == 1)
135 clk_enable(adc->clk);
136}
137
138static inline void jz4740_adc_clk_disable(struct jz4740_adc *adc)
139{
140 if (atomic_dec_return(&adc->clk_ref) == 0)
141 clk_disable(adc->clk);
142}
143
144static inline void jz4740_adc_set_enabled(struct jz4740_adc *adc, int engine,
145 bool enabled)
146{
147 unsigned long flags;
148 uint8_t val;
149
150 spin_lock_irqsave(&adc->lock, flags);
151
152 val = readb(adc->base + JZ_REG_ADC_ENABLE);
153 if (enabled)
154 val |= BIT(engine);
155 else
156 val &= BIT(engine);
157 writeb(val, adc->base + JZ_REG_ADC_ENABLE);
158
159 spin_unlock_irqrestore(&adc->lock, flags);
160}
161
162static int jz4740_adc_cell_enable(struct platform_device *pdev)
163{
164 struct jz4740_adc *adc = dev_get_drvdata(pdev->dev.parent);
165
166 jz4740_adc_clk_enable(adc);
167 jz4740_adc_set_enabled(adc, pdev->id, true);
168
169 return 0;
170}
171
172static int jz4740_adc_cell_disable(struct platform_device *pdev)
173{
174 struct jz4740_adc *adc = dev_get_drvdata(pdev->dev.parent);
175
176 jz4740_adc_set_enabled(adc, pdev->id, false);
177 jz4740_adc_clk_disable(adc);
178
179 return 0;
180}
181
182int jz4740_adc_set_config(struct device *dev, uint32_t mask, uint32_t val)
183{
184 struct jz4740_adc *adc = dev_get_drvdata(dev);
185 unsigned long flags;
186 uint32_t cfg;
187
188 if (!adc)
189 return -ENODEV;
190
191 spin_lock_irqsave(&adc->lock, flags);
192
193 cfg = readl(adc->base + JZ_REG_ADC_CFG);
194
195 cfg &= ~mask;
196 cfg |= val;
197
198 writel(cfg, adc->base + JZ_REG_ADC_CFG);
199
200 spin_unlock_irqrestore(&adc->lock, flags);
201
202 return 0;
203}
204EXPORT_SYMBOL_GPL(jz4740_adc_set_config);
205
206static struct resource jz4740_hwmon_resources[] = {
207 {
208 .start = JZ_ADC_IRQ_ADCIN,
209 .flags = IORESOURCE_IRQ,
210 },
211 {
212 .start = JZ_REG_ADC_HWMON_BASE,
213 .end = JZ_REG_ADC_HWMON_BASE + 3,
214 .flags = IORESOURCE_MEM,
215 },
216};
217
218static struct resource jz4740_battery_resources[] = {
219 {
220 .start = JZ_ADC_IRQ_BATTERY,
221 .flags = IORESOURCE_IRQ,
222 },
223 {
224 .start = JZ_REG_ADC_BATTERY_BASE,
225 .end = JZ_REG_ADC_BATTERY_BASE + 3,
226 .flags = IORESOURCE_MEM,
227 },
228};
229
230const struct mfd_cell jz4740_adc_cells[] = {
231 {
232 .id = 0,
233 .name = "jz4740-hwmon",
234 .num_resources = ARRAY_SIZE(jz4740_hwmon_resources),
235 .resources = jz4740_hwmon_resources,
236 .platform_data = (void *)&jz4740_adc_cells[0],
237 .data_size = sizeof(struct mfd_cell),
238
239 .enable = jz4740_adc_cell_enable,
240 .disable = jz4740_adc_cell_disable,
241 },
242 {
243 .id = 1,
244 .name = "jz4740-battery",
245 .num_resources = ARRAY_SIZE(jz4740_battery_resources),
246 .resources = jz4740_battery_resources,
247 .platform_data = (void *)&jz4740_adc_cells[1],
248 .data_size = sizeof(struct mfd_cell),
249
250 .enable = jz4740_adc_cell_enable,
251 .disable = jz4740_adc_cell_disable,
252 },
253};
254
255static int __devinit jz4740_adc_probe(struct platform_device *pdev)
256{
257 int ret;
258 struct jz4740_adc *adc;
259 struct resource *mem_base;
260 int irq;
261
262 adc = kmalloc(sizeof(*adc), GFP_KERNEL);
263 if (!adc) {
264 dev_err(&pdev->dev, "Failed to allocate driver structure\n");
265 return -ENOMEM;
266 }
267
268 adc->irq = platform_get_irq(pdev, 0);
269 if (adc->irq < 0) {
270 ret = adc->irq;
271 dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
272 goto err_free;
273 }
274
275 adc->irq_base = platform_get_irq(pdev, 1);
276 if (adc->irq_base < 0) {
277 ret = adc->irq_base;
278 dev_err(&pdev->dev, "Failed to get irq base: %d\n", ret);
279 goto err_free;
280 }
281
282 mem_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
283 if (!mem_base) {
284 ret = -ENOENT;
285 dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
286 goto err_free;
287 }
288
289 /* Only request the shared registers for the MFD driver */
290 adc->mem = request_mem_region(mem_base->start, JZ_REG_ADC_STATUS,
291 pdev->name);
292 if (!adc->mem) {
293 ret = -EBUSY;
294 dev_err(&pdev->dev, "Failed to request mmio memory region\n");
295 goto err_free;
296 }
297
298 adc->base = ioremap_nocache(adc->mem->start, resource_size(adc->mem));
299 if (!adc->base) {
300 ret = -EBUSY;
301 dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
302 goto err_release_mem_region;
303 }
304
305 adc->clk = clk_get(&pdev->dev, "adc");
306 if (IS_ERR(adc->clk)) {
307 ret = PTR_ERR(adc->clk);
308 dev_err(&pdev->dev, "Failed to get clock: %d\n", ret);
309 goto err_iounmap;
310 }
311
312 spin_lock_init(&adc->lock);
313 atomic_set(&adc->clk_ref, 0);
314
315 platform_set_drvdata(pdev, adc);
316
317 for (irq = adc->irq_base; irq < adc->irq_base + 5; ++irq) {
318 set_irq_chip_data(irq, adc);
319 set_irq_chip_and_handler(irq, &jz4740_adc_irq_chip,
320 handle_level_irq);
321 }
322
323 set_irq_data(adc->irq, adc);
324 set_irq_chained_handler(adc->irq, jz4740_adc_irq_demux);
325
326 writeb(0x00, adc->base + JZ_REG_ADC_ENABLE);
327 writeb(0xff, adc->base + JZ_REG_ADC_CTRL);
328
329 ret = mfd_add_devices(&pdev->dev, 0, jz4740_adc_cells,
330 ARRAY_SIZE(jz4740_adc_cells), mem_base, adc->irq_base);
331 if (ret < 0)
332 goto err_clk_put;
333
334 return 0;
335
336err_clk_put:
337 clk_put(adc->clk);
338err_iounmap:
339 platform_set_drvdata(pdev, NULL);
340 iounmap(adc->base);
341err_release_mem_region:
342 release_mem_region(adc->mem->start, resource_size(adc->mem));
343err_free:
344 kfree(adc);
345
346 return ret;
347}
348
349static int __devexit jz4740_adc_remove(struct platform_device *pdev)
350{
351 struct jz4740_adc *adc = platform_get_drvdata(pdev);
352
353 mfd_remove_devices(&pdev->dev);
354
355 set_irq_data(adc->irq, NULL);
356 set_irq_chained_handler(adc->irq, NULL);
357
358 iounmap(adc->base);
359 release_mem_region(adc->mem->start, resource_size(adc->mem));
360
361 clk_put(adc->clk);
362
363 platform_set_drvdata(pdev, NULL);
364
365 kfree(adc);
366
367 return 0;
368}
369
370struct platform_driver jz4740_adc_driver = {
371 .probe = jz4740_adc_probe,
372 .remove = __devexit_p(jz4740_adc_remove),
373 .driver = {
374 .name = "jz4740-adc",
375 .owner = THIS_MODULE,
376 },
377};
378
379static int __init jz4740_adc_init(void)
380{
381 return platform_driver_register(&jz4740_adc_driver);
382}
383module_init(jz4740_adc_init);
384
385static void __exit jz4740_adc_exit(void)
386{
387 platform_driver_unregister(&jz4740_adc_driver);
388}
389module_exit(jz4740_adc_exit);
390
391MODULE_DESCRIPTION("JZ4740 SoC ADC driver");
392MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
393MODULE_LICENSE("GPL");
394MODULE_ALIAS("platform:jz4740-adc");
diff --git a/drivers/mfd/max8925-core.c b/drivers/mfd/max8925-core.c
index f621bcea3d02..04028a9ee082 100644
--- a/drivers/mfd/max8925-core.c
+++ b/drivers/mfd/max8925-core.c
@@ -90,6 +90,24 @@ static struct mfd_cell rtc_devs[] = {
90 }, 90 },
91}; 91};
92 92
93static struct resource onkey_resources[] = {
94 {
95 .name = "max8925-onkey",
96 .start = MAX8925_IRQ_GPM_SW_3SEC,
97 .end = MAX8925_IRQ_GPM_SW_3SEC,
98 .flags = IORESOURCE_IRQ,
99 },
100};
101
102static struct mfd_cell onkey_devs[] = {
103 {
104 .name = "max8925-onkey",
105 .num_resources = 1,
106 .resources = &onkey_resources[0],
107 .id = -1,
108 },
109};
110
93#define MAX8925_REG_RESOURCE(_start, _end) \ 111#define MAX8925_REG_RESOURCE(_start, _end) \
94{ \ 112{ \
95 .start = MAX8925_##_start, \ 113 .start = MAX8925_##_start, \
@@ -596,6 +614,15 @@ int __devinit max8925_device_init(struct max8925_chip *chip,
596 dev_err(chip->dev, "Failed to add rtc subdev\n"); 614 dev_err(chip->dev, "Failed to add rtc subdev\n");
597 goto out; 615 goto out;
598 } 616 }
617
618 ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
619 ARRAY_SIZE(onkey_devs),
620 &onkey_resources[0], 0);
621 if (ret < 0) {
622 dev_err(chip->dev, "Failed to add onkey subdev\n");
623 goto out_dev;
624 }
625
599 if (pdata && pdata->regulator[0]) { 626 if (pdata && pdata->regulator[0]) {
600 ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0], 627 ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0],
601 ARRAY_SIZE(regulator_devs), 628 ARRAY_SIZE(regulator_devs),
diff --git a/drivers/mfd/max8998.c b/drivers/mfd/max8998.c
new file mode 100644
index 000000000000..73e6f5c4efc9
--- /dev/null
+++ b/drivers/mfd/max8998.c
@@ -0,0 +1,158 @@
1/*
2 * max8698.c - mfd core driver for the Maxim 8998
3 *
4 * Copyright (C) 2009-2010 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 * Marek Szyprowski <m.szyprowski@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
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/i2c.h>
28#include <linux/mutex.h>
29#include <linux/mfd/core.h>
30#include <linux/mfd/max8998.h>
31#include <linux/mfd/max8998-private.h>
32
33static struct mfd_cell max8998_devs[] = {
34 {
35 .name = "max8998-pmic",
36 }
37};
38
39static int max8998_i2c_device_read(struct max8998_dev *max8998, u8 reg, u8 *dest)
40{
41 struct i2c_client *client = max8998->i2c_client;
42 int ret;
43
44 mutex_lock(&max8998->iolock);
45 ret = i2c_smbus_read_byte_data(client, reg);
46 mutex_unlock(&max8998->iolock);
47 if (ret < 0)
48 return ret;
49
50 ret &= 0xff;
51 *dest = ret;
52 return 0;
53}
54
55static int max8998_i2c_device_write(struct max8998_dev *max8998, u8 reg, u8 value)
56{
57 struct i2c_client *client = max8998->i2c_client;
58 int ret;
59
60 mutex_lock(&max8998->iolock);
61 ret = i2c_smbus_write_byte_data(client, reg, value);
62 mutex_unlock(&max8998->iolock);
63 return ret;
64}
65
66static int max8998_i2c_device_update(struct max8998_dev *max8998, u8 reg,
67 u8 val, u8 mask)
68{
69 struct i2c_client *client = max8998->i2c_client;
70 int ret;
71
72 mutex_lock(&max8998->iolock);
73 ret = i2c_smbus_read_byte_data(client, reg);
74 if (ret >= 0) {
75 u8 old_val = ret & 0xff;
76 u8 new_val = (val & mask) | (old_val & (~mask));
77 ret = i2c_smbus_write_byte_data(client, reg, new_val);
78 if (ret >= 0)
79 ret = 0;
80 }
81 mutex_unlock(&max8998->iolock);
82 return ret;
83}
84
85static int max8998_i2c_probe(struct i2c_client *i2c,
86 const struct i2c_device_id *id)
87{
88 struct max8998_dev *max8998;
89 int ret = 0;
90
91 max8998 = kzalloc(sizeof(struct max8998_dev), GFP_KERNEL);
92 if (max8998 == NULL)
93 return -ENOMEM;
94
95 i2c_set_clientdata(i2c, max8998);
96 max8998->dev = &i2c->dev;
97 max8998->i2c_client = i2c;
98 max8998->dev_read = max8998_i2c_device_read;
99 max8998->dev_write = max8998_i2c_device_write;
100 max8998->dev_update = max8998_i2c_device_update;
101 mutex_init(&max8998->iolock);
102
103 ret = mfd_add_devices(max8998->dev, -1,
104 max8998_devs, ARRAY_SIZE(max8998_devs),
105 NULL, 0);
106 if (ret < 0)
107 goto err;
108
109 return ret;
110
111err:
112 mfd_remove_devices(max8998->dev);
113 kfree(max8998);
114 return ret;
115}
116
117static int max8998_i2c_remove(struct i2c_client *i2c)
118{
119 struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
120
121 mfd_remove_devices(max8998->dev);
122 kfree(max8998);
123
124 return 0;
125}
126
127static const struct i2c_device_id max8998_i2c_id[] = {
128 { "max8998", 0 },
129 { }
130};
131MODULE_DEVICE_TABLE(i2c, max8998_i2c_id);
132
133static struct i2c_driver max8998_i2c_driver = {
134 .driver = {
135 .name = "max8998",
136 .owner = THIS_MODULE,
137 },
138 .probe = max8998_i2c_probe,
139 .remove = max8998_i2c_remove,
140 .id_table = max8998_i2c_id,
141};
142
143static int __init max8998_i2c_init(void)
144{
145 return i2c_add_driver(&max8998_i2c_driver);
146}
147/* init early so consumer devices can complete system boot */
148subsys_initcall(max8998_i2c_init);
149
150static void __exit max8998_i2c_exit(void)
151{
152 i2c_del_driver(&max8998_i2c_driver);
153}
154module_exit(max8998_i2c_exit);
155
156MODULE_DESCRIPTION("MAXIM 8998 multi-function core driver");
157MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
158MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/mc13783-core.c b/drivers/mfd/mc13783-core.c
index fecf38a4f025..6df34989c1f6 100644
--- a/drivers/mfd/mc13783-core.c
+++ b/drivers/mfd/mc13783-core.c
@@ -11,9 +11,31 @@
11 */ 11 */
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/mutex.h>
16#include <linux/interrupt.h>
14#include <linux/spi/spi.h> 17#include <linux/spi/spi.h>
15#include <linux/mfd/core.h> 18#include <linux/mfd/core.h>
16#include <linux/mfd/mc13783-private.h> 19#include <linux/mfd/mc13783.h>
20
21struct mc13783 {
22 struct spi_device *spidev;
23 struct mutex lock;
24 int irq;
25 int flags;
26
27 irq_handler_t irqhandler[MC13783_NUM_IRQ];
28 void *irqdata[MC13783_NUM_IRQ];
29
30 /* XXX these should go as platformdata to the regulator subdevice */
31 struct mc13783_regulator_init_data *regulators;
32 int num_regulators;
33};
34
35#define MC13783_REG_REVISION 7
36#define MC13783_REG_ADC_0 43
37#define MC13783_REG_ADC_1 44
38#define MC13783_REG_ADC_2 45
17 39
18#define MC13783_IRQSTAT0 0 40#define MC13783_IRQSTAT0 0
19#define MC13783_IRQSTAT0_ADCDONEI (1 << 0) 41#define MC13783_IRQSTAT0_ADCDONEI (1 << 0)
@@ -226,6 +248,12 @@ int mc13783_reg_rmw(struct mc13783 *mc13783, unsigned int offset,
226} 248}
227EXPORT_SYMBOL(mc13783_reg_rmw); 249EXPORT_SYMBOL(mc13783_reg_rmw);
228 250
251int mc13783_get_flags(struct mc13783 *mc13783)
252{
253 return mc13783->flags;
254}
255EXPORT_SYMBOL(mc13783_get_flags);
256
229int mc13783_irq_mask(struct mc13783 *mc13783, int irq) 257int mc13783_irq_mask(struct mc13783 *mc13783, int irq)
230{ 258{
231 int ret; 259 int ret;
diff --git a/drivers/mfd/menelaus.c b/drivers/mfd/menelaus.c
index a3fb4bcb9889..4ba85bbdb4c1 100644
--- a/drivers/mfd/menelaus.c
+++ b/drivers/mfd/menelaus.c
@@ -128,6 +128,39 @@
128#define MENELAUS_RESERVED14_IRQ 14 /* Reserved */ 128#define MENELAUS_RESERVED14_IRQ 14 /* Reserved */
129#define MENELAUS_RESERVED15_IRQ 15 /* Reserved */ 129#define MENELAUS_RESERVED15_IRQ 15 /* Reserved */
130 130
131/* VCORE_CTRL1 register */
132#define VCORE_CTRL1_BYP_COMP (1 << 5)
133#define VCORE_CTRL1_HW_NSW (1 << 7)
134
135/* GPIO_CTRL register */
136#define GPIO_CTRL_SLOTSELEN (1 << 5)
137#define GPIO_CTRL_SLPCTLEN (1 << 6)
138#define GPIO1_DIR_INPUT (1 << 0)
139#define GPIO2_DIR_INPUT (1 << 1)
140#define GPIO3_DIR_INPUT (1 << 2)
141
142/* MCT_CTRL1 register */
143#define MCT_CTRL1_S1_CMD_OD (1 << 2)
144#define MCT_CTRL1_S2_CMD_OD (1 << 3)
145
146/* MCT_CTRL2 register */
147#define MCT_CTRL2_VS2_SEL_D0 (1 << 0)
148#define MCT_CTRL2_VS2_SEL_D1 (1 << 1)
149#define MCT_CTRL2_S1CD_BUFEN (1 << 4)
150#define MCT_CTRL2_S2CD_BUFEN (1 << 5)
151#define MCT_CTRL2_S1CD_DBEN (1 << 6)
152#define MCT_CTRL2_S2CD_BEN (1 << 7)
153
154/* MCT_CTRL3 register */
155#define MCT_CTRL3_SLOT1_EN (1 << 0)
156#define MCT_CTRL3_SLOT2_EN (1 << 1)
157#define MCT_CTRL3_S1_AUTO_EN (1 << 2)
158#define MCT_CTRL3_S2_AUTO_EN (1 << 3)
159
160/* MCT_PIN_ST register */
161#define MCT_PIN_ST_S1_CD_ST (1 << 0)
162#define MCT_PIN_ST_S2_CD_ST (1 << 1)
163
131static void menelaus_work(struct work_struct *_menelaus); 164static void menelaus_work(struct work_struct *_menelaus);
132 165
133struct menelaus_chip { 166struct menelaus_chip {
@@ -249,10 +282,10 @@ static void menelaus_mmc_cd_work(struct menelaus_chip *menelaus_hw)
249 return; 282 return;
250 283
251 if (!(reg & 0x1)) 284 if (!(reg & 0x1))
252 card_mask |= (1 << 0); 285 card_mask |= MCT_PIN_ST_S1_CD_ST;
253 286
254 if (!(reg & 0x2)) 287 if (!(reg & 0x2))
255 card_mask |= (1 << 1); 288 card_mask |= MCT_PIN_ST_S2_CD_ST;
256 289
257 if (menelaus_hw->mmc_callback) 290 if (menelaus_hw->mmc_callback)
258 menelaus_hw->mmc_callback(menelaus_hw->mmc_callback_data, 291 menelaus_hw->mmc_callback(menelaus_hw->mmc_callback_data,
@@ -277,14 +310,14 @@ int menelaus_set_mmc_opendrain(int slot, int enable)
277 val = ret; 310 val = ret;
278 if (slot == 1) { 311 if (slot == 1) {
279 if (enable) 312 if (enable)
280 val |= 1 << 2; 313 val |= MCT_CTRL1_S1_CMD_OD;
281 else 314 else
282 val &= ~(1 << 2); 315 val &= ~MCT_CTRL1_S1_CMD_OD;
283 } else { 316 } else {
284 if (enable) 317 if (enable)
285 val |= 1 << 3; 318 val |= MCT_CTRL1_S2_CMD_OD;
286 else 319 else
287 val &= ~(1 << 3); 320 val &= ~MCT_CTRL1_S2_CMD_OD;
288 } 321 }
289 ret = menelaus_write_reg(MENELAUS_MCT_CTRL1, val); 322 ret = menelaus_write_reg(MENELAUS_MCT_CTRL1, val);
290 mutex_unlock(&the_menelaus->lock); 323 mutex_unlock(&the_menelaus->lock);
@@ -301,11 +334,11 @@ int menelaus_set_slot_sel(int enable)
301 ret = menelaus_read_reg(MENELAUS_GPIO_CTRL); 334 ret = menelaus_read_reg(MENELAUS_GPIO_CTRL);
302 if (ret < 0) 335 if (ret < 0)
303 goto out; 336 goto out;
304 ret |= 0x02; 337 ret |= GPIO2_DIR_INPUT;
305 if (enable) 338 if (enable)
306 ret |= 1 << 5; 339 ret |= GPIO_CTRL_SLOTSELEN;
307 else 340 else
308 ret &= ~(1 << 5); 341 ret &= ~GPIO_CTRL_SLOTSELEN;
309 ret = menelaus_write_reg(MENELAUS_GPIO_CTRL, ret); 342 ret = menelaus_write_reg(MENELAUS_GPIO_CTRL, ret);
310out: 343out:
311 mutex_unlock(&the_menelaus->lock); 344 mutex_unlock(&the_menelaus->lock);
@@ -330,14 +363,14 @@ int menelaus_set_mmc_slot(int slot, int enable, int power, int cd_en)
330 val = ret; 363 val = ret;
331 if (slot == 1) { 364 if (slot == 1) {
332 if (cd_en) 365 if (cd_en)
333 val |= (1 << 4) | (1 << 6); 366 val |= MCT_CTRL2_S1CD_BUFEN | MCT_CTRL2_S1CD_DBEN;
334 else 367 else
335 val &= ~((1 << 4) | (1 << 6)); 368 val &= ~(MCT_CTRL2_S1CD_BUFEN | MCT_CTRL2_S1CD_DBEN);
336 } else { 369 } else {
337 if (cd_en) 370 if (cd_en)
338 val |= (1 << 5) | (1 << 7); 371 val |= MCT_CTRL2_S2CD_BUFEN | MCT_CTRL2_S2CD_BEN;
339 else 372 else
340 val &= ~((1 << 5) | (1 << 7)); 373 val &= ~(MCT_CTRL2_S2CD_BUFEN | MCT_CTRL2_S2CD_BEN);
341 } 374 }
342 ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, val); 375 ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, val);
343 if (ret < 0) 376 if (ret < 0)
@@ -349,25 +382,25 @@ int menelaus_set_mmc_slot(int slot, int enable, int power, int cd_en)
349 val = ret; 382 val = ret;
350 if (slot == 1) { 383 if (slot == 1) {
351 if (enable) 384 if (enable)
352 val |= 1 << 0; 385 val |= MCT_CTRL3_SLOT1_EN;
353 else 386 else
354 val &= ~(1 << 0); 387 val &= ~MCT_CTRL3_SLOT1_EN;
355 } else { 388 } else {
356 int b; 389 int b;
357 390
358 if (enable) 391 if (enable)
359 ret |= 1 << 1; 392 val |= MCT_CTRL3_SLOT2_EN;
360 else 393 else
361 ret &= ~(1 << 1); 394 val &= ~MCT_CTRL3_SLOT2_EN;
362 b = menelaus_read_reg(MENELAUS_MCT_CTRL2); 395 b = menelaus_read_reg(MENELAUS_MCT_CTRL2);
363 b &= ~0x03; 396 b &= ~(MCT_CTRL2_VS2_SEL_D0 | MCT_CTRL2_VS2_SEL_D1);
364 b |= power; 397 b |= power;
365 ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, b); 398 ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, b);
366 if (ret < 0) 399 if (ret < 0)
367 goto out; 400 goto out;
368 } 401 }
369 /* Disable autonomous shutdown */ 402 /* Disable autonomous shutdown */
370 val &= ~(0x03 << 2); 403 val &= ~(MCT_CTRL3_S1_AUTO_EN | MCT_CTRL3_S2_AUTO_EN);
371 ret = menelaus_write_reg(MENELAUS_MCT_CTRL3, val); 404 ret = menelaus_write_reg(MENELAUS_MCT_CTRL3, val);
372out: 405out:
373 mutex_unlock(&the_menelaus->lock); 406 mutex_unlock(&the_menelaus->lock);
@@ -552,7 +585,7 @@ int menelaus_set_vcore_hw(unsigned int roof_mV, unsigned int floor_mV)
552 if (!the_menelaus->vcore_hw_mode) { 585 if (!the_menelaus->vcore_hw_mode) {
553 val = menelaus_read_reg(MENELAUS_VCORE_CTRL1); 586 val = menelaus_read_reg(MENELAUS_VCORE_CTRL1);
554 /* HW mode, turn OFF byte comparator */ 587 /* HW mode, turn OFF byte comparator */
555 val |= ((1 << 7) | (1 << 5)); 588 val |= (VCORE_CTRL1_HW_NSW | VCORE_CTRL1_BYP_COMP);
556 ret = menelaus_write_reg(MENELAUS_VCORE_CTRL1, val); 589 ret = menelaus_write_reg(MENELAUS_VCORE_CTRL1, val);
557 the_menelaus->vcore_hw_mode = 1; 590 the_menelaus->vcore_hw_mode = 1;
558 } 591 }
@@ -749,7 +782,7 @@ int menelaus_set_regulator_sleep(int enable, u32 val)
749 ret = menelaus_read_reg(MENELAUS_GPIO_CTRL); 782 ret = menelaus_read_reg(MENELAUS_GPIO_CTRL);
750 if (ret < 0) 783 if (ret < 0)
751 goto out; 784 goto out;
752 t = ((1 << 6) | 0x04); 785 t = (GPIO_CTRL_SLPCTLEN | GPIO3_DIR_INPUT);
753 if (enable) 786 if (enable)
754 ret |= t; 787 ret |= t;
755 else 788 else
diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 7dd76bceaae8..1823a57b7d8f 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -70,7 +70,9 @@ static int mfd_add_device(struct device *parent, int id,
70 goto fail_res; 70 goto fail_res;
71 } 71 }
72 72
73 platform_device_add_resources(pdev, res, cell->num_resources); 73 ret = platform_device_add_resources(pdev, res, cell->num_resources);
74 if (ret)
75 goto fail_res;
74 76
75 ret = platform_device_add(pdev); 77 ret = platform_device_add(pdev);
76 if (ret) 78 if (ret)
diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
new file mode 100644
index 000000000000..0754c5e91995
--- /dev/null
+++ b/drivers/mfd/stmpe.c
@@ -0,0 +1,985 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
6 */
7
8#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/interrupt.h>
11#include <linux/irq.h>
12#include <linux/slab.h>
13#include <linux/i2c.h>
14#include <linux/mfd/core.h>
15#include <linux/mfd/stmpe.h>
16#include "stmpe.h"
17
18static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks)
19{
20 return stmpe->variant->enable(stmpe, blocks, true);
21}
22
23static int __stmpe_disable(struct stmpe *stmpe, unsigned int blocks)
24{
25 return stmpe->variant->enable(stmpe, blocks, false);
26}
27
28static int __stmpe_reg_read(struct stmpe *stmpe, u8 reg)
29{
30 int ret;
31
32 ret = i2c_smbus_read_byte_data(stmpe->i2c, reg);
33 if (ret < 0)
34 dev_err(stmpe->dev, "failed to read reg %#x: %d\n",
35 reg, ret);
36
37 dev_vdbg(stmpe->dev, "rd: reg %#x => data %#x\n", reg, ret);
38
39 return ret;
40}
41
42static int __stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
43{
44 int ret;
45
46 dev_vdbg(stmpe->dev, "wr: reg %#x <= %#x\n", reg, val);
47
48 ret = i2c_smbus_write_byte_data(stmpe->i2c, reg, val);
49 if (ret < 0)
50 dev_err(stmpe->dev, "failed to write reg %#x: %d\n",
51 reg, ret);
52
53 return ret;
54}
55
56static int __stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val)
57{
58 int ret;
59
60 ret = __stmpe_reg_read(stmpe, reg);
61 if (ret < 0)
62 return ret;
63
64 ret &= ~mask;
65 ret |= val;
66
67 return __stmpe_reg_write(stmpe, reg, ret);
68}
69
70static int __stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length,
71 u8 *values)
72{
73 int ret;
74
75 ret = i2c_smbus_read_i2c_block_data(stmpe->i2c, reg, length, values);
76 if (ret < 0)
77 dev_err(stmpe->dev, "failed to read regs %#x: %d\n",
78 reg, ret);
79
80 dev_vdbg(stmpe->dev, "rd: reg %#x (%d) => ret %#x\n", reg, length, ret);
81 stmpe_dump_bytes("stmpe rd: ", values, length);
82
83 return ret;
84}
85
86static int __stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
87 const u8 *values)
88{
89 int ret;
90
91 dev_vdbg(stmpe->dev, "wr: regs %#x (%d)\n", reg, length);
92 stmpe_dump_bytes("stmpe wr: ", values, length);
93
94 ret = i2c_smbus_write_i2c_block_data(stmpe->i2c, reg, length,
95 values);
96 if (ret < 0)
97 dev_err(stmpe->dev, "failed to write regs %#x: %d\n",
98 reg, ret);
99
100 return ret;
101}
102
103/**
104 * stmpe_enable - enable blocks on an STMPE device
105 * @stmpe: Device to work on
106 * @blocks: Mask of blocks (enum stmpe_block values) to enable
107 */
108int stmpe_enable(struct stmpe *stmpe, unsigned int blocks)
109{
110 int ret;
111
112 mutex_lock(&stmpe->lock);
113 ret = __stmpe_enable(stmpe, blocks);
114 mutex_unlock(&stmpe->lock);
115
116 return ret;
117}
118EXPORT_SYMBOL_GPL(stmpe_enable);
119
120/**
121 * stmpe_disable - disable blocks on an STMPE device
122 * @stmpe: Device to work on
123 * @blocks: Mask of blocks (enum stmpe_block values) to enable
124 */
125int stmpe_disable(struct stmpe *stmpe, unsigned int blocks)
126{
127 int ret;
128
129 mutex_lock(&stmpe->lock);
130 ret = __stmpe_disable(stmpe, blocks);
131 mutex_unlock(&stmpe->lock);
132
133 return ret;
134}
135EXPORT_SYMBOL_GPL(stmpe_disable);
136
137/**
138 * stmpe_reg_read() - read a single STMPE register
139 * @stmpe: Device to read from
140 * @reg: Register to read
141 */
142int stmpe_reg_read(struct stmpe *stmpe, u8 reg)
143{
144 int ret;
145
146 mutex_lock(&stmpe->lock);
147 ret = __stmpe_reg_read(stmpe, reg);
148 mutex_unlock(&stmpe->lock);
149
150 return ret;
151}
152EXPORT_SYMBOL_GPL(stmpe_reg_read);
153
154/**
155 * stmpe_reg_write() - write a single STMPE register
156 * @stmpe: Device to write to
157 * @reg: Register to write
158 * @val: Value to write
159 */
160int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
161{
162 int ret;
163
164 mutex_lock(&stmpe->lock);
165 ret = __stmpe_reg_write(stmpe, reg, val);
166 mutex_unlock(&stmpe->lock);
167
168 return ret;
169}
170EXPORT_SYMBOL_GPL(stmpe_reg_write);
171
172/**
173 * stmpe_set_bits() - set the value of a bitfield in a STMPE register
174 * @stmpe: Device to write to
175 * @reg: Register to write
176 * @mask: Mask of bits to set
177 * @val: Value to set
178 */
179int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val)
180{
181 int ret;
182
183 mutex_lock(&stmpe->lock);
184 ret = __stmpe_set_bits(stmpe, reg, mask, val);
185 mutex_unlock(&stmpe->lock);
186
187 return ret;
188}
189EXPORT_SYMBOL_GPL(stmpe_set_bits);
190
191/**
192 * stmpe_block_read() - read multiple STMPE registers
193 * @stmpe: Device to read from
194 * @reg: First register
195 * @length: Number of registers
196 * @values: Buffer to write to
197 */
198int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values)
199{
200 int ret;
201
202 mutex_lock(&stmpe->lock);
203 ret = __stmpe_block_read(stmpe, reg, length, values);
204 mutex_unlock(&stmpe->lock);
205
206 return ret;
207}
208EXPORT_SYMBOL_GPL(stmpe_block_read);
209
210/**
211 * stmpe_block_write() - write multiple STMPE registers
212 * @stmpe: Device to write to
213 * @reg: First register
214 * @length: Number of registers
215 * @values: Values to write
216 */
217int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
218 const u8 *values)
219{
220 int ret;
221
222 mutex_lock(&stmpe->lock);
223 ret = __stmpe_block_write(stmpe, reg, length, values);
224 mutex_unlock(&stmpe->lock);
225
226 return ret;
227}
228EXPORT_SYMBOL_GPL(stmpe_block_write);
229
230/**
231 * stmpe_set_altfunc: set the alternate function for STMPE pins
232 * @stmpe: Device to configure
233 * @pins: Bitmask of pins to affect
234 * @block: block to enable alternate functions for
235 *
236 * @pins is assumed to have a bit set for each of the bits whose alternate
237 * function is to be changed, numbered according to the GPIOXY numbers.
238 *
239 * If the GPIO module is not enabled, this function automatically enables it in
240 * order to perform the change.
241 */
242int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins, enum stmpe_block block)
243{
244 struct stmpe_variant_info *variant = stmpe->variant;
245 u8 regaddr = stmpe->regs[STMPE_IDX_GPAFR_U_MSB];
246 int af_bits = variant->af_bits;
247 int numregs = DIV_ROUND_UP(stmpe->num_gpios * af_bits, 8);
248 int afperreg = 8 / af_bits;
249 int mask = (1 << af_bits) - 1;
250 u8 regs[numregs];
251 int af;
252 int ret;
253
254 mutex_lock(&stmpe->lock);
255
256 ret = __stmpe_enable(stmpe, STMPE_BLOCK_GPIO);
257 if (ret < 0)
258 goto out;
259
260 ret = __stmpe_block_read(stmpe, regaddr, numregs, regs);
261 if (ret < 0)
262 goto out;
263
264 af = variant->get_altfunc(stmpe, block);
265
266 while (pins) {
267 int pin = __ffs(pins);
268 int regoffset = numregs - (pin / afperreg) - 1;
269 int pos = (pin % afperreg) * (8 / afperreg);
270
271 regs[regoffset] &= ~(mask << pos);
272 regs[regoffset] |= af << pos;
273
274 pins &= ~(1 << pin);
275 }
276
277 ret = __stmpe_block_write(stmpe, regaddr, numregs, regs);
278
279out:
280 mutex_unlock(&stmpe->lock);
281 return ret;
282}
283EXPORT_SYMBOL_GPL(stmpe_set_altfunc);
284
285/*
286 * GPIO (all variants)
287 */
288
289static struct resource stmpe_gpio_resources[] = {
290 /* Start and end filled dynamically */
291 {
292 .flags = IORESOURCE_IRQ,
293 },
294};
295
296static struct mfd_cell stmpe_gpio_cell = {
297 .name = "stmpe-gpio",
298 .resources = stmpe_gpio_resources,
299 .num_resources = ARRAY_SIZE(stmpe_gpio_resources),
300};
301
302/*
303 * Keypad (1601, 2401, 2403)
304 */
305
306static struct resource stmpe_keypad_resources[] = {
307 {
308 .name = "KEYPAD",
309 .start = 0,
310 .end = 0,
311 .flags = IORESOURCE_IRQ,
312 },
313 {
314 .name = "KEYPAD_OVER",
315 .start = 1,
316 .end = 1,
317 .flags = IORESOURCE_IRQ,
318 },
319};
320
321static struct mfd_cell stmpe_keypad_cell = {
322 .name = "stmpe-keypad",
323 .resources = stmpe_keypad_resources,
324 .num_resources = ARRAY_SIZE(stmpe_keypad_resources),
325};
326
327/*
328 * Touchscreen (STMPE811)
329 */
330
331static struct resource stmpe_ts_resources[] = {
332 {
333 .name = "TOUCH_DET",
334 .start = 0,
335 .end = 0,
336 .flags = IORESOURCE_IRQ,
337 },
338 {
339 .name = "FIFO_TH",
340 .start = 1,
341 .end = 1,
342 .flags = IORESOURCE_IRQ,
343 },
344};
345
346static struct mfd_cell stmpe_ts_cell = {
347 .name = "stmpe-ts",
348 .resources = stmpe_ts_resources,
349 .num_resources = ARRAY_SIZE(stmpe_ts_resources),
350};
351
352/*
353 * STMPE811
354 */
355
356static const u8 stmpe811_regs[] = {
357 [STMPE_IDX_CHIP_ID] = STMPE811_REG_CHIP_ID,
358 [STMPE_IDX_ICR_LSB] = STMPE811_REG_INT_CTRL,
359 [STMPE_IDX_IER_LSB] = STMPE811_REG_INT_EN,
360 [STMPE_IDX_ISR_MSB] = STMPE811_REG_INT_STA,
361 [STMPE_IDX_GPMR_LSB] = STMPE811_REG_GPIO_MP_STA,
362 [STMPE_IDX_GPSR_LSB] = STMPE811_REG_GPIO_SET_PIN,
363 [STMPE_IDX_GPCR_LSB] = STMPE811_REG_GPIO_CLR_PIN,
364 [STMPE_IDX_GPDR_LSB] = STMPE811_REG_GPIO_DIR,
365 [STMPE_IDX_GPRER_LSB] = STMPE811_REG_GPIO_RE,
366 [STMPE_IDX_GPFER_LSB] = STMPE811_REG_GPIO_FE,
367 [STMPE_IDX_GPAFR_U_MSB] = STMPE811_REG_GPIO_AF,
368 [STMPE_IDX_IEGPIOR_LSB] = STMPE811_REG_GPIO_INT_EN,
369 [STMPE_IDX_ISGPIOR_MSB] = STMPE811_REG_GPIO_INT_STA,
370 [STMPE_IDX_GPEDR_MSB] = STMPE811_REG_GPIO_ED,
371};
372
373static struct stmpe_variant_block stmpe811_blocks[] = {
374 {
375 .cell = &stmpe_gpio_cell,
376 .irq = STMPE811_IRQ_GPIOC,
377 .block = STMPE_BLOCK_GPIO,
378 },
379 {
380 .cell = &stmpe_ts_cell,
381 .irq = STMPE811_IRQ_TOUCH_DET,
382 .block = STMPE_BLOCK_TOUCHSCREEN,
383 },
384};
385
386static int stmpe811_enable(struct stmpe *stmpe, unsigned int blocks,
387 bool enable)
388{
389 unsigned int mask = 0;
390
391 if (blocks & STMPE_BLOCK_GPIO)
392 mask |= STMPE811_SYS_CTRL2_GPIO_OFF;
393
394 if (blocks & STMPE_BLOCK_ADC)
395 mask |= STMPE811_SYS_CTRL2_ADC_OFF;
396
397 if (blocks & STMPE_BLOCK_TOUCHSCREEN)
398 mask |= STMPE811_SYS_CTRL2_TSC_OFF;
399
400 return __stmpe_set_bits(stmpe, STMPE811_REG_SYS_CTRL2, mask,
401 enable ? 0 : mask);
402}
403
404static int stmpe811_get_altfunc(struct stmpe *stmpe, enum stmpe_block block)
405{
406 /* 0 for touchscreen, 1 for GPIO */
407 return block != STMPE_BLOCK_TOUCHSCREEN;
408}
409
410static struct stmpe_variant_info stmpe811 = {
411 .name = "stmpe811",
412 .id_val = 0x0811,
413 .id_mask = 0xffff,
414 .num_gpios = 8,
415 .af_bits = 1,
416 .regs = stmpe811_regs,
417 .blocks = stmpe811_blocks,
418 .num_blocks = ARRAY_SIZE(stmpe811_blocks),
419 .num_irqs = STMPE811_NR_INTERNAL_IRQS,
420 .enable = stmpe811_enable,
421 .get_altfunc = stmpe811_get_altfunc,
422};
423
424/*
425 * STMPE1601
426 */
427
428static const u8 stmpe1601_regs[] = {
429 [STMPE_IDX_CHIP_ID] = STMPE1601_REG_CHIP_ID,
430 [STMPE_IDX_ICR_LSB] = STMPE1601_REG_ICR_LSB,
431 [STMPE_IDX_IER_LSB] = STMPE1601_REG_IER_LSB,
432 [STMPE_IDX_ISR_MSB] = STMPE1601_REG_ISR_MSB,
433 [STMPE_IDX_GPMR_LSB] = STMPE1601_REG_GPIO_MP_LSB,
434 [STMPE_IDX_GPSR_LSB] = STMPE1601_REG_GPIO_SET_LSB,
435 [STMPE_IDX_GPCR_LSB] = STMPE1601_REG_GPIO_CLR_LSB,
436 [STMPE_IDX_GPDR_LSB] = STMPE1601_REG_GPIO_SET_DIR_LSB,
437 [STMPE_IDX_GPRER_LSB] = STMPE1601_REG_GPIO_RE_LSB,
438 [STMPE_IDX_GPFER_LSB] = STMPE1601_REG_GPIO_FE_LSB,
439 [STMPE_IDX_GPAFR_U_MSB] = STMPE1601_REG_GPIO_AF_U_MSB,
440 [STMPE_IDX_IEGPIOR_LSB] = STMPE1601_REG_INT_EN_GPIO_MASK_LSB,
441 [STMPE_IDX_ISGPIOR_MSB] = STMPE1601_REG_INT_STA_GPIO_MSB,
442 [STMPE_IDX_GPEDR_MSB] = STMPE1601_REG_GPIO_ED_MSB,
443};
444
445static struct stmpe_variant_block stmpe1601_blocks[] = {
446 {
447 .cell = &stmpe_gpio_cell,
448 .irq = STMPE24XX_IRQ_GPIOC,
449 .block = STMPE_BLOCK_GPIO,
450 },
451 {
452 .cell = &stmpe_keypad_cell,
453 .irq = STMPE24XX_IRQ_KEYPAD,
454 .block = STMPE_BLOCK_KEYPAD,
455 },
456};
457
458/* supported autosleep timeout delay (in msecs) */
459static const int stmpe_autosleep_delay[] = {
460 4, 16, 32, 64, 128, 256, 512, 1024,
461};
462
463static int stmpe_round_timeout(int timeout)
464{
465 int i;
466
467 for (i = 0; i < ARRAY_SIZE(stmpe_autosleep_delay); i++) {
468 if (stmpe_autosleep_delay[i] >= timeout)
469 return i;
470 }
471
472 /*
473 * requests for delays longer than supported should not return the
474 * longest supported delay
475 */
476 return -EINVAL;
477}
478
479static int stmpe_autosleep(struct stmpe *stmpe, int autosleep_timeout)
480{
481 int ret;
482
483 if (!stmpe->variant->enable_autosleep)
484 return -ENOSYS;
485
486 mutex_lock(&stmpe->lock);
487 ret = stmpe->variant->enable_autosleep(stmpe, autosleep_timeout);
488 mutex_unlock(&stmpe->lock);
489
490 return ret;
491}
492
493/*
494 * Both stmpe 1601/2403 support same layout for autosleep
495 */
496static int stmpe1601_autosleep(struct stmpe *stmpe,
497 int autosleep_timeout)
498{
499 int ret, timeout;
500
501 /* choose the best available timeout */
502 timeout = stmpe_round_timeout(autosleep_timeout);
503 if (timeout < 0) {
504 dev_err(stmpe->dev, "invalid timeout\n");
505 return timeout;
506 }
507
508 ret = __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2,
509 STMPE1601_AUTOSLEEP_TIMEOUT_MASK,
510 timeout);
511 if (ret < 0)
512 return ret;
513
514 return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2,
515 STPME1601_AUTOSLEEP_ENABLE,
516 STPME1601_AUTOSLEEP_ENABLE);
517}
518
519static int stmpe1601_enable(struct stmpe *stmpe, unsigned int blocks,
520 bool enable)
521{
522 unsigned int mask = 0;
523
524 if (blocks & STMPE_BLOCK_GPIO)
525 mask |= STMPE1601_SYS_CTRL_ENABLE_GPIO;
526
527 if (blocks & STMPE_BLOCK_KEYPAD)
528 mask |= STMPE1601_SYS_CTRL_ENABLE_KPC;
529
530 return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL, mask,
531 enable ? mask : 0);
532}
533
534static int stmpe1601_get_altfunc(struct stmpe *stmpe, enum stmpe_block block)
535{
536 switch (block) {
537 case STMPE_BLOCK_PWM:
538 return 2;
539
540 case STMPE_BLOCK_KEYPAD:
541 return 1;
542
543 case STMPE_BLOCK_GPIO:
544 default:
545 return 0;
546 }
547}
548
549static struct stmpe_variant_info stmpe1601 = {
550 .name = "stmpe1601",
551 .id_val = 0x0210,
552 .id_mask = 0xfff0, /* at least 0x0210 and 0x0212 */
553 .num_gpios = 16,
554 .af_bits = 2,
555 .regs = stmpe1601_regs,
556 .blocks = stmpe1601_blocks,
557 .num_blocks = ARRAY_SIZE(stmpe1601_blocks),
558 .num_irqs = STMPE1601_NR_INTERNAL_IRQS,
559 .enable = stmpe1601_enable,
560 .get_altfunc = stmpe1601_get_altfunc,
561 .enable_autosleep = stmpe1601_autosleep,
562};
563
564/*
565 * STMPE24XX
566 */
567
568static const u8 stmpe24xx_regs[] = {
569 [STMPE_IDX_CHIP_ID] = STMPE24XX_REG_CHIP_ID,
570 [STMPE_IDX_ICR_LSB] = STMPE24XX_REG_ICR_LSB,
571 [STMPE_IDX_IER_LSB] = STMPE24XX_REG_IER_LSB,
572 [STMPE_IDX_ISR_MSB] = STMPE24XX_REG_ISR_MSB,
573 [STMPE_IDX_GPMR_LSB] = STMPE24XX_REG_GPMR_LSB,
574 [STMPE_IDX_GPSR_LSB] = STMPE24XX_REG_GPSR_LSB,
575 [STMPE_IDX_GPCR_LSB] = STMPE24XX_REG_GPCR_LSB,
576 [STMPE_IDX_GPDR_LSB] = STMPE24XX_REG_GPDR_LSB,
577 [STMPE_IDX_GPRER_LSB] = STMPE24XX_REG_GPRER_LSB,
578 [STMPE_IDX_GPFER_LSB] = STMPE24XX_REG_GPFER_LSB,
579 [STMPE_IDX_GPAFR_U_MSB] = STMPE24XX_REG_GPAFR_U_MSB,
580 [STMPE_IDX_IEGPIOR_LSB] = STMPE24XX_REG_IEGPIOR_LSB,
581 [STMPE_IDX_ISGPIOR_MSB] = STMPE24XX_REG_ISGPIOR_MSB,
582 [STMPE_IDX_GPEDR_MSB] = STMPE24XX_REG_GPEDR_MSB,
583};
584
585static struct stmpe_variant_block stmpe24xx_blocks[] = {
586 {
587 .cell = &stmpe_gpio_cell,
588 .irq = STMPE24XX_IRQ_GPIOC,
589 .block = STMPE_BLOCK_GPIO,
590 },
591 {
592 .cell = &stmpe_keypad_cell,
593 .irq = STMPE24XX_IRQ_KEYPAD,
594 .block = STMPE_BLOCK_KEYPAD,
595 },
596};
597
598static int stmpe24xx_enable(struct stmpe *stmpe, unsigned int blocks,
599 bool enable)
600{
601 unsigned int mask = 0;
602
603 if (blocks & STMPE_BLOCK_GPIO)
604 mask |= STMPE24XX_SYS_CTRL_ENABLE_GPIO;
605
606 if (blocks & STMPE_BLOCK_KEYPAD)
607 mask |= STMPE24XX_SYS_CTRL_ENABLE_KPC;
608
609 return __stmpe_set_bits(stmpe, STMPE24XX_REG_SYS_CTRL, mask,
610 enable ? mask : 0);
611}
612
613static int stmpe24xx_get_altfunc(struct stmpe *stmpe, enum stmpe_block block)
614{
615 switch (block) {
616 case STMPE_BLOCK_ROTATOR:
617 return 2;
618
619 case STMPE_BLOCK_KEYPAD:
620 return 1;
621
622 case STMPE_BLOCK_GPIO:
623 default:
624 return 0;
625 }
626}
627
628static struct stmpe_variant_info stmpe2401 = {
629 .name = "stmpe2401",
630 .id_val = 0x0101,
631 .id_mask = 0xffff,
632 .num_gpios = 24,
633 .af_bits = 2,
634 .regs = stmpe24xx_regs,
635 .blocks = stmpe24xx_blocks,
636 .num_blocks = ARRAY_SIZE(stmpe24xx_blocks),
637 .num_irqs = STMPE24XX_NR_INTERNAL_IRQS,
638 .enable = stmpe24xx_enable,
639 .get_altfunc = stmpe24xx_get_altfunc,
640};
641
642static struct stmpe_variant_info stmpe2403 = {
643 .name = "stmpe2403",
644 .id_val = 0x0120,
645 .id_mask = 0xffff,
646 .num_gpios = 24,
647 .af_bits = 2,
648 .regs = stmpe24xx_regs,
649 .blocks = stmpe24xx_blocks,
650 .num_blocks = ARRAY_SIZE(stmpe24xx_blocks),
651 .num_irqs = STMPE24XX_NR_INTERNAL_IRQS,
652 .enable = stmpe24xx_enable,
653 .get_altfunc = stmpe24xx_get_altfunc,
654 .enable_autosleep = stmpe1601_autosleep, /* same as stmpe1601 */
655};
656
657static struct stmpe_variant_info *stmpe_variant_info[] = {
658 [STMPE811] = &stmpe811,
659 [STMPE1601] = &stmpe1601,
660 [STMPE2401] = &stmpe2401,
661 [STMPE2403] = &stmpe2403,
662};
663
664static irqreturn_t stmpe_irq(int irq, void *data)
665{
666 struct stmpe *stmpe = data;
667 struct stmpe_variant_info *variant = stmpe->variant;
668 int num = DIV_ROUND_UP(variant->num_irqs, 8);
669 u8 israddr = stmpe->regs[STMPE_IDX_ISR_MSB];
670 u8 isr[num];
671 int ret;
672 int i;
673
674 ret = stmpe_block_read(stmpe, israddr, num, isr);
675 if (ret < 0)
676 return IRQ_NONE;
677
678 for (i = 0; i < num; i++) {
679 int bank = num - i - 1;
680 u8 status = isr[i];
681 u8 clear;
682
683 status &= stmpe->ier[bank];
684 if (!status)
685 continue;
686
687 clear = status;
688 while (status) {
689 int bit = __ffs(status);
690 int line = bank * 8 + bit;
691
692 handle_nested_irq(stmpe->irq_base + line);
693 status &= ~(1 << bit);
694 }
695
696 stmpe_reg_write(stmpe, israddr + i, clear);
697 }
698
699 return IRQ_HANDLED;
700}
701
702static void stmpe_irq_lock(unsigned int irq)
703{
704 struct stmpe *stmpe = get_irq_chip_data(irq);
705
706 mutex_lock(&stmpe->irq_lock);
707}
708
709static void stmpe_irq_sync_unlock(unsigned int irq)
710{
711 struct stmpe *stmpe = get_irq_chip_data(irq);
712 struct stmpe_variant_info *variant = stmpe->variant;
713 int num = DIV_ROUND_UP(variant->num_irqs, 8);
714 int i;
715
716 for (i = 0; i < num; i++) {
717 u8 new = stmpe->ier[i];
718 u8 old = stmpe->oldier[i];
719
720 if (new == old)
721 continue;
722
723 stmpe->oldier[i] = new;
724 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_IER_LSB] - i, new);
725 }
726
727 mutex_unlock(&stmpe->irq_lock);
728}
729
730static void stmpe_irq_mask(unsigned int irq)
731{
732 struct stmpe *stmpe = get_irq_chip_data(irq);
733 int offset = irq - stmpe->irq_base;
734 int regoffset = offset / 8;
735 int mask = 1 << (offset % 8);
736
737 stmpe->ier[regoffset] &= ~mask;
738}
739
740static void stmpe_irq_unmask(unsigned int irq)
741{
742 struct stmpe *stmpe = get_irq_chip_data(irq);
743 int offset = irq - stmpe->irq_base;
744 int regoffset = offset / 8;
745 int mask = 1 << (offset % 8);
746
747 stmpe->ier[regoffset] |= mask;
748}
749
750static struct irq_chip stmpe_irq_chip = {
751 .name = "stmpe",
752 .bus_lock = stmpe_irq_lock,
753 .bus_sync_unlock = stmpe_irq_sync_unlock,
754 .mask = stmpe_irq_mask,
755 .unmask = stmpe_irq_unmask,
756};
757
758static int __devinit stmpe_irq_init(struct stmpe *stmpe)
759{
760 int num_irqs = stmpe->variant->num_irqs;
761 int base = stmpe->irq_base;
762 int irq;
763
764 for (irq = base; irq < base + num_irqs; irq++) {
765 set_irq_chip_data(irq, stmpe);
766 set_irq_chip_and_handler(irq, &stmpe_irq_chip,
767 handle_edge_irq);
768 set_irq_nested_thread(irq, 1);
769#ifdef CONFIG_ARM
770 set_irq_flags(irq, IRQF_VALID);
771#else
772 set_irq_noprobe(irq);
773#endif
774 }
775
776 return 0;
777}
778
779static void stmpe_irq_remove(struct stmpe *stmpe)
780{
781 int num_irqs = stmpe->variant->num_irqs;
782 int base = stmpe->irq_base;
783 int irq;
784
785 for (irq = base; irq < base + num_irqs; irq++) {
786#ifdef CONFIG_ARM
787 set_irq_flags(irq, 0);
788#endif
789 set_irq_chip_and_handler(irq, NULL, NULL);
790 set_irq_chip_data(irq, NULL);
791 }
792}
793
794static int __devinit stmpe_chip_init(struct stmpe *stmpe)
795{
796 unsigned int irq_trigger = stmpe->pdata->irq_trigger;
797 int autosleep_timeout = stmpe->pdata->autosleep_timeout;
798 struct stmpe_variant_info *variant = stmpe->variant;
799 u8 icr = STMPE_ICR_LSB_GIM;
800 unsigned int id;
801 u8 data[2];
802 int ret;
803
804 ret = stmpe_block_read(stmpe, stmpe->regs[STMPE_IDX_CHIP_ID],
805 ARRAY_SIZE(data), data);
806 if (ret < 0)
807 return ret;
808
809 id = (data[0] << 8) | data[1];
810 if ((id & variant->id_mask) != variant->id_val) {
811 dev_err(stmpe->dev, "unknown chip id: %#x\n", id);
812 return -EINVAL;
813 }
814
815 dev_info(stmpe->dev, "%s detected, chip id: %#x\n", variant->name, id);
816
817 /* Disable all modules -- subdrivers should enable what they need. */
818 ret = stmpe_disable(stmpe, ~0);
819 if (ret)
820 return ret;
821
822 if (irq_trigger == IRQF_TRIGGER_FALLING ||
823 irq_trigger == IRQF_TRIGGER_RISING)
824 icr |= STMPE_ICR_LSB_EDGE;
825
826 if (irq_trigger == IRQF_TRIGGER_RISING ||
827 irq_trigger == IRQF_TRIGGER_HIGH)
828 icr |= STMPE_ICR_LSB_HIGH;
829
830 if (stmpe->pdata->irq_invert_polarity)
831 icr ^= STMPE_ICR_LSB_HIGH;
832
833 if (stmpe->pdata->autosleep) {
834 ret = stmpe_autosleep(stmpe, autosleep_timeout);
835 if (ret)
836 return ret;
837 }
838
839 return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr);
840}
841
842static int __devinit stmpe_add_device(struct stmpe *stmpe,
843 struct mfd_cell *cell, int irq)
844{
845 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1,
846 NULL, stmpe->irq_base + irq);
847}
848
849static int __devinit stmpe_devices_init(struct stmpe *stmpe)
850{
851 struct stmpe_variant_info *variant = stmpe->variant;
852 unsigned int platform_blocks = stmpe->pdata->blocks;
853 int ret = -EINVAL;
854 int i;
855
856 for (i = 0; i < variant->num_blocks; i++) {
857 struct stmpe_variant_block *block = &variant->blocks[i];
858
859 if (!(platform_blocks & block->block))
860 continue;
861
862 platform_blocks &= ~block->block;
863 ret = stmpe_add_device(stmpe, block->cell, block->irq);
864 if (ret)
865 return ret;
866 }
867
868 if (platform_blocks)
869 dev_warn(stmpe->dev,
870 "platform wants blocks (%#x) not present on variant",
871 platform_blocks);
872
873 return ret;
874}
875
876static int __devinit stmpe_probe(struct i2c_client *i2c,
877 const struct i2c_device_id *id)
878{
879 struct stmpe_platform_data *pdata = i2c->dev.platform_data;
880 struct stmpe *stmpe;
881 int ret;
882
883 if (!pdata)
884 return -EINVAL;
885
886 stmpe = kzalloc(sizeof(struct stmpe), GFP_KERNEL);
887 if (!stmpe)
888 return -ENOMEM;
889
890 mutex_init(&stmpe->irq_lock);
891 mutex_init(&stmpe->lock);
892
893 stmpe->dev = &i2c->dev;
894 stmpe->i2c = i2c;
895
896 stmpe->pdata = pdata;
897 stmpe->irq_base = pdata->irq_base;
898
899 stmpe->partnum = id->driver_data;
900 stmpe->variant = stmpe_variant_info[stmpe->partnum];
901 stmpe->regs = stmpe->variant->regs;
902 stmpe->num_gpios = stmpe->variant->num_gpios;
903
904 i2c_set_clientdata(i2c, stmpe);
905
906 ret = stmpe_chip_init(stmpe);
907 if (ret)
908 goto out_free;
909
910 ret = stmpe_irq_init(stmpe);
911 if (ret)
912 goto out_free;
913
914 ret = request_threaded_irq(stmpe->i2c->irq, NULL, stmpe_irq,
915 pdata->irq_trigger | IRQF_ONESHOT,
916 "stmpe", stmpe);
917 if (ret) {
918 dev_err(stmpe->dev, "failed to request IRQ: %d\n", ret);
919 goto out_removeirq;
920 }
921
922 ret = stmpe_devices_init(stmpe);
923 if (ret) {
924 dev_err(stmpe->dev, "failed to add children\n");
925 goto out_removedevs;
926 }
927
928 return 0;
929
930out_removedevs:
931 mfd_remove_devices(stmpe->dev);
932 free_irq(stmpe->i2c->irq, stmpe);
933out_removeirq:
934 stmpe_irq_remove(stmpe);
935out_free:
936 kfree(stmpe);
937 return ret;
938}
939
940static int __devexit stmpe_remove(struct i2c_client *client)
941{
942 struct stmpe *stmpe = i2c_get_clientdata(client);
943
944 mfd_remove_devices(stmpe->dev);
945
946 free_irq(stmpe->i2c->irq, stmpe);
947 stmpe_irq_remove(stmpe);
948
949 kfree(stmpe);
950
951 return 0;
952}
953
954static const struct i2c_device_id stmpe_id[] = {
955 { "stmpe811", STMPE811 },
956 { "stmpe1601", STMPE1601 },
957 { "stmpe2401", STMPE2401 },
958 { "stmpe2403", STMPE2403 },
959 { }
960};
961MODULE_DEVICE_TABLE(i2c, stmpe_id);
962
963static struct i2c_driver stmpe_driver = {
964 .driver.name = "stmpe",
965 .driver.owner = THIS_MODULE,
966 .probe = stmpe_probe,
967 .remove = __devexit_p(stmpe_remove),
968 .id_table = stmpe_id,
969};
970
971static int __init stmpe_init(void)
972{
973 return i2c_add_driver(&stmpe_driver);
974}
975subsys_initcall(stmpe_init);
976
977static void __exit stmpe_exit(void)
978{
979 i2c_del_driver(&stmpe_driver);
980}
981module_exit(stmpe_exit);
982
983MODULE_LICENSE("GPL v2");
984MODULE_DESCRIPTION("STMPE MFD core driver");
985MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");
diff --git a/drivers/mfd/stmpe.h b/drivers/mfd/stmpe.h
new file mode 100644
index 000000000000..0dbdc4e8cd77
--- /dev/null
+++ b/drivers/mfd/stmpe.h
@@ -0,0 +1,183 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
6 */
7
8#ifndef __STMPE_H
9#define __STMPE_H
10
11#ifdef STMPE_DUMP_BYTES
12static inline void stmpe_dump_bytes(const char *str, const void *buf,
13 size_t len)
14{
15 print_hex_dump_bytes(str, DUMP_PREFIX_OFFSET, buf, len);
16}
17#else
18static inline void stmpe_dump_bytes(const char *str, const void *buf,
19 size_t len)
20{
21}
22#endif
23
24/**
25 * struct stmpe_variant_block - information about block
26 * @cell: base mfd cell
27 * @irq: interrupt number to be added to each IORESOURCE_IRQ
28 * in the cell
29 * @block: block id; used for identification with platform data and for
30 * enable and altfunc callbacks
31 */
32struct stmpe_variant_block {
33 struct mfd_cell *cell;
34 int irq;
35 enum stmpe_block block;
36};
37
38/**
39 * struct stmpe_variant_info - variant-specific information
40 * @name: part name
41 * @id_val: content of CHIPID register
42 * @id_mask: bits valid in CHIPID register for comparison with id_val
43 * @num_gpios: number of GPIOS
44 * @af_bits: number of bits used to specify the alternate function
45 * @blocks: list of blocks present on this device
46 * @num_blocks: number of blocks present on this device
47 * @num_irqs: number of internal IRQs available on this device
48 * @enable: callback to enable the specified blocks.
49 * Called with the I/O lock held.
50 * @get_altfunc: callback to get the alternate function number for the
51 * specific block
52 * @enable_autosleep: callback to configure autosleep with specified timeout
53 */
54struct stmpe_variant_info {
55 const char *name;
56 u16 id_val;
57 u16 id_mask;
58 int num_gpios;
59 int af_bits;
60 const u8 *regs;
61 struct stmpe_variant_block *blocks;
62 int num_blocks;
63 int num_irqs;
64 int (*enable)(struct stmpe *stmpe, unsigned int blocks, bool enable);
65 int (*get_altfunc)(struct stmpe *stmpe, enum stmpe_block block);
66 int (*enable_autosleep)(struct stmpe *stmpe, int autosleep_timeout);
67};
68
69#define STMPE_ICR_LSB_HIGH (1 << 2)
70#define STMPE_ICR_LSB_EDGE (1 << 1)
71#define STMPE_ICR_LSB_GIM (1 << 0)
72
73/*
74 * STMPE811
75 */
76
77#define STMPE811_IRQ_TOUCH_DET 0
78#define STMPE811_IRQ_FIFO_TH 1
79#define STMPE811_IRQ_FIFO_OFLOW 2
80#define STMPE811_IRQ_FIFO_FULL 3
81#define STMPE811_IRQ_FIFO_EMPTY 4
82#define STMPE811_IRQ_TEMP_SENS 5
83#define STMPE811_IRQ_ADC 6
84#define STMPE811_IRQ_GPIOC 7
85#define STMPE811_NR_INTERNAL_IRQS 8
86
87#define STMPE811_REG_CHIP_ID 0x00
88#define STMPE811_REG_SYS_CTRL2 0x04
89#define STMPE811_REG_INT_CTRL 0x09
90#define STMPE811_REG_INT_EN 0x0A
91#define STMPE811_REG_INT_STA 0x0B
92#define STMPE811_REG_GPIO_INT_EN 0x0C
93#define STMPE811_REG_GPIO_INT_STA 0x0D
94#define STMPE811_REG_GPIO_SET_PIN 0x10
95#define STMPE811_REG_GPIO_CLR_PIN 0x11
96#define STMPE811_REG_GPIO_MP_STA 0x12
97#define STMPE811_REG_GPIO_DIR 0x13
98#define STMPE811_REG_GPIO_ED 0x14
99#define STMPE811_REG_GPIO_RE 0x15
100#define STMPE811_REG_GPIO_FE 0x16
101#define STMPE811_REG_GPIO_AF 0x17
102
103#define STMPE811_SYS_CTRL2_ADC_OFF (1 << 0)
104#define STMPE811_SYS_CTRL2_TSC_OFF (1 << 1)
105#define STMPE811_SYS_CTRL2_GPIO_OFF (1 << 2)
106#define STMPE811_SYS_CTRL2_TS_OFF (1 << 3)
107
108/*
109 * STMPE1601
110 */
111
112#define STMPE1601_IRQ_GPIOC 8
113#define STMPE1601_IRQ_PWM3 7
114#define STMPE1601_IRQ_PWM2 6
115#define STMPE1601_IRQ_PWM1 5
116#define STMPE1601_IRQ_PWM0 4
117#define STMPE1601_IRQ_KEYPAD_OVER 2
118#define STMPE1601_IRQ_KEYPAD 1
119#define STMPE1601_IRQ_WAKEUP 0
120#define STMPE1601_NR_INTERNAL_IRQS 9
121
122#define STMPE1601_REG_SYS_CTRL 0x02
123#define STMPE1601_REG_SYS_CTRL2 0x03
124#define STMPE1601_REG_ICR_LSB 0x11
125#define STMPE1601_REG_IER_LSB 0x13
126#define STMPE1601_REG_ISR_MSB 0x14
127#define STMPE1601_REG_CHIP_ID 0x80
128#define STMPE1601_REG_INT_EN_GPIO_MASK_LSB 0x17
129#define STMPE1601_REG_INT_STA_GPIO_MSB 0x18
130#define STMPE1601_REG_GPIO_MP_LSB 0x87
131#define STMPE1601_REG_GPIO_SET_LSB 0x83
132#define STMPE1601_REG_GPIO_CLR_LSB 0x85
133#define STMPE1601_REG_GPIO_SET_DIR_LSB 0x89
134#define STMPE1601_REG_GPIO_ED_MSB 0x8A
135#define STMPE1601_REG_GPIO_RE_LSB 0x8D
136#define STMPE1601_REG_GPIO_FE_LSB 0x8F
137#define STMPE1601_REG_GPIO_AF_U_MSB 0x92
138
139#define STMPE1601_SYS_CTRL_ENABLE_GPIO (1 << 3)
140#define STMPE1601_SYS_CTRL_ENABLE_KPC (1 << 1)
141#define STMPE1601_SYSCON_ENABLE_SPWM (1 << 0)
142
143/* The 1601/2403 share the same masks */
144#define STMPE1601_AUTOSLEEP_TIMEOUT_MASK (0x7)
145#define STPME1601_AUTOSLEEP_ENABLE (1 << 3)
146
147/*
148 * STMPE24xx
149 */
150
151#define STMPE24XX_IRQ_GPIOC 8
152#define STMPE24XX_IRQ_PWM2 7
153#define STMPE24XX_IRQ_PWM1 6
154#define STMPE24XX_IRQ_PWM0 5
155#define STMPE24XX_IRQ_ROT_OVER 4
156#define STMPE24XX_IRQ_ROT 3
157#define STMPE24XX_IRQ_KEYPAD_OVER 2
158#define STMPE24XX_IRQ_KEYPAD 1
159#define STMPE24XX_IRQ_WAKEUP 0
160#define STMPE24XX_NR_INTERNAL_IRQS 9
161
162#define STMPE24XX_REG_SYS_CTRL 0x02
163#define STMPE24XX_REG_ICR_LSB 0x11
164#define STMPE24XX_REG_IER_LSB 0x13
165#define STMPE24XX_REG_ISR_MSB 0x14
166#define STMPE24XX_REG_CHIP_ID 0x80
167#define STMPE24XX_REG_IEGPIOR_LSB 0x18
168#define STMPE24XX_REG_ISGPIOR_MSB 0x19
169#define STMPE24XX_REG_GPMR_LSB 0xA5
170#define STMPE24XX_REG_GPSR_LSB 0x85
171#define STMPE24XX_REG_GPCR_LSB 0x88
172#define STMPE24XX_REG_GPDR_LSB 0x8B
173#define STMPE24XX_REG_GPEDR_MSB 0x8C
174#define STMPE24XX_REG_GPRER_LSB 0x91
175#define STMPE24XX_REG_GPFER_LSB 0x94
176#define STMPE24XX_REG_GPAFR_U_MSB 0x9B
177
178#define STMPE24XX_SYS_CTRL_ENABLE_GPIO (1 << 3)
179#define STMPE24XX_SYSCON_ENABLE_PWM (1 << 2)
180#define STMPE24XX_SYS_CTRL_ENABLE_KPC (1 << 1)
181#define STMPE24XX_SYSCON_ENABLE_ROT (1 << 0)
182
183#endif
diff --git a/drivers/mfd/t7l66xb.c b/drivers/mfd/t7l66xb.c
index 5041d33adf0b..006c121f3f0d 100644
--- a/drivers/mfd/t7l66xb.c
+++ b/drivers/mfd/t7l66xb.c
@@ -350,7 +350,6 @@ static int t7l66xb_probe(struct platform_device *dev)
350 t7l66xb->clk48m = clk_get(&dev->dev, "CLK_CK48M"); 350 t7l66xb->clk48m = clk_get(&dev->dev, "CLK_CK48M");
351 if (IS_ERR(t7l66xb->clk48m)) { 351 if (IS_ERR(t7l66xb->clk48m)) {
352 ret = PTR_ERR(t7l66xb->clk48m); 352 ret = PTR_ERR(t7l66xb->clk48m);
353 clk_put(t7l66xb->clk32k);
354 goto err_clk48m_get; 353 goto err_clk48m_get;
355 } 354 }
356 355
@@ -425,6 +424,8 @@ static int t7l66xb_remove(struct platform_device *dev)
425 ret = pdata->disable(dev); 424 ret = pdata->disable(dev);
426 clk_disable(t7l66xb->clk48m); 425 clk_disable(t7l66xb->clk48m);
427 clk_put(t7l66xb->clk48m); 426 clk_put(t7l66xb->clk48m);
427 clk_disable(t7l66xb->clk32k);
428 clk_put(t7l66xb->clk32k);
428 t7l66xb_detach_irq(dev); 429 t7l66xb_detach_irq(dev);
429 iounmap(t7l66xb->scr); 430 iounmap(t7l66xb->scr);
430 release_resource(&t7l66xb->rscr); 431 release_resource(&t7l66xb->rscr);
diff --git a/drivers/mfd/tc6387xb.c b/drivers/mfd/tc6387xb.c
index 517f9bcdeaac..6315f63f017d 100644
--- a/drivers/mfd/tc6387xb.c
+++ b/drivers/mfd/tc6387xb.c
@@ -137,7 +137,7 @@ static struct mfd_cell tc6387xb_cells[] = {
137 }, 137 },
138}; 138};
139 139
140static int tc6387xb_probe(struct platform_device *dev) 140static int __devinit tc6387xb_probe(struct platform_device *dev)
141{ 141{
142 struct tc6387xb_platform_data *pdata = dev->dev.platform_data; 142 struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
143 struct resource *iomem, *rscr; 143 struct resource *iomem, *rscr;
@@ -201,6 +201,7 @@ static int tc6387xb_probe(struct platform_device *dev)
201 if (!ret) 201 if (!ret)
202 return 0; 202 return 0;
203 203
204 iounmap(tc6387xb->scr);
204err_ioremap: 205err_ioremap:
205 release_resource(&tc6387xb->rscr); 206 release_resource(&tc6387xb->rscr);
206err_resource: 207err_resource:
@@ -211,14 +212,17 @@ err_no_irq:
211 return ret; 212 return ret;
212} 213}
213 214
214static int tc6387xb_remove(struct platform_device *dev) 215static int __devexit tc6387xb_remove(struct platform_device *dev)
215{ 216{
216 struct clk *clk32k = platform_get_drvdata(dev); 217 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
217 218
218 mfd_remove_devices(&dev->dev); 219 mfd_remove_devices(&dev->dev);
219 clk_disable(clk32k); 220 iounmap(tc6387xb->scr);
220 clk_put(clk32k); 221 release_resource(&tc6387xb->rscr);
222 clk_disable(tc6387xb->clk32k);
223 clk_put(tc6387xb->clk32k);
221 platform_set_drvdata(dev, NULL); 224 platform_set_drvdata(dev, NULL);
225 kfree(tc6387xb);
222 226
223 return 0; 227 return 0;
224} 228}
@@ -229,7 +233,7 @@ static struct platform_driver tc6387xb_platform_driver = {
229 .name = "tc6387xb", 233 .name = "tc6387xb",
230 }, 234 },
231 .probe = tc6387xb_probe, 235 .probe = tc6387xb_probe,
232 .remove = tc6387xb_remove, 236 .remove = __devexit_p(tc6387xb_remove),
233 .suspend = tc6387xb_suspend, 237 .suspend = tc6387xb_suspend,
234 .resume = tc6387xb_resume, 238 .resume = tc6387xb_resume,
235}; 239};
diff --git a/drivers/mfd/tc6393xb.c b/drivers/mfd/tc6393xb.c
index fcf9068810fb..ef6c42c8917a 100644
--- a/drivers/mfd/tc6393xb.c
+++ b/drivers/mfd/tc6393xb.c
@@ -732,9 +732,9 @@ err_gpio_add:
732 if (tc6393xb->gpio.base != -1) 732 if (tc6393xb->gpio.base != -1)
733 temp = gpiochip_remove(&tc6393xb->gpio); 733 temp = gpiochip_remove(&tc6393xb->gpio);
734 tcpd->disable(dev); 734 tcpd->disable(dev);
735err_clk_enable:
736 clk_disable(tc6393xb->clk);
737err_enable: 735err_enable:
736 clk_disable(tc6393xb->clk);
737err_clk_enable:
738 iounmap(tc6393xb->scr); 738 iounmap(tc6393xb->scr);
739err_ioremap: 739err_ioremap:
740 release_resource(&tc6393xb->rscr); 740 release_resource(&tc6393xb->rscr);
diff --git a/drivers/mfd/tps6507x.c b/drivers/mfd/tps6507x.c
index d859dffed39f..fc0197649281 100644
--- a/drivers/mfd/tps6507x.c
+++ b/drivers/mfd/tps6507x.c
@@ -89,10 +89,8 @@ static int tps6507x_i2c_probe(struct i2c_client *i2c,
89 int ret = 0; 89 int ret = 0;
90 90
91 tps6507x = kzalloc(sizeof(struct tps6507x_dev), GFP_KERNEL); 91 tps6507x = kzalloc(sizeof(struct tps6507x_dev), GFP_KERNEL);
92 if (tps6507x == NULL) { 92 if (tps6507x == NULL)
93 kfree(i2c);
94 return -ENOMEM; 93 return -ENOMEM;
95 }
96 94
97 i2c_set_clientdata(i2c, tps6507x); 95 i2c_set_clientdata(i2c, tps6507x);
98 tps6507x->dev = &i2c->dev; 96 tps6507x->dev = &i2c->dev;
diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c
new file mode 100644
index 000000000000..4cde31e6a252
--- /dev/null
+++ b/drivers/mfd/tps6586x.c
@@ -0,0 +1,375 @@
1/*
2 * Core driver for TI TPS6586x PMIC family
3 *
4 * Copyright (c) 2010 CompuLab Ltd.
5 * Mike Rapoport <mike@compulab.co.il>
6 *
7 * Based on da903x.c.
8 * Copyright (C) 2008 Compulab, Ltd.
9 * Mike Rapoport <mike@compulab.co.il>
10 * Copyright (C) 2006-2008 Marvell International Ltd.
11 * Eric Miao <eric.miao@marvell.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 */
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/mutex.h>
21#include <linux/slab.h>
22#include <linux/gpio.h>
23#include <linux/i2c.h>
24
25#include <linux/mfd/core.h>
26#include <linux/mfd/tps6586x.h>
27
28/* GPIO control registers */
29#define TPS6586X_GPIOSET1 0x5d
30#define TPS6586X_GPIOSET2 0x5e
31
32/* device id */
33#define TPS6586X_VERSIONCRC 0xcd
34#define TPS658621A_VERSIONCRC 0x15
35
36struct tps6586x {
37 struct mutex lock;
38 struct device *dev;
39 struct i2c_client *client;
40
41 struct gpio_chip gpio;
42};
43
44static inline int __tps6586x_read(struct i2c_client *client,
45 int reg, uint8_t *val)
46{
47 int ret;
48
49 ret = i2c_smbus_read_byte_data(client, reg);
50 if (ret < 0) {
51 dev_err(&client->dev, "failed reading at 0x%02x\n", reg);
52 return ret;
53 }
54
55 *val = (uint8_t)ret;
56
57 return 0;
58}
59
60static inline int __tps6586x_reads(struct i2c_client *client, int reg,
61 int len, uint8_t *val)
62{
63 int ret;
64
65 ret = i2c_smbus_read_i2c_block_data(client, reg, len, val);
66 if (ret < 0) {
67 dev_err(&client->dev, "failed reading from 0x%02x\n", reg);
68 return ret;
69 }
70
71 return 0;
72}
73
74static inline int __tps6586x_write(struct i2c_client *client,
75 int reg, uint8_t val)
76{
77 int ret;
78
79 ret = i2c_smbus_write_byte_data(client, reg, val);
80 if (ret < 0) {
81 dev_err(&client->dev, "failed writing 0x%02x to 0x%02x\n",
82 val, reg);
83 return ret;
84 }
85
86 return 0;
87}
88
89static inline int __tps6586x_writes(struct i2c_client *client, int reg,
90 int len, uint8_t *val)
91{
92 int ret;
93
94 ret = i2c_smbus_write_i2c_block_data(client, reg, len, val);
95 if (ret < 0) {
96 dev_err(&client->dev, "failed writings to 0x%02x\n", reg);
97 return ret;
98 }
99
100 return 0;
101}
102
103int tps6586x_write(struct device *dev, int reg, uint8_t val)
104{
105 return __tps6586x_write(to_i2c_client(dev), reg, val);
106}
107EXPORT_SYMBOL_GPL(tps6586x_write);
108
109int tps6586x_writes(struct device *dev, int reg, int len, uint8_t *val)
110{
111 return __tps6586x_writes(to_i2c_client(dev), reg, len, val);
112}
113EXPORT_SYMBOL_GPL(tps6586x_writes);
114
115int tps6586x_read(struct device *dev, int reg, uint8_t *val)
116{
117 return __tps6586x_read(to_i2c_client(dev), reg, val);
118}
119EXPORT_SYMBOL_GPL(tps6586x_read);
120
121int tps6586x_reads(struct device *dev, int reg, int len, uint8_t *val)
122{
123 return __tps6586x_reads(to_i2c_client(dev), reg, len, val);
124}
125EXPORT_SYMBOL_GPL(tps6586x_reads);
126
127int tps6586x_set_bits(struct device *dev, int reg, uint8_t bit_mask)
128{
129 struct tps6586x *tps6586x = dev_get_drvdata(dev);
130 uint8_t reg_val;
131 int ret = 0;
132
133 mutex_lock(&tps6586x->lock);
134
135 ret = __tps6586x_read(to_i2c_client(dev), reg, &reg_val);
136 if (ret)
137 goto out;
138
139 if ((reg_val & bit_mask) == 0) {
140 reg_val |= bit_mask;
141 ret = __tps6586x_write(to_i2c_client(dev), reg, reg_val);
142 }
143out:
144 mutex_unlock(&tps6586x->lock);
145 return ret;
146}
147EXPORT_SYMBOL_GPL(tps6586x_set_bits);
148
149int tps6586x_clr_bits(struct device *dev, int reg, uint8_t bit_mask)
150{
151 struct tps6586x *tps6586x = dev_get_drvdata(dev);
152 uint8_t reg_val;
153 int ret = 0;
154
155 mutex_lock(&tps6586x->lock);
156
157 ret = __tps6586x_read(to_i2c_client(dev), reg, &reg_val);
158 if (ret)
159 goto out;
160
161 if (reg_val & bit_mask) {
162 reg_val &= ~bit_mask;
163 ret = __tps6586x_write(to_i2c_client(dev), reg, reg_val);
164 }
165out:
166 mutex_unlock(&tps6586x->lock);
167 return ret;
168}
169EXPORT_SYMBOL_GPL(tps6586x_clr_bits);
170
171int tps6586x_update(struct device *dev, int reg, uint8_t val, uint8_t mask)
172{
173 struct tps6586x *tps6586x = dev_get_drvdata(dev);
174 uint8_t reg_val;
175 int ret = 0;
176
177 mutex_lock(&tps6586x->lock);
178
179 ret = __tps6586x_read(tps6586x->client, reg, &reg_val);
180 if (ret)
181 goto out;
182
183 if ((reg_val & mask) != val) {
184 reg_val = (reg_val & ~mask) | val;
185 ret = __tps6586x_write(tps6586x->client, reg, reg_val);
186 }
187out:
188 mutex_unlock(&tps6586x->lock);
189 return ret;
190}
191EXPORT_SYMBOL_GPL(tps6586x_update);
192
193static int tps6586x_gpio_get(struct gpio_chip *gc, unsigned offset)
194{
195 struct tps6586x *tps6586x = container_of(gc, struct tps6586x, gpio);
196 uint8_t val;
197 int ret;
198
199 ret = __tps6586x_read(tps6586x->client, TPS6586X_GPIOSET2, &val);
200 if (ret)
201 return ret;
202
203 return !!(val & (1 << offset));
204}
205
206
207static void tps6586x_gpio_set(struct gpio_chip *chip, unsigned offset,
208 int value)
209{
210 struct tps6586x *tps6586x = container_of(chip, struct tps6586x, gpio);
211
212 __tps6586x_write(tps6586x->client, TPS6586X_GPIOSET2,
213 value << offset);
214}
215
216static int tps6586x_gpio_output(struct gpio_chip *gc, unsigned offset,
217 int value)
218{
219 struct tps6586x *tps6586x = container_of(gc, struct tps6586x, gpio);
220 uint8_t val, mask;
221
222 tps6586x_gpio_set(gc, offset, value);
223
224 val = 0x1 << (offset * 2);
225 mask = 0x3 << (offset * 2);
226
227 return tps6586x_update(tps6586x->dev, TPS6586X_GPIOSET1, val, mask);
228}
229
230static void tps6586x_gpio_init(struct tps6586x *tps6586x, int gpio_base)
231{
232 int ret;
233
234 if (!gpio_base)
235 return;
236
237 tps6586x->gpio.owner = THIS_MODULE;
238 tps6586x->gpio.label = tps6586x->client->name;
239 tps6586x->gpio.dev = tps6586x->dev;
240 tps6586x->gpio.base = gpio_base;
241 tps6586x->gpio.ngpio = 4;
242 tps6586x->gpio.can_sleep = 1;
243
244 /* FIXME: add handling of GPIOs as dedicated inputs */
245 tps6586x->gpio.direction_output = tps6586x_gpio_output;
246 tps6586x->gpio.set = tps6586x_gpio_set;
247 tps6586x->gpio.get = tps6586x_gpio_get;
248
249 ret = gpiochip_add(&tps6586x->gpio);
250 if (ret)
251 dev_warn(tps6586x->dev, "GPIO registration failed: %d\n", ret);
252}
253
254static int __remove_subdev(struct device *dev, void *unused)
255{
256 platform_device_unregister(to_platform_device(dev));
257 return 0;
258}
259
260static int tps6586x_remove_subdevs(struct tps6586x *tps6586x)
261{
262 return device_for_each_child(tps6586x->dev, NULL, __remove_subdev);
263}
264
265static int __devinit tps6586x_add_subdevs(struct tps6586x *tps6586x,
266 struct tps6586x_platform_data *pdata)
267{
268 struct tps6586x_subdev_info *subdev;
269 struct platform_device *pdev;
270 int i, ret = 0;
271
272 for (i = 0; i < pdata->num_subdevs; i++) {
273 subdev = &pdata->subdevs[i];
274
275 pdev = platform_device_alloc(subdev->name, subdev->id);
276
277 pdev->dev.parent = tps6586x->dev;
278 pdev->dev.platform_data = subdev->platform_data;
279
280 ret = platform_device_add(pdev);
281 if (ret)
282 goto failed;
283 }
284 return 0;
285
286failed:
287 tps6586x_remove_subdevs(tps6586x);
288 return ret;
289}
290
291static int __devinit tps6586x_i2c_probe(struct i2c_client *client,
292 const struct i2c_device_id *id)
293{
294 struct tps6586x_platform_data *pdata = client->dev.platform_data;
295 struct tps6586x *tps6586x;
296 int ret;
297
298 if (!pdata) {
299 dev_err(&client->dev, "tps6586x requires platform data\n");
300 return -ENOTSUPP;
301 }
302
303 ret = i2c_smbus_read_byte_data(client, TPS6586X_VERSIONCRC);
304 if (ret < 0) {
305 dev_err(&client->dev, "Chip ID read failed: %d\n", ret);
306 return -EIO;
307 }
308
309 if (ret != TPS658621A_VERSIONCRC) {
310 dev_err(&client->dev, "Unsupported chip ID: %x\n", ret);
311 return -ENODEV;
312 }
313
314 tps6586x = kzalloc(sizeof(struct tps6586x), GFP_KERNEL);
315 if (tps6586x == NULL)
316 return -ENOMEM;
317
318 tps6586x->client = client;
319 tps6586x->dev = &client->dev;
320 i2c_set_clientdata(client, tps6586x);
321
322 mutex_init(&tps6586x->lock);
323
324 ret = tps6586x_add_subdevs(tps6586x, pdata);
325 if (ret) {
326 dev_err(&client->dev, "add devices failed: %d\n", ret);
327 goto err_add_devs;
328 }
329
330 tps6586x_gpio_init(tps6586x, pdata->gpio_base);
331
332 return 0;
333
334err_add_devs:
335 kfree(tps6586x);
336 return ret;
337}
338
339static int __devexit tps6586x_i2c_remove(struct i2c_client *client)
340{
341 return 0;
342}
343
344static const struct i2c_device_id tps6586x_id_table[] = {
345 { "tps6586x", 0 },
346 { },
347};
348MODULE_DEVICE_TABLE(i2c, tps6586x_id_table);
349
350static struct i2c_driver tps6586x_driver = {
351 .driver = {
352 .name = "tps6586x",
353 .owner = THIS_MODULE,
354 },
355 .probe = tps6586x_i2c_probe,
356 .remove = __devexit_p(tps6586x_i2c_remove),
357 .id_table = tps6586x_id_table,
358};
359
360static int __init tps6586x_init(void)
361{
362 return i2c_add_driver(&tps6586x_driver);
363}
364subsys_initcall(tps6586x_init);
365
366static void __exit tps6586x_exit(void)
367{
368 i2c_del_driver(&tps6586x_driver);
369}
370module_exit(tps6586x_exit);
371
372MODULE_DESCRIPTION("TPS6586X core driver");
373MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
374MODULE_LICENSE("GPL");
375
diff --git a/drivers/mfd/twl6030-pwm.c b/drivers/mfd/twl6030-pwm.c
new file mode 100644
index 000000000000..5d25bdc78424
--- /dev/null
+++ b/drivers/mfd/twl6030-pwm.c
@@ -0,0 +1,163 @@
1/*
2 * twl6030_pwm.c
3 * Driver for PHOENIX (TWL6030) Pulse Width Modulator
4 *
5 * Copyright (C) 2010 Texas Instruments
6 * Author: Hemanth V <hemanthv@ti.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 version 2 as published by
10 * the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/i2c/twl.h>
24#include <linux/slab.h>
25
26#define LED_PWM_CTRL1 0xF4
27#define LED_PWM_CTRL2 0xF5
28
29/* Max value for CTRL1 register */
30#define PWM_CTRL1_MAX 255
31
32/* Pull down disable */
33#define PWM_CTRL2_DIS_PD (1 << 6)
34
35/* Current control 2.5 milli Amps */
36#define PWM_CTRL2_CURR_02 (2 << 4)
37
38/* LED supply source */
39#define PWM_CTRL2_SRC_VAC (1 << 2)
40
41/* LED modes */
42#define PWM_CTRL2_MODE_HW (0 << 0)
43#define PWM_CTRL2_MODE_SW (1 << 0)
44#define PWM_CTRL2_MODE_DIS (2 << 0)
45
46#define PWM_CTRL2_MODE_MASK 0x3
47
48struct pwm_device {
49 const char *label;
50 unsigned int pwm_id;
51};
52
53int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
54{
55 u8 duty_cycle;
56 int ret;
57
58 if (pwm == NULL || period_ns == 0 || duty_ns > period_ns)
59 return -EINVAL;
60
61 duty_cycle = (duty_ns * PWM_CTRL1_MAX) / period_ns;
62
63 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, duty_cycle, LED_PWM_CTRL1);
64
65 if (ret < 0) {
66 pr_err("%s: Failed to configure PWM, Error %d\n",
67 pwm->label, ret);
68 return ret;
69 }
70 return 0;
71}
72EXPORT_SYMBOL(pwm_config);
73
74int pwm_enable(struct pwm_device *pwm)
75{
76 u8 val;
77 int ret;
78
79 ret = twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, LED_PWM_CTRL2);
80 if (ret < 0) {
81 pr_err("%s: Failed to enable PWM, Error %d\n", pwm->label, ret);
82 return ret;
83 }
84
85 /* Change mode to software control */
86 val &= ~PWM_CTRL2_MODE_MASK;
87 val |= PWM_CTRL2_MODE_SW;
88
89 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, LED_PWM_CTRL2);
90 if (ret < 0) {
91 pr_err("%s: Failed to enable PWM, Error %d\n", pwm->label, ret);
92 return ret;
93 }
94
95 twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, LED_PWM_CTRL2);
96 return 0;
97}
98EXPORT_SYMBOL(pwm_enable);
99
100void pwm_disable(struct pwm_device *pwm)
101{
102 u8 val;
103 int ret;
104
105 ret = twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, LED_PWM_CTRL2);
106 if (ret < 0) {
107 pr_err("%s: Failed to disable PWM, Error %d\n",
108 pwm->label, ret);
109 return;
110 }
111
112 val &= ~PWM_CTRL2_MODE_MASK;
113 val |= PWM_CTRL2_MODE_HW;
114
115 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, LED_PWM_CTRL2);
116 if (ret < 0) {
117 pr_err("%s: Failed to disable PWM, Error %d\n",
118 pwm->label, ret);
119 return;
120 }
121 return;
122}
123EXPORT_SYMBOL(pwm_disable);
124
125struct pwm_device *pwm_request(int pwm_id, const char *label)
126{
127 u8 val;
128 int ret;
129 struct pwm_device *pwm;
130
131 pwm = kzalloc(sizeof(struct pwm_device), GFP_KERNEL);
132 if (pwm == NULL) {
133 pr_err("%s: failed to allocate memory\n", label);
134 return NULL;
135 }
136
137 pwm->label = label;
138 pwm->pwm_id = pwm_id;
139
140 /* Configure PWM */
141 val = PWM_CTRL2_DIS_PD | PWM_CTRL2_CURR_02 | PWM_CTRL2_SRC_VAC |
142 PWM_CTRL2_MODE_HW;
143
144 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, LED_PWM_CTRL2);
145
146 if (ret < 0) {
147 pr_err("%s: Failed to configure PWM, Error %d\n",
148 pwm->label, ret);
149
150 kfree(pwm);
151 return NULL;
152 }
153
154 return pwm;
155}
156EXPORT_SYMBOL(pwm_request);
157
158void pwm_free(struct pwm_device *pwm)
159{
160 pwm_disable(pwm);
161 kfree(pwm);
162}
163EXPORT_SYMBOL(pwm_free);
diff --git a/drivers/mfd/ucb1400_core.c b/drivers/mfd/ucb1400_core.c
index dbe280153f9e..d73f84ba0f08 100644
--- a/drivers/mfd/ucb1400_core.c
+++ b/drivers/mfd/ucb1400_core.c
@@ -114,7 +114,7 @@ static int ucb1400_core_probe(struct device *dev)
114err3: 114err3:
115 platform_device_put(ucb->ucb1400_ts); 115 platform_device_put(ucb->ucb1400_ts);
116err2: 116err2:
117 platform_device_unregister(ucb->ucb1400_gpio); 117 platform_device_del(ucb->ucb1400_gpio);
118err1: 118err1:
119 platform_device_put(ucb->ucb1400_gpio); 119 platform_device_put(ucb->ucb1400_gpio);
120err0: 120err0:
diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c
index 1a968f34d679..1e7aaaf6cc6f 100644
--- a/drivers/mfd/wm831x-core.c
+++ b/drivers/mfd/wm831x-core.c
@@ -95,6 +95,7 @@ enum wm831x_parent {
95 WM8311 = 0x8311, 95 WM8311 = 0x8311,
96 WM8312 = 0x8312, 96 WM8312 = 0x8312,
97 WM8320 = 0x8320, 97 WM8320 = 0x8320,
98 WM8321 = 0x8321,
98}; 99};
99 100
100static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg) 101static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg)
@@ -1533,6 +1534,12 @@ static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1533 dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev); 1534 dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev);
1534 break; 1535 break;
1535 1536
1537 case WM8321:
1538 parent = WM8321;
1539 wm831x->num_gpio = 12;
1540 dev_info(wm831x->dev, "WM8321 revision %c\n", 'A' + rev);
1541 break;
1542
1536 default: 1543 default:
1537 dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret); 1544 dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
1538 ret = -EINVAL; 1545 ret = -EINVAL;
@@ -1607,6 +1614,12 @@ static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1607 NULL, 0); 1614 NULL, 0);
1608 break; 1615 break;
1609 1616
1617 case WM8321:
1618 ret = mfd_add_devices(wm831x->dev, -1,
1619 wm8320_devs, ARRAY_SIZE(wm8320_devs),
1620 NULL, 0);
1621 break;
1622
1610 default: 1623 default:
1611 /* If this happens the bus probe function is buggy */ 1624 /* If this happens the bus probe function is buggy */
1612 BUG(); 1625 BUG();
@@ -1744,10 +1757,8 @@ static int wm831x_i2c_probe(struct i2c_client *i2c,
1744 struct wm831x *wm831x; 1757 struct wm831x *wm831x;
1745 1758
1746 wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); 1759 wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL);
1747 if (wm831x == NULL) { 1760 if (wm831x == NULL)
1748 kfree(i2c);
1749 return -ENOMEM; 1761 return -ENOMEM;
1750 }
1751 1762
1752 i2c_set_clientdata(i2c, wm831x); 1763 i2c_set_clientdata(i2c, wm831x);
1753 wm831x->dev = &i2c->dev; 1764 wm831x->dev = &i2c->dev;
@@ -1779,6 +1790,7 @@ static const struct i2c_device_id wm831x_i2c_id[] = {
1779 { "wm8311", WM8311 }, 1790 { "wm8311", WM8311 },
1780 { "wm8312", WM8312 }, 1791 { "wm8312", WM8312 },
1781 { "wm8320", WM8320 }, 1792 { "wm8320", WM8320 },
1793 { "wm8321", WM8321 },
1782 { } 1794 { }
1783}; 1795};
1784MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id); 1796MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id);
diff --git a/drivers/mfd/wm8350-core.c b/drivers/mfd/wm8350-core.c
index b5807484b4c9..e81cc31e4202 100644
--- a/drivers/mfd/wm8350-core.c
+++ b/drivers/mfd/wm8350-core.c
@@ -536,6 +536,7 @@ static int wm8350_create_cache(struct wm8350 *wm8350, int type, int mode)
536 } 536 }
537 537
538out: 538out:
539 kfree(wm8350->reg_cache);
539 return ret; 540 return ret;
540} 541}
541 542
@@ -700,7 +701,7 @@ int wm8350_device_init(struct wm8350 *wm8350, int irq,
700 701
701 ret = wm8350_irq_init(wm8350, irq, pdata); 702 ret = wm8350_irq_init(wm8350, irq, pdata);
702 if (ret < 0) 703 if (ret < 0)
703 goto err; 704 goto err_free;
704 705
705 if (wm8350->irq_base) { 706 if (wm8350->irq_base) {
706 ret = request_threaded_irq(wm8350->irq_base + 707 ret = request_threaded_irq(wm8350->irq_base +
@@ -738,8 +739,9 @@ int wm8350_device_init(struct wm8350 *wm8350, int irq,
738 739
739err_irq: 740err_irq:
740 wm8350_irq_exit(wm8350); 741 wm8350_irq_exit(wm8350);
741err: 742err_free:
742 kfree(wm8350->reg_cache); 743 kfree(wm8350->reg_cache);
744err:
743 return ret; 745 return ret;
744} 746}
745EXPORT_SYMBOL_GPL(wm8350_device_init); 747EXPORT_SYMBOL_GPL(wm8350_device_init);
diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c
index ec71c9368906..b3b2aaf89dbe 100644
--- a/drivers/mfd/wm8994-core.c
+++ b/drivers/mfd/wm8994-core.c
@@ -326,8 +326,10 @@ static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq)
326 wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) * 326 wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) *
327 ARRAY_SIZE(wm8994_main_supplies), 327 ARRAY_SIZE(wm8994_main_supplies),
328 GFP_KERNEL); 328 GFP_KERNEL);
329 if (!wm8994->supplies) 329 if (!wm8994->supplies) {
330 ret = -ENOMEM;
330 goto err; 331 goto err;
332 }
331 333
332 for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++) 334 for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++)
333 wm8994->supplies[i].supply = wm8994_main_supplies[i]; 335 wm8994->supplies[i].supply = wm8994_main_supplies[i];
@@ -495,10 +497,8 @@ static int wm8994_i2c_probe(struct i2c_client *i2c,
495 struct wm8994 *wm8994; 497 struct wm8994 *wm8994;
496 498
497 wm8994 = kzalloc(sizeof(struct wm8994), GFP_KERNEL); 499 wm8994 = kzalloc(sizeof(struct wm8994), GFP_KERNEL);
498 if (wm8994 == NULL) { 500 if (wm8994 == NULL)
499 kfree(i2c);
500 return -ENOMEM; 501 return -ENOMEM;
501 }
502 502
503 i2c_set_clientdata(i2c, wm8994); 503 i2c_set_clientdata(i2c, wm8994);
504 wm8994->dev = &i2c->dev; 504 wm8994->dev = &i2c->dev;
diff --git a/drivers/misc/cs5535-mfgpt.c b/drivers/misc/cs5535-mfgpt.c
index 2d44b3300104..6f6218061b0d 100644
--- a/drivers/misc/cs5535-mfgpt.c
+++ b/drivers/misc/cs5535-mfgpt.c
@@ -211,6 +211,17 @@ EXPORT_SYMBOL_GPL(cs5535_mfgpt_alloc_timer);
211 */ 211 */
212void cs5535_mfgpt_free_timer(struct cs5535_mfgpt_timer *timer) 212void cs5535_mfgpt_free_timer(struct cs5535_mfgpt_timer *timer)
213{ 213{
214 unsigned long flags;
215 uint16_t val;
216
217 /* timer can be made available again only if never set up */
218 val = cs5535_mfgpt_read(timer, MFGPT_REG_SETUP);
219 if (!(val & MFGPT_SETUP_SETUP)) {
220 spin_lock_irqsave(&timer->chip->lock, flags);
221 __set_bit(timer->nr, timer->chip->avail);
222 spin_unlock_irqrestore(&timer->chip->lock, flags);
223 }
224
214 kfree(timer); 225 kfree(timer);
215} 226}
216EXPORT_SYMBOL_GPL(cs5535_mfgpt_free_timer); 227EXPORT_SYMBOL_GPL(cs5535_mfgpt_free_timer);
diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
index 5bfb2a2041b8..ef34de7a8026 100644
--- a/drivers/misc/lkdtm.c
+++ b/drivers/misc/lkdtm.c
@@ -124,9 +124,9 @@ static int count = DEFAULT_COUNT;
124module_param(recur_count, int, 0644); 124module_param(recur_count, int, 0644);
125MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test, "\ 125MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test, "\
126 "default is 10"); 126 "default is 10");
127module_param(cpoint_name, charp, 0644); 127module_param(cpoint_name, charp, 0444);
128MODULE_PARM_DESC(cpoint_name, " Crash Point, where kernel is to be crashed"); 128MODULE_PARM_DESC(cpoint_name, " Crash Point, where kernel is to be crashed");
129module_param(cpoint_type, charp, 0644); 129module_param(cpoint_type, charp, 0444);
130MODULE_PARM_DESC(cpoint_type, " Crash Point Type, action to be taken on "\ 130MODULE_PARM_DESC(cpoint_type, " Crash Point Type, action to be taken on "\
131 "hitting the crash point"); 131 "hitting the crash point");
132module_param(cpoint_count, int, 0644); 132module_param(cpoint_count, int, 0644);
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 8433cde29c8b..d545f79f6000 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -247,7 +247,76 @@ static u32 get_card_status(struct mmc_card *card, struct request *req)
247 return cmd.resp[0]; 247 return cmd.resp[0];
248} 248}
249 249
250static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) 250static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
251{
252 struct mmc_blk_data *md = mq->data;
253 struct mmc_card *card = md->queue.card;
254 unsigned int from, nr, arg;
255 int err = 0;
256
257 mmc_claim_host(card->host);
258
259 if (!mmc_can_erase(card)) {
260 err = -EOPNOTSUPP;
261 goto out;
262 }
263
264 from = blk_rq_pos(req);
265 nr = blk_rq_sectors(req);
266
267 if (mmc_can_trim(card))
268 arg = MMC_TRIM_ARG;
269 else
270 arg = MMC_ERASE_ARG;
271
272 err = mmc_erase(card, from, nr, arg);
273out:
274 spin_lock_irq(&md->lock);
275 __blk_end_request(req, err, blk_rq_bytes(req));
276 spin_unlock_irq(&md->lock);
277
278 mmc_release_host(card->host);
279
280 return err ? 0 : 1;
281}
282
283static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
284 struct request *req)
285{
286 struct mmc_blk_data *md = mq->data;
287 struct mmc_card *card = md->queue.card;
288 unsigned int from, nr, arg;
289 int err = 0;
290
291 mmc_claim_host(card->host);
292
293 if (!mmc_can_secure_erase_trim(card)) {
294 err = -EOPNOTSUPP;
295 goto out;
296 }
297
298 from = blk_rq_pos(req);
299 nr = blk_rq_sectors(req);
300
301 if (mmc_can_trim(card) && !mmc_erase_group_aligned(card, from, nr))
302 arg = MMC_SECURE_TRIM1_ARG;
303 else
304 arg = MMC_SECURE_ERASE_ARG;
305
306 err = mmc_erase(card, from, nr, arg);
307 if (!err && arg == MMC_SECURE_TRIM1_ARG)
308 err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG);
309out:
310 spin_lock_irq(&md->lock);
311 __blk_end_request(req, err, blk_rq_bytes(req));
312 spin_unlock_irq(&md->lock);
313
314 mmc_release_host(card->host);
315
316 return err ? 0 : 1;
317}
318
319static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
251{ 320{
252 struct mmc_blk_data *md = mq->data; 321 struct mmc_blk_data *md = mq->data;
253 struct mmc_card *card = md->queue.card; 322 struct mmc_card *card = md->queue.card;
@@ -475,6 +544,17 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
475 return 0; 544 return 0;
476} 545}
477 546
547static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
548{
549 if (req->cmd_flags & REQ_DISCARD) {
550 if (req->cmd_flags & REQ_SECURE)
551 return mmc_blk_issue_secdiscard_rq(mq, req);
552 else
553 return mmc_blk_issue_discard_rq(mq, req);
554 } else {
555 return mmc_blk_issue_rw_rq(mq, req);
556 }
557}
478 558
479static inline int mmc_blk_readonly(struct mmc_card *card) 559static inline int mmc_blk_readonly(struct mmc_card *card)
480{ 560{
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
index 445d7db2277e..5dd8576b5c18 100644
--- a/drivers/mmc/card/mmc_test.c
+++ b/drivers/mmc/card/mmc_test.c
@@ -16,6 +16,7 @@
16#include <linux/slab.h> 16#include <linux/slab.h>
17 17
18#include <linux/scatterlist.h> 18#include <linux/scatterlist.h>
19#include <linux/swap.h> /* For nr_free_buffer_pages() */
19 20
20#define RESULT_OK 0 21#define RESULT_OK 0
21#define RESULT_FAIL 1 22#define RESULT_FAIL 1
@@ -25,6 +26,60 @@
25#define BUFFER_ORDER 2 26#define BUFFER_ORDER 2
26#define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER) 27#define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER)
27 28
29/*
30 * Limit the test area size to the maximum MMC HC erase group size. Note that
31 * the maximum SD allocation unit size is just 4MiB.
32 */
33#define TEST_AREA_MAX_SIZE (128 * 1024 * 1024)
34
35/**
36 * struct mmc_test_pages - pages allocated by 'alloc_pages()'.
37 * @page: first page in the allocation
38 * @order: order of the number of pages allocated
39 */
40struct mmc_test_pages {
41 struct page *page;
42 unsigned int order;
43};
44
45/**
46 * struct mmc_test_mem - allocated memory.
47 * @arr: array of allocations
48 * @cnt: number of allocations
49 */
50struct mmc_test_mem {
51 struct mmc_test_pages *arr;
52 unsigned int cnt;
53};
54
55/**
56 * struct mmc_test_area - information for performance tests.
57 * @max_sz: test area size (in bytes)
58 * @dev_addr: address on card at which to do performance tests
59 * @max_segs: maximum segments in scatterlist @sg
60 * @blocks: number of (512 byte) blocks currently mapped by @sg
61 * @sg_len: length of currently mapped scatterlist @sg
62 * @mem: allocated memory
63 * @sg: scatterlist
64 */
65struct mmc_test_area {
66 unsigned long max_sz;
67 unsigned int dev_addr;
68 unsigned int max_segs;
69 unsigned int blocks;
70 unsigned int sg_len;
71 struct mmc_test_mem *mem;
72 struct scatterlist *sg;
73};
74
75/**
76 * struct mmc_test_card - test information.
77 * @card: card under test
78 * @scratch: transfer buffer
79 * @buffer: transfer buffer
80 * @highmem: buffer for highmem tests
81 * @area: information for performance tests
82 */
28struct mmc_test_card { 83struct mmc_test_card {
29 struct mmc_card *card; 84 struct mmc_card *card;
30 85
@@ -33,6 +88,7 @@ struct mmc_test_card {
33#ifdef CONFIG_HIGHMEM 88#ifdef CONFIG_HIGHMEM
34 struct page *highmem; 89 struct page *highmem;
35#endif 90#endif
91 struct mmc_test_area area;
36}; 92};
37 93
38/*******************************************************************/ 94/*******************************************************************/
@@ -97,6 +153,12 @@ static void mmc_test_prepare_mrq(struct mmc_test_card *test,
97 mmc_set_data_timeout(mrq->data, test->card); 153 mmc_set_data_timeout(mrq->data, test->card);
98} 154}
99 155
156static int mmc_test_busy(struct mmc_command *cmd)
157{
158 return !(cmd->resp[0] & R1_READY_FOR_DATA) ||
159 (R1_CURRENT_STATE(cmd->resp[0]) == 7);
160}
161
100/* 162/*
101 * Wait for the card to finish the busy state 163 * Wait for the card to finish the busy state
102 */ 164 */
@@ -117,13 +179,13 @@ static int mmc_test_wait_busy(struct mmc_test_card *test)
117 if (ret) 179 if (ret)
118 break; 180 break;
119 181
120 if (!busy && !(cmd.resp[0] & R1_READY_FOR_DATA)) { 182 if (!busy && mmc_test_busy(&cmd)) {
121 busy = 1; 183 busy = 1;
122 printk(KERN_INFO "%s: Warning: Host did not " 184 printk(KERN_INFO "%s: Warning: Host did not "
123 "wait for busy state to end.\n", 185 "wait for busy state to end.\n",
124 mmc_hostname(test->card->host)); 186 mmc_hostname(test->card->host));
125 } 187 }
126 } while (!(cmd.resp[0] & R1_READY_FOR_DATA)); 188 } while (mmc_test_busy(&cmd));
127 189
128 return ret; 190 return ret;
129} 191}
@@ -170,6 +232,248 @@ static int mmc_test_buffer_transfer(struct mmc_test_card *test,
170 return 0; 232 return 0;
171} 233}
172 234
235static void mmc_test_free_mem(struct mmc_test_mem *mem)
236{
237 if (!mem)
238 return;
239 while (mem->cnt--)
240 __free_pages(mem->arr[mem->cnt].page,
241 mem->arr[mem->cnt].order);
242 kfree(mem->arr);
243 kfree(mem);
244}
245
246/*
247 * Allocate a lot of memory, preferrably max_sz but at least min_sz. In case
248 * there isn't much memory do not exceed 1/16th total lowmem pages.
249 */
250static struct mmc_test_mem *mmc_test_alloc_mem(unsigned long min_sz,
251 unsigned long max_sz)
252{
253 unsigned long max_page_cnt = DIV_ROUND_UP(max_sz, PAGE_SIZE);
254 unsigned long min_page_cnt = DIV_ROUND_UP(min_sz, PAGE_SIZE);
255 unsigned long page_cnt = 0;
256 unsigned long limit = nr_free_buffer_pages() >> 4;
257 struct mmc_test_mem *mem;
258
259 if (max_page_cnt > limit)
260 max_page_cnt = limit;
261 if (max_page_cnt < min_page_cnt)
262 max_page_cnt = min_page_cnt;
263
264 mem = kzalloc(sizeof(struct mmc_test_mem), GFP_KERNEL);
265 if (!mem)
266 return NULL;
267
268 mem->arr = kzalloc(sizeof(struct mmc_test_pages) * max_page_cnt,
269 GFP_KERNEL);
270 if (!mem->arr)
271 goto out_free;
272
273 while (max_page_cnt) {
274 struct page *page;
275 unsigned int order;
276 gfp_t flags = GFP_KERNEL | GFP_DMA | __GFP_NOWARN |
277 __GFP_NORETRY;
278
279 order = get_order(max_page_cnt << PAGE_SHIFT);
280 while (1) {
281 page = alloc_pages(flags, order);
282 if (page || !order)
283 break;
284 order -= 1;
285 }
286 if (!page) {
287 if (page_cnt < min_page_cnt)
288 goto out_free;
289 break;
290 }
291 mem->arr[mem->cnt].page = page;
292 mem->arr[mem->cnt].order = order;
293 mem->cnt += 1;
294 if (max_page_cnt <= (1UL << order))
295 break;
296 max_page_cnt -= 1UL << order;
297 page_cnt += 1UL << order;
298 }
299
300 return mem;
301
302out_free:
303 mmc_test_free_mem(mem);
304 return NULL;
305}
306
307/*
308 * Map memory into a scatterlist. Optionally allow the same memory to be
309 * mapped more than once.
310 */
311static int mmc_test_map_sg(struct mmc_test_mem *mem, unsigned long sz,
312 struct scatterlist *sglist, int repeat,
313 unsigned int max_segs, unsigned int *sg_len)
314{
315 struct scatterlist *sg = NULL;
316 unsigned int i;
317
318 sg_init_table(sglist, max_segs);
319
320 *sg_len = 0;
321 do {
322 for (i = 0; i < mem->cnt; i++) {
323 unsigned long len = PAGE_SIZE << mem->arr[i].order;
324
325 if (sz < len)
326 len = sz;
327 if (sg)
328 sg = sg_next(sg);
329 else
330 sg = sglist;
331 if (!sg)
332 return -EINVAL;
333 sg_set_page(sg, mem->arr[i].page, len, 0);
334 sz -= len;
335 *sg_len += 1;
336 if (!sz)
337 break;
338 }
339 } while (sz && repeat);
340
341 if (sz)
342 return -EINVAL;
343
344 if (sg)
345 sg_mark_end(sg);
346
347 return 0;
348}
349
350/*
351 * Map memory into a scatterlist so that no pages are contiguous. Allow the
352 * same memory to be mapped more than once.
353 */
354static int mmc_test_map_sg_max_scatter(struct mmc_test_mem *mem,
355 unsigned long sz,
356 struct scatterlist *sglist,
357 unsigned int max_segs,
358 unsigned int *sg_len)
359{
360 struct scatterlist *sg = NULL;
361 unsigned int i = mem->cnt, cnt;
362 unsigned long len;
363 void *base, *addr, *last_addr = NULL;
364
365 sg_init_table(sglist, max_segs);
366
367 *sg_len = 0;
368 while (sz && i) {
369 base = page_address(mem->arr[--i].page);
370 cnt = 1 << mem->arr[i].order;
371 while (sz && cnt) {
372 addr = base + PAGE_SIZE * --cnt;
373 if (last_addr && last_addr + PAGE_SIZE == addr)
374 continue;
375 last_addr = addr;
376 len = PAGE_SIZE;
377 if (sz < len)
378 len = sz;
379 if (sg)
380 sg = sg_next(sg);
381 else
382 sg = sglist;
383 if (!sg)
384 return -EINVAL;
385 sg_set_page(sg, virt_to_page(addr), len, 0);
386 sz -= len;
387 *sg_len += 1;
388 }
389 }
390
391 if (sg)
392 sg_mark_end(sg);
393
394 return 0;
395}
396
397/*
398 * Calculate transfer rate in bytes per second.
399 */
400static unsigned int mmc_test_rate(uint64_t bytes, struct timespec *ts)
401{
402 uint64_t ns;
403
404 ns = ts->tv_sec;
405 ns *= 1000000000;
406 ns += ts->tv_nsec;
407
408 bytes *= 1000000000;
409
410 while (ns > UINT_MAX) {
411 bytes >>= 1;
412 ns >>= 1;
413 }
414
415 if (!ns)
416 return 0;
417
418 do_div(bytes, (uint32_t)ns);
419
420 return bytes;
421}
422
423/*
424 * Print the transfer rate.
425 */
426static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes,
427 struct timespec *ts1, struct timespec *ts2)
428{
429 unsigned int rate, sectors = bytes >> 9;
430 struct timespec ts;
431
432 ts = timespec_sub(*ts2, *ts1);
433
434 rate = mmc_test_rate(bytes, &ts);
435
436 printk(KERN_INFO "%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
437 "seconds (%u kB/s, %u KiB/s)\n",
438 mmc_hostname(test->card->host), sectors, sectors >> 1,
439 (sectors == 1 ? ".5" : ""), (unsigned long)ts.tv_sec,
440 (unsigned long)ts.tv_nsec, rate / 1000, rate / 1024);
441}
442
443/*
444 * Print the average transfer rate.
445 */
446static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes,
447 unsigned int count, struct timespec *ts1,
448 struct timespec *ts2)
449{
450 unsigned int rate, sectors = bytes >> 9;
451 uint64_t tot = bytes * count;
452 struct timespec ts;
453
454 ts = timespec_sub(*ts2, *ts1);
455
456 rate = mmc_test_rate(tot, &ts);
457
458 printk(KERN_INFO "%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
459 "%lu.%09lu seconds (%u kB/s, %u KiB/s)\n",
460 mmc_hostname(test->card->host), count, sectors, count,
461 sectors >> 1, (sectors == 1 ? ".5" : ""),
462 (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec,
463 rate / 1000, rate / 1024);
464}
465
466/*
467 * Return the card size in sectors.
468 */
469static unsigned int mmc_test_capacity(struct mmc_card *card)
470{
471 if (!mmc_card_sd(card) && mmc_card_blockaddr(card))
472 return card->ext_csd.sectors;
473 else
474 return card->csd.capacity << (card->csd.read_blkbits - 9);
475}
476
173/*******************************************************************/ 477/*******************************************************************/
174/* Test preparation and cleanup */ 478/* Test preparation and cleanup */
175/*******************************************************************/ 479/*******************************************************************/
@@ -893,8 +1197,419 @@ static int mmc_test_multi_read_high(struct mmc_test_card *test)
893 return 0; 1197 return 0;
894} 1198}
895 1199
1200#else
1201
1202static int mmc_test_no_highmem(struct mmc_test_card *test)
1203{
1204 printk(KERN_INFO "%s: Highmem not configured - test skipped\n",
1205 mmc_hostname(test->card->host));
1206 return 0;
1207}
1208
896#endif /* CONFIG_HIGHMEM */ 1209#endif /* CONFIG_HIGHMEM */
897 1210
1211/*
1212 * Map sz bytes so that it can be transferred.
1213 */
1214static int mmc_test_area_map(struct mmc_test_card *test, unsigned long sz,
1215 int max_scatter)
1216{
1217 struct mmc_test_area *t = &test->area;
1218
1219 t->blocks = sz >> 9;
1220
1221 if (max_scatter) {
1222 return mmc_test_map_sg_max_scatter(t->mem, sz, t->sg,
1223 t->max_segs, &t->sg_len);
1224 } else {
1225 return mmc_test_map_sg(t->mem, sz, t->sg, 1, t->max_segs,
1226 &t->sg_len);
1227 }
1228}
1229
1230/*
1231 * Transfer bytes mapped by mmc_test_area_map().
1232 */
1233static int mmc_test_area_transfer(struct mmc_test_card *test,
1234 unsigned int dev_addr, int write)
1235{
1236 struct mmc_test_area *t = &test->area;
1237
1238 return mmc_test_simple_transfer(test, t->sg, t->sg_len, dev_addr,
1239 t->blocks, 512, write);
1240}
1241
1242/*
1243 * Map and transfer bytes.
1244 */
1245static int mmc_test_area_io(struct mmc_test_card *test, unsigned long sz,
1246 unsigned int dev_addr, int write, int max_scatter,
1247 int timed)
1248{
1249 struct timespec ts1, ts2;
1250 int ret;
1251
1252 ret = mmc_test_area_map(test, sz, max_scatter);
1253 if (ret)
1254 return ret;
1255
1256 if (timed)
1257 getnstimeofday(&ts1);
1258
1259 ret = mmc_test_area_transfer(test, dev_addr, write);
1260 if (ret)
1261 return ret;
1262
1263 if (timed)
1264 getnstimeofday(&ts2);
1265
1266 if (timed)
1267 mmc_test_print_rate(test, sz, &ts1, &ts2);
1268
1269 return 0;
1270}
1271
1272/*
1273 * Write the test area entirely.
1274 */
1275static int mmc_test_area_fill(struct mmc_test_card *test)
1276{
1277 return mmc_test_area_io(test, test->area.max_sz, test->area.dev_addr,
1278 1, 0, 0);
1279}
1280
1281/*
1282 * Erase the test area entirely.
1283 */
1284static int mmc_test_area_erase(struct mmc_test_card *test)
1285{
1286 struct mmc_test_area *t = &test->area;
1287
1288 if (!mmc_can_erase(test->card))
1289 return 0;
1290
1291 return mmc_erase(test->card, t->dev_addr, test->area.max_sz >> 9,
1292 MMC_ERASE_ARG);
1293}
1294
1295/*
1296 * Cleanup struct mmc_test_area.
1297 */
1298static int mmc_test_area_cleanup(struct mmc_test_card *test)
1299{
1300 struct mmc_test_area *t = &test->area;
1301
1302 kfree(t->sg);
1303 mmc_test_free_mem(t->mem);
1304
1305 return 0;
1306}
1307
1308/*
1309 * Initialize an area for testing large transfers. The size of the area is the
1310 * preferred erase size which is a good size for optimal transfer speed. Note
1311 * that is typically 4MiB for modern cards. The test area is set to the middle
1312 * of the card because cards may have different charateristics at the front
1313 * (for FAT file system optimization). Optionally, the area is erased (if the
1314 * card supports it) which may improve write performance. Optionally, the area
1315 * is filled with data for subsequent read tests.
1316 */
1317static int mmc_test_area_init(struct mmc_test_card *test, int erase, int fill)
1318{
1319 struct mmc_test_area *t = &test->area;
1320 unsigned long min_sz = 64 * 1024;
1321 int ret;
1322
1323 ret = mmc_test_set_blksize(test, 512);
1324 if (ret)
1325 return ret;
1326
1327 if (test->card->pref_erase > TEST_AREA_MAX_SIZE >> 9)
1328 t->max_sz = TEST_AREA_MAX_SIZE;
1329 else
1330 t->max_sz = (unsigned long)test->card->pref_erase << 9;
1331 /*
1332 * Try to allocate enough memory for the whole area. Less is OK
1333 * because the same memory can be mapped into the scatterlist more than
1334 * once.
1335 */
1336 t->mem = mmc_test_alloc_mem(min_sz, t->max_sz);
1337 if (!t->mem)
1338 return -ENOMEM;
1339
1340 t->max_segs = DIV_ROUND_UP(t->max_sz, PAGE_SIZE);
1341 t->sg = kmalloc(sizeof(struct scatterlist) * t->max_segs, GFP_KERNEL);
1342 if (!t->sg) {
1343 ret = -ENOMEM;
1344 goto out_free;
1345 }
1346
1347 t->dev_addr = mmc_test_capacity(test->card) / 2;
1348 t->dev_addr -= t->dev_addr % (t->max_sz >> 9);
1349
1350 if (erase) {
1351 ret = mmc_test_area_erase(test);
1352 if (ret)
1353 goto out_free;
1354 }
1355
1356 if (fill) {
1357 ret = mmc_test_area_fill(test);
1358 if (ret)
1359 goto out_free;
1360 }
1361
1362 return 0;
1363
1364out_free:
1365 mmc_test_area_cleanup(test);
1366 return ret;
1367}
1368
1369/*
1370 * Prepare for large transfers. Do not erase the test area.
1371 */
1372static int mmc_test_area_prepare(struct mmc_test_card *test)
1373{
1374 return mmc_test_area_init(test, 0, 0);
1375}
1376
1377/*
1378 * Prepare for large transfers. Do erase the test area.
1379 */
1380static int mmc_test_area_prepare_erase(struct mmc_test_card *test)
1381{
1382 return mmc_test_area_init(test, 1, 0);
1383}
1384
1385/*
1386 * Prepare for large transfers. Erase and fill the test area.
1387 */
1388static int mmc_test_area_prepare_fill(struct mmc_test_card *test)
1389{
1390 return mmc_test_area_init(test, 1, 1);
1391}
1392
1393/*
1394 * Test best-case performance. Best-case performance is expected from
1395 * a single large transfer.
1396 *
1397 * An additional option (max_scatter) allows the measurement of the same
1398 * transfer but with no contiguous pages in the scatter list. This tests
1399 * the efficiency of DMA to handle scattered pages.
1400 */
1401static int mmc_test_best_performance(struct mmc_test_card *test, int write,
1402 int max_scatter)
1403{
1404 return mmc_test_area_io(test, test->area.max_sz, test->area.dev_addr,
1405 write, max_scatter, 1);
1406}
1407
1408/*
1409 * Best-case read performance.
1410 */
1411static int mmc_test_best_read_performance(struct mmc_test_card *test)
1412{
1413 return mmc_test_best_performance(test, 0, 0);
1414}
1415
1416/*
1417 * Best-case write performance.
1418 */
1419static int mmc_test_best_write_performance(struct mmc_test_card *test)
1420{
1421 return mmc_test_best_performance(test, 1, 0);
1422}
1423
1424/*
1425 * Best-case read performance into scattered pages.
1426 */
1427static int mmc_test_best_read_perf_max_scatter(struct mmc_test_card *test)
1428{
1429 return mmc_test_best_performance(test, 0, 1);
1430}
1431
1432/*
1433 * Best-case write performance from scattered pages.
1434 */
1435static int mmc_test_best_write_perf_max_scatter(struct mmc_test_card *test)
1436{
1437 return mmc_test_best_performance(test, 1, 1);
1438}
1439
1440/*
1441 * Single read performance by transfer size.
1442 */
1443static int mmc_test_profile_read_perf(struct mmc_test_card *test)
1444{
1445 unsigned long sz;
1446 unsigned int dev_addr;
1447 int ret;
1448
1449 for (sz = 512; sz < test->area.max_sz; sz <<= 1) {
1450 dev_addr = test->area.dev_addr + (sz >> 9);
1451 ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
1452 if (ret)
1453 return ret;
1454 }
1455 dev_addr = test->area.dev_addr;
1456 return mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
1457}
1458
1459/*
1460 * Single write performance by transfer size.
1461 */
1462static int mmc_test_profile_write_perf(struct mmc_test_card *test)
1463{
1464 unsigned long sz;
1465 unsigned int dev_addr;
1466 int ret;
1467
1468 ret = mmc_test_area_erase(test);
1469 if (ret)
1470 return ret;
1471 for (sz = 512; sz < test->area.max_sz; sz <<= 1) {
1472 dev_addr = test->area.dev_addr + (sz >> 9);
1473 ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
1474 if (ret)
1475 return ret;
1476 }
1477 ret = mmc_test_area_erase(test);
1478 if (ret)
1479 return ret;
1480 dev_addr = test->area.dev_addr;
1481 return mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
1482}
1483
1484/*
1485 * Single trim performance by transfer size.
1486 */
1487static int mmc_test_profile_trim_perf(struct mmc_test_card *test)
1488{
1489 unsigned long sz;
1490 unsigned int dev_addr;
1491 struct timespec ts1, ts2;
1492 int ret;
1493
1494 if (!mmc_can_trim(test->card))
1495 return RESULT_UNSUP_CARD;
1496
1497 if (!mmc_can_erase(test->card))
1498 return RESULT_UNSUP_HOST;
1499
1500 for (sz = 512; sz < test->area.max_sz; sz <<= 1) {
1501 dev_addr = test->area.dev_addr + (sz >> 9);
1502 getnstimeofday(&ts1);
1503 ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
1504 if (ret)
1505 return ret;
1506 getnstimeofday(&ts2);
1507 mmc_test_print_rate(test, sz, &ts1, &ts2);
1508 }
1509 dev_addr = test->area.dev_addr;
1510 getnstimeofday(&ts1);
1511 ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
1512 if (ret)
1513 return ret;
1514 getnstimeofday(&ts2);
1515 mmc_test_print_rate(test, sz, &ts1, &ts2);
1516 return 0;
1517}
1518
1519/*
1520 * Consecutive read performance by transfer size.
1521 */
1522static int mmc_test_profile_seq_read_perf(struct mmc_test_card *test)
1523{
1524 unsigned long sz;
1525 unsigned int dev_addr, i, cnt;
1526 struct timespec ts1, ts2;
1527 int ret;
1528
1529 for (sz = 512; sz <= test->area.max_sz; sz <<= 1) {
1530 cnt = test->area.max_sz / sz;
1531 dev_addr = test->area.dev_addr;
1532 getnstimeofday(&ts1);
1533 for (i = 0; i < cnt; i++) {
1534 ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 0);
1535 if (ret)
1536 return ret;
1537 dev_addr += (sz >> 9);
1538 }
1539 getnstimeofday(&ts2);
1540 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1541 }
1542 return 0;
1543}
1544
1545/*
1546 * Consecutive write performance by transfer size.
1547 */
1548static int mmc_test_profile_seq_write_perf(struct mmc_test_card *test)
1549{
1550 unsigned long sz;
1551 unsigned int dev_addr, i, cnt;
1552 struct timespec ts1, ts2;
1553 int ret;
1554
1555 for (sz = 512; sz <= test->area.max_sz; sz <<= 1) {
1556 ret = mmc_test_area_erase(test);
1557 if (ret)
1558 return ret;
1559 cnt = test->area.max_sz / sz;
1560 dev_addr = test->area.dev_addr;
1561 getnstimeofday(&ts1);
1562 for (i = 0; i < cnt; i++) {
1563 ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 0);
1564 if (ret)
1565 return ret;
1566 dev_addr += (sz >> 9);
1567 }
1568 getnstimeofday(&ts2);
1569 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1570 }
1571 return 0;
1572}
1573
1574/*
1575 * Consecutive trim performance by transfer size.
1576 */
1577static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test)
1578{
1579 unsigned long sz;
1580 unsigned int dev_addr, i, cnt;
1581 struct timespec ts1, ts2;
1582 int ret;
1583
1584 if (!mmc_can_trim(test->card))
1585 return RESULT_UNSUP_CARD;
1586
1587 if (!mmc_can_erase(test->card))
1588 return RESULT_UNSUP_HOST;
1589
1590 for (sz = 512; sz <= test->area.max_sz; sz <<= 1) {
1591 ret = mmc_test_area_erase(test);
1592 if (ret)
1593 return ret;
1594 ret = mmc_test_area_fill(test);
1595 if (ret)
1596 return ret;
1597 cnt = test->area.max_sz / sz;
1598 dev_addr = test->area.dev_addr;
1599 getnstimeofday(&ts1);
1600 for (i = 0; i < cnt; i++) {
1601 ret = mmc_erase(test->card, dev_addr, sz >> 9,
1602 MMC_TRIM_ARG);
1603 if (ret)
1604 return ret;
1605 dev_addr += (sz >> 9);
1606 }
1607 getnstimeofday(&ts2);
1608 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1609 }
1610 return 0;
1611}
1612
898static const struct mmc_test_case mmc_test_cases[] = { 1613static const struct mmc_test_case mmc_test_cases[] = {
899 { 1614 {
900 .name = "Basic write (no data verification)", 1615 .name = "Basic write (no data verification)",
@@ -1040,8 +1755,100 @@ static const struct mmc_test_case mmc_test_cases[] = {
1040 .cleanup = mmc_test_cleanup, 1755 .cleanup = mmc_test_cleanup,
1041 }, 1756 },
1042 1757
1758#else
1759
1760 {
1761 .name = "Highmem write",
1762 .run = mmc_test_no_highmem,
1763 },
1764
1765 {
1766 .name = "Highmem read",
1767 .run = mmc_test_no_highmem,
1768 },
1769
1770 {
1771 .name = "Multi-block highmem write",
1772 .run = mmc_test_no_highmem,
1773 },
1774
1775 {
1776 .name = "Multi-block highmem read",
1777 .run = mmc_test_no_highmem,
1778 },
1779
1043#endif /* CONFIG_HIGHMEM */ 1780#endif /* CONFIG_HIGHMEM */
1044 1781
1782 {
1783 .name = "Best-case read performance",
1784 .prepare = mmc_test_area_prepare_fill,
1785 .run = mmc_test_best_read_performance,
1786 .cleanup = mmc_test_area_cleanup,
1787 },
1788
1789 {
1790 .name = "Best-case write performance",
1791 .prepare = mmc_test_area_prepare_erase,
1792 .run = mmc_test_best_write_performance,
1793 .cleanup = mmc_test_area_cleanup,
1794 },
1795
1796 {
1797 .name = "Best-case read performance into scattered pages",
1798 .prepare = mmc_test_area_prepare_fill,
1799 .run = mmc_test_best_read_perf_max_scatter,
1800 .cleanup = mmc_test_area_cleanup,
1801 },
1802
1803 {
1804 .name = "Best-case write performance from scattered pages",
1805 .prepare = mmc_test_area_prepare_erase,
1806 .run = mmc_test_best_write_perf_max_scatter,
1807 .cleanup = mmc_test_area_cleanup,
1808 },
1809
1810 {
1811 .name = "Single read performance by transfer size",
1812 .prepare = mmc_test_area_prepare_fill,
1813 .run = mmc_test_profile_read_perf,
1814 .cleanup = mmc_test_area_cleanup,
1815 },
1816
1817 {
1818 .name = "Single write performance by transfer size",
1819 .prepare = mmc_test_area_prepare,
1820 .run = mmc_test_profile_write_perf,
1821 .cleanup = mmc_test_area_cleanup,
1822 },
1823
1824 {
1825 .name = "Single trim performance by transfer size",
1826 .prepare = mmc_test_area_prepare_fill,
1827 .run = mmc_test_profile_trim_perf,
1828 .cleanup = mmc_test_area_cleanup,
1829 },
1830
1831 {
1832 .name = "Consecutive read performance by transfer size",
1833 .prepare = mmc_test_area_prepare_fill,
1834 .run = mmc_test_profile_seq_read_perf,
1835 .cleanup = mmc_test_area_cleanup,
1836 },
1837
1838 {
1839 .name = "Consecutive write performance by transfer size",
1840 .prepare = mmc_test_area_prepare,
1841 .run = mmc_test_profile_seq_write_perf,
1842 .cleanup = mmc_test_area_cleanup,
1843 },
1844
1845 {
1846 .name = "Consecutive trim performance by transfer size",
1847 .prepare = mmc_test_area_prepare,
1848 .run = mmc_test_profile_seq_trim_perf,
1849 .cleanup = mmc_test_area_cleanup,
1850 },
1851
1045}; 1852};
1046 1853
1047static DEFINE_MUTEX(mmc_test_lock); 1854static DEFINE_MUTEX(mmc_test_lock);
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index c77eb49eda0e..e876678176be 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -30,9 +30,9 @@
30static int mmc_prep_request(struct request_queue *q, struct request *req) 30static int mmc_prep_request(struct request_queue *q, struct request *req)
31{ 31{
32 /* 32 /*
33 * We only like normal block requests. 33 * We only like normal block requests and discards.
34 */ 34 */
35 if (req->cmd_type != REQ_TYPE_FS) { 35 if (req->cmd_type != REQ_TYPE_FS && !(req->cmd_flags & REQ_DISCARD)) {
36 blk_dump_rq_flags(req, "MMC bad request"); 36 blk_dump_rq_flags(req, "MMC bad request");
37 return BLKPREP_KILL; 37 return BLKPREP_KILL;
38 } 38 }
@@ -130,6 +130,21 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
130 blk_queue_prep_rq(mq->queue, mmc_prep_request); 130 blk_queue_prep_rq(mq->queue, mmc_prep_request);
131 blk_queue_ordered(mq->queue, QUEUE_ORDERED_DRAIN); 131 blk_queue_ordered(mq->queue, QUEUE_ORDERED_DRAIN);
132 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue); 132 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue);
133 if (mmc_can_erase(card)) {
134 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, mq->queue);
135 mq->queue->limits.max_discard_sectors = UINT_MAX;
136 if (card->erased_byte == 0)
137 mq->queue->limits.discard_zeroes_data = 1;
138 if (!mmc_can_trim(card) && is_power_of_2(card->erase_size)) {
139 mq->queue->limits.discard_granularity =
140 card->erase_size << 9;
141 mq->queue->limits.discard_alignment =
142 card->erase_size << 9;
143 }
144 if (mmc_can_secure_erase_trim(card))
145 queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD,
146 mq->queue);
147 }
133 148
134#ifdef CONFIG_MMC_BLOCK_BOUNCE 149#ifdef CONFIG_MMC_BLOCK_BOUNCE
135 if (host->max_hw_segs == 1) { 150 if (host->max_hw_segs == 1) {
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 49d9dcaeca49..7cd9749dc21d 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -37,6 +37,8 @@ static ssize_t mmc_type_show(struct device *dev,
37 return sprintf(buf, "SD\n"); 37 return sprintf(buf, "SD\n");
38 case MMC_TYPE_SDIO: 38 case MMC_TYPE_SDIO:
39 return sprintf(buf, "SDIO\n"); 39 return sprintf(buf, "SDIO\n");
40 case MMC_TYPE_SD_COMBO:
41 return sprintf(buf, "SDcombo\n");
40 default: 42 default:
41 return -EFAULT; 43 return -EFAULT;
42 } 44 }
@@ -74,6 +76,9 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
74 case MMC_TYPE_SDIO: 76 case MMC_TYPE_SDIO:
75 type = "SDIO"; 77 type = "SDIO";
76 break; 78 break;
79 case MMC_TYPE_SD_COMBO:
80 type = "SDcombo";
81 break;
77 default: 82 default:
78 type = NULL; 83 type = NULL;
79 } 84 }
@@ -239,6 +244,10 @@ int mmc_add_card(struct mmc_card *card)
239 case MMC_TYPE_SDIO: 244 case MMC_TYPE_SDIO:
240 type = "SDIO"; 245 type = "SDIO";
241 break; 246 break;
247 case MMC_TYPE_SD_COMBO:
248 type = "SD-combo";
249 if (mmc_card_blockaddr(card))
250 type = "SDHC-combo";
242 default: 251 default:
243 type = "?"; 252 type = "?";
244 break; 253 break;
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 569e94da844c..5db49b124ffa 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -1050,6 +1050,352 @@ void mmc_detect_change(struct mmc_host *host, unsigned long delay)
1050 1050
1051EXPORT_SYMBOL(mmc_detect_change); 1051EXPORT_SYMBOL(mmc_detect_change);
1052 1052
1053void mmc_init_erase(struct mmc_card *card)
1054{
1055 unsigned int sz;
1056
1057 if (is_power_of_2(card->erase_size))
1058 card->erase_shift = ffs(card->erase_size) - 1;
1059 else
1060 card->erase_shift = 0;
1061
1062 /*
1063 * It is possible to erase an arbitrarily large area of an SD or MMC
1064 * card. That is not desirable because it can take a long time
1065 * (minutes) potentially delaying more important I/O, and also the
1066 * timeout calculations become increasingly hugely over-estimated.
1067 * Consequently, 'pref_erase' is defined as a guide to limit erases
1068 * to that size and alignment.
1069 *
1070 * For SD cards that define Allocation Unit size, limit erases to one
1071 * Allocation Unit at a time. For MMC cards that define High Capacity
1072 * Erase Size, whether it is switched on or not, limit to that size.
1073 * Otherwise just have a stab at a good value. For modern cards it
1074 * will end up being 4MiB. Note that if the value is too small, it
1075 * can end up taking longer to erase.
1076 */
1077 if (mmc_card_sd(card) && card->ssr.au) {
1078 card->pref_erase = card->ssr.au;
1079 card->erase_shift = ffs(card->ssr.au) - 1;
1080 } else if (card->ext_csd.hc_erase_size) {
1081 card->pref_erase = card->ext_csd.hc_erase_size;
1082 } else {
1083 sz = (card->csd.capacity << (card->csd.read_blkbits - 9)) >> 11;
1084 if (sz < 128)
1085 card->pref_erase = 512 * 1024 / 512;
1086 else if (sz < 512)
1087 card->pref_erase = 1024 * 1024 / 512;
1088 else if (sz < 1024)
1089 card->pref_erase = 2 * 1024 * 1024 / 512;
1090 else
1091 card->pref_erase = 4 * 1024 * 1024 / 512;
1092 if (card->pref_erase < card->erase_size)
1093 card->pref_erase = card->erase_size;
1094 else {
1095 sz = card->pref_erase % card->erase_size;
1096 if (sz)
1097 card->pref_erase += card->erase_size - sz;
1098 }
1099 }
1100}
1101
1102static void mmc_set_mmc_erase_timeout(struct mmc_card *card,
1103 struct mmc_command *cmd,
1104 unsigned int arg, unsigned int qty)
1105{
1106 unsigned int erase_timeout;
1107
1108 if (card->ext_csd.erase_group_def & 1) {
1109 /* High Capacity Erase Group Size uses HC timeouts */
1110 if (arg == MMC_TRIM_ARG)
1111 erase_timeout = card->ext_csd.trim_timeout;
1112 else
1113 erase_timeout = card->ext_csd.hc_erase_timeout;
1114 } else {
1115 /* CSD Erase Group Size uses write timeout */
1116 unsigned int mult = (10 << card->csd.r2w_factor);
1117 unsigned int timeout_clks = card->csd.tacc_clks * mult;
1118 unsigned int timeout_us;
1119
1120 /* Avoid overflow: e.g. tacc_ns=80000000 mult=1280 */
1121 if (card->csd.tacc_ns < 1000000)
1122 timeout_us = (card->csd.tacc_ns * mult) / 1000;
1123 else
1124 timeout_us = (card->csd.tacc_ns / 1000) * mult;
1125
1126 /*
1127 * ios.clock is only a target. The real clock rate might be
1128 * less but not that much less, so fudge it by multiplying by 2.
1129 */
1130 timeout_clks <<= 1;
1131 timeout_us += (timeout_clks * 1000) /
1132 (card->host->ios.clock / 1000);
1133
1134 erase_timeout = timeout_us / 1000;
1135
1136 /*
1137 * Theoretically, the calculation could underflow so round up
1138 * to 1ms in that case.
1139 */
1140 if (!erase_timeout)
1141 erase_timeout = 1;
1142 }
1143
1144 /* Multiplier for secure operations */
1145 if (arg & MMC_SECURE_ARGS) {
1146 if (arg == MMC_SECURE_ERASE_ARG)
1147 erase_timeout *= card->ext_csd.sec_erase_mult;
1148 else
1149 erase_timeout *= card->ext_csd.sec_trim_mult;
1150 }
1151
1152 erase_timeout *= qty;
1153
1154 /*
1155 * Ensure at least a 1 second timeout for SPI as per
1156 * 'mmc_set_data_timeout()'
1157 */
1158 if (mmc_host_is_spi(card->host) && erase_timeout < 1000)
1159 erase_timeout = 1000;
1160
1161 cmd->erase_timeout = erase_timeout;
1162}
1163
1164static void mmc_set_sd_erase_timeout(struct mmc_card *card,
1165 struct mmc_command *cmd, unsigned int arg,
1166 unsigned int qty)
1167{
1168 if (card->ssr.erase_timeout) {
1169 /* Erase timeout specified in SD Status Register (SSR) */
1170 cmd->erase_timeout = card->ssr.erase_timeout * qty +
1171 card->ssr.erase_offset;
1172 } else {
1173 /*
1174 * Erase timeout not specified in SD Status Register (SSR) so
1175 * use 250ms per write block.
1176 */
1177 cmd->erase_timeout = 250 * qty;
1178 }
1179
1180 /* Must not be less than 1 second */
1181 if (cmd->erase_timeout < 1000)
1182 cmd->erase_timeout = 1000;
1183}
1184
1185static void mmc_set_erase_timeout(struct mmc_card *card,
1186 struct mmc_command *cmd, unsigned int arg,
1187 unsigned int qty)
1188{
1189 if (mmc_card_sd(card))
1190 mmc_set_sd_erase_timeout(card, cmd, arg, qty);
1191 else
1192 mmc_set_mmc_erase_timeout(card, cmd, arg, qty);
1193}
1194
1195static int mmc_do_erase(struct mmc_card *card, unsigned int from,
1196 unsigned int to, unsigned int arg)
1197{
1198 struct mmc_command cmd;
1199 unsigned int qty = 0;
1200 int err;
1201
1202 /*
1203 * qty is used to calculate the erase timeout which depends on how many
1204 * erase groups (or allocation units in SD terminology) are affected.
1205 * We count erasing part of an erase group as one erase group.
1206 * For SD, the allocation units are always a power of 2. For MMC, the
1207 * erase group size is almost certainly also power of 2, but it does not
1208 * seem to insist on that in the JEDEC standard, so we fall back to
1209 * division in that case. SD may not specify an allocation unit size,
1210 * in which case the timeout is based on the number of write blocks.
1211 *
1212 * Note that the timeout for secure trim 2 will only be correct if the
1213 * number of erase groups specified is the same as the total of all
1214 * preceding secure trim 1 commands. Since the power may have been
1215 * lost since the secure trim 1 commands occurred, it is generally
1216 * impossible to calculate the secure trim 2 timeout correctly.
1217 */
1218 if (card->erase_shift)
1219 qty += ((to >> card->erase_shift) -
1220 (from >> card->erase_shift)) + 1;
1221 else if (mmc_card_sd(card))
1222 qty += to - from + 1;
1223 else
1224 qty += ((to / card->erase_size) -
1225 (from / card->erase_size)) + 1;
1226
1227 if (!mmc_card_blockaddr(card)) {
1228 from <<= 9;
1229 to <<= 9;
1230 }
1231
1232 memset(&cmd, 0, sizeof(struct mmc_command));
1233 if (mmc_card_sd(card))
1234 cmd.opcode = SD_ERASE_WR_BLK_START;
1235 else
1236 cmd.opcode = MMC_ERASE_GROUP_START;
1237 cmd.arg = from;
1238 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
1239 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1240 if (err) {
1241 printk(KERN_ERR "mmc_erase: group start error %d, "
1242 "status %#x\n", err, cmd.resp[0]);
1243 err = -EINVAL;
1244 goto out;
1245 }
1246
1247 memset(&cmd, 0, sizeof(struct mmc_command));
1248 if (mmc_card_sd(card))
1249 cmd.opcode = SD_ERASE_WR_BLK_END;
1250 else
1251 cmd.opcode = MMC_ERASE_GROUP_END;
1252 cmd.arg = to;
1253 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
1254 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1255 if (err) {
1256 printk(KERN_ERR "mmc_erase: group end error %d, status %#x\n",
1257 err, cmd.resp[0]);
1258 err = -EINVAL;
1259 goto out;
1260 }
1261
1262 memset(&cmd, 0, sizeof(struct mmc_command));
1263 cmd.opcode = MMC_ERASE;
1264 cmd.arg = arg;
1265 cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
1266 mmc_set_erase_timeout(card, &cmd, arg, qty);
1267 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1268 if (err) {
1269 printk(KERN_ERR "mmc_erase: erase error %d, status %#x\n",
1270 err, cmd.resp[0]);
1271 err = -EIO;
1272 goto out;
1273 }
1274
1275 if (mmc_host_is_spi(card->host))
1276 goto out;
1277
1278 do {
1279 memset(&cmd, 0, sizeof(struct mmc_command));
1280 cmd.opcode = MMC_SEND_STATUS;
1281 cmd.arg = card->rca << 16;
1282 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
1283 /* Do not retry else we can't see errors */
1284 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1285 if (err || (cmd.resp[0] & 0xFDF92000)) {
1286 printk(KERN_ERR "error %d requesting status %#x\n",
1287 err, cmd.resp[0]);
1288 err = -EIO;
1289 goto out;
1290 }
1291 } while (!(cmd.resp[0] & R1_READY_FOR_DATA) ||
1292 R1_CURRENT_STATE(cmd.resp[0]) == 7);
1293out:
1294 return err;
1295}
1296
1297/**
1298 * mmc_erase - erase sectors.
1299 * @card: card to erase
1300 * @from: first sector to erase
1301 * @nr: number of sectors to erase
1302 * @arg: erase command argument (SD supports only %MMC_ERASE_ARG)
1303 *
1304 * Caller must claim host before calling this function.
1305 */
1306int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
1307 unsigned int arg)
1308{
1309 unsigned int rem, to = from + nr;
1310
1311 if (!(card->host->caps & MMC_CAP_ERASE) ||
1312 !(card->csd.cmdclass & CCC_ERASE))
1313 return -EOPNOTSUPP;
1314
1315 if (!card->erase_size)
1316 return -EOPNOTSUPP;
1317
1318 if (mmc_card_sd(card) && arg != MMC_ERASE_ARG)
1319 return -EOPNOTSUPP;
1320
1321 if ((arg & MMC_SECURE_ARGS) &&
1322 !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN))
1323 return -EOPNOTSUPP;
1324
1325 if ((arg & MMC_TRIM_ARGS) &&
1326 !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN))
1327 return -EOPNOTSUPP;
1328
1329 if (arg == MMC_SECURE_ERASE_ARG) {
1330 if (from % card->erase_size || nr % card->erase_size)
1331 return -EINVAL;
1332 }
1333
1334 if (arg == MMC_ERASE_ARG) {
1335 rem = from % card->erase_size;
1336 if (rem) {
1337 rem = card->erase_size - rem;
1338 from += rem;
1339 if (nr > rem)
1340 nr -= rem;
1341 else
1342 return 0;
1343 }
1344 rem = nr % card->erase_size;
1345 if (rem)
1346 nr -= rem;
1347 }
1348
1349 if (nr == 0)
1350 return 0;
1351
1352 to = from + nr;
1353
1354 if (to <= from)
1355 return -EINVAL;
1356
1357 /* 'from' and 'to' are inclusive */
1358 to -= 1;
1359
1360 return mmc_do_erase(card, from, to, arg);
1361}
1362EXPORT_SYMBOL(mmc_erase);
1363
1364int mmc_can_erase(struct mmc_card *card)
1365{
1366 if ((card->host->caps & MMC_CAP_ERASE) &&
1367 (card->csd.cmdclass & CCC_ERASE) && card->erase_size)
1368 return 1;
1369 return 0;
1370}
1371EXPORT_SYMBOL(mmc_can_erase);
1372
1373int mmc_can_trim(struct mmc_card *card)
1374{
1375 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN)
1376 return 1;
1377 return 0;
1378}
1379EXPORT_SYMBOL(mmc_can_trim);
1380
1381int mmc_can_secure_erase_trim(struct mmc_card *card)
1382{
1383 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN)
1384 return 1;
1385 return 0;
1386}
1387EXPORT_SYMBOL(mmc_can_secure_erase_trim);
1388
1389int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
1390 unsigned int nr)
1391{
1392 if (!card->erase_size)
1393 return 0;
1394 if (from % card->erase_size || nr % card->erase_size)
1395 return 0;
1396 return 1;
1397}
1398EXPORT_SYMBOL(mmc_erase_group_aligned);
1053 1399
1054void mmc_rescan(struct work_struct *work) 1400void mmc_rescan(struct work_struct *work)
1055{ 1401{
@@ -1057,6 +1403,17 @@ void mmc_rescan(struct work_struct *work)
1057 container_of(work, struct mmc_host, detect.work); 1403 container_of(work, struct mmc_host, detect.work);
1058 u32 ocr; 1404 u32 ocr;
1059 int err; 1405 int err;
1406 unsigned long flags;
1407
1408 spin_lock_irqsave(&host->lock, flags);
1409
1410 if (host->rescan_disable) {
1411 spin_unlock_irqrestore(&host->lock, flags);
1412 return;
1413 }
1414
1415 spin_unlock_irqrestore(&host->lock, flags);
1416
1060 1417
1061 mmc_bus_get(host); 1418 mmc_bus_get(host);
1062 1419
@@ -1099,8 +1456,15 @@ void mmc_rescan(struct work_struct *work)
1099 */ 1456 */
1100 err = mmc_send_io_op_cond(host, 0, &ocr); 1457 err = mmc_send_io_op_cond(host, 0, &ocr);
1101 if (!err) { 1458 if (!err) {
1102 if (mmc_attach_sdio(host, ocr)) 1459 if (mmc_attach_sdio(host, ocr)) {
1103 mmc_power_off(host); 1460 mmc_claim_host(host);
1461 /* try SDMEM (but not MMC) even if SDIO is broken */
1462 if (mmc_send_app_op_cond(host, 0, &ocr))
1463 goto out_fail;
1464
1465 if (mmc_attach_sd(host, ocr))
1466 mmc_power_off(host);
1467 }
1104 goto out; 1468 goto out;
1105 } 1469 }
1106 1470
@@ -1124,6 +1488,7 @@ void mmc_rescan(struct work_struct *work)
1124 goto out; 1488 goto out;
1125 } 1489 }
1126 1490
1491out_fail:
1127 mmc_release_host(host); 1492 mmc_release_host(host);
1128 mmc_power_off(host); 1493 mmc_power_off(host);
1129 1494
@@ -1266,19 +1631,6 @@ int mmc_suspend_host(struct mmc_host *host)
1266 if (host->bus_ops && !host->bus_dead) { 1631 if (host->bus_ops && !host->bus_dead) {
1267 if (host->bus_ops->suspend) 1632 if (host->bus_ops->suspend)
1268 err = host->bus_ops->suspend(host); 1633 err = host->bus_ops->suspend(host);
1269 if (err == -ENOSYS || !host->bus_ops->resume) {
1270 /*
1271 * We simply "remove" the card in this case.
1272 * It will be redetected on resume.
1273 */
1274 if (host->bus_ops->remove)
1275 host->bus_ops->remove(host);
1276 mmc_claim_host(host);
1277 mmc_detach_bus(host);
1278 mmc_release_host(host);
1279 host->pm_flags = 0;
1280 err = 0;
1281 }
1282 } 1634 }
1283 mmc_bus_put(host); 1635 mmc_bus_put(host);
1284 1636
@@ -1310,28 +1662,61 @@ int mmc_resume_host(struct mmc_host *host)
1310 printk(KERN_WARNING "%s: error %d during resume " 1662 printk(KERN_WARNING "%s: error %d during resume "
1311 "(card was removed?)\n", 1663 "(card was removed?)\n",
1312 mmc_hostname(host), err); 1664 mmc_hostname(host), err);
1313 if (host->bus_ops->remove)
1314 host->bus_ops->remove(host);
1315 mmc_claim_host(host);
1316 mmc_detach_bus(host);
1317 mmc_release_host(host);
1318 /* no need to bother upper layers */
1319 err = 0; 1665 err = 0;
1320 } 1666 }
1321 } 1667 }
1322 mmc_bus_put(host); 1668 mmc_bus_put(host);
1323 1669
1324 /*
1325 * We add a slight delay here so that resume can progress
1326 * in parallel.
1327 */
1328 mmc_detect_change(host, 1);
1329
1330 return err; 1670 return err;
1331} 1671}
1332
1333EXPORT_SYMBOL(mmc_resume_host); 1672EXPORT_SYMBOL(mmc_resume_host);
1334 1673
1674/* Do the card removal on suspend if card is assumed removeable
1675 * Do that in pm notifier while userspace isn't yet frozen, so we will be able
1676 to sync the card.
1677*/
1678int mmc_pm_notify(struct notifier_block *notify_block,
1679 unsigned long mode, void *unused)
1680{
1681 struct mmc_host *host = container_of(
1682 notify_block, struct mmc_host, pm_notify);
1683 unsigned long flags;
1684
1685
1686 switch (mode) {
1687 case PM_HIBERNATION_PREPARE:
1688 case PM_SUSPEND_PREPARE:
1689
1690 spin_lock_irqsave(&host->lock, flags);
1691 host->rescan_disable = 1;
1692 spin_unlock_irqrestore(&host->lock, flags);
1693 cancel_delayed_work_sync(&host->detect);
1694
1695 if (!host->bus_ops || host->bus_ops->suspend)
1696 break;
1697
1698 mmc_claim_host(host);
1699
1700 if (host->bus_ops->remove)
1701 host->bus_ops->remove(host);
1702
1703 mmc_detach_bus(host);
1704 mmc_release_host(host);
1705 host->pm_flags = 0;
1706 break;
1707
1708 case PM_POST_SUSPEND:
1709 case PM_POST_HIBERNATION:
1710
1711 spin_lock_irqsave(&host->lock, flags);
1712 host->rescan_disable = 0;
1713 spin_unlock_irqrestore(&host->lock, flags);
1714 mmc_detect_change(host, 0);
1715
1716 }
1717
1718 return 0;
1719}
1335#endif 1720#endif
1336 1721
1337static int __init mmc_init(void) 1722static int __init mmc_init(void)
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index a811c52a1659..9d9eef50e5d1 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -29,6 +29,8 @@ struct mmc_bus_ops {
29void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops); 29void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
30void mmc_detach_bus(struct mmc_host *host); 30void mmc_detach_bus(struct mmc_host *host);
31 31
32void mmc_init_erase(struct mmc_card *card);
33
32void mmc_set_chip_select(struct mmc_host *host, int mode); 34void mmc_set_chip_select(struct mmc_host *host, int mode);
33void mmc_set_clock(struct mmc_host *host, unsigned int hz); 35void mmc_set_clock(struct mmc_host *host, unsigned int hz);
34void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode); 36void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 47353909e345..0efe631e50ca 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -17,6 +17,7 @@
17#include <linux/pagemap.h> 17#include <linux/pagemap.h>
18#include <linux/leds.h> 18#include <linux/leds.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/suspend.h>
20 21
21#include <linux/mmc/host.h> 22#include <linux/mmc/host.h>
22 23
@@ -85,6 +86,7 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
85 init_waitqueue_head(&host->wq); 86 init_waitqueue_head(&host->wq);
86 INIT_DELAYED_WORK(&host->detect, mmc_rescan); 87 INIT_DELAYED_WORK(&host->detect, mmc_rescan);
87 INIT_DELAYED_WORK_DEFERRABLE(&host->disable, mmc_host_deeper_disable); 88 INIT_DELAYED_WORK_DEFERRABLE(&host->disable, mmc_host_deeper_disable);
89 host->pm_notify.notifier_call = mmc_pm_notify;
88 90
89 /* 91 /*
90 * By default, hosts do not support SGIO or large requests. 92 * By default, hosts do not support SGIO or large requests.
@@ -133,6 +135,7 @@ int mmc_add_host(struct mmc_host *host)
133#endif 135#endif
134 136
135 mmc_start_host(host); 137 mmc_start_host(host);
138 register_pm_notifier(&host->pm_notify);
136 139
137 return 0; 140 return 0;
138} 141}
@@ -149,6 +152,7 @@ EXPORT_SYMBOL(mmc_add_host);
149 */ 152 */
150void mmc_remove_host(struct mmc_host *host) 153void mmc_remove_host(struct mmc_host *host)
151{ 154{
155 unregister_pm_notifier(&host->pm_notify);
152 mmc_stop_host(host); 156 mmc_stop_host(host);
153 157
154#ifdef CONFIG_DEBUG_FS 158#ifdef CONFIG_DEBUG_FS
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 89f7a25b7ac1..6909a54c39be 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -108,23 +108,34 @@ static int mmc_decode_cid(struct mmc_card *card)
108 return 0; 108 return 0;
109} 109}
110 110
111static void mmc_set_erase_size(struct mmc_card *card)
112{
113 if (card->ext_csd.erase_group_def & 1)
114 card->erase_size = card->ext_csd.hc_erase_size;
115 else
116 card->erase_size = card->csd.erase_size;
117
118 mmc_init_erase(card);
119}
120
111/* 121/*
112 * Given a 128-bit response, decode to our card CSD structure. 122 * Given a 128-bit response, decode to our card CSD structure.
113 */ 123 */
114static int mmc_decode_csd(struct mmc_card *card) 124static int mmc_decode_csd(struct mmc_card *card)
115{ 125{
116 struct mmc_csd *csd = &card->csd; 126 struct mmc_csd *csd = &card->csd;
117 unsigned int e, m, csd_struct; 127 unsigned int e, m, a, b;
118 u32 *resp = card->raw_csd; 128 u32 *resp = card->raw_csd;
119 129
120 /* 130 /*
121 * We only understand CSD structure v1.1 and v1.2. 131 * We only understand CSD structure v1.1 and v1.2.
122 * v1.2 has extra information in bits 15, 11 and 10. 132 * v1.2 has extra information in bits 15, 11 and 10.
133 * We also support eMMC v4.4 & v4.41.
123 */ 134 */
124 csd_struct = UNSTUFF_BITS(resp, 126, 2); 135 csd->structure = UNSTUFF_BITS(resp, 126, 2);
125 if (csd_struct != 1 && csd_struct != 2) { 136 if (csd->structure == 0) {
126 printk(KERN_ERR "%s: unrecognised CSD structure version %d\n", 137 printk(KERN_ERR "%s: unrecognised CSD structure version %d\n",
127 mmc_hostname(card->host), csd_struct); 138 mmc_hostname(card->host), csd->structure);
128 return -EINVAL; 139 return -EINVAL;
129 } 140 }
130 141
@@ -151,6 +162,13 @@ static int mmc_decode_csd(struct mmc_card *card)
151 csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); 162 csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4);
152 csd->write_partial = UNSTUFF_BITS(resp, 21, 1); 163 csd->write_partial = UNSTUFF_BITS(resp, 21, 1);
153 164
165 if (csd->write_blkbits >= 9) {
166 a = UNSTUFF_BITS(resp, 42, 5);
167 b = UNSTUFF_BITS(resp, 37, 5);
168 csd->erase_size = (a + 1) * (b + 1);
169 csd->erase_size <<= csd->write_blkbits - 9;
170 }
171
154 return 0; 172 return 0;
155} 173}
156 174
@@ -207,11 +225,22 @@ static int mmc_read_ext_csd(struct mmc_card *card)
207 goto out; 225 goto out;
208 } 226 }
209 227
228 /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */
229 if (card->csd.structure == 3) {
230 int ext_csd_struct = ext_csd[EXT_CSD_STRUCTURE];
231 if (ext_csd_struct > 2) {
232 printk(KERN_ERR "%s: unrecognised EXT_CSD structure "
233 "version %d\n", mmc_hostname(card->host),
234 ext_csd_struct);
235 err = -EINVAL;
236 goto out;
237 }
238 }
239
210 card->ext_csd.rev = ext_csd[EXT_CSD_REV]; 240 card->ext_csd.rev = ext_csd[EXT_CSD_REV];
211 if (card->ext_csd.rev > 5) { 241 if (card->ext_csd.rev > 5) {
212 printk(KERN_ERR "%s: unrecognised EXT_CSD structure " 242 printk(KERN_ERR "%s: unrecognised EXT_CSD revision %d\n",
213 "version %d\n", mmc_hostname(card->host), 243 mmc_hostname(card->host), card->ext_csd.rev);
214 card->ext_csd.rev);
215 err = -EINVAL; 244 err = -EINVAL;
216 goto out; 245 goto out;
217 } 246 }
@@ -222,7 +251,9 @@ static int mmc_read_ext_csd(struct mmc_card *card)
222 ext_csd[EXT_CSD_SEC_CNT + 1] << 8 | 251 ext_csd[EXT_CSD_SEC_CNT + 1] << 8 |
223 ext_csd[EXT_CSD_SEC_CNT + 2] << 16 | 252 ext_csd[EXT_CSD_SEC_CNT + 2] << 16 |
224 ext_csd[EXT_CSD_SEC_CNT + 3] << 24; 253 ext_csd[EXT_CSD_SEC_CNT + 3] << 24;
225 if (card->ext_csd.sectors) 254
255 /* Cards with density > 2GiB are sector addressed */
256 if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512)
226 mmc_card_set_blockaddr(card); 257 mmc_card_set_blockaddr(card);
227 } 258 }
228 259
@@ -247,8 +278,30 @@ static int mmc_read_ext_csd(struct mmc_card *card)
247 if (sa_shift > 0 && sa_shift <= 0x17) 278 if (sa_shift > 0 && sa_shift <= 0x17)
248 card->ext_csd.sa_timeout = 279 card->ext_csd.sa_timeout =
249 1 << ext_csd[EXT_CSD_S_A_TIMEOUT]; 280 1 << ext_csd[EXT_CSD_S_A_TIMEOUT];
281 card->ext_csd.erase_group_def =
282 ext_csd[EXT_CSD_ERASE_GROUP_DEF];
283 card->ext_csd.hc_erase_timeout = 300 *
284 ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT];
285 card->ext_csd.hc_erase_size =
286 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] << 10;
250 } 287 }
251 288
289 if (card->ext_csd.rev >= 4) {
290 card->ext_csd.sec_trim_mult =
291 ext_csd[EXT_CSD_SEC_TRIM_MULT];
292 card->ext_csd.sec_erase_mult =
293 ext_csd[EXT_CSD_SEC_ERASE_MULT];
294 card->ext_csd.sec_feature_support =
295 ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT];
296 card->ext_csd.trim_timeout = 300 *
297 ext_csd[EXT_CSD_TRIM_MULT];
298 }
299
300 if (ext_csd[EXT_CSD_ERASED_MEM_CONT])
301 card->erased_byte = 0xFF;
302 else
303 card->erased_byte = 0x0;
304
252out: 305out:
253 kfree(ext_csd); 306 kfree(ext_csd);
254 307
@@ -260,6 +313,8 @@ MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
260MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], 313MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
261 card->raw_csd[2], card->raw_csd[3]); 314 card->raw_csd[2], card->raw_csd[3]);
262MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); 315MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
316MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
317MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
263MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); 318MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
264MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); 319MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
265MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); 320MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
@@ -271,6 +326,8 @@ static struct attribute *mmc_std_attrs[] = {
271 &dev_attr_cid.attr, 326 &dev_attr_cid.attr,
272 &dev_attr_csd.attr, 327 &dev_attr_csd.attr,
273 &dev_attr_date.attr, 328 &dev_attr_date.attr,
329 &dev_attr_erase_size.attr,
330 &dev_attr_preferred_erase_size.attr,
274 &dev_attr_fwrev.attr, 331 &dev_attr_fwrev.attr,
275 &dev_attr_hwrev.attr, 332 &dev_attr_hwrev.attr,
276 &dev_attr_manfid.attr, 333 &dev_attr_manfid.attr,
@@ -407,6 +464,8 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
407 err = mmc_read_ext_csd(card); 464 err = mmc_read_ext_csd(card);
408 if (err) 465 if (err)
409 goto free_card; 466 goto free_card;
467 /* Erase size depends on CSD and Extended CSD */
468 mmc_set_erase_size(card);
410 } 469 }
411 470
412 /* 471 /*
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 5eac21df4809..0f5241085557 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -59,7 +59,7 @@ static const unsigned int tacc_mant[] = {
59/* 59/*
60 * Given the decoded CSD structure, decode the raw CID to our CID structure. 60 * Given the decoded CSD structure, decode the raw CID to our CID structure.
61 */ 61 */
62static void mmc_decode_cid(struct mmc_card *card) 62void mmc_decode_cid(struct mmc_card *card)
63{ 63{
64 u32 *resp = card->raw_cid; 64 u32 *resp = card->raw_cid;
65 65
@@ -119,6 +119,13 @@ static int mmc_decode_csd(struct mmc_card *card)
119 csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3); 119 csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3);
120 csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); 120 csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4);
121 csd->write_partial = UNSTUFF_BITS(resp, 21, 1); 121 csd->write_partial = UNSTUFF_BITS(resp, 21, 1);
122
123 if (UNSTUFF_BITS(resp, 46, 1)) {
124 csd->erase_size = 1;
125 } else if (csd->write_blkbits >= 9) {
126 csd->erase_size = UNSTUFF_BITS(resp, 39, 7) + 1;
127 csd->erase_size <<= csd->write_blkbits - 9;
128 }
122 break; 129 break;
123 case 1: 130 case 1:
124 /* 131 /*
@@ -147,6 +154,7 @@ static int mmc_decode_csd(struct mmc_card *card)
147 csd->r2w_factor = 4; /* Unused */ 154 csd->r2w_factor = 4; /* Unused */
148 csd->write_blkbits = 9; 155 csd->write_blkbits = 9;
149 csd->write_partial = 0; 156 csd->write_partial = 0;
157 csd->erase_size = 1;
150 break; 158 break;
151 default: 159 default:
152 printk(KERN_ERR "%s: unrecognised CSD structure version %d\n", 160 printk(KERN_ERR "%s: unrecognised CSD structure version %d\n",
@@ -154,6 +162,8 @@ static int mmc_decode_csd(struct mmc_card *card)
154 return -EINVAL; 162 return -EINVAL;
155 } 163 }
156 164
165 card->erase_size = csd->erase_size;
166
157 return 0; 167 return 0;
158} 168}
159 169
@@ -179,10 +189,68 @@ static int mmc_decode_scr(struct mmc_card *card)
179 scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4); 189 scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4);
180 scr->bus_widths = UNSTUFF_BITS(resp, 48, 4); 190 scr->bus_widths = UNSTUFF_BITS(resp, 48, 4);
181 191
192 if (UNSTUFF_BITS(resp, 55, 1))
193 card->erased_byte = 0xFF;
194 else
195 card->erased_byte = 0x0;
196
182 return 0; 197 return 0;
183} 198}
184 199
185/* 200/*
201 * Fetch and process SD Status register.
202 */
203static int mmc_read_ssr(struct mmc_card *card)
204{
205 unsigned int au, es, et, eo;
206 int err, i;
207 u32 *ssr;
208
209 if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
210 printk(KERN_WARNING "%s: card lacks mandatory SD Status "
211 "function.\n", mmc_hostname(card->host));
212 return 0;
213 }
214
215 ssr = kmalloc(64, GFP_KERNEL);
216 if (!ssr)
217 return -ENOMEM;
218
219 err = mmc_app_sd_status(card, ssr);
220 if (err) {
221 printk(KERN_WARNING "%s: problem reading SD Status "
222 "register.\n", mmc_hostname(card->host));
223 err = 0;
224 goto out;
225 }
226
227 for (i = 0; i < 16; i++)
228 ssr[i] = be32_to_cpu(ssr[i]);
229
230 /*
231 * UNSTUFF_BITS only works with four u32s so we have to offset the
232 * bitfield positions accordingly.
233 */
234 au = UNSTUFF_BITS(ssr, 428 - 384, 4);
235 if (au > 0 || au <= 9) {
236 card->ssr.au = 1 << (au + 4);
237 es = UNSTUFF_BITS(ssr, 408 - 384, 16);
238 et = UNSTUFF_BITS(ssr, 402 - 384, 6);
239 eo = UNSTUFF_BITS(ssr, 400 - 384, 2);
240 if (es && et) {
241 card->ssr.erase_timeout = (et * 1000) / es;
242 card->ssr.erase_offset = eo * 1000;
243 }
244 } else {
245 printk(KERN_WARNING "%s: SD Status: Invalid Allocation Unit "
246 "size.\n", mmc_hostname(card->host));
247 }
248out:
249 kfree(ssr);
250 return err;
251}
252
253/*
186 * Fetches and decodes switch information 254 * Fetches and decodes switch information
187 */ 255 */
188static int mmc_read_switch(struct mmc_card *card) 256static int mmc_read_switch(struct mmc_card *card)
@@ -238,7 +306,7 @@ out:
238/* 306/*
239 * Test if the card supports high-speed mode and, if so, switch to it. 307 * Test if the card supports high-speed mode and, if so, switch to it.
240 */ 308 */
241static int mmc_switch_hs(struct mmc_card *card) 309int mmc_sd_switch_hs(struct mmc_card *card)
242{ 310{
243 int err; 311 int err;
244 u8 *status; 312 u8 *status;
@@ -272,9 +340,9 @@ static int mmc_switch_hs(struct mmc_card *card)
272 printk(KERN_WARNING "%s: Problem switching card " 340 printk(KERN_WARNING "%s: Problem switching card "
273 "into high-speed mode!\n", 341 "into high-speed mode!\n",
274 mmc_hostname(card->host)); 342 mmc_hostname(card->host));
343 err = 0;
275 } else { 344 } else {
276 mmc_card_set_highspeed(card); 345 err = 1;
277 mmc_set_timing(card->host, MMC_TIMING_SD_HS);
278 } 346 }
279 347
280out: 348out:
@@ -289,6 +357,8 @@ MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
289 card->raw_csd[2], card->raw_csd[3]); 357 card->raw_csd[2], card->raw_csd[3]);
290MMC_DEV_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]); 358MMC_DEV_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]);
291MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); 359MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
360MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
361MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
292MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); 362MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
293MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); 363MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
294MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); 364MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
@@ -302,6 +372,8 @@ static struct attribute *sd_std_attrs[] = {
302 &dev_attr_csd.attr, 372 &dev_attr_csd.attr,
303 &dev_attr_scr.attr, 373 &dev_attr_scr.attr,
304 &dev_attr_date.attr, 374 &dev_attr_date.attr,
375 &dev_attr_erase_size.attr,
376 &dev_attr_preferred_erase_size.attr,
305 &dev_attr_fwrev.attr, 377 &dev_attr_fwrev.attr,
306 &dev_attr_hwrev.attr, 378 &dev_attr_hwrev.attr,
307 &dev_attr_manfid.attr, 379 &dev_attr_manfid.attr,
@@ -320,26 +392,16 @@ static const struct attribute_group *sd_attr_groups[] = {
320 NULL, 392 NULL,
321}; 393};
322 394
323static struct device_type sd_type = { 395struct device_type sd_type = {
324 .groups = sd_attr_groups, 396 .groups = sd_attr_groups,
325}; 397};
326 398
327/* 399/*
328 * Handle the detection and initialisation of a card. 400 * Fetch CID from card.
329 *
330 * In the case of a resume, "oldcard" will contain the card
331 * we're trying to reinitialise.
332 */ 401 */
333static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, 402int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
334 struct mmc_card *oldcard)
335{ 403{
336 struct mmc_card *card;
337 int err; 404 int err;
338 u32 cid[4];
339 unsigned int max_dtr;
340
341 BUG_ON(!host);
342 WARN_ON(!host->claimed);
343 405
344 /* 406 /*
345 * Since we're changing the OCR value, we seem to 407 * Since we're changing the OCR value, we seem to
@@ -361,92 +423,67 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
361 423
362 err = mmc_send_app_op_cond(host, ocr, NULL); 424 err = mmc_send_app_op_cond(host, ocr, NULL);
363 if (err) 425 if (err)
364 goto err; 426 return err;
365 427
366 /*
367 * Fetch CID from card.
368 */
369 if (mmc_host_is_spi(host)) 428 if (mmc_host_is_spi(host))
370 err = mmc_send_cid(host, cid); 429 err = mmc_send_cid(host, cid);
371 else 430 else
372 err = mmc_all_send_cid(host, cid); 431 err = mmc_all_send_cid(host, cid);
373 if (err)
374 goto err;
375 432
376 if (oldcard) { 433 return err;
377 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) { 434}
378 err = -ENOENT;
379 goto err;
380 }
381
382 card = oldcard;
383 } else {
384 /*
385 * Allocate card structure.
386 */
387 card = mmc_alloc_card(host, &sd_type);
388 if (IS_ERR(card)) {
389 err = PTR_ERR(card);
390 goto err;
391 }
392 435
393 card->type = MMC_TYPE_SD; 436int mmc_sd_get_csd(struct mmc_host *host, struct mmc_card *card)
394 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); 437{
395 } 438 int err;
396 439
397 /* 440 /*
398 * For native busses: get card RCA and quit open drain mode. 441 * Fetch CSD from card.
399 */ 442 */
400 if (!mmc_host_is_spi(host)) { 443 err = mmc_send_csd(card, card->raw_csd);
401 err = mmc_send_relative_addr(host, &card->rca); 444 if (err)
402 if (err) 445 return err;
403 goto free_card;
404 446
405 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); 447 err = mmc_decode_csd(card);
406 } 448 if (err)
449 return err;
407 450
408 if (!oldcard) { 451 return 0;
452}
453
454int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,
455 bool reinit)
456{
457 int err;
458
459 if (!reinit) {
409 /* 460 /*
410 * Fetch CSD from card. 461 * Fetch SCR from card.
411 */ 462 */
412 err = mmc_send_csd(card, card->raw_csd); 463 err = mmc_app_send_scr(card, card->raw_scr);
413 if (err)
414 goto free_card;
415
416 err = mmc_decode_csd(card);
417 if (err) 464 if (err)
418 goto free_card; 465 return err;
419
420 mmc_decode_cid(card);
421 }
422 466
423 /* 467 err = mmc_decode_scr(card);
424 * Select card, as all following commands rely on that.
425 */
426 if (!mmc_host_is_spi(host)) {
427 err = mmc_select_card(card);
428 if (err) 468 if (err)
429 goto free_card; 469 return err;
430 }
431 470
432 if (!oldcard) {
433 /* 471 /*
434 * Fetch SCR from card. 472 * Fetch and process SD Status register.
435 */ 473 */
436 err = mmc_app_send_scr(card, card->raw_scr); 474 err = mmc_read_ssr(card);
437 if (err) 475 if (err)
438 goto free_card; 476 return err;
439 477
440 err = mmc_decode_scr(card); 478 /* Erase init depends on CSD and SSR */
441 if (err < 0) 479 mmc_init_erase(card);
442 goto free_card;
443 480
444 /* 481 /*
445 * Fetch switch information from card. 482 * Fetch switch information from card.
446 */ 483 */
447 err = mmc_read_switch(card); 484 err = mmc_read_switch(card);
448 if (err) 485 if (err)
449 goto free_card; 486 return err;
450 } 487 }
451 488
452 /* 489 /*
@@ -458,20 +495,34 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
458 if (mmc_host_is_spi(host)) { 495 if (mmc_host_is_spi(host)) {
459 err = mmc_spi_set_crc(host, use_spi_crc); 496 err = mmc_spi_set_crc(host, use_spi_crc);
460 if (err) 497 if (err)
461 goto free_card; 498 return err;
462 } 499 }
463 500
464 /* 501 /*
465 * Attempt to change to high-speed (if supported) 502 * Check if read-only switch is active.
466 */ 503 */
467 err = mmc_switch_hs(card); 504 if (!reinit) {
468 if (err) 505 int ro = -1;
469 goto free_card;
470 506
471 /* 507 if (host->ops->get_ro)
472 * Compute bus speed. 508 ro = host->ops->get_ro(host);
473 */ 509
474 max_dtr = (unsigned int)-1; 510 if (ro < 0) {
511 printk(KERN_WARNING "%s: host does not "
512 "support reading read-only "
513 "switch. assuming write-enable.\n",
514 mmc_hostname(host));
515 } else if (ro > 0) {
516 mmc_card_set_readonly(card);
517 }
518 }
519
520 return 0;
521}
522
523unsigned mmc_sd_get_max_clock(struct mmc_card *card)
524{
525 unsigned max_dtr = (unsigned int)-1;
475 526
476 if (mmc_card_highspeed(card)) { 527 if (mmc_card_highspeed(card)) {
477 if (max_dtr > card->sw_caps.hs_max_dtr) 528 if (max_dtr > card->sw_caps.hs_max_dtr)
@@ -480,7 +531,97 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
480 max_dtr = card->csd.max_dtr; 531 max_dtr = card->csd.max_dtr;
481 } 532 }
482 533
483 mmc_set_clock(host, max_dtr); 534 return max_dtr;
535}
536
537void mmc_sd_go_highspeed(struct mmc_card *card)
538{
539 mmc_card_set_highspeed(card);
540 mmc_set_timing(card->host, MMC_TIMING_SD_HS);
541}
542
543/*
544 * Handle the detection and initialisation of a card.
545 *
546 * In the case of a resume, "oldcard" will contain the card
547 * we're trying to reinitialise.
548 */
549static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
550 struct mmc_card *oldcard)
551{
552 struct mmc_card *card;
553 int err;
554 u32 cid[4];
555
556 BUG_ON(!host);
557 WARN_ON(!host->claimed);
558
559 err = mmc_sd_get_cid(host, ocr, cid);
560 if (err)
561 return err;
562
563 if (oldcard) {
564 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0)
565 return -ENOENT;
566
567 card = oldcard;
568 } else {
569 /*
570 * Allocate card structure.
571 */
572 card = mmc_alloc_card(host, &sd_type);
573 if (IS_ERR(card))
574 return PTR_ERR(card);
575
576 card->type = MMC_TYPE_SD;
577 memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
578 }
579
580 /*
581 * For native busses: get card RCA and quit open drain mode.
582 */
583 if (!mmc_host_is_spi(host)) {
584 err = mmc_send_relative_addr(host, &card->rca);
585 if (err)
586 return err;
587
588 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
589 }
590
591 if (!oldcard) {
592 err = mmc_sd_get_csd(host, card);
593 if (err)
594 return err;
595
596 mmc_decode_cid(card);
597 }
598
599 /*
600 * Select card, as all following commands rely on that.
601 */
602 if (!mmc_host_is_spi(host)) {
603 err = mmc_select_card(card);
604 if (err)
605 return err;
606 }
607
608 err = mmc_sd_setup_card(host, card, oldcard != NULL);
609 if (err)
610 goto free_card;
611
612 /*
613 * Attempt to change to high-speed (if supported)
614 */
615 err = mmc_sd_switch_hs(card);
616 if (err > 0)
617 mmc_sd_go_highspeed(card);
618 else if (err)
619 goto free_card;
620
621 /*
622 * Set bus speed.
623 */
624 mmc_set_clock(host, mmc_sd_get_max_clock(card));
484 625
485 /* 626 /*
486 * Switch to wider bus (if supported). 627 * Switch to wider bus (if supported).
@@ -494,30 +635,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
494 mmc_set_bus_width(host, MMC_BUS_WIDTH_4); 635 mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
495 } 636 }
496 637
497 /* 638 host->card = card;
498 * Check if read-only switch is active.
499 */
500 if (!oldcard) {
501 if (!host->ops->get_ro || host->ops->get_ro(host) < 0) {
502 printk(KERN_WARNING "%s: host does not "
503 "support reading read-only "
504 "switch. assuming write-enable.\n",
505 mmc_hostname(host));
506 } else {
507 if (host->ops->get_ro(host) > 0)
508 mmc_card_set_readonly(card);
509 }
510 }
511
512 if (!oldcard)
513 host->card = card;
514
515 return 0; 639 return 0;
516 640
517free_card: 641free_card:
518 if (!oldcard) 642 if (!oldcard)
519 mmc_remove_card(card); 643 mmc_remove_card(card);
520err:
521 644
522 return err; 645 return err;
523} 646}
diff --git a/drivers/mmc/core/sd.h b/drivers/mmc/core/sd.h
new file mode 100644
index 000000000000..3d8800fa7600
--- /dev/null
+++ b/drivers/mmc/core/sd.h
@@ -0,0 +1,17 @@
1#ifndef _MMC_CORE_SD_H
2#define _MMC_CORE_SD_H
3
4#include <linux/mmc/card.h>
5
6extern struct device_type sd_type;
7
8int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid);
9int mmc_sd_get_csd(struct mmc_host *host, struct mmc_card *card);
10void mmc_decode_cid(struct mmc_card *card);
11int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,
12 bool reinit);
13unsigned mmc_sd_get_max_clock(struct mmc_card *card);
14int mmc_sd_switch_hs(struct mmc_card *card);
15void mmc_sd_go_highspeed(struct mmc_card *card);
16
17#endif
diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
index 63772e7e7608..797cdb5887fd 100644
--- a/drivers/mmc/core/sd_ops.c
+++ b/drivers/mmc/core/sd_ops.c
@@ -346,3 +346,51 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
346 return 0; 346 return 0;
347} 347}
348 348
349int mmc_app_sd_status(struct mmc_card *card, void *ssr)
350{
351 int err;
352 struct mmc_request mrq;
353 struct mmc_command cmd;
354 struct mmc_data data;
355 struct scatterlist sg;
356
357 BUG_ON(!card);
358 BUG_ON(!card->host);
359 BUG_ON(!ssr);
360
361 /* NOTE: caller guarantees ssr is heap-allocated */
362
363 err = mmc_app_cmd(card->host, card);
364 if (err)
365 return err;
366
367 memset(&mrq, 0, sizeof(struct mmc_request));
368 memset(&cmd, 0, sizeof(struct mmc_command));
369 memset(&data, 0, sizeof(struct mmc_data));
370
371 mrq.cmd = &cmd;
372 mrq.data = &data;
373
374 cmd.opcode = SD_APP_SD_STATUS;
375 cmd.arg = 0;
376 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_ADTC;
377
378 data.blksz = 64;
379 data.blocks = 1;
380 data.flags = MMC_DATA_READ;
381 data.sg = &sg;
382 data.sg_len = 1;
383
384 sg_init_one(&sg, ssr, 64);
385
386 mmc_set_data_timeout(&data, card);
387
388 mmc_wait_for_req(card->host, &mrq);
389
390 if (cmd.error)
391 return cmd.error;
392 if (data.error)
393 return data.error;
394
395 return 0;
396}
diff --git a/drivers/mmc/core/sd_ops.h b/drivers/mmc/core/sd_ops.h
index 9742d8a30664..ffc2305d905f 100644
--- a/drivers/mmc/core/sd_ops.h
+++ b/drivers/mmc/core/sd_ops.h
@@ -19,6 +19,7 @@ int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca);
19int mmc_app_send_scr(struct mmc_card *card, u32 *scr); 19int mmc_app_send_scr(struct mmc_card *card, u32 *scr);
20int mmc_sd_switch(struct mmc_card *card, int mode, int group, 20int mmc_sd_switch(struct mmc_card *card, int mode, int group,
21 u8 value, u8 *resp); 21 u8 value, u8 *resp);
22int mmc_app_sd_status(struct mmc_card *card, void *ssr);
22 23
23#endif 24#endif
24 25
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index b9dee28ee7d0..bd2755e8d9a3 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -18,6 +18,7 @@
18 18
19#include "core.h" 19#include "core.h"
20#include "bus.h" 20#include "bus.h"
21#include "sd.h"
21#include "sdio_bus.h" 22#include "sdio_bus.h"
22#include "mmc_ops.h" 23#include "mmc_ops.h"
23#include "sd_ops.h" 24#include "sd_ops.h"
@@ -62,13 +63,19 @@ static int sdio_init_func(struct mmc_card *card, unsigned int fn)
62 63
63 func->num = fn; 64 func->num = fn;
64 65
65 ret = sdio_read_fbr(func); 66 if (!(card->quirks & MMC_QUIRK_NONSTD_SDIO)) {
66 if (ret) 67 ret = sdio_read_fbr(func);
67 goto fail; 68 if (ret)
69 goto fail;
68 70
69 ret = sdio_read_func_cis(func); 71 ret = sdio_read_func_cis(func);
70 if (ret) 72 if (ret)
71 goto fail; 73 goto fail;
74 } else {
75 func->vendor = func->card->cis.vendor;
76 func->device = func->card->cis.device;
77 func->max_blksize = func->card->cis.blksize;
78 }
72 79
73 card->sdio_func[fn - 1] = func; 80 card->sdio_func[fn - 1] = func;
74 81
@@ -159,9 +166,7 @@ static int sdio_enable_wide(struct mmc_card *card)
159 if (ret) 166 if (ret)
160 return ret; 167 return ret;
161 168
162 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); 169 return 1;
163
164 return 0;
165} 170}
166 171
167/* 172/*
@@ -221,10 +226,34 @@ static int sdio_disable_wide(struct mmc_card *card)
221 return 0; 226 return 0;
222} 227}
223 228
229
230static int sdio_enable_4bit_bus(struct mmc_card *card)
231{
232 int err;
233
234 if (card->type == MMC_TYPE_SDIO)
235 return sdio_enable_wide(card);
236
237 if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
238 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
239 err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4);
240 if (err)
241 return err;
242 } else
243 return 0;
244
245 err = sdio_enable_wide(card);
246 if (err <= 0)
247 mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
248
249 return err;
250}
251
252
224/* 253/*
225 * Test if the card supports high-speed mode and, if so, switch to it. 254 * Test if the card supports high-speed mode and, if so, switch to it.
226 */ 255 */
227static int sdio_enable_hs(struct mmc_card *card) 256static int mmc_sdio_switch_hs(struct mmc_card *card, int enable)
228{ 257{
229 int ret; 258 int ret;
230 u8 speed; 259 u8 speed;
@@ -239,16 +268,56 @@ static int sdio_enable_hs(struct mmc_card *card)
239 if (ret) 268 if (ret)
240 return ret; 269 return ret;
241 270
242 speed |= SDIO_SPEED_EHS; 271 if (enable)
272 speed |= SDIO_SPEED_EHS;
273 else
274 speed &= ~SDIO_SPEED_EHS;
243 275
244 ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_SPEED, speed, NULL); 276 ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_SPEED, speed, NULL);
245 if (ret) 277 if (ret)
246 return ret; 278 return ret;
247 279
248 mmc_card_set_highspeed(card); 280 return 1;
249 mmc_set_timing(card->host, MMC_TIMING_SD_HS); 281}
250 282
251 return 0; 283/*
284 * Enable SDIO/combo card's high-speed mode. Return 0/1 if [not]supported.
285 */
286static int sdio_enable_hs(struct mmc_card *card)
287{
288 int ret;
289
290 ret = mmc_sdio_switch_hs(card, true);
291 if (ret <= 0 || card->type == MMC_TYPE_SDIO)
292 return ret;
293
294 ret = mmc_sd_switch_hs(card);
295 if (ret <= 0)
296 mmc_sdio_switch_hs(card, false);
297
298 return ret;
299}
300
301static unsigned mmc_sdio_get_max_clock(struct mmc_card *card)
302{
303 unsigned max_dtr;
304
305 if (mmc_card_highspeed(card)) {
306 /*
307 * The SDIO specification doesn't mention how
308 * the CIS transfer speed register relates to
309 * high-speed, but it seems that 50 MHz is
310 * mandatory.
311 */
312 max_dtr = 50000000;
313 } else {
314 max_dtr = card->cis.max_dtr;
315 }
316
317 if (card->type == MMC_TYPE_SD_COMBO)
318 max_dtr = min(max_dtr, mmc_sd_get_max_clock(card));
319
320 return max_dtr;
252} 321}
253 322
254/* 323/*
@@ -293,7 +362,24 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
293 goto err; 362 goto err;
294 } 363 }
295 364
296 card->type = MMC_TYPE_SDIO; 365 err = mmc_sd_get_cid(host, host->ocr & ocr, card->raw_cid);
366
367 if (!err) {
368 card->type = MMC_TYPE_SD_COMBO;
369
370 if (oldcard && (oldcard->type != MMC_TYPE_SD_COMBO ||
371 memcmp(card->raw_cid, oldcard->raw_cid, sizeof(card->raw_cid)) != 0)) {
372 mmc_remove_card(card);
373 return -ENOENT;
374 }
375 } else {
376 card->type = MMC_TYPE_SDIO;
377
378 if (oldcard && oldcard->type != MMC_TYPE_SDIO) {
379 mmc_remove_card(card);
380 return -ENOENT;
381 }
382 }
297 383
298 /* 384 /*
299 * Call the optional HC's init_card function to handle quirks. 385 * Call the optional HC's init_card function to handle quirks.
@@ -313,6 +399,17 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
313 } 399 }
314 400
315 /* 401 /*
402 * Read CSD, before selecting the card
403 */
404 if (!oldcard && card->type == MMC_TYPE_SD_COMBO) {
405 err = mmc_sd_get_csd(host, card);
406 if (err)
407 return err;
408
409 mmc_decode_cid(card);
410 }
411
412 /*
316 * Select card, as all following commands rely on that. 413 * Select card, as all following commands rely on that.
317 */ 414 */
318 if (!powered_resume && !mmc_host_is_spi(host)) { 415 if (!powered_resume && !mmc_host_is_spi(host)) {
@@ -321,6 +418,23 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
321 goto remove; 418 goto remove;
322 } 419 }
323 420
421 if (card->quirks & MMC_QUIRK_NONSTD_SDIO) {
422 /*
423 * This is non-standard SDIO device, meaning it doesn't
424 * have any CIA (Common I/O area) registers present.
425 * It's host's responsibility to fill cccr and cis
426 * structures in init_card().
427 */
428 mmc_set_clock(host, card->cis.max_dtr);
429
430 if (card->cccr.high_speed) {
431 mmc_card_set_highspeed(card);
432 mmc_set_timing(card->host, MMC_TIMING_SD_HS);
433 }
434
435 goto finish;
436 }
437
324 /* 438 /*
325 * Read the common registers. 439 * Read the common registers.
326 */ 440 */
@@ -339,43 +453,57 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
339 int same = (card->cis.vendor == oldcard->cis.vendor && 453 int same = (card->cis.vendor == oldcard->cis.vendor &&
340 card->cis.device == oldcard->cis.device); 454 card->cis.device == oldcard->cis.device);
341 mmc_remove_card(card); 455 mmc_remove_card(card);
342 if (!same) { 456 if (!same)
343 err = -ENOENT; 457 return -ENOENT;
344 goto err; 458
345 }
346 card = oldcard; 459 card = oldcard;
347 return 0; 460 return 0;
348 } 461 }
349 462
463 if (card->type == MMC_TYPE_SD_COMBO) {
464 err = mmc_sd_setup_card(host, card, oldcard != NULL);
465 /* handle as SDIO-only card if memory init failed */
466 if (err) {
467 mmc_go_idle(host);
468 if (mmc_host_is_spi(host))
469 /* should not fail, as it worked previously */
470 mmc_spi_set_crc(host, use_spi_crc);
471 card->type = MMC_TYPE_SDIO;
472 } else
473 card->dev.type = &sd_type;
474 }
475
476 /*
477 * If needed, disconnect card detection pull-up resistor.
478 */
479 err = sdio_disable_cd(card);
480 if (err)
481 goto remove;
482
350 /* 483 /*
351 * Switch to high-speed (if supported). 484 * Switch to high-speed (if supported).
352 */ 485 */
353 err = sdio_enable_hs(card); 486 err = sdio_enable_hs(card);
354 if (err) 487 if (err > 0)
488 mmc_sd_go_highspeed(card);
489 else if (err)
355 goto remove; 490 goto remove;
356 491
357 /* 492 /*
358 * Change to the card's maximum speed. 493 * Change to the card's maximum speed.
359 */ 494 */
360 if (mmc_card_highspeed(card)) { 495 mmc_set_clock(host, mmc_sdio_get_max_clock(card));
361 /*
362 * The SDIO specification doesn't mention how
363 * the CIS transfer speed register relates to
364 * high-speed, but it seems that 50 MHz is
365 * mandatory.
366 */
367 mmc_set_clock(host, 50000000);
368 } else {
369 mmc_set_clock(host, card->cis.max_dtr);
370 }
371 496
372 /* 497 /*
373 * Switch to wider bus (if supported). 498 * Switch to wider bus (if supported).
374 */ 499 */
375 err = sdio_enable_wide(card); 500 err = sdio_enable_4bit_bus(card);
376 if (err) 501 if (err > 0)
502 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
503 else if (err)
377 goto remove; 504 goto remove;
378 505
506finish:
379 if (!oldcard) 507 if (!oldcard)
380 host->card = card; 508 host->card = card;
381 return 0; 509 return 0;
@@ -487,9 +615,14 @@ static int mmc_sdio_resume(struct mmc_host *host)
487 mmc_claim_host(host); 615 mmc_claim_host(host);
488 err = mmc_sdio_init_card(host, host->ocr, host->card, 616 err = mmc_sdio_init_card(host, host->ocr, host->card,
489 (host->pm_flags & MMC_PM_KEEP_POWER)); 617 (host->pm_flags & MMC_PM_KEEP_POWER));
490 if (!err) 618 if (!err) {
491 /* We may have switched to 1-bit mode during suspend. */ 619 /* We may have switched to 1-bit mode during suspend. */
492 err = sdio_enable_wide(host->card); 620 err = sdio_enable_4bit_bus(host->card);
621 if (err > 0) {
622 mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
623 err = 0;
624 }
625 }
493 if (!err && host->sdio_irqs) 626 if (!err && host->sdio_irqs)
494 mmc_signal_sdio_irq(host); 627 mmc_signal_sdio_irq(host);
495 mmc_release_host(host); 628 mmc_release_host(host);
@@ -574,13 +707,6 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
574 card->sdio_funcs = 0; 707 card->sdio_funcs = 0;
575 708
576 /* 709 /*
577 * If needed, disconnect card detection pull-up resistor.
578 */
579 err = sdio_disable_cd(card);
580 if (err)
581 goto remove;
582
583 /*
584 * Initialize (but don't add) all present functions. 710 * Initialize (but don't add) all present functions.
585 */ 711 */
586 for (i = 0; i < funcs; i++, card->sdio_funcs++) { 712 for (i = 0; i < funcs; i++, card->sdio_funcs++) {
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index d25e22cee4c4..c997474c649f 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -121,6 +121,15 @@ config MMC_SDHCI_PLTFM
121 121
122 If unsure, say N. 122 If unsure, say N.
123 123
124config MMC_SDHCI_CNS3XXX
125 bool "SDHCI support on the Cavium Networks CNS3xxx SoC"
126 depends on ARCH_CNS3XXX
127 depends on MMC_SDHCI_PLTFM
128 help
129 This selects the SDHCI support for CNS3xxx System-on-Chip devices.
130
131 If unsure, say N.
132
124config MMC_SDHCI_S3C 133config MMC_SDHCI_S3C
125 tristate "SDHCI support on Samsung S3C SoC" 134 tristate "SDHCI support on Samsung S3C SoC"
126 depends on MMC_SDHCI && (PLAT_S3C24XX || PLAT_S3C64XX) 135 depends on MMC_SDHCI && (PLAT_S3C24XX || PLAT_S3C64XX)
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index f4e53c98d944..fe0ba4e2b8b0 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -12,7 +12,6 @@ obj-$(CONFIG_MMC_IMX) += imxmmc.o
12obj-$(CONFIG_MMC_MXC) += mxcmmc.o 12obj-$(CONFIG_MMC_MXC) += mxcmmc.o
13obj-$(CONFIG_MMC_SDHCI) += sdhci.o 13obj-$(CONFIG_MMC_SDHCI) += sdhci.o
14obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o 14obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o
15obj-$(CONFIG_MMC_SDHCI_PLTFM) += sdhci-pltfm.o
16obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o 15obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
17obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o 16obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
18obj-$(CONFIG_MMC_WBSD) += wbsd.o 17obj-$(CONFIG_MMC_WBSD) += wbsd.o
@@ -38,6 +37,10 @@ obj-$(CONFIG_SDH_BFIN) += bfin_sdh.o
38obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o 37obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o
39obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o 38obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o
40 39
40obj-$(CONFIG_MMC_SDHCI_PLTFM) += sdhci-platform.o
41sdhci-platform-y := sdhci-pltfm.o
42sdhci-platform-$(CONFIG_MMC_SDHCI_CNS3XXX) += sdhci-cns3xxx.o
43
41obj-$(CONFIG_MMC_SDHCI_OF) += sdhci-of.o 44obj-$(CONFIG_MMC_SDHCI_OF) += sdhci-of.o
42sdhci-of-y := sdhci-of-core.o 45sdhci-of-y := sdhci-of-core.o
43sdhci-of-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o 46sdhci-of-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 7b0f3ef50f96..1145ea0792e6 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -1536,6 +1536,7 @@ static int __devexit mmc_spi_remove(struct spi_device *spi)
1536#if defined(CONFIG_OF) 1536#if defined(CONFIG_OF)
1537static struct of_device_id mmc_spi_of_match_table[] __devinitdata = { 1537static struct of_device_id mmc_spi_of_match_table[] __devinitdata = {
1538 { .compatible = "mmc-spi-slot", }, 1538 { .compatible = "mmc-spi-slot", },
1539 {},
1539}; 1540};
1540#endif 1541#endif
1541 1542
diff --git a/drivers/mmc/host/msm_sdcc.c b/drivers/mmc/host/msm_sdcc.c
index 24e09454e522..6824917f5c60 100644
--- a/drivers/mmc/host/msm_sdcc.c
+++ b/drivers/mmc/host/msm_sdcc.c
@@ -1057,26 +1057,10 @@ msmsdcc_init_dma(struct msmsdcc_host *host)
1057 return 0; 1057 return 0;
1058} 1058}
1059 1059
1060#ifdef CONFIG_MMC_MSM7X00A_RESUME_IN_WQ
1061static void
1062do_resume_work(struct work_struct *work)
1063{
1064 struct msmsdcc_host *host =
1065 container_of(work, struct msmsdcc_host, resume_task);
1066 struct mmc_host *mmc = host->mmc;
1067
1068 if (mmc) {
1069 mmc_resume_host(mmc);
1070 if (host->stat_irq)
1071 enable_irq(host->stat_irq);
1072 }
1073}
1074#endif
1075
1076static int 1060static int
1077msmsdcc_probe(struct platform_device *pdev) 1061msmsdcc_probe(struct platform_device *pdev)
1078{ 1062{
1079 struct mmc_platform_data *plat = pdev->dev.platform_data; 1063 struct msm_mmc_platform_data *plat = pdev->dev.platform_data;
1080 struct msmsdcc_host *host; 1064 struct msmsdcc_host *host;
1081 struct mmc_host *mmc; 1065 struct mmc_host *mmc;
1082 struct resource *cmd_irqres = NULL; 1066 struct resource *cmd_irqres = NULL;
@@ -1145,15 +1129,6 @@ msmsdcc_probe(struct platform_device *pdev)
1145 host->dmares = dmares; 1129 host->dmares = dmares;
1146 spin_lock_init(&host->lock); 1130 spin_lock_init(&host->lock);
1147 1131
1148#ifdef CONFIG_MMC_EMBEDDED_SDIO
1149 if (plat->embedded_sdio)
1150 mmc_set_embedded_sdio_data(mmc,
1151 &plat->embedded_sdio->cis,
1152 &plat->embedded_sdio->cccr,
1153 plat->embedded_sdio->funcs,
1154 plat->embedded_sdio->num_funcs);
1155#endif
1156
1157 /* 1132 /*
1158 * Setup DMA 1133 * Setup DMA
1159 */ 1134 */
diff --git a/drivers/mmc/host/msm_sdcc.h b/drivers/mmc/host/msm_sdcc.h
index da0039c9285e..ff2b0f74f6f4 100644
--- a/drivers/mmc/host/msm_sdcc.h
+++ b/drivers/mmc/host/msm_sdcc.h
@@ -225,7 +225,7 @@ struct msmsdcc_host {
225 225
226 u32 pwr; 226 u32 pwr;
227 u32 saved_irq0mask; /* MMCIMASK0 reg value */ 227 u32 saved_irq0mask; /* MMCIMASK0 reg value */
228 struct mmc_platform_data *plat; 228 struct msm_mmc_platform_data *plat;
229 229
230 struct timer_list timer; 230 struct timer_list timer;
231 unsigned int oldstat; 231 unsigned int oldstat;
@@ -235,10 +235,6 @@ struct msmsdcc_host {
235 int cmdpoll; 235 int cmdpoll;
236 struct msmsdcc_stats stats; 236 struct msmsdcc_stats stats;
237 237
238#ifdef CONFIG_MMC_MSM7X00A_RESUME_IN_WQ
239 struct work_struct resume_task;
240#endif
241
242 /* Command parameters */ 238 /* Command parameters */
243 unsigned int cmd_timeout; 239 unsigned int cmd_timeout;
244 unsigned int cmd_pio_irqmask; 240 unsigned int cmd_pio_irqmask;
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index b032828c6126..4a8776f8afdd 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -28,6 +28,7 @@
28#include <linux/clk.h> 28#include <linux/clk.h>
29#include <linux/mmc/host.h> 29#include <linux/mmc/host.h>
30#include <linux/mmc/core.h> 30#include <linux/mmc/core.h>
31#include <linux/mmc/mmc.h>
31#include <linux/io.h> 32#include <linux/io.h>
32#include <linux/semaphore.h> 33#include <linux/semaphore.h>
33#include <linux/gpio.h> 34#include <linux/gpio.h>
@@ -78,6 +79,7 @@
78#define INT_EN_MASK 0x307F0033 79#define INT_EN_MASK 0x307F0033
79#define BWR_ENABLE (1 << 4) 80#define BWR_ENABLE (1 << 4)
80#define BRR_ENABLE (1 << 5) 81#define BRR_ENABLE (1 << 5)
82#define DTO_ENABLE (1 << 20)
81#define INIT_STREAM (1 << 1) 83#define INIT_STREAM (1 << 1)
82#define DP_SELECT (1 << 21) 84#define DP_SELECT (1 << 21)
83#define DDIR (1 << 4) 85#define DDIR (1 << 4)
@@ -523,7 +525,8 @@ static void omap_hsmmc_stop_clock(struct omap_hsmmc_host *host)
523 dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stoped\n"); 525 dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stoped\n");
524} 526}
525 527
526static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host) 528static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host,
529 struct mmc_command *cmd)
527{ 530{
528 unsigned int irq_mask; 531 unsigned int irq_mask;
529 532
@@ -532,6 +535,10 @@ static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host)
532 else 535 else
533 irq_mask = INT_EN_MASK; 536 irq_mask = INT_EN_MASK;
534 537
538 /* Disable timeout for erases */
539 if (cmd->opcode == MMC_ERASE)
540 irq_mask &= ~DTO_ENABLE;
541
535 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); 542 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
536 OMAP_HSMMC_WRITE(host->base, ISE, irq_mask); 543 OMAP_HSMMC_WRITE(host->base, ISE, irq_mask);
537 OMAP_HSMMC_WRITE(host->base, IE, irq_mask); 544 OMAP_HSMMC_WRITE(host->base, IE, irq_mask);
@@ -782,7 +789,7 @@ omap_hsmmc_start_command(struct omap_hsmmc_host *host, struct mmc_command *cmd,
782 mmc_hostname(host->mmc), cmd->opcode, cmd->arg); 789 mmc_hostname(host->mmc), cmd->opcode, cmd->arg);
783 host->cmd = cmd; 790 host->cmd = cmd;
784 791
785 omap_hsmmc_enable_irq(host); 792 omap_hsmmc_enable_irq(host, cmd);
786 793
787 host->response_busy = 0; 794 host->response_busy = 0;
788 if (cmd->flags & MMC_RSP_PRESENT) { 795 if (cmd->flags & MMC_RSP_PRESENT) {
@@ -1273,8 +1280,11 @@ static void omap_hsmmc_dma_cb(int lch, u16 ch_status, void *cb_data)
1273 struct mmc_data *data = host->mrq->data; 1280 struct mmc_data *data = host->mrq->data;
1274 int dma_ch, req_in_progress; 1281 int dma_ch, req_in_progress;
1275 1282
1276 if (ch_status & OMAP2_DMA_MISALIGNED_ERR_IRQ) 1283 if (!(ch_status & OMAP_DMA_BLOCK_IRQ)) {
1277 dev_dbg(mmc_dev(host->mmc), "MISALIGNED_ADRS_ERR\n"); 1284 dev_warn(mmc_dev(host->mmc), "unexpected dma status %x\n",
1285 ch_status);
1286 return;
1287 }
1278 1288
1279 spin_lock(&host->irq_lock); 1289 spin_lock(&host->irq_lock);
1280 if (host->dma_ch < 0) { 1290 if (host->dma_ch < 0) {
@@ -1598,6 +1608,14 @@ static int omap_hsmmc_get_ro(struct mmc_host *mmc)
1598 return mmc_slot(host).get_ro(host->dev, 0); 1608 return mmc_slot(host).get_ro(host->dev, 0);
1599} 1609}
1600 1610
1611static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card)
1612{
1613 struct omap_hsmmc_host *host = mmc_priv(mmc);
1614
1615 if (mmc_slot(host).init_card)
1616 mmc_slot(host).init_card(card);
1617}
1618
1601static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host) 1619static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host)
1602{ 1620{
1603 u32 hctl, capa, value; 1621 u32 hctl, capa, value;
@@ -1869,6 +1887,7 @@ static const struct mmc_host_ops omap_hsmmc_ops = {
1869 .set_ios = omap_hsmmc_set_ios, 1887 .set_ios = omap_hsmmc_set_ios,
1870 .get_cd = omap_hsmmc_get_cd, 1888 .get_cd = omap_hsmmc_get_cd,
1871 .get_ro = omap_hsmmc_get_ro, 1889 .get_ro = omap_hsmmc_get_ro,
1890 .init_card = omap_hsmmc_init_card,
1872 /* NYET -- enable_sdio_irq */ 1891 /* NYET -- enable_sdio_irq */
1873}; 1892};
1874 1893
@@ -1879,6 +1898,7 @@ static const struct mmc_host_ops omap_hsmmc_ps_ops = {
1879 .set_ios = omap_hsmmc_set_ios, 1898 .set_ios = omap_hsmmc_set_ios,
1880 .get_cd = omap_hsmmc_get_cd, 1899 .get_cd = omap_hsmmc_get_cd,
1881 .get_ro = omap_hsmmc_get_ro, 1900 .get_ro = omap_hsmmc_get_ro,
1901 .init_card = omap_hsmmc_init_card,
1882 /* NYET -- enable_sdio_irq */ 1902 /* NYET -- enable_sdio_irq */
1883}; 1903};
1884 1904
@@ -2094,12 +2114,25 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
2094 mmc->max_seg_size = mmc->max_req_size; 2114 mmc->max_seg_size = mmc->max_req_size;
2095 2115
2096 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED | 2116 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
2097 MMC_CAP_WAIT_WHILE_BUSY; 2117 MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE;
2098 2118
2099 if (mmc_slot(host).wires >= 8) 2119 switch (mmc_slot(host).wires) {
2120 case 8:
2100 mmc->caps |= MMC_CAP_8_BIT_DATA; 2121 mmc->caps |= MMC_CAP_8_BIT_DATA;
2101 else if (mmc_slot(host).wires >= 4) 2122 /* Fall through */
2123 case 4:
2102 mmc->caps |= MMC_CAP_4_BIT_DATA; 2124 mmc->caps |= MMC_CAP_4_BIT_DATA;
2125 break;
2126 case 1:
2127 /* Nothing to crib here */
2128 case 0:
2129 /* Assuming nothing was given by board, Core use's 1-Bit */
2130 break;
2131 default:
2132 /* Completely unexpected.. Core goes with 1-Bit Width */
2133 dev_crit(mmc_dev(host->mmc), "Invalid width %d\n used!"
2134 "using 1 instead\n", mmc_slot(host).wires);
2135 }
2103 2136
2104 if (mmc_slot(host).nonremovable) 2137 if (mmc_slot(host).nonremovable)
2105 mmc->caps |= MMC_CAP_NONREMOVABLE; 2138 mmc->caps |= MMC_CAP_NONREMOVABLE;
diff --git a/drivers/mmc/host/sdhci-cns3xxx.c b/drivers/mmc/host/sdhci-cns3xxx.c
new file mode 100644
index 000000000000..b7050b380d5f
--- /dev/null
+++ b/drivers/mmc/host/sdhci-cns3xxx.c
@@ -0,0 +1,97 @@
1/*
2 * SDHCI support for CNS3xxx SoC
3 *
4 * Copyright 2008 Cavium Networks
5 * Copyright 2010 MontaVista Software, LLC.
6 *
7 * Authors: Scott Shu
8 * Anton Vorontsov <avorontsov@mvista.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/delay.h>
16#include <linux/device.h>
17#include <linux/mmc/host.h>
18#include <linux/sdhci-pltfm.h>
19#include <mach/cns3xxx.h>
20#include "sdhci.h"
21#include "sdhci-pltfm.h"
22
23static unsigned int sdhci_cns3xxx_get_max_clk(struct sdhci_host *host)
24{
25 return 150000000;
26}
27
28static void sdhci_cns3xxx_set_clock(struct sdhci_host *host, unsigned int clock)
29{
30 struct device *dev = mmc_dev(host->mmc);
31 int div = 1;
32 u16 clk;
33 unsigned long timeout;
34
35 if (clock == host->clock)
36 return;
37
38 sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
39
40 if (clock == 0)
41 goto out;
42
43 while (host->max_clk / div > clock) {
44 /*
45 * On CNS3xxx divider grows linearly up to 4, and then
46 * exponentially up to 256.
47 */
48 if (div < 4)
49 div += 1;
50 else if (div < 256)
51 div *= 2;
52 else
53 break;
54 }
55
56 dev_dbg(dev, "desired SD clock: %d, actual: %d\n",
57 clock, host->max_clk / div);
58
59 /* Divide by 3 is special. */
60 if (div != 3)
61 div >>= 1;
62
63 clk = div << SDHCI_DIVIDER_SHIFT;
64 clk |= SDHCI_CLOCK_INT_EN;
65 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
66
67 timeout = 20;
68 while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
69 & SDHCI_CLOCK_INT_STABLE)) {
70 if (timeout == 0) {
71 dev_warn(dev, "clock is unstable");
72 break;
73 }
74 timeout--;
75 mdelay(1);
76 }
77
78 clk |= SDHCI_CLOCK_CARD_EN;
79 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
80out:
81 host->clock = clock;
82}
83
84static struct sdhci_ops sdhci_cns3xxx_ops = {
85 .get_max_clock = sdhci_cns3xxx_get_max_clk,
86 .set_clock = sdhci_cns3xxx_set_clock,
87};
88
89struct sdhci_pltfm_data sdhci_cns3xxx_pdata = {
90 .ops = &sdhci_cns3xxx_ops,
91 .quirks = SDHCI_QUIRK_BROKEN_DMA |
92 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
93 SDHCI_QUIRK_INVERTED_WRITE_PROTECT |
94 SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN |
95 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
96 SDHCI_QUIRK_NONSTANDARD_CLOCK,
97};
diff --git a/drivers/mmc/host/sdhci-of-core.c b/drivers/mmc/host/sdhci-of-core.c
index a2e9820cd42f..c51b71174c1d 100644
--- a/drivers/mmc/host/sdhci-of-core.c
+++ b/drivers/mmc/host/sdhci-of-core.c
@@ -85,14 +85,14 @@ void sdhci_be32bs_writeb(struct sdhci_host *host, u8 val, int reg)
85 85
86#ifdef CONFIG_PM 86#ifdef CONFIG_PM
87 87
88static int sdhci_of_suspend(struct of_device *ofdev, pm_message_t state) 88static int sdhci_of_suspend(struct platform_device *ofdev, pm_message_t state)
89{ 89{
90 struct sdhci_host *host = dev_get_drvdata(&ofdev->dev); 90 struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);
91 91
92 return mmc_suspend_host(host->mmc); 92 return mmc_suspend_host(host->mmc);
93} 93}
94 94
95static int sdhci_of_resume(struct of_device *ofdev) 95static int sdhci_of_resume(struct platform_device *ofdev)
96{ 96{
97 struct sdhci_host *host = dev_get_drvdata(&ofdev->dev); 97 struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);
98 98
@@ -115,7 +115,7 @@ static bool __devinit sdhci_of_wp_inverted(struct device_node *np)
115 return machine_is(mpc837x_rdb) || machine_is(mpc837x_mds); 115 return machine_is(mpc837x_rdb) || machine_is(mpc837x_mds);
116} 116}
117 117
118static int __devinit sdhci_of_probe(struct of_device *ofdev, 118static int __devinit sdhci_of_probe(struct platform_device *ofdev,
119 const struct of_device_id *match) 119 const struct of_device_id *match)
120{ 120{
121 struct device_node *np = ofdev->dev.of_node; 121 struct device_node *np = ofdev->dev.of_node;
@@ -154,6 +154,10 @@ static int __devinit sdhci_of_probe(struct of_device *ofdev,
154 host->ops = &sdhci_of_data->ops; 154 host->ops = &sdhci_of_data->ops;
155 } 155 }
156 156
157 if (of_get_property(np, "sdhci,auto-cmd12", NULL))
158 host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12;
159
160
157 if (of_get_property(np, "sdhci,1-bit-only", NULL)) 161 if (of_get_property(np, "sdhci,1-bit-only", NULL))
158 host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA; 162 host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA;
159 163
@@ -179,7 +183,7 @@ err_addr_map:
179 return ret; 183 return ret;
180} 184}
181 185
182static int __devexit sdhci_of_remove(struct of_device *ofdev) 186static int __devexit sdhci_of_remove(struct platform_device *ofdev)
183{ 187{
184 struct sdhci_host *host = dev_get_drvdata(&ofdev->dev); 188 struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);
185 189
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index 65483fdea45b..e8aa99deae9a 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -17,6 +17,7 @@
17#include <linux/pci.h> 17#include <linux/pci.h>
18#include <linux/dma-mapping.h> 18#include <linux/dma-mapping.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/device.h>
20 21
21#include <linux/mmc/host.h> 22#include <linux/mmc/host.h>
22 23
@@ -84,7 +85,30 @@ static int ricoh_probe(struct sdhci_pci_chip *chip)
84 if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG || 85 if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
85 chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY) 86 chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
86 chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET; 87 chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
88 return 0;
89}
90
91static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot)
92{
93 slot->host->caps =
94 ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT)
95 & SDHCI_TIMEOUT_CLK_MASK) |
96
97 ((0x21 << SDHCI_CLOCK_BASE_SHIFT)
98 & SDHCI_CLOCK_BASE_MASK) |
87 99
100 SDHCI_TIMEOUT_CLK_UNIT |
101 SDHCI_CAN_VDD_330 |
102 SDHCI_CAN_DO_SDMA;
103 return 0;
104}
105
106static int ricoh_mmc_resume(struct sdhci_pci_chip *chip)
107{
108 /* Apply a delay to allow controller to settle */
109 /* Otherwise it becomes confused if card state changed
110 during suspend */
111 msleep(500);
88 return 0; 112 return 0;
89} 113}
90 114
@@ -95,6 +119,15 @@ static const struct sdhci_pci_fixes sdhci_ricoh = {
95 SDHCI_QUIRK_CLOCK_BEFORE_RESET, 119 SDHCI_QUIRK_CLOCK_BEFORE_RESET,
96}; 120};
97 121
122static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {
123 .probe_slot = ricoh_mmc_probe_slot,
124 .resume = ricoh_mmc_resume,
125 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
126 SDHCI_QUIRK_CLOCK_BEFORE_RESET |
127 SDHCI_QUIRK_NO_CARD_NO_RESET |
128 SDHCI_QUIRK_MISSING_CAPS
129};
130
98static const struct sdhci_pci_fixes sdhci_ene_712 = { 131static const struct sdhci_pci_fixes sdhci_ene_712 = {
99 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE | 132 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
100 SDHCI_QUIRK_BROKEN_DMA, 133 SDHCI_QUIRK_BROKEN_DMA,
@@ -374,6 +407,22 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
374 }, 407 },
375 408
376 { 409 {
410 .vendor = PCI_VENDOR_ID_RICOH,
411 .device = 0x843,
412 .subvendor = PCI_ANY_ID,
413 .subdevice = PCI_ANY_ID,
414 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
415 },
416
417 {
418 .vendor = PCI_VENDOR_ID_RICOH,
419 .device = 0xe822,
420 .subvendor = PCI_ANY_ID,
421 .subdevice = PCI_ANY_ID,
422 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
423 },
424
425 {
377 .vendor = PCI_VENDOR_ID_ENE, 426 .vendor = PCI_VENDOR_ID_ENE,
378 .device = PCI_DEVICE_ID_ENE_CB712_SD, 427 .device = PCI_DEVICE_ID_ENE_CB712_SD,
379 .subvendor = PCI_ANY_ID, 428 .subvendor = PCI_ANY_ID,
diff --git a/drivers/mmc/host/sdhci-pltfm.c b/drivers/mmc/host/sdhci-pltfm.c
index b6ee0d719698..e045e3c61dde 100644
--- a/drivers/mmc/host/sdhci-pltfm.c
+++ b/drivers/mmc/host/sdhci-pltfm.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/highmem.h> 26#include <linux/highmem.h>
27#include <linux/mod_devicetable.h>
27#include <linux/platform_device.h> 28#include <linux/platform_device.h>
28 29
29#include <linux/mmc/host.h> 30#include <linux/mmc/host.h>
@@ -32,6 +33,7 @@
32#include <linux/sdhci-pltfm.h> 33#include <linux/sdhci-pltfm.h>
33 34
34#include "sdhci.h" 35#include "sdhci.h"
36#include "sdhci-pltfm.h"
35 37
36/*****************************************************************************\ 38/*****************************************************************************\
37 * * 39 * *
@@ -51,10 +53,14 @@ static struct sdhci_ops sdhci_pltfm_ops = {
51static int __devinit sdhci_pltfm_probe(struct platform_device *pdev) 53static int __devinit sdhci_pltfm_probe(struct platform_device *pdev)
52{ 54{
53 struct sdhci_pltfm_data *pdata = pdev->dev.platform_data; 55 struct sdhci_pltfm_data *pdata = pdev->dev.platform_data;
56 const struct platform_device_id *platid = platform_get_device_id(pdev);
54 struct sdhci_host *host; 57 struct sdhci_host *host;
55 struct resource *iomem; 58 struct resource *iomem;
56 int ret; 59 int ret;
57 60
61 if (!pdata && platid && platid->driver_data)
62 pdata = (void *)platid->driver_data;
63
58 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 64 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
59 if (!iomem) { 65 if (!iomem) {
60 ret = -ENOMEM; 66 ret = -ENOMEM;
@@ -150,6 +156,15 @@ static int __devexit sdhci_pltfm_remove(struct platform_device *pdev)
150 return 0; 156 return 0;
151} 157}
152 158
159static const struct platform_device_id sdhci_pltfm_ids[] = {
160 { "sdhci", },
161#ifdef CONFIG_MMC_SDHCI_CNS3XXX
162 { "sdhci-cns3xxx", (kernel_ulong_t)&sdhci_cns3xxx_pdata },
163#endif
164 { },
165};
166MODULE_DEVICE_TABLE(platform, sdhci_pltfm_ids);
167
153static struct platform_driver sdhci_pltfm_driver = { 168static struct platform_driver sdhci_pltfm_driver = {
154 .driver = { 169 .driver = {
155 .name = "sdhci", 170 .name = "sdhci",
@@ -157,6 +172,7 @@ static struct platform_driver sdhci_pltfm_driver = {
157 }, 172 },
158 .probe = sdhci_pltfm_probe, 173 .probe = sdhci_pltfm_probe,
159 .remove = __devexit_p(sdhci_pltfm_remove), 174 .remove = __devexit_p(sdhci_pltfm_remove),
175 .id_table = sdhci_pltfm_ids,
160}; 176};
161 177
162/*****************************************************************************\ 178/*****************************************************************************\
@@ -181,4 +197,3 @@ module_exit(sdhci_drv_exit);
181MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver"); 197MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
182MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>"); 198MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
183MODULE_LICENSE("GPL v2"); 199MODULE_LICENSE("GPL v2");
184MODULE_ALIAS("platform:sdhci");
diff --git a/drivers/mmc/host/sdhci-pltfm.h b/drivers/mmc/host/sdhci-pltfm.h
new file mode 100644
index 000000000000..900f32902f73
--- /dev/null
+++ b/drivers/mmc/host/sdhci-pltfm.h
@@ -0,0 +1,18 @@
1/*
2 * Copyright 2010 MontaVista Software, LLC.
3 *
4 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef _DRIVERS_MMC_SDHCI_PLTFM_H
12#define _DRIVERS_MMC_SDHCI_PLTFM_H
13
14#include <linux/sdhci-pltfm.h>
15
16extern struct sdhci_pltfm_data sdhci_cns3xxx_pdata;
17
18#endif /* _DRIVERS_MMC_SDHCI_PLTFM_H */
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index ad30f074ee15..0a7f2614c6f0 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -18,6 +18,7 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/clk.h> 19#include <linux/clk.h>
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/gpio.h>
21 22
22#include <linux/mmc/host.h> 23#include <linux/mmc/host.h>
23 24
@@ -44,6 +45,8 @@ struct sdhci_s3c {
44 struct resource *ioarea; 45 struct resource *ioarea;
45 struct s3c_sdhci_platdata *pdata; 46 struct s3c_sdhci_platdata *pdata;
46 unsigned int cur_clk; 47 unsigned int cur_clk;
48 int ext_cd_irq;
49 int ext_cd_gpio;
47 50
48 struct clk *clk_io; 51 struct clk *clk_io;
49 struct clk *clk_bus[MAX_BUS_CLK]; 52 struct clk *clk_bus[MAX_BUS_CLK];
@@ -110,11 +113,6 @@ static unsigned int sdhci_s3c_get_max_clk(struct sdhci_host *host)
110 return max; 113 return max;
111} 114}
112 115
113static unsigned int sdhci_s3c_get_timeout_clk(struct sdhci_host *host)
114{
115 return sdhci_s3c_get_max_clk(host) / 1000000;
116}
117
118/** 116/**
119 * sdhci_s3c_consider_clock - consider one the bus clocks for current setting 117 * sdhci_s3c_consider_clock - consider one the bus clocks for current setting
120 * @ourhost: Our SDHCI instance. 118 * @ourhost: Our SDHCI instance.
@@ -188,7 +186,6 @@ static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock)
188 186
189 ourhost->cur_clk = best_src; 187 ourhost->cur_clk = best_src;
190 host->max_clk = clk_get_rate(clk); 188 host->max_clk = clk_get_rate(clk);
191 host->timeout_clk = sdhci_s3c_get_timeout_clk(host);
192 189
193 ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2); 190 ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
194 ctrl &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK; 191 ctrl &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK;
@@ -209,12 +206,93 @@ static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock)
209 } 206 }
210} 207}
211 208
209/**
210 * sdhci_s3c_get_min_clock - callback to get minimal supported clock value
211 * @host: The SDHCI host being queried
212 *
213 * To init mmc host properly a minimal clock value is needed. For high system
214 * bus clock's values the standard formula gives values out of allowed range.
215 * The clock still can be set to lower values, if clock source other then
216 * system bus is selected.
217*/
218static unsigned int sdhci_s3c_get_min_clock(struct sdhci_host *host)
219{
220 struct sdhci_s3c *ourhost = to_s3c(host);
221 unsigned int delta, min = UINT_MAX;
222 int src;
223
224 for (src = 0; src < MAX_BUS_CLK; src++) {
225 delta = sdhci_s3c_consider_clock(ourhost, src, 0);
226 if (delta == UINT_MAX)
227 continue;
228 /* delta is a negative value in this case */
229 if (-delta < min)
230 min = -delta;
231 }
232 return min;
233}
234
212static struct sdhci_ops sdhci_s3c_ops = { 235static struct sdhci_ops sdhci_s3c_ops = {
213 .get_max_clock = sdhci_s3c_get_max_clk, 236 .get_max_clock = sdhci_s3c_get_max_clk,
214 .get_timeout_clock = sdhci_s3c_get_timeout_clk,
215 .set_clock = sdhci_s3c_set_clock, 237 .set_clock = sdhci_s3c_set_clock,
238 .get_min_clock = sdhci_s3c_get_min_clock,
216}; 239};
217 240
241static void sdhci_s3c_notify_change(struct platform_device *dev, int state)
242{
243 struct sdhci_host *host = platform_get_drvdata(dev);
244 if (host) {
245 mutex_lock(&host->lock);
246 if (state) {
247 dev_dbg(&dev->dev, "card inserted.\n");
248 host->flags &= ~SDHCI_DEVICE_DEAD;
249 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
250 } else {
251 dev_dbg(&dev->dev, "card removed.\n");
252 host->flags |= SDHCI_DEVICE_DEAD;
253 host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
254 }
255 sdhci_card_detect(host);
256 mutex_unlock(&host->lock);
257 }
258}
259
260static irqreturn_t sdhci_s3c_gpio_card_detect_thread(int irq, void *dev_id)
261{
262 struct sdhci_s3c *sc = dev_id;
263 int status = gpio_get_value(sc->ext_cd_gpio);
264 if (sc->pdata->ext_cd_gpio_invert)
265 status = !status;
266 sdhci_s3c_notify_change(sc->pdev, status);
267 return IRQ_HANDLED;
268}
269
270static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc)
271{
272 struct s3c_sdhci_platdata *pdata = sc->pdata;
273 struct device *dev = &sc->pdev->dev;
274
275 if (gpio_request(pdata->ext_cd_gpio, "SDHCI EXT CD") == 0) {
276 sc->ext_cd_gpio = pdata->ext_cd_gpio;
277 sc->ext_cd_irq = gpio_to_irq(pdata->ext_cd_gpio);
278 if (sc->ext_cd_irq &&
279 request_threaded_irq(sc->ext_cd_irq, NULL,
280 sdhci_s3c_gpio_card_detect_thread,
281 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
282 dev_name(dev), sc) == 0) {
283 int status = gpio_get_value(sc->ext_cd_gpio);
284 if (pdata->ext_cd_gpio_invert)
285 status = !status;
286 sdhci_s3c_notify_change(sc->pdev, status);
287 } else {
288 dev_warn(dev, "cannot request irq for card detect\n");
289 sc->ext_cd_irq = 0;
290 }
291 } else {
292 dev_err(dev, "cannot request gpio for card detect\n");
293 }
294}
295
218static int __devinit sdhci_s3c_probe(struct platform_device *pdev) 296static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
219{ 297{
220 struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data; 298 struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data;
@@ -252,6 +330,7 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
252 sc->host = host; 330 sc->host = host;
253 sc->pdev = pdev; 331 sc->pdev = pdev;
254 sc->pdata = pdata; 332 sc->pdata = pdata;
333 sc->ext_cd_gpio = -1; /* invalid gpio number */
255 334
256 platform_set_drvdata(pdev, host); 335 platform_set_drvdata(pdev, host);
257 336
@@ -318,6 +397,7 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
318 397
319 /* Setup quirks for the controller */ 398 /* Setup quirks for the controller */
320 host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC; 399 host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC;
400 host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT;
321 401
322#ifndef CONFIG_MMC_SDHCI_S3C_DMA 402#ifndef CONFIG_MMC_SDHCI_S3C_DMA
323 403
@@ -332,15 +412,34 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
332 * SDHCI block, or a missing configuration that needs to be set. */ 412 * SDHCI block, or a missing configuration that needs to be set. */
333 host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ; 413 host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ;
334 414
415 if (pdata->cd_type == S3C_SDHCI_CD_NONE ||
416 pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
417 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
418
419 if (pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
420 host->mmc->caps = MMC_CAP_NONREMOVABLE;
421
335 host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR | 422 host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR |
336 SDHCI_QUIRK_32BIT_DMA_SIZE); 423 SDHCI_QUIRK_32BIT_DMA_SIZE);
337 424
425 /* HSMMC on Samsung SoCs uses SDCLK as timeout clock */
426 host->quirks |= SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK;
427
338 ret = sdhci_add_host(host); 428 ret = sdhci_add_host(host);
339 if (ret) { 429 if (ret) {
340 dev_err(dev, "sdhci_add_host() failed\n"); 430 dev_err(dev, "sdhci_add_host() failed\n");
341 goto err_add_host; 431 goto err_add_host;
342 } 432 }
343 433
434 /* The following two methods of card detection might call
435 sdhci_s3c_notify_change() immediately, so they can be called
436 only after sdhci_add_host(). Setup errors are ignored. */
437 if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_init)
438 pdata->ext_cd_init(&sdhci_s3c_notify_change);
439 if (pdata->cd_type == S3C_SDHCI_CD_GPIO &&
440 gpio_is_valid(pdata->ext_cd_gpio))
441 sdhci_s3c_setup_card_detect_gpio(sc);
442
344 return 0; 443 return 0;
345 444
346 err_add_host: 445 err_add_host:
@@ -365,10 +464,20 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
365 464
366static int __devexit sdhci_s3c_remove(struct platform_device *pdev) 465static int __devexit sdhci_s3c_remove(struct platform_device *pdev)
367{ 466{
467 struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data;
368 struct sdhci_host *host = platform_get_drvdata(pdev); 468 struct sdhci_host *host = platform_get_drvdata(pdev);
369 struct sdhci_s3c *sc = sdhci_priv(host); 469 struct sdhci_s3c *sc = sdhci_priv(host);
370 int ptr; 470 int ptr;
371 471
472 if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_cleanup)
473 pdata->ext_cd_cleanup(&sdhci_s3c_notify_change);
474
475 if (sc->ext_cd_irq)
476 free_irq(sc->ext_cd_irq, sc);
477
478 if (gpio_is_valid(sc->ext_cd_gpio))
479 gpio_free(sc->ext_cd_gpio);
480
372 sdhci_remove_host(host, 1); 481 sdhci_remove_host(host, 1);
373 482
374 for (ptr = 0; ptr < 3; ptr++) { 483 for (ptr = 0; ptr < 3; ptr++) {
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index c6d1bd8d4ac4..785512133b50 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -19,6 +19,7 @@
19#include <linux/dma-mapping.h> 19#include <linux/dma-mapping.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/scatterlist.h> 21#include <linux/scatterlist.h>
22#include <linux/regulator/consumer.h>
22 23
23#include <linux/leds.h> 24#include <linux/leds.h>
24 25
@@ -817,8 +818,12 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,
817 WARN_ON(!host->data); 818 WARN_ON(!host->data);
818 819
819 mode = SDHCI_TRNS_BLK_CNT_EN; 820 mode = SDHCI_TRNS_BLK_CNT_EN;
820 if (data->blocks > 1) 821 if (data->blocks > 1) {
821 mode |= SDHCI_TRNS_MULTI; 822 if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12)
823 mode |= SDHCI_TRNS_MULTI | SDHCI_TRNS_ACMD12;
824 else
825 mode |= SDHCI_TRNS_MULTI;
826 }
822 if (data->flags & MMC_DATA_READ) 827 if (data->flags & MMC_DATA_READ)
823 mode |= SDHCI_TRNS_READ; 828 mode |= SDHCI_TRNS_READ;
824 if (host->flags & SDHCI_REQ_USE_DMA) 829 if (host->flags & SDHCI_REQ_USE_DMA)
@@ -1108,6 +1113,12 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1108#ifndef SDHCI_USE_LEDS_CLASS 1113#ifndef SDHCI_USE_LEDS_CLASS
1109 sdhci_activate_led(host); 1114 sdhci_activate_led(host);
1110#endif 1115#endif
1116 if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) {
1117 if (mrq->stop) {
1118 mrq->data->stop = NULL;
1119 mrq->stop = NULL;
1120 }
1121 }
1111 1122
1112 host->mrq = mrq; 1123 host->mrq = mrq;
1113 1124
@@ -1159,6 +1170,11 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1159 1170
1160 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); 1171 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
1161 1172
1173 if (ios->bus_width == MMC_BUS_WIDTH_8)
1174 ctrl |= SDHCI_CTRL_8BITBUS;
1175 else
1176 ctrl &= ~SDHCI_CTRL_8BITBUS;
1177
1162 if (ios->bus_width == MMC_BUS_WIDTH_4) 1178 if (ios->bus_width == MMC_BUS_WIDTH_4)
1163 ctrl |= SDHCI_CTRL_4BITBUS; 1179 ctrl |= SDHCI_CTRL_4BITBUS;
1164 else 1180 else
@@ -1603,7 +1619,10 @@ int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state)
1603 1619
1604 free_irq(host->irq, host); 1620 free_irq(host->irq, host);
1605 1621
1606 return 0; 1622 if (host->vmmc)
1623 ret = regulator_disable(host->vmmc);
1624
1625 return ret;
1607} 1626}
1608 1627
1609EXPORT_SYMBOL_GPL(sdhci_suspend_host); 1628EXPORT_SYMBOL_GPL(sdhci_suspend_host);
@@ -1612,6 +1631,13 @@ int sdhci_resume_host(struct sdhci_host *host)
1612{ 1631{
1613 int ret; 1632 int ret;
1614 1633
1634 if (host->vmmc) {
1635 int ret = regulator_enable(host->vmmc);
1636 if (ret)
1637 return ret;
1638 }
1639
1640
1615 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { 1641 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
1616 if (host->ops->enable_dma) 1642 if (host->ops->enable_dma)
1617 host->ops->enable_dma(host); 1643 host->ops->enable_dma(host);
@@ -1687,7 +1713,8 @@ int sdhci_add_host(struct sdhci_host *host)
1687 host->version); 1713 host->version);
1688 } 1714 }
1689 1715
1690 caps = sdhci_readl(host, SDHCI_CAPABILITIES); 1716 caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
1717 sdhci_readl(host, SDHCI_CAPABILITIES);
1691 1718
1692 if (host->quirks & SDHCI_QUIRK_FORCE_DMA) 1719 if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
1693 host->flags |= SDHCI_USE_SDMA; 1720 host->flags |= SDHCI_USE_SDMA;
@@ -1785,13 +1812,12 @@ int sdhci_add_host(struct sdhci_host *host)
1785 * Set host parameters. 1812 * Set host parameters.
1786 */ 1813 */
1787 mmc->ops = &sdhci_ops; 1814 mmc->ops = &sdhci_ops;
1788 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK && 1815 if (host->ops->get_min_clock)
1789 host->ops->set_clock && host->ops->get_min_clock)
1790 mmc->f_min = host->ops->get_min_clock(host); 1816 mmc->f_min = host->ops->get_min_clock(host);
1791 else 1817 else
1792 mmc->f_min = host->max_clk / 256; 1818 mmc->f_min = host->max_clk / 256;
1793 mmc->f_max = host->max_clk; 1819 mmc->f_max = host->max_clk;
1794 mmc->caps = MMC_CAP_SDIO_IRQ; 1820 mmc->caps |= MMC_CAP_SDIO_IRQ;
1795 1821
1796 if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA)) 1822 if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
1797 mmc->caps |= MMC_CAP_4_BIT_DATA; 1823 mmc->caps |= MMC_CAP_4_BIT_DATA;
@@ -1884,6 +1910,14 @@ int sdhci_add_host(struct sdhci_host *host)
1884 if (ret) 1910 if (ret)
1885 goto untasklet; 1911 goto untasklet;
1886 1912
1913 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
1914 if (IS_ERR(host->vmmc)) {
1915 printk(KERN_INFO "%s: no vmmc regulator found\n", mmc_hostname(mmc));
1916 host->vmmc = NULL;
1917 } else {
1918 regulator_enable(host->vmmc);
1919 }
1920
1887 sdhci_init(host, 0); 1921 sdhci_init(host, 0);
1888 1922
1889#ifdef CONFIG_MMC_DEBUG 1923#ifdef CONFIG_MMC_DEBUG
@@ -1968,6 +2002,11 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
1968 tasklet_kill(&host->card_tasklet); 2002 tasklet_kill(&host->card_tasklet);
1969 tasklet_kill(&host->finish_tasklet); 2003 tasklet_kill(&host->finish_tasklet);
1970 2004
2005 if (host->vmmc) {
2006 regulator_disable(host->vmmc);
2007 regulator_put(host->vmmc);
2008 }
2009
1971 kfree(host->adma_desc); 2010 kfree(host->adma_desc);
1972 kfree(host->align_buffer); 2011 kfree(host->align_buffer);
1973 2012
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index c8468134adc9..036cfae76368 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -72,6 +72,7 @@
72#define SDHCI_CTRL_ADMA1 0x08 72#define SDHCI_CTRL_ADMA1 0x08
73#define SDHCI_CTRL_ADMA32 0x10 73#define SDHCI_CTRL_ADMA32 0x10
74#define SDHCI_CTRL_ADMA64 0x18 74#define SDHCI_CTRL_ADMA64 0x18
75#define SDHCI_CTRL_8BITBUS 0x20
75 76
76#define SDHCI_POWER_CONTROL 0x29 77#define SDHCI_POWER_CONTROL 0x29
77#define SDHCI_POWER_ON 0x01 78#define SDHCI_POWER_ON 0x01
@@ -240,12 +241,18 @@ struct sdhci_host {
240#define SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN (1<<25) 241#define SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN (1<<25)
241/* Controller cannot support End Attribute in NOP ADMA descriptor */ 242/* Controller cannot support End Attribute in NOP ADMA descriptor */
242#define SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC (1<<26) 243#define SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC (1<<26)
244/* Controller is missing device caps. Use caps provided by host */
245#define SDHCI_QUIRK_MISSING_CAPS (1<<27)
246/* Controller uses Auto CMD12 command to stop the transfer */
247#define SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12 (1<<28)
243 248
244 int irq; /* Device IRQ */ 249 int irq; /* Device IRQ */
245 void __iomem * ioaddr; /* Mapped address */ 250 void __iomem * ioaddr; /* Mapped address */
246 251
247 const struct sdhci_ops *ops; /* Low level hw interface */ 252 const struct sdhci_ops *ops; /* Low level hw interface */
248 253
254 struct regulator *vmmc; /* Power regulator */
255
249 /* Internal data */ 256 /* Internal data */
250 struct mmc_host *mmc; /* MMC structure */ 257 struct mmc_host *mmc; /* MMC structure */
251 u64 dma_mask; /* custom DMA mask */ 258 u64 dma_mask; /* custom DMA mask */
@@ -292,6 +299,8 @@ struct sdhci_host {
292 299
293 struct timer_list timer; /* Timer for timeouts */ 300 struct timer_list timer; /* Timer for timeouts */
294 301
302 unsigned int caps; /* Alternative capabilities */
303
295 unsigned long private[0] ____cacheline_aligned; 304 unsigned long private[0] ____cacheline_aligned;
296}; 305};
297 306
@@ -407,6 +416,7 @@ static inline void *sdhci_priv(struct sdhci_host *host)
407 return (void *)host->private; 416 return (void *)host->private;
408} 417}
409 418
419extern void sdhci_card_detect(struct sdhci_host *host);
410extern int sdhci_add_host(struct sdhci_host *host); 420extern int sdhci_add_host(struct sdhci_host *host);
411extern void sdhci_remove_host(struct sdhci_host *host, int dead); 421extern void sdhci_remove_host(struct sdhci_host *host, int dead);
412 422
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
index 6ac5f9f28ac3..00af55d7afba 100644
--- a/drivers/mtd/maps/physmap_of.c
+++ b/drivers/mtd/maps/physmap_of.c
@@ -43,7 +43,7 @@ struct of_flash {
43#ifdef CONFIG_MTD_PARTITIONS 43#ifdef CONFIG_MTD_PARTITIONS
44#define OF_FLASH_PARTS(info) ((info)->parts) 44#define OF_FLASH_PARTS(info) ((info)->parts)
45 45
46static int parse_obsolete_partitions(struct of_device *dev, 46static int parse_obsolete_partitions(struct platform_device *dev,
47 struct of_flash *info, 47 struct of_flash *info,
48 struct device_node *dp) 48 struct device_node *dp)
49{ 49{
@@ -93,7 +93,7 @@ static int parse_obsolete_partitions(struct of_device *dev,
93#define parse_partitions(info, dev) (0) 93#define parse_partitions(info, dev) (0)
94#endif /* MTD_PARTITIONS */ 94#endif /* MTD_PARTITIONS */
95 95
96static int of_flash_remove(struct of_device *dev) 96static int of_flash_remove(struct platform_device *dev)
97{ 97{
98 struct of_flash *info; 98 struct of_flash *info;
99 int i; 99 int i;
@@ -140,7 +140,7 @@ static int of_flash_remove(struct of_device *dev)
140/* Helper function to handle probing of the obsolete "direct-mapped" 140/* Helper function to handle probing of the obsolete "direct-mapped"
141 * compatible binding, which has an extra "probe-type" property 141 * compatible binding, which has an extra "probe-type" property
142 * describing the type of flash probe necessary. */ 142 * describing the type of flash probe necessary. */
143static struct mtd_info * __devinit obsolete_probe(struct of_device *dev, 143static struct mtd_info * __devinit obsolete_probe(struct platform_device *dev,
144 struct map_info *map) 144 struct map_info *map)
145{ 145{
146 struct device_node *dp = dev->dev.of_node; 146 struct device_node *dp = dev->dev.of_node;
@@ -215,7 +215,7 @@ static void __devinit of_free_probes(const char **probes)
215} 215}
216#endif 216#endif
217 217
218static int __devinit of_flash_probe(struct of_device *dev, 218static int __devinit of_flash_probe(struct platform_device *dev,
219 const struct of_device_id *match) 219 const struct of_device_id *match)
220{ 220{
221#ifdef CONFIG_MTD_PARTITIONS 221#ifdef CONFIG_MTD_PARTITIONS
diff --git a/drivers/mtd/maps/sun_uflash.c b/drivers/mtd/maps/sun_uflash.c
index 8984236a8d0a..3582ba1f9b09 100644
--- a/drivers/mtd/maps/sun_uflash.c
+++ b/drivers/mtd/maps/sun_uflash.c
@@ -48,7 +48,7 @@ struct map_info uflash_map_templ = {
48 .bankwidth = UFLASH_BUSWIDTH, 48 .bankwidth = UFLASH_BUSWIDTH,
49}; 49};
50 50
51int uflash_devinit(struct of_device *op, struct device_node *dp) 51int uflash_devinit(struct platform_device *op, struct device_node *dp)
52{ 52{
53 struct uflash_dev *up; 53 struct uflash_dev *up;
54 54
@@ -108,7 +108,7 @@ int uflash_devinit(struct of_device *op, struct device_node *dp)
108 return 0; 108 return 0;
109} 109}
110 110
111static int __devinit uflash_probe(struct of_device *op, const struct of_device_id *match) 111static int __devinit uflash_probe(struct platform_device *op, const struct of_device_id *match)
112{ 112{
113 struct device_node *dp = op->dev.of_node; 113 struct device_node *dp = op->dev.of_node;
114 114
@@ -121,7 +121,7 @@ static int __devinit uflash_probe(struct of_device *op, const struct of_device_i
121 return uflash_devinit(op, dp); 121 return uflash_devinit(op, dp);
122} 122}
123 123
124static int __devexit uflash_remove(struct of_device *op) 124static int __devexit uflash_remove(struct platform_device *op)
125{ 125{
126 struct uflash_dev *up = dev_get_drvdata(&op->dev); 126 struct uflash_dev *up = dev_get_drvdata(&op->dev);
127 127
diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
index 5084cc517944..80de0bff6c3a 100644
--- a/drivers/mtd/nand/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/fsl_elbc_nand.c
@@ -958,7 +958,7 @@ static int __devinit fsl_elbc_ctrl_init(struct fsl_elbc_ctrl *ctrl)
958 return 0; 958 return 0;
959} 959}
960 960
961static int fsl_elbc_ctrl_remove(struct of_device *ofdev) 961static int fsl_elbc_ctrl_remove(struct platform_device *ofdev)
962{ 962{
963 struct fsl_elbc_ctrl *ctrl = dev_get_drvdata(&ofdev->dev); 963 struct fsl_elbc_ctrl *ctrl = dev_get_drvdata(&ofdev->dev);
964 int i; 964 int i;
@@ -1013,7 +1013,7 @@ static irqreturn_t fsl_elbc_ctrl_irq(int irqno, void *data)
1013 * in the chip probe function. 1013 * in the chip probe function.
1014*/ 1014*/
1015 1015
1016static int __devinit fsl_elbc_ctrl_probe(struct of_device *ofdev, 1016static int __devinit fsl_elbc_ctrl_probe(struct platform_device *ofdev,
1017 const struct of_device_id *match) 1017 const struct of_device_id *match)
1018{ 1018{
1019 struct device_node *child; 1019 struct device_node *child;
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
index 1312eda57ba6..4eff8b25e5af 100644
--- a/drivers/mtd/nand/fsl_upm.c
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -217,7 +217,7 @@ err:
217 return ret; 217 return ret;
218} 218}
219 219
220static int __devinit fun_probe(struct of_device *ofdev, 220static int __devinit fun_probe(struct platform_device *ofdev,
221 const struct of_device_id *ofid) 221 const struct of_device_id *ofid)
222{ 222{
223 struct fsl_upm_nand *fun; 223 struct fsl_upm_nand *fun;
@@ -335,7 +335,7 @@ err1:
335 return ret; 335 return ret;
336} 336}
337 337
338static int __devexit fun_remove(struct of_device *ofdev) 338static int __devexit fun_remove(struct platform_device *ofdev)
339{ 339{
340 struct fsl_upm_nand *fun = dev_get_drvdata(&ofdev->dev); 340 struct fsl_upm_nand *fun = dev_get_drvdata(&ofdev->dev);
341 int i; 341 int i;
diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c
index 0a130dcaa129..df0c1da4ff49 100644
--- a/drivers/mtd/nand/mpc5121_nfc.c
+++ b/drivers/mtd/nand/mpc5121_nfc.c
@@ -647,7 +647,7 @@ static void mpc5121_nfc_free(struct device *dev, struct mtd_info *mtd)
647 iounmap(prv->csreg); 647 iounmap(prv->csreg);
648} 648}
649 649
650static int __devinit mpc5121_nfc_probe(struct of_device *op, 650static int __devinit mpc5121_nfc_probe(struct platform_device *op,
651 const struct of_device_id *match) 651 const struct of_device_id *match)
652{ 652{
653 struct device_node *rootnode, *dn = op->dev.of_node; 653 struct device_node *rootnode, *dn = op->dev.of_node;
@@ -869,7 +869,7 @@ error:
869 return retval; 869 return retval;
870} 870}
871 871
872static int __devexit mpc5121_nfc_remove(struct of_device *op) 872static int __devexit mpc5121_nfc_remove(struct platform_device *op)
873{ 873{
874 struct device *dev = &op->dev; 874 struct device *dev = &op->dev;
875 struct mtd_info *mtd = dev_get_drvdata(dev); 875 struct mtd_info *mtd = dev_get_drvdata(dev);
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 16a1714df008..a3c7473dd409 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -889,17 +889,17 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
889} 889}
890 890
891/** 891/**
892 * __nand_unlock - [REPLACABLE] unlocks specified locked blockes 892 * __nand_unlock - [REPLACEABLE] unlocks specified locked blocks
893 * 893 *
894 * @param mtd - mtd info 894 * @mtd: mtd info
895 * @param ofs - offset to start unlock from 895 * @ofs: offset to start unlock from
896 * @param len - length to unlock 896 * @len: length to unlock
897 * @invert - when = 0, unlock the range of blocks within the lower and 897 * @invert: when = 0, unlock the range of blocks within the lower and
898 * upper boundary address 898 * upper boundary address
899 * whne = 1, unlock the range of blocks outside the boundaries 899 * when = 1, unlock the range of blocks outside the boundaries
900 * of the lower and upper boundary address 900 * of the lower and upper boundary address
901 * 901 *
902 * @return - unlock status 902 * return - unlock status
903 */ 903 */
904static int __nand_unlock(struct mtd_info *mtd, loff_t ofs, 904static int __nand_unlock(struct mtd_info *mtd, loff_t ofs,
905 uint64_t len, int invert) 905 uint64_t len, int invert)
@@ -931,13 +931,13 @@ static int __nand_unlock(struct mtd_info *mtd, loff_t ofs,
931} 931}
932 932
933/** 933/**
934 * nand_unlock - [REPLACABLE] unlocks specified locked blockes 934 * nand_unlock - [REPLACEABLE] unlocks specified locked blocks
935 * 935 *
936 * @param mtd - mtd info 936 * @mtd: mtd info
937 * @param ofs - offset to start unlock from 937 * @ofs: offset to start unlock from
938 * @param len - length to unlock 938 * @len: length to unlock
939 * 939 *
940 * @return - unlock status 940 * return - unlock status
941 */ 941 */
942int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) 942int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
943{ 943{
@@ -982,16 +982,16 @@ out:
982} 982}
983 983
984/** 984/**
985 * nand_lock - [REPLACABLE] locks all blockes present in the device 985 * nand_lock - [REPLACEABLE] locks all blocks present in the device
986 * 986 *
987 * @param mtd - mtd info 987 * @mtd: mtd info
988 * @param ofs - offset to start unlock from 988 * @ofs: offset to start unlock from
989 * @param len - length to unlock 989 * @len: length to unlock
990 * 990 *
991 * @return - lock status 991 * return - lock status
992 * 992 *
993 * This feature is not support in many NAND parts. 'Micron' NAND parts 993 * This feature is not supported in many NAND parts. 'Micron' NAND parts
994 * do have this feature, but it allows only to lock all blocks not for 994 * do have this feature, but it allows only to lock all blocks, not for
995 * specified range for block. 995 * specified range for block.
996 * 996 *
997 * Implementing 'lock' feature by making use of 'unlock', for now. 997 * Implementing 'lock' feature by making use of 'unlock', for now.
@@ -2093,6 +2093,7 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
2093 * nand_fill_oob - [Internal] Transfer client buffer to oob 2093 * nand_fill_oob - [Internal] Transfer client buffer to oob
2094 * @chip: nand chip structure 2094 * @chip: nand chip structure
2095 * @oob: oob data buffer 2095 * @oob: oob data buffer
2096 * @len: oob data write length
2096 * @ops: oob ops structure 2097 * @ops: oob ops structure
2097 */ 2098 */
2098static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, size_t len, 2099static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, size_t len,
diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
index 98fd2bdf8be1..510554e6c115 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -35,7 +35,7 @@
35 35
36 36
37struct ndfc_controller { 37struct ndfc_controller {
38 struct of_device *ofdev; 38 struct platform_device *ofdev;
39 void __iomem *ndfcbase; 39 void __iomem *ndfcbase;
40 struct mtd_info mtd; 40 struct mtd_info mtd;
41 struct nand_chip chip; 41 struct nand_chip chip;
@@ -225,7 +225,7 @@ err:
225 return ret; 225 return ret;
226} 226}
227 227
228static int __devinit ndfc_probe(struct of_device *ofdev, 228static int __devinit ndfc_probe(struct platform_device *ofdev,
229 const struct of_device_id *match) 229 const struct of_device_id *match)
230{ 230{
231 struct ndfc_controller *ndfc = &ndfc_ctrl; 231 struct ndfc_controller *ndfc = &ndfc_ctrl;
@@ -277,7 +277,7 @@ static int __devinit ndfc_probe(struct of_device *ofdev,
277 return 0; 277 return 0;
278} 278}
279 279
280static int __devexit ndfc_remove(struct of_device *ofdev) 280static int __devexit ndfc_remove(struct platform_device *ofdev)
281{ 281{
282 struct ndfc_controller *ndfc = dev_get_drvdata(&ofdev->dev); 282 struct ndfc_controller *ndfc = dev_get_drvdata(&ofdev->dev);
283 283
diff --git a/drivers/mtd/nand/pasemi_nand.c b/drivers/mtd/nand/pasemi_nand.c
index f02af24d033a..6ddb2461d740 100644
--- a/drivers/mtd/nand/pasemi_nand.c
+++ b/drivers/mtd/nand/pasemi_nand.c
@@ -89,7 +89,7 @@ int pasemi_device_ready(struct mtd_info *mtd)
89 return !!(inl(lpcctl) & LBICTRL_LPCCTL_NR); 89 return !!(inl(lpcctl) & LBICTRL_LPCCTL_NR);
90} 90}
91 91
92static int __devinit pasemi_nand_probe(struct of_device *ofdev, 92static int __devinit pasemi_nand_probe(struct platform_device *ofdev,
93 const struct of_device_id *match) 93 const struct of_device_id *match)
94{ 94{
95 struct pci_dev *pdev; 95 struct pci_dev *pdev;
@@ -185,7 +185,7 @@ static int __devinit pasemi_nand_probe(struct of_device *ofdev,
185 return err; 185 return err;
186} 186}
187 187
188static int __devexit pasemi_nand_remove(struct of_device *ofdev) 188static int __devexit pasemi_nand_remove(struct platform_device *ofdev)
189{ 189{
190 struct nand_chip *chip; 190 struct nand_chip *chip;
191 191
diff --git a/drivers/mtd/nand/socrates_nand.c b/drivers/mtd/nand/socrates_nand.c
index cc728b12de82..a8e403eebedb 100644
--- a/drivers/mtd/nand/socrates_nand.c
+++ b/drivers/mtd/nand/socrates_nand.c
@@ -162,7 +162,7 @@ static const char *part_probes[] = { "cmdlinepart", NULL };
162/* 162/*
163 * Probe for the NAND device. 163 * Probe for the NAND device.
164 */ 164 */
165static int __devinit socrates_nand_probe(struct of_device *ofdev, 165static int __devinit socrates_nand_probe(struct platform_device *ofdev,
166 const struct of_device_id *ofid) 166 const struct of_device_id *ofid)
167{ 167{
168 struct socrates_nand_host *host; 168 struct socrates_nand_host *host;
@@ -276,7 +276,7 @@ out:
276/* 276/*
277 * Remove a NAND device. 277 * Remove a NAND device.
278 */ 278 */
279static int __devexit socrates_nand_remove(struct of_device *ofdev) 279static int __devexit socrates_nand_remove(struct platform_device *ofdev)
280{ 280{
281 struct socrates_nand_host *host = dev_get_drvdata(&ofdev->dev); 281 struct socrates_nand_host *host = dev_get_drvdata(&ofdev->dev);
282 struct mtd_info *mtd = &host->mtd; 282 struct mtd_info *mtd = &host->mtd;
diff --git a/drivers/net/arm/ixp4xx_eth.c b/drivers/net/arm/ixp4xx_eth.c
index 4f1cc7164ad9..6028226a7270 100644
--- a/drivers/net/arm/ixp4xx_eth.c
+++ b/drivers/net/arm/ixp4xx_eth.c
@@ -241,7 +241,7 @@ static inline void memcpy_swab32(u32 *dest, u32 *src, int cnt)
241 241
242static spinlock_t mdio_lock; 242static spinlock_t mdio_lock;
243static struct eth_regs __iomem *mdio_regs; /* mdio command and status only */ 243static struct eth_regs __iomem *mdio_regs; /* mdio command and status only */
244struct mii_bus *mdio_bus; 244static struct mii_bus *mdio_bus;
245static int ports_open; 245static int ports_open;
246static struct port *npe_port_tab[MAX_NPES]; 246static struct port *npe_port_tab[MAX_NPES];
247static struct dma_pool *dma_pool; 247static struct dma_pool *dma_pool;
diff --git a/drivers/net/caif/caif_spi_slave.c b/drivers/net/caif/caif_spi_slave.c
index 077ccf840edf..2111dbfea6fe 100644
--- a/drivers/net/caif/caif_spi_slave.c
+++ b/drivers/net/caif/caif_spi_slave.c
@@ -22,13 +22,13 @@
22#include <net/caif/caif_spi.h> 22#include <net/caif/caif_spi.h>
23 23
24#ifndef CONFIG_CAIF_SPI_SYNC 24#ifndef CONFIG_CAIF_SPI_SYNC
25#define SPI_DATA_POS SPI_CMD_SZ 25#define SPI_DATA_POS 0
26static inline int forward_to_spi_cmd(struct cfspi *cfspi) 26static inline int forward_to_spi_cmd(struct cfspi *cfspi)
27{ 27{
28 return cfspi->rx_cpck_len; 28 return cfspi->rx_cpck_len;
29} 29}
30#else 30#else
31#define SPI_DATA_POS 0 31#define SPI_DATA_POS SPI_CMD_SZ
32static inline int forward_to_spi_cmd(struct cfspi *cfspi) 32static inline int forward_to_spi_cmd(struct cfspi *cfspi)
33{ 33{
34 return 0; 34 return 0;
diff --git a/drivers/net/can/mscan/mpc5xxx_can.c b/drivers/net/can/mscan/mpc5xxx_can.c
index af753936e835..b1bdc909090f 100644
--- a/drivers/net/can/mscan/mpc5xxx_can.c
+++ b/drivers/net/can/mscan/mpc5xxx_can.c
@@ -38,7 +38,7 @@
38 38
39struct mpc5xxx_can_data { 39struct mpc5xxx_can_data {
40 unsigned int type; 40 unsigned int type;
41 u32 (*get_clock)(struct of_device *ofdev, const char *clock_name, 41 u32 (*get_clock)(struct platform_device *ofdev, const char *clock_name,
42 int *mscan_clksrc); 42 int *mscan_clksrc);
43}; 43};
44 44
@@ -48,7 +48,7 @@ static struct of_device_id __devinitdata mpc52xx_cdm_ids[] = {
48 {} 48 {}
49}; 49};
50 50
51static u32 __devinit mpc52xx_can_get_clock(struct of_device *ofdev, 51static u32 __devinit mpc52xx_can_get_clock(struct platform_device *ofdev,
52 const char *clock_name, 52 const char *clock_name,
53 int *mscan_clksrc) 53 int *mscan_clksrc)
54{ 54{
@@ -101,7 +101,7 @@ static u32 __devinit mpc52xx_can_get_clock(struct of_device *ofdev,
101 return freq; 101 return freq;
102} 102}
103#else /* !CONFIG_PPC_MPC52xx */ 103#else /* !CONFIG_PPC_MPC52xx */
104static u32 __devinit mpc52xx_can_get_clock(struct of_device *ofdev, 104static u32 __devinit mpc52xx_can_get_clock(struct platform_device *ofdev,
105 const char *clock_name, 105 const char *clock_name,
106 int *mscan_clksrc) 106 int *mscan_clksrc)
107{ 107{
@@ -129,7 +129,7 @@ static struct of_device_id __devinitdata mpc512x_clock_ids[] = {
129 {} 129 {}
130}; 130};
131 131
132static u32 __devinit mpc512x_can_get_clock(struct of_device *ofdev, 132static u32 __devinit mpc512x_can_get_clock(struct platform_device *ofdev,
133 const char *clock_name, 133 const char *clock_name,
134 int *mscan_clksrc) 134 int *mscan_clksrc)
135{ 135{
@@ -239,7 +239,7 @@ exit_unmap:
239 return freq; 239 return freq;
240} 240}
241#else /* !CONFIG_PPC_MPC512x */ 241#else /* !CONFIG_PPC_MPC512x */
242static u32 __devinit mpc512x_can_get_clock(struct of_device *ofdev, 242static u32 __devinit mpc512x_can_get_clock(struct platform_device *ofdev,
243 const char *clock_name, 243 const char *clock_name,
244 int *mscan_clksrc) 244 int *mscan_clksrc)
245{ 245{
@@ -247,7 +247,7 @@ static u32 __devinit mpc512x_can_get_clock(struct of_device *ofdev,
247} 247}
248#endif /* CONFIG_PPC_MPC512x */ 248#endif /* CONFIG_PPC_MPC512x */
249 249
250static int __devinit mpc5xxx_can_probe(struct of_device *ofdev, 250static int __devinit mpc5xxx_can_probe(struct platform_device *ofdev,
251 const struct of_device_id *id) 251 const struct of_device_id *id)
252{ 252{
253 struct mpc5xxx_can_data *data = (struct mpc5xxx_can_data *)id->data; 253 struct mpc5xxx_can_data *data = (struct mpc5xxx_can_data *)id->data;
@@ -317,7 +317,7 @@ exit_unmap_mem:
317 return err; 317 return err;
318} 318}
319 319
320static int __devexit mpc5xxx_can_remove(struct of_device *ofdev) 320static int __devexit mpc5xxx_can_remove(struct platform_device *ofdev)
321{ 321{
322 struct net_device *dev = dev_get_drvdata(&ofdev->dev); 322 struct net_device *dev = dev_get_drvdata(&ofdev->dev);
323 struct mscan_priv *priv = netdev_priv(dev); 323 struct mscan_priv *priv = netdev_priv(dev);
@@ -334,7 +334,7 @@ static int __devexit mpc5xxx_can_remove(struct of_device *ofdev)
334 334
335#ifdef CONFIG_PM 335#ifdef CONFIG_PM
336static struct mscan_regs saved_regs; 336static struct mscan_regs saved_regs;
337static int mpc5xxx_can_suspend(struct of_device *ofdev, pm_message_t state) 337static int mpc5xxx_can_suspend(struct platform_device *ofdev, pm_message_t state)
338{ 338{
339 struct net_device *dev = dev_get_drvdata(&ofdev->dev); 339 struct net_device *dev = dev_get_drvdata(&ofdev->dev);
340 struct mscan_priv *priv = netdev_priv(dev); 340 struct mscan_priv *priv = netdev_priv(dev);
@@ -345,7 +345,7 @@ static int mpc5xxx_can_suspend(struct of_device *ofdev, pm_message_t state)
345 return 0; 345 return 0;
346} 346}
347 347
348static int mpc5xxx_can_resume(struct of_device *ofdev) 348static int mpc5xxx_can_resume(struct platform_device *ofdev)
349{ 349{
350 struct net_device *dev = dev_get_drvdata(&ofdev->dev); 350 struct net_device *dev = dev_get_drvdata(&ofdev->dev);
351 struct mscan_priv *priv = netdev_priv(dev); 351 struct mscan_priv *priv = netdev_priv(dev);
diff --git a/drivers/net/can/sja1000/sja1000_of_platform.c b/drivers/net/can/sja1000/sja1000_of_platform.c
index ac1a83d7c204..5bfccfdf3bbb 100644
--- a/drivers/net/can/sja1000/sja1000_of_platform.c
+++ b/drivers/net/can/sja1000/sja1000_of_platform.c
@@ -67,7 +67,7 @@ static void sja1000_ofp_write_reg(const struct sja1000_priv *priv,
67 out_8(priv->reg_base + reg, val); 67 out_8(priv->reg_base + reg, val);
68} 68}
69 69
70static int __devexit sja1000_ofp_remove(struct of_device *ofdev) 70static int __devexit sja1000_ofp_remove(struct platform_device *ofdev)
71{ 71{
72 struct net_device *dev = dev_get_drvdata(&ofdev->dev); 72 struct net_device *dev = dev_get_drvdata(&ofdev->dev);
73 struct sja1000_priv *priv = netdev_priv(dev); 73 struct sja1000_priv *priv = netdev_priv(dev);
@@ -87,7 +87,7 @@ static int __devexit sja1000_ofp_remove(struct of_device *ofdev)
87 return 0; 87 return 0;
88} 88}
89 89
90static int __devinit sja1000_ofp_probe(struct of_device *ofdev, 90static int __devinit sja1000_ofp_probe(struct platform_device *ofdev,
91 const struct of_device_id *id) 91 const struct of_device_id *id)
92{ 92{
93 struct device_node *np = ofdev->dev.of_node; 93 struct device_node *np = ofdev->dev.of_node;
diff --git a/drivers/net/ehea/ehea.h b/drivers/net/ehea/ehea.h
index 0060e422f171..99a929964e3c 100644
--- a/drivers/net/ehea/ehea.h
+++ b/drivers/net/ehea/ehea.h
@@ -413,7 +413,7 @@ struct ehea_port_res {
413 413
414struct ehea_adapter { 414struct ehea_adapter {
415 u64 handle; 415 u64 handle;
416 struct of_device *ofdev; 416 struct platform_device *ofdev;
417 struct ehea_port *port[EHEA_MAX_PORTS]; 417 struct ehea_port *port[EHEA_MAX_PORTS];
418 struct ehea_eq *neq; /* notification event queue */ 418 struct ehea_eq *neq; /* notification event queue */
419 struct tasklet_struct neq_tasklet; 419 struct tasklet_struct neq_tasklet;
@@ -465,7 +465,7 @@ struct ehea_port {
465 struct net_device *netdev; 465 struct net_device *netdev;
466 struct net_device_stats stats; 466 struct net_device_stats stats;
467 struct ehea_port_res port_res[EHEA_MAX_PORT_RES]; 467 struct ehea_port_res port_res[EHEA_MAX_PORT_RES];
468 struct of_device ofdev; /* Open Firmware Device */ 468 struct platform_device ofdev; /* Open Firmware Device */
469 struct ehea_mc_list *mc_list; /* Multicast MAC addresses */ 469 struct ehea_mc_list *mc_list; /* Multicast MAC addresses */
470 struct vlan_group *vgrp; 470 struct vlan_group *vgrp;
471 struct ehea_eq *qp_eq; 471 struct ehea_eq *qp_eq;
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index 3beba70b7dea..897719b49f96 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -107,10 +107,10 @@ struct ehea_fw_handle_array ehea_fw_handles;
107struct ehea_bcmc_reg_array ehea_bcmc_regs; 107struct ehea_bcmc_reg_array ehea_bcmc_regs;
108 108
109 109
110static int __devinit ehea_probe_adapter(struct of_device *dev, 110static int __devinit ehea_probe_adapter(struct platform_device *dev,
111 const struct of_device_id *id); 111 const struct of_device_id *id);
112 112
113static int __devexit ehea_remove(struct of_device *dev); 113static int __devexit ehea_remove(struct platform_device *dev);
114 114
115static struct of_device_id ehea_device_table[] = { 115static struct of_device_id ehea_device_table[] = {
116 { 116 {
@@ -3376,7 +3376,7 @@ static ssize_t ehea_remove_port(struct device *dev,
3376static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port); 3376static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3377static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port); 3377static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3378 3378
3379int ehea_create_device_sysfs(struct of_device *dev) 3379int ehea_create_device_sysfs(struct platform_device *dev)
3380{ 3380{
3381 int ret = device_create_file(&dev->dev, &dev_attr_probe_port); 3381 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
3382 if (ret) 3382 if (ret)
@@ -3387,13 +3387,13 @@ out:
3387 return ret; 3387 return ret;
3388} 3388}
3389 3389
3390void ehea_remove_device_sysfs(struct of_device *dev) 3390void ehea_remove_device_sysfs(struct platform_device *dev)
3391{ 3391{
3392 device_remove_file(&dev->dev, &dev_attr_probe_port); 3392 device_remove_file(&dev->dev, &dev_attr_probe_port);
3393 device_remove_file(&dev->dev, &dev_attr_remove_port); 3393 device_remove_file(&dev->dev, &dev_attr_remove_port);
3394} 3394}
3395 3395
3396static int __devinit ehea_probe_adapter(struct of_device *dev, 3396static int __devinit ehea_probe_adapter(struct platform_device *dev,
3397 const struct of_device_id *id) 3397 const struct of_device_id *id)
3398{ 3398{
3399 struct ehea_adapter *adapter; 3399 struct ehea_adapter *adapter;
@@ -3492,7 +3492,7 @@ out:
3492 return ret; 3492 return ret;
3493} 3493}
3494 3494
3495static int __devexit ehea_remove(struct of_device *dev) 3495static int __devexit ehea_remove(struct platform_device *dev)
3496{ 3496{
3497 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev); 3497 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
3498 int i; 3498 int i;
diff --git a/drivers/net/fec_mpc52xx.c b/drivers/net/fec_mpc52xx.c
index d1a5b17b2a95..e3e10b4add9c 100644
--- a/drivers/net/fec_mpc52xx.c
+++ b/drivers/net/fec_mpc52xx.c
@@ -850,7 +850,7 @@ static const struct net_device_ops mpc52xx_fec_netdev_ops = {
850/* ======================================================================== */ 850/* ======================================================================== */
851 851
852static int __devinit 852static int __devinit
853mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match) 853mpc52xx_fec_probe(struct platform_device *op, const struct of_device_id *match)
854{ 854{
855 int rv; 855 int rv;
856 struct net_device *ndev; 856 struct net_device *ndev;
@@ -995,7 +995,7 @@ err_netdev:
995} 995}
996 996
997static int 997static int
998mpc52xx_fec_remove(struct of_device *op) 998mpc52xx_fec_remove(struct platform_device *op)
999{ 999{
1000 struct net_device *ndev; 1000 struct net_device *ndev;
1001 struct mpc52xx_fec_priv *priv; 1001 struct mpc52xx_fec_priv *priv;
@@ -1025,7 +1025,7 @@ mpc52xx_fec_remove(struct of_device *op)
1025} 1025}
1026 1026
1027#ifdef CONFIG_PM 1027#ifdef CONFIG_PM
1028static int mpc52xx_fec_of_suspend(struct of_device *op, pm_message_t state) 1028static int mpc52xx_fec_of_suspend(struct platform_device *op, pm_message_t state)
1029{ 1029{
1030 struct net_device *dev = dev_get_drvdata(&op->dev); 1030 struct net_device *dev = dev_get_drvdata(&op->dev);
1031 1031
@@ -1035,7 +1035,7 @@ static int mpc52xx_fec_of_suspend(struct of_device *op, pm_message_t state)
1035 return 0; 1035 return 0;
1036} 1036}
1037 1037
1038static int mpc52xx_fec_of_resume(struct of_device *op) 1038static int mpc52xx_fec_of_resume(struct platform_device *op)
1039{ 1039{
1040 struct net_device *dev = dev_get_drvdata(&op->dev); 1040 struct net_device *dev = dev_get_drvdata(&op->dev);
1041 1041
diff --git a/drivers/net/fec_mpc52xx_phy.c b/drivers/net/fec_mpc52xx_phy.c
index dbaf72cbb233..0b4cb6f15984 100644
--- a/drivers/net/fec_mpc52xx_phy.c
+++ b/drivers/net/fec_mpc52xx_phy.c
@@ -61,7 +61,7 @@ static int mpc52xx_fec_mdio_write(struct mii_bus *bus, int phy_id, int reg,
61 data | FEC_MII_WRITE_FRAME); 61 data | FEC_MII_WRITE_FRAME);
62} 62}
63 63
64static int mpc52xx_fec_mdio_probe(struct of_device *of, 64static int mpc52xx_fec_mdio_probe(struct platform_device *of,
65 const struct of_device_id *match) 65 const struct of_device_id *match)
66{ 66{
67 struct device *dev = &of->dev; 67 struct device *dev = &of->dev;
@@ -122,7 +122,7 @@ static int mpc52xx_fec_mdio_probe(struct of_device *of,
122 return err; 122 return err;
123} 123}
124 124
125static int mpc52xx_fec_mdio_remove(struct of_device *of) 125static int mpc52xx_fec_mdio_remove(struct platform_device *of)
126{ 126{
127 struct device *dev = &of->dev; 127 struct device *dev = &of->dev;
128 struct mii_bus *bus = dev_get_drvdata(dev); 128 struct mii_bus *bus = dev_get_drvdata(dev);
diff --git a/drivers/net/fs_enet/fs_enet-main.c b/drivers/net/fs_enet/fs_enet-main.c
index f08cff9020bd..d6e3111959ab 100644
--- a/drivers/net/fs_enet/fs_enet-main.c
+++ b/drivers/net/fs_enet/fs_enet-main.c
@@ -997,7 +997,7 @@ static const struct net_device_ops fs_enet_netdev_ops = {
997#endif 997#endif
998}; 998};
999 999
1000static int __devinit fs_enet_probe(struct of_device *ofdev, 1000static int __devinit fs_enet_probe(struct platform_device *ofdev,
1001 const struct of_device_id *match) 1001 const struct of_device_id *match)
1002{ 1002{
1003 struct net_device *ndev; 1003 struct net_device *ndev;
@@ -1105,7 +1105,7 @@ out_free_fpi:
1105 return ret; 1105 return ret;
1106} 1106}
1107 1107
1108static int fs_enet_remove(struct of_device *ofdev) 1108static int fs_enet_remove(struct platform_device *ofdev)
1109{ 1109{
1110 struct net_device *ndev = dev_get_drvdata(&ofdev->dev); 1110 struct net_device *ndev = dev_get_drvdata(&ofdev->dev);
1111 struct fs_enet_private *fep = netdev_priv(ndev); 1111 struct fs_enet_private *fep = netdev_priv(ndev);
diff --git a/drivers/net/fs_enet/mac-fcc.c b/drivers/net/fs_enet/mac-fcc.c
index 48e91b6242ce..7a84e45487e8 100644
--- a/drivers/net/fs_enet/mac-fcc.c
+++ b/drivers/net/fs_enet/mac-fcc.c
@@ -84,7 +84,7 @@ static inline int fcc_cr_cmd(struct fs_enet_private *fep, u32 op)
84 84
85static int do_pd_setup(struct fs_enet_private *fep) 85static int do_pd_setup(struct fs_enet_private *fep)
86{ 86{
87 struct of_device *ofdev = to_of_device(fep->dev); 87 struct platform_device *ofdev = to_platform_device(fep->dev);
88 struct fs_platform_info *fpi = fep->fpi; 88 struct fs_platform_info *fpi = fep->fpi;
89 int ret = -EINVAL; 89 int ret = -EINVAL;
90 90
diff --git a/drivers/net/fs_enet/mac-fec.c b/drivers/net/fs_enet/mac-fec.c
index 7ca1642276d0..61035fc5599b 100644
--- a/drivers/net/fs_enet/mac-fec.c
+++ b/drivers/net/fs_enet/mac-fec.c
@@ -96,7 +96,7 @@ static int whack_reset(struct fec __iomem *fecp)
96 96
97static int do_pd_setup(struct fs_enet_private *fep) 97static int do_pd_setup(struct fs_enet_private *fep)
98{ 98{
99 struct of_device *ofdev = to_of_device(fep->dev); 99 struct platform_device *ofdev = to_platform_device(fep->dev);
100 100
101 fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL); 101 fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL);
102 if (fep->interrupt == NO_IRQ) 102 if (fep->interrupt == NO_IRQ)
diff --git a/drivers/net/fs_enet/mac-scc.c b/drivers/net/fs_enet/mac-scc.c
index a3c44544846d..22a02a767069 100644
--- a/drivers/net/fs_enet/mac-scc.c
+++ b/drivers/net/fs_enet/mac-scc.c
@@ -96,7 +96,7 @@ static inline int scc_cr_cmd(struct fs_enet_private *fep, u32 op)
96 96
97static int do_pd_setup(struct fs_enet_private *fep) 97static int do_pd_setup(struct fs_enet_private *fep)
98{ 98{
99 struct of_device *ofdev = to_of_device(fep->dev); 99 struct platform_device *ofdev = to_platform_device(fep->dev);
100 100
101 fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL); 101 fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL);
102 if (fep->interrupt == NO_IRQ) 102 if (fep->interrupt == NO_IRQ)
diff --git a/drivers/net/fs_enet/mii-bitbang.c b/drivers/net/fs_enet/mii-bitbang.c
index 3607340f3da7..3cda2b515471 100644
--- a/drivers/net/fs_enet/mii-bitbang.c
+++ b/drivers/net/fs_enet/mii-bitbang.c
@@ -150,7 +150,7 @@ static int __devinit fs_mii_bitbang_init(struct mii_bus *bus,
150 return 0; 150 return 0;
151} 151}
152 152
153static int __devinit fs_enet_mdio_probe(struct of_device *ofdev, 153static int __devinit fs_enet_mdio_probe(struct platform_device *ofdev,
154 const struct of_device_id *match) 154 const struct of_device_id *match)
155{ 155{
156 struct mii_bus *new_bus; 156 struct mii_bus *new_bus;
@@ -200,7 +200,7 @@ out:
200 return ret; 200 return ret;
201} 201}
202 202
203static int fs_enet_mdio_remove(struct of_device *ofdev) 203static int fs_enet_mdio_remove(struct platform_device *ofdev)
204{ 204{
205 struct mii_bus *bus = dev_get_drvdata(&ofdev->dev); 205 struct mii_bus *bus = dev_get_drvdata(&ofdev->dev);
206 struct bb_info *bitbang = bus->priv; 206 struct bb_info *bitbang = bus->priv;
diff --git a/drivers/net/fs_enet/mii-fec.c b/drivers/net/fs_enet/mii-fec.c
index bddffd169b93..dbb9c48623df 100644
--- a/drivers/net/fs_enet/mii-fec.c
+++ b/drivers/net/fs_enet/mii-fec.c
@@ -101,7 +101,7 @@ static int fs_enet_fec_mii_reset(struct mii_bus *bus)
101 return 0; 101 return 0;
102} 102}
103 103
104static int __devinit fs_enet_mdio_probe(struct of_device *ofdev, 104static int __devinit fs_enet_mdio_probe(struct platform_device *ofdev,
105 const struct of_device_id *match) 105 const struct of_device_id *match)
106{ 106{
107 struct resource res; 107 struct resource res;
@@ -192,7 +192,7 @@ out:
192 return ret; 192 return ret;
193} 193}
194 194
195static int fs_enet_mdio_remove(struct of_device *ofdev) 195static int fs_enet_mdio_remove(struct platform_device *ofdev)
196{ 196{
197 struct mii_bus *bus = dev_get_drvdata(&ofdev->dev); 197 struct mii_bus *bus = dev_get_drvdata(&ofdev->dev);
198 struct fec_info *fec = bus->priv; 198 struct fec_info *fec = bus->priv;
diff --git a/drivers/net/fsl_pq_mdio.c b/drivers/net/fsl_pq_mdio.c
index f53f850b6418..d4bf91aac25f 100644
--- a/drivers/net/fsl_pq_mdio.c
+++ b/drivers/net/fsl_pq_mdio.c
@@ -265,7 +265,7 @@ static int get_ucc_id_for_range(u64 start, u64 end, u32 *ucc_id)
265#endif 265#endif
266 266
267 267
268static int fsl_pq_mdio_probe(struct of_device *ofdev, 268static int fsl_pq_mdio_probe(struct platform_device *ofdev,
269 const struct of_device_id *match) 269 const struct of_device_id *match)
270{ 270{
271 struct device_node *np = ofdev->dev.of_node; 271 struct device_node *np = ofdev->dev.of_node;
@@ -425,7 +425,7 @@ err_free_priv:
425} 425}
426 426
427 427
428static int fsl_pq_mdio_remove(struct of_device *ofdev) 428static int fsl_pq_mdio_remove(struct platform_device *ofdev)
429{ 429{
430 struct device *device = &ofdev->dev; 430 struct device *device = &ofdev->dev;
431 struct mii_bus *bus = dev_get_drvdata(device); 431 struct mii_bus *bus = dev_get_drvdata(device);
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index a1b6301bc674..4f7c3f3ca234 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -122,9 +122,9 @@ static irqreturn_t gfar_interrupt(int irq, void *dev_id);
122static void adjust_link(struct net_device *dev); 122static void adjust_link(struct net_device *dev);
123static void init_registers(struct net_device *dev); 123static void init_registers(struct net_device *dev);
124static int init_phy(struct net_device *dev); 124static int init_phy(struct net_device *dev);
125static int gfar_probe(struct of_device *ofdev, 125static int gfar_probe(struct platform_device *ofdev,
126 const struct of_device_id *match); 126 const struct of_device_id *match);
127static int gfar_remove(struct of_device *ofdev); 127static int gfar_remove(struct platform_device *ofdev);
128static void free_skb_resources(struct gfar_private *priv); 128static void free_skb_resources(struct gfar_private *priv);
129static void gfar_set_multi(struct net_device *dev); 129static void gfar_set_multi(struct net_device *dev);
130static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr); 130static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr);
@@ -605,7 +605,7 @@ static int gfar_parse_group(struct device_node *np,
605 return 0; 605 return 0;
606} 606}
607 607
608static int gfar_of_init(struct of_device *ofdev, struct net_device **pdev) 608static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
609{ 609{
610 const char *model; 610 const char *model;
611 const char *ctype; 611 const char *ctype;
@@ -959,7 +959,7 @@ static void gfar_detect_errata(struct gfar_private *priv)
959 959
960/* Set up the ethernet device structure, private data, 960/* Set up the ethernet device structure, private data,
961 * and anything else we need before we start */ 961 * and anything else we need before we start */
962static int gfar_probe(struct of_device *ofdev, 962static int gfar_probe(struct platform_device *ofdev,
963 const struct of_device_id *match) 963 const struct of_device_id *match)
964{ 964{
965 u32 tempval; 965 u32 tempval;
@@ -1238,7 +1238,7 @@ register_fail:
1238 return err; 1238 return err;
1239} 1239}
1240 1240
1241static int gfar_remove(struct of_device *ofdev) 1241static int gfar_remove(struct platform_device *ofdev)
1242{ 1242{
1243 struct gfar_private *priv = dev_get_drvdata(&ofdev->dev); 1243 struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
1244 1244
diff --git a/drivers/net/gianfar.h b/drivers/net/gianfar.h
index 710810e2adb4..68984eb88ae0 100644
--- a/drivers/net/gianfar.h
+++ b/drivers/net/gianfar.h
@@ -1054,7 +1054,7 @@ struct gfar_private {
1054 1054
1055 struct device_node *node; 1055 struct device_node *node;
1056 struct net_device *ndev; 1056 struct net_device *ndev;
1057 struct of_device *ofdev; 1057 struct platform_device *ofdev;
1058 enum gfar_errata errata; 1058 enum gfar_errata errata;
1059 1059
1060 struct gfar_priv_grp gfargrp[MAXGROUPS]; 1060 struct gfar_priv_grp gfargrp[MAXGROUPS];
diff --git a/drivers/net/greth.c b/drivers/net/greth.c
index 4d09eab3548e..f15c64f1cd38 100644
--- a/drivers/net/greth.c
+++ b/drivers/net/greth.c
@@ -1373,7 +1373,7 @@ error:
1373} 1373}
1374 1374
1375/* Initialize the GRETH MAC */ 1375/* Initialize the GRETH MAC */
1376static int __devinit greth_of_probe(struct of_device *ofdev, const struct of_device_id *match) 1376static int __devinit greth_of_probe(struct platform_device *ofdev, const struct of_device_id *match)
1377{ 1377{
1378 struct net_device *dev; 1378 struct net_device *dev;
1379 struct greth_private *greth; 1379 struct greth_private *greth;
@@ -1412,7 +1412,7 @@ static int __devinit greth_of_probe(struct of_device *ofdev, const struct of_dev
1412 } 1412 }
1413 1413
1414 regs = (struct greth_regs *) greth->regs; 1414 regs = (struct greth_regs *) greth->regs;
1415 greth->irq = ofdev->irqs[0]; 1415 greth->irq = ofdev->archdata.irqs[0];
1416 1416
1417 dev_set_drvdata(greth->dev, dev); 1417 dev_set_drvdata(greth->dev, dev);
1418 SET_NETDEV_DEV(dev, greth->dev); 1418 SET_NETDEV_DEV(dev, greth->dev);
@@ -1572,7 +1572,7 @@ error1:
1572 return err; 1572 return err;
1573} 1573}
1574 1574
1575static int __devexit greth_of_remove(struct of_device *of_dev) 1575static int __devexit greth_of_remove(struct platform_device *of_dev)
1576{ 1576{
1577 struct net_device *ndev = dev_get_drvdata(&of_dev->dev); 1577 struct net_device *ndev = dev_get_drvdata(&of_dev->dev);
1578 struct greth_private *greth = netdev_priv(ndev); 1578 struct greth_private *greth = netdev_priv(ndev);
diff --git a/drivers/net/greth.h b/drivers/net/greth.h
index 973388d6abca..03ad903cd676 100644
--- a/drivers/net/greth.h
+++ b/drivers/net/greth.h
@@ -118,7 +118,7 @@ struct greth_private {
118 118
119 int irq; 119 int irq;
120 120
121 struct device *dev; /* Pointer to of_device->dev */ 121 struct device *dev; /* Pointer to platform_device->dev */
122 struct net_device *netdev; 122 struct net_device *netdev;
123 struct napi_struct napi; 123 struct napi_struct napi;
124 spinlock_t devlock; 124 spinlock_t devlock;
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index eeec7bc2ce74..3506fd6ad726 100644
--- a/drivers/net/ibm_newemac/core.c
+++ b/drivers/net/ibm_newemac/core.c
@@ -2245,7 +2245,7 @@ static int emac_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
2245struct emac_depentry { 2245struct emac_depentry {
2246 u32 phandle; 2246 u32 phandle;
2247 struct device_node *node; 2247 struct device_node *node;
2248 struct of_device *ofdev; 2248 struct platform_device *ofdev;
2249 void *drvdata; 2249 void *drvdata;
2250}; 2250};
2251 2251
@@ -2719,7 +2719,7 @@ static const struct net_device_ops emac_gige_netdev_ops = {
2719 .ndo_change_mtu = emac_change_mtu, 2719 .ndo_change_mtu = emac_change_mtu,
2720}; 2720};
2721 2721
2722static int __devinit emac_probe(struct of_device *ofdev, 2722static int __devinit emac_probe(struct platform_device *ofdev,
2723 const struct of_device_id *match) 2723 const struct of_device_id *match)
2724{ 2724{
2725 struct net_device *ndev; 2725 struct net_device *ndev;
@@ -2941,7 +2941,7 @@ static int __devinit emac_probe(struct of_device *ofdev,
2941 return err; 2941 return err;
2942} 2942}
2943 2943
2944static int __devexit emac_remove(struct of_device *ofdev) 2944static int __devexit emac_remove(struct platform_device *ofdev)
2945{ 2945{
2946 struct emac_instance *dev = dev_get_drvdata(&ofdev->dev); 2946 struct emac_instance *dev = dev_get_drvdata(&ofdev->dev);
2947 2947
diff --git a/drivers/net/ibm_newemac/core.h b/drivers/net/ibm_newemac/core.h
index b1cbe6fdfc7a..9e37e3d9c51d 100644
--- a/drivers/net/ibm_newemac/core.h
+++ b/drivers/net/ibm_newemac/core.h
@@ -170,12 +170,12 @@ struct emac_instance {
170 struct net_device *ndev; 170 struct net_device *ndev;
171 struct resource rsrc_regs; 171 struct resource rsrc_regs;
172 struct emac_regs __iomem *emacp; 172 struct emac_regs __iomem *emacp;
173 struct of_device *ofdev; 173 struct platform_device *ofdev;
174 struct device_node **blist; /* bootlist entry */ 174 struct device_node **blist; /* bootlist entry */
175 175
176 /* MAL linkage */ 176 /* MAL linkage */
177 u32 mal_ph; 177 u32 mal_ph;
178 struct of_device *mal_dev; 178 struct platform_device *mal_dev;
179 u32 mal_rx_chan; 179 u32 mal_rx_chan;
180 u32 mal_tx_chan; 180 u32 mal_tx_chan;
181 struct mal_instance *mal; 181 struct mal_instance *mal;
@@ -196,24 +196,24 @@ struct emac_instance {
196 196
197 /* Shared MDIO if any */ 197 /* Shared MDIO if any */
198 u32 mdio_ph; 198 u32 mdio_ph;
199 struct of_device *mdio_dev; 199 struct platform_device *mdio_dev;
200 struct emac_instance *mdio_instance; 200 struct emac_instance *mdio_instance;
201 struct mutex mdio_lock; 201 struct mutex mdio_lock;
202 202
203 /* ZMII infos if any */ 203 /* ZMII infos if any */
204 u32 zmii_ph; 204 u32 zmii_ph;
205 u32 zmii_port; 205 u32 zmii_port;
206 struct of_device *zmii_dev; 206 struct platform_device *zmii_dev;
207 207
208 /* RGMII infos if any */ 208 /* RGMII infos if any */
209 u32 rgmii_ph; 209 u32 rgmii_ph;
210 u32 rgmii_port; 210 u32 rgmii_port;
211 struct of_device *rgmii_dev; 211 struct platform_device *rgmii_dev;
212 212
213 /* TAH infos if any */ 213 /* TAH infos if any */
214 u32 tah_ph; 214 u32 tah_ph;
215 u32 tah_port; 215 u32 tah_port;
216 struct of_device *tah_dev; 216 struct platform_device *tah_dev;
217 217
218 /* IRQs */ 218 /* IRQs */
219 int wol_irq; 219 int wol_irq;
diff --git a/drivers/net/ibm_newemac/mal.c b/drivers/net/ibm_newemac/mal.c
index fcff9e0bd382..d5717e2123e1 100644
--- a/drivers/net/ibm_newemac/mal.c
+++ b/drivers/net/ibm_newemac/mal.c
@@ -517,7 +517,7 @@ void *mal_dump_regs(struct mal_instance *mal, void *buf)
517 return regs + 1; 517 return regs + 1;
518} 518}
519 519
520static int __devinit mal_probe(struct of_device *ofdev, 520static int __devinit mal_probe(struct platform_device *ofdev,
521 const struct of_device_id *match) 521 const struct of_device_id *match)
522{ 522{
523 struct mal_instance *mal; 523 struct mal_instance *mal;
@@ -730,7 +730,7 @@ static int __devinit mal_probe(struct of_device *ofdev,
730 return err; 730 return err;
731} 731}
732 732
733static int __devexit mal_remove(struct of_device *ofdev) 733static int __devexit mal_remove(struct platform_device *ofdev)
734{ 734{
735 struct mal_instance *mal = dev_get_drvdata(&ofdev->dev); 735 struct mal_instance *mal = dev_get_drvdata(&ofdev->dev);
736 736
diff --git a/drivers/net/ibm_newemac/mal.h b/drivers/net/ibm_newemac/mal.h
index 9ededfbf0726..66084214bf45 100644
--- a/drivers/net/ibm_newemac/mal.h
+++ b/drivers/net/ibm_newemac/mal.h
@@ -210,7 +210,7 @@ struct mal_instance {
210 dma_addr_t bd_dma; 210 dma_addr_t bd_dma;
211 struct mal_descriptor *bd_virt; 211 struct mal_descriptor *bd_virt;
212 212
213 struct of_device *ofdev; 213 struct platform_device *ofdev;
214 int index; 214 int index;
215 spinlock_t lock; 215 spinlock_t lock;
216 216
diff --git a/drivers/net/ibm_newemac/rgmii.c b/drivers/net/ibm_newemac/rgmii.c
index 108919bcdf13..dd61798897ac 100644
--- a/drivers/net/ibm_newemac/rgmii.c
+++ b/drivers/net/ibm_newemac/rgmii.c
@@ -93,7 +93,7 @@ static inline u32 rgmii_mode_mask(int mode, int input)
93 } 93 }
94} 94}
95 95
96int __devinit rgmii_attach(struct of_device *ofdev, int input, int mode) 96int __devinit rgmii_attach(struct platform_device *ofdev, int input, int mode)
97{ 97{
98 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 98 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
99 struct rgmii_regs __iomem *p = dev->base; 99 struct rgmii_regs __iomem *p = dev->base;
@@ -122,7 +122,7 @@ int __devinit rgmii_attach(struct of_device *ofdev, int input, int mode)
122 return 0; 122 return 0;
123} 123}
124 124
125void rgmii_set_speed(struct of_device *ofdev, int input, int speed) 125void rgmii_set_speed(struct platform_device *ofdev, int input, int speed)
126{ 126{
127 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 127 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
128 struct rgmii_regs __iomem *p = dev->base; 128 struct rgmii_regs __iomem *p = dev->base;
@@ -144,7 +144,7 @@ void rgmii_set_speed(struct of_device *ofdev, int input, int speed)
144 mutex_unlock(&dev->lock); 144 mutex_unlock(&dev->lock);
145} 145}
146 146
147void rgmii_get_mdio(struct of_device *ofdev, int input) 147void rgmii_get_mdio(struct platform_device *ofdev, int input)
148{ 148{
149 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 149 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
150 struct rgmii_regs __iomem *p = dev->base; 150 struct rgmii_regs __iomem *p = dev->base;
@@ -165,7 +165,7 @@ void rgmii_get_mdio(struct of_device *ofdev, int input)
165 DBG2(dev, " fer = 0x%08x\n", fer); 165 DBG2(dev, " fer = 0x%08x\n", fer);
166} 166}
167 167
168void rgmii_put_mdio(struct of_device *ofdev, int input) 168void rgmii_put_mdio(struct platform_device *ofdev, int input)
169{ 169{
170 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 170 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
171 struct rgmii_regs __iomem *p = dev->base; 171 struct rgmii_regs __iomem *p = dev->base;
@@ -186,7 +186,7 @@ void rgmii_put_mdio(struct of_device *ofdev, int input)
186 mutex_unlock(&dev->lock); 186 mutex_unlock(&dev->lock);
187} 187}
188 188
189void rgmii_detach(struct of_device *ofdev, int input) 189void rgmii_detach(struct platform_device *ofdev, int input)
190{ 190{
191 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 191 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
192 struct rgmii_regs __iomem *p; 192 struct rgmii_regs __iomem *p;
@@ -206,13 +206,13 @@ void rgmii_detach(struct of_device *ofdev, int input)
206 mutex_unlock(&dev->lock); 206 mutex_unlock(&dev->lock);
207} 207}
208 208
209int rgmii_get_regs_len(struct of_device *ofdev) 209int rgmii_get_regs_len(struct platform_device *ofdev)
210{ 210{
211 return sizeof(struct emac_ethtool_regs_subhdr) + 211 return sizeof(struct emac_ethtool_regs_subhdr) +
212 sizeof(struct rgmii_regs); 212 sizeof(struct rgmii_regs);
213} 213}
214 214
215void *rgmii_dump_regs(struct of_device *ofdev, void *buf) 215void *rgmii_dump_regs(struct platform_device *ofdev, void *buf)
216{ 216{
217 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 217 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
218 struct emac_ethtool_regs_subhdr *hdr = buf; 218 struct emac_ethtool_regs_subhdr *hdr = buf;
@@ -228,7 +228,7 @@ void *rgmii_dump_regs(struct of_device *ofdev, void *buf)
228} 228}
229 229
230 230
231static int __devinit rgmii_probe(struct of_device *ofdev, 231static int __devinit rgmii_probe(struct platform_device *ofdev,
232 const struct of_device_id *match) 232 const struct of_device_id *match)
233{ 233{
234 struct device_node *np = ofdev->dev.of_node; 234 struct device_node *np = ofdev->dev.of_node;
@@ -293,7 +293,7 @@ static int __devinit rgmii_probe(struct of_device *ofdev,
293 return rc; 293 return rc;
294} 294}
295 295
296static int __devexit rgmii_remove(struct of_device *ofdev) 296static int __devexit rgmii_remove(struct platform_device *ofdev)
297{ 297{
298 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 298 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
299 299
diff --git a/drivers/net/ibm_newemac/rgmii.h b/drivers/net/ibm_newemac/rgmii.h
index c4a4b358a270..d69799049865 100644
--- a/drivers/net/ibm_newemac/rgmii.h
+++ b/drivers/net/ibm_newemac/rgmii.h
@@ -51,20 +51,20 @@ struct rgmii_instance {
51 int users; 51 int users;
52 52
53 /* OF device instance */ 53 /* OF device instance */
54 struct of_device *ofdev; 54 struct platform_device *ofdev;
55}; 55};
56 56
57#ifdef CONFIG_IBM_NEW_EMAC_RGMII 57#ifdef CONFIG_IBM_NEW_EMAC_RGMII
58 58
59extern int rgmii_init(void); 59extern int rgmii_init(void);
60extern void rgmii_exit(void); 60extern void rgmii_exit(void);
61extern int rgmii_attach(struct of_device *ofdev, int input, int mode); 61extern int rgmii_attach(struct platform_device *ofdev, int input, int mode);
62extern void rgmii_detach(struct of_device *ofdev, int input); 62extern void rgmii_detach(struct platform_device *ofdev, int input);
63extern void rgmii_get_mdio(struct of_device *ofdev, int input); 63extern void rgmii_get_mdio(struct platform_device *ofdev, int input);
64extern void rgmii_put_mdio(struct of_device *ofdev, int input); 64extern void rgmii_put_mdio(struct platform_device *ofdev, int input);
65extern void rgmii_set_speed(struct of_device *ofdev, int input, int speed); 65extern void rgmii_set_speed(struct platform_device *ofdev, int input, int speed);
66extern int rgmii_get_regs_len(struct of_device *ofdev); 66extern int rgmii_get_regs_len(struct platform_device *ofdev);
67extern void *rgmii_dump_regs(struct of_device *ofdev, void *buf); 67extern void *rgmii_dump_regs(struct platform_device *ofdev, void *buf);
68 68
69#else 69#else
70 70
diff --git a/drivers/net/ibm_newemac/tah.c b/drivers/net/ibm_newemac/tah.c
index 044637144c43..299aa49490c0 100644
--- a/drivers/net/ibm_newemac/tah.c
+++ b/drivers/net/ibm_newemac/tah.c
@@ -23,7 +23,7 @@
23#include "emac.h" 23#include "emac.h"
24#include "core.h" 24#include "core.h"
25 25
26int __devinit tah_attach(struct of_device *ofdev, int channel) 26int __devinit tah_attach(struct platform_device *ofdev, int channel)
27{ 27{
28 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); 28 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
29 29
@@ -35,7 +35,7 @@ int __devinit tah_attach(struct of_device *ofdev, int channel)
35 return 0; 35 return 0;
36} 36}
37 37
38void tah_detach(struct of_device *ofdev, int channel) 38void tah_detach(struct platform_device *ofdev, int channel)
39{ 39{
40 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); 40 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
41 41
@@ -44,7 +44,7 @@ void tah_detach(struct of_device *ofdev, int channel)
44 mutex_unlock(&dev->lock); 44 mutex_unlock(&dev->lock);
45} 45}
46 46
47void tah_reset(struct of_device *ofdev) 47void tah_reset(struct platform_device *ofdev)
48{ 48{
49 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); 49 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
50 struct tah_regs __iomem *p = dev->base; 50 struct tah_regs __iomem *p = dev->base;
@@ -66,13 +66,13 @@ void tah_reset(struct of_device *ofdev)
66 TAH_MR_DIG); 66 TAH_MR_DIG);
67} 67}
68 68
69int tah_get_regs_len(struct of_device *ofdev) 69int tah_get_regs_len(struct platform_device *ofdev)
70{ 70{
71 return sizeof(struct emac_ethtool_regs_subhdr) + 71 return sizeof(struct emac_ethtool_regs_subhdr) +
72 sizeof(struct tah_regs); 72 sizeof(struct tah_regs);
73} 73}
74 74
75void *tah_dump_regs(struct of_device *ofdev, void *buf) 75void *tah_dump_regs(struct platform_device *ofdev, void *buf)
76{ 76{
77 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); 77 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
78 struct emac_ethtool_regs_subhdr *hdr = buf; 78 struct emac_ethtool_regs_subhdr *hdr = buf;
@@ -87,7 +87,7 @@ void *tah_dump_regs(struct of_device *ofdev, void *buf)
87 return regs + 1; 87 return regs + 1;
88} 88}
89 89
90static int __devinit tah_probe(struct of_device *ofdev, 90static int __devinit tah_probe(struct platform_device *ofdev,
91 const struct of_device_id *match) 91 const struct of_device_id *match)
92{ 92{
93 struct device_node *np = ofdev->dev.of_node; 93 struct device_node *np = ofdev->dev.of_node;
@@ -139,7 +139,7 @@ static int __devinit tah_probe(struct of_device *ofdev,
139 return rc; 139 return rc;
140} 140}
141 141
142static int __devexit tah_remove(struct of_device *ofdev) 142static int __devexit tah_remove(struct platform_device *ofdev)
143{ 143{
144 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); 144 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
145 145
diff --git a/drivers/net/ibm_newemac/tah.h b/drivers/net/ibm_newemac/tah.h
index a068b5658dad..61dbeca006d1 100644
--- a/drivers/net/ibm_newemac/tah.h
+++ b/drivers/net/ibm_newemac/tah.h
@@ -48,7 +48,7 @@ struct tah_instance {
48 int users; 48 int users;
49 49
50 /* OF device instance */ 50 /* OF device instance */
51 struct of_device *ofdev; 51 struct platform_device *ofdev;
52}; 52};
53 53
54 54
@@ -74,11 +74,11 @@ struct tah_instance {
74 74
75extern int tah_init(void); 75extern int tah_init(void);
76extern void tah_exit(void); 76extern void tah_exit(void);
77extern int tah_attach(struct of_device *ofdev, int channel); 77extern int tah_attach(struct platform_device *ofdev, int channel);
78extern void tah_detach(struct of_device *ofdev, int channel); 78extern void tah_detach(struct platform_device *ofdev, int channel);
79extern void tah_reset(struct of_device *ofdev); 79extern void tah_reset(struct platform_device *ofdev);
80extern int tah_get_regs_len(struct of_device *ofdev); 80extern int tah_get_regs_len(struct platform_device *ofdev);
81extern void *tah_dump_regs(struct of_device *ofdev, void *buf); 81extern void *tah_dump_regs(struct platform_device *ofdev, void *buf);
82 82
83#else 83#else
84 84
diff --git a/drivers/net/ibm_newemac/zmii.c b/drivers/net/ibm_newemac/zmii.c
index 046dcd069c45..34ed6ee8ca8a 100644
--- a/drivers/net/ibm_newemac/zmii.c
+++ b/drivers/net/ibm_newemac/zmii.c
@@ -82,7 +82,7 @@ static inline u32 zmii_mode_mask(int mode, int input)
82 } 82 }
83} 83}
84 84
85int __devinit zmii_attach(struct of_device *ofdev, int input, int *mode) 85int __devinit zmii_attach(struct platform_device *ofdev, int input, int *mode)
86{ 86{
87 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 87 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
88 struct zmii_regs __iomem *p = dev->base; 88 struct zmii_regs __iomem *p = dev->base;
@@ -148,7 +148,7 @@ int __devinit zmii_attach(struct of_device *ofdev, int input, int *mode)
148 return 0; 148 return 0;
149} 149}
150 150
151void zmii_get_mdio(struct of_device *ofdev, int input) 151void zmii_get_mdio(struct platform_device *ofdev, int input)
152{ 152{
153 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 153 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
154 u32 fer; 154 u32 fer;
@@ -161,7 +161,7 @@ void zmii_get_mdio(struct of_device *ofdev, int input)
161 out_be32(&dev->base->fer, fer | ZMII_FER_MDI(input)); 161 out_be32(&dev->base->fer, fer | ZMII_FER_MDI(input));
162} 162}
163 163
164void zmii_put_mdio(struct of_device *ofdev, int input) 164void zmii_put_mdio(struct platform_device *ofdev, int input)
165{ 165{
166 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 166 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
167 167
@@ -170,7 +170,7 @@ void zmii_put_mdio(struct of_device *ofdev, int input)
170} 170}
171 171
172 172
173void zmii_set_speed(struct of_device *ofdev, int input, int speed) 173void zmii_set_speed(struct platform_device *ofdev, int input, int speed)
174{ 174{
175 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 175 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
176 u32 ssr; 176 u32 ssr;
@@ -191,7 +191,7 @@ void zmii_set_speed(struct of_device *ofdev, int input, int speed)
191 mutex_unlock(&dev->lock); 191 mutex_unlock(&dev->lock);
192} 192}
193 193
194void zmii_detach(struct of_device *ofdev, int input) 194void zmii_detach(struct platform_device *ofdev, int input)
195{ 195{
196 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 196 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
197 197
@@ -210,13 +210,13 @@ void zmii_detach(struct of_device *ofdev, int input)
210 mutex_unlock(&dev->lock); 210 mutex_unlock(&dev->lock);
211} 211}
212 212
213int zmii_get_regs_len(struct of_device *ofdev) 213int zmii_get_regs_len(struct platform_device *ofdev)
214{ 214{
215 return sizeof(struct emac_ethtool_regs_subhdr) + 215 return sizeof(struct emac_ethtool_regs_subhdr) +
216 sizeof(struct zmii_regs); 216 sizeof(struct zmii_regs);
217} 217}
218 218
219void *zmii_dump_regs(struct of_device *ofdev, void *buf) 219void *zmii_dump_regs(struct platform_device *ofdev, void *buf)
220{ 220{
221 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 221 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
222 struct emac_ethtool_regs_subhdr *hdr = buf; 222 struct emac_ethtool_regs_subhdr *hdr = buf;
@@ -231,7 +231,7 @@ void *zmii_dump_regs(struct of_device *ofdev, void *buf)
231 return regs + 1; 231 return regs + 1;
232} 232}
233 233
234static int __devinit zmii_probe(struct of_device *ofdev, 234static int __devinit zmii_probe(struct platform_device *ofdev,
235 const struct of_device_id *match) 235 const struct of_device_id *match)
236{ 236{
237 struct device_node *np = ofdev->dev.of_node; 237 struct device_node *np = ofdev->dev.of_node;
@@ -286,7 +286,7 @@ static int __devinit zmii_probe(struct of_device *ofdev,
286 return rc; 286 return rc;
287} 287}
288 288
289static int __devexit zmii_remove(struct of_device *ofdev) 289static int __devexit zmii_remove(struct platform_device *ofdev)
290{ 290{
291 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 291 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
292 292
diff --git a/drivers/net/ibm_newemac/zmii.h b/drivers/net/ibm_newemac/zmii.h
index 6c9beba0c4b6..1333fa2b2781 100644
--- a/drivers/net/ibm_newemac/zmii.h
+++ b/drivers/net/ibm_newemac/zmii.h
@@ -48,20 +48,20 @@ struct zmii_instance {
48 u32 fer_save; 48 u32 fer_save;
49 49
50 /* OF device instance */ 50 /* OF device instance */
51 struct of_device *ofdev; 51 struct platform_device *ofdev;
52}; 52};
53 53
54#ifdef CONFIG_IBM_NEW_EMAC_ZMII 54#ifdef CONFIG_IBM_NEW_EMAC_ZMII
55 55
56extern int zmii_init(void); 56extern int zmii_init(void);
57extern void zmii_exit(void); 57extern void zmii_exit(void);
58extern int zmii_attach(struct of_device *ofdev, int input, int *mode); 58extern int zmii_attach(struct platform_device *ofdev, int input, int *mode);
59extern void zmii_detach(struct of_device *ofdev, int input); 59extern void zmii_detach(struct platform_device *ofdev, int input);
60extern void zmii_get_mdio(struct of_device *ofdev, int input); 60extern void zmii_get_mdio(struct platform_device *ofdev, int input);
61extern void zmii_put_mdio(struct of_device *ofdev, int input); 61extern void zmii_put_mdio(struct platform_device *ofdev, int input);
62extern void zmii_set_speed(struct of_device *ofdev, int input, int speed); 62extern void zmii_set_speed(struct platform_device *ofdev, int input, int speed);
63extern int zmii_get_regs_len(struct of_device *ocpdev); 63extern int zmii_get_regs_len(struct platform_device *ocpdev);
64extern void *zmii_dump_regs(struct of_device *ofdev, void *buf); 64extern void *zmii_dump_regs(struct platform_device *ofdev, void *buf);
65 65
66#else 66#else
67# define zmii_init() 0 67# define zmii_init() 0
diff --git a/drivers/net/irda/sh_irda.c b/drivers/net/irda/sh_irda.c
index edd5666f0ffb..9e3f4f54281d 100644
--- a/drivers/net/irda/sh_irda.c
+++ b/drivers/net/irda/sh_irda.c
@@ -748,7 +748,6 @@ static int __devinit sh_irda_probe(struct platform_device *pdev)
748 struct net_device *ndev; 748 struct net_device *ndev;
749 struct sh_irda_self *self; 749 struct sh_irda_self *self;
750 struct resource *res; 750 struct resource *res;
751 char clk_name[8];
752 int irq; 751 int irq;
753 int err = -ENOMEM; 752 int err = -ENOMEM;
754 753
@@ -775,10 +774,9 @@ static int __devinit sh_irda_probe(struct platform_device *pdev)
775 if (err) 774 if (err)
776 goto err_mem_2; 775 goto err_mem_2;
777 776
778 snprintf(clk_name, sizeof(clk_name), "irda%d", pdev->id); 777 self->clk = clk_get(&pdev->dev, NULL);
779 self->clk = clk_get(&pdev->dev, clk_name);
780 if (IS_ERR(self->clk)) { 778 if (IS_ERR(self->clk)) {
781 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name); 779 dev_err(&pdev->dev, "cannot get irda clock\n");
782 goto err_mem_3; 780 goto err_mem_3;
783 } 781 }
784 782
diff --git a/drivers/net/ll_temac_main.c b/drivers/net/ll_temac_main.c
index 4eea3f70c5cf..c7b624711f5e 100644
--- a/drivers/net/ll_temac_main.c
+++ b/drivers/net/ll_temac_main.c
@@ -159,7 +159,7 @@ static void temac_dma_dcr_out(struct temac_local *lp, int reg, u32 value)
159 * temac_dcr_setup - If the DMA is DCR based, then setup the address and 159 * temac_dcr_setup - If the DMA is DCR based, then setup the address and
160 * I/O functions 160 * I/O functions
161 */ 161 */
162static int temac_dcr_setup(struct temac_local *lp, struct of_device *op, 162static int temac_dcr_setup(struct temac_local *lp, struct platform_device *op,
163 struct device_node *np) 163 struct device_node *np)
164{ 164{
165 unsigned int dcrs; 165 unsigned int dcrs;
@@ -184,7 +184,7 @@ static int temac_dcr_setup(struct temac_local *lp, struct of_device *op,
184 * temac_dcr_setup - This is a stub for when DCR is not supported, 184 * temac_dcr_setup - This is a stub for when DCR is not supported,
185 * such as with MicroBlaze 185 * such as with MicroBlaze
186 */ 186 */
187static int temac_dcr_setup(struct temac_local *lp, struct of_device *op, 187static int temac_dcr_setup(struct temac_local *lp, struct platform_device *op,
188 struct device_node *np) 188 struct device_node *np)
189{ 189{
190 return -1; 190 return -1;
@@ -952,7 +952,7 @@ static const struct attribute_group temac_attr_group = {
952}; 952};
953 953
954static int __init 954static int __init
955temac_of_probe(struct of_device *op, const struct of_device_id *match) 955temac_of_probe(struct platform_device *op, const struct of_device_id *match)
956{ 956{
957 struct device_node *np; 957 struct device_node *np;
958 struct temac_local *lp; 958 struct temac_local *lp;
@@ -1094,7 +1094,7 @@ temac_of_probe(struct of_device *op, const struct of_device_id *match)
1094 return rc; 1094 return rc;
1095} 1095}
1096 1096
1097static int __devexit temac_of_remove(struct of_device *op) 1097static int __devexit temac_of_remove(struct platform_device *op)
1098{ 1098{
1099 struct net_device *ndev = dev_get_drvdata(&op->dev); 1099 struct net_device *ndev = dev_get_drvdata(&op->dev);
1100 struct temac_local *lp = netdev_priv(ndev); 1100 struct temac_local *lp = netdev_priv(ndev);
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index d771d1650d60..fb2c0927d3cc 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -239,6 +239,7 @@ struct myri10ge_priv {
239 int watchdog_resets; 239 int watchdog_resets;
240 int watchdog_pause; 240 int watchdog_pause;
241 int pause; 241 int pause;
242 bool fw_name_allocated;
242 char *fw_name; 243 char *fw_name;
243 char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE]; 244 char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE];
244 char *product_code_string; 245 char *product_code_string;
@@ -271,6 +272,7 @@ MODULE_FIRMWARE("myri10ge_eth_z8e.dat");
271MODULE_FIRMWARE("myri10ge_rss_ethp_z8e.dat"); 272MODULE_FIRMWARE("myri10ge_rss_ethp_z8e.dat");
272MODULE_FIRMWARE("myri10ge_rss_eth_z8e.dat"); 273MODULE_FIRMWARE("myri10ge_rss_eth_z8e.dat");
273 274
275/* Careful: must be accessed under kparam_block_sysfs_write */
274static char *myri10ge_fw_name = NULL; 276static char *myri10ge_fw_name = NULL;
275module_param(myri10ge_fw_name, charp, S_IRUGO | S_IWUSR); 277module_param(myri10ge_fw_name, charp, S_IRUGO | S_IWUSR);
276MODULE_PARM_DESC(myri10ge_fw_name, "Firmware image name"); 278MODULE_PARM_DESC(myri10ge_fw_name, "Firmware image name");
@@ -376,6 +378,14 @@ static inline void put_be32(__be32 val, __be32 __iomem * p)
376 378
377static struct net_device_stats *myri10ge_get_stats(struct net_device *dev); 379static struct net_device_stats *myri10ge_get_stats(struct net_device *dev);
378 380
381static void set_fw_name(struct myri10ge_priv *mgp, char *name, bool allocated)
382{
383 if (mgp->fw_name_allocated)
384 kfree(mgp->fw_name);
385 mgp->fw_name = name;
386 mgp->fw_name_allocated = allocated;
387}
388
379static int 389static int
380myri10ge_send_cmd(struct myri10ge_priv *mgp, u32 cmd, 390myri10ge_send_cmd(struct myri10ge_priv *mgp, u32 cmd,
381 struct myri10ge_cmd *data, int atomic) 391 struct myri10ge_cmd *data, int atomic)
@@ -747,7 +757,7 @@ static int myri10ge_load_firmware(struct myri10ge_priv *mgp, int adopt)
747 dev_warn(&mgp->pdev->dev, "via hotplug\n"); 757 dev_warn(&mgp->pdev->dev, "via hotplug\n");
748 } 758 }
749 759
750 mgp->fw_name = "adopted"; 760 set_fw_name(mgp, "adopted", false);
751 mgp->tx_boundary = 2048; 761 mgp->tx_boundary = 2048;
752 myri10ge_dummy_rdma(mgp, 1); 762 myri10ge_dummy_rdma(mgp, 1);
753 status = myri10ge_get_firmware_capabilities(mgp); 763 status = myri10ge_get_firmware_capabilities(mgp);
@@ -3233,7 +3243,7 @@ static void myri10ge_firmware_probe(struct myri10ge_priv *mgp)
3233 * load the optimized firmware (which assumes aligned PCIe 3243 * load the optimized firmware (which assumes aligned PCIe
3234 * completions) in order to see if it works on this host. 3244 * completions) in order to see if it works on this host.
3235 */ 3245 */
3236 mgp->fw_name = myri10ge_fw_aligned; 3246 set_fw_name(mgp, myri10ge_fw_aligned, false);
3237 status = myri10ge_load_firmware(mgp, 1); 3247 status = myri10ge_load_firmware(mgp, 1);
3238 if (status != 0) { 3248 if (status != 0) {
3239 goto abort; 3249 goto abort;
@@ -3261,7 +3271,7 @@ static void myri10ge_firmware_probe(struct myri10ge_priv *mgp)
3261abort: 3271abort:
3262 /* fall back to using the unaligned firmware */ 3272 /* fall back to using the unaligned firmware */
3263 mgp->tx_boundary = 2048; 3273 mgp->tx_boundary = 2048;
3264 mgp->fw_name = myri10ge_fw_unaligned; 3274 set_fw_name(mgp, myri10ge_fw_unaligned, false);
3265 3275
3266} 3276}
3267 3277
@@ -3284,7 +3294,7 @@ static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
3284 dev_info(&mgp->pdev->dev, "PCIE x%d Link\n", 3294 dev_info(&mgp->pdev->dev, "PCIE x%d Link\n",
3285 link_width); 3295 link_width);
3286 mgp->tx_boundary = 4096; 3296 mgp->tx_boundary = 4096;
3287 mgp->fw_name = myri10ge_fw_aligned; 3297 set_fw_name(mgp, myri10ge_fw_aligned, false);
3288 } else { 3298 } else {
3289 myri10ge_firmware_probe(mgp); 3299 myri10ge_firmware_probe(mgp);
3290 } 3300 }
@@ -3293,22 +3303,29 @@ static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
3293 dev_info(&mgp->pdev->dev, 3303 dev_info(&mgp->pdev->dev,
3294 "Assuming aligned completions (forced)\n"); 3304 "Assuming aligned completions (forced)\n");
3295 mgp->tx_boundary = 4096; 3305 mgp->tx_boundary = 4096;
3296 mgp->fw_name = myri10ge_fw_aligned; 3306 set_fw_name(mgp, myri10ge_fw_aligned, false);
3297 } else { 3307 } else {
3298 dev_info(&mgp->pdev->dev, 3308 dev_info(&mgp->pdev->dev,
3299 "Assuming unaligned completions (forced)\n"); 3309 "Assuming unaligned completions (forced)\n");
3300 mgp->tx_boundary = 2048; 3310 mgp->tx_boundary = 2048;
3301 mgp->fw_name = myri10ge_fw_unaligned; 3311 set_fw_name(mgp, myri10ge_fw_unaligned, false);
3302 } 3312 }
3303 } 3313 }
3314
3315 kparam_block_sysfs_write(myri10ge_fw_name);
3304 if (myri10ge_fw_name != NULL) { 3316 if (myri10ge_fw_name != NULL) {
3305 overridden = 1; 3317 char *fw_name = kstrdup(myri10ge_fw_name, GFP_KERNEL);
3306 mgp->fw_name = myri10ge_fw_name; 3318 if (fw_name) {
3319 overridden = 1;
3320 set_fw_name(mgp, fw_name, true);
3321 }
3307 } 3322 }
3323 kparam_unblock_sysfs_write(myri10ge_fw_name);
3324
3308 if (mgp->board_number < MYRI10GE_MAX_BOARDS && 3325 if (mgp->board_number < MYRI10GE_MAX_BOARDS &&
3309 myri10ge_fw_names[mgp->board_number] != NULL && 3326 myri10ge_fw_names[mgp->board_number] != NULL &&
3310 strlen(myri10ge_fw_names[mgp->board_number])) { 3327 strlen(myri10ge_fw_names[mgp->board_number])) {
3311 mgp->fw_name = myri10ge_fw_names[mgp->board_number]; 3328 set_fw_name(mgp, myri10ge_fw_names[mgp->board_number], false);
3312 overridden = 1; 3329 overridden = 1;
3313 } 3330 }
3314 if (overridden) 3331 if (overridden)
@@ -3660,6 +3677,7 @@ static void myri10ge_probe_slices(struct myri10ge_priv *mgp)
3660 struct myri10ge_cmd cmd; 3677 struct myri10ge_cmd cmd;
3661 struct pci_dev *pdev = mgp->pdev; 3678 struct pci_dev *pdev = mgp->pdev;
3662 char *old_fw; 3679 char *old_fw;
3680 bool old_allocated;
3663 int i, status, ncpus, msix_cap; 3681 int i, status, ncpus, msix_cap;
3664 3682
3665 mgp->num_slices = 1; 3683 mgp->num_slices = 1;
@@ -3672,17 +3690,23 @@ static void myri10ge_probe_slices(struct myri10ge_priv *mgp)
3672 3690
3673 /* try to load the slice aware rss firmware */ 3691 /* try to load the slice aware rss firmware */
3674 old_fw = mgp->fw_name; 3692 old_fw = mgp->fw_name;
3693 old_allocated = mgp->fw_name_allocated;
3694 /* don't free old_fw if we override it. */
3695 mgp->fw_name_allocated = false;
3696
3675 if (myri10ge_fw_name != NULL) { 3697 if (myri10ge_fw_name != NULL) {
3676 dev_info(&mgp->pdev->dev, "overriding rss firmware to %s\n", 3698 dev_info(&mgp->pdev->dev, "overriding rss firmware to %s\n",
3677 myri10ge_fw_name); 3699 myri10ge_fw_name);
3678 mgp->fw_name = myri10ge_fw_name; 3700 set_fw_name(mgp, myri10ge_fw_name, false);
3679 } else if (old_fw == myri10ge_fw_aligned) 3701 } else if (old_fw == myri10ge_fw_aligned)
3680 mgp->fw_name = myri10ge_fw_rss_aligned; 3702 set_fw_name(mgp, myri10ge_fw_rss_aligned, false);
3681 else 3703 else
3682 mgp->fw_name = myri10ge_fw_rss_unaligned; 3704 set_fw_name(mgp, myri10ge_fw_rss_unaligned, false);
3683 status = myri10ge_load_firmware(mgp, 0); 3705 status = myri10ge_load_firmware(mgp, 0);
3684 if (status != 0) { 3706 if (status != 0) {
3685 dev_info(&pdev->dev, "Rss firmware not found\n"); 3707 dev_info(&pdev->dev, "Rss firmware not found\n");
3708 if (old_allocated)
3709 kfree(old_fw);
3686 return; 3710 return;
3687 } 3711 }
3688 3712
@@ -3747,6 +3771,8 @@ static void myri10ge_probe_slices(struct myri10ge_priv *mgp)
3747 mgp->num_slices); 3771 mgp->num_slices);
3748 if (status == 0) { 3772 if (status == 0) {
3749 pci_disable_msix(pdev); 3773 pci_disable_msix(pdev);
3774 if (old_allocated)
3775 kfree(old_fw);
3750 return; 3776 return;
3751 } 3777 }
3752 if (status > 0) 3778 if (status > 0)
@@ -3763,7 +3789,7 @@ disable_msix:
3763 3789
3764abort_with_fw: 3790abort_with_fw:
3765 mgp->num_slices = 1; 3791 mgp->num_slices = 1;
3766 mgp->fw_name = old_fw; 3792 set_fw_name(mgp, old_fw, old_allocated);
3767 myri10ge_load_firmware(mgp, 0); 3793 myri10ge_load_firmware(mgp, 0);
3768} 3794}
3769 3795
@@ -3993,6 +4019,7 @@ abort_with_enabled:
3993 pci_disable_device(pdev); 4019 pci_disable_device(pdev);
3994 4020
3995abort_with_netdev: 4021abort_with_netdev:
4022 set_fw_name(mgp, NULL, false);
3996 free_netdev(netdev); 4023 free_netdev(netdev);
3997 return status; 4024 return status;
3998} 4025}
@@ -4037,6 +4064,7 @@ static void myri10ge_remove(struct pci_dev *pdev)
4037 dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd), 4064 dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
4038 mgp->cmd, mgp->cmd_bus); 4065 mgp->cmd, mgp->cmd_bus);
4039 4066
4067 set_fw_name(mgp, NULL, false);
4040 free_netdev(netdev); 4068 free_netdev(netdev);
4041 pci_disable_device(pdev); 4069 pci_disable_device(pdev);
4042 pci_set_drvdata(pdev, NULL); 4070 pci_set_drvdata(pdev, NULL);
diff --git a/drivers/net/myri_sbus.c b/drivers/net/myri_sbus.c
index 04e552aa14ec..617f898ba5f0 100644
--- a/drivers/net/myri_sbus.c
+++ b/drivers/net/myri_sbus.c
@@ -926,7 +926,7 @@ static const struct net_device_ops myri_ops = {
926 .ndo_validate_addr = eth_validate_addr, 926 .ndo_validate_addr = eth_validate_addr,
927}; 927};
928 928
929static int __devinit myri_sbus_probe(struct of_device *op, const struct of_device_id *match) 929static int __devinit myri_sbus_probe(struct platform_device *op, const struct of_device_id *match)
930{ 930{
931 struct device_node *dp = op->dev.of_node; 931 struct device_node *dp = op->dev.of_node;
932 static unsigned version_printed; 932 static unsigned version_printed;
@@ -1124,7 +1124,7 @@ err:
1124 return -ENODEV; 1124 return -ENODEV;
1125} 1125}
1126 1126
1127static int __devexit myri_sbus_remove(struct of_device *op) 1127static int __devexit myri_sbus_remove(struct platform_device *op)
1128{ 1128{
1129 struct myri_eth *mp = dev_get_drvdata(&op->dev); 1129 struct myri_eth *mp = dev_get_drvdata(&op->dev);
1130 struct net_device *net_dev = mp->dev; 1130 struct net_device *net_dev = mp->dev;
diff --git a/drivers/net/myri_sbus.h b/drivers/net/myri_sbus.h
index ff363e95d9cf..80a2fa5cf757 100644
--- a/drivers/net/myri_sbus.h
+++ b/drivers/net/myri_sbus.h
@@ -288,7 +288,7 @@ struct myri_eth {
288 struct myri_eeprom eeprom; /* Local copy of EEPROM. */ 288 struct myri_eeprom eeprom; /* Local copy of EEPROM. */
289 unsigned int reg_size; /* Size of register space. */ 289 unsigned int reg_size; /* Size of register space. */
290 unsigned int shmem_base; /* Offset to shared ram. */ 290 unsigned int shmem_base; /* Offset to shared ram. */
291 struct of_device *myri_op; /* Our OF device struct. */ 291 struct platform_device *myri_op; /* Our OF device struct. */
292}; 292};
293 293
294/* We use this to acquire receive skb's that we can DMA directly into. */ 294/* We use this to acquire receive skb's that we can DMA directly into. */
diff --git a/drivers/net/niu.c b/drivers/net/niu.c
index 404f2d552888..bc695d53cdcc 100644
--- a/drivers/net/niu.c
+++ b/drivers/net/niu.c
@@ -9103,7 +9103,7 @@ retry:
9103static int __devinit niu_n2_irq_init(struct niu *np, u8 *ldg_num_map) 9103static int __devinit niu_n2_irq_init(struct niu *np, u8 *ldg_num_map)
9104{ 9104{
9105#ifdef CONFIG_SPARC64 9105#ifdef CONFIG_SPARC64
9106 struct of_device *op = np->op; 9106 struct platform_device *op = np->op;
9107 const u32 *int_prop; 9107 const u32 *int_prop;
9108 int i; 9108 int i;
9109 9109
@@ -9688,7 +9688,7 @@ static void __devinit niu_driver_version(void)
9688 9688
9689static struct net_device * __devinit niu_alloc_and_init( 9689static struct net_device * __devinit niu_alloc_and_init(
9690 struct device *gen_dev, struct pci_dev *pdev, 9690 struct device *gen_dev, struct pci_dev *pdev,
9691 struct of_device *op, const struct niu_ops *ops, 9691 struct platform_device *op, const struct niu_ops *ops,
9692 u8 port) 9692 u8 port)
9693{ 9693{
9694 struct net_device *dev; 9694 struct net_device *dev;
@@ -10064,7 +10064,7 @@ static const struct niu_ops niu_phys_ops = {
10064 .unmap_single = niu_phys_unmap_single, 10064 .unmap_single = niu_phys_unmap_single,
10065}; 10065};
10066 10066
10067static int __devinit niu_of_probe(struct of_device *op, 10067static int __devinit niu_of_probe(struct platform_device *op,
10068 const struct of_device_id *match) 10068 const struct of_device_id *match)
10069{ 10069{
10070 union niu_parent_id parent_id; 10070 union niu_parent_id parent_id;
@@ -10179,7 +10179,7 @@ err_out:
10179 return err; 10179 return err;
10180} 10180}
10181 10181
10182static int __devexit niu_of_remove(struct of_device *op) 10182static int __devexit niu_of_remove(struct platform_device *op)
10183{ 10183{
10184 struct net_device *dev = dev_get_drvdata(&op->dev); 10184 struct net_device *dev = dev_get_drvdata(&op->dev);
10185 10185
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index a527e37728cd..eb799b36c86a 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -5,7 +5,7 @@
5menuconfig PHYLIB 5menuconfig PHYLIB
6 tristate "PHY Device support and infrastructure" 6 tristate "PHY Device support and infrastructure"
7 depends on !S390 7 depends on !S390
8 depends on NET_ETHERNET 8 depends on NETDEVICES
9 help 9 help
10 Ethernet controllers are usually attached to PHY 10 Ethernet controllers are usually attached to PHY
11 devices. This option provides infrastructure for 11 devices. This option provides infrastructure for
diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index fc5fef2a8175..f62c7b717bc8 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -188,7 +188,7 @@ static int __devexit mdio_gpio_remove(struct platform_device *pdev)
188 188
189#ifdef CONFIG_OF_GPIO 189#ifdef CONFIG_OF_GPIO
190 190
191static int __devinit mdio_ofgpio_probe(struct of_device *ofdev, 191static int __devinit mdio_ofgpio_probe(struct platform_device *ofdev,
192 const struct of_device_id *match) 192 const struct of_device_id *match)
193{ 193{
194 struct mdio_gpio_platform_data *pdata; 194 struct mdio_gpio_platform_data *pdata;
@@ -224,7 +224,7 @@ out_free:
224 return -ENODEV; 224 return -ENODEV;
225} 225}
226 226
227static int __devexit mdio_ofgpio_remove(struct of_device *ofdev) 227static int __devexit mdio_ofgpio_remove(struct platform_device *ofdev)
228{ 228{
229 mdio_gpio_bus_destroy(&ofdev->dev); 229 mdio_gpio_bus_destroy(&ofdev->dev);
230 kfree(ofdev->dev.platform_data); 230 kfree(ofdev->dev.platform_data);
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 5130db8f5c4e..1bb16cb79433 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -301,7 +301,7 @@ EXPORT_SYMBOL(phy_ethtool_gset);
301/** 301/**
302 * phy_mii_ioctl - generic PHY MII ioctl interface 302 * phy_mii_ioctl - generic PHY MII ioctl interface
303 * @phydev: the phy_device struct 303 * @phydev: the phy_device struct
304 * @mii_data: MII ioctl data 304 * @ifr: &struct ifreq for socket ioctl's
305 * @cmd: ioctl cmd to execute 305 * @cmd: ioctl cmd to execute
306 * 306 *
307 * Note that this function is currently incompatible with the 307 * Note that this function is currently incompatible with the
diff --git a/drivers/net/qlcnic/qlcnic_main.c b/drivers/net/qlcnic/qlcnic_main.c
index b9615bd745ea..bf6d87adda4f 100644
--- a/drivers/net/qlcnic/qlcnic_main.c
+++ b/drivers/net/qlcnic/qlcnic_main.c
@@ -473,48 +473,58 @@ qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter)
473static int 473static int
474qlcnic_init_pci_info(struct qlcnic_adapter *adapter) 474qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
475{ 475{
476 struct qlcnic_pci_info pci_info[QLCNIC_MAX_PCI_FUNC]; 476 struct qlcnic_pci_info *pci_info;
477 int i, ret = 0, err; 477 int i, ret = 0, err;
478 u8 pfn; 478 u8 pfn;
479 479
480 if (!adapter->npars) 480 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
481 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) * 481 if (!pci_info)
482 QLCNIC_MAX_PCI_FUNC, GFP_KERNEL);
483 if (!adapter->npars)
484 return -ENOMEM; 482 return -ENOMEM;
485 483
486 if (!adapter->eswitch) 484 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
487 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) * 485 QLCNIC_MAX_PCI_FUNC, GFP_KERNEL);
486 if (!adapter->npars) {
487 err = -ENOMEM;
488 goto err_pci_info;
489 }
490
491 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
488 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL); 492 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
489 if (!adapter->eswitch) { 493 if (!adapter->eswitch) {
490 err = -ENOMEM; 494 err = -ENOMEM;
491 goto err_eswitch; 495 goto err_npars;
492 } 496 }
493 497
494 ret = qlcnic_get_pci_info(adapter, pci_info); 498 ret = qlcnic_get_pci_info(adapter, pci_info);
495 if (!ret) { 499 if (ret)
496 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 500 goto err_eswitch;
497 pfn = pci_info[i].id;
498 if (pfn > QLCNIC_MAX_PCI_FUNC)
499 return QL_STATUS_INVALID_PARAM;
500 adapter->npars[pfn].active = pci_info[i].active;
501 adapter->npars[pfn].type = pci_info[i].type;
502 adapter->npars[pfn].phy_port = pci_info[i].default_port;
503 adapter->npars[pfn].mac_learning = DEFAULT_MAC_LEARN;
504 adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw;
505 adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw;
506 }
507
508 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
509 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
510 501
511 return ret; 502 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
503 pfn = pci_info[i].id;
504 if (pfn > QLCNIC_MAX_PCI_FUNC)
505 return QL_STATUS_INVALID_PARAM;
506 adapter->npars[pfn].active = pci_info[i].active;
507 adapter->npars[pfn].type = pci_info[i].type;
508 adapter->npars[pfn].phy_port = pci_info[i].default_port;
509 adapter->npars[pfn].mac_learning = DEFAULT_MAC_LEARN;
510 adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw;
511 adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw;
512 } 512 }
513 513
514 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
515 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
516
517 kfree(pci_info);
518 return 0;
519
520err_eswitch:
514 kfree(adapter->eswitch); 521 kfree(adapter->eswitch);
515 adapter->eswitch = NULL; 522 adapter->eswitch = NULL;
516err_eswitch: 523err_npars:
517 kfree(adapter->npars); 524 kfree(adapter->npars);
525 adapter->npars = NULL;
526err_pci_info:
527 kfree(pci_info);
518 528
519 return ret; 529 return ret;
520} 530}
@@ -3361,15 +3371,21 @@ qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj,
3361 struct device *dev = container_of(kobj, struct device, kobj); 3371 struct device *dev = container_of(kobj, struct device, kobj);
3362 struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3372 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3363 struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC]; 3373 struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC];
3364 struct qlcnic_pci_info pci_info[QLCNIC_MAX_PCI_FUNC]; 3374 struct qlcnic_pci_info *pci_info;
3365 int i, ret; 3375 int i, ret;
3366 3376
3367 if (size != sizeof(pci_cfg)) 3377 if (size != sizeof(pci_cfg))
3368 return QL_STATUS_INVALID_PARAM; 3378 return QL_STATUS_INVALID_PARAM;
3369 3379
3380 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
3381 if (!pci_info)
3382 return -ENOMEM;
3383
3370 ret = qlcnic_get_pci_info(adapter, pci_info); 3384 ret = qlcnic_get_pci_info(adapter, pci_info);
3371 if (ret) 3385 if (ret) {
3386 kfree(pci_info);
3372 return ret; 3387 return ret;
3388 }
3373 3389
3374 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) { 3390 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) {
3375 pci_cfg[i].pci_func = pci_info[i].id; 3391 pci_cfg[i].pci_func = pci_info[i].id;
@@ -3380,8 +3396,8 @@ qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj,
3380 memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN); 3396 memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN);
3381 } 3397 }
3382 memcpy(buf, &pci_cfg, size); 3398 memcpy(buf, &pci_cfg, size);
3399 kfree(pci_info);
3383 return size; 3400 return size;
3384
3385} 3401}
3386static struct bin_attribute bin_attr_npar_config = { 3402static struct bin_attribute bin_attr_npar_config = {
3387 .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)}, 3403 .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)},
diff --git a/drivers/net/sunbmac.c b/drivers/net/sunbmac.c
index 09c071bd6ad4..618643e3ca3e 100644
--- a/drivers/net/sunbmac.c
+++ b/drivers/net/sunbmac.c
@@ -97,7 +97,7 @@ static int qec_global_reset(void __iomem *gregs)
97 97
98static void qec_init(struct bigmac *bp) 98static void qec_init(struct bigmac *bp)
99{ 99{
100 struct of_device *qec_op = bp->qec_op; 100 struct platform_device *qec_op = bp->qec_op;
101 void __iomem *gregs = bp->gregs; 101 void __iomem *gregs = bp->gregs;
102 u8 bsizes = bp->bigmac_bursts; 102 u8 bsizes = bp->bigmac_bursts;
103 u32 regval; 103 u32 regval;
@@ -1083,8 +1083,8 @@ static const struct net_device_ops bigmac_ops = {
1083 .ndo_validate_addr = eth_validate_addr, 1083 .ndo_validate_addr = eth_validate_addr,
1084}; 1084};
1085 1085
1086static int __devinit bigmac_ether_init(struct of_device *op, 1086static int __devinit bigmac_ether_init(struct platform_device *op,
1087 struct of_device *qec_op) 1087 struct platform_device *qec_op)
1088{ 1088{
1089 static int version_printed; 1089 static int version_printed;
1090 struct net_device *dev; 1090 struct net_device *dev;
@@ -1242,25 +1242,25 @@ fail_and_cleanup:
1242/* QEC can be the parent of either QuadEthernet or a BigMAC. We want 1242/* QEC can be the parent of either QuadEthernet or a BigMAC. We want
1243 * the latter. 1243 * the latter.
1244 */ 1244 */
1245static int __devinit bigmac_sbus_probe(struct of_device *op, 1245static int __devinit bigmac_sbus_probe(struct platform_device *op,
1246 const struct of_device_id *match) 1246 const struct of_device_id *match)
1247{ 1247{
1248 struct device *parent = op->dev.parent; 1248 struct device *parent = op->dev.parent;
1249 struct of_device *qec_op; 1249 struct platform_device *qec_op;
1250 1250
1251 qec_op = to_of_device(parent); 1251 qec_op = to_platform_device(parent);
1252 1252
1253 return bigmac_ether_init(op, qec_op); 1253 return bigmac_ether_init(op, qec_op);
1254} 1254}
1255 1255
1256static int __devexit bigmac_sbus_remove(struct of_device *op) 1256static int __devexit bigmac_sbus_remove(struct platform_device *op)
1257{ 1257{
1258 struct bigmac *bp = dev_get_drvdata(&op->dev); 1258 struct bigmac *bp = dev_get_drvdata(&op->dev);
1259 struct device *parent = op->dev.parent; 1259 struct device *parent = op->dev.parent;
1260 struct net_device *net_dev = bp->dev; 1260 struct net_device *net_dev = bp->dev;
1261 struct of_device *qec_op; 1261 struct platform_device *qec_op;
1262 1262
1263 qec_op = to_of_device(parent); 1263 qec_op = to_platform_device(parent);
1264 1264
1265 unregister_netdev(net_dev); 1265 unregister_netdev(net_dev);
1266 1266
diff --git a/drivers/net/sunbmac.h b/drivers/net/sunbmac.h
index 8840bc0b840b..8db88945b889 100644
--- a/drivers/net/sunbmac.h
+++ b/drivers/net/sunbmac.h
@@ -329,8 +329,8 @@ struct bigmac {
329 unsigned int timer_ticks; 329 unsigned int timer_ticks;
330 330
331 struct net_device_stats enet_stats; 331 struct net_device_stats enet_stats;
332 struct of_device *qec_op; 332 struct platform_device *qec_op;
333 struct of_device *bigmac_op; 333 struct platform_device *bigmac_op;
334 struct net_device *dev; 334 struct net_device *dev;
335}; 335};
336 336
diff --git a/drivers/net/sunhme.c b/drivers/net/sunhme.c
index eec443f64079..bd0df1c14955 100644
--- a/drivers/net/sunhme.c
+++ b/drivers/net/sunhme.c
@@ -1591,7 +1591,7 @@ static int happy_meal_init(struct happy_meal *hp)
1591 */ 1591 */
1592#ifdef CONFIG_SBUS 1592#ifdef CONFIG_SBUS
1593 if ((hp->happy_flags & HFLAG_PCI) == 0) { 1593 if ((hp->happy_flags & HFLAG_PCI) == 0) {
1594 struct of_device *op = hp->happy_dev; 1594 struct platform_device *op = hp->happy_dev;
1595 if (sbus_can_dma_64bit()) { 1595 if (sbus_can_dma_64bit()) {
1596 sbus_set_sbus64(&op->dev, 1596 sbus_set_sbus64(&op->dev,
1597 hp->happy_bursts); 1597 hp->happy_bursts);
@@ -2480,7 +2480,7 @@ static void hme_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info
2480#ifdef CONFIG_SBUS 2480#ifdef CONFIG_SBUS
2481 else { 2481 else {
2482 const struct linux_prom_registers *regs; 2482 const struct linux_prom_registers *regs;
2483 struct of_device *op = hp->happy_dev; 2483 struct platform_device *op = hp->happy_dev;
2484 regs = of_get_property(op->dev.of_node, "regs", NULL); 2484 regs = of_get_property(op->dev.of_node, "regs", NULL);
2485 if (regs) 2485 if (regs)
2486 sprintf(info->bus_info, "SBUS:%d", 2486 sprintf(info->bus_info, "SBUS:%d",
@@ -2515,13 +2515,13 @@ static int hme_version_printed;
2515 * 2515 *
2516 * Return NULL on failure. 2516 * Return NULL on failure.
2517 */ 2517 */
2518static struct quattro * __devinit quattro_sbus_find(struct of_device *child) 2518static struct quattro * __devinit quattro_sbus_find(struct platform_device *child)
2519{ 2519{
2520 struct device *parent = child->dev.parent; 2520 struct device *parent = child->dev.parent;
2521 struct of_device *op; 2521 struct platform_device *op;
2522 struct quattro *qp; 2522 struct quattro *qp;
2523 2523
2524 op = to_of_device(parent); 2524 op = to_platform_device(parent);
2525 qp = dev_get_drvdata(&op->dev); 2525 qp = dev_get_drvdata(&op->dev);
2526 if (qp) 2526 if (qp)
2527 return qp; 2527 return qp;
@@ -2551,7 +2551,7 @@ static int __init quattro_sbus_register_irqs(void)
2551 struct quattro *qp; 2551 struct quattro *qp;
2552 2552
2553 for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) { 2553 for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) {
2554 struct of_device *op = qp->quattro_dev; 2554 struct platform_device *op = qp->quattro_dev;
2555 int err, qfe_slot, skip = 0; 2555 int err, qfe_slot, skip = 0;
2556 2556
2557 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++) { 2557 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++) {
@@ -2580,7 +2580,7 @@ static void quattro_sbus_free_irqs(void)
2580 struct quattro *qp; 2580 struct quattro *qp;
2581 2581
2582 for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) { 2582 for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) {
2583 struct of_device *op = qp->quattro_dev; 2583 struct platform_device *op = qp->quattro_dev;
2584 int qfe_slot, skip = 0; 2584 int qfe_slot, skip = 0;
2585 2585
2586 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++) { 2586 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++) {
@@ -2639,7 +2639,7 @@ static const struct net_device_ops hme_netdev_ops = {
2639}; 2639};
2640 2640
2641#ifdef CONFIG_SBUS 2641#ifdef CONFIG_SBUS
2642static int __devinit happy_meal_sbus_probe_one(struct of_device *op, int is_qfe) 2642static int __devinit happy_meal_sbus_probe_one(struct platform_device *op, int is_qfe)
2643{ 2643{
2644 struct device_node *dp = op->dev.of_node, *sbus_dp; 2644 struct device_node *dp = op->dev.of_node, *sbus_dp;
2645 struct quattro *qp = NULL; 2645 struct quattro *qp = NULL;
@@ -2648,7 +2648,7 @@ static int __devinit happy_meal_sbus_probe_one(struct of_device *op, int is_qfe)
2648 int i, qfe_slot = -1; 2648 int i, qfe_slot = -1;
2649 int err = -ENODEV; 2649 int err = -ENODEV;
2650 2650
2651 sbus_dp = to_of_device(op->dev.parent)->dev.of_node; 2651 sbus_dp = op->dev.parent->of_node;
2652 2652
2653 /* We can match PCI devices too, do not accept those here. */ 2653 /* We can match PCI devices too, do not accept those here. */
2654 if (strcmp(sbus_dp->name, "sbus")) 2654 if (strcmp(sbus_dp->name, "sbus"))
@@ -3235,7 +3235,7 @@ static void happy_meal_pci_exit(void)
3235#endif 3235#endif
3236 3236
3237#ifdef CONFIG_SBUS 3237#ifdef CONFIG_SBUS
3238static int __devinit hme_sbus_probe(struct of_device *op, const struct of_device_id *match) 3238static int __devinit hme_sbus_probe(struct platform_device *op, const struct of_device_id *match)
3239{ 3239{
3240 struct device_node *dp = op->dev.of_node; 3240 struct device_node *dp = op->dev.of_node;
3241 const char *model = of_get_property(dp, "model", NULL); 3241 const char *model = of_get_property(dp, "model", NULL);
@@ -3247,7 +3247,7 @@ static int __devinit hme_sbus_probe(struct of_device *op, const struct of_device
3247 return happy_meal_sbus_probe_one(op, is_qfe); 3247 return happy_meal_sbus_probe_one(op, is_qfe);
3248} 3248}
3249 3249
3250static int __devexit hme_sbus_remove(struct of_device *op) 3250static int __devexit hme_sbus_remove(struct platform_device *op)
3251{ 3251{
3252 struct happy_meal *hp = dev_get_drvdata(&op->dev); 3252 struct happy_meal *hp = dev_get_drvdata(&op->dev);
3253 struct net_device *net_dev = hp->dev; 3253 struct net_device *net_dev = hp->dev;
diff --git a/drivers/net/sunhme.h b/drivers/net/sunhme.h
index efd2ca0fcad3..756b5bf3aa89 100644
--- a/drivers/net/sunhme.h
+++ b/drivers/net/sunhme.h
@@ -407,7 +407,7 @@ struct happy_meal {
407 void (*write_rxd)(struct happy_meal_rxd *, u32, u32); 407 void (*write_rxd)(struct happy_meal_rxd *, u32, u32);
408#endif 408#endif
409 409
410 /* This is either an of_device or a pci_dev. */ 410 /* This is either an platform_device or a pci_dev. */
411 void *happy_dev; 411 void *happy_dev;
412 struct device *dma_dev; 412 struct device *dma_dev;
413 413
diff --git a/drivers/net/sunlance.c b/drivers/net/sunlance.c
index ee364fa75634..8dcb858f2168 100644
--- a/drivers/net/sunlance.c
+++ b/drivers/net/sunlance.c
@@ -250,7 +250,7 @@ struct lance_private {
250 int rx_new, tx_new; 250 int rx_new, tx_new;
251 int rx_old, tx_old; 251 int rx_old, tx_old;
252 252
253 struct of_device *ledma; /* If set this points to ledma */ 253 struct platform_device *ledma; /* If set this points to ledma */
254 char tpe; /* cable-selection is TPE */ 254 char tpe; /* cable-selection is TPE */
255 char auto_select; /* cable-selection by carrier */ 255 char auto_select; /* cable-selection by carrier */
256 char burst_sizes; /* ledma SBus burst sizes */ 256 char burst_sizes; /* ledma SBus burst sizes */
@@ -265,8 +265,8 @@ struct lance_private {
265 char *name; 265 char *name;
266 dma_addr_t init_block_dvma; 266 dma_addr_t init_block_dvma;
267 struct net_device *dev; /* Backpointer */ 267 struct net_device *dev; /* Backpointer */
268 struct of_device *op; 268 struct platform_device *op;
269 struct of_device *lebuffer; 269 struct platform_device *lebuffer;
270 struct timer_list multicast_timer; 270 struct timer_list multicast_timer;
271}; 271};
272 272
@@ -1272,7 +1272,7 @@ static void lance_free_hwresources(struct lance_private *lp)
1272 if (lp->lregs) 1272 if (lp->lregs)
1273 of_iounmap(&lp->op->resource[0], lp->lregs, LANCE_REG_SIZE); 1273 of_iounmap(&lp->op->resource[0], lp->lregs, LANCE_REG_SIZE);
1274 if (lp->dregs) { 1274 if (lp->dregs) {
1275 struct of_device *ledma = lp->ledma; 1275 struct platform_device *ledma = lp->ledma;
1276 1276
1277 of_iounmap(&ledma->resource[0], lp->dregs, 1277 of_iounmap(&ledma->resource[0], lp->dregs,
1278 resource_size(&ledma->resource[0])); 1278 resource_size(&ledma->resource[0]));
@@ -1319,9 +1319,9 @@ static const struct net_device_ops sparc_lance_ops = {
1319 .ndo_validate_addr = eth_validate_addr, 1319 .ndo_validate_addr = eth_validate_addr,
1320}; 1320};
1321 1321
1322static int __devinit sparc_lance_probe_one(struct of_device *op, 1322static int __devinit sparc_lance_probe_one(struct platform_device *op,
1323 struct of_device *ledma, 1323 struct platform_device *ledma,
1324 struct of_device *lebuffer) 1324 struct platform_device *lebuffer)
1325{ 1325{
1326 struct device_node *dp = op->dev.of_node; 1326 struct device_node *dp = op->dev.of_node;
1327 static unsigned version_printed; 1327 static unsigned version_printed;
@@ -1503,9 +1503,9 @@ fail:
1503 return -ENODEV; 1503 return -ENODEV;
1504} 1504}
1505 1505
1506static int __devinit sunlance_sbus_probe(struct of_device *op, const struct of_device_id *match) 1506static int __devinit sunlance_sbus_probe(struct platform_device *op, const struct of_device_id *match)
1507{ 1507{
1508 struct of_device *parent = to_of_device(op->dev.parent); 1508 struct platform_device *parent = to_platform_device(op->dev.parent);
1509 struct device_node *parent_dp = parent->dev.of_node; 1509 struct device_node *parent_dp = parent->dev.of_node;
1510 int err; 1510 int err;
1511 1511
@@ -1519,7 +1519,7 @@ static int __devinit sunlance_sbus_probe(struct of_device *op, const struct of_d
1519 return err; 1519 return err;
1520} 1520}
1521 1521
1522static int __devexit sunlance_sbus_remove(struct of_device *op) 1522static int __devexit sunlance_sbus_remove(struct platform_device *op)
1523{ 1523{
1524 struct lance_private *lp = dev_get_drvdata(&op->dev); 1524 struct lance_private *lp = dev_get_drvdata(&op->dev);
1525 struct net_device *net_dev = lp->dev; 1525 struct net_device *net_dev = lp->dev;
diff --git a/drivers/net/sunqe.c b/drivers/net/sunqe.c
index 5f84a5dadedd..72e65d4666ef 100644
--- a/drivers/net/sunqe.c
+++ b/drivers/net/sunqe.c
@@ -689,7 +689,7 @@ static void qe_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
689{ 689{
690 const struct linux_prom_registers *regs; 690 const struct linux_prom_registers *regs;
691 struct sunqe *qep = netdev_priv(dev); 691 struct sunqe *qep = netdev_priv(dev);
692 struct of_device *op; 692 struct platform_device *op;
693 693
694 strcpy(info->driver, "sunqe"); 694 strcpy(info->driver, "sunqe");
695 strcpy(info->version, "3.0"); 695 strcpy(info->version, "3.0");
@@ -720,7 +720,7 @@ static const struct ethtool_ops qe_ethtool_ops = {
720}; 720};
721 721
722/* This is only called once at boot time for each card probed. */ 722/* This is only called once at boot time for each card probed. */
723static void qec_init_once(struct sunqec *qecp, struct of_device *op) 723static void qec_init_once(struct sunqec *qecp, struct platform_device *op)
724{ 724{
725 u8 bsizes = qecp->qec_bursts; 725 u8 bsizes = qecp->qec_bursts;
726 726
@@ -770,9 +770,9 @@ static u8 __devinit qec_get_burst(struct device_node *dp)
770 return bsizes; 770 return bsizes;
771} 771}
772 772
773static struct sunqec * __devinit get_qec(struct of_device *child) 773static struct sunqec * __devinit get_qec(struct platform_device *child)
774{ 774{
775 struct of_device *op = to_of_device(child->dev.parent); 775 struct platform_device *op = to_platform_device(child->dev.parent);
776 struct sunqec *qecp; 776 struct sunqec *qecp;
777 777
778 qecp = dev_get_drvdata(&op->dev); 778 qecp = dev_get_drvdata(&op->dev);
@@ -836,7 +836,7 @@ static const struct net_device_ops qec_ops = {
836 .ndo_validate_addr = eth_validate_addr, 836 .ndo_validate_addr = eth_validate_addr,
837}; 837};
838 838
839static int __devinit qec_ether_init(struct of_device *op) 839static int __devinit qec_ether_init(struct platform_device *op)
840{ 840{
841 static unsigned version_printed; 841 static unsigned version_printed;
842 struct net_device *dev; 842 struct net_device *dev;
@@ -941,12 +941,12 @@ fail:
941 return res; 941 return res;
942} 942}
943 943
944static int __devinit qec_sbus_probe(struct of_device *op, const struct of_device_id *match) 944static int __devinit qec_sbus_probe(struct platform_device *op, const struct of_device_id *match)
945{ 945{
946 return qec_ether_init(op); 946 return qec_ether_init(op);
947} 947}
948 948
949static int __devexit qec_sbus_remove(struct of_device *op) 949static int __devexit qec_sbus_remove(struct platform_device *op)
950{ 950{
951 struct sunqe *qp = dev_get_drvdata(&op->dev); 951 struct sunqe *qp = dev_get_drvdata(&op->dev);
952 struct net_device *net_dev = qp->dev; 952 struct net_device *net_dev = qp->dev;
@@ -997,7 +997,7 @@ static void __exit qec_exit(void)
997 997
998 while (root_qec_dev) { 998 while (root_qec_dev) {
999 struct sunqec *next = root_qec_dev->next_module; 999 struct sunqec *next = root_qec_dev->next_module;
1000 struct of_device *op = root_qec_dev->op; 1000 struct platform_device *op = root_qec_dev->op;
1001 1001
1002 free_irq(op->archdata.irqs[0], (void *) root_qec_dev); 1002 free_irq(op->archdata.irqs[0], (void *) root_qec_dev);
1003 of_iounmap(&op->resource[0], root_qec_dev->gregs, 1003 of_iounmap(&op->resource[0], root_qec_dev->gregs,
diff --git a/drivers/net/sunqe.h b/drivers/net/sunqe.h
index 5813a7b2faa5..581781b6b2fa 100644
--- a/drivers/net/sunqe.h
+++ b/drivers/net/sunqe.h
@@ -314,7 +314,7 @@ struct sunqec {
314 void __iomem *gregs; /* QEC Global Registers */ 314 void __iomem *gregs; /* QEC Global Registers */
315 struct sunqe *qes[4]; /* Each child MACE */ 315 struct sunqe *qes[4]; /* Each child MACE */
316 unsigned int qec_bursts; /* Support burst sizes */ 316 unsigned int qec_bursts; /* Support burst sizes */
317 struct of_device *op; /* QEC's OF device */ 317 struct platform_device *op; /* QEC's OF device */
318 struct sunqec *next_module; /* List of all QECs in system */ 318 struct sunqec *next_module; /* List of all QECs in system */
319}; 319};
320 320
@@ -342,7 +342,7 @@ struct sunqe {
342 __u32 buffers_dvma; /* DVMA visible address. */ 342 __u32 buffers_dvma; /* DVMA visible address. */
343 struct sunqec *parent; 343 struct sunqec *parent;
344 u8 mconfig; /* Base MACE mconfig value */ 344 u8 mconfig; /* Base MACE mconfig value */
345 struct of_device *op; /* QE's OF device struct */ 345 struct platform_device *op; /* QE's OF device struct */
346 struct net_device *dev; /* QE's netdevice struct */ 346 struct net_device *dev; /* QE's netdevice struct */
347 int channel; /* Who am I? */ 347 int channel; /* Who am I? */
348}; 348};
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index 8d532f9b50d0..a4c3f5708246 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -3601,7 +3601,7 @@ static void ucc_geth_timeout(struct net_device *dev)
3601 3601
3602#ifdef CONFIG_PM 3602#ifdef CONFIG_PM
3603 3603
3604static int ucc_geth_suspend(struct of_device *ofdev, pm_message_t state) 3604static int ucc_geth_suspend(struct platform_device *ofdev, pm_message_t state)
3605{ 3605{
3606 struct net_device *ndev = dev_get_drvdata(&ofdev->dev); 3606 struct net_device *ndev = dev_get_drvdata(&ofdev->dev);
3607 struct ucc_geth_private *ugeth = netdev_priv(ndev); 3607 struct ucc_geth_private *ugeth = netdev_priv(ndev);
@@ -3629,7 +3629,7 @@ static int ucc_geth_suspend(struct of_device *ofdev, pm_message_t state)
3629 return 0; 3629 return 0;
3630} 3630}
3631 3631
3632static int ucc_geth_resume(struct of_device *ofdev) 3632static int ucc_geth_resume(struct platform_device *ofdev)
3633{ 3633{
3634 struct net_device *ndev = dev_get_drvdata(&ofdev->dev); 3634 struct net_device *ndev = dev_get_drvdata(&ofdev->dev);
3635 struct ucc_geth_private *ugeth = netdev_priv(ndev); 3635 struct ucc_geth_private *ugeth = netdev_priv(ndev);
@@ -3732,7 +3732,7 @@ static const struct net_device_ops ucc_geth_netdev_ops = {
3732#endif 3732#endif
3733}; 3733};
3734 3734
3735static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *match) 3735static int ucc_geth_probe(struct platform_device* ofdev, const struct of_device_id *match)
3736{ 3736{
3737 struct device *device = &ofdev->dev; 3737 struct device *device = &ofdev->dev;
3738 struct device_node *np = ofdev->dev.of_node; 3738 struct device_node *np = ofdev->dev.of_node;
@@ -3954,7 +3954,7 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
3954 return 0; 3954 return 0;
3955} 3955}
3956 3956
3957static int ucc_geth_remove(struct of_device* ofdev) 3957static int ucc_geth_remove(struct platform_device* ofdev)
3958{ 3958{
3959 struct device *device = &ofdev->dev; 3959 struct device *device = &ofdev->dev;
3960 struct net_device *dev = dev_get_drvdata(device); 3960 struct net_device *dev = dev_get_drvdata(device);
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 7f62e2dea28f..ca7fc9df1ccf 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(usbnet_defer_kevent);
315 315
316static void rx_complete (struct urb *urb); 316static void rx_complete (struct urb *urb);
317 317
318static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags) 318static int rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
319{ 319{
320 struct sk_buff *skb; 320 struct sk_buff *skb;
321 struct skb_data *entry; 321 struct skb_data *entry;
@@ -327,7 +327,7 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
327 netif_dbg(dev, rx_err, dev->net, "no rx skb\n"); 327 netif_dbg(dev, rx_err, dev->net, "no rx skb\n");
328 usbnet_defer_kevent (dev, EVENT_RX_MEMORY); 328 usbnet_defer_kevent (dev, EVENT_RX_MEMORY);
329 usb_free_urb (urb); 329 usb_free_urb (urb);
330 return; 330 return -ENOMEM;
331 } 331 }
332 skb_reserve (skb, NET_IP_ALIGN); 332 skb_reserve (skb, NET_IP_ALIGN);
333 333
@@ -357,6 +357,9 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
357 netif_dbg(dev, ifdown, dev->net, "device gone\n"); 357 netif_dbg(dev, ifdown, dev->net, "device gone\n");
358 netif_device_detach (dev->net); 358 netif_device_detach (dev->net);
359 break; 359 break;
360 case -EHOSTUNREACH:
361 retval = -ENOLINK;
362 break;
360 default: 363 default:
361 netif_dbg(dev, rx_err, dev->net, 364 netif_dbg(dev, rx_err, dev->net,
362 "rx submit, %d\n", retval); 365 "rx submit, %d\n", retval);
@@ -374,6 +377,7 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
374 dev_kfree_skb_any (skb); 377 dev_kfree_skb_any (skb);
375 usb_free_urb (urb); 378 usb_free_urb (urb);
376 } 379 }
380 return retval;
377} 381}
378 382
379 383
@@ -912,6 +916,7 @@ fail_halt:
912 /* tasklet could resubmit itself forever if memory is tight */ 916 /* tasklet could resubmit itself forever if memory is tight */
913 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) { 917 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
914 struct urb *urb = NULL; 918 struct urb *urb = NULL;
919 int resched = 1;
915 920
916 if (netif_running (dev->net)) 921 if (netif_running (dev->net))
917 urb = usb_alloc_urb (0, GFP_KERNEL); 922 urb = usb_alloc_urb (0, GFP_KERNEL);
@@ -922,10 +927,12 @@ fail_halt:
922 status = usb_autopm_get_interface(dev->intf); 927 status = usb_autopm_get_interface(dev->intf);
923 if (status < 0) 928 if (status < 0)
924 goto fail_lowmem; 929 goto fail_lowmem;
925 rx_submit (dev, urb, GFP_KERNEL); 930 if (rx_submit (dev, urb, GFP_KERNEL) == -ENOLINK)
931 resched = 0;
926 usb_autopm_put_interface(dev->intf); 932 usb_autopm_put_interface(dev->intf);
927fail_lowmem: 933fail_lowmem:
928 tasklet_schedule (&dev->bh); 934 if (resched)
935 tasklet_schedule (&dev->bh);
929 } 936 }
930 } 937 }
931 938
@@ -1175,8 +1182,11 @@ static void usbnet_bh (unsigned long param)
1175 // don't refill the queue all at once 1182 // don't refill the queue all at once
1176 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) { 1183 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
1177 urb = usb_alloc_urb (0, GFP_ATOMIC); 1184 urb = usb_alloc_urb (0, GFP_ATOMIC);
1178 if (urb != NULL) 1185 if (urb != NULL) {
1179 rx_submit (dev, urb, GFP_ATOMIC); 1186 if (rx_submit (dev, urb, GFP_ATOMIC) ==
1187 -ENOLINK)
1188 return;
1189 }
1180 } 1190 }
1181 if (temp != dev->rxq.qlen) 1191 if (temp != dev->rxq.qlen)
1182 netif_dbg(dev, link, dev->net, 1192 netif_dbg(dev, link, dev->net,
diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
index ad7719fe6d0a..e050bd65e037 100644
--- a/drivers/net/wan/farsync.c
+++ b/drivers/net/wan/farsync.c
@@ -885,20 +885,21 @@ fst_rx_dma_complete(struct fst_card_info *card, struct fst_port_info *port,
885 * Receive a frame through the DMA 885 * Receive a frame through the DMA
886 */ 886 */
887static inline void 887static inline void
888fst_rx_dma(struct fst_card_info *card, unsigned char *skb, 888fst_rx_dma(struct fst_card_info *card, dma_addr_t skb,
889 unsigned char *mem, int len) 889 dma_addr_t mem, int len)
890{ 890{
891 /* 891 /*
892 * This routine will setup the DMA and start it 892 * This routine will setup the DMA and start it
893 */ 893 */
894 894
895 dbg(DBG_RX, "In fst_rx_dma %p %p %d\n", skb, mem, len); 895 dbg(DBG_RX, "In fst_rx_dma %lx %lx %d\n",
896 (unsigned long) skb, (unsigned long) mem, len);
896 if (card->dmarx_in_progress) { 897 if (card->dmarx_in_progress) {
897 dbg(DBG_ASS, "In fst_rx_dma while dma in progress\n"); 898 dbg(DBG_ASS, "In fst_rx_dma while dma in progress\n");
898 } 899 }
899 900
900 outl((unsigned long) skb, card->pci_conf + DMAPADR0); /* Copy to here */ 901 outl(skb, card->pci_conf + DMAPADR0); /* Copy to here */
901 outl((unsigned long) mem, card->pci_conf + DMALADR0); /* from here */ 902 outl(mem, card->pci_conf + DMALADR0); /* from here */
902 outl(len, card->pci_conf + DMASIZ0); /* for this length */ 903 outl(len, card->pci_conf + DMASIZ0); /* for this length */
903 outl(0x00000000c, card->pci_conf + DMADPR0); /* In this direction */ 904 outl(0x00000000c, card->pci_conf + DMADPR0); /* In this direction */
904 905
@@ -1309,8 +1310,8 @@ fst_intr_rx(struct fst_card_info *card, struct fst_port_info *port)
1309 card->dma_port_rx = port; 1310 card->dma_port_rx = port;
1310 card->dma_len_rx = len; 1311 card->dma_len_rx = len;
1311 card->dma_rxpos = rxp; 1312 card->dma_rxpos = rxp;
1312 fst_rx_dma(card, (char *) card->rx_dma_handle_card, 1313 fst_rx_dma(card, card->rx_dma_handle_card,
1313 (char *) BUF_OFFSET(rxBuffer[pi][rxp][0]), len); 1314 BUF_OFFSET(rxBuffer[pi][rxp][0]), len);
1314 } 1315 }
1315 if (rxp != port->rxpos) { 1316 if (rxp != port->rxpos) {
1316 dbg(DBG_ASS, "About to increment rxpos by more than 1\n"); 1317 dbg(DBG_ASS, "About to increment rxpos by more than 1\n");
diff --git a/drivers/net/wan/ixp4xx_hss.c b/drivers/net/wan/ixp4xx_hss.c
index 88e363033e23..6c571e198835 100644
--- a/drivers/net/wan/ixp4xx_hss.c
+++ b/drivers/net/wan/ixp4xx_hss.c
@@ -396,7 +396,7 @@ static void hss_config(struct port *port)
396 msg.cmd = PORT_CONFIG_WRITE; 396 msg.cmd = PORT_CONFIG_WRITE;
397 msg.hss_port = port->id; 397 msg.hss_port = port->id;
398 msg.index = HSS_CONFIG_TX_PCR; 398 msg.index = HSS_CONFIG_TX_PCR;
399 msg.data32 = PCR_FRM_SYNC_OUTPUT_RISING | PCR_MSB_ENDIAN | 399 msg.data32 = PCR_FRM_PULSE_DISABLED | PCR_MSB_ENDIAN |
400 PCR_TX_DATA_ENABLE | PCR_SOF_NO_FBIT; 400 PCR_TX_DATA_ENABLE | PCR_SOF_NO_FBIT;
401 if (port->clock_type == CLOCK_INT) 401 if (port->clock_type == CLOCK_INT)
402 msg.data32 |= PCR_SYNC_CLK_DIR_OUTPUT; 402 msg.data32 |= PCR_SYNC_CLK_DIR_OUTPUT;
diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
index 8848333bc3a9..fec026212326 100644
--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
@@ -260,7 +260,7 @@ struct iwl_cfg iwl1000_bgn_cfg = {
260 .shadow_ram_support = false, 260 .shadow_ram_support = false,
261 .ht_greenfield_support = true, 261 .ht_greenfield_support = true,
262 .led_compensation = 51, 262 .led_compensation = 51,
263 .use_rts_for_ht = true, /* use rts/cts protection */ 263 .use_rts_for_aggregation = true, /* use rts/cts protection */
264 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 264 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
265 .support_ct_kill_exit = true, 265 .support_ct_kill_exit = true,
266 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF, 266 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF,
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index a07310fefcf2..6950a783913b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -769,22 +769,6 @@ void iwl3945_hw_build_tx_cmd_rate(struct iwl_priv *priv,
769 rts_retry_limit = data_retry_limit; 769 rts_retry_limit = data_retry_limit;
770 tx_cmd->rts_retry_limit = rts_retry_limit; 770 tx_cmd->rts_retry_limit = rts_retry_limit;
771 771
772 if (ieee80211_is_mgmt(fc)) {
773 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
774 case cpu_to_le16(IEEE80211_STYPE_AUTH):
775 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
776 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
777 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
778 if (tx_flags & TX_CMD_FLG_RTS_MSK) {
779 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
780 tx_flags |= TX_CMD_FLG_CTS_MSK;
781 }
782 break;
783 default:
784 break;
785 }
786 }
787
788 tx_cmd->rate = rate; 772 tx_cmd->rate = rate;
789 tx_cmd->tx_flags = tx_flags; 773 tx_cmd->tx_flags = tx_flags;
790 774
@@ -2717,7 +2701,7 @@ static struct iwl_lib_ops iwl3945_lib = {
2717static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = { 2701static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
2718 .get_hcmd_size = iwl3945_get_hcmd_size, 2702 .get_hcmd_size = iwl3945_get_hcmd_size,
2719 .build_addsta_hcmd = iwl3945_build_addsta_hcmd, 2703 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
2720 .rts_tx_cmd_flag = iwlcore_rts_tx_cmd_flag, 2704 .tx_cmd_protection = iwlcore_tx_cmd_protection,
2721 .request_scan = iwl3945_request_scan, 2705 .request_scan = iwl3945_request_scan,
2722}; 2706};
2723 2707
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index d6531ad3906a..d6da356608fa 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -2223,7 +2223,7 @@ static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
2223 .build_addsta_hcmd = iwl4965_build_addsta_hcmd, 2223 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
2224 .chain_noise_reset = iwl4965_chain_noise_reset, 2224 .chain_noise_reset = iwl4965_chain_noise_reset,
2225 .gain_computation = iwl4965_gain_computation, 2225 .gain_computation = iwl4965_gain_computation,
2226 .rts_tx_cmd_flag = iwlcore_rts_tx_cmd_flag, 2226 .tx_cmd_protection = iwlcore_tx_cmd_protection,
2227 .calc_rssi = iwl4965_calc_rssi, 2227 .calc_rssi = iwl4965_calc_rssi,
2228 .request_scan = iwlagn_request_scan, 2228 .request_scan = iwlagn_request_scan,
2229}; 2229};
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index 8093ce2804fb..aacf3770f075 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -506,7 +506,7 @@ struct iwl_cfg iwl5300_agn_cfg = {
506 .use_bsm = false, 506 .use_bsm = false,
507 .ht_greenfield_support = true, 507 .ht_greenfield_support = true,
508 .led_compensation = 51, 508 .led_compensation = 51,
509 .use_rts_for_ht = true, /* use rts/cts protection */ 509 .use_rts_for_aggregation = true, /* use rts/cts protection */
510 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 510 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
511 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 511 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
512 .chain_noise_scale = 1000, 512 .chain_noise_scale = 1000,
@@ -537,7 +537,7 @@ struct iwl_cfg iwl5100_bgn_cfg = {
537 .use_bsm = false, 537 .use_bsm = false,
538 .ht_greenfield_support = true, 538 .ht_greenfield_support = true,
539 .led_compensation = 51, 539 .led_compensation = 51,
540 .use_rts_for_ht = true, /* use rts/cts protection */ 540 .use_rts_for_aggregation = true, /* use rts/cts protection */
541 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 541 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
542 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 542 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
543 .chain_noise_scale = 1000, 543 .chain_noise_scale = 1000,
@@ -597,7 +597,7 @@ struct iwl_cfg iwl5100_agn_cfg = {
597 .use_bsm = false, 597 .use_bsm = false,
598 .ht_greenfield_support = true, 598 .ht_greenfield_support = true,
599 .led_compensation = 51, 599 .led_compensation = 51,
600 .use_rts_for_ht = true, /* use rts/cts protection */ 600 .use_rts_for_aggregation = true, /* use rts/cts protection */
601 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 601 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
602 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 602 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
603 .chain_noise_scale = 1000, 603 .chain_noise_scale = 1000,
@@ -628,7 +628,7 @@ struct iwl_cfg iwl5350_agn_cfg = {
628 .use_bsm = false, 628 .use_bsm = false,
629 .ht_greenfield_support = true, 629 .ht_greenfield_support = true,
630 .led_compensation = 51, 630 .led_compensation = 51,
631 .use_rts_for_ht = true, /* use rts/cts protection */ 631 .use_rts_for_aggregation = true, /* use rts/cts protection */
632 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 632 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
633 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 633 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
634 .chain_noise_scale = 1000, 634 .chain_noise_scale = 1000,
@@ -659,7 +659,7 @@ struct iwl_cfg iwl5150_agn_cfg = {
659 .use_bsm = false, 659 .use_bsm = false,
660 .ht_greenfield_support = true, 660 .ht_greenfield_support = true,
661 .led_compensation = 51, 661 .led_compensation = 51,
662 .use_rts_for_ht = true, /* use rts/cts protection */ 662 .use_rts_for_aggregation = true, /* use rts/cts protection */
663 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 663 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
664 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 664 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
665 .chain_noise_scale = 1000, 665 .chain_noise_scale = 1000,
diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
index 58270529a0e4..af4fd50f3405 100644
--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
@@ -381,7 +381,7 @@ struct iwl_cfg iwl6000g2a_2agn_cfg = {
381 .shadow_ram_support = true, 381 .shadow_ram_support = true,
382 .ht_greenfield_support = true, 382 .ht_greenfield_support = true,
383 .led_compensation = 51, 383 .led_compensation = 51,
384 .use_rts_for_ht = true, /* use rts/cts protection */ 384 .use_rts_for_aggregation = true, /* use rts/cts protection */
385 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 385 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
386 .supports_idle = true, 386 .supports_idle = true,
387 .adv_thermal_throttle = true, 387 .adv_thermal_throttle = true,
@@ -489,7 +489,7 @@ struct iwl_cfg iwl6000g2b_2agn_cfg = {
489 .shadow_ram_support = true, 489 .shadow_ram_support = true,
490 .ht_greenfield_support = true, 490 .ht_greenfield_support = true,
491 .led_compensation = 51, 491 .led_compensation = 51,
492 .use_rts_for_ht = true, /* use rts/cts protection */ 492 .use_rts_for_aggregation = true, /* use rts/cts protection */
493 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 493 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
494 .supports_idle = true, 494 .supports_idle = true,
495 .adv_thermal_throttle = true, 495 .adv_thermal_throttle = true,
@@ -563,7 +563,7 @@ struct iwl_cfg iwl6000g2b_2bgn_cfg = {
563 .shadow_ram_support = true, 563 .shadow_ram_support = true,
564 .ht_greenfield_support = true, 564 .ht_greenfield_support = true,
565 .led_compensation = 51, 565 .led_compensation = 51,
566 .use_rts_for_ht = true, /* use rts/cts protection */ 566 .use_rts_for_aggregation = true, /* use rts/cts protection */
567 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 567 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
568 .supports_idle = true, 568 .supports_idle = true,
569 .adv_thermal_throttle = true, 569 .adv_thermal_throttle = true,
@@ -637,7 +637,7 @@ struct iwl_cfg iwl6000g2b_bgn_cfg = {
637 .shadow_ram_support = true, 637 .shadow_ram_support = true,
638 .ht_greenfield_support = true, 638 .ht_greenfield_support = true,
639 .led_compensation = 51, 639 .led_compensation = 51,
640 .use_rts_for_ht = true, /* use rts/cts protection */ 640 .use_rts_for_aggregation = true, /* use rts/cts protection */
641 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 641 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
642 .supports_idle = true, 642 .supports_idle = true,
643 .adv_thermal_throttle = true, 643 .adv_thermal_throttle = true,
@@ -714,7 +714,7 @@ struct iwl_cfg iwl6000i_2agn_cfg = {
714 .shadow_ram_support = true, 714 .shadow_ram_support = true,
715 .ht_greenfield_support = true, 715 .ht_greenfield_support = true,
716 .led_compensation = 51, 716 .led_compensation = 51,
717 .use_rts_for_ht = true, /* use rts/cts protection */ 717 .use_rts_for_aggregation = true, /* use rts/cts protection */
718 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 718 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
719 .supports_idle = true, 719 .supports_idle = true,
720 .adv_thermal_throttle = true, 720 .adv_thermal_throttle = true,
@@ -821,7 +821,7 @@ struct iwl_cfg iwl6050_2agn_cfg = {
821 .shadow_ram_support = true, 821 .shadow_ram_support = true,
822 .ht_greenfield_support = true, 822 .ht_greenfield_support = true,
823 .led_compensation = 51, 823 .led_compensation = 51,
824 .use_rts_for_ht = true, /* use rts/cts protection */ 824 .use_rts_for_aggregation = true, /* use rts/cts protection */
825 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 825 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
826 .supports_idle = true, 826 .supports_idle = true,
827 .adv_thermal_throttle = true, 827 .adv_thermal_throttle = true,
@@ -859,7 +859,7 @@ struct iwl_cfg iwl6050g2_bgn_cfg = {
859 .shadow_ram_support = true, 859 .shadow_ram_support = true,
860 .ht_greenfield_support = true, 860 .ht_greenfield_support = true,
861 .led_compensation = 51, 861 .led_compensation = 51,
862 .use_rts_for_ht = true, /* use rts/cts protection */ 862 .use_rts_for_aggregation = true, /* use rts/cts protection */
863 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 863 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
864 .supports_idle = true, 864 .supports_idle = true,
865 .adv_thermal_throttle = true, 865 .adv_thermal_throttle = true,
@@ -933,7 +933,7 @@ struct iwl_cfg iwl6000_3agn_cfg = {
933 .shadow_ram_support = true, 933 .shadow_ram_support = true,
934 .ht_greenfield_support = true, 934 .ht_greenfield_support = true,
935 .led_compensation = 51, 935 .led_compensation = 51,
936 .use_rts_for_ht = true, /* use rts/cts protection */ 936 .use_rts_for_aggregation = true, /* use rts/cts protection */
937 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 937 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
938 .supports_idle = true, 938 .supports_idle = true,
939 .adv_thermal_throttle = true, 939 .adv_thermal_throttle = true,
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c b/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
index a7216dda9786..75b901b3eb1e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
@@ -211,10 +211,21 @@ static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
211 } 211 }
212} 212}
213 213
214static void iwlagn_rts_tx_cmd_flag(struct ieee80211_tx_info *info, 214static void iwlagn_tx_cmd_protection(struct iwl_priv *priv,
215 __le32 *tx_flags) 215 struct ieee80211_tx_info *info,
216 __le16 fc, __le32 *tx_flags)
216{ 217{
217 *tx_flags |= TX_CMD_FLG_PROT_REQUIRE_MSK; 218 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS ||
219 info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
220 *tx_flags |= TX_CMD_FLG_PROT_REQUIRE_MSK;
221 return;
222 }
223
224 if (priv->cfg->use_rts_for_aggregation &&
225 info->flags & IEEE80211_TX_CTL_AMPDU) {
226 *tx_flags |= TX_CMD_FLG_PROT_REQUIRE_MSK;
227 return;
228 }
218} 229}
219 230
220/* Calc max signal level (dBm) among 3 possible receivers */ 231/* Calc max signal level (dBm) among 3 possible receivers */
@@ -268,7 +279,7 @@ struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = {
268 .build_addsta_hcmd = iwlagn_build_addsta_hcmd, 279 .build_addsta_hcmd = iwlagn_build_addsta_hcmd,
269 .gain_computation = iwlagn_gain_computation, 280 .gain_computation = iwlagn_gain_computation,
270 .chain_noise_reset = iwlagn_chain_noise_reset, 281 .chain_noise_reset = iwlagn_chain_noise_reset,
271 .rts_tx_cmd_flag = iwlagn_rts_tx_cmd_flag, 282 .tx_cmd_protection = iwlagn_tx_cmd_protection,
272 .calc_rssi = iwlagn_calc_rssi, 283 .calc_rssi = iwlagn_calc_rssi,
273 .request_scan = iwlagn_request_scan, 284 .request_scan = iwlagn_request_scan,
274}; 285};
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c b/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
index d04502d54df3..69155aa448fb 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
@@ -379,10 +379,7 @@ static void iwlagn_tx_cmd_build_basic(struct iwl_priv *priv,
379 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; 379 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
380 } 380 }
381 381
382 priv->cfg->ops->utils->rts_tx_cmd_flag(info, &tx_flags); 382 priv->cfg->ops->utils->tx_cmd_protection(priv, info, fc, &tx_flags);
383
384 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
385 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
386 383
387 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); 384 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
388 if (ieee80211_is_mgmt(fc)) { 385 if (ieee80211_is_mgmt(fc)) {
@@ -456,21 +453,6 @@ static void iwlagn_tx_cmd_build_rate(struct iwl_priv *priv,
456 if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE)) 453 if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
457 rate_flags |= RATE_MCS_CCK_MSK; 454 rate_flags |= RATE_MCS_CCK_MSK;
458 455
459 /* Set up RTS and CTS flags for certain packets */
460 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
461 case cpu_to_le16(IEEE80211_STYPE_AUTH):
462 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
463 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
464 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
465 if (tx_cmd->tx_flags & TX_CMD_FLG_RTS_MSK) {
466 tx_cmd->tx_flags &= ~TX_CMD_FLG_RTS_MSK;
467 tx_cmd->tx_flags |= TX_CMD_FLG_CTS_MSK;
468 }
469 break;
470 default:
471 break;
472 }
473
474 /* Set up antennas */ 456 /* Set up antennas */
475 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant, 457 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
476 priv->hw_params.valid_tx_ant); 458 priv->hw_params.valid_tx_ant);
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index 35337b1e7cac..c1882fd8345d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -202,13 +202,6 @@ int iwl_commit_rxon(struct iwl_priv *priv)
202 202
203 priv->start_calib = 0; 203 priv->start_calib = 0;
204 if (new_assoc) { 204 if (new_assoc) {
205 /*
206 * allow CTS-to-self if possible for new association.
207 * this is relevant only for 5000 series and up,
208 * but will not damage 4965
209 */
210 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
211
212 /* Apply the new configuration 205 /* Apply the new configuration
213 * RXON assoc doesn't clear the station table in uCode, 206 * RXON assoc doesn't clear the station table in uCode,
214 */ 207 */
@@ -1618,45 +1611,9 @@ static ssize_t store_tx_power(struct device *d,
1618 1611
1619static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); 1612static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
1620 1613
1621static ssize_t show_rts_ht_protection(struct device *d,
1622 struct device_attribute *attr, char *buf)
1623{
1624 struct iwl_priv *priv = dev_get_drvdata(d);
1625
1626 return sprintf(buf, "%s\n",
1627 priv->cfg->use_rts_for_ht ? "RTS/CTS" : "CTS-to-self");
1628}
1629
1630static ssize_t store_rts_ht_protection(struct device *d,
1631 struct device_attribute *attr,
1632 const char *buf, size_t count)
1633{
1634 struct iwl_priv *priv = dev_get_drvdata(d);
1635 unsigned long val;
1636 int ret;
1637
1638 ret = strict_strtoul(buf, 10, &val);
1639 if (ret)
1640 IWL_INFO(priv, "Input is not in decimal form.\n");
1641 else {
1642 if (!iwl_is_associated(priv))
1643 priv->cfg->use_rts_for_ht = val ? true : false;
1644 else
1645 IWL_ERR(priv, "Sta associated with AP - "
1646 "Change protection mechanism is not allowed\n");
1647 ret = count;
1648 }
1649 return ret;
1650}
1651
1652static DEVICE_ATTR(rts_ht_protection, S_IWUSR | S_IRUGO,
1653 show_rts_ht_protection, store_rts_ht_protection);
1654
1655
1656static struct attribute *iwl_sysfs_entries[] = { 1614static struct attribute *iwl_sysfs_entries[] = {
1657 &dev_attr_temperature.attr, 1615 &dev_attr_temperature.attr,
1658 &dev_attr_tx_power.attr, 1616 &dev_attr_tx_power.attr,
1659 &dev_attr_rts_ht_protection.attr,
1660#ifdef CONFIG_IWLWIFI_DEBUG 1617#ifdef CONFIG_IWLWIFI_DEBUG
1661 &dev_attr_debug_level.attr, 1618 &dev_attr_debug_level.attr,
1662#endif 1619#endif
@@ -3464,25 +3421,6 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3464 return ret; 3421 return ret;
3465} 3422}
3466 3423
3467/*
3468 * switch to RTS/CTS for TX
3469 */
3470static void iwl_enable_rts_cts(struct iwl_priv *priv)
3471{
3472
3473 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3474 return;
3475
3476 priv->staging_rxon.flags &= ~RXON_FLG_SELF_CTS_EN;
3477 if (!test_bit(STATUS_SCANNING, &priv->status)) {
3478 IWL_DEBUG_INFO(priv, "use RTS/CTS protection\n");
3479 iwlcore_commit_rxon(priv);
3480 } else {
3481 /* scanning, defer the request until scan completed */
3482 IWL_DEBUG_INFO(priv, "defer setting RTS/CTS protection\n");
3483 }
3484}
3485
3486static int iwl_mac_ampdu_action(struct ieee80211_hw *hw, 3424static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
3487 struct ieee80211_vif *vif, 3425 struct ieee80211_vif *vif,
3488 enum ieee80211_ampdu_mlme_action action, 3426 enum ieee80211_ampdu_mlme_action action,
@@ -3529,14 +3467,33 @@ static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
3529 } 3467 }
3530 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 3468 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3531 ret = 0; 3469 ret = 0;
3470 if (priv->cfg->use_rts_for_aggregation) {
3471 struct iwl_station_priv *sta_priv =
3472 (void *) sta->drv_priv;
3473 /*
3474 * switch off RTS/CTS if it was previously enabled
3475 */
3476
3477 sta_priv->lq_sta.lq.general_params.flags &=
3478 ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
3479 iwl_send_lq_cmd(priv, &sta_priv->lq_sta.lq,
3480 CMD_ASYNC, false);
3481 }
3532 break; 3482 break;
3533 case IEEE80211_AMPDU_TX_OPERATIONAL: 3483 case IEEE80211_AMPDU_TX_OPERATIONAL:
3534 if (priv->cfg->use_rts_for_ht) { 3484 if (priv->cfg->use_rts_for_aggregation) {
3485 struct iwl_station_priv *sta_priv =
3486 (void *) sta->drv_priv;
3487
3535 /* 3488 /*
3536 * switch to RTS/CTS if it is the prefer protection 3489 * switch to RTS/CTS if it is the prefer protection
3537 * method for HT traffic 3490 * method for HT traffic
3538 */ 3491 */
3539 iwl_enable_rts_cts(priv); 3492
3493 sta_priv->lq_sta.lq.general_params.flags |=
3494 LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
3495 iwl_send_lq_cmd(priv, &sta_priv->lq_sta.lq,
3496 CMD_ASYNC, false);
3540 } 3497 }
3541 ret = 0; 3498 ret = 0;
3542 break; 3499 break;
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index 8ccb6d205b6d..2c03c6e20a72 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -401,21 +401,38 @@ void iwlcore_free_geos(struct iwl_priv *priv)
401EXPORT_SYMBOL(iwlcore_free_geos); 401EXPORT_SYMBOL(iwlcore_free_geos);
402 402
403/* 403/*
404 * iwlcore_rts_tx_cmd_flag: Set rts/cts. 3945 and 4965 only share this 404 * iwlcore_tx_cmd_protection: Set rts/cts. 3945 and 4965 only share this
405 * function. 405 * function.
406 */ 406 */
407void iwlcore_rts_tx_cmd_flag(struct ieee80211_tx_info *info, 407void iwlcore_tx_cmd_protection(struct iwl_priv *priv,
408 __le32 *tx_flags) 408 struct ieee80211_tx_info *info,
409 __le16 fc, __le32 *tx_flags)
409{ 410{
410 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) { 411 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
411 *tx_flags |= TX_CMD_FLG_RTS_MSK; 412 *tx_flags |= TX_CMD_FLG_RTS_MSK;
412 *tx_flags &= ~TX_CMD_FLG_CTS_MSK; 413 *tx_flags &= ~TX_CMD_FLG_CTS_MSK;
414 *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
415
416 if (!ieee80211_is_mgmt(fc))
417 return;
418
419 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
420 case cpu_to_le16(IEEE80211_STYPE_AUTH):
421 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
422 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
423 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
424 *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
425 *tx_flags |= TX_CMD_FLG_CTS_MSK;
426 break;
427 }
413 } else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { 428 } else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
414 *tx_flags &= ~TX_CMD_FLG_RTS_MSK; 429 *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
415 *tx_flags |= TX_CMD_FLG_CTS_MSK; 430 *tx_flags |= TX_CMD_FLG_CTS_MSK;
431 *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
416 } 432 }
417} 433}
418EXPORT_SYMBOL(iwlcore_rts_tx_cmd_flag); 434EXPORT_SYMBOL(iwlcore_tx_cmd_protection);
435
419 436
420static bool is_single_rx_stream(struct iwl_priv *priv) 437static bool is_single_rx_stream(struct iwl_priv *priv)
421{ 438{
@@ -1869,6 +1886,10 @@ void iwl_bss_info_changed(struct ieee80211_hw *hw,
1869 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; 1886 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
1870 else 1887 else
1871 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; 1888 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1889 if (bss_conf->use_cts_prot)
1890 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
1891 else
1892 priv->staging_rxon.flags &= ~RXON_FLG_SELF_CTS_EN;
1872 } 1893 }
1873 1894
1874 if (changes & BSS_CHANGED_BASIC_RATES) { 1895 if (changes & BSS_CHANGED_BASIC_RATES) {
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index e9d23f2f869d..4a71dfb10a15 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -104,8 +104,9 @@ struct iwl_hcmd_utils_ops {
104 u32 min_average_noise, 104 u32 min_average_noise,
105 u8 default_chain); 105 u8 default_chain);
106 void (*chain_noise_reset)(struct iwl_priv *priv); 106 void (*chain_noise_reset)(struct iwl_priv *priv);
107 void (*rts_tx_cmd_flag)(struct ieee80211_tx_info *info, 107 void (*tx_cmd_protection)(struct iwl_priv *priv,
108 __le32 *tx_flags); 108 struct ieee80211_tx_info *info,
109 __le16 fc, __le32 *tx_flags);
109 int (*calc_rssi)(struct iwl_priv *priv, 110 int (*calc_rssi)(struct iwl_priv *priv,
110 struct iwl_rx_phy_res *rx_resp); 111 struct iwl_rx_phy_res *rx_resp);
111 void (*request_scan)(struct iwl_priv *priv, struct ieee80211_vif *vif); 112 void (*request_scan)(struct iwl_priv *priv, struct ieee80211_vif *vif);
@@ -249,7 +250,7 @@ struct iwl_mod_params {
249 * @led_compensation: compensate on the led on/off time per HW according 250 * @led_compensation: compensate on the led on/off time per HW according
250 * to the deviation to achieve the desired led frequency. 251 * to the deviation to achieve the desired led frequency.
251 * The detail algorithm is described in iwl-led.c 252 * The detail algorithm is described in iwl-led.c
252 * @use_rts_for_ht: use rts/cts protection for HT traffic 253 * @use_rts_for_aggregation: use rts/cts protection for HT traffic
253 * @chain_noise_num_beacons: number of beacons used to compute chain noise 254 * @chain_noise_num_beacons: number of beacons used to compute chain noise
254 * @adv_thermal_throttle: support advance thermal throttle 255 * @adv_thermal_throttle: support advance thermal throttle
255 * @support_ct_kill_exit: support ct kill exit condition 256 * @support_ct_kill_exit: support ct kill exit condition
@@ -318,7 +319,7 @@ struct iwl_cfg {
318 const bool ht_greenfield_support; 319 const bool ht_greenfield_support;
319 u16 led_compensation; 320 u16 led_compensation;
320 const bool broken_powersave; 321 const bool broken_powersave;
321 bool use_rts_for_ht; 322 bool use_rts_for_aggregation;
322 int chain_noise_num_beacons; 323 int chain_noise_num_beacons;
323 const bool supports_idle; 324 const bool supports_idle;
324 bool adv_thermal_throttle; 325 bool adv_thermal_throttle;
@@ -390,8 +391,9 @@ void iwl_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif);
390void iwl_mac_reset_tsf(struct ieee80211_hw *hw); 391void iwl_mac_reset_tsf(struct ieee80211_hw *hw);
391int iwl_alloc_txq_mem(struct iwl_priv *priv); 392int iwl_alloc_txq_mem(struct iwl_priv *priv);
392void iwl_free_txq_mem(struct iwl_priv *priv); 393void iwl_free_txq_mem(struct iwl_priv *priv);
393void iwlcore_rts_tx_cmd_flag(struct ieee80211_tx_info *info, 394void iwlcore_tx_cmd_protection(struct iwl_priv *priv,
394 __le32 *tx_flags); 395 struct ieee80211_tx_info *info,
396 __le16 fc, __le32 *tx_flags);
395#ifdef CONFIG_IWLWIFI_DEBUGFS 397#ifdef CONFIG_IWLWIFI_DEBUGFS
396int iwl_alloc_traffic_mem(struct iwl_priv *priv); 398int iwl_alloc_traffic_mem(struct iwl_priv *priv);
397void iwl_free_traffic_mem(struct iwl_priv *priv); 399void iwl_free_traffic_mem(struct iwl_priv *priv);
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index d24eb47d3705..70c4b8fba0ee 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -435,10 +435,7 @@ static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
435 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; 435 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
436 } 436 }
437 437
438 priv->cfg->ops->utils->rts_tx_cmd_flag(info, &tx_flags); 438 priv->cfg->ops->utils->tx_cmd_protection(priv, info, fc, &tx_flags);
439
440 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
441 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
442 439
443 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); 440 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
444 if (ieee80211_is_mgmt(fc)) { 441 if (ieee80211_is_mgmt(fc)) {
diff --git a/drivers/net/wireless/libertas/cfg.c b/drivers/net/wireless/libertas/cfg.c
index 8e9fbfd804b6..3e82f1627209 100644
--- a/drivers/net/wireless/libertas/cfg.c
+++ b/drivers/net/wireless/libertas/cfg.c
@@ -6,7 +6,10 @@
6 * 6 *
7 */ 7 */
8 8
9#include <linux/sched.h>
10#include <linux/wait.h>
9#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/sched.h>
10#include <linux/ieee80211.h> 13#include <linux/ieee80211.h>
11#include <net/cfg80211.h> 14#include <net/cfg80211.h>
12#include <asm/unaligned.h> 15#include <asm/unaligned.h>
diff --git a/drivers/net/wireless/libertas/if_sdio.c b/drivers/net/wireless/libertas/if_sdio.c
index 6e71346a7550..ba854c70ab94 100644
--- a/drivers/net/wireless/libertas/if_sdio.c
+++ b/drivers/net/wireless/libertas/if_sdio.c
@@ -125,6 +125,8 @@ struct if_sdio_card {
125 125
126 const char *helper; 126 const char *helper;
127 const char *firmware; 127 const char *firmware;
128 bool helper_allocated;
129 bool firmware_allocated;
128 130
129 u8 buffer[65536]; 131 u8 buffer[65536];
130 132
@@ -984,16 +986,34 @@ static int if_sdio_probe(struct sdio_func *func,
984 card->helper = if_sdio_models[i].helper; 986 card->helper = if_sdio_models[i].helper;
985 card->firmware = if_sdio_models[i].firmware; 987 card->firmware = if_sdio_models[i].firmware;
986 988
989 kparam_block_sysfs_write(helper_name);
987 if (lbs_helper_name) { 990 if (lbs_helper_name) {
991 char *helper = kstrdup(lbs_helper_name, GFP_KERNEL);
992 if (!helper) {
993 kparam_unblock_sysfs_write(helper_name);
994 ret = -ENOMEM;
995 goto free;
996 }
988 lbs_deb_sdio("overriding helper firmware: %s\n", 997 lbs_deb_sdio("overriding helper firmware: %s\n",
989 lbs_helper_name); 998 lbs_helper_name);
990 card->helper = lbs_helper_name; 999 card->helper = helper;
1000 card->helper_allocated = true;
991 } 1001 }
1002 kparam_unblock_sysfs_write(helper_name);
992 1003
1004 kparam_block_sysfs_write(fw_name);
993 if (lbs_fw_name) { 1005 if (lbs_fw_name) {
1006 char *fw_name = kstrdup(lbs_fw_name, GFP_KERNEL);
1007 if (!fw_name) {
1008 kparam_unblock_sysfs_write(fw_name);
1009 ret = -ENOMEM;
1010 goto free;
1011 }
994 lbs_deb_sdio("overriding firmware: %s\n", lbs_fw_name); 1012 lbs_deb_sdio("overriding firmware: %s\n", lbs_fw_name);
995 card->firmware = lbs_fw_name; 1013 card->firmware = fw_name;
1014 card->firmware_allocated = true;
996 } 1015 }
1016 kparam_unblock_sysfs_write(fw_name);
997 1017
998 sdio_claim_host(func); 1018 sdio_claim_host(func);
999 1019
@@ -1127,6 +1147,10 @@ free:
1127 kfree(packet); 1147 kfree(packet);
1128 } 1148 }
1129 1149
1150 if (card->helper_allocated)
1151 kfree(card->helper);
1152 if (card->firmware_allocated)
1153 kfree(card->firmware);
1130 kfree(card); 1154 kfree(card);
1131 1155
1132 goto out; 1156 goto out;
@@ -1177,6 +1201,10 @@ static void if_sdio_remove(struct sdio_func *func)
1177 kfree(packet); 1201 kfree(packet);
1178 } 1202 }
1179 1203
1204 if (card->helper_allocated)
1205 kfree(card->helper);
1206 if (card->firmware_allocated)
1207 kfree(card->firmware);
1180 kfree(card); 1208 kfree(card);
1181 1209
1182 lbs_deb_leave(LBS_DEB_SDIO); 1210 lbs_deb_leave(LBS_DEB_SDIO);
diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index 07ece9d26c63..3ff61063671a 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -289,10 +289,13 @@ static int if_usb_probe(struct usb_interface *intf,
289 } 289 }
290 290
291 /* Upload firmware */ 291 /* Upload firmware */
292 kparam_block_sysfs_write(fw_name);
292 if (__if_usb_prog_firmware(cardp, lbs_fw_name, BOOT_CMD_FW_BY_USB)) { 293 if (__if_usb_prog_firmware(cardp, lbs_fw_name, BOOT_CMD_FW_BY_USB)) {
294 kparam_unblock_sysfs_write(fw_name);
293 lbs_deb_usbd(&udev->dev, "FW upload failed\n"); 295 lbs_deb_usbd(&udev->dev, "FW upload failed\n");
294 goto err_prog_firmware; 296 goto err_prog_firmware;
295 } 297 }
298 kparam_unblock_sysfs_write(fw_name);
296 299
297 if (!(priv = lbs_add_card(cardp, &udev->dev))) 300 if (!(priv = lbs_add_card(cardp, &udev->dev)))
298 goto err_prog_firmware; 301 goto err_prog_firmware;
diff --git a/drivers/net/wireless/libertas_tf/if_usb.c b/drivers/net/wireless/libertas_tf/if_usb.c
index b172f5d87a3b..41a4f214ade1 100644
--- a/drivers/net/wireless/libertas_tf/if_usb.c
+++ b/drivers/net/wireless/libertas_tf/if_usb.c
@@ -811,12 +811,15 @@ static int if_usb_prog_firmware(struct if_usb_card *cardp)
811 811
812 lbtf_deb_enter(LBTF_DEB_USB); 812 lbtf_deb_enter(LBTF_DEB_USB);
813 813
814 kparam_block_sysfs_write(fw_name);
814 ret = request_firmware(&cardp->fw, lbtf_fw_name, &cardp->udev->dev); 815 ret = request_firmware(&cardp->fw, lbtf_fw_name, &cardp->udev->dev);
815 if (ret < 0) { 816 if (ret < 0) {
816 pr_err("request_firmware() failed with %#x\n", ret); 817 pr_err("request_firmware() failed with %#x\n", ret);
817 pr_err("firmware %s not found\n", lbtf_fw_name); 818 pr_err("firmware %s not found\n", lbtf_fw_name);
819 kparam_unblock_sysfs_write(fw_name);
818 goto done; 820 goto done;
819 } 821 }
822 kparam_unblock_sysfs_write(fw_name);
820 823
821 if (check_fwfile_format(cardp->fw->data, cardp->fw->size)) 824 if (check_fwfile_format(cardp->fw->data, cardp->fw->size))
822 goto release_fw; 825 goto release_fw;
diff --git a/drivers/net/wireless/p54/p54pci.c b/drivers/net/wireless/p54/p54pci.c
index 71a101fb2e4e..822f8dc26e9c 100644
--- a/drivers/net/wireless/p54/p54pci.c
+++ b/drivers/net/wireless/p54/p54pci.c
@@ -43,8 +43,6 @@ static DEFINE_PCI_DEVICE_TABLE(p54p_table) = {
43 { PCI_DEVICE(0x1260, 0x3886) }, 43 { PCI_DEVICE(0x1260, 0x3886) },
44 /* Intersil PRISM Xbow Wireless LAN adapter (Symbol AP-300) */ 44 /* Intersil PRISM Xbow Wireless LAN adapter (Symbol AP-300) */
45 { PCI_DEVICE(0x1260, 0xffff) }, 45 { PCI_DEVICE(0x1260, 0xffff) },
46 /* Standard Microsystems Corp SMC2802W Wireless PCI */
47 { PCI_DEVICE(0x10b8, 0x2802) },
48 { }, 46 { },
49}; 47};
50 48
diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c
index b2c2f391b29d..ecbbb688eba0 100644
--- a/drivers/net/xilinx_emaclite.c
+++ b/drivers/net/xilinx_emaclite.c
@@ -1086,7 +1086,7 @@ static void xemaclite_remove_ndev(struct net_device *ndev)
1086 * 1086 *
1087 * Return: Value of the parameter if the parameter is found, or 0 otherwise 1087 * Return: Value of the parameter if the parameter is found, or 0 otherwise
1088 */ 1088 */
1089static bool get_bool(struct of_device *ofdev, const char *s) 1089static bool get_bool(struct platform_device *ofdev, const char *s)
1090{ 1090{
1091 u32 *p = (u32 *)of_get_property(ofdev->dev.of_node, s, NULL); 1091 u32 *p = (u32 *)of_get_property(ofdev->dev.of_node, s, NULL);
1092 1092
@@ -1115,7 +1115,7 @@ static struct net_device_ops xemaclite_netdev_ops;
1115 * Return: 0, if the driver is bound to the Emaclite device, or 1115 * Return: 0, if the driver is bound to the Emaclite device, or
1116 * a negative error if there is failure. 1116 * a negative error if there is failure.
1117 */ 1117 */
1118static int __devinit xemaclite_of_probe(struct of_device *ofdev, 1118static int __devinit xemaclite_of_probe(struct platform_device *ofdev,
1119 const struct of_device_id *match) 1119 const struct of_device_id *match)
1120{ 1120{
1121 struct resource r_irq; /* Interrupt resources */ 1121 struct resource r_irq; /* Interrupt resources */
@@ -1240,7 +1240,7 @@ error2:
1240 * 1240 *
1241 * Return: 0, always. 1241 * Return: 0, always.
1242 */ 1242 */
1243static int __devexit xemaclite_of_remove(struct of_device *of_dev) 1243static int __devexit xemaclite_of_remove(struct platform_device *of_dev)
1244{ 1244{
1245 struct device *dev = &of_dev->dev; 1245 struct device *dev = &of_dev->dev;
1246 struct net_device *ndev = dev_get_drvdata(dev); 1246 struct net_device *ndev = dev_get_drvdata(dev);
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 0d8a0644f540..92de0eb74aea 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -14,7 +14,7 @@
14 * @ids: array of of device match structures to search in 14 * @ids: array of of device match structures to search in
15 * @dev: the of device structure to match against 15 * @dev: the of device structure to match against
16 * 16 *
17 * Used by a driver to check whether an of_device present in the 17 * Used by a driver to check whether an platform_device present in the
18 * system is in its list of supported devices. 18 * system is in its list of supported devices.
19 */ 19 */
20const struct of_device_id *of_match_device(const struct of_device_id *matches, 20const struct of_device_id *of_match_device(const struct of_device_id *matches,
diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c
index 40e208d130f5..f01e26440f11 100644
--- a/drivers/parport/parport_serial.c
+++ b/drivers/parport/parport_serial.c
@@ -342,7 +342,6 @@ static int __devinit parport_register (struct pci_dev *dev,
342 dev_dbg(&dev->dev, 342 dev_dbg(&dev->dev,
343 "PCI parallel port detected: I/O at %#lx(%#lx), IRQ %d\n", 343 "PCI parallel port detected: I/O at %#lx(%#lx), IRQ %d\n",
344 io_lo, io_hi, irq); 344 io_lo, io_hi, irq);
345 irq = PARPORT_IRQ_NONE;
346 } 345 }
347 port = parport_pc_probe_port (io_lo, io_hi, irq, 346 port = parport_pc_probe_port (io_lo, io_hi, irq,
348 PARPORT_DMA_NONE, &dev->dev, IRQF_SHARED); 347 PARPORT_DMA_NONE, &dev->dev, IRQF_SHARED);
diff --git a/drivers/parport/parport_sunbpp.c b/drivers/parport/parport_sunbpp.c
index 210a6441a066..55ba118f1cf1 100644
--- a/drivers/parport/parport_sunbpp.c
+++ b/drivers/parport/parport_sunbpp.c
@@ -286,7 +286,7 @@ static struct parport_operations parport_sunbpp_ops =
286 .owner = THIS_MODULE, 286 .owner = THIS_MODULE,
287}; 287};
288 288
289static int __devinit bpp_probe(struct of_device *op, const struct of_device_id *match) 289static int __devinit bpp_probe(struct platform_device *op, const struct of_device_id *match)
290{ 290{
291 struct parport_operations *ops; 291 struct parport_operations *ops;
292 struct bpp_regs __iomem *regs; 292 struct bpp_regs __iomem *regs;
@@ -351,7 +351,7 @@ out_unmap:
351 return err; 351 return err;
352} 352}
353 353
354static int __devexit bpp_remove(struct of_device *op) 354static int __devexit bpp_remove(struct platform_device *op)
355{ 355{
356 struct parport *p = dev_get_drvdata(&op->dev); 356 struct parport *p = dev_get_drvdata(&op->dev);
357 struct parport_operations *ops = p->ops; 357 struct parport_operations *ops = p->ops;
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index c988514eb551..c80a7a6e7698 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -215,7 +215,7 @@ config PCMCIA_PXA2XX
215 depends on (ARCH_LUBBOCK || MACH_MAINSTONE || PXA_SHARPSL \ 215 depends on (ARCH_LUBBOCK || MACH_MAINSTONE || PXA_SHARPSL \
216 || MACH_ARMCORE || ARCH_PXA_PALM || TRIZEPS_PCMCIA \ 216 || MACH_ARMCORE || ARCH_PXA_PALM || TRIZEPS_PCMCIA \
217 || ARCOM_PCMCIA || ARCH_PXA_ESERIES || MACH_STARGATE2 \ 217 || ARCOM_PCMCIA || ARCH_PXA_ESERIES || MACH_STARGATE2 \
218 || MACH_VPAC270) 218 || MACH_VPAC270 || MACH_BALLOON3)
219 select PCMCIA_SOC_COMMON 219 select PCMCIA_SOC_COMMON
220 help 220 help
221 Say Y here to include support for the PXA2xx PCMCIA controller 221 Say Y here to include support for the PXA2xx PCMCIA controller
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
index 7a2b1604bf1c..8d9386a22eb3 100644
--- a/drivers/pcmcia/Makefile
+++ b/drivers/pcmcia/Makefile
@@ -69,6 +69,7 @@ pxa2xx-obj-$(CONFIG_MACH_PALMLD) += pxa2xx_palmld.o
69pxa2xx-obj-$(CONFIG_MACH_E740) += pxa2xx_e740.o 69pxa2xx-obj-$(CONFIG_MACH_E740) += pxa2xx_e740.o
70pxa2xx-obj-$(CONFIG_MACH_STARGATE2) += pxa2xx_stargate2.o 70pxa2xx-obj-$(CONFIG_MACH_STARGATE2) += pxa2xx_stargate2.o
71pxa2xx-obj-$(CONFIG_MACH_VPAC270) += pxa2xx_vpac270.o 71pxa2xx-obj-$(CONFIG_MACH_VPAC270) += pxa2xx_vpac270.o
72pxa2xx-obj-$(CONFIG_MACH_BALLOON3) += pxa2xx_balloon3.o
72 73
73obj-$(CONFIG_PCMCIA_PXA2XX) += pxa2xx_base.o $(pxa2xx-obj-y) 74obj-$(CONFIG_PCMCIA_PXA2XX) += pxa2xx_base.o $(pxa2xx-obj-y)
74 75
diff --git a/drivers/pcmcia/electra_cf.c b/drivers/pcmcia/electra_cf.c
index f94d8281cfb0..546d3024b6f0 100644
--- a/drivers/pcmcia/electra_cf.c
+++ b/drivers/pcmcia/electra_cf.c
@@ -44,7 +44,7 @@ struct electra_cf_socket {
44 unsigned present:1; 44 unsigned present:1;
45 unsigned active:1; 45 unsigned active:1;
46 46
47 struct of_device *ofdev; 47 struct platform_device *ofdev;
48 unsigned long mem_phys; 48 unsigned long mem_phys;
49 void __iomem * mem_base; 49 void __iomem * mem_base;
50 unsigned long mem_size; 50 unsigned long mem_size;
@@ -181,7 +181,7 @@ static struct pccard_operations electra_cf_ops = {
181 .set_mem_map = electra_cf_set_mem_map, 181 .set_mem_map = electra_cf_set_mem_map,
182}; 182};
183 183
184static int __devinit electra_cf_probe(struct of_device *ofdev, 184static int __devinit electra_cf_probe(struct platform_device *ofdev,
185 const struct of_device_id *match) 185 const struct of_device_id *match)
186{ 186{
187 struct device *device = &ofdev->dev; 187 struct device *device = &ofdev->dev;
@@ -325,7 +325,7 @@ fail1:
325 325
326} 326}
327 327
328static int __devexit electra_cf_remove(struct of_device *ofdev) 328static int __devexit electra_cf_remove(struct platform_device *ofdev)
329{ 329{
330 struct device *device = &ofdev->dev; 330 struct device *device = &ofdev->dev;
331 struct electra_cf_socket *cf; 331 struct electra_cf_socket *cf;
diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c
index f2f90a7d3e12..f0ecad99ce81 100644
--- a/drivers/pcmcia/m8xx_pcmcia.c
+++ b/drivers/pcmcia/m8xx_pcmcia.c
@@ -1149,7 +1149,7 @@ static struct pccard_operations m8xx_services = {
1149 .set_mem_map = m8xx_set_mem_map, 1149 .set_mem_map = m8xx_set_mem_map,
1150}; 1150};
1151 1151
1152static int __init m8xx_probe(struct of_device *ofdev, 1152static int __init m8xx_probe(struct platform_device *ofdev,
1153 const struct of_device_id *match) 1153 const struct of_device_id *match)
1154{ 1154{
1155 struct pcmcia_win *w; 1155 struct pcmcia_win *w;
@@ -1249,7 +1249,7 @@ static int __init m8xx_probe(struct of_device *ofdev,
1249 return 0; 1249 return 0;
1250} 1250}
1251 1251
1252static int m8xx_remove(struct of_device *ofdev) 1252static int m8xx_remove(struct platform_device *ofdev)
1253{ 1253{
1254 u32 m, i; 1254 u32 m, i;
1255 struct pcmcia_win *w; 1255 struct pcmcia_win *w;
diff --git a/drivers/pcmcia/pxa2xx_balloon3.c b/drivers/pcmcia/pxa2xx_balloon3.c
new file mode 100644
index 000000000000..dbbdd0063202
--- /dev/null
+++ b/drivers/pcmcia/pxa2xx_balloon3.c
@@ -0,0 +1,158 @@
1/*
2 * linux/drivers/pcmcia/pxa2xx_balloon3.c
3 *
4 * Balloon3 PCMCIA specific routines.
5 *
6 * Author: Nick Bane
7 * Created: June, 2006
8 * Copyright: Toby Churchill Ltd
9 * Derived from pxa2xx_mainstone.c, by Nico Pitre
10 *
11 * Various modification by Marek Vasut <marek.vasut@gmail.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 */
17
18#include <linux/module.h>
19#include <linux/gpio.h>
20#include <linux/errno.h>
21#include <linux/interrupt.h>
22#include <linux/platform_device.h>
23#include <linux/irq.h>
24#include <linux/io.h>
25
26#include <mach/balloon3.h>
27
28#include "soc_common.h"
29
30/*
31 * These are a list of interrupt sources that provokes a polled
32 * check of status
33 */
34static struct pcmcia_irqs irqs[] = {
35 { 0, BALLOON3_S0_CD_IRQ, "PCMCIA0 CD" },
36 { 0, BALLOON3_BP_NSTSCHG_IRQ, "PCMCIA0 STSCHG" },
37};
38
39static int balloon3_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
40{
41 uint16_t ver;
42 int ret;
43 static void __iomem *fpga_ver;
44
45 ver = __raw_readw(BALLOON3_FPGA_VER);
46 if (ver > 0x0201)
47 pr_warn("The FPGA code, version 0x%04x, is newer than rel-0.3. "
48 "PCMCIA/CF support might be broken in this version!",
49 ver);
50
51 skt->socket.pci_irq = BALLOON3_BP_CF_NRDY_IRQ;
52 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
53}
54
55static void balloon3_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
56{
57 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
58}
59
60static unsigned long balloon3_pcmcia_status[2] = {
61 BALLOON3_CF_nSTSCHG_BVD1,
62 BALLOON3_CF_nSTSCHG_BVD1
63};
64
65static void balloon3_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
66 struct pcmcia_state *state)
67{
68 uint16_t status;
69 int flip;
70
71 /* This actually reads the STATUS register */
72 status = __raw_readw(BALLOON3_CF_STATUS_REG);
73 flip = (status ^ balloon3_pcmcia_status[skt->nr])
74 & BALLOON3_CF_nSTSCHG_BVD1;
75 /*
76 * Workaround for STSCHG which can't be deasserted:
77 * We therefore disable/enable corresponding IRQs
78 * as needed to avoid IRQ locks.
79 */
80 if (flip) {
81 balloon3_pcmcia_status[skt->nr] = status;
82 if (status & BALLOON3_CF_nSTSCHG_BVD1)
83 enable_irq(BALLOON3_BP_NSTSCHG_IRQ);
84 else
85 disable_irq(BALLOON3_BP_NSTSCHG_IRQ);
86 }
87
88 state->detect = !gpio_get_value(BALLOON3_GPIO_S0_CD);
89 state->ready = !!(status & BALLOON3_CF_nIRQ);
90 state->bvd1 = !!(status & BALLOON3_CF_nSTSCHG_BVD1);
91 state->bvd2 = 0; /* not available */
92 state->vs_3v = 1; /* Always true its a CF card */
93 state->vs_Xv = 0; /* not available */
94 state->wrprot = 0; /* not available */
95}
96
97static int balloon3_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
98 const socket_state_t *state)
99{
100 __raw_writew((state->flags & SS_RESET) ? BALLOON3_CF_RESET : 0,
101 BALLOON3_CF_CONTROL_REG);
102 return 0;
103}
104
105static void balloon3_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
106{
107}
108
109static void balloon3_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
110{
111}
112
113static struct pcmcia_low_level balloon3_pcmcia_ops = {
114 .owner = THIS_MODULE,
115 .hw_init = balloon3_pcmcia_hw_init,
116 .hw_shutdown = balloon3_pcmcia_hw_shutdown,
117 .socket_state = balloon3_pcmcia_socket_state,
118 .configure_socket = balloon3_pcmcia_configure_socket,
119 .socket_init = balloon3_pcmcia_socket_init,
120 .socket_suspend = balloon3_pcmcia_socket_suspend,
121 .first = 0,
122 .nr = 1,
123};
124
125static struct platform_device *balloon3_pcmcia_device;
126
127static int __init balloon3_pcmcia_init(void)
128{
129 int ret;
130
131 balloon3_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
132 if (!balloon3_pcmcia_device)
133 return -ENOMEM;
134
135 ret = platform_device_add_data(balloon3_pcmcia_device,
136 &balloon3_pcmcia_ops, sizeof(balloon3_pcmcia_ops));
137
138 if (!ret)
139 ret = platform_device_add(balloon3_pcmcia_device);
140
141 if (ret)
142 platform_device_put(balloon3_pcmcia_device);
143
144 return ret;
145}
146
147static void __exit balloon3_pcmcia_exit(void)
148{
149 platform_device_unregister(balloon3_pcmcia_device);
150}
151
152module_init(balloon3_pcmcia_init);
153module_exit(balloon3_pcmcia_exit);
154
155MODULE_LICENSE("GPL");
156MODULE_AUTHOR("Nick Bane <nick@cecomputing.co.uk>");
157MODULE_ALIAS("platform:pxa2xx-pcmcia");
158MODULE_DESCRIPTION("Balloon3 board CF/PCMCIA driver");
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 1e5506be39b4..07343568a12e 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -136,6 +136,12 @@ config BATTERY_Z2
136 help 136 help
137 Say Y to include support for the battery on the Zipit Z2. 137 Say Y to include support for the battery on the Zipit Z2.
138 138
139config BATTERY_S3C_ADC
140 tristate "Battery driver for Samsung ADC based monitoring"
141 depends on S3C_ADC
142 help
143 Say Y here to enable support for iPAQ h1930/h1940/rx1950 battery
144
139config CHARGER_PCF50633 145config CHARGER_PCF50633
140 tristate "NXP PCF50633 MBC" 146 tristate "NXP PCF50633 MBC"
141 depends on MFD_PCF50633 147 depends on MFD_PCF50633
@@ -153,4 +159,11 @@ config BATTERY_JZ4740
153 This driver can be build as a module. If so, the module will be 159 This driver can be build as a module. If so, the module will be
154 called jz4740-battery. 160 called jz4740-battery.
155 161
162config BATTERY_INTEL_MID
163 tristate "Battery driver for Intel MID platforms"
164 depends on INTEL_SCU_IPC && SPI
165 help
166 Say Y here to enable the battery driver on Intel MID
167 platforms.
168
156endif # POWER_SUPPLY 169endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index cf95009d9bcd..10143aaf4ee3 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -33,5 +33,7 @@ obj-$(CONFIG_BATTERY_BQ27x00) += bq27x00_battery.o
33obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o 33obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o
34obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o 34obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o
35obj-$(CONFIG_BATTERY_Z2) += z2_battery.o 35obj-$(CONFIG_BATTERY_Z2) += z2_battery.o
36obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o
36obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o 37obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o
37obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o 38obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o
39obj-$(CONFIG_BATTERY_INTEL_MID) += intel_mid_battery.o
diff --git a/drivers/power/intel_mid_battery.c b/drivers/power/intel_mid_battery.c
new file mode 100644
index 000000000000..c61ffec2ff10
--- /dev/null
+++ b/drivers/power/intel_mid_battery.c
@@ -0,0 +1,799 @@
1/*
2 * intel_mid_battery.c - Intel MID PMIC Battery Driver
3 *
4 * Copyright (C) 2009 Intel Corporation
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 *
21 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 * Author: Nithish Mahalingam <nithish.mahalingam@intel.com>
23 */
24
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/err.h>
28#include <linux/interrupt.h>
29#include <linux/workqueue.h>
30#include <linux/jiffies.h>
31#include <linux/param.h>
32#include <linux/device.h>
33#include <linux/spi/spi.h>
34#include <linux/platform_device.h>
35#include <linux/power_supply.h>
36
37#include <asm/intel_scu_ipc.h>
38
39#define DRIVER_NAME "pmic_battery"
40
41/*********************************************************************
42 * Generic defines
43 *********************************************************************/
44
45static int debug;
46module_param(debug, int, 0444);
47MODULE_PARM_DESC(debug, "Flag to enable PMIC Battery debug messages.");
48
49#define PMIC_BATT_DRV_INFO_UPDATED 1
50#define PMIC_BATT_PRESENT 1
51#define PMIC_BATT_NOT_PRESENT 0
52#define PMIC_USB_PRESENT PMIC_BATT_PRESENT
53#define PMIC_USB_NOT_PRESENT PMIC_BATT_NOT_PRESENT
54
55/* pmic battery register related */
56#define PMIC_BATT_CHR_SCHRGINT_ADDR 0xD2
57#define PMIC_BATT_CHR_SBATOVP_MASK (1 << 1)
58#define PMIC_BATT_CHR_STEMP_MASK (1 << 2)
59#define PMIC_BATT_CHR_SCOMP_MASK (1 << 3)
60#define PMIC_BATT_CHR_SUSBDET_MASK (1 << 4)
61#define PMIC_BATT_CHR_SBATDET_MASK (1 << 5)
62#define PMIC_BATT_CHR_SDCLMT_MASK (1 << 6)
63#define PMIC_BATT_CHR_SUSBOVP_MASK (1 << 7)
64#define PMIC_BATT_CHR_EXCPT_MASK 0xC6
65#define PMIC_BATT_ADC_ACCCHRG_MASK (1 << 31)
66#define PMIC_BATT_ADC_ACCCHRGVAL_MASK 0x7FFFFFFF
67
68/* pmic ipc related */
69#define PMIC_BATT_CHR_IPC_FCHRG_SUBID 0x4
70#define PMIC_BATT_CHR_IPC_TCHRG_SUBID 0x6
71
72/* types of battery charging */
73enum batt_charge_type {
74 BATT_USBOTG_500MA_CHARGE,
75 BATT_USBOTG_TRICKLE_CHARGE,
76};
77
78/* valid battery events */
79enum batt_event {
80 BATT_EVENT_BATOVP_EXCPT,
81 BATT_EVENT_USBOVP_EXCPT,
82 BATT_EVENT_TEMP_EXCPT,
83 BATT_EVENT_DCLMT_EXCPT,
84 BATT_EVENT_EXCPT
85};
86
87
88/*********************************************************************
89 * Battery properties
90 *********************************************************************/
91
92/*
93 * pmic battery info
94 */
95struct pmic_power_module_info {
96 bool is_dev_info_updated;
97 struct device *dev;
98 /* pmic battery data */
99 unsigned long update_time; /* jiffies when data read */
100 unsigned int usb_is_present;
101 unsigned int batt_is_present;
102 unsigned int batt_health;
103 unsigned int usb_health;
104 unsigned int batt_status;
105 unsigned int batt_charge_now; /* in mAS */
106 unsigned int batt_prev_charge_full; /* in mAS */
107 unsigned int batt_charge_rate; /* in units per second */
108
109 struct power_supply usb;
110 struct power_supply batt;
111 int irq; /* GPE_ID or IRQ# */
112 struct workqueue_struct *monitor_wqueue;
113 struct delayed_work monitor_battery;
114 struct work_struct handler;
115};
116
117static unsigned int delay_time = 2000; /* in ms */
118
119/*
120 * pmic ac properties
121 */
122static enum power_supply_property pmic_usb_props[] = {
123 POWER_SUPPLY_PROP_PRESENT,
124 POWER_SUPPLY_PROP_HEALTH,
125};
126
127/*
128 * pmic battery properties
129 */
130static enum power_supply_property pmic_battery_props[] = {
131 POWER_SUPPLY_PROP_STATUS,
132 POWER_SUPPLY_PROP_HEALTH,
133 POWER_SUPPLY_PROP_PRESENT,
134 POWER_SUPPLY_PROP_CHARGE_NOW,
135 POWER_SUPPLY_PROP_CHARGE_FULL,
136};
137
138
139/*
140 * Glue functions for talking to the IPC
141 */
142
143struct battery_property {
144 u32 capacity; /* Charger capacity */
145 u8 crnt; /* Quick charge current value*/
146 u8 volt; /* Fine adjustment of constant charge voltage */
147 u8 prot; /* CHRGPROT register value */
148 u8 prot2; /* CHRGPROT1 register value */
149 u8 timer; /* Charging timer */
150};
151
152#define IPCMSG_BATTERY 0xEF
153
154/* Battery coulomb counter accumulator commands */
155#define IPC_CMD_CC_WR 0 /* Update coulomb counter value */
156#define IPC_CMD_CC_RD 1 /* Read coulomb counter value */
157#define IPC_CMD_BATTERY_PROPERTY 2 /* Read Battery property */
158
159/**
160 * pmic_scu_ipc_battery_cc_read - read battery cc
161 * @value: battery coulomb counter read
162 *
163 * Reads the battery couloumb counter value, returns 0 on success, or
164 * an error code
165 *
166 * This function may sleep. Locking for SCU accesses is handled for
167 * the caller.
168 */
169static int pmic_scu_ipc_battery_cc_read(u32 *value)
170{
171 return intel_scu_ipc_command(IPCMSG_BATTERY, IPC_CMD_CC_RD,
172 NULL, 0, value, 1);
173}
174
175/**
176 * pmic_scu_ipc_battery_property_get - fetch properties
177 * @prop: battery properties
178 *
179 * Retrieve the battery properties from the power management
180 *
181 * This function may sleep. Locking for SCU accesses is handled for
182 * the caller.
183 */
184static int pmic_scu_ipc_battery_property_get(struct battery_property *prop)
185{
186 u32 data[3];
187 u8 *p = (u8 *)&data[1];
188 int err = intel_scu_ipc_command(IPC_CMD_BATTERY_PROPERTY,
189 IPCMSG_BATTERY, NULL, 0, data, 3);
190
191 prop->capacity = data[0];
192 prop->crnt = *p++;
193 prop->volt = *p++;
194 prop->prot = *p++;
195 prop->prot2 = *p++;
196 prop->timer = *p++;
197
198 return err;
199}
200
201/**
202 * pmic_scu_ipc_set_charger - set charger
203 * @charger: charger to select
204 *
205 * Switch the charging mode for the SCU
206 */
207
208static int pmic_scu_ipc_set_charger(int charger)
209{
210 return intel_scu_ipc_simple_command(charger, IPCMSG_BATTERY);
211}
212
213/**
214 * pmic_battery_log_event - log battery events
215 * @event: battery event to be logged
216 * Context: can sleep
217 *
218 * There are multiple battery events which may be of interest to users;
219 * this battery function logs the different battery events onto the
220 * kernel log messages.
221 */
222static void pmic_battery_log_event(enum batt_event event)
223{
224 printk(KERN_WARNING "pmic-battery: ");
225 switch (event) {
226 case BATT_EVENT_BATOVP_EXCPT:
227 printk(KERN_CONT "battery overvoltage condition\n");
228 break;
229 case BATT_EVENT_USBOVP_EXCPT:
230 printk(KERN_CONT "usb charger overvoltage condition\n");
231 break;
232 case BATT_EVENT_TEMP_EXCPT:
233 printk(KERN_CONT "high battery temperature condition\n");
234 break;
235 case BATT_EVENT_DCLMT_EXCPT:
236 printk(KERN_CONT "over battery charge current condition\n");
237 break;
238 default:
239 printk(KERN_CONT "charger/battery exception %d\n", event);
240 break;
241 }
242}
243
244/**
245 * pmic_battery_read_status - read battery status information
246 * @pbi: device info structure to update the read information
247 * Context: can sleep
248 *
249 * PMIC power source information need to be updated based on the data read
250 * from the PMIC battery registers.
251 *
252 */
253static void pmic_battery_read_status(struct pmic_power_module_info *pbi)
254{
255 unsigned int update_time_intrvl;
256 unsigned int chrg_val;
257 u32 ccval;
258 u8 r8;
259 struct battery_property batt_prop;
260 int batt_present = 0;
261 int usb_present = 0;
262 int batt_exception = 0;
263
264 /* make sure the last batt_status read happened delay_time before */
265 if (pbi->update_time && time_before(jiffies, pbi->update_time +
266 msecs_to_jiffies(delay_time)))
267 return;
268
269 update_time_intrvl = jiffies_to_msecs(jiffies - pbi->update_time);
270 pbi->update_time = jiffies;
271
272 /* read coulomb counter registers and schrgint register */
273 if (pmic_scu_ipc_battery_cc_read(&ccval)) {
274 dev_warn(pbi->dev, "%s(): ipc config cmd failed\n",
275 __func__);
276 return;
277 }
278
279 if (intel_scu_ipc_ioread8(PMIC_BATT_CHR_SCHRGINT_ADDR, &r8)) {
280 dev_warn(pbi->dev, "%s(): ipc pmic read failed\n",
281 __func__);
282 return;
283 }
284
285 /*
286 * set pmic_power_module_info members based on pmic register values
287 * read.
288 */
289
290 /* set batt_is_present */
291 if (r8 & PMIC_BATT_CHR_SBATDET_MASK) {
292 pbi->batt_is_present = PMIC_BATT_PRESENT;
293 batt_present = 1;
294 } else {
295 pbi->batt_is_present = PMIC_BATT_NOT_PRESENT;
296 pbi->batt_health = POWER_SUPPLY_HEALTH_UNKNOWN;
297 pbi->batt_status = POWER_SUPPLY_STATUS_UNKNOWN;
298 }
299
300 /* set batt_health */
301 if (batt_present) {
302 if (r8 & PMIC_BATT_CHR_SBATOVP_MASK) {
303 pbi->batt_health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
304 pbi->batt_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
305 pmic_battery_log_event(BATT_EVENT_BATOVP_EXCPT);
306 batt_exception = 1;
307 } else if (r8 & PMIC_BATT_CHR_SDCLMT_MASK) {
308 pbi->batt_health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
309 pbi->batt_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
310 pmic_battery_log_event(BATT_EVENT_DCLMT_EXCPT);
311 batt_exception = 1;
312 } else if (r8 & PMIC_BATT_CHR_STEMP_MASK) {
313 pbi->batt_health = POWER_SUPPLY_HEALTH_OVERHEAT;
314 pbi->batt_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
315 pmic_battery_log_event(BATT_EVENT_TEMP_EXCPT);
316 batt_exception = 1;
317 } else {
318 pbi->batt_health = POWER_SUPPLY_HEALTH_GOOD;
319 }
320 }
321
322 /* set usb_is_present */
323 if (r8 & PMIC_BATT_CHR_SUSBDET_MASK) {
324 pbi->usb_is_present = PMIC_USB_PRESENT;
325 usb_present = 1;
326 } else {
327 pbi->usb_is_present = PMIC_USB_NOT_PRESENT;
328 pbi->usb_health = POWER_SUPPLY_HEALTH_UNKNOWN;
329 }
330
331 if (usb_present) {
332 if (r8 & PMIC_BATT_CHR_SUSBOVP_MASK) {
333 pbi->usb_health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
334 pmic_battery_log_event(BATT_EVENT_USBOVP_EXCPT);
335 } else {
336 pbi->usb_health = POWER_SUPPLY_HEALTH_GOOD;
337 }
338 }
339
340 chrg_val = ccval & PMIC_BATT_ADC_ACCCHRGVAL_MASK;
341
342 /* set batt_prev_charge_full to battery capacity the first time */
343 if (!pbi->is_dev_info_updated) {
344 if (pmic_scu_ipc_battery_property_get(&batt_prop)) {
345 dev_warn(pbi->dev, "%s(): ipc config cmd failed\n",
346 __func__);
347 return;
348 }
349 pbi->batt_prev_charge_full = batt_prop.capacity;
350 }
351
352 /* set batt_status */
353 if (batt_present && !batt_exception) {
354 if (r8 & PMIC_BATT_CHR_SCOMP_MASK) {
355 pbi->batt_status = POWER_SUPPLY_STATUS_FULL;
356 pbi->batt_prev_charge_full = chrg_val;
357 } else if (ccval & PMIC_BATT_ADC_ACCCHRG_MASK) {
358 pbi->batt_status = POWER_SUPPLY_STATUS_DISCHARGING;
359 } else {
360 pbi->batt_status = POWER_SUPPLY_STATUS_CHARGING;
361 }
362 }
363
364 /* set batt_charge_rate */
365 if (pbi->is_dev_info_updated && batt_present && !batt_exception) {
366 if (pbi->batt_status == POWER_SUPPLY_STATUS_DISCHARGING) {
367 if (pbi->batt_charge_now - chrg_val) {
368 pbi->batt_charge_rate = ((pbi->batt_charge_now -
369 chrg_val) * 1000 * 60) /
370 update_time_intrvl;
371 }
372 } else if (pbi->batt_status == POWER_SUPPLY_STATUS_CHARGING) {
373 if (chrg_val - pbi->batt_charge_now) {
374 pbi->batt_charge_rate = ((chrg_val -
375 pbi->batt_charge_now) * 1000 * 60) /
376 update_time_intrvl;
377 }
378 } else
379 pbi->batt_charge_rate = 0;
380 } else {
381 pbi->batt_charge_rate = -1;
382 }
383
384 /* batt_charge_now */
385 if (batt_present && !batt_exception)
386 pbi->batt_charge_now = chrg_val;
387 else
388 pbi->batt_charge_now = -1;
389
390 pbi->is_dev_info_updated = PMIC_BATT_DRV_INFO_UPDATED;
391}
392
393/**
394 * pmic_usb_get_property - usb power source get property
395 * @psy: usb power supply context
396 * @psp: usb power source property
397 * @val: usb power source property value
398 * Context: can sleep
399 *
400 * PMIC usb power source property needs to be provided to power_supply
401 * subsytem for it to provide the information to users.
402 */
403static int pmic_usb_get_property(struct power_supply *psy,
404 enum power_supply_property psp,
405 union power_supply_propval *val)
406{
407 struct pmic_power_module_info *pbi = container_of(psy,
408 struct pmic_power_module_info, usb);
409
410 /* update pmic_power_module_info members */
411 pmic_battery_read_status(pbi);
412
413 switch (psp) {
414 case POWER_SUPPLY_PROP_PRESENT:
415 val->intval = pbi->usb_is_present;
416 break;
417 case POWER_SUPPLY_PROP_HEALTH:
418 val->intval = pbi->usb_health;
419 break;
420 default:
421 return -EINVAL;
422 }
423
424 return 0;
425}
426
427static inline unsigned long mAStouAh(unsigned long v)
428{
429 /* seconds to hours, mA to µA */
430 return (v * 1000) / 3600;
431}
432
433/**
434 * pmic_battery_get_property - battery power source get property
435 * @psy: battery power supply context
436 * @psp: battery power source property
437 * @val: battery power source property value
438 * Context: can sleep
439 *
440 * PMIC battery power source property needs to be provided to power_supply
441 * subsytem for it to provide the information to users.
442 */
443static int pmic_battery_get_property(struct power_supply *psy,
444 enum power_supply_property psp,
445 union power_supply_propval *val)
446{
447 struct pmic_power_module_info *pbi = container_of(psy,
448 struct pmic_power_module_info, batt);
449
450 /* update pmic_power_module_info members */
451 pmic_battery_read_status(pbi);
452
453 switch (psp) {
454 case POWER_SUPPLY_PROP_STATUS:
455 val->intval = pbi->batt_status;
456 break;
457 case POWER_SUPPLY_PROP_HEALTH:
458 val->intval = pbi->batt_health;
459 break;
460 case POWER_SUPPLY_PROP_PRESENT:
461 val->intval = pbi->batt_is_present;
462 break;
463 case POWER_SUPPLY_PROP_CHARGE_NOW:
464 val->intval = mAStouAh(pbi->batt_charge_now);
465 break;
466 case POWER_SUPPLY_PROP_CHARGE_FULL:
467 val->intval = mAStouAh(pbi->batt_prev_charge_full);
468 break;
469 default:
470 return -EINVAL;
471 }
472
473 return 0;
474}
475
476/**
477 * pmic_battery_monitor - monitor battery status
478 * @work: work structure
479 * Context: can sleep
480 *
481 * PMIC battery status needs to be monitored for any change
482 * and information needs to be frequently updated.
483 */
484static void pmic_battery_monitor(struct work_struct *work)
485{
486 struct pmic_power_module_info *pbi = container_of(work,
487 struct pmic_power_module_info, monitor_battery.work);
488
489 /* update pmic_power_module_info members */
490 pmic_battery_read_status(pbi);
491 queue_delayed_work(pbi->monitor_wqueue, &pbi->monitor_battery, HZ * 10);
492}
493
494/**
495 * pmic_battery_set_charger - set battery charger
496 * @pbi: device info structure
497 * @chrg: charge mode to set battery charger in
498 * Context: can sleep
499 *
500 * PMIC battery charger needs to be enabled based on the usb charge
501 * capabilities connected to the platform.
502 */
503static int pmic_battery_set_charger(struct pmic_power_module_info *pbi,
504 enum batt_charge_type chrg)
505{
506 int retval;
507
508 /* set usblmt bits and chrgcntl register bits appropriately */
509 switch (chrg) {
510 case BATT_USBOTG_500MA_CHARGE:
511 retval = pmic_scu_ipc_set_charger(PMIC_BATT_CHR_IPC_FCHRG_SUBID);
512 break;
513 case BATT_USBOTG_TRICKLE_CHARGE:
514 retval = pmic_scu_ipc_set_charger(PMIC_BATT_CHR_IPC_TCHRG_SUBID);
515 break;
516 default:
517 dev_warn(pbi->dev, "%s(): out of range usb charger "
518 "charge detected\n", __func__);
519 return -EINVAL;
520 }
521
522 if (retval) {
523 dev_warn(pbi->dev, "%s(): ipc pmic read failed\n",
524 __func__);
525 return retval;;
526 }
527
528 return 0;
529}
530
531/**
532 * pmic_battery_interrupt_handler - pmic battery interrupt handler
533 * Context: interrupt context
534 *
535 * PMIC battery interrupt handler which will be called with either
536 * battery full condition occurs or usb otg & battery connect
537 * condition occurs.
538 */
539static irqreturn_t pmic_battery_interrupt_handler(int id, void *dev)
540{
541 struct pmic_power_module_info *pbi = dev;
542
543 schedule_work(&pbi->handler);
544
545 return IRQ_HANDLED;
546}
547
548/**
549 * pmic_battery_handle_intrpt - pmic battery service interrupt
550 * @work: work structure
551 * Context: can sleep
552 *
553 * PMIC battery needs to either update the battery status as full
554 * if it detects battery full condition caused the interrupt or needs
555 * to enable battery charger if it detects usb and battery detect
556 * caused the source of interrupt.
557 */
558static void pmic_battery_handle_intrpt(struct work_struct *work)
559{
560 struct pmic_power_module_info *pbi = container_of(work,
561 struct pmic_power_module_info, handler);
562 enum batt_charge_type chrg;
563 u8 r8;
564
565 if (intel_scu_ipc_ioread8(PMIC_BATT_CHR_SCHRGINT_ADDR, &r8)) {
566 dev_warn(pbi->dev, "%s(): ipc pmic read failed\n",
567 __func__);
568 return;
569 }
570 /* find the cause of the interrupt */
571 if (r8 & PMIC_BATT_CHR_SBATDET_MASK) {
572 pbi->batt_is_present = PMIC_BATT_PRESENT;
573 } else {
574 pbi->batt_is_present = PMIC_BATT_NOT_PRESENT;
575 pbi->batt_health = POWER_SUPPLY_HEALTH_UNKNOWN;
576 pbi->batt_status = POWER_SUPPLY_STATUS_UNKNOWN;
577 return;
578 }
579
580 if (r8 & PMIC_BATT_CHR_EXCPT_MASK) {
581 pbi->batt_health = POWER_SUPPLY_HEALTH_UNKNOWN;
582 pbi->batt_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
583 pbi->usb_health = POWER_SUPPLY_HEALTH_UNKNOWN;
584 pmic_battery_log_event(BATT_EVENT_EXCPT);
585 return;
586 } else {
587 pbi->batt_health = POWER_SUPPLY_HEALTH_GOOD;
588 pbi->usb_health = POWER_SUPPLY_HEALTH_GOOD;
589 }
590
591 if (r8 & PMIC_BATT_CHR_SCOMP_MASK) {
592 u32 ccval;
593 pbi->batt_status = POWER_SUPPLY_STATUS_FULL;
594
595 if (pmic_scu_ipc_battery_cc_read(&ccval)) {
596 dev_warn(pbi->dev, "%s(): ipc config cmd "
597 "failed\n", __func__);
598 return;
599 }
600 pbi->batt_prev_charge_full = ccval &
601 PMIC_BATT_ADC_ACCCHRGVAL_MASK;
602 return;
603 }
604
605 if (r8 & PMIC_BATT_CHR_SUSBDET_MASK) {
606 pbi->usb_is_present = PMIC_USB_PRESENT;
607 } else {
608 pbi->usb_is_present = PMIC_USB_NOT_PRESENT;
609 pbi->usb_health = POWER_SUPPLY_HEALTH_UNKNOWN;
610 return;
611 }
612
613 /* setup battery charging */
614
615#if 0
616 /* check usb otg power capability and set charger accordingly */
617 retval = langwell_udc_maxpower(&power);
618 if (retval) {
619 dev_warn(pbi->dev,
620 "%s(): usb otg power query failed with error code %d\n",
621 __func__, retval);
622 return;
623 }
624
625 if (power >= 500)
626 chrg = BATT_USBOTG_500MA_CHARGE;
627 else
628#endif
629 chrg = BATT_USBOTG_TRICKLE_CHARGE;
630
631 /* enable battery charging */
632 if (pmic_battery_set_charger(pbi, chrg)) {
633 dev_warn(pbi->dev,
634 "%s(): failed to set up battery charging\n", __func__);
635 return;
636 }
637
638 dev_dbg(pbi->dev,
639 "pmic-battery: %s() - setting up battery charger successful\n",
640 __func__);
641}
642
643/**
644 * pmic_battery_probe - pmic battery initialize
645 * @irq: pmic battery device irq
646 * @dev: pmic battery device structure
647 * Context: can sleep
648 *
649 * PMIC battery initializes its internal data structue and other
650 * infrastructure components for it to work as expected.
651 */
652static __devinit int probe(int irq, struct device *dev)
653{
654 int retval = 0;
655 struct pmic_power_module_info *pbi;
656
657 dev_dbg(dev, "pmic-battery: found pmic battery device\n");
658
659 pbi = kzalloc(sizeof(*pbi), GFP_KERNEL);
660 if (!pbi) {
661 dev_err(dev, "%s(): memory allocation failed\n",
662 __func__);
663 return -ENOMEM;
664 }
665
666 pbi->dev = dev;
667 pbi->irq = irq;
668 dev_set_drvdata(dev, pbi);
669
670 /* initialize all required framework before enabling interrupts */
671 INIT_WORK(&pbi->handler, pmic_battery_handle_intrpt);
672 INIT_DELAYED_WORK(&pbi->monitor_battery, pmic_battery_monitor);
673 pbi->monitor_wqueue =
674 create_singlethread_workqueue(dev_name(dev));
675 if (!pbi->monitor_wqueue) {
676 dev_err(dev, "%s(): wqueue init failed\n", __func__);
677 retval = -ESRCH;
678 goto wqueue_failed;
679 }
680
681 /* register interrupt */
682 retval = request_irq(pbi->irq, pmic_battery_interrupt_handler,
683 0, DRIVER_NAME, pbi);
684 if (retval) {
685 dev_err(dev, "%s(): cannot get IRQ\n", __func__);
686 goto requestirq_failed;
687 }
688
689 /* register pmic-batt with power supply subsystem */
690 pbi->batt.name = "pmic-batt";
691 pbi->batt.type = POWER_SUPPLY_TYPE_BATTERY;
692 pbi->batt.properties = pmic_battery_props;
693 pbi->batt.num_properties = ARRAY_SIZE(pmic_battery_props);
694 pbi->batt.get_property = pmic_battery_get_property;
695 retval = power_supply_register(dev, &pbi->batt);
696 if (retval) {
697 dev_err(dev,
698 "%s(): failed to register pmic battery device with power supply subsystem\n",
699 __func__);
700 goto power_reg_failed;
701 }
702
703 dev_dbg(dev, "pmic-battery: %s() - pmic battery device "
704 "registration with power supply subsystem successful\n",
705 __func__);
706
707 queue_delayed_work(pbi->monitor_wqueue, &pbi->monitor_battery, HZ * 1);
708
709 /* register pmic-usb with power supply subsystem */
710 pbi->usb.name = "pmic-usb";
711 pbi->usb.type = POWER_SUPPLY_TYPE_USB;
712 pbi->usb.properties = pmic_usb_props;
713 pbi->usb.num_properties = ARRAY_SIZE(pmic_usb_props);
714 pbi->usb.get_property = pmic_usb_get_property;
715 retval = power_supply_register(dev, &pbi->usb);
716 if (retval) {
717 dev_err(dev,
718 "%s(): failed to register pmic usb device with power supply subsystem\n",
719 __func__);
720 goto power_reg_failed_1;
721 }
722
723 if (debug)
724 printk(KERN_INFO "pmic-battery: %s() - pmic usb device "
725 "registration with power supply subsystem successful\n",
726 __func__);
727
728 return retval;
729
730power_reg_failed_1:
731 power_supply_unregister(&pbi->batt);
732power_reg_failed:
733 cancel_rearming_delayed_workqueue(pbi->monitor_wqueue,
734 &pbi->monitor_battery);
735requestirq_failed:
736 destroy_workqueue(pbi->monitor_wqueue);
737wqueue_failed:
738 kfree(pbi);
739
740 return retval;
741}
742
743static int __devinit platform_pmic_battery_probe(struct platform_device *pdev)
744{
745 return probe(pdev->id, &pdev->dev);
746}
747
748/**
749 * pmic_battery_remove - pmic battery finalize
750 * @dev: pmic battery device structure
751 * Context: can sleep
752 *
753 * PMIC battery finalizes its internal data structue and other
754 * infrastructure components that it initialized in
755 * pmic_battery_probe.
756 */
757
758static int __devexit platform_pmic_battery_remove(struct platform_device *pdev)
759{
760 struct pmic_power_module_info *pbi = dev_get_drvdata(&pdev->dev);
761
762 free_irq(pbi->irq, pbi);
763 cancel_rearming_delayed_workqueue(pbi->monitor_wqueue,
764 &pbi->monitor_battery);
765 destroy_workqueue(pbi->monitor_wqueue);
766
767 power_supply_unregister(&pbi->usb);
768 power_supply_unregister(&pbi->batt);
769
770 flush_scheduled_work();
771 kfree(pbi);
772 return 0;
773}
774
775static struct platform_driver platform_pmic_battery_driver = {
776 .driver = {
777 .name = DRIVER_NAME,
778 .owner = THIS_MODULE,
779 },
780 .probe = platform_pmic_battery_probe,
781 .remove = __devexit_p(platform_pmic_battery_remove),
782};
783
784static int __init platform_pmic_battery_module_init(void)
785{
786 return platform_driver_register(&platform_pmic_battery_driver);
787}
788
789static void __exit platform_pmic_battery_module_exit(void)
790{
791 platform_driver_unregister(&platform_pmic_battery_driver);
792}
793
794module_init(platform_pmic_battery_module_init);
795module_exit(platform_pmic_battery_module_exit);
796
797MODULE_AUTHOR("Nithish Mahalingam <nithish.mahalingam@intel.com>");
798MODULE_DESCRIPTION("Intel Moorestown PMIC Battery Driver");
799MODULE_LICENSE("GPL");
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index 5ab9109b69e6..aafc1c506eda 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Battery driver for One Laptop Per Child board. 2 * Battery driver for One Laptop Per Child board.
3 * 3 *
4 * Copyright © 2006 David Woodhouse <dwmw2@infradead.org> 4 * Copyright © 2006-2010 David Woodhouse <dwmw2@infradead.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
diff --git a/drivers/power/s3c_adc_battery.c b/drivers/power/s3c_adc_battery.c
new file mode 100644
index 000000000000..fe16b482e912
--- /dev/null
+++ b/drivers/power/s3c_adc_battery.c
@@ -0,0 +1,431 @@
1/*
2 * iPAQ h1930/h1940/rx1950 battery controler driver
3 * Copyright (c) Vasily Khoruzhick
4 * Based on h1940_battery.c by Arnaud Patard
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive for
8 * more details.
9 *
10 */
11
12#include <linux/interrupt.h>
13#include <linux/platform_device.h>
14#include <linux/power_supply.h>
15#include <linux/leds.h>
16#include <linux/gpio.h>
17#include <linux/err.h>
18#include <linux/timer.h>
19#include <linux/jiffies.h>
20#include <linux/s3c_adc_battery.h>
21#include <linux/errno.h>
22#include <linux/init.h>
23
24#include <plat/adc.h>
25
26#define BAT_POLL_INTERVAL 10000 /* ms */
27#define JITTER_DELAY 500 /* ms */
28
29struct s3c_adc_bat {
30 struct power_supply psy;
31 struct s3c_adc_client *client;
32 struct s3c_adc_bat_pdata *pdata;
33 int volt_value;
34 int cur_value;
35 unsigned int timestamp;
36 int level;
37 int status;
38 int cable_plugged:1;
39};
40
41static struct delayed_work bat_work;
42
43static void s3c_adc_bat_ext_power_changed(struct power_supply *psy)
44{
45 schedule_delayed_work(&bat_work,
46 msecs_to_jiffies(JITTER_DELAY));
47}
48
49static enum power_supply_property s3c_adc_backup_bat_props[] = {
50 POWER_SUPPLY_PROP_VOLTAGE_NOW,
51 POWER_SUPPLY_PROP_VOLTAGE_MIN,
52 POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
53};
54
55static int s3c_adc_backup_bat_get_property(struct power_supply *psy,
56 enum power_supply_property psp,
57 union power_supply_propval *val)
58{
59 struct s3c_adc_bat *bat = container_of(psy, struct s3c_adc_bat, psy);
60
61 if (!bat) {
62 dev_err(psy->dev, "%s: no battery infos ?!\n", __func__);
63 return -EINVAL;
64 }
65
66 if (bat->volt_value < 0 ||
67 jiffies_to_msecs(jiffies - bat->timestamp) >
68 BAT_POLL_INTERVAL) {
69 bat->volt_value = s3c_adc_read(bat->client,
70 bat->pdata->backup_volt_channel);
71 bat->volt_value *= bat->pdata->backup_volt_mult;
72 bat->timestamp = jiffies;
73 }
74
75 switch (psp) {
76 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
77 val->intval = bat->volt_value;
78 return 0;
79 case POWER_SUPPLY_PROP_VOLTAGE_MIN:
80 val->intval = bat->pdata->backup_volt_min;
81 return 0;
82 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
83 val->intval = bat->pdata->backup_volt_max;
84 return 0;
85 default:
86 return -EINVAL;
87 }
88}
89
90static struct s3c_adc_bat backup_bat = {
91 .psy = {
92 .name = "backup-battery",
93 .type = POWER_SUPPLY_TYPE_BATTERY,
94 .properties = s3c_adc_backup_bat_props,
95 .num_properties = ARRAY_SIZE(s3c_adc_backup_bat_props),
96 .get_property = s3c_adc_backup_bat_get_property,
97 .use_for_apm = 1,
98 },
99};
100
101static enum power_supply_property s3c_adc_main_bat_props[] = {
102 POWER_SUPPLY_PROP_STATUS,
103 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
104 POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
105 POWER_SUPPLY_PROP_CHARGE_NOW,
106 POWER_SUPPLY_PROP_VOLTAGE_NOW,
107 POWER_SUPPLY_PROP_CURRENT_NOW,
108};
109
110static int calc_full_volt(int volt_val, int cur_val, int impedance)
111{
112 return volt_val + cur_val * impedance / 1000;
113}
114
115static int s3c_adc_bat_get_property(struct power_supply *psy,
116 enum power_supply_property psp,
117 union power_supply_propval *val)
118{
119 struct s3c_adc_bat *bat = container_of(psy, struct s3c_adc_bat, psy);
120
121 int new_level;
122 int full_volt;
123 const struct s3c_adc_bat_thresh *lut = bat->pdata->lut_noac;
124 unsigned int lut_size = bat->pdata->lut_noac_cnt;
125
126 if (!bat) {
127 dev_err(psy->dev, "no battery infos ?!\n");
128 return -EINVAL;
129 }
130
131 if (bat->volt_value < 0 || bat->cur_value < 0 ||
132 jiffies_to_msecs(jiffies - bat->timestamp) >
133 BAT_POLL_INTERVAL) {
134 bat->volt_value = s3c_adc_read(bat->client,
135 bat->pdata->volt_channel) * bat->pdata->volt_mult;
136 bat->cur_value = s3c_adc_read(bat->client,
137 bat->pdata->current_channel) * bat->pdata->current_mult;
138 bat->timestamp = jiffies;
139 }
140
141 if (bat->cable_plugged &&
142 ((bat->pdata->gpio_charge_finished < 0) ||
143 !gpio_get_value(bat->pdata->gpio_charge_finished))) {
144 lut = bat->pdata->lut_acin;
145 lut_size = bat->pdata->lut_acin_cnt;
146 }
147
148 new_level = 100000;
149 full_volt = calc_full_volt((bat->volt_value / 1000),
150 (bat->cur_value / 1000), bat->pdata->internal_impedance);
151
152 if (full_volt < calc_full_volt(lut->volt, lut->cur,
153 bat->pdata->internal_impedance)) {
154 lut_size--;
155 while (lut_size--) {
156 int lut_volt1;
157 int lut_volt2;
158
159 lut_volt1 = calc_full_volt(lut[0].volt, lut[0].cur,
160 bat->pdata->internal_impedance);
161 lut_volt2 = calc_full_volt(lut[1].volt, lut[1].cur,
162 bat->pdata->internal_impedance);
163 if (full_volt < lut_volt1 && full_volt >= lut_volt2) {
164 new_level = (lut[1].level +
165 (lut[0].level - lut[1].level) *
166 (full_volt - lut_volt2) /
167 (lut_volt1 - lut_volt2)) * 1000;
168 break;
169 }
170 new_level = lut[1].level * 1000;
171 lut++;
172 }
173 }
174
175 bat->level = new_level;
176
177 switch (psp) {
178 case POWER_SUPPLY_PROP_STATUS:
179 if (bat->pdata->gpio_charge_finished < 0)
180 val->intval = bat->level == 100000 ?
181 POWER_SUPPLY_STATUS_FULL : bat->status;
182 else
183 val->intval = bat->status;
184 return 0;
185 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
186 val->intval = 100000;
187 return 0;
188 case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
189 val->intval = 0;
190 return 0;
191 case POWER_SUPPLY_PROP_CHARGE_NOW:
192 val->intval = bat->level;
193 return 0;
194 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
195 val->intval = bat->volt_value;
196 return 0;
197 case POWER_SUPPLY_PROP_CURRENT_NOW:
198 val->intval = bat->cur_value;
199 return 0;
200 default:
201 return -EINVAL;
202 }
203}
204
205static struct s3c_adc_bat main_bat = {
206 .psy = {
207 .name = "main-battery",
208 .type = POWER_SUPPLY_TYPE_BATTERY,
209 .properties = s3c_adc_main_bat_props,
210 .num_properties = ARRAY_SIZE(s3c_adc_main_bat_props),
211 .get_property = s3c_adc_bat_get_property,
212 .external_power_changed = s3c_adc_bat_ext_power_changed,
213 .use_for_apm = 1,
214 },
215};
216
217static void s3c_adc_bat_work(struct work_struct *work)
218{
219 struct s3c_adc_bat *bat = &main_bat;
220 int is_charged;
221 int is_plugged;
222 static int was_plugged;
223
224 is_plugged = power_supply_am_i_supplied(&bat->psy);
225 bat->cable_plugged = is_plugged;
226 if (is_plugged != was_plugged) {
227 was_plugged = is_plugged;
228 if (is_plugged) {
229 if (bat->pdata->enable_charger)
230 bat->pdata->enable_charger();
231 bat->status = POWER_SUPPLY_STATUS_CHARGING;
232 } else {
233 if (bat->pdata->disable_charger)
234 bat->pdata->disable_charger();
235 bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
236 }
237 } else {
238 if ((bat->pdata->gpio_charge_finished >= 0) && is_plugged) {
239 is_charged = gpio_get_value(
240 main_bat.pdata->gpio_charge_finished);
241 if (is_charged) {
242 if (bat->pdata->disable_charger)
243 bat->pdata->disable_charger();
244 bat->status = POWER_SUPPLY_STATUS_FULL;
245 } else {
246 if (bat->pdata->enable_charger)
247 bat->pdata->enable_charger();
248 bat->status = POWER_SUPPLY_STATUS_CHARGING;
249 }
250 }
251 }
252
253 power_supply_changed(&bat->psy);
254}
255
256static irqreturn_t s3c_adc_bat_charged(int irq, void *dev_id)
257{
258 schedule_delayed_work(&bat_work,
259 msecs_to_jiffies(JITTER_DELAY));
260 return IRQ_HANDLED;
261}
262
263static int __init s3c_adc_bat_probe(struct platform_device *pdev)
264{
265 struct s3c_adc_client *client;
266 struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;
267 int ret;
268
269 client = s3c_adc_register(pdev, NULL, NULL, 0);
270 if (IS_ERR(client)) {
271 dev_err(&pdev->dev, "cannot register adc\n");
272 return PTR_ERR(client);
273 }
274
275 platform_set_drvdata(pdev, client);
276
277 main_bat.client = client;
278 main_bat.pdata = pdata;
279 main_bat.volt_value = -1;
280 main_bat.cur_value = -1;
281 main_bat.cable_plugged = 0;
282 main_bat.status = POWER_SUPPLY_STATUS_DISCHARGING;
283
284 ret = power_supply_register(&pdev->dev, &main_bat.psy);
285 if (ret)
286 goto err_reg_main;
287 if (pdata->backup_volt_mult) {
288 backup_bat.client = client;
289 backup_bat.pdata = pdev->dev.platform_data;
290 backup_bat.volt_value = -1;
291 ret = power_supply_register(&pdev->dev, &backup_bat.psy);
292 if (ret)
293 goto err_reg_backup;
294 }
295
296 INIT_DELAYED_WORK(&bat_work, s3c_adc_bat_work);
297
298 if (pdata->gpio_charge_finished >= 0) {
299 ret = gpio_request(pdata->gpio_charge_finished, "charged");
300 if (ret)
301 goto err_gpio;
302
303 ret = request_irq(gpio_to_irq(pdata->gpio_charge_finished),
304 s3c_adc_bat_charged,
305 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
306 "battery charged", NULL);
307 if (ret)
308 goto err_irq;
309 }
310
311 if (pdata->init) {
312 ret = pdata->init();
313 if (ret)
314 goto err_platform;
315 }
316
317 dev_info(&pdev->dev, "successfully loaded\n");
318 device_init_wakeup(&pdev->dev, 1);
319
320 /* Schedule timer to check current status */
321 schedule_delayed_work(&bat_work,
322 msecs_to_jiffies(JITTER_DELAY));
323
324 return 0;
325
326err_platform:
327 if (pdata->gpio_charge_finished >= 0)
328 free_irq(gpio_to_irq(pdata->gpio_charge_finished), NULL);
329err_irq:
330 if (pdata->gpio_charge_finished >= 0)
331 gpio_free(pdata->gpio_charge_finished);
332err_gpio:
333 if (pdata->backup_volt_mult)
334 power_supply_unregister(&backup_bat.psy);
335err_reg_backup:
336 power_supply_unregister(&main_bat.psy);
337err_reg_main:
338 return ret;
339}
340
341static int s3c_adc_bat_remove(struct platform_device *pdev)
342{
343 struct s3c_adc_client *client = platform_get_drvdata(pdev);
344 struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;
345
346 power_supply_unregister(&main_bat.psy);
347 if (pdata->backup_volt_mult)
348 power_supply_unregister(&backup_bat.psy);
349
350 s3c_adc_release(client);
351
352 if (pdata->gpio_charge_finished >= 0) {
353 free_irq(gpio_to_irq(pdata->gpio_charge_finished), NULL);
354 gpio_free(pdata->gpio_charge_finished);
355 }
356
357 cancel_delayed_work(&bat_work);
358
359 if (pdata->exit)
360 pdata->exit();
361
362 return 0;
363}
364
365#ifdef CONFIG_PM
366static int s3c_adc_bat_suspend(struct platform_device *pdev,
367 pm_message_t state)
368{
369 struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;
370
371 if (pdata->gpio_charge_finished >= 0) {
372 if (device_may_wakeup(&pdev->dev))
373 enable_irq_wake(
374 gpio_to_irq(pdata->gpio_charge_finished));
375 else {
376 disable_irq(gpio_to_irq(pdata->gpio_charge_finished));
377 main_bat.pdata->disable_charger();
378 }
379 }
380
381 return 0;
382}
383
384static int s3c_adc_bat_resume(struct platform_device *pdev)
385{
386 struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;
387
388 if (pdata->gpio_charge_finished >= 0) {
389 if (device_may_wakeup(&pdev->dev))
390 disable_irq_wake(
391 gpio_to_irq(pdata->gpio_charge_finished));
392 else
393 enable_irq(gpio_to_irq(pdata->gpio_charge_finished));
394 }
395
396 /* Schedule timer to check current status */
397 schedule_delayed_work(&bat_work,
398 msecs_to_jiffies(JITTER_DELAY));
399
400 return 0;
401}
402#else
403#define s3c_adc_battery_suspend NULL
404#define s3c_adc_battery_resume NULL
405#endif
406
407static struct platform_driver s3c_adc_bat_driver = {
408 .driver = {
409 .name = "s3c-adc-battery",
410 },
411 .probe = s3c_adc_bat_probe,
412 .remove = s3c_adc_bat_remove,
413 .suspend = s3c_adc_bat_suspend,
414 .resume = s3c_adc_bat_resume,
415};
416
417static int __init s3c_adc_bat_init(void)
418{
419 return platform_driver_register(&s3c_adc_bat_driver);
420}
421module_init(s3c_adc_bat_init);
422
423static void __exit s3c_adc_bat_exit(void)
424{
425 platform_driver_unregister(&s3c_adc_bat_driver);
426}
427module_exit(s3c_adc_bat_exit);
428
429MODULE_AUTHOR("Vasily Khoruzhick <anarsoul@gmail.com>");
430MODULE_DESCRIPTION("iPAQ H1930/H1940/RX1950 battery controler driver");
431MODULE_LICENSE("GPL");
diff --git a/drivers/power/wm97xx_battery.c b/drivers/power/wm97xx_battery.c
index 4e8afce0c818..5071d85ec12d 100644
--- a/drivers/power/wm97xx_battery.c
+++ b/drivers/power/wm97xx_battery.c
@@ -29,7 +29,6 @@ static DEFINE_MUTEX(bat_lock);
29static struct work_struct bat_work; 29static struct work_struct bat_work;
30static struct mutex work_lock; 30static struct mutex work_lock;
31static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN; 31static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
32static struct wm97xx_batt_info *gpdata;
33static enum power_supply_property *prop; 32static enum power_supply_property *prop;
34 33
35static unsigned long wm97xx_read_bat(struct power_supply *bat_ps) 34static unsigned long wm97xx_read_bat(struct power_supply *bat_ps)
@@ -172,12 +171,6 @@ static int __devinit wm97xx_bat_probe(struct platform_device *dev)
172 struct wm97xx_pdata *wmdata = dev->dev.platform_data; 171 struct wm97xx_pdata *wmdata = dev->dev.platform_data;
173 struct wm97xx_batt_pdata *pdata; 172 struct wm97xx_batt_pdata *pdata;
174 173
175 if (gpdata) {
176 dev_err(&dev->dev, "Do not pass platform_data through "
177 "wm97xx_bat_set_pdata!\n");
178 return -EINVAL;
179 }
180
181 if (!wmdata) { 174 if (!wmdata) {
182 dev_err(&dev->dev, "No platform data supplied\n"); 175 dev_err(&dev->dev, "No platform data supplied\n");
183 return -EINVAL; 176 return -EINVAL;
@@ -308,15 +301,6 @@ static void __exit wm97xx_bat_exit(void)
308 platform_driver_unregister(&wm97xx_bat_driver); 301 platform_driver_unregister(&wm97xx_bat_driver);
309} 302}
310 303
311/* The interface is deprecated, as well as linux/wm97xx_batt.h */
312void wm97xx_bat_set_pdata(struct wm97xx_batt_info *data);
313
314void wm97xx_bat_set_pdata(struct wm97xx_batt_info *data)
315{
316 gpdata = data;
317}
318EXPORT_SYMBOL_GPL(wm97xx_bat_set_pdata);
319
320module_init(wm97xx_bat_init); 304module_init(wm97xx_bat_init);
321module_exit(wm97xx_bat_exit); 305module_exit(wm97xx_bat_exit);
322 306
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 04f2e085116a..172951bf23a4 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -100,6 +100,14 @@ config REGULATOR_MAX8925
100 help 100 help
101 Say y here to support the voltage regulaltor of Maxim MAX8925 PMIC. 101 Say y here to support the voltage regulaltor of Maxim MAX8925 PMIC.
102 102
103config REGULATOR_MAX8998
104 tristate "Maxim 8998 voltage regulator"
105 depends on MFD_MAX8998
106 help
107 This driver controls a Maxim 8998 voltage output regulator
108 via I2C bus. The provided regulator is suitable for S3C6410
109 and S5PC1XX chips to control VCC_CORE and VCC_USIM voltages.
110
103config REGULATOR_TWL4030 111config REGULATOR_TWL4030
104 bool "TI TWL4030/TWL5030/TWL6030/TPS695x0 PMIC" 112 bool "TI TWL4030/TWL5030/TWL6030/TPS695x0 PMIC"
105 depends on TWL4030_CORE 113 depends on TWL4030_CORE
@@ -201,5 +209,31 @@ config REGULATOR_88PM8607
201 help 209 help
202 This driver supports 88PM8607 voltage regulator chips. 210 This driver supports 88PM8607 voltage regulator chips.
203 211
212config REGULATOR_ISL6271A
213 tristate "Intersil ISL6271A Power regulator"
214 depends on I2C
215 help
216 This driver supports ISL6271A voltage regulator chip.
217
218config REGULATOR_AD5398
219 tristate "Analog Devices AD5398/AD5821 regulators"
220 depends on I2C
221 help
222 This driver supports AD5398 and AD5821 current regulator chips.
223 If building into module, its name is ad5398.ko.
224
225config REGULATOR_AB8500
226 bool "ST-Ericsson AB8500 Power Regulators"
227 depends on AB8500_CORE
228 help
229 This driver supports the regulators found on the ST-Ericsson mixed
230 signal AB8500 PMIC
231
232config REGULATOR_TPS6586X
233 tristate "TI TPS6586X Power regulators"
234 depends on MFD_TPS6586X
235 help
236 This driver supports TPS6586X voltage regulator chips.
237
204endif 238endif
205 239
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 4e7feece22d5..8285fd832e16 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
8obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o 8obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
9obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o 9obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
10 10
11obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o
11obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o 12obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
12obj-$(CONFIG_REGULATOR_DUMMY) += dummy.o 13obj-$(CONFIG_REGULATOR_DUMMY) += dummy.o
13obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o 14obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
@@ -16,12 +17,14 @@ obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o
16obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o 17obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o
17obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o 18obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o
18obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o 19obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o
20obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o
19obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o 21obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o
20obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o 22obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o
21obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o 23obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o
22obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o 24obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o
23obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o 25obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o
24obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o 26obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o
27obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o
25obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 28obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
26obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o 29obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
27obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o 30obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
@@ -31,5 +34,7 @@ obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o
31obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o 34obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o
32obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o 35obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o
33obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o 36obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o
37obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o
38obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o
34 39
35ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG 40ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
new file mode 100644
index 000000000000..dc3f1a491675
--- /dev/null
+++ b/drivers/regulator/ab8500.c
@@ -0,0 +1,427 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License v2
5 *
6 * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
7 *
8 * AB8500 peripheral regulators
9 *
10 * AB8500 supports the following regulators,
11 * LDOs - VAUDIO, VANAMIC2/2, VDIGMIC, VINTCORE12, VTVOUT,
12 * VAUX1/2/3, VANA
13 *
14 * for DB8500 cut 1.0 and previous versions of the silicon, all accesses
15 * to registers are through the DB8500 SPI. In cut 1.1 onwards, these
16 * accesses are through the DB8500 PRCMU I2C
17 *
18 */
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/err.h>
22#include <linux/platform_device.h>
23#include <linux/mfd/ab8500.h>
24#include <linux/regulator/driver.h>
25#include <linux/regulator/machine.h>
26#include <linux/regulator/ab8500.h>
27
28/**
29 * struct ab8500_regulator_info - ab8500 regulator information
30 * @desc: regulator description
31 * @ab8500: ab8500 parent
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_reg: register to control on/off
37 * @mask: mask to enable/disable regulator
38 * @enable: bits to enable the regulator in normal(high power) mode
39 * @voltage_reg: register to control regulator voltage
40 * @voltage_mask: mask to control regulator voltage
41 * @supported_voltages: supported voltage table
42 * @voltages_len: number of supported voltages for the regulator
43 */
44struct ab8500_regulator_info {
45 struct device *dev;
46 struct regulator_desc desc;
47 struct ab8500 *ab8500;
48 struct regulator_dev *regulator;
49 int max_uV;
50 int min_uV;
51 int fixed_uV;
52 int update_reg;
53 int mask;
54 int enable;
55 int voltage_reg;
56 int voltage_mask;
57 int const *supported_voltages;
58 int voltages_len;
59};
60
61/* voltage tables for the vauxn/vintcore supplies */
62static const int ldo_vauxn_voltages[] = {
63 1100000,
64 1200000,
65 1300000,
66 1400000,
67 1500000,
68 1800000,
69 1850000,
70 1900000,
71 2500000,
72 2650000,
73 2700000,
74 2750000,
75 2800000,
76 2900000,
77 3000000,
78 3300000,
79};
80
81static const int ldo_vintcore_voltages[] = {
82 1200000,
83 1225000,
84 1250000,
85 1275000,
86 1300000,
87 1325000,
88 1350000,
89};
90
91static int ab8500_regulator_enable(struct regulator_dev *rdev)
92{
93 int regulator_id, ret;
94 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
95
96 regulator_id = rdev_get_id(rdev);
97 if (regulator_id >= AB8500_NUM_REGULATORS)
98 return -EINVAL;
99
100 ret = ab8500_set_bits(info->ab8500, info->update_reg,
101 info->mask, info->enable);
102 if (ret < 0)
103 dev_err(rdev_get_dev(rdev),
104 "couldn't set enable bits for regulator\n");
105 return ret;
106}
107
108static int ab8500_regulator_disable(struct regulator_dev *rdev)
109{
110 int regulator_id, ret;
111 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
112
113 regulator_id = rdev_get_id(rdev);
114 if (regulator_id >= AB8500_NUM_REGULATORS)
115 return -EINVAL;
116
117 ret = ab8500_set_bits(info->ab8500, info->update_reg,
118 info->mask, 0x0);
119 if (ret < 0)
120 dev_err(rdev_get_dev(rdev),
121 "couldn't set disable bits for regulator\n");
122 return ret;
123}
124
125static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
126{
127 int regulator_id, ret;
128 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
129
130 regulator_id = rdev_get_id(rdev);
131 if (regulator_id >= AB8500_NUM_REGULATORS)
132 return -EINVAL;
133
134 ret = ab8500_read(info->ab8500, info->update_reg);
135 if (ret < 0) {
136 dev_err(rdev_get_dev(rdev),
137 "couldn't read 0x%x register\n", info->update_reg);
138 return ret;
139 }
140
141 if (ret & info->mask)
142 return true;
143 else
144 return false;
145}
146
147static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
148{
149 int regulator_id;
150 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
151
152 regulator_id = rdev_get_id(rdev);
153 if (regulator_id >= AB8500_NUM_REGULATORS)
154 return -EINVAL;
155
156 /* return the uV for the fixed regulators */
157 if (info->fixed_uV)
158 return info->fixed_uV;
159
160 if (selector > info->voltages_len)
161 return -EINVAL;
162
163 return info->supported_voltages[selector];
164}
165
166static int ab8500_regulator_get_voltage(struct regulator_dev *rdev)
167{
168 int regulator_id, ret, val;
169 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
170
171 regulator_id = rdev_get_id(rdev);
172 if (regulator_id >= AB8500_NUM_REGULATORS)
173 return -EINVAL;
174
175 ret = ab8500_read(info->ab8500, info->voltage_reg);
176 if (ret < 0) {
177 dev_err(rdev_get_dev(rdev),
178 "couldn't read voltage reg for regulator\n");
179 return ret;
180 }
181
182 /* vintcore has a different layout */
183 val = ret & info->voltage_mask;
184 if (regulator_id == AB8500_LDO_INTCORE)
185 ret = info->supported_voltages[val >> 0x3];
186 else
187 ret = info->supported_voltages[val];
188
189 return ret;
190}
191
192static int ab8500_get_best_voltage_index(struct regulator_dev *rdev,
193 int min_uV, int max_uV)
194{
195 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
196 int i;
197
198 /* check the supported voltage */
199 for (i = 0; i < info->voltages_len; i++) {
200 if ((info->supported_voltages[i] >= min_uV) &&
201 (info->supported_voltages[i] <= max_uV))
202 return i;
203 }
204
205 return -EINVAL;
206}
207
208static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
209 int min_uV, int max_uV)
210{
211 int regulator_id, ret;
212 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
213
214 regulator_id = rdev_get_id(rdev);
215 if (regulator_id >= AB8500_NUM_REGULATORS)
216 return -EINVAL;
217
218 /* get the appropriate voltages within the range */
219 ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV);
220 if (ret < 0) {
221 dev_err(rdev_get_dev(rdev),
222 "couldn't get best voltage for regulator\n");
223 return ret;
224 }
225
226 /* set the registers for the request */
227 ret = ab8500_set_bits(info->ab8500, info->voltage_reg,
228 info->voltage_mask, ret);
229 if (ret < 0)
230 dev_err(rdev_get_dev(rdev),
231 "couldn't set voltage reg for regulator\n");
232
233 return ret;
234}
235
236static struct regulator_ops ab8500_regulator_ops = {
237 .enable = ab8500_regulator_enable,
238 .disable = ab8500_regulator_disable,
239 .is_enabled = ab8500_regulator_is_enabled,
240 .get_voltage = ab8500_regulator_get_voltage,
241 .set_voltage = ab8500_regulator_set_voltage,
242 .list_voltage = ab8500_list_voltage,
243};
244
245static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
246{
247 int regulator_id;
248 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
249
250 regulator_id = rdev_get_id(rdev);
251 if (regulator_id >= AB8500_NUM_REGULATORS)
252 return -EINVAL;
253
254 return info->fixed_uV;
255}
256
257static struct regulator_ops ab8500_ldo_fixed_ops = {
258 .enable = ab8500_regulator_enable,
259 .disable = ab8500_regulator_disable,
260 .is_enabled = ab8500_regulator_is_enabled,
261 .get_voltage = ab8500_fixed_get_voltage,
262 .list_voltage = ab8500_list_voltage,
263};
264
265#define AB8500_LDO(_id, min, max, reg, reg_mask, reg_enable, \
266 volt_reg, volt_mask, voltages, \
267 len_volts) \
268{ \
269 .desc = { \
270 .name = "LDO-" #_id, \
271 .ops = &ab8500_regulator_ops, \
272 .type = REGULATOR_VOLTAGE, \
273 .id = AB8500_LDO_##_id, \
274 .owner = THIS_MODULE, \
275 }, \
276 .min_uV = (min) * 1000, \
277 .max_uV = (max) * 1000, \
278 .update_reg = reg, \
279 .mask = reg_mask, \
280 .enable = reg_enable, \
281 .voltage_reg = volt_reg, \
282 .voltage_mask = volt_mask, \
283 .supported_voltages = voltages, \
284 .voltages_len = len_volts, \
285 .fixed_uV = 0, \
286}
287
288#define AB8500_FIXED_LDO(_id, fixed, reg, reg_mask, \
289 reg_enable) \
290{ \
291 .desc = { \
292 .name = "LDO-" #_id, \
293 .ops = &ab8500_ldo_fixed_ops, \
294 .type = REGULATOR_VOLTAGE, \
295 .id = AB8500_LDO_##_id, \
296 .owner = THIS_MODULE, \
297 }, \
298 .fixed_uV = fixed * 1000, \
299 .update_reg = reg, \
300 .mask = reg_mask, \
301 .enable = reg_enable, \
302}
303
304static struct ab8500_regulator_info ab8500_regulator_info[] = {
305 /*
306 * Variable Voltage LDOs
307 * name, min uV, max uV, ctrl reg, reg mask, enable mask,
308 * volt ctrl reg, volt ctrl mask, volt table, num supported volts
309 */
310 AB8500_LDO(AUX1, 1100, 3300, 0x0409, 0x3, 0x1, 0x041f, 0xf,
311 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)),
312 AB8500_LDO(AUX2, 1100, 3300, 0x0409, 0xc, 0x4, 0x0420, 0xf,
313 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)),
314 AB8500_LDO(AUX3, 1100, 3300, 0x040a, 0x3, 0x1, 0x0421, 0xf,
315 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)),
316 AB8500_LDO(INTCORE, 1100, 3300, 0x0380, 0x4, 0x4, 0x0380, 0x38,
317 ldo_vintcore_voltages, ARRAY_SIZE(ldo_vintcore_voltages)),
318
319 /*
320 * Fixed Voltage LDOs
321 * name, o/p uV, ctrl reg, enable, disable
322 */
323 AB8500_FIXED_LDO(TVOUT, 2000, 0x0380, 0x2, 0x2),
324 AB8500_FIXED_LDO(AUDIO, 2000, 0x0383, 0x2, 0x2),
325 AB8500_FIXED_LDO(ANAMIC1, 2050, 0x0383, 0x4, 0x4),
326 AB8500_FIXED_LDO(ANAMIC2, 2050, 0x0383, 0x8, 0x8),
327 AB8500_FIXED_LDO(DMIC, 1800, 0x0383, 0x10, 0x10),
328 AB8500_FIXED_LDO(ANA, 1200, 0x0383, 0xc, 0x4),
329};
330
331static inline struct ab8500_regulator_info *find_regulator_info(int id)
332{
333 struct ab8500_regulator_info *info;
334 int i;
335
336 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
337 info = &ab8500_regulator_info[i];
338 if (info->desc.id == id)
339 return info;
340 }
341 return NULL;
342}
343
344static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
345{
346 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
347 struct ab8500_platform_data *pdata = dev_get_platdata(ab8500->dev);
348 int i, err;
349
350 if (!ab8500) {
351 dev_err(&pdev->dev, "null mfd parent\n");
352 return -EINVAL;
353 }
354
355 /* register all regulators */
356 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
357 struct ab8500_regulator_info *info = NULL;
358
359 /* assign per-regulator data */
360 info = &ab8500_regulator_info[i];
361 info->dev = &pdev->dev;
362 info->ab8500 = ab8500;
363
364 info->regulator = regulator_register(&info->desc, &pdev->dev,
365 pdata->regulator[i], info);
366 if (IS_ERR(info->regulator)) {
367 err = PTR_ERR(info->regulator);
368 dev_err(&pdev->dev, "failed to register regulator %s\n",
369 info->desc.name);
370 /* when we fail, un-register all earlier regulators */
371 i--;
372 while (i > 0) {
373 info = &ab8500_regulator_info[i];
374 regulator_unregister(info->regulator);
375 i--;
376 }
377 return err;
378 }
379 }
380
381 return 0;
382}
383
384static __devexit int ab8500_regulator_remove(struct platform_device *pdev)
385{
386 int i;
387
388 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
389 struct ab8500_regulator_info *info = NULL;
390 info = &ab8500_regulator_info[i];
391 regulator_unregister(info->regulator);
392 }
393
394 return 0;
395}
396
397static struct platform_driver ab8500_regulator_driver = {
398 .probe = ab8500_regulator_probe,
399 .remove = __devexit_p(ab8500_regulator_remove),
400 .driver = {
401 .name = "ab8500-regulator",
402 .owner = THIS_MODULE,
403 },
404};
405
406static int __init ab8500_regulator_init(void)
407{
408 int ret;
409
410 ret = platform_driver_register(&ab8500_regulator_driver);
411 if (ret != 0)
412 pr_err("Failed to register ab8500 regulator: %d\n", ret);
413
414 return ret;
415}
416subsys_initcall(ab8500_regulator_init);
417
418static void __exit ab8500_regulator_exit(void)
419{
420 platform_driver_unregister(&ab8500_regulator_driver);
421}
422module_exit(ab8500_regulator_exit);
423
424MODULE_LICENSE("GPL v2");
425MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
426MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
427MODULE_ALIAS("platform:ab8500-regulator");
diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c
new file mode 100644
index 000000000000..d59d2f2314af
--- /dev/null
+++ b/drivers/regulator/ad5398.c
@@ -0,0 +1,288 @@
1/*
2 * Voltage and current regulation for AD5398 and AD5821
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Enter bugs at http://blackfin.uclinux.org/
7 *
8 * Licensed under the GPL-2 or later.
9 */
10
11#include <linux/module.h>
12#include <linux/err.h>
13#include <linux/i2c.h>
14#include <linux/slab.h>
15#include <linux/platform_device.h>
16#include <linux/regulator/driver.h>
17#include <linux/regulator/machine.h>
18
19#define AD5398_CURRENT_EN_MASK 0x8000
20
21struct ad5398_chip_info {
22 struct i2c_client *client;
23 int min_uA;
24 int max_uA;
25 unsigned int current_level;
26 unsigned int current_mask;
27 unsigned int current_offset;
28 struct regulator_dev rdev;
29};
30
31static int ad5398_calc_current(struct ad5398_chip_info *chip,
32 unsigned selector)
33{
34 unsigned range_uA = chip->max_uA - chip->min_uA;
35
36 return chip->min_uA + (selector * range_uA / chip->current_level);
37}
38
39static int ad5398_read_reg(struct i2c_client *client, unsigned short *data)
40{
41 unsigned short val;
42 int ret;
43
44 ret = i2c_master_recv(client, (char *)&val, 2);
45 if (ret < 0) {
46 dev_err(&client->dev, "I2C read error\n");
47 return ret;
48 }
49 *data = be16_to_cpu(val);
50
51 return ret;
52}
53
54static int ad5398_write_reg(struct i2c_client *client, const unsigned short data)
55{
56 unsigned short val;
57 int ret;
58
59 val = cpu_to_be16(data);
60 ret = i2c_master_send(client, (char *)&val, 2);
61 if (ret < 0)
62 dev_err(&client->dev, "I2C write error\n");
63
64 return ret;
65}
66
67static int ad5398_get_current_limit(struct regulator_dev *rdev)
68{
69 struct ad5398_chip_info *chip = rdev_get_drvdata(rdev);
70 struct i2c_client *client = chip->client;
71 unsigned short data;
72 int ret;
73
74 ret = ad5398_read_reg(client, &data);
75 if (ret < 0)
76 return ret;
77
78 ret = (data & chip->current_mask) >> chip->current_offset;
79
80 return ad5398_calc_current(chip, ret);
81}
82
83static int ad5398_set_current_limit(struct regulator_dev *rdev, int min_uA, int max_uA)
84{
85 struct ad5398_chip_info *chip = rdev_get_drvdata(rdev);
86 struct i2c_client *client = chip->client;
87 unsigned range_uA = chip->max_uA - chip->min_uA;
88 unsigned selector;
89 unsigned short data;
90 int ret;
91
92 if (min_uA > chip->max_uA || min_uA < chip->min_uA)
93 return -EINVAL;
94 if (max_uA > chip->max_uA || max_uA < chip->min_uA)
95 return -EINVAL;
96
97 selector = ((min_uA - chip->min_uA) * chip->current_level +
98 range_uA - 1) / range_uA;
99 if (ad5398_calc_current(chip, selector) > max_uA)
100 return -EINVAL;
101
102 dev_dbg(&client->dev, "changing current %dmA\n",
103 ad5398_calc_current(chip, selector) / 1000);
104
105 /* read chip enable bit */
106 ret = ad5398_read_reg(client, &data);
107 if (ret < 0)
108 return ret;
109
110 /* prepare register data */
111 selector = (selector << chip->current_offset) & chip->current_mask;
112 data = (unsigned short)selector | (data & AD5398_CURRENT_EN_MASK);
113
114 /* write the new current value back as well as enable bit */
115 ret = ad5398_write_reg(client, data);
116
117 return ret;
118}
119
120static int ad5398_is_enabled(struct regulator_dev *rdev)
121{
122 struct ad5398_chip_info *chip = rdev_get_drvdata(rdev);
123 struct i2c_client *client = chip->client;
124 unsigned short data;
125 int ret;
126
127 ret = ad5398_read_reg(client, &data);
128 if (ret < 0)
129 return ret;
130
131 if (data & AD5398_CURRENT_EN_MASK)
132 return 1;
133 else
134 return 0;
135}
136
137static int ad5398_enable(struct regulator_dev *rdev)
138{
139 struct ad5398_chip_info *chip = rdev_get_drvdata(rdev);
140 struct i2c_client *client = chip->client;
141 unsigned short data;
142 int ret;
143
144 ret = ad5398_read_reg(client, &data);
145 if (ret < 0)
146 return ret;
147
148 if (data & AD5398_CURRENT_EN_MASK)
149 return 0;
150
151 data |= AD5398_CURRENT_EN_MASK;
152
153 ret = ad5398_write_reg(client, data);
154
155 return ret;
156}
157
158static int ad5398_disable(struct regulator_dev *rdev)
159{
160 struct ad5398_chip_info *chip = rdev_get_drvdata(rdev);
161 struct i2c_client *client = chip->client;
162 unsigned short data;
163 int ret;
164
165 ret = ad5398_read_reg(client, &data);
166 if (ret < 0)
167 return ret;
168
169 if (!(data & AD5398_CURRENT_EN_MASK))
170 return 0;
171
172 data &= ~AD5398_CURRENT_EN_MASK;
173
174 ret = ad5398_write_reg(client, data);
175
176 return ret;
177}
178
179static struct regulator_ops ad5398_ops = {
180 .get_current_limit = ad5398_get_current_limit,
181 .set_current_limit = ad5398_set_current_limit,
182 .enable = ad5398_enable,
183 .disable = ad5398_disable,
184 .is_enabled = ad5398_is_enabled,
185};
186
187static struct regulator_desc ad5398_reg = {
188 .name = "isink",
189 .id = 0,
190 .ops = &ad5398_ops,
191 .type = REGULATOR_CURRENT,
192 .owner = THIS_MODULE,
193};
194
195struct ad5398_current_data_format {
196 int current_bits;
197 int current_offset;
198 int min_uA;
199 int max_uA;
200};
201
202static const struct ad5398_current_data_format df_10_4_120 = {10, 4, 0, 120000};
203
204static const struct i2c_device_id ad5398_id[] = {
205 { "ad5398", (kernel_ulong_t)&df_10_4_120 },
206 { "ad5821", (kernel_ulong_t)&df_10_4_120 },
207 { }
208};
209MODULE_DEVICE_TABLE(i2c, ad5398_id);
210
211static int __devinit ad5398_probe(struct i2c_client *client,
212 const struct i2c_device_id *id)
213{
214 struct regulator_dev *rdev;
215 struct regulator_init_data *init_data = client->dev.platform_data;
216 struct ad5398_chip_info *chip;
217 const struct ad5398_current_data_format *df =
218 (struct ad5398_current_data_format *)id->driver_data;
219 int ret;
220
221 if (!init_data)
222 return -EINVAL;
223
224 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
225 if (!chip)
226 return -ENOMEM;
227
228 chip->client = client;
229
230 chip->min_uA = df->min_uA;
231 chip->max_uA = df->max_uA;
232 chip->current_level = 1 << df->current_bits;
233 chip->current_offset = df->current_offset;
234 chip->current_mask = (chip->current_level - 1) << chip->current_offset;
235
236 rdev = regulator_register(&ad5398_reg, &client->dev, init_data, chip);
237 if (IS_ERR(rdev)) {
238 ret = PTR_ERR(rdev);
239 dev_err(&client->dev, "failed to register %s %s\n",
240 id->name, ad5398_reg.name);
241 goto err;
242 }
243
244 i2c_set_clientdata(client, chip);
245 dev_dbg(&client->dev, "%s regulator driver is registered.\n", id->name);
246 return 0;
247
248err:
249 kfree(chip);
250 return ret;
251}
252
253static int __devexit ad5398_remove(struct i2c_client *client)
254{
255 struct ad5398_chip_info *chip = i2c_get_clientdata(client);
256
257 regulator_unregister(&chip->rdev);
258 kfree(chip);
259 i2c_set_clientdata(client, NULL);
260
261 return 0;
262}
263
264static struct i2c_driver ad5398_driver = {
265 .probe = ad5398_probe,
266 .remove = __devexit_p(ad5398_remove),
267 .driver = {
268 .name = "ad5398",
269 },
270 .id_table = ad5398_id,
271};
272
273static int __init ad5398_init(void)
274{
275 return i2c_add_driver(&ad5398_driver);
276}
277subsys_initcall(ad5398_init);
278
279static void __exit ad5398_exit(void)
280{
281 i2c_del_driver(&ad5398_driver);
282}
283module_exit(ad5398_exit);
284
285MODULE_DESCRIPTION("AD5398 and AD5821 current regulator driver");
286MODULE_AUTHOR("Sonic Zhang");
287MODULE_LICENSE("GPL");
288MODULE_ALIAS("i2c:ad5398-regulator");
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c
new file mode 100644
index 000000000000..e49d2bd393f2
--- /dev/null
+++ b/drivers/regulator/isl6271a-regulator.c
@@ -0,0 +1,236 @@
1/*
2 * isl6271a-regulator.c
3 *
4 * Support for Intersil ISL6271A voltage regulator
5 *
6 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation version 2.
11 *
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
13 * whether express or implied; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/err.h>
22#include <linux/platform_device.h>
23#include <linux/regulator/driver.h>
24#include <linux/i2c.h>
25#include <linux/delay.h>
26#include <linux/slab.h>
27
28#define ISL6271A_VOLTAGE_MIN 850000
29#define ISL6271A_VOLTAGE_MAX 1600000
30#define ISL6271A_VOLTAGE_STEP 50000
31
32/* PMIC details */
33struct isl_pmic {
34 struct i2c_client *client;
35 struct regulator_dev *rdev[3];
36 struct mutex mtx;
37};
38
39static int isl6271a_get_voltage(struct regulator_dev *dev)
40{
41 struct isl_pmic *pmic = rdev_get_drvdata(dev);
42 int idx, data;
43
44 mutex_lock(&pmic->mtx);
45
46 idx = i2c_smbus_read_byte(pmic->client);
47 if (idx < 0) {
48 dev_err(&pmic->client->dev, "Error getting voltage\n");
49 data = idx;
50 goto out;
51 }
52
53 /* Convert the data from chip to microvolts */
54 data = ISL6271A_VOLTAGE_MIN + (ISL6271A_VOLTAGE_STEP * (idx & 0xf));
55
56out:
57 mutex_unlock(&pmic->mtx);
58 return data;
59}
60
61static int isl6271a_set_voltage(struct regulator_dev *dev, int minuV, int maxuV)
62{
63 struct isl_pmic *pmic = rdev_get_drvdata(dev);
64 int vsel, err, data;
65
66 if (minuV < ISL6271A_VOLTAGE_MIN || minuV > ISL6271A_VOLTAGE_MAX)
67 return -EINVAL;
68 if (maxuV < ISL6271A_VOLTAGE_MIN || maxuV > ISL6271A_VOLTAGE_MAX)
69 return -EINVAL;
70
71 /* Align to 50000 mV */
72 vsel = minuV - (minuV % ISL6271A_VOLTAGE_STEP);
73
74 /* If the result fell out of [minuV,maxuV] range, put it back */
75 if (vsel < minuV)
76 vsel += ISL6271A_VOLTAGE_STEP;
77
78 /* Convert the microvolts to data for the chip */
79 data = (vsel - ISL6271A_VOLTAGE_MIN) / ISL6271A_VOLTAGE_STEP;
80
81 mutex_lock(&pmic->mtx);
82
83 err = i2c_smbus_write_byte(pmic->client, data);
84 if (err < 0)
85 dev_err(&pmic->client->dev, "Error setting voltage\n");
86
87 mutex_unlock(&pmic->mtx);
88 return err;
89}
90
91static int isl6271a_list_voltage(struct regulator_dev *dev, unsigned selector)
92{
93 return ISL6271A_VOLTAGE_MIN + (ISL6271A_VOLTAGE_STEP * selector);
94}
95
96static struct regulator_ops isl_core_ops = {
97 .get_voltage = isl6271a_get_voltage,
98 .set_voltage = isl6271a_set_voltage,
99 .list_voltage = isl6271a_list_voltage,
100};
101
102static int isl6271a_get_fixed_voltage(struct regulator_dev *dev)
103{
104 int id = rdev_get_id(dev);
105 return (id == 1) ? 1100000 : 1300000;
106}
107
108static int isl6271a_list_fixed_voltage(struct regulator_dev *dev, unsigned selector)
109{
110 int id = rdev_get_id(dev);
111 return (id == 1) ? 1100000 : 1300000;
112}
113
114static struct regulator_ops isl_fixed_ops = {
115 .get_voltage = isl6271a_get_fixed_voltage,
116 .list_voltage = isl6271a_list_fixed_voltage,
117};
118
119static struct regulator_desc isl_rd[] = {
120 {
121 .name = "Core Buck",
122 .id = 0,
123 .n_voltages = 16,
124 .ops = &isl_core_ops,
125 .type = REGULATOR_VOLTAGE,
126 .owner = THIS_MODULE,
127 }, {
128 .name = "LDO1",
129 .id = 1,
130 .n_voltages = 1,
131 .ops = &isl_fixed_ops,
132 .type = REGULATOR_VOLTAGE,
133 .owner = THIS_MODULE,
134 }, {
135 .name = "LDO2",
136 .id = 2,
137 .n_voltages = 1,
138 .ops = &isl_fixed_ops,
139 .type = REGULATOR_VOLTAGE,
140 .owner = THIS_MODULE,
141 },
142};
143
144static int __devinit isl6271a_probe(struct i2c_client *i2c,
145 const struct i2c_device_id *id)
146{
147 struct regulator_init_data *init_data = i2c->dev.platform_data;
148 struct isl_pmic *pmic;
149 int err, i;
150
151 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
152 return -EIO;
153
154 if (!init_data) {
155 dev_err(&i2c->dev, "no platform data supplied\n");
156 return -EIO;
157 }
158
159 pmic = kzalloc(sizeof(struct isl_pmic), GFP_KERNEL);
160 if (!pmic)
161 return -ENOMEM;
162
163 pmic->client = i2c;
164
165 mutex_init(&pmic->mtx);
166
167 for (i = 0; i < 3; i++) {
168 pmic->rdev[i] = regulator_register(&isl_rd[0], &i2c->dev,
169 init_data, pmic);
170 if (IS_ERR(pmic->rdev[i])) {
171 dev_err(&i2c->dev, "failed to register %s\n", id->name);
172 err = PTR_ERR(pmic->rdev);
173 goto error;
174 }
175 }
176
177 i2c_set_clientdata(i2c, pmic);
178
179 return 0;
180
181error:
182 while (--i >= 0)
183 regulator_unregister(pmic->rdev[i]);
184
185 kfree(pmic);
186 return err;
187}
188
189static int __devexit isl6271a_remove(struct i2c_client *i2c)
190{
191 struct isl_pmic *pmic = i2c_get_clientdata(i2c);
192 int i;
193
194 i2c_set_clientdata(i2c, NULL);
195
196 for (i = 0; i < 3; i++)
197 regulator_unregister(pmic->rdev[i]);
198
199 kfree(pmic);
200
201 return 0;
202}
203
204static const struct i2c_device_id isl6271a_id[] = {
205 {.name = "isl6271a", 0 },
206 { },
207};
208
209MODULE_DEVICE_TABLE(i2c, isl6271a_id);
210
211static struct i2c_driver isl6271a_i2c_driver = {
212 .driver = {
213 .name = "isl6271a",
214 .owner = THIS_MODULE,
215 },
216 .probe = isl6271a_probe,
217 .remove = __devexit_p(isl6271a_remove),
218 .id_table = isl6271a_id,
219};
220
221static int __init isl6271a_init(void)
222{
223 return i2c_add_driver(&isl6271a_i2c_driver);
224}
225
226static void __exit isl6271a_cleanup(void)
227{
228 i2c_del_driver(&isl6271a_i2c_driver);
229}
230
231subsys_initcall(isl6271a_init);
232module_exit(isl6271a_cleanup);
233
234MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
235MODULE_DESCRIPTION("Intersil ISL6271A voltage regulator driver");
236MODULE_LICENSE("GPL v2");
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c
index 8ae3732eb24b..3bb82b624e19 100644
--- a/drivers/regulator/lp3971.c
+++ b/drivers/regulator/lp3971.c
@@ -377,7 +377,7 @@ static int lp3971_i2c_read(struct i2c_client *i2c, char reg, int count,
377 if (count != 1) 377 if (count != 1)
378 return -EIO; 378 return -EIO;
379 ret = i2c_smbus_read_byte_data(i2c, reg); 379 ret = i2c_smbus_read_byte_data(i2c, reg);
380 if (ret < 0 || count != 1) 380 if (ret < 0)
381 return -EIO; 381 return -EIO;
382 382
383 *dest = ret; 383 *dest = ret;
@@ -387,15 +387,9 @@ static int lp3971_i2c_read(struct i2c_client *i2c, char reg, int count,
387static int lp3971_i2c_write(struct i2c_client *i2c, char reg, int count, 387static int lp3971_i2c_write(struct i2c_client *i2c, char reg, int count,
388 const u16 *src) 388 const u16 *src)
389{ 389{
390 int ret;
391
392 if (count != 1) 390 if (count != 1)
393 return -EIO; 391 return -EIO;
394 ret = i2c_smbus_write_byte_data(i2c, reg, *src); 392 return i2c_smbus_write_byte_data(i2c, reg, *src);
395 if (ret >= 0)
396 return 0;
397
398 return ret;
399} 393}
400 394
401static u8 lp3971_reg_read(struct lp3971 *lp3971, u8 reg) 395static u8 lp3971_reg_read(struct lp3971 *lp3971, u8 reg)
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index 2b54d9d75f11..8867c2710a6d 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -223,7 +223,7 @@ static int __devinit max1586_pmic_probe(struct i2c_client *client,
223 } 223 }
224 } 224 }
225 225
226 i2c_set_clientdata(client, rdev); 226 i2c_set_clientdata(client, max1586);
227 dev_info(&client->dev, "Maxim 1586 regulator driver loaded\n"); 227 dev_info(&client->dev, "Maxim 1586 regulator driver loaded\n");
228 return 0; 228 return 0;
229 229
@@ -238,13 +238,13 @@ out:
238 238
239static int __devexit max1586_pmic_remove(struct i2c_client *client) 239static int __devexit max1586_pmic_remove(struct i2c_client *client)
240{ 240{
241 struct regulator_dev **rdev = i2c_get_clientdata(client); 241 struct max1586_data *max1586 = i2c_get_clientdata(client);
242 int i; 242 int i;
243 243
244 for (i = 0; i <= MAX1586_V6; i++) 244 for (i = 0; i <= MAX1586_V6; i++)
245 if (rdev[i]) 245 if (max1586->rdev[i])
246 regulator_unregister(rdev[i]); 246 regulator_unregister(max1586->rdev[i]);
247 kfree(rdev); 247 kfree(max1586);
248 248
249 return 0; 249 return 0;
250} 250}
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
index d97220efae5a..c570e6eb0db2 100644
--- a/drivers/regulator/max8660.c
+++ b/drivers/regulator/max8660.c
@@ -450,7 +450,7 @@ static int __devinit max8660_probe(struct i2c_client *client,
450 } 450 }
451 } 451 }
452 452
453 i2c_set_clientdata(client, rdev); 453 i2c_set_clientdata(client, max8660);
454 dev_info(&client->dev, "Maxim 8660/8661 regulator driver loaded\n"); 454 dev_info(&client->dev, "Maxim 8660/8661 regulator driver loaded\n");
455 return 0; 455 return 0;
456 456
@@ -465,13 +465,13 @@ out:
465 465
466static int __devexit max8660_remove(struct i2c_client *client) 466static int __devexit max8660_remove(struct i2c_client *client)
467{ 467{
468 struct regulator_dev **rdev = i2c_get_clientdata(client); 468 struct max8660 *max8660 = i2c_get_clientdata(client);
469 int i; 469 int i;
470 470
471 for (i = 0; i < MAX8660_V_END; i++) 471 for (i = 0; i < MAX8660_V_END; i++)
472 if (rdev[i]) 472 if (max8660->rdev[i])
473 regulator_unregister(rdev[i]); 473 regulator_unregister(max8660->rdev[i]);
474 kfree(rdev); 474 kfree(max8660);
475 475
476 return 0; 476 return 0;
477} 477}
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
new file mode 100644
index 000000000000..ab67298799f9
--- /dev/null
+++ b/drivers/regulator/max8998.c
@@ -0,0 +1,635 @@
1/*
2 * max8998.c - Voltage regulator driver for the Maxim 8998
3 *
4 * Copyright (C) 2009-2010 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 * Marek Szyprowski <m.szyprowski@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
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/i2c.h>
26#include <linux/err.h>
27#include <linux/gpio.h>
28#include <linux/slab.h>
29#include <linux/interrupt.h>
30#include <linux/mutex.h>
31#include <linux/delay.h>
32#include <linux/platform_device.h>
33#include <linux/regulator/driver.h>
34#include <linux/mfd/max8998.h>
35#include <linux/mfd/max8998-private.h>
36
37struct max8998_data {
38 struct device *dev;
39 struct max8998_dev *iodev;
40 int num_regulators;
41 struct regulator_dev **rdev;
42};
43
44struct voltage_map_desc {
45 int min;
46 int max;
47 int step;
48};
49
50/* Voltage maps */
51static const struct voltage_map_desc ldo23_voltage_map_desc = {
52 .min = 800, .step = 50, .max = 1300,
53};
54static const struct voltage_map_desc ldo456711_voltage_map_desc = {
55 .min = 1600, .step = 100, .max = 3600,
56};
57static const struct voltage_map_desc ldo8_voltage_map_desc = {
58 .min = 3000, .step = 100, .max = 3600,
59};
60static const struct voltage_map_desc ldo9_voltage_map_desc = {
61 .min = 2800, .step = 100, .max = 3100,
62};
63static const struct voltage_map_desc ldo10_voltage_map_desc = {
64 .min = 950, .step = 50, .max = 1300,
65};
66static const struct voltage_map_desc ldo1213_voltage_map_desc = {
67 .min = 800, .step = 100, .max = 3300,
68};
69static const struct voltage_map_desc ldo1415_voltage_map_desc = {
70 .min = 1200, .step = 100, .max = 3300,
71};
72static const struct voltage_map_desc ldo1617_voltage_map_desc = {
73 .min = 1600, .step = 100, .max = 3600,
74};
75static const struct voltage_map_desc buck12_voltage_map_desc = {
76 .min = 750, .step = 25, .max = 1525,
77};
78static const struct voltage_map_desc buck3_voltage_map_desc = {
79 .min = 1600, .step = 100, .max = 3600,
80};
81static const struct voltage_map_desc buck4_voltage_map_desc = {
82 .min = 800, .step = 100, .max = 2300,
83};
84
85static const struct voltage_map_desc *ldo_voltage_map[] = {
86 NULL,
87 NULL,
88 &ldo23_voltage_map_desc, /* LDO2 */
89 &ldo23_voltage_map_desc, /* LDO3 */
90 &ldo456711_voltage_map_desc, /* LDO4 */
91 &ldo456711_voltage_map_desc, /* LDO5 */
92 &ldo456711_voltage_map_desc, /* LDO6 */
93 &ldo456711_voltage_map_desc, /* LDO7 */
94 &ldo8_voltage_map_desc, /* LDO8 */
95 &ldo9_voltage_map_desc, /* LDO9 */
96 &ldo10_voltage_map_desc, /* LDO10 */
97 &ldo456711_voltage_map_desc, /* LDO11 */
98 &ldo1213_voltage_map_desc, /* LDO12 */
99 &ldo1213_voltage_map_desc, /* LDO13 */
100 &ldo1415_voltage_map_desc, /* LDO14 */
101 &ldo1415_voltage_map_desc, /* LDO15 */
102 &ldo1617_voltage_map_desc, /* LDO16 */
103 &ldo1617_voltage_map_desc, /* LDO17 */
104 &buck12_voltage_map_desc, /* BUCK1 */
105 &buck12_voltage_map_desc, /* BUCK2 */
106 &buck3_voltage_map_desc, /* BUCK3 */
107 &buck4_voltage_map_desc, /* BUCK4 */
108};
109
110static inline int max8998_get_ldo(struct regulator_dev *rdev)
111{
112 return rdev_get_id(rdev);
113}
114
115static int max8998_list_voltage(struct regulator_dev *rdev,
116 unsigned int selector)
117{
118 const struct voltage_map_desc *desc;
119 int ldo = max8998_get_ldo(rdev);
120 int val;
121
122 if (ldo >= ARRAY_SIZE(ldo_voltage_map))
123 return -EINVAL;
124
125 desc = ldo_voltage_map[ldo];
126 if (desc == NULL)
127 return -EINVAL;
128
129 val = desc->min + desc->step * selector;
130 if (val > desc->max)
131 return -EINVAL;
132
133 return val * 1000;
134}
135
136static int max8998_get_enable_register(struct regulator_dev *rdev,
137 int *reg, int *shift)
138{
139 int ldo = max8998_get_ldo(rdev);
140
141 switch (ldo) {
142 case MAX8998_LDO2 ... MAX8998_LDO5:
143 *reg = MAX8998_REG_ONOFF1;
144 *shift = 3 - (ldo - MAX8998_LDO2);
145 break;
146 case MAX8998_LDO6 ... MAX8998_LDO13:
147 *reg = MAX8998_REG_ONOFF2;
148 *shift = 7 - (ldo - MAX8998_LDO6);
149 break;
150 case MAX8998_LDO14 ... MAX8998_LDO17:
151 *reg = MAX8998_REG_ONOFF3;
152 *shift = 7 - (ldo - MAX8998_LDO14);
153 break;
154 case MAX8998_BUCK1 ... MAX8998_BUCK4:
155 *reg = MAX8998_REG_ONOFF1;
156 *shift = 7 - (ldo - MAX8998_BUCK1);
157 break;
158 case MAX8998_EN32KHZ_AP ... MAX8998_ENVICHG:
159 *reg = MAX8998_REG_ONOFF4;
160 *shift = 7 - (ldo - MAX8998_EN32KHZ_AP);
161 break;
162 case MAX8998_ESAFEOUT1 ... MAX8998_ESAFEOUT2:
163 *reg = MAX8998_REG_CHGR2;
164 *shift = 7 - (ldo - MAX8998_ESAFEOUT1);
165 break;
166 default:
167 return -EINVAL;
168 }
169
170 return 0;
171}
172
173static int max8998_ldo_is_enabled(struct regulator_dev *rdev)
174{
175 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
176 int ret, reg, shift = 8;
177 u8 val;
178
179 ret = max8998_get_enable_register(rdev, &reg, &shift);
180 if (ret)
181 return ret;
182
183 ret = max8998_read_reg(max8998->iodev, reg, &val);
184 if (ret)
185 return ret;
186
187 return val & (1 << shift);
188}
189
190static int max8998_ldo_enable(struct regulator_dev *rdev)
191{
192 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
193 int reg, shift = 8, ret;
194
195 ret = max8998_get_enable_register(rdev, &reg, &shift);
196 if (ret)
197 return ret;
198
199 return max8998_update_reg(max8998->iodev, reg, 1<<shift, 1<<shift);
200}
201
202static int max8998_ldo_disable(struct regulator_dev *rdev)
203{
204 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
205 int reg, shift = 8, ret;
206
207 ret = max8998_get_enable_register(rdev, &reg, &shift);
208 if (ret)
209 return ret;
210
211 return max8998_update_reg(max8998->iodev, reg, 0, 1<<shift);
212}
213
214static int max8998_get_voltage_register(struct regulator_dev *rdev,
215 int *_reg, int *_shift, int *_mask)
216{
217 int ldo = max8998_get_ldo(rdev);
218 int reg, shift = 0, mask = 0xff;
219
220 switch (ldo) {
221 case MAX8998_LDO2 ... MAX8998_LDO3:
222 reg = MAX8998_REG_LDO2_LDO3;
223 mask = 0xf;
224 if (ldo == MAX8998_LDO2)
225 shift = 4;
226 else
227 shift = 0;
228 break;
229 case MAX8998_LDO4 ... MAX8998_LDO7:
230 reg = MAX8998_REG_LDO4 + (ldo - MAX8998_LDO4);
231 break;
232 case MAX8998_LDO8 ... MAX8998_LDO9:
233 reg = MAX8998_REG_LDO8_LDO9;
234 mask = 0xf;
235 if (ldo == MAX8998_LDO8)
236 shift = 4;
237 else
238 shift = 0;
239 break;
240 case MAX8998_LDO10 ... MAX8998_LDO11:
241 reg = MAX8998_REG_LDO10_LDO11;
242 if (ldo == MAX8998_LDO10) {
243 shift = 5;
244 mask = 0x7;
245 } else {
246 shift = 0;
247 mask = 0x1f;
248 }
249 break;
250 case MAX8998_LDO12 ... MAX8998_LDO17:
251 reg = MAX8998_REG_LDO12 + (ldo - MAX8998_LDO12);
252 break;
253 case MAX8998_BUCK1:
254 reg = MAX8998_REG_BUCK1_DVSARM1;
255 break;
256 case MAX8998_BUCK2:
257 reg = MAX8998_REG_BUCK2_DVSINT1;
258 break;
259 case MAX8998_BUCK3:
260 reg = MAX8998_REG_BUCK3;
261 break;
262 case MAX8998_BUCK4:
263 reg = MAX8998_REG_BUCK4;
264 break;
265 default:
266 return -EINVAL;
267 }
268
269 *_reg = reg;
270 *_shift = shift;
271 *_mask = mask;
272
273 return 0;
274}
275
276static int max8998_get_voltage(struct regulator_dev *rdev)
277{
278 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
279 int reg, shift = 0, mask, ret;
280 u8 val;
281
282 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
283 if (ret)
284 return ret;
285
286 ret = max8998_read_reg(max8998->iodev, reg, &val);
287 if (ret)
288 return ret;
289
290 val >>= shift;
291 val &= mask;
292
293 return max8998_list_voltage(rdev, val);
294}
295
296static int max8998_set_voltage(struct regulator_dev *rdev,
297 int min_uV, int max_uV)
298{
299 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
300 int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
301 int previous_vol = 0;
302 const struct voltage_map_desc *desc;
303 int ldo = max8998_get_ldo(rdev);
304 int reg, shift = 0, mask, ret;
305 int i = 0;
306 u8 val;
307 bool en_ramp = false;
308
309 if (ldo >= ARRAY_SIZE(ldo_voltage_map))
310 return -EINVAL;
311
312 desc = ldo_voltage_map[ldo];
313 if (desc == NULL)
314 return -EINVAL;
315
316 if (max_vol < desc->min || min_vol > desc->max)
317 return -EINVAL;
318
319 while (desc->min + desc->step*i < min_vol &&
320 desc->min + desc->step*i < desc->max)
321 i++;
322
323 if (desc->min + desc->step*i > max_vol)
324 return -EINVAL;
325
326 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
327 if (ret)
328 return ret;
329
330 /* wait for RAMP_UP_DELAY if rdev is BUCK1/2 and
331 * ENRAMP is ON */
332 if (ldo == MAX8998_BUCK1 || ldo == MAX8998_BUCK2) {
333 max8998_read_reg(max8998->iodev, MAX8998_REG_ONOFF4, &val);
334 if (val & (1 << 4)) {
335 en_ramp = true;
336 previous_vol = max8998_get_voltage(rdev);
337 }
338 }
339
340 ret = max8998_update_reg(max8998->iodev, reg, i<<shift, mask<<shift);
341
342 if (en_ramp == true) {
343 int difference = desc->min + desc->step*i - previous_vol/1000;
344 if (difference > 0)
345 udelay(difference / ((val & 0x0f) + 1));
346 }
347
348 return ret;
349}
350
351static struct regulator_ops max8998_ldo_ops = {
352 .list_voltage = max8998_list_voltage,
353 .is_enabled = max8998_ldo_is_enabled,
354 .enable = max8998_ldo_enable,
355 .disable = max8998_ldo_disable,
356 .get_voltage = max8998_get_voltage,
357 .set_voltage = max8998_set_voltage,
358 .set_suspend_enable = max8998_ldo_enable,
359 .set_suspend_disable = max8998_ldo_disable,
360};
361
362static struct regulator_ops max8998_buck_ops = {
363 .list_voltage = max8998_list_voltage,
364 .is_enabled = max8998_ldo_is_enabled,
365 .enable = max8998_ldo_enable,
366 .disable = max8998_ldo_disable,
367 .get_voltage = max8998_get_voltage,
368 .set_voltage = max8998_set_voltage,
369 .set_suspend_enable = max8998_ldo_enable,
370 .set_suspend_disable = max8998_ldo_disable,
371};
372
373static struct regulator_ops max8998_others_ops = {
374 .is_enabled = max8998_ldo_is_enabled,
375 .enable = max8998_ldo_enable,
376 .disable = max8998_ldo_disable,
377 .set_suspend_enable = max8998_ldo_enable,
378 .set_suspend_disable = max8998_ldo_disable,
379};
380
381static struct regulator_desc regulators[] = {
382 {
383 .name = "LDO2",
384 .id = MAX8998_LDO2,
385 .ops = &max8998_ldo_ops,
386 .type = REGULATOR_VOLTAGE,
387 .owner = THIS_MODULE,
388 }, {
389 .name = "LDO3",
390 .id = MAX8998_LDO3,
391 .ops = &max8998_ldo_ops,
392 .type = REGULATOR_VOLTAGE,
393 .owner = THIS_MODULE,
394 }, {
395 .name = "LDO4",
396 .id = MAX8998_LDO4,
397 .ops = &max8998_ldo_ops,
398 .type = REGULATOR_VOLTAGE,
399 .owner = THIS_MODULE,
400 }, {
401 .name = "LDO5",
402 .id = MAX8998_LDO5,
403 .ops = &max8998_ldo_ops,
404 .type = REGULATOR_VOLTAGE,
405 .owner = THIS_MODULE,
406 }, {
407 .name = "LDO6",
408 .id = MAX8998_LDO6,
409 .ops = &max8998_ldo_ops,
410 .type = REGULATOR_VOLTAGE,
411 .owner = THIS_MODULE,
412 }, {
413 .name = "LDO7",
414 .id = MAX8998_LDO7,
415 .ops = &max8998_ldo_ops,
416 .type = REGULATOR_VOLTAGE,
417 .owner = THIS_MODULE,
418 }, {
419 .name = "LDO8",
420 .id = MAX8998_LDO8,
421 .ops = &max8998_ldo_ops,
422 .type = REGULATOR_VOLTAGE,
423 .owner = THIS_MODULE,
424 }, {
425 .name = "LDO9",
426 .id = MAX8998_LDO9,
427 .ops = &max8998_ldo_ops,
428 .type = REGULATOR_VOLTAGE,
429 .owner = THIS_MODULE,
430 }, {
431 .name = "LDO10",
432 .id = MAX8998_LDO10,
433 .ops = &max8998_ldo_ops,
434 .type = REGULATOR_VOLTAGE,
435 .owner = THIS_MODULE,
436 }, {
437 .name = "LDO11",
438 .id = MAX8998_LDO11,
439 .ops = &max8998_ldo_ops,
440 .type = REGULATOR_VOLTAGE,
441 .owner = THIS_MODULE,
442 }, {
443 .name = "LDO12",
444 .id = MAX8998_LDO12,
445 .ops = &max8998_ldo_ops,
446 .type = REGULATOR_VOLTAGE,
447 .owner = THIS_MODULE,
448 }, {
449 .name = "LDO13",
450 .id = MAX8998_LDO13,
451 .ops = &max8998_ldo_ops,
452 .type = REGULATOR_VOLTAGE,
453 .owner = THIS_MODULE,
454 }, {
455 .name = "LDO14",
456 .id = MAX8998_LDO14,
457 .ops = &max8998_ldo_ops,
458 .type = REGULATOR_VOLTAGE,
459 .owner = THIS_MODULE,
460 }, {
461 .name = "LDO15",
462 .id = MAX8998_LDO15,
463 .ops = &max8998_ldo_ops,
464 .type = REGULATOR_VOLTAGE,
465 .owner = THIS_MODULE,
466 }, {
467 .name = "LDO16",
468 .id = MAX8998_LDO16,
469 .ops = &max8998_ldo_ops,
470 .type = REGULATOR_VOLTAGE,
471 .owner = THIS_MODULE,
472 }, {
473 .name = "LDO17",
474 .id = MAX8998_LDO17,
475 .ops = &max8998_ldo_ops,
476 .type = REGULATOR_VOLTAGE,
477 .owner = THIS_MODULE,
478 }, {
479 .name = "BUCK1",
480 .id = MAX8998_BUCK1,
481 .ops = &max8998_buck_ops,
482 .type = REGULATOR_VOLTAGE,
483 .owner = THIS_MODULE,
484 }, {
485 .name = "BUCK2",
486 .id = MAX8998_BUCK2,
487 .ops = &max8998_buck_ops,
488 .type = REGULATOR_VOLTAGE,
489 .owner = THIS_MODULE,
490 }, {
491 .name = "BUCK3",
492 .id = MAX8998_BUCK3,
493 .ops = &max8998_buck_ops,
494 .type = REGULATOR_VOLTAGE,
495 .owner = THIS_MODULE,
496 }, {
497 .name = "BUCK4",
498 .id = MAX8998_BUCK4,
499 .ops = &max8998_buck_ops,
500 .type = REGULATOR_VOLTAGE,
501 .owner = THIS_MODULE,
502 }, {
503 .name = "EN32KHz AP",
504 .id = MAX8998_EN32KHZ_AP,
505 .ops = &max8998_others_ops,
506 .type = REGULATOR_VOLTAGE,
507 .owner = THIS_MODULE,
508 }, {
509 .name = "EN32KHz CP",
510 .id = MAX8998_EN32KHZ_CP,
511 .ops = &max8998_others_ops,
512 .type = REGULATOR_VOLTAGE,
513 .owner = THIS_MODULE,
514 }, {
515 .name = "ENVICHG",
516 .id = MAX8998_ENVICHG,
517 .ops = &max8998_others_ops,
518 .type = REGULATOR_VOLTAGE,
519 .owner = THIS_MODULE,
520 }, {
521 .name = "ESAFEOUT1",
522 .id = MAX8998_ESAFEOUT1,
523 .ops = &max8998_others_ops,
524 .type = REGULATOR_VOLTAGE,
525 .owner = THIS_MODULE,
526 }, {
527 .name = "ESAFEOUT2",
528 .id = MAX8998_ESAFEOUT2,
529 .ops = &max8998_others_ops,
530 .type = REGULATOR_VOLTAGE,
531 .owner = THIS_MODULE,
532 }
533};
534
535static __devinit int max8998_pmic_probe(struct platform_device *pdev)
536{
537 struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent);
538 struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev);
539 struct regulator_dev **rdev;
540 struct max8998_data *max8998;
541 int i, ret, size;
542
543 if (!pdata) {
544 dev_err(pdev->dev.parent, "No platform init data supplied\n");
545 return -ENODEV;
546 }
547
548 max8998 = kzalloc(sizeof(struct max8998_data), GFP_KERNEL);
549 if (!max8998)
550 return -ENOMEM;
551
552 size = sizeof(struct regulator_dev *) * (pdata->num_regulators + 1);
553 max8998->rdev = kzalloc(size, GFP_KERNEL);
554 if (!max8998->rdev) {
555 kfree(max8998);
556 return -ENOMEM;
557 }
558
559 rdev = max8998->rdev;
560 max8998->iodev = iodev;
561 platform_set_drvdata(pdev, max8998);
562
563 for (i = 0; i < pdata->num_regulators; i++) {
564 const struct voltage_map_desc *desc;
565 int id = pdata->regulators[i].id;
566 int index = id - MAX8998_LDO2;
567
568 desc = ldo_voltage_map[id];
569 if (desc && regulators[index].ops != &max8998_others_ops) {
570 int count = (desc->max - desc->min) / desc->step + 1;
571 regulators[index].n_voltages = count;
572 }
573 rdev[i] = regulator_register(&regulators[index], max8998->dev,
574 pdata->regulators[i].initdata, max8998);
575 if (IS_ERR(rdev[i])) {
576 ret = PTR_ERR(rdev[i]);
577 dev_err(max8998->dev, "regulator init failed\n");
578 rdev[i] = NULL;
579 goto err;
580 }
581 }
582
583
584 return 0;
585err:
586 for (i = 0; i <= max8998->num_regulators; i++)
587 if (rdev[i])
588 regulator_unregister(rdev[i]);
589
590 kfree(max8998->rdev);
591 kfree(max8998);
592
593 return ret;
594}
595
596static int __devexit max8998_pmic_remove(struct platform_device *pdev)
597{
598 struct max8998_data *max8998 = platform_get_drvdata(pdev);
599 struct regulator_dev **rdev = max8998->rdev;
600 int i;
601
602 for (i = 0; i <= max8998->num_regulators; i++)
603 if (rdev[i])
604 regulator_unregister(rdev[i]);
605
606 kfree(max8998->rdev);
607 kfree(max8998);
608
609 return 0;
610}
611
612static struct platform_driver max8998_pmic_driver = {
613 .driver = {
614 .name = "max8998-pmic",
615 .owner = THIS_MODULE,
616 },
617 .probe = max8998_pmic_probe,
618 .remove = __devexit_p(max8998_pmic_remove),
619};
620
621static int __init max8998_pmic_init(void)
622{
623 return platform_driver_register(&max8998_pmic_driver);
624}
625subsys_initcall(max8998_pmic_init);
626
627static void __exit max8998_pmic_cleanup(void)
628{
629 platform_driver_unregister(&max8998_pmic_driver);
630}
631module_exit(max8998_pmic_cleanup);
632
633MODULE_DESCRIPTION("MAXIM 8998 voltage regulator driver");
634MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
635MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c
index f50afc9f287a..cd6d4fc9d74f 100644
--- a/drivers/regulator/tps65023-regulator.c
+++ b/drivers/regulator/tps65023-regulator.c
@@ -585,6 +585,8 @@ static const struct tps_info tps65023_regs[] = {
585static const struct i2c_device_id tps_65023_id[] = { 585static const struct i2c_device_id tps_65023_id[] = {
586 {.name = "tps65023", 586 {.name = "tps65023",
587 .driver_data = (unsigned long) tps65023_regs,}, 587 .driver_data = (unsigned long) tps65023_regs,},
588 {.name = "tps65021",
589 .driver_data = (unsigned long) tps65023_regs,},
588 { }, 590 { },
589}; 591};
590 592
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c
index 8152d65220f5..c239f42aa4a3 100644
--- a/drivers/regulator/tps6507x-regulator.c
+++ b/drivers/regulator/tps6507x-regulator.c
@@ -614,6 +614,7 @@ int tps6507x_pmic_probe(struct platform_device *pdev)
614 } 614 }
615 615
616 tps6507x_dev->pmic = tps; 616 tps6507x_dev->pmic = tps;
617 platform_set_drvdata(pdev, tps6507x_dev);
617 618
618 return 0; 619 return 0;
619 620
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c
new file mode 100644
index 000000000000..8cff1413a147
--- /dev/null
+++ b/drivers/regulator/tps6586x-regulator.c
@@ -0,0 +1,396 @@
1/*
2 * Regulator driver for TI TPS6586x
3 *
4 * Copyright (C) 2010 Compulab Ltd.
5 * Author: Mike Rapoport <mike@compulab.co.il>
6 *
7 * Based on da903x
8 * Copyright (C) 2006-2008 Marvell International Ltd.
9 * Copyright (C) 2008 Compulab Ltd.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/err.h>
19#include <linux/slab.h>
20#include <linux/platform_device.h>
21#include <linux/regulator/driver.h>
22#include <linux/regulator/machine.h>
23#include <linux/mfd/tps6586x.h>
24
25/* supply control and voltage setting */
26#define TPS6586X_SUPPLYENA 0x10
27#define TPS6586X_SUPPLYENB 0x11
28#define TPS6586X_SUPPLYENC 0x12
29#define TPS6586X_SUPPLYEND 0x13
30#define TPS6586X_SUPPLYENE 0x14
31#define TPS6586X_VCC1 0x20
32#define TPS6586X_VCC2 0x21
33#define TPS6586X_SM1V1 0x23
34#define TPS6586X_SM1V2 0x24
35#define TPS6586X_SM1SL 0x25
36#define TPS6586X_SM0V1 0x26
37#define TPS6586X_SM0V2 0x27
38#define TPS6586X_SM0SL 0x28
39#define TPS6586X_LDO2AV1 0x29
40#define TPS6586X_LDO2AV2 0x2A
41#define TPS6586X_LDO2BV1 0x2F
42#define TPS6586X_LDO2BV2 0x30
43#define TPS6586X_LDO4V1 0x32
44#define TPS6586X_LDO4V2 0x33
45
46/* converter settings */
47#define TPS6586X_SUPPLYV1 0x41
48#define TPS6586X_SUPPLYV2 0x42
49#define TPS6586X_SUPPLYV3 0x43
50#define TPS6586X_SUPPLYV4 0x44
51#define TPS6586X_SUPPLYV5 0x45
52#define TPS6586X_SUPPLYV6 0x46
53#define TPS6586X_SMODE1 0x47
54#define TPS6586X_SMODE2 0x48
55
56struct tps6586x_regulator {
57 struct regulator_desc desc;
58
59 int volt_reg;
60 int volt_shift;
61 int volt_nbits;
62 int enable_bit[2];
63 int enable_reg[2];
64
65 int *voltages;
66
67 /* for DVM regulators */
68 int go_reg;
69 int go_bit;
70};
71
72static inline struct device *to_tps6586x_dev(struct regulator_dev *rdev)
73{
74 return rdev_get_dev(rdev)->parent->parent;
75}
76
77static int tps6586x_ldo_list_voltage(struct regulator_dev *rdev,
78 unsigned selector)
79{
80 struct tps6586x_regulator *info = rdev_get_drvdata(rdev);
81
82 return info->voltages[selector] * 1000;
83}
84
85
86static int __tps6586x_ldo_set_voltage(struct device *parent,
87 struct tps6586x_regulator *ri,
88 int min_uV, int max_uV)
89{
90 int val, uV;
91 uint8_t mask;
92
93 for (val = 0; val < ri->desc.n_voltages; val++) {
94 uV = ri->voltages[val] * 1000;
95
96 /* LDO0 has minimal voltage 1.2 rather than 1.25 */
97 if (ri->desc.id == TPS6586X_ID_LDO_0 && val == 0)
98 uV -= 50 * 1000;
99
100 /* use the first in-range value */
101 if (min_uV <= uV && uV <= max_uV) {
102
103 val <<= ri->volt_shift;
104 mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift;
105
106 return tps6586x_update(parent, ri->volt_reg, val, mask);
107 }
108 }
109
110 return -EINVAL;
111}
112
113static int tps6586x_ldo_set_voltage(struct regulator_dev *rdev,
114 int min_uV, int max_uV)
115{
116 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
117 struct device *parent = to_tps6586x_dev(rdev);
118
119 return __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV);
120}
121
122static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev)
123{
124 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
125 struct device *parent = to_tps6586x_dev(rdev);
126 uint8_t val, mask;
127 int ret;
128
129 ret = tps6586x_read(parent, ri->volt_reg, &val);
130 if (ret)
131 return ret;
132
133 mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift;
134 val = (val & mask) >> ri->volt_shift;
135
136 if (val > ri->desc.n_voltages)
137 BUG();
138
139 return ri->voltages[val] * 1000;
140}
141
142static int tps6586x_dvm_set_voltage(struct regulator_dev *rdev,
143 int min_uV, int max_uV)
144{
145 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
146 struct device *parent = to_tps6586x_dev(rdev);
147 int ret;
148
149 ret = __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV);
150 if (ret)
151 return ret;
152
153 return tps6586x_set_bits(parent, ri->go_reg, ri->go_bit);
154}
155
156static int tps6586x_regulator_enable(struct regulator_dev *rdev)
157{
158 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
159 struct device *parent = to_tps6586x_dev(rdev);
160
161 return tps6586x_set_bits(parent, ri->enable_reg[0],
162 1 << ri->enable_bit[0]);
163}
164
165static int tps6586x_regulator_disable(struct regulator_dev *rdev)
166{
167 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
168 struct device *parent = to_tps6586x_dev(rdev);
169
170 return tps6586x_clr_bits(parent, ri->enable_reg[0],
171 1 << ri->enable_bit[0]);
172}
173
174static int tps6586x_regulator_is_enabled(struct regulator_dev *rdev)
175{
176 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
177 struct device *parent = to_tps6586x_dev(rdev);
178 uint8_t reg_val;
179 int ret;
180
181 ret = tps6586x_read(parent, ri->enable_reg[0], &reg_val);
182 if (ret)
183 return ret;
184
185 return !!(reg_val & (1 << ri->enable_bit[0]));
186}
187
188static struct regulator_ops tps6586x_regulator_ldo_ops = {
189 .list_voltage = tps6586x_ldo_list_voltage,
190 .get_voltage = tps6586x_ldo_get_voltage,
191 .set_voltage = tps6586x_ldo_set_voltage,
192
193 .is_enabled = tps6586x_regulator_is_enabled,
194 .enable = tps6586x_regulator_enable,
195 .disable = tps6586x_regulator_disable,
196};
197
198static struct regulator_ops tps6586x_regulator_dvm_ops = {
199 .list_voltage = tps6586x_ldo_list_voltage,
200 .get_voltage = tps6586x_ldo_get_voltage,
201 .set_voltage = tps6586x_dvm_set_voltage,
202
203 .is_enabled = tps6586x_regulator_is_enabled,
204 .enable = tps6586x_regulator_enable,
205 .disable = tps6586x_regulator_disable,
206};
207
208static int tps6586x_ldo_voltages[] = {
209 1250, 1500, 1800, 2500, 2700, 2850, 3100, 3300,
210};
211
212static int tps6586x_ldo4_voltages[] = {
213 1700, 1725, 1750, 1775, 1800, 1825, 1850, 1875,
214 1900, 1925, 1950, 1975, 2000, 2025, 2050, 2075,
215 2100, 2125, 2150, 2175, 2200, 2225, 2250, 2275,
216 2300, 2325, 2350, 2375, 2400, 2425, 2450, 2475,
217};
218
219static int tps6586x_sm2_voltages[] = {
220 3000, 3050, 3100, 3150, 3200, 3250, 3300, 3350,
221 3400, 3450, 3500, 3550, 3600, 3650, 3700, 3750,
222 3800, 3850, 3900, 3950, 4000, 4050, 4100, 4150,
223 4200, 4250, 4300, 4350, 4400, 4450, 4500, 4550,
224};
225
226static int tps6586x_dvm_voltages[] = {
227 725, 750, 775, 800, 825, 850, 875, 900,
228 925, 950, 975, 1000, 1025, 1050, 1075, 1100,
229 1125, 1150, 1175, 1200, 1225, 1250, 1275, 1300,
230 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500,
231};
232
233#define TPS6586X_REGULATOR(_id, vdata, _ops, vreg, shift, nbits, \
234 ereg0, ebit0, ereg1, ebit1, goreg, gobit) \
235{ \
236 .desc = { \
237 .name = "REG-" #_id, \
238 .ops = &tps6586x_regulator_##_ops, \
239 .type = REGULATOR_VOLTAGE, \
240 .id = TPS6586X_ID_##_id, \
241 .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \
242 .owner = THIS_MODULE, \
243 }, \
244 .volt_reg = TPS6586X_##vreg, \
245 .volt_shift = (shift), \
246 .volt_nbits = (nbits), \
247 .enable_reg[0] = TPS6586X_SUPPLY##ereg0, \
248 .enable_bit[0] = (ebit0), \
249 .enable_reg[1] = TPS6586X_SUPPLY##ereg1, \
250 .enable_bit[1] = (ebit1), \
251 .voltages = tps6586x_##vdata##_voltages, \
252}
253
254#define TPS6586X_LDO(_id, vdata, vreg, shift, nbits, \
255 ereg0, ebit0, ereg1, ebit1) \
256 TPS6586X_REGULATOR(_id, vdata, ldo_ops, vreg, shift, nbits, \
257 ereg0, ebit0, ereg1, ebit1, 0, 0)
258
259#define TPS6586X_DVM(_id, vdata, vreg, shift, nbits, \
260 ereg0, ebit0, ereg1, ebit1, goreg, gobit) \
261 TPS6586X_REGULATOR(_id, vdata, dvm_ops, vreg, shift, nbits, \
262 ereg0, ebit0, ereg1, ebit1, goreg, gobit)
263
264static struct tps6586x_regulator tps6586x_regulator[] = {
265 TPS6586X_LDO(LDO_0, ldo, SUPPLYV1, 5, 3, ENC, 0, END, 0),
266 TPS6586X_LDO(LDO_3, ldo, SUPPLYV4, 0, 3, ENC, 2, END, 2),
267 TPS6586X_LDO(LDO_5, ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6),
268 TPS6586X_LDO(LDO_6, ldo, SUPPLYV3, 0, 3, ENC, 4, END, 4),
269 TPS6586X_LDO(LDO_7, ldo, SUPPLYV3, 3, 3, ENC, 5, END, 5),
270 TPS6586X_LDO(LDO_8, ldo, SUPPLYV1, 5, 3, ENC, 6, END, 6),
271 TPS6586X_LDO(LDO_9, ldo, SUPPLYV6, 3, 3, ENE, 7, ENE, 7),
272 TPS6586X_LDO(LDO_RTC, ldo, SUPPLYV4, 3, 3, ENE, 7, ENE, 7),
273 TPS6586X_LDO(LDO_1, dvm, SUPPLYV1, 0, 5, ENC, 1, END, 1),
274 TPS6586X_LDO(SM_2, sm2, SUPPLYV2, 0, 5, ENC, 1, END, 1),
275
276 TPS6586X_DVM(LDO_2, dvm, LDO2BV1, 0, 5, ENA, 3, ENB, 3, VCC2, 6),
277 TPS6586X_DVM(LDO_4, ldo4, LDO4V1, 0, 5, ENC, 3, END, 3, VCC1, 6),
278 TPS6586X_DVM(SM_0, dvm, SM0V1, 0, 5, ENA, 1, ENB, 1, VCC1, 2),
279 TPS6586X_DVM(SM_1, dvm, SM1V1, 0, 5, ENA, 0, ENB, 0, VCC1, 0),
280};
281
282/*
283 * TPS6586X has 2 enable bits that are OR'ed to determine the actual
284 * regulator state. Clearing one of this bits allows switching
285 * regulator on and of with single register write.
286 */
287static inline int tps6586x_regulator_preinit(struct device *parent,
288 struct tps6586x_regulator *ri)
289{
290 uint8_t val1, val2;
291 int ret;
292
293 ret = tps6586x_read(parent, ri->enable_reg[0], &val1);
294 if (ret)
295 return ret;
296
297 ret = tps6586x_read(parent, ri->enable_reg[1], &val2);
298 if (ret)
299 return ret;
300
301 if (!(val2 & ri->enable_bit[1]))
302 return 0;
303
304 /*
305 * The regulator is on, but it's enabled with the bit we don't
306 * want to use, so we switch the enable bits
307 */
308 if (!(val1 & ri->enable_bit[0])) {
309 ret = tps6586x_set_bits(parent, ri->enable_reg[0],
310 1 << ri->enable_bit[0]);
311 if (ret)
312 return ret;
313 }
314
315 return tps6586x_clr_bits(parent, ri->enable_reg[1],
316 1 << ri->enable_bit[1]);
317}
318
319static inline struct tps6586x_regulator *find_regulator_info(int id)
320{
321 struct tps6586x_regulator *ri;
322 int i;
323
324 for (i = 0; i < ARRAY_SIZE(tps6586x_regulator); i++) {
325 ri = &tps6586x_regulator[i];
326 if (ri->desc.id == id)
327 return ri;
328 }
329 return NULL;
330}
331
332static int __devinit tps6586x_regulator_probe(struct platform_device *pdev)
333{
334 struct tps6586x_regulator *ri = NULL;
335 struct regulator_dev *rdev;
336 int id = pdev->id;
337 int err;
338
339 dev_dbg(&pdev->dev, "Probing reulator %d\n", id);
340
341 ri = find_regulator_info(id);
342 if (ri == NULL) {
343 dev_err(&pdev->dev, "invalid regulator ID specified\n");
344 return -EINVAL;
345 }
346
347 err = tps6586x_regulator_preinit(pdev->dev.parent, ri);
348 if (err)
349 return err;
350
351 rdev = regulator_register(&ri->desc, &pdev->dev,
352 pdev->dev.platform_data, ri);
353 if (IS_ERR(rdev)) {
354 dev_err(&pdev->dev, "failed to register regulator %s\n",
355 ri->desc.name);
356 return PTR_ERR(rdev);
357 }
358
359 platform_set_drvdata(pdev, rdev);
360
361 return 0;
362}
363
364static int __devexit tps6586x_regulator_remove(struct platform_device *pdev)
365{
366 struct regulator_dev *rdev = platform_get_drvdata(pdev);
367
368 regulator_unregister(rdev);
369 return 0;
370}
371
372static struct platform_driver tps6586x_regulator_driver = {
373 .driver = {
374 .name = "tps6586x-regulator",
375 .owner = THIS_MODULE,
376 },
377 .probe = tps6586x_regulator_probe,
378 .remove = __devexit_p(tps6586x_regulator_remove),
379};
380
381static int __init tps6586x_regulator_init(void)
382{
383 return platform_driver_register(&tps6586x_regulator_driver);
384}
385subsys_initcall(tps6586x_regulator_init);
386
387static void __exit tps6586x_regulator_exit(void)
388{
389 platform_driver_unregister(&tps6586x_regulator_driver);
390}
391module_exit(tps6586x_regulator_exit);
392
393MODULE_LICENSE("GPL");
394MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
395MODULE_DESCRIPTION("Regulator Driver for TI TPS6586X PMIC");
396MODULE_ALIAS("platform:tps6586x-regulator");
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c
index 5a1dc8a24d35..03713bc66e4a 100644
--- a/drivers/regulator/wm8994-regulator.c
+++ b/drivers/regulator/wm8994-regulator.c
@@ -219,8 +219,6 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev)
219 219
220 ldo->wm8994 = wm8994; 220 ldo->wm8994 = wm8994;
221 221
222 ldo->is_enabled = true;
223
224 if (pdata->ldo[id].enable && gpio_is_valid(pdata->ldo[id].enable)) { 222 if (pdata->ldo[id].enable && gpio_is_valid(pdata->ldo[id].enable)) {
225 ldo->enable = pdata->ldo[id].enable; 223 ldo->enable = pdata->ldo[id].enable;
226 224
@@ -237,7 +235,8 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev)
237 ret); 235 ret);
238 goto err_gpio; 236 goto err_gpio;
239 } 237 }
240 } 238 } else
239 ldo->is_enabled = true;
241 240
242 ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &pdev->dev, 241 ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &pdev->dev,
243 pdata->ldo[id].init_data, ldo); 242 pdata->ldo[id].init_data, ldo);
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 4301a6c7ed3b..48ca7132cc05 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -166,6 +166,16 @@ config RTC_DRV_DS1672
166 This driver can also be built as a module. If so, the module 166 This driver can also be built as a module. If so, the module
167 will be called rtc-ds1672. 167 will be called rtc-ds1672.
168 168
169config RTC_DRV_DS3232
170 tristate "Dallas/Maxim DS3232"
171 depends on RTC_CLASS && I2C
172 help
173 If you say yes here you get support for Dallas Semiconductor
174 DS3232 real-time clock chips.
175
176 This driver can also be built as a module. If so, the module
177 will be called rtc-ds3232.
178
169config RTC_DRV_MAX6900 179config RTC_DRV_MAX6900
170 tristate "Maxim MAX6900" 180 tristate "Maxim MAX6900"
171 help 181 help
@@ -203,6 +213,15 @@ config RTC_DRV_ISL1208
203 This driver can also be built as a module. If so, the module 213 This driver can also be built as a module. If so, the module
204 will be called rtc-isl1208. 214 will be called rtc-isl1208.
205 215
216config RTC_DRV_ISL12022
217 tristate "Intersil ISL12022"
218 help
219 If you say yes here you get support for the
220 Intersil ISL12022 RTC chip.
221
222 This driver can also be built as a module. If so, the module
223 will be called rtc-isl12022.
224
206config RTC_DRV_X1205 225config RTC_DRV_X1205
207 tristate "Xicor/Intersil X1205" 226 tristate "Xicor/Intersil X1205"
208 help 227 help
@@ -537,6 +556,16 @@ config RTC_DRV_MSM6242
537 This driver can also be built as a module. If so, the module 556 This driver can also be built as a module. If so, the module
538 will be called rtc-msm6242. 557 will be called rtc-msm6242.
539 558
559config RTC_DRV_IMXDI
560 tristate "Freescale IMX DryIce Real Time Clock"
561 depends on ARCH_MX25
562 depends on RTC_CLASS
563 help
564 Support for Freescale IMX DryIce RTC
565
566 This driver can also be built as a module, if so, the module
567 will be called "rtc-imxdi".
568
540config RTC_MXC 569config RTC_MXC
541 tristate "Freescale MXC Real Time Clock" 570 tristate "Freescale MXC Real Time Clock"
542 depends on ARCH_MXC 571 depends on ARCH_MXC
@@ -645,9 +674,16 @@ config RTC_DRV_OMAP
645 DA8xx/OMAP-L13x chips. This driver can also be built as a 674 DA8xx/OMAP-L13x chips. This driver can also be built as a
646 module called rtc-omap. 675 module called rtc-omap.
647 676
677config HAVE_S3C_RTC
678 bool
679 help
680 This will include RTC support for Samsung SoCs. If
681 you want to include RTC support for any machine, kindly
682 select this in the respective mach-XXXX/Kconfig file.
683
648config RTC_DRV_S3C 684config RTC_DRV_S3C
649 tristate "Samsung S3C series SoC RTC" 685 tristate "Samsung S3C series SoC RTC"
650 depends on ARCH_S3C2410 || ARCH_S3C64XX 686 depends on ARCH_S3C2410 || ARCH_S3C64XX || HAVE_S3C_RTC
651 help 687 help
652 RTC (Realtime Clock) driver for the clock inbuilt into the 688 RTC (Realtime Clock) driver for the clock inbuilt into the
653 Samsung S3C24XX series of SoCs. This can provide periodic 689 Samsung S3C24XX series of SoCs. This can provide periodic
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index fedf9bb36593..0f207b3b5833 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -41,12 +41,15 @@ obj-$(CONFIG_RTC_DRV_DS1511) += rtc-ds1511.o
41obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o 41obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o
42obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o 42obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o
43obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o 43obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o
44obj-$(CONFIG_RTC_DRV_DS3232) += rtc-ds3232.o
44obj-$(CONFIG_RTC_DRV_DS3234) += rtc-ds3234.o 45obj-$(CONFIG_RTC_DRV_DS3234) += rtc-ds3234.o
45obj-$(CONFIG_RTC_DRV_EFI) += rtc-efi.o 46obj-$(CONFIG_RTC_DRV_EFI) += rtc-efi.o
46obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o 47obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
47obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o 48obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o
48obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o 49obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o
50obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o
49obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o 51obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
52obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o
50obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o 53obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o
51obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o 54obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o
52obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o 55obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 11b8ea29d2b7..5856167a0c90 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -970,7 +970,6 @@ static inline int cmos_poweroff(struct device *dev)
970 970
971#include <linux/acpi.h> 971#include <linux/acpi.h>
972 972
973#ifdef CONFIG_PM
974static u32 rtc_handler(void *context) 973static u32 rtc_handler(void *context)
975{ 974{
976 acpi_clear_event(ACPI_EVENT_RTC); 975 acpi_clear_event(ACPI_EVENT_RTC);
@@ -999,11 +998,6 @@ static void rtc_wake_off(struct device *dev)
999{ 998{
1000 acpi_disable_event(ACPI_EVENT_RTC, 0); 999 acpi_disable_event(ACPI_EVENT_RTC, 0);
1001} 1000}
1002#else
1003#define rtc_wake_setup() do{}while(0)
1004#define rtc_wake_on NULL
1005#define rtc_wake_off NULL
1006#endif
1007 1001
1008/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find 1002/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find
1009 * its device node and pass extra config data. This helps its driver use 1003 * its device node and pass extra config data. This helps its driver use
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c
new file mode 100644
index 000000000000..9daed8db83d3
--- /dev/null
+++ b/drivers/rtc/rtc-ds3232.c
@@ -0,0 +1,326 @@
1/*
2 * RTC client/driver for the Maxim/Dallas DS3232 Real-Time Clock over I2C
3 *
4 * Copyright (C) 2009-2010 Freescale Semiconductor.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11/*
12 * It would be more efficient to use i2c msgs/i2c_transfer directly but, as
13 * recommened in .../Documentation/i2c/writing-clients section
14 * "Sending and receiving", using SMBus level communication is preferred.
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/interrupt.h>
20#include <linux/i2c.h>
21#include <linux/rtc.h>
22#include <linux/bcd.h>
23#include <linux/workqueue.h>
24#include <linux/slab.h>
25
26#define DS3232_REG_SECONDS 0x00
27#define DS3232_REG_MINUTES 0x01
28#define DS3232_REG_HOURS 0x02
29#define DS3232_REG_AMPM 0x02
30#define DS3232_REG_DAY 0x03
31#define DS3232_REG_DATE 0x04
32#define DS3232_REG_MONTH 0x05
33#define DS3232_REG_CENTURY 0x05
34#define DS3232_REG_YEAR 0x06
35#define DS3232_REG_ALARM1 0x07 /* Alarm 1 BASE */
36#define DS3232_REG_ALARM2 0x0B /* Alarm 2 BASE */
37#define DS3232_REG_CR 0x0E /* Control register */
38# define DS3232_REG_CR_nEOSC 0x80
39# define DS3232_REG_CR_INTCN 0x04
40# define DS3232_REG_CR_A2IE 0x02
41# define DS3232_REG_CR_A1IE 0x01
42
43#define DS3232_REG_SR 0x0F /* control/status register */
44# define DS3232_REG_SR_OSF 0x80
45# define DS3232_REG_SR_BSY 0x04
46# define DS3232_REG_SR_A2F 0x02
47# define DS3232_REG_SR_A1F 0x01
48
49struct ds3232 {
50 struct i2c_client *client;
51 struct rtc_device *rtc;
52 struct work_struct work;
53
54 /* The mutex protects alarm operations, and prevents a race
55 * between the enable_irq() in the workqueue and the free_irq()
56 * in the remove function.
57 */
58 struct mutex mutex;
59 int exiting;
60};
61
62static struct i2c_driver ds3232_driver;
63
64static int ds3232_check_rtc_status(struct i2c_client *client)
65{
66 int ret = 0;
67 int control, stat;
68
69 stat = i2c_smbus_read_byte_data(client, DS3232_REG_SR);
70 if (stat < 0)
71 return stat;
72
73 if (stat & DS3232_REG_SR_OSF)
74 dev_warn(&client->dev,
75 "oscillator discontinuity flagged, "
76 "time unreliable\n");
77
78 stat &= ~(DS3232_REG_SR_OSF | DS3232_REG_SR_A1F | DS3232_REG_SR_A2F);
79
80 ret = i2c_smbus_write_byte_data(client, DS3232_REG_SR, stat);
81 if (ret < 0)
82 return ret;
83
84 /* If the alarm is pending, clear it before requesting
85 * the interrupt, so an interrupt event isn't reported
86 * before everything is initialized.
87 */
88
89 control = i2c_smbus_read_byte_data(client, DS3232_REG_CR);
90 if (control < 0)
91 return control;
92
93 control &= ~(DS3232_REG_CR_A1IE | DS3232_REG_CR_A2IE);
94 control |= DS3232_REG_CR_INTCN;
95
96 return i2c_smbus_write_byte_data(client, DS3232_REG_CR, control);
97}
98
99static int ds3232_read_time(struct device *dev, struct rtc_time *time)
100{
101 struct i2c_client *client = to_i2c_client(dev);
102 int ret;
103 u8 buf[7];
104 unsigned int year, month, day, hour, minute, second;
105 unsigned int week, twelve_hr, am_pm;
106 unsigned int century, add_century = 0;
107
108 ret = i2c_smbus_read_i2c_block_data(client, DS3232_REG_SECONDS, 7, buf);
109
110 if (ret < 0)
111 return ret;
112 if (ret < 7)
113 return -EIO;
114
115 second = buf[0];
116 minute = buf[1];
117 hour = buf[2];
118 week = buf[3];
119 day = buf[4];
120 month = buf[5];
121 year = buf[6];
122
123 /* Extract additional information for AM/PM and century */
124
125 twelve_hr = hour & 0x40;
126 am_pm = hour & 0x20;
127 century = month & 0x80;
128
129 /* Write to rtc_time structure */
130
131 time->tm_sec = bcd2bin(second);
132 time->tm_min = bcd2bin(minute);
133 if (twelve_hr) {
134 /* Convert to 24 hr */
135 if (am_pm)
136 time->tm_hour = bcd2bin(hour & 0x1F) + 12;
137 else
138 time->tm_hour = bcd2bin(hour & 0x1F);
139 } else {
140 time->tm_hour = bcd2bin(hour);
141 }
142
143 time->tm_wday = bcd2bin(week);
144 time->tm_mday = bcd2bin(day);
145 time->tm_mon = bcd2bin(month & 0x7F);
146 if (century)
147 add_century = 100;
148
149 time->tm_year = bcd2bin(year) + add_century;
150
151 return rtc_valid_tm(time);
152}
153
154static int ds3232_set_time(struct device *dev, struct rtc_time *time)
155{
156 struct i2c_client *client = to_i2c_client(dev);
157 u8 buf[7];
158
159 /* Extract time from rtc_time and load into ds3232*/
160
161 buf[0] = bin2bcd(time->tm_sec);
162 buf[1] = bin2bcd(time->tm_min);
163 buf[2] = bin2bcd(time->tm_hour);
164 buf[3] = bin2bcd(time->tm_wday); /* Day of the week */
165 buf[4] = bin2bcd(time->tm_mday); /* Date */
166 buf[5] = bin2bcd(time->tm_mon);
167 if (time->tm_year >= 100) {
168 buf[5] |= 0x80;
169 buf[6] = bin2bcd(time->tm_year - 100);
170 } else {
171 buf[6] = bin2bcd(time->tm_year);
172 }
173
174 return i2c_smbus_write_i2c_block_data(client,
175 DS3232_REG_SECONDS, 7, buf);
176}
177
178static irqreturn_t ds3232_irq(int irq, void *dev_id)
179{
180 struct i2c_client *client = dev_id;
181 struct ds3232 *ds3232 = i2c_get_clientdata(client);
182
183 disable_irq_nosync(irq);
184 schedule_work(&ds3232->work);
185 return IRQ_HANDLED;
186}
187
188static void ds3232_work(struct work_struct *work)
189{
190 struct ds3232 *ds3232 = container_of(work, struct ds3232, work);
191 struct i2c_client *client = ds3232->client;
192 int stat, control;
193
194 mutex_lock(&ds3232->mutex);
195
196 stat = i2c_smbus_read_byte_data(client, DS3232_REG_SR);
197 if (stat < 0)
198 goto unlock;
199
200 if (stat & DS3232_REG_SR_A1F) {
201 control = i2c_smbus_read_byte_data(client, DS3232_REG_CR);
202 if (control < 0)
203 goto out;
204 /* disable alarm1 interrupt */
205 control &= ~(DS3232_REG_CR_A1IE);
206 i2c_smbus_write_byte_data(client, DS3232_REG_CR, control);
207
208 /* clear the alarm pend flag */
209 stat &= ~DS3232_REG_SR_A1F;
210 i2c_smbus_write_byte_data(client, DS3232_REG_SR, stat);
211
212 rtc_update_irq(ds3232->rtc, 1, RTC_AF | RTC_IRQF);
213 }
214
215out:
216 if (!ds3232->exiting)
217 enable_irq(client->irq);
218unlock:
219 mutex_unlock(&ds3232->mutex);
220}
221
222static const struct rtc_class_ops ds3232_rtc_ops = {
223 .read_time = ds3232_read_time,
224 .set_time = ds3232_set_time,
225};
226
227static int __devinit ds3232_probe(struct i2c_client *client,
228 const struct i2c_device_id *id)
229{
230 struct ds3232 *ds3232;
231 int ret;
232
233 ds3232 = kzalloc(sizeof(struct ds3232), GFP_KERNEL);
234 if (!ds3232)
235 return -ENOMEM;
236
237 ds3232->client = client;
238 i2c_set_clientdata(client, ds3232);
239
240 INIT_WORK(&ds3232->work, ds3232_work);
241 mutex_init(&ds3232->mutex);
242
243 ret = ds3232_check_rtc_status(client);
244 if (ret)
245 goto out_free;
246
247 ds3232->rtc = rtc_device_register(client->name, &client->dev,
248 &ds3232_rtc_ops, THIS_MODULE);
249 if (IS_ERR(ds3232->rtc)) {
250 ret = PTR_ERR(ds3232->rtc);
251 dev_err(&client->dev, "unable to register the class device\n");
252 goto out_irq;
253 }
254
255 if (client->irq >= 0) {
256 ret = request_irq(client->irq, ds3232_irq, 0,
257 "ds3232", client);
258 if (ret) {
259 dev_err(&client->dev, "unable to request IRQ\n");
260 goto out_free;
261 }
262 }
263
264 return 0;
265
266out_irq:
267 if (client->irq >= 0)
268 free_irq(client->irq, client);
269
270out_free:
271 i2c_set_clientdata(client, NULL);
272 kfree(ds3232);
273 return ret;
274}
275
276static int __devexit ds3232_remove(struct i2c_client *client)
277{
278 struct ds3232 *ds3232 = i2c_get_clientdata(client);
279
280 if (client->irq >= 0) {
281 mutex_lock(&ds3232->mutex);
282 ds3232->exiting = 1;
283 mutex_unlock(&ds3232->mutex);
284
285 free_irq(client->irq, client);
286 flush_scheduled_work();
287 }
288
289 rtc_device_unregister(ds3232->rtc);
290 i2c_set_clientdata(client, NULL);
291 kfree(ds3232);
292 return 0;
293}
294
295static const struct i2c_device_id ds3232_id[] = {
296 { "ds3232", 0 },
297 { }
298};
299MODULE_DEVICE_TABLE(i2c, ds3232_id);
300
301static struct i2c_driver ds3232_driver = {
302 .driver = {
303 .name = "rtc-ds3232",
304 .owner = THIS_MODULE,
305 },
306 .probe = ds3232_probe,
307 .remove = __devexit_p(ds3232_remove),
308 .id_table = ds3232_id,
309};
310
311static int __init ds3232_init(void)
312{
313 return i2c_add_driver(&ds3232_driver);
314}
315
316static void __exit ds3232_exit(void)
317{
318 i2c_del_driver(&ds3232_driver);
319}
320
321module_init(ds3232_init);
322module_exit(ds3232_exit);
323
324MODULE_AUTHOR("Srikanth Srinivasan <srikanth.srinivasan@freescale.com>");
325MODULE_DESCRIPTION("Maxim/Dallas DS3232 RTC Driver");
326MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-fm3130.c b/drivers/rtc/rtc-fm3130.c
index e4de8f37ae4a..4cf2e70c5078 100644
--- a/drivers/rtc/rtc-fm3130.c
+++ b/drivers/rtc/rtc-fm3130.c
@@ -52,8 +52,8 @@ struct fm3130 {
52 struct i2c_msg msg[4]; 52 struct i2c_msg msg[4];
53 struct i2c_client *client; 53 struct i2c_client *client;
54 struct rtc_device *rtc; 54 struct rtc_device *rtc;
55 int alarm_valid;
55 int data_valid; 56 int data_valid;
56 int alarm;
57}; 57};
58static const struct i2c_device_id fm3130_id[] = { 58static const struct i2c_device_id fm3130_id[] = {
59 { "fm3130", 0 }, 59 { "fm3130", 0 },
@@ -87,11 +87,7 @@ static void fm3130_rtc_mode(struct device *dev, int mode)
87 dev_dbg(dev, "invalid mode %d\n", mode); 87 dev_dbg(dev, "invalid mode %d\n", mode);
88 break; 88 break;
89 } 89 }
90 /* Checking for alarm */ 90
91 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_AF) {
92 fm3130->alarm = 1;
93 fm3130->regs[FM3130_RTC_CONTROL] &= ~FM3130_RTC_CONTROL_BIT_AF;
94 }
95 i2c_smbus_write_byte_data(fm3130->client, 91 i2c_smbus_write_byte_data(fm3130->client,
96 FM3130_RTC_CONTROL, fm3130->regs[FM3130_RTC_CONTROL]); 92 FM3130_RTC_CONTROL, fm3130->regs[FM3130_RTC_CONTROL]);
97} 93}
@@ -208,6 +204,17 @@ static int fm3130_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
208 struct fm3130 *fm3130 = dev_get_drvdata(dev); 204 struct fm3130 *fm3130 = dev_get_drvdata(dev);
209 int tmp; 205 int tmp;
210 struct rtc_time *tm = &alrm->time; 206 struct rtc_time *tm = &alrm->time;
207
208 if (!fm3130->alarm_valid) {
209 /*
210 * We have invalid alarm in RTC, probably due to battery faults
211 * or other problems. Return EIO for now, it will allow us to
212 * set alarm value later instead of error during probing which
213 * disables device
214 */
215 return -EIO;
216 }
217
211 /* read the RTC alarm registers all at once */ 218 /* read the RTC alarm registers all at once */
212 tmp = i2c_transfer(to_i2c_adapter(fm3130->client->dev.parent), 219 tmp = i2c_transfer(to_i2c_adapter(fm3130->client->dev.parent),
213 &fm3130->msg[2], 2); 220 &fm3130->msg[2], 2);
@@ -222,20 +229,31 @@ static int fm3130_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
222 fm3130->regs[FM3130_ALARM_DATE], 229 fm3130->regs[FM3130_ALARM_DATE],
223 fm3130->regs[FM3130_ALARM_MONTHS]); 230 fm3130->regs[FM3130_ALARM_MONTHS]);
224 231
225
226 tm->tm_sec = bcd2bin(fm3130->regs[FM3130_ALARM_SECONDS] & 0x7F); 232 tm->tm_sec = bcd2bin(fm3130->regs[FM3130_ALARM_SECONDS] & 0x7F);
227 tm->tm_min = bcd2bin(fm3130->regs[FM3130_ALARM_MINUTES] & 0x7F); 233 tm->tm_min = bcd2bin(fm3130->regs[FM3130_ALARM_MINUTES] & 0x7F);
228 tm->tm_hour = bcd2bin(fm3130->regs[FM3130_ALARM_HOURS] & 0x3F); 234 tm->tm_hour = bcd2bin(fm3130->regs[FM3130_ALARM_HOURS] & 0x3F);
229 tm->tm_mday = bcd2bin(fm3130->regs[FM3130_ALARM_DATE] & 0x3F); 235 tm->tm_mday = bcd2bin(fm3130->regs[FM3130_ALARM_DATE] & 0x3F);
230 tm->tm_mon = bcd2bin(fm3130->regs[FM3130_ALARM_MONTHS] & 0x1F); 236 tm->tm_mon = bcd2bin(fm3130->regs[FM3130_ALARM_MONTHS] & 0x1F);
237
231 if (tm->tm_mon > 0) 238 if (tm->tm_mon > 0)
232 tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */ 239 tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */
240
233 dev_dbg(dev, "%s secs=%d, mins=%d, " 241 dev_dbg(dev, "%s secs=%d, mins=%d, "
234 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", 242 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
235 "read alarm", tm->tm_sec, tm->tm_min, 243 "read alarm", tm->tm_sec, tm->tm_min,
236 tm->tm_hour, tm->tm_mday, 244 tm->tm_hour, tm->tm_mday,
237 tm->tm_mon, tm->tm_year, tm->tm_wday); 245 tm->tm_mon, tm->tm_year, tm->tm_wday);
238 246
247 /* check if alarm enabled */
248 fm3130->regs[FM3130_RTC_CONTROL] =
249 i2c_smbus_read_byte_data(fm3130->client, FM3130_RTC_CONTROL);
250
251 if ((fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_AEN) &&
252 (~fm3130->regs[FM3130_RTC_CONTROL] &
253 FM3130_RTC_CONTROL_BIT_CAL)) {
254 alrm->enabled = 1;
255 }
256
239 return 0; 257 return 0;
240} 258}
241 259
@@ -251,25 +269,20 @@ static int fm3130_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
251 tm->tm_hour, tm->tm_mday, 269 tm->tm_hour, tm->tm_mday,
252 tm->tm_mon, tm->tm_year, tm->tm_wday); 270 tm->tm_mon, tm->tm_year, tm->tm_wday);
253 271
254 if (tm->tm_sec != -1) 272 fm3130->regs[FM3130_ALARM_SECONDS] =
255 fm3130->regs[FM3130_ALARM_SECONDS] = 273 (tm->tm_sec != -1) ? bin2bcd(tm->tm_sec) : 0x80;
256 bin2bcd(tm->tm_sec) | 0x80;
257 274
258 if (tm->tm_min != -1) 275 fm3130->regs[FM3130_ALARM_MINUTES] =
259 fm3130->regs[FM3130_ALARM_MINUTES] = 276 (tm->tm_min != -1) ? bin2bcd(tm->tm_min) : 0x80;
260 bin2bcd(tm->tm_min) | 0x80;
261 277
262 if (tm->tm_hour != -1) 278 fm3130->regs[FM3130_ALARM_HOURS] =
263 fm3130->regs[FM3130_ALARM_HOURS] = 279 (tm->tm_hour != -1) ? bin2bcd(tm->tm_hour) : 0x80;
264 bin2bcd(tm->tm_hour) | 0x80;
265 280
266 if (tm->tm_mday != -1) 281 fm3130->regs[FM3130_ALARM_DATE] =
267 fm3130->regs[FM3130_ALARM_DATE] = 282 (tm->tm_mday != -1) ? bin2bcd(tm->tm_mday) : 0x80;
268 bin2bcd(tm->tm_mday) | 0x80;
269 283
270 if (tm->tm_mon != -1) 284 fm3130->regs[FM3130_ALARM_MONTHS] =
271 fm3130->regs[FM3130_ALARM_MONTHS] = 285 (tm->tm_mon != -1) ? bin2bcd(tm->tm_mon + 1) : 0x80;
272 bin2bcd(tm->tm_mon + 1) | 0x80;
273 286
274 dev_dbg(dev, "alarm write %02x %02x %02x %02x %02x\n", 287 dev_dbg(dev, "alarm write %02x %02x %02x %02x %02x\n",
275 fm3130->regs[FM3130_ALARM_SECONDS], 288 fm3130->regs[FM3130_ALARM_SECONDS],
@@ -285,11 +298,8 @@ static int fm3130_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
285 } 298 }
286 fm3130->regs[FM3130_RTC_CONTROL] = 299 fm3130->regs[FM3130_RTC_CONTROL] =
287 i2c_smbus_read_byte_data(fm3130->client, FM3130_RTC_CONTROL); 300 i2c_smbus_read_byte_data(fm3130->client, FM3130_RTC_CONTROL);
288 /* Checking for alarm */ 301
289 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_AF) { 302 /* enable or disable alarm */
290 fm3130->alarm = 1;
291 fm3130->regs[FM3130_RTC_CONTROL] &= ~FM3130_RTC_CONTROL_BIT_AF;
292 }
293 if (alrm->enabled) { 303 if (alrm->enabled) {
294 i2c_smbus_write_byte_data(fm3130->client, FM3130_RTC_CONTROL, 304 i2c_smbus_write_byte_data(fm3130->client, FM3130_RTC_CONTROL,
295 (fm3130->regs[FM3130_RTC_CONTROL] & 305 (fm3130->regs[FM3130_RTC_CONTROL] &
@@ -298,16 +308,55 @@ static int fm3130_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
298 } else { 308 } else {
299 i2c_smbus_write_byte_data(fm3130->client, FM3130_RTC_CONTROL, 309 i2c_smbus_write_byte_data(fm3130->client, FM3130_RTC_CONTROL,
300 fm3130->regs[FM3130_RTC_CONTROL] & 310 fm3130->regs[FM3130_RTC_CONTROL] &
301 ~(FM3130_RTC_CONTROL_BIT_AEN)); 311 ~(FM3130_RTC_CONTROL_BIT_CAL) &
312 ~(FM3130_RTC_CONTROL_BIT_AEN));
302 } 313 }
314
315 /* We assume here that data is valid once written */
316 if (!fm3130->alarm_valid)
317 fm3130->alarm_valid = 1;
318
303 return 0; 319 return 0;
304} 320}
305 321
322static int fm3130_alarm_irq_enable(struct device *dev, unsigned int enabled)
323{
324 struct fm3130 *fm3130 = dev_get_drvdata(dev);
325 int ret = 0;
326
327 fm3130->regs[FM3130_RTC_CONTROL] =
328 i2c_smbus_read_byte_data(fm3130->client, FM3130_RTC_CONTROL);
329
330 dev_dbg(dev, "alarm_irq_enable: enable=%d, FM3130_RTC_CONTROL=%02x\n",
331 enabled, fm3130->regs[FM3130_RTC_CONTROL]);
332
333 switch (enabled) {
334 case 0: /* alarm off */
335 ret = i2c_smbus_write_byte_data(fm3130->client,
336 FM3130_RTC_CONTROL, fm3130->regs[FM3130_RTC_CONTROL] &
337 ~(FM3130_RTC_CONTROL_BIT_CAL) &
338 ~(FM3130_RTC_CONTROL_BIT_AEN));
339 break;
340 case 1: /* alarm on */
341 ret = i2c_smbus_write_byte_data(fm3130->client,
342 FM3130_RTC_CONTROL, (fm3130->regs[FM3130_RTC_CONTROL] &
343 ~(FM3130_RTC_CONTROL_BIT_CAL)) |
344 FM3130_RTC_CONTROL_BIT_AEN);
345 break;
346 default:
347 ret = -EINVAL;
348 break;
349 }
350
351 return ret;
352}
353
306static const struct rtc_class_ops fm3130_rtc_ops = { 354static const struct rtc_class_ops fm3130_rtc_ops = {
307 .read_time = fm3130_get_time, 355 .read_time = fm3130_get_time,
308 .set_time = fm3130_set_time, 356 .set_time = fm3130_set_time,
309 .read_alarm = fm3130_read_alarm, 357 .read_alarm = fm3130_read_alarm,
310 .set_alarm = fm3130_set_alarm, 358 .set_alarm = fm3130_set_alarm,
359 .alarm_irq_enable = fm3130_alarm_irq_enable,
311}; 360};
312 361
313static struct i2c_driver fm3130_driver; 362static struct i2c_driver fm3130_driver;
@@ -356,6 +405,7 @@ static int __devinit fm3130_probe(struct i2c_client *client,
356 fm3130->msg[3].len = FM3130_ALARM_REGS; 405 fm3130->msg[3].len = FM3130_ALARM_REGS;
357 fm3130->msg[3].buf = &fm3130->regs[FM3130_ALARM_SECONDS]; 406 fm3130->msg[3].buf = &fm3130->regs[FM3130_ALARM_SECONDS];
358 407
408 fm3130->alarm_valid = 0;
359 fm3130->data_valid = 0; 409 fm3130->data_valid = 0;
360 410
361 tmp = i2c_transfer(adapter, fm3130->msg, 4); 411 tmp = i2c_transfer(adapter, fm3130->msg, 4);
@@ -370,12 +420,6 @@ static int __devinit fm3130_probe(struct i2c_client *client,
370 fm3130->regs[FM3130_CAL_CONTROL] = 420 fm3130->regs[FM3130_CAL_CONTROL] =
371 i2c_smbus_read_byte_data(client, FM3130_CAL_CONTROL); 421 i2c_smbus_read_byte_data(client, FM3130_CAL_CONTROL);
372 422
373 /* Checking for alarm */
374 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_AF) {
375 fm3130->alarm = 1;
376 fm3130->regs[FM3130_RTC_CONTROL] &= ~FM3130_RTC_CONTROL_BIT_AF;
377 }
378
379 /* Disabling calibration mode */ 423 /* Disabling calibration mode */
380 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_CAL) { 424 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_CAL) {
381 i2c_smbus_write_byte_data(client, FM3130_RTC_CONTROL, 425 i2c_smbus_write_byte_data(client, FM3130_RTC_CONTROL,
@@ -400,44 +444,79 @@ static int __devinit fm3130_probe(struct i2c_client *client,
400 fm3130->regs[FM3130_CAL_CONTROL] & 444 fm3130->regs[FM3130_CAL_CONTROL] &
401 ~(FM3130_CAL_CONTROL_BIT_nOSCEN)); 445 ~(FM3130_CAL_CONTROL_BIT_nOSCEN));
402 446
403 /* oscillator fault? clear flag, and warn */ 447 /* low battery? clear flag, and warn */
404 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_LB) 448 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_LB) {
449 i2c_smbus_write_byte_data(client, FM3130_RTC_CONTROL,
450 fm3130->regs[FM3130_RTC_CONTROL] &
451 ~(FM3130_RTC_CONTROL_BIT_LB));
405 dev_warn(&client->dev, "Low battery!\n"); 452 dev_warn(&client->dev, "Low battery!\n");
453 }
406 454
407 /* oscillator fault? clear flag, and warn */ 455 /* check if Power On Reset bit is set */
408 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_POR) { 456 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_POR) {
409 i2c_smbus_write_byte_data(client, FM3130_RTC_CONTROL, 457 i2c_smbus_write_byte_data(client, FM3130_RTC_CONTROL,
410 fm3130->regs[FM3130_RTC_CONTROL] & 458 fm3130->regs[FM3130_RTC_CONTROL] &
411 ~FM3130_RTC_CONTROL_BIT_POR); 459 ~FM3130_RTC_CONTROL_BIT_POR);
412 dev_warn(&client->dev, "SET TIME!\n"); 460 dev_dbg(&client->dev, "POR bit is set\n");
413 } 461 }
414 /* ACS is controlled by alarm */ 462 /* ACS is controlled by alarm */
415 i2c_smbus_write_byte_data(client, FM3130_ALARM_WP_CONTROL, 0x80); 463 i2c_smbus_write_byte_data(client, FM3130_ALARM_WP_CONTROL, 0x80);
416 464
417 /* TODO */ 465 /* alarm registers sanity check */
418 /* TODO need to sanity check alarm */ 466 tmp = bcd2bin(fm3130->regs[FM3130_RTC_SECONDS] & 0x7f);
419 tmp = fm3130->regs[FM3130_RTC_SECONDS]; 467 if (tmp > 59)
420 tmp = bcd2bin(tmp & 0x7f); 468 goto bad_alarm;
421 if (tmp > 60) 469
422 goto exit_bad;
423 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f); 470 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f);
424 if (tmp > 60) 471 if (tmp > 59)
425 goto exit_bad; 472 goto bad_alarm;
473
474 tmp = bcd2bin(fm3130->regs[FM3130_RTC_HOURS] & 0x3f);
475 if (tmp > 23)
476 goto bad_alarm;
426 477
427 tmp = bcd2bin(fm3130->regs[FM3130_RTC_DATE] & 0x3f); 478 tmp = bcd2bin(fm3130->regs[FM3130_RTC_DATE] & 0x3f);
428 if (tmp == 0 || tmp > 31) 479 if (tmp == 0 || tmp > 31)
429 goto exit_bad; 480 goto bad_alarm;
430 481
431 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MONTHS] & 0x1f); 482 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MONTHS] & 0x1f);
432 if (tmp == 0 || tmp > 12) 483 if (tmp == 0 || tmp > 12)
433 goto exit_bad; 484 goto bad_alarm;
434 485
435 tmp = fm3130->regs[FM3130_RTC_HOURS]; 486 fm3130->alarm_valid = 1;
487
488bad_alarm:
489
490 /* clock registers sanity chek */
491 tmp = bcd2bin(fm3130->regs[FM3130_RTC_SECONDS] & 0x7f);
492 if (tmp > 59)
493 goto bad_clock;
494
495 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f);
496 if (tmp > 59)
497 goto bad_clock;
498
499 tmp = bcd2bin(fm3130->regs[FM3130_RTC_HOURS] & 0x3f);
500 if (tmp > 23)
501 goto bad_clock;
502
503 tmp = bcd2bin(fm3130->regs[FM3130_RTC_DAY] & 0x7);
504 if (tmp == 0 || tmp > 7)
505 goto bad_clock;
506
507 tmp = bcd2bin(fm3130->regs[FM3130_RTC_DATE] & 0x3f);
508 if (tmp == 0 || tmp > 31)
509 goto bad_clock;
510
511 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MONTHS] & 0x1f);
512 if (tmp == 0 || tmp > 12)
513 goto bad_clock;
436 514
437 fm3130->data_valid = 1; 515 fm3130->data_valid = 1;
438 516
439exit_bad: 517bad_clock:
440 if (!fm3130->data_valid) 518
519 if (!fm3130->data_valid || !fm3130->alarm_valid)
441 dev_dbg(&client->dev, 520 dev_dbg(&client->dev,
442 "%s: %02x %02x %02x %02x %02x %02x %02x %02x" 521 "%s: %02x %02x %02x %02x %02x %02x %02x %02x"
443 "%02x %02x %02x %02x %02x %02x %02x\n", 522 "%02x %02x %02x %02x %02x %02x %02x\n",
diff --git a/drivers/rtc/rtc-imxdi.c b/drivers/rtc/rtc-imxdi.c
new file mode 100644
index 000000000000..2dd3c0163272
--- /dev/null
+++ b/drivers/rtc/rtc-imxdi.c
@@ -0,0 +1,519 @@
1/*
2 * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
3 * Copyright 2010 Orex Computed Radiography
4 */
5
6/*
7 * The code contained herein is licensed under the GNU General Public
8 * License. You may obtain a copy of the GNU General Public License
9 * Version 2 or later at the following locations:
10 *
11 * http://www.opensource.org/licenses/gpl-license.html
12 * http://www.gnu.org/copyleft/gpl.html
13 */
14
15/* based on rtc-mc13892.c */
16
17/*
18 * This driver uses the 47-bit 32 kHz counter in the Freescale DryIce block
19 * to implement a Linux RTC. Times and alarms are truncated to seconds.
20 * Since the RTC framework performs API locking via rtc->ops_lock the
21 * only simultaneous accesses we need to deal with is updating DryIce
22 * registers while servicing an alarm.
23 *
24 * Note that reading the DSR (DryIce Status Register) automatically clears
25 * the WCF (Write Complete Flag). All DryIce writes are synchronized to the
26 * LP (Low Power) domain and set the WCF upon completion. Writes to the
27 * DIER (DryIce Interrupt Enable Register) are the only exception. These
28 * occur at normal bus speeds and do not set WCF. Periodic interrupts are
29 * not supported by the hardware.
30 */
31
32#include <linux/io.h>
33#include <linux/clk.h>
34#include <linux/delay.h>
35#include <linux/module.h>
36#include <linux/platform_device.h>
37#include <linux/rtc.h>
38#include <linux/workqueue.h>
39
40/* DryIce Register Definitions */
41
42#define DTCMR 0x00 /* Time Counter MSB Reg */
43#define DTCLR 0x04 /* Time Counter LSB Reg */
44
45#define DCAMR 0x08 /* Clock Alarm MSB Reg */
46#define DCALR 0x0c /* Clock Alarm LSB Reg */
47#define DCAMR_UNSET 0xFFFFFFFF /* doomsday - 1 sec */
48
49#define DCR 0x10 /* Control Reg */
50#define DCR_TCE (1 << 3) /* Time Counter Enable */
51
52#define DSR 0x14 /* Status Reg */
53#define DSR_WBF (1 << 10) /* Write Busy Flag */
54#define DSR_WNF (1 << 9) /* Write Next Flag */
55#define DSR_WCF (1 << 8) /* Write Complete Flag */
56#define DSR_WEF (1 << 7) /* Write Error Flag */
57#define DSR_CAF (1 << 4) /* Clock Alarm Flag */
58#define DSR_NVF (1 << 1) /* Non-Valid Flag */
59#define DSR_SVF (1 << 0) /* Security Violation Flag */
60
61#define DIER 0x18 /* Interrupt Enable Reg */
62#define DIER_WNIE (1 << 9) /* Write Next Interrupt Enable */
63#define DIER_WCIE (1 << 8) /* Write Complete Interrupt Enable */
64#define DIER_WEIE (1 << 7) /* Write Error Interrupt Enable */
65#define DIER_CAIE (1 << 4) /* Clock Alarm Interrupt Enable */
66
67/**
68 * struct imxdi_dev - private imxdi rtc data
69 * @pdev: pionter to platform dev
70 * @rtc: pointer to rtc struct
71 * @ioaddr: IO registers pointer
72 * @irq: dryice normal interrupt
73 * @clk: input reference clock
74 * @dsr: copy of the DSR register
75 * @irq_lock: interrupt enable register (DIER) lock
76 * @write_wait: registers write complete queue
77 * @write_mutex: serialize registers write
78 * @work: schedule alarm work
79 */
80struct imxdi_dev {
81 struct platform_device *pdev;
82 struct rtc_device *rtc;
83 void __iomem *ioaddr;
84 int irq;
85 struct clk *clk;
86 u32 dsr;
87 spinlock_t irq_lock;
88 wait_queue_head_t write_wait;
89 struct mutex write_mutex;
90 struct work_struct work;
91};
92
93/*
94 * enable a dryice interrupt
95 */
96static void di_int_enable(struct imxdi_dev *imxdi, u32 intr)
97{
98 unsigned long flags;
99
100 spin_lock_irqsave(&imxdi->irq_lock, flags);
101 __raw_writel(__raw_readl(imxdi->ioaddr + DIER) | intr,
102 imxdi->ioaddr + DIER);
103 spin_unlock_irqrestore(&imxdi->irq_lock, flags);
104}
105
106/*
107 * disable a dryice interrupt
108 */
109static void di_int_disable(struct imxdi_dev *imxdi, u32 intr)
110{
111 unsigned long flags;
112
113 spin_lock_irqsave(&imxdi->irq_lock, flags);
114 __raw_writel(__raw_readl(imxdi->ioaddr + DIER) & ~intr,
115 imxdi->ioaddr + DIER);
116 spin_unlock_irqrestore(&imxdi->irq_lock, flags);
117}
118
119/*
120 * This function attempts to clear the dryice write-error flag.
121 *
122 * A dryice write error is similar to a bus fault and should not occur in
123 * normal operation. Clearing the flag requires another write, so the root
124 * cause of the problem may need to be fixed before the flag can be cleared.
125 */
126static void clear_write_error(struct imxdi_dev *imxdi)
127{
128 int cnt;
129
130 dev_warn(&imxdi->pdev->dev, "WARNING: Register write error!\n");
131
132 /* clear the write error flag */
133 __raw_writel(DSR_WEF, imxdi->ioaddr + DSR);
134
135 /* wait for it to take effect */
136 for (cnt = 0; cnt < 1000; cnt++) {
137 if ((__raw_readl(imxdi->ioaddr + DSR) & DSR_WEF) == 0)
138 return;
139 udelay(10);
140 }
141 dev_err(&imxdi->pdev->dev,
142 "ERROR: Cannot clear write-error flag!\n");
143}
144
145/*
146 * Write a dryice register and wait until it completes.
147 *
148 * This function uses interrupts to determine when the
149 * write has completed.
150 */
151static int di_write_wait(struct imxdi_dev *imxdi, u32 val, int reg)
152{
153 int ret;
154 int rc = 0;
155
156 /* serialize register writes */
157 mutex_lock(&imxdi->write_mutex);
158
159 /* enable the write-complete interrupt */
160 di_int_enable(imxdi, DIER_WCIE);
161
162 imxdi->dsr = 0;
163
164 /* do the register write */
165 __raw_writel(val, imxdi->ioaddr + reg);
166
167 /* wait for the write to finish */
168 ret = wait_event_interruptible_timeout(imxdi->write_wait,
169 imxdi->dsr & (DSR_WCF | DSR_WEF), msecs_to_jiffies(1));
170 if (ret < 0) {
171 rc = ret;
172 goto out;
173 } else if (ret == 0) {
174 dev_warn(&imxdi->pdev->dev,
175 "Write-wait timeout "
176 "val = 0x%08x reg = 0x%08x\n", val, reg);
177 }
178
179 /* check for write error */
180 if (imxdi->dsr & DSR_WEF) {
181 clear_write_error(imxdi);
182 rc = -EIO;
183 }
184
185out:
186 mutex_unlock(&imxdi->write_mutex);
187
188 return rc;
189}
190
191/*
192 * read the seconds portion of the current time from the dryice time counter
193 */
194static int dryice_rtc_read_time(struct device *dev, struct rtc_time *tm)
195{
196 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
197 unsigned long now;
198
199 now = __raw_readl(imxdi->ioaddr + DTCMR);
200 rtc_time_to_tm(now, tm);
201
202 return 0;
203}
204
205/*
206 * set the seconds portion of dryice time counter and clear the
207 * fractional part.
208 */
209static int dryice_rtc_set_mmss(struct device *dev, unsigned long secs)
210{
211 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
212 int rc;
213
214 /* zero the fractional part first */
215 rc = di_write_wait(imxdi, 0, DTCLR);
216 if (rc == 0)
217 rc = di_write_wait(imxdi, secs, DTCMR);
218
219 return rc;
220}
221
222static int dryice_rtc_alarm_irq_enable(struct device *dev,
223 unsigned int enabled)
224{
225 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
226
227 if (enabled)
228 di_int_enable(imxdi, DIER_CAIE);
229 else
230 di_int_disable(imxdi, DIER_CAIE);
231
232 return 0;
233}
234
235/*
236 * read the seconds portion of the alarm register.
237 * the fractional part of the alarm register is always zero.
238 */
239static int dryice_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
240{
241 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
242 u32 dcamr;
243
244 dcamr = __raw_readl(imxdi->ioaddr + DCAMR);
245 rtc_time_to_tm(dcamr, &alarm->time);
246
247 /* alarm is enabled if the interrupt is enabled */
248 alarm->enabled = (__raw_readl(imxdi->ioaddr + DIER) & DIER_CAIE) != 0;
249
250 /* don't allow the DSR read to mess up DSR_WCF */
251 mutex_lock(&imxdi->write_mutex);
252
253 /* alarm is pending if the alarm flag is set */
254 alarm->pending = (__raw_readl(imxdi->ioaddr + DSR) & DSR_CAF) != 0;
255
256 mutex_unlock(&imxdi->write_mutex);
257
258 return 0;
259}
260
261/*
262 * set the seconds portion of dryice alarm register
263 */
264static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
265{
266 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
267 unsigned long now;
268 unsigned long alarm_time;
269 int rc;
270
271 rc = rtc_tm_to_time(&alarm->time, &alarm_time);
272 if (rc)
273 return rc;
274
275 /* don't allow setting alarm in the past */
276 now = __raw_readl(imxdi->ioaddr + DTCMR);
277 if (alarm_time < now)
278 return -EINVAL;
279
280 /* write the new alarm time */
281 rc = di_write_wait(imxdi, (u32)alarm_time, DCAMR);
282 if (rc)
283 return rc;
284
285 if (alarm->enabled)
286 di_int_enable(imxdi, DIER_CAIE); /* enable alarm intr */
287 else
288 di_int_disable(imxdi, DIER_CAIE); /* disable alarm intr */
289
290 return 0;
291}
292
293static struct rtc_class_ops dryice_rtc_ops = {
294 .read_time = dryice_rtc_read_time,
295 .set_mmss = dryice_rtc_set_mmss,
296 .alarm_irq_enable = dryice_rtc_alarm_irq_enable,
297 .read_alarm = dryice_rtc_read_alarm,
298 .set_alarm = dryice_rtc_set_alarm,
299};
300
301/*
302 * dryice "normal" interrupt handler
303 */
304static irqreturn_t dryice_norm_irq(int irq, void *dev_id)
305{
306 struct imxdi_dev *imxdi = dev_id;
307 u32 dsr, dier;
308 irqreturn_t rc = IRQ_NONE;
309
310 dier = __raw_readl(imxdi->ioaddr + DIER);
311
312 /* handle write complete and write error cases */
313 if ((dier & DIER_WCIE)) {
314 /*If the write wait queue is empty then there is no pending
315 operations. It means the interrupt is for DryIce -Security.
316 IRQ must be returned as none.*/
317 if (list_empty_careful(&imxdi->write_wait.task_list))
318 return rc;
319
320 /* DSR_WCF clears itself on DSR read */
321 dsr = __raw_readl(imxdi->ioaddr + DSR);
322 if ((dsr & (DSR_WCF | DSR_WEF))) {
323 /* mask the interrupt */
324 di_int_disable(imxdi, DIER_WCIE);
325
326 /* save the dsr value for the wait queue */
327 imxdi->dsr |= dsr;
328
329 wake_up_interruptible(&imxdi->write_wait);
330 rc = IRQ_HANDLED;
331 }
332 }
333
334 /* handle the alarm case */
335 if ((dier & DIER_CAIE)) {
336 /* DSR_WCF clears itself on DSR read */
337 dsr = __raw_readl(imxdi->ioaddr + DSR);
338 if (dsr & DSR_CAF) {
339 /* mask the interrupt */
340 di_int_disable(imxdi, DIER_CAIE);
341
342 /* finish alarm in user context */
343 schedule_work(&imxdi->work);
344 rc = IRQ_HANDLED;
345 }
346 }
347 return rc;
348}
349
350/*
351 * post the alarm event from user context so it can sleep
352 * on the write completion.
353 */
354static void dryice_work(struct work_struct *work)
355{
356 struct imxdi_dev *imxdi = container_of(work,
357 struct imxdi_dev, work);
358
359 /* dismiss the interrupt (ignore error) */
360 di_write_wait(imxdi, DSR_CAF, DSR);
361
362 /* pass the alarm event to the rtc framework. */
363 rtc_update_irq(imxdi->rtc, 1, RTC_AF | RTC_IRQF);
364}
365
366/*
367 * probe for dryice rtc device
368 */
369static int dryice_rtc_probe(struct platform_device *pdev)
370{
371 struct resource *res;
372 struct imxdi_dev *imxdi;
373 int rc;
374
375 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
376 if (!res)
377 return -ENODEV;
378
379 imxdi = devm_kzalloc(&pdev->dev, sizeof(*imxdi), GFP_KERNEL);
380 if (!imxdi)
381 return -ENOMEM;
382
383 imxdi->pdev = pdev;
384
385 if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res),
386 pdev->name))
387 return -EBUSY;
388
389 imxdi->ioaddr = devm_ioremap(&pdev->dev, res->start,
390 resource_size(res));
391 if (imxdi->ioaddr == NULL)
392 return -ENOMEM;
393
394 imxdi->irq = platform_get_irq(pdev, 0);
395 if (imxdi->irq < 0)
396 return imxdi->irq;
397
398 init_waitqueue_head(&imxdi->write_wait);
399
400 INIT_WORK(&imxdi->work, dryice_work);
401
402 mutex_init(&imxdi->write_mutex);
403
404 imxdi->clk = clk_get(&pdev->dev, NULL);
405 if (IS_ERR(imxdi->clk))
406 return PTR_ERR(imxdi->clk);
407 clk_enable(imxdi->clk);
408
409 /*
410 * Initialize dryice hardware
411 */
412
413 /* mask all interrupts */
414 __raw_writel(0, imxdi->ioaddr + DIER);
415
416 rc = devm_request_irq(&pdev->dev, imxdi->irq, dryice_norm_irq,
417 IRQF_SHARED, pdev->name, imxdi);
418 if (rc) {
419 dev_warn(&pdev->dev, "interrupt not available.\n");
420 goto err;
421 }
422
423 /* put dryice into valid state */
424 if (__raw_readl(imxdi->ioaddr + DSR) & DSR_NVF) {
425 rc = di_write_wait(imxdi, DSR_NVF | DSR_SVF, DSR);
426 if (rc)
427 goto err;
428 }
429
430 /* initialize alarm */
431 rc = di_write_wait(imxdi, DCAMR_UNSET, DCAMR);
432 if (rc)
433 goto err;
434 rc = di_write_wait(imxdi, 0, DCALR);
435 if (rc)
436 goto err;
437
438 /* clear alarm flag */
439 if (__raw_readl(imxdi->ioaddr + DSR) & DSR_CAF) {
440 rc = di_write_wait(imxdi, DSR_CAF, DSR);
441 if (rc)
442 goto err;
443 }
444
445 /* the timer won't count if it has never been written to */
446 if (__raw_readl(imxdi->ioaddr + DTCMR) == 0) {
447 rc = di_write_wait(imxdi, 0, DTCMR);
448 if (rc)
449 goto err;
450 }
451
452 /* start keeping time */
453 if (!(__raw_readl(imxdi->ioaddr + DCR) & DCR_TCE)) {
454 rc = di_write_wait(imxdi,
455 __raw_readl(imxdi->ioaddr + DCR) | DCR_TCE,
456 DCR);
457 if (rc)
458 goto err;
459 }
460
461 platform_set_drvdata(pdev, imxdi);
462 imxdi->rtc = rtc_device_register(pdev->name, &pdev->dev,
463 &dryice_rtc_ops, THIS_MODULE);
464 if (IS_ERR(imxdi->rtc)) {
465 rc = PTR_ERR(imxdi->rtc);
466 goto err;
467 }
468
469 return 0;
470
471err:
472 clk_disable(imxdi->clk);
473 clk_put(imxdi->clk);
474
475 return rc;
476}
477
478static int __devexit dryice_rtc_remove(struct platform_device *pdev)
479{
480 struct imxdi_dev *imxdi = platform_get_drvdata(pdev);
481
482 flush_work(&imxdi->work);
483
484 /* mask all interrupts */
485 __raw_writel(0, imxdi->ioaddr + DIER);
486
487 rtc_device_unregister(imxdi->rtc);
488
489 clk_disable(imxdi->clk);
490 clk_put(imxdi->clk);
491
492 return 0;
493}
494
495static struct platform_driver dryice_rtc_driver = {
496 .driver = {
497 .name = "imxdi_rtc",
498 .owner = THIS_MODULE,
499 },
500 .remove = __devexit_p(dryice_rtc_remove),
501};
502
503static int __init dryice_rtc_init(void)
504{
505 return platform_driver_probe(&dryice_rtc_driver, dryice_rtc_probe);
506}
507
508static void __exit dryice_rtc_exit(void)
509{
510 platform_driver_unregister(&dryice_rtc_driver);
511}
512
513module_init(dryice_rtc_init);
514module_exit(dryice_rtc_exit);
515
516MODULE_AUTHOR("Freescale Semiconductor, Inc.");
517MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>");
518MODULE_DESCRIPTION("IMX DryIce Realtime Clock Driver (RTC)");
519MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
new file mode 100644
index 000000000000..ddbc797ea6cd
--- /dev/null
+++ b/drivers/rtc/rtc-isl12022.c
@@ -0,0 +1,327 @@
1/*
2 * An I2C driver for the Intersil ISL 12022
3 *
4 * Author: Roman Fietze <roman.fietze@telemotive.de>
5 *
6 * Based on the Philips PCF8563 RTC
7 * by Alessandro Zummo <a.zummo@towertech.it>.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License version
11 * 2 as published by the Free Software Foundation.
12 */
13
14#include <linux/i2c.h>
15#include <linux/bcd.h>
16#include <linux/rtc.h>
17#include <linux/slab.h>
18
19#define DRV_VERSION "0.1"
20
21/* ISL register offsets */
22#define ISL12022_REG_SC 0x00
23#define ISL12022_REG_MN 0x01
24#define ISL12022_REG_HR 0x02
25#define ISL12022_REG_DT 0x03
26#define ISL12022_REG_MO 0x04
27#define ISL12022_REG_YR 0x05
28#define ISL12022_REG_DW 0x06
29
30#define ISL12022_REG_SR 0x07
31#define ISL12022_REG_INT 0x08
32
33/* ISL register bits */
34#define ISL12022_HR_MIL (1 << 7) /* military or 24 hour time */
35
36#define ISL12022_SR_LBAT85 (1 << 2)
37#define ISL12022_SR_LBAT75 (1 << 1)
38
39#define ISL12022_INT_WRTC (1 << 6)
40
41
42static struct i2c_driver isl12022_driver;
43
44struct isl12022 {
45 struct rtc_device *rtc;
46
47 bool write_enabled; /* true if write enable is set */
48};
49
50
51static int isl12022_read_regs(struct i2c_client *client, uint8_t reg,
52 uint8_t *data, size_t n)
53{
54 struct i2c_msg msgs[] = {
55 {
56 .addr = client->addr,
57 .flags = 0,
58 .len = 1,
59 .buf = data
60 }, /* setup read ptr */
61 {
62 .addr = client->addr,
63 .flags = I2C_M_RD,
64 .len = n,
65 .buf = data
66 }
67 };
68
69 int ret;
70
71 data[0] = reg;
72 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
73 if (ret != ARRAY_SIZE(msgs)) {
74 dev_err(&client->dev, "%s: read error, ret=%d\n",
75 __func__, ret);
76 return -EIO;
77 }
78
79 return 0;
80}
81
82
83static int isl12022_write_reg(struct i2c_client *client,
84 uint8_t reg, uint8_t val)
85{
86 uint8_t data[2] = { reg, val };
87 int err;
88
89 err = i2c_master_send(client, data, sizeof(data));
90 if (err != sizeof(data)) {
91 dev_err(&client->dev,
92 "%s: err=%d addr=%02x, data=%02x\n",
93 __func__, err, data[0], data[1]);
94 return -EIO;
95 }
96
97 return 0;
98}
99
100
101/*
102 * In the routines that deal directly with the isl12022 hardware, we use
103 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
104 */
105static int isl12022_get_datetime(struct i2c_client *client, struct rtc_time *tm)
106{
107 uint8_t buf[ISL12022_REG_INT + 1];
108 int ret;
109
110 ret = isl12022_read_regs(client, ISL12022_REG_SC, buf, sizeof(buf));
111 if (ret)
112 return ret;
113
114 if (buf[ISL12022_REG_SR] & (ISL12022_SR_LBAT85 | ISL12022_SR_LBAT75)) {
115 dev_warn(&client->dev,
116 "voltage dropped below %u%%, "
117 "date and time is not reliable.\n",
118 buf[ISL12022_REG_SR] & ISL12022_SR_LBAT85 ? 85 : 75);
119 }
120
121 dev_dbg(&client->dev,
122 "%s: raw data is sec=%02x, min=%02x, hr=%02x, "
123 "mday=%02x, mon=%02x, year=%02x, wday=%02x, "
124 "sr=%02x, int=%02x",
125 __func__,
126 buf[ISL12022_REG_SC],
127 buf[ISL12022_REG_MN],
128 buf[ISL12022_REG_HR],
129 buf[ISL12022_REG_DT],
130 buf[ISL12022_REG_MO],
131 buf[ISL12022_REG_YR],
132 buf[ISL12022_REG_DW],
133 buf[ISL12022_REG_SR],
134 buf[ISL12022_REG_INT]);
135
136 tm->tm_sec = bcd2bin(buf[ISL12022_REG_SC] & 0x7F);
137 tm->tm_min = bcd2bin(buf[ISL12022_REG_MN] & 0x7F);
138 tm->tm_hour = bcd2bin(buf[ISL12022_REG_HR] & 0x3F);
139 tm->tm_mday = bcd2bin(buf[ISL12022_REG_DT] & 0x3F);
140 tm->tm_wday = buf[ISL12022_REG_DW] & 0x07;
141 tm->tm_mon = bcd2bin(buf[ISL12022_REG_MO] & 0x1F) - 1;
142 tm->tm_year = bcd2bin(buf[ISL12022_REG_YR]) + 100;
143
144 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
145 "mday=%d, mon=%d, year=%d, wday=%d\n",
146 __func__,
147 tm->tm_sec, tm->tm_min, tm->tm_hour,
148 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
149
150 /* The clock can give out invalid datetime, but we cannot return
151 * -EINVAL otherwise hwclock will refuse to set the time on bootup. */
152 if (rtc_valid_tm(tm) < 0)
153 dev_err(&client->dev, "retrieved date and time is invalid.\n");
154
155 return 0;
156}
157
158static int isl12022_set_datetime(struct i2c_client *client, struct rtc_time *tm)
159{
160 struct isl12022 *isl12022 = i2c_get_clientdata(client);
161 size_t i;
162 int ret;
163 uint8_t buf[ISL12022_REG_DW + 1];
164
165 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
166 "mday=%d, mon=%d, year=%d, wday=%d\n",
167 __func__,
168 tm->tm_sec, tm->tm_min, tm->tm_hour,
169 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
170
171 if (!isl12022->write_enabled) {
172
173 ret = isl12022_read_regs(client, ISL12022_REG_INT, buf, 1);
174 if (ret)
175 return ret;
176
177 /* Check if WRTC (write rtc enable) is set factory default is
178 * 0 (not set) */
179 if (!(buf[0] & ISL12022_INT_WRTC)) {
180 dev_info(&client->dev,
181 "init write enable and 24 hour format\n");
182
183 /* Set the write enable bit. */
184 ret = isl12022_write_reg(client,
185 ISL12022_REG_INT,
186 buf[0] | ISL12022_INT_WRTC);
187 if (ret)
188 return ret;
189
190 /* Write to any RTC register to start RTC, we use the
191 * HR register, setting the MIL bit to use the 24 hour
192 * format. */
193 ret = isl12022_read_regs(client, ISL12022_REG_HR,
194 buf, 1);
195 if (ret)
196 return ret;
197
198 ret = isl12022_write_reg(client,
199 ISL12022_REG_HR,
200 buf[0] | ISL12022_HR_MIL);
201 if (ret)
202 return ret;
203 }
204
205 isl12022->write_enabled = 1;
206 }
207
208 /* hours, minutes and seconds */
209 buf[ISL12022_REG_SC] = bin2bcd(tm->tm_sec);
210 buf[ISL12022_REG_MN] = bin2bcd(tm->tm_min);
211 buf[ISL12022_REG_HR] = bin2bcd(tm->tm_hour) | ISL12022_HR_MIL;
212
213 buf[ISL12022_REG_DT] = bin2bcd(tm->tm_mday);
214
215 /* month, 1 - 12 */
216 buf[ISL12022_REG_MO] = bin2bcd(tm->tm_mon + 1);
217
218 /* year and century */
219 buf[ISL12022_REG_YR] = bin2bcd(tm->tm_year % 100);
220
221 buf[ISL12022_REG_DW] = tm->tm_wday & 0x07;
222
223 /* write register's data */
224 for (i = 0; i < ARRAY_SIZE(buf); i++) {
225 ret = isl12022_write_reg(client, ISL12022_REG_SC + i,
226 buf[ISL12022_REG_SC + i]);
227 if (ret)
228 return -EIO;
229 };
230
231 return 0;
232}
233
234static int isl12022_rtc_read_time(struct device *dev, struct rtc_time *tm)
235{
236 return isl12022_get_datetime(to_i2c_client(dev), tm);
237}
238
239static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm)
240{
241 return isl12022_set_datetime(to_i2c_client(dev), tm);
242}
243
244static const struct rtc_class_ops isl12022_rtc_ops = {
245 .read_time = isl12022_rtc_read_time,
246 .set_time = isl12022_rtc_set_time,
247};
248
249static int isl12022_probe(struct i2c_client *client,
250 const struct i2c_device_id *id)
251{
252 struct isl12022 *isl12022;
253
254 int ret = 0;
255
256 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
257 return -ENODEV;
258
259 isl12022 = kzalloc(sizeof(struct isl12022), GFP_KERNEL);
260 if (!isl12022)
261 return -ENOMEM;
262
263 dev_dbg(&client->dev, "chip found, driver version " DRV_VERSION "\n");
264
265 i2c_set_clientdata(client, isl12022);
266
267 isl12022->rtc = rtc_device_register(isl12022_driver.driver.name,
268 &client->dev,
269 &isl12022_rtc_ops,
270 THIS_MODULE);
271
272 if (IS_ERR(isl12022->rtc)) {
273 ret = PTR_ERR(isl12022->rtc);
274 goto exit_kfree;
275 }
276
277 return 0;
278
279exit_kfree:
280 kfree(isl12022);
281
282 return ret;
283}
284
285static int isl12022_remove(struct i2c_client *client)
286{
287 struct isl12022 *isl12022 = i2c_get_clientdata(client);
288
289 rtc_device_unregister(isl12022->rtc);
290 kfree(isl12022);
291
292 return 0;
293}
294
295static const struct i2c_device_id isl12022_id[] = {
296 { "isl12022", 0 },
297 { "rtc8564", 0 },
298 { }
299};
300MODULE_DEVICE_TABLE(i2c, isl12022_id);
301
302static struct i2c_driver isl12022_driver = {
303 .driver = {
304 .name = "rtc-isl12022",
305 },
306 .probe = isl12022_probe,
307 .remove = isl12022_remove,
308 .id_table = isl12022_id,
309};
310
311static int __init isl12022_init(void)
312{
313 return i2c_add_driver(&isl12022_driver);
314}
315
316static void __exit isl12022_exit(void)
317{
318 i2c_del_driver(&isl12022_driver);
319}
320
321module_init(isl12022_init);
322module_exit(isl12022_exit);
323
324MODULE_AUTHOR("roman.fietze@telemotive.de");
325MODULE_DESCRIPTION("ISL 12022 RTC driver");
326MODULE_LICENSE("GPL");
327MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 6dc4e6241418..66377f3e28b8 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -121,7 +121,7 @@ static int m41t80_get_datetime(struct i2c_client *client,
121 121
122 /* assume 20YY not 19YY, and ignore the Century Bit */ 122 /* assume 20YY not 19YY, and ignore the Century Bit */
123 tm->tm_year = bcd2bin(buf[M41T80_REG_YEAR]) + 100; 123 tm->tm_year = bcd2bin(buf[M41T80_REG_YEAR]) + 100;
124 return 0; 124 return rtc_valid_tm(tm);
125} 125}
126 126
127/* Sets the given date and time to the real time clock. */ 127/* Sets the given date and time to the real time clock. */
@@ -364,7 +364,7 @@ static int m41t80_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *t)
364 t->time.tm_isdst = -1; 364 t->time.tm_isdst = -1;
365 t->enabled = !!(reg[M41T80_REG_ALARM_MON] & M41T80_ALMON_AFE); 365 t->enabled = !!(reg[M41T80_REG_ALARM_MON] & M41T80_ALMON_AFE);
366 t->pending = !!(reg[M41T80_REG_FLAGS] & M41T80_FLAGS_AF); 366 t->pending = !!(reg[M41T80_REG_FLAGS] & M41T80_FLAGS_AF);
367 return 0; 367 return rtc_valid_tm(t);
368} 368}
369 369
370static struct rtc_class_ops m41t80_rtc_ops = { 370static struct rtc_class_ops m41t80_rtc_ops = {
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
index be8359fdb65a..a99a0b554eb8 100644
--- a/drivers/rtc/rtc-m48t59.c
+++ b/drivers/rtc/rtc-m48t59.c
@@ -105,7 +105,7 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
105 dev_dbg(dev, "RTC read time %04d-%02d-%02d %02d/%02d/%02d\n", 105 dev_dbg(dev, "RTC read time %04d-%02d-%02d %02d/%02d/%02d\n",
106 tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, 106 tm->tm_year + 1900, tm->tm_mon, tm->tm_mday,
107 tm->tm_hour, tm->tm_min, tm->tm_sec); 107 tm->tm_hour, tm->tm_min, tm->tm_sec);
108 return 0; 108 return rtc_valid_tm(tm);
109} 109}
110 110
111static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm) 111static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -196,7 +196,7 @@ static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
196 dev_dbg(dev, "RTC read alarm time %04d-%02d-%02d %02d/%02d/%02d\n", 196 dev_dbg(dev, "RTC read alarm time %04d-%02d-%02d %02d/%02d/%02d\n",
197 tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, 197 tm->tm_year + 1900, tm->tm_mon, tm->tm_mday,
198 tm->tm_hour, tm->tm_min, tm->tm_sec); 198 tm->tm_hour, tm->tm_min, tm->tm_sec);
199 return 0; 199 return rtc_valid_tm(tm);
200} 200}
201 201
202/* 202/*
@@ -506,7 +506,6 @@ out:
506 free_irq(m48t59->irq, &pdev->dev); 506 free_irq(m48t59->irq, &pdev->dev);
507 if (m48t59->ioaddr) 507 if (m48t59->ioaddr)
508 iounmap(m48t59->ioaddr); 508 iounmap(m48t59->ioaddr);
509 if (m48t59)
510 kfree(m48t59); 509 kfree(m48t59);
511 return ret; 510 return ret;
512} 511}
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 7c045cffa9ff..f981287d582b 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -77,7 +77,7 @@ static int m48t86_rtc_read_time(struct device *dev, struct rtc_time *tm)
77 if (ops->readbyte(M48T86_REG_HOUR) & 0x80) 77 if (ops->readbyte(M48T86_REG_HOUR) & 0x80)
78 tm->tm_hour += 12; 78 tm->tm_hour += 12;
79 79
80 return 0; 80 return rtc_valid_tm(tm);
81} 81}
82 82
83static int m48t86_rtc_set_time(struct device *dev, struct rtc_time *tm) 83static int m48t86_rtc_set_time(struct device *dev, struct rtc_time *tm)
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
index a4f6665ab3c5..486142c2637a 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -159,7 +159,7 @@ static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
159 bcd2bin(regs[MAX6900_REG_CENTURY]) * 100 - 1900; 159 bcd2bin(regs[MAX6900_REG_CENTURY]) * 100 - 1900;
160 tm->tm_wday = bcd2bin(regs[MAX6900_REG_DW]); 160 tm->tm_wday = bcd2bin(regs[MAX6900_REG_DW]);
161 161
162 return 0; 162 return rtc_valid_tm(tm);
163} 163}
164 164
165static int max6900_i2c_clear_write_protect(struct i2c_client *client) 165static int max6900_i2c_clear_write_protect(struct i2c_client *client)
diff --git a/drivers/rtc/rtc-mpc5121.c b/drivers/rtc/rtc-mpc5121.c
index db5d8c416d26..dfcdf0901d21 100644
--- a/drivers/rtc/rtc-mpc5121.c
+++ b/drivers/rtc/rtc-mpc5121.c
@@ -268,7 +268,7 @@ static const struct rtc_class_ops mpc5121_rtc_ops = {
268 .update_irq_enable = mpc5121_rtc_update_irq_enable, 268 .update_irq_enable = mpc5121_rtc_update_irq_enable,
269}; 269};
270 270
271static int __devinit mpc5121_rtc_probe(struct of_device *op, 271static int __devinit mpc5121_rtc_probe(struct platform_device *op,
272 const struct of_device_id *match) 272 const struct of_device_id *match)
273{ 273{
274 struct mpc5121_rtc_data *rtc; 274 struct mpc5121_rtc_data *rtc;
@@ -338,7 +338,7 @@ out_free:
338 return err; 338 return err;
339} 339}
340 340
341static int __devexit mpc5121_rtc_remove(struct of_device *op) 341static int __devexit mpc5121_rtc_remove(struct platform_device *op)
342{ 342{
343 struct mpc5121_rtc_data *rtc = dev_get_drvdata(&op->dev); 343 struct mpc5121_rtc_data *rtc = dev_get_drvdata(&op->dev);
344 struct mpc5121_rtc_regs __iomem *regs = rtc->regs; 344 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
index 25ec921db07c..0b06c1e03fd5 100644
--- a/drivers/rtc/rtc-mxc.c
+++ b/drivers/rtc/rtc-mxc.c
@@ -83,12 +83,6 @@ struct rtc_plat_data {
83 void __iomem *ioaddr; 83 void __iomem *ioaddr;
84 int irq; 84 int irq;
85 struct clk *clk; 85 struct clk *clk;
86 unsigned int irqen;
87 int alrm_sec;
88 int alrm_min;
89 int alrm_hour;
90 int alrm_mday;
91 struct timespec mxc_rtc_delta;
92 struct rtc_time g_rtc_alarm; 86 struct rtc_time g_rtc_alarm;
93}; 87};
94 88
diff --git a/drivers/rtc/rtc-nuc900.c b/drivers/rtc/rtc-nuc900.c
index a351bd5d8176..62de66af0a68 100644
--- a/drivers/rtc/rtc-nuc900.c
+++ b/drivers/rtc/rtc-nuc900.c
@@ -85,25 +85,24 @@ static irqreturn_t nuc900_rtc_interrupt(int irq, void *_rtc)
85 85
86static int *check_rtc_access_enable(struct nuc900_rtc *nuc900_rtc) 86static int *check_rtc_access_enable(struct nuc900_rtc *nuc900_rtc)
87{ 87{
88 unsigned int i; 88 unsigned int timeout = 0x1000;
89 __raw_writel(INIRRESET, nuc900_rtc->rtc_reg + REG_RTC_INIR); 89 __raw_writel(INIRRESET, nuc900_rtc->rtc_reg + REG_RTC_INIR);
90 90
91 mdelay(10); 91 mdelay(10);
92 92
93 __raw_writel(AERPOWERON, nuc900_rtc->rtc_reg + REG_RTC_AER); 93 __raw_writel(AERPOWERON, nuc900_rtc->rtc_reg + REG_RTC_AER);
94 94
95 for (i = 0; i < 1000; i++) { 95 while (!(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_AER) & AERRWENB)
96 if (__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_AER) & AERRWENB) 96 && timeout--)
97 return 0; 97 mdelay(1);
98 }
99 98
100 if ((__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_AER) & AERRWENB) == 0x0) 99 if (!timeout)
101 return ERR_PTR(-ENODEV); 100 return ERR_PTR(-EPERM);
102 101
103 return ERR_PTR(-EPERM); 102 return 0;
104} 103}
105 104
106static void nuc900_rtc_bcd2bin(unsigned int timereg, 105static int nuc900_rtc_bcd2bin(unsigned int timereg,
107 unsigned int calreg, struct rtc_time *tm) 106 unsigned int calreg, struct rtc_time *tm)
108{ 107{
109 tm->tm_mday = bcd2bin(calreg >> 0); 108 tm->tm_mday = bcd2bin(calreg >> 0);
@@ -114,15 +113,21 @@ static void nuc900_rtc_bcd2bin(unsigned int timereg,
114 tm->tm_min = bcd2bin(timereg >> 8); 113 tm->tm_min = bcd2bin(timereg >> 8);
115 tm->tm_hour = bcd2bin(timereg >> 16); 114 tm->tm_hour = bcd2bin(timereg >> 16);
116 115
117 rtc_valid_tm(tm); 116 return rtc_valid_tm(tm);
118} 117}
119 118
120static void nuc900_rtc_bin2bcd(struct rtc_time *settm, 119static void nuc900_rtc_bin2bcd(struct device *dev, struct rtc_time *settm,
121 struct nuc900_bcd_time *gettm) 120 struct nuc900_bcd_time *gettm)
122{ 121{
123 gettm->bcd_mday = bin2bcd(settm->tm_mday) << 0; 122 gettm->bcd_mday = bin2bcd(settm->tm_mday) << 0;
124 gettm->bcd_mon = bin2bcd(settm->tm_mon) << 8; 123 gettm->bcd_mon = bin2bcd(settm->tm_mon) << 8;
125 gettm->bcd_year = bin2bcd(settm->tm_year - 100) << 16; 124
125 if (settm->tm_year < 100) {
126 dev_warn(dev, "The year will be between 1970-1999, right?\n");
127 gettm->bcd_year = bin2bcd(settm->tm_year) << 16;
128 } else {
129 gettm->bcd_year = bin2bcd(settm->tm_year - 100) << 16;
130 }
126 131
127 gettm->bcd_sec = bin2bcd(settm->tm_sec) << 0; 132 gettm->bcd_sec = bin2bcd(settm->tm_sec) << 0;
128 gettm->bcd_min = bin2bcd(settm->tm_min) << 8; 133 gettm->bcd_min = bin2bcd(settm->tm_min) << 8;
@@ -165,9 +170,7 @@ static int nuc900_rtc_read_time(struct device *dev, struct rtc_time *tm)
165 timeval = __raw_readl(rtc->rtc_reg + REG_RTC_TLR); 170 timeval = __raw_readl(rtc->rtc_reg + REG_RTC_TLR);
166 clrval = __raw_readl(rtc->rtc_reg + REG_RTC_CLR); 171 clrval = __raw_readl(rtc->rtc_reg + REG_RTC_CLR);
167 172
168 nuc900_rtc_bcd2bin(timeval, clrval, tm); 173 return nuc900_rtc_bcd2bin(timeval, clrval, tm);
169
170 return 0;
171} 174}
172 175
173static int nuc900_rtc_set_time(struct device *dev, struct rtc_time *tm) 176static int nuc900_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -177,7 +180,7 @@ static int nuc900_rtc_set_time(struct device *dev, struct rtc_time *tm)
177 unsigned long val; 180 unsigned long val;
178 int *err; 181 int *err;
179 182
180 nuc900_rtc_bin2bcd(tm, &gettm); 183 nuc900_rtc_bin2bcd(dev, tm, &gettm);
181 184
182 err = check_rtc_access_enable(rtc); 185 err = check_rtc_access_enable(rtc);
183 if (IS_ERR(err)) 186 if (IS_ERR(err))
@@ -200,9 +203,7 @@ static int nuc900_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
200 timeval = __raw_readl(rtc->rtc_reg + REG_RTC_TAR); 203 timeval = __raw_readl(rtc->rtc_reg + REG_RTC_TAR);
201 carval = __raw_readl(rtc->rtc_reg + REG_RTC_CAR); 204 carval = __raw_readl(rtc->rtc_reg + REG_RTC_CAR);
202 205
203 nuc900_rtc_bcd2bin(timeval, carval, &alrm->time); 206 return nuc900_rtc_bcd2bin(timeval, carval, &alrm->time);
204
205 return 0;
206} 207}
207 208
208static int nuc900_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 209static int nuc900_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
@@ -212,7 +213,7 @@ static int nuc900_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
212 unsigned long val; 213 unsigned long val;
213 int *err; 214 int *err;
214 215
215 nuc900_rtc_bin2bcd(&alrm->time, &tm); 216 nuc900_rtc_bin2bcd(dev, &alrm->time, &tm);
216 217
217 err = check_rtc_access_enable(rtc); 218 err = check_rtc_access_enable(rtc);
218 if (IS_ERR(err)) 219 if (IS_ERR(err))
@@ -268,29 +269,30 @@ static int __devinit nuc900_rtc_probe(struct platform_device *pdev)
268 goto fail2; 269 goto fail2;
269 } 270 }
270 271
271 nuc900_rtc->irq_num = platform_get_irq(pdev, 0); 272 platform_set_drvdata(pdev, nuc900_rtc);
272 if (request_irq(nuc900_rtc->irq_num, nuc900_rtc_interrupt,
273 IRQF_DISABLED, "nuc900rtc", nuc900_rtc)) {
274 dev_err(&pdev->dev, "NUC900 RTC request irq failed\n");
275 err = -EBUSY;
276 goto fail3;
277 }
278 273
279 nuc900_rtc->rtcdev = rtc_device_register(pdev->name, &pdev->dev, 274 nuc900_rtc->rtcdev = rtc_device_register(pdev->name, &pdev->dev,
280 &nuc900_rtc_ops, THIS_MODULE); 275 &nuc900_rtc_ops, THIS_MODULE);
281 if (IS_ERR(nuc900_rtc->rtcdev)) { 276 if (IS_ERR(nuc900_rtc->rtcdev)) {
282 dev_err(&pdev->dev, "rtc device register faild\n"); 277 dev_err(&pdev->dev, "rtc device register faild\n");
283 err = PTR_ERR(nuc900_rtc->rtcdev); 278 err = PTR_ERR(nuc900_rtc->rtcdev);
284 goto fail4; 279 goto fail3;
285 } 280 }
286 281
287 platform_set_drvdata(pdev, nuc900_rtc);
288 __raw_writel(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_TSSR) | MODE24, 282 __raw_writel(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_TSSR) | MODE24,
289 nuc900_rtc->rtc_reg + REG_RTC_TSSR); 283 nuc900_rtc->rtc_reg + REG_RTC_TSSR);
290 284
285 nuc900_rtc->irq_num = platform_get_irq(pdev, 0);
286 if (request_irq(nuc900_rtc->irq_num, nuc900_rtc_interrupt,
287 IRQF_DISABLED, "nuc900rtc", nuc900_rtc)) {
288 dev_err(&pdev->dev, "NUC900 RTC request irq failed\n");
289 err = -EBUSY;
290 goto fail4;
291 }
292
291 return 0; 293 return 0;
292 294
293fail4: free_irq(nuc900_rtc->irq_num, nuc900_rtc); 295fail4: rtc_device_unregister(nuc900_rtc->rtcdev);
294fail3: iounmap(nuc900_rtc->rtc_reg); 296fail3: iounmap(nuc900_rtc->rtc_reg);
295fail2: release_mem_region(res->start, resource_size(res)); 297fail2: release_mem_region(res->start, resource_size(res));
296fail1: kfree(nuc900_rtc); 298fail1: kfree(nuc900_rtc);
@@ -302,8 +304,8 @@ static int __devexit nuc900_rtc_remove(struct platform_device *pdev)
302 struct nuc900_rtc *nuc900_rtc = platform_get_drvdata(pdev); 304 struct nuc900_rtc *nuc900_rtc = platform_get_drvdata(pdev);
303 struct resource *res; 305 struct resource *res;
304 306
305 rtc_device_unregister(nuc900_rtc->rtcdev);
306 free_irq(nuc900_rtc->irq_num, nuc900_rtc); 307 free_irq(nuc900_rtc->irq_num, nuc900_rtc);
308 rtc_device_unregister(nuc900_rtc->rtcdev);
307 iounmap(nuc900_rtc->rtc_reg); 309 iounmap(nuc900_rtc->rtc_reg);
308 310
309 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 311 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index 1af42b4a6f59..b42c0c679266 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -172,14 +172,6 @@ static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
172 return 0; 172 return 0;
173} 173}
174 174
175struct pcf8563_limit
176{
177 unsigned char reg;
178 unsigned char mask;
179 unsigned char min;
180 unsigned char max;
181};
182
183static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm) 175static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
184{ 176{
185 return pcf8563_get_datetime(to_i2c_client(dev), tm); 177 return pcf8563_get_datetime(to_i2c_client(dev), tm);
diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c
index 71bbefc3544e..6c418fe7f288 100644
--- a/drivers/rtc/rtc-pl031.c
+++ b/drivers/rtc/rtc-pl031.c
@@ -23,7 +23,6 @@
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/bcd.h> 24#include <linux/bcd.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/version.h>
27#include <linux/slab.h> 26#include <linux/slab.h>
28 27
29/* 28/*
diff --git a/drivers/rtc/rtc-pxa.c b/drivers/rtc/rtc-pxa.c
index e9c6fa035989..29e867a1aaa8 100644
--- a/drivers/rtc/rtc-pxa.c
+++ b/drivers/rtc/rtc-pxa.c
@@ -87,7 +87,6 @@ struct pxa_rtc {
87 int irq_Alrm; 87 int irq_Alrm;
88 struct rtc_device *rtc; 88 struct rtc_device *rtc;
89 spinlock_t lock; /* Protects this structure */ 89 spinlock_t lock; /* Protects this structure */
90 struct rtc_time rtc_alarm;
91}; 90};
92 91
93static u32 ryxr_calc(struct rtc_time *tm) 92static u32 ryxr_calc(struct rtc_time *tm)
@@ -236,32 +235,34 @@ static int pxa_periodic_irq_set_state(struct device *dev, int enabled)
236 return 0; 235 return 0;
237} 236}
238 237
239static int pxa_rtc_ioctl(struct device *dev, unsigned int cmd, 238static int pxa_alarm_irq_enable(struct device *dev, unsigned int enabled)
240 unsigned long arg)
241{ 239{
242 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev); 240 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
243 int ret = 0;
244 241
245 spin_lock_irq(&pxa_rtc->lock); 242 spin_lock_irq(&pxa_rtc->lock);
246 switch (cmd) { 243
247 case RTC_AIE_OFF: 244 if (enabled)
248 rtsr_clear_bits(pxa_rtc, RTSR_RDALE1);
249 break;
250 case RTC_AIE_ON:
251 rtsr_set_bits(pxa_rtc, RTSR_RDALE1); 245 rtsr_set_bits(pxa_rtc, RTSR_RDALE1);
252 break; 246 else
253 case RTC_UIE_OFF: 247 rtsr_clear_bits(pxa_rtc, RTSR_RDALE1);
254 rtsr_clear_bits(pxa_rtc, RTSR_HZE); 248
255 break; 249 spin_unlock_irq(&pxa_rtc->lock);
256 case RTC_UIE_ON: 250 return 0;
251}
252
253static int pxa_update_irq_enable(struct device *dev, unsigned int enabled)
254{
255 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
256
257 spin_lock_irq(&pxa_rtc->lock);
258
259 if (enabled)
257 rtsr_set_bits(pxa_rtc, RTSR_HZE); 260 rtsr_set_bits(pxa_rtc, RTSR_HZE);
258 break; 261 else
259 default: 262 rtsr_clear_bits(pxa_rtc, RTSR_HZE);
260 ret = -ENOIOCTLCMD;
261 }
262 263
263 spin_unlock_irq(&pxa_rtc->lock); 264 spin_unlock_irq(&pxa_rtc->lock);
264 return ret; 265 return 0;
265} 266}
266 267
267static int pxa_rtc_read_time(struct device *dev, struct rtc_time *tm) 268static int pxa_rtc_read_time(struct device *dev, struct rtc_time *tm)
@@ -340,11 +341,12 @@ static int pxa_rtc_proc(struct device *dev, struct seq_file *seq)
340static const struct rtc_class_ops pxa_rtc_ops = { 341static const struct rtc_class_ops pxa_rtc_ops = {
341 .open = pxa_rtc_open, 342 .open = pxa_rtc_open,
342 .release = pxa_rtc_release, 343 .release = pxa_rtc_release,
343 .ioctl = pxa_rtc_ioctl,
344 .read_time = pxa_rtc_read_time, 344 .read_time = pxa_rtc_read_time,
345 .set_time = pxa_rtc_set_time, 345 .set_time = pxa_rtc_set_time,
346 .read_alarm = pxa_rtc_read_alarm, 346 .read_alarm = pxa_rtc_read_alarm,
347 .set_alarm = pxa_rtc_set_alarm, 347 .set_alarm = pxa_rtc_set_alarm,
348 .alarm_irq_enable = pxa_alarm_irq_enable,
349 .update_irq_enable = pxa_update_irq_enable,
348 .proc = pxa_rtc_proc, 350 .proc = pxa_rtc_proc,
349 .irq_set_state = pxa_periodic_irq_set_state, 351 .irq_set_state = pxa_periodic_irq_set_state,
350 .irq_set_freq = pxa_periodic_irq_set_freq, 352 .irq_set_freq = pxa_periodic_irq_set_freq,
diff --git a/drivers/rtc/rtc-rp5c01.c b/drivers/rtc/rtc-rp5c01.c
index a95f733bb15a..36eb66184461 100644
--- a/drivers/rtc/rtc-rp5c01.c
+++ b/drivers/rtc/rtc-rp5c01.c
@@ -63,6 +63,8 @@ enum {
63struct rp5c01_priv { 63struct rp5c01_priv {
64 u32 __iomem *regs; 64 u32 __iomem *regs;
65 struct rtc_device *rtc; 65 struct rtc_device *rtc;
66 spinlock_t lock; /* against concurrent RTC/NVRAM access */
67 struct bin_attribute nvram_attr;
66}; 68};
67 69
68static inline unsigned int rp5c01_read(struct rp5c01_priv *priv, 70static inline unsigned int rp5c01_read(struct rp5c01_priv *priv,
@@ -92,6 +94,7 @@ static int rp5c01_read_time(struct device *dev, struct rtc_time *tm)
92{ 94{
93 struct rp5c01_priv *priv = dev_get_drvdata(dev); 95 struct rp5c01_priv *priv = dev_get_drvdata(dev);
94 96
97 spin_lock_irq(&priv->lock);
95 rp5c01_lock(priv); 98 rp5c01_lock(priv);
96 99
97 tm->tm_sec = rp5c01_read(priv, RP5C01_10_SECOND) * 10 + 100 tm->tm_sec = rp5c01_read(priv, RP5C01_10_SECOND) * 10 +
@@ -111,6 +114,7 @@ static int rp5c01_read_time(struct device *dev, struct rtc_time *tm)
111 tm->tm_year += 100; 114 tm->tm_year += 100;
112 115
113 rp5c01_unlock(priv); 116 rp5c01_unlock(priv);
117 spin_unlock_irq(&priv->lock);
114 118
115 return rtc_valid_tm(tm); 119 return rtc_valid_tm(tm);
116} 120}
@@ -119,6 +123,7 @@ static int rp5c01_set_time(struct device *dev, struct rtc_time *tm)
119{ 123{
120 struct rp5c01_priv *priv = dev_get_drvdata(dev); 124 struct rp5c01_priv *priv = dev_get_drvdata(dev);
121 125
126 spin_lock_irq(&priv->lock);
122 rp5c01_lock(priv); 127 rp5c01_lock(priv);
123 128
124 rp5c01_write(priv, tm->tm_sec / 10, RP5C01_10_SECOND); 129 rp5c01_write(priv, tm->tm_sec / 10, RP5C01_10_SECOND);
@@ -139,6 +144,7 @@ static int rp5c01_set_time(struct device *dev, struct rtc_time *tm)
139 rp5c01_write(priv, tm->tm_year % 10, RP5C01_1_YEAR); 144 rp5c01_write(priv, tm->tm_year % 10, RP5C01_1_YEAR);
140 145
141 rp5c01_unlock(priv); 146 rp5c01_unlock(priv);
147 spin_unlock_irq(&priv->lock);
142 return 0; 148 return 0;
143} 149}
144 150
@@ -147,6 +153,72 @@ static const struct rtc_class_ops rp5c01_rtc_ops = {
147 .set_time = rp5c01_set_time, 153 .set_time = rp5c01_set_time,
148}; 154};
149 155
156
157/*
158 * The NVRAM is organized as 2 blocks of 13 nibbles of 4 bits.
159 * We provide access to them like AmigaOS does: the high nibble of each 8-bit
160 * byte is stored in BLOCK10, the low nibble in BLOCK11.
161 */
162
163static ssize_t rp5c01_nvram_read(struct file *filp, struct kobject *kobj,
164 struct bin_attribute *bin_attr,
165 char *buf, loff_t pos, size_t size)
166{
167 struct device *dev = container_of(kobj, struct device, kobj);
168 struct rp5c01_priv *priv = dev_get_drvdata(dev);
169 ssize_t count;
170
171 spin_lock_irq(&priv->lock);
172
173 for (count = 0; size > 0 && pos < RP5C01_MODE; count++, size--) {
174 u8 data;
175
176 rp5c01_write(priv,
177 RP5C01_MODE_TIMER_EN | RP5C01_MODE_RAM_BLOCK10,
178 RP5C01_MODE);
179 data = rp5c01_read(priv, pos) << 4;
180 rp5c01_write(priv,
181 RP5C01_MODE_TIMER_EN | RP5C01_MODE_RAM_BLOCK11,
182 RP5C01_MODE);
183 data |= rp5c01_read(priv, pos++);
184 rp5c01_write(priv, RP5C01_MODE_TIMER_EN | RP5C01_MODE_MODE01,
185 RP5C01_MODE);
186 *buf++ = data;
187 }
188
189 spin_unlock_irq(&priv->lock);
190 return count;
191}
192
193static ssize_t rp5c01_nvram_write(struct file *filp, struct kobject *kobj,
194 struct bin_attribute *bin_attr,
195 char *buf, loff_t pos, size_t size)
196{
197 struct device *dev = container_of(kobj, struct device, kobj);
198 struct rp5c01_priv *priv = dev_get_drvdata(dev);
199 ssize_t count;
200
201 spin_lock_irq(&priv->lock);
202
203 for (count = 0; size > 0 && pos < RP5C01_MODE; count++, size--) {
204 u8 data = *buf++;
205
206 rp5c01_write(priv,
207 RP5C01_MODE_TIMER_EN | RP5C01_MODE_RAM_BLOCK10,
208 RP5C01_MODE);
209 rp5c01_write(priv, data >> 4, pos);
210 rp5c01_write(priv,
211 RP5C01_MODE_TIMER_EN | RP5C01_MODE_RAM_BLOCK11,
212 RP5C01_MODE);
213 rp5c01_write(priv, data & 0xf, pos++);
214 rp5c01_write(priv, RP5C01_MODE_TIMER_EN | RP5C01_MODE_MODE01,
215 RP5C01_MODE);
216 }
217
218 spin_unlock_irq(&priv->lock);
219 return count;
220}
221
150static int __init rp5c01_rtc_probe(struct platform_device *dev) 222static int __init rp5c01_rtc_probe(struct platform_device *dev)
151{ 223{
152 struct resource *res; 224 struct resource *res;
@@ -168,6 +240,15 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
168 goto out_free_priv; 240 goto out_free_priv;
169 } 241 }
170 242
243 sysfs_bin_attr_init(&priv->nvram_attr);
244 priv->nvram_attr.attr.name = "nvram";
245 priv->nvram_attr.attr.mode = S_IRUGO | S_IWUSR;
246 priv->nvram_attr.read = rp5c01_nvram_read;
247 priv->nvram_attr.write = rp5c01_nvram_write;
248 priv->nvram_attr.size = RP5C01_MODE;
249
250 spin_lock_init(&priv->lock);
251
171 rtc = rtc_device_register("rtc-rp5c01", &dev->dev, &rp5c01_rtc_ops, 252 rtc = rtc_device_register("rtc-rp5c01", &dev->dev, &rp5c01_rtc_ops,
172 THIS_MODULE); 253 THIS_MODULE);
173 if (IS_ERR(rtc)) { 254 if (IS_ERR(rtc)) {
@@ -177,8 +258,15 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
177 258
178 priv->rtc = rtc; 259 priv->rtc = rtc;
179 platform_set_drvdata(dev, priv); 260 platform_set_drvdata(dev, priv);
261
262 error = sysfs_create_bin_file(&dev->dev.kobj, &priv->nvram_attr);
263 if (error)
264 goto out_unregister;
265
180 return 0; 266 return 0;
181 267
268out_unregister:
269 rtc_device_unregister(rtc);
182out_unmap: 270out_unmap:
183 iounmap(priv->regs); 271 iounmap(priv->regs);
184out_free_priv: 272out_free_priv:
@@ -190,6 +278,7 @@ static int __exit rp5c01_rtc_remove(struct platform_device *dev)
190{ 278{
191 struct rp5c01_priv *priv = platform_get_drvdata(dev); 279 struct rp5c01_priv *priv = platform_get_drvdata(dev);
192 280
281 sysfs_remove_bin_file(&dev->dev.kobj, &priv->nvram_attr);
193 rtc_device_unregister(priv->rtc); 282 rtc_device_unregister(priv->rtc);
194 iounmap(priv->regs); 283 iounmap(priv->regs);
195 kfree(priv); 284 kfree(priv);
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 70b68d35f969..a0d3ec89d412 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -1,5 +1,8 @@
1/* drivers/rtc/rtc-s3c.c 1/* drivers/rtc/rtc-s3c.c
2 * 2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
3 * Copyright (c) 2004,2006 Simtec Electronics 6 * Copyright (c) 2004,2006 Simtec Electronics
4 * Ben Dooks, <ben@simtec.co.uk> 7 * Ben Dooks, <ben@simtec.co.uk>
5 * http://armlinux.simtec.co.uk/ 8 * http://armlinux.simtec.co.uk/
@@ -39,6 +42,7 @@ enum s3c_cpu_type {
39 42
40static struct resource *s3c_rtc_mem; 43static struct resource *s3c_rtc_mem;
41 44
45static struct clk *rtc_clk;
42static void __iomem *s3c_rtc_base; 46static void __iomem *s3c_rtc_base;
43static int s3c_rtc_alarmno = NO_IRQ; 47static int s3c_rtc_alarmno = NO_IRQ;
44static int s3c_rtc_tickno = NO_IRQ; 48static int s3c_rtc_tickno = NO_IRQ;
@@ -53,6 +57,10 @@ static irqreturn_t s3c_rtc_alarmirq(int irq, void *id)
53 struct rtc_device *rdev = id; 57 struct rtc_device *rdev = id;
54 58
55 rtc_update_irq(rdev, 1, RTC_AF | RTC_IRQF); 59 rtc_update_irq(rdev, 1, RTC_AF | RTC_IRQF);
60
61 if (s3c_rtc_cpu_type == TYPE_S3C64XX)
62 writeb(S3C2410_INTP_ALM, s3c_rtc_base + S3C2410_INTP);
63
56 return IRQ_HANDLED; 64 return IRQ_HANDLED;
57} 65}
58 66
@@ -61,6 +69,10 @@ static irqreturn_t s3c_rtc_tickirq(int irq, void *id)
61 struct rtc_device *rdev = id; 69 struct rtc_device *rdev = id;
62 70
63 rtc_update_irq(rdev, 1, RTC_PF | RTC_IRQF); 71 rtc_update_irq(rdev, 1, RTC_PF | RTC_IRQF);
72
73 if (s3c_rtc_cpu_type == TYPE_S3C64XX)
74 writeb(S3C2410_INTP_TIC, s3c_rtc_base + S3C2410_INTP);
75
64 return IRQ_HANDLED; 76 return IRQ_HANDLED;
65} 77}
66 78
@@ -94,7 +106,7 @@ static int s3c_rtc_setpie(struct device *dev, int enabled)
94 if (enabled) 106 if (enabled)
95 tmp |= S3C64XX_RTCCON_TICEN; 107 tmp |= S3C64XX_RTCCON_TICEN;
96 108
97 writeb(tmp, s3c_rtc_base + S3C2410_RTCCON); 109 writew(tmp, s3c_rtc_base + S3C2410_RTCCON);
98 } else { 110 } else {
99 tmp = readb(s3c_rtc_base + S3C2410_TICNT); 111 tmp = readb(s3c_rtc_base + S3C2410_TICNT);
100 tmp &= ~S3C2410_TICNT_ENABLE; 112 tmp &= ~S3C2410_TICNT_ENABLE;
@@ -128,7 +140,7 @@ static int s3c_rtc_setfreq(struct device *dev, int freq)
128 140
129 tmp |= (rtc_dev->max_user_freq / freq)-1; 141 tmp |= (rtc_dev->max_user_freq / freq)-1;
130 142
131 writeb(tmp, s3c_rtc_base + S3C2410_TICNT); 143 writel(tmp, s3c_rtc_base + S3C2410_TICNT);
132 spin_unlock_irq(&s3c_rtc_pie_lock); 144 spin_unlock_irq(&s3c_rtc_pie_lock);
133 145
134 return 0; 146 return 0;
@@ -431,6 +443,10 @@ static int __devexit s3c_rtc_remove(struct platform_device *dev)
431 s3c_rtc_setpie(&dev->dev, 0); 443 s3c_rtc_setpie(&dev->dev, 0);
432 s3c_rtc_setaie(0); 444 s3c_rtc_setaie(0);
433 445
446 clk_disable(rtc_clk);
447 clk_put(rtc_clk);
448 rtc_clk = NULL;
449
434 iounmap(s3c_rtc_base); 450 iounmap(s3c_rtc_base);
435 release_resource(s3c_rtc_mem); 451 release_resource(s3c_rtc_mem);
436 kfree(s3c_rtc_mem); 452 kfree(s3c_rtc_mem);
@@ -442,6 +458,7 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
442{ 458{
443 struct rtc_device *rtc; 459 struct rtc_device *rtc;
444 struct resource *res; 460 struct resource *res;
461 unsigned int tmp, i;
445 int ret; 462 int ret;
446 463
447 pr_debug("%s: probe=%p\n", __func__, pdev); 464 pr_debug("%s: probe=%p\n", __func__, pdev);
@@ -488,6 +505,16 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
488 goto err_nomap; 505 goto err_nomap;
489 } 506 }
490 507
508 rtc_clk = clk_get(&pdev->dev, "rtc");
509 if (IS_ERR(rtc_clk)) {
510 dev_err(&pdev->dev, "failed to find rtc clock source\n");
511 ret = PTR_ERR(rtc_clk);
512 rtc_clk = NULL;
513 goto err_clk;
514 }
515
516 clk_enable(rtc_clk);
517
491 /* check to see if everything is setup correctly */ 518 /* check to see if everything is setup correctly */
492 519
493 s3c_rtc_enable(pdev, 1); 520 s3c_rtc_enable(pdev, 1);
@@ -510,6 +537,15 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
510 537
511 s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data; 538 s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data;
512 539
540 /* Check RTC Time */
541
542 for (i = S3C2410_RTCSEC; i <= S3C2410_RTCYEAR; i += 0x4) {
543 tmp = readb(s3c_rtc_base + i);
544
545 if ((tmp & 0xf) > 0x9 || ((tmp >> 4) & 0xf) > 0x9)
546 writeb(0, s3c_rtc_base + i);
547 }
548
513 if (s3c_rtc_cpu_type == TYPE_S3C64XX) 549 if (s3c_rtc_cpu_type == TYPE_S3C64XX)
514 rtc->max_user_freq = 32768; 550 rtc->max_user_freq = 32768;
515 else 551 else
@@ -523,6 +559,10 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
523 559
524 err_nortc: 560 err_nortc:
525 s3c_rtc_enable(pdev, 0); 561 s3c_rtc_enable(pdev, 0);
562 clk_disable(rtc_clk);
563 clk_put(rtc_clk);
564
565 err_clk:
526 iounmap(s3c_rtc_base); 566 iounmap(s3c_rtc_base);
527 567
528 err_nomap: 568 err_nomap:
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 1a84fae155e1..8373ca0de8e0 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -1325,14 +1325,14 @@ static void __dasd_device_check_expire(struct dasd_device *device)
1325 if (device->discipline->term_IO(cqr) != 0) { 1325 if (device->discipline->term_IO(cqr) != 0) {
1326 /* Hmpf, try again in 5 sec */ 1326 /* Hmpf, try again in 5 sec */
1327 dev_err(&device->cdev->dev, 1327 dev_err(&device->cdev->dev,
1328 "cqr %p timed out (%is) but cannot be " 1328 "cqr %p timed out (%lus) but cannot be "
1329 "ended, retrying in 5 s\n", 1329 "ended, retrying in 5 s\n",
1330 cqr, (cqr->expires/HZ)); 1330 cqr, (cqr->expires/HZ));
1331 cqr->expires += 5*HZ; 1331 cqr->expires += 5*HZ;
1332 dasd_device_set_timer(device, 5*HZ); 1332 dasd_device_set_timer(device, 5*HZ);
1333 } else { 1333 } else {
1334 dev_err(&device->cdev->dev, 1334 dev_err(&device->cdev->dev,
1335 "cqr %p timed out (%is), %i retries " 1335 "cqr %p timed out (%lus), %i retries "
1336 "remaining\n", cqr, (cqr->expires/HZ), 1336 "remaining\n", cqr, (cqr->expires/HZ),
1337 cqr->retries); 1337 cqr->retries);
1338 } 1338 }
diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
index a75ed3083a6a..8e4153d740f3 100644
--- a/drivers/s390/net/claw.c
+++ b/drivers/s390/net/claw.c
@@ -386,7 +386,7 @@ claw_tx(struct sk_buff *skb, struct net_device *dev)
386 struct chbk *p_ch; 386 struct chbk *p_ch;
387 387
388 CLAW_DBF_TEXT(4, trace, "claw_tx"); 388 CLAW_DBF_TEXT(4, trace, "claw_tx");
389 p_ch=&privptr->channel[WRITE]; 389 p_ch = &privptr->channel[WRITE_CHANNEL];
390 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags); 390 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
391 rc=claw_hw_tx( skb, dev, 1 ); 391 rc=claw_hw_tx( skb, dev, 1 );
392 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags); 392 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
@@ -407,7 +407,7 @@ static struct sk_buff *
407claw_pack_skb(struct claw_privbk *privptr) 407claw_pack_skb(struct claw_privbk *privptr)
408{ 408{
409 struct sk_buff *new_skb,*held_skb; 409 struct sk_buff *new_skb,*held_skb;
410 struct chbk *p_ch = &privptr->channel[WRITE]; 410 struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL];
411 struct claw_env *p_env = privptr->p_env; 411 struct claw_env *p_env = privptr->p_env;
412 int pkt_cnt,pk_ind,so_far; 412 int pkt_cnt,pk_ind,so_far;
413 413
@@ -515,15 +515,15 @@ claw_open(struct net_device *dev)
515 privptr->p_env->write_size=CLAW_FRAME_SIZE; 515 privptr->p_env->write_size=CLAW_FRAME_SIZE;
516 } 516 }
517 claw_set_busy(dev); 517 claw_set_busy(dev);
518 tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet, 518 tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet,
519 (unsigned long) &privptr->channel[READ]); 519 (unsigned long) &privptr->channel[READ_CHANNEL]);
520 for ( i = 0; i < 2; i++) { 520 for ( i = 0; i < 2; i++) {
521 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i); 521 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
522 init_waitqueue_head(&privptr->channel[i].wait); 522 init_waitqueue_head(&privptr->channel[i].wait);
523 /* skb_queue_head_init(&p_ch->io_queue); */ 523 /* skb_queue_head_init(&p_ch->io_queue); */
524 if (i == WRITE) 524 if (i == WRITE_CHANNEL)
525 skb_queue_head_init( 525 skb_queue_head_init(
526 &privptr->channel[WRITE].collect_queue); 526 &privptr->channel[WRITE_CHANNEL].collect_queue);
527 privptr->channel[i].flag_a = 0; 527 privptr->channel[i].flag_a = 0;
528 privptr->channel[i].IO_active = 0; 528 privptr->channel[i].IO_active = 0;
529 privptr->channel[i].flag &= ~CLAW_TIMER; 529 privptr->channel[i].flag &= ~CLAW_TIMER;
@@ -551,12 +551,12 @@ claw_open(struct net_device *dev)
551 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00) 551 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
552 del_timer(&timer); 552 del_timer(&timer);
553 } 553 }
554 if ((((privptr->channel[READ].last_dstat | 554 if ((((privptr->channel[READ_CHANNEL].last_dstat |
555 privptr->channel[WRITE].last_dstat) & 555 privptr->channel[WRITE_CHANNEL].last_dstat) &
556 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) || 556 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
557 (((privptr->channel[READ].flag | 557 (((privptr->channel[READ_CHANNEL].flag |
558 privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) { 558 privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) {
559 dev_info(&privptr->channel[READ].cdev->dev, 559 dev_info(&privptr->channel[READ_CHANNEL].cdev->dev,
560 "%s: remote side is not ready\n", dev->name); 560 "%s: remote side is not ready\n", dev->name);
561 CLAW_DBF_TEXT(2, trace, "notrdy"); 561 CLAW_DBF_TEXT(2, trace, "notrdy");
562 562
@@ -608,8 +608,8 @@ claw_open(struct net_device *dev)
608 } 608 }
609 } 609 }
610 privptr->buffs_alloc = 0; 610 privptr->buffs_alloc = 0;
611 privptr->channel[READ].flag= 0x00; 611 privptr->channel[READ_CHANNEL].flag = 0x00;
612 privptr->channel[WRITE].flag = 0x00; 612 privptr->channel[WRITE_CHANNEL].flag = 0x00;
613 privptr->p_buff_ccw=NULL; 613 privptr->p_buff_ccw=NULL;
614 privptr->p_buff_read=NULL; 614 privptr->p_buff_read=NULL;
615 privptr->p_buff_write=NULL; 615 privptr->p_buff_write=NULL;
@@ -652,10 +652,10 @@ claw_irq_handler(struct ccw_device *cdev,
652 } 652 }
653 653
654 /* Try to extract channel from driver data. */ 654 /* Try to extract channel from driver data. */
655 if (privptr->channel[READ].cdev == cdev) 655 if (privptr->channel[READ_CHANNEL].cdev == cdev)
656 p_ch = &privptr->channel[READ]; 656 p_ch = &privptr->channel[READ_CHANNEL];
657 else if (privptr->channel[WRITE].cdev == cdev) 657 else if (privptr->channel[WRITE_CHANNEL].cdev == cdev)
658 p_ch = &privptr->channel[WRITE]; 658 p_ch = &privptr->channel[WRITE_CHANNEL];
659 else { 659 else {
660 dev_warn(&cdev->dev, "The device is not a CLAW device\n"); 660 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
661 CLAW_DBF_TEXT(2, trace, "badchan"); 661 CLAW_DBF_TEXT(2, trace, "badchan");
@@ -813,7 +813,7 @@ claw_irq_handler(struct ccw_device *cdev,
813 claw_clearbit_busy(TB_TX, dev); 813 claw_clearbit_busy(TB_TX, dev);
814 claw_clear_busy(dev); 814 claw_clear_busy(dev);
815 } 815 }
816 p_ch_r = (struct chbk *)&privptr->channel[READ]; 816 p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL];
817 if (test_and_set_bit(CLAW_BH_ACTIVE, 817 if (test_and_set_bit(CLAW_BH_ACTIVE,
818 (void *)&p_ch_r->flag_a) == 0) 818 (void *)&p_ch_r->flag_a) == 0)
819 tasklet_schedule(&p_ch_r->tasklet); 819 tasklet_schedule(&p_ch_r->tasklet);
@@ -878,13 +878,13 @@ claw_release(struct net_device *dev)
878 for ( i = 1; i >=0 ; i--) { 878 for ( i = 1; i >=0 ; i--) {
879 spin_lock_irqsave( 879 spin_lock_irqsave(
880 get_ccwdev_lock(privptr->channel[i].cdev), saveflags); 880 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
881 /* del_timer(&privptr->channel[READ].timer); */ 881 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
882 privptr->channel[i].claw_state = CLAW_STOP; 882 privptr->channel[i].claw_state = CLAW_STOP;
883 privptr->channel[i].IO_active = 0; 883 privptr->channel[i].IO_active = 0;
884 parm = (unsigned long) &privptr->channel[i]; 884 parm = (unsigned long) &privptr->channel[i];
885 if (i == WRITE) 885 if (i == WRITE_CHANNEL)
886 claw_purge_skb_queue( 886 claw_purge_skb_queue(
887 &privptr->channel[WRITE].collect_queue); 887 &privptr->channel[WRITE_CHANNEL].collect_queue);
888 rc = ccw_device_halt (privptr->channel[i].cdev, parm); 888 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
889 if (privptr->system_validate_comp==0x00) /* never opened? */ 889 if (privptr->system_validate_comp==0x00) /* never opened? */
890 init_waitqueue_head(&privptr->channel[i].wait); 890 init_waitqueue_head(&privptr->channel[i].wait);
@@ -971,16 +971,16 @@ claw_release(struct net_device *dev)
971 privptr->mtc_skipping = 1; 971 privptr->mtc_skipping = 1;
972 privptr->mtc_offset=0; 972 privptr->mtc_offset=0;
973 973
974 if (((privptr->channel[READ].last_dstat | 974 if (((privptr->channel[READ_CHANNEL].last_dstat |
975 privptr->channel[WRITE].last_dstat) & 975 privptr->channel[WRITE_CHANNEL].last_dstat) &
976 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) { 976 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
977 dev_warn(&privptr->channel[READ].cdev->dev, 977 dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev,
978 "Deactivating %s completed with incorrect" 978 "Deactivating %s completed with incorrect"
979 " subchannel status " 979 " subchannel status "
980 "(read %02x, write %02x)\n", 980 "(read %02x, write %02x)\n",
981 dev->name, 981 dev->name,
982 privptr->channel[READ].last_dstat, 982 privptr->channel[READ_CHANNEL].last_dstat,
983 privptr->channel[WRITE].last_dstat); 983 privptr->channel[WRITE_CHANNEL].last_dstat);
984 CLAW_DBF_TEXT(2, trace, "badclose"); 984 CLAW_DBF_TEXT(2, trace, "badclose");
985 } 985 }
986 CLAW_DBF_TEXT(4, trace, "rlsexit"); 986 CLAW_DBF_TEXT(4, trace, "rlsexit");
@@ -1324,7 +1324,7 @@ claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1324 1324
1325 CLAW_DBF_TEXT(4, trace, "hw_tx"); 1325 CLAW_DBF_TEXT(4, trace, "hw_tx");
1326 privptr = (struct claw_privbk *)(dev->ml_priv); 1326 privptr = (struct claw_privbk *)(dev->ml_priv);
1327 p_ch=(struct chbk *)&privptr->channel[WRITE]; 1327 p_ch = (struct chbk *)&privptr->channel[WRITE_CHANNEL];
1328 p_env =privptr->p_env; 1328 p_env =privptr->p_env;
1329 claw_free_wrt_buf(dev); /* Clean up free chain if posible */ 1329 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1330 /* scan the write queue to free any completed write packets */ 1330 /* scan the write queue to free any completed write packets */
@@ -1357,7 +1357,7 @@ claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1357 claw_strt_out_IO(dev ); 1357 claw_strt_out_IO(dev );
1358 claw_free_wrt_buf( dev ); 1358 claw_free_wrt_buf( dev );
1359 if (privptr->write_free_count==0) { 1359 if (privptr->write_free_count==0) {
1360 ch = &privptr->channel[WRITE]; 1360 ch = &privptr->channel[WRITE_CHANNEL];
1361 atomic_inc(&skb->users); 1361 atomic_inc(&skb->users);
1362 skb_queue_tail(&ch->collect_queue, skb); 1362 skb_queue_tail(&ch->collect_queue, skb);
1363 goto Done; 1363 goto Done;
@@ -1369,7 +1369,7 @@ claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1369 } 1369 }
1370 /* tx lock */ 1370 /* tx lock */
1371 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */ 1371 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
1372 ch = &privptr->channel[WRITE]; 1372 ch = &privptr->channel[WRITE_CHANNEL];
1373 atomic_inc(&skb->users); 1373 atomic_inc(&skb->users);
1374 skb_queue_tail(&ch->collect_queue, skb); 1374 skb_queue_tail(&ch->collect_queue, skb);
1375 claw_strt_out_IO(dev ); 1375 claw_strt_out_IO(dev );
@@ -1385,7 +1385,7 @@ claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1385 privptr->p_write_free_chain == NULL ) { 1385 privptr->p_write_free_chain == NULL ) {
1386 1386
1387 claw_setbit_busy(TB_NOBUFFER,dev); 1387 claw_setbit_busy(TB_NOBUFFER,dev);
1388 ch = &privptr->channel[WRITE]; 1388 ch = &privptr->channel[WRITE_CHANNEL];
1389 atomic_inc(&skb->users); 1389 atomic_inc(&skb->users);
1390 skb_queue_tail(&ch->collect_queue, skb); 1390 skb_queue_tail(&ch->collect_queue, skb);
1391 CLAW_DBF_TEXT(2, trace, "clawbusy"); 1391 CLAW_DBF_TEXT(2, trace, "clawbusy");
@@ -1397,7 +1397,7 @@ claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1397 while (len_of_data > 0) { 1397 while (len_of_data > 0) {
1398 p_this_ccw=privptr->p_write_free_chain; /* get a block */ 1398 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1399 if (p_this_ccw == NULL) { /* lost the race */ 1399 if (p_this_ccw == NULL) { /* lost the race */
1400 ch = &privptr->channel[WRITE]; 1400 ch = &privptr->channel[WRITE_CHANNEL];
1401 atomic_inc(&skb->users); 1401 atomic_inc(&skb->users);
1402 skb_queue_tail(&ch->collect_queue, skb); 1402 skb_queue_tail(&ch->collect_queue, skb);
1403 goto Done2; 1403 goto Done2;
@@ -2067,7 +2067,7 @@ claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2067 *catch up to each other */ 2067 *catch up to each other */
2068 privptr = dev->ml_priv; 2068 privptr = dev->ml_priv;
2069 p_env=privptr->p_env; 2069 p_env=privptr->p_env;
2070 tdev = &privptr->channel[READ].cdev->dev; 2070 tdev = &privptr->channel[READ_CHANNEL].cdev->dev;
2071 memcpy( &temp_host_name, p_env->host_name, 8); 2071 memcpy( &temp_host_name, p_env->host_name, 8);
2072 memcpy( &temp_ws_name, p_env->adapter_name , 8); 2072 memcpy( &temp_ws_name, p_env->adapter_name , 8);
2073 dev_info(tdev, "%s: CLAW device %.8s: " 2073 dev_info(tdev, "%s: CLAW device %.8s: "
@@ -2245,7 +2245,7 @@ claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2245 dev->name, temp_ws_name, 2245 dev->name, temp_ws_name,
2246 p_ctlbk->linkid); 2246 p_ctlbk->linkid);
2247 privptr->active_link_ID = p_ctlbk->linkid; 2247 privptr->active_link_ID = p_ctlbk->linkid;
2248 p_ch = &privptr->channel[WRITE]; 2248 p_ch = &privptr->channel[WRITE_CHANNEL];
2249 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */ 2249 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2250 break; 2250 break;
2251 case CONNECTION_RESPONSE: 2251 case CONNECTION_RESPONSE:
@@ -2296,7 +2296,7 @@ claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2296 "%s: Confirmed Now packing\n", dev->name); 2296 "%s: Confirmed Now packing\n", dev->name);
2297 p_env->packing = DO_PACKED; 2297 p_env->packing = DO_PACKED;
2298 } 2298 }
2299 p_ch = &privptr->channel[WRITE]; 2299 p_ch = &privptr->channel[WRITE_CHANNEL];
2300 wake_up(&p_ch->wait); 2300 wake_up(&p_ch->wait);
2301 } else { 2301 } else {
2302 dev_warn(tdev, "Activating %s failed because of" 2302 dev_warn(tdev, "Activating %s failed because of"
@@ -2556,7 +2556,7 @@ unpack_read(struct net_device *dev )
2556 p_packd=NULL; 2556 p_packd=NULL;
2557 privptr = dev->ml_priv; 2557 privptr = dev->ml_priv;
2558 2558
2559 p_dev = &privptr->channel[READ].cdev->dev; 2559 p_dev = &privptr->channel[READ_CHANNEL].cdev->dev;
2560 p_env = privptr->p_env; 2560 p_env = privptr->p_env;
2561 p_this_ccw=privptr->p_read_active_first; 2561 p_this_ccw=privptr->p_read_active_first;
2562 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) { 2562 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
@@ -2728,7 +2728,7 @@ claw_strt_read (struct net_device *dev, int lock )
2728 struct ccwbk*p_ccwbk; 2728 struct ccwbk*p_ccwbk;
2729 struct chbk *p_ch; 2729 struct chbk *p_ch;
2730 struct clawh *p_clawh; 2730 struct clawh *p_clawh;
2731 p_ch=&privptr->channel[READ]; 2731 p_ch = &privptr->channel[READ_CHANNEL];
2732 2732
2733 CLAW_DBF_TEXT(4, trace, "StRdNter"); 2733 CLAW_DBF_TEXT(4, trace, "StRdNter");
2734 p_clawh=(struct clawh *)privptr->p_claw_signal_blk; 2734 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
@@ -2782,7 +2782,7 @@ claw_strt_out_IO( struct net_device *dev )
2782 return; 2782 return;
2783 } 2783 }
2784 privptr = (struct claw_privbk *)dev->ml_priv; 2784 privptr = (struct claw_privbk *)dev->ml_priv;
2785 p_ch=&privptr->channel[WRITE]; 2785 p_ch = &privptr->channel[WRITE_CHANNEL];
2786 2786
2787 CLAW_DBF_TEXT(4, trace, "strt_io"); 2787 CLAW_DBF_TEXT(4, trace, "strt_io");
2788 p_first_ccw=privptr->p_write_active_first; 2788 p_first_ccw=privptr->p_write_active_first;
@@ -2875,7 +2875,7 @@ claw_free_netdevice(struct net_device * dev, int free_dev)
2875 if (dev->flags & IFF_RUNNING) 2875 if (dev->flags & IFF_RUNNING)
2876 claw_release(dev); 2876 claw_release(dev);
2877 if (privptr) { 2877 if (privptr) {
2878 privptr->channel[READ].ndev = NULL; /* say it's free */ 2878 privptr->channel[READ_CHANNEL].ndev = NULL; /* say it's free */
2879 } 2879 }
2880 dev->ml_priv = NULL; 2880 dev->ml_priv = NULL;
2881#ifdef MODULE 2881#ifdef MODULE
@@ -2960,18 +2960,18 @@ claw_new_device(struct ccwgroup_device *cgdev)
2960 struct ccw_dev_id dev_id; 2960 struct ccw_dev_id dev_id;
2961 2961
2962 dev_info(&cgdev->dev, "add for %s\n", 2962 dev_info(&cgdev->dev, "add for %s\n",
2963 dev_name(&cgdev->cdev[READ]->dev)); 2963 dev_name(&cgdev->cdev[READ_CHANNEL]->dev));
2964 CLAW_DBF_TEXT(2, setup, "new_dev"); 2964 CLAW_DBF_TEXT(2, setup, "new_dev");
2965 privptr = dev_get_drvdata(&cgdev->dev); 2965 privptr = dev_get_drvdata(&cgdev->dev);
2966 dev_set_drvdata(&cgdev->cdev[READ]->dev, privptr); 2966 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2967 dev_set_drvdata(&cgdev->cdev[WRITE]->dev, privptr); 2967 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
2968 if (!privptr) 2968 if (!privptr)
2969 return -ENODEV; 2969 return -ENODEV;
2970 p_env = privptr->p_env; 2970 p_env = privptr->p_env;
2971 ccw_device_get_id(cgdev->cdev[READ], &dev_id); 2971 ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id);
2972 p_env->devno[READ] = dev_id.devno; 2972 p_env->devno[READ_CHANNEL] = dev_id.devno;
2973 ccw_device_get_id(cgdev->cdev[WRITE], &dev_id); 2973 ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id);
2974 p_env->devno[WRITE] = dev_id.devno; 2974 p_env->devno[WRITE_CHANNEL] = dev_id.devno;
2975 ret = add_channel(cgdev->cdev[0],0,privptr); 2975 ret = add_channel(cgdev->cdev[0],0,privptr);
2976 if (ret == 0) 2976 if (ret == 0)
2977 ret = add_channel(cgdev->cdev[1],1,privptr); 2977 ret = add_channel(cgdev->cdev[1],1,privptr);
@@ -2980,14 +2980,14 @@ claw_new_device(struct ccwgroup_device *cgdev)
2980 " failed with error code %d\n", ret); 2980 " failed with error code %d\n", ret);
2981 goto out; 2981 goto out;
2982 } 2982 }
2983 ret = ccw_device_set_online(cgdev->cdev[READ]); 2983 ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]);
2984 if (ret != 0) { 2984 if (ret != 0) {
2985 dev_warn(&cgdev->dev, 2985 dev_warn(&cgdev->dev,
2986 "Setting the read subchannel online" 2986 "Setting the read subchannel online"
2987 " failed with error code %d\n", ret); 2987 " failed with error code %d\n", ret);
2988 goto out; 2988 goto out;
2989 } 2989 }
2990 ret = ccw_device_set_online(cgdev->cdev[WRITE]); 2990 ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]);
2991 if (ret != 0) { 2991 if (ret != 0) {
2992 dev_warn(&cgdev->dev, 2992 dev_warn(&cgdev->dev,
2993 "Setting the write subchannel online " 2993 "Setting the write subchannel online "
@@ -3002,8 +3002,8 @@ claw_new_device(struct ccwgroup_device *cgdev)
3002 } 3002 }
3003 dev->ml_priv = privptr; 3003 dev->ml_priv = privptr;
3004 dev_set_drvdata(&cgdev->dev, privptr); 3004 dev_set_drvdata(&cgdev->dev, privptr);
3005 dev_set_drvdata(&cgdev->cdev[READ]->dev, privptr); 3005 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
3006 dev_set_drvdata(&cgdev->cdev[WRITE]->dev, privptr); 3006 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
3007 /* sysfs magic */ 3007 /* sysfs magic */
3008 SET_NETDEV_DEV(dev, &cgdev->dev); 3008 SET_NETDEV_DEV(dev, &cgdev->dev);
3009 if (register_netdev(dev) != 0) { 3009 if (register_netdev(dev) != 0) {
@@ -3021,16 +3021,16 @@ claw_new_device(struct ccwgroup_device *cgdev)
3021 goto out; 3021 goto out;
3022 } 3022 }
3023 } 3023 }
3024 privptr->channel[READ].ndev = dev; 3024 privptr->channel[READ_CHANNEL].ndev = dev;
3025 privptr->channel[WRITE].ndev = dev; 3025 privptr->channel[WRITE_CHANNEL].ndev = dev;
3026 privptr->p_env->ndev = dev; 3026 privptr->p_env->ndev = dev;
3027 3027
3028 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d " 3028 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
3029 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n", 3029 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
3030 dev->name, p_env->read_size, 3030 dev->name, p_env->read_size,
3031 p_env->write_size, p_env->read_buffers, 3031 p_env->write_size, p_env->read_buffers,
3032 p_env->write_buffers, p_env->devno[READ], 3032 p_env->write_buffers, p_env->devno[READ_CHANNEL],
3033 p_env->devno[WRITE]); 3033 p_env->devno[WRITE_CHANNEL]);
3034 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name " 3034 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
3035 ":%.8s api_type: %.8s\n", 3035 ":%.8s api_type: %.8s\n",
3036 dev->name, p_env->host_name, 3036 dev->name, p_env->host_name,
@@ -3072,10 +3072,10 @@ claw_shutdown_device(struct ccwgroup_device *cgdev)
3072 priv = dev_get_drvdata(&cgdev->dev); 3072 priv = dev_get_drvdata(&cgdev->dev);
3073 if (!priv) 3073 if (!priv)
3074 return -ENODEV; 3074 return -ENODEV;
3075 ndev = priv->channel[READ].ndev; 3075 ndev = priv->channel[READ_CHANNEL].ndev;
3076 if (ndev) { 3076 if (ndev) {
3077 /* Close the device */ 3077 /* Close the device */
3078 dev_info(&cgdev->dev, "%s: shutting down \n", 3078 dev_info(&cgdev->dev, "%s: shutting down\n",
3079 ndev->name); 3079 ndev->name);
3080 if (ndev->flags & IFF_RUNNING) 3080 if (ndev->flags & IFF_RUNNING)
3081 ret = claw_release(ndev); 3081 ret = claw_release(ndev);
@@ -3083,8 +3083,8 @@ claw_shutdown_device(struct ccwgroup_device *cgdev)
3083 unregister_netdev(ndev); 3083 unregister_netdev(ndev);
3084 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */ 3084 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
3085 claw_free_netdevice(ndev, 1); 3085 claw_free_netdevice(ndev, 1);
3086 priv->channel[READ].ndev = NULL; 3086 priv->channel[READ_CHANNEL].ndev = NULL;
3087 priv->channel[WRITE].ndev = NULL; 3087 priv->channel[WRITE_CHANNEL].ndev = NULL;
3088 priv->p_env->ndev = NULL; 3088 priv->p_env->ndev = NULL;
3089 } 3089 }
3090 ccw_device_set_offline(cgdev->cdev[1]); 3090 ccw_device_set_offline(cgdev->cdev[1]);
@@ -3115,8 +3115,8 @@ claw_remove_device(struct ccwgroup_device *cgdev)
3115 priv->channel[1].irb=NULL; 3115 priv->channel[1].irb=NULL;
3116 kfree(priv); 3116 kfree(priv);
3117 dev_set_drvdata(&cgdev->dev, NULL); 3117 dev_set_drvdata(&cgdev->dev, NULL);
3118 dev_set_drvdata(&cgdev->cdev[READ]->dev, NULL); 3118 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL);
3119 dev_set_drvdata(&cgdev->cdev[WRITE]->dev, NULL); 3119 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL);
3120 put_device(&cgdev->dev); 3120 put_device(&cgdev->dev);
3121 3121
3122 return; 3122 return;
diff --git a/drivers/s390/net/claw.h b/drivers/s390/net/claw.h
index 46d59a13db12..1bc5904df19f 100644
--- a/drivers/s390/net/claw.h
+++ b/drivers/s390/net/claw.h
@@ -74,8 +74,8 @@
74#define MAX_ENVELOPE_SIZE 65536 74#define MAX_ENVELOPE_SIZE 65536
75#define CLAW_DEFAULT_MTU_SIZE 4096 75#define CLAW_DEFAULT_MTU_SIZE 4096
76#define DEF_PACK_BUFSIZE 32768 76#define DEF_PACK_BUFSIZE 32768
77#define READ 0 77#define READ_CHANNEL 0
78#define WRITE 1 78#define WRITE_CHANNEL 1
79 79
80#define TB_TX 0 /* sk buffer handling in process */ 80#define TB_TX 0 /* sk buffer handling in process */
81#define TB_STOP 1 /* network device stop in process */ 81#define TB_STOP 1 /* network device stop in process */
diff --git a/drivers/s390/net/ctcm_fsms.c b/drivers/s390/net/ctcm_fsms.c
index 70eb7f138414..8c921fc3511a 100644
--- a/drivers/s390/net/ctcm_fsms.c
+++ b/drivers/s390/net/ctcm_fsms.c
@@ -454,7 +454,7 @@ static void chx_firstio(fsm_instance *fi, int event, void *arg)
454 if ((fsmstate == CTC_STATE_SETUPWAIT) && 454 if ((fsmstate == CTC_STATE_SETUPWAIT) &&
455 (ch->protocol == CTCM_PROTO_OS390)) { 455 (ch->protocol == CTCM_PROTO_OS390)) {
456 /* OS/390 resp. z/OS */ 456 /* OS/390 resp. z/OS */
457 if (CHANNEL_DIRECTION(ch->flags) == READ) { 457 if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
458 *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN; 458 *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN;
459 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, 459 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC,
460 CTC_EVENT_TIMER, ch); 460 CTC_EVENT_TIMER, ch);
@@ -472,14 +472,14 @@ static void chx_firstio(fsm_instance *fi, int event, void *arg)
472 * if in compatibility mode, since VM TCP delays the initial 472 * if in compatibility mode, since VM TCP delays the initial
473 * frame until it has some data to send. 473 * frame until it has some data to send.
474 */ 474 */
475 if ((CHANNEL_DIRECTION(ch->flags) == WRITE) || 475 if ((CHANNEL_DIRECTION(ch->flags) == CTCM_WRITE) ||
476 (ch->protocol != CTCM_PROTO_S390)) 476 (ch->protocol != CTCM_PROTO_S390))
477 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch); 477 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
478 478
479 *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN; 479 *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN;
480 ch->ccw[1].count = 2; /* Transfer only length */ 480 ch->ccw[1].count = 2; /* Transfer only length */
481 481
482 fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == READ) 482 fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
483 ? CTC_STATE_RXINIT : CTC_STATE_TXINIT); 483 ? CTC_STATE_RXINIT : CTC_STATE_TXINIT);
484 rc = ccw_device_start(ch->cdev, &ch->ccw[0], 484 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
485 (unsigned long)ch, 0xff, 0); 485 (unsigned long)ch, 0xff, 0);
@@ -495,7 +495,7 @@ static void chx_firstio(fsm_instance *fi, int event, void *arg)
495 * reply from VM TCP which brings up the RX channel to it's 495 * reply from VM TCP which brings up the RX channel to it's
496 * final state. 496 * final state.
497 */ 497 */
498 if ((CHANNEL_DIRECTION(ch->flags) == READ) && 498 if ((CHANNEL_DIRECTION(ch->flags) == CTCM_READ) &&
499 (ch->protocol == CTCM_PROTO_S390)) { 499 (ch->protocol == CTCM_PROTO_S390)) {
500 struct net_device *dev = ch->netdev; 500 struct net_device *dev = ch->netdev;
501 struct ctcm_priv *priv = dev->ml_priv; 501 struct ctcm_priv *priv = dev->ml_priv;
@@ -600,15 +600,15 @@ static void ctcm_chx_start(fsm_instance *fi, int event, void *arg)
600 int rc; 600 int rc;
601 601
602 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s): %s", 602 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s): %s",
603 CTCM_FUNTAIL, ch->id, 603 CTCM_FUNTAIL, ch->id,
604 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX"); 604 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? "RX" : "TX");
605 605
606 if (ch->trans_skb != NULL) { 606 if (ch->trans_skb != NULL) {
607 clear_normalized_cda(&ch->ccw[1]); 607 clear_normalized_cda(&ch->ccw[1]);
608 dev_kfree_skb(ch->trans_skb); 608 dev_kfree_skb(ch->trans_skb);
609 ch->trans_skb = NULL; 609 ch->trans_skb = NULL;
610 } 610 }
611 if (CHANNEL_DIRECTION(ch->flags) == READ) { 611 if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
612 ch->ccw[1].cmd_code = CCW_CMD_READ; 612 ch->ccw[1].cmd_code = CCW_CMD_READ;
613 ch->ccw[1].flags = CCW_FLAG_SLI; 613 ch->ccw[1].flags = CCW_FLAG_SLI;
614 ch->ccw[1].count = 0; 614 ch->ccw[1].count = 0;
@@ -622,7 +622,8 @@ static void ctcm_chx_start(fsm_instance *fi, int event, void *arg)
622 "%s(%s): %s trans_skb alloc delayed " 622 "%s(%s): %s trans_skb alloc delayed "
623 "until first transfer", 623 "until first transfer",
624 CTCM_FUNTAIL, ch->id, 624 CTCM_FUNTAIL, ch->id,
625 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX"); 625 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
626 "RX" : "TX");
626 } 627 }
627 ch->ccw[0].cmd_code = CCW_CMD_PREPARE; 628 ch->ccw[0].cmd_code = CCW_CMD_PREPARE;
628 ch->ccw[0].flags = CCW_FLAG_SLI | CCW_FLAG_CC; 629 ch->ccw[0].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
@@ -720,7 +721,7 @@ static void ctcm_chx_cleanup(fsm_instance *fi, int state,
720 721
721 ch->th_seg = 0x00; 722 ch->th_seg = 0x00;
722 ch->th_seq_num = 0x00; 723 ch->th_seq_num = 0x00;
723 if (CHANNEL_DIRECTION(ch->flags) == READ) { 724 if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
724 skb_queue_purge(&ch->io_queue); 725 skb_queue_purge(&ch->io_queue);
725 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev); 726 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
726 } else { 727 } else {
@@ -799,7 +800,8 @@ static void ctcm_chx_setuperr(fsm_instance *fi, int event, void *arg)
799 fsm_newstate(fi, CTC_STATE_STARTRETRY); 800 fsm_newstate(fi, CTC_STATE_STARTRETRY);
800 fsm_deltimer(&ch->timer); 801 fsm_deltimer(&ch->timer);
801 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch); 802 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
802 if (!IS_MPC(ch) && (CHANNEL_DIRECTION(ch->flags) == READ)) { 803 if (!IS_MPC(ch) &&
804 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ)) {
803 int rc = ccw_device_halt(ch->cdev, (unsigned long)ch); 805 int rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
804 if (rc != 0) 806 if (rc != 0)
805 ctcm_ccw_check_rc(ch, rc, 807 ctcm_ccw_check_rc(ch, rc,
@@ -811,10 +813,10 @@ static void ctcm_chx_setuperr(fsm_instance *fi, int event, void *arg)
811 CTCM_DBF_TEXT_(ERROR, CTC_DBF_CRIT, 813 CTCM_DBF_TEXT_(ERROR, CTC_DBF_CRIT,
812 "%s(%s) : %s error during %s channel setup state=%s\n", 814 "%s(%s) : %s error during %s channel setup state=%s\n",
813 CTCM_FUNTAIL, dev->name, ctc_ch_event_names[event], 815 CTCM_FUNTAIL, dev->name, ctc_ch_event_names[event],
814 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX", 816 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? "RX" : "TX",
815 fsm_getstate_str(fi)); 817 fsm_getstate_str(fi));
816 818
817 if (CHANNEL_DIRECTION(ch->flags) == READ) { 819 if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
818 fsm_newstate(fi, CTC_STATE_RXERR); 820 fsm_newstate(fi, CTC_STATE_RXERR);
819 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev); 821 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
820 } else { 822 } else {
@@ -945,7 +947,7 @@ static void ctcm_chx_rxdisc(fsm_instance *fi, int event, void *arg)
945 fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev); 947 fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
946 948
947 fsm_newstate(fi, CTC_STATE_DTERM); 949 fsm_newstate(fi, CTC_STATE_DTERM);
948 ch2 = priv->channel[WRITE]; 950 ch2 = priv->channel[CTCM_WRITE];
949 fsm_newstate(ch2->fsm, CTC_STATE_DTERM); 951 fsm_newstate(ch2->fsm, CTC_STATE_DTERM);
950 952
951 ccw_device_halt(ch->cdev, (unsigned long)ch); 953 ccw_device_halt(ch->cdev, (unsigned long)ch);
@@ -1074,13 +1076,13 @@ static void ctcm_chx_iofatal(fsm_instance *fi, int event, void *arg)
1074 fsm_deltimer(&ch->timer); 1076 fsm_deltimer(&ch->timer);
1075 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, 1077 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
1076 "%s: %s: %s unrecoverable channel error", 1078 "%s: %s: %s unrecoverable channel error",
1077 CTCM_FUNTAIL, ch->id, rd == READ ? "RX" : "TX"); 1079 CTCM_FUNTAIL, ch->id, rd == CTCM_READ ? "RX" : "TX");
1078 1080
1079 if (IS_MPC(ch)) { 1081 if (IS_MPC(ch)) {
1080 priv->stats.tx_dropped++; 1082 priv->stats.tx_dropped++;
1081 priv->stats.tx_errors++; 1083 priv->stats.tx_errors++;
1082 } 1084 }
1083 if (rd == READ) { 1085 if (rd == CTCM_READ) {
1084 fsm_newstate(fi, CTC_STATE_RXERR); 1086 fsm_newstate(fi, CTC_STATE_RXERR);
1085 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev); 1087 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
1086 } else { 1088 } else {
@@ -1503,7 +1505,7 @@ static void ctcmpc_chx_firstio(fsm_instance *fi, int event, void *arg)
1503 switch (fsm_getstate(fi)) { 1505 switch (fsm_getstate(fi)) {
1504 case CTC_STATE_STARTRETRY: 1506 case CTC_STATE_STARTRETRY:
1505 case CTC_STATE_SETUPWAIT: 1507 case CTC_STATE_SETUPWAIT:
1506 if (CHANNEL_DIRECTION(ch->flags) == READ) { 1508 if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
1507 ctcmpc_chx_rxidle(fi, event, arg); 1509 ctcmpc_chx_rxidle(fi, event, arg);
1508 } else { 1510 } else {
1509 fsm_newstate(fi, CTC_STATE_TXIDLE); 1511 fsm_newstate(fi, CTC_STATE_TXIDLE);
@@ -1514,7 +1516,7 @@ static void ctcmpc_chx_firstio(fsm_instance *fi, int event, void *arg)
1514 break; 1516 break;
1515 }; 1517 };
1516 1518
1517 fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == READ) 1519 fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
1518 ? CTC_STATE_RXINIT : CTC_STATE_TXINIT); 1520 ? CTC_STATE_RXINIT : CTC_STATE_TXINIT);
1519 1521
1520done: 1522done:
@@ -1753,8 +1755,8 @@ static void ctcmpc_chx_send_sweep(fsm_instance *fsm, int event, void *arg)
1753 struct net_device *dev = ach->netdev; 1755 struct net_device *dev = ach->netdev;
1754 struct ctcm_priv *priv = dev->ml_priv; 1756 struct ctcm_priv *priv = dev->ml_priv;
1755 struct mpc_group *grp = priv->mpcg; 1757 struct mpc_group *grp = priv->mpcg;
1756 struct channel *wch = priv->channel[WRITE]; 1758 struct channel *wch = priv->channel[CTCM_WRITE];
1757 struct channel *rch = priv->channel[READ]; 1759 struct channel *rch = priv->channel[CTCM_READ];
1758 struct sk_buff *skb; 1760 struct sk_buff *skb;
1759 struct th_sweep *header; 1761 struct th_sweep *header;
1760 int rc = 0; 1762 int rc = 0;
@@ -2070,7 +2072,7 @@ static void dev_action_start(fsm_instance *fi, int event, void *arg)
2070 fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX); 2072 fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
2071 if (IS_MPC(priv)) 2073 if (IS_MPC(priv))
2072 priv->mpcg->channels_terminating = 0; 2074 priv->mpcg->channels_terminating = 0;
2073 for (direction = READ; direction <= WRITE; direction++) { 2075 for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
2074 struct channel *ch = priv->channel[direction]; 2076 struct channel *ch = priv->channel[direction];
2075 fsm_event(ch->fsm, CTC_EVENT_START, ch); 2077 fsm_event(ch->fsm, CTC_EVENT_START, ch);
2076 } 2078 }
@@ -2092,7 +2094,7 @@ static void dev_action_stop(fsm_instance *fi, int event, void *arg)
2092 CTCMY_DBF_DEV_NAME(SETUP, dev, ""); 2094 CTCMY_DBF_DEV_NAME(SETUP, dev, "");
2093 2095
2094 fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX); 2096 fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
2095 for (direction = READ; direction <= WRITE; direction++) { 2097 for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
2096 struct channel *ch = priv->channel[direction]; 2098 struct channel *ch = priv->channel[direction];
2097 fsm_event(ch->fsm, CTC_EVENT_STOP, ch); 2099 fsm_event(ch->fsm, CTC_EVENT_STOP, ch);
2098 ch->th_seq_num = 0x00; 2100 ch->th_seq_num = 0x00;
@@ -2183,11 +2185,11 @@ static void dev_action_chup(fsm_instance *fi, int event, void *arg)
2183 2185
2184 if (IS_MPC(priv)) { 2186 if (IS_MPC(priv)) {
2185 if (event == DEV_EVENT_RXUP) 2187 if (event == DEV_EVENT_RXUP)
2186 mpc_channel_action(priv->channel[READ], 2188 mpc_channel_action(priv->channel[CTCM_READ],
2187 READ, MPC_CHANNEL_ADD); 2189 CTCM_READ, MPC_CHANNEL_ADD);
2188 else 2190 else
2189 mpc_channel_action(priv->channel[WRITE], 2191 mpc_channel_action(priv->channel[CTCM_WRITE],
2190 WRITE, MPC_CHANNEL_ADD); 2192 CTCM_WRITE, MPC_CHANNEL_ADD);
2191 } 2193 }
2192} 2194}
2193 2195
@@ -2239,11 +2241,11 @@ static void dev_action_chdown(fsm_instance *fi, int event, void *arg)
2239 } 2241 }
2240 if (IS_MPC(priv)) { 2242 if (IS_MPC(priv)) {
2241 if (event == DEV_EVENT_RXDOWN) 2243 if (event == DEV_EVENT_RXDOWN)
2242 mpc_channel_action(priv->channel[READ], 2244 mpc_channel_action(priv->channel[CTCM_READ],
2243 READ, MPC_CHANNEL_REMOVE); 2245 CTCM_READ, MPC_CHANNEL_REMOVE);
2244 else 2246 else
2245 mpc_channel_action(priv->channel[WRITE], 2247 mpc_channel_action(priv->channel[CTCM_WRITE],
2246 WRITE, MPC_CHANNEL_REMOVE); 2248 CTCM_WRITE, MPC_CHANNEL_REMOVE);
2247 } 2249 }
2248} 2250}
2249 2251
diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
index 4ecafbf91211..6edf20b62de5 100644
--- a/drivers/s390/net/ctcm_main.c
+++ b/drivers/s390/net/ctcm_main.c
@@ -267,7 +267,7 @@ static struct channel *channel_get(enum ctcm_channel_types type,
267 else { 267 else {
268 ch->flags |= CHANNEL_FLAGS_INUSE; 268 ch->flags |= CHANNEL_FLAGS_INUSE;
269 ch->flags &= ~CHANNEL_FLAGS_RWMASK; 269 ch->flags &= ~CHANNEL_FLAGS_RWMASK;
270 ch->flags |= (direction == WRITE) 270 ch->flags |= (direction == CTCM_WRITE)
271 ? CHANNEL_FLAGS_WRITE : CHANNEL_FLAGS_READ; 271 ? CHANNEL_FLAGS_WRITE : CHANNEL_FLAGS_READ;
272 fsm_newstate(ch->fsm, CTC_STATE_STOPPED); 272 fsm_newstate(ch->fsm, CTC_STATE_STOPPED);
273 } 273 }
@@ -388,7 +388,8 @@ int ctcm_ch_alloc_buffer(struct channel *ch)
388 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, 388 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
389 "%s(%s): %s trans_skb allocation error", 389 "%s(%s): %s trans_skb allocation error",
390 CTCM_FUNTAIL, ch->id, 390 CTCM_FUNTAIL, ch->id,
391 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX"); 391 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
392 "RX" : "TX");
392 return -ENOMEM; 393 return -ENOMEM;
393 } 394 }
394 395
@@ -399,7 +400,8 @@ int ctcm_ch_alloc_buffer(struct channel *ch)
399 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, 400 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
400 "%s(%s): %s set norm_cda failed", 401 "%s(%s): %s set norm_cda failed",
401 CTCM_FUNTAIL, ch->id, 402 CTCM_FUNTAIL, ch->id,
402 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX"); 403 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
404 "RX" : "TX");
403 return -ENOMEM; 405 return -ENOMEM;
404 } 406 }
405 407
@@ -603,14 +605,14 @@ static void ctcmpc_send_sweep_req(struct channel *rch)
603 605
604 priv = dev->ml_priv; 606 priv = dev->ml_priv;
605 grp = priv->mpcg; 607 grp = priv->mpcg;
606 ch = priv->channel[WRITE]; 608 ch = priv->channel[CTCM_WRITE];
607 609
608 /* sweep processing is not complete until response and request */ 610 /* sweep processing is not complete until response and request */
609 /* has completed for all read channels in group */ 611 /* has completed for all read channels in group */
610 if (grp->in_sweep == 0) { 612 if (grp->in_sweep == 0) {
611 grp->in_sweep = 1; 613 grp->in_sweep = 1;
612 grp->sweep_rsp_pend_num = grp->active_channels[READ]; 614 grp->sweep_rsp_pend_num = grp->active_channels[CTCM_READ];
613 grp->sweep_req_pend_num = grp->active_channels[READ]; 615 grp->sweep_req_pend_num = grp->active_channels[CTCM_READ];
614 } 616 }
615 617
616 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA); 618 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
@@ -911,7 +913,7 @@ static int ctcm_tx(struct sk_buff *skb, struct net_device *dev)
911 return NETDEV_TX_BUSY; 913 return NETDEV_TX_BUSY;
912 914
913 dev->trans_start = jiffies; 915 dev->trans_start = jiffies;
914 if (ctcm_transmit_skb(priv->channel[WRITE], skb) != 0) 916 if (ctcm_transmit_skb(priv->channel[CTCM_WRITE], skb) != 0)
915 return NETDEV_TX_BUSY; 917 return NETDEV_TX_BUSY;
916 return NETDEV_TX_OK; 918 return NETDEV_TX_OK;
917} 919}
@@ -994,7 +996,7 @@ static int ctcmpc_tx(struct sk_buff *skb, struct net_device *dev)
994 } 996 }
995 997
996 dev->trans_start = jiffies; 998 dev->trans_start = jiffies;
997 if (ctcmpc_transmit_skb(priv->channel[WRITE], skb) != 0) { 999 if (ctcmpc_transmit_skb(priv->channel[CTCM_WRITE], skb) != 0) {
998 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR, 1000 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
999 "%s(%s): device error - dropped", 1001 "%s(%s): device error - dropped",
1000 CTCM_FUNTAIL, dev->name); 1002 CTCM_FUNTAIL, dev->name);
@@ -1035,7 +1037,7 @@ static int ctcm_change_mtu(struct net_device *dev, int new_mtu)
1035 return -EINVAL; 1037 return -EINVAL;
1036 1038
1037 priv = dev->ml_priv; 1039 priv = dev->ml_priv;
1038 max_bufsize = priv->channel[READ]->max_bufsize; 1040 max_bufsize = priv->channel[CTCM_READ]->max_bufsize;
1039 1041
1040 if (IS_MPC(priv)) { 1042 if (IS_MPC(priv)) {
1041 if (new_mtu > max_bufsize - TH_HEADER_LENGTH) 1043 if (new_mtu > max_bufsize - TH_HEADER_LENGTH)
@@ -1226,10 +1228,10 @@ static void ctcm_irq_handler(struct ccw_device *cdev,
1226 priv = dev_get_drvdata(&cgdev->dev); 1228 priv = dev_get_drvdata(&cgdev->dev);
1227 1229
1228 /* Try to extract channel from driver data. */ 1230 /* Try to extract channel from driver data. */
1229 if (priv->channel[READ]->cdev == cdev) 1231 if (priv->channel[CTCM_READ]->cdev == cdev)
1230 ch = priv->channel[READ]; 1232 ch = priv->channel[CTCM_READ];
1231 else if (priv->channel[WRITE]->cdev == cdev) 1233 else if (priv->channel[CTCM_WRITE]->cdev == cdev)
1232 ch = priv->channel[WRITE]; 1234 ch = priv->channel[CTCM_WRITE];
1233 else { 1235 else {
1234 dev_err(&cdev->dev, 1236 dev_err(&cdev->dev,
1235 "%s: Internal error: Can't determine channel for " 1237 "%s: Internal error: Can't determine channel for "
@@ -1587,13 +1589,13 @@ static int ctcm_new_device(struct ccwgroup_device *cgdev)
1587 goto out_ccw2; 1589 goto out_ccw2;
1588 } 1590 }
1589 1591
1590 for (direction = READ; direction <= WRITE; direction++) { 1592 for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
1591 priv->channel[direction] = 1593 priv->channel[direction] =
1592 channel_get(type, direction == READ ? read_id : write_id, 1594 channel_get(type, direction == CTCM_READ ?
1593 direction); 1595 read_id : write_id, direction);
1594 if (priv->channel[direction] == NULL) { 1596 if (priv->channel[direction] == NULL) {
1595 if (direction == WRITE) 1597 if (direction == CTCM_WRITE)
1596 channel_free(priv->channel[READ]); 1598 channel_free(priv->channel[CTCM_READ]);
1597 goto out_dev; 1599 goto out_dev;
1598 } 1600 }
1599 priv->channel[direction]->netdev = dev; 1601 priv->channel[direction]->netdev = dev;
@@ -1617,13 +1619,13 @@ static int ctcm_new_device(struct ccwgroup_device *cgdev)
1617 1619
1618 dev_info(&dev->dev, 1620 dev_info(&dev->dev,
1619 "setup OK : r/w = %s/%s, protocol : %d\n", 1621 "setup OK : r/w = %s/%s, protocol : %d\n",
1620 priv->channel[READ]->id, 1622 priv->channel[CTCM_READ]->id,
1621 priv->channel[WRITE]->id, priv->protocol); 1623 priv->channel[CTCM_WRITE]->id, priv->protocol);
1622 1624
1623 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, 1625 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1624 "setup(%s) OK : r/w = %s/%s, protocol : %d", dev->name, 1626 "setup(%s) OK : r/w = %s/%s, protocol : %d", dev->name,
1625 priv->channel[READ]->id, 1627 priv->channel[CTCM_READ]->id,
1626 priv->channel[WRITE]->id, priv->protocol); 1628 priv->channel[CTCM_WRITE]->id, priv->protocol);
1627 1629
1628 return 0; 1630 return 0;
1629out_unregister: 1631out_unregister:
@@ -1635,10 +1637,10 @@ out_ccw2:
1635out_ccw1: 1637out_ccw1:
1636 ccw_device_set_offline(cgdev->cdev[0]); 1638 ccw_device_set_offline(cgdev->cdev[0]);
1637out_remove_channel2: 1639out_remove_channel2:
1638 readc = channel_get(type, read_id, READ); 1640 readc = channel_get(type, read_id, CTCM_READ);
1639 channel_remove(readc); 1641 channel_remove(readc);
1640out_remove_channel1: 1642out_remove_channel1:
1641 writec = channel_get(type, write_id, WRITE); 1643 writec = channel_get(type, write_id, CTCM_WRITE);
1642 channel_remove(writec); 1644 channel_remove(writec);
1643out_err_result: 1645out_err_result:
1644 return result; 1646 return result;
@@ -1660,19 +1662,19 @@ static int ctcm_shutdown_device(struct ccwgroup_device *cgdev)
1660 if (!priv) 1662 if (!priv)
1661 return -ENODEV; 1663 return -ENODEV;
1662 1664
1663 if (priv->channel[READ]) { 1665 if (priv->channel[CTCM_READ]) {
1664 dev = priv->channel[READ]->netdev; 1666 dev = priv->channel[CTCM_READ]->netdev;
1665 CTCM_DBF_DEV(SETUP, dev, ""); 1667 CTCM_DBF_DEV(SETUP, dev, "");
1666 /* Close the device */ 1668 /* Close the device */
1667 ctcm_close(dev); 1669 ctcm_close(dev);
1668 dev->flags &= ~IFF_RUNNING; 1670 dev->flags &= ~IFF_RUNNING;
1669 ctcm_remove_attributes(&cgdev->dev); 1671 ctcm_remove_attributes(&cgdev->dev);
1670 channel_free(priv->channel[READ]); 1672 channel_free(priv->channel[CTCM_READ]);
1671 } else 1673 } else
1672 dev = NULL; 1674 dev = NULL;
1673 1675
1674 if (priv->channel[WRITE]) 1676 if (priv->channel[CTCM_WRITE])
1675 channel_free(priv->channel[WRITE]); 1677 channel_free(priv->channel[CTCM_WRITE]);
1676 1678
1677 if (dev) { 1679 if (dev) {
1678 unregister_netdev(dev); 1680 unregister_netdev(dev);
@@ -1685,11 +1687,11 @@ static int ctcm_shutdown_device(struct ccwgroup_device *cgdev)
1685 ccw_device_set_offline(cgdev->cdev[1]); 1687 ccw_device_set_offline(cgdev->cdev[1]);
1686 ccw_device_set_offline(cgdev->cdev[0]); 1688 ccw_device_set_offline(cgdev->cdev[0]);
1687 1689
1688 if (priv->channel[READ]) 1690 if (priv->channel[CTCM_READ])
1689 channel_remove(priv->channel[READ]); 1691 channel_remove(priv->channel[CTCM_READ]);
1690 if (priv->channel[WRITE]) 1692 if (priv->channel[CTCM_WRITE])
1691 channel_remove(priv->channel[WRITE]); 1693 channel_remove(priv->channel[CTCM_WRITE]);
1692 priv->channel[READ] = priv->channel[WRITE] = NULL; 1694 priv->channel[CTCM_READ] = priv->channel[CTCM_WRITE] = NULL;
1693 1695
1694 return 0; 1696 return 0;
1695 1697
@@ -1720,11 +1722,11 @@ static int ctcm_pm_suspend(struct ccwgroup_device *gdev)
1720 1722
1721 if (gdev->state == CCWGROUP_OFFLINE) 1723 if (gdev->state == CCWGROUP_OFFLINE)
1722 return 0; 1724 return 0;
1723 netif_device_detach(priv->channel[READ]->netdev); 1725 netif_device_detach(priv->channel[CTCM_READ]->netdev);
1724 ctcm_close(priv->channel[READ]->netdev); 1726 ctcm_close(priv->channel[CTCM_READ]->netdev);
1725 if (!wait_event_timeout(priv->fsm->wait_q, 1727 if (!wait_event_timeout(priv->fsm->wait_q,
1726 fsm_getstate(priv->fsm) == DEV_STATE_STOPPED, CTCM_TIME_5_SEC)) { 1728 fsm_getstate(priv->fsm) == DEV_STATE_STOPPED, CTCM_TIME_5_SEC)) {
1727 netif_device_attach(priv->channel[READ]->netdev); 1729 netif_device_attach(priv->channel[CTCM_READ]->netdev);
1728 return -EBUSY; 1730 return -EBUSY;
1729 } 1731 }
1730 ccw_device_set_offline(gdev->cdev[1]); 1732 ccw_device_set_offline(gdev->cdev[1]);
@@ -1745,9 +1747,9 @@ static int ctcm_pm_resume(struct ccwgroup_device *gdev)
1745 rc = ccw_device_set_online(gdev->cdev[0]); 1747 rc = ccw_device_set_online(gdev->cdev[0]);
1746 if (rc) 1748 if (rc)
1747 goto err_out; 1749 goto err_out;
1748 ctcm_open(priv->channel[READ]->netdev); 1750 ctcm_open(priv->channel[CTCM_READ]->netdev);
1749err_out: 1751err_out:
1750 netif_device_attach(priv->channel[READ]->netdev); 1752 netif_device_attach(priv->channel[CTCM_READ]->netdev);
1751 return rc; 1753 return rc;
1752} 1754}
1753 1755
diff --git a/drivers/s390/net/ctcm_main.h b/drivers/s390/net/ctcm_main.h
index d34fa14f44e7..24d5215eb0c4 100644
--- a/drivers/s390/net/ctcm_main.h
+++ b/drivers/s390/net/ctcm_main.h
@@ -111,8 +111,8 @@ enum ctcm_channel_types {
111 111
112#define CTCM_INITIAL_BLOCKLEN 2 112#define CTCM_INITIAL_BLOCKLEN 2
113 113
114#define READ 0 114#define CTCM_READ 0
115#define WRITE 1 115#define CTCM_WRITE 1
116 116
117#define CTCM_ID_SIZE 20+3 117#define CTCM_ID_SIZE 20+3
118 118
diff --git a/drivers/s390/net/ctcm_mpc.c b/drivers/s390/net/ctcm_mpc.c
index 87c24d2936d6..2861e78773cb 100644
--- a/drivers/s390/net/ctcm_mpc.c
+++ b/drivers/s390/net/ctcm_mpc.c
@@ -419,8 +419,8 @@ void ctc_mpc_establish_connectivity(int port_num,
419 return; 419 return;
420 priv = dev->ml_priv; 420 priv = dev->ml_priv;
421 grp = priv->mpcg; 421 grp = priv->mpcg;
422 rch = priv->channel[READ]; 422 rch = priv->channel[CTCM_READ];
423 wch = priv->channel[WRITE]; 423 wch = priv->channel[CTCM_WRITE];
424 424
425 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO, 425 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
426 "%s(%s): state=%s", 426 "%s(%s): state=%s",
@@ -578,7 +578,7 @@ void ctc_mpc_flow_control(int port_num, int flowc)
578 "%s: %s: flowc = %d", 578 "%s: %s: flowc = %d",
579 CTCM_FUNTAIL, dev->name, flowc); 579 CTCM_FUNTAIL, dev->name, flowc);
580 580
581 rch = priv->channel[READ]; 581 rch = priv->channel[CTCM_READ];
582 582
583 mpcg_state = fsm_getstate(grp->fsm); 583 mpcg_state = fsm_getstate(grp->fsm);
584 switch (flowc) { 584 switch (flowc) {
@@ -622,7 +622,7 @@ static void mpc_rcvd_sweep_resp(struct mpcg_info *mpcginfo)
622 struct net_device *dev = rch->netdev; 622 struct net_device *dev = rch->netdev;
623 struct ctcm_priv *priv = dev->ml_priv; 623 struct ctcm_priv *priv = dev->ml_priv;
624 struct mpc_group *grp = priv->mpcg; 624 struct mpc_group *grp = priv->mpcg;
625 struct channel *ch = priv->channel[WRITE]; 625 struct channel *ch = priv->channel[CTCM_WRITE];
626 626
627 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, ch, ch->id); 627 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, ch, ch->id);
628 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH); 628 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
@@ -656,7 +656,7 @@ static void ctcmpc_send_sweep_resp(struct channel *rch)
656 int rc = 0; 656 int rc = 0;
657 struct th_sweep *header; 657 struct th_sweep *header;
658 struct sk_buff *sweep_skb; 658 struct sk_buff *sweep_skb;
659 struct channel *ch = priv->channel[WRITE]; 659 struct channel *ch = priv->channel[CTCM_WRITE];
660 660
661 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, rch, rch->id); 661 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, rch, rch->id);
662 662
@@ -712,7 +712,7 @@ static void mpc_rcvd_sweep_req(struct mpcg_info *mpcginfo)
712 struct net_device *dev = rch->netdev; 712 struct net_device *dev = rch->netdev;
713 struct ctcm_priv *priv = dev->ml_priv; 713 struct ctcm_priv *priv = dev->ml_priv;
714 struct mpc_group *grp = priv->mpcg; 714 struct mpc_group *grp = priv->mpcg;
715 struct channel *ch = priv->channel[WRITE]; 715 struct channel *ch = priv->channel[CTCM_WRITE];
716 716
717 if (do_debug) 717 if (do_debug)
718 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG, 718 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
@@ -721,8 +721,8 @@ static void mpc_rcvd_sweep_req(struct mpcg_info *mpcginfo)
721 if (grp->in_sweep == 0) { 721 if (grp->in_sweep == 0) {
722 grp->in_sweep = 1; 722 grp->in_sweep = 1;
723 ctcm_test_and_set_busy(dev); 723 ctcm_test_and_set_busy(dev);
724 grp->sweep_req_pend_num = grp->active_channels[READ]; 724 grp->sweep_req_pend_num = grp->active_channels[CTCM_READ];
725 grp->sweep_rsp_pend_num = grp->active_channels[READ]; 725 grp->sweep_rsp_pend_num = grp->active_channels[CTCM_READ];
726 } 726 }
727 727
728 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH); 728 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
@@ -906,14 +906,14 @@ void mpc_group_ready(unsigned long adev)
906 fsm_newstate(grp->fsm, MPCG_STATE_READY); 906 fsm_newstate(grp->fsm, MPCG_STATE_READY);
907 907
908 /* Put up a read on the channel */ 908 /* Put up a read on the channel */
909 ch = priv->channel[READ]; 909 ch = priv->channel[CTCM_READ];
910 ch->pdu_seq = 0; 910 ch->pdu_seq = 0;
911 CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" , 911 CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" ,
912 __func__, ch->pdu_seq); 912 __func__, ch->pdu_seq);
913 913
914 ctcmpc_chx_rxidle(ch->fsm, CTC_EVENT_START, ch); 914 ctcmpc_chx_rxidle(ch->fsm, CTC_EVENT_START, ch);
915 /* Put the write channel in idle state */ 915 /* Put the write channel in idle state */
916 ch = priv->channel[WRITE]; 916 ch = priv->channel[CTCM_WRITE];
917 if (ch->collect_len > 0) { 917 if (ch->collect_len > 0) {
918 spin_lock(&ch->collect_lock); 918 spin_lock(&ch->collect_lock);
919 ctcm_purge_skb_queue(&ch->collect_queue); 919 ctcm_purge_skb_queue(&ch->collect_queue);
@@ -960,7 +960,8 @@ void mpc_channel_action(struct channel *ch, int direction, int action)
960 "%s: %i / Grp:%s total_channels=%i, active_channels: " 960 "%s: %i / Grp:%s total_channels=%i, active_channels: "
961 "read=%i, write=%i\n", __func__, action, 961 "read=%i, write=%i\n", __func__, action,
962 fsm_getstate_str(grp->fsm), grp->num_channel_paths, 962 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
963 grp->active_channels[READ], grp->active_channels[WRITE]); 963 grp->active_channels[CTCM_READ],
964 grp->active_channels[CTCM_WRITE]);
964 965
965 if ((action == MPC_CHANNEL_ADD) && (ch->in_mpcgroup == 0)) { 966 if ((action == MPC_CHANNEL_ADD) && (ch->in_mpcgroup == 0)) {
966 grp->num_channel_paths++; 967 grp->num_channel_paths++;
@@ -994,10 +995,11 @@ void mpc_channel_action(struct channel *ch, int direction, int action)
994 grp->xid_skb->data, 995 grp->xid_skb->data,
995 grp->xid_skb->len); 996 grp->xid_skb->len);
996 997
997 ch->xid->xid2_dlc_type = ((CHANNEL_DIRECTION(ch->flags) == READ) 998 ch->xid->xid2_dlc_type =
999 ((CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
998 ? XID2_READ_SIDE : XID2_WRITE_SIDE); 1000 ? XID2_READ_SIDE : XID2_WRITE_SIDE);
999 1001
1000 if (CHANNEL_DIRECTION(ch->flags) == WRITE) 1002 if (CHANNEL_DIRECTION(ch->flags) == CTCM_WRITE)
1001 ch->xid->xid2_buf_len = 0x00; 1003 ch->xid->xid2_buf_len = 0x00;
1002 1004
1003 ch->xid_skb->data = ch->xid_skb_data; 1005 ch->xid_skb->data = ch->xid_skb_data;
@@ -1006,8 +1008,8 @@ void mpc_channel_action(struct channel *ch, int direction, int action)
1006 1008
1007 fsm_newstate(ch->fsm, CH_XID0_PENDING); 1009 fsm_newstate(ch->fsm, CH_XID0_PENDING);
1008 1010
1009 if ((grp->active_channels[READ] > 0) && 1011 if ((grp->active_channels[CTCM_READ] > 0) &&
1010 (grp->active_channels[WRITE] > 0) && 1012 (grp->active_channels[CTCM_WRITE] > 0) &&
1011 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) { 1013 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
1012 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW); 1014 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);
1013 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE, 1015 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
@@ -1027,10 +1029,10 @@ void mpc_channel_action(struct channel *ch, int direction, int action)
1027 if (grp->channels_terminating) 1029 if (grp->channels_terminating)
1028 goto done; 1030 goto done;
1029 1031
1030 if (((grp->active_channels[READ] == 0) && 1032 if (((grp->active_channels[CTCM_READ] == 0) &&
1031 (grp->active_channels[WRITE] > 0)) 1033 (grp->active_channels[CTCM_WRITE] > 0))
1032 || ((grp->active_channels[WRITE] == 0) && 1034 || ((grp->active_channels[CTCM_WRITE] == 0) &&
1033 (grp->active_channels[READ] > 0))) 1035 (grp->active_channels[CTCM_READ] > 0)))
1034 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev); 1036 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1035 } 1037 }
1036done: 1038done:
@@ -1038,7 +1040,8 @@ done:
1038 "exit %s: %i / Grp:%s total_channels=%i, active_channels: " 1040 "exit %s: %i / Grp:%s total_channels=%i, active_channels: "
1039 "read=%i, write=%i\n", __func__, action, 1041 "read=%i, write=%i\n", __func__, action,
1040 fsm_getstate_str(grp->fsm), grp->num_channel_paths, 1042 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
1041 grp->active_channels[READ], grp->active_channels[WRITE]); 1043 grp->active_channels[CTCM_READ],
1044 grp->active_channels[CTCM_WRITE]);
1042 1045
1043 CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__, ch, ch->id); 1046 CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
1044} 1047}
@@ -1392,8 +1395,8 @@ static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg)
1392 (grp->port_persist == 0)) 1395 (grp->port_persist == 0))
1393 fsm_deltimer(&priv->restart_timer); 1396 fsm_deltimer(&priv->restart_timer);
1394 1397
1395 wch = priv->channel[WRITE]; 1398 wch = priv->channel[CTCM_WRITE];
1396 rch = priv->channel[READ]; 1399 rch = priv->channel[CTCM_READ];
1397 1400
1398 switch (grp->saved_state) { 1401 switch (grp->saved_state) {
1399 case MPCG_STATE_RESET: 1402 case MPCG_STATE_RESET:
@@ -1480,8 +1483,8 @@ static void mpc_action_timeout(fsm_instance *fi, int event, void *arg)
1480 1483
1481 priv = dev->ml_priv; 1484 priv = dev->ml_priv;
1482 grp = priv->mpcg; 1485 grp = priv->mpcg;
1483 wch = priv->channel[WRITE]; 1486 wch = priv->channel[CTCM_WRITE];
1484 rch = priv->channel[READ]; 1487 rch = priv->channel[CTCM_READ];
1485 1488
1486 switch (fsm_getstate(grp->fsm)) { 1489 switch (fsm_getstate(grp->fsm)) {
1487 case MPCG_STATE_XID2INITW: 1490 case MPCG_STATE_XID2INITW:
@@ -1586,7 +1589,7 @@ static int mpc_validate_xid(struct mpcg_info *mpcginfo)
1586 CTCM_D3_DUMP((char *)xid, XID2_LENGTH); 1589 CTCM_D3_DUMP((char *)xid, XID2_LENGTH);
1587 1590
1588 /*the received direction should be the opposite of ours */ 1591 /*the received direction should be the opposite of ours */
1589 if (((CHANNEL_DIRECTION(ch->flags) == READ) ? XID2_WRITE_SIDE : 1592 if (((CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? XID2_WRITE_SIDE :
1590 XID2_READ_SIDE) != xid->xid2_dlc_type) { 1593 XID2_READ_SIDE) != xid->xid2_dlc_type) {
1591 rc = 2; 1594 rc = 2;
1592 /* XID REJECTED: r/w channel pairing mismatch */ 1595 /* XID REJECTED: r/w channel pairing mismatch */
@@ -1912,7 +1915,7 @@ static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg)
1912 if (grp == NULL) 1915 if (grp == NULL)
1913 return; 1916 return;
1914 1917
1915 for (direction = READ; direction <= WRITE; direction++) { 1918 for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
1916 struct channel *ch = priv->channel[direction]; 1919 struct channel *ch = priv->channel[direction];
1917 struct xid2 *thisxid = ch->xid; 1920 struct xid2 *thisxid = ch->xid;
1918 ch->xid_skb->data = ch->xid_skb_data; 1921 ch->xid_skb->data = ch->xid_skb_data;
@@ -2152,14 +2155,15 @@ static int mpc_send_qllc_discontact(struct net_device *dev)
2152 return -ENOMEM; 2155 return -ENOMEM;
2153 } 2156 }
2154 2157
2155 *((__u32 *)skb_push(skb, 4)) = priv->channel[READ]->pdu_seq; 2158 *((__u32 *)skb_push(skb, 4)) =
2156 priv->channel[READ]->pdu_seq++; 2159 priv->channel[CTCM_READ]->pdu_seq;
2160 priv->channel[CTCM_READ]->pdu_seq++;
2157 CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n", 2161 CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n",
2158 __func__, priv->channel[READ]->pdu_seq); 2162 __func__, priv->channel[CTCM_READ]->pdu_seq);
2159 2163
2160 /* receipt of CC03 resets anticipated sequence number on 2164 /* receipt of CC03 resets anticipated sequence number on
2161 receiving side */ 2165 receiving side */
2162 priv->channel[READ]->pdu_seq = 0x00; 2166 priv->channel[CTCM_READ]->pdu_seq = 0x00;
2163 skb_reset_mac_header(skb); 2167 skb_reset_mac_header(skb);
2164 skb->dev = dev; 2168 skb->dev = dev;
2165 skb->protocol = htons(ETH_P_SNAP); 2169 skb->protocol = htons(ETH_P_SNAP);
diff --git a/drivers/s390/net/ctcm_sysfs.c b/drivers/s390/net/ctcm_sysfs.c
index 2b24550e865e..8305319b2a84 100644
--- a/drivers/s390/net/ctcm_sysfs.c
+++ b/drivers/s390/net/ctcm_sysfs.c
@@ -38,8 +38,8 @@ static ssize_t ctcm_buffer_write(struct device *dev,
38 int bs1; 38 int bs1;
39 struct ctcm_priv *priv = dev_get_drvdata(dev); 39 struct ctcm_priv *priv = dev_get_drvdata(dev);
40 40
41 if (!(priv && priv->channel[READ] && 41 ndev = priv->channel[CTCM_READ]->netdev;
42 (ndev = priv->channel[READ]->netdev))) { 42 if (!(priv && priv->channel[CTCM_READ] && ndev)) {
43 CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, "bfnondev"); 43 CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, "bfnondev");
44 return -ENODEV; 44 return -ENODEV;
45 } 45 }
@@ -55,12 +55,12 @@ static ssize_t ctcm_buffer_write(struct device *dev,
55 (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2))) 55 (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2)))
56 goto einval; 56 goto einval;
57 57
58 priv->channel[READ]->max_bufsize = bs1; 58 priv->channel[CTCM_READ]->max_bufsize = bs1;
59 priv->channel[WRITE]->max_bufsize = bs1; 59 priv->channel[CTCM_WRITE]->max_bufsize = bs1;
60 if (!(ndev->flags & IFF_RUNNING)) 60 if (!(ndev->flags & IFF_RUNNING))
61 ndev->mtu = bs1 - LL_HEADER_LENGTH - 2; 61 ndev->mtu = bs1 - LL_HEADER_LENGTH - 2;
62 priv->channel[READ]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED; 62 priv->channel[CTCM_READ]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
63 priv->channel[WRITE]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED; 63 priv->channel[CTCM_WRITE]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
64 64
65 CTCM_DBF_DEV(SETUP, ndev, buf); 65 CTCM_DBF_DEV(SETUP, ndev, buf);
66 return count; 66 return count;
@@ -85,9 +85,9 @@ static void ctcm_print_statistics(struct ctcm_priv *priv)
85 p += sprintf(p, " Device FSM state: %s\n", 85 p += sprintf(p, " Device FSM state: %s\n",
86 fsm_getstate_str(priv->fsm)); 86 fsm_getstate_str(priv->fsm));
87 p += sprintf(p, " RX channel FSM state: %s\n", 87 p += sprintf(p, " RX channel FSM state: %s\n",
88 fsm_getstate_str(priv->channel[READ]->fsm)); 88 fsm_getstate_str(priv->channel[CTCM_READ]->fsm));
89 p += sprintf(p, " TX channel FSM state: %s\n", 89 p += sprintf(p, " TX channel FSM state: %s\n",
90 fsm_getstate_str(priv->channel[WRITE]->fsm)); 90 fsm_getstate_str(priv->channel[CTCM_WRITE]->fsm));
91 p += sprintf(p, " Max. TX buffer used: %ld\n", 91 p += sprintf(p, " Max. TX buffer used: %ld\n",
92 priv->channel[WRITE]->prof.maxmulti); 92 priv->channel[WRITE]->prof.maxmulti);
93 p += sprintf(p, " Max. chained SKBs: %ld\n", 93 p += sprintf(p, " Max. chained SKBs: %ld\n",
@@ -102,7 +102,7 @@ static void ctcm_print_statistics(struct ctcm_priv *priv)
102 priv->channel[WRITE]->prof.tx_time); 102 priv->channel[WRITE]->prof.tx_time);
103 103
104 printk(KERN_INFO "Statistics for %s:\n%s", 104 printk(KERN_INFO "Statistics for %s:\n%s",
105 priv->channel[WRITE]->netdev->name, sbuf); 105 priv->channel[CTCM_WRITE]->netdev->name, sbuf);
106 kfree(sbuf); 106 kfree(sbuf);
107 return; 107 return;
108} 108}
@@ -125,7 +125,7 @@ static ssize_t stats_write(struct device *dev, struct device_attribute *attr,
125 return -ENODEV; 125 return -ENODEV;
126 /* Reset statistics */ 126 /* Reset statistics */
127 memset(&priv->channel[WRITE]->prof, 0, 127 memset(&priv->channel[WRITE]->prof, 0,
128 sizeof(priv->channel[WRITE]->prof)); 128 sizeof(priv->channel[CTCM_WRITE]->prof));
129 return count; 129 return count;
130} 130}
131 131
diff --git a/drivers/sbus/char/bbc_envctrl.c b/drivers/sbus/char/bbc_envctrl.c
index 103fdf6b0b89..160e7510aca6 100644
--- a/drivers/sbus/char/bbc_envctrl.c
+++ b/drivers/sbus/char/bbc_envctrl.c
@@ -443,7 +443,7 @@ static int kenvctrld(void *__unused)
443 return 0; 443 return 0;
444} 444}
445 445
446static void attach_one_temp(struct bbc_i2c_bus *bp, struct of_device *op, 446static void attach_one_temp(struct bbc_i2c_bus *bp, struct platform_device *op,
447 int temp_idx) 447 int temp_idx)
448{ 448{
449 struct bbc_cpu_temperature *tp; 449 struct bbc_cpu_temperature *tp;
@@ -488,7 +488,7 @@ static void attach_one_temp(struct bbc_i2c_bus *bp, struct of_device *op,
488 tp->fan_todo[FAN_CPU] = FAN_SAME; 488 tp->fan_todo[FAN_CPU] = FAN_SAME;
489} 489}
490 490
491static void attach_one_fan(struct bbc_i2c_bus *bp, struct of_device *op, 491static void attach_one_fan(struct bbc_i2c_bus *bp, struct platform_device *op,
492 int fan_idx) 492 int fan_idx)
493{ 493{
494 struct bbc_fan_control *fp; 494 struct bbc_fan_control *fp;
@@ -559,7 +559,7 @@ static void destroy_all_fans(struct bbc_i2c_bus *bp)
559 559
560int bbc_envctrl_init(struct bbc_i2c_bus *bp) 560int bbc_envctrl_init(struct bbc_i2c_bus *bp)
561{ 561{
562 struct of_device *op; 562 struct platform_device *op;
563 int temp_index = 0; 563 int temp_index = 0;
564 int fan_index = 0; 564 int fan_index = 0;
565 int devidx = 0; 565 int devidx = 0;
diff --git a/drivers/sbus/char/bbc_i2c.c b/drivers/sbus/char/bbc_i2c.c
index 3e89c313e98d..614a5e114a19 100644
--- a/drivers/sbus/char/bbc_i2c.c
+++ b/drivers/sbus/char/bbc_i2c.c
@@ -51,7 +51,7 @@
51 * The second controller also connects to the smartcard reader, if present. 51 * The second controller also connects to the smartcard reader, if present.
52 */ 52 */
53 53
54static void set_device_claimage(struct bbc_i2c_bus *bp, struct of_device *op, int val) 54static void set_device_claimage(struct bbc_i2c_bus *bp, struct platform_device *op, int val)
55{ 55{
56 int i; 56 int i;
57 57
@@ -66,9 +66,9 @@ static void set_device_claimage(struct bbc_i2c_bus *bp, struct of_device *op, in
66#define claim_device(BP,ECHILD) set_device_claimage(BP,ECHILD,1) 66#define claim_device(BP,ECHILD) set_device_claimage(BP,ECHILD,1)
67#define release_device(BP,ECHILD) set_device_claimage(BP,ECHILD,0) 67#define release_device(BP,ECHILD) set_device_claimage(BP,ECHILD,0)
68 68
69struct of_device *bbc_i2c_getdev(struct bbc_i2c_bus *bp, int index) 69struct platform_device *bbc_i2c_getdev(struct bbc_i2c_bus *bp, int index)
70{ 70{
71 struct of_device *op = NULL; 71 struct platform_device *op = NULL;
72 int curidx = 0, i; 72 int curidx = 0, i;
73 73
74 for (i = 0; i < NUM_CHILDREN; i++) { 74 for (i = 0; i < NUM_CHILDREN; i++) {
@@ -86,7 +86,7 @@ out:
86 return NULL; 86 return NULL;
87} 87}
88 88
89struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct of_device *op) 89struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct platform_device *op)
90{ 90{
91 struct bbc_i2c_client *client; 91 struct bbc_i2c_client *client;
92 const u32 *reg; 92 const u32 *reg;
@@ -114,7 +114,7 @@ struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct of_device *
114void bbc_i2c_detach(struct bbc_i2c_client *client) 114void bbc_i2c_detach(struct bbc_i2c_client *client)
115{ 115{
116 struct bbc_i2c_bus *bp = client->bp; 116 struct bbc_i2c_bus *bp = client->bp;
117 struct of_device *op = client->op; 117 struct platform_device *op = client->op;
118 118
119 release_device(bp, op); 119 release_device(bp, op);
120 kfree(client); 120 kfree(client);
@@ -297,7 +297,7 @@ static void __init reset_one_i2c(struct bbc_i2c_bus *bp)
297 writeb(I2C_PCF_IDLE, bp->i2c_control_regs + 0x0); 297 writeb(I2C_PCF_IDLE, bp->i2c_control_regs + 0x0);
298} 298}
299 299
300static struct bbc_i2c_bus * __init attach_one_i2c(struct of_device *op, int index) 300static struct bbc_i2c_bus * __init attach_one_i2c(struct platform_device *op, int index)
301{ 301{
302 struct bbc_i2c_bus *bp; 302 struct bbc_i2c_bus *bp;
303 struct device_node *dp; 303 struct device_node *dp;
@@ -330,7 +330,7 @@ static struct bbc_i2c_bus * __init attach_one_i2c(struct of_device *op, int inde
330 for (dp = op->dev.of_node->child; 330 for (dp = op->dev.of_node->child;
331 dp && entry < 8; 331 dp && entry < 8;
332 dp = dp->sibling, entry++) { 332 dp = dp->sibling, entry++) {
333 struct of_device *child_op; 333 struct platform_device *child_op;
334 334
335 child_op = of_find_device_by_node(dp); 335 child_op = of_find_device_by_node(dp);
336 bp->devs[entry].device = child_op; 336 bp->devs[entry].device = child_op;
@@ -361,7 +361,7 @@ fail:
361extern int bbc_envctrl_init(struct bbc_i2c_bus *bp); 361extern int bbc_envctrl_init(struct bbc_i2c_bus *bp);
362extern void bbc_envctrl_cleanup(struct bbc_i2c_bus *bp); 362extern void bbc_envctrl_cleanup(struct bbc_i2c_bus *bp);
363 363
364static int __devinit bbc_i2c_probe(struct of_device *op, 364static int __devinit bbc_i2c_probe(struct platform_device *op,
365 const struct of_device_id *match) 365 const struct of_device_id *match)
366{ 366{
367 struct bbc_i2c_bus *bp; 367 struct bbc_i2c_bus *bp;
@@ -386,7 +386,7 @@ static int __devinit bbc_i2c_probe(struct of_device *op,
386 return err; 386 return err;
387} 387}
388 388
389static int __devexit bbc_i2c_remove(struct of_device *op) 389static int __devexit bbc_i2c_remove(struct platform_device *op)
390{ 390{
391 struct bbc_i2c_bus *bp = dev_get_drvdata(&op->dev); 391 struct bbc_i2c_bus *bp = dev_get_drvdata(&op->dev);
392 392
diff --git a/drivers/sbus/char/bbc_i2c.h b/drivers/sbus/char/bbc_i2c.h
index 83c4811b7b5e..4b4531066e75 100644
--- a/drivers/sbus/char/bbc_i2c.h
+++ b/drivers/sbus/char/bbc_i2c.h
@@ -7,7 +7,7 @@
7 7
8struct bbc_i2c_client { 8struct bbc_i2c_client {
9 struct bbc_i2c_bus *bp; 9 struct bbc_i2c_bus *bp;
10 struct of_device *op; 10 struct platform_device *op;
11 int bus; 11 int bus;
12 int address; 12 int address;
13}; 13};
@@ -64,16 +64,16 @@ struct bbc_i2c_bus {
64 struct list_head temps; 64 struct list_head temps;
65 struct list_head fans; 65 struct list_head fans;
66 66
67 struct of_device *op; 67 struct platform_device *op;
68 struct { 68 struct {
69 struct of_device *device; 69 struct platform_device *device;
70 int client_claimed; 70 int client_claimed;
71 } devs[NUM_CHILDREN]; 71 } devs[NUM_CHILDREN];
72}; 72};
73 73
74/* Probing and attachment. */ 74/* Probing and attachment. */
75extern struct of_device *bbc_i2c_getdev(struct bbc_i2c_bus *, int); 75extern struct platform_device *bbc_i2c_getdev(struct bbc_i2c_bus *, int);
76extern struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct of_device *); 76extern struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct platform_device *);
77extern void bbc_i2c_detach(struct bbc_i2c_client *); 77extern void bbc_i2c_detach(struct bbc_i2c_client *);
78 78
79/* Register read/write. NOTE: Blocking! */ 79/* Register read/write. NOTE: Blocking! */
diff --git a/drivers/sbus/char/display7seg.c b/drivers/sbus/char/display7seg.c
index 47db97583ea7..1690e53fb84a 100644
--- a/drivers/sbus/char/display7seg.c
+++ b/drivers/sbus/char/display7seg.c
@@ -170,7 +170,7 @@ static struct miscdevice d7s_miscdev = {
170 .fops = &d7s_fops 170 .fops = &d7s_fops
171}; 171};
172 172
173static int __devinit d7s_probe(struct of_device *op, 173static int __devinit d7s_probe(struct platform_device *op,
174 const struct of_device_id *match) 174 const struct of_device_id *match)
175{ 175{
176 struct device_node *opts; 176 struct device_node *opts;
@@ -236,7 +236,7 @@ out_free:
236 goto out; 236 goto out;
237} 237}
238 238
239static int __devexit d7s_remove(struct of_device *op) 239static int __devexit d7s_remove(struct platform_device *op)
240{ 240{
241 struct d7s *p = dev_get_drvdata(&op->dev); 241 struct d7s *p = dev_get_drvdata(&op->dev);
242 u8 regs = readb(p->regs); 242 u8 regs = readb(p->regs);
diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
index 3c27f45e2b6d..078e5f4520ef 100644
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -1027,7 +1027,7 @@ static int kenvctrld(void *__unused)
1027 return 0; 1027 return 0;
1028} 1028}
1029 1029
1030static int __devinit envctrl_probe(struct of_device *op, 1030static int __devinit envctrl_probe(struct platform_device *op,
1031 const struct of_device_id *match) 1031 const struct of_device_id *match)
1032{ 1032{
1033 struct device_node *dp; 1033 struct device_node *dp;
@@ -1104,7 +1104,7 @@ out_iounmap:
1104 return err; 1104 return err;
1105} 1105}
1106 1106
1107static int __devexit envctrl_remove(struct of_device *op) 1107static int __devexit envctrl_remove(struct platform_device *op)
1108{ 1108{
1109 int index; 1109 int index;
1110 1110
diff --git a/drivers/sbus/char/flash.c b/drivers/sbus/char/flash.c
index 8bb31c584b64..2b4b4b613c48 100644
--- a/drivers/sbus/char/flash.c
+++ b/drivers/sbus/char/flash.c
@@ -160,7 +160,7 @@ static const struct file_operations flash_fops = {
160 160
161static struct miscdevice flash_dev = { FLASH_MINOR, "flash", &flash_fops }; 161static struct miscdevice flash_dev = { FLASH_MINOR, "flash", &flash_fops };
162 162
163static int __devinit flash_probe(struct of_device *op, 163static int __devinit flash_probe(struct platform_device *op,
164 const struct of_device_id *match) 164 const struct of_device_id *match)
165{ 165{
166 struct device_node *dp = op->dev.of_node; 166 struct device_node *dp = op->dev.of_node;
@@ -192,7 +192,7 @@ static int __devinit flash_probe(struct of_device *op,
192 return misc_register(&flash_dev); 192 return misc_register(&flash_dev);
193} 193}
194 194
195static int __devexit flash_remove(struct of_device *op) 195static int __devexit flash_remove(struct platform_device *op)
196{ 196{
197 misc_deregister(&flash_dev); 197 misc_deregister(&flash_dev);
198 198
diff --git a/drivers/sbus/char/uctrl.c b/drivers/sbus/char/uctrl.c
index 41eb6725ff5f..1b345be5cc02 100644
--- a/drivers/sbus/char/uctrl.c
+++ b/drivers/sbus/char/uctrl.c
@@ -348,7 +348,7 @@ static void uctrl_get_external_status(struct uctrl_driver *driver)
348 348
349} 349}
350 350
351static int __devinit uctrl_probe(struct of_device *op, 351static int __devinit uctrl_probe(struct platform_device *op,
352 const struct of_device_id *match) 352 const struct of_device_id *match)
353{ 353{
354 struct uctrl_driver *p; 354 struct uctrl_driver *p;
@@ -404,7 +404,7 @@ out_free:
404 goto out; 404 goto out;
405} 405}
406 406
407static int __devexit uctrl_remove(struct of_device *op) 407static int __devexit uctrl_remove(struct platform_device *op)
408{ 408{
409 struct uctrl_driver *p = dev_get_drvdata(&op->dev); 409 struct uctrl_driver *p = dev_get_drvdata(&op->dev);
410 410
diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index 80dc3ac12cde..89fc1c8af86b 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -309,9 +309,6 @@ NCR_700_detect(struct scsi_host_template *tpnt,
309 hostdata->msgin = memory + MSGIN_OFFSET; 309 hostdata->msgin = memory + MSGIN_OFFSET;
310 hostdata->msgout = memory + MSGOUT_OFFSET; 310 hostdata->msgout = memory + MSGOUT_OFFSET;
311 hostdata->status = memory + STATUS_OFFSET; 311 hostdata->status = memory + STATUS_OFFSET;
312 /* all of these offsets are L1_CACHE_BYTES separated. It is fatal
313 * if this isn't sufficient separation to avoid dma flushing issues */
314 BUG_ON(!dma_is_consistent(hostdata->dev, pScript) && L1_CACHE_BYTES < dma_get_cache_alignment());
315 hostdata->slots = (struct NCR_700_command_slot *)(memory + SLOTS_OFFSET); 312 hostdata->slots = (struct NCR_700_command_slot *)(memory + SLOTS_OFFSET);
316 hostdata->dev = dev; 313 hostdata->dev = dev;
317 314
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 158284f05732..6466231f338b 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1853,7 +1853,7 @@ config ZFCP_DIF
1853 1853
1854config SCSI_PMCRAID 1854config SCSI_PMCRAID
1855 tristate "PMC SIERRA Linux MaxRAID adapter support" 1855 tristate "PMC SIERRA Linux MaxRAID adapter support"
1856 depends on PCI && SCSI 1856 depends on PCI && SCSI && NET
1857 ---help--- 1857 ---help---
1858 This driver supports the PMC SIERRA MaxRAID adapters. 1858 This driver supports the PMC SIERRA MaxRAID adapters.
1859 1859
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index f92da9fd5f20..5d2f148889ad 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -1857,7 +1857,9 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance, unsigned char *phase
1857#endif 1857#endif
1858 /* KLL May need eop and parity in 53c400 */ 1858 /* KLL May need eop and parity in 53c400 */
1859 if (hostdata->flags & FLAG_NCR53C400) 1859 if (hostdata->flags & FLAG_NCR53C400)
1860 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_ENABLE_PAR_CHECK | MR_ENABLE_PAR_INTR | MR_ENABLE_EOP_INTR | MR_DMA_MODE | MR_MONITOR_BSY); 1860 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE |
1861 MR_ENABLE_PAR_CHECK | MR_ENABLE_PAR_INTR |
1862 MR_ENABLE_EOP_INTR | MR_MONITOR_BSY);
1861 else 1863 else
1862 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE); 1864 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE);
1863#endif /* def REAL_DMA */ 1865#endif /* def REAL_DMA */
diff --git a/drivers/scsi/aacraid/rx.c b/drivers/scsi/aacraid/rx.c
index 04057ab72a8b..84d77fd86e5b 100644
--- a/drivers/scsi/aacraid/rx.c
+++ b/drivers/scsi/aacraid/rx.c
@@ -352,9 +352,8 @@ static int aac_rx_check_health(struct aac_dev *dev)
352 pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS), 352 pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS),
353 post, paddr); 353 post, paddr);
354 if (likely((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X')))) { 354 if (likely((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X')))) {
355 ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10); 355 ret = (hex_to_bin(buffer[2]) << 4) +
356 ret <<= 4; 356 hex_to_bin(buffer[3]);
357 ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10);
358 } 357 }
359 pci_free_consistent(dev->pdev, 512, buffer, baddr); 358 pci_free_consistent(dev->pdev, 512, buffer, baddr);
360 return ret; 359 return ret;
diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
index 24ac2315c5c7..3b7e83d2dab4 100644
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -688,9 +688,9 @@ static int asd_register_sas_ha(struct asd_ha_struct *asd_ha)
688{ 688{
689 int i; 689 int i;
690 struct asd_sas_phy **sas_phys = 690 struct asd_sas_phy **sas_phys =
691 kmalloc(ASD_MAX_PHYS * sizeof(struct asd_sas_phy), GFP_KERNEL); 691 kcalloc(ASD_MAX_PHYS, sizeof(*sas_phys), GFP_KERNEL);
692 struct asd_sas_port **sas_ports = 692 struct asd_sas_port **sas_ports =
693 kmalloc(ASD_MAX_PHYS * sizeof(struct asd_sas_port), GFP_KERNEL); 693 kcalloc(ASD_MAX_PHYS, sizeof(*sas_ports), GFP_KERNEL);
694 694
695 if (!sas_phys || !sas_ports) { 695 if (!sas_phys || !sas_ports) {
696 kfree(sas_phys); 696 kfree(sas_phys);
diff --git a/drivers/scsi/bfa/bfa_fcport.c b/drivers/scsi/bfa/bfa_fcport.c
index f0933d8d1eda..76867b5577fa 100644
--- a/drivers/scsi/bfa/bfa_fcport.c
+++ b/drivers/scsi/bfa/bfa_fcport.c
@@ -1310,7 +1310,7 @@ bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
1310 break; 1310 break;
1311 1311
1312 case BFI_FCPORT_I2H_DISABLE_RSP: 1312 case BFI_FCPORT_I2H_DISABLE_RSP:
1313 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) 1313 if (fcport->msgtag == i2hmsg.pdisable_rsp->msgtag)
1314 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP); 1314 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
1315 break; 1315 break;
1316 1316
diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
index 915a29d6c7ad..ca04cc9d332f 100644
--- a/drivers/scsi/bfa/bfad.c
+++ b/drivers/scsi/bfa/bfad.c
@@ -788,6 +788,7 @@ bfad_drv_init(struct bfad_s *bfad)
788 memset(&driver_info, 0, sizeof(driver_info)); 788 memset(&driver_info, 0, sizeof(driver_info));
789 strncpy(driver_info.version, BFAD_DRIVER_VERSION, 789 strncpy(driver_info.version, BFAD_DRIVER_VERSION,
790 sizeof(driver_info.version) - 1); 790 sizeof(driver_info.version) - 1);
791 __kernel_param_lock();
791 if (host_name) 792 if (host_name)
792 strncpy(driver_info.host_machine_name, host_name, 793 strncpy(driver_info.host_machine_name, host_name,
793 sizeof(driver_info.host_machine_name) - 1); 794 sizeof(driver_info.host_machine_name) - 1);
@@ -797,6 +798,7 @@ bfad_drv_init(struct bfad_s *bfad)
797 if (os_patch) 798 if (os_patch)
798 strncpy(driver_info.host_os_patch, os_patch, 799 strncpy(driver_info.host_os_patch, os_patch,
799 sizeof(driver_info.host_os_patch) - 1); 800 sizeof(driver_info.host_os_patch) - 1);
801 __kernel_param_unlock();
800 802
801 strncpy(driver_info.os_device_name, bfad->pci_name, 803 strncpy(driver_info.os_device_name, bfad->pci_name,
802 sizeof(driver_info.os_device_name - 1)); 804 sizeof(driver_info.os_device_name - 1));
diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
index 678120b70460..6ef87f6fcdbb 100644
--- a/drivers/scsi/bfa/bfad_im.c
+++ b/drivers/scsi/bfa/bfad_im.c
@@ -291,7 +291,7 @@ bfad_im_reset_lun_handler(struct scsi_cmnd *cmnd)
291 struct bfa_tskim_s *tskim; 291 struct bfa_tskim_s *tskim;
292 struct bfad_itnim_s *itnim; 292 struct bfad_itnim_s *itnim;
293 struct bfa_itnim_s *bfa_itnim; 293 struct bfa_itnim_s *bfa_itnim;
294 DECLARE_WAIT_QUEUE_HEAD(wq); 294 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
295 int rc = SUCCESS; 295 int rc = SUCCESS;
296 unsigned long flags; 296 unsigned long flags;
297 enum bfi_tskim_status task_status; 297 enum bfi_tskim_status task_status;
@@ -353,7 +353,7 @@ bfad_im_reset_bus_handler(struct scsi_cmnd *cmnd)
353 struct bfad_itnim_s *itnim; 353 struct bfad_itnim_s *itnim;
354 unsigned long flags; 354 unsigned long flags;
355 u32 i, rc, err_cnt = 0; 355 u32 i, rc, err_cnt = 0;
356 DECLARE_WAIT_QUEUE_HEAD(wq); 356 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
357 enum bfi_tskim_status task_status; 357 enum bfi_tskim_status task_status;
358 358
359 spin_lock_irqsave(&bfad->bfad_lock, flags); 359 spin_lock_irqsave(&bfad->bfad_lock, flags);
diff --git a/drivers/scsi/bfa/include/protocol/fcp.h b/drivers/scsi/bfa/include/protocol/fcp.h
index 9ade68ad2853..74ea63ce84b7 100644
--- a/drivers/scsi/bfa/include/protocol/fcp.h
+++ b/drivers/scsi/bfa/include/protocol/fcp.h
@@ -18,6 +18,7 @@
18#ifndef __FCPPROTO_H__ 18#ifndef __FCPPROTO_H__
19#define __FCPPROTO_H__ 19#define __FCPPROTO_H__
20 20
21#include <linux/bitops.h>
21#include <protocol/scsi.h> 22#include <protocol/scsi.h>
22 23
23#pragma pack(1) 24#pragma pack(1)
@@ -102,9 +103,6 @@ enum {
102/* 103/*
103 * Task management flags field - only one bit shall be set 104 * Task management flags field - only one bit shall be set
104 */ 105 */
105#ifndef BIT
106#define BIT(_x) (1 << (_x))
107#endif
108enum fcp_tm_cmnd{ 106enum fcp_tm_cmnd{
109 FCP_TM_ABORT_TASK_SET = BIT(1), 107 FCP_TM_ABORT_TASK_SET = BIT(1),
110 FCP_TM_CLEAR_TASK_SET = BIT(2), 108 FCP_TM_CLEAR_TASK_SET = BIT(2),
diff --git a/drivers/scsi/bnx2i/Kconfig b/drivers/scsi/bnx2i/Kconfig
index 1e9f7141102b..45a6154ce972 100644
--- a/drivers/scsi/bnx2i/Kconfig
+++ b/drivers/scsi/bnx2i/Kconfig
@@ -1,10 +1,11 @@
1config SCSI_BNX2_ISCSI 1config SCSI_BNX2_ISCSI
2 tristate "Broadcom NetXtreme II iSCSI support" 2 tristate "Broadcom NetXtreme II iSCSI support"
3 depends on NET
4 depends on PCI
3 select SCSI_ISCSI_ATTRS 5 select SCSI_ISCSI_ATTRS
4 select NETDEVICES 6 select NETDEVICES
5 select NETDEV_1000 7 select NETDEV_1000
6 select CNIC 8 select CNIC
7 depends on PCI
8 ---help--- 9 ---help---
9 This driver supports iSCSI offload for the Broadcom NetXtreme II 10 This driver supports iSCSI offload for the Broadcom NetXtreme II
10 devices. 11 devices.
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index 4799d4391203..d6532187f616 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -84,10 +84,16 @@ static const char * vendor_labels[CH_TYPES-4] = {
84}; 84};
85// module_param_string_array(vendor_labels, NULL, 0444); 85// module_param_string_array(vendor_labels, NULL, 0444);
86 86
87#define dprintk(fmt, arg...) if (debug) \ 87#define DPRINTK(fmt, arg...) \
88 printk(KERN_DEBUG "%s: " fmt, ch->name , ## arg) 88do { \
89#define vprintk(fmt, arg...) if (verbose) \ 89 if (debug) \
90 printk(KERN_INFO "%s: " fmt, ch->name , ## arg) 90 printk(KERN_DEBUG "%s: " fmt, ch->name, ##arg); \
91} while (0)
92#define VPRINTK(level, fmt, arg...) \
93do { \
94 if (verbose) \
95 printk(level "%s: " fmt, ch->name, ##arg); \
96} while (0)
91 97
92/* ------------------------------------------------------------------- */ 98/* ------------------------------------------------------------------- */
93 99
@@ -186,7 +192,7 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
186 retry: 192 retry:
187 errno = 0; 193 errno = 0;
188 if (debug) { 194 if (debug) {
189 dprintk("command: "); 195 DPRINTK("command: ");
190 __scsi_print_command(cmd); 196 __scsi_print_command(cmd);
191 } 197 }
192 198
@@ -194,7 +200,7 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
194 buflength, &sshdr, timeout * HZ, 200 buflength, &sshdr, timeout * HZ,
195 MAX_RETRIES, NULL); 201 MAX_RETRIES, NULL);
196 202
197 dprintk("result: 0x%x\n",result); 203 DPRINTK("result: 0x%x\n",result);
198 if (driver_byte(result) & DRIVER_SENSE) { 204 if (driver_byte(result) & DRIVER_SENSE) {
199 if (debug) 205 if (debug)
200 scsi_print_sense_hdr(ch->name, &sshdr); 206 scsi_print_sense_hdr(ch->name, &sshdr);
@@ -250,7 +256,7 @@ ch_read_element_status(scsi_changer *ch, u_int elem, char *data)
250 cmd[9] = 255; 256 cmd[9] = 255;
251 if (0 == (result = ch_do_scsi(ch, cmd, buffer, 256, DMA_FROM_DEVICE))) { 257 if (0 == (result = ch_do_scsi(ch, cmd, buffer, 256, DMA_FROM_DEVICE))) {
252 if (((buffer[16] << 8) | buffer[17]) != elem) { 258 if (((buffer[16] << 8) | buffer[17]) != elem) {
253 dprintk("asked for element 0x%02x, got 0x%02x\n", 259 DPRINTK("asked for element 0x%02x, got 0x%02x\n",
254 elem,(buffer[16] << 8) | buffer[17]); 260 elem,(buffer[16] << 8) | buffer[17]);
255 kfree(buffer); 261 kfree(buffer);
256 return -EIO; 262 return -EIO;
@@ -259,10 +265,10 @@ ch_read_element_status(scsi_changer *ch, u_int elem, char *data)
259 } else { 265 } else {
260 if (ch->voltags) { 266 if (ch->voltags) {
261 ch->voltags = 0; 267 ch->voltags = 0;
262 vprintk("device has no volume tag support\n"); 268 VPRINTK(KERN_INFO, "device has no volume tag support\n");
263 goto retry; 269 goto retry;
264 } 270 }
265 dprintk("READ ELEMENT STATUS for element 0x%x failed\n",elem); 271 DPRINTK("READ ELEMENT STATUS for element 0x%x failed\n",elem);
266 } 272 }
267 kfree(buffer); 273 kfree(buffer);
268 return result; 274 return result;
@@ -274,12 +280,12 @@ ch_init_elem(scsi_changer *ch)
274 int err; 280 int err;
275 u_char cmd[6]; 281 u_char cmd[6];
276 282
277 vprintk("INITIALIZE ELEMENT STATUS, may take some time ...\n"); 283 VPRINTK(KERN_INFO, "INITIALIZE ELEMENT STATUS, may take some time ...\n");
278 memset(cmd,0,sizeof(cmd)); 284 memset(cmd,0,sizeof(cmd));
279 cmd[0] = INITIALIZE_ELEMENT_STATUS; 285 cmd[0] = INITIALIZE_ELEMENT_STATUS;
280 cmd[1] = ch->device->lun << 5; 286 cmd[1] = ch->device->lun << 5;
281 err = ch_do_scsi(ch, cmd, NULL, 0, DMA_NONE); 287 err = ch_do_scsi(ch, cmd, NULL, 0, DMA_NONE);
282 vprintk("... finished\n"); 288 VPRINTK(KERN_INFO, "... finished\n");
283 return err; 289 return err;
284} 290}
285 291
@@ -322,20 +328,20 @@ ch_readconfig(scsi_changer *ch)
322 (buffer[buffer[3]+18] << 8) | buffer[buffer[3]+19]; 328 (buffer[buffer[3]+18] << 8) | buffer[buffer[3]+19];
323 ch->counts[CHET_DT] = 329 ch->counts[CHET_DT] =
324 (buffer[buffer[3]+20] << 8) | buffer[buffer[3]+21]; 330 (buffer[buffer[3]+20] << 8) | buffer[buffer[3]+21];
325 vprintk("type #1 (mt): 0x%x+%d [medium transport]\n", 331 VPRINTK(KERN_INFO, "type #1 (mt): 0x%x+%d [medium transport]\n",
326 ch->firsts[CHET_MT], 332 ch->firsts[CHET_MT],
327 ch->counts[CHET_MT]); 333 ch->counts[CHET_MT]);
328 vprintk("type #2 (st): 0x%x+%d [storage]\n", 334 VPRINTK(KERN_INFO, "type #2 (st): 0x%x+%d [storage]\n",
329 ch->firsts[CHET_ST], 335 ch->firsts[CHET_ST],
330 ch->counts[CHET_ST]); 336 ch->counts[CHET_ST]);
331 vprintk("type #3 (ie): 0x%x+%d [import/export]\n", 337 VPRINTK(KERN_INFO, "type #3 (ie): 0x%x+%d [import/export]\n",
332 ch->firsts[CHET_IE], 338 ch->firsts[CHET_IE],
333 ch->counts[CHET_IE]); 339 ch->counts[CHET_IE]);
334 vprintk("type #4 (dt): 0x%x+%d [data transfer]\n", 340 VPRINTK(KERN_INFO, "type #4 (dt): 0x%x+%d [data transfer]\n",
335 ch->firsts[CHET_DT], 341 ch->firsts[CHET_DT],
336 ch->counts[CHET_DT]); 342 ch->counts[CHET_DT]);
337 } else { 343 } else {
338 vprintk("reading element address assigment page failed!\n"); 344 VPRINTK(KERN_INFO, "reading element address assigment page failed!\n");
339 } 345 }
340 346
341 /* vendor specific element types */ 347 /* vendor specific element types */
@@ -346,13 +352,13 @@ ch_readconfig(scsi_changer *ch)
346 continue; 352 continue;
347 ch->firsts[CHET_V1+i] = vendor_firsts[i]; 353 ch->firsts[CHET_V1+i] = vendor_firsts[i];
348 ch->counts[CHET_V1+i] = vendor_counts[i]; 354 ch->counts[CHET_V1+i] = vendor_counts[i];
349 vprintk("type #%d (v%d): 0x%x+%d [%s, vendor specific]\n", 355 VPRINTK(KERN_INFO, "type #%d (v%d): 0x%x+%d [%s, vendor specific]\n",
350 i+5,i+1,vendor_firsts[i],vendor_counts[i], 356 i+5,i+1,vendor_firsts[i],vendor_counts[i],
351 vendor_labels[i]); 357 vendor_labels[i]);
352 } 358 }
353 359
354 /* look up the devices of the data transfer elements */ 360 /* look up the devices of the data transfer elements */
355 ch->dt = kmalloc(ch->counts[CHET_DT]*sizeof(struct scsi_device), 361 ch->dt = kcalloc(ch->counts[CHET_DT], sizeof(*ch->dt),
356 GFP_KERNEL); 362 GFP_KERNEL);
357 363
358 if (!ch->dt) { 364 if (!ch->dt) {
@@ -366,21 +372,19 @@ ch_readconfig(scsi_changer *ch)
366 if (elem < CH_DT_MAX && -1 != dt_id[elem]) { 372 if (elem < CH_DT_MAX && -1 != dt_id[elem]) {
367 id = dt_id[elem]; 373 id = dt_id[elem];
368 lun = dt_lun[elem]; 374 lun = dt_lun[elem];
369 vprintk("dt 0x%x: [insmod option] ", 375 VPRINTK(KERN_INFO, "dt 0x%x: [insmod option] ",
370 elem+ch->firsts[CHET_DT]); 376 elem+ch->firsts[CHET_DT]);
371 } else if (0 != ch_read_element_status 377 } else if (0 != ch_read_element_status
372 (ch,elem+ch->firsts[CHET_DT],data)) { 378 (ch,elem+ch->firsts[CHET_DT],data)) {
373 vprintk("dt 0x%x: READ ELEMENT STATUS failed\n", 379 VPRINTK(KERN_INFO, "dt 0x%x: READ ELEMENT STATUS failed\n",
374 elem+ch->firsts[CHET_DT]); 380 elem+ch->firsts[CHET_DT]);
375 } else { 381 } else {
376 vprintk("dt 0x%x: ",elem+ch->firsts[CHET_DT]); 382 VPRINTK(KERN_INFO, "dt 0x%x: ",elem+ch->firsts[CHET_DT]);
377 if (data[6] & 0x80) { 383 if (data[6] & 0x80) {
378 if (verbose) 384 VPRINTK(KERN_CONT, "not this SCSI bus\n");
379 printk("not this SCSI bus\n");
380 ch->dt[elem] = NULL; 385 ch->dt[elem] = NULL;
381 } else if (0 == (data[6] & 0x30)) { 386 } else if (0 == (data[6] & 0x30)) {
382 if (verbose) 387 VPRINTK(KERN_CONT, "ID/LUN unknown\n");
383 printk("ID/LUN unknown\n");
384 ch->dt[elem] = NULL; 388 ch->dt[elem] = NULL;
385 } else { 389 } else {
386 id = ch->device->id; 390 id = ch->device->id;
@@ -390,22 +394,19 @@ ch_readconfig(scsi_changer *ch)
390 } 394 }
391 } 395 }
392 if (-1 != id) { 396 if (-1 != id) {
393 if (verbose) 397 VPRINTK(KERN_CONT, "ID %i, LUN %i, ",id,lun);
394 printk("ID %i, LUN %i, ",id,lun);
395 ch->dt[elem] = 398 ch->dt[elem] =
396 scsi_device_lookup(ch->device->host, 399 scsi_device_lookup(ch->device->host,
397 ch->device->channel, 400 ch->device->channel,
398 id,lun); 401 id,lun);
399 if (!ch->dt[elem]) { 402 if (!ch->dt[elem]) {
400 /* should not happen */ 403 /* should not happen */
401 if (verbose) 404 VPRINTK(KERN_CONT, "Huh? device not found!\n");
402 printk("Huh? device not found!\n");
403 } else { 405 } else {
404 if (verbose) 406 VPRINTK(KERN_CONT, "name: %8.8s %16.16s %4.4s\n",
405 printk("name: %8.8s %16.16s %4.4s\n", 407 ch->dt[elem]->vendor,
406 ch->dt[elem]->vendor, 408 ch->dt[elem]->model,
407 ch->dt[elem]->model, 409 ch->dt[elem]->rev);
408 ch->dt[elem]->rev);
409 } 410 }
410 } 411 }
411 } 412 }
@@ -422,7 +423,7 @@ ch_position(scsi_changer *ch, u_int trans, u_int elem, int rotate)
422{ 423{
423 u_char cmd[10]; 424 u_char cmd[10];
424 425
425 dprintk("position: 0x%x\n",elem); 426 DPRINTK("position: 0x%x\n",elem);
426 if (0 == trans) 427 if (0 == trans)
427 trans = ch->firsts[CHET_MT]; 428 trans = ch->firsts[CHET_MT];
428 memset(cmd,0,sizeof(cmd)); 429 memset(cmd,0,sizeof(cmd));
@@ -441,7 +442,7 @@ ch_move(scsi_changer *ch, u_int trans, u_int src, u_int dest, int rotate)
441{ 442{
442 u_char cmd[12]; 443 u_char cmd[12];
443 444
444 dprintk("move: 0x%x => 0x%x\n",src,dest); 445 DPRINTK("move: 0x%x => 0x%x\n",src,dest);
445 if (0 == trans) 446 if (0 == trans)
446 trans = ch->firsts[CHET_MT]; 447 trans = ch->firsts[CHET_MT];
447 memset(cmd,0,sizeof(cmd)); 448 memset(cmd,0,sizeof(cmd));
@@ -463,7 +464,7 @@ ch_exchange(scsi_changer *ch, u_int trans, u_int src,
463{ 464{
464 u_char cmd[12]; 465 u_char cmd[12];
465 466
466 dprintk("exchange: 0x%x => 0x%x => 0x%x\n", 467 DPRINTK("exchange: 0x%x => 0x%x => 0x%x\n",
467 src,dest1,dest2); 468 src,dest1,dest2);
468 if (0 == trans) 469 if (0 == trans)
469 trans = ch->firsts[CHET_MT]; 470 trans = ch->firsts[CHET_MT];
@@ -511,7 +512,7 @@ ch_set_voltag(scsi_changer *ch, u_int elem,
511 if (!buffer) 512 if (!buffer)
512 return -ENOMEM; 513 return -ENOMEM;
513 514
514 dprintk("%s %s voltag: 0x%x => \"%s\"\n", 515 DPRINTK("%s %s voltag: 0x%x => \"%s\"\n",
515 clear ? "clear" : "set", 516 clear ? "clear" : "set",
516 alternate ? "alternate" : "primary", 517 alternate ? "alternate" : "primary",
517 elem, tag); 518 elem, tag);
@@ -550,7 +551,7 @@ static int ch_gstatus(scsi_changer *ch, int type, unsigned char __user *dest)
550 } 551 }
551 put_user(data[2], dest+i); 552 put_user(data[2], dest+i);
552 if (data[2] & CESTATUS_EXCEPT) 553 if (data[2] & CESTATUS_EXCEPT)
553 vprintk("element 0x%x: asc=0x%x, ascq=0x%x\n", 554 VPRINTK(KERN_INFO, "element 0x%x: asc=0x%x, ascq=0x%x\n",
554 ch->firsts[type]+i, 555 ch->firsts[type]+i,
555 (int)data[4],(int)data[5]); 556 (int)data[4],(int)data[5]);
556 retval = ch_read_element_status 557 retval = ch_read_element_status
@@ -660,7 +661,7 @@ static long ch_ioctl(struct file *file,
660 return -EFAULT; 661 return -EFAULT;
661 662
662 if (0 != ch_checkrange(ch, pos.cp_type, pos.cp_unit)) { 663 if (0 != ch_checkrange(ch, pos.cp_type, pos.cp_unit)) {
663 dprintk("CHIOPOSITION: invalid parameter\n"); 664 DPRINTK("CHIOPOSITION: invalid parameter\n");
664 return -EBADSLT; 665 return -EBADSLT;
665 } 666 }
666 mutex_lock(&ch->lock); 667 mutex_lock(&ch->lock);
@@ -680,7 +681,7 @@ static long ch_ioctl(struct file *file,
680 681
681 if (0 != ch_checkrange(ch, mv.cm_fromtype, mv.cm_fromunit) || 682 if (0 != ch_checkrange(ch, mv.cm_fromtype, mv.cm_fromunit) ||
682 0 != ch_checkrange(ch, mv.cm_totype, mv.cm_tounit )) { 683 0 != ch_checkrange(ch, mv.cm_totype, mv.cm_tounit )) {
683 dprintk("CHIOMOVE: invalid parameter\n"); 684 DPRINTK("CHIOMOVE: invalid parameter\n");
684 return -EBADSLT; 685 return -EBADSLT;
685 } 686 }
686 687
@@ -703,7 +704,7 @@ static long ch_ioctl(struct file *file,
703 if (0 != ch_checkrange(ch, mv.ce_srctype, mv.ce_srcunit ) || 704 if (0 != ch_checkrange(ch, mv.ce_srctype, mv.ce_srcunit ) ||
704 0 != ch_checkrange(ch, mv.ce_fdsttype, mv.ce_fdstunit) || 705 0 != ch_checkrange(ch, mv.ce_fdsttype, mv.ce_fdstunit) ||
705 0 != ch_checkrange(ch, mv.ce_sdsttype, mv.ce_sdstunit)) { 706 0 != ch_checkrange(ch, mv.ce_sdsttype, mv.ce_sdstunit)) {
706 dprintk("CHIOEXCHANGE: invalid parameter\n"); 707 DPRINTK("CHIOEXCHANGE: invalid parameter\n");
707 return -EBADSLT; 708 return -EBADSLT;
708 } 709 }
709 710
@@ -796,7 +797,7 @@ static long ch_ioctl(struct file *file,
796 } 797 }
797 } else if (ch->voltags) { 798 } else if (ch->voltags) {
798 ch->voltags = 0; 799 ch->voltags = 0;
799 vprintk("device has no volume tag support\n"); 800 VPRINTK(KERN_INFO, "device has no volume tag support\n");
800 goto voltag_retry; 801 goto voltag_retry;
801 } 802 }
802 kfree(buffer); 803 kfree(buffer);
@@ -824,7 +825,7 @@ static long ch_ioctl(struct file *file,
824 return -EFAULT; 825 return -EFAULT;
825 826
826 if (0 != ch_checkrange(ch, csv.csv_type, csv.csv_unit)) { 827 if (0 != ch_checkrange(ch, csv.csv_type, csv.csv_unit)) {
827 dprintk("CHIOSVOLTAG: invalid parameter\n"); 828 DPRINTK("CHIOSVOLTAG: invalid parameter\n");
828 return -EBADSLT; 829 return -EBADSLT;
829 } 830 }
830 elem = ch->firsts[csv.csv_type] + csv.csv_unit; 831 elem = ch->firsts[csv.csv_type] + csv.csv_unit;
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index bd977be7544e..54f50b07dac7 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -1597,7 +1597,7 @@ static u8 start_scsi(struct AdapterCtlBlk* acb, struct DeviceCtlBlk* dcb,
1597 u32 tag_mask = 1; 1597 u32 tag_mask = 1;
1598 u8 tag_number = 0; 1598 u8 tag_number = 0;
1599 while (tag_mask & dcb->tag_mask 1599 while (tag_mask & dcb->tag_mask
1600 && tag_number <= dcb->max_command) { 1600 && tag_number < dcb->max_command) {
1601 tag_mask = tag_mask << 1; 1601 tag_mask = tag_mask << 1;
1602 tag_number++; 1602 tag_number++;
1603 } 1603 }
diff --git a/drivers/scsi/fnic/fnic.h b/drivers/scsi/fnic/fnic.h
index 19338e0ba2c5..cbb20b13b228 100644
--- a/drivers/scsi/fnic/fnic.h
+++ b/drivers/scsi/fnic/fnic.h
@@ -21,6 +21,7 @@
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/netdevice.h> 22#include <linux/netdevice.h>
23#include <linux/workqueue.h> 23#include <linux/workqueue.h>
24#include <linux/bitops.h>
24#include <scsi/libfc.h> 25#include <scsi/libfc.h>
25#include <scsi/libfcoe.h> 26#include <scsi/libfcoe.h>
26#include "fnic_io.h" 27#include "fnic_io.h"
@@ -49,7 +50,6 @@
49/* 50/*
50 * Tag bits used for special requests. 51 * Tag bits used for special requests.
51 */ 52 */
52#define BIT(nr) (1UL << (nr))
53#define FNIC_TAG_ABORT BIT(30) /* tag bit indicating abort */ 53#define FNIC_TAG_ABORT BIT(30) /* tag bit indicating abort */
54#define FNIC_TAG_DEV_RST BIT(29) /* indicates device reset */ 54#define FNIC_TAG_DEV_RST BIT(29) /* indicates device reset */
55#define FNIC_TAG_MASK (BIT(24) - 1) /* mask for lookup */ 55#define FNIC_TAG_MASK (BIT(24) - 1) /* mask for lookup */
diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 75585a52c88b..427a56d3117e 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -285,9 +285,12 @@ static int __init do_DTC3181E_setup(char *str)
285int __init generic_NCR5380_detect(struct scsi_host_template * tpnt) 285int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
286{ 286{
287 static int current_override = 0; 287 static int current_override = 0;
288 int count, i; 288 int count;
289 unsigned int *ports; 289 unsigned int *ports;
290#ifndef SCSI_G_NCR5380_MEM
291 int i;
290 unsigned long region_size = 16; 292 unsigned long region_size = 16;
293#endif
291 static unsigned int __initdata ncr_53c400a_ports[] = { 294 static unsigned int __initdata ncr_53c400a_ports[] = {
292 0x280, 0x290, 0x300, 0x310, 0x330, 0x340, 0x348, 0x350, 0 295 0x280, 0x290, 0x300, 0x310, 0x330, 0x340, 0x348, 0x350, 0
293 }; 296 };
@@ -296,7 +299,7 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
296 }; 299 };
297 int flags = 0; 300 int flags = 0;
298 struct Scsi_Host *instance; 301 struct Scsi_Host *instance;
299#ifdef CONFIG_SCSI_G_NCR5380_MEM 302#ifdef SCSI_G_NCR5380_MEM
300 unsigned long base; 303 unsigned long base;
301 void __iomem *iomem; 304 void __iomem *iomem;
302#endif 305#endif
@@ -315,17 +318,15 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
315 overrides[0].board = BOARD_NCR53C400A; 318 overrides[0].board = BOARD_NCR53C400A;
316 else if (dtc_3181e != NCR_NOT_SET) 319 else if (dtc_3181e != NCR_NOT_SET)
317 overrides[0].board = BOARD_DTC3181E; 320 overrides[0].board = BOARD_DTC3181E;
318 321#ifndef SCSI_G_NCR5380_MEM
319 if (!current_override && isapnp_present()) { 322 if (!current_override && isapnp_present()) {
320 struct pnp_dev *dev = NULL; 323 struct pnp_dev *dev = NULL;
321 count = 0; 324 count = 0;
322 while ((dev = pnp_find_dev(NULL, ISAPNP_VENDOR('D', 'T', 'C'), ISAPNP_FUNCTION(0x436e), dev))) { 325 while ((dev = pnp_find_dev(NULL, ISAPNP_VENDOR('D', 'T', 'C'), ISAPNP_FUNCTION(0x436e), dev))) {
323 if (count >= NO_OVERRIDES) 326 if (count >= NO_OVERRIDES)
324 break; 327 break;
325 if (pnp_device_attach(dev) < 0) { 328 if (pnp_device_attach(dev) < 0)
326 printk(KERN_ERR "dtc436e probe: attach failed\n");
327 continue; 329 continue;
328 }
329 if (pnp_activate_dev(dev) < 0) { 330 if (pnp_activate_dev(dev) < 0) {
330 printk(KERN_ERR "dtc436e probe: activate failed\n"); 331 printk(KERN_ERR "dtc436e probe: activate failed\n");
331 pnp_device_detach(dev); 332 pnp_device_detach(dev);
@@ -349,7 +350,7 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
349 count++; 350 count++;
350 } 351 }
351 } 352 }
352 353#endif
353 tpnt->proc_name = "g_NCR5380"; 354 tpnt->proc_name = "g_NCR5380";
354 355
355 for (count = 0; current_override < NO_OVERRIDES; ++current_override) { 356 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
@@ -374,7 +375,7 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
374 break; 375 break;
375 } 376 }
376 377
377#ifndef CONFIG_SCSI_G_NCR5380_MEM 378#ifndef SCSI_G_NCR5380_MEM
378 if (ports) { 379 if (ports) {
379 /* wakeup sequence for the NCR53C400A and DTC3181E */ 380 /* wakeup sequence for the NCR53C400A and DTC3181E */
380 381
@@ -436,7 +437,7 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
436#endif 437#endif
437 instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata)); 438 instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata));
438 if (instance == NULL) { 439 if (instance == NULL) {
439#ifndef CONFIG_SCSI_G_NCR5380_MEM 440#ifndef SCSI_G_NCR5380_MEM
440 release_region(overrides[current_override].NCR5380_map_name, region_size); 441 release_region(overrides[current_override].NCR5380_map_name, region_size);
441#else 442#else
442 iounmap(iomem); 443 iounmap(iomem);
@@ -446,10 +447,10 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
446 } 447 }
447 448
448 instance->NCR5380_instance_name = overrides[current_override].NCR5380_map_name; 449 instance->NCR5380_instance_name = overrides[current_override].NCR5380_map_name;
449#ifndef CONFIG_SCSI_G_NCR5380_MEM 450#ifndef SCSI_G_NCR5380_MEM
450 instance->n_io_port = region_size; 451 instance->n_io_port = region_size;
451#else 452#else
452 ((struct NCR5380_hostdata *)instance->hostdata).iomem = iomem; 453 ((struct NCR5380_hostdata *)instance->hostdata)->iomem = iomem;
453#endif 454#endif
454 455
455 NCR5380_init(instance, flags); 456 NCR5380_init(instance, flags);
@@ -517,10 +518,10 @@ int generic_NCR5380_release_resources(struct Scsi_Host *instance)
517 free_irq(instance->irq, instance); 518 free_irq(instance->irq, instance);
518 NCR5380_exit(instance); 519 NCR5380_exit(instance);
519 520
520#ifndef CONFIG_SCSI_G_NCR5380_MEM 521#ifndef SCSI_G_NCR5380_MEM
521 release_region(instance->NCR5380_instance_name, instance->n_io_port); 522 release_region(instance->NCR5380_instance_name, instance->n_io_port);
522#else 523#else
523 iounmap(((struct NCR5380_hostdata *)instance->hostdata).iomem); 524 iounmap(((struct NCR5380_hostdata *)instance->hostdata)->iomem);
524 release_mem_region(instance->NCR5380_instance_name, NCR5380_region_size); 525 release_mem_region(instance->NCR5380_instance_name, NCR5380_region_size);
525#endif 526#endif
526 527
@@ -590,14 +591,14 @@ static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst,
590 } 591 }
591 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY); 592 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY);
592 593
593#ifndef CONFIG_SCSI_G_NCR5380_MEM 594#ifndef SCSI_G_NCR5380_MEM
594 { 595 {
595 int i; 596 int i;
596 for (i = 0; i < 128; i++) 597 for (i = 0; i < 128; i++)
597 dst[start + i] = NCR5380_read(C400_HOST_BUFFER); 598 dst[start + i] = NCR5380_read(C400_HOST_BUFFER);
598 } 599 }
599#else 600#else
600 /* implies CONFIG_SCSI_G_NCR5380_MEM */ 601 /* implies SCSI_G_NCR5380_MEM */
601 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128); 602 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128);
602#endif 603#endif
603 start += 128; 604 start += 128;
@@ -610,14 +611,14 @@ static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst,
610 // FIXME - no timeout 611 // FIXME - no timeout
611 } 612 }
612 613
613#ifndef CONFIG_SCSI_G_NCR5380_MEM 614#ifndef SCSI_G_NCR5380_MEM
614 { 615 {
615 int i; 616 int i;
616 for (i = 0; i < 128; i++) 617 for (i = 0; i < 128; i++)
617 dst[start + i] = NCR5380_read(C400_HOST_BUFFER); 618 dst[start + i] = NCR5380_read(C400_HOST_BUFFER);
618 } 619 }
619#else 620#else
620 /* implies CONFIG_SCSI_G_NCR5380_MEM */ 621 /* implies SCSI_G_NCR5380_MEM */
621 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128); 622 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128);
622#endif 623#endif
623 start += 128; 624 start += 128;
@@ -676,13 +677,13 @@ static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src,
676 } 677 }
677 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY) 678 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
678 ; // FIXME - timeout 679 ; // FIXME - timeout
679#ifndef CONFIG_SCSI_G_NCR5380_MEM 680#ifndef SCSI_G_NCR5380_MEM
680 { 681 {
681 for (i = 0; i < 128; i++) 682 for (i = 0; i < 128; i++)
682 NCR5380_write(C400_HOST_BUFFER, src[start + i]); 683 NCR5380_write(C400_HOST_BUFFER, src[start + i]);
683 } 684 }
684#else 685#else
685 /* implies CONFIG_SCSI_G_NCR5380_MEM */ 686 /* implies SCSI_G_NCR5380_MEM */
686 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128); 687 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128);
687#endif 688#endif
688 start += 128; 689 start += 128;
@@ -692,13 +693,13 @@ static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src,
692 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY) 693 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
693 ; // FIXME - no timeout 694 ; // FIXME - no timeout
694 695
695#ifndef CONFIG_SCSI_G_NCR5380_MEM 696#ifndef SCSI_G_NCR5380_MEM
696 { 697 {
697 for (i = 0; i < 128; i++) 698 for (i = 0; i < 128; i++)
698 NCR5380_write(C400_HOST_BUFFER, src[start + i]); 699 NCR5380_write(C400_HOST_BUFFER, src[start + i]);
699 } 700 }
700#else 701#else
701 /* implies CONFIG_SCSI_G_NCR5380_MEM */ 702 /* implies SCSI_G_NCR5380_MEM */
702 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128); 703 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128);
703#endif 704#endif
704 start += 128; 705 start += 128;
@@ -938,7 +939,7 @@ module_param(ncr_53c400a, int, 0);
938module_param(dtc_3181e, int, 0); 939module_param(dtc_3181e, int, 0);
939MODULE_LICENSE("GPL"); 940MODULE_LICENSE("GPL");
940 941
941 942#ifndef SCSI_G_NCR5380_MEM
942static struct isapnp_device_id id_table[] __devinitdata = { 943static struct isapnp_device_id id_table[] __devinitdata = {
943 { 944 {
944 ISAPNP_ANY_ID, ISAPNP_ANY_ID, 945 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
@@ -948,7 +949,7 @@ static struct isapnp_device_id id_table[] __devinitdata = {
948}; 949};
949 950
950MODULE_DEVICE_TABLE(isapnp, id_table); 951MODULE_DEVICE_TABLE(isapnp, id_table);
951 952#endif
952 953
953__setup("ncr5380=", do_NCR5380_setup); 954__setup("ncr5380=", do_NCR5380_setup);
954__setup("ncr53c400=", do_NCR53C400_setup); 955__setup("ncr53c400=", do_NCR53C400_setup);
diff --git a/drivers/scsi/g_NCR5380.h b/drivers/scsi/g_NCR5380.h
index df0b3f69ef63..921764c9ab24 100644
--- a/drivers/scsi/g_NCR5380.h
+++ b/drivers/scsi/g_NCR5380.h
@@ -63,7 +63,7 @@ static const char* generic_NCR5380_info(struct Scsi_Host *);
63#define __STRVAL(x) #x 63#define __STRVAL(x) #x
64#define STRVAL(x) __STRVAL(x) 64#define STRVAL(x) __STRVAL(x)
65 65
66#ifndef CONFIG_SCSI_G_NCR5380_MEM 66#ifndef SCSI_G_NCR5380_MEM
67 67
68#define NCR5380_map_config port 68#define NCR5380_map_config port
69#define NCR5380_map_type int 69#define NCR5380_map_type int
@@ -91,7 +91,7 @@ static const char* generic_NCR5380_info(struct Scsi_Host *);
91 NCR5380_map_name = (NCR5380_map_type)((instance)->NCR5380_instance_name) 91 NCR5380_map_name = (NCR5380_map_type)((instance)->NCR5380_instance_name)
92 92
93#else 93#else
94/* therefore CONFIG_SCSI_G_NCR5380_MEM */ 94/* therefore SCSI_G_NCR5380_MEM */
95 95
96#define NCR5380_map_config memory 96#define NCR5380_map_config memory
97#define NCR5380_map_type unsigned long 97#define NCR5380_map_type unsigned long
@@ -114,7 +114,7 @@ static const char* generic_NCR5380_info(struct Scsi_Host *);
114 register void __iomem *iomem 114 register void __iomem *iomem
115 115
116#define NCR5380_setup(instance) \ 116#define NCR5380_setup(instance) \
117 iomem = (((struct NCR5380_hostdata *)(instance)->hostdata).iomem) 117 iomem = (((struct NCR5380_hostdata *)(instance)->hostdata)->iomem)
118 118
119#endif 119#endif
120 120
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index f672d6213eea..b860d650a563 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -4914,7 +4914,7 @@ static int __init gdth_eisa_probe_one(u16 eisa_slot)
4914 4914
4915 error = scsi_add_host(shp, NULL); 4915 error = scsi_add_host(shp, NULL);
4916 if (error) 4916 if (error)
4917 goto out_free_coal_stat; 4917 goto out_free_ccb_phys;
4918 list_add_tail(&ha->list, &gdth_instances); 4918 list_add_tail(&ha->list, &gdth_instances);
4919 gdth_timer_init(); 4919 gdth_timer_init();
4920 4920
diff --git a/drivers/scsi/initio.c b/drivers/scsi/initio.c
index a7714160fbc3..108797761b95 100644
--- a/drivers/scsi/initio.c
+++ b/drivers/scsi/initio.c
@@ -2817,7 +2817,6 @@ static void i91uSCBPost(u8 * host_mem, u8 * cblk_mem)
2817 } 2817 }
2818 2818
2819 cmnd->result = cblk->tastat | (cblk->hastat << 16); 2819 cmnd->result = cblk->tastat | (cblk->hastat << 16);
2820 WARN_ON(cmnd == NULL);
2821 i91u_unmap_scb(host->pci_dev, cmnd); 2820 i91u_unmap_scb(host->pci_dev, cmnd);
2822 cmnd->scsi_done(cmnd); /* Notify system DONE */ 2821 cmnd->scsi_done(cmnd); /* Notify system DONE */
2823 initio_release_scb(host, cblk); /* Release SCB for current channel */ 2822 initio_release_scb(host, cblk); /* Release SCB for current channel */
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 162704cf6a96..ad05b266e950 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -25,6 +25,7 @@
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/aer.h> 26#include <linux/aer.h>
27#include <linux/gfp.h> 27#include <linux/gfp.h>
28#include <linux/kernel.h>
28 29
29#include <scsi/scsi.h> 30#include <scsi/scsi.h>
30#include <scsi/scsi_device.h> 31#include <scsi/scsi_device.h>
@@ -1795,12 +1796,11 @@ lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1795 1796
1796 /* Validate and store the new name */ 1797 /* Validate and store the new name */
1797 for (i=0, j=0; i < 16; i++) { 1798 for (i=0, j=0; i < 16; i++) {
1798 if ((*buf >= 'a') && (*buf <= 'f')) 1799 int value;
1799 j = ((j << 4) | ((*buf++ -'a') + 10)); 1800
1800 else if ((*buf >= 'A') && (*buf <= 'F')) 1801 value = hex_to_bin(*buf++);
1801 j = ((j << 4) | ((*buf++ -'A') + 10)); 1802 if (value >= 0)
1802 else if ((*buf >= '0') && (*buf <= '9')) 1803 j = (j << 4) | value;
1803 j = ((j << 4) | (*buf++ -'0'));
1804 else 1804 else
1805 return -EINVAL; 1805 return -EINVAL;
1806 if (i % 2) { 1806 if (i % 2) {
@@ -1888,12 +1888,11 @@ lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1888 1888
1889 /* Validate and store the new name */ 1889 /* Validate and store the new name */
1890 for (i=0, j=0; i < 16; i++) { 1890 for (i=0, j=0; i < 16; i++) {
1891 if ((*buf >= 'a') && (*buf <= 'f')) 1891 int value;
1892 j = ((j << 4) | ((*buf++ -'a') + 10)); 1892
1893 else if ((*buf >= 'A') && (*buf <= 'F')) 1893 value = hex_to_bin(*buf++);
1894 j = ((j << 4) | ((*buf++ -'A') + 10)); 1894 if (value >= 0)
1895 else if ((*buf >= '0') && (*buf <= '9')) 1895 j = (j << 4) | value;
1896 j = ((j << 4) | (*buf++ -'0'));
1897 else 1896 else
1898 return -EINVAL; 1897 return -EINVAL;
1899 if (i % 2) { 1898 if (i % 2) {
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index d64b7178fa08..278b352ae78d 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -5868,7 +5868,8 @@ static int osst_probe(struct device *dev)
5868 } 5868 }
5869 5869
5870 /* find a free minor number */ 5870 /* find a free minor number */
5871 for (i=0; os_scsi_tapes[i] && i<osst_max_dev; i++); 5871 for (i = 0; i < osst_max_dev && os_scsi_tapes[i]; i++)
5872 ;
5872 if(i >= osst_max_dev) panic ("Scsi_devices corrupt (osst)"); 5873 if(i >= osst_max_dev) panic ("Scsi_devices corrupt (osst)");
5873 dev_num = i; 5874 dev_num = i;
5874 5875
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index ff2172da7c19..8c80b49ac1c4 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -115,8 +115,8 @@ int ql2xmaxqueues = 1;
115module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR); 115module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
116MODULE_PARM_DESC(ql2xmaxqueues, 116MODULE_PARM_DESC(ql2xmaxqueues,
117 "Enables MQ settings " 117 "Enables MQ settings "
118 "Default is 1 for single queue. Set it to number \ 118 "Default is 1 for single queue. Set it to number "
119 of queues in MQ mode."); 119 "of queues in MQ mode.");
120 120
121int ql2xmultique_tag; 121int ql2xmultique_tag;
122module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR); 122module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR);
diff --git a/drivers/scsi/qlogicpti.c b/drivers/scsi/qlogicpti.c
index 53d7ed0dc169..f8c561cf751e 100644
--- a/drivers/scsi/qlogicpti.c
+++ b/drivers/scsi/qlogicpti.c
@@ -704,7 +704,7 @@ static void __devexit qpti_chain_del(struct qlogicpti *qpti)
704 704
705static int __devinit qpti_map_regs(struct qlogicpti *qpti) 705static int __devinit qpti_map_regs(struct qlogicpti *qpti)
706{ 706{
707 struct of_device *op = qpti->op; 707 struct platform_device *op = qpti->op;
708 708
709 qpti->qregs = of_ioremap(&op->resource[0], 0, 709 qpti->qregs = of_ioremap(&op->resource[0], 0,
710 resource_size(&op->resource[0]), 710 resource_size(&op->resource[0]),
@@ -727,7 +727,7 @@ static int __devinit qpti_map_regs(struct qlogicpti *qpti)
727 727
728static int __devinit qpti_register_irq(struct qlogicpti *qpti) 728static int __devinit qpti_register_irq(struct qlogicpti *qpti)
729{ 729{
730 struct of_device *op = qpti->op; 730 struct platform_device *op = qpti->op;
731 731
732 qpti->qhost->irq = qpti->irq = op->archdata.irqs[0]; 732 qpti->qhost->irq = qpti->irq = op->archdata.irqs[0];
733 733
@@ -752,7 +752,7 @@ fail:
752 752
753static void __devinit qpti_get_scsi_id(struct qlogicpti *qpti) 753static void __devinit qpti_get_scsi_id(struct qlogicpti *qpti)
754{ 754{
755 struct of_device *op = qpti->op; 755 struct platform_device *op = qpti->op;
756 struct device_node *dp; 756 struct device_node *dp;
757 757
758 dp = op->dev.of_node; 758 dp = op->dev.of_node;
@@ -773,7 +773,7 @@ static void __devinit qpti_get_scsi_id(struct qlogicpti *qpti)
773 773
774static void qpti_get_bursts(struct qlogicpti *qpti) 774static void qpti_get_bursts(struct qlogicpti *qpti)
775{ 775{
776 struct of_device *op = qpti->op; 776 struct platform_device *op = qpti->op;
777 u8 bursts, bmask; 777 u8 bursts, bmask;
778 778
779 bursts = of_getintprop_default(op->dev.of_node, "burst-sizes", 0xff); 779 bursts = of_getintprop_default(op->dev.of_node, "burst-sizes", 0xff);
@@ -806,7 +806,7 @@ static void qpti_get_clock(struct qlogicpti *qpti)
806 */ 806 */
807static int __devinit qpti_map_queues(struct qlogicpti *qpti) 807static int __devinit qpti_map_queues(struct qlogicpti *qpti)
808{ 808{
809 struct of_device *op = qpti->op; 809 struct platform_device *op = qpti->op;
810 810
811#define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN) 811#define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN)
812 qpti->res_cpu = dma_alloc_coherent(&op->dev, 812 qpti->res_cpu = dma_alloc_coherent(&op->dev,
@@ -1290,7 +1290,7 @@ static struct scsi_host_template qpti_template = {
1290 .use_clustering = ENABLE_CLUSTERING, 1290 .use_clustering = ENABLE_CLUSTERING,
1291}; 1291};
1292 1292
1293static int __devinit qpti_sbus_probe(struct of_device *op, const struct of_device_id *match) 1293static int __devinit qpti_sbus_probe(struct platform_device *op, const struct of_device_id *match)
1294{ 1294{
1295 struct scsi_host_template *tpnt = match->data; 1295 struct scsi_host_template *tpnt = match->data;
1296 struct device_node *dp = op->dev.of_node; 1296 struct device_node *dp = op->dev.of_node;
@@ -1401,7 +1401,7 @@ fail_unlink:
1401 return -ENODEV; 1401 return -ENODEV;
1402} 1402}
1403 1403
1404static int __devexit qpti_sbus_remove(struct of_device *op) 1404static int __devexit qpti_sbus_remove(struct platform_device *op)
1405{ 1405{
1406 struct qlogicpti *qpti = dev_get_drvdata(&op->dev); 1406 struct qlogicpti *qpti = dev_get_drvdata(&op->dev);
1407 1407
diff --git a/drivers/scsi/qlogicpti.h b/drivers/scsi/qlogicpti.h
index e3c74d1ee2db..4377e87ee79c 100644
--- a/drivers/scsi/qlogicpti.h
+++ b/drivers/scsi/qlogicpti.h
@@ -342,7 +342,7 @@ struct qlogicpti {
342 u_int req_in_ptr; /* index of next request slot */ 342 u_int req_in_ptr; /* index of next request slot */
343 u_int res_out_ptr; /* index of next result slot */ 343 u_int res_out_ptr; /* index of next result slot */
344 long send_marker; /* must we send a marker? */ 344 long send_marker; /* must we send a marker? */
345 struct of_device *op; 345 struct platform_device *op;
346 unsigned long __pad; 346 unsigned long __pad;
347 347
348 int cmd_count[MAX_TARGETS]; 348 int cmd_count[MAX_TARGETS];
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index b8de389636f8..9ade720422c6 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1370,12 +1370,6 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
1370 1370
1371 blk_start_request(req); 1371 blk_start_request(req);
1372 1372
1373 if (unlikely(cmd == NULL)) {
1374 printk(KERN_CRIT "impossible request in %s.\n",
1375 __func__);
1376 BUG();
1377 }
1378
1379 sdev = cmd->device; 1373 sdev = cmd->device;
1380 starget = scsi_target(sdev); 1374 starget = scsi_target(sdev);
1381 shost = sdev->host; 1375 shost = sdev->host;
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index edb6b362a8fa..d7e470a06180 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -29,6 +29,7 @@
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/kernel.h>
32#include <scsi/scsi_device.h> 33#include <scsi/scsi_device.h>
33#include <scsi/scsi_host.h> 34#include <scsi/scsi_host.h>
34#include <scsi/scsi_transport.h> 35#include <scsi/scsi_transport.h>
@@ -1730,12 +1731,11 @@ fc_parse_wwn(const char *ns, u64 *nm)
1730 1731
1731 /* Validate and store the new name */ 1732 /* Validate and store the new name */
1732 for (i=0, j=0; i < 16; i++) { 1733 for (i=0, j=0; i < 16; i++) {
1733 if ((*ns >= 'a') && (*ns <= 'f')) 1734 int value;
1734 j = ((j << 4) | ((*ns++ -'a') + 10)); 1735
1735 else if ((*ns >= 'A') && (*ns <= 'F')) 1736 value = hex_to_bin(*ns++);
1736 j = ((j << 4) | ((*ns++ -'A') + 10)); 1737 if (value >= 0)
1737 else if ((*ns >= '0') && (*ns <= '9')) 1738 j = (j << 4) | value;
1738 j = ((j << 4) | (*ns++ -'0'));
1739 else 1739 else
1740 return -EINVAL; 1740 return -EINVAL;
1741 if (i % 2) { 1741 if (i % 2) {
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 8e2e893db9e7..2714becc2eaf 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -119,8 +119,8 @@ static DEFINE_IDA(sd_index_ida);
119 * object after last put) */ 119 * object after last put) */
120static DEFINE_MUTEX(sd_ref_mutex); 120static DEFINE_MUTEX(sd_ref_mutex);
121 121
122struct kmem_cache *sd_cdb_cache; 122static struct kmem_cache *sd_cdb_cache;
123mempool_t *sd_cdb_pool; 123static mempool_t *sd_cdb_pool;
124 124
125static const char *sd_cache_types[] = { 125static const char *sd_cache_types[] = {
126 "write through", "none", "write back", 126 "write through", "none", "write back",
@@ -147,7 +147,7 @@ sd_store_cache_type(struct device *dev, struct device_attribute *attr,
147 return -EINVAL; 147 return -EINVAL;
148 148
149 for (i = 0; i < ARRAY_SIZE(sd_cache_types); i++) { 149 for (i = 0; i < ARRAY_SIZE(sd_cache_types); i++) {
150 const int len = strlen(sd_cache_types[i]); 150 len = strlen(sd_cache_types[i]);
151 if (strncmp(sd_cache_types[i], buf, len) == 0 && 151 if (strncmp(sd_cache_types[i], buf, len) == 0 &&
152 buf[len] == '\n') { 152 buf[len] == '\n') {
153 ct = i; 153 ct = i;
@@ -1423,7 +1423,7 @@ sd_spinup_disk(struct scsi_disk *sdkp)
1423/* 1423/*
1424 * Determine whether disk supports Data Integrity Field. 1424 * Determine whether disk supports Data Integrity Field.
1425 */ 1425 */
1426void sd_read_protection_type(struct scsi_disk *sdkp, unsigned char *buffer) 1426static void sd_read_protection_type(struct scsi_disk *sdkp, unsigned char *buffer)
1427{ 1427{
1428 struct scsi_device *sdp = sdkp->device; 1428 struct scsi_device *sdp = sdkp->device;
1429 u8 type; 1429 u8 type;
@@ -1969,7 +1969,7 @@ defaults:
1969 * The ATO bit indicates whether the DIF application tag is available 1969 * The ATO bit indicates whether the DIF application tag is available
1970 * for use by the operating system. 1970 * for use by the operating system.
1971 */ 1971 */
1972void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer) 1972static void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer)
1973{ 1973{
1974 int res, offset; 1974 int res, offset;
1975 struct scsi_device *sdp = sdkp->device; 1975 struct scsi_device *sdp = sdkp->device;
@@ -2315,7 +2315,7 @@ static int sd_probe(struct device *dev)
2315 struct scsi_device *sdp = to_scsi_device(dev); 2315 struct scsi_device *sdp = to_scsi_device(dev);
2316 struct scsi_disk *sdkp; 2316 struct scsi_disk *sdkp;
2317 struct gendisk *gd; 2317 struct gendisk *gd;
2318 u32 index; 2318 int index;
2319 int error; 2319 int error;
2320 2320
2321 error = -ENODEV; 2321 error = -ENODEV;
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 2968c6b83ddb..78d616315d8e 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1686,14 +1686,9 @@ static int sg_start_req(Sg_request *srp, unsigned char *cmd)
1686 int len, size = sizeof(struct sg_iovec) * iov_count; 1686 int len, size = sizeof(struct sg_iovec) * iov_count;
1687 struct iovec *iov; 1687 struct iovec *iov;
1688 1688
1689 iov = kmalloc(size, GFP_ATOMIC); 1689 iov = memdup_user(hp->dxferp, size);
1690 if (!iov) 1690 if (IS_ERR(iov))
1691 return -ENOMEM; 1691 return PTR_ERR(iov);
1692
1693 if (copy_from_user(iov, hp->dxferp, size)) {
1694 kfree(iov);
1695 return -EFAULT;
1696 }
1697 1692
1698 len = iov_length(iov, iov_count); 1693 len = iov_length(iov, iov_count);
1699 if (hp->dxfer_len < len) { 1694 if (hp->dxfer_len < len) {
diff --git a/drivers/scsi/sun_esp.c b/drivers/scsi/sun_esp.c
index 89ba6fe02f80..193b37ba1834 100644
--- a/drivers/scsi/sun_esp.c
+++ b/drivers/scsi/sun_esp.c
@@ -44,7 +44,7 @@ enum dvma_rev {
44}; 44};
45 45
46static int __devinit esp_sbus_setup_dma(struct esp *esp, 46static int __devinit esp_sbus_setup_dma(struct esp *esp,
47 struct of_device *dma_of) 47 struct platform_device *dma_of)
48{ 48{
49 esp->dma = dma_of; 49 esp->dma = dma_of;
50 50
@@ -81,7 +81,7 @@ static int __devinit esp_sbus_setup_dma(struct esp *esp,
81 81
82static int __devinit esp_sbus_map_regs(struct esp *esp, int hme) 82static int __devinit esp_sbus_map_regs(struct esp *esp, int hme)
83{ 83{
84 struct of_device *op = esp->dev; 84 struct platform_device *op = esp->dev;
85 struct resource *res; 85 struct resource *res;
86 86
87 /* On HME, two reg sets exist, first is DVMA, 87 /* On HME, two reg sets exist, first is DVMA,
@@ -101,7 +101,7 @@ static int __devinit esp_sbus_map_regs(struct esp *esp, int hme)
101 101
102static int __devinit esp_sbus_map_command_block(struct esp *esp) 102static int __devinit esp_sbus_map_command_block(struct esp *esp)
103{ 103{
104 struct of_device *op = esp->dev; 104 struct platform_device *op = esp->dev;
105 105
106 esp->command_block = dma_alloc_coherent(&op->dev, 16, 106 esp->command_block = dma_alloc_coherent(&op->dev, 16,
107 &esp->command_block_dma, 107 &esp->command_block_dma,
@@ -114,15 +114,15 @@ static int __devinit esp_sbus_map_command_block(struct esp *esp)
114static int __devinit esp_sbus_register_irq(struct esp *esp) 114static int __devinit esp_sbus_register_irq(struct esp *esp)
115{ 115{
116 struct Scsi_Host *host = esp->host; 116 struct Scsi_Host *host = esp->host;
117 struct of_device *op = esp->dev; 117 struct platform_device *op = esp->dev;
118 118
119 host->irq = op->archdata.irqs[0]; 119 host->irq = op->archdata.irqs[0];
120 return request_irq(host->irq, scsi_esp_intr, IRQF_SHARED, "ESP", esp); 120 return request_irq(host->irq, scsi_esp_intr, IRQF_SHARED, "ESP", esp);
121} 121}
122 122
123static void __devinit esp_get_scsi_id(struct esp *esp, struct of_device *espdma) 123static void __devinit esp_get_scsi_id(struct esp *esp, struct platform_device *espdma)
124{ 124{
125 struct of_device *op = esp->dev; 125 struct platform_device *op = esp->dev;
126 struct device_node *dp; 126 struct device_node *dp;
127 127
128 dp = op->dev.of_node; 128 dp = op->dev.of_node;
@@ -144,7 +144,7 @@ done:
144 144
145static void __devinit esp_get_differential(struct esp *esp) 145static void __devinit esp_get_differential(struct esp *esp)
146{ 146{
147 struct of_device *op = esp->dev; 147 struct platform_device *op = esp->dev;
148 struct device_node *dp; 148 struct device_node *dp;
149 149
150 dp = op->dev.of_node; 150 dp = op->dev.of_node;
@@ -156,7 +156,7 @@ static void __devinit esp_get_differential(struct esp *esp)
156 156
157static void __devinit esp_get_clock_params(struct esp *esp) 157static void __devinit esp_get_clock_params(struct esp *esp)
158{ 158{
159 struct of_device *op = esp->dev; 159 struct platform_device *op = esp->dev;
160 struct device_node *bus_dp, *dp; 160 struct device_node *bus_dp, *dp;
161 int fmhz; 161 int fmhz;
162 162
@@ -170,10 +170,10 @@ static void __devinit esp_get_clock_params(struct esp *esp)
170 esp->cfreq = fmhz; 170 esp->cfreq = fmhz;
171} 171}
172 172
173static void __devinit esp_get_bursts(struct esp *esp, struct of_device *dma_of) 173static void __devinit esp_get_bursts(struct esp *esp, struct platform_device *dma_of)
174{ 174{
175 struct device_node *dma_dp = dma_of->dev.of_node; 175 struct device_node *dma_dp = dma_of->dev.of_node;
176 struct of_device *op = esp->dev; 176 struct platform_device *op = esp->dev;
177 struct device_node *dp; 177 struct device_node *dp;
178 u8 bursts, val; 178 u8 bursts, val;
179 179
@@ -195,7 +195,7 @@ static void __devinit esp_get_bursts(struct esp *esp, struct of_device *dma_of)
195 esp->bursts = bursts; 195 esp->bursts = bursts;
196} 196}
197 197
198static void __devinit esp_sbus_get_props(struct esp *esp, struct of_device *espdma) 198static void __devinit esp_sbus_get_props(struct esp *esp, struct platform_device *espdma)
199{ 199{
200 esp_get_scsi_id(esp, espdma); 200 esp_get_scsi_id(esp, espdma);
201 esp_get_differential(esp); 201 esp_get_differential(esp);
@@ -216,7 +216,7 @@ static u8 sbus_esp_read8(struct esp *esp, unsigned long reg)
216static dma_addr_t sbus_esp_map_single(struct esp *esp, void *buf, 216static dma_addr_t sbus_esp_map_single(struct esp *esp, void *buf,
217 size_t sz, int dir) 217 size_t sz, int dir)
218{ 218{
219 struct of_device *op = esp->dev; 219 struct platform_device *op = esp->dev;
220 220
221 return dma_map_single(&op->dev, buf, sz, dir); 221 return dma_map_single(&op->dev, buf, sz, dir);
222} 222}
@@ -224,7 +224,7 @@ static dma_addr_t sbus_esp_map_single(struct esp *esp, void *buf,
224static int sbus_esp_map_sg(struct esp *esp, struct scatterlist *sg, 224static int sbus_esp_map_sg(struct esp *esp, struct scatterlist *sg,
225 int num_sg, int dir) 225 int num_sg, int dir)
226{ 226{
227 struct of_device *op = esp->dev; 227 struct platform_device *op = esp->dev;
228 228
229 return dma_map_sg(&op->dev, sg, num_sg, dir); 229 return dma_map_sg(&op->dev, sg, num_sg, dir);
230} 230}
@@ -232,7 +232,7 @@ static int sbus_esp_map_sg(struct esp *esp, struct scatterlist *sg,
232static void sbus_esp_unmap_single(struct esp *esp, dma_addr_t addr, 232static void sbus_esp_unmap_single(struct esp *esp, dma_addr_t addr,
233 size_t sz, int dir) 233 size_t sz, int dir)
234{ 234{
235 struct of_device *op = esp->dev; 235 struct platform_device *op = esp->dev;
236 236
237 dma_unmap_single(&op->dev, addr, sz, dir); 237 dma_unmap_single(&op->dev, addr, sz, dir);
238} 238}
@@ -240,7 +240,7 @@ static void sbus_esp_unmap_single(struct esp *esp, dma_addr_t addr,
240static void sbus_esp_unmap_sg(struct esp *esp, struct scatterlist *sg, 240static void sbus_esp_unmap_sg(struct esp *esp, struct scatterlist *sg,
241 int num_sg, int dir) 241 int num_sg, int dir)
242{ 242{
243 struct of_device *op = esp->dev; 243 struct platform_device *op = esp->dev;
244 244
245 dma_unmap_sg(&op->dev, sg, num_sg, dir); 245 dma_unmap_sg(&op->dev, sg, num_sg, dir);
246} 246}
@@ -256,7 +256,7 @@ static void sbus_esp_reset_dma(struct esp *esp)
256{ 256{
257 int can_do_burst16, can_do_burst32, can_do_burst64; 257 int can_do_burst16, can_do_burst32, can_do_burst64;
258 int can_do_sbus64, lim; 258 int can_do_sbus64, lim;
259 struct of_device *op; 259 struct platform_device *op;
260 u32 val; 260 u32 val;
261 261
262 can_do_burst16 = (esp->bursts & DMA_BURST16) != 0; 262 can_do_burst16 = (esp->bursts & DMA_BURST16) != 0;
@@ -487,8 +487,8 @@ static const struct esp_driver_ops sbus_esp_ops = {
487 .dma_error = sbus_esp_dma_error, 487 .dma_error = sbus_esp_dma_error,
488}; 488};
489 489
490static int __devinit esp_sbus_probe_one(struct of_device *op, 490static int __devinit esp_sbus_probe_one(struct platform_device *op,
491 struct of_device *espdma, 491 struct platform_device *espdma,
492 int hme) 492 int hme)
493{ 493{
494 struct scsi_host_template *tpnt = &scsi_esp_template; 494 struct scsi_host_template *tpnt = &scsi_esp_template;
@@ -562,11 +562,11 @@ fail:
562 return err; 562 return err;
563} 563}
564 564
565static int __devinit esp_sbus_probe(struct of_device *op, const struct of_device_id *match) 565static int __devinit esp_sbus_probe(struct platform_device *op, const struct of_device_id *match)
566{ 566{
567 struct device_node *dma_node = NULL; 567 struct device_node *dma_node = NULL;
568 struct device_node *dp = op->dev.of_node; 568 struct device_node *dp = op->dev.of_node;
569 struct of_device *dma_of = NULL; 569 struct platform_device *dma_of = NULL;
570 int hme = 0; 570 int hme = 0;
571 571
572 if (dp->parent && 572 if (dp->parent &&
@@ -585,10 +585,10 @@ static int __devinit esp_sbus_probe(struct of_device *op, const struct of_device
585 return esp_sbus_probe_one(op, dma_of, hme); 585 return esp_sbus_probe_one(op, dma_of, hme);
586} 586}
587 587
588static int __devexit esp_sbus_remove(struct of_device *op) 588static int __devexit esp_sbus_remove(struct platform_device *op)
589{ 589{
590 struct esp *esp = dev_get_drvdata(&op->dev); 590 struct esp *esp = dev_get_drvdata(&op->dev);
591 struct of_device *dma_of = esp->dma; 591 struct platform_device *dma_of = esp->dma;
592 unsigned int irq = esp->host->irq; 592 unsigned int irq = esp->host->irq;
593 bool is_hme; 593 bool is_hme;
594 u32 val; 594 u32 val;
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index a22e60c06f48..12900f7083b0 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -536,8 +536,8 @@ config SERIAL_S3C6400
536 536
537config SERIAL_S5PV210 537config SERIAL_S5PV210
538 tristate "Samsung S5PV210 Serial port support" 538 tristate "Samsung S5PV210 Serial port support"
539 depends on SERIAL_SAMSUNG && (CPU_S5PV210 || CPU_S5P6442) 539 depends on SERIAL_SAMSUNG && (CPU_S5PV210 || CPU_S5P6442 || CPU_S5PV310)
540 select SERIAL_SAMSUNG_UARTS_4 if CPU_S5PV210 540 select SERIAL_SAMSUNG_UARTS_4 if (CPU_S5PV210 || CPU_S5PV310)
541 default y 541 default y
542 help 542 help
543 Serial port support for Samsung's S5P Family of SoC's 543 Serial port support for Samsung's S5P Family of SoC's
diff --git a/drivers/serial/apbuart.c b/drivers/serial/apbuart.c
index 0099b8692b60..cc01c650a144 100644
--- a/drivers/serial/apbuart.c
+++ b/drivers/serial/apbuart.c
@@ -551,7 +551,7 @@ static struct uart_driver grlib_apbuart_driver = {
551/* OF Platform Driver */ 551/* OF Platform Driver */
552/* ======================================================================== */ 552/* ======================================================================== */
553 553
554static int __devinit apbuart_probe(struct of_device *op, 554static int __devinit apbuart_probe(struct platform_device *op,
555 const struct of_device_id *match) 555 const struct of_device_id *match)
556{ 556{
557 int i = -1; 557 int i = -1;
diff --git a/drivers/serial/cpm_uart/cpm_uart_core.c b/drivers/serial/cpm_uart/cpm_uart_core.c
index 6016179db533..f2b8adcc6c92 100644
--- a/drivers/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/serial/cpm_uart/cpm_uart_core.c
@@ -1340,7 +1340,7 @@ static struct uart_driver cpm_reg = {
1340 1340
1341static int probe_index; 1341static int probe_index;
1342 1342
1343static int __devinit cpm_uart_probe(struct of_device *ofdev, 1343static int __devinit cpm_uart_probe(struct platform_device *ofdev,
1344 const struct of_device_id *match) 1344 const struct of_device_id *match)
1345{ 1345{
1346 int index = probe_index++; 1346 int index = probe_index++;
@@ -1364,7 +1364,7 @@ static int __devinit cpm_uart_probe(struct of_device *ofdev,
1364 return uart_add_one_port(&cpm_reg, &pinfo->port); 1364 return uart_add_one_port(&cpm_reg, &pinfo->port);
1365} 1365}
1366 1366
1367static int __devexit cpm_uart_remove(struct of_device *ofdev) 1367static int __devexit cpm_uart_remove(struct platform_device *ofdev)
1368{ 1368{
1369 struct uart_cpm_port *pinfo = dev_get_drvdata(&ofdev->dev); 1369 struct uart_cpm_port *pinfo = dev_get_drvdata(&ofdev->dev);
1370 return uart_remove_one_port(&cpm_reg, &pinfo->port); 1370 return uart_remove_one_port(&cpm_reg, &pinfo->port);
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 1a88b363005c..8dedb266f143 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -1298,7 +1298,7 @@ static struct of_device_id mpc52xx_uart_of_match[] = {
1298}; 1298};
1299 1299
1300static int __devinit 1300static int __devinit
1301mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match) 1301mpc52xx_uart_of_probe(struct platform_device *op, const struct of_device_id *match)
1302{ 1302{
1303 int idx = -1; 1303 int idx = -1;
1304 unsigned int uartclk; 1304 unsigned int uartclk;
@@ -1369,7 +1369,7 @@ mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match)
1369} 1369}
1370 1370
1371static int 1371static int
1372mpc52xx_uart_of_remove(struct of_device *op) 1372mpc52xx_uart_of_remove(struct platform_device *op)
1373{ 1373{
1374 struct uart_port *port = dev_get_drvdata(&op->dev); 1374 struct uart_port *port = dev_get_drvdata(&op->dev);
1375 dev_set_drvdata(&op->dev, NULL); 1375 dev_set_drvdata(&op->dev, NULL);
@@ -1382,7 +1382,7 @@ mpc52xx_uart_of_remove(struct of_device *op)
1382 1382
1383#ifdef CONFIG_PM 1383#ifdef CONFIG_PM
1384static int 1384static int
1385mpc52xx_uart_of_suspend(struct of_device *op, pm_message_t state) 1385mpc52xx_uart_of_suspend(struct platform_device *op, pm_message_t state)
1386{ 1386{
1387 struct uart_port *port = (struct uart_port *) dev_get_drvdata(&op->dev); 1387 struct uart_port *port = (struct uart_port *) dev_get_drvdata(&op->dev);
1388 1388
@@ -1393,7 +1393,7 @@ mpc52xx_uart_of_suspend(struct of_device *op, pm_message_t state)
1393} 1393}
1394 1394
1395static int 1395static int
1396mpc52xx_uart_of_resume(struct of_device *op) 1396mpc52xx_uart_of_resume(struct platform_device *op)
1397{ 1397{
1398 struct uart_port *port = (struct uart_port *) dev_get_drvdata(&op->dev); 1398 struct uart_port *port = (struct uart_port *) dev_get_drvdata(&op->dev);
1399 1399
diff --git a/drivers/serial/nwpserial.c b/drivers/serial/nwpserial.c
index e65b0d9202a5..de173671e3d0 100644
--- a/drivers/serial/nwpserial.c
+++ b/drivers/serial/nwpserial.c
@@ -344,7 +344,7 @@ int nwpserial_register_port(struct uart_port *port)
344 344
345 mutex_lock(&nwpserial_mutex); 345 mutex_lock(&nwpserial_mutex);
346 346
347 dn = to_of_device(port->dev)->dev.of_node; 347 dn = port->dev->of_node;
348 if (dn == NULL) 348 if (dn == NULL)
349 goto out; 349 goto out;
350 350
diff --git a/drivers/serial/of_serial.c b/drivers/serial/of_serial.c
index a48d9080f552..659a695bdad6 100644
--- a/drivers/serial/of_serial.c
+++ b/drivers/serial/of_serial.c
@@ -27,7 +27,7 @@ struct of_serial_info {
27/* 27/*
28 * Fill a struct uart_port for a given device node 28 * Fill a struct uart_port for a given device node
29 */ 29 */
30static int __devinit of_platform_serial_setup(struct of_device *ofdev, 30static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
31 int type, struct uart_port *port) 31 int type, struct uart_port *port)
32{ 32{
33 struct resource resource; 33 struct resource resource;
@@ -80,7 +80,7 @@ static int __devinit of_platform_serial_setup(struct of_device *ofdev,
80/* 80/*
81 * Try to register a serial port 81 * Try to register a serial port
82 */ 82 */
83static int __devinit of_platform_serial_probe(struct of_device *ofdev, 83static int __devinit of_platform_serial_probe(struct platform_device *ofdev,
84 const struct of_device_id *id) 84 const struct of_device_id *id)
85{ 85{
86 struct of_serial_info *info; 86 struct of_serial_info *info;
@@ -134,7 +134,7 @@ out:
134/* 134/*
135 * Release a line 135 * Release a line
136 */ 136 */
137static int of_platform_serial_remove(struct of_device *ofdev) 137static int of_platform_serial_remove(struct platform_device *ofdev)
138{ 138{
139 struct of_serial_info *info = dev_get_drvdata(&ofdev->dev); 139 struct of_serial_info *info = dev_get_drvdata(&ofdev->dev);
140 switch (info->type) { 140 switch (info->type) {
diff --git a/drivers/serial/s5pv210.c b/drivers/serial/s5pv210.c
index 4a789e5361a4..6ebccd70a707 100644
--- a/drivers/serial/s5pv210.c
+++ b/drivers/serial/s5pv210.c
@@ -28,8 +28,12 @@
28static int s5pv210_serial_setsource(struct uart_port *port, 28static int s5pv210_serial_setsource(struct uart_port *port,
29 struct s3c24xx_uart_clksrc *clk) 29 struct s3c24xx_uart_clksrc *clk)
30{ 30{
31 struct s3c2410_uartcfg *cfg = port->dev->platform_data;
31 unsigned long ucon = rd_regl(port, S3C2410_UCON); 32 unsigned long ucon = rd_regl(port, S3C2410_UCON);
32 33
34 if ((cfg->clocks_size) == 1)
35 return 0;
36
33 if (strcmp(clk->name, "pclk") == 0) 37 if (strcmp(clk->name, "pclk") == 0)
34 ucon &= ~S5PV210_UCON_CLKMASK; 38 ucon &= ~S5PV210_UCON_CLKMASK;
35 else if (strcmp(clk->name, "uclk1") == 0) 39 else if (strcmp(clk->name, "uclk1") == 0)
@@ -47,10 +51,14 @@ static int s5pv210_serial_setsource(struct uart_port *port,
47static int s5pv210_serial_getsource(struct uart_port *port, 51static int s5pv210_serial_getsource(struct uart_port *port,
48 struct s3c24xx_uart_clksrc *clk) 52 struct s3c24xx_uart_clksrc *clk)
49{ 53{
54 struct s3c2410_uartcfg *cfg = port->dev->platform_data;
50 u32 ucon = rd_regl(port, S3C2410_UCON); 55 u32 ucon = rd_regl(port, S3C2410_UCON);
51 56
52 clk->divisor = 1; 57 clk->divisor = 1;
53 58
59 if ((cfg->clocks_size) == 1)
60 return 0;
61
54 switch (ucon & S5PV210_UCON_CLKMASK) { 62 switch (ucon & S5PV210_UCON_CLKMASK) {
55 case S5PV210_UCON_PCLK: 63 case S5PV210_UCON_PCLK:
56 clk->name = "pclk"; 64 clk->name = "pclk";
diff --git a/drivers/serial/samsung.c b/drivers/serial/samsung.c
index a9d6c5626a0a..b1156ba8ad14 100644
--- a/drivers/serial/samsung.c
+++ b/drivers/serial/samsung.c
@@ -705,8 +705,13 @@ static void s3c24xx_serial_set_termios(struct uart_port *port,
705 if (ourport->info->has_divslot) { 705 if (ourport->info->has_divslot) {
706 unsigned int div = ourport->baudclk_rate / baud; 706 unsigned int div = ourport->baudclk_rate / baud;
707 707
708 udivslot = udivslot_table[div & 15]; 708 if (cfg->has_fracval) {
709 dbg("udivslot = %04x (div %d)\n", udivslot, div & 15); 709 udivslot = (div & 15);
710 dbg("fracval = %04x\n", udivslot);
711 } else {
712 udivslot = udivslot_table[div & 15];
713 dbg("udivslot = %04x (div %d)\n", udivslot, div & 15);
714 }
710 } 715 }
711 716
712 switch (termios->c_cflag & CSIZE) { 717 switch (termios->c_cflag & CSIZE) {
diff --git a/drivers/serial/sh-sci.c b/drivers/serial/sh-sci.c
index 5f90fcd7d107..c291b3add1d2 100644
--- a/drivers/serial/sh-sci.c
+++ b/drivers/serial/sh-sci.c
@@ -346,6 +346,27 @@ static int scif_rxfill(struct uart_port *port)
346 return sci_in(port, SCFDR) & SCIF2_RFDC_MASK; 346 return sci_in(port, SCFDR) & SCIF2_RFDC_MASK;
347 } 347 }
348} 348}
349#elif defined(CONFIG_ARCH_SH7372)
350static int scif_txfill(struct uart_port *port)
351{
352 if (port->type == PORT_SCIFA)
353 return sci_in(port, SCFDR) >> 8;
354 else
355 return sci_in(port, SCTFDR);
356}
357
358static int scif_txroom(struct uart_port *port)
359{
360 return port->fifosize - scif_txfill(port);
361}
362
363static int scif_rxfill(struct uart_port *port)
364{
365 if (port->type == PORT_SCIFA)
366 return sci_in(port, SCFDR) & SCIF_RFDC_MASK;
367 else
368 return sci_in(port, SCRFDR);
369}
349#else 370#else
350static int scif_txfill(struct uart_port *port) 371static int scif_txfill(struct uart_port *port)
351{ 372{
@@ -683,7 +704,7 @@ static irqreturn_t sci_rx_interrupt(int irq, void *ptr)
683 u16 ssr = sci_in(port, SCxSR); 704 u16 ssr = sci_in(port, SCxSR);
684 705
685 /* Disable future Rx interrupts */ 706 /* Disable future Rx interrupts */
686 if (port->type == PORT_SCIFA) { 707 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
687 disable_irq_nosync(irq); 708 disable_irq_nosync(irq);
688 scr |= 0x4000; 709 scr |= 0x4000;
689 } else { 710 } else {
@@ -928,7 +949,7 @@ static void sci_dma_tx_complete(void *arg)
928 949
929 if (!uart_circ_empty(xmit)) { 950 if (!uart_circ_empty(xmit)) {
930 schedule_work(&s->work_tx); 951 schedule_work(&s->work_tx);
931 } else if (port->type == PORT_SCIFA) { 952 } else if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
932 u16 ctrl = sci_in(port, SCSCR); 953 u16 ctrl = sci_in(port, SCSCR);
933 sci_out(port, SCSCR, ctrl & ~SCI_CTRL_FLAGS_TIE); 954 sci_out(port, SCSCR, ctrl & ~SCI_CTRL_FLAGS_TIE);
934 } 955 }
@@ -1184,7 +1205,7 @@ static void sci_start_tx(struct uart_port *port)
1184 unsigned short ctrl; 1205 unsigned short ctrl;
1185 1206
1186#ifdef CONFIG_SERIAL_SH_SCI_DMA 1207#ifdef CONFIG_SERIAL_SH_SCI_DMA
1187 if (port->type == PORT_SCIFA) { 1208 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1188 u16 new, scr = sci_in(port, SCSCR); 1209 u16 new, scr = sci_in(port, SCSCR);
1189 if (s->chan_tx) 1210 if (s->chan_tx)
1190 new = scr | 0x8000; 1211 new = scr | 0x8000;
@@ -1197,7 +1218,7 @@ static void sci_start_tx(struct uart_port *port)
1197 s->cookie_tx < 0) 1218 s->cookie_tx < 0)
1198 schedule_work(&s->work_tx); 1219 schedule_work(&s->work_tx);
1199#endif 1220#endif
1200 if (!s->chan_tx || port->type == PORT_SCIFA) { 1221 if (!s->chan_tx || port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1201 /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */ 1222 /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */
1202 ctrl = sci_in(port, SCSCR); 1223 ctrl = sci_in(port, SCSCR);
1203 sci_out(port, SCSCR, ctrl | SCI_CTRL_FLAGS_TIE); 1224 sci_out(port, SCSCR, ctrl | SCI_CTRL_FLAGS_TIE);
@@ -1210,7 +1231,7 @@ static void sci_stop_tx(struct uart_port *port)
1210 1231
1211 /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */ 1232 /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */
1212 ctrl = sci_in(port, SCSCR); 1233 ctrl = sci_in(port, SCSCR);
1213 if (port->type == PORT_SCIFA) 1234 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
1214 ctrl &= ~0x8000; 1235 ctrl &= ~0x8000;
1215 ctrl &= ~SCI_CTRL_FLAGS_TIE; 1236 ctrl &= ~SCI_CTRL_FLAGS_TIE;
1216 sci_out(port, SCSCR, ctrl); 1237 sci_out(port, SCSCR, ctrl);
@@ -1222,7 +1243,7 @@ static void sci_start_rx(struct uart_port *port)
1222 1243
1223 /* Set RIE (Receive Interrupt Enable) bit in SCSCR */ 1244 /* Set RIE (Receive Interrupt Enable) bit in SCSCR */
1224 ctrl |= sci_in(port, SCSCR); 1245 ctrl |= sci_in(port, SCSCR);
1225 if (port->type == PORT_SCIFA) 1246 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
1226 ctrl &= ~0x4000; 1247 ctrl &= ~0x4000;
1227 sci_out(port, SCSCR, ctrl); 1248 sci_out(port, SCSCR, ctrl);
1228} 1249}
@@ -1233,7 +1254,7 @@ static void sci_stop_rx(struct uart_port *port)
1233 1254
1234 /* Clear RIE (Receive Interrupt Enable) bit in SCSCR */ 1255 /* Clear RIE (Receive Interrupt Enable) bit in SCSCR */
1235 ctrl = sci_in(port, SCSCR); 1256 ctrl = sci_in(port, SCSCR);
1236 if (port->type == PORT_SCIFA) 1257 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
1237 ctrl &= ~0x4000; 1258 ctrl &= ~0x4000;
1238 ctrl &= ~(SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE); 1259 ctrl &= ~(SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE);
1239 sci_out(port, SCSCR, ctrl); 1260 sci_out(port, SCSCR, ctrl);
@@ -1271,7 +1292,7 @@ static void rx_timer_fn(unsigned long arg)
1271 struct uart_port *port = &s->port; 1292 struct uart_port *port = &s->port;
1272 u16 scr = sci_in(port, SCSCR); 1293 u16 scr = sci_in(port, SCSCR);
1273 1294
1274 if (port->type == PORT_SCIFA) { 1295 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1275 scr &= ~0x4000; 1296 scr &= ~0x4000;
1276 enable_irq(s->irqs[1]); 1297 enable_irq(s->irqs[1]);
1277 } 1298 }
@@ -1524,6 +1545,8 @@ static const char *sci_type(struct uart_port *port)
1524 return "scif"; 1545 return "scif";
1525 case PORT_SCIFA: 1546 case PORT_SCIFA:
1526 return "scifa"; 1547 return "scifa";
1548 case PORT_SCIFB:
1549 return "scifb";
1527 } 1550 }
1528 1551
1529 return NULL; 1552 return NULL;
@@ -1612,6 +1635,9 @@ static int __devinit sci_init_single(struct platform_device *dev,
1612 port->line = index; 1635 port->line = index;
1613 1636
1614 switch (p->type) { 1637 switch (p->type) {
1638 case PORT_SCIFB:
1639 port->fifosize = 256;
1640 break;
1615 case PORT_SCIFA: 1641 case PORT_SCIFA:
1616 port->fifosize = 64; 1642 port->fifosize = 64;
1617 break; 1643 break;
diff --git a/drivers/serial/sh-sci.h b/drivers/serial/sh-sci.h
index f70c49f915fa..9b52f77a9305 100644
--- a/drivers/serial/sh-sci.h
+++ b/drivers/serial/sh-sci.h
@@ -322,7 +322,7 @@
322#define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\ 322#define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
323 static inline unsigned int sci_##name##_in(struct uart_port *port) \ 323 static inline unsigned int sci_##name##_in(struct uart_port *port) \
324 { \ 324 { \
325 if (port->type == PORT_SCIF) { \ 325 if (port->type == PORT_SCIF || port->type == PORT_SCIFB) { \
326 SCI_IN(scif_size, scif_offset) \ 326 SCI_IN(scif_size, scif_offset) \
327 } else { /* PORT_SCI or PORT_SCIFA */ \ 327 } else { /* PORT_SCI or PORT_SCIFA */ \
328 SCI_IN(sci_size, sci_offset); \ 328 SCI_IN(sci_size, sci_offset); \
@@ -330,7 +330,7 @@
330 } \ 330 } \
331 static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \ 331 static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
332 { \ 332 { \
333 if (port->type == PORT_SCIF) { \ 333 if (port->type == PORT_SCIF || port->type == PORT_SCIFB) { \
334 SCI_OUT(scif_size, scif_offset, value) \ 334 SCI_OUT(scif_size, scif_offset, value) \
335 } else { /* PORT_SCI or PORT_SCIFA */ \ 335 } else { /* PORT_SCI or PORT_SCIFA */ \
336 SCI_OUT(sci_size, sci_offset, value); \ 336 SCI_OUT(sci_size, sci_offset, value); \
@@ -384,8 +384,12 @@
384 defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 384 defined(CONFIG_CPU_SUBTYPE_SH7720) || \
385 defined(CONFIG_CPU_SUBTYPE_SH7721) || \ 385 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
386 defined(CONFIG_ARCH_SH7367) || \ 386 defined(CONFIG_ARCH_SH7367) || \
387 defined(CONFIG_ARCH_SH7377) || \ 387 defined(CONFIG_ARCH_SH7377)
388 defined(CONFIG_ARCH_SH7372) 388#define SCIF_FNS(name, scif_offset, scif_size) \
389 CPU_SCIF_FNS(name, scif_offset, scif_size)
390#elif defined(CONFIG_ARCH_SH7372)
391#define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scifb_offset, sh4_scifb_size) \
392 CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scifb_offset, sh4_scifb_size)
389#define SCIF_FNS(name, scif_offset, scif_size) \ 393#define SCIF_FNS(name, scif_offset, scif_size) \
390 CPU_SCIF_FNS(name, scif_offset, scif_size) 394 CPU_SCIF_FNS(name, scif_offset, scif_size)
391#else 395#else
@@ -422,8 +426,7 @@
422 defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 426 defined(CONFIG_CPU_SUBTYPE_SH7720) || \
423 defined(CONFIG_CPU_SUBTYPE_SH7721) || \ 427 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
424 defined(CONFIG_ARCH_SH7367) || \ 428 defined(CONFIG_ARCH_SH7367) || \
425 defined(CONFIG_ARCH_SH7377) || \ 429 defined(CONFIG_ARCH_SH7377)
426 defined(CONFIG_ARCH_SH7372)
427 430
428SCIF_FNS(SCSMR, 0x00, 16) 431SCIF_FNS(SCSMR, 0x00, 16)
429SCIF_FNS(SCBRR, 0x04, 8) 432SCIF_FNS(SCBRR, 0x04, 8)
@@ -436,6 +439,20 @@ SCIF_FNS(SCFDR, 0x1c, 16)
436SCIF_FNS(SCxTDR, 0x20, 8) 439SCIF_FNS(SCxTDR, 0x20, 8)
437SCIF_FNS(SCxRDR, 0x24, 8) 440SCIF_FNS(SCxRDR, 0x24, 8)
438SCIF_FNS(SCLSR, 0x00, 0) 441SCIF_FNS(SCLSR, 0x00, 0)
442#elif defined(CONFIG_ARCH_SH7372)
443SCIF_FNS(SCSMR, 0x00, 16)
444SCIF_FNS(SCBRR, 0x04, 8)
445SCIF_FNS(SCSCR, 0x08, 16)
446SCIF_FNS(SCTDSR, 0x0c, 16)
447SCIF_FNS(SCFER, 0x10, 16)
448SCIF_FNS(SCxSR, 0x14, 16)
449SCIF_FNS(SCFCR, 0x18, 16)
450SCIF_FNS(SCFDR, 0x1c, 16)
451SCIF_FNS(SCTFDR, 0x38, 16)
452SCIF_FNS(SCRFDR, 0x3c, 16)
453SCIx_FNS(SCxTDR, 0x20, 8, 0x40, 8)
454SCIx_FNS(SCxRDR, 0x24, 8, 0x60, 8)
455SCIF_FNS(SCLSR, 0x00, 0)
439#elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\ 456#elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\
440 defined(CONFIG_CPU_SUBTYPE_SH7724) 457 defined(CONFIG_CPU_SUBTYPE_SH7724)
441SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16) 458SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16)
diff --git a/drivers/serial/sunhv.c b/drivers/serial/sunhv.c
index a779e22d213e..c9014868297d 100644
--- a/drivers/serial/sunhv.c
+++ b/drivers/serial/sunhv.c
@@ -519,7 +519,7 @@ static struct console sunhv_console = {
519 .data = &sunhv_reg, 519 .data = &sunhv_reg,
520}; 520};
521 521
522static int __devinit hv_probe(struct of_device *op, const struct of_device_id *match) 522static int __devinit hv_probe(struct platform_device *op, const struct of_device_id *match)
523{ 523{
524 struct uart_port *port; 524 struct uart_port *port;
525 unsigned long minor; 525 unsigned long minor;
@@ -598,7 +598,7 @@ out_free_port:
598 return err; 598 return err;
599} 599}
600 600
601static int __devexit hv_remove(struct of_device *dev) 601static int __devexit hv_remove(struct platform_device *dev)
602{ 602{
603 struct uart_port *port = dev_get_drvdata(&dev->dev); 603 struct uart_port *port = dev_get_drvdata(&dev->dev);
604 604
diff --git a/drivers/serial/sunsab.c b/drivers/serial/sunsab.c
index 9845fb1cfb1f..5b246b18f42f 100644
--- a/drivers/serial/sunsab.c
+++ b/drivers/serial/sunsab.c
@@ -883,7 +883,7 @@ static int sunsab_console_setup(struct console *con, char *options)
883 printk("Console: ttyS%d (SAB82532)\n", 883 printk("Console: ttyS%d (SAB82532)\n",
884 (sunsab_reg.minor - 64) + con->index); 884 (sunsab_reg.minor - 64) + con->index);
885 885
886 sunserial_console_termios(con, to_of_device(up->port.dev)->dev.of_node); 886 sunserial_console_termios(con, up->port.dev->of_node);
887 887
888 switch (con->cflag & CBAUD) { 888 switch (con->cflag & CBAUD) {
889 case B150: baud = 150; break; 889 case B150: baud = 150; break;
@@ -954,7 +954,7 @@ static inline struct console *SUNSAB_CONSOLE(void)
954#endif 954#endif
955 955
956static int __devinit sunsab_init_one(struct uart_sunsab_port *up, 956static int __devinit sunsab_init_one(struct uart_sunsab_port *up,
957 struct of_device *op, 957 struct platform_device *op,
958 unsigned long offset, 958 unsigned long offset,
959 int line) 959 int line)
960{ 960{
@@ -1006,7 +1006,7 @@ static int __devinit sunsab_init_one(struct uart_sunsab_port *up,
1006 return 0; 1006 return 0;
1007} 1007}
1008 1008
1009static int __devinit sab_probe(struct of_device *op, const struct of_device_id *match) 1009static int __devinit sab_probe(struct platform_device *op, const struct of_device_id *match)
1010{ 1010{
1011 static int inst; 1011 static int inst;
1012 struct uart_sunsab_port *up; 1012 struct uart_sunsab_port *up;
@@ -1062,7 +1062,7 @@ out:
1062 return err; 1062 return err;
1063} 1063}
1064 1064
1065static int __devexit sab_remove(struct of_device *op) 1065static int __devexit sab_remove(struct platform_device *op)
1066{ 1066{
1067 struct uart_sunsab_port *up = dev_get_drvdata(&op->dev); 1067 struct uart_sunsab_port *up = dev_get_drvdata(&op->dev);
1068 1068
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index 3cdf74822db5..551ebfe3ccbb 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -1200,7 +1200,7 @@ static int __devinit sunsu_kbd_ms_init(struct uart_sunsu_port *up)
1200 return -ENODEV; 1200 return -ENODEV;
1201 1201
1202 printk("%s: %s port at %llx, irq %u\n", 1202 printk("%s: %s port at %llx, irq %u\n",
1203 to_of_device(up->port.dev)->dev.of_node->full_name, 1203 up->port.dev->of_node->full_name,
1204 (up->su_type == SU_PORT_KBD) ? "Keyboard" : "Mouse", 1204 (up->su_type == SU_PORT_KBD) ? "Keyboard" : "Mouse",
1205 (unsigned long long) up->port.mapbase, 1205 (unsigned long long) up->port.mapbase,
1206 up->port.irq); 1206 up->port.irq);
@@ -1352,7 +1352,7 @@ static int __init sunsu_console_setup(struct console *co, char *options)
1352 spin_lock_init(&port->lock); 1352 spin_lock_init(&port->lock);
1353 1353
1354 /* Get firmware console settings. */ 1354 /* Get firmware console settings. */
1355 sunserial_console_termios(co, to_of_device(port->dev)->dev.of_node); 1355 sunserial_console_termios(co, port->dev->of_node);
1356 1356
1357 memset(&termios, 0, sizeof(struct ktermios)); 1357 memset(&termios, 0, sizeof(struct ktermios));
1358 termios.c_cflag = co->cflag; 1358 termios.c_cflag = co->cflag;
@@ -1406,7 +1406,7 @@ static enum su_type __devinit su_get_type(struct device_node *dp)
1406 return SU_PORT_PORT; 1406 return SU_PORT_PORT;
1407} 1407}
1408 1408
1409static int __devinit su_probe(struct of_device *op, const struct of_device_id *match) 1409static int __devinit su_probe(struct platform_device *op, const struct of_device_id *match)
1410{ 1410{
1411 static int inst; 1411 static int inst;
1412 struct device_node *dp = op->dev.of_node; 1412 struct device_node *dp = op->dev.of_node;
@@ -1497,7 +1497,7 @@ out_unmap:
1497 return err; 1497 return err;
1498} 1498}
1499 1499
1500static int __devexit su_remove(struct of_device *op) 1500static int __devexit su_remove(struct platform_device *op)
1501{ 1501{
1502 struct uart_sunsu_port *up = dev_get_drvdata(&op->dev); 1502 struct uart_sunsu_port *up = dev_get_drvdata(&op->dev);
1503 bool kbdms = false; 1503 bool kbdms = false;
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index d1e6bcb59546..c1967ac1c07f 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -1230,7 +1230,7 @@ static int __init sunzilog_console_setup(struct console *con, char *options)
1230 (sunzilog_reg.minor - 64) + con->index, con->index); 1230 (sunzilog_reg.minor - 64) + con->index, con->index);
1231 1231
1232 /* Get firmware console settings. */ 1232 /* Get firmware console settings. */
1233 sunserial_console_termios(con, to_of_device(up->port.dev)->dev.of_node); 1233 sunserial_console_termios(con, up->port.dev->of_node);
1234 1234
1235 /* Firmware console speed is limited to 150-->38400 baud so 1235 /* Firmware console speed is limited to 150-->38400 baud so
1236 * this hackish cflag thing is OK. 1236 * this hackish cflag thing is OK.
@@ -1399,7 +1399,7 @@ static void __devinit sunzilog_init_hw(struct uart_sunzilog_port *up)
1399 1399
1400static int zilog_irq = -1; 1400static int zilog_irq = -1;
1401 1401
1402static int __devinit zs_probe(struct of_device *op, const struct of_device_id *match) 1402static int __devinit zs_probe(struct platform_device *op, const struct of_device_id *match)
1403{ 1403{
1404 static int kbm_inst, uart_inst; 1404 static int kbm_inst, uart_inst;
1405 int inst; 1405 int inst;
@@ -1516,7 +1516,7 @@ static void __devexit zs_remove_one(struct uart_sunzilog_port *up)
1516 uart_remove_one_port(&sunzilog_reg, &up->port); 1516 uart_remove_one_port(&sunzilog_reg, &up->port);
1517} 1517}
1518 1518
1519static int __devexit zs_remove(struct of_device *op) 1519static int __devexit zs_remove(struct platform_device *op)
1520{ 1520{
1521 struct uart_sunzilog_port *up = dev_get_drvdata(&op->dev); 1521 struct uart_sunzilog_port *up = dev_get_drvdata(&op->dev);
1522 struct zilog_layout __iomem *regs; 1522 struct zilog_layout __iomem *regs;
diff --git a/drivers/serial/uartlite.c b/drivers/serial/uartlite.c
index caf085d3a76a..9b03d7b3e456 100644
--- a/drivers/serial/uartlite.c
+++ b/drivers/serial/uartlite.c
@@ -584,7 +584,7 @@ static struct platform_driver ulite_platform_driver = {
584 */ 584 */
585#if defined(CONFIG_OF) && (defined(CONFIG_PPC32) || defined(CONFIG_MICROBLAZE)) 585#if defined(CONFIG_OF) && (defined(CONFIG_PPC32) || defined(CONFIG_MICROBLAZE))
586static int __devinit 586static int __devinit
587ulite_of_probe(struct of_device *op, const struct of_device_id *match) 587ulite_of_probe(struct platform_device *op, const struct of_device_id *match)
588{ 588{
589 struct resource res; 589 struct resource res;
590 const unsigned int *id; 590 const unsigned int *id;
@@ -605,7 +605,7 @@ ulite_of_probe(struct of_device *op, const struct of_device_id *match)
605 return ulite_assign(&op->dev, id ? *id : -1, res.start, irq); 605 return ulite_assign(&op->dev, id ? *id : -1, res.start, irq);
606} 606}
607 607
608static int __devexit ulite_of_remove(struct of_device *op) 608static int __devexit ulite_of_remove(struct platform_device *op)
609{ 609{
610 return ulite_release(&op->dev); 610 return ulite_release(&op->dev);
611} 611}
diff --git a/drivers/serial/ucc_uart.c b/drivers/serial/ucc_uart.c
index 907b06f5c447..3f4848e2174a 100644
--- a/drivers/serial/ucc_uart.c
+++ b/drivers/serial/ucc_uart.c
@@ -1194,7 +1194,7 @@ static void uart_firmware_cont(const struct firmware *fw, void *context)
1194 release_firmware(fw); 1194 release_firmware(fw);
1195} 1195}
1196 1196
1197static int ucc_uart_probe(struct of_device *ofdev, 1197static int ucc_uart_probe(struct platform_device *ofdev,
1198 const struct of_device_id *match) 1198 const struct of_device_id *match)
1199{ 1199{
1200 struct device_node *np = ofdev->dev.of_node; 1200 struct device_node *np = ofdev->dev.of_node;
@@ -1462,7 +1462,7 @@ static int ucc_uart_probe(struct of_device *ofdev,
1462 return 0; 1462 return 0;
1463} 1463}
1464 1464
1465static int ucc_uart_remove(struct of_device *ofdev) 1465static int ucc_uart_remove(struct platform_device *ofdev)
1466{ 1466{
1467 struct uart_qe_port *qe_port = dev_get_drvdata(&ofdev->dev); 1467 struct uart_qe_port *qe_port = dev_get_drvdata(&ofdev->dev);
1468 1468
diff --git a/drivers/sh/Makefile b/drivers/sh/Makefile
index 78bb5127abd0..08fc653a825c 100644
--- a/drivers/sh/Makefile
+++ b/drivers/sh/Makefile
@@ -1,9 +1,10 @@
1# 1#
2# Makefile for the SuperH specific drivers. 2# Makefile for the SuperH specific drivers.
3# 3#
4obj-y := clk.o intc.o
5
4obj-$(CONFIG_SUPERHYWAY) += superhyway/ 6obj-$(CONFIG_SUPERHYWAY) += superhyway/
5obj-$(CONFIG_MAPLE) += maple/ 7obj-$(CONFIG_MAPLE) += maple/
8
6obj-$(CONFIG_GENERIC_GPIO) += pfc.o 9obj-$(CONFIG_GENERIC_GPIO) += pfc.o
7obj-$(CONFIG_SUPERH) += clk.o
8obj-$(CONFIG_SH_CLK_CPG) += clk-cpg.o 10obj-$(CONFIG_SH_CLK_CPG) += clk-cpg.o
9obj-y += intc.o
diff --git a/drivers/sh/clk-cpg.c b/drivers/sh/clk-cpg.c
index f5c80ba9ab1c..8c024b984ed8 100644
--- a/drivers/sh/clk-cpg.c
+++ b/drivers/sh/clk-cpg.c
@@ -68,6 +68,39 @@ static unsigned long sh_clk_div6_recalc(struct clk *clk)
68 return clk->freq_table[idx].frequency; 68 return clk->freq_table[idx].frequency;
69} 69}
70 70
71static int sh_clk_div6_set_parent(struct clk *clk, struct clk *parent)
72{
73 struct clk_div_mult_table *table = &sh_clk_div6_table;
74 u32 value;
75 int ret, i;
76
77 if (!clk->parent_table || !clk->parent_num)
78 return -EINVAL;
79
80 /* Search the parent */
81 for (i = 0; i < clk->parent_num; i++)
82 if (clk->parent_table[i] == parent)
83 break;
84
85 if (i == clk->parent_num)
86 return -ENODEV;
87
88 ret = clk_reparent(clk, parent);
89 if (ret < 0)
90 return ret;
91
92 value = __raw_readl(clk->enable_reg) &
93 ~(((1 << clk->src_width) - 1) << clk->src_shift);
94
95 __raw_writel(value | (i << clk->src_shift), clk->enable_reg);
96
97 /* Rebuild the frequency table */
98 clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
99 table, &clk->arch_flags);
100
101 return 0;
102}
103
71static int sh_clk_div6_set_rate(struct clk *clk, 104static int sh_clk_div6_set_rate(struct clk *clk,
72 unsigned long rate, int algo_id) 105 unsigned long rate, int algo_id)
73{ 106{
@@ -117,7 +150,17 @@ static struct clk_ops sh_clk_div6_clk_ops = {
117 .disable = sh_clk_div6_disable, 150 .disable = sh_clk_div6_disable,
118}; 151};
119 152
120int __init sh_clk_div6_register(struct clk *clks, int nr) 153static struct clk_ops sh_clk_div6_reparent_clk_ops = {
154 .recalc = sh_clk_div6_recalc,
155 .round_rate = sh_clk_div_round_rate,
156 .set_rate = sh_clk_div6_set_rate,
157 .enable = sh_clk_div6_enable,
158 .disable = sh_clk_div6_disable,
159 .set_parent = sh_clk_div6_set_parent,
160};
161
162static int __init sh_clk_div6_register_ops(struct clk *clks, int nr,
163 struct clk_ops *ops)
121{ 164{
122 struct clk *clkp; 165 struct clk *clkp;
123 void *freq_table; 166 void *freq_table;
@@ -136,7 +179,7 @@ int __init sh_clk_div6_register(struct clk *clks, int nr)
136 for (k = 0; !ret && (k < nr); k++) { 179 for (k = 0; !ret && (k < nr); k++) {
137 clkp = clks + k; 180 clkp = clks + k;
138 181
139 clkp->ops = &sh_clk_div6_clk_ops; 182 clkp->ops = ops;
140 clkp->id = -1; 183 clkp->id = -1;
141 clkp->freq_table = freq_table + (k * freq_table_size); 184 clkp->freq_table = freq_table + (k * freq_table_size);
142 clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END; 185 clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
@@ -147,6 +190,17 @@ int __init sh_clk_div6_register(struct clk *clks, int nr)
147 return ret; 190 return ret;
148} 191}
149 192
193int __init sh_clk_div6_register(struct clk *clks, int nr)
194{
195 return sh_clk_div6_register_ops(clks, nr, &sh_clk_div6_clk_ops);
196}
197
198int __init sh_clk_div6_reparent_register(struct clk *clks, int nr)
199{
200 return sh_clk_div6_register_ops(clks, nr,
201 &sh_clk_div6_reparent_clk_ops);
202}
203
150static unsigned long sh_clk_div4_recalc(struct clk *clk) 204static unsigned long sh_clk_div4_recalc(struct clk *clk)
151{ 205{
152 struct clk_div4_table *d4t = clk->priv; 206 struct clk_div4_table *d4t = clk->priv;
diff --git a/drivers/spi/mpc512x_psc_spi.c b/drivers/spi/mpc512x_psc_spi.c
index 10baac3f8ea5..cddbfceb324f 100644
--- a/drivers/spi/mpc512x_psc_spi.c
+++ b/drivers/spi/mpc512x_psc_spi.c
@@ -507,7 +507,7 @@ static int __exit mpc512x_psc_spi_do_remove(struct device *dev)
507 return 0; 507 return 0;
508} 508}
509 509
510static int __init mpc512x_psc_spi_of_probe(struct of_device *op, 510static int __init mpc512x_psc_spi_of_probe(struct platform_device *op,
511 const struct of_device_id *match) 511 const struct of_device_id *match)
512{ 512{
513 const u32 *regaddr_p; 513 const u32 *regaddr_p;
@@ -539,7 +539,7 @@ static int __init mpc512x_psc_spi_of_probe(struct of_device *op,
539 irq_of_parse_and_map(op->dev.of_node, 0), id); 539 irq_of_parse_and_map(op->dev.of_node, 0), id);
540} 540}
541 541
542static int __exit mpc512x_psc_spi_of_remove(struct of_device *op) 542static int __exit mpc512x_psc_spi_of_remove(struct platform_device *op)
543{ 543{
544 return mpc512x_psc_spi_do_remove(&op->dev); 544 return mpc512x_psc_spi_do_remove(&op->dev);
545} 545}
diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c
index 66d170147dcc..983fbbfce76e 100644
--- a/drivers/spi/mpc52xx_psc_spi.c
+++ b/drivers/spi/mpc52xx_psc_spi.c
@@ -465,7 +465,7 @@ static int __exit mpc52xx_psc_spi_do_remove(struct device *dev)
465 return 0; 465 return 0;
466} 466}
467 467
468static int __init mpc52xx_psc_spi_of_probe(struct of_device *op, 468static int __init mpc52xx_psc_spi_of_probe(struct platform_device *op,
469 const struct of_device_id *match) 469 const struct of_device_id *match)
470{ 470{
471 const u32 *regaddr_p; 471 const u32 *regaddr_p;
@@ -495,7 +495,7 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
495 irq_of_parse_and_map(op->dev.of_node, 0), id); 495 irq_of_parse_and_map(op->dev.of_node, 0), id);
496} 496}
497 497
498static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op) 498static int __exit mpc52xx_psc_spi_of_remove(struct platform_device *op)
499{ 499{
500 return mpc52xx_psc_spi_do_remove(&op->dev); 500 return mpc52xx_psc_spi_do_remove(&op->dev);
501} 501}
diff --git a/drivers/spi/mpc52xx_spi.c b/drivers/spi/mpc52xx_spi.c
index 56136ff00e01..ec9f0b1bf864 100644
--- a/drivers/spi/mpc52xx_spi.c
+++ b/drivers/spi/mpc52xx_spi.c
@@ -390,7 +390,7 @@ static int mpc52xx_spi_transfer(struct spi_device *spi, struct spi_message *m)
390/* 390/*
391 * OF Platform Bus Binding 391 * OF Platform Bus Binding
392 */ 392 */
393static int __devinit mpc52xx_spi_probe(struct of_device *op, 393static int __devinit mpc52xx_spi_probe(struct platform_device *op,
394 const struct of_device_id *match) 394 const struct of_device_id *match)
395{ 395{
396 struct spi_master *master; 396 struct spi_master *master;
@@ -530,7 +530,7 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
530 return rc; 530 return rc;
531} 531}
532 532
533static int __devexit mpc52xx_spi_remove(struct of_device *op) 533static int __devexit mpc52xx_spi_remove(struct platform_device *op)
534{ 534{
535 struct spi_master *master = dev_get_drvdata(&op->dev); 535 struct spi_master *master = dev_get_drvdata(&op->dev);
536 struct mpc52xx_spi *ms = spi_master_get_devdata(master); 536 struct mpc52xx_spi *ms = spi_master_get_devdata(master);
diff --git a/drivers/spi/spi_mpc8xxx.c b/drivers/spi/spi_mpc8xxx.c
index aad9ae1b9c69..d31b57f7baaf 100644
--- a/drivers/spi/spi_mpc8xxx.c
+++ b/drivers/spi/spi_mpc8xxx.c
@@ -1236,7 +1236,7 @@ static int of_mpc8xxx_spi_free_chipselects(struct device *dev)
1236 return 0; 1236 return 0;
1237} 1237}
1238 1238
1239static int __devinit of_mpc8xxx_spi_probe(struct of_device *ofdev, 1239static int __devinit of_mpc8xxx_spi_probe(struct platform_device *ofdev,
1240 const struct of_device_id *ofid) 1240 const struct of_device_id *ofid)
1241{ 1241{
1242 struct device *dev = &ofdev->dev; 1242 struct device *dev = &ofdev->dev;
@@ -1308,7 +1308,7 @@ err_clk:
1308 return ret; 1308 return ret;
1309} 1309}
1310 1310
1311static int __devexit of_mpc8xxx_spi_remove(struct of_device *ofdev) 1311static int __devexit of_mpc8xxx_spi_remove(struct platform_device *ofdev)
1312{ 1312{
1313 int ret; 1313 int ret;
1314 1314
diff --git a/drivers/spi/spi_ppc4xx.c b/drivers/spi/spi_ppc4xx.c
index 0f5fa7e2a550..80e172d3e72a 100644
--- a/drivers/spi/spi_ppc4xx.c
+++ b/drivers/spi/spi_ppc4xx.c
@@ -388,9 +388,9 @@ static void free_gpios(struct ppc4xx_spi *hw)
388} 388}
389 389
390/* 390/*
391 * of_device layer stuff... 391 * platform_device layer stuff...
392 */ 392 */
393static int __init spi_ppc4xx_of_probe(struct of_device *op, 393static int __init spi_ppc4xx_of_probe(struct platform_device *op,
394 const struct of_device_id *match) 394 const struct of_device_id *match)
395{ 395{
396 struct ppc4xx_spi *hw; 396 struct ppc4xx_spi *hw;
@@ -565,7 +565,7 @@ free_master:
565 return ret; 565 return ret;
566} 566}
567 567
568static int __exit spi_ppc4xx_of_remove(struct of_device *op) 568static int __exit spi_ppc4xx_of_remove(struct platform_device *op)
569{ 569{
570 struct spi_master *master = dev_get_drvdata(&op->dev); 570 struct spi_master *master = dev_get_drvdata(&op->dev);
571 struct ppc4xx_spi *hw = spi_master_get_devdata(master); 571 struct ppc4xx_spi *hw = spi_master_get_devdata(master);
diff --git a/drivers/spi/xilinx_spi_of.c b/drivers/spi/xilinx_spi_of.c
index f53d3f6b9f61..b66c2dbf20a5 100644
--- a/drivers/spi/xilinx_spi_of.c
+++ b/drivers/spi/xilinx_spi_of.c
@@ -38,7 +38,7 @@
38#include "xilinx_spi.h" 38#include "xilinx_spi.h"
39 39
40 40
41static int __devinit xilinx_spi_of_probe(struct of_device *ofdev, 41static int __devinit xilinx_spi_of_probe(struct platform_device *ofdev,
42 const struct of_device_id *match) 42 const struct of_device_id *match)
43{ 43{
44 struct spi_master *master; 44 struct spi_master *master;
@@ -84,7 +84,7 @@ static int __devinit xilinx_spi_of_probe(struct of_device *ofdev,
84 return 0; 84 return 0;
85} 85}
86 86
87static int __devexit xilinx_spi_remove(struct of_device *ofdev) 87static int __devexit xilinx_spi_remove(struct platform_device *ofdev)
88{ 88{
89 xilinx_spi_deinit(dev_get_drvdata(&ofdev->dev)); 89 xilinx_spi_deinit(dev_get_drvdata(&ofdev->dev));
90 dev_set_drvdata(&ofdev->dev, 0); 90 dev_set_drvdata(&ofdev->dev, 0);
@@ -93,7 +93,7 @@ static int __devexit xilinx_spi_remove(struct of_device *ofdev)
93 return 0; 93 return 0;
94} 94}
95 95
96static int __exit xilinx_spi_of_remove(struct of_device *op) 96static int __exit xilinx_spi_of_remove(struct platform_device *op)
97{ 97{
98 return xilinx_spi_remove(op); 98 return xilinx_spi_remove(op);
99} 99}
diff --git a/drivers/staging/rtl8187se/r8180_core.c b/drivers/staging/rtl8187se/r8180_core.c
index 49ab9fa9ffa7..ed7457bc24ea 100644
--- a/drivers/staging/rtl8187se/r8180_core.c
+++ b/drivers/staging/rtl8187se/r8180_core.c
@@ -61,7 +61,7 @@ static struct pci_device_id rtl8180_pci_id_tbl[] __devinitdata = {
61}; 61};
62 62
63 63
64static char *ifname = "wlan%d"; 64static char ifname[IFNAMSIZ] = "wlan%d";
65static int hwseqnum = 0; 65static int hwseqnum = 0;
66static int hwwep = 0; 66static int hwwep = 0;
67static int channels = 0x3fff; 67static int channels = 0x3fff;
@@ -72,7 +72,7 @@ MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>");
72MODULE_DESCRIPTION("Linux driver for Realtek RTL8180 / RTL8185 WiFi cards"); 72MODULE_DESCRIPTION("Linux driver for Realtek RTL8180 / RTL8185 WiFi cards");
73 73
74 74
75module_param(ifname, charp, S_IRUGO|S_IWUSR); 75module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR);
76module_param(hwseqnum, int, S_IRUGO|S_IWUSR); 76module_param(hwseqnum, int, S_IRUGO|S_IWUSR);
77module_param(hwwep, int, S_IRUGO|S_IWUSR); 77module_param(hwwep, int, S_IRUGO|S_IWUSR);
78module_param(channels, int, S_IRUGO|S_IWUSR); 78module_param(channels, int, S_IRUGO|S_IWUSR);
@@ -3609,7 +3609,7 @@ static int __devinit rtl8180_pci_probe(struct pci_dev *pdev,
3609 3609
3610 if (dev_alloc_name(dev, ifname) < 0) { 3610 if (dev_alloc_name(dev, ifname) < 0) {
3611 DMESG("Oops: devname already taken! Trying wlan%%d...\n"); 3611 DMESG("Oops: devname already taken! Trying wlan%%d...\n");
3612 ifname = "wlan%d"; 3612 strcpy(ifname, "wlan%d");
3613 dev_alloc_name(dev, ifname); 3613 dev_alloc_name(dev, ifname);
3614 } 3614 }
3615 3615
diff --git a/drivers/staging/rtl8192e/r8192E_core.c b/drivers/staging/rtl8192e/r8192E_core.c
index 4cd071adf84b..17a806f9ee77 100644
--- a/drivers/staging/rtl8192e/r8192E_core.c
+++ b/drivers/staging/rtl8192e/r8192E_core.c
@@ -112,7 +112,7 @@ static const struct pci_device_id rtl8192_pci_id_tbl[] __devinitdata = {
112 {} 112 {}
113}; 113};
114 114
115static char* ifname = "wlan%d"; 115static char ifname[IFNAMSIZ] = "wlan%d";
116static int hwwep = 1; //default use hw. set 0 to use software security 116static int hwwep = 1; //default use hw. set 0 to use software security
117static int channels = 0x3fff; 117static int channels = 0x3fff;
118 118
@@ -123,7 +123,7 @@ MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl);
123MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards"); 123MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards");
124 124
125 125
126module_param(ifname, charp, S_IRUGO|S_IWUSR ); 126module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR);
127//module_param(hwseqnum,int, S_IRUGO|S_IWUSR); 127//module_param(hwseqnum,int, S_IRUGO|S_IWUSR);
128module_param(hwwep,int, S_IRUGO|S_IWUSR); 128module_param(hwwep,int, S_IRUGO|S_IWUSR);
129module_param(channels,int, S_IRUGO|S_IWUSR); 129module_param(channels,int, S_IRUGO|S_IWUSR);
@@ -6446,7 +6446,7 @@ static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
6446 6446
6447 if (dev_alloc_name(dev, ifname) < 0){ 6447 if (dev_alloc_name(dev, ifname) < 0){
6448 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n"); 6448 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
6449 ifname = "wlan%d"; 6449 strcpy(ifname, "wlan%d");
6450 dev_alloc_name(dev, ifname); 6450 dev_alloc_name(dev, ifname);
6451 } 6451 }
6452 6452
diff --git a/drivers/staging/rtl8192su/r8192U_core.c b/drivers/staging/rtl8192su/r8192U_core.c
index 6970c97713d8..df5b52baf893 100644
--- a/drivers/staging/rtl8192su/r8192U_core.c
+++ b/drivers/staging/rtl8192su/r8192U_core.c
@@ -144,13 +144,13 @@ MODULE_VERSION("V 1.1");
144MODULE_DEVICE_TABLE(usb, rtl8192_usb_id_tbl); 144MODULE_DEVICE_TABLE(usb, rtl8192_usb_id_tbl);
145MODULE_DESCRIPTION("Linux driver for Realtek RTL8192 USB WiFi cards"); 145MODULE_DESCRIPTION("Linux driver for Realtek RTL8192 USB WiFi cards");
146 146
147static char* ifname = "wlan%d"; 147static char ifname[IFNAMSIZ] = "wlan%d";
148static int hwwep = 1; //default use hw. set 0 to use software security 148static int hwwep = 1; //default use hw. set 0 to use software security
149static int channels = 0x3fff; 149static int channels = 0x3fff;
150 150
151 151
152 152
153module_param(ifname, charp, S_IRUGO|S_IWUSR ); 153module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR);
154//module_param(hwseqnum,int, S_IRUGO|S_IWUSR); 154//module_param(hwseqnum,int, S_IRUGO|S_IWUSR);
155module_param(hwwep,int, S_IRUGO|S_IWUSR); 155module_param(hwwep,int, S_IRUGO|S_IWUSR);
156module_param(channels,int, S_IRUGO|S_IWUSR); 156module_param(channels,int, S_IRUGO|S_IWUSR);
@@ -7406,7 +7406,7 @@ static int __devinit rtl8192_usb_probe(struct usb_interface *intf,
7406 7406
7407 if (dev_alloc_name(dev, ifname) < 0){ 7407 if (dev_alloc_name(dev, ifname) < 0){
7408 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n"); 7408 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
7409 ifname = "wlan%d"; 7409 strcpy(ifname, "wlan%d");
7410 dev_alloc_name(dev, ifname); 7410 dev_alloc_name(dev, ifname);
7411 } 7411 }
7412 7412
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index 5b3f555e01c9..ea071a5b6eee 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -1577,6 +1577,7 @@ static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1577 char file_arr[] = "CMVxy.bin"; 1577 char file_arr[] = "CMVxy.bin";
1578 char *file; 1578 char *file;
1579 1579
1580 kparam_block_sysfs_write(cmv_file);
1580 /* set proper name corresponding modem version and line type */ 1581 /* set proper name corresponding modem version and line type */
1581 if (cmv_file[sc->modem_index] == NULL) { 1582 if (cmv_file[sc->modem_index] == NULL) {
1582 if (UEA_CHIP_VERSION(sc) == ADI930) 1583 if (UEA_CHIP_VERSION(sc) == ADI930)
@@ -1595,6 +1596,7 @@ static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1595 strlcat(cmv_name, file, UEA_FW_NAME_MAX); 1596 strlcat(cmv_name, file, UEA_FW_NAME_MAX);
1596 if (ver == 2) 1597 if (ver == 2)
1597 strlcat(cmv_name, ".v2", UEA_FW_NAME_MAX); 1598 strlcat(cmv_name, ".v2", UEA_FW_NAME_MAX);
1599 kparam_unblock_sysfs_write(cmv_file);
1598} 1600}
1599 1601
1600static int request_cmvs_old(struct uea_softc *sc, 1602static int request_cmvs_old(struct uea_softc *sc,
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index 9648b75f0283..a5ea2c1d8c93 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -2398,7 +2398,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2398EXPORT_SYMBOL(usb_gadget_unregister_driver); 2398EXPORT_SYMBOL(usb_gadget_unregister_driver);
2399 2399
2400/* udc structure's alloc and setup, include ep-param alloc */ 2400/* udc structure's alloc and setup, include ep-param alloc */
2401static struct qe_udc __devinit *qe_udc_config(struct of_device *ofdev) 2401static struct qe_udc __devinit *qe_udc_config(struct platform_device *ofdev)
2402{ 2402{
2403 struct qe_udc *udc; 2403 struct qe_udc *udc;
2404 struct device_node *np = ofdev->dev.of_node; 2404 struct device_node *np = ofdev->dev.of_node;
@@ -2523,7 +2523,7 @@ static void qe_udc_release(struct device *dev)
2523} 2523}
2524 2524
2525/* Driver probe functions */ 2525/* Driver probe functions */
2526static int __devinit qe_udc_probe(struct of_device *ofdev, 2526static int __devinit qe_udc_probe(struct platform_device *ofdev,
2527 const struct of_device_id *match) 2527 const struct of_device_id *match)
2528{ 2528{
2529 struct device_node *np = ofdev->dev.of_node; 2529 struct device_node *np = ofdev->dev.of_node;
@@ -2679,18 +2679,18 @@ err1:
2679} 2679}
2680 2680
2681#ifdef CONFIG_PM 2681#ifdef CONFIG_PM
2682static int qe_udc_suspend(struct of_device *dev, pm_message_t state) 2682static int qe_udc_suspend(struct platform_device *dev, pm_message_t state)
2683{ 2683{
2684 return -ENOTSUPP; 2684 return -ENOTSUPP;
2685} 2685}
2686 2686
2687static int qe_udc_resume(struct of_device *dev) 2687static int qe_udc_resume(struct platform_device *dev)
2688{ 2688{
2689 return -ENOTSUPP; 2689 return -ENOTSUPP;
2690} 2690}
2691#endif 2691#endif
2692 2692
2693static int __devexit qe_udc_remove(struct of_device *ofdev) 2693static int __devexit qe_udc_remove(struct platform_device *ofdev)
2694{ 2694{
2695 struct qe_ep *ep; 2695 struct qe_ep *ep;
2696 unsigned int size; 2696 unsigned int size;
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
index 5aec92866ab3..335ee699fd85 100644
--- a/drivers/usb/host/ehci-ppc-of.c
+++ b/drivers/usb/host/ehci-ppc-of.c
@@ -106,7 +106,7 @@ ppc44x_enable_bmt(struct device_node *dn)
106 106
107 107
108static int __devinit 108static int __devinit
109ehci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match) 109ehci_hcd_ppc_of_probe(struct platform_device *op, const struct of_device_id *match)
110{ 110{
111 struct device_node *dn = op->dev.of_node; 111 struct device_node *dn = op->dev.of_node;
112 struct usb_hcd *hcd; 112 struct usb_hcd *hcd;
@@ -210,7 +210,7 @@ err_rmr:
210} 210}
211 211
212 212
213static int ehci_hcd_ppc_of_remove(struct of_device *op) 213static int ehci_hcd_ppc_of_remove(struct platform_device *op)
214{ 214{
215 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 215 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
216 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 216 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
@@ -253,7 +253,7 @@ static int ehci_hcd_ppc_of_remove(struct of_device *op)
253} 253}
254 254
255 255
256static int ehci_hcd_ppc_of_shutdown(struct of_device *op) 256static int ehci_hcd_ppc_of_shutdown(struct platform_device *op)
257{ 257{
258 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 258 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
259 259
diff --git a/drivers/usb/host/ehci-xilinx-of.c b/drivers/usb/host/ehci-xilinx-of.c
index 4899f451add9..6c8076ad821d 100644
--- a/drivers/usb/host/ehci-xilinx-of.c
+++ b/drivers/usb/host/ehci-xilinx-of.c
@@ -140,7 +140,7 @@ static const struct hc_driver ehci_xilinx_of_hc_driver = {
140 140
141/** 141/**
142 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller 142 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
143 * @op: pointer to the of_device to which the host controller bound 143 * @op: pointer to the platform_device bound to the host controller
144 * @match: pointer to of_device_id structure, not used 144 * @match: pointer to of_device_id structure, not used
145 * 145 *
146 * This function requests resources and sets up appropriate properties for the 146 * This function requests resources and sets up appropriate properties for the
@@ -149,7 +149,7 @@ static const struct hc_driver ehci_xilinx_of_hc_driver = {
149 * entry, and sets an appropriate value for hcd->has_tt. 149 * entry, and sets an appropriate value for hcd->has_tt.
150 */ 150 */
151static int __devinit 151static int __devinit
152ehci_hcd_xilinx_of_probe(struct of_device *op, const struct of_device_id *match) 152ehci_hcd_xilinx_of_probe(struct platform_device *op, const struct of_device_id *match)
153{ 153{
154 struct device_node *dn = op->dev.of_node; 154 struct device_node *dn = op->dev.of_node;
155 struct usb_hcd *hcd; 155 struct usb_hcd *hcd;
@@ -242,12 +242,12 @@ err_rmr:
242 242
243/** 243/**
244 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources 244 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
245 * @op: pointer to of_device structure that is to be removed 245 * @op: pointer to platform_device structure that is to be removed
246 * 246 *
247 * Remove the hcd structure, and release resources that has been requested 247 * Remove the hcd structure, and release resources that has been requested
248 * during probe. 248 * during probe.
249 */ 249 */
250static int ehci_hcd_xilinx_of_remove(struct of_device *op) 250static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
251{ 251{
252 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 252 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
253 dev_set_drvdata(&op->dev, NULL); 253 dev_set_drvdata(&op->dev, NULL);
@@ -266,11 +266,11 @@ static int ehci_hcd_xilinx_of_remove(struct of_device *op)
266 266
267/** 267/**
268 * ehci_hcd_xilinx_of_shutdown - shutdown the hcd 268 * ehci_hcd_xilinx_of_shutdown - shutdown the hcd
269 * @op: pointer to of_device structure that is to be removed 269 * @op: pointer to platform_device structure that is to be removed
270 * 270 *
271 * Properly shutdown the hcd, call driver's shutdown routine. 271 * Properly shutdown the hcd, call driver's shutdown routine.
272 */ 272 */
273static int ehci_hcd_xilinx_of_shutdown(struct of_device *op) 273static int ehci_hcd_xilinx_of_shutdown(struct platform_device *op)
274{ 274{
275 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 275 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
276 276
diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c
index c7c8392a88b9..20092a27a1e8 100644
--- a/drivers/usb/host/fhci-hcd.c
+++ b/drivers/usb/host/fhci-hcd.c
@@ -561,7 +561,7 @@ static const struct hc_driver fhci_driver = {
561 .hub_control = fhci_hub_control, 561 .hub_control = fhci_hub_control,
562}; 562};
563 563
564static int __devinit of_fhci_probe(struct of_device *ofdev, 564static int __devinit of_fhci_probe(struct platform_device *ofdev,
565 const struct of_device_id *ofid) 565 const struct of_device_id *ofid)
566{ 566{
567 struct device *dev = &ofdev->dev; 567 struct device *dev = &ofdev->dev;
@@ -801,7 +801,7 @@ static int __devexit fhci_remove(struct device *dev)
801 return 0; 801 return 0;
802} 802}
803 803
804static int __devexit of_fhci_remove(struct of_device *ofdev) 804static int __devexit of_fhci_remove(struct platform_device *ofdev)
805{ 805{
806 return fhci_remove(&ofdev->dev); 806 return fhci_remove(&ofdev->dev);
807} 807}
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index ec85d0c3cc3e..3b28dbfca058 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -27,7 +27,7 @@
27#endif 27#endif
28 28
29#ifdef CONFIG_PPC_OF 29#ifdef CONFIG_PPC_OF
30static int of_isp1760_probe(struct of_device *dev, 30static int of_isp1760_probe(struct platform_device *dev,
31 const struct of_device_id *match) 31 const struct of_device_id *match)
32{ 32{
33 struct usb_hcd *hcd; 33 struct usb_hcd *hcd;
@@ -95,7 +95,7 @@ release_reg:
95 return ret; 95 return ret;
96} 96}
97 97
98static int of_isp1760_remove(struct of_device *dev) 98static int of_isp1760_remove(struct platform_device *dev)
99{ 99{
100 struct usb_hcd *hcd = dev_get_drvdata(&dev->dev); 100 struct usb_hcd *hcd = dev_get_drvdata(&dev->dev);
101 101
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c
index cd74bbdd007c..653d6a60edb5 100644
--- a/drivers/usb/host/ohci-pnx4008.c
+++ b/drivers/usb/host/ohci-pnx4008.c
@@ -329,7 +329,7 @@ static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev)
329 memset(&i2c_info, 0, sizeof(struct i2c_board_info)); 329 memset(&i2c_info, 0, sizeof(struct i2c_board_info));
330 strlcpy(i2c_info.type, "isp1301_pnx", I2C_NAME_SIZE); 330 strlcpy(i2c_info.type, "isp1301_pnx", I2C_NAME_SIZE);
331 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, 331 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info,
332 normal_i2c); 332 normal_i2c, NULL);
333 i2c_put_adapter(i2c_adap); 333 i2c_put_adapter(i2c_adap);
334 if (!isp1301_i2c_client) { 334 if (!isp1301_i2c_client) {
335 err("failed to connect I2C to ISP1301 USB Transceiver"); 335 err("failed to connect I2C to ISP1301 USB Transceiver");
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c
index df165917412a..b2c2dbf08766 100644
--- a/drivers/usb/host/ohci-ppc-of.c
+++ b/drivers/usb/host/ohci-ppc-of.c
@@ -81,7 +81,7 @@ static const struct hc_driver ohci_ppc_of_hc_driver = {
81 81
82 82
83static int __devinit 83static int __devinit
84ohci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match) 84ohci_hcd_ppc_of_probe(struct platform_device *op, const struct of_device_id *match)
85{ 85{
86 struct device_node *dn = op->dev.of_node; 86 struct device_node *dn = op->dev.of_node;
87 struct usb_hcd *hcd; 87 struct usb_hcd *hcd;
@@ -183,7 +183,7 @@ err_rmr:
183 return rv; 183 return rv;
184} 184}
185 185
186static int ohci_hcd_ppc_of_remove(struct of_device *op) 186static int ohci_hcd_ppc_of_remove(struct platform_device *op)
187{ 187{
188 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 188 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
189 dev_set_drvdata(&op->dev, NULL); 189 dev_set_drvdata(&op->dev, NULL);
@@ -201,7 +201,7 @@ static int ohci_hcd_ppc_of_remove(struct of_device *op)
201 return 0; 201 return 0;
202} 202}
203 203
204static int ohci_hcd_ppc_of_shutdown(struct of_device *op) 204static int ohci_hcd_ppc_of_shutdown(struct platform_device *op)
205{ 205{
206 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 206 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
207 207
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index a9ca72f301bf..8b31fdfefc98 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -1896,6 +1896,13 @@ config FB_W100
1896 1896
1897 If unsure, say N. 1897 If unsure, say N.
1898 1898
1899config SH_MIPI_DSI
1900 tristate
1901 depends on (SUPERH || ARCH_SHMOBILE) && HAVE_CLK
1902
1903config SH_LCD_MIPI_DSI
1904 bool
1905
1899config FB_SH_MOBILE_LCDC 1906config FB_SH_MOBILE_LCDC
1900 tristate "SuperH Mobile LCDC framebuffer support" 1907 tristate "SuperH Mobile LCDC framebuffer support"
1901 depends on FB && (SUPERH || ARCH_SHMOBILE) && HAVE_CLK 1908 depends on FB && (SUPERH || ARCH_SHMOBILE) && HAVE_CLK
@@ -1904,9 +1911,17 @@ config FB_SH_MOBILE_LCDC
1904 select FB_SYS_IMAGEBLIT 1911 select FB_SYS_IMAGEBLIT
1905 select FB_SYS_FOPS 1912 select FB_SYS_FOPS
1906 select FB_DEFERRED_IO 1913 select FB_DEFERRED_IO
1914 select SH_MIPI_DSI if SH_LCD_MIPI_DSI
1907 ---help--- 1915 ---help---
1908 Frame buffer driver for the on-chip SH-Mobile LCD controller. 1916 Frame buffer driver for the on-chip SH-Mobile LCD controller.
1909 1917
1918config FB_SH_MOBILE_HDMI
1919 tristate "SuperH Mobile HDMI controller support"
1920 depends on FB_SH_MOBILE_LCDC
1921 select FB_MODE_HELPERS
1922 ---help---
1923 Driver for the on-chip SH-Mobile HDMI controller.
1924
1910config FB_TMIO 1925config FB_TMIO
1911 tristate "Toshiba Mobile IO FrameBuffer support" 1926 tristate "Toshiba Mobile IO FrameBuffer support"
1912 depends on FB && MFD_CORE 1927 depends on FB && MFD_CORE
@@ -1931,7 +1946,7 @@ config FB_TMIO_ACCELL
1931 1946
1932config FB_S3C 1947config FB_S3C
1933 tristate "Samsung S3C framebuffer support" 1948 tristate "Samsung S3C framebuffer support"
1934 depends on FB && ARCH_S3C64XX 1949 depends on FB && S3C_DEV_FB
1935 select FB_CFB_FILLRECT 1950 select FB_CFB_FILLRECT
1936 select FB_CFB_COPYAREA 1951 select FB_CFB_COPYAREA
1937 select FB_CFB_IMAGEBLIT 1952 select FB_CFB_IMAGEBLIT
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index f56a9cae2157..485e8ed1318c 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -123,6 +123,8 @@ obj-$(CONFIG_FB_IBM_GXT4500) += gxt4500.o
123obj-$(CONFIG_FB_PS3) += ps3fb.o 123obj-$(CONFIG_FB_PS3) += ps3fb.o
124obj-$(CONFIG_FB_SM501) += sm501fb.o 124obj-$(CONFIG_FB_SM501) += sm501fb.o
125obj-$(CONFIG_FB_XILINX) += xilinxfb.o 125obj-$(CONFIG_FB_XILINX) += xilinxfb.o
126obj-$(CONFIG_SH_MIPI_DSI) += sh_mipi_dsi.o
127obj-$(CONFIG_FB_SH_MOBILE_HDMI) += sh_mobile_hdmi.o
126obj-$(CONFIG_FB_SH_MOBILE_LCDC) += sh_mobile_lcdcfb.o 128obj-$(CONFIG_FB_SH_MOBILE_LCDC) += sh_mobile_lcdcfb.o
127obj-$(CONFIG_FB_OMAP) += omap/ 129obj-$(CONFIG_FB_OMAP) += omap/
128obj-y += omap2/ 130obj-y += omap2/
diff --git a/drivers/video/bw2.c b/drivers/video/bw2.c
index c7796637bafd..4dc13467281d 100644
--- a/drivers/video/bw2.c
+++ b/drivers/video/bw2.c
@@ -273,7 +273,7 @@ static int __devinit bw2_do_default_mode(struct bw2_par *par,
273 return 0; 273 return 0;
274} 274}
275 275
276static int __devinit bw2_probe(struct of_device *op, const struct of_device_id *match) 276static int __devinit bw2_probe(struct platform_device *op, const struct of_device_id *match)
277{ 277{
278 struct device_node *dp = op->dev.of_node; 278 struct device_node *dp = op->dev.of_node;
279 struct fb_info *info; 279 struct fb_info *info;
@@ -350,7 +350,7 @@ out_err:
350 return err; 350 return err;
351} 351}
352 352
353static int __devexit bw2_remove(struct of_device *op) 353static int __devexit bw2_remove(struct platform_device *op)
354{ 354{
355 struct fb_info *info = dev_get_drvdata(&op->dev); 355 struct fb_info *info = dev_get_drvdata(&op->dev);
356 struct bw2_par *par = info->par; 356 struct bw2_par *par = info->par;
diff --git a/drivers/video/cg14.c b/drivers/video/cg14.c
index d09fde8beb69..24249535ac86 100644
--- a/drivers/video/cg14.c
+++ b/drivers/video/cg14.c
@@ -446,7 +446,7 @@ static struct sbus_mmap_map __cg14_mmap_map[CG14_MMAP_ENTRIES] __devinitdata = {
446 { .size = 0 } 446 { .size = 0 }
447}; 447};
448 448
449static void cg14_unmap_regs(struct of_device *op, struct fb_info *info, 449static void cg14_unmap_regs(struct platform_device *op, struct fb_info *info,
450 struct cg14_par *par) 450 struct cg14_par *par)
451{ 451{
452 if (par->regs) 452 if (par->regs)
@@ -463,7 +463,7 @@ static void cg14_unmap_regs(struct of_device *op, struct fb_info *info,
463 info->screen_base, info->fix.smem_len); 463 info->screen_base, info->fix.smem_len);
464} 464}
465 465
466static int __devinit cg14_probe(struct of_device *op, const struct of_device_id *match) 466static int __devinit cg14_probe(struct platform_device *op, const struct of_device_id *match)
467{ 467{
468 struct device_node *dp = op->dev.of_node; 468 struct device_node *dp = op->dev.of_node;
469 struct fb_info *info; 469 struct fb_info *info;
@@ -570,7 +570,7 @@ out_err:
570 return err; 570 return err;
571} 571}
572 572
573static int __devexit cg14_remove(struct of_device *op) 573static int __devexit cg14_remove(struct platform_device *op)
574{ 574{
575 struct fb_info *info = dev_get_drvdata(&op->dev); 575 struct fb_info *info = dev_get_drvdata(&op->dev);
576 struct cg14_par *par = info->par; 576 struct cg14_par *par = info->par;
diff --git a/drivers/video/cg3.c b/drivers/video/cg3.c
index 64aa29809fb9..09c0c3c42482 100644
--- a/drivers/video/cg3.c
+++ b/drivers/video/cg3.c
@@ -346,7 +346,7 @@ static int __devinit cg3_do_default_mode(struct cg3_par *par)
346 return 0; 346 return 0;
347} 347}
348 348
349static int __devinit cg3_probe(struct of_device *op, 349static int __devinit cg3_probe(struct platform_device *op,
350 const struct of_device_id *match) 350 const struct of_device_id *match)
351{ 351{
352 struct device_node *dp = op->dev.of_node; 352 struct device_node *dp = op->dev.of_node;
@@ -433,7 +433,7 @@ out_err:
433 return err; 433 return err;
434} 434}
435 435
436static int __devexit cg3_remove(struct of_device *op) 436static int __devexit cg3_remove(struct platform_device *op)
437{ 437{
438 struct fb_info *info = dev_get_drvdata(&op->dev); 438 struct fb_info *info = dev_get_drvdata(&op->dev);
439 struct cg3_par *par = info->par; 439 struct cg3_par *par = info->par;
diff --git a/drivers/video/cg6.c b/drivers/video/cg6.c
index 2389a719dcc7..2b5a97058b08 100644
--- a/drivers/video/cg6.c
+++ b/drivers/video/cg6.c
@@ -718,7 +718,7 @@ static void __devinit cg6_chip_init(struct fb_info *info)
718 sbus_writel(info->var.yres - 1, &fbc->clipmaxy); 718 sbus_writel(info->var.yres - 1, &fbc->clipmaxy);
719} 719}
720 720
721static void cg6_unmap_regs(struct of_device *op, struct fb_info *info, 721static void cg6_unmap_regs(struct platform_device *op, struct fb_info *info,
722 struct cg6_par *par) 722 struct cg6_par *par)
723{ 723{
724 if (par->fbc) 724 if (par->fbc)
@@ -737,7 +737,7 @@ static void cg6_unmap_regs(struct of_device *op, struct fb_info *info,
737 info->fix.smem_len); 737 info->fix.smem_len);
738} 738}
739 739
740static int __devinit cg6_probe(struct of_device *op, 740static int __devinit cg6_probe(struct platform_device *op,
741 const struct of_device_id *match) 741 const struct of_device_id *match)
742{ 742{
743 struct device_node *dp = op->dev.of_node; 743 struct device_node *dp = op->dev.of_node;
@@ -827,7 +827,7 @@ out_err:
827 return err; 827 return err;
828} 828}
829 829
830static int __devexit cg6_remove(struct of_device *op) 830static int __devexit cg6_remove(struct platform_device *op)
831{ 831{
832 struct fb_info *info = dev_get_drvdata(&op->dev); 832 struct fb_info *info = dev_get_drvdata(&op->dev);
833 struct cg6_par *par = info->par; 833 struct cg6_par *par = info->par;
diff --git a/drivers/video/console/bitblit.c b/drivers/video/console/bitblit.c
index af88651b0735..28b1a834906b 100644
--- a/drivers/video/console/bitblit.c
+++ b/drivers/video/console/bitblit.c
@@ -22,7 +22,7 @@
22/* 22/*
23 * Accelerated handlers. 23 * Accelerated handlers.
24 */ 24 */
25static inline void update_attr(u8 *dst, u8 *src, int attribute, 25static void update_attr(u8 *dst, u8 *src, int attribute,
26 struct vc_data *vc) 26 struct vc_data *vc)
27{ 27{
28 int i, offset = (vc->vc_font.height < 10) ? 1 : 2; 28 int i, offset = (vc->vc_font.height < 10) ? 1 : 2;
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 26bf7cbfecc2..84f842331dfa 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -287,7 +287,7 @@ static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
287 !vt_force_oops_output(vc); 287 !vt_force_oops_output(vc);
288} 288}
289 289
290static inline int get_color(struct vc_data *vc, struct fb_info *info, 290static int get_color(struct vc_data *vc, struct fb_info *info,
291 u16 c, int is_fg) 291 u16 c, int is_fg)
292{ 292{
293 int depth = fb_get_color_depth(&info->var, &info->fix); 293 int depth = fb_get_color_depth(&info->var, &info->fix);
diff --git a/drivers/video/console/fbcon_ccw.c b/drivers/video/console/fbcon_ccw.c
index d135671d9961..41b32ae23dac 100644
--- a/drivers/video/console/fbcon_ccw.c
+++ b/drivers/video/console/fbcon_ccw.c
@@ -22,7 +22,7 @@
22 * Rotation 270 degrees 22 * Rotation 270 degrees
23 */ 23 */
24 24
25static inline void ccw_update_attr(u8 *dst, u8 *src, int attribute, 25static void ccw_update_attr(u8 *dst, u8 *src, int attribute,
26 struct vc_data *vc) 26 struct vc_data *vc)
27{ 27{
28 int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2; 28 int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2;
diff --git a/drivers/video/console/fbcon_cw.c b/drivers/video/console/fbcon_cw.c
index 126110f8454f..6a737827beb1 100644
--- a/drivers/video/console/fbcon_cw.c
+++ b/drivers/video/console/fbcon_cw.c
@@ -22,7 +22,7 @@
22 * Rotation 90 degrees 22 * Rotation 90 degrees
23 */ 23 */
24 24
25static inline void cw_update_attr(u8 *dst, u8 *src, int attribute, 25static void cw_update_attr(u8 *dst, u8 *src, int attribute,
26 struct vc_data *vc) 26 struct vc_data *vc)
27{ 27{
28 int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2; 28 int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2;
diff --git a/drivers/video/console/fbcon_ud.c b/drivers/video/console/fbcon_ud.c
index 93a3e7381b50..ff0872c0498b 100644
--- a/drivers/video/console/fbcon_ud.c
+++ b/drivers/video/console/fbcon_ud.c
@@ -22,7 +22,7 @@
22 * Rotation 180 degrees 22 * Rotation 180 degrees
23 */ 23 */
24 24
25static inline void ud_update_attr(u8 *dst, u8 *src, int attribute, 25static void ud_update_attr(u8 *dst, u8 *src, int attribute,
26 struct vc_data *vc) 26 struct vc_data *vc)
27{ 27{
28 int i, offset = (vc->vc_font.height < 10) ? 1 : 2; 28 int i, offset = (vc->vc_font.height < 10) ? 1 : 2;
diff --git a/drivers/video/efifb.c b/drivers/video/efifb.c
index 4a56f46af40a..815f84b07933 100644
--- a/drivers/video/efifb.c
+++ b/drivers/video/efifb.c
@@ -16,7 +16,7 @@
16 16
17#include <video/vga.h> 17#include <video/vga.h>
18 18
19static struct fb_var_screeninfo efifb_defined __initdata = { 19static struct fb_var_screeninfo efifb_defined __devinitdata = {
20 .activate = FB_ACTIVATE_NOW, 20 .activate = FB_ACTIVATE_NOW,
21 .height = -1, 21 .height = -1,
22 .width = -1, 22 .width = -1,
@@ -27,7 +27,7 @@ static struct fb_var_screeninfo efifb_defined __initdata = {
27 .vmode = FB_VMODE_NONINTERLACED, 27 .vmode = FB_VMODE_NONINTERLACED,
28}; 28};
29 29
30static struct fb_fix_screeninfo efifb_fix __initdata = { 30static struct fb_fix_screeninfo efifb_fix __devinitdata = {
31 .id = "EFI VGA", 31 .id = "EFI VGA",
32 .type = FB_TYPE_PACKED_PIXELS, 32 .type = FB_TYPE_PACKED_PIXELS,
33 .accel = FB_ACCEL_NONE, 33 .accel = FB_ACCEL_NONE,
@@ -59,7 +59,7 @@ static struct efifb_dmi_info {
59 int stride; 59 int stride;
60 int width; 60 int width;
61 int height; 61 int height;
62} dmi_list[] = { 62} dmi_list[] __initdata = {
63 [M_I17] = { "i17", 0x80010000, 1472 * 4, 1440, 900 }, 63 [M_I17] = { "i17", 0x80010000, 1472 * 4, 1440, 900 },
64 [M_I20] = { "i20", 0x80010000, 1728 * 4, 1680, 1050 }, /* guess */ 64 [M_I20] = { "i20", 0x80010000, 1728 * 4, 1680, 1050 }, /* guess */
65 [M_I20_SR] = { "imac7", 0x40010000, 1728 * 4, 1680, 1050 }, 65 [M_I20_SR] = { "imac7", 0x40010000, 1728 * 4, 1680, 1050 },
@@ -83,7 +83,7 @@ static int set_system(const struct dmi_system_id *id);
83 DMI_MATCH(DMI_PRODUCT_NAME, name) }, \ 83 DMI_MATCH(DMI_PRODUCT_NAME, name) }, \
84 &dmi_list[enumid] } 84 &dmi_list[enumid] }
85 85
86static struct dmi_system_id __initdata dmi_system_table[] = { 86static const struct dmi_system_id dmi_system_table[] __initconst = {
87 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac4,1", M_I17), 87 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac4,1", M_I17),
88 /* At least one of these two will be right; maybe both? */ 88 /* At least one of these two will be right; maybe both? */
89 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac5,1", M_I20), 89 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac5,1", M_I20),
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 731fce64df9d..b06647517c0e 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -1362,6 +1362,7 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
1362 vma->vm_pgoff = off >> PAGE_SHIFT; 1362 vma->vm_pgoff = off >> PAGE_SHIFT;
1363 /* This is an IO map - tell maydump to skip this VMA */ 1363 /* This is an IO map - tell maydump to skip this VMA */
1364 vma->vm_flags |= VM_IO | VM_RESERVED; 1364 vma->vm_flags |= VM_IO | VM_RESERVED;
1365 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1365 fb_pgprotect(file, vma, off); 1366 fb_pgprotect(file, vma, off);
1366 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, 1367 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
1367 vma->vm_end - vma->vm_start, vma->vm_page_prot)) 1368 vma->vm_end - vma->vm_start, vma->vm_page_prot))
@@ -1786,7 +1787,7 @@ static int ofonly __read_mostly;
1786int fb_get_options(char *name, char **option) 1787int fb_get_options(char *name, char **option)
1787{ 1788{
1788 char *opt, *options = NULL; 1789 char *opt, *options = NULL;
1789 int opt_len, retval = 0; 1790 int retval = 0;
1790 int name_len = strlen(name), i; 1791 int name_len = strlen(name), i;
1791 1792
1792 if (name_len && ofonly && strncmp(name, "offb", 4)) 1793 if (name_len && ofonly && strncmp(name, "offb", 4))
@@ -1796,8 +1797,7 @@ int fb_get_options(char *name, char **option)
1796 for (i = 0; i < FB_MAX; i++) { 1797 for (i = 0; i < FB_MAX; i++) {
1797 if (video_options[i] == NULL) 1798 if (video_options[i] == NULL)
1798 continue; 1799 continue;
1799 opt_len = strlen(video_options[i]); 1800 if (!video_options[i][0])
1800 if (!opt_len)
1801 continue; 1801 continue;
1802 opt = video_options[i]; 1802 opt = video_options[i];
1803 if (!strncmp(name, opt, name_len) && 1803 if (!strncmp(name, opt, name_len) &&
diff --git a/drivers/video/ffb.c b/drivers/video/ffb.c
index f6ecfab296d3..6739b2af3bc0 100644
--- a/drivers/video/ffb.c
+++ b/drivers/video/ffb.c
@@ -893,7 +893,7 @@ static void ffb_init_fix(struct fb_info *info)
893 info->fix.accel = FB_ACCEL_SUN_CREATOR; 893 info->fix.accel = FB_ACCEL_SUN_CREATOR;
894} 894}
895 895
896static int __devinit ffb_probe(struct of_device *op, 896static int __devinit ffb_probe(struct platform_device *op,
897 const struct of_device_id *match) 897 const struct of_device_id *match)
898{ 898{
899 struct device_node *dp = op->dev.of_node; 899 struct device_node *dp = op->dev.of_node;
@@ -1023,7 +1023,7 @@ out_err:
1023 return err; 1023 return err;
1024} 1024}
1025 1025
1026static int __devexit ffb_remove(struct of_device *op) 1026static int __devexit ffb_remove(struct platform_device *op)
1027{ 1027{
1028 struct fb_info *info = dev_get_drvdata(&op->dev); 1028 struct fb_info *info = dev_get_drvdata(&op->dev);
1029 struct ffb_par *par = info->par; 1029 struct ffb_par *par = info->par;
diff --git a/drivers/video/fsl-diu-fb.c b/drivers/video/fsl-diu-fb.c
index e38ad2224540..8bbbf08fa3ce 100644
--- a/drivers/video/fsl-diu-fb.c
+++ b/drivers/video/fsl-diu-fb.c
@@ -1393,7 +1393,7 @@ static void free_irq_local(int irq)
1393 * Power management hooks. Note that we won't be called from IRQ context, 1393 * Power management hooks. Note that we won't be called from IRQ context,
1394 * unlike the blank functions above, so we may sleep. 1394 * unlike the blank functions above, so we may sleep.
1395 */ 1395 */
1396static int fsl_diu_suspend(struct of_device *ofdev, pm_message_t state) 1396static int fsl_diu_suspend(struct platform_device *ofdev, pm_message_t state)
1397{ 1397{
1398 struct fsl_diu_data *machine_data; 1398 struct fsl_diu_data *machine_data;
1399 1399
@@ -1403,7 +1403,7 @@ static int fsl_diu_suspend(struct of_device *ofdev, pm_message_t state)
1403 return 0; 1403 return 0;
1404} 1404}
1405 1405
1406static int fsl_diu_resume(struct of_device *ofdev) 1406static int fsl_diu_resume(struct platform_device *ofdev)
1407{ 1407{
1408 struct fsl_diu_data *machine_data; 1408 struct fsl_diu_data *machine_data;
1409 1409
@@ -1487,7 +1487,7 @@ static ssize_t show_monitor(struct device *device,
1487 return diu_ops.show_monitor_port(machine_data->monitor_port, buf); 1487 return diu_ops.show_monitor_port(machine_data->monitor_port, buf);
1488} 1488}
1489 1489
1490static int __devinit fsl_diu_probe(struct of_device *ofdev, 1490static int __devinit fsl_diu_probe(struct platform_device *ofdev,
1491 const struct of_device_id *match) 1491 const struct of_device_id *match)
1492{ 1492{
1493 struct device_node *np = ofdev->dev.of_node; 1493 struct device_node *np = ofdev->dev.of_node;
@@ -1667,7 +1667,7 @@ error2:
1667} 1667}
1668 1668
1669 1669
1670static int fsl_diu_remove(struct of_device *ofdev) 1670static int fsl_diu_remove(struct platform_device *ofdev)
1671{ 1671{
1672 struct fsl_diu_data *machine_data; 1672 struct fsl_diu_data *machine_data;
1673 int i; 1673 int i;
diff --git a/drivers/video/igafb.c b/drivers/video/igafb.c
index 15d200109446..d885c770eb84 100644
--- a/drivers/video/igafb.c
+++ b/drivers/video/igafb.c
@@ -368,7 +368,7 @@ static int __init iga_init(struct fb_info *info, struct iga_par *par)
368 return 1; 368 return 1;
369} 369}
370 370
371int __init igafb_init(void) 371static int __init igafb_init(void)
372{ 372{
373 struct fb_info *info; 373 struct fb_info *info;
374 struct pci_dev *pdev; 374 struct pci_dev *pdev;
@@ -531,6 +531,7 @@ int __init igafb_init(void)
531 iounmap(info->screen_base); 531 iounmap(info->screen_base);
532 kfree(par->mmap_map); 532 kfree(par->mmap_map);
533 kfree(info); 533 kfree(info);
534 return -ENODEV;
534 } 535 }
535 536
536#ifdef CONFIG_SPARC 537#ifdef CONFIG_SPARC
@@ -556,7 +557,7 @@ int __init igafb_init(void)
556 return 0; 557 return 0;
557} 558}
558 559
559int __init igafb_setup(char *options) 560static int __init igafb_setup(char *options)
560{ 561{
561 char *this_opt; 562 char *this_opt;
562 563
diff --git a/drivers/video/imxfb.c b/drivers/video/imxfb.c
index 43f0639b1c10..5c363d026f64 100644
--- a/drivers/video/imxfb.c
+++ b/drivers/video/imxfb.c
@@ -40,6 +40,12 @@
40 */ 40 */
41#define DEBUG_VAR 1 41#define DEBUG_VAR 1
42 42
43#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || \
44 (defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE) && \
45 defined(CONFIG_FB_IMX_MODULE))
46#define PWMR_BACKLIGHT_AVAILABLE
47#endif
48
43#define DRIVER_NAME "imx-fb" 49#define DRIVER_NAME "imx-fb"
44 50
45#define LCDC_SSA 0x00 51#define LCDC_SSA 0x00
@@ -175,7 +181,9 @@ struct imxfb_info {
175 181
176 struct imx_fb_videomode *mode; 182 struct imx_fb_videomode *mode;
177 int num_modes; 183 int num_modes;
184#ifdef PWMR_BACKLIGHT_AVAILABLE
178 struct backlight_device *bl; 185 struct backlight_device *bl;
186#endif
179 187
180 void (*lcd_power)(int); 188 void (*lcd_power)(int);
181 void (*backlight_power)(int); 189 void (*backlight_power)(int);
@@ -450,8 +458,7 @@ static int imxfb_set_par(struct fb_info *info)
450 return 0; 458 return 0;
451} 459}
452 460
453 461#ifdef PWMR_BACKLIGHT_AVAILABLE
454
455static int imxfb_bl_get_brightness(struct backlight_device *bl) 462static int imxfb_bl_get_brightness(struct backlight_device *bl)
456{ 463{
457 struct imxfb_info *fbi = bl_get_data(bl); 464 struct imxfb_info *fbi = bl_get_data(bl);
@@ -516,6 +523,7 @@ static void imxfb_exit_backlight(struct imxfb_info *fbi)
516 if (fbi->bl) 523 if (fbi->bl)
517 backlight_device_unregister(fbi->bl); 524 backlight_device_unregister(fbi->bl);
518} 525}
526#endif
519 527
520static void imxfb_enable_controller(struct imxfb_info *fbi) 528static void imxfb_enable_controller(struct imxfb_info *fbi)
521{ 529{
@@ -647,6 +655,9 @@ static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *inf
647 fbi->regs + LCDC_SIZE); 655 fbi->regs + LCDC_SIZE);
648 656
649 writel(fbi->pcr, fbi->regs + LCDC_PCR); 657 writel(fbi->pcr, fbi->regs + LCDC_PCR);
658#ifndef PWMR_BACKLIGHT_AVAILABLE
659 writel(fbi->pwmr, fbi->regs + LCDC_PWMR);
660#endif
650 writel(fbi->lscr1, fbi->regs + LCDC_LSCR1); 661 writel(fbi->lscr1, fbi->regs + LCDC_LSCR1);
651 writel(fbi->dmacr, fbi->regs + LCDC_DMACR); 662 writel(fbi->dmacr, fbi->regs + LCDC_DMACR);
652 663
@@ -847,7 +858,9 @@ static int __init imxfb_probe(struct platform_device *pdev)
847 858
848 imxfb_enable_controller(fbi); 859 imxfb_enable_controller(fbi);
849 fbi->pdev = pdev; 860 fbi->pdev = pdev;
861#ifdef PWMR_BACKLIGHT_AVAILABLE
850 imxfb_init_backlight(fbi); 862 imxfb_init_backlight(fbi);
863#endif
851 864
852 return 0; 865 return 0;
853 866
@@ -885,7 +898,9 @@ static int __devexit imxfb_remove(struct platform_device *pdev)
885 898
886 imxfb_disable_controller(fbi); 899 imxfb_disable_controller(fbi);
887 900
901#ifdef PWMR_BACKLIGHT_AVAILABLE
888 imxfb_exit_backlight(fbi); 902 imxfb_exit_backlight(fbi);
903#endif
889 unregister_framebuffer(info); 904 unregister_framebuffer(info);
890 905
891 pdata = pdev->dev.platform_data; 906 pdata = pdev->dev.platform_data;
diff --git a/drivers/video/leo.c b/drivers/video/leo.c
index ad677637ffbb..b599e5e36ced 100644
--- a/drivers/video/leo.c
+++ b/drivers/video/leo.c
@@ -529,7 +529,7 @@ static void leo_fixup_var_rgb(struct fb_var_screeninfo *var)
529 var->transp.length = 0; 529 var->transp.length = 0;
530} 530}
531 531
532static void leo_unmap_regs(struct of_device *op, struct fb_info *info, 532static void leo_unmap_regs(struct platform_device *op, struct fb_info *info,
533 struct leo_par *par) 533 struct leo_par *par)
534{ 534{
535 if (par->lc_ss0_usr) 535 if (par->lc_ss0_usr)
@@ -547,7 +547,7 @@ static void leo_unmap_regs(struct of_device *op, struct fb_info *info,
547 of_iounmap(&op->resource[0], info->screen_base, 0x800000); 547 of_iounmap(&op->resource[0], info->screen_base, 0x800000);
548} 548}
549 549
550static int __devinit leo_probe(struct of_device *op, 550static int __devinit leo_probe(struct platform_device *op,
551 const struct of_device_id *match) 551 const struct of_device_id *match)
552{ 552{
553 struct device_node *dp = op->dev.of_node; 553 struct device_node *dp = op->dev.of_node;
@@ -637,7 +637,7 @@ out_err:
637 return err; 637 return err;
638} 638}
639 639
640static int __devexit leo_remove(struct of_device *op) 640static int __devexit leo_remove(struct platform_device *op)
641{ 641{
642 struct fb_info *info = dev_get_drvdata(&op->dev); 642 struct fb_info *info = dev_get_drvdata(&op->dev);
643 struct leo_par *par = info->par; 643 struct leo_par *par = info->par;
diff --git a/drivers/video/matrox/i2c-matroxfb.c b/drivers/video/matrox/i2c-matroxfb.c
index 403b14445a78..0fb280ead3dc 100644
--- a/drivers/video/matrox/i2c-matroxfb.c
+++ b/drivers/video/matrox/i2c-matroxfb.c
@@ -191,7 +191,7 @@ static void* i2c_matroxfb_probe(struct matrox_fb_info* minfo) {
191 }; 191 };
192 192
193 i2c_new_probed_device(&m2info->maven.adapter, 193 i2c_new_probed_device(&m2info->maven.adapter,
194 &maven_info, addr_list); 194 &maven_info, addr_list, NULL);
195 } 195 }
196 } 196 }
197 return m2info; 197 return m2info;
diff --git a/drivers/video/mb862xx/mb862xxfb.c b/drivers/video/mb862xx/mb862xxfb.c
index 4e2b8cc3d460..b1c4374cf940 100644
--- a/drivers/video/mb862xx/mb862xxfb.c
+++ b/drivers/video/mb862xx/mb862xxfb.c
@@ -550,7 +550,7 @@ static int mb862xx_gdc_init(struct mb862xxfb_par *par)
550 return 0; 550 return 0;
551} 551}
552 552
553static int __devinit of_platform_mb862xx_probe(struct of_device *ofdev, 553static int __devinit of_platform_mb862xx_probe(struct platform_device *ofdev,
554 const struct of_device_id *id) 554 const struct of_device_id *id)
555{ 555{
556 struct device_node *np = ofdev->dev.of_node; 556 struct device_node *np = ofdev->dev.of_node;
@@ -669,7 +669,7 @@ fbrel:
669 return ret; 669 return ret;
670} 670}
671 671
672static int __devexit of_platform_mb862xx_remove(struct of_device *ofdev) 672static int __devexit of_platform_mb862xx_remove(struct platform_device *ofdev)
673{ 673{
674 struct fb_info *fbi = dev_get_drvdata(&ofdev->dev); 674 struct fb_info *fbi = dev_get_drvdata(&ofdev->dev);
675 struct mb862xxfb_par *par = fbi->par; 675 struct mb862xxfb_par *par = fbi->par;
diff --git a/drivers/video/msm/mddi.c b/drivers/video/msm/mddi.c
index c1ff271017a9..7c316c34dfca 100644
--- a/drivers/video/msm/mddi.c
+++ b/drivers/video/msm/mddi.c
@@ -187,10 +187,8 @@ static void mddi_wait_interrupt(struct mddi_info *mddi, uint32_t intmask);
187 187
188static void mddi_handle_rev_data_avail(struct mddi_info *mddi) 188static void mddi_handle_rev_data_avail(struct mddi_info *mddi)
189{ 189{
190 union mddi_rev *rev = mddi->rev_data;
191 uint32_t rev_data_count; 190 uint32_t rev_data_count;
192 uint32_t rev_crc_err_count; 191 uint32_t rev_crc_err_count;
193 int i;
194 struct reg_read_info *ri; 192 struct reg_read_info *ri;
195 size_t prev_offset; 193 size_t prev_offset;
196 uint16_t length; 194 uint16_t length;
@@ -670,7 +668,7 @@ static int __init mddi_rev_data_setup(struct mddi_info *mddi)
670 return 0; 668 return 0;
671} 669}
672 670
673static int __init mddi_probe(struct platform_device *pdev) 671static int __devinit mddi_probe(struct platform_device *pdev)
674{ 672{
675 struct msm_mddi_platform_data *pdata = pdev->dev.platform_data; 673 struct msm_mddi_platform_data *pdata = pdev->dev.platform_data;
676 struct mddi_info *mddi = &mddi_info[pdev->id]; 674 struct mddi_info *mddi = &mddi_info[pdev->id];
diff --git a/drivers/video/msm/mdp.c b/drivers/video/msm/mdp.c
index 19c01c6208e8..3c28db03ad39 100644
--- a/drivers/video/msm/mdp.c
+++ b/drivers/video/msm/mdp.c
@@ -258,7 +258,6 @@ int get_img(struct mdp_img *img, struct fb_info *info,
258{ 258{
259 int put_needed, ret = 0; 259 int put_needed, ret = 0;
260 struct file *file; 260 struct file *file;
261 unsigned long vstart;
262 261
263 file = fget_light(img->memory_id, &put_needed); 262 file = fget_light(img->memory_id, &put_needed);
264 if (file == NULL) 263 if (file == NULL)
diff --git a/drivers/video/p9100.c b/drivers/video/p9100.c
index 688b055abab2..b6c3fc2db632 100644
--- a/drivers/video/p9100.c
+++ b/drivers/video/p9100.c
@@ -249,7 +249,7 @@ static void p9100_init_fix(struct fb_info *info, int linebytes, struct device_no
249 info->fix.accel = FB_ACCEL_SUN_CGTHREE; 249 info->fix.accel = FB_ACCEL_SUN_CGTHREE;
250} 250}
251 251
252static int __devinit p9100_probe(struct of_device *op, const struct of_device_id *match) 252static int __devinit p9100_probe(struct platform_device *op, const struct of_device_id *match)
253{ 253{
254 struct device_node *dp = op->dev.of_node; 254 struct device_node *dp = op->dev.of_node;
255 struct fb_info *info; 255 struct fb_info *info;
@@ -326,7 +326,7 @@ out_err:
326 return err; 326 return err;
327} 327}
328 328
329static int __devexit p9100_remove(struct of_device *op) 329static int __devexit p9100_remove(struct platform_device *op)
330{ 330{
331 struct fb_info *info = dev_get_drvdata(&op->dev); 331 struct fb_info *info = dev_get_drvdata(&op->dev);
332 struct p9100_par *par = info->par; 332 struct p9100_par *par = info->par;
diff --git a/drivers/video/platinumfb.c b/drivers/video/platinumfb.c
index 72a1f4c04732..a50e1977b316 100644
--- a/drivers/video/platinumfb.c
+++ b/drivers/video/platinumfb.c
@@ -533,7 +533,7 @@ static int __init platinumfb_setup(char *options)
533#define invalidate_cache(addr) 533#define invalidate_cache(addr)
534#endif 534#endif
535 535
536static int __devinit platinumfb_probe(struct of_device* odev, 536static int __devinit platinumfb_probe(struct platform_device* odev,
537 const struct of_device_id *match) 537 const struct of_device_id *match)
538{ 538{
539 struct device_node *dp = odev->dev.of_node; 539 struct device_node *dp = odev->dev.of_node;
@@ -646,7 +646,7 @@ static int __devinit platinumfb_probe(struct of_device* odev,
646 return rc; 646 return rc;
647} 647}
648 648
649static int __devexit platinumfb_remove(struct of_device* odev) 649static int __devexit platinumfb_remove(struct platform_device* odev)
650{ 650{
651 struct fb_info *info = dev_get_drvdata(&odev->dev); 651 struct fb_info *info = dev_get_drvdata(&odev->dev);
652 struct fb_info_platinum *pinfo = info->par; 652 struct fb_info_platinum *pinfo = info->par;
diff --git a/drivers/video/s3c-fb.c b/drivers/video/s3c-fb.c
index 9682ecc60e12..f9aca9d13d1b 100644
--- a/drivers/video/s3c-fb.c
+++ b/drivers/video/s3c-fb.c
@@ -1,7 +1,7 @@
1/* linux/drivers/video/s3c-fb.c 1/* linux/drivers/video/s3c-fb.c
2 * 2 *
3 * Copyright 2008 Openmoko Inc. 3 * Copyright 2008 Openmoko Inc.
4 * Copyright 2008 Simtec Electronics 4 * Copyright 2008-2010 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk> 5 * Ben Dooks <ben@simtec.co.uk>
6 * http://armlinux.simtec.co.uk/ 6 * http://armlinux.simtec.co.uk/
7 * 7 *
@@ -9,7 +9,7 @@
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as 11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. 12 * published by the Free Software FoundatIon.
13*/ 13*/
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
@@ -21,9 +21,11 @@
21#include <linux/clk.h> 21#include <linux/clk.h>
22#include <linux/fb.h> 22#include <linux/fb.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/uaccess.h>
25#include <linux/interrupt.h>
24 26
25#include <mach/map.h> 27#include <mach/map.h>
26#include <mach/regs-fb.h> 28#include <plat/regs-fb-v4.h>
27#include <plat/fb.h> 29#include <plat/fb.h>
28 30
29/* This driver will export a number of framebuffer interfaces depending 31/* This driver will export a number of framebuffer interfaces depending
@@ -36,9 +38,9 @@
36 * output timings and as the control for the output power-down state. 38 * output timings and as the control for the output power-down state.
37*/ 39*/
38 40
39/* note, some of the functions that get called are derived from including 41/* note, the previous use of <mach/regs-fb.h> to get platform specific data
40 * <mach/regs-fb.h> as they are specific to the architecture that the code 42 * has been replaced by using the platform device name to pick the correct
41 * is being built for. 43 * configuration data for the system.
42*/ 44*/
43 45
44#ifdef CONFIG_FB_S3C_DEBUG_REGWRITE 46#ifdef CONFIG_FB_S3C_DEBUG_REGWRITE
@@ -48,13 +50,108 @@
48 __raw_writel(v, r); } while(0) 50 __raw_writel(v, r); } while(0)
49#endif /* FB_S3C_DEBUG_REGWRITE */ 51#endif /* FB_S3C_DEBUG_REGWRITE */
50 52
53/* irq_flags bits */
54#define S3C_FB_VSYNC_IRQ_EN 0
55
56#define VSYNC_TIMEOUT_MSEC 50
57
51struct s3c_fb; 58struct s3c_fb;
52 59
60#define VALID_BPP(x) (1 << ((x) - 1))
61
62#define OSD_BASE(win, variant) ((variant).osd + ((win) * (variant).osd_stride))
63#define VIDOSD_A(win, variant) (OSD_BASE(win, variant) + 0x00)
64#define VIDOSD_B(win, variant) (OSD_BASE(win, variant) + 0x04)
65#define VIDOSD_C(win, variant) (OSD_BASE(win, variant) + 0x08)
66#define VIDOSD_D(win, variant) (OSD_BASE(win, variant) + 0x0C)
67
68/**
69 * struct s3c_fb_variant - fb variant information
70 * @is_2443: Set if S3C2443/S3C2416 style hardware.
71 * @nr_windows: The number of windows.
72 * @vidtcon: The base for the VIDTCONx registers
73 * @wincon: The base for the WINxCON registers.
74 * @winmap: The base for the WINxMAP registers.
75 * @keycon: The abse for the WxKEYCON registers.
76 * @buf_start: Offset of buffer start registers.
77 * @buf_size: Offset of buffer size registers.
78 * @buf_end: Offset of buffer end registers.
79 * @osd: The base for the OSD registers.
80 * @palette: Address of palette memory, or 0 if none.
81 * @has_prtcon: Set if has PRTCON register.
82 * @has_shadowcon: Set if has SHADOWCON register.
83 */
84struct s3c_fb_variant {
85 unsigned int is_2443:1;
86 unsigned short nr_windows;
87 unsigned short vidtcon;
88 unsigned short wincon;
89 unsigned short winmap;
90 unsigned short keycon;
91 unsigned short buf_start;
92 unsigned short buf_end;
93 unsigned short buf_size;
94 unsigned short osd;
95 unsigned short osd_stride;
96 unsigned short palette[S3C_FB_MAX_WIN];
97
98 unsigned int has_prtcon:1;
99 unsigned int has_shadowcon:1;
100};
101
102/**
103 * struct s3c_fb_win_variant
104 * @has_osd_c: Set if has OSD C register.
105 * @has_osd_d: Set if has OSD D register.
106 * @has_osd_alpha: Set if can change alpha transparency for a window.
107 * @palette_sz: Size of palette in entries.
108 * @palette_16bpp: Set if palette is 16bits wide.
109 * @osd_size_off: If != 0, supports setting up OSD for a window; the appropriate
110 * register is located at the given offset from OSD_BASE.
111 * @valid_bpp: 1 bit per BPP setting to show valid bits-per-pixel.
112 *
113 * valid_bpp bit x is set if (x+1)BPP is supported.
114 */
115struct s3c_fb_win_variant {
116 unsigned int has_osd_c:1;
117 unsigned int has_osd_d:1;
118 unsigned int has_osd_alpha:1;
119 unsigned int palette_16bpp:1;
120 unsigned short osd_size_off;
121 unsigned short palette_sz;
122 u32 valid_bpp;
123};
124
125/**
126 * struct s3c_fb_driverdata - per-device type driver data for init time.
127 * @variant: The variant information for this driver.
128 * @win: The window information for each window.
129 */
130struct s3c_fb_driverdata {
131 struct s3c_fb_variant variant;
132 struct s3c_fb_win_variant *win[S3C_FB_MAX_WIN];
133};
134
135/**
136 * struct s3c_fb_palette - palette information
137 * @r: Red bitfield.
138 * @g: Green bitfield.
139 * @b: Blue bitfield.
140 * @a: Alpha bitfield.
141 */
142struct s3c_fb_palette {
143 struct fb_bitfield r;
144 struct fb_bitfield g;
145 struct fb_bitfield b;
146 struct fb_bitfield a;
147};
148
53/** 149/**
54 * struct s3c_fb_win - per window private data for each framebuffer. 150 * struct s3c_fb_win - per window private data for each framebuffer.
55 * @windata: The platform data supplied for the window configuration. 151 * @windata: The platform data supplied for the window configuration.
56 * @parent: The hardware that this window is part of. 152 * @parent: The hardware that this window is part of.
57 * @fbinfo: Pointer pack to the framebuffer info for this window. 153 * @fbinfo: Pointer pack to the framebuffer info for this window.
154 * @varint: The variant information for this window.
58 * @palette_buffer: Buffer/cache to hold palette entries. 155 * @palette_buffer: Buffer/cache to hold palette entries.
59 * @pseudo_palette: For use in TRUECOLOUR modes for entries 0..15/ 156 * @pseudo_palette: For use in TRUECOLOUR modes for entries 0..15/
60 * @index: The window number of this window. 157 * @index: The window number of this window.
@@ -65,6 +162,7 @@ struct s3c_fb_win {
65 struct s3c_fb *parent; 162 struct s3c_fb *parent;
66 struct fb_info *fbinfo; 163 struct fb_info *fbinfo;
67 struct s3c_fb_palette palette; 164 struct s3c_fb_palette palette;
165 struct s3c_fb_win_variant variant;
68 166
69 u32 *palette_buffer; 167 u32 *palette_buffer;
70 u32 pseudo_palette[16]; 168 u32 pseudo_palette[16];
@@ -72,37 +170,54 @@ struct s3c_fb_win {
72}; 170};
73 171
74/** 172/**
173 * struct s3c_fb_vsync - vsync information
174 * @wait: a queue for processes waiting for vsync
175 * @count: vsync interrupt count
176 */
177struct s3c_fb_vsync {
178 wait_queue_head_t wait;
179 unsigned int count;
180};
181
182/**
75 * struct s3c_fb - overall hardware state of the hardware 183 * struct s3c_fb - overall hardware state of the hardware
76 * @dev: The device that we bound to, for printing, etc. 184 * @dev: The device that we bound to, for printing, etc.
77 * @regs_res: The resource we claimed for the IO registers. 185 * @regs_res: The resource we claimed for the IO registers.
78 * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk. 186 * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk.
79 * @regs: The mapped hardware registers. 187 * @regs: The mapped hardware registers.
188 * @variant: Variant information for this hardware.
80 * @enabled: A bitmask of enabled hardware windows. 189 * @enabled: A bitmask of enabled hardware windows.
81 * @pdata: The platform configuration data passed with the device. 190 * @pdata: The platform configuration data passed with the device.
82 * @windows: The hardware windows that have been claimed. 191 * @windows: The hardware windows that have been claimed.
192 * @irq_no: IRQ line number
193 * @irq_flags: irq flags
194 * @vsync_info: VSYNC-related information (count, queues...)
83 */ 195 */
84struct s3c_fb { 196struct s3c_fb {
85 struct device *dev; 197 struct device *dev;
86 struct resource *regs_res; 198 struct resource *regs_res;
87 struct clk *bus_clk; 199 struct clk *bus_clk;
88 void __iomem *regs; 200 void __iomem *regs;
201 struct s3c_fb_variant variant;
89 202
90 unsigned char enabled; 203 unsigned char enabled;
91 204
92 struct s3c_fb_platdata *pdata; 205 struct s3c_fb_platdata *pdata;
93 struct s3c_fb_win *windows[S3C_FB_MAX_WIN]; 206 struct s3c_fb_win *windows[S3C_FB_MAX_WIN];
207
208 int irq_no;
209 unsigned long irq_flags;
210 struct s3c_fb_vsync vsync_info;
94}; 211};
95 212
96/** 213/**
97 * s3c_fb_win_has_palette() - determine if a mode has a palette 214 * s3c_fb_validate_win_bpp - validate the bits-per-pixel for this mode.
98 * @win: The window number being queried. 215 * @win: The device window.
99 * @bpp: The number of bits per pixel to test. 216 * @bpp: The bit depth.
100 *
101 * Work out if the given window supports palletised data at the specified bpp.
102 */ 217 */
103static int s3c_fb_win_has_palette(unsigned int win, unsigned int bpp) 218static bool s3c_fb_validate_win_bpp(struct s3c_fb_win *win, unsigned int bpp)
104{ 219{
105 return s3c_fb_win_pal_size(win) <= (1 << bpp); 220 return win->variant.valid_bpp & VALID_BPP(bpp);
106} 221}
107 222
108/** 223/**
@@ -125,7 +240,7 @@ static int s3c_fb_check_var(struct fb_var_screeninfo *var,
125 var->xres_virtual = max((unsigned int)windata->virtual_x, var->xres); 240 var->xres_virtual = max((unsigned int)windata->virtual_x, var->xres);
126 var->yres_virtual = max((unsigned int)windata->virtual_y, var->yres); 241 var->yres_virtual = max((unsigned int)windata->virtual_y, var->yres);
127 242
128 if (!s3c_fb_validate_win_bpp(win->index, var->bits_per_pixel)) { 243 if (!s3c_fb_validate_win_bpp(win, var->bits_per_pixel)) {
129 dev_dbg(sfb->dev, "win %d: unsupported bpp %d\n", 244 dev_dbg(sfb->dev, "win %d: unsupported bpp %d\n",
130 win->index, var->bits_per_pixel); 245 win->index, var->bits_per_pixel);
131 return -EINVAL; 246 return -EINVAL;
@@ -140,7 +255,7 @@ static int s3c_fb_check_var(struct fb_var_screeninfo *var,
140 case 2: 255 case 2:
141 case 4: 256 case 4:
142 case 8: 257 case 8:
143 if (!s3c_fb_win_has_palette(win->index, var->bits_per_pixel)) { 258 if (sfb->variant.palette[win->index] != 0) {
144 /* non palletised, A:1,R:2,G:3,B:2 mode */ 259 /* non palletised, A:1,R:2,G:3,B:2 mode */
145 var->red.offset = 4; 260 var->red.offset = 4;
146 var->green.offset = 2; 261 var->green.offset = 2;
@@ -255,6 +370,66 @@ static int s3c_fb_align_word(unsigned int bpp, unsigned int pix)
255} 370}
256 371
257/** 372/**
373 * vidosd_set_size() - set OSD size for a window
374 *
375 * @win: the window to set OSD size for
376 * @size: OSD size register value
377 */
378static void vidosd_set_size(struct s3c_fb_win *win, u32 size)
379{
380 struct s3c_fb *sfb = win->parent;
381
382 /* OSD can be set up if osd_size_off != 0 for this window */
383 if (win->variant.osd_size_off)
384 writel(size, sfb->regs + OSD_BASE(win->index, sfb->variant)
385 + win->variant.osd_size_off);
386}
387
388/**
389 * vidosd_set_alpha() - set alpha transparency for a window
390 *
391 * @win: the window to set OSD size for
392 * @alpha: alpha register value
393 */
394static void vidosd_set_alpha(struct s3c_fb_win *win, u32 alpha)
395{
396 struct s3c_fb *sfb = win->parent;
397
398 if (win->variant.has_osd_alpha)
399 writel(alpha, sfb->regs + VIDOSD_C(win->index, sfb->variant));
400}
401
402/**
403 * shadow_protect_win() - disable updating values from shadow registers at vsync
404 *
405 * @win: window to protect registers for
406 * @protect: 1 to protect (disable updates)
407 */
408static void shadow_protect_win(struct s3c_fb_win *win, bool protect)
409{
410 struct s3c_fb *sfb = win->parent;
411 u32 reg;
412
413 if (protect) {
414 if (sfb->variant.has_prtcon) {
415 writel(PRTCON_PROTECT, sfb->regs + PRTCON);
416 } else if (sfb->variant.has_shadowcon) {
417 reg = readl(sfb->regs + SHADOWCON);
418 writel(reg | SHADOWCON_WINx_PROTECT(win->index),
419 sfb->regs + SHADOWCON);
420 }
421 } else {
422 if (sfb->variant.has_prtcon) {
423 writel(0, sfb->regs + PRTCON);
424 } else if (sfb->variant.has_shadowcon) {
425 reg = readl(sfb->regs + SHADOWCON);
426 writel(reg & ~SHADOWCON_WINx_PROTECT(win->index),
427 sfb->regs + SHADOWCON);
428 }
429 }
430}
431
432/**
258 * s3c_fb_set_par() - framebuffer request to set new framebuffer state. 433 * s3c_fb_set_par() - framebuffer request to set new framebuffer state.
259 * @info: The framebuffer to change. 434 * @info: The framebuffer to change.
260 * 435 *
@@ -266,14 +441,17 @@ static int s3c_fb_set_par(struct fb_info *info)
266 struct s3c_fb_win *win = info->par; 441 struct s3c_fb_win *win = info->par;
267 struct s3c_fb *sfb = win->parent; 442 struct s3c_fb *sfb = win->parent;
268 void __iomem *regs = sfb->regs; 443 void __iomem *regs = sfb->regs;
444 void __iomem *buf = regs;
269 int win_no = win->index; 445 int win_no = win->index;
270 u32 osdc_data = 0; 446 u32 alpha = 0;
271 u32 data; 447 u32 data;
272 u32 pagewidth; 448 u32 pagewidth;
273 int clkdiv; 449 int clkdiv;
274 450
275 dev_dbg(sfb->dev, "setting framebuffer parameters\n"); 451 dev_dbg(sfb->dev, "setting framebuffer parameters\n");
276 452
453 shadow_protect_win(win, 1);
454
277 switch (var->bits_per_pixel) { 455 switch (var->bits_per_pixel) {
278 case 32: 456 case 32:
279 case 24: 457 case 24:
@@ -282,7 +460,7 @@ static int s3c_fb_set_par(struct fb_info *info)
282 info->fix.visual = FB_VISUAL_TRUECOLOR; 460 info->fix.visual = FB_VISUAL_TRUECOLOR;
283 break; 461 break;
284 case 8: 462 case 8:
285 if (s3c_fb_win_has_palette(win_no, 8)) 463 if (win->variant.palette_sz >= 256)
286 info->fix.visual = FB_VISUAL_PSEUDOCOLOR; 464 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
287 else 465 else
288 info->fix.visual = FB_VISUAL_TRUECOLOR; 466 info->fix.visual = FB_VISUAL_TRUECOLOR;
@@ -297,12 +475,15 @@ static int s3c_fb_set_par(struct fb_info *info)
297 475
298 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8; 476 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8;
299 477
478 info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
479 info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
480
300 /* disable the window whilst we update it */ 481 /* disable the window whilst we update it */
301 writel(0, regs + WINCON(win_no)); 482 writel(0, regs + WINCON(win_no));
302 483
303 /* use window 0 as the basis for the lcd output timings */ 484 /* use platform specified window as the basis for the lcd timings */
304 485
305 if (win_no == 0) { 486 if (win_no == sfb->pdata->default_win) {
306 clkdiv = s3c_fb_calc_pixclk(sfb, var->pixclock); 487 clkdiv = s3c_fb_calc_pixclk(sfb, var->pixclock);
307 488
308 data = sfb->pdata->vidcon0; 489 data = sfb->pdata->vidcon0;
@@ -315,6 +496,9 @@ static int s3c_fb_set_par(struct fb_info *info)
315 496
316 /* write the timing data to the panel */ 497 /* write the timing data to the panel */
317 498
499 if (sfb->variant.is_2443)
500 data |= (1 << 5);
501
318 data |= VIDCON0_ENVID | VIDCON0_ENVID_F; 502 data |= VIDCON0_ENVID | VIDCON0_ENVID_F;
319 writel(data, regs + VIDCON0); 503 writel(data, regs + VIDCON0);
320 504
@@ -322,53 +506,54 @@ static int s3c_fb_set_par(struct fb_info *info)
322 VIDTCON0_VFPD(var->lower_margin - 1) | 506 VIDTCON0_VFPD(var->lower_margin - 1) |
323 VIDTCON0_VSPW(var->vsync_len - 1); 507 VIDTCON0_VSPW(var->vsync_len - 1);
324 508
325 writel(data, regs + VIDTCON0); 509 writel(data, regs + sfb->variant.vidtcon);
326 510
327 data = VIDTCON1_HBPD(var->left_margin - 1) | 511 data = VIDTCON1_HBPD(var->left_margin - 1) |
328 VIDTCON1_HFPD(var->right_margin - 1) | 512 VIDTCON1_HFPD(var->right_margin - 1) |
329 VIDTCON1_HSPW(var->hsync_len - 1); 513 VIDTCON1_HSPW(var->hsync_len - 1);
330 514
331 writel(data, regs + VIDTCON1); 515 /* VIDTCON1 */
516 writel(data, regs + sfb->variant.vidtcon + 4);
332 517
333 data = VIDTCON2_LINEVAL(var->yres - 1) | 518 data = VIDTCON2_LINEVAL(var->yres - 1) |
334 VIDTCON2_HOZVAL(var->xres - 1); 519 VIDTCON2_HOZVAL(var->xres - 1);
335 writel(data, regs + VIDTCON2); 520 writel(data, regs +sfb->variant.vidtcon + 8 );
336 } 521 }
337 522
338 /* write the buffer address */ 523 /* write the buffer address */
339 524
340 writel(info->fix.smem_start, regs + VIDW_BUF_START(win_no)); 525 /* start and end registers stride is 8 */
526 buf = regs + win_no * 8;
527
528 writel(info->fix.smem_start, buf + sfb->variant.buf_start);
341 529
342 data = info->fix.smem_start + info->fix.line_length * var->yres; 530 data = info->fix.smem_start + info->fix.line_length * var->yres;
343 writel(data, regs + VIDW_BUF_END(win_no)); 531 writel(data, buf + sfb->variant.buf_end);
344 532
345 pagewidth = (var->xres * var->bits_per_pixel) >> 3; 533 pagewidth = (var->xres * var->bits_per_pixel) >> 3;
346 data = VIDW_BUF_SIZE_OFFSET(info->fix.line_length - pagewidth) | 534 data = VIDW_BUF_SIZE_OFFSET(info->fix.line_length - pagewidth) |
347 VIDW_BUF_SIZE_PAGEWIDTH(pagewidth); 535 VIDW_BUF_SIZE_PAGEWIDTH(pagewidth);
348 writel(data, regs + VIDW_BUF_SIZE(win_no)); 536 writel(data, regs + sfb->variant.buf_size + (win_no * 4));
349 537
350 /* write 'OSD' registers to control position of framebuffer */ 538 /* write 'OSD' registers to control position of framebuffer */
351 539
352 data = VIDOSDxA_TOPLEFT_X(0) | VIDOSDxA_TOPLEFT_Y(0); 540 data = VIDOSDxA_TOPLEFT_X(0) | VIDOSDxA_TOPLEFT_Y(0);
353 writel(data, regs + VIDOSD_A(win_no)); 541 writel(data, regs + VIDOSD_A(win_no, sfb->variant));
354 542
355 data = VIDOSDxB_BOTRIGHT_X(s3c_fb_align_word(var->bits_per_pixel, 543 data = VIDOSDxB_BOTRIGHT_X(s3c_fb_align_word(var->bits_per_pixel,
356 var->xres - 1)) | 544 var->xres - 1)) |
357 VIDOSDxB_BOTRIGHT_Y(var->yres - 1); 545 VIDOSDxB_BOTRIGHT_Y(var->yres - 1);
358 546
359 writel(data, regs + VIDOSD_B(win_no)); 547 writel(data, regs + VIDOSD_B(win_no, sfb->variant));
360 548
361 data = var->xres * var->yres; 549 data = var->xres * var->yres;
362 550
363 osdc_data = VIDISD14C_ALPHA1_R(0xf) | 551 alpha = VIDISD14C_ALPHA1_R(0xf) |
364 VIDISD14C_ALPHA1_G(0xf) | 552 VIDISD14C_ALPHA1_G(0xf) |
365 VIDISD14C_ALPHA1_B(0xf); 553 VIDISD14C_ALPHA1_B(0xf);
366 554
367 if (s3c_fb_has_osd_d(win_no)) { 555 vidosd_set_alpha(win, alpha);
368 writel(data, regs + VIDOSD_D(win_no)); 556 vidosd_set_size(win, data);
369 writel(osdc_data, regs + VIDOSD_C(win_no));
370 } else
371 writel(data, regs + VIDOSD_C(win_no));
372 557
373 data = WINCONx_ENWIN; 558 data = WINCONx_ENWIN;
374 559
@@ -424,13 +609,15 @@ static int s3c_fb_set_par(struct fb_info *info)
424 else 609 else
425 data |= WINCON0_BPPMODE_24BPP_888; 610 data |= WINCON0_BPPMODE_24BPP_888;
426 611
612 data |= WINCONx_WSWP;
427 data |= WINCONx_BURSTLEN_16WORD; 613 data |= WINCONx_BURSTLEN_16WORD;
428 break; 614 break;
429 } 615 }
430 616
431 /* It has no color key control register for window0 */ 617 /* Enable the colour keying for the window below this one */
432 if (win_no > 0) { 618 if (win_no > 0) {
433 u32 keycon0_data = 0, keycon1_data = 0; 619 u32 keycon0_data = 0, keycon1_data = 0;
620 void __iomem *keycon = regs + sfb->variant.keycon;
434 621
435 keycon0_data = ~(WxKEYCON0_KEYBL_EN | 622 keycon0_data = ~(WxKEYCON0_KEYBL_EN |
436 WxKEYCON0_KEYEN_F | 623 WxKEYCON0_KEYEN_F |
@@ -438,12 +625,23 @@ static int s3c_fb_set_par(struct fb_info *info)
438 625
439 keycon1_data = WxKEYCON1_COLVAL(0xffffff); 626 keycon1_data = WxKEYCON1_COLVAL(0xffffff);
440 627
441 writel(keycon0_data, regs + WxKEYCONy(win_no-1, 0)); 628 keycon += (win_no - 1) * 8;
442 writel(keycon1_data, regs + WxKEYCONy(win_no-1, 1)); 629
630 writel(keycon0_data, keycon + WKEYCON0);
631 writel(keycon1_data, keycon + WKEYCON1);
632 }
633
634 writel(data, regs + sfb->variant.wincon + (win_no * 4));
635 writel(0x0, regs + sfb->variant.winmap + (win_no * 4));
636
637 /* Enable DMA channel for this window */
638 if (sfb->variant.has_shadowcon) {
639 data = readl(sfb->regs + SHADOWCON);
640 data |= SHADOWCON_CHx_ENABLE(win_no);
641 writel(data, sfb->regs + SHADOWCON);
443 } 642 }
444 643
445 writel(data, regs + WINCON(win_no)); 644 shadow_protect_win(win, 0);
446 writel(0x0, regs + WINxMAP(win_no));
447 645
448 return 0; 646 return 0;
449} 647}
@@ -470,7 +668,7 @@ static void s3c_fb_update_palette(struct s3c_fb *sfb,
470 void __iomem *palreg; 668 void __iomem *palreg;
471 u32 palcon; 669 u32 palcon;
472 670
473 palreg = sfb->regs + s3c_fb_pal_reg(win->index, reg); 671 palreg = sfb->regs + sfb->variant.palette[win->index];
474 672
475 dev_dbg(sfb->dev, "%s: win %d, reg %d (%p): %08x\n", 673 dev_dbg(sfb->dev, "%s: win %d, reg %d (%p): %08x\n",
476 __func__, win->index, reg, palreg, value); 674 __func__, win->index, reg, palreg, value);
@@ -480,10 +678,10 @@ static void s3c_fb_update_palette(struct s3c_fb *sfb,
480 palcon = readl(sfb->regs + WPALCON); 678 palcon = readl(sfb->regs + WPALCON);
481 writel(palcon | WPALCON_PAL_UPDATE, sfb->regs + WPALCON); 679 writel(palcon | WPALCON_PAL_UPDATE, sfb->regs + WPALCON);
482 680
483 if (s3c_fb_pal_is16(win->index)) 681 if (win->variant.palette_16bpp)
484 writew(value, palreg); 682 writew(value, palreg + (reg * 2));
485 else 683 else
486 writel(value, palreg); 684 writel(value, palreg + (reg * 4));
487 685
488 writel(palcon, sfb->regs + WPALCON); 686 writel(palcon, sfb->regs + WPALCON);
489} 687}
@@ -532,7 +730,7 @@ static int s3c_fb_setcolreg(unsigned regno,
532 break; 730 break;
533 731
534 case FB_VISUAL_PSEUDOCOLOR: 732 case FB_VISUAL_PSEUDOCOLOR:
535 if (regno < s3c_fb_win_pal_size(win->index)) { 733 if (regno < win->variant.palette_sz) {
536 val = chan_to_field(red, &win->palette.r); 734 val = chan_to_field(red, &win->palette.r);
537 val |= chan_to_field(green, &win->palette.g); 735 val |= chan_to_field(green, &win->palette.g);
538 val |= chan_to_field(blue, &win->palette.b); 736 val |= chan_to_field(blue, &win->palette.b);
@@ -591,7 +789,7 @@ static int s3c_fb_blank(int blank_mode, struct fb_info *info)
591 789
592 dev_dbg(sfb->dev, "blank mode %d\n", blank_mode); 790 dev_dbg(sfb->dev, "blank mode %d\n", blank_mode);
593 791
594 wincon = readl(sfb->regs + WINCON(index)); 792 wincon = readl(sfb->regs + sfb->variant.wincon + (index * 4));
595 793
596 switch (blank_mode) { 794 switch (blank_mode) {
597 case FB_BLANK_POWERDOWN: 795 case FB_BLANK_POWERDOWN:
@@ -602,11 +800,11 @@ static int s3c_fb_blank(int blank_mode, struct fb_info *info)
602 case FB_BLANK_NORMAL: 800 case FB_BLANK_NORMAL:
603 /* disable the DMA and display 0x0 (black) */ 801 /* disable the DMA and display 0x0 (black) */
604 writel(WINxMAP_MAP | WINxMAP_MAP_COLOUR(0x0), 802 writel(WINxMAP_MAP | WINxMAP_MAP_COLOUR(0x0),
605 sfb->regs + WINxMAP(index)); 803 sfb->regs + sfb->variant.winmap + (index * 4));
606 break; 804 break;
607 805
608 case FB_BLANK_UNBLANK: 806 case FB_BLANK_UNBLANK:
609 writel(0x0, sfb->regs + WINxMAP(index)); 807 writel(0x0, sfb->regs + sfb->variant.winmap + (index * 4));
610 wincon |= WINCONx_ENWIN; 808 wincon |= WINCONx_ENWIN;
611 sfb->enabled |= (1 << index); 809 sfb->enabled |= (1 << index);
612 break; 810 break;
@@ -617,7 +815,7 @@ static int s3c_fb_blank(int blank_mode, struct fb_info *info)
617 return 1; 815 return 1;
618 } 816 }
619 817
620 writel(wincon, sfb->regs + WINCON(index)); 818 writel(wincon, sfb->regs + sfb->variant.wincon + (index * 4));
621 819
622 /* Check the enabled state to see if we need to be running the 820 /* Check the enabled state to see if we need to be running the
623 * main LCD interface, as if there are no active windows then 821 * main LCD interface, as if there are no active windows then
@@ -636,12 +834,185 @@ static int s3c_fb_blank(int blank_mode, struct fb_info *info)
636 /* we're stuck with this until we can do something about overriding 834 /* we're stuck with this until we can do something about overriding
637 * the power control using the blanking event for a single fb. 835 * the power control using the blanking event for a single fb.
638 */ 836 */
639 if (index == 0) 837 if (index == sfb->pdata->default_win)
640 s3c_fb_enable(sfb, blank_mode != FB_BLANK_POWERDOWN ? 1 : 0); 838 s3c_fb_enable(sfb, blank_mode != FB_BLANK_POWERDOWN ? 1 : 0);
641 839
642 return 0; 840 return 0;
643} 841}
644 842
843/**
844 * s3c_fb_pan_display() - Pan the display.
845 *
846 * Note that the offsets can be written to the device at any time, as their
847 * values are latched at each vsync automatically. This also means that only
848 * the last call to this function will have any effect on next vsync, but
849 * there is no need to sleep waiting for it to prevent tearing.
850 *
851 * @var: The screen information to verify.
852 * @info: The framebuffer device.
853 */
854static int s3c_fb_pan_display(struct fb_var_screeninfo *var,
855 struct fb_info *info)
856{
857 struct s3c_fb_win *win = info->par;
858 struct s3c_fb *sfb = win->parent;
859 void __iomem *buf = sfb->regs + win->index * 8;
860 unsigned int start_boff, end_boff;
861
862 /* Offset in bytes to the start of the displayed area */
863 start_boff = var->yoffset * info->fix.line_length;
864 /* X offset depends on the current bpp */
865 if (info->var.bits_per_pixel >= 8) {
866 start_boff += var->xoffset * (info->var.bits_per_pixel >> 3);
867 } else {
868 switch (info->var.bits_per_pixel) {
869 case 4:
870 start_boff += var->xoffset >> 1;
871 break;
872 case 2:
873 start_boff += var->xoffset >> 2;
874 break;
875 case 1:
876 start_boff += var->xoffset >> 3;
877 break;
878 default:
879 dev_err(sfb->dev, "invalid bpp\n");
880 return -EINVAL;
881 }
882 }
883 /* Offset in bytes to the end of the displayed area */
884 end_boff = start_boff + var->yres * info->fix.line_length;
885
886 /* Temporarily turn off per-vsync update from shadow registers until
887 * both start and end addresses are updated to prevent corruption */
888 shadow_protect_win(win, 1);
889
890 writel(info->fix.smem_start + start_boff, buf + sfb->variant.buf_start);
891 writel(info->fix.smem_start + end_boff, buf + sfb->variant.buf_end);
892
893 shadow_protect_win(win, 0);
894
895 return 0;
896}
897
898/**
899 * s3c_fb_enable_irq() - enable framebuffer interrupts
900 * @sfb: main hardware state
901 */
902static void s3c_fb_enable_irq(struct s3c_fb *sfb)
903{
904 void __iomem *regs = sfb->regs;
905 u32 irq_ctrl_reg;
906
907 if (!test_and_set_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
908 /* IRQ disabled, enable it */
909 irq_ctrl_reg = readl(regs + VIDINTCON0);
910
911 irq_ctrl_reg |= VIDINTCON0_INT_ENABLE;
912 irq_ctrl_reg |= VIDINTCON0_INT_FRAME;
913
914 irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL0_MASK;
915 irq_ctrl_reg |= VIDINTCON0_FRAMESEL0_VSYNC;
916 irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL1_MASK;
917 irq_ctrl_reg |= VIDINTCON0_FRAMESEL1_NONE;
918
919 writel(irq_ctrl_reg, regs + VIDINTCON0);
920 }
921}
922
923/**
924 * s3c_fb_disable_irq() - disable framebuffer interrupts
925 * @sfb: main hardware state
926 */
927static void s3c_fb_disable_irq(struct s3c_fb *sfb)
928{
929 void __iomem *regs = sfb->regs;
930 u32 irq_ctrl_reg;
931
932 if (test_and_clear_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
933 /* IRQ enabled, disable it */
934 irq_ctrl_reg = readl(regs + VIDINTCON0);
935
936 irq_ctrl_reg &= ~VIDINTCON0_INT_FRAME;
937 irq_ctrl_reg &= ~VIDINTCON0_INT_ENABLE;
938
939 writel(irq_ctrl_reg, regs + VIDINTCON0);
940 }
941}
942
943static irqreturn_t s3c_fb_irq(int irq, void *dev_id)
944{
945 struct s3c_fb *sfb = dev_id;
946 void __iomem *regs = sfb->regs;
947 u32 irq_sts_reg;
948
949 irq_sts_reg = readl(regs + VIDINTCON1);
950
951 if (irq_sts_reg & VIDINTCON1_INT_FRAME) {
952
953 /* VSYNC interrupt, accept it */
954 writel(VIDINTCON1_INT_FRAME, regs + VIDINTCON1);
955
956 sfb->vsync_info.count++;
957 wake_up_interruptible(&sfb->vsync_info.wait);
958 }
959
960 /* We only support waiting for VSYNC for now, so it's safe
961 * to always disable irqs here.
962 */
963 s3c_fb_disable_irq(sfb);
964
965 return IRQ_HANDLED;
966}
967
968/**
969 * s3c_fb_wait_for_vsync() - sleep until next VSYNC interrupt or timeout
970 * @sfb: main hardware state
971 * @crtc: head index.
972 */
973static int s3c_fb_wait_for_vsync(struct s3c_fb *sfb, u32 crtc)
974{
975 unsigned long count;
976 int ret;
977
978 if (crtc != 0)
979 return -ENODEV;
980
981 count = sfb->vsync_info.count;
982 s3c_fb_enable_irq(sfb);
983 ret = wait_event_interruptible_timeout(sfb->vsync_info.wait,
984 count != sfb->vsync_info.count,
985 msecs_to_jiffies(VSYNC_TIMEOUT_MSEC));
986 if (ret == 0)
987 return -ETIMEDOUT;
988
989 return 0;
990}
991
992static int s3c_fb_ioctl(struct fb_info *info, unsigned int cmd,
993 unsigned long arg)
994{
995 struct s3c_fb_win *win = info->par;
996 struct s3c_fb *sfb = win->parent;
997 int ret;
998 u32 crtc;
999
1000 switch (cmd) {
1001 case FBIO_WAITFORVSYNC:
1002 if (get_user(crtc, (u32 __user *)arg)) {
1003 ret = -EFAULT;
1004 break;
1005 }
1006
1007 ret = s3c_fb_wait_for_vsync(sfb, crtc);
1008 break;
1009 default:
1010 ret = -ENOTTY;
1011 }
1012
1013 return ret;
1014}
1015
645static struct fb_ops s3c_fb_ops = { 1016static struct fb_ops s3c_fb_ops = {
646 .owner = THIS_MODULE, 1017 .owner = THIS_MODULE,
647 .fb_check_var = s3c_fb_check_var, 1018 .fb_check_var = s3c_fb_check_var,
@@ -651,9 +1022,33 @@ static struct fb_ops s3c_fb_ops = {
651 .fb_fillrect = cfb_fillrect, 1022 .fb_fillrect = cfb_fillrect,
652 .fb_copyarea = cfb_copyarea, 1023 .fb_copyarea = cfb_copyarea,
653 .fb_imageblit = cfb_imageblit, 1024 .fb_imageblit = cfb_imageblit,
1025 .fb_pan_display = s3c_fb_pan_display,
1026 .fb_ioctl = s3c_fb_ioctl,
654}; 1027};
655 1028
656/** 1029/**
1030 * s3c_fb_missing_pixclock() - calculates pixel clock
1031 * @mode: The video mode to change.
1032 *
1033 * Calculate the pixel clock when none has been given through platform data.
1034 */
1035static void __devinit s3c_fb_missing_pixclock(struct fb_videomode *mode)
1036{
1037 u64 pixclk = 1000000000000ULL;
1038 u32 div;
1039
1040 div = mode->left_margin + mode->hsync_len + mode->right_margin +
1041 mode->xres;
1042 div *= mode->upper_margin + mode->vsync_len + mode->lower_margin +
1043 mode->yres;
1044 div *= mode->refresh ? : 60;
1045
1046 do_div(pixclk, div);
1047
1048 mode->pixclock = pixclk;
1049}
1050
1051/**
657 * s3c_fb_alloc_memory() - allocate display memory for framebuffer window 1052 * s3c_fb_alloc_memory() - allocate display memory for framebuffer window
658 * @sfb: The base resources for the hardware. 1053 * @sfb: The base resources for the hardware.
659 * @win: The window to initialise memory for. 1054 * @win: The window to initialise memory for.
@@ -711,7 +1106,8 @@ static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win)
711{ 1106{
712 struct fb_info *fbi = win->fbinfo; 1107 struct fb_info *fbi = win->fbinfo;
713 1108
714 dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len), 1109 if (fbi->screen_base)
1110 dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len),
715 fbi->screen_base, fbi->fix.smem_start); 1111 fbi->screen_base, fbi->fix.smem_start);
716} 1112}
717 1113
@@ -724,9 +1120,18 @@ static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win)
724 */ 1120 */
725static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win) 1121static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
726{ 1122{
1123 u32 data;
1124
727 if (win->fbinfo) { 1125 if (win->fbinfo) {
1126 if (sfb->variant.has_shadowcon) {
1127 data = readl(sfb->regs + SHADOWCON);
1128 data &= ~SHADOWCON_CHx_ENABLE(win->index);
1129 data &= ~SHADOWCON_CHx_LOCAL_ENABLE(win->index);
1130 writel(data, sfb->regs + SHADOWCON);
1131 }
728 unregister_framebuffer(win->fbinfo); 1132 unregister_framebuffer(win->fbinfo);
729 fb_dealloc_cmap(&win->fbinfo->cmap); 1133 if (win->fbinfo->cmap.len)
1134 fb_dealloc_cmap(&win->fbinfo->cmap);
730 s3c_fb_free_memory(sfb, win); 1135 s3c_fb_free_memory(sfb, win);
731 framebuffer_release(win->fbinfo); 1136 framebuffer_release(win->fbinfo);
732 } 1137 }
@@ -735,12 +1140,14 @@ static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
735/** 1140/**
736 * s3c_fb_probe_win() - register an hardware window 1141 * s3c_fb_probe_win() - register an hardware window
737 * @sfb: The base resources for the hardware 1142 * @sfb: The base resources for the hardware
1143 * @variant: The variant information for this window.
738 * @res: Pointer to where to place the resultant window. 1144 * @res: Pointer to where to place the resultant window.
739 * 1145 *
740 * Allocate and do the basic initialisation for one of the hardware's graphics 1146 * Allocate and do the basic initialisation for one of the hardware's graphics
741 * windows. 1147 * windows.
742 */ 1148 */
743static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no, 1149static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
1150 struct s3c_fb_win_variant *variant,
744 struct s3c_fb_win **res) 1151 struct s3c_fb_win **res)
745{ 1152{
746 struct fb_var_screeninfo *var; 1153 struct fb_var_screeninfo *var;
@@ -751,9 +1158,11 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
751 int palette_size; 1158 int palette_size;
752 int ret; 1159 int ret;
753 1160
754 dev_dbg(sfb->dev, "probing window %d\n", win_no); 1161 dev_dbg(sfb->dev, "probing window %d, variant %p\n", win_no, variant);
1162
1163 init_waitqueue_head(&sfb->vsync_info.wait);
755 1164
756 palette_size = s3c_fb_win_pal_size(win_no); 1165 palette_size = variant->palette_sz * 4;
757 1166
758 fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) + 1167 fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) +
759 palette_size * sizeof(u32), sfb->dev); 1168 palette_size * sizeof(u32), sfb->dev);
@@ -770,7 +1179,9 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
770 WARN_ON(windata->win_mode.yres == 0); 1179 WARN_ON(windata->win_mode.yres == 0);
771 1180
772 win = fbinfo->par; 1181 win = fbinfo->par;
1182 *res = win;
773 var = &fbinfo->var; 1183 var = &fbinfo->var;
1184 win->variant = *variant;
774 win->fbinfo = fbinfo; 1185 win->fbinfo = fbinfo;
775 win->parent = sfb; 1186 win->parent = sfb;
776 win->windata = windata; 1187 win->windata = windata;
@@ -784,7 +1195,24 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
784 } 1195 }
785 1196
786 /* setup the r/b/g positions for the window's palette */ 1197 /* setup the r/b/g positions for the window's palette */
787 s3c_fb_init_palette(win_no, &win->palette); 1198 if (win->variant.palette_16bpp) {
1199 /* Set RGB 5:6:5 as default */
1200 win->palette.r.offset = 11;
1201 win->palette.r.length = 5;
1202 win->palette.g.offset = 5;
1203 win->palette.g.length = 6;
1204 win->palette.b.offset = 0;
1205 win->palette.b.length = 5;
1206
1207 } else {
1208 /* Set 8bpp or 8bpp and 1bit alpha */
1209 win->palette.r.offset = 16;
1210 win->palette.r.length = 8;
1211 win->palette.g.offset = 8;
1212 win->palette.g.length = 8;
1213 win->palette.b.offset = 0;
1214 win->palette.b.length = 8;
1215 }
788 1216
789 /* setup the initial video mode from the window */ 1217 /* setup the initial video mode from the window */
790 fb_videomode_to_var(&fbinfo->var, initmode); 1218 fb_videomode_to_var(&fbinfo->var, initmode);
@@ -808,7 +1236,7 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
808 1236
809 /* create initial colour map */ 1237 /* create initial colour map */
810 1238
811 ret = fb_alloc_cmap(&fbinfo->cmap, s3c_fb_win_pal_size(win_no), 1); 1239 ret = fb_alloc_cmap(&fbinfo->cmap, win->variant.palette_sz, 1);
812 if (ret == 0) 1240 if (ret == 0)
813 fb_set_cmap(&fbinfo->cmap, fbinfo); 1241 fb_set_cmap(&fbinfo->cmap, fbinfo);
814 else 1242 else
@@ -826,7 +1254,6 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
826 return ret; 1254 return ret;
827 } 1255 }
828 1256
829 *res = win;
830 dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id); 1257 dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id);
831 1258
832 return 0; 1259 return 0;
@@ -842,18 +1269,19 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
842static void s3c_fb_clear_win(struct s3c_fb *sfb, int win) 1269static void s3c_fb_clear_win(struct s3c_fb *sfb, int win)
843{ 1270{
844 void __iomem *regs = sfb->regs; 1271 void __iomem *regs = sfb->regs;
845 1272 u32 reg;
846 writel(0, regs + WINCON(win)); 1273
847 writel(0xffffff, regs + WxKEYCONy(win, 0)); 1274 writel(0, regs + sfb->variant.wincon + (win * 4));
848 writel(0xffffff, regs + WxKEYCONy(win, 1)); 1275 writel(0, regs + VIDOSD_A(win, sfb->variant));
849 1276 writel(0, regs + VIDOSD_B(win, sfb->variant));
850 writel(0, regs + VIDOSD_A(win)); 1277 writel(0, regs + VIDOSD_C(win, sfb->variant));
851 writel(0, regs + VIDOSD_B(win)); 1278 reg = readl(regs + SHADOWCON);
852 writel(0, regs + VIDOSD_C(win)); 1279 writel(reg & ~SHADOWCON_WINx_PROTECT(win), regs + SHADOWCON);
853} 1280}
854 1281
855static int __devinit s3c_fb_probe(struct platform_device *pdev) 1282static int __devinit s3c_fb_probe(struct platform_device *pdev)
856{ 1283{
1284 struct s3c_fb_driverdata *fbdrv;
857 struct device *dev = &pdev->dev; 1285 struct device *dev = &pdev->dev;
858 struct s3c_fb_platdata *pd; 1286 struct s3c_fb_platdata *pd;
859 struct s3c_fb *sfb; 1287 struct s3c_fb *sfb;
@@ -861,6 +1289,13 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
861 int win; 1289 int win;
862 int ret = 0; 1290 int ret = 0;
863 1291
1292 fbdrv = (struct s3c_fb_driverdata *)platform_get_device_id(pdev)->driver_data;
1293
1294 if (fbdrv->variant.nr_windows > S3C_FB_MAX_WIN) {
1295 dev_err(dev, "too many windows, cannot attach\n");
1296 return -EINVAL;
1297 }
1298
864 pd = pdev->dev.platform_data; 1299 pd = pdev->dev.platform_data;
865 if (!pd) { 1300 if (!pd) {
866 dev_err(dev, "no platform data specified\n"); 1301 dev_err(dev, "no platform data specified\n");
@@ -873,8 +1308,11 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
873 return -ENOMEM; 1308 return -ENOMEM;
874 } 1309 }
875 1310
1311 dev_dbg(dev, "allocate new framebuffer %p\n", sfb);
1312
876 sfb->dev = dev; 1313 sfb->dev = dev;
877 sfb->pdata = pd; 1314 sfb->pdata = pd;
1315 sfb->variant = fbdrv->variant;
878 1316
879 sfb->bus_clk = clk_get(dev, "lcd"); 1317 sfb->bus_clk = clk_get(dev, "lcd");
880 if (IS_ERR(sfb->bus_clk)) { 1318 if (IS_ERR(sfb->bus_clk)) {
@@ -906,6 +1344,20 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
906 goto err_req_region; 1344 goto err_req_region;
907 } 1345 }
908 1346
1347 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1348 if (!res) {
1349 dev_err(dev, "failed to acquire irq resource\n");
1350 ret = -ENOENT;
1351 goto err_ioremap;
1352 }
1353 sfb->irq_no = res->start;
1354 ret = request_irq(sfb->irq_no, s3c_fb_irq,
1355 0, "s3c_fb", sfb);
1356 if (ret) {
1357 dev_err(dev, "irq request failed\n");
1358 goto err_ioremap;
1359 }
1360
909 dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs); 1361 dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs);
910 1362
911 /* setup gpio and output polarity controls */ 1363 /* setup gpio and output polarity controls */
@@ -916,21 +1368,34 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
916 1368
917 /* zero all windows before we do anything */ 1369 /* zero all windows before we do anything */
918 1370
919 for (win = 0; win < S3C_FB_MAX_WIN; win++) 1371 for (win = 0; win < fbdrv->variant.nr_windows; win++)
920 s3c_fb_clear_win(sfb, win); 1372 s3c_fb_clear_win(sfb, win);
921 1373
1374 /* initialise colour key controls */
1375 for (win = 0; win < (fbdrv->variant.nr_windows - 1); win++) {
1376 void __iomem *regs = sfb->regs + sfb->variant.keycon;
1377
1378 regs += (win * 8);
1379 writel(0xffffff, regs + WKEYCON0);
1380 writel(0xffffff, regs + WKEYCON1);
1381 }
1382
922 /* we have the register setup, start allocating framebuffers */ 1383 /* we have the register setup, start allocating framebuffers */
923 1384
924 for (win = 0; win < S3C_FB_MAX_WIN; win++) { 1385 for (win = 0; win < fbdrv->variant.nr_windows; win++) {
925 if (!pd->win[win]) 1386 if (!pd->win[win])
926 continue; 1387 continue;
927 1388
928 ret = s3c_fb_probe_win(sfb, win, &sfb->windows[win]); 1389 if (!pd->win[win]->win_mode.pixclock)
1390 s3c_fb_missing_pixclock(&pd->win[win]->win_mode);
1391
1392 ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win],
1393 &sfb->windows[win]);
929 if (ret < 0) { 1394 if (ret < 0) {
930 dev_err(dev, "failed to create window %d\n", win); 1395 dev_err(dev, "failed to create window %d\n", win);
931 for (; win >= 0; win--) 1396 for (; win >= 0; win--)
932 s3c_fb_release_win(sfb, sfb->windows[win]); 1397 s3c_fb_release_win(sfb, sfb->windows[win]);
933 goto err_ioremap; 1398 goto err_irq;
934 } 1399 }
935 } 1400 }
936 1401
@@ -938,6 +1403,9 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
938 1403
939 return 0; 1404 return 0;
940 1405
1406err_irq:
1407 free_irq(sfb->irq_no, sfb);
1408
941err_ioremap: 1409err_ioremap:
942 iounmap(sfb->regs); 1410 iounmap(sfb->regs);
943 1411
@@ -970,6 +1438,8 @@ static int __devexit s3c_fb_remove(struct platform_device *pdev)
970 if (sfb->windows[win]) 1438 if (sfb->windows[win])
971 s3c_fb_release_win(sfb, sfb->windows[win]); 1439 s3c_fb_release_win(sfb, sfb->windows[win]);
972 1440
1441 free_irq(sfb->irq_no, sfb);
1442
973 iounmap(sfb->regs); 1443 iounmap(sfb->regs);
974 1444
975 clk_disable(sfb->bus_clk); 1445 clk_disable(sfb->bus_clk);
@@ -1016,9 +1486,17 @@ static int s3c_fb_resume(struct platform_device *pdev)
1016 writel(pd->vidcon1, sfb->regs + VIDCON1); 1486 writel(pd->vidcon1, sfb->regs + VIDCON1);
1017 1487
1018 /* zero all windows before we do anything */ 1488 /* zero all windows before we do anything */
1019 for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) 1489 for (win_no = 0; win_no < sfb->variant.nr_windows; win_no++)
1020 s3c_fb_clear_win(sfb, win_no); 1490 s3c_fb_clear_win(sfb, win_no);
1021 1491
1492 for (win_no = 0; win_no < sfb->variant.nr_windows - 1; win_no++) {
1493 void __iomem *regs = sfb->regs + sfb->variant.keycon;
1494
1495 regs += (win_no * 8);
1496 writel(0xffffff, regs + WKEYCON0);
1497 writel(0xffffff, regs + WKEYCON1);
1498 }
1499
1022 /* restore framebuffers */ 1500 /* restore framebuffers */
1023 for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) { 1501 for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) {
1024 win = sfb->windows[win_no]; 1502 win = sfb->windows[win_no];
@@ -1036,11 +1514,208 @@ static int s3c_fb_resume(struct platform_device *pdev)
1036#define s3c_fb_resume NULL 1514#define s3c_fb_resume NULL
1037#endif 1515#endif
1038 1516
1517
1518#define VALID_BPP124 (VALID_BPP(1) | VALID_BPP(2) | VALID_BPP(4))
1519#define VALID_BPP1248 (VALID_BPP124 | VALID_BPP(8))
1520
1521static struct s3c_fb_win_variant s3c_fb_data_64xx_wins[] = {
1522 [0] = {
1523 .has_osd_c = 1,
1524 .osd_size_off = 0x8,
1525 .palette_sz = 256,
1526 .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
1527 },
1528 [1] = {
1529 .has_osd_c = 1,
1530 .has_osd_d = 1,
1531 .osd_size_off = 0x12,
1532 .has_osd_alpha = 1,
1533 .palette_sz = 256,
1534 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1535 VALID_BPP(18) | VALID_BPP(19) |
1536 VALID_BPP(24) | VALID_BPP(25)),
1537 },
1538 [2] = {
1539 .has_osd_c = 1,
1540 .has_osd_d = 1,
1541 .osd_size_off = 0x12,
1542 .has_osd_alpha = 1,
1543 .palette_sz = 16,
1544 .palette_16bpp = 1,
1545 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1546 VALID_BPP(18) | VALID_BPP(19) |
1547 VALID_BPP(24) | VALID_BPP(25)),
1548 },
1549 [3] = {
1550 .has_osd_c = 1,
1551 .has_osd_alpha = 1,
1552 .palette_sz = 16,
1553 .palette_16bpp = 1,
1554 .valid_bpp = (VALID_BPP124 | VALID_BPP(16) |
1555 VALID_BPP(18) | VALID_BPP(19) |
1556 VALID_BPP(24) | VALID_BPP(25)),
1557 },
1558 [4] = {
1559 .has_osd_c = 1,
1560 .has_osd_alpha = 1,
1561 .palette_sz = 4,
1562 .palette_16bpp = 1,
1563 .valid_bpp = (VALID_BPP(1) | VALID_BPP(2) |
1564 VALID_BPP(16) | VALID_BPP(18) |
1565 VALID_BPP(24) | VALID_BPP(25)),
1566 },
1567};
1568
1569static struct s3c_fb_driverdata s3c_fb_data_64xx = {
1570 .variant = {
1571 .nr_windows = 5,
1572 .vidtcon = VIDTCON0,
1573 .wincon = WINCON(0),
1574 .winmap = WINxMAP(0),
1575 .keycon = WKEYCON,
1576 .osd = VIDOSD_BASE,
1577 .osd_stride = 16,
1578 .buf_start = VIDW_BUF_START(0),
1579 .buf_size = VIDW_BUF_SIZE(0),
1580 .buf_end = VIDW_BUF_END(0),
1581
1582 .palette = {
1583 [0] = 0x400,
1584 [1] = 0x800,
1585 [2] = 0x300,
1586 [3] = 0x320,
1587 [4] = 0x340,
1588 },
1589
1590 .has_prtcon = 1,
1591 },
1592 .win[0] = &s3c_fb_data_64xx_wins[0],
1593 .win[1] = &s3c_fb_data_64xx_wins[1],
1594 .win[2] = &s3c_fb_data_64xx_wins[2],
1595 .win[3] = &s3c_fb_data_64xx_wins[3],
1596 .win[4] = &s3c_fb_data_64xx_wins[4],
1597};
1598
1599static struct s3c_fb_driverdata s3c_fb_data_s5pc100 = {
1600 .variant = {
1601 .nr_windows = 5,
1602 .vidtcon = VIDTCON0,
1603 .wincon = WINCON(0),
1604 .winmap = WINxMAP(0),
1605 .keycon = WKEYCON,
1606 .osd = VIDOSD_BASE,
1607 .osd_stride = 16,
1608 .buf_start = VIDW_BUF_START(0),
1609 .buf_size = VIDW_BUF_SIZE(0),
1610 .buf_end = VIDW_BUF_END(0),
1611
1612 .palette = {
1613 [0] = 0x2400,
1614 [1] = 0x2800,
1615 [2] = 0x2c00,
1616 [3] = 0x3000,
1617 [4] = 0x3400,
1618 },
1619
1620 .has_prtcon = 1,
1621 },
1622 .win[0] = &s3c_fb_data_64xx_wins[0],
1623 .win[1] = &s3c_fb_data_64xx_wins[1],
1624 .win[2] = &s3c_fb_data_64xx_wins[2],
1625 .win[3] = &s3c_fb_data_64xx_wins[3],
1626 .win[4] = &s3c_fb_data_64xx_wins[4],
1627};
1628
1629static struct s3c_fb_driverdata s3c_fb_data_s5pv210 = {
1630 .variant = {
1631 .nr_windows = 5,
1632 .vidtcon = VIDTCON0,
1633 .wincon = WINCON(0),
1634 .winmap = WINxMAP(0),
1635 .keycon = WKEYCON,
1636 .osd = VIDOSD_BASE,
1637 .osd_stride = 16,
1638 .buf_start = VIDW_BUF_START(0),
1639 .buf_size = VIDW_BUF_SIZE(0),
1640 .buf_end = VIDW_BUF_END(0),
1641
1642 .palette = {
1643 [0] = 0x2400,
1644 [1] = 0x2800,
1645 [2] = 0x2c00,
1646 [3] = 0x3000,
1647 [4] = 0x3400,
1648 },
1649
1650 .has_shadowcon = 1,
1651 },
1652 .win[0] = &s3c_fb_data_64xx_wins[0],
1653 .win[1] = &s3c_fb_data_64xx_wins[1],
1654 .win[2] = &s3c_fb_data_64xx_wins[2],
1655 .win[3] = &s3c_fb_data_64xx_wins[3],
1656 .win[4] = &s3c_fb_data_64xx_wins[4],
1657};
1658
1659/* S3C2443/S3C2416 style hardware */
1660static struct s3c_fb_driverdata s3c_fb_data_s3c2443 = {
1661 .variant = {
1662 .nr_windows = 2,
1663 .is_2443 = 1,
1664
1665 .vidtcon = 0x08,
1666 .wincon = 0x14,
1667 .winmap = 0xd0,
1668 .keycon = 0xb0,
1669 .osd = 0x28,
1670 .osd_stride = 12,
1671 .buf_start = 0x64,
1672 .buf_size = 0x94,
1673 .buf_end = 0x7c,
1674
1675 .palette = {
1676 [0] = 0x400,
1677 [1] = 0x800,
1678 },
1679 },
1680 .win[0] = &(struct s3c_fb_win_variant) {
1681 .palette_sz = 256,
1682 .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
1683 },
1684 .win[1] = &(struct s3c_fb_win_variant) {
1685 .has_osd_c = 1,
1686 .has_osd_alpha = 1,
1687 .palette_sz = 256,
1688 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1689 VALID_BPP(18) | VALID_BPP(19) |
1690 VALID_BPP(24) | VALID_BPP(25) |
1691 VALID_BPP(28)),
1692 },
1693};
1694
1695static struct platform_device_id s3c_fb_driver_ids[] = {
1696 {
1697 .name = "s3c-fb",
1698 .driver_data = (unsigned long)&s3c_fb_data_64xx,
1699 }, {
1700 .name = "s5pc100-fb",
1701 .driver_data = (unsigned long)&s3c_fb_data_s5pc100,
1702 }, {
1703 .name = "s5pv210-fb",
1704 .driver_data = (unsigned long)&s3c_fb_data_s5pv210,
1705 }, {
1706 .name = "s3c2443-fb",
1707 .driver_data = (unsigned long)&s3c_fb_data_s3c2443,
1708 },
1709 {},
1710};
1711MODULE_DEVICE_TABLE(platform, s3c_fb_driver_ids);
1712
1039static struct platform_driver s3c_fb_driver = { 1713static struct platform_driver s3c_fb_driver = {
1040 .probe = s3c_fb_probe, 1714 .probe = s3c_fb_probe,
1041 .remove = __devexit_p(s3c_fb_remove), 1715 .remove = __devexit_p(s3c_fb_remove),
1042 .suspend = s3c_fb_suspend, 1716 .suspend = s3c_fb_suspend,
1043 .resume = s3c_fb_resume, 1717 .resume = s3c_fb_resume,
1718 .id_table = s3c_fb_driver_ids,
1044 .driver = { 1719 .driver = {
1045 .name = "s3c-fb", 1720 .name = "s3c-fb",
1046 .owner = THIS_MODULE, 1721 .owner = THIS_MODULE,
diff --git a/drivers/video/sh_mipi_dsi.c b/drivers/video/sh_mipi_dsi.c
new file mode 100644
index 000000000000..5699ce0c1780
--- /dev/null
+++ b/drivers/video/sh_mipi_dsi.c
@@ -0,0 +1,505 @@
1/*
2 * Renesas SH-mobile MIPI DSI support
3 *
4 * Copyright (C) 2010 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This is free software; you can redistribute it and/or modify
7 * it under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/clk.h>
12#include <linux/delay.h>
13#include <linux/init.h>
14#include <linux/io.h>
15#include <linux/platform_device.h>
16#include <linux/slab.h>
17#include <linux/string.h>
18#include <linux/types.h>
19
20#include <video/mipi_display.h>
21#include <video/sh_mipi_dsi.h>
22#include <video/sh_mobile_lcdc.h>
23
24#define CMTSRTCTR 0x80d0
25#define CMTSRTREQ 0x8070
26
27#define DSIINTE 0x0060
28
29/* E.g., sh7372 has 2 MIPI-DSIs - one for each LCDC */
30#define MAX_SH_MIPI_DSI 2
31
32struct sh_mipi {
33 void __iomem *base;
34 struct clk *dsit_clk;
35 struct clk *dsip_clk;
36};
37
38static struct sh_mipi *mipi_dsi[MAX_SH_MIPI_DSI];
39
40/* Protect the above array */
41static DEFINE_MUTEX(array_lock);
42
43static struct sh_mipi *sh_mipi_by_handle(int handle)
44{
45 if (handle >= ARRAY_SIZE(mipi_dsi) || handle < 0)
46 return NULL;
47
48 return mipi_dsi[handle];
49}
50
51static int sh_mipi_send_short(struct sh_mipi *mipi, u8 dsi_cmd,
52 u8 cmd, u8 param)
53{
54 u32 data = (dsi_cmd << 24) | (cmd << 16) | (param << 8);
55 int cnt = 100;
56
57 /* transmit a short packet to LCD panel */
58 iowrite32(1 | data, mipi->base + 0x80d0); /* CMTSRTCTR */
59 iowrite32(1, mipi->base + 0x8070); /* CMTSRTREQ */
60
61 while ((ioread32(mipi->base + 0x8070) & 1) && --cnt)
62 udelay(1);
63
64 return cnt ? 0 : -ETIMEDOUT;
65}
66
67#define LCD_CHAN2MIPI(c) ((c) < LCDC_CHAN_MAINLCD || (c) > LCDC_CHAN_SUBLCD ? \
68 -EINVAL : (c) - 1)
69
70static int sh_mipi_dcs(int handle, u8 cmd)
71{
72 struct sh_mipi *mipi = sh_mipi_by_handle(LCD_CHAN2MIPI(handle));
73 if (!mipi)
74 return -ENODEV;
75 return sh_mipi_send_short(mipi, MIPI_DSI_DCS_SHORT_WRITE, cmd, 0);
76}
77
78static int sh_mipi_dcs_param(int handle, u8 cmd, u8 param)
79{
80 struct sh_mipi *mipi = sh_mipi_by_handle(LCD_CHAN2MIPI(handle));
81 if (!mipi)
82 return -ENODEV;
83 return sh_mipi_send_short(mipi, MIPI_DSI_DCS_SHORT_WRITE_PARAM, cmd,
84 param);
85}
86
87static void sh_mipi_dsi_enable(struct sh_mipi *mipi, bool enable)
88{
89 /*
90 * enable LCDC data tx, transition to LPS after completion of each HS
91 * packet
92 */
93 iowrite32(0x00000002 | enable, mipi->base + 0x8000); /* DTCTR */
94}
95
96static void sh_mipi_shutdown(struct platform_device *pdev)
97{
98 struct sh_mipi *mipi = platform_get_drvdata(pdev);
99
100 sh_mipi_dsi_enable(mipi, false);
101}
102
103static void mipi_display_on(void *arg, struct fb_info *info)
104{
105 struct sh_mipi *mipi = arg;
106
107 sh_mipi_dsi_enable(mipi, true);
108}
109
110static void mipi_display_off(void *arg)
111{
112 struct sh_mipi *mipi = arg;
113
114 sh_mipi_dsi_enable(mipi, false);
115}
116
117static int __init sh_mipi_setup(struct sh_mipi *mipi,
118 struct sh_mipi_dsi_info *pdata)
119{
120 void __iomem *base = mipi->base;
121 struct sh_mobile_lcdc_chan_cfg *ch = pdata->lcd_chan;
122 u32 pctype, datatype, pixfmt;
123 u32 linelength;
124 bool yuv;
125
126 /* Select data format */
127 switch (pdata->data_format) {
128 case MIPI_RGB888:
129 pctype = 0;
130 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_24;
131 pixfmt = MIPI_DCS_PIXEL_FMT_24BIT;
132 linelength = ch->lcd_cfg.xres * 3;
133 yuv = false;
134 break;
135 case MIPI_RGB565:
136 pctype = 1;
137 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_16;
138 pixfmt = MIPI_DCS_PIXEL_FMT_16BIT;
139 linelength = ch->lcd_cfg.xres * 2;
140 yuv = false;
141 break;
142 case MIPI_RGB666_LP:
143 pctype = 2;
144 datatype = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
145 pixfmt = MIPI_DCS_PIXEL_FMT_24BIT;
146 linelength = ch->lcd_cfg.xres * 3;
147 yuv = false;
148 break;
149 case MIPI_RGB666:
150 pctype = 3;
151 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_18;
152 pixfmt = MIPI_DCS_PIXEL_FMT_18BIT;
153 linelength = (ch->lcd_cfg.xres * 18 + 7) / 8;
154 yuv = false;
155 break;
156 case MIPI_BGR888:
157 pctype = 8;
158 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_24;
159 pixfmt = MIPI_DCS_PIXEL_FMT_24BIT;
160 linelength = ch->lcd_cfg.xres * 3;
161 yuv = false;
162 break;
163 case MIPI_BGR565:
164 pctype = 9;
165 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_16;
166 pixfmt = MIPI_DCS_PIXEL_FMT_16BIT;
167 linelength = ch->lcd_cfg.xres * 2;
168 yuv = false;
169 break;
170 case MIPI_BGR666_LP:
171 pctype = 0xa;
172 datatype = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
173 pixfmt = MIPI_DCS_PIXEL_FMT_24BIT;
174 linelength = ch->lcd_cfg.xres * 3;
175 yuv = false;
176 break;
177 case MIPI_BGR666:
178 pctype = 0xb;
179 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_18;
180 pixfmt = MIPI_DCS_PIXEL_FMT_18BIT;
181 linelength = (ch->lcd_cfg.xres * 18 + 7) / 8;
182 yuv = false;
183 break;
184 case MIPI_YUYV:
185 pctype = 4;
186 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16;
187 pixfmt = MIPI_DCS_PIXEL_FMT_16BIT;
188 linelength = ch->lcd_cfg.xres * 2;
189 yuv = true;
190 break;
191 case MIPI_UYVY:
192 pctype = 5;
193 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16;
194 pixfmt = MIPI_DCS_PIXEL_FMT_16BIT;
195 linelength = ch->lcd_cfg.xres * 2;
196 yuv = true;
197 break;
198 case MIPI_YUV420_L:
199 pctype = 6;
200 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12;
201 pixfmt = MIPI_DCS_PIXEL_FMT_12BIT;
202 linelength = (ch->lcd_cfg.xres * 12 + 7) / 8;
203 yuv = true;
204 break;
205 case MIPI_YUV420:
206 pctype = 7;
207 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12;
208 pixfmt = MIPI_DCS_PIXEL_FMT_12BIT;
209 /* Length of U/V line */
210 linelength = (ch->lcd_cfg.xres + 1) / 2;
211 yuv = true;
212 break;
213 default:
214 return -EINVAL;
215 }
216
217 if ((yuv && ch->interface_type != YUV422) ||
218 (!yuv && ch->interface_type != RGB24))
219 return -EINVAL;
220
221 /* reset DSI link */
222 iowrite32(0x00000001, base); /* SYSCTRL */
223 /* Hold reset for 100 cycles of the slowest of bus, HS byte and LP clock */
224 udelay(50);
225 iowrite32(0x00000000, base); /* SYSCTRL */
226
227 /* setup DSI link */
228
229 /*
230 * Default = ULPS enable |
231 * Contention detection enabled |
232 * EoT packet transmission enable |
233 * CRC check enable |
234 * ECC check enable
235 * additionally enable first two lanes
236 */
237 iowrite32(0x00003703, base + 0x04); /* SYSCONF */
238 /*
239 * T_wakeup = 0x7000
240 * T_hs-trail = 3
241 * T_hs-prepare = 3
242 * T_clk-trail = 3
243 * T_clk-prepare = 2
244 */
245 iowrite32(0x70003332, base + 0x08); /* TIMSET */
246 /* no responses requested */
247 iowrite32(0x00000000, base + 0x18); /* RESREQSET0 */
248 /* request response to packets of type 0x28 */
249 iowrite32(0x00000100, base + 0x1c); /* RESREQSET1 */
250 /* High-speed transmission timeout, default 0xffffffff */
251 iowrite32(0x0fffffff, base + 0x20); /* HSTTOVSET */
252 /* LP reception timeout, default 0xffffffff */
253 iowrite32(0x0fffffff, base + 0x24); /* LPRTOVSET */
254 /* Turn-around timeout, default 0xffffffff */
255 iowrite32(0x0fffffff, base + 0x28); /* TATOVSET */
256 /* Peripheral reset timeout, default 0xffffffff */
257 iowrite32(0x0fffffff, base + 0x2c); /* PRTOVSET */
258 /* Enable timeout counters */
259 iowrite32(0x00000f00, base + 0x30); /* DSICTRL */
260 /* Interrupts not used, disable all */
261 iowrite32(0, base + DSIINTE);
262 /* DSI-Tx bias on */
263 iowrite32(0x00000001, base + 0x70); /* PHYCTRL */
264 udelay(200);
265 /* Deassert resets, power on, set multiplier */
266 iowrite32(0x03070b01, base + 0x70); /* PHYCTRL */
267
268 /* setup l-bridge */
269
270 /*
271 * Enable transmission of all packets,
272 * transmit LPS after each HS packet completion
273 */
274 iowrite32(0x00000006, base + 0x8000); /* DTCTR */
275 /* VSYNC width = 2 (<< 17) */
276 iowrite32(0x00040000 | (pctype << 12) | datatype, base + 0x8020); /* VMCTR1 */
277 /*
278 * Non-burst mode with sync pulses: VSE and HSE are output,
279 * HSA period allowed, no commands in LP
280 */
281 iowrite32(0x00e00000, base + 0x8024); /* VMCTR2 */
282 /*
283 * 0x660 = 1632 bytes per line (RGB24, 544 pixels: see
284 * sh_mobile_lcdc_info.ch[0].lcd_cfg.xres), HSALEN = 1 - default
285 * (unused, since VMCTR2[HSABM] = 0)
286 */
287 iowrite32(1 | (linelength << 16), base + 0x8028); /* VMLEN1 */
288
289 msleep(5);
290
291 /* setup LCD panel */
292
293 /* cf. drivers/video/omap/lcd_mipid.c */
294 sh_mipi_dcs(ch->chan, MIPI_DCS_EXIT_SLEEP_MODE);
295 msleep(120);
296 /*
297 * [7] - Page Address Mode
298 * [6] - Column Address Mode
299 * [5] - Page / Column Address Mode
300 * [4] - Display Device Line Refresh Order
301 * [3] - RGB/BGR Order
302 * [2] - Display Data Latch Data Order
303 * [1] - Flip Horizontal
304 * [0] - Flip Vertical
305 */
306 sh_mipi_dcs_param(ch->chan, MIPI_DCS_SET_ADDRESS_MODE, 0x00);
307 /* cf. set_data_lines() */
308 sh_mipi_dcs_param(ch->chan, MIPI_DCS_SET_PIXEL_FORMAT,
309 pixfmt << 4);
310 sh_mipi_dcs(ch->chan, MIPI_DCS_SET_DISPLAY_ON);
311
312 return 0;
313}
314
315static int __init sh_mipi_probe(struct platform_device *pdev)
316{
317 struct sh_mipi *mipi;
318 struct sh_mipi_dsi_info *pdata = pdev->dev.platform_data;
319 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
320 unsigned long rate, f_current;
321 int idx = pdev->id, ret;
322 char dsip_clk[] = "dsi.p_clk";
323
324 if (!res || idx >= ARRAY_SIZE(mipi_dsi) || !pdata)
325 return -ENODEV;
326
327 mutex_lock(&array_lock);
328 if (idx < 0)
329 for (idx = 0; idx < ARRAY_SIZE(mipi_dsi) && mipi_dsi[idx]; idx++)
330 ;
331
332 if (idx == ARRAY_SIZE(mipi_dsi)) {
333 ret = -EBUSY;
334 goto efindslot;
335 }
336
337 mipi = kzalloc(sizeof(*mipi), GFP_KERNEL);
338 if (!mipi) {
339 ret = -ENOMEM;
340 goto ealloc;
341 }
342
343 if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
344 dev_err(&pdev->dev, "MIPI register region already claimed\n");
345 ret = -EBUSY;
346 goto ereqreg;
347 }
348
349 mipi->base = ioremap(res->start, resource_size(res));
350 if (!mipi->base) {
351 ret = -ENOMEM;
352 goto emap;
353 }
354
355 mipi->dsit_clk = clk_get(&pdev->dev, "dsit_clk");
356 if (IS_ERR(mipi->dsit_clk)) {
357 ret = PTR_ERR(mipi->dsit_clk);
358 goto eclktget;
359 }
360
361 f_current = clk_get_rate(mipi->dsit_clk);
362 /* 80MHz required by the datasheet */
363 rate = clk_round_rate(mipi->dsit_clk, 80000000);
364 if (rate > 0 && rate != f_current)
365 ret = clk_set_rate(mipi->dsit_clk, rate);
366 else
367 ret = rate;
368 if (ret < 0)
369 goto esettrate;
370
371 dev_dbg(&pdev->dev, "DSI-T clk %lu -> %lu\n", f_current, rate);
372
373 sprintf(dsip_clk, "dsi%1.1dp_clk", idx);
374 mipi->dsip_clk = clk_get(&pdev->dev, dsip_clk);
375 if (IS_ERR(mipi->dsip_clk)) {
376 ret = PTR_ERR(mipi->dsip_clk);
377 goto eclkpget;
378 }
379
380 f_current = clk_get_rate(mipi->dsip_clk);
381 /* Between 10 and 50MHz */
382 rate = clk_round_rate(mipi->dsip_clk, 24000000);
383 if (rate > 0 && rate != f_current)
384 ret = clk_set_rate(mipi->dsip_clk, rate);
385 else
386 ret = rate;
387 if (ret < 0)
388 goto esetprate;
389
390 dev_dbg(&pdev->dev, "DSI-P clk %lu -> %lu\n", f_current, rate);
391
392 msleep(10);
393
394 ret = clk_enable(mipi->dsit_clk);
395 if (ret < 0)
396 goto eclkton;
397
398 ret = clk_enable(mipi->dsip_clk);
399 if (ret < 0)
400 goto eclkpon;
401
402 mipi_dsi[idx] = mipi;
403
404 ret = sh_mipi_setup(mipi, pdata);
405 if (ret < 0)
406 goto emipisetup;
407
408 mutex_unlock(&array_lock);
409 platform_set_drvdata(pdev, mipi);
410
411 /* Set up LCDC callbacks */
412 pdata->lcd_chan->board_cfg.board_data = mipi;
413 pdata->lcd_chan->board_cfg.display_on = mipi_display_on;
414 pdata->lcd_chan->board_cfg.display_off = mipi_display_off;
415
416 return 0;
417
418emipisetup:
419 mipi_dsi[idx] = NULL;
420 clk_disable(mipi->dsip_clk);
421eclkpon:
422 clk_disable(mipi->dsit_clk);
423eclkton:
424esetprate:
425 clk_put(mipi->dsip_clk);
426eclkpget:
427esettrate:
428 clk_put(mipi->dsit_clk);
429eclktget:
430 iounmap(mipi->base);
431emap:
432 release_mem_region(res->start, resource_size(res));
433ereqreg:
434 kfree(mipi);
435ealloc:
436efindslot:
437 mutex_unlock(&array_lock);
438
439 return ret;
440}
441
442static int __exit sh_mipi_remove(struct platform_device *pdev)
443{
444 struct sh_mipi_dsi_info *pdata = pdev->dev.platform_data;
445 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
446 struct sh_mipi *mipi = platform_get_drvdata(pdev);
447 int i, ret;
448
449 mutex_lock(&array_lock);
450
451 for (i = 0; i < ARRAY_SIZE(mipi_dsi) && mipi_dsi[i] != mipi; i++)
452 ;
453
454 if (i == ARRAY_SIZE(mipi_dsi)) {
455 ret = -EINVAL;
456 } else {
457 ret = 0;
458 mipi_dsi[i] = NULL;
459 }
460
461 mutex_unlock(&array_lock);
462
463 if (ret < 0)
464 return ret;
465
466 pdata->lcd_chan->board_cfg.display_on = NULL;
467 pdata->lcd_chan->board_cfg.display_off = NULL;
468 pdata->lcd_chan->board_cfg.board_data = NULL;
469
470 clk_disable(mipi->dsip_clk);
471 clk_disable(mipi->dsit_clk);
472 clk_put(mipi->dsit_clk);
473 clk_put(mipi->dsip_clk);
474 iounmap(mipi->base);
475 if (res)
476 release_mem_region(res->start, resource_size(res));
477 platform_set_drvdata(pdev, NULL);
478 kfree(mipi);
479
480 return 0;
481}
482
483static struct platform_driver sh_mipi_driver = {
484 .remove = __exit_p(sh_mipi_remove),
485 .shutdown = sh_mipi_shutdown,
486 .driver = {
487 .name = "sh-mipi-dsi",
488 },
489};
490
491static int __init sh_mipi_init(void)
492{
493 return platform_driver_probe(&sh_mipi_driver, sh_mipi_probe);
494}
495module_init(sh_mipi_init);
496
497static void __exit sh_mipi_exit(void)
498{
499 platform_driver_unregister(&sh_mipi_driver);
500}
501module_exit(sh_mipi_exit);
502
503MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
504MODULE_DESCRIPTION("SuperH / ARM-shmobile MIPI DSI driver");
505MODULE_LICENSE("GPL v2");
diff --git a/drivers/video/sh_mobile_hdmi.c b/drivers/video/sh_mobile_hdmi.c
new file mode 100644
index 000000000000..2fde08cc66bf
--- /dev/null
+++ b/drivers/video/sh_mobile_hdmi.c
@@ -0,0 +1,1028 @@
1/*
2 * SH-Mobile High-Definition Multimedia Interface (HDMI) driver
3 * for SLISHDMI13T and SLIPHDMIT IP cores
4 *
5 * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/clk.h>
13#include <linux/console.h>
14#include <linux/delay.h>
15#include <linux/err.h>
16#include <linux/init.h>
17#include <linux/interrupt.h>
18#include <linux/io.h>
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/pm_runtime.h>
22#include <linux/slab.h>
23#include <linux/types.h>
24#include <linux/workqueue.h>
25
26#include <video/sh_mobile_hdmi.h>
27#include <video/sh_mobile_lcdc.h>
28
29#define HDMI_SYSTEM_CTRL 0x00 /* System control */
30#define HDMI_L_R_DATA_SWAP_CTRL_RPKT 0x01 /* L/R data swap control,
31 bits 19..16 of 20-bit N for Audio Clock Regeneration packet */
32#define HDMI_20_BIT_N_FOR_AUDIO_RPKT_15_8 0x02 /* bits 15..8 of 20-bit N for Audio Clock Regeneration packet */
33#define HDMI_20_BIT_N_FOR_AUDIO_RPKT_7_0 0x03 /* bits 7..0 of 20-bit N for Audio Clock Regeneration packet */
34#define HDMI_SPDIF_AUDIO_SAMP_FREQ_CTS 0x04 /* SPDIF audio sampling frequency,
35 bits 19..16 of Internal CTS */
36#define HDMI_INTERNAL_CTS_15_8 0x05 /* bits 15..8 of Internal CTS */
37#define HDMI_INTERNAL_CTS_7_0 0x06 /* bits 7..0 of Internal CTS */
38#define HDMI_EXTERNAL_CTS_19_16 0x07 /* External CTS */
39#define HDMI_EXTERNAL_CTS_15_8 0x08 /* External CTS */
40#define HDMI_EXTERNAL_CTS_7_0 0x09 /* External CTS */
41#define HDMI_AUDIO_SETTING_1 0x0A /* Audio setting.1 */
42#define HDMI_AUDIO_SETTING_2 0x0B /* Audio setting.2 */
43#define HDMI_I2S_AUDIO_SET 0x0C /* I2S audio setting */
44#define HDMI_DSD_AUDIO_SET 0x0D /* DSD audio setting */
45#define HDMI_DEBUG_MONITOR_1 0x0E /* Debug monitor.1 */
46#define HDMI_DEBUG_MONITOR_2 0x0F /* Debug monitor.2 */
47#define HDMI_I2S_INPUT_PIN_SWAP 0x10 /* I2S input pin swap */
48#define HDMI_AUDIO_STATUS_BITS_SETTING_1 0x11 /* Audio status bits setting.1 */
49#define HDMI_AUDIO_STATUS_BITS_SETTING_2 0x12 /* Audio status bits setting.2 */
50#define HDMI_CATEGORY_CODE 0x13 /* Category code */
51#define HDMI_SOURCE_NUM_AUDIO_WORD_LEN 0x14 /* Source number/Audio word length */
52#define HDMI_AUDIO_VIDEO_SETTING_1 0x15 /* Audio/Video setting.1 */
53#define HDMI_VIDEO_SETTING_1 0x16 /* Video setting.1 */
54#define HDMI_DEEP_COLOR_MODES 0x17 /* Deep Color Modes */
55
56/* 12 16- and 10-bit Color space conversion parameters: 0x18..0x2f */
57#define HDMI_COLOR_SPACE_CONVERSION_PARAMETERS 0x18
58
59#define HDMI_EXTERNAL_VIDEO_PARAM_SETTINGS 0x30 /* External video parameter settings */
60#define HDMI_EXTERNAL_H_TOTAL_7_0 0x31 /* External horizontal total (LSB) */
61#define HDMI_EXTERNAL_H_TOTAL_11_8 0x32 /* External horizontal total (MSB) */
62#define HDMI_EXTERNAL_H_BLANK_7_0 0x33 /* External horizontal blank (LSB) */
63#define HDMI_EXTERNAL_H_BLANK_9_8 0x34 /* External horizontal blank (MSB) */
64#define HDMI_EXTERNAL_H_DELAY_7_0 0x35 /* External horizontal delay (LSB) */
65#define HDMI_EXTERNAL_H_DELAY_9_8 0x36 /* External horizontal delay (MSB) */
66#define HDMI_EXTERNAL_H_DURATION_7_0 0x37 /* External horizontal duration (LSB) */
67#define HDMI_EXTERNAL_H_DURATION_9_8 0x38 /* External horizontal duration (MSB) */
68#define HDMI_EXTERNAL_V_TOTAL_7_0 0x39 /* External vertical total (LSB) */
69#define HDMI_EXTERNAL_V_TOTAL_9_8 0x3A /* External vertical total (MSB) */
70#define HDMI_AUDIO_VIDEO_SETTING_2 0x3B /* Audio/Video setting.2 */
71#define HDMI_EXTERNAL_V_BLANK 0x3D /* External vertical blank */
72#define HDMI_EXTERNAL_V_DELAY 0x3E /* External vertical delay */
73#define HDMI_EXTERNAL_V_DURATION 0x3F /* External vertical duration */
74#define HDMI_CTRL_PKT_MANUAL_SEND_CONTROL 0x40 /* Control packet manual send control */
75#define HDMI_CTRL_PKT_AUTO_SEND 0x41 /* Control packet auto send with VSYNC control */
76#define HDMI_AUTO_CHECKSUM_OPTION 0x42 /* Auto checksum option */
77#define HDMI_VIDEO_SETTING_2 0x45 /* Video setting.2 */
78#define HDMI_OUTPUT_OPTION 0x46 /* Output option */
79#define HDMI_SLIPHDMIT_PARAM_OPTION 0x51 /* SLIPHDMIT parameter option */
80#define HDMI_HSYNC_PMENT_AT_EMB_7_0 0x52 /* HSYNC placement at embedded sync (LSB) */
81#define HDMI_HSYNC_PMENT_AT_EMB_15_8 0x53 /* HSYNC placement at embedded sync (MSB) */
82#define HDMI_VSYNC_PMENT_AT_EMB_7_0 0x54 /* VSYNC placement at embedded sync (LSB) */
83#define HDMI_VSYNC_PMENT_AT_EMB_14_8 0x55 /* VSYNC placement at embedded sync (MSB) */
84#define HDMI_SLIPHDMIT_PARAM_SETTINGS_1 0x56 /* SLIPHDMIT parameter settings.1 */
85#define HDMI_SLIPHDMIT_PARAM_SETTINGS_2 0x57 /* SLIPHDMIT parameter settings.2 */
86#define HDMI_SLIPHDMIT_PARAM_SETTINGS_3 0x58 /* SLIPHDMIT parameter settings.3 */
87#define HDMI_SLIPHDMIT_PARAM_SETTINGS_5 0x59 /* SLIPHDMIT parameter settings.5 */
88#define HDMI_SLIPHDMIT_PARAM_SETTINGS_6 0x5A /* SLIPHDMIT parameter settings.6 */
89#define HDMI_SLIPHDMIT_PARAM_SETTINGS_7 0x5B /* SLIPHDMIT parameter settings.7 */
90#define HDMI_SLIPHDMIT_PARAM_SETTINGS_8 0x5C /* SLIPHDMIT parameter settings.8 */
91#define HDMI_SLIPHDMIT_PARAM_SETTINGS_9 0x5D /* SLIPHDMIT parameter settings.9 */
92#define HDMI_SLIPHDMIT_PARAM_SETTINGS_10 0x5E /* SLIPHDMIT parameter settings.10 */
93#define HDMI_CTRL_PKT_BUF_INDEX 0x5F /* Control packet buffer index */
94#define HDMI_CTRL_PKT_BUF_ACCESS_HB0 0x60 /* Control packet data buffer access window - HB0 */
95#define HDMI_CTRL_PKT_BUF_ACCESS_HB1 0x61 /* Control packet data buffer access window - HB1 */
96#define HDMI_CTRL_PKT_BUF_ACCESS_HB2 0x62 /* Control packet data buffer access window - HB2 */
97#define HDMI_CTRL_PKT_BUF_ACCESS_PB0 0x63 /* Control packet data buffer access window - PB0 */
98#define HDMI_CTRL_PKT_BUF_ACCESS_PB1 0x64 /* Control packet data buffer access window - PB1 */
99#define HDMI_CTRL_PKT_BUF_ACCESS_PB2 0x65 /* Control packet data buffer access window - PB2 */
100#define HDMI_CTRL_PKT_BUF_ACCESS_PB3 0x66 /* Control packet data buffer access window - PB3 */
101#define HDMI_CTRL_PKT_BUF_ACCESS_PB4 0x67 /* Control packet data buffer access window - PB4 */
102#define HDMI_CTRL_PKT_BUF_ACCESS_PB5 0x68 /* Control packet data buffer access window - PB5 */
103#define HDMI_CTRL_PKT_BUF_ACCESS_PB6 0x69 /* Control packet data buffer access window - PB6 */
104#define HDMI_CTRL_PKT_BUF_ACCESS_PB7 0x6A /* Control packet data buffer access window - PB7 */
105#define HDMI_CTRL_PKT_BUF_ACCESS_PB8 0x6B /* Control packet data buffer access window - PB8 */
106#define HDMI_CTRL_PKT_BUF_ACCESS_PB9 0x6C /* Control packet data buffer access window - PB9 */
107#define HDMI_CTRL_PKT_BUF_ACCESS_PB10 0x6D /* Control packet data buffer access window - PB10 */
108#define HDMI_CTRL_PKT_BUF_ACCESS_PB11 0x6E /* Control packet data buffer access window - PB11 */
109#define HDMI_CTRL_PKT_BUF_ACCESS_PB12 0x6F /* Control packet data buffer access window - PB12 */
110#define HDMI_CTRL_PKT_BUF_ACCESS_PB13 0x70 /* Control packet data buffer access window - PB13 */
111#define HDMI_CTRL_PKT_BUF_ACCESS_PB14 0x71 /* Control packet data buffer access window - PB14 */
112#define HDMI_CTRL_PKT_BUF_ACCESS_PB15 0x72 /* Control packet data buffer access window - PB15 */
113#define HDMI_CTRL_PKT_BUF_ACCESS_PB16 0x73 /* Control packet data buffer access window - PB16 */
114#define HDMI_CTRL_PKT_BUF_ACCESS_PB17 0x74 /* Control packet data buffer access window - PB17 */
115#define HDMI_CTRL_PKT_BUF_ACCESS_PB18 0x75 /* Control packet data buffer access window - PB18 */
116#define HDMI_CTRL_PKT_BUF_ACCESS_PB19 0x76 /* Control packet data buffer access window - PB19 */
117#define HDMI_CTRL_PKT_BUF_ACCESS_PB20 0x77 /* Control packet data buffer access window - PB20 */
118#define HDMI_CTRL_PKT_BUF_ACCESS_PB21 0x78 /* Control packet data buffer access window - PB21 */
119#define HDMI_CTRL_PKT_BUF_ACCESS_PB22 0x79 /* Control packet data buffer access window - PB22 */
120#define HDMI_CTRL_PKT_BUF_ACCESS_PB23 0x7A /* Control packet data buffer access window - PB23 */
121#define HDMI_CTRL_PKT_BUF_ACCESS_PB24 0x7B /* Control packet data buffer access window - PB24 */
122#define HDMI_CTRL_PKT_BUF_ACCESS_PB25 0x7C /* Control packet data buffer access window - PB25 */
123#define HDMI_CTRL_PKT_BUF_ACCESS_PB26 0x7D /* Control packet data buffer access window - PB26 */
124#define HDMI_CTRL_PKT_BUF_ACCESS_PB27 0x7E /* Control packet data buffer access window - PB27 */
125#define HDMI_EDID_KSV_FIFO_ACCESS_WINDOW 0x80 /* EDID/KSV FIFO access window */
126#define HDMI_DDC_BUS_ACCESS_FREQ_CTRL_7_0 0x81 /* DDC bus access frequency control (LSB) */
127#define HDMI_DDC_BUS_ACCESS_FREQ_CTRL_15_8 0x82 /* DDC bus access frequency control (MSB) */
128#define HDMI_INTERRUPT_MASK_1 0x92 /* Interrupt mask.1 */
129#define HDMI_INTERRUPT_MASK_2 0x93 /* Interrupt mask.2 */
130#define HDMI_INTERRUPT_STATUS_1 0x94 /* Interrupt status.1 */
131#define HDMI_INTERRUPT_STATUS_2 0x95 /* Interrupt status.2 */
132#define HDMI_INTERRUPT_MASK_3 0x96 /* Interrupt mask.3 */
133#define HDMI_INTERRUPT_MASK_4 0x97 /* Interrupt mask.4 */
134#define HDMI_INTERRUPT_STATUS_3 0x98 /* Interrupt status.3 */
135#define HDMI_INTERRUPT_STATUS_4 0x99 /* Interrupt status.4 */
136#define HDMI_SOFTWARE_HDCP_CONTROL_1 0x9A /* Software HDCP control.1 */
137#define HDMI_FRAME_COUNTER 0x9C /* Frame counter */
138#define HDMI_FRAME_COUNTER_FOR_RI_CHECK 0x9D /* Frame counter for Ri check */
139#define HDMI_HDCP_CONTROL 0xAF /* HDCP control */
140#define HDMI_RI_FRAME_COUNT_REGISTER 0xB2 /* Ri frame count register */
141#define HDMI_DDC_BUS_CONTROL 0xB7 /* DDC bus control */
142#define HDMI_HDCP_STATUS 0xB8 /* HDCP status */
143#define HDMI_SHA0 0xB9 /* sha0 */
144#define HDMI_SHA1 0xBA /* sha1 */
145#define HDMI_SHA2 0xBB /* sha2 */
146#define HDMI_SHA3 0xBC /* sha3 */
147#define HDMI_SHA4 0xBD /* sha4 */
148#define HDMI_BCAPS_READ 0xBE /* BCAPS read / debug */
149#define HDMI_AKSV_BKSV_7_0_MONITOR 0xBF /* AKSV/BKSV[7:0] monitor */
150#define HDMI_AKSV_BKSV_15_8_MONITOR 0xC0 /* AKSV/BKSV[15:8] monitor */
151#define HDMI_AKSV_BKSV_23_16_MONITOR 0xC1 /* AKSV/BKSV[23:16] monitor */
152#define HDMI_AKSV_BKSV_31_24_MONITOR 0xC2 /* AKSV/BKSV[31:24] monitor */
153#define HDMI_AKSV_BKSV_39_32_MONITOR 0xC3 /* AKSV/BKSV[39:32] monitor */
154#define HDMI_EDID_SEGMENT_POINTER 0xC4 /* EDID segment pointer */
155#define HDMI_EDID_WORD_ADDRESS 0xC5 /* EDID word address */
156#define HDMI_EDID_DATA_FIFO_ADDRESS 0xC6 /* EDID data FIFO address */
157#define HDMI_NUM_OF_HDMI_DEVICES 0xC7 /* Number of HDMI devices */
158#define HDMI_HDCP_ERROR_CODE 0xC8 /* HDCP error code */
159#define HDMI_100MS_TIMER_SET 0xC9 /* 100ms timer setting */
160#define HDMI_5SEC_TIMER_SET 0xCA /* 5sec timer setting */
161#define HDMI_RI_READ_COUNT 0xCB /* Ri read count */
162#define HDMI_AN_SEED 0xCC /* An seed */
163#define HDMI_MAX_NUM_OF_RCIVRS_ALLOWED 0xCD /* Maximum number of receivers allowed */
164#define HDMI_HDCP_MEMORY_ACCESS_CONTROL_1 0xCE /* HDCP memory access control.1 */
165#define HDMI_HDCP_MEMORY_ACCESS_CONTROL_2 0xCF /* HDCP memory access control.2 */
166#define HDMI_HDCP_CONTROL_2 0xD0 /* HDCP Control 2 */
167#define HDMI_HDCP_KEY_MEMORY_CONTROL 0xD2 /* HDCP Key Memory Control */
168#define HDMI_COLOR_SPACE_CONV_CONFIG_1 0xD3 /* Color space conversion configuration.1 */
169#define HDMI_VIDEO_SETTING_3 0xD4 /* Video setting.3 */
170#define HDMI_RI_7_0 0xD5 /* Ri[7:0] */
171#define HDMI_RI_15_8 0xD6 /* Ri[15:8] */
172#define HDMI_PJ 0xD7 /* Pj */
173#define HDMI_SHA_RD 0xD8 /* sha_rd */
174#define HDMI_RI_7_0_SAVED 0xD9 /* Ri[7:0] saved */
175#define HDMI_RI_15_8_SAVED 0xDA /* Ri[15:8] saved */
176#define HDMI_PJ_SAVED 0xDB /* Pj saved */
177#define HDMI_NUM_OF_DEVICES 0xDC /* Number of devices */
178#define HDMI_HOT_PLUG_MSENS_STATUS 0xDF /* Hot plug/MSENS status */
179#define HDMI_BCAPS_WRITE 0xE0 /* bcaps */
180#define HDMI_BSTAT_7_0 0xE1 /* bstat[7:0] */
181#define HDMI_BSTAT_15_8 0xE2 /* bstat[15:8] */
182#define HDMI_BKSV_7_0 0xE3 /* bksv[7:0] */
183#define HDMI_BKSV_15_8 0xE4 /* bksv[15:8] */
184#define HDMI_BKSV_23_16 0xE5 /* bksv[23:16] */
185#define HDMI_BKSV_31_24 0xE6 /* bksv[31:24] */
186#define HDMI_BKSV_39_32 0xE7 /* bksv[39:32] */
187#define HDMI_AN_7_0 0xE8 /* An[7:0] */
188#define HDMI_AN_15_8 0xE9 /* An [15:8] */
189#define HDMI_AN_23_16 0xEA /* An [23:16] */
190#define HDMI_AN_31_24 0xEB /* An [31:24] */
191#define HDMI_AN_39_32 0xEC /* An [39:32] */
192#define HDMI_AN_47_40 0xED /* An [47:40] */
193#define HDMI_AN_55_48 0xEE /* An [55:48] */
194#define HDMI_AN_63_56 0xEF /* An [63:56] */
195#define HDMI_PRODUCT_ID 0xF0 /* Product ID */
196#define HDMI_REVISION_ID 0xF1 /* Revision ID */
197#define HDMI_TEST_MODE 0xFE /* Test mode */
198
199enum hotplug_state {
200 HDMI_HOTPLUG_DISCONNECTED,
201 HDMI_HOTPLUG_CONNECTED,
202 HDMI_HOTPLUG_EDID_DONE,
203};
204
205struct sh_hdmi {
206 void __iomem *base;
207 enum hotplug_state hp_state;
208 struct clk *hdmi_clk;
209 struct device *dev;
210 struct fb_info *info;
211 struct delayed_work edid_work;
212 struct fb_var_screeninfo var;
213};
214
215static void hdmi_write(struct sh_hdmi *hdmi, u8 data, u8 reg)
216{
217 iowrite8(data, hdmi->base + reg);
218}
219
220static u8 hdmi_read(struct sh_hdmi *hdmi, u8 reg)
221{
222 return ioread8(hdmi->base + reg);
223}
224
225/* External video parameter settings */
226static void hdmi_external_video_param(struct sh_hdmi *hdmi)
227{
228 struct fb_var_screeninfo *var = &hdmi->var;
229 u16 htotal, hblank, hdelay, vtotal, vblank, vdelay, voffset;
230 u8 sync = 0;
231
232 htotal = var->xres + var->right_margin + var->left_margin + var->hsync_len;
233
234 hdelay = var->hsync_len + var->left_margin;
235 hblank = var->right_margin + hdelay;
236
237 /*
238 * Vertical timing looks a bit different in Figure 18,
239 * but let's try the same first by setting offset = 0
240 */
241 vtotal = var->yres + var->upper_margin + var->lower_margin + var->vsync_len;
242
243 vdelay = var->vsync_len + var->upper_margin;
244 vblank = var->lower_margin + vdelay;
245 voffset = min(var->upper_margin / 2, 6U);
246
247 /*
248 * [3]: VSYNC polarity: Positive
249 * [2]: HSYNC polarity: Positive
250 * [1]: Interlace/Progressive: Progressive
251 * [0]: External video settings enable: used.
252 */
253 if (var->sync & FB_SYNC_HOR_HIGH_ACT)
254 sync |= 4;
255 if (var->sync & FB_SYNC_VERT_HIGH_ACT)
256 sync |= 8;
257
258 pr_debug("H: %u, %u, %u, %u; V: %u, %u, %u, %u; sync 0x%x\n",
259 htotal, hblank, hdelay, var->hsync_len,
260 vtotal, vblank, vdelay, var->vsync_len, sync);
261
262 hdmi_write(hdmi, sync | (voffset << 4), HDMI_EXTERNAL_VIDEO_PARAM_SETTINGS);
263
264 hdmi_write(hdmi, htotal, HDMI_EXTERNAL_H_TOTAL_7_0);
265 hdmi_write(hdmi, htotal >> 8, HDMI_EXTERNAL_H_TOTAL_11_8);
266
267 hdmi_write(hdmi, hblank, HDMI_EXTERNAL_H_BLANK_7_0);
268 hdmi_write(hdmi, hblank >> 8, HDMI_EXTERNAL_H_BLANK_9_8);
269
270 hdmi_write(hdmi, hdelay, HDMI_EXTERNAL_H_DELAY_7_0);
271 hdmi_write(hdmi, hdelay >> 8, HDMI_EXTERNAL_H_DELAY_9_8);
272
273 hdmi_write(hdmi, var->hsync_len, HDMI_EXTERNAL_H_DURATION_7_0);
274 hdmi_write(hdmi, var->hsync_len >> 8, HDMI_EXTERNAL_H_DURATION_9_8);
275
276 hdmi_write(hdmi, vtotal, HDMI_EXTERNAL_V_TOTAL_7_0);
277 hdmi_write(hdmi, vtotal >> 8, HDMI_EXTERNAL_V_TOTAL_9_8);
278
279 hdmi_write(hdmi, vblank, HDMI_EXTERNAL_V_BLANK);
280
281 hdmi_write(hdmi, vdelay, HDMI_EXTERNAL_V_DELAY);
282
283 hdmi_write(hdmi, var->vsync_len, HDMI_EXTERNAL_V_DURATION);
284
285 /* Set bit 0 of HDMI_EXTERNAL_VIDEO_PARAM_SETTINGS here for manual mode */
286}
287
288/**
289 * sh_hdmi_video_config()
290 */
291static void sh_hdmi_video_config(struct sh_hdmi *hdmi)
292{
293 /*
294 * [7:4]: Audio sampling frequency: 48kHz
295 * [3:1]: Input video format: RGB and YCbCr 4:4:4 (Y on Green)
296 * [0]: Internal/External DE select: internal
297 */
298 hdmi_write(hdmi, 0x20, HDMI_AUDIO_VIDEO_SETTING_1);
299
300 /*
301 * [7:6]: Video output format: RGB 4:4:4
302 * [5:4]: Input video data width: 8 bit
303 * [3:1]: EAV/SAV location: channel 1
304 * [0]: Video input color space: RGB
305 */
306 hdmi_write(hdmi, 0x34, HDMI_VIDEO_SETTING_1);
307
308 /*
309 * [7:6]: Together with bit [6] of HDMI_AUDIO_VIDEO_SETTING_2, which is
310 * left at 0 by default, this configures 24bpp and sets the Color Depth
311 * (CD) field in the General Control Packet
312 */
313 hdmi_write(hdmi, 0x20, HDMI_DEEP_COLOR_MODES);
314}
315
316/**
317 * sh_hdmi_audio_config()
318 */
319static void sh_hdmi_audio_config(struct sh_hdmi *hdmi)
320{
321 /*
322 * [7:4] L/R data swap control
323 * [3:0] appropriate N[19:16]
324 */
325 hdmi_write(hdmi, 0x00, HDMI_L_R_DATA_SWAP_CTRL_RPKT);
326 /* appropriate N[15:8] */
327 hdmi_write(hdmi, 0x18, HDMI_20_BIT_N_FOR_AUDIO_RPKT_15_8);
328 /* appropriate N[7:0] */
329 hdmi_write(hdmi, 0x00, HDMI_20_BIT_N_FOR_AUDIO_RPKT_7_0);
330
331 /* [7:4] 48 kHz SPDIF not used */
332 hdmi_write(hdmi, 0x20, HDMI_SPDIF_AUDIO_SAMP_FREQ_CTS);
333
334 /*
335 * [6:5] set required down sampling rate if required
336 * [4:3] set required audio source
337 */
338 hdmi_write(hdmi, 0x00, HDMI_AUDIO_SETTING_1);
339
340 /* [3:0] set sending channel number for channel status */
341 hdmi_write(hdmi, 0x40, HDMI_AUDIO_SETTING_2);
342
343 /*
344 * [5:2] set valid I2S source input pin
345 * [1:0] set input I2S source mode
346 */
347 hdmi_write(hdmi, 0x04, HDMI_I2S_AUDIO_SET);
348
349 /* [7:4] set valid DSD source input pin */
350 hdmi_write(hdmi, 0x00, HDMI_DSD_AUDIO_SET);
351
352 /* [7:0] set appropriate I2S input pin swap settings if required */
353 hdmi_write(hdmi, 0x00, HDMI_I2S_INPUT_PIN_SWAP);
354
355 /*
356 * [7] set validity bit for channel status
357 * [3:0] set original sample frequency for channel status
358 */
359 hdmi_write(hdmi, 0x00, HDMI_AUDIO_STATUS_BITS_SETTING_1);
360
361 /*
362 * [7] set value for channel status
363 * [6] set value for channel status
364 * [5] set copyright bit for channel status
365 * [4:2] set additional information for channel status
366 * [1:0] set clock accuracy for channel status
367 */
368 hdmi_write(hdmi, 0x00, HDMI_AUDIO_STATUS_BITS_SETTING_2);
369
370 /* [7:0] set category code for channel status */
371 hdmi_write(hdmi, 0x00, HDMI_CATEGORY_CODE);
372
373 /*
374 * [7:4] set source number for channel status
375 * [3:0] set word length for channel status
376 */
377 hdmi_write(hdmi, 0x00, HDMI_SOURCE_NUM_AUDIO_WORD_LEN);
378
379 /* [7:4] set sample frequency for channel status */
380 hdmi_write(hdmi, 0x20, HDMI_AUDIO_VIDEO_SETTING_1);
381}
382
383/**
384 * sh_hdmi_phy_config()
385 */
386static void sh_hdmi_phy_config(struct sh_hdmi *hdmi)
387{
388 /* 720p, 8bit, 74.25MHz. Might need to be adjusted for other formats */
389 hdmi_write(hdmi, 0x19, HDMI_SLIPHDMIT_PARAM_SETTINGS_1);
390 hdmi_write(hdmi, 0x00, HDMI_SLIPHDMIT_PARAM_SETTINGS_2);
391 hdmi_write(hdmi, 0x00, HDMI_SLIPHDMIT_PARAM_SETTINGS_3);
392 /* PLLA_CONFIG[7:0]: VCO gain, VCO offset, LPF resistance[0] */
393 hdmi_write(hdmi, 0x44, HDMI_SLIPHDMIT_PARAM_SETTINGS_5);
394 hdmi_write(hdmi, 0x32, HDMI_SLIPHDMIT_PARAM_SETTINGS_6);
395 hdmi_write(hdmi, 0x4A, HDMI_SLIPHDMIT_PARAM_SETTINGS_7);
396 hdmi_write(hdmi, 0x0E, HDMI_SLIPHDMIT_PARAM_SETTINGS_8);
397 hdmi_write(hdmi, 0x25, HDMI_SLIPHDMIT_PARAM_SETTINGS_9);
398 hdmi_write(hdmi, 0x04, HDMI_SLIPHDMIT_PARAM_SETTINGS_10);
399}
400
401/**
402 * sh_hdmi_avi_infoframe_setup() - Auxiliary Video Information InfoFrame CONTROL PACKET
403 */
404static void sh_hdmi_avi_infoframe_setup(struct sh_hdmi *hdmi)
405{
406 /* AVI InfoFrame */
407 hdmi_write(hdmi, 0x06, HDMI_CTRL_PKT_BUF_INDEX);
408
409 /* Packet Type = 0x82 */
410 hdmi_write(hdmi, 0x82, HDMI_CTRL_PKT_BUF_ACCESS_HB0);
411
412 /* Version = 0x02 */
413 hdmi_write(hdmi, 0x02, HDMI_CTRL_PKT_BUF_ACCESS_HB1);
414
415 /* Length = 13 (0x0D) */
416 hdmi_write(hdmi, 0x0D, HDMI_CTRL_PKT_BUF_ACCESS_HB2);
417
418 /* N. A. Checksum */
419 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0);
420
421 /*
422 * Y = RGB
423 * A0 = No Data
424 * B = Bar Data not valid
425 * S = No Data
426 */
427 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB1);
428
429 /*
430 * C = No Data
431 * M = 16:9 Picture Aspect Ratio
432 * R = Same as picture aspect ratio
433 */
434 hdmi_write(hdmi, 0x28, HDMI_CTRL_PKT_BUF_ACCESS_PB2);
435
436 /*
437 * ITC = No Data
438 * EC = xvYCC601
439 * Q = Default (depends on video format)
440 * SC = No Known non_uniform Scaling
441 */
442 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB3);
443
444 /*
445 * VIC = 1280 x 720p: ignored if external config is used
446 * Send 2 for 720 x 480p, 16 for 1080p
447 */
448 hdmi_write(hdmi, 4, HDMI_CTRL_PKT_BUF_ACCESS_PB4);
449
450 /* PR = No Repetition */
451 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB5);
452
453 /* Line Number of End of Top Bar (lower 8 bits) */
454 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB6);
455
456 /* Line Number of End of Top Bar (upper 8 bits) */
457 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB7);
458
459 /* Line Number of Start of Bottom Bar (lower 8 bits) */
460 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB8);
461
462 /* Line Number of Start of Bottom Bar (upper 8 bits) */
463 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB9);
464
465 /* Pixel Number of End of Left Bar (lower 8 bits) */
466 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB10);
467
468 /* Pixel Number of End of Left Bar (upper 8 bits) */
469 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB11);
470
471 /* Pixel Number of Start of Right Bar (lower 8 bits) */
472 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB12);
473
474 /* Pixel Number of Start of Right Bar (upper 8 bits) */
475 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB13);
476}
477
478/**
479 * sh_hdmi_audio_infoframe_setup() - Audio InfoFrame of CONTROL PACKET
480 */
481static void sh_hdmi_audio_infoframe_setup(struct sh_hdmi *hdmi)
482{
483 /* Audio InfoFrame */
484 hdmi_write(hdmi, 0x08, HDMI_CTRL_PKT_BUF_INDEX);
485
486 /* Packet Type = 0x84 */
487 hdmi_write(hdmi, 0x84, HDMI_CTRL_PKT_BUF_ACCESS_HB0);
488
489 /* Version Number = 0x01 */
490 hdmi_write(hdmi, 0x01, HDMI_CTRL_PKT_BUF_ACCESS_HB1);
491
492 /* 0 Length = 10 (0x0A) */
493 hdmi_write(hdmi, 0x0A, HDMI_CTRL_PKT_BUF_ACCESS_HB2);
494
495 /* n. a. Checksum */
496 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0);
497
498 /* Audio Channel Count = Refer to Stream Header */
499 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB1);
500
501 /* Refer to Stream Header */
502 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB2);
503
504 /* Format depends on coding type (i.e. CT0...CT3) */
505 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB3);
506
507 /* Speaker Channel Allocation = Front Right + Front Left */
508 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB4);
509
510 /* Level Shift Value = 0 dB, Down - mix is permitted or no information */
511 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB5);
512
513 /* Reserved (0) */
514 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB6);
515 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB7);
516 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB8);
517 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB9);
518 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB10);
519}
520
521/**
522 * sh_hdmi_gamut_metadata_setup() - Gamut Metadata Packet of CONTROL PACKET
523 */
524static void sh_hdmi_gamut_metadata_setup(struct sh_hdmi *hdmi)
525{
526 int i;
527
528 /* Gamut Metadata Packet */
529 hdmi_write(hdmi, 0x04, HDMI_CTRL_PKT_BUF_INDEX);
530
531 /* Packet Type = 0x0A */
532 hdmi_write(hdmi, 0x0A, HDMI_CTRL_PKT_BUF_ACCESS_HB0);
533 /* Gamut Packet is not used, so default value */
534 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB1);
535 /* Gamut Packet is not used, so default value */
536 hdmi_write(hdmi, 0x10, HDMI_CTRL_PKT_BUF_ACCESS_HB2);
537
538 /* GBD bytes 0 through 27 */
539 for (i = 0; i <= 27; i++)
540 /* HDMI_CTRL_PKT_BUF_ACCESS_PB0_63H - PB27_7EH */
541 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0 + i);
542}
543
544/**
545 * sh_hdmi_acp_setup() - Audio Content Protection Packet (ACP)
546 */
547static void sh_hdmi_acp_setup(struct sh_hdmi *hdmi)
548{
549 int i;
550
551 /* Audio Content Protection Packet (ACP) */
552 hdmi_write(hdmi, 0x01, HDMI_CTRL_PKT_BUF_INDEX);
553
554 /* Packet Type = 0x04 */
555 hdmi_write(hdmi, 0x04, HDMI_CTRL_PKT_BUF_ACCESS_HB0);
556 /* ACP_Type */
557 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB1);
558 /* Reserved (0) */
559 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB2);
560
561 /* GBD bytes 0 through 27 */
562 for (i = 0; i <= 27; i++)
563 /* HDMI_CTRL_PKT_BUF_ACCESS_PB0 - PB27 */
564 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0 + i);
565}
566
567/**
568 * sh_hdmi_isrc1_setup() - ISRC1 Packet
569 */
570static void sh_hdmi_isrc1_setup(struct sh_hdmi *hdmi)
571{
572 int i;
573
574 /* ISRC1 Packet */
575 hdmi_write(hdmi, 0x02, HDMI_CTRL_PKT_BUF_INDEX);
576
577 /* Packet Type = 0x05 */
578 hdmi_write(hdmi, 0x05, HDMI_CTRL_PKT_BUF_ACCESS_HB0);
579 /* ISRC_Cont, ISRC_Valid, Reserved (0), ISRC_Status */
580 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB1);
581 /* Reserved (0) */
582 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB2);
583
584 /* PB0 UPC_EAN_ISRC_0-15 */
585 /* Bytes PB16-PB27 shall be set to a value of 0. */
586 for (i = 0; i <= 27; i++)
587 /* HDMI_CTRL_PKT_BUF_ACCESS_PB0 - PB27 */
588 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0 + i);
589}
590
591/**
592 * sh_hdmi_isrc2_setup() - ISRC2 Packet
593 */
594static void sh_hdmi_isrc2_setup(struct sh_hdmi *hdmi)
595{
596 int i;
597
598 /* ISRC2 Packet */
599 hdmi_write(hdmi, 0x03, HDMI_CTRL_PKT_BUF_INDEX);
600
601 /* HB0 Packet Type = 0x06 */
602 hdmi_write(hdmi, 0x06, HDMI_CTRL_PKT_BUF_ACCESS_HB0);
603 /* Reserved (0) */
604 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB1);
605 /* Reserved (0) */
606 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB2);
607
608 /* PB0 UPC_EAN_ISRC_16-31 */
609 /* Bytes PB16-PB27 shall be set to a value of 0. */
610 for (i = 0; i <= 27; i++)
611 /* HDMI_CTRL_PKT_BUF_ACCESS_PB0 - PB27 */
612 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0 + i);
613}
614
615/**
616 * sh_hdmi_configure() - Initialise HDMI for output
617 */
618static void sh_hdmi_configure(struct sh_hdmi *hdmi)
619{
620 /* Configure video format */
621 sh_hdmi_video_config(hdmi);
622
623 /* Configure audio format */
624 sh_hdmi_audio_config(hdmi);
625
626 /* Configure PHY */
627 sh_hdmi_phy_config(hdmi);
628
629 /* Auxiliary Video Information (AVI) InfoFrame */
630 sh_hdmi_avi_infoframe_setup(hdmi);
631
632 /* Audio InfoFrame */
633 sh_hdmi_audio_infoframe_setup(hdmi);
634
635 /* Gamut Metadata packet */
636 sh_hdmi_gamut_metadata_setup(hdmi);
637
638 /* Audio Content Protection (ACP) Packet */
639 sh_hdmi_acp_setup(hdmi);
640
641 /* ISRC1 Packet */
642 sh_hdmi_isrc1_setup(hdmi);
643
644 /* ISRC2 Packet */
645 sh_hdmi_isrc2_setup(hdmi);
646
647 /*
648 * Control packet auto send with VSYNC control: auto send
649 * General control, Gamut metadata, ISRC, and ACP packets
650 */
651 hdmi_write(hdmi, 0x8E, HDMI_CTRL_PKT_AUTO_SEND);
652
653 /* FIXME */
654 msleep(10);
655
656 /* PS mode b->d, reset PLLA and PLLB */
657 hdmi_write(hdmi, 0x4C, HDMI_SYSTEM_CTRL);
658
659 udelay(10);
660
661 hdmi_write(hdmi, 0x40, HDMI_SYSTEM_CTRL);
662}
663
664static void sh_hdmi_read_edid(struct sh_hdmi *hdmi)
665{
666 struct fb_var_screeninfo *var = &hdmi->var;
667 struct sh_mobile_hdmi_info *pdata = hdmi->dev->platform_data;
668 struct fb_videomode *lcd_cfg = &pdata->lcd_chan->lcd_cfg;
669 unsigned long height = var->height, width = var->width;
670 int i;
671 u8 edid[128];
672
673 /* Read EDID */
674 pr_debug("Read back EDID code:");
675 for (i = 0; i < 128; i++) {
676 edid[i] = hdmi_read(hdmi, HDMI_EDID_KSV_FIFO_ACCESS_WINDOW);
677#ifdef DEBUG
678 if ((i % 16) == 0) {
679 printk(KERN_CONT "\n");
680 printk(KERN_DEBUG "%02X | %02X", i, edid[i]);
681 } else {
682 printk(KERN_CONT " %02X", edid[i]);
683 }
684#endif
685 }
686#ifdef DEBUG
687 printk(KERN_CONT "\n");
688#endif
689 fb_parse_edid(edid, var);
690 pr_debug("%u-%u-%u-%u x %u-%u-%u-%u @ %lu kHz monitor detected\n",
691 var->left_margin, var->xres, var->right_margin, var->hsync_len,
692 var->upper_margin, var->yres, var->lower_margin, var->vsync_len,
693 PICOS2KHZ(var->pixclock));
694
695 /* FIXME: Use user-provided configuration instead of EDID */
696 var->width = width;
697 var->xres = lcd_cfg->xres;
698 var->xres_virtual = lcd_cfg->xres;
699 var->left_margin = lcd_cfg->left_margin;
700 var->right_margin = lcd_cfg->right_margin;
701 var->hsync_len = lcd_cfg->hsync_len;
702 var->height = height;
703 var->yres = lcd_cfg->yres;
704 var->yres_virtual = lcd_cfg->yres * 2;
705 var->upper_margin = lcd_cfg->upper_margin;
706 var->lower_margin = lcd_cfg->lower_margin;
707 var->vsync_len = lcd_cfg->vsync_len;
708 var->sync = lcd_cfg->sync;
709 var->pixclock = lcd_cfg->pixclock;
710
711 hdmi_external_video_param(hdmi);
712}
713
714static irqreturn_t sh_hdmi_hotplug(int irq, void *dev_id)
715{
716 struct sh_hdmi *hdmi = dev_id;
717 u8 status1, status2, mask1, mask2;
718
719 /* mode_b and PLLA and PLLB reset */
720 hdmi_write(hdmi, 0x2C, HDMI_SYSTEM_CTRL);
721
722 /* How long shall reset be held? */
723 udelay(10);
724
725 /* mode_b and PLLA and PLLB reset release */
726 hdmi_write(hdmi, 0x20, HDMI_SYSTEM_CTRL);
727
728 status1 = hdmi_read(hdmi, HDMI_INTERRUPT_STATUS_1);
729 status2 = hdmi_read(hdmi, HDMI_INTERRUPT_STATUS_2);
730
731 mask1 = hdmi_read(hdmi, HDMI_INTERRUPT_MASK_1);
732 mask2 = hdmi_read(hdmi, HDMI_INTERRUPT_MASK_2);
733
734 /* Correct would be to ack only set bits, but the datasheet requires 0xff */
735 hdmi_write(hdmi, 0xFF, HDMI_INTERRUPT_STATUS_1);
736 hdmi_write(hdmi, 0xFF, HDMI_INTERRUPT_STATUS_2);
737
738 if (printk_ratelimit())
739 pr_debug("IRQ #%d: Status #1: 0x%x & 0x%x, #2: 0x%x & 0x%x\n",
740 irq, status1, mask1, status2, mask2);
741
742 if (!((status1 & mask1) | (status2 & mask2))) {
743 return IRQ_NONE;
744 } else if (status1 & 0xc0) {
745 u8 msens;
746
747 /* Datasheet specifies 10ms... */
748 udelay(500);
749
750 msens = hdmi_read(hdmi, HDMI_HOT_PLUG_MSENS_STATUS);
751 pr_debug("MSENS 0x%x\n", msens);
752 /* Check, if hot plug & MSENS pin status are both high */
753 if ((msens & 0xC0) == 0xC0) {
754 /* Display plug in */
755 hdmi->hp_state = HDMI_HOTPLUG_CONNECTED;
756
757 /* Set EDID word address */
758 hdmi_write(hdmi, 0x00, HDMI_EDID_WORD_ADDRESS);
759 /* Set EDID segment pointer */
760 hdmi_write(hdmi, 0x00, HDMI_EDID_SEGMENT_POINTER);
761 /* Enable EDID interrupt */
762 hdmi_write(hdmi, 0xC6, HDMI_INTERRUPT_MASK_1);
763 } else if (!(status1 & 0x80)) {
764 /* Display unplug, beware multiple interrupts */
765 if (hdmi->hp_state != HDMI_HOTPLUG_DISCONNECTED)
766 schedule_delayed_work(&hdmi->edid_work, 0);
767
768 hdmi->hp_state = HDMI_HOTPLUG_DISCONNECTED;
769 /* display_off will switch back to mode_a */
770 }
771 } else if (status1 & 2) {
772 /* EDID error interrupt: retry */
773 /* Set EDID word address */
774 hdmi_write(hdmi, 0x00, HDMI_EDID_WORD_ADDRESS);
775 /* Set EDID segment pointer */
776 hdmi_write(hdmi, 0x00, HDMI_EDID_SEGMENT_POINTER);
777 } else if (status1 & 4) {
778 /* Disable EDID interrupt */
779 hdmi_write(hdmi, 0xC0, HDMI_INTERRUPT_MASK_1);
780 hdmi->hp_state = HDMI_HOTPLUG_EDID_DONE;
781 schedule_delayed_work(&hdmi->edid_work, msecs_to_jiffies(10));
782 }
783
784 return IRQ_HANDLED;
785}
786
787static void hdmi_display_on(void *arg, struct fb_info *info)
788{
789 struct sh_hdmi *hdmi = arg;
790 struct sh_mobile_hdmi_info *pdata = hdmi->dev->platform_data;
791
792 if (info->var.xres != 1280 || info->var.yres != 720) {
793 dev_warn(info->device, "Unsupported framebuffer geometry %ux%u\n",
794 info->var.xres, info->var.yres);
795 return;
796 }
797
798 pr_debug("%s(%p): state %x\n", __func__, pdata->lcd_dev, info->state);
799 /*
800 * FIXME: not a good place to store fb_info. And we cannot nullify it
801 * even on monitor disconnect. What should the lifecycle be?
802 */
803 hdmi->info = info;
804 switch (hdmi->hp_state) {
805 case HDMI_HOTPLUG_EDID_DONE:
806 /* PS mode d->e. All functions are active */
807 hdmi_write(hdmi, 0x80, HDMI_SYSTEM_CTRL);
808 pr_debug("HDMI running\n");
809 break;
810 case HDMI_HOTPLUG_DISCONNECTED:
811 info->state = FBINFO_STATE_SUSPENDED;
812 default:
813 hdmi->var = info->var;
814 }
815}
816
817static void hdmi_display_off(void *arg)
818{
819 struct sh_hdmi *hdmi = arg;
820 struct sh_mobile_hdmi_info *pdata = hdmi->dev->platform_data;
821
822 pr_debug("%s(%p)\n", __func__, pdata->lcd_dev);
823 /* PS mode e->a */
824 hdmi_write(hdmi, 0x10, HDMI_SYSTEM_CTRL);
825}
826
827/* Hotplug interrupt occurred, read EDID */
828static void edid_work_fn(struct work_struct *work)
829{
830 struct sh_hdmi *hdmi = container_of(work, struct sh_hdmi, edid_work.work);
831 struct sh_mobile_hdmi_info *pdata = hdmi->dev->platform_data;
832
833 pr_debug("%s(%p): begin, hotplug status %d\n", __func__,
834 pdata->lcd_dev, hdmi->hp_state);
835
836 if (!pdata->lcd_dev)
837 return;
838
839 if (hdmi->hp_state == HDMI_HOTPLUG_EDID_DONE) {
840 pm_runtime_get_sync(hdmi->dev);
841 /* A device has been plugged in */
842 sh_hdmi_read_edid(hdmi);
843 msleep(10);
844 sh_hdmi_configure(hdmi);
845 /* Switched to another (d) power-save mode */
846 msleep(10);
847
848 if (!hdmi->info)
849 return;
850
851 acquire_console_sem();
852
853 /* HDMI plug in */
854 hdmi->info->var = hdmi->var;
855 if (hdmi->info->state != FBINFO_STATE_RUNNING)
856 fb_set_suspend(hdmi->info, 0);
857 else
858 hdmi_display_on(hdmi, hdmi->info);
859
860 release_console_sem();
861 } else {
862 if (!hdmi->info)
863 return;
864
865 acquire_console_sem();
866
867 /* HDMI disconnect */
868 fb_set_suspend(hdmi->info, 1);
869
870 release_console_sem();
871 pm_runtime_put(hdmi->dev);
872 }
873
874 pr_debug("%s(%p): end\n", __func__, pdata->lcd_dev);
875}
876
877static int __init sh_hdmi_probe(struct platform_device *pdev)
878{
879 struct sh_mobile_hdmi_info *pdata = pdev->dev.platform_data;
880 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
881 int irq = platform_get_irq(pdev, 0), ret;
882 struct sh_hdmi *hdmi;
883 long rate;
884
885 if (!res || !pdata || irq < 0)
886 return -ENODEV;
887
888 hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL);
889 if (!hdmi) {
890 dev_err(&pdev->dev, "Cannot allocate device data\n");
891 return -ENOMEM;
892 }
893
894 hdmi->dev = &pdev->dev;
895
896 hdmi->hdmi_clk = clk_get(&pdev->dev, "ick");
897 if (IS_ERR(hdmi->hdmi_clk)) {
898 ret = PTR_ERR(hdmi->hdmi_clk);
899 dev_err(&pdev->dev, "Unable to get clock: %d\n", ret);
900 goto egetclk;
901 }
902
903 rate = PICOS2KHZ(pdata->lcd_chan->lcd_cfg.pixclock) * 1000;
904
905 rate = clk_round_rate(hdmi->hdmi_clk, rate);
906 if (rate < 0) {
907 ret = rate;
908 dev_err(&pdev->dev, "Cannot get suitable rate: %ld\n", rate);
909 goto erate;
910 }
911
912 ret = clk_set_rate(hdmi->hdmi_clk, rate);
913 if (ret < 0) {
914 dev_err(&pdev->dev, "Cannot set rate %ld: %d\n", rate, ret);
915 goto erate;
916 }
917
918 pr_debug("HDMI set frequency %lu\n", rate);
919
920 ret = clk_enable(hdmi->hdmi_clk);
921 if (ret < 0) {
922 dev_err(&pdev->dev, "Cannot enable clock: %d\n", ret);
923 goto eclkenable;
924 }
925
926 dev_info(&pdev->dev, "Enabled HDMI clock at %luHz\n", rate);
927
928 if (!request_mem_region(res->start, resource_size(res), dev_name(&pdev->dev))) {
929 dev_err(&pdev->dev, "HDMI register region already claimed\n");
930 ret = -EBUSY;
931 goto ereqreg;
932 }
933
934 hdmi->base = ioremap(res->start, resource_size(res));
935 if (!hdmi->base) {
936 dev_err(&pdev->dev, "HDMI register region already claimed\n");
937 ret = -ENOMEM;
938 goto emap;
939 }
940
941 platform_set_drvdata(pdev, hdmi);
942
943#if 1
944 /* Product and revision IDs are 0 in sh-mobile version */
945 dev_info(&pdev->dev, "Detected HDMI controller 0x%x:0x%x\n",
946 hdmi_read(hdmi, HDMI_PRODUCT_ID), hdmi_read(hdmi, HDMI_REVISION_ID));
947#endif
948
949 /* Set up LCDC callbacks */
950 pdata->lcd_chan->board_cfg.board_data = hdmi;
951 pdata->lcd_chan->board_cfg.display_on = hdmi_display_on;
952 pdata->lcd_chan->board_cfg.display_off = hdmi_display_off;
953
954 INIT_DELAYED_WORK(&hdmi->edid_work, edid_work_fn);
955
956 pm_runtime_enable(&pdev->dev);
957 pm_runtime_resume(&pdev->dev);
958
959 ret = request_irq(irq, sh_hdmi_hotplug, 0,
960 dev_name(&pdev->dev), hdmi);
961 if (ret < 0) {
962 dev_err(&pdev->dev, "Unable to request irq: %d\n", ret);
963 goto ereqirq;
964 }
965
966 return 0;
967
968ereqirq:
969 pm_runtime_disable(&pdev->dev);
970 iounmap(hdmi->base);
971emap:
972 release_mem_region(res->start, resource_size(res));
973ereqreg:
974 clk_disable(hdmi->hdmi_clk);
975eclkenable:
976erate:
977 clk_put(hdmi->hdmi_clk);
978egetclk:
979 kfree(hdmi);
980
981 return ret;
982}
983
984static int __exit sh_hdmi_remove(struct platform_device *pdev)
985{
986 struct sh_mobile_hdmi_info *pdata = pdev->dev.platform_data;
987 struct sh_hdmi *hdmi = platform_get_drvdata(pdev);
988 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
989 int irq = platform_get_irq(pdev, 0);
990
991 pdata->lcd_chan->board_cfg.display_on = NULL;
992 pdata->lcd_chan->board_cfg.display_off = NULL;
993 pdata->lcd_chan->board_cfg.board_data = NULL;
994
995 free_irq(irq, hdmi);
996 pm_runtime_disable(&pdev->dev);
997 cancel_delayed_work_sync(&hdmi->edid_work);
998 clk_disable(hdmi->hdmi_clk);
999 clk_put(hdmi->hdmi_clk);
1000 iounmap(hdmi->base);
1001 release_mem_region(res->start, resource_size(res));
1002 kfree(hdmi);
1003
1004 return 0;
1005}
1006
1007static struct platform_driver sh_hdmi_driver = {
1008 .remove = __exit_p(sh_hdmi_remove),
1009 .driver = {
1010 .name = "sh-mobile-hdmi",
1011 },
1012};
1013
1014static int __init sh_hdmi_init(void)
1015{
1016 return platform_driver_probe(&sh_hdmi_driver, sh_hdmi_probe);
1017}
1018module_init(sh_hdmi_init);
1019
1020static void __exit sh_hdmi_exit(void)
1021{
1022 platform_driver_unregister(&sh_hdmi_driver);
1023}
1024module_exit(sh_hdmi_exit);
1025
1026MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
1027MODULE_DESCRIPTION("SuperH / ARM-shmobile HDMI driver");
1028MODULE_LICENSE("GPL v2");
diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
index 12c451a711e9..d72075a9f01c 100644
--- a/drivers/video/sh_mobile_lcdcfb.c
+++ b/drivers/video/sh_mobile_lcdcfb.c
@@ -56,6 +56,7 @@ static int lcdc_shared_regs[] = {
56/* per-channel registers */ 56/* per-channel registers */
57enum { LDDCKPAT1R, LDDCKPAT2R, LDMT1R, LDMT2R, LDMT3R, LDDFR, LDSM1R, 57enum { LDDCKPAT1R, LDDCKPAT2R, LDMT1R, LDMT2R, LDMT3R, LDDFR, LDSM1R,
58 LDSM2R, LDSA1R, LDMLSR, LDHCNR, LDHSYNR, LDVLNR, LDVSYNR, LDPMR, 58 LDSM2R, LDSA1R, LDMLSR, LDHCNR, LDHSYNR, LDVLNR, LDVSYNR, LDPMR,
59 LDHAJR,
59 NR_CH_REGS }; 60 NR_CH_REGS };
60 61
61static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = { 62static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = {
@@ -74,6 +75,7 @@ static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = {
74 [LDVLNR] = 0x450, 75 [LDVLNR] = 0x450,
75 [LDVSYNR] = 0x454, 76 [LDVSYNR] = 0x454,
76 [LDPMR] = 0x460, 77 [LDPMR] = 0x460,
78 [LDHAJR] = 0x4a0,
77}; 79};
78 80
79static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = { 81static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = {
@@ -137,6 +139,7 @@ struct sh_mobile_lcdc_priv {
137 struct clk *dot_clk; 139 struct clk *dot_clk;
138 unsigned long lddckr; 140 unsigned long lddckr;
139 struct sh_mobile_lcdc_chan ch[2]; 141 struct sh_mobile_lcdc_chan ch[2];
142 struct notifier_block notifier;
140 unsigned long saved_shared_regs[NR_SHARED_REGS]; 143 unsigned long saved_shared_regs[NR_SHARED_REGS];
141 int started; 144 int started;
142}; 145};
@@ -404,6 +407,56 @@ static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
404 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */ 407 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
405} 408}
406 409
410static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch)
411{
412 struct fb_var_screeninfo *var = &ch->info->var;
413 unsigned long h_total, hsync_pos;
414 u32 tmp;
415
416 tmp = ch->ldmt1r_value;
417 tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : 1 << 28;
418 tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : 1 << 27;
419 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? 1 << 26 : 0;
420 tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? 1 << 25 : 0;
421 tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? 1 << 24 : 0;
422 tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? 1 << 17 : 0;
423 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? 1 << 16 : 0;
424 lcdc_write_chan(ch, LDMT1R, tmp);
425
426 /* setup SYS bus */
427 lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
428 lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
429
430 /* horizontal configuration */
431 h_total = var->xres + var->hsync_len +
432 var->left_margin + var->right_margin;
433 tmp = h_total / 8; /* HTCN */
434 tmp |= (var->xres / 8) << 16; /* HDCN */
435 lcdc_write_chan(ch, LDHCNR, tmp);
436
437 hsync_pos = var->xres + var->right_margin;
438 tmp = hsync_pos / 8; /* HSYNP */
439 tmp |= (var->hsync_len / 8) << 16; /* HSYNW */
440 lcdc_write_chan(ch, LDHSYNR, tmp);
441
442 /* vertical configuration */
443 tmp = var->yres + var->vsync_len +
444 var->upper_margin + var->lower_margin; /* VTLN */
445 tmp |= var->yres << 16; /* VDLN */
446 lcdc_write_chan(ch, LDVLNR, tmp);
447
448 tmp = var->yres + var->lower_margin; /* VSYNP */
449 tmp |= var->vsync_len << 16; /* VSYNW */
450 lcdc_write_chan(ch, LDVSYNR, tmp);
451
452 /* Adjust horizontal synchronisation for HDMI */
453 tmp = ((var->xres & 7) << 24) |
454 ((h_total & 7) << 16) |
455 ((var->hsync_len & 7) << 8) |
456 hsync_pos;
457 lcdc_write_chan(ch, LDHAJR, tmp);
458}
459
407static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv) 460static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
408{ 461{
409 struct sh_mobile_lcdc_chan *ch; 462 struct sh_mobile_lcdc_chan *ch;
@@ -470,49 +523,11 @@ static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
470 if (!ch->enabled) 523 if (!ch->enabled)
471 continue; 524 continue;
472 525
473 tmp = ch->ldmt1r_value; 526 sh_mobile_lcdc_geometry(ch);
474 tmp |= (lcd_cfg->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : 1 << 28;
475 tmp |= (lcd_cfg->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : 1 << 27;
476 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? 1 << 26 : 0;
477 tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? 1 << 25 : 0;
478 tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? 1 << 24 : 0;
479 tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? 1 << 17 : 0;
480 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? 1 << 16 : 0;
481 lcdc_write_chan(ch, LDMT1R, tmp);
482
483 /* setup SYS bus */
484 lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
485 lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
486
487 /* horizontal configuration */
488 tmp = lcd_cfg->xres + lcd_cfg->hsync_len;
489 tmp += lcd_cfg->left_margin;
490 tmp += lcd_cfg->right_margin;
491 tmp /= 8; /* HTCN */
492 tmp |= (lcd_cfg->xres / 8) << 16; /* HDCN */
493 lcdc_write_chan(ch, LDHCNR, tmp);
494
495 tmp = lcd_cfg->xres;
496 tmp += lcd_cfg->right_margin;
497 tmp /= 8; /* HSYNP */
498 tmp |= (lcd_cfg->hsync_len / 8) << 16; /* HSYNW */
499 lcdc_write_chan(ch, LDHSYNR, tmp);
500 527
501 /* power supply */ 528 /* power supply */
502 lcdc_write_chan(ch, LDPMR, 0); 529 lcdc_write_chan(ch, LDPMR, 0);
503 530
504 /* vertical configuration */
505 tmp = lcd_cfg->yres + lcd_cfg->vsync_len;
506 tmp += lcd_cfg->upper_margin;
507 tmp += lcd_cfg->lower_margin; /* VTLN */
508 tmp |= lcd_cfg->yres << 16; /* VDLN */
509 lcdc_write_chan(ch, LDVLNR, tmp);
510
511 tmp = lcd_cfg->yres;
512 tmp += lcd_cfg->lower_margin; /* VSYNP */
513 tmp |= lcd_cfg->vsync_len << 16; /* VSYNW */
514 lcdc_write_chan(ch, LDVSYNR, tmp);
515
516 board_cfg = &ch->cfg.board_cfg; 531 board_cfg = &ch->cfg.board_cfg;
517 if (board_cfg->setup_sys) 532 if (board_cfg->setup_sys)
518 ret = board_cfg->setup_sys(board_cfg->board_data, ch, 533 ret = board_cfg->setup_sys(board_cfg->board_data, ch,
@@ -577,7 +592,7 @@ static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
577 592
578 board_cfg = &ch->cfg.board_cfg; 593 board_cfg = &ch->cfg.board_cfg;
579 if (board_cfg->display_on) 594 if (board_cfg->display_on)
580 board_cfg->display_on(board_cfg->board_data); 595 board_cfg->display_on(board_cfg->board_data, ch->info);
581 } 596 }
582 597
583 return 0; 598 return 0;
@@ -943,6 +958,62 @@ static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
943 .runtime_resume = sh_mobile_lcdc_runtime_resume, 958 .runtime_resume = sh_mobile_lcdc_runtime_resume,
944}; 959};
945 960
961static int sh_mobile_lcdc_notify(struct notifier_block *nb,
962 unsigned long action, void *data)
963{
964 struct fb_event *event = data;
965 struct fb_info *info = event->info;
966 struct sh_mobile_lcdc_chan *ch = info->par;
967 struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg;
968 struct fb_var_screeninfo *var;
969
970 if (&ch->lcdc->notifier != nb)
971 return 0;
972
973 dev_dbg(info->dev, "%s(): action = %lu, data = %p\n",
974 __func__, action, event->data);
975
976 switch(action) {
977 case FB_EVENT_SUSPEND:
978 if (board_cfg->display_off)
979 board_cfg->display_off(board_cfg->board_data);
980 pm_runtime_put(info->device);
981 break;
982 case FB_EVENT_RESUME:
983 var = &info->var;
984
985 /* HDMI must be enabled before LCDC configuration */
986 if (board_cfg->display_on)
987 board_cfg->display_on(board_cfg->board_data, ch->info);
988
989 /* Check if the new display is not in our modelist */
990 if (ch->info->modelist.next &&
991 !fb_match_mode(var, &ch->info->modelist)) {
992 struct fb_videomode mode;
993 int ret;
994
995 /* Can we handle this display? */
996 if (var->xres > ch->cfg.lcd_cfg.xres ||
997 var->yres > ch->cfg.lcd_cfg.yres)
998 return -ENOMEM;
999
1000 /* Add to the modelist */
1001 fb_var_to_videomode(&mode, var);
1002 ret = fb_add_videomode(&mode, &ch->info->modelist);
1003 if (ret < 0)
1004 return ret;
1005 }
1006
1007 pm_runtime_get_sync(info->device);
1008
1009 sh_mobile_lcdc_geometry(ch);
1010
1011 break;
1012 }
1013
1014 return 0;
1015}
1016
946static int sh_mobile_lcdc_remove(struct platform_device *pdev); 1017static int sh_mobile_lcdc_remove(struct platform_device *pdev);
947 1018
948static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev) 1019static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
@@ -1020,15 +1091,19 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1020 goto err1; 1091 goto err1;
1021 } 1092 }
1022 1093
1094 priv->base = ioremap_nocache(res->start, resource_size(res));
1095 if (!priv->base)
1096 goto err1;
1097
1023 error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv); 1098 error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv);
1024 if (error) { 1099 if (error) {
1025 dev_err(&pdev->dev, "unable to setup clocks\n"); 1100 dev_err(&pdev->dev, "unable to setup clocks\n");
1026 goto err1; 1101 goto err1;
1027 } 1102 }
1028 1103
1029 priv->base = ioremap_nocache(res->start, (res->end - res->start) + 1);
1030
1031 for (i = 0; i < j; i++) { 1104 for (i = 0; i < j; i++) {
1105 struct fb_var_screeninfo *var;
1106 struct fb_videomode *lcd_cfg;
1032 cfg = &priv->ch[i].cfg; 1107 cfg = &priv->ch[i].cfg;
1033 1108
1034 priv->ch[i].info = framebuffer_alloc(0, &pdev->dev); 1109 priv->ch[i].info = framebuffer_alloc(0, &pdev->dev);
@@ -1039,22 +1114,33 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1039 } 1114 }
1040 1115
1041 info = priv->ch[i].info; 1116 info = priv->ch[i].info;
1117 var = &info->var;
1118 lcd_cfg = &cfg->lcd_cfg;
1042 info->fbops = &sh_mobile_lcdc_ops; 1119 info->fbops = &sh_mobile_lcdc_ops;
1043 info->var.xres = info->var.xres_virtual = cfg->lcd_cfg.xres; 1120 var->xres = var->xres_virtual = lcd_cfg->xres;
1044 info->var.yres = cfg->lcd_cfg.yres; 1121 var->yres = lcd_cfg->yres;
1045 /* Default Y virtual resolution is 2x panel size */ 1122 /* Default Y virtual resolution is 2x panel size */
1046 info->var.yres_virtual = info->var.yres * 2; 1123 var->yres_virtual = var->yres * 2;
1047 info->var.width = cfg->lcd_size_cfg.width; 1124 var->width = cfg->lcd_size_cfg.width;
1048 info->var.height = cfg->lcd_size_cfg.height; 1125 var->height = cfg->lcd_size_cfg.height;
1049 info->var.activate = FB_ACTIVATE_NOW; 1126 var->activate = FB_ACTIVATE_NOW;
1050 error = sh_mobile_lcdc_set_bpp(&info->var, cfg->bpp); 1127 var->left_margin = lcd_cfg->left_margin;
1128 var->right_margin = lcd_cfg->right_margin;
1129 var->upper_margin = lcd_cfg->upper_margin;
1130 var->lower_margin = lcd_cfg->lower_margin;
1131 var->hsync_len = lcd_cfg->hsync_len;
1132 var->vsync_len = lcd_cfg->vsync_len;
1133 var->sync = lcd_cfg->sync;
1134 var->pixclock = lcd_cfg->pixclock;
1135
1136 error = sh_mobile_lcdc_set_bpp(var, cfg->bpp);
1051 if (error) 1137 if (error)
1052 break; 1138 break;
1053 1139
1054 info->fix = sh_mobile_lcdc_fix; 1140 info->fix = sh_mobile_lcdc_fix;
1055 info->fix.line_length = cfg->lcd_cfg.xres * (cfg->bpp / 8); 1141 info->fix.line_length = lcd_cfg->xres * (cfg->bpp / 8);
1056 info->fix.smem_len = info->fix.line_length * 1142 info->fix.smem_len = info->fix.line_length *
1057 info->var.yres_virtual; 1143 var->yres_virtual;
1058 1144
1059 buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len, 1145 buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
1060 &priv->ch[i].dma_handle, GFP_KERNEL); 1146 &priv->ch[i].dma_handle, GFP_KERNEL);
@@ -1119,10 +1205,14 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1119 ch->cfg.bpp); 1205 ch->cfg.bpp);
1120 1206
1121 /* deferred io mode: disable clock to save power */ 1207 /* deferred io mode: disable clock to save power */
1122 if (info->fbdefio) 1208 if (info->fbdefio || info->state == FBINFO_STATE_SUSPENDED)
1123 sh_mobile_lcdc_clk_off(priv); 1209 sh_mobile_lcdc_clk_off(priv);
1124 } 1210 }
1125 1211
1212 /* Failure ignored */
1213 priv->notifier.notifier_call = sh_mobile_lcdc_notify;
1214 fb_register_client(&priv->notifier);
1215
1126 return 0; 1216 return 0;
1127err1: 1217err1:
1128 sh_mobile_lcdc_remove(pdev); 1218 sh_mobile_lcdc_remove(pdev);
@@ -1136,6 +1226,8 @@ static int sh_mobile_lcdc_remove(struct platform_device *pdev)
1136 struct fb_info *info; 1226 struct fb_info *info;
1137 int i; 1227 int i;
1138 1228
1229 fb_unregister_client(&priv->notifier);
1230
1139 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) 1231 for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
1140 if (priv->ch[i].info && priv->ch[i].info->dev) 1232 if (priv->ch[i].info && priv->ch[i].info->dev)
1141 unregister_framebuffer(priv->ch[i].info); 1233 unregister_framebuffer(priv->ch[i].info);
diff --git a/drivers/video/sunxvr1000.c b/drivers/video/sunxvr1000.c
index 7288934c0d49..5dbe06af2226 100644
--- a/drivers/video/sunxvr1000.c
+++ b/drivers/video/sunxvr1000.c
@@ -111,7 +111,7 @@ static int __devinit gfb_set_fbinfo(struct gfb_info *gp)
111 return 0; 111 return 0;
112} 112}
113 113
114static int __devinit gfb_probe(struct of_device *op, 114static int __devinit gfb_probe(struct platform_device *op,
115 const struct of_device_id *match) 115 const struct of_device_id *match)
116{ 116{
117 struct device_node *dp = op->dev.of_node; 117 struct device_node *dp = op->dev.of_node;
@@ -172,7 +172,7 @@ err_out:
172 return err; 172 return err;
173} 173}
174 174
175static int __devexit gfb_remove(struct of_device *op) 175static int __devexit gfb_remove(struct platform_device *op)
176{ 176{
177 struct fb_info *info = dev_get_drvdata(&op->dev); 177 struct fb_info *info = dev_get_drvdata(&op->dev);
178 struct gfb_info *gp = info->par; 178 struct gfb_info *gp = info->par;
diff --git a/drivers/video/tcx.c b/drivers/video/tcx.c
index f375e0db6776..77ad27955cf0 100644
--- a/drivers/video/tcx.c
+++ b/drivers/video/tcx.c
@@ -342,7 +342,7 @@ tcx_init_fix(struct fb_info *info, int linebytes)
342 info->fix.accel = FB_ACCEL_SUN_TCX; 342 info->fix.accel = FB_ACCEL_SUN_TCX;
343} 343}
344 344
345static void tcx_unmap_regs(struct of_device *op, struct fb_info *info, 345static void tcx_unmap_regs(struct platform_device *op, struct fb_info *info,
346 struct tcx_par *par) 346 struct tcx_par *par)
347{ 347{
348 if (par->tec) 348 if (par->tec)
@@ -362,7 +362,7 @@ static void tcx_unmap_regs(struct of_device *op, struct fb_info *info,
362 info->screen_base, info->fix.smem_len); 362 info->screen_base, info->fix.smem_len);
363} 363}
364 364
365static int __devinit tcx_probe(struct of_device *op, 365static int __devinit tcx_probe(struct platform_device *op,
366 const struct of_device_id *match) 366 const struct of_device_id *match)
367{ 367{
368 struct device_node *dp = op->dev.of_node; 368 struct device_node *dp = op->dev.of_node;
@@ -486,7 +486,7 @@ out_err:
486 return err; 486 return err;
487} 487}
488 488
489static int __devexit tcx_remove(struct of_device *op) 489static int __devexit tcx_remove(struct platform_device *op)
490{ 490{
491 struct fb_info *info = dev_get_drvdata(&op->dev); 491 struct fb_info *info = dev_get_drvdata(&op->dev);
492 struct tcx_par *par = info->par; 492 struct tcx_par *par = info->par;
diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
index 7b8839ebf3c4..52ec0959d462 100644
--- a/drivers/video/uvesafb.c
+++ b/drivers/video/uvesafb.c
@@ -1977,8 +1977,7 @@ static void __devexit uvesafb_exit(void)
1977 1977
1978module_exit(uvesafb_exit); 1978module_exit(uvesafb_exit);
1979 1979
1980#define param_get_scroll NULL 1980static int param_set_scroll(const char *val, const struct kernel_param *kp)
1981static int param_set_scroll(const char *val, struct kernel_param *kp)
1982{ 1981{
1983 ypan = 0; 1982 ypan = 0;
1984 1983
@@ -1993,7 +1992,9 @@ static int param_set_scroll(const char *val, struct kernel_param *kp)
1993 1992
1994 return 0; 1993 return 0;
1995} 1994}
1996 1995static struct kernel_param_ops param_ops_scroll = {
1996 .set = param_set_scroll,
1997};
1997#define param_check_scroll(name, p) __param_check(name, p, void) 1998#define param_check_scroll(name, p) __param_check(name, p, void)
1998 1999
1999module_param_named(scroll, ypan, scroll, 0); 2000module_param_named(scroll, ypan, scroll, 0);
diff --git a/drivers/video/vt8623fb.c b/drivers/video/vt8623fb.c
index d31dc96f838a..85d76ec4c63e 100644
--- a/drivers/video/vt8623fb.c
+++ b/drivers/video/vt8623fb.c
@@ -726,7 +726,9 @@ static int __devinit vt8623_pci_probe(struct pci_dev *dev, const struct pci_devi
726 726
727 /* Prepare startup mode */ 727 /* Prepare startup mode */
728 728
729 kparam_block_sysfs_write(mode_option);
729 rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8); 730 rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8);
731 kparam_unblock_sysfs_write(mode_option);
730 if (! ((rc == 1) || (rc == 2))) { 732 if (! ((rc == 1) || (rc == 2))) {
731 rc = -EINVAL; 733 rc = -EINVAL;
732 dev_err(info->device, "mode %s not found\n", mode_option); 734 dev_err(info->device, "mode %s not found\n", mode_option);
diff --git a/drivers/video/xilinxfb.c b/drivers/video/xilinxfb.c
index 29b5daacc217..0c9ce88e95e8 100644
--- a/drivers/video/xilinxfb.c
+++ b/drivers/video/xilinxfb.c
@@ -397,7 +397,7 @@ static int xilinxfb_release(struct device *dev)
397 */ 397 */
398 398
399static int __devinit 399static int __devinit
400xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match) 400xilinxfb_of_probe(struct platform_device *op, const struct of_device_id *match)
401{ 401{
402 const u32 *prop; 402 const u32 *prop;
403 u32 *p; 403 u32 *p;
@@ -477,7 +477,7 @@ xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match)
477 return -ENODEV; 477 return -ENODEV;
478} 478}
479 479
480static int __devexit xilinxfb_of_remove(struct of_device *op) 480static int __devexit xilinxfb_of_remove(struct platform_device *op)
481{ 481{
482 return xilinxfb_release(&op->dev); 482 return xilinxfb_release(&op->dev);
483} 483}
diff --git a/drivers/watchdog/cpwd.c b/drivers/watchdog/cpwd.c
index 30a2512fd52e..566343b3c131 100644
--- a/drivers/watchdog/cpwd.c
+++ b/drivers/watchdog/cpwd.c
@@ -526,7 +526,7 @@ static const struct file_operations cpwd_fops = {
526 .release = cpwd_release, 526 .release = cpwd_release,
527}; 527};
528 528
529static int __devinit cpwd_probe(struct of_device *op, 529static int __devinit cpwd_probe(struct platform_device *op,
530 const struct of_device_id *match) 530 const struct of_device_id *match)
531{ 531{
532 struct device_node *options; 532 struct device_node *options;
@@ -639,7 +639,7 @@ out_free:
639 goto out; 639 goto out;
640} 640}
641 641
642static int __devexit cpwd_remove(struct of_device *op) 642static int __devexit cpwd_remove(struct platform_device *op)
643{ 643{
644 struct cpwd *p = dev_get_drvdata(&op->dev); 644 struct cpwd *p = dev_get_drvdata(&op->dev);
645 int i; 645 int i;
diff --git a/drivers/watchdog/gef_wdt.c b/drivers/watchdog/gef_wdt.c
index 1df284f9c2a1..9c21d19043a6 100644
--- a/drivers/watchdog/gef_wdt.c
+++ b/drivers/watchdog/gef_wdt.c
@@ -260,7 +260,7 @@ static struct miscdevice gef_wdt_miscdev = {
260}; 260};
261 261
262 262
263static int __devinit gef_wdt_probe(struct of_device *dev, 263static int __devinit gef_wdt_probe(struct platform_device *dev,
264 const struct of_device_id *match) 264 const struct of_device_id *match)
265{ 265{
266 int timeout = 10; 266 int timeout = 10;
diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
index 4cda64dd309c..8fa213cdb499 100644
--- a/drivers/watchdog/mpc8xxx_wdt.c
+++ b/drivers/watchdog/mpc8xxx_wdt.c
@@ -185,7 +185,7 @@ static struct miscdevice mpc8xxx_wdt_miscdev = {
185 .fops = &mpc8xxx_wdt_fops, 185 .fops = &mpc8xxx_wdt_fops,
186}; 186};
187 187
188static int __devinit mpc8xxx_wdt_probe(struct of_device *ofdev, 188static int __devinit mpc8xxx_wdt_probe(struct platform_device *ofdev,
189 const struct of_device_id *match) 189 const struct of_device_id *match)
190{ 190{
191 int ret; 191 int ret;
@@ -238,7 +238,7 @@ err_unmap:
238 return ret; 238 return ret;
239} 239}
240 240
241static int __devexit mpc8xxx_wdt_remove(struct of_device *ofdev) 241static int __devexit mpc8xxx_wdt_remove(struct platform_device *ofdev)
242{ 242{
243 mpc8xxx_wdt_pr_warn("watchdog removed"); 243 mpc8xxx_wdt_pr_warn("watchdog removed");
244 del_timer_sync(&wdt_timer); 244 del_timer_sync(&wdt_timer);
diff --git a/drivers/watchdog/riowd.c b/drivers/watchdog/riowd.c
index 4082b4ace1fc..3faee1ae64bd 100644
--- a/drivers/watchdog/riowd.c
+++ b/drivers/watchdog/riowd.c
@@ -172,7 +172,7 @@ static struct miscdevice riowd_miscdev = {
172 .fops = &riowd_fops 172 .fops = &riowd_fops
173}; 173};
174 174
175static int __devinit riowd_probe(struct of_device *op, 175static int __devinit riowd_probe(struct platform_device *op,
176 const struct of_device_id *match) 176 const struct of_device_id *match)
177{ 177{
178 struct riowd *p; 178 struct riowd *p;
@@ -219,7 +219,7 @@ out:
219 return err; 219 return err;
220} 220}
221 221
222static int __devexit riowd_remove(struct of_device *op) 222static int __devexit riowd_remove(struct platform_device *op)
223{ 223{
224 struct riowd *p = dev_get_drvdata(&op->dev); 224 struct riowd *p = dev_get_drvdata(&op->dev);
225 225
diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig
index 0a8826936639..60d71e9abe9f 100644
--- a/drivers/xen/Kconfig
+++ b/drivers/xen/Kconfig
@@ -71,4 +71,9 @@ config XEN_PLATFORM_PCI
71 initializing xenbus and grant_table when running in a Xen HVM 71 initializing xenbus and grant_table when running in a Xen HVM
72 domain. As a consequence this driver is required to run any Xen PV 72 domain. As a consequence this driver is required to run any Xen PV
73 frontend on Xen HVM. 73 frontend on Xen HVM.
74
75config SWIOTLB_XEN
76 def_bool y
77 depends on SWIOTLB
78
74endmenu 79endmenu
diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index e392fb776af3..fcaf838f54be 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_XEN_DEV_EVTCHN) += evtchn.o
11obj-$(CONFIG_XENFS) += xenfs/ 11obj-$(CONFIG_XENFS) += xenfs/
12obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o 12obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o
13obj-$(CONFIG_XEN_PLATFORM_PCI) += platform-pci.o 13obj-$(CONFIG_XEN_PLATFORM_PCI) += platform-pci.o
14obj-$(CONFIG_SWIOTLB_XEN) += swiotlb-xen.o
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 1a0d8c2a0354..500290b150bb 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -85,13 +85,6 @@ static struct sys_device balloon_sysdev;
85 85
86static int register_balloon(struct sys_device *sysdev); 86static int register_balloon(struct sys_device *sysdev);
87 87
88/*
89 * Protects atomic reservation decrease/increase against concurrent increases.
90 * Also protects non-atomic updates of current_pages and driver_pages, and
91 * balloon lists.
92 */
93static DEFINE_SPINLOCK(balloon_lock);
94
95static struct balloon_stats balloon_stats; 88static struct balloon_stats balloon_stats;
96 89
97/* We increase/decrease in batches which fit in a page */ 90/* We increase/decrease in batches which fit in a page */
@@ -210,7 +203,7 @@ static int increase_reservation(unsigned long nr_pages)
210 if (nr_pages > ARRAY_SIZE(frame_list)) 203 if (nr_pages > ARRAY_SIZE(frame_list))
211 nr_pages = ARRAY_SIZE(frame_list); 204 nr_pages = ARRAY_SIZE(frame_list);
212 205
213 spin_lock_irqsave(&balloon_lock, flags); 206 spin_lock_irqsave(&xen_reservation_lock, flags);
214 207
215 page = balloon_first_page(); 208 page = balloon_first_page();
216 for (i = 0; i < nr_pages; i++) { 209 for (i = 0; i < nr_pages; i++) {
@@ -254,7 +247,7 @@ static int increase_reservation(unsigned long nr_pages)
254 balloon_stats.current_pages += rc; 247 balloon_stats.current_pages += rc;
255 248
256 out: 249 out:
257 spin_unlock_irqrestore(&balloon_lock, flags); 250 spin_unlock_irqrestore(&xen_reservation_lock, flags);
258 251
259 return rc < 0 ? rc : rc != nr_pages; 252 return rc < 0 ? rc : rc != nr_pages;
260} 253}
@@ -299,7 +292,7 @@ static int decrease_reservation(unsigned long nr_pages)
299 kmap_flush_unused(); 292 kmap_flush_unused();
300 flush_tlb_all(); 293 flush_tlb_all();
301 294
302 spin_lock_irqsave(&balloon_lock, flags); 295 spin_lock_irqsave(&xen_reservation_lock, flags);
303 296
304 /* No more mappings: invalidate P2M and add to balloon. */ 297 /* No more mappings: invalidate P2M and add to balloon. */
305 for (i = 0; i < nr_pages; i++) { 298 for (i = 0; i < nr_pages; i++) {
@@ -315,7 +308,7 @@ static int decrease_reservation(unsigned long nr_pages)
315 308
316 balloon_stats.current_pages -= nr_pages; 309 balloon_stats.current_pages -= nr_pages;
317 310
318 spin_unlock_irqrestore(&balloon_lock, flags); 311 spin_unlock_irqrestore(&xen_reservation_lock, flags);
319 312
320 return need_sleep; 313 return need_sleep;
321} 314}
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
new file mode 100644
index 000000000000..54469c3eeacd
--- /dev/null
+++ b/drivers/xen/swiotlb-xen.c
@@ -0,0 +1,515 @@
1/*
2 * Copyright 2010
3 * by Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
4 *
5 * This code provides a IOMMU for Xen PV guests with PCI passthrough.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License v2.0 as published by
9 * the Free Software Foundation
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * PV guests under Xen are running in an non-contiguous memory architecture.
17 *
18 * When PCI pass-through is utilized, this necessitates an IOMMU for
19 * translating bus (DMA) to virtual and vice-versa and also providing a
20 * mechanism to have contiguous pages for device drivers operations (say DMA
21 * operations).
22 *
23 * Specifically, under Xen the Linux idea of pages is an illusion. It
24 * assumes that pages start at zero and go up to the available memory. To
25 * help with that, the Linux Xen MMU provides a lookup mechanism to
26 * translate the page frame numbers (PFN) to machine frame numbers (MFN)
27 * and vice-versa. The MFN are the "real" frame numbers. Furthermore
28 * memory is not contiguous. Xen hypervisor stitches memory for guests
29 * from different pools, which means there is no guarantee that PFN==MFN
30 * and PFN+1==MFN+1. Lastly with Xen 4.0, pages (in debug mode) are
31 * allocated in descending order (high to low), meaning the guest might
32 * never get any MFN's under the 4GB mark.
33 *
34 */
35
36#include <linux/bootmem.h>
37#include <linux/dma-mapping.h>
38#include <xen/swiotlb-xen.h>
39#include <xen/page.h>
40#include <xen/xen-ops.h>
41/*
42 * Used to do a quick range check in swiotlb_tbl_unmap_single and
43 * swiotlb_tbl_sync_single_*, to see if the memory was in fact allocated by this
44 * API.
45 */
46
47static char *xen_io_tlb_start, *xen_io_tlb_end;
48static unsigned long xen_io_tlb_nslabs;
49/*
50 * Quick lookup value of the bus address of the IOTLB.
51 */
52
53u64 start_dma_addr;
54
55static dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
56{
57 return phys_to_machine(XPADDR(paddr)).maddr;;
58}
59
60static phys_addr_t xen_bus_to_phys(dma_addr_t baddr)
61{
62 return machine_to_phys(XMADDR(baddr)).paddr;
63}
64
65static dma_addr_t xen_virt_to_bus(void *address)
66{
67 return xen_phys_to_bus(virt_to_phys(address));
68}
69
70static int check_pages_physically_contiguous(unsigned long pfn,
71 unsigned int offset,
72 size_t length)
73{
74 unsigned long next_mfn;
75 int i;
76 int nr_pages;
77
78 next_mfn = pfn_to_mfn(pfn);
79 nr_pages = (offset + length + PAGE_SIZE-1) >> PAGE_SHIFT;
80
81 for (i = 1; i < nr_pages; i++) {
82 if (pfn_to_mfn(++pfn) != ++next_mfn)
83 return 0;
84 }
85 return 1;
86}
87
88static int range_straddles_page_boundary(phys_addr_t p, size_t size)
89{
90 unsigned long pfn = PFN_DOWN(p);
91 unsigned int offset = p & ~PAGE_MASK;
92
93 if (offset + size <= PAGE_SIZE)
94 return 0;
95 if (check_pages_physically_contiguous(pfn, offset, size))
96 return 0;
97 return 1;
98}
99
100static int is_xen_swiotlb_buffer(dma_addr_t dma_addr)
101{
102 unsigned long mfn = PFN_DOWN(dma_addr);
103 unsigned long pfn = mfn_to_local_pfn(mfn);
104 phys_addr_t paddr;
105
106 /* If the address is outside our domain, it CAN
107 * have the same virtual address as another address
108 * in our domain. Therefore _only_ check address within our domain.
109 */
110 if (pfn_valid(pfn)) {
111 paddr = PFN_PHYS(pfn);
112 return paddr >= virt_to_phys(xen_io_tlb_start) &&
113 paddr < virt_to_phys(xen_io_tlb_end);
114 }
115 return 0;
116}
117
118static int max_dma_bits = 32;
119
120static int
121xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
122{
123 int i, rc;
124 int dma_bits;
125
126 dma_bits = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT) + PAGE_SHIFT;
127
128 i = 0;
129 do {
130 int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE);
131
132 do {
133 rc = xen_create_contiguous_region(
134 (unsigned long)buf + (i << IO_TLB_SHIFT),
135 get_order(slabs << IO_TLB_SHIFT),
136 dma_bits);
137 } while (rc && dma_bits++ < max_dma_bits);
138 if (rc)
139 return rc;
140
141 i += slabs;
142 } while (i < nslabs);
143 return 0;
144}
145
146void __init xen_swiotlb_init(int verbose)
147{
148 unsigned long bytes;
149 int rc;
150
151 xen_io_tlb_nslabs = (64 * 1024 * 1024 >> IO_TLB_SHIFT);
152 xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, IO_TLB_SEGSIZE);
153
154 bytes = xen_io_tlb_nslabs << IO_TLB_SHIFT;
155
156 /*
157 * Get IO TLB memory from any location.
158 */
159 xen_io_tlb_start = alloc_bootmem(bytes);
160 if (!xen_io_tlb_start)
161 panic("Cannot allocate SWIOTLB buffer");
162
163 xen_io_tlb_end = xen_io_tlb_start + bytes;
164 /*
165 * And replace that memory with pages under 4GB.
166 */
167 rc = xen_swiotlb_fixup(xen_io_tlb_start,
168 bytes,
169 xen_io_tlb_nslabs);
170 if (rc)
171 goto error;
172
173 start_dma_addr = xen_virt_to_bus(xen_io_tlb_start);
174 swiotlb_init_with_tbl(xen_io_tlb_start, xen_io_tlb_nslabs, verbose);
175
176 return;
177error:
178 panic("DMA(%d): Failed to exchange pages allocated for DMA with Xen! "\
179 "We either don't have the permission or you do not have enough"\
180 "free memory under 4GB!\n", rc);
181}
182
183void *
184xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
185 dma_addr_t *dma_handle, gfp_t flags)
186{
187 void *ret;
188 int order = get_order(size);
189 u64 dma_mask = DMA_BIT_MASK(32);
190 unsigned long vstart;
191
192 /*
193 * Ignore region specifiers - the kernel's ideas of
194 * pseudo-phys memory layout has nothing to do with the
195 * machine physical layout. We can't allocate highmem
196 * because we can't return a pointer to it.
197 */
198 flags &= ~(__GFP_DMA | __GFP_HIGHMEM);
199
200 if (dma_alloc_from_coherent(hwdev, size, dma_handle, &ret))
201 return ret;
202
203 vstart = __get_free_pages(flags, order);
204 ret = (void *)vstart;
205
206 if (hwdev && hwdev->coherent_dma_mask)
207 dma_mask = dma_alloc_coherent_mask(hwdev, flags);
208
209 if (ret) {
210 if (xen_create_contiguous_region(vstart, order,
211 fls64(dma_mask)) != 0) {
212 free_pages(vstart, order);
213 return NULL;
214 }
215 memset(ret, 0, size);
216 *dma_handle = virt_to_machine(ret).maddr;
217 }
218 return ret;
219}
220EXPORT_SYMBOL_GPL(xen_swiotlb_alloc_coherent);
221
222void
223xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
224 dma_addr_t dev_addr)
225{
226 int order = get_order(size);
227
228 if (dma_release_from_coherent(hwdev, order, vaddr))
229 return;
230
231 xen_destroy_contiguous_region((unsigned long)vaddr, order);
232 free_pages((unsigned long)vaddr, order);
233}
234EXPORT_SYMBOL_GPL(xen_swiotlb_free_coherent);
235
236
237/*
238 * Map a single buffer of the indicated size for DMA in streaming mode. The
239 * physical address to use is returned.
240 *
241 * Once the device is given the dma address, the device owns this memory until
242 * either xen_swiotlb_unmap_page or xen_swiotlb_dma_sync_single is performed.
243 */
244dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
245 unsigned long offset, size_t size,
246 enum dma_data_direction dir,
247 struct dma_attrs *attrs)
248{
249 phys_addr_t phys = page_to_phys(page) + offset;
250 dma_addr_t dev_addr = xen_phys_to_bus(phys);
251 void *map;
252
253 BUG_ON(dir == DMA_NONE);
254 /*
255 * If the address happens to be in the device's DMA window,
256 * we can safely return the device addr and not worry about bounce
257 * buffering it.
258 */
259 if (dma_capable(dev, dev_addr, size) &&
260 !range_straddles_page_boundary(phys, size) && !swiotlb_force)
261 return dev_addr;
262
263 /*
264 * Oh well, have to allocate and map a bounce buffer.
265 */
266 map = swiotlb_tbl_map_single(dev, start_dma_addr, phys, size, dir);
267 if (!map)
268 return DMA_ERROR_CODE;
269
270 dev_addr = xen_virt_to_bus(map);
271
272 /*
273 * Ensure that the address returned is DMA'ble
274 */
275 if (!dma_capable(dev, dev_addr, size))
276 panic("map_single: bounce buffer is not DMA'ble");
277
278 return dev_addr;
279}
280EXPORT_SYMBOL_GPL(xen_swiotlb_map_page);
281
282/*
283 * Unmap a single streaming mode DMA translation. The dma_addr and size must
284 * match what was provided for in a previous xen_swiotlb_map_page call. All
285 * other usages are undefined.
286 *
287 * After this call, reads by the cpu to the buffer are guaranteed to see
288 * whatever the device wrote there.
289 */
290static void xen_unmap_single(struct device *hwdev, dma_addr_t dev_addr,
291 size_t size, enum dma_data_direction dir)
292{
293 phys_addr_t paddr = xen_bus_to_phys(dev_addr);
294
295 BUG_ON(dir == DMA_NONE);
296
297 /* NOTE: We use dev_addr here, not paddr! */
298 if (is_xen_swiotlb_buffer(dev_addr)) {
299 swiotlb_tbl_unmap_single(hwdev, phys_to_virt(paddr), size, dir);
300 return;
301 }
302
303 if (dir != DMA_FROM_DEVICE)
304 return;
305
306 /*
307 * phys_to_virt doesn't work with hihgmem page but we could
308 * call dma_mark_clean() with hihgmem page here. However, we
309 * are fine since dma_mark_clean() is null on POWERPC. We can
310 * make dma_mark_clean() take a physical address if necessary.
311 */
312 dma_mark_clean(phys_to_virt(paddr), size);
313}
314
315void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr,
316 size_t size, enum dma_data_direction dir,
317 struct dma_attrs *attrs)
318{
319 xen_unmap_single(hwdev, dev_addr, size, dir);
320}
321EXPORT_SYMBOL_GPL(xen_swiotlb_unmap_page);
322
323/*
324 * Make physical memory consistent for a single streaming mode DMA translation
325 * after a transfer.
326 *
327 * If you perform a xen_swiotlb_map_page() but wish to interrogate the buffer
328 * using the cpu, yet do not wish to teardown the dma mapping, you must
329 * call this function before doing so. At the next point you give the dma
330 * address back to the card, you must first perform a
331 * xen_swiotlb_dma_sync_for_device, and then the device again owns the buffer
332 */
333static void
334xen_swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr,
335 size_t size, enum dma_data_direction dir,
336 enum dma_sync_target target)
337{
338 phys_addr_t paddr = xen_bus_to_phys(dev_addr);
339
340 BUG_ON(dir == DMA_NONE);
341
342 /* NOTE: We use dev_addr here, not paddr! */
343 if (is_xen_swiotlb_buffer(dev_addr)) {
344 swiotlb_tbl_sync_single(hwdev, phys_to_virt(paddr), size, dir,
345 target);
346 return;
347 }
348
349 if (dir != DMA_FROM_DEVICE)
350 return;
351
352 dma_mark_clean(phys_to_virt(paddr), size);
353}
354
355void
356xen_swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
357 size_t size, enum dma_data_direction dir)
358{
359 xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_CPU);
360}
361EXPORT_SYMBOL_GPL(xen_swiotlb_sync_single_for_cpu);
362
363void
364xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
365 size_t size, enum dma_data_direction dir)
366{
367 xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_DEVICE);
368}
369EXPORT_SYMBOL_GPL(xen_swiotlb_sync_single_for_device);
370
371/*
372 * Map a set of buffers described by scatterlist in streaming mode for DMA.
373 * This is the scatter-gather version of the above xen_swiotlb_map_page
374 * interface. Here the scatter gather list elements are each tagged with the
375 * appropriate dma address and length. They are obtained via
376 * sg_dma_{address,length}(SG).
377 *
378 * NOTE: An implementation may be able to use a smaller number of
379 * DMA address/length pairs than there are SG table elements.
380 * (for example via virtual mapping capabilities)
381 * The routine returns the number of addr/length pairs actually
382 * used, at most nents.
383 *
384 * Device ownership issues as mentioned above for xen_swiotlb_map_page are the
385 * same here.
386 */
387int
388xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
389 int nelems, enum dma_data_direction dir,
390 struct dma_attrs *attrs)
391{
392 struct scatterlist *sg;
393 int i;
394
395 BUG_ON(dir == DMA_NONE);
396
397 for_each_sg(sgl, sg, nelems, i) {
398 phys_addr_t paddr = sg_phys(sg);
399 dma_addr_t dev_addr = xen_phys_to_bus(paddr);
400
401 if (swiotlb_force ||
402 !dma_capable(hwdev, dev_addr, sg->length) ||
403 range_straddles_page_boundary(paddr, sg->length)) {
404 void *map = swiotlb_tbl_map_single(hwdev,
405 start_dma_addr,
406 sg_phys(sg),
407 sg->length, dir);
408 if (!map) {
409 /* Don't panic here, we expect map_sg users
410 to do proper error handling. */
411 xen_swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir,
412 attrs);
413 sgl[0].dma_length = 0;
414 return DMA_ERROR_CODE;
415 }
416 sg->dma_address = xen_virt_to_bus(map);
417 } else
418 sg->dma_address = dev_addr;
419 sg->dma_length = sg->length;
420 }
421 return nelems;
422}
423EXPORT_SYMBOL_GPL(xen_swiotlb_map_sg_attrs);
424
425int
426xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems,
427 enum dma_data_direction dir)
428{
429 return xen_swiotlb_map_sg_attrs(hwdev, sgl, nelems, dir, NULL);
430}
431EXPORT_SYMBOL_GPL(xen_swiotlb_map_sg);
432
433/*
434 * Unmap a set of streaming mode DMA translations. Again, cpu read rules
435 * concerning calls here are the same as for swiotlb_unmap_page() above.
436 */
437void
438xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
439 int nelems, enum dma_data_direction dir,
440 struct dma_attrs *attrs)
441{
442 struct scatterlist *sg;
443 int i;
444
445 BUG_ON(dir == DMA_NONE);
446
447 for_each_sg(sgl, sg, nelems, i)
448 xen_unmap_single(hwdev, sg->dma_address, sg->dma_length, dir);
449
450}
451EXPORT_SYMBOL_GPL(xen_swiotlb_unmap_sg_attrs);
452
453void
454xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems,
455 enum dma_data_direction dir)
456{
457 return xen_swiotlb_unmap_sg_attrs(hwdev, sgl, nelems, dir, NULL);
458}
459EXPORT_SYMBOL_GPL(xen_swiotlb_unmap_sg);
460
461/*
462 * Make physical memory consistent for a set of streaming mode DMA translations
463 * after a transfer.
464 *
465 * The same as swiotlb_sync_single_* but for a scatter-gather list, same rules
466 * and usage.
467 */
468static void
469xen_swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl,
470 int nelems, enum dma_data_direction dir,
471 enum dma_sync_target target)
472{
473 struct scatterlist *sg;
474 int i;
475
476 for_each_sg(sgl, sg, nelems, i)
477 xen_swiotlb_sync_single(hwdev, sg->dma_address,
478 sg->dma_length, dir, target);
479}
480
481void
482xen_swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
483 int nelems, enum dma_data_direction dir)
484{
485 xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_CPU);
486}
487EXPORT_SYMBOL_GPL(xen_swiotlb_sync_sg_for_cpu);
488
489void
490xen_swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
491 int nelems, enum dma_data_direction dir)
492{
493 xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_DEVICE);
494}
495EXPORT_SYMBOL_GPL(xen_swiotlb_sync_sg_for_device);
496
497int
498xen_swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr)
499{
500 return !dma_addr;
501}
502EXPORT_SYMBOL_GPL(xen_swiotlb_dma_mapping_error);
503
504/*
505 * Return whether the given device DMA address mask can be supported
506 * properly. For example, if your device can only drive the low 24-bits
507 * during bus mastering, then you would pass 0x00ffffff as the mask to
508 * this function.
509 */
510int
511xen_swiotlb_dma_supported(struct device *hwdev, u64 mask)
512{
513 return xen_virt_to_bus(xen_io_tlb_end - 1) <= mask;
514}
515EXPORT_SYMBOL_GPL(xen_swiotlb_dma_supported);
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index d97c34a24f7a..c7c23eab9440 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -1263,10 +1263,19 @@ static int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
1263 return PTR_ERR(fid); 1263 return PTR_ERR(fid);
1264 1264
1265 retval = p9_client_setattr(fid, &p9attr); 1265 retval = p9_client_setattr(fid, &p9attr);
1266 if (retval >= 0) 1266 if (retval < 0)
1267 retval = inode_setattr(dentry->d_inode, iattr); 1267 return retval;
1268 1268
1269 return retval; 1269 if ((iattr->ia_valid & ATTR_SIZE) &&
1270 iattr->ia_size != i_size_read(dentry->d_inode)) {
1271 retval = vmtruncate(dentry->d_inode, iattr->ia_size);
1272 if (retval)
1273 return retval;
1274 }
1275
1276 setattr_copy(dentry->d_inode, iattr);
1277 mark_inode_dirty(dentry->d_inode);
1278 return 0;
1270} 1279}
1271 1280
1272/** 1281/**
diff --git a/fs/afs/cell.c b/fs/afs/cell.c
index ffea35c63879..0d5eeadf6121 100644
--- a/fs/afs/cell.c
+++ b/fs/afs/cell.c
@@ -31,21 +31,20 @@ static struct afs_cell *afs_cell_root;
31 * allocate a cell record and fill in its name, VL server address list and 31 * allocate a cell record and fill in its name, VL server address list and
32 * allocate an anonymous key 32 * allocate an anonymous key
33 */ 33 */
34static struct afs_cell *afs_cell_alloc(const char *name, char *vllist) 34static struct afs_cell *afs_cell_alloc(const char *name, unsigned namelen,
35 char *vllist)
35{ 36{
36 struct afs_cell *cell; 37 struct afs_cell *cell;
37 struct key *key; 38 struct key *key;
38 size_t namelen;
39 char keyname[4 + AFS_MAXCELLNAME + 1], *cp, *dp, *next; 39 char keyname[4 + AFS_MAXCELLNAME + 1], *cp, *dp, *next;
40 char *dvllist = NULL, *_vllist = NULL; 40 char *dvllist = NULL, *_vllist = NULL;
41 char delimiter = ':'; 41 char delimiter = ':';
42 int ret; 42 int ret;
43 43
44 _enter("%s,%s", name, vllist); 44 _enter("%*.*s,%s", namelen, namelen, name ?: "", vllist);
45 45
46 BUG_ON(!name); /* TODO: want to look up "this cell" in the cache */ 46 BUG_ON(!name); /* TODO: want to look up "this cell" in the cache */
47 47
48 namelen = strlen(name);
49 if (namelen > AFS_MAXCELLNAME) { 48 if (namelen > AFS_MAXCELLNAME) {
50 _leave(" = -ENAMETOOLONG"); 49 _leave(" = -ENAMETOOLONG");
51 return ERR_PTR(-ENAMETOOLONG); 50 return ERR_PTR(-ENAMETOOLONG);
@@ -73,6 +72,10 @@ static struct afs_cell *afs_cell_alloc(const char *name, char *vllist)
73 if (!vllist || strlen(vllist) < 7) { 72 if (!vllist || strlen(vllist) < 7) {
74 ret = dns_query("afsdb", name, namelen, "ipv4", &dvllist, NULL); 73 ret = dns_query("afsdb", name, namelen, "ipv4", &dvllist, NULL);
75 if (ret < 0) { 74 if (ret < 0) {
75 if (ret == -ENODATA || ret == -EAGAIN || ret == -ENOKEY)
76 /* translate these errors into something
77 * userspace might understand */
78 ret = -EDESTADDRREQ;
76 _leave(" = %d", ret); 79 _leave(" = %d", ret);
77 return ERR_PTR(ret); 80 return ERR_PTR(ret);
78 } 81 }
@@ -138,26 +141,29 @@ error:
138} 141}
139 142
140/* 143/*
141 * create a cell record 144 * afs_cell_crate() - create a cell record
142 * - "name" is the name of the cell 145 * @name: is the name of the cell.
143 * - "vllist" is a colon separated list of IP addresses in "a.b.c.d" format 146 * @namsesz: is the strlen of the cell name.
147 * @vllist: is a colon separated list of IP addresses in "a.b.c.d" format.
148 * @retref: is T to return the cell reference when the cell exists.
144 */ 149 */
145struct afs_cell *afs_cell_create(const char *name, char *vllist) 150struct afs_cell *afs_cell_create(const char *name, unsigned namesz,
151 char *vllist, bool retref)
146{ 152{
147 struct afs_cell *cell; 153 struct afs_cell *cell;
148 int ret; 154 int ret;
149 155
150 _enter("%s,%s", name, vllist); 156 _enter("%*.*s,%s", namesz, namesz, name ?: "", vllist);
151 157
152 down_write(&afs_cells_sem); 158 down_write(&afs_cells_sem);
153 read_lock(&afs_cells_lock); 159 read_lock(&afs_cells_lock);
154 list_for_each_entry(cell, &afs_cells, link) { 160 list_for_each_entry(cell, &afs_cells, link) {
155 if (strcasecmp(cell->name, name) == 0) 161 if (strncasecmp(cell->name, name, namesz) == 0)
156 goto duplicate_name; 162 goto duplicate_name;
157 } 163 }
158 read_unlock(&afs_cells_lock); 164 read_unlock(&afs_cells_lock);
159 165
160 cell = afs_cell_alloc(name, vllist); 166 cell = afs_cell_alloc(name, namesz, vllist);
161 if (IS_ERR(cell)) { 167 if (IS_ERR(cell)) {
162 _leave(" = %ld", PTR_ERR(cell)); 168 _leave(" = %ld", PTR_ERR(cell));
163 up_write(&afs_cells_sem); 169 up_write(&afs_cells_sem);
@@ -197,8 +203,18 @@ error:
197 return ERR_PTR(ret); 203 return ERR_PTR(ret);
198 204
199duplicate_name: 205duplicate_name:
206 if (retref && !IS_ERR(cell))
207 afs_get_cell(cell);
208
200 read_unlock(&afs_cells_lock); 209 read_unlock(&afs_cells_lock);
201 up_write(&afs_cells_sem); 210 up_write(&afs_cells_sem);
211
212 if (retref) {
213 _leave(" = %p", cell);
214 return cell;
215 }
216
217 _leave(" = -EEXIST");
202 return ERR_PTR(-EEXIST); 218 return ERR_PTR(-EEXIST);
203} 219}
204 220
@@ -229,7 +245,7 @@ int afs_cell_init(char *rootcell)
229 *cp++ = 0; 245 *cp++ = 0;
230 246
231 /* allocate a cell record for the root cell */ 247 /* allocate a cell record for the root cell */
232 new_root = afs_cell_create(rootcell, cp); 248 new_root = afs_cell_create(rootcell, strlen(rootcell), cp, false);
233 if (IS_ERR(new_root)) { 249 if (IS_ERR(new_root)) {
234 _leave(" = %ld", PTR_ERR(new_root)); 250 _leave(" = %ld", PTR_ERR(new_root));
235 return PTR_ERR(new_root); 251 return PTR_ERR(new_root);
@@ -249,11 +265,12 @@ int afs_cell_init(char *rootcell)
249/* 265/*
250 * lookup a cell record 266 * lookup a cell record
251 */ 267 */
252struct afs_cell *afs_cell_lookup(const char *name, unsigned namesz) 268struct afs_cell *afs_cell_lookup(const char *name, unsigned namesz,
269 bool dns_cell)
253{ 270{
254 struct afs_cell *cell; 271 struct afs_cell *cell;
255 272
256 _enter("\"%*.*s\",", namesz, namesz, name ? name : ""); 273 _enter("\"%*.*s\",", namesz, namesz, name ?: "");
257 274
258 down_read(&afs_cells_sem); 275 down_read(&afs_cells_sem);
259 read_lock(&afs_cells_lock); 276 read_lock(&afs_cells_lock);
@@ -267,6 +284,8 @@ struct afs_cell *afs_cell_lookup(const char *name, unsigned namesz)
267 } 284 }
268 } 285 }
269 cell = ERR_PTR(-ENOENT); 286 cell = ERR_PTR(-ENOENT);
287 if (dns_cell)
288 goto create_cell;
270 found: 289 found:
271 ; 290 ;
272 } else { 291 } else {
@@ -289,6 +308,15 @@ struct afs_cell *afs_cell_lookup(const char *name, unsigned namesz)
289 up_read(&afs_cells_sem); 308 up_read(&afs_cells_sem);
290 _leave(" = %p", cell); 309 _leave(" = %p", cell);
291 return cell; 310 return cell;
311
312create_cell:
313 read_unlock(&afs_cells_lock);
314 up_read(&afs_cells_sem);
315
316 cell = afs_cell_create(name, namesz, NULL, true);
317
318 _leave(" = %p", cell);
319 return cell;
292} 320}
293 321
294#if 0 322#if 0
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index b42d5cc1d6d2..0d38c09bd55e 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -477,6 +477,40 @@ static int afs_do_lookup(struct inode *dir, struct dentry *dentry,
477} 477}
478 478
479/* 479/*
480 * Try to auto mount the mountpoint with pseudo directory, if the autocell
481 * operation is setted.
482 */
483static struct inode *afs_try_auto_mntpt(
484 int ret, struct dentry *dentry, struct inode *dir, struct key *key,
485 struct afs_fid *fid)
486{
487 const char *devname = dentry->d_name.name;
488 struct afs_vnode *vnode = AFS_FS_I(dir);
489 struct inode *inode;
490
491 _enter("%d, %p{%s}, {%x:%u}, %p",
492 ret, dentry, devname, vnode->fid.vid, vnode->fid.vnode, key);
493
494 if (ret != -ENOENT ||
495 !test_bit(AFS_VNODE_AUTOCELL, &vnode->flags))
496 goto out;
497
498 inode = afs_iget_autocell(dir, devname, strlen(devname), key);
499 if (IS_ERR(inode)) {
500 ret = PTR_ERR(inode);
501 goto out;
502 }
503
504 *fid = AFS_FS_I(inode)->fid;
505 _leave("= %p", inode);
506 return inode;
507
508out:
509 _leave("= %d", ret);
510 return ERR_PTR(ret);
511}
512
513/*
480 * look up an entry in a directory 514 * look up an entry in a directory
481 */ 515 */
482static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry, 516static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
@@ -520,6 +554,13 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
520 554
521 ret = afs_do_lookup(dir, dentry, &fid, key); 555 ret = afs_do_lookup(dir, dentry, &fid, key);
522 if (ret < 0) { 556 if (ret < 0) {
557 inode = afs_try_auto_mntpt(ret, dentry, dir, key, &fid);
558 if (!IS_ERR(inode)) {
559 key_put(key);
560 goto success;
561 }
562
563 ret = PTR_ERR(inode);
523 key_put(key); 564 key_put(key);
524 if (ret == -ENOENT) { 565 if (ret == -ENOENT) {
525 d_add(dentry, NULL); 566 d_add(dentry, NULL);
@@ -539,6 +580,7 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
539 return ERR_CAST(inode); 580 return ERR_CAST(inode);
540 } 581 }
541 582
583success:
542 dentry->d_op = &afs_fs_dentry_operations; 584 dentry->d_op = &afs_fs_dentry_operations;
543 585
544 d_add(dentry, inode); 586 d_add(dentry, inode);
@@ -696,8 +738,9 @@ static int afs_d_delete(struct dentry *dentry)
696 goto zap; 738 goto zap;
697 739
698 if (dentry->d_inode && 740 if (dentry->d_inode &&
699 test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dentry->d_inode)->flags)) 741 (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dentry->d_inode)->flags) ||
700 goto zap; 742 test_bit(AFS_VNODE_PSEUDODIR, &AFS_FS_I(dentry->d_inode)->flags)))
743 goto zap;
701 744
702 _leave(" = 0 [keep]"); 745 _leave(" = 0 [keep]");
703 return 0; 746 return 0;
diff --git a/fs/afs/inode.c b/fs/afs/inode.c
index 320ffef11574..0747339011c3 100644
--- a/fs/afs/inode.c
+++ b/fs/afs/inode.c
@@ -19,6 +19,8 @@
19#include <linux/fs.h> 19#include <linux/fs.h>
20#include <linux/pagemap.h> 20#include <linux/pagemap.h>
21#include <linux/sched.h> 21#include <linux/sched.h>
22#include <linux/mount.h>
23#include <linux/namei.h>
22#include "internal.h" 24#include "internal.h"
23 25
24struct afs_iget_data { 26struct afs_iget_data {
@@ -102,6 +104,16 @@ static int afs_iget5_test(struct inode *inode, void *opaque)
102} 104}
103 105
104/* 106/*
107 * iget5() comparator for inode created by autocell operations
108 *
109 * These pseudo inodes don't match anything.
110 */
111static int afs_iget5_autocell_test(struct inode *inode, void *opaque)
112{
113 return 0;
114}
115
116/*
105 * iget5() inode initialiser 117 * iget5() inode initialiser
106 */ 118 */
107static int afs_iget5_set(struct inode *inode, void *opaque) 119static int afs_iget5_set(struct inode *inode, void *opaque)
@@ -118,6 +130,67 @@ static int afs_iget5_set(struct inode *inode, void *opaque)
118} 130}
119 131
120/* 132/*
133 * inode retrieval for autocell
134 */
135struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
136 int namesz, struct key *key)
137{
138 struct afs_iget_data data;
139 struct afs_super_info *as;
140 struct afs_vnode *vnode;
141 struct super_block *sb;
142 struct inode *inode;
143 static atomic_t afs_autocell_ino;
144
145 _enter("{%x:%u},%*.*s,",
146 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
147 namesz, namesz, dev_name ?: "");
148
149 sb = dir->i_sb;
150 as = sb->s_fs_info;
151 data.volume = as->volume;
152 data.fid.vid = as->volume->vid;
153 data.fid.unique = 0;
154 data.fid.vnode = 0;
155
156 inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
157 afs_iget5_autocell_test, afs_iget5_set,
158 &data);
159 if (!inode) {
160 _leave(" = -ENOMEM");
161 return ERR_PTR(-ENOMEM);
162 }
163
164 _debug("GOT INODE %p { ino=%lu, vl=%x, vn=%x, u=%x }",
165 inode, inode->i_ino, data.fid.vid, data.fid.vnode,
166 data.fid.unique);
167
168 vnode = AFS_FS_I(inode);
169
170 /* there shouldn't be an existing inode */
171 BUG_ON(!(inode->i_state & I_NEW));
172
173 inode->i_size = 0;
174 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
175 inode->i_op = &afs_autocell_inode_operations;
176 inode->i_nlink = 2;
177 inode->i_uid = 0;
178 inode->i_gid = 0;
179 inode->i_ctime.tv_sec = get_seconds();
180 inode->i_ctime.tv_nsec = 0;
181 inode->i_atime = inode->i_mtime = inode->i_ctime;
182 inode->i_blocks = 0;
183 inode->i_version = 0;
184 inode->i_generation = 0;
185
186 set_bit(AFS_VNODE_PSEUDODIR, &vnode->flags);
187 inode->i_flags |= S_NOATIME;
188 unlock_new_inode(inode);
189 _leave(" = %p", inode);
190 return inode;
191}
192
193/*
121 * inode retrieval 194 * inode retrieval
122 */ 195 */
123struct inode *afs_iget(struct super_block *sb, struct key *key, 196struct inode *afs_iget(struct super_block *sb, struct key *key,
@@ -314,6 +387,19 @@ int afs_getattr(struct vfsmount *mnt, struct dentry *dentry,
314} 387}
315 388
316/* 389/*
390 * discard an AFS inode
391 */
392int afs_drop_inode(struct inode *inode)
393{
394 _enter("");
395
396 if (test_bit(AFS_VNODE_PSEUDODIR, &AFS_FS_I(inode)->flags))
397 return generic_delete_inode(inode);
398 else
399 return generic_drop_inode(inode);
400}
401
402/*
317 * clear an AFS inode 403 * clear an AFS inode
318 */ 404 */
319void afs_evict_inode(struct inode *inode) 405void afs_evict_inode(struct inode *inode)
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 8679089ce9a1..cca8eef736fc 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -42,6 +42,7 @@ typedef enum {
42struct afs_mount_params { 42struct afs_mount_params {
43 bool rwpath; /* T if the parent should be considered R/W */ 43 bool rwpath; /* T if the parent should be considered R/W */
44 bool force; /* T to force cell type */ 44 bool force; /* T to force cell type */
45 bool autocell; /* T if set auto mount operation */
45 afs_voltype_t type; /* type of volume requested */ 46 afs_voltype_t type; /* type of volume requested */
46 int volnamesz; /* size of volume name */ 47 int volnamesz; /* size of volume name */
47 const char *volname; /* name of volume to mount */ 48 const char *volname; /* name of volume to mount */
@@ -358,6 +359,8 @@ struct afs_vnode {
358#define AFS_VNODE_READLOCKED 7 /* set if vnode is read-locked on the server */ 359#define AFS_VNODE_READLOCKED 7 /* set if vnode is read-locked on the server */
359#define AFS_VNODE_WRITELOCKED 8 /* set if vnode is write-locked on the server */ 360#define AFS_VNODE_WRITELOCKED 8 /* set if vnode is write-locked on the server */
360#define AFS_VNODE_UNLOCKING 9 /* set if vnode is being unlocked on the server */ 361#define AFS_VNODE_UNLOCKING 9 /* set if vnode is being unlocked on the server */
362#define AFS_VNODE_AUTOCELL 10 /* set if Vnode is an auto mount point */
363#define AFS_VNODE_PSEUDODIR 11 /* set if Vnode is a pseudo directory */
361 364
362 long acl_order; /* ACL check count (callback break count) */ 365 long acl_order; /* ACL check count (callback break count) */
363 366
@@ -468,8 +471,8 @@ extern struct list_head afs_proc_cells;
468 471
469#define afs_get_cell(C) do { atomic_inc(&(C)->usage); } while(0) 472#define afs_get_cell(C) do { atomic_inc(&(C)->usage); } while(0)
470extern int afs_cell_init(char *); 473extern int afs_cell_init(char *);
471extern struct afs_cell *afs_cell_create(const char *, char *); 474extern struct afs_cell *afs_cell_create(const char *, unsigned, char *, bool);
472extern struct afs_cell *afs_cell_lookup(const char *, unsigned); 475extern struct afs_cell *afs_cell_lookup(const char *, unsigned, bool);
473extern struct afs_cell *afs_grab_cell(struct afs_cell *); 476extern struct afs_cell *afs_grab_cell(struct afs_cell *);
474extern void afs_put_cell(struct afs_cell *); 477extern void afs_put_cell(struct afs_cell *);
475extern void afs_cell_purge(void); 478extern void afs_cell_purge(void);
@@ -558,6 +561,8 @@ extern int afs_fs_release_lock(struct afs_server *, struct key *,
558/* 561/*
559 * inode.c 562 * inode.c
560 */ 563 */
564extern struct inode *afs_iget_autocell(struct inode *, const char *, int,
565 struct key *);
561extern struct inode *afs_iget(struct super_block *, struct key *, 566extern struct inode *afs_iget(struct super_block *, struct key *,
562 struct afs_fid *, struct afs_file_status *, 567 struct afs_fid *, struct afs_file_status *,
563 struct afs_callback *); 568 struct afs_callback *);
@@ -566,6 +571,7 @@ extern int afs_validate(struct afs_vnode *, struct key *);
566extern int afs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 571extern int afs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
567extern int afs_setattr(struct dentry *, struct iattr *); 572extern int afs_setattr(struct dentry *, struct iattr *);
568extern void afs_evict_inode(struct inode *); 573extern void afs_evict_inode(struct inode *);
574extern int afs_drop_inode(struct inode *);
569 575
570/* 576/*
571 * main.c 577 * main.c
@@ -581,6 +587,7 @@ extern int afs_abort_to_error(u32);
581 * mntpt.c 587 * mntpt.c
582 */ 588 */
583extern const struct inode_operations afs_mntpt_inode_operations; 589extern const struct inode_operations afs_mntpt_inode_operations;
590extern const struct inode_operations afs_autocell_inode_operations;
584extern const struct file_operations afs_mntpt_file_operations; 591extern const struct file_operations afs_mntpt_file_operations;
585 592
586extern int afs_mntpt_check_symlink(struct afs_vnode *, struct key *); 593extern int afs_mntpt_check_symlink(struct afs_vnode *, struct key *);
@@ -752,12 +759,6 @@ extern unsigned afs_debug;
752#define dbgprintk(FMT,...) \ 759#define dbgprintk(FMT,...) \
753 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 760 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
754 761
755/* make sure we maintain the format strings, even when debugging is disabled */
756static inline __attribute__((format(printf,1,2)))
757void _dbprintk(const char *fmt, ...)
758{
759}
760
761#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 762#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
762#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 763#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
763#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 764#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
@@ -792,9 +793,9 @@ do { \
792} while (0) 793} while (0)
793 794
794#else 795#else
795#define _enter(FMT,...) _dbprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 796#define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
796#define _leave(FMT,...) _dbprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 797#define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
797#define _debug(FMT,...) _dbprintk(" "FMT ,##__VA_ARGS__) 798#define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
798#endif 799#endif
799 800
800/* 801/*
diff --git a/fs/afs/mntpt.c b/fs/afs/mntpt.c
index a9e23039ea34..6d552686c498 100644
--- a/fs/afs/mntpt.c
+++ b/fs/afs/mntpt.c
@@ -38,6 +38,11 @@ const struct inode_operations afs_mntpt_inode_operations = {
38 .getattr = afs_getattr, 38 .getattr = afs_getattr,
39}; 39};
40 40
41const struct inode_operations afs_autocell_inode_operations = {
42 .follow_link = afs_mntpt_follow_link,
43 .getattr = afs_getattr,
44};
45
41static LIST_HEAD(afs_vfsmounts); 46static LIST_HEAD(afs_vfsmounts);
42static DECLARE_DELAYED_WORK(afs_mntpt_expiry_timer, afs_mntpt_expiry_timed_out); 47static DECLARE_DELAYED_WORK(afs_mntpt_expiry_timer, afs_mntpt_expiry_timed_out);
43 48
@@ -136,20 +141,16 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
136{ 141{
137 struct afs_super_info *super; 142 struct afs_super_info *super;
138 struct vfsmount *mnt; 143 struct vfsmount *mnt;
144 struct afs_vnode *vnode;
139 struct page *page; 145 struct page *page;
140 size_t size; 146 char *devname, *options;
141 char *buf, *devname, *options; 147 bool rwpath = false;
142 int ret; 148 int ret;
143 149
144 _enter("{%s}", mntpt->d_name.name); 150 _enter("{%s}", mntpt->d_name.name);
145 151
146 BUG_ON(!mntpt->d_inode); 152 BUG_ON(!mntpt->d_inode);
147 153
148 ret = -EINVAL;
149 size = mntpt->d_inode->i_size;
150 if (size > PAGE_SIZE - 1)
151 goto error_no_devname;
152
153 ret = -ENOMEM; 154 ret = -ENOMEM;
154 devname = (char *) get_zeroed_page(GFP_KERNEL); 155 devname = (char *) get_zeroed_page(GFP_KERNEL);
155 if (!devname) 156 if (!devname)
@@ -159,28 +160,59 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
159 if (!options) 160 if (!options)
160 goto error_no_options; 161 goto error_no_options;
161 162
162 /* read the contents of the AFS special symlink */ 163 vnode = AFS_FS_I(mntpt->d_inode);
163 page = read_mapping_page(mntpt->d_inode->i_mapping, 0, NULL); 164 if (test_bit(AFS_VNODE_PSEUDODIR, &vnode->flags)) {
164 if (IS_ERR(page)) { 165 /* if the directory is a pseudo directory, use the d_name */
165 ret = PTR_ERR(page); 166 static const char afs_root_cell[] = ":root.cell.";
166 goto error_no_page; 167 unsigned size = mntpt->d_name.len;
168
169 ret = -ENOENT;
170 if (size < 2 || size > AFS_MAXCELLNAME)
171 goto error_no_page;
172
173 if (mntpt->d_name.name[0] == '.') {
174 devname[0] = '#';
175 memcpy(devname + 1, mntpt->d_name.name, size - 1);
176 memcpy(devname + size, afs_root_cell,
177 sizeof(afs_root_cell));
178 rwpath = true;
179 } else {
180 devname[0] = '%';
181 memcpy(devname + 1, mntpt->d_name.name, size);
182 memcpy(devname + size + 1, afs_root_cell,
183 sizeof(afs_root_cell));
184 }
185 } else {
186 /* read the contents of the AFS special symlink */
187 loff_t size = i_size_read(mntpt->d_inode);
188 char *buf;
189
190 ret = -EINVAL;
191 if (size > PAGE_SIZE - 1)
192 goto error_no_page;
193
194 page = read_mapping_page(mntpt->d_inode->i_mapping, 0, NULL);
195 if (IS_ERR(page)) {
196 ret = PTR_ERR(page);
197 goto error_no_page;
198 }
199
200 ret = -EIO;
201 if (PageError(page))
202 goto error;
203
204 buf = kmap_atomic(page, KM_USER0);
205 memcpy(devname, buf, size);
206 kunmap_atomic(buf, KM_USER0);
207 page_cache_release(page);
208 page = NULL;
167 } 209 }
168 210
169 ret = -EIO;
170 if (PageError(page))
171 goto error;
172
173 buf = kmap_atomic(page, KM_USER0);
174 memcpy(devname, buf, size);
175 kunmap_atomic(buf, KM_USER0);
176 page_cache_release(page);
177 page = NULL;
178
179 /* work out what options we want */ 211 /* work out what options we want */
180 super = AFS_FS_S(mntpt->d_sb); 212 super = AFS_FS_S(mntpt->d_sb);
181 memcpy(options, "cell=", 5); 213 memcpy(options, "cell=", 5);
182 strcpy(options + 5, super->volume->cell->name); 214 strcpy(options + 5, super->volume->cell->name);
183 if (super->volume->type == AFSVL_RWVOL) 215 if (super->volume->type == AFSVL_RWVOL || rwpath)
184 strcat(options, ",rwpath"); 216 strcat(options, ",rwpath");
185 217
186 /* try and do the mount */ 218 /* try and do the mount */
diff --git a/fs/afs/proc.c b/fs/afs/proc.c
index 852739d262a9..096b23f821a1 100644
--- a/fs/afs/proc.c
+++ b/fs/afs/proc.c
@@ -294,7 +294,7 @@ static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf,
294 if (strcmp(kbuf, "add") == 0) { 294 if (strcmp(kbuf, "add") == 0) {
295 struct afs_cell *cell; 295 struct afs_cell *cell;
296 296
297 cell = afs_cell_create(name, args); 297 cell = afs_cell_create(name, strlen(name), args, false);
298 if (IS_ERR(cell)) { 298 if (IS_ERR(cell)) {
299 ret = PTR_ERR(cell); 299 ret = PTR_ERR(cell);
300 goto done; 300 goto done;
diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c
index 67cf810e0fd6..654d8fdbf01f 100644
--- a/fs/afs/rxrpc.c
+++ b/fs/afs/rxrpc.c
@@ -100,6 +100,7 @@ int afs_open_socket(void)
100 ret = kernel_bind(socket, (struct sockaddr *) &srx, sizeof(srx)); 100 ret = kernel_bind(socket, (struct sockaddr *) &srx, sizeof(srx));
101 if (ret < 0) { 101 if (ret < 0) {
102 sock_release(socket); 102 sock_release(socket);
103 destroy_workqueue(afs_async_calls);
103 _leave(" = %d [bind]", ret); 104 _leave(" = %d [bind]", ret);
104 return ret; 105 return ret;
105 } 106 }
diff --git a/fs/afs/super.c b/fs/afs/super.c
index 9cf80f02da16..77e1e5a61154 100644
--- a/fs/afs/super.c
+++ b/fs/afs/super.c
@@ -16,6 +16,7 @@
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/mount.h>
19#include <linux/init.h> 20#include <linux/init.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21#include <linux/smp_lock.h> 22#include <linux/smp_lock.h>
@@ -48,6 +49,7 @@ struct file_system_type afs_fs_type = {
48static const struct super_operations afs_super_ops = { 49static const struct super_operations afs_super_ops = {
49 .statfs = afs_statfs, 50 .statfs = afs_statfs,
50 .alloc_inode = afs_alloc_inode, 51 .alloc_inode = afs_alloc_inode,
52 .drop_inode = afs_drop_inode,
51 .destroy_inode = afs_destroy_inode, 53 .destroy_inode = afs_destroy_inode,
52 .evict_inode = afs_evict_inode, 54 .evict_inode = afs_evict_inode,
53 .put_super = afs_put_super, 55 .put_super = afs_put_super,
@@ -62,12 +64,14 @@ enum {
62 afs_opt_cell, 64 afs_opt_cell,
63 afs_opt_rwpath, 65 afs_opt_rwpath,
64 afs_opt_vol, 66 afs_opt_vol,
67 afs_opt_autocell,
65}; 68};
66 69
67static const match_table_t afs_options_list = { 70static const match_table_t afs_options_list = {
68 { afs_opt_cell, "cell=%s" }, 71 { afs_opt_cell, "cell=%s" },
69 { afs_opt_rwpath, "rwpath" }, 72 { afs_opt_rwpath, "rwpath" },
70 { afs_opt_vol, "vol=%s" }, 73 { afs_opt_vol, "vol=%s" },
74 { afs_opt_autocell, "autocell" },
71 { afs_no_opt, NULL }, 75 { afs_no_opt, NULL },
72}; 76};
73 77
@@ -151,7 +155,8 @@ static int afs_parse_options(struct afs_mount_params *params,
151 switch (token) { 155 switch (token) {
152 case afs_opt_cell: 156 case afs_opt_cell:
153 cell = afs_cell_lookup(args[0].from, 157 cell = afs_cell_lookup(args[0].from,
154 args[0].to - args[0].from); 158 args[0].to - args[0].from,
159 false);
155 if (IS_ERR(cell)) 160 if (IS_ERR(cell))
156 return PTR_ERR(cell); 161 return PTR_ERR(cell);
157 afs_put_cell(params->cell); 162 afs_put_cell(params->cell);
@@ -166,6 +171,10 @@ static int afs_parse_options(struct afs_mount_params *params,
166 *devname = args[0].from; 171 *devname = args[0].from;
167 break; 172 break;
168 173
174 case afs_opt_autocell:
175 params->autocell = 1;
176 break;
177
169 default: 178 default:
170 printk(KERN_ERR "kAFS:" 179 printk(KERN_ERR "kAFS:"
171 " Unknown or invalid mount option: '%s'\n", p); 180 " Unknown or invalid mount option: '%s'\n", p);
@@ -252,10 +261,10 @@ static int afs_parse_device_name(struct afs_mount_params *params,
252 261
253 /* lookup the cell record */ 262 /* lookup the cell record */
254 if (cellname || !params->cell) { 263 if (cellname || !params->cell) {
255 cell = afs_cell_lookup(cellname, cellnamesz); 264 cell = afs_cell_lookup(cellname, cellnamesz, true);
256 if (IS_ERR(cell)) { 265 if (IS_ERR(cell)) {
257 printk(KERN_ERR "kAFS: unable to lookup cell '%s'\n", 266 printk(KERN_ERR "kAFS: unable to lookup cell '%*.*s'\n",
258 cellname ?: ""); 267 cellnamesz, cellnamesz, cellname ?: "");
259 return PTR_ERR(cell); 268 return PTR_ERR(cell);
260 } 269 }
261 afs_put_cell(params->cell); 270 afs_put_cell(params->cell);
@@ -321,6 +330,9 @@ static int afs_fill_super(struct super_block *sb, void *data)
321 if (IS_ERR(inode)) 330 if (IS_ERR(inode))
322 goto error_inode; 331 goto error_inode;
323 332
333 if (params->autocell)
334 set_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(inode)->flags);
335
324 ret = -ENOMEM; 336 ret = -ENOMEM;
325 root = d_alloc_root(inode); 337 root = d_alloc_root(inode);
326 if (!root) 338 if (!root)
diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
index 48e056e70fd6..cb1bd38dc08c 100644
--- a/fs/autofs4/root.c
+++ b/fs/autofs4/root.c
@@ -204,8 +204,7 @@ static int try_to_fill_dentry(struct dentry *dentry, int flags)
204 } 204 }
205 205
206 /* Initialize expiry counter after successful mount */ 206 /* Initialize expiry counter after successful mount */
207 if (ino) 207 ino->last_used = jiffies;
208 ino->last_used = jiffies;
209 208
210 spin_lock(&sbi->fs_lock); 209 spin_lock(&sbi->fs_lock);
211 ino->flags &= ~AUTOFS_INF_PENDING; 210 ino->flags &= ~AUTOFS_INF_PENDING;
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 66411463b734..50e8c8582faa 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1340,10 +1340,12 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
1340 /* 1340 /*
1341 * hooks: /n/, see "layering violations". 1341 * hooks: /n/, see "layering violations".
1342 */ 1342 */
1343 ret = devcgroup_inode_permission(bdev->bd_inode, perm); 1343 if (!for_part) {
1344 if (ret != 0) { 1344 ret = devcgroup_inode_permission(bdev->bd_inode, perm);
1345 bdput(bdev); 1345 if (ret != 0) {
1346 return ret; 1346 bdput(bdev);
1347 return ret;
1348 }
1347 } 1349 }
1348 1350
1349 restart: 1351 restart:
diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
index 24eb0d37241a..727caedcdd92 100644
--- a/fs/cachefiles/daemon.c
+++ b/fs/cachefiles/daemon.c
@@ -552,8 +552,7 @@ static int cachefiles_daemon_tag(struct cachefiles_cache *cache, char *args)
552 */ 552 */
553static int cachefiles_daemon_cull(struct cachefiles_cache *cache, char *args) 553static int cachefiles_daemon_cull(struct cachefiles_cache *cache, char *args)
554{ 554{
555 struct fs_struct *fs; 555 struct path path;
556 struct dentry *dir;
557 const struct cred *saved_cred; 556 const struct cred *saved_cred;
558 int ret; 557 int ret;
559 558
@@ -573,24 +572,21 @@ static int cachefiles_daemon_cull(struct cachefiles_cache *cache, char *args)
573 } 572 }
574 573
575 /* extract the directory dentry from the cwd */ 574 /* extract the directory dentry from the cwd */
576 fs = current->fs; 575 get_fs_pwd(current->fs, &path);
577 read_lock(&fs->lock);
578 dir = dget(fs->pwd.dentry);
579 read_unlock(&fs->lock);
580 576
581 if (!S_ISDIR(dir->d_inode->i_mode)) 577 if (!S_ISDIR(path.dentry->d_inode->i_mode))
582 goto notdir; 578 goto notdir;
583 579
584 cachefiles_begin_secure(cache, &saved_cred); 580 cachefiles_begin_secure(cache, &saved_cred);
585 ret = cachefiles_cull(cache, dir, args); 581 ret = cachefiles_cull(cache, path.dentry, args);
586 cachefiles_end_secure(cache, saved_cred); 582 cachefiles_end_secure(cache, saved_cred);
587 583
588 dput(dir); 584 path_put(&path);
589 _leave(" = %d", ret); 585 _leave(" = %d", ret);
590 return ret; 586 return ret;
591 587
592notdir: 588notdir:
593 dput(dir); 589 path_put(&path);
594 kerror("cull command requires dirfd to be a directory"); 590 kerror("cull command requires dirfd to be a directory");
595 return -ENOTDIR; 591 return -ENOTDIR;
596 592
@@ -628,8 +624,7 @@ inval:
628 */ 624 */
629static int cachefiles_daemon_inuse(struct cachefiles_cache *cache, char *args) 625static int cachefiles_daemon_inuse(struct cachefiles_cache *cache, char *args)
630{ 626{
631 struct fs_struct *fs; 627 struct path path;
632 struct dentry *dir;
633 const struct cred *saved_cred; 628 const struct cred *saved_cred;
634 int ret; 629 int ret;
635 630
@@ -649,24 +644,21 @@ static int cachefiles_daemon_inuse(struct cachefiles_cache *cache, char *args)
649 } 644 }
650 645
651 /* extract the directory dentry from the cwd */ 646 /* extract the directory dentry from the cwd */
652 fs = current->fs; 647 get_fs_pwd(current->fs, &path);
653 read_lock(&fs->lock);
654 dir = dget(fs->pwd.dentry);
655 read_unlock(&fs->lock);
656 648
657 if (!S_ISDIR(dir->d_inode->i_mode)) 649 if (!S_ISDIR(path.dentry->d_inode->i_mode))
658 goto notdir; 650 goto notdir;
659 651
660 cachefiles_begin_secure(cache, &saved_cred); 652 cachefiles_begin_secure(cache, &saved_cred);
661 ret = cachefiles_check_in_use(cache, dir, args); 653 ret = cachefiles_check_in_use(cache, path.dentry, args);
662 cachefiles_end_secure(cache, saved_cred); 654 cachefiles_end_secure(cache, saved_cred);
663 655
664 dput(dir); 656 path_put(&path);
665 //_leave(" = %d", ret); 657 //_leave(" = %d", ret);
666 return ret; 658 return ret;
667 659
668notdir: 660notdir:
669 dput(dir); 661 path_put(&path);
670 kerror("inuse command requires dirfd to be a directory"); 662 kerror("inuse command requires dirfd to be a directory");
671 return -ENOTDIR; 663 return -ENOTDIR;
672 664
diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
index a8cd821226da..bd6bc1bde2d7 100644
--- a/fs/cachefiles/internal.h
+++ b/fs/cachefiles/internal.h
@@ -267,13 +267,6 @@ do { \
267#define dbgprintk(FMT, ...) \ 267#define dbgprintk(FMT, ...) \
268 printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__) 268 printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
269 269
270/* make sure we maintain the format strings, even when debugging is disabled */
271static inline void _dbprintk(const char *fmt, ...)
272 __attribute__((format(printf, 1, 2)));
273static inline void _dbprintk(const char *fmt, ...)
274{
275}
276
277#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__) 270#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
278#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__) 271#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
279#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__) 272#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
@@ -304,9 +297,9 @@ do { \
304} while (0) 297} while (0)
305 298
306#else 299#else
307#define _enter(FMT, ...) _dbprintk("==> %s("FMT")", __func__, ##__VA_ARGS__) 300#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
308#define _leave(FMT, ...) _dbprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__) 301#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
309#define _debug(FMT, ...) _dbprintk(FMT, ##__VA_ARGS__) 302#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
310#endif 303#endif
311 304
312#if 1 /* defined(__KDEBUGALL) */ 305#if 1 /* defined(__KDEBUGALL) */
diff --git a/fs/ceph/Makefile b/fs/ceph/Makefile
index 6a660e610be8..278e1172600d 100644
--- a/fs/ceph/Makefile
+++ b/fs/ceph/Makefile
@@ -6,7 +6,7 @@ ifneq ($(KERNELRELEASE),)
6 6
7obj-$(CONFIG_CEPH_FS) += ceph.o 7obj-$(CONFIG_CEPH_FS) += ceph.o
8 8
9ceph-objs := super.o inode.o dir.o file.o addr.o ioctl.o \ 9ceph-objs := super.o inode.o dir.o file.o locks.o addr.o ioctl.o \
10 export.o caps.o snap.o xattr.o \ 10 export.o caps.o snap.o xattr.o \
11 messenger.o msgpool.o buffer.o pagelist.o \ 11 messenger.o msgpool.o buffer.o pagelist.o \
12 mds_client.o mdsmap.o \ 12 mds_client.o mdsmap.o \
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index d9c60b84949a..5598a0d02295 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -309,7 +309,8 @@ static int ceph_readpages(struct file *file, struct address_space *mapping,
309 zero_user_segment(page, s, PAGE_CACHE_SIZE); 309 zero_user_segment(page, s, PAGE_CACHE_SIZE);
310 } 310 }
311 311
312 if (add_to_page_cache_lru(page, mapping, page->index, GFP_NOFS)) { 312 if (add_to_page_cache_lru(page, mapping, page->index,
313 GFP_NOFS)) {
313 page_cache_release(page); 314 page_cache_release(page);
314 dout("readpages %p add_to_page_cache failed %p\n", 315 dout("readpages %p add_to_page_cache failed %p\n",
315 inode, page); 316 inode, page);
@@ -552,7 +553,7 @@ static void writepages_finish(struct ceph_osd_request *req,
552 * page truncation thread, possibly losing some data that 553 * page truncation thread, possibly losing some data that
553 * raced its way in 554 * raced its way in
554 */ 555 */
555 if ((issued & CEPH_CAP_FILE_CACHE) == 0) 556 if ((issued & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0)
556 generic_error_remove_page(inode->i_mapping, page); 557 generic_error_remove_page(inode->i_mapping, page);
557 558
558 unlock_page(page); 559 unlock_page(page);
@@ -797,9 +798,12 @@ get_more_pages:
797 dout("%p will write page %p idx %lu\n", 798 dout("%p will write page %p idx %lu\n",
798 inode, page, page->index); 799 inode, page, page->index);
799 800
800 writeback_stat = atomic_long_inc_return(&client->writeback_count); 801 writeback_stat =
801 if (writeback_stat > CONGESTION_ON_THRESH(client->mount_args->congestion_kb)) { 802 atomic_long_inc_return(&client->writeback_count);
802 set_bdi_congested(&client->backing_dev_info, BLK_RW_ASYNC); 803 if (writeback_stat > CONGESTION_ON_THRESH(
804 client->mount_args->congestion_kb)) {
805 set_bdi_congested(&client->backing_dev_info,
806 BLK_RW_ASYNC);
803 } 807 }
804 808
805 set_page_writeback(page); 809 set_page_writeback(page);
@@ -1036,7 +1040,7 @@ static int ceph_write_begin(struct file *file, struct address_space *mapping,
1036 *pagep = page; 1040 *pagep = page;
1037 1041
1038 dout("write_begin file %p inode %p page %p %d~%d\n", file, 1042 dout("write_begin file %p inode %p page %p %d~%d\n", file,
1039 inode, page, (int)pos, (int)len); 1043 inode, page, (int)pos, (int)len);
1040 1044
1041 r = ceph_update_writeable_page(file, pos, len, page); 1045 r = ceph_update_writeable_page(file, pos, len, page);
1042 } while (r == -EAGAIN); 1046 } while (r == -EAGAIN);
diff --git a/fs/ceph/armor.c b/fs/ceph/armor.c
index 67b2c030924b..eb2a666b0be7 100644
--- a/fs/ceph/armor.c
+++ b/fs/ceph/armor.c
@@ -1,11 +1,15 @@
1 1
2#include <linux/errno.h> 2#include <linux/errno.h>
3 3
4int ceph_armor(char *dst, const char *src, const char *end);
5int ceph_unarmor(char *dst, const char *src, const char *end);
6
4/* 7/*
5 * base64 encode/decode. 8 * base64 encode/decode.
6 */ 9 */
7 10
8const char *pem_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 11static const char *pem_key =
12 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
9 13
10static int encode_bits(int c) 14static int encode_bits(int c)
11{ 15{
diff --git a/fs/ceph/auth.c b/fs/ceph/auth.c
index 89490beaf537..6d2e30600627 100644
--- a/fs/ceph/auth.c
+++ b/fs/ceph/auth.c
@@ -20,7 +20,7 @@ static u32 supported_protocols[] = {
20 CEPH_AUTH_CEPHX 20 CEPH_AUTH_CEPHX
21}; 21};
22 22
23int ceph_auth_init_protocol(struct ceph_auth_client *ac, int protocol) 23static int ceph_auth_init_protocol(struct ceph_auth_client *ac, int protocol)
24{ 24{
25 switch (protocol) { 25 switch (protocol) {
26 case CEPH_AUTH_NONE: 26 case CEPH_AUTH_NONE:
@@ -133,8 +133,8 @@ bad:
133 return -ERANGE; 133 return -ERANGE;
134} 134}
135 135
136int ceph_build_auth_request(struct ceph_auth_client *ac, 136static int ceph_build_auth_request(struct ceph_auth_client *ac,
137 void *msg_buf, size_t msg_len) 137 void *msg_buf, size_t msg_len)
138{ 138{
139 struct ceph_mon_request_header *monhdr = msg_buf; 139 struct ceph_mon_request_header *monhdr = msg_buf;
140 void *p = monhdr + 1; 140 void *p = monhdr + 1;
diff --git a/fs/ceph/auth_x.c b/fs/ceph/auth_x.c
index 6d44053ecff1..582e0b2caf8a 100644
--- a/fs/ceph/auth_x.c
+++ b/fs/ceph/auth_x.c
@@ -87,8 +87,8 @@ static int ceph_x_decrypt(struct ceph_crypto_key *secret,
87/* 87/*
88 * get existing (or insert new) ticket handler 88 * get existing (or insert new) ticket handler
89 */ 89 */
90struct ceph_x_ticket_handler *get_ticket_handler(struct ceph_auth_client *ac, 90static struct ceph_x_ticket_handler *
91 int service) 91get_ticket_handler(struct ceph_auth_client *ac, int service)
92{ 92{
93 struct ceph_x_ticket_handler *th; 93 struct ceph_x_ticket_handler *th;
94 struct ceph_x_info *xi = ac->private; 94 struct ceph_x_info *xi = ac->private;
@@ -429,7 +429,7 @@ static int ceph_x_build_request(struct ceph_auth_client *ac,
429 auth->struct_v = 1; 429 auth->struct_v = 1;
430 auth->key = 0; 430 auth->key = 0;
431 for (u = (u64 *)tmp_enc; u + 1 <= (u64 *)(tmp_enc + ret); u++) 431 for (u = (u64 *)tmp_enc; u + 1 <= (u64 *)(tmp_enc + ret); u++)
432 auth->key ^= *u; 432 auth->key ^= *(__le64 *)u;
433 dout(" server_challenge %llx client_challenge %llx key %llx\n", 433 dout(" server_challenge %llx client_challenge %llx key %llx\n",
434 xi->server_challenge, le64_to_cpu(auth->client_challenge), 434 xi->server_challenge, le64_to_cpu(auth->client_challenge),
435 le64_to_cpu(auth->key)); 435 le64_to_cpu(auth->key));
diff --git a/fs/ceph/buffer.c b/fs/ceph/buffer.c
index c67535d70aa6..cd39f17021de 100644
--- a/fs/ceph/buffer.c
+++ b/fs/ceph/buffer.c
@@ -47,22 +47,6 @@ void ceph_buffer_release(struct kref *kref)
47 kfree(b); 47 kfree(b);
48} 48}
49 49
50int ceph_buffer_alloc(struct ceph_buffer *b, int len, gfp_t gfp)
51{
52 b->vec.iov_base = kmalloc(len, gfp | __GFP_NOWARN);
53 if (b->vec.iov_base) {
54 b->is_vmalloc = false;
55 } else {
56 b->vec.iov_base = __vmalloc(len, gfp, PAGE_KERNEL);
57 b->is_vmalloc = true;
58 }
59 if (!b->vec.iov_base)
60 return -ENOMEM;
61 b->alloc_len = len;
62 b->vec.iov_len = len;
63 return 0;
64}
65
66int ceph_decode_buffer(struct ceph_buffer **b, void **p, void *end) 50int ceph_decode_buffer(struct ceph_buffer **b, void **p, void *end)
67{ 51{
68 size_t len; 52 size_t len;
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index b81be9a56487..7bf182b03973 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -113,58 +113,41 @@ const char *ceph_cap_string(int caps)
113 return cap_str[i]; 113 return cap_str[i];
114} 114}
115 115
116/* 116void ceph_caps_init(struct ceph_mds_client *mdsc)
117 * Cap reservations
118 *
119 * Maintain a global pool of preallocated struct ceph_caps, referenced
120 * by struct ceph_caps_reservations. This ensures that we preallocate
121 * memory needed to successfully process an MDS response. (If an MDS
122 * sends us cap information and we fail to process it, we will have
123 * problems due to the client and MDS being out of sync.)
124 *
125 * Reservations are 'owned' by a ceph_cap_reservation context.
126 */
127static spinlock_t caps_list_lock;
128static struct list_head caps_list; /* unused (reserved or unreserved) */
129static int caps_total_count; /* total caps allocated */
130static int caps_use_count; /* in use */
131static int caps_reserve_count; /* unused, reserved */
132static int caps_avail_count; /* unused, unreserved */
133static int caps_min_count; /* keep at least this many (unreserved) */
134
135void __init ceph_caps_init(void)
136{ 117{
137 INIT_LIST_HEAD(&caps_list); 118 INIT_LIST_HEAD(&mdsc->caps_list);
138 spin_lock_init(&caps_list_lock); 119 spin_lock_init(&mdsc->caps_list_lock);
139} 120}
140 121
141void ceph_caps_finalize(void) 122void ceph_caps_finalize(struct ceph_mds_client *mdsc)
142{ 123{
143 struct ceph_cap *cap; 124 struct ceph_cap *cap;
144 125
145 spin_lock(&caps_list_lock); 126 spin_lock(&mdsc->caps_list_lock);
146 while (!list_empty(&caps_list)) { 127 while (!list_empty(&mdsc->caps_list)) {
147 cap = list_first_entry(&caps_list, struct ceph_cap, caps_item); 128 cap = list_first_entry(&mdsc->caps_list,
129 struct ceph_cap, caps_item);
148 list_del(&cap->caps_item); 130 list_del(&cap->caps_item);
149 kmem_cache_free(ceph_cap_cachep, cap); 131 kmem_cache_free(ceph_cap_cachep, cap);
150 } 132 }
151 caps_total_count = 0; 133 mdsc->caps_total_count = 0;
152 caps_avail_count = 0; 134 mdsc->caps_avail_count = 0;
153 caps_use_count = 0; 135 mdsc->caps_use_count = 0;
154 caps_reserve_count = 0; 136 mdsc->caps_reserve_count = 0;
155 caps_min_count = 0; 137 mdsc->caps_min_count = 0;
156 spin_unlock(&caps_list_lock); 138 spin_unlock(&mdsc->caps_list_lock);
157} 139}
158 140
159void ceph_adjust_min_caps(int delta) 141void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta)
160{ 142{
161 spin_lock(&caps_list_lock); 143 spin_lock(&mdsc->caps_list_lock);
162 caps_min_count += delta; 144 mdsc->caps_min_count += delta;
163 BUG_ON(caps_min_count < 0); 145 BUG_ON(mdsc->caps_min_count < 0);
164 spin_unlock(&caps_list_lock); 146 spin_unlock(&mdsc->caps_list_lock);
165} 147}
166 148
167int ceph_reserve_caps(struct ceph_cap_reservation *ctx, int need) 149int ceph_reserve_caps(struct ceph_mds_client *mdsc,
150 struct ceph_cap_reservation *ctx, int need)
168{ 151{
169 int i; 152 int i;
170 struct ceph_cap *cap; 153 struct ceph_cap *cap;
@@ -176,16 +159,17 @@ int ceph_reserve_caps(struct ceph_cap_reservation *ctx, int need)
176 dout("reserve caps ctx=%p need=%d\n", ctx, need); 159 dout("reserve caps ctx=%p need=%d\n", ctx, need);
177 160
178 /* first reserve any caps that are already allocated */ 161 /* first reserve any caps that are already allocated */
179 spin_lock(&caps_list_lock); 162 spin_lock(&mdsc->caps_list_lock);
180 if (caps_avail_count >= need) 163 if (mdsc->caps_avail_count >= need)
181 have = need; 164 have = need;
182 else 165 else
183 have = caps_avail_count; 166 have = mdsc->caps_avail_count;
184 caps_avail_count -= have; 167 mdsc->caps_avail_count -= have;
185 caps_reserve_count += have; 168 mdsc->caps_reserve_count += have;
186 BUG_ON(caps_total_count != caps_use_count + caps_reserve_count + 169 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count +
187 caps_avail_count); 170 mdsc->caps_reserve_count +
188 spin_unlock(&caps_list_lock); 171 mdsc->caps_avail_count);
172 spin_unlock(&mdsc->caps_list_lock);
189 173
190 for (i = have; i < need; i++) { 174 for (i = have; i < need; i++) {
191 cap = kmem_cache_alloc(ceph_cap_cachep, GFP_NOFS); 175 cap = kmem_cache_alloc(ceph_cap_cachep, GFP_NOFS);
@@ -198,19 +182,20 @@ int ceph_reserve_caps(struct ceph_cap_reservation *ctx, int need)
198 } 182 }
199 BUG_ON(have + alloc != need); 183 BUG_ON(have + alloc != need);
200 184
201 spin_lock(&caps_list_lock); 185 spin_lock(&mdsc->caps_list_lock);
202 caps_total_count += alloc; 186 mdsc->caps_total_count += alloc;
203 caps_reserve_count += alloc; 187 mdsc->caps_reserve_count += alloc;
204 list_splice(&newcaps, &caps_list); 188 list_splice(&newcaps, &mdsc->caps_list);
205 189
206 BUG_ON(caps_total_count != caps_use_count + caps_reserve_count + 190 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count +
207 caps_avail_count); 191 mdsc->caps_reserve_count +
208 spin_unlock(&caps_list_lock); 192 mdsc->caps_avail_count);
193 spin_unlock(&mdsc->caps_list_lock);
209 194
210 ctx->count = need; 195 ctx->count = need;
211 dout("reserve caps ctx=%p %d = %d used + %d resv + %d avail\n", 196 dout("reserve caps ctx=%p %d = %d used + %d resv + %d avail\n",
212 ctx, caps_total_count, caps_use_count, caps_reserve_count, 197 ctx, mdsc->caps_total_count, mdsc->caps_use_count,
213 caps_avail_count); 198 mdsc->caps_reserve_count, mdsc->caps_avail_count);
214 return 0; 199 return 0;
215 200
216out_alloc_count: 201out_alloc_count:
@@ -220,26 +205,29 @@ out_alloc_count:
220 return ret; 205 return ret;
221} 206}
222 207
223int ceph_unreserve_caps(struct ceph_cap_reservation *ctx) 208int ceph_unreserve_caps(struct ceph_mds_client *mdsc,
209 struct ceph_cap_reservation *ctx)
224{ 210{
225 dout("unreserve caps ctx=%p count=%d\n", ctx, ctx->count); 211 dout("unreserve caps ctx=%p count=%d\n", ctx, ctx->count);
226 if (ctx->count) { 212 if (ctx->count) {
227 spin_lock(&caps_list_lock); 213 spin_lock(&mdsc->caps_list_lock);
228 BUG_ON(caps_reserve_count < ctx->count); 214 BUG_ON(mdsc->caps_reserve_count < ctx->count);
229 caps_reserve_count -= ctx->count; 215 mdsc->caps_reserve_count -= ctx->count;
230 caps_avail_count += ctx->count; 216 mdsc->caps_avail_count += ctx->count;
231 ctx->count = 0; 217 ctx->count = 0;
232 dout("unreserve caps %d = %d used + %d resv + %d avail\n", 218 dout("unreserve caps %d = %d used + %d resv + %d avail\n",
233 caps_total_count, caps_use_count, caps_reserve_count, 219 mdsc->caps_total_count, mdsc->caps_use_count,
234 caps_avail_count); 220 mdsc->caps_reserve_count, mdsc->caps_avail_count);
235 BUG_ON(caps_total_count != caps_use_count + caps_reserve_count + 221 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count +
236 caps_avail_count); 222 mdsc->caps_reserve_count +
237 spin_unlock(&caps_list_lock); 223 mdsc->caps_avail_count);
224 spin_unlock(&mdsc->caps_list_lock);
238 } 225 }
239 return 0; 226 return 0;
240} 227}
241 228
242static struct ceph_cap *get_cap(struct ceph_cap_reservation *ctx) 229static struct ceph_cap *get_cap(struct ceph_mds_client *mdsc,
230 struct ceph_cap_reservation *ctx)
243{ 231{
244 struct ceph_cap *cap = NULL; 232 struct ceph_cap *cap = NULL;
245 233
@@ -247,71 +235,74 @@ static struct ceph_cap *get_cap(struct ceph_cap_reservation *ctx)
247 if (!ctx) { 235 if (!ctx) {
248 cap = kmem_cache_alloc(ceph_cap_cachep, GFP_NOFS); 236 cap = kmem_cache_alloc(ceph_cap_cachep, GFP_NOFS);
249 if (cap) { 237 if (cap) {
250 caps_use_count++; 238 mdsc->caps_use_count++;
251 caps_total_count++; 239 mdsc->caps_total_count++;
252 } 240 }
253 return cap; 241 return cap;
254 } 242 }
255 243
256 spin_lock(&caps_list_lock); 244 spin_lock(&mdsc->caps_list_lock);
257 dout("get_cap ctx=%p (%d) %d = %d used + %d resv + %d avail\n", 245 dout("get_cap ctx=%p (%d) %d = %d used + %d resv + %d avail\n",
258 ctx, ctx->count, caps_total_count, caps_use_count, 246 ctx, ctx->count, mdsc->caps_total_count, mdsc->caps_use_count,
259 caps_reserve_count, caps_avail_count); 247 mdsc->caps_reserve_count, mdsc->caps_avail_count);
260 BUG_ON(!ctx->count); 248 BUG_ON(!ctx->count);
261 BUG_ON(ctx->count > caps_reserve_count); 249 BUG_ON(ctx->count > mdsc->caps_reserve_count);
262 BUG_ON(list_empty(&caps_list)); 250 BUG_ON(list_empty(&mdsc->caps_list));
263 251
264 ctx->count--; 252 ctx->count--;
265 caps_reserve_count--; 253 mdsc->caps_reserve_count--;
266 caps_use_count++; 254 mdsc->caps_use_count++;
267 255
268 cap = list_first_entry(&caps_list, struct ceph_cap, caps_item); 256 cap = list_first_entry(&mdsc->caps_list, struct ceph_cap, caps_item);
269 list_del(&cap->caps_item); 257 list_del(&cap->caps_item);
270 258
271 BUG_ON(caps_total_count != caps_use_count + caps_reserve_count + 259 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count +
272 caps_avail_count); 260 mdsc->caps_reserve_count + mdsc->caps_avail_count);
273 spin_unlock(&caps_list_lock); 261 spin_unlock(&mdsc->caps_list_lock);
274 return cap; 262 return cap;
275} 263}
276 264
277void ceph_put_cap(struct ceph_cap *cap) 265void ceph_put_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap)
278{ 266{
279 spin_lock(&caps_list_lock); 267 spin_lock(&mdsc->caps_list_lock);
280 dout("put_cap %p %d = %d used + %d resv + %d avail\n", 268 dout("put_cap %p %d = %d used + %d resv + %d avail\n",
281 cap, caps_total_count, caps_use_count, 269 cap, mdsc->caps_total_count, mdsc->caps_use_count,
282 caps_reserve_count, caps_avail_count); 270 mdsc->caps_reserve_count, mdsc->caps_avail_count);
283 caps_use_count--; 271 mdsc->caps_use_count--;
284 /* 272 /*
285 * Keep some preallocated caps around (ceph_min_count), to 273 * Keep some preallocated caps around (ceph_min_count), to
286 * avoid lots of free/alloc churn. 274 * avoid lots of free/alloc churn.
287 */ 275 */
288 if (caps_avail_count >= caps_reserve_count + caps_min_count) { 276 if (mdsc->caps_avail_count >= mdsc->caps_reserve_count +
289 caps_total_count--; 277 mdsc->caps_min_count) {
278 mdsc->caps_total_count--;
290 kmem_cache_free(ceph_cap_cachep, cap); 279 kmem_cache_free(ceph_cap_cachep, cap);
291 } else { 280 } else {
292 caps_avail_count++; 281 mdsc->caps_avail_count++;
293 list_add(&cap->caps_item, &caps_list); 282 list_add(&cap->caps_item, &mdsc->caps_list);
294 } 283 }
295 284
296 BUG_ON(caps_total_count != caps_use_count + caps_reserve_count + 285 BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count +
297 caps_avail_count); 286 mdsc->caps_reserve_count + mdsc->caps_avail_count);
298 spin_unlock(&caps_list_lock); 287 spin_unlock(&mdsc->caps_list_lock);
299} 288}
300 289
301void ceph_reservation_status(struct ceph_client *client, 290void ceph_reservation_status(struct ceph_client *client,
302 int *total, int *avail, int *used, int *reserved, 291 int *total, int *avail, int *used, int *reserved,
303 int *min) 292 int *min)
304{ 293{
294 struct ceph_mds_client *mdsc = &client->mdsc;
295
305 if (total) 296 if (total)
306 *total = caps_total_count; 297 *total = mdsc->caps_total_count;
307 if (avail) 298 if (avail)
308 *avail = caps_avail_count; 299 *avail = mdsc->caps_avail_count;
309 if (used) 300 if (used)
310 *used = caps_use_count; 301 *used = mdsc->caps_use_count;
311 if (reserved) 302 if (reserved)
312 *reserved = caps_reserve_count; 303 *reserved = mdsc->caps_reserve_count;
313 if (min) 304 if (min)
314 *min = caps_min_count; 305 *min = mdsc->caps_min_count;
315} 306}
316 307
317/* 308/*
@@ -336,22 +327,29 @@ static struct ceph_cap *__get_cap_for_mds(struct ceph_inode_info *ci, int mds)
336 return NULL; 327 return NULL;
337} 328}
338 329
330struct ceph_cap *ceph_get_cap_for_mds(struct ceph_inode_info *ci, int mds)
331{
332 struct ceph_cap *cap;
333
334 spin_lock(&ci->vfs_inode.i_lock);
335 cap = __get_cap_for_mds(ci, mds);
336 spin_unlock(&ci->vfs_inode.i_lock);
337 return cap;
338}
339
339/* 340/*
340 * Return id of any MDS with a cap, preferably FILE_WR|WRBUFFER|EXCL, else 341 * Return id of any MDS with a cap, preferably FILE_WR|BUFFER|EXCL, else -1.
341 * -1.
342 */ 342 */
343static int __ceph_get_cap_mds(struct ceph_inode_info *ci, u32 *mseq) 343static int __ceph_get_cap_mds(struct ceph_inode_info *ci)
344{ 344{
345 struct ceph_cap *cap; 345 struct ceph_cap *cap;
346 int mds = -1; 346 int mds = -1;
347 struct rb_node *p; 347 struct rb_node *p;
348 348
349 /* prefer mds with WR|WRBUFFER|EXCL caps */ 349 /* prefer mds with WR|BUFFER|EXCL caps */
350 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { 350 for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) {
351 cap = rb_entry(p, struct ceph_cap, ci_node); 351 cap = rb_entry(p, struct ceph_cap, ci_node);
352 mds = cap->mds; 352 mds = cap->mds;
353 if (mseq)
354 *mseq = cap->mseq;
355 if (cap->issued & (CEPH_CAP_FILE_WR | 353 if (cap->issued & (CEPH_CAP_FILE_WR |
356 CEPH_CAP_FILE_BUFFER | 354 CEPH_CAP_FILE_BUFFER |
357 CEPH_CAP_FILE_EXCL)) 355 CEPH_CAP_FILE_EXCL))
@@ -364,7 +362,7 @@ int ceph_get_cap_mds(struct inode *inode)
364{ 362{
365 int mds; 363 int mds;
366 spin_lock(&inode->i_lock); 364 spin_lock(&inode->i_lock);
367 mds = __ceph_get_cap_mds(ceph_inode(inode), NULL); 365 mds = __ceph_get_cap_mds(ceph_inode(inode));
368 spin_unlock(&inode->i_lock); 366 spin_unlock(&inode->i_lock);
369 return mds; 367 return mds;
370} 368}
@@ -483,8 +481,8 @@ static void __check_cap_issue(struct ceph_inode_info *ci, struct ceph_cap *cap,
483 * Each time we receive FILE_CACHE anew, we increment 481 * Each time we receive FILE_CACHE anew, we increment
484 * i_rdcache_gen. 482 * i_rdcache_gen.
485 */ 483 */
486 if ((issued & CEPH_CAP_FILE_CACHE) && 484 if ((issued & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) &&
487 (had & CEPH_CAP_FILE_CACHE) == 0) 485 (had & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0)
488 ci->i_rdcache_gen++; 486 ci->i_rdcache_gen++;
489 487
490 /* 488 /*
@@ -543,7 +541,7 @@ retry:
543 new_cap = NULL; 541 new_cap = NULL;
544 } else { 542 } else {
545 spin_unlock(&inode->i_lock); 543 spin_unlock(&inode->i_lock);
546 new_cap = get_cap(caps_reservation); 544 new_cap = get_cap(mdsc, caps_reservation);
547 if (new_cap == NULL) 545 if (new_cap == NULL)
548 return -ENOMEM; 546 return -ENOMEM;
549 goto retry; 547 goto retry;
@@ -588,6 +586,7 @@ retry:
588 } else { 586 } else {
589 pr_err("ceph_add_cap: couldn't find snap realm %llx\n", 587 pr_err("ceph_add_cap: couldn't find snap realm %llx\n",
590 realmino); 588 realmino);
589 WARN_ON(!realm);
591 } 590 }
592 } 591 }
593 592
@@ -831,7 +830,7 @@ int __ceph_caps_file_wanted(struct ceph_inode_info *ci)
831{ 830{
832 int want = 0; 831 int want = 0;
833 int mode; 832 int mode;
834 for (mode = 0; mode < 4; mode++) 833 for (mode = 0; mode < CEPH_FILE_MODE_NUM; mode++)
835 if (ci->i_nr_by_mode[mode]) 834 if (ci->i_nr_by_mode[mode])
836 want |= ceph_caps_for_mode(mode); 835 want |= ceph_caps_for_mode(mode);
837 return want; 836 return want;
@@ -901,7 +900,7 @@ void __ceph_remove_cap(struct ceph_cap *cap)
901 ci->i_auth_cap = NULL; 900 ci->i_auth_cap = NULL;
902 901
903 if (removed) 902 if (removed)
904 ceph_put_cap(cap); 903 ceph_put_cap(mdsc, cap);
905 904
906 if (!__ceph_is_any_caps(ci) && ci->i_snap_realm) { 905 if (!__ceph_is_any_caps(ci) && ci->i_snap_realm) {
907 struct ceph_snap_realm *realm = ci->i_snap_realm; 906 struct ceph_snap_realm *realm = ci->i_snap_realm;
@@ -1197,6 +1196,8 @@ static int __send_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap,
1197 */ 1196 */
1198void __ceph_flush_snaps(struct ceph_inode_info *ci, 1197void __ceph_flush_snaps(struct ceph_inode_info *ci,
1199 struct ceph_mds_session **psession) 1198 struct ceph_mds_session **psession)
1199 __releases(ci->vfs_inode->i_lock)
1200 __acquires(ci->vfs_inode->i_lock)
1200{ 1201{
1201 struct inode *inode = &ci->vfs_inode; 1202 struct inode *inode = &ci->vfs_inode;
1202 int mds; 1203 int mds;
@@ -1232,7 +1233,13 @@ retry:
1232 BUG_ON(capsnap->dirty == 0); 1233 BUG_ON(capsnap->dirty == 0);
1233 1234
1234 /* pick mds, take s_mutex */ 1235 /* pick mds, take s_mutex */
1235 mds = __ceph_get_cap_mds(ci, &mseq); 1236 if (ci->i_auth_cap == NULL) {
1237 dout("no auth cap (migrating?), doing nothing\n");
1238 goto out;
1239 }
1240 mds = ci->i_auth_cap->session->s_mds;
1241 mseq = ci->i_auth_cap->mseq;
1242
1236 if (session && session->s_mds != mds) { 1243 if (session && session->s_mds != mds) {
1237 dout("oops, wrong session %p mutex\n", session); 1244 dout("oops, wrong session %p mutex\n", session);
1238 mutex_unlock(&session->s_mutex); 1245 mutex_unlock(&session->s_mutex);
@@ -1251,8 +1258,8 @@ retry:
1251 } 1258 }
1252 /* 1259 /*
1253 * if session == NULL, we raced against a cap 1260 * if session == NULL, we raced against a cap
1254 * deletion. retry, and we'll get a better 1261 * deletion or migration. retry, and we'll
1255 * @mds value next time. 1262 * get a better @mds value next time.
1256 */ 1263 */
1257 spin_lock(&inode->i_lock); 1264 spin_lock(&inode->i_lock);
1258 goto retry; 1265 goto retry;
@@ -1290,6 +1297,7 @@ retry:
1290 list_del_init(&ci->i_snap_flush_item); 1297 list_del_init(&ci->i_snap_flush_item);
1291 spin_unlock(&mdsc->snap_flush_lock); 1298 spin_unlock(&mdsc->snap_flush_lock);
1292 1299
1300out:
1293 if (psession) 1301 if (psession)
1294 *psession = session; 1302 *psession = session;
1295 else if (session) { 1303 else if (session) {
@@ -1435,7 +1443,6 @@ static int try_nonblocking_invalidate(struct inode *inode)
1435 */ 1443 */
1436void ceph_check_caps(struct ceph_inode_info *ci, int flags, 1444void ceph_check_caps(struct ceph_inode_info *ci, int flags,
1437 struct ceph_mds_session *session) 1445 struct ceph_mds_session *session)
1438 __releases(session->s_mutex)
1439{ 1446{
1440 struct ceph_client *client = ceph_inode_to_client(&ci->vfs_inode); 1447 struct ceph_client *client = ceph_inode_to_client(&ci->vfs_inode);
1441 struct ceph_mds_client *mdsc = &client->mdsc; 1448 struct ceph_mds_client *mdsc = &client->mdsc;
@@ -1510,11 +1517,13 @@ retry_locked:
1510 ci->i_wrbuffer_ref == 0 && /* no dirty pages... */ 1517 ci->i_wrbuffer_ref == 0 && /* no dirty pages... */
1511 ci->i_rdcache_gen && /* may have cached pages */ 1518 ci->i_rdcache_gen && /* may have cached pages */
1512 (file_wanted == 0 || /* no open files */ 1519 (file_wanted == 0 || /* no open files */
1513 (revoking & CEPH_CAP_FILE_CACHE)) && /* or revoking cache */ 1520 (revoking & (CEPH_CAP_FILE_CACHE|
1521 CEPH_CAP_FILE_LAZYIO))) && /* or revoking cache */
1514 !tried_invalidate) { 1522 !tried_invalidate) {
1515 dout("check_caps trying to invalidate on %p\n", inode); 1523 dout("check_caps trying to invalidate on %p\n", inode);
1516 if (try_nonblocking_invalidate(inode) < 0) { 1524 if (try_nonblocking_invalidate(inode) < 0) {
1517 if (revoking & CEPH_CAP_FILE_CACHE) { 1525 if (revoking & (CEPH_CAP_FILE_CACHE|
1526 CEPH_CAP_FILE_LAZYIO)) {
1518 dout("check_caps queuing invalidate\n"); 1527 dout("check_caps queuing invalidate\n");
1519 queue_invalidate = 1; 1528 queue_invalidate = 1;
1520 ci->i_rdcache_revoking = ci->i_rdcache_gen; 1529 ci->i_rdcache_revoking = ci->i_rdcache_gen;
@@ -2250,8 +2259,7 @@ static void handle_cap_grant(struct inode *inode, struct ceph_mds_caps *grant,
2250 struct ceph_mds_session *session, 2259 struct ceph_mds_session *session,
2251 struct ceph_cap *cap, 2260 struct ceph_cap *cap,
2252 struct ceph_buffer *xattr_buf) 2261 struct ceph_buffer *xattr_buf)
2253 __releases(inode->i_lock) 2262 __releases(inode->i_lock)
2254 __releases(session->s_mutex)
2255{ 2263{
2256 struct ceph_inode_info *ci = ceph_inode(inode); 2264 struct ceph_inode_info *ci = ceph_inode(inode);
2257 int mds = session->s_mds; 2265 int mds = session->s_mds;
@@ -2278,6 +2286,7 @@ static void handle_cap_grant(struct inode *inode, struct ceph_mds_caps *grant,
2278 * will invalidate _after_ writeback.) 2286 * will invalidate _after_ writeback.)
2279 */ 2287 */
2280 if (((cap->issued & ~newcaps) & CEPH_CAP_FILE_CACHE) && 2288 if (((cap->issued & ~newcaps) & CEPH_CAP_FILE_CACHE) &&
2289 (newcaps & CEPH_CAP_FILE_LAZYIO) == 0 &&
2281 !ci->i_wrbuffer_ref) { 2290 !ci->i_wrbuffer_ref) {
2282 if (try_nonblocking_invalidate(inode) == 0) { 2291 if (try_nonblocking_invalidate(inode) == 0) {
2283 revoked_rdcache = 1; 2292 revoked_rdcache = 1;
@@ -2369,15 +2378,22 @@ static void handle_cap_grant(struct inode *inode, struct ceph_mds_caps *grant,
2369 2378
2370 /* revocation, grant, or no-op? */ 2379 /* revocation, grant, or no-op? */
2371 if (cap->issued & ~newcaps) { 2380 if (cap->issued & ~newcaps) {
2372 dout("revocation: %s -> %s\n", ceph_cap_string(cap->issued), 2381 int revoking = cap->issued & ~newcaps;
2373 ceph_cap_string(newcaps)); 2382
2374 if ((used & ~newcaps) & CEPH_CAP_FILE_BUFFER) 2383 dout("revocation: %s -> %s (revoking %s)\n",
2375 writeback = 1; /* will delay ack */ 2384 ceph_cap_string(cap->issued),
2376 else if (dirty & ~newcaps) 2385 ceph_cap_string(newcaps),
2377 check_caps = 1; /* initiate writeback in check_caps */ 2386 ceph_cap_string(revoking));
2378 else if (((used & ~newcaps) & CEPH_CAP_FILE_CACHE) == 0 || 2387 if (revoking & used & CEPH_CAP_FILE_BUFFER)
2379 revoked_rdcache) 2388 writeback = 1; /* initiate writeback; will delay ack */
2380 check_caps = 2; /* send revoke ack in check_caps */ 2389 else if (revoking == CEPH_CAP_FILE_CACHE &&
2390 (newcaps & CEPH_CAP_FILE_LAZYIO) == 0 &&
2391 queue_invalidate)
2392 ; /* do nothing yet, invalidation will be queued */
2393 else if (cap == ci->i_auth_cap)
2394 check_caps = 1; /* check auth cap only */
2395 else
2396 check_caps = 2; /* check all caps */
2381 cap->issued = newcaps; 2397 cap->issued = newcaps;
2382 cap->implemented |= newcaps; 2398 cap->implemented |= newcaps;
2383 } else if (cap->issued == newcaps) { 2399 } else if (cap->issued == newcaps) {
@@ -2568,7 +2584,8 @@ static void handle_cap_trunc(struct inode *inode,
2568 * caller holds s_mutex 2584 * caller holds s_mutex
2569 */ 2585 */
2570static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex, 2586static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,
2571 struct ceph_mds_session *session) 2587 struct ceph_mds_session *session,
2588 int *open_target_sessions)
2572{ 2589{
2573 struct ceph_inode_info *ci = ceph_inode(inode); 2590 struct ceph_inode_info *ci = ceph_inode(inode);
2574 int mds = session->s_mds; 2591 int mds = session->s_mds;
@@ -2600,6 +2617,12 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,
2600 ci->i_cap_exporting_mds = mds; 2617 ci->i_cap_exporting_mds = mds;
2601 ci->i_cap_exporting_mseq = mseq; 2618 ci->i_cap_exporting_mseq = mseq;
2602 ci->i_cap_exporting_issued = cap->issued; 2619 ci->i_cap_exporting_issued = cap->issued;
2620
2621 /*
2622 * make sure we have open sessions with all possible
2623 * export targets, so that we get the matching IMPORT
2624 */
2625 *open_target_sessions = 1;
2603 } 2626 }
2604 __ceph_remove_cap(cap); 2627 __ceph_remove_cap(cap);
2605 } 2628 }
@@ -2675,6 +2698,10 @@ void ceph_handle_caps(struct ceph_mds_session *session,
2675 u64 size, max_size; 2698 u64 size, max_size;
2676 u64 tid; 2699 u64 tid;
2677 void *snaptrace; 2700 void *snaptrace;
2701 size_t snaptrace_len;
2702 void *flock;
2703 u32 flock_len;
2704 int open_target_sessions = 0;
2678 2705
2679 dout("handle_caps from mds%d\n", mds); 2706 dout("handle_caps from mds%d\n", mds);
2680 2707
@@ -2683,7 +2710,6 @@ void ceph_handle_caps(struct ceph_mds_session *session,
2683 if (msg->front.iov_len < sizeof(*h)) 2710 if (msg->front.iov_len < sizeof(*h))
2684 goto bad; 2711 goto bad;
2685 h = msg->front.iov_base; 2712 h = msg->front.iov_base;
2686 snaptrace = h + 1;
2687 op = le32_to_cpu(h->op); 2713 op = le32_to_cpu(h->op);
2688 vino.ino = le64_to_cpu(h->ino); 2714 vino.ino = le64_to_cpu(h->ino);
2689 vino.snap = CEPH_NOSNAP; 2715 vino.snap = CEPH_NOSNAP;
@@ -2693,6 +2719,21 @@ void ceph_handle_caps(struct ceph_mds_session *session,
2693 size = le64_to_cpu(h->size); 2719 size = le64_to_cpu(h->size);
2694 max_size = le64_to_cpu(h->max_size); 2720 max_size = le64_to_cpu(h->max_size);
2695 2721
2722 snaptrace = h + 1;
2723 snaptrace_len = le32_to_cpu(h->snap_trace_len);
2724
2725 if (le16_to_cpu(msg->hdr.version) >= 2) {
2726 void *p, *end;
2727
2728 p = snaptrace + snaptrace_len;
2729 end = msg->front.iov_base + msg->front.iov_len;
2730 ceph_decode_32_safe(&p, end, flock_len, bad);
2731 flock = p;
2732 } else {
2733 flock = NULL;
2734 flock_len = 0;
2735 }
2736
2696 mutex_lock(&session->s_mutex); 2737 mutex_lock(&session->s_mutex);
2697 session->s_seq++; 2738 session->s_seq++;
2698 dout(" mds%d seq %lld cap seq %u\n", session->s_mds, session->s_seq, 2739 dout(" mds%d seq %lld cap seq %u\n", session->s_mds, session->s_seq,
@@ -2714,7 +2755,7 @@ void ceph_handle_caps(struct ceph_mds_session *session,
2714 * along for the mds (who clearly thinks we still have this 2755 * along for the mds (who clearly thinks we still have this
2715 * cap). 2756 * cap).
2716 */ 2757 */
2717 ceph_add_cap_releases(mdsc, session, -1); 2758 ceph_add_cap_releases(mdsc, session);
2718 ceph_send_cap_releases(mdsc, session); 2759 ceph_send_cap_releases(mdsc, session);
2719 goto done; 2760 goto done;
2720 } 2761 }
@@ -2726,12 +2767,12 @@ void ceph_handle_caps(struct ceph_mds_session *session,
2726 goto done; 2767 goto done;
2727 2768
2728 case CEPH_CAP_OP_EXPORT: 2769 case CEPH_CAP_OP_EXPORT:
2729 handle_cap_export(inode, h, session); 2770 handle_cap_export(inode, h, session, &open_target_sessions);
2730 goto done; 2771 goto done;
2731 2772
2732 case CEPH_CAP_OP_IMPORT: 2773 case CEPH_CAP_OP_IMPORT:
2733 handle_cap_import(mdsc, inode, h, session, 2774 handle_cap_import(mdsc, inode, h, session,
2734 snaptrace, le32_to_cpu(h->snap_trace_len)); 2775 snaptrace, snaptrace_len);
2735 ceph_check_caps(ceph_inode(inode), CHECK_CAPS_NODELAY, 2776 ceph_check_caps(ceph_inode(inode), CHECK_CAPS_NODELAY,
2736 session); 2777 session);
2737 goto done_unlocked; 2778 goto done_unlocked;
@@ -2773,6 +2814,8 @@ done:
2773done_unlocked: 2814done_unlocked:
2774 if (inode) 2815 if (inode)
2775 iput(inode); 2816 iput(inode);
2817 if (open_target_sessions)
2818 ceph_mdsc_open_export_target_sessions(mdsc, session);
2776 return; 2819 return;
2777 2820
2778bad: 2821bad:
diff --git a/fs/ceph/ceph_frag.h b/fs/ceph/ceph_frag.h
index 793f50cb7c22..5babb8e95352 100644
--- a/fs/ceph/ceph_frag.h
+++ b/fs/ceph/ceph_frag.h
@@ -1,5 +1,5 @@
1#ifndef _FS_CEPH_FRAG_H 1#ifndef FS_CEPH_FRAG_H
2#define _FS_CEPH_FRAG_H 2#define FS_CEPH_FRAG_H
3 3
4/* 4/*
5 * "Frags" are a way to describe a subset of a 32-bit number space, 5 * "Frags" are a way to describe a subset of a 32-bit number space,
diff --git a/fs/ceph/ceph_fs.c b/fs/ceph/ceph_fs.c
index 79d76bc4303f..3ac6cc7c1156 100644
--- a/fs/ceph/ceph_fs.c
+++ b/fs/ceph/ceph_fs.c
@@ -29,46 +29,44 @@ int ceph_file_layout_is_valid(const struct ceph_file_layout *layout)
29 29
30int ceph_flags_to_mode(int flags) 30int ceph_flags_to_mode(int flags)
31{ 31{
32 int mode;
33
32#ifdef O_DIRECTORY /* fixme */ 34#ifdef O_DIRECTORY /* fixme */
33 if ((flags & O_DIRECTORY) == O_DIRECTORY) 35 if ((flags & O_DIRECTORY) == O_DIRECTORY)
34 return CEPH_FILE_MODE_PIN; 36 return CEPH_FILE_MODE_PIN;
35#endif 37#endif
38 if ((flags & O_APPEND) == O_APPEND)
39 flags |= O_WRONLY;
40
41 if ((flags & O_ACCMODE) == O_RDWR)
42 mode = CEPH_FILE_MODE_RDWR;
43 else if ((flags & O_ACCMODE) == O_WRONLY)
44 mode = CEPH_FILE_MODE_WR;
45 else
46 mode = CEPH_FILE_MODE_RD;
47
36#ifdef O_LAZY 48#ifdef O_LAZY
37 if (flags & O_LAZY) 49 if (flags & O_LAZY)
38 return CEPH_FILE_MODE_LAZY; 50 mode |= CEPH_FILE_MODE_LAZY;
39#endif 51#endif
40 if ((flags & O_APPEND) == O_APPEND)
41 flags |= O_WRONLY;
42 52
43 flags &= O_ACCMODE; 53 return mode;
44 if ((flags & O_RDWR) == O_RDWR)
45 return CEPH_FILE_MODE_RDWR;
46 if ((flags & O_WRONLY) == O_WRONLY)
47 return CEPH_FILE_MODE_WR;
48 return CEPH_FILE_MODE_RD;
49} 54}
50 55
51int ceph_caps_for_mode(int mode) 56int ceph_caps_for_mode(int mode)
52{ 57{
53 switch (mode) { 58 int caps = CEPH_CAP_PIN;
54 case CEPH_FILE_MODE_PIN: 59
55 return CEPH_CAP_PIN; 60 if (mode & CEPH_FILE_MODE_RD)
56 case CEPH_FILE_MODE_RD: 61 caps |= CEPH_CAP_FILE_SHARED |
57 return CEPH_CAP_PIN | CEPH_CAP_FILE_SHARED |
58 CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE; 62 CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE;
59 case CEPH_FILE_MODE_RDWR: 63 if (mode & CEPH_FILE_MODE_WR)
60 return CEPH_CAP_PIN | CEPH_CAP_FILE_SHARED | 64 caps |= CEPH_CAP_FILE_EXCL |
61 CEPH_CAP_FILE_EXCL |
62 CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE |
63 CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER |
64 CEPH_CAP_AUTH_SHARED | CEPH_CAP_AUTH_EXCL |
65 CEPH_CAP_XATTR_SHARED | CEPH_CAP_XATTR_EXCL;
66 case CEPH_FILE_MODE_WR:
67 return CEPH_CAP_PIN | CEPH_CAP_FILE_SHARED |
68 CEPH_CAP_FILE_EXCL |
69 CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER | 65 CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER |
70 CEPH_CAP_AUTH_SHARED | CEPH_CAP_AUTH_EXCL | 66 CEPH_CAP_AUTH_SHARED | CEPH_CAP_AUTH_EXCL |
71 CEPH_CAP_XATTR_SHARED | CEPH_CAP_XATTR_EXCL; 67 CEPH_CAP_XATTR_SHARED | CEPH_CAP_XATTR_EXCL;
72 } 68 if (mode & CEPH_FILE_MODE_LAZY)
73 return 0; 69 caps |= CEPH_CAP_FILE_LAZYIO;
70
71 return caps;
74} 72}
diff --git a/fs/ceph/ceph_fs.h b/fs/ceph/ceph_fs.h
index 2fa992eaf7da..d5619ac86711 100644
--- a/fs/ceph/ceph_fs.h
+++ b/fs/ceph/ceph_fs.h
@@ -9,27 +9,13 @@
9 * LGPL2 9 * LGPL2
10 */ 10 */
11 11
12#ifndef _FS_CEPH_CEPH_FS_H 12#ifndef CEPH_FS_H
13#define _FS_CEPH_CEPH_FS_H 13#define CEPH_FS_H
14 14
15#include "msgr.h" 15#include "msgr.h"
16#include "rados.h" 16#include "rados.h"
17 17
18/* 18/*
19 * Ceph release version
20 */
21#define CEPH_VERSION_MAJOR 0
22#define CEPH_VERSION_MINOR 20
23#define CEPH_VERSION_PATCH 0
24
25#define _CEPH_STRINGIFY(x) #x
26#define CEPH_STRINGIFY(x) _CEPH_STRINGIFY(x)
27#define CEPH_MAKE_VERSION(x, y, z) CEPH_STRINGIFY(x) "." CEPH_STRINGIFY(y) \
28 "." CEPH_STRINGIFY(z)
29#define CEPH_VERSION CEPH_MAKE_VERSION(CEPH_VERSION_MAJOR, \
30 CEPH_VERSION_MINOR, CEPH_VERSION_PATCH)
31
32/*
33 * subprotocol versions. when specific messages types or high-level 19 * subprotocol versions. when specific messages types or high-level
34 * protocols change, bump the affected components. we keep rev 20 * protocols change, bump the affected components. we keep rev
35 * internal cluster protocols separately from the public, 21 * internal cluster protocols separately from the public,
@@ -53,18 +39,10 @@
53/* 39/*
54 * feature bits 40 * feature bits
55 */ 41 */
56#define CEPH_FEATURE_UID 1 42#define CEPH_FEATURE_UID (1<<0)
57#define CEPH_FEATURE_NOSRCADDR 2 43#define CEPH_FEATURE_NOSRCADDR (1<<1)
58#define CEPH_FEATURE_FLOCK 4 44#define CEPH_FEATURE_MONCLOCKCHECK (1<<2)
59 45#define CEPH_FEATURE_FLOCK (1<<3)
60#define CEPH_FEATURE_SUPPORTED_MON CEPH_FEATURE_UID|CEPH_FEATURE_NOSRCADDR
61#define CEPH_FEATURE_REQUIRED_MON CEPH_FEATURE_UID
62#define CEPH_FEATURE_SUPPORTED_MDS CEPH_FEATURE_UID|CEPH_FEATURE_NOSRCADDR|CEPH_FEATURE_FLOCK
63#define CEPH_FEATURE_REQUIRED_MDS CEPH_FEATURE_UID
64#define CEPH_FEATURE_SUPPORTED_OSD CEPH_FEATURE_UID|CEPH_FEATURE_NOSRCADDR
65#define CEPH_FEATURE_REQUIRED_OSD CEPH_FEATURE_UID
66#define CEPH_FEATURE_SUPPORTED_CLIENT CEPH_FEATURE_NOSRCADDR
67#define CEPH_FEATURE_REQUIRED_CLIENT CEPH_FEATURE_NOSRCADDR
68 46
69 47
70/* 48/*
@@ -96,6 +74,8 @@ int ceph_file_layout_is_valid(const struct ceph_file_layout *layout);
96#define CEPH_CRYPTO_NONE 0x0 74#define CEPH_CRYPTO_NONE 0x0
97#define CEPH_CRYPTO_AES 0x1 75#define CEPH_CRYPTO_AES 0x1
98 76
77#define CEPH_AES_IV "cephsageyudagreg"
78
99/* security/authentication protocols */ 79/* security/authentication protocols */
100#define CEPH_AUTH_UNKNOWN 0x0 80#define CEPH_AUTH_UNKNOWN 0x0
101#define CEPH_AUTH_NONE 0x1 81#define CEPH_AUTH_NONE 0x1
@@ -275,6 +255,7 @@ extern const char *ceph_mds_state_name(int s);
275#define CEPH_LOCK_IDFT 512 /* dir frag tree */ 255#define CEPH_LOCK_IDFT 512 /* dir frag tree */
276#define CEPH_LOCK_INEST 1024 /* mds internal */ 256#define CEPH_LOCK_INEST 1024 /* mds internal */
277#define CEPH_LOCK_IXATTR 2048 257#define CEPH_LOCK_IXATTR 2048
258#define CEPH_LOCK_IFLOCK 4096 /* advisory file locks */
278#define CEPH_LOCK_INO 8192 /* immutable inode bits; not a lock */ 259#define CEPH_LOCK_INO 8192 /* immutable inode bits; not a lock */
279 260
280/* client_session ops */ 261/* client_session ops */
@@ -316,6 +297,8 @@ enum {
316 CEPH_MDS_OP_RMXATTR = 0x01106, 297 CEPH_MDS_OP_RMXATTR = 0x01106,
317 CEPH_MDS_OP_SETLAYOUT = 0x01107, 298 CEPH_MDS_OP_SETLAYOUT = 0x01107,
318 CEPH_MDS_OP_SETATTR = 0x01108, 299 CEPH_MDS_OP_SETATTR = 0x01108,
300 CEPH_MDS_OP_SETFILELOCK= 0x01109,
301 CEPH_MDS_OP_GETFILELOCK= 0x00110,
319 302
320 CEPH_MDS_OP_MKNOD = 0x01201, 303 CEPH_MDS_OP_MKNOD = 0x01201,
321 CEPH_MDS_OP_LINK = 0x01202, 304 CEPH_MDS_OP_LINK = 0x01202,
@@ -386,6 +369,15 @@ union ceph_mds_request_args {
386 struct { 369 struct {
387 struct ceph_file_layout layout; 370 struct ceph_file_layout layout;
388 } __attribute__ ((packed)) setlayout; 371 } __attribute__ ((packed)) setlayout;
372 struct {
373 __u8 rule; /* currently fcntl or flock */
374 __u8 type; /* shared, exclusive, remove*/
375 __le64 pid; /* process id requesting the lock */
376 __le64 pid_namespace;
377 __le64 start; /* initial location to lock */
378 __le64 length; /* num bytes to lock from start */
379 __u8 wait; /* will caller wait for lock to become available? */
380 } __attribute__ ((packed)) filelock_change;
389} __attribute__ ((packed)); 381} __attribute__ ((packed));
390 382
391#define CEPH_MDS_FLAG_REPLAY 1 /* this is a replayed op */ 383#define CEPH_MDS_FLAG_REPLAY 1 /* this is a replayed op */
@@ -480,6 +472,23 @@ struct ceph_mds_reply_dirfrag {
480 __le32 dist[]; 472 __le32 dist[];
481} __attribute__ ((packed)); 473} __attribute__ ((packed));
482 474
475#define CEPH_LOCK_FCNTL 1
476#define CEPH_LOCK_FLOCK 2
477
478#define CEPH_LOCK_SHARED 1
479#define CEPH_LOCK_EXCL 2
480#define CEPH_LOCK_UNLOCK 4
481
482struct ceph_filelock {
483 __le64 start;/* file offset to start lock at */
484 __le64 length; /* num bytes to lock; 0 for all following start */
485 __le64 client; /* which client holds the lock */
486 __le64 pid; /* process id holding the lock on the client */
487 __le64 pid_namespace;
488 __u8 type; /* shared lock, exclusive lock, or unlock */
489} __attribute__ ((packed));
490
491
483/* file access modes */ 492/* file access modes */
484#define CEPH_FILE_MODE_PIN 0 493#define CEPH_FILE_MODE_PIN 0
485#define CEPH_FILE_MODE_RD 1 494#define CEPH_FILE_MODE_RD 1
@@ -508,9 +517,10 @@ int ceph_flags_to_mode(int flags);
508#define CEPH_CAP_SAUTH 2 517#define CEPH_CAP_SAUTH 2
509#define CEPH_CAP_SLINK 4 518#define CEPH_CAP_SLINK 4
510#define CEPH_CAP_SXATTR 6 519#define CEPH_CAP_SXATTR 6
511#define CEPH_CAP_SFILE 8 /* goes at the end (uses >2 cap bits) */ 520#define CEPH_CAP_SFILE 8
521#define CEPH_CAP_SFLOCK 20
512 522
513#define CEPH_CAP_BITS 16 523#define CEPH_CAP_BITS 22
514 524
515/* composed values */ 525/* composed values */
516#define CEPH_CAP_AUTH_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SAUTH) 526#define CEPH_CAP_AUTH_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SAUTH)
@@ -528,6 +538,9 @@ int ceph_flags_to_mode(int flags);
528#define CEPH_CAP_FILE_BUFFER (CEPH_CAP_GBUFFER << CEPH_CAP_SFILE) 538#define CEPH_CAP_FILE_BUFFER (CEPH_CAP_GBUFFER << CEPH_CAP_SFILE)
529#define CEPH_CAP_FILE_WREXTEND (CEPH_CAP_GWREXTEND << CEPH_CAP_SFILE) 539#define CEPH_CAP_FILE_WREXTEND (CEPH_CAP_GWREXTEND << CEPH_CAP_SFILE)
530#define CEPH_CAP_FILE_LAZYIO (CEPH_CAP_GLAZYIO << CEPH_CAP_SFILE) 540#define CEPH_CAP_FILE_LAZYIO (CEPH_CAP_GLAZYIO << CEPH_CAP_SFILE)
541#define CEPH_CAP_FLOCK_SHARED (CEPH_CAP_GSHARED << CEPH_CAP_SFLOCK)
542#define CEPH_CAP_FLOCK_EXCL (CEPH_CAP_GEXCL << CEPH_CAP_SFLOCK)
543
531 544
532/* cap masks (for getattr) */ 545/* cap masks (for getattr) */
533#define CEPH_STAT_CAP_INODE CEPH_CAP_PIN 546#define CEPH_STAT_CAP_INODE CEPH_CAP_PIN
@@ -563,7 +576,8 @@ int ceph_flags_to_mode(int flags);
563 CEPH_CAP_FILE_EXCL) 576 CEPH_CAP_FILE_EXCL)
564#define CEPH_CAP_ANY_WR (CEPH_CAP_ANY_EXCL | CEPH_CAP_ANY_FILE_WR) 577#define CEPH_CAP_ANY_WR (CEPH_CAP_ANY_EXCL | CEPH_CAP_ANY_FILE_WR)
565#define CEPH_CAP_ANY (CEPH_CAP_ANY_RD | CEPH_CAP_ANY_EXCL | \ 578#define CEPH_CAP_ANY (CEPH_CAP_ANY_RD | CEPH_CAP_ANY_EXCL | \
566 CEPH_CAP_ANY_FILE_WR | CEPH_CAP_PIN) 579 CEPH_CAP_ANY_FILE_WR | CEPH_CAP_FILE_LAZYIO | \
580 CEPH_CAP_PIN)
567 581
568#define CEPH_CAP_LOCKS (CEPH_LOCK_IFILE | CEPH_LOCK_IAUTH | CEPH_LOCK_ILINK | \ 582#define CEPH_CAP_LOCKS (CEPH_LOCK_IFILE | CEPH_LOCK_IAUTH | CEPH_LOCK_ILINK | \
569 CEPH_LOCK_IXATTR) 583 CEPH_LOCK_IXATTR)
@@ -653,12 +667,21 @@ struct ceph_mds_cap_reconnect {
653 __le64 cap_id; 667 __le64 cap_id;
654 __le32 wanted; 668 __le32 wanted;
655 __le32 issued; 669 __le32 issued;
670 __le64 snaprealm;
671 __le64 pathbase; /* base ino for our path to this ino */
672 __le32 flock_len; /* size of flock state blob, if any */
673} __attribute__ ((packed));
674/* followed by flock blob */
675
676struct ceph_mds_cap_reconnect_v1 {
677 __le64 cap_id;
678 __le32 wanted;
679 __le32 issued;
656 __le64 size; 680 __le64 size;
657 struct ceph_timespec mtime, atime; 681 struct ceph_timespec mtime, atime;
658 __le64 snaprealm; 682 __le64 snaprealm;
659 __le64 pathbase; /* base ino for our path to this ino */ 683 __le64 pathbase; /* base ino for our path to this ino */
660} __attribute__ ((packed)); 684} __attribute__ ((packed));
661/* followed by encoded string */
662 685
663struct ceph_mds_snaprealm_reconnect { 686struct ceph_mds_snaprealm_reconnect {
664 __le64 ino; /* snap realm base */ 687 __le64 ino; /* snap realm base */
diff --git a/fs/ceph/ceph_hash.h b/fs/ceph/ceph_hash.h
index 5ac470c433c9..d099c3f90236 100644
--- a/fs/ceph/ceph_hash.h
+++ b/fs/ceph/ceph_hash.h
@@ -1,5 +1,5 @@
1#ifndef _FS_CEPH_HASH_H 1#ifndef FS_CEPH_HASH_H
2#define _FS_CEPH_HASH_H 2#define FS_CEPH_HASH_H
3 3
4#define CEPH_STR_HASH_LINUX 0x1 /* linux dcache hash */ 4#define CEPH_STR_HASH_LINUX 0x1 /* linux dcache hash */
5#define CEPH_STR_HASH_RJENKINS 0x2 /* robert jenkins' */ 5#define CEPH_STR_HASH_RJENKINS 0x2 /* robert jenkins' */
diff --git a/fs/ceph/ceph_strings.c b/fs/ceph/ceph_strings.c
index 7503aee828ce..c6179d3a26a2 100644
--- a/fs/ceph/ceph_strings.c
+++ b/fs/ceph/ceph_strings.c
@@ -28,6 +28,7 @@ const char *ceph_osd_op_name(int op)
28 case CEPH_OSD_OP_TRUNCATE: return "truncate"; 28 case CEPH_OSD_OP_TRUNCATE: return "truncate";
29 case CEPH_OSD_OP_ZERO: return "zero"; 29 case CEPH_OSD_OP_ZERO: return "zero";
30 case CEPH_OSD_OP_WRITEFULL: return "writefull"; 30 case CEPH_OSD_OP_WRITEFULL: return "writefull";
31 case CEPH_OSD_OP_ROLLBACK: return "rollback";
31 32
32 case CEPH_OSD_OP_APPEND: return "append"; 33 case CEPH_OSD_OP_APPEND: return "append";
33 case CEPH_OSD_OP_STARTSYNC: return "startsync"; 34 case CEPH_OSD_OP_STARTSYNC: return "startsync";
@@ -129,6 +130,8 @@ const char *ceph_mds_op_name(int op)
129 case CEPH_MDS_OP_LSSNAP: return "lssnap"; 130 case CEPH_MDS_OP_LSSNAP: return "lssnap";
130 case CEPH_MDS_OP_MKSNAP: return "mksnap"; 131 case CEPH_MDS_OP_MKSNAP: return "mksnap";
131 case CEPH_MDS_OP_RMSNAP: return "rmsnap"; 132 case CEPH_MDS_OP_RMSNAP: return "rmsnap";
133 case CEPH_MDS_OP_SETFILELOCK: return "setfilelock";
134 case CEPH_MDS_OP_GETFILELOCK: return "getfilelock";
132 } 135 }
133 return "???"; 136 return "???";
134} 137}
diff --git a/fs/ceph/crush/crush.h b/fs/ceph/crush/crush.h
index dcd7e7523700..97e435b191f4 100644
--- a/fs/ceph/crush/crush.h
+++ b/fs/ceph/crush/crush.h
@@ -1,5 +1,5 @@
1#ifndef _CRUSH_CRUSH_H 1#ifndef CEPH_CRUSH_CRUSH_H
2#define _CRUSH_CRUSH_H 2#define CEPH_CRUSH_CRUSH_H
3 3
4#include <linux/types.h> 4#include <linux/types.h>
5 5
diff --git a/fs/ceph/crush/hash.h b/fs/ceph/crush/hash.h
index ff48e110e4bb..91e884230d5d 100644
--- a/fs/ceph/crush/hash.h
+++ b/fs/ceph/crush/hash.h
@@ -1,5 +1,5 @@
1#ifndef _CRUSH_HASH_H 1#ifndef CEPH_CRUSH_HASH_H
2#define _CRUSH_HASH_H 2#define CEPH_CRUSH_HASH_H
3 3
4#define CRUSH_HASH_RJENKINS1 0 4#define CRUSH_HASH_RJENKINS1 0
5 5
diff --git a/fs/ceph/crush/mapper.h b/fs/ceph/crush/mapper.h
index 98e90046fd9f..c46b99c18bb0 100644
--- a/fs/ceph/crush/mapper.h
+++ b/fs/ceph/crush/mapper.h
@@ -1,5 +1,5 @@
1#ifndef _CRUSH_MAPPER_H 1#ifndef CEPH_CRUSH_MAPPER_H
2#define _CRUSH_MAPPER_H 2#define CEPH_CRUSH_MAPPER_H
3 3
4/* 4/*
5 * CRUSH functions for find rules and then mapping an input to an 5 * CRUSH functions for find rules and then mapping an input to an
diff --git a/fs/ceph/crypto.c b/fs/ceph/crypto.c
index f704b3b62424..a3e627f63293 100644
--- a/fs/ceph/crypto.c
+++ b/fs/ceph/crypto.c
@@ -75,10 +75,11 @@ static struct crypto_blkcipher *ceph_crypto_alloc_cipher(void)
75 return crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC); 75 return crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
76} 76}
77 77
78const u8 *aes_iv = "cephsageyudagreg"; 78static const u8 *aes_iv = (u8 *)CEPH_AES_IV;
79 79
80int ceph_aes_encrypt(const void *key, int key_len, void *dst, size_t *dst_len, 80static int ceph_aes_encrypt(const void *key, int key_len,
81 const void *src, size_t src_len) 81 void *dst, size_t *dst_len,
82 const void *src, size_t src_len)
82{ 83{
83 struct scatterlist sg_in[2], sg_out[1]; 84 struct scatterlist sg_in[2], sg_out[1];
84 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher(); 85 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher();
@@ -126,9 +127,10 @@ int ceph_aes_encrypt(const void *key, int key_len, void *dst, size_t *dst_len,
126 return 0; 127 return 0;
127} 128}
128 129
129int ceph_aes_encrypt2(const void *key, int key_len, void *dst, size_t *dst_len, 130static int ceph_aes_encrypt2(const void *key, int key_len, void *dst,
130 const void *src1, size_t src1_len, 131 size_t *dst_len,
131 const void *src2, size_t src2_len) 132 const void *src1, size_t src1_len,
133 const void *src2, size_t src2_len)
132{ 134{
133 struct scatterlist sg_in[3], sg_out[1]; 135 struct scatterlist sg_in[3], sg_out[1];
134 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher(); 136 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher();
@@ -179,8 +181,9 @@ int ceph_aes_encrypt2(const void *key, int key_len, void *dst, size_t *dst_len,
179 return 0; 181 return 0;
180} 182}
181 183
182int ceph_aes_decrypt(const void *key, int key_len, void *dst, size_t *dst_len, 184static int ceph_aes_decrypt(const void *key, int key_len,
183 const void *src, size_t src_len) 185 void *dst, size_t *dst_len,
186 const void *src, size_t src_len)
184{ 187{
185 struct scatterlist sg_in[1], sg_out[2]; 188 struct scatterlist sg_in[1], sg_out[2];
186 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher(); 189 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher();
@@ -238,10 +241,10 @@ int ceph_aes_decrypt(const void *key, int key_len, void *dst, size_t *dst_len,
238 return 0; 241 return 0;
239} 242}
240 243
241int ceph_aes_decrypt2(const void *key, int key_len, 244static int ceph_aes_decrypt2(const void *key, int key_len,
242 void *dst1, size_t *dst1_len, 245 void *dst1, size_t *dst1_len,
243 void *dst2, size_t *dst2_len, 246 void *dst2, size_t *dst2_len,
244 const void *src, size_t src_len) 247 const void *src, size_t src_len)
245{ 248{
246 struct scatterlist sg_in[1], sg_out[3]; 249 struct scatterlist sg_in[1], sg_out[3];
247 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher(); 250 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher();
diff --git a/fs/ceph/crypto.h b/fs/ceph/crypto.h
index 40b502e6bd89..bdf38607323c 100644
--- a/fs/ceph/crypto.h
+++ b/fs/ceph/crypto.h
@@ -42,7 +42,7 @@ extern int ceph_encrypt2(struct ceph_crypto_key *secret,
42 const void *src2, size_t src2_len); 42 const void *src2, size_t src2_len);
43 43
44/* armor.c */ 44/* armor.c */
45extern int ceph_armor(char *dst, const void *src, const void *end); 45extern int ceph_armor(char *dst, const char *src, const char *end);
46extern int ceph_unarmor(void *dst, const char *src, const char *end); 46extern int ceph_unarmor(char *dst, const char *src, const char *end);
47 47
48#endif 48#endif
diff --git a/fs/ceph/debugfs.c b/fs/ceph/debugfs.c
index f2f5332ddbba..360c4f22718d 100644
--- a/fs/ceph/debugfs.c
+++ b/fs/ceph/debugfs.c
@@ -291,7 +291,7 @@ static int dentry_lru_show(struct seq_file *s, void *ptr)
291 return 0; 291 return 0;
292} 292}
293 293
294#define DEFINE_SHOW_FUNC(name) \ 294#define DEFINE_SHOW_FUNC(name) \
295static int name##_open(struct inode *inode, struct file *file) \ 295static int name##_open(struct inode *inode, struct file *file) \
296{ \ 296{ \
297 struct seq_file *sf; \ 297 struct seq_file *sf; \
@@ -361,8 +361,8 @@ int ceph_debugfs_client_init(struct ceph_client *client)
361 int ret = 0; 361 int ret = 0;
362 char name[80]; 362 char name[80];
363 363
364 snprintf(name, sizeof(name), FSID_FORMAT ".client%lld", 364 snprintf(name, sizeof(name), "%pU.client%lld", &client->fsid,
365 PR_FSID(&client->fsid), client->monc.auth->global_id); 365 client->monc.auth->global_id);
366 366
367 client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir); 367 client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
368 if (!client->debugfs_dir) 368 if (!client->debugfs_dir)
@@ -432,11 +432,12 @@ int ceph_debugfs_client_init(struct ceph_client *client)
432 if (!client->debugfs_caps) 432 if (!client->debugfs_caps)
433 goto out; 433 goto out;
434 434
435 client->debugfs_congestion_kb = debugfs_create_file("writeback_congestion_kb", 435 client->debugfs_congestion_kb =
436 0600, 436 debugfs_create_file("writeback_congestion_kb",
437 client->debugfs_dir, 437 0600,
438 client, 438 client->debugfs_dir,
439 &congestion_kb_fops); 439 client,
440 &congestion_kb_fops);
440 if (!client->debugfs_congestion_kb) 441 if (!client->debugfs_congestion_kb)
441 goto out; 442 goto out;
442 443
@@ -466,7 +467,7 @@ void ceph_debugfs_client_cleanup(struct ceph_client *client)
466 debugfs_remove(client->debugfs_dir); 467 debugfs_remove(client->debugfs_dir);
467} 468}
468 469
469#else // CONFIG_DEBUG_FS 470#else /* CONFIG_DEBUG_FS */
470 471
471int __init ceph_debugfs_init(void) 472int __init ceph_debugfs_init(void)
472{ 473{
@@ -486,4 +487,4 @@ void ceph_debugfs_client_cleanup(struct ceph_client *client)
486{ 487{
487} 488}
488 489
489#endif // CONFIG_DEBUG_FS 490#endif /* CONFIG_DEBUG_FS */
diff --git a/fs/ceph/decode.h b/fs/ceph/decode.h
index 65b3e022eaf5..3d25415afe63 100644
--- a/fs/ceph/decode.h
+++ b/fs/ceph/decode.h
@@ -99,11 +99,13 @@ static inline void ceph_encode_timespec(struct ceph_timespec *tv,
99 */ 99 */
100static inline void ceph_encode_addr(struct ceph_entity_addr *a) 100static inline void ceph_encode_addr(struct ceph_entity_addr *a)
101{ 101{
102 a->in_addr.ss_family = htons(a->in_addr.ss_family); 102 __be16 ss_family = htons(a->in_addr.ss_family);
103 a->in_addr.ss_family = *(__u16 *)&ss_family;
103} 104}
104static inline void ceph_decode_addr(struct ceph_entity_addr *a) 105static inline void ceph_decode_addr(struct ceph_entity_addr *a)
105{ 106{
106 a->in_addr.ss_family = ntohs(a->in_addr.ss_family); 107 __be16 ss_family = *(__be16 *)&a->in_addr.ss_family;
108 a->in_addr.ss_family = ntohs(ss_family);
107 WARN_ON(a->in_addr.ss_family == 512); 109 WARN_ON(a->in_addr.ss_family == 512);
108} 110}
109 111
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index f94ed3c7f6a5..67bbb41d5526 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -27,7 +27,7 @@
27 27
28const struct inode_operations ceph_dir_iops; 28const struct inode_operations ceph_dir_iops;
29const struct file_operations ceph_dir_fops; 29const struct file_operations ceph_dir_fops;
30struct dentry_operations ceph_dentry_ops; 30const struct dentry_operations ceph_dentry_ops;
31 31
32/* 32/*
33 * Initialize ceph dentry state. 33 * Initialize ceph dentry state.
@@ -94,6 +94,8 @@ static unsigned fpos_off(loff_t p)
94 */ 94 */
95static int __dcache_readdir(struct file *filp, 95static int __dcache_readdir(struct file *filp,
96 void *dirent, filldir_t filldir) 96 void *dirent, filldir_t filldir)
97 __releases(inode->i_lock)
98 __acquires(inode->i_lock)
97{ 99{
98 struct inode *inode = filp->f_dentry->d_inode; 100 struct inode *inode = filp->f_dentry->d_inode;
99 struct ceph_file_info *fi = filp->private_data; 101 struct ceph_file_info *fi = filp->private_data;
@@ -1239,16 +1241,16 @@ const struct inode_operations ceph_dir_iops = {
1239 .create = ceph_create, 1241 .create = ceph_create,
1240}; 1242};
1241 1243
1242struct dentry_operations ceph_dentry_ops = { 1244const struct dentry_operations ceph_dentry_ops = {
1243 .d_revalidate = ceph_d_revalidate, 1245 .d_revalidate = ceph_d_revalidate,
1244 .d_release = ceph_dentry_release, 1246 .d_release = ceph_dentry_release,
1245}; 1247};
1246 1248
1247struct dentry_operations ceph_snapdir_dentry_ops = { 1249const struct dentry_operations ceph_snapdir_dentry_ops = {
1248 .d_revalidate = ceph_snapdir_d_revalidate, 1250 .d_revalidate = ceph_snapdir_d_revalidate,
1249 .d_release = ceph_dentry_release, 1251 .d_release = ceph_dentry_release,
1250}; 1252};
1251 1253
1252struct dentry_operations ceph_snap_dentry_ops = { 1254const struct dentry_operations ceph_snap_dentry_ops = {
1253 .d_release = ceph_dentry_release, 1255 .d_release = ceph_dentry_release,
1254}; 1256};
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index 7c08698fad3e..8c044a4f0457 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -317,7 +317,7 @@ void ceph_release_page_vector(struct page **pages, int num_pages)
317/* 317/*
318 * allocate a vector new pages 318 * allocate a vector new pages
319 */ 319 */
320struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags) 320static struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags)
321{ 321{
322 struct page **pages; 322 struct page **pages;
323 int i; 323 int i;
@@ -665,7 +665,7 @@ more:
665 * throw out any page cache pages in this range. this 665 * throw out any page cache pages in this range. this
666 * may block. 666 * may block.
667 */ 667 */
668 truncate_inode_pages_range(inode->i_mapping, pos, 668 truncate_inode_pages_range(inode->i_mapping, pos,
669 (pos+len) | (PAGE_CACHE_SIZE-1)); 669 (pos+len) | (PAGE_CACHE_SIZE-1));
670 } else { 670 } else {
671 pages = ceph_alloc_page_vector(num_pages, GFP_NOFS); 671 pages = ceph_alloc_page_vector(num_pages, GFP_NOFS);
@@ -740,28 +740,32 @@ static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov,
740 unsigned long nr_segs, loff_t pos) 740 unsigned long nr_segs, loff_t pos)
741{ 741{
742 struct file *filp = iocb->ki_filp; 742 struct file *filp = iocb->ki_filp;
743 struct ceph_file_info *fi = filp->private_data;
743 loff_t *ppos = &iocb->ki_pos; 744 loff_t *ppos = &iocb->ki_pos;
744 size_t len = iov->iov_len; 745 size_t len = iov->iov_len;
745 struct inode *inode = filp->f_dentry->d_inode; 746 struct inode *inode = filp->f_dentry->d_inode;
746 struct ceph_inode_info *ci = ceph_inode(inode); 747 struct ceph_inode_info *ci = ceph_inode(inode);
747 void *base = iov->iov_base; 748 void __user *base = iov->iov_base;
748 ssize_t ret; 749 ssize_t ret;
749 int got = 0; 750 int want, got = 0;
750 int checkeof = 0, read = 0; 751 int checkeof = 0, read = 0;
751 752
752 dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n", 753 dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n",
753 inode, ceph_vinop(inode), pos, (unsigned)len, inode); 754 inode, ceph_vinop(inode), pos, (unsigned)len, inode);
754again: 755again:
755 __ceph_do_pending_vmtruncate(inode); 756 __ceph_do_pending_vmtruncate(inode);
756 ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, CEPH_CAP_FILE_CACHE, 757 if (fi->fmode & CEPH_FILE_MODE_LAZY)
757 &got, -1); 758 want = CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO;
759 else
760 want = CEPH_CAP_FILE_CACHE;
761 ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, &got, -1);
758 if (ret < 0) 762 if (ret < 0)
759 goto out; 763 goto out;
760 dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n", 764 dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n",
761 inode, ceph_vinop(inode), pos, (unsigned)len, 765 inode, ceph_vinop(inode), pos, (unsigned)len,
762 ceph_cap_string(got)); 766 ceph_cap_string(got));
763 767
764 if ((got & CEPH_CAP_FILE_CACHE) == 0 || 768 if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 ||
765 (iocb->ki_filp->f_flags & O_DIRECT) || 769 (iocb->ki_filp->f_flags & O_DIRECT) ||
766 (inode->i_sb->s_flags & MS_SYNCHRONOUS)) 770 (inode->i_sb->s_flags & MS_SYNCHRONOUS))
767 /* hmm, this isn't really async... */ 771 /* hmm, this isn't really async... */
@@ -807,11 +811,12 @@ static ssize_t ceph_aio_write(struct kiocb *iocb, const struct iovec *iov,
807 unsigned long nr_segs, loff_t pos) 811 unsigned long nr_segs, loff_t pos)
808{ 812{
809 struct file *file = iocb->ki_filp; 813 struct file *file = iocb->ki_filp;
814 struct ceph_file_info *fi = file->private_data;
810 struct inode *inode = file->f_dentry->d_inode; 815 struct inode *inode = file->f_dentry->d_inode;
811 struct ceph_inode_info *ci = ceph_inode(inode); 816 struct ceph_inode_info *ci = ceph_inode(inode);
812 struct ceph_osd_client *osdc = &ceph_sb_to_client(inode->i_sb)->osdc; 817 struct ceph_osd_client *osdc = &ceph_sb_to_client(inode->i_sb)->osdc;
813 loff_t endoff = pos + iov->iov_len; 818 loff_t endoff = pos + iov->iov_len;
814 int got = 0; 819 int want, got = 0;
815 int ret, err; 820 int ret, err;
816 821
817 if (ceph_snap(inode) != CEPH_NOSNAP) 822 if (ceph_snap(inode) != CEPH_NOSNAP)
@@ -824,8 +829,11 @@ retry_snap:
824 dout("aio_write %p %llx.%llx %llu~%u getting caps. i_size %llu\n", 829 dout("aio_write %p %llx.%llx %llu~%u getting caps. i_size %llu\n",
825 inode, ceph_vinop(inode), pos, (unsigned)iov->iov_len, 830 inode, ceph_vinop(inode), pos, (unsigned)iov->iov_len,
826 inode->i_size); 831 inode->i_size);
827 ret = ceph_get_caps(ci, CEPH_CAP_FILE_WR, CEPH_CAP_FILE_BUFFER, 832 if (fi->fmode & CEPH_FILE_MODE_LAZY)
828 &got, endoff); 833 want = CEPH_CAP_FILE_BUFFER | CEPH_CAP_FILE_LAZYIO;
834 else
835 want = CEPH_CAP_FILE_BUFFER;
836 ret = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, &got, endoff);
829 if (ret < 0) 837 if (ret < 0)
830 goto out; 838 goto out;
831 839
@@ -833,7 +841,7 @@ retry_snap:
833 inode, ceph_vinop(inode), pos, (unsigned)iov->iov_len, 841 inode, ceph_vinop(inode), pos, (unsigned)iov->iov_len,
834 ceph_cap_string(got)); 842 ceph_cap_string(got));
835 843
836 if ((got & CEPH_CAP_FILE_BUFFER) == 0 || 844 if ((got & (CEPH_CAP_FILE_BUFFER|CEPH_CAP_FILE_LAZYIO)) == 0 ||
837 (iocb->ki_filp->f_flags & O_DIRECT) || 845 (iocb->ki_filp->f_flags & O_DIRECT) ||
838 (inode->i_sb->s_flags & MS_SYNCHRONOUS)) { 846 (inode->i_sb->s_flags & MS_SYNCHRONOUS)) {
839 ret = ceph_sync_write(file, iov->iov_base, iov->iov_len, 847 ret = ceph_sync_write(file, iov->iov_base, iov->iov_len,
@@ -930,6 +938,8 @@ const struct file_operations ceph_file_fops = {
930 .aio_write = ceph_aio_write, 938 .aio_write = ceph_aio_write,
931 .mmap = ceph_mmap, 939 .mmap = ceph_mmap,
932 .fsync = ceph_fsync, 940 .fsync = ceph_fsync,
941 .lock = ceph_lock,
942 .flock = ceph_flock,
933 .splice_read = generic_file_splice_read, 943 .splice_read = generic_file_splice_read,
934 .splice_write = generic_file_splice_write, 944 .splice_write = generic_file_splice_write,
935 .unlocked_ioctl = ceph_ioctl, 945 .unlocked_ioctl = ceph_ioctl,
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 389f9dbd9949..5d893d31e399 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -442,8 +442,9 @@ int ceph_fill_file_size(struct inode *inode, int issued,
442 * the file is either opened or mmaped 442 * the file is either opened or mmaped
443 */ 443 */
444 if ((issued & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_RD| 444 if ((issued & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_RD|
445 CEPH_CAP_FILE_WR|CEPH_CAP_FILE_BUFFER| 445 CEPH_CAP_FILE_WR|CEPH_CAP_FILE_BUFFER|
446 CEPH_CAP_FILE_EXCL)) || 446 CEPH_CAP_FILE_EXCL|
447 CEPH_CAP_FILE_LAZYIO)) ||
447 mapping_mapped(inode->i_mapping) || 448 mapping_mapped(inode->i_mapping) ||
448 __ceph_caps_file_wanted(ci)) { 449 __ceph_caps_file_wanted(ci)) {
449 ci->i_truncate_pending++; 450 ci->i_truncate_pending++;
diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
index d085f07756b4..76e307d2aba1 100644
--- a/fs/ceph/ioctl.c
+++ b/fs/ceph/ioctl.c
@@ -143,6 +143,27 @@ static long ceph_ioctl_get_dataloc(struct file *file, void __user *arg)
143 return 0; 143 return 0;
144} 144}
145 145
146static long ceph_ioctl_lazyio(struct file *file)
147{
148 struct ceph_file_info *fi = file->private_data;
149 struct inode *inode = file->f_dentry->d_inode;
150 struct ceph_inode_info *ci = ceph_inode(inode);
151
152 if ((fi->fmode & CEPH_FILE_MODE_LAZY) == 0) {
153 spin_lock(&inode->i_lock);
154 ci->i_nr_by_mode[fi->fmode]--;
155 fi->fmode |= CEPH_FILE_MODE_LAZY;
156 ci->i_nr_by_mode[fi->fmode]++;
157 spin_unlock(&inode->i_lock);
158 dout("ioctl_layzio: file %p marked lazy\n", file);
159
160 ceph_check_caps(ci, 0, NULL);
161 } else {
162 dout("ioctl_layzio: file %p already lazy\n", file);
163 }
164 return 0;
165}
166
146long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 167long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
147{ 168{
148 dout("ioctl file %p cmd %u arg %lu\n", file, cmd, arg); 169 dout("ioctl file %p cmd %u arg %lu\n", file, cmd, arg);
@@ -155,6 +176,9 @@ long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
155 176
156 case CEPH_IOC_GET_DATALOC: 177 case CEPH_IOC_GET_DATALOC:
157 return ceph_ioctl_get_dataloc(file, (void __user *)arg); 178 return ceph_ioctl_get_dataloc(file, (void __user *)arg);
179
180 case CEPH_IOC_LAZYIO:
181 return ceph_ioctl_lazyio(file);
158 } 182 }
159 return -ENOTTY; 183 return -ENOTTY;
160} 184}
diff --git a/fs/ceph/ioctl.h b/fs/ceph/ioctl.h
index 25e4f1a9d059..88451a3b6857 100644
--- a/fs/ceph/ioctl.h
+++ b/fs/ceph/ioctl.h
@@ -37,4 +37,6 @@ struct ceph_ioctl_dataloc {
37#define CEPH_IOC_GET_DATALOC _IOWR(CEPH_IOCTL_MAGIC, 3, \ 37#define CEPH_IOC_GET_DATALOC _IOWR(CEPH_IOCTL_MAGIC, 3, \
38 struct ceph_ioctl_dataloc) 38 struct ceph_ioctl_dataloc)
39 39
40#define CEPH_IOC_LAZYIO _IO(CEPH_IOCTL_MAGIC, 4)
41
40#endif 42#endif
diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c
new file mode 100644
index 000000000000..ae85af06454f
--- /dev/null
+++ b/fs/ceph/locks.c
@@ -0,0 +1,256 @@
1#include "ceph_debug.h"
2
3#include <linux/file.h>
4#include <linux/namei.h>
5
6#include "super.h"
7#include "mds_client.h"
8#include "pagelist.h"
9
10/**
11 * Implement fcntl and flock locking functions.
12 */
13static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file,
14 u64 pid, u64 pid_ns,
15 int cmd, u64 start, u64 length, u8 wait)
16{
17 struct inode *inode = file->f_dentry->d_inode;
18 struct ceph_mds_client *mdsc =
19 &ceph_sb_to_client(inode->i_sb)->mdsc;
20 struct ceph_mds_request *req;
21 int err;
22
23 req = ceph_mdsc_create_request(mdsc, operation, USE_AUTH_MDS);
24 if (IS_ERR(req))
25 return PTR_ERR(req);
26 req->r_inode = igrab(inode);
27
28 dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, "
29 "length: %llu, wait: %d, type`: %d", (int)lock_type,
30 (int)operation, pid, start, length, wait, cmd);
31
32 req->r_args.filelock_change.rule = lock_type;
33 req->r_args.filelock_change.type = cmd;
34 req->r_args.filelock_change.pid = cpu_to_le64(pid);
35 /* This should be adjusted, but I'm not sure if
36 namespaces actually get id numbers*/
37 req->r_args.filelock_change.pid_namespace =
38 cpu_to_le64((u64)pid_ns);
39 req->r_args.filelock_change.start = cpu_to_le64(start);
40 req->r_args.filelock_change.length = cpu_to_le64(length);
41 req->r_args.filelock_change.wait = wait;
42
43 err = ceph_mdsc_do_request(mdsc, inode, req);
44 ceph_mdsc_put_request(req);
45 dout("ceph_lock_message: rule: %d, op: %d, pid: %llu, start: %llu, "
46 "length: %llu, wait: %d, type`: %d err code %d", (int)lock_type,
47 (int)operation, pid, start, length, wait, cmd, err);
48 return err;
49}
50
51/**
52 * Attempt to set an fcntl lock.
53 * For now, this just goes away to the server. Later it may be more awesome.
54 */
55int ceph_lock(struct file *file, int cmd, struct file_lock *fl)
56{
57 u64 length;
58 u8 lock_cmd;
59 int err;
60 u8 wait = 0;
61 u16 op = CEPH_MDS_OP_SETFILELOCK;
62
63 fl->fl_nspid = get_pid(task_tgid(current));
64 dout("ceph_lock, fl_pid:%d", fl->fl_pid);
65
66 /* set wait bit as appropriate, then make command as Ceph expects it*/
67 if (F_SETLKW == cmd)
68 wait = 1;
69 if (F_GETLK == cmd)
70 op = CEPH_MDS_OP_GETFILELOCK;
71
72 if (F_RDLCK == fl->fl_type)
73 lock_cmd = CEPH_LOCK_SHARED;
74 else if (F_WRLCK == fl->fl_type)
75 lock_cmd = CEPH_LOCK_EXCL;
76 else
77 lock_cmd = CEPH_LOCK_UNLOCK;
78
79 if (LLONG_MAX == fl->fl_end)
80 length = 0;
81 else
82 length = fl->fl_end - fl->fl_start + 1;
83
84 err = ceph_lock_message(CEPH_LOCK_FCNTL, op, file,
85 (u64)fl->fl_pid, (u64)fl->fl_nspid,
86 lock_cmd, fl->fl_start,
87 length, wait);
88 if (!err) {
89 dout("mds locked, locking locally");
90 err = posix_lock_file(file, fl, NULL);
91 if (err && (CEPH_MDS_OP_SETFILELOCK == op)) {
92 /* undo! This should only happen if the kernel detects
93 * local deadlock. */
94 ceph_lock_message(CEPH_LOCK_FCNTL, op, file,
95 (u64)fl->fl_pid, (u64)fl->fl_nspid,
96 CEPH_LOCK_UNLOCK, fl->fl_start,
97 length, 0);
98 dout("got %d on posix_lock_file, undid lock", err);
99 }
100 } else {
101 dout("mds returned error code %d", err);
102 }
103 return err;
104}
105
106int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
107{
108 u64 length;
109 u8 lock_cmd;
110 int err;
111 u8 wait = 1;
112
113 fl->fl_nspid = get_pid(task_tgid(current));
114 dout("ceph_flock, fl_pid:%d", fl->fl_pid);
115
116 /* set wait bit, then clear it out of cmd*/
117 if (cmd & LOCK_NB)
118 wait = 0;
119 cmd = cmd & (LOCK_SH | LOCK_EX | LOCK_UN);
120 /* set command sequence that Ceph wants to see:
121 shared lock, exclusive lock, or unlock */
122 if (LOCK_SH == cmd)
123 lock_cmd = CEPH_LOCK_SHARED;
124 else if (LOCK_EX == cmd)
125 lock_cmd = CEPH_LOCK_EXCL;
126 else
127 lock_cmd = CEPH_LOCK_UNLOCK;
128 /* mds requires start and length rather than start and end */
129 if (LLONG_MAX == fl->fl_end)
130 length = 0;
131 else
132 length = fl->fl_end - fl->fl_start + 1;
133
134 err = ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK,
135 file, (u64)fl->fl_pid, (u64)fl->fl_nspid,
136 lock_cmd, fl->fl_start,
137 length, wait);
138 if (!err) {
139 err = flock_lock_file_wait(file, fl);
140 if (err) {
141 ceph_lock_message(CEPH_LOCK_FLOCK,
142 CEPH_MDS_OP_SETFILELOCK,
143 file, (u64)fl->fl_pid,
144 (u64)fl->fl_nspid,
145 CEPH_LOCK_UNLOCK, fl->fl_start,
146 length, 0);
147 dout("got %d on flock_lock_file_wait, undid lock", err);
148 }
149 } else {
150 dout("mds error code %d", err);
151 }
152 return err;
153}
154
155/**
156 * Must be called with BKL already held. Fills in the passed
157 * counter variables, so you can prepare pagelist metadata before calling
158 * ceph_encode_locks.
159 */
160void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count)
161{
162 struct file_lock *lock;
163
164 *fcntl_count = 0;
165 *flock_count = 0;
166
167 for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) {
168 if (lock->fl_flags & FL_POSIX)
169 ++(*fcntl_count);
170 else if (lock->fl_flags & FL_FLOCK)
171 ++(*flock_count);
172 }
173 dout("counted %d flock locks and %d fcntl locks",
174 *flock_count, *fcntl_count);
175}
176
177/**
178 * Encode the flock and fcntl locks for the given inode into the pagelist.
179 * Format is: #fcntl locks, sequential fcntl locks, #flock locks,
180 * sequential flock locks.
181 * Must be called with BLK already held, and the lock numbers should have
182 * been gathered under the same lock holding window.
183 */
184int ceph_encode_locks(struct inode *inode, struct ceph_pagelist *pagelist,
185 int num_fcntl_locks, int num_flock_locks)
186{
187 struct file_lock *lock;
188 struct ceph_filelock cephlock;
189 int err = 0;
190
191 dout("encoding %d flock and %d fcntl locks", num_flock_locks,
192 num_fcntl_locks);
193 err = ceph_pagelist_append(pagelist, &num_fcntl_locks, sizeof(u32));
194 if (err)
195 goto fail;
196 for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) {
197 if (lock->fl_flags & FL_POSIX) {
198 err = lock_to_ceph_filelock(lock, &cephlock);
199 if (err)
200 goto fail;
201 err = ceph_pagelist_append(pagelist, &cephlock,
202 sizeof(struct ceph_filelock));
203 }
204 if (err)
205 goto fail;
206 }
207
208 err = ceph_pagelist_append(pagelist, &num_flock_locks, sizeof(u32));
209 if (err)
210 goto fail;
211 for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) {
212 if (lock->fl_flags & FL_FLOCK) {
213 err = lock_to_ceph_filelock(lock, &cephlock);
214 if (err)
215 goto fail;
216 err = ceph_pagelist_append(pagelist, &cephlock,
217 sizeof(struct ceph_filelock));
218 }
219 if (err)
220 goto fail;
221 }
222fail:
223 return err;
224}
225
226/*
227 * Given a pointer to a lock, convert it to a ceph filelock
228 */
229int lock_to_ceph_filelock(struct file_lock *lock,
230 struct ceph_filelock *cephlock)
231{
232 int err = 0;
233
234 cephlock->start = cpu_to_le64(lock->fl_start);
235 cephlock->length = cpu_to_le64(lock->fl_end - lock->fl_start + 1);
236 cephlock->client = cpu_to_le64(0);
237 cephlock->pid = cpu_to_le64(lock->fl_pid);
238 cephlock->pid_namespace = cpu_to_le64((u64)lock->fl_nspid);
239
240 switch (lock->fl_type) {
241 case F_RDLCK:
242 cephlock->type = CEPH_LOCK_SHARED;
243 break;
244 case F_WRLCK:
245 cephlock->type = CEPH_LOCK_EXCL;
246 break;
247 case F_UNLCK:
248 cephlock->type = CEPH_LOCK_UNLOCK;
249 break;
250 default:
251 dout("Have unknown lock type %d", lock->fl_type);
252 err = -EINVAL;
253 }
254
255 return err;
256}
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index dd440bd438a9..a75ddbf9fe37 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -3,6 +3,7 @@
3#include <linux/wait.h> 3#include <linux/wait.h>
4#include <linux/slab.h> 4#include <linux/slab.h>
5#include <linux/sched.h> 5#include <linux/sched.h>
6#include <linux/smp_lock.h>
6 7
7#include "mds_client.h" 8#include "mds_client.h"
8#include "mon_client.h" 9#include "mon_client.h"
@@ -37,6 +38,11 @@
37 * are no longer valid. 38 * are no longer valid.
38 */ 39 */
39 40
41struct ceph_reconnect_state {
42 struct ceph_pagelist *pagelist;
43 bool flock;
44};
45
40static void __wake_requests(struct ceph_mds_client *mdsc, 46static void __wake_requests(struct ceph_mds_client *mdsc,
41 struct list_head *head); 47 struct list_head *head);
42 48
@@ -449,7 +455,7 @@ void ceph_mdsc_release_request(struct kref *kref)
449 kfree(req->r_path1); 455 kfree(req->r_path1);
450 kfree(req->r_path2); 456 kfree(req->r_path2);
451 put_request_session(req); 457 put_request_session(req);
452 ceph_unreserve_caps(&req->r_caps_reservation); 458 ceph_unreserve_caps(req->r_mdsc, &req->r_caps_reservation);
453 kfree(req); 459 kfree(req);
454} 460}
455 461
@@ -512,7 +518,8 @@ static void __register_request(struct ceph_mds_client *mdsc,
512{ 518{
513 req->r_tid = ++mdsc->last_tid; 519 req->r_tid = ++mdsc->last_tid;
514 if (req->r_num_caps) 520 if (req->r_num_caps)
515 ceph_reserve_caps(&req->r_caps_reservation, req->r_num_caps); 521 ceph_reserve_caps(mdsc, &req->r_caps_reservation,
522 req->r_num_caps);
516 dout("__register_request %p tid %lld\n", req, req->r_tid); 523 dout("__register_request %p tid %lld\n", req, req->r_tid);
517 ceph_mdsc_get_request(req); 524 ceph_mdsc_get_request(req);
518 __insert_request(mdsc, req); 525 __insert_request(mdsc, req);
@@ -704,6 +711,51 @@ static int __open_session(struct ceph_mds_client *mdsc,
704} 711}
705 712
706/* 713/*
714 * open sessions for any export targets for the given mds
715 *
716 * called under mdsc->mutex
717 */
718static void __open_export_target_sessions(struct ceph_mds_client *mdsc,
719 struct ceph_mds_session *session)
720{
721 struct ceph_mds_info *mi;
722 struct ceph_mds_session *ts;
723 int i, mds = session->s_mds;
724 int target;
725
726 if (mds >= mdsc->mdsmap->m_max_mds)
727 return;
728 mi = &mdsc->mdsmap->m_info[mds];
729 dout("open_export_target_sessions for mds%d (%d targets)\n",
730 session->s_mds, mi->num_export_targets);
731
732 for (i = 0; i < mi->num_export_targets; i++) {
733 target = mi->export_targets[i];
734 ts = __ceph_lookup_mds_session(mdsc, target);
735 if (!ts) {
736 ts = register_session(mdsc, target);
737 if (IS_ERR(ts))
738 return;
739 }
740 if (session->s_state == CEPH_MDS_SESSION_NEW ||
741 session->s_state == CEPH_MDS_SESSION_CLOSING)
742 __open_session(mdsc, session);
743 else
744 dout(" mds%d target mds%d %p is %s\n", session->s_mds,
745 i, ts, session_state_name(ts->s_state));
746 ceph_put_mds_session(ts);
747 }
748}
749
750void ceph_mdsc_open_export_target_sessions(struct ceph_mds_client *mdsc,
751 struct ceph_mds_session *session)
752{
753 mutex_lock(&mdsc->mutex);
754 __open_export_target_sessions(mdsc, session);
755 mutex_unlock(&mdsc->mutex);
756}
757
758/*
707 * session caps 759 * session caps
708 */ 760 */
709 761
@@ -764,7 +816,7 @@ static int iterate_session_caps(struct ceph_mds_session *session,
764 last_inode = NULL; 816 last_inode = NULL;
765 } 817 }
766 if (old_cap) { 818 if (old_cap) {
767 ceph_put_cap(old_cap); 819 ceph_put_cap(session->s_mdsc, old_cap);
768 old_cap = NULL; 820 old_cap = NULL;
769 } 821 }
770 822
@@ -793,7 +845,7 @@ out:
793 if (last_inode) 845 if (last_inode)
794 iput(last_inode); 846 iput(last_inode);
795 if (old_cap) 847 if (old_cap)
796 ceph_put_cap(old_cap); 848 ceph_put_cap(session->s_mdsc, old_cap);
797 849
798 return ret; 850 return ret;
799} 851}
@@ -1067,15 +1119,16 @@ static int trim_caps(struct ceph_mds_client *mdsc,
1067 * Called under s_mutex. 1119 * Called under s_mutex.
1068 */ 1120 */
1069int ceph_add_cap_releases(struct ceph_mds_client *mdsc, 1121int ceph_add_cap_releases(struct ceph_mds_client *mdsc,
1070 struct ceph_mds_session *session, 1122 struct ceph_mds_session *session)
1071 int extra)
1072{ 1123{
1073 struct ceph_msg *msg; 1124 struct ceph_msg *msg, *partial = NULL;
1074 struct ceph_mds_cap_release *head; 1125 struct ceph_mds_cap_release *head;
1075 int err = -ENOMEM; 1126 int err = -ENOMEM;
1127 int extra = mdsc->client->mount_args->cap_release_safety;
1128 int num;
1076 1129
1077 if (extra < 0) 1130 dout("add_cap_releases %p mds%d extra %d\n", session, session->s_mds,
1078 extra = mdsc->client->mount_args->cap_release_safety; 1131 extra);
1079 1132
1080 spin_lock(&session->s_cap_lock); 1133 spin_lock(&session->s_cap_lock);
1081 1134
@@ -1084,9 +1137,14 @@ int ceph_add_cap_releases(struct ceph_mds_client *mdsc,
1084 struct ceph_msg, 1137 struct ceph_msg,
1085 list_head); 1138 list_head);
1086 head = msg->front.iov_base; 1139 head = msg->front.iov_base;
1087 extra += CEPH_CAPS_PER_RELEASE - le32_to_cpu(head->num); 1140 num = le32_to_cpu(head->num);
1141 if (num) {
1142 dout(" partial %p with (%d/%d)\n", msg, num,
1143 (int)CEPH_CAPS_PER_RELEASE);
1144 extra += CEPH_CAPS_PER_RELEASE - num;
1145 partial = msg;
1146 }
1088 } 1147 }
1089
1090 while (session->s_num_cap_releases < session->s_nr_caps + extra) { 1148 while (session->s_num_cap_releases < session->s_nr_caps + extra) {
1091 spin_unlock(&session->s_cap_lock); 1149 spin_unlock(&session->s_cap_lock);
1092 msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPRELEASE, PAGE_CACHE_SIZE, 1150 msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPRELEASE, PAGE_CACHE_SIZE,
@@ -1103,19 +1161,14 @@ int ceph_add_cap_releases(struct ceph_mds_client *mdsc,
1103 session->s_num_cap_releases += CEPH_CAPS_PER_RELEASE; 1161 session->s_num_cap_releases += CEPH_CAPS_PER_RELEASE;
1104 } 1162 }
1105 1163
1106 if (!list_empty(&session->s_cap_releases)) { 1164 if (partial) {
1107 msg = list_first_entry(&session->s_cap_releases, 1165 head = partial->front.iov_base;
1108 struct ceph_msg, 1166 num = le32_to_cpu(head->num);
1109 list_head); 1167 dout(" queueing partial %p with %d/%d\n", partial, num,
1110 head = msg->front.iov_base; 1168 (int)CEPH_CAPS_PER_RELEASE);
1111 if (head->num) { 1169 list_move_tail(&partial->list_head,
1112 dout(" queueing non-full %p (%d)\n", msg, 1170 &session->s_cap_releases_done);
1113 le32_to_cpu(head->num)); 1171 session->s_num_cap_releases -= CEPH_CAPS_PER_RELEASE - num;
1114 list_move_tail(&msg->list_head,
1115 &session->s_cap_releases_done);
1116 session->s_num_cap_releases -=
1117 CEPH_CAPS_PER_RELEASE - le32_to_cpu(head->num);
1118 }
1119 } 1172 }
1120 err = 0; 1173 err = 0;
1121 spin_unlock(&session->s_cap_lock); 1174 spin_unlock(&session->s_cap_lock);
@@ -1250,6 +1303,7 @@ ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode)
1250 return ERR_PTR(-ENOMEM); 1303 return ERR_PTR(-ENOMEM);
1251 1304
1252 mutex_init(&req->r_fill_mutex); 1305 mutex_init(&req->r_fill_mutex);
1306 req->r_mdsc = mdsc;
1253 req->r_started = jiffies; 1307 req->r_started = jiffies;
1254 req->r_resend_mds = -1; 1308 req->r_resend_mds = -1;
1255 INIT_LIST_HEAD(&req->r_unsafe_dir_item); 1309 INIT_LIST_HEAD(&req->r_unsafe_dir_item);
@@ -1580,6 +1634,15 @@ static int __prepare_send_request(struct ceph_mds_client *mdsc,
1580 1634
1581 req->r_mds = mds; 1635 req->r_mds = mds;
1582 req->r_attempts++; 1636 req->r_attempts++;
1637 if (req->r_inode) {
1638 struct ceph_cap *cap =
1639 ceph_get_cap_for_mds(ceph_inode(req->r_inode), mds);
1640
1641 if (cap)
1642 req->r_sent_on_mseq = cap->mseq;
1643 else
1644 req->r_sent_on_mseq = -1;
1645 }
1583 dout("prepare_send_request %p tid %lld %s (attempt %d)\n", req, 1646 dout("prepare_send_request %p tid %lld %s (attempt %d)\n", req,
1584 req->r_tid, ceph_mds_op_name(req->r_op), req->r_attempts); 1647 req->r_tid, ceph_mds_op_name(req->r_op), req->r_attempts);
1585 1648
@@ -1914,21 +1977,40 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
1914 result = le32_to_cpu(head->result); 1977 result = le32_to_cpu(head->result);
1915 1978
1916 /* 1979 /*
1917 * Tolerate 2 consecutive ESTALEs from the same mds. 1980 * Handle an ESTALE
1918 * FIXME: we should be looking at the cap migrate_seq. 1981 * if we're not talking to the authority, send to them
1982 * if the authority has changed while we weren't looking,
1983 * send to new authority
1984 * Otherwise we just have to return an ESTALE
1919 */ 1985 */
1920 if (result == -ESTALE) { 1986 if (result == -ESTALE) {
1921 req->r_direct_mode = USE_AUTH_MDS; 1987 dout("got ESTALE on request %llu", req->r_tid);
1922 req->r_num_stale++; 1988 if (!req->r_inode) {
1923 if (req->r_num_stale <= 2) { 1989 /* do nothing; not an authority problem */
1990 } else if (req->r_direct_mode != USE_AUTH_MDS) {
1991 dout("not using auth, setting for that now");
1992 req->r_direct_mode = USE_AUTH_MDS;
1924 __do_request(mdsc, req); 1993 __do_request(mdsc, req);
1925 mutex_unlock(&mdsc->mutex); 1994 mutex_unlock(&mdsc->mutex);
1926 goto out; 1995 goto out;
1996 } else {
1997 struct ceph_inode_info *ci = ceph_inode(req->r_inode);
1998 struct ceph_cap *cap =
1999 ceph_get_cap_for_mds(ci, req->r_mds);;
2000
2001 dout("already using auth");
2002 if ((!cap || cap != ci->i_auth_cap) ||
2003 (cap->mseq != req->r_sent_on_mseq)) {
2004 dout("but cap changed, so resending");
2005 __do_request(mdsc, req);
2006 mutex_unlock(&mdsc->mutex);
2007 goto out;
2008 }
1927 } 2009 }
1928 } else { 2010 dout("have to return ESTALE on request %llu", req->r_tid);
1929 req->r_num_stale = 0;
1930 } 2011 }
1931 2012
2013
1932 if (head->safe) { 2014 if (head->safe) {
1933 req->r_got_safe = true; 2015 req->r_got_safe = true;
1934 __unregister_request(mdsc, req); 2016 __unregister_request(mdsc, req);
@@ -1985,7 +2067,7 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
1985 if (err == 0) { 2067 if (err == 0) {
1986 if (result == 0 && rinfo->dir_nr) 2068 if (result == 0 && rinfo->dir_nr)
1987 ceph_readdir_prepopulate(req, req->r_session); 2069 ceph_readdir_prepopulate(req, req->r_session);
1988 ceph_unreserve_caps(&req->r_caps_reservation); 2070 ceph_unreserve_caps(mdsc, &req->r_caps_reservation);
1989 } 2071 }
1990 mutex_unlock(&req->r_fill_mutex); 2072 mutex_unlock(&req->r_fill_mutex);
1991 2073
@@ -2005,7 +2087,7 @@ out_err:
2005 } 2087 }
2006 mutex_unlock(&mdsc->mutex); 2088 mutex_unlock(&mdsc->mutex);
2007 2089
2008 ceph_add_cap_releases(mdsc, req->r_session, -1); 2090 ceph_add_cap_releases(mdsc, req->r_session);
2009 mutex_unlock(&session->s_mutex); 2091 mutex_unlock(&session->s_mutex);
2010 2092
2011 /* kick calling process */ 2093 /* kick calling process */
@@ -2193,9 +2275,14 @@ static void replay_unsafe_requests(struct ceph_mds_client *mdsc,
2193static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap, 2275static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap,
2194 void *arg) 2276 void *arg)
2195{ 2277{
2196 struct ceph_mds_cap_reconnect rec; 2278 union {
2279 struct ceph_mds_cap_reconnect v2;
2280 struct ceph_mds_cap_reconnect_v1 v1;
2281 } rec;
2282 size_t reclen;
2197 struct ceph_inode_info *ci; 2283 struct ceph_inode_info *ci;
2198 struct ceph_pagelist *pagelist = arg; 2284 struct ceph_reconnect_state *recon_state = arg;
2285 struct ceph_pagelist *pagelist = recon_state->pagelist;
2199 char *path; 2286 char *path;
2200 int pathlen, err; 2287 int pathlen, err;
2201 u64 pathbase; 2288 u64 pathbase;
@@ -2228,17 +2315,44 @@ static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap,
2228 spin_lock(&inode->i_lock); 2315 spin_lock(&inode->i_lock);
2229 cap->seq = 0; /* reset cap seq */ 2316 cap->seq = 0; /* reset cap seq */
2230 cap->issue_seq = 0; /* and issue_seq */ 2317 cap->issue_seq = 0; /* and issue_seq */
2231 rec.cap_id = cpu_to_le64(cap->cap_id); 2318
2232 rec.pathbase = cpu_to_le64(pathbase); 2319 if (recon_state->flock) {
2233 rec.wanted = cpu_to_le32(__ceph_caps_wanted(ci)); 2320 rec.v2.cap_id = cpu_to_le64(cap->cap_id);
2234 rec.issued = cpu_to_le32(cap->issued); 2321 rec.v2.wanted = cpu_to_le32(__ceph_caps_wanted(ci));
2235 rec.size = cpu_to_le64(inode->i_size); 2322 rec.v2.issued = cpu_to_le32(cap->issued);
2236 ceph_encode_timespec(&rec.mtime, &inode->i_mtime); 2323 rec.v2.snaprealm = cpu_to_le64(ci->i_snap_realm->ino);
2237 ceph_encode_timespec(&rec.atime, &inode->i_atime); 2324 rec.v2.pathbase = cpu_to_le64(pathbase);
2238 rec.snaprealm = cpu_to_le64(ci->i_snap_realm->ino); 2325 rec.v2.flock_len = 0;
2326 reclen = sizeof(rec.v2);
2327 } else {
2328 rec.v1.cap_id = cpu_to_le64(cap->cap_id);
2329 rec.v1.wanted = cpu_to_le32(__ceph_caps_wanted(ci));
2330 rec.v1.issued = cpu_to_le32(cap->issued);
2331 rec.v1.size = cpu_to_le64(inode->i_size);
2332 ceph_encode_timespec(&rec.v1.mtime, &inode->i_mtime);
2333 ceph_encode_timespec(&rec.v1.atime, &inode->i_atime);
2334 rec.v1.snaprealm = cpu_to_le64(ci->i_snap_realm->ino);
2335 rec.v1.pathbase = cpu_to_le64(pathbase);
2336 reclen = sizeof(rec.v1);
2337 }
2239 spin_unlock(&inode->i_lock); 2338 spin_unlock(&inode->i_lock);
2240 2339
2241 err = ceph_pagelist_append(pagelist, &rec, sizeof(rec)); 2340 if (recon_state->flock) {
2341 int num_fcntl_locks, num_flock_locks;
2342
2343 lock_kernel();
2344 ceph_count_locks(inode, &num_fcntl_locks, &num_flock_locks);
2345 rec.v2.flock_len = (2*sizeof(u32) +
2346 (num_fcntl_locks+num_flock_locks) *
2347 sizeof(struct ceph_filelock));
2348
2349 err = ceph_pagelist_append(pagelist, &rec, reclen);
2350 if (!err)
2351 err = ceph_encode_locks(inode, pagelist,
2352 num_fcntl_locks,
2353 num_flock_locks);
2354 unlock_kernel();
2355 }
2242 2356
2243out: 2357out:
2244 kfree(path); 2358 kfree(path);
@@ -2267,6 +2381,7 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc,
2267 int mds = session->s_mds; 2381 int mds = session->s_mds;
2268 int err = -ENOMEM; 2382 int err = -ENOMEM;
2269 struct ceph_pagelist *pagelist; 2383 struct ceph_pagelist *pagelist;
2384 struct ceph_reconnect_state recon_state;
2270 2385
2271 pr_info("mds%d reconnect start\n", mds); 2386 pr_info("mds%d reconnect start\n", mds);
2272 2387
@@ -2301,7 +2416,10 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc,
2301 err = ceph_pagelist_encode_32(pagelist, session->s_nr_caps); 2416 err = ceph_pagelist_encode_32(pagelist, session->s_nr_caps);
2302 if (err) 2417 if (err)
2303 goto fail; 2418 goto fail;
2304 err = iterate_session_caps(session, encode_caps_cb, pagelist); 2419
2420 recon_state.pagelist = pagelist;
2421 recon_state.flock = session->s_con.peer_features & CEPH_FEATURE_FLOCK;
2422 err = iterate_session_caps(session, encode_caps_cb, &recon_state);
2305 if (err < 0) 2423 if (err < 0)
2306 goto fail; 2424 goto fail;
2307 2425
@@ -2326,6 +2444,8 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc,
2326 } 2444 }
2327 2445
2328 reply->pagelist = pagelist; 2446 reply->pagelist = pagelist;
2447 if (recon_state.flock)
2448 reply->hdr.version = cpu_to_le16(2);
2329 reply->hdr.data_len = cpu_to_le32(pagelist->length); 2449 reply->hdr.data_len = cpu_to_le32(pagelist->length);
2330 reply->nr_pages = calc_pages_for(0, pagelist->length); 2450 reply->nr_pages = calc_pages_for(0, pagelist->length);
2331 ceph_con_send(&session->s_con, reply); 2451 ceph_con_send(&session->s_con, reply);
@@ -2376,9 +2496,11 @@ static void check_new_map(struct ceph_mds_client *mdsc,
2376 oldstate = ceph_mdsmap_get_state(oldmap, i); 2496 oldstate = ceph_mdsmap_get_state(oldmap, i);
2377 newstate = ceph_mdsmap_get_state(newmap, i); 2497 newstate = ceph_mdsmap_get_state(newmap, i);
2378 2498
2379 dout("check_new_map mds%d state %s -> %s (session %s)\n", 2499 dout("check_new_map mds%d state %s%s -> %s%s (session %s)\n",
2380 i, ceph_mds_state_name(oldstate), 2500 i, ceph_mds_state_name(oldstate),
2501 ceph_mdsmap_is_laggy(oldmap, i) ? " (laggy)" : "",
2381 ceph_mds_state_name(newstate), 2502 ceph_mds_state_name(newstate),
2503 ceph_mdsmap_is_laggy(newmap, i) ? " (laggy)" : "",
2382 session_state_name(s->s_state)); 2504 session_state_name(s->s_state));
2383 2505
2384 if (memcmp(ceph_mdsmap_get_addr(oldmap, i), 2506 if (memcmp(ceph_mdsmap_get_addr(oldmap, i),
@@ -2428,6 +2550,21 @@ static void check_new_map(struct ceph_mds_client *mdsc,
2428 wake_up_session_caps(s, 1); 2550 wake_up_session_caps(s, 1);
2429 } 2551 }
2430 } 2552 }
2553
2554 for (i = 0; i < newmap->m_max_mds && i < mdsc->max_sessions; i++) {
2555 s = mdsc->sessions[i];
2556 if (!s)
2557 continue;
2558 if (!ceph_mdsmap_is_laggy(newmap, i))
2559 continue;
2560 if (s->s_state == CEPH_MDS_SESSION_OPEN ||
2561 s->s_state == CEPH_MDS_SESSION_HUNG ||
2562 s->s_state == CEPH_MDS_SESSION_CLOSING) {
2563 dout(" connecting to export targets of laggy mds%d\n",
2564 i);
2565 __open_export_target_sessions(mdsc, s);
2566 }
2567 }
2431} 2568}
2432 2569
2433 2570
@@ -2715,7 +2852,7 @@ static void delayed_work(struct work_struct *work)
2715 send_renew_caps(mdsc, s); 2852 send_renew_caps(mdsc, s);
2716 else 2853 else
2717 ceph_con_keepalive(&s->s_con); 2854 ceph_con_keepalive(&s->s_con);
2718 ceph_add_cap_releases(mdsc, s, -1); 2855 ceph_add_cap_releases(mdsc, s);
2719 if (s->s_state == CEPH_MDS_SESSION_OPEN || 2856 if (s->s_state == CEPH_MDS_SESSION_OPEN ||
2720 s->s_state == CEPH_MDS_SESSION_HUNG) 2857 s->s_state == CEPH_MDS_SESSION_HUNG)
2721 ceph_send_cap_releases(mdsc, s); 2858 ceph_send_cap_releases(mdsc, s);
@@ -2764,6 +2901,9 @@ int ceph_mdsc_init(struct ceph_mds_client *mdsc, struct ceph_client *client)
2764 spin_lock_init(&mdsc->dentry_lru_lock); 2901 spin_lock_init(&mdsc->dentry_lru_lock);
2765 INIT_LIST_HEAD(&mdsc->dentry_lru); 2902 INIT_LIST_HEAD(&mdsc->dentry_lru);
2766 2903
2904 ceph_caps_init(mdsc);
2905 ceph_adjust_min_caps(mdsc, client->min_caps);
2906
2767 return 0; 2907 return 0;
2768} 2908}
2769 2909
@@ -2959,6 +3099,7 @@ void ceph_mdsc_stop(struct ceph_mds_client *mdsc)
2959 if (mdsc->mdsmap) 3099 if (mdsc->mdsmap)
2960 ceph_mdsmap_destroy(mdsc->mdsmap); 3100 ceph_mdsmap_destroy(mdsc->mdsmap);
2961 kfree(mdsc->sessions); 3101 kfree(mdsc->sessions);
3102 ceph_caps_finalize(mdsc);
2962} 3103}
2963 3104
2964 3105
diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
index 952410c60d09..ab7e89f5e344 100644
--- a/fs/ceph/mds_client.h
+++ b/fs/ceph/mds_client.h
@@ -151,6 +151,7 @@ typedef void (*ceph_mds_request_callback_t) (struct ceph_mds_client *mdsc,
151struct ceph_mds_request { 151struct ceph_mds_request {
152 u64 r_tid; /* transaction id */ 152 u64 r_tid; /* transaction id */
153 struct rb_node r_node; 153 struct rb_node r_node;
154 struct ceph_mds_client *r_mdsc;
154 155
155 int r_op; /* mds op code */ 156 int r_op; /* mds op code */
156 int r_mds; 157 int r_mds;
@@ -207,8 +208,8 @@ struct ceph_mds_request {
207 208
208 int r_attempts; /* resend attempts */ 209 int r_attempts; /* resend attempts */
209 int r_num_fwd; /* number of forward attempts */ 210 int r_num_fwd; /* number of forward attempts */
210 int r_num_stale;
211 int r_resend_mds; /* mds to resend to next, if any*/ 211 int r_resend_mds; /* mds to resend to next, if any*/
212 u32 r_sent_on_mseq; /* cap mseq request was sent at*/
212 213
213 struct kref r_kref; 214 struct kref r_kref;
214 struct list_head r_wait; 215 struct list_head r_wait;
@@ -267,6 +268,27 @@ struct ceph_mds_client {
267 spinlock_t cap_dirty_lock; /* protects above items */ 268 spinlock_t cap_dirty_lock; /* protects above items */
268 wait_queue_head_t cap_flushing_wq; 269 wait_queue_head_t cap_flushing_wq;
269 270
271 /*
272 * Cap reservations
273 *
274 * Maintain a global pool of preallocated struct ceph_caps, referenced
275 * by struct ceph_caps_reservations. This ensures that we preallocate
276 * memory needed to successfully process an MDS response. (If an MDS
277 * sends us cap information and we fail to process it, we will have
278 * problems due to the client and MDS being out of sync.)
279 *
280 * Reservations are 'owned' by a ceph_cap_reservation context.
281 */
282 spinlock_t caps_list_lock;
283 struct list_head caps_list; /* unused (reserved or
284 unreserved) */
285 int caps_total_count; /* total caps allocated */
286 int caps_use_count; /* in use */
287 int caps_reserve_count; /* unused, reserved */
288 int caps_avail_count; /* unused, unreserved */
289 int caps_min_count; /* keep at least this many
290 (unreserved) */
291
270#ifdef CONFIG_DEBUG_FS 292#ifdef CONFIG_DEBUG_FS
271 struct dentry *debugfs_file; 293 struct dentry *debugfs_file;
272#endif 294#endif
@@ -324,8 +346,7 @@ static inline void ceph_mdsc_put_request(struct ceph_mds_request *req)
324} 346}
325 347
326extern int ceph_add_cap_releases(struct ceph_mds_client *mdsc, 348extern int ceph_add_cap_releases(struct ceph_mds_client *mdsc,
327 struct ceph_mds_session *session, 349 struct ceph_mds_session *session);
328 int extra);
329extern void ceph_send_cap_releases(struct ceph_mds_client *mdsc, 350extern void ceph_send_cap_releases(struct ceph_mds_client *mdsc,
330 struct ceph_mds_session *session); 351 struct ceph_mds_session *session);
331 352
@@ -343,4 +364,7 @@ extern void ceph_mdsc_lease_send_msg(struct ceph_mds_session *session,
343extern void ceph_mdsc_handle_map(struct ceph_mds_client *mdsc, 364extern void ceph_mdsc_handle_map(struct ceph_mds_client *mdsc,
344 struct ceph_msg *msg); 365 struct ceph_msg *msg);
345 366
367extern void ceph_mdsc_open_export_target_sessions(struct ceph_mds_client *mdsc,
368 struct ceph_mds_session *session);
369
346#endif 370#endif
diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c
index c4c498e6dfef..040be6d1150b 100644
--- a/fs/ceph/mdsmap.c
+++ b/fs/ceph/mdsmap.c
@@ -85,6 +85,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
85 struct ceph_entity_addr addr; 85 struct ceph_entity_addr addr;
86 u32 num_export_targets; 86 u32 num_export_targets;
87 void *pexport_targets = NULL; 87 void *pexport_targets = NULL;
88 struct ceph_timespec laggy_since;
88 89
89 ceph_decode_need(p, end, sizeof(u64)*2 + 1 + sizeof(u32), bad); 90 ceph_decode_need(p, end, sizeof(u64)*2 + 1 + sizeof(u32), bad);
90 global_id = ceph_decode_64(p); 91 global_id = ceph_decode_64(p);
@@ -103,7 +104,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
103 state_seq = ceph_decode_64(p); 104 state_seq = ceph_decode_64(p);
104 ceph_decode_copy(p, &addr, sizeof(addr)); 105 ceph_decode_copy(p, &addr, sizeof(addr));
105 ceph_decode_addr(&addr); 106 ceph_decode_addr(&addr);
106 *p += sizeof(struct ceph_timespec); 107 ceph_decode_copy(p, &laggy_since, sizeof(laggy_since));
107 *p += sizeof(u32); 108 *p += sizeof(u32);
108 ceph_decode_32_safe(p, end, namelen, bad); 109 ceph_decode_32_safe(p, end, namelen, bad);
109 *p += namelen; 110 *p += namelen;
@@ -122,6 +123,9 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
122 m->m_info[mds].global_id = global_id; 123 m->m_info[mds].global_id = global_id;
123 m->m_info[mds].state = state; 124 m->m_info[mds].state = state;
124 m->m_info[mds].addr = addr; 125 m->m_info[mds].addr = addr;
126 m->m_info[mds].laggy =
127 (laggy_since.tv_sec != 0 ||
128 laggy_since.tv_nsec != 0);
125 m->m_info[mds].num_export_targets = num_export_targets; 129 m->m_info[mds].num_export_targets = num_export_targets;
126 if (num_export_targets) { 130 if (num_export_targets) {
127 m->m_info[mds].export_targets = 131 m->m_info[mds].export_targets =
diff --git a/fs/ceph/mdsmap.h b/fs/ceph/mdsmap.h
index eacc131aa5cb..4c5cb0880bba 100644
--- a/fs/ceph/mdsmap.h
+++ b/fs/ceph/mdsmap.h
@@ -13,6 +13,7 @@ struct ceph_mds_info {
13 struct ceph_entity_addr addr; 13 struct ceph_entity_addr addr;
14 s32 state; 14 s32 state;
15 int num_export_targets; 15 int num_export_targets;
16 bool laggy;
16 u32 *export_targets; 17 u32 *export_targets;
17}; 18};
18 19
@@ -47,6 +48,13 @@ static inline int ceph_mdsmap_get_state(struct ceph_mdsmap *m, int w)
47 return m->m_info[w].state; 48 return m->m_info[w].state;
48} 49}
49 50
51static inline bool ceph_mdsmap_is_laggy(struct ceph_mdsmap *m, int w)
52{
53 if (w >= 0 && w < m->m_max_mds)
54 return m->m_info[w].laggy;
55 return false;
56}
57
50extern int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m); 58extern int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m);
51extern struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end); 59extern struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end);
52extern void ceph_mdsmap_destroy(struct ceph_mdsmap *m); 60extern void ceph_mdsmap_destroy(struct ceph_mdsmap *m);
diff --git a/fs/ceph/messenger.c b/fs/ceph/messenger.c
index 15167b2daa55..2502d76fcec1 100644
--- a/fs/ceph/messenger.c
+++ b/fs/ceph/messenger.c
@@ -108,7 +108,7 @@ void ceph_msgr_exit(void)
108 destroy_workqueue(ceph_msgr_wq); 108 destroy_workqueue(ceph_msgr_wq);
109} 109}
110 110
111void ceph_msgr_flush() 111void ceph_msgr_flush(void)
112{ 112{
113 flush_workqueue(ceph_msgr_wq); 113 flush_workqueue(ceph_msgr_wq);
114} 114}
@@ -647,7 +647,7 @@ static void prepare_write_connect(struct ceph_messenger *msgr,
647 dout("prepare_write_connect %p cseq=%d gseq=%d proto=%d\n", con, 647 dout("prepare_write_connect %p cseq=%d gseq=%d proto=%d\n", con,
648 con->connect_seq, global_seq, proto); 648 con->connect_seq, global_seq, proto);
649 649
650 con->out_connect.features = cpu_to_le64(CEPH_FEATURE_SUPPORTED_CLIENT); 650 con->out_connect.features = cpu_to_le64(CEPH_FEATURE_SUPPORTED);
651 con->out_connect.host_type = cpu_to_le32(CEPH_ENTITY_TYPE_CLIENT); 651 con->out_connect.host_type = cpu_to_le32(CEPH_ENTITY_TYPE_CLIENT);
652 con->out_connect.connect_seq = cpu_to_le32(con->connect_seq); 652 con->out_connect.connect_seq = cpu_to_le32(con->connect_seq);
653 con->out_connect.global_seq = cpu_to_le32(global_seq); 653 con->out_connect.global_seq = cpu_to_le32(global_seq);
@@ -1081,11 +1081,11 @@ static int process_banner(struct ceph_connection *con)
1081 sizeof(con->peer_addr)) != 0 && 1081 sizeof(con->peer_addr)) != 0 &&
1082 !(addr_is_blank(&con->actual_peer_addr.in_addr) && 1082 !(addr_is_blank(&con->actual_peer_addr.in_addr) &&
1083 con->actual_peer_addr.nonce == con->peer_addr.nonce)) { 1083 con->actual_peer_addr.nonce == con->peer_addr.nonce)) {
1084 pr_warning("wrong peer, want %s/%lld, got %s/%lld\n", 1084 pr_warning("wrong peer, want %s/%d, got %s/%d\n",
1085 pr_addr(&con->peer_addr.in_addr), 1085 pr_addr(&con->peer_addr.in_addr),
1086 le64_to_cpu(con->peer_addr.nonce), 1086 (int)le32_to_cpu(con->peer_addr.nonce),
1087 pr_addr(&con->actual_peer_addr.in_addr), 1087 pr_addr(&con->actual_peer_addr.in_addr),
1088 le64_to_cpu(con->actual_peer_addr.nonce)); 1088 (int)le32_to_cpu(con->actual_peer_addr.nonce));
1089 con->error_msg = "wrong peer at address"; 1089 con->error_msg = "wrong peer at address";
1090 return -1; 1090 return -1;
1091 } 1091 }
@@ -1123,8 +1123,8 @@ static void fail_protocol(struct ceph_connection *con)
1123 1123
1124static int process_connect(struct ceph_connection *con) 1124static int process_connect(struct ceph_connection *con)
1125{ 1125{
1126 u64 sup_feat = CEPH_FEATURE_SUPPORTED_CLIENT; 1126 u64 sup_feat = CEPH_FEATURE_SUPPORTED;
1127 u64 req_feat = CEPH_FEATURE_REQUIRED_CLIENT; 1127 u64 req_feat = CEPH_FEATURE_REQUIRED;
1128 u64 server_feat = le64_to_cpu(con->in_reply.features); 1128 u64 server_feat = le64_to_cpu(con->in_reply.features);
1129 1129
1130 dout("process_connect on %p tag %d\n", con, (int)con->in_tag); 1130 dout("process_connect on %p tag %d\n", con, (int)con->in_tag);
@@ -1302,8 +1302,8 @@ static void process_ack(struct ceph_connection *con)
1302 1302
1303 1303
1304static int read_partial_message_section(struct ceph_connection *con, 1304static int read_partial_message_section(struct ceph_connection *con,
1305 struct kvec *section, unsigned int sec_len, 1305 struct kvec *section,
1306 u32 *crc) 1306 unsigned int sec_len, u32 *crc)
1307{ 1307{
1308 int left; 1308 int left;
1309 int ret; 1309 int ret;
@@ -1434,7 +1434,8 @@ static int read_partial_message(struct ceph_connection *con)
1434 1434
1435 /* middle */ 1435 /* middle */
1436 if (m->middle) { 1436 if (m->middle) {
1437 ret = read_partial_message_section(con, &m->middle->vec, middle_len, 1437 ret = read_partial_message_section(con, &m->middle->vec,
1438 middle_len,
1438 &con->in_middle_crc); 1439 &con->in_middle_crc);
1439 if (ret <= 0) 1440 if (ret <= 0)
1440 return ret; 1441 return ret;
@@ -1920,7 +1921,7 @@ out:
1920 /* 1921 /*
1921 * in case we faulted due to authentication, invalidate our 1922 * in case we faulted due to authentication, invalidate our
1922 * current tickets so that we can get new ones. 1923 * current tickets so that we can get new ones.
1923 */ 1924 */
1924 if (con->auth_retry && con->ops->invalidate_authorizer) { 1925 if (con->auth_retry && con->ops->invalidate_authorizer) {
1925 dout("calling invalidate_authorizer()\n"); 1926 dout("calling invalidate_authorizer()\n");
1926 con->ops->invalidate_authorizer(con); 1927 con->ops->invalidate_authorizer(con);
diff --git a/fs/ceph/mon_client.c b/fs/ceph/mon_client.c
index 54fe01c50706..b2a5a3e4a671 100644
--- a/fs/ceph/mon_client.c
+++ b/fs/ceph/mon_client.c
@@ -349,7 +349,7 @@ out:
349} 349}
350 350
351/* 351/*
352 * statfs 352 * generic requests (e.g., statfs, poolop)
353 */ 353 */
354static struct ceph_mon_generic_request *__lookup_generic_req( 354static struct ceph_mon_generic_request *__lookup_generic_req(
355 struct ceph_mon_client *monc, u64 tid) 355 struct ceph_mon_client *monc, u64 tid)
@@ -442,6 +442,35 @@ static struct ceph_msg *get_generic_reply(struct ceph_connection *con,
442 return m; 442 return m;
443} 443}
444 444
445static int do_generic_request(struct ceph_mon_client *monc,
446 struct ceph_mon_generic_request *req)
447{
448 int err;
449
450 /* register request */
451 mutex_lock(&monc->mutex);
452 req->tid = ++monc->last_tid;
453 req->request->hdr.tid = cpu_to_le64(req->tid);
454 __insert_generic_request(monc, req);
455 monc->num_generic_requests++;
456 ceph_con_send(monc->con, ceph_msg_get(req->request));
457 mutex_unlock(&monc->mutex);
458
459 err = wait_for_completion_interruptible(&req->completion);
460
461 mutex_lock(&monc->mutex);
462 rb_erase(&req->node, &monc->generic_request_tree);
463 monc->num_generic_requests--;
464 mutex_unlock(&monc->mutex);
465
466 if (!err)
467 err = req->result;
468 return err;
469}
470
471/*
472 * statfs
473 */
445static void handle_statfs_reply(struct ceph_mon_client *monc, 474static void handle_statfs_reply(struct ceph_mon_client *monc,
446 struct ceph_msg *msg) 475 struct ceph_msg *msg)
447{ 476{
@@ -468,7 +497,7 @@ static void handle_statfs_reply(struct ceph_mon_client *monc,
468 return; 497 return;
469 498
470bad: 499bad:
471 pr_err("corrupt generic reply, no tid\n"); 500 pr_err("corrupt generic reply, tid %llu\n", tid);
472 ceph_msg_dump(msg); 501 ceph_msg_dump(msg);
473} 502}
474 503
@@ -487,6 +516,7 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
487 516
488 kref_init(&req->kref); 517 kref_init(&req->kref);
489 req->buf = buf; 518 req->buf = buf;
519 req->buf_len = sizeof(*buf);
490 init_completion(&req->completion); 520 init_completion(&req->completion);
491 521
492 err = -ENOMEM; 522 err = -ENOMEM;
@@ -504,33 +534,134 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
504 h->monhdr.session_mon_tid = 0; 534 h->monhdr.session_mon_tid = 0;
505 h->fsid = monc->monmap->fsid; 535 h->fsid = monc->monmap->fsid;
506 536
507 /* register request */ 537 err = do_generic_request(monc, req);
508 mutex_lock(&monc->mutex);
509 req->tid = ++monc->last_tid;
510 req->request->hdr.tid = cpu_to_le64(req->tid);
511 __insert_generic_request(monc, req);
512 monc->num_generic_requests++;
513 mutex_unlock(&monc->mutex);
514 538
515 /* send request and wait */ 539out:
516 ceph_con_send(monc->con, ceph_msg_get(req->request)); 540 kref_put(&req->kref, release_generic_request);
517 err = wait_for_completion_interruptible(&req->completion); 541 return err;
542}
543
544/*
545 * pool ops
546 */
547static int get_poolop_reply_buf(const char *src, size_t src_len,
548 char *dst, size_t dst_len)
549{
550 u32 buf_len;
551
552 if (src_len != sizeof(u32) + dst_len)
553 return -EINVAL;
554
555 buf_len = le32_to_cpu(*(u32 *)src);
556 if (buf_len != dst_len)
557 return -EINVAL;
558
559 memcpy(dst, src + sizeof(u32), dst_len);
560 return 0;
561}
562
563static void handle_poolop_reply(struct ceph_mon_client *monc,
564 struct ceph_msg *msg)
565{
566 struct ceph_mon_generic_request *req;
567 struct ceph_mon_poolop_reply *reply = msg->front.iov_base;
568 u64 tid = le64_to_cpu(msg->hdr.tid);
569
570 if (msg->front.iov_len < sizeof(*reply))
571 goto bad;
572 dout("handle_poolop_reply %p tid %llu\n", msg, tid);
518 573
519 mutex_lock(&monc->mutex); 574 mutex_lock(&monc->mutex);
520 rb_erase(&req->node, &monc->generic_request_tree); 575 req = __lookup_generic_req(monc, tid);
521 monc->num_generic_requests--; 576 if (req) {
577 if (req->buf_len &&
578 get_poolop_reply_buf(msg->front.iov_base + sizeof(*reply),
579 msg->front.iov_len - sizeof(*reply),
580 req->buf, req->buf_len) < 0) {
581 mutex_unlock(&monc->mutex);
582 goto bad;
583 }
584 req->result = le32_to_cpu(reply->reply_code);
585 get_generic_request(req);
586 }
522 mutex_unlock(&monc->mutex); 587 mutex_unlock(&monc->mutex);
588 if (req) {
589 complete(&req->completion);
590 put_generic_request(req);
591 }
592 return;
523 593
524 if (!err) 594bad:
525 err = req->result; 595 pr_err("corrupt generic reply, tid %llu\n", tid);
596 ceph_msg_dump(msg);
597}
598
599/*
600 * Do a synchronous pool op.
601 */
602int ceph_monc_do_poolop(struct ceph_mon_client *monc, u32 op,
603 u32 pool, u64 snapid,
604 char *buf, int len)
605{
606 struct ceph_mon_generic_request *req;
607 struct ceph_mon_poolop *h;
608 int err;
609
610 req = kzalloc(sizeof(*req), GFP_NOFS);
611 if (!req)
612 return -ENOMEM;
613
614 kref_init(&req->kref);
615 req->buf = buf;
616 req->buf_len = len;
617 init_completion(&req->completion);
618
619 err = -ENOMEM;
620 req->request = ceph_msg_new(CEPH_MSG_POOLOP, sizeof(*h), GFP_NOFS);
621 if (!req->request)
622 goto out;
623 req->reply = ceph_msg_new(CEPH_MSG_POOLOP_REPLY, 1024, GFP_NOFS);
624 if (!req->reply)
625 goto out;
626
627 /* fill out request */
628 req->request->hdr.version = cpu_to_le16(2);
629 h = req->request->front.iov_base;
630 h->monhdr.have_version = 0;
631 h->monhdr.session_mon = cpu_to_le16(-1);
632 h->monhdr.session_mon_tid = 0;
633 h->fsid = monc->monmap->fsid;
634 h->pool = cpu_to_le32(pool);
635 h->op = cpu_to_le32(op);
636 h->auid = 0;
637 h->snapid = cpu_to_le64(snapid);
638 h->name_len = 0;
639
640 err = do_generic_request(monc, req);
526 641
527out: 642out:
528 kref_put(&req->kref, release_generic_request); 643 kref_put(&req->kref, release_generic_request);
529 return err; 644 return err;
530} 645}
531 646
647int ceph_monc_create_snapid(struct ceph_mon_client *monc,
648 u32 pool, u64 *snapid)
649{
650 return ceph_monc_do_poolop(monc, POOL_OP_CREATE_UNMANAGED_SNAP,
651 pool, 0, (char *)snapid, sizeof(*snapid));
652
653}
654
655int ceph_monc_delete_snapid(struct ceph_mon_client *monc,
656 u32 pool, u64 snapid)
657{
658 return ceph_monc_do_poolop(monc, POOL_OP_CREATE_UNMANAGED_SNAP,
659 pool, snapid, 0, 0);
660
661}
662
532/* 663/*
533 * Resend pending statfs requests. 664 * Resend pending generic requests.
534 */ 665 */
535static void __resend_generic_request(struct ceph_mon_client *monc) 666static void __resend_generic_request(struct ceph_mon_client *monc)
536{ 667{
@@ -783,6 +914,10 @@ static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
783 handle_statfs_reply(monc, msg); 914 handle_statfs_reply(monc, msg);
784 break; 915 break;
785 916
917 case CEPH_MSG_POOLOP_REPLY:
918 handle_poolop_reply(monc, msg);
919 break;
920
786 case CEPH_MSG_MON_MAP: 921 case CEPH_MSG_MON_MAP:
787 ceph_monc_handle_map(monc, msg); 922 ceph_monc_handle_map(monc, msg);
788 break; 923 break;
@@ -820,6 +955,7 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
820 case CEPH_MSG_MON_SUBSCRIBE_ACK: 955 case CEPH_MSG_MON_SUBSCRIBE_ACK:
821 m = ceph_msg_get(monc->m_subscribe_ack); 956 m = ceph_msg_get(monc->m_subscribe_ack);
822 break; 957 break;
958 case CEPH_MSG_POOLOP_REPLY:
823 case CEPH_MSG_STATFS_REPLY: 959 case CEPH_MSG_STATFS_REPLY:
824 return get_generic_reply(con, hdr, skip); 960 return get_generic_reply(con, hdr, skip);
825 case CEPH_MSG_AUTH_REPLY: 961 case CEPH_MSG_AUTH_REPLY:
diff --git a/fs/ceph/mon_client.h b/fs/ceph/mon_client.h
index 174d794321d0..8e396f2c0963 100644
--- a/fs/ceph/mon_client.h
+++ b/fs/ceph/mon_client.h
@@ -50,6 +50,7 @@ struct ceph_mon_generic_request {
50 struct rb_node node; 50 struct rb_node node;
51 int result; 51 int result;
52 void *buf; 52 void *buf;
53 int buf_len;
53 struct completion completion; 54 struct completion completion;
54 struct ceph_msg *request; /* original request */ 55 struct ceph_msg *request; /* original request */
55 struct ceph_msg *reply; /* and reply */ 56 struct ceph_msg *reply; /* and reply */
@@ -111,6 +112,10 @@ extern int ceph_monc_open_session(struct ceph_mon_client *monc);
111 112
112extern int ceph_monc_validate_auth(struct ceph_mon_client *monc); 113extern int ceph_monc_validate_auth(struct ceph_mon_client *monc);
113 114
115extern int ceph_monc_create_snapid(struct ceph_mon_client *monc,
116 u32 pool, u64 *snapid);
114 117
118extern int ceph_monc_delete_snapid(struct ceph_mon_client *monc,
119 u32 pool, u64 snapid);
115 120
116#endif 121#endif
diff --git a/fs/ceph/msgr.h b/fs/ceph/msgr.h
index 892a0298dfdf..680d3d648cac 100644
--- a/fs/ceph/msgr.h
+++ b/fs/ceph/msgr.h
@@ -1,5 +1,5 @@
1#ifndef __MSGR_H 1#ifndef CEPH_MSGR_H
2#define __MSGR_H 2#define CEPH_MSGR_H
3 3
4/* 4/*
5 * Data types for message passing layer used by Ceph. 5 * Data types for message passing layer used by Ceph.
diff --git a/fs/ceph/osd_client.c b/fs/ceph/osd_client.c
index e38522347898..bed6391e52c7 100644
--- a/fs/ceph/osd_client.c
+++ b/fs/ceph/osd_client.c
@@ -1276,8 +1276,6 @@ int ceph_osdc_readpages(struct ceph_osd_client *osdc,
1276 1276
1277 /* it may be a short read due to an object boundary */ 1277 /* it may be a short read due to an object boundary */
1278 req->r_pages = pages; 1278 req->r_pages = pages;
1279 num_pages = calc_pages_for(off, *plen);
1280 req->r_num_pages = num_pages;
1281 1279
1282 dout("readpages final extent is %llu~%llu (%d pages)\n", 1280 dout("readpages final extent is %llu~%llu (%d pages)\n",
1283 off, *plen, req->r_num_pages); 1281 off, *plen, req->r_num_pages);
@@ -1319,7 +1317,6 @@ int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
1319 1317
1320 /* it may be a short write due to an object boundary */ 1318 /* it may be a short write due to an object boundary */
1321 req->r_pages = pages; 1319 req->r_pages = pages;
1322 req->r_num_pages = calc_pages_for(off, len);
1323 dout("writepages %llu~%llu (%d pages)\n", off, len, 1320 dout("writepages %llu~%llu (%d pages)\n", off, len,
1324 req->r_num_pages); 1321 req->r_num_pages);
1325 1322
@@ -1476,8 +1473,8 @@ static void put_osd_con(struct ceph_connection *con)
1476 * authentication 1473 * authentication
1477 */ 1474 */
1478static int get_authorizer(struct ceph_connection *con, 1475static int get_authorizer(struct ceph_connection *con,
1479 void **buf, int *len, int *proto, 1476 void **buf, int *len, int *proto,
1480 void **reply_buf, int *reply_len, int force_new) 1477 void **reply_buf, int *reply_len, int force_new)
1481{ 1478{
1482 struct ceph_osd *o = con->private; 1479 struct ceph_osd *o = con->private;
1483 struct ceph_osd_client *osdc = o->o_osdc; 1480 struct ceph_osd_client *osdc = o->o_osdc;
@@ -1497,7 +1494,7 @@ static int get_authorizer(struct ceph_connection *con,
1497 &o->o_authorizer_reply_buf, 1494 &o->o_authorizer_reply_buf,
1498 &o->o_authorizer_reply_buf_len); 1495 &o->o_authorizer_reply_buf_len);
1499 if (ret) 1496 if (ret)
1500 return ret; 1497 return ret;
1501 } 1498 }
1502 1499
1503 *proto = ac->protocol; 1500 *proto = ac->protocol;
diff --git a/fs/ceph/osdmap.c b/fs/ceph/osdmap.c
index 416d46adbf87..e31f118f1392 100644
--- a/fs/ceph/osdmap.c
+++ b/fs/ceph/osdmap.c
@@ -424,12 +424,30 @@ static void __remove_pg_pool(struct rb_root *root, struct ceph_pg_pool_info *pi)
424 kfree(pi); 424 kfree(pi);
425} 425}
426 426
427void __decode_pool(void **p, struct ceph_pg_pool_info *pi) 427static int __decode_pool(void **p, void *end, struct ceph_pg_pool_info *pi)
428{ 428{
429 unsigned n, m;
430
429 ceph_decode_copy(p, &pi->v, sizeof(pi->v)); 431 ceph_decode_copy(p, &pi->v, sizeof(pi->v));
430 calc_pg_masks(pi); 432 calc_pg_masks(pi);
431 *p += le32_to_cpu(pi->v.num_snaps) * sizeof(u64); 433
434 /* num_snaps * snap_info_t */
435 n = le32_to_cpu(pi->v.num_snaps);
436 while (n--) {
437 ceph_decode_need(p, end, sizeof(u64) + 1 + sizeof(u64) +
438 sizeof(struct ceph_timespec), bad);
439 *p += sizeof(u64) + /* key */
440 1 + sizeof(u64) + /* u8, snapid */
441 sizeof(struct ceph_timespec);
442 m = ceph_decode_32(p); /* snap name */
443 *p += m;
444 }
445
432 *p += le32_to_cpu(pi->v.num_removed_snap_intervals) * sizeof(u64) * 2; 446 *p += le32_to_cpu(pi->v.num_removed_snap_intervals) * sizeof(u64) * 2;
447 return 0;
448
449bad:
450 return -EINVAL;
433} 451}
434 452
435static int __decode_pool_names(void **p, void *end, struct ceph_osdmap *map) 453static int __decode_pool_names(void **p, void *end, struct ceph_osdmap *map)
@@ -571,7 +589,9 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end)
571 kfree(pi); 589 kfree(pi);
572 goto bad; 590 goto bad;
573 } 591 }
574 __decode_pool(p, pi); 592 err = __decode_pool(p, end, pi);
593 if (err < 0)
594 goto bad;
575 __insert_pg_pool(&map->pg_pools, pi); 595 __insert_pg_pool(&map->pg_pools, pi);
576 } 596 }
577 597
@@ -760,7 +780,9 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
760 pi->id = pool; 780 pi->id = pool;
761 __insert_pg_pool(&map->pg_pools, pi); 781 __insert_pg_pool(&map->pg_pools, pi);
762 } 782 }
763 __decode_pool(p, pi); 783 err = __decode_pool(p, end, pi);
784 if (err < 0)
785 goto bad;
764 } 786 }
765 if (version >= 5 && __decode_pool_names(p, end, map) < 0) 787 if (version >= 5 && __decode_pool_names(p, end, map) < 0)
766 goto bad; 788 goto bad;
@@ -833,7 +855,7 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
833 node)->pgid, pgid) <= 0) { 855 node)->pgid, pgid) <= 0) {
834 struct ceph_pg_mapping *cur = 856 struct ceph_pg_mapping *cur =
835 rb_entry(rbp, struct ceph_pg_mapping, node); 857 rb_entry(rbp, struct ceph_pg_mapping, node);
836 858
837 rbp = rb_next(rbp); 859 rbp = rb_next(rbp);
838 dout(" removed pg_temp %llx\n", *(u64 *)&cur->pgid); 860 dout(" removed pg_temp %llx\n", *(u64 *)&cur->pgid);
839 rb_erase(&cur->node, &map->pg_temp); 861 rb_erase(&cur->node, &map->pg_temp);
@@ -1026,8 +1048,9 @@ static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg pgid,
1026 ruleno = crush_find_rule(osdmap->crush, pool->v.crush_ruleset, 1048 ruleno = crush_find_rule(osdmap->crush, pool->v.crush_ruleset,
1027 pool->v.type, pool->v.size); 1049 pool->v.type, pool->v.size);
1028 if (ruleno < 0) { 1050 if (ruleno < 0) {
1029 pr_err("no crush rule pool %d type %d size %d\n", 1051 pr_err("no crush rule pool %d ruleset %d type %d size %d\n",
1030 poolid, pool->v.type, pool->v.size); 1052 poolid, pool->v.crush_ruleset, pool->v.type,
1053 pool->v.size);
1031 return NULL; 1054 return NULL;
1032 } 1055 }
1033 1056
diff --git a/fs/ceph/rados.h b/fs/ceph/rados.h
index 8fcc023056c7..6d5247f2e81b 100644
--- a/fs/ceph/rados.h
+++ b/fs/ceph/rados.h
@@ -1,5 +1,5 @@
1#ifndef __RADOS_H 1#ifndef CEPH_RADOS_H
2#define __RADOS_H 2#define CEPH_RADOS_H
3 3
4/* 4/*
5 * Data types for the Ceph distributed object storage layer RADOS 5 * Data types for the Ceph distributed object storage layer RADOS
@@ -203,6 +203,7 @@ enum {
203 CEPH_OSD_OP_TMAPGET = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 12, 203 CEPH_OSD_OP_TMAPGET = CEPH_OSD_OP_MODE_RD | CEPH_OSD_OP_TYPE_DATA | 12,
204 204
205 CEPH_OSD_OP_CREATE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 13, 205 CEPH_OSD_OP_CREATE = CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 13,
206 CEPH_OSD_OP_ROLLBACK= CEPH_OSD_OP_MODE_WR | CEPH_OSD_OP_TYPE_DATA | 14,
206 207
207 /** attrs **/ 208 /** attrs **/
208 /* read */ 209 /* read */
@@ -272,6 +273,10 @@ static inline int ceph_osd_op_mode_modify(int op)
272 return (op & CEPH_OSD_OP_MODE) == CEPH_OSD_OP_MODE_WR; 273 return (op & CEPH_OSD_OP_MODE) == CEPH_OSD_OP_MODE_WR;
273} 274}
274 275
276/*
277 * note that the following tmap stuff is also defined in the ceph librados.h
278 * any modification here needs to be updated there
279 */
275#define CEPH_OSD_TMAP_HDR 'h' 280#define CEPH_OSD_TMAP_HDR 'h'
276#define CEPH_OSD_TMAP_SET 's' 281#define CEPH_OSD_TMAP_SET 's'
277#define CEPH_OSD_TMAP_RM 'r' 282#define CEPH_OSD_TMAP_RM 'r'
@@ -297,6 +302,7 @@ enum {
297 CEPH_OSD_FLAG_PARALLELEXEC = 512, /* execute op in parallel */ 302 CEPH_OSD_FLAG_PARALLELEXEC = 512, /* execute op in parallel */
298 CEPH_OSD_FLAG_PGOP = 1024, /* pg op, no object */ 303 CEPH_OSD_FLAG_PGOP = 1024, /* pg op, no object */
299 CEPH_OSD_FLAG_EXEC = 2048, /* op may exec */ 304 CEPH_OSD_FLAG_EXEC = 2048, /* op may exec */
305 CEPH_OSD_FLAG_EXEC_PUBLIC = 4096, /* op may exec (public) */
300}; 306};
301 307
302enum { 308enum {
@@ -350,6 +356,9 @@ struct ceph_osd_op {
350 struct { 356 struct {
351 __le64 cookie, count; 357 __le64 cookie, count;
352 } __attribute__ ((packed)) pgls; 358 } __attribute__ ((packed)) pgls;
359 struct {
360 __le64 snapid;
361 } __attribute__ ((packed)) snap;
353 }; 362 };
354 __le32 payload_len; 363 __le32 payload_len;
355} __attribute__ ((packed)); 364} __attribute__ ((packed));
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index fa87f51e38e1..9922628532b2 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -2,6 +2,7 @@
2#include "ceph_debug.h" 2#include "ceph_debug.h"
3 3
4#include <linux/backing-dev.h> 4#include <linux/backing-dev.h>
5#include <linux/ctype.h>
5#include <linux/fs.h> 6#include <linux/fs.h>
6#include <linux/inet.h> 7#include <linux/inet.h>
7#include <linux/in6.h> 8#include <linux/in6.h>
@@ -101,12 +102,21 @@ static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
101} 102}
102 103
103 104
104static int ceph_syncfs(struct super_block *sb, int wait) 105static int ceph_sync_fs(struct super_block *sb, int wait)
105{ 106{
106 dout("sync_fs %d\n", wait); 107 struct ceph_client *client = ceph_sb_to_client(sb);
108
109 if (!wait) {
110 dout("sync_fs (non-blocking)\n");
111 ceph_flush_dirty_caps(&client->mdsc);
112 dout("sync_fs (non-blocking) done\n");
113 return 0;
114 }
115
116 dout("sync_fs (blocking)\n");
107 ceph_osdc_sync(&ceph_sb_to_client(sb)->osdc); 117 ceph_osdc_sync(&ceph_sb_to_client(sb)->osdc);
108 ceph_mdsc_sync(&ceph_sb_to_client(sb)->mdsc); 118 ceph_mdsc_sync(&ceph_sb_to_client(sb)->mdsc);
109 dout("sync_fs %d done\n", wait); 119 dout("sync_fs (blocking) done\n");
110 return 0; 120 return 0;
111} 121}
112 122
@@ -150,9 +160,7 @@ static int ceph_show_options(struct seq_file *m, struct vfsmount *mnt)
150 struct ceph_mount_args *args = client->mount_args; 160 struct ceph_mount_args *args = client->mount_args;
151 161
152 if (args->flags & CEPH_OPT_FSID) 162 if (args->flags & CEPH_OPT_FSID)
153 seq_printf(m, ",fsidmajor=%llu,fsidminor%llu", 163 seq_printf(m, ",fsid=%pU", &args->fsid);
154 le64_to_cpu(*(__le64 *)&args->fsid.fsid[0]),
155 le64_to_cpu(*(__le64 *)&args->fsid.fsid[8]));
156 if (args->flags & CEPH_OPT_NOSHARE) 164 if (args->flags & CEPH_OPT_NOSHARE)
157 seq_puts(m, ",noshare"); 165 seq_puts(m, ",noshare");
158 if (args->flags & CEPH_OPT_DIRSTAT) 166 if (args->flags & CEPH_OPT_DIRSTAT)
@@ -279,7 +287,7 @@ static const struct super_operations ceph_super_ops = {
279 .alloc_inode = ceph_alloc_inode, 287 .alloc_inode = ceph_alloc_inode,
280 .destroy_inode = ceph_destroy_inode, 288 .destroy_inode = ceph_destroy_inode,
281 .write_inode = ceph_write_inode, 289 .write_inode = ceph_write_inode,
282 .sync_fs = ceph_syncfs, 290 .sync_fs = ceph_sync_fs,
283 .put_super = ceph_put_super, 291 .put_super = ceph_put_super,
284 .show_options = ceph_show_options, 292 .show_options = ceph_show_options,
285 .statfs = ceph_statfs, 293 .statfs = ceph_statfs,
@@ -322,9 +330,6 @@ const char *ceph_msg_type_name(int type)
322 * mount options 330 * mount options
323 */ 331 */
324enum { 332enum {
325 Opt_fsidmajor,
326 Opt_fsidminor,
327 Opt_monport,
328 Opt_wsize, 333 Opt_wsize,
329 Opt_rsize, 334 Opt_rsize,
330 Opt_osdtimeout, 335 Opt_osdtimeout,
@@ -339,6 +344,7 @@ enum {
339 Opt_congestion_kb, 344 Opt_congestion_kb,
340 Opt_last_int, 345 Opt_last_int,
341 /* int args above */ 346 /* int args above */
347 Opt_fsid,
342 Opt_snapdirname, 348 Opt_snapdirname,
343 Opt_name, 349 Opt_name,
344 Opt_secret, 350 Opt_secret,
@@ -355,9 +361,6 @@ enum {
355}; 361};
356 362
357static match_table_t arg_tokens = { 363static match_table_t arg_tokens = {
358 {Opt_fsidmajor, "fsidmajor=%ld"},
359 {Opt_fsidminor, "fsidminor=%ld"},
360 {Opt_monport, "monport=%d"},
361 {Opt_wsize, "wsize=%d"}, 364 {Opt_wsize, "wsize=%d"},
362 {Opt_rsize, "rsize=%d"}, 365 {Opt_rsize, "rsize=%d"},
363 {Opt_osdtimeout, "osdtimeout=%d"}, 366 {Opt_osdtimeout, "osdtimeout=%d"},
@@ -371,6 +374,7 @@ static match_table_t arg_tokens = {
371 {Opt_readdir_max_bytes, "readdir_max_bytes=%d"}, 374 {Opt_readdir_max_bytes, "readdir_max_bytes=%d"},
372 {Opt_congestion_kb, "write_congestion_kb=%d"}, 375 {Opt_congestion_kb, "write_congestion_kb=%d"},
373 /* int args above */ 376 /* int args above */
377 {Opt_fsid, "fsid=%s"},
374 {Opt_snapdirname, "snapdirname=%s"}, 378 {Opt_snapdirname, "snapdirname=%s"},
375 {Opt_name, "name=%s"}, 379 {Opt_name, "name=%s"},
376 {Opt_secret, "secret=%s"}, 380 {Opt_secret, "secret=%s"},
@@ -386,6 +390,36 @@ static match_table_t arg_tokens = {
386 {-1, NULL} 390 {-1, NULL}
387}; 391};
388 392
393static int parse_fsid(const char *str, struct ceph_fsid *fsid)
394{
395 int i = 0;
396 char tmp[3];
397 int err = -EINVAL;
398 int d;
399
400 dout("parse_fsid '%s'\n", str);
401 tmp[2] = 0;
402 while (*str && i < 16) {
403 if (ispunct(*str)) {
404 str++;
405 continue;
406 }
407 if (!isxdigit(str[0]) || !isxdigit(str[1]))
408 break;
409 tmp[0] = str[0];
410 tmp[1] = str[1];
411 if (sscanf(tmp, "%x", &d) < 1)
412 break;
413 fsid->fsid[i] = d & 0xff;
414 i++;
415 str += 2;
416 }
417
418 if (i == 16)
419 err = 0;
420 dout("parse_fsid ret %d got fsid %pU", err, fsid);
421 return err;
422}
389 423
390static struct ceph_mount_args *parse_mount_args(int flags, char *options, 424static struct ceph_mount_args *parse_mount_args(int flags, char *options,
391 const char *dev_name, 425 const char *dev_name,
@@ -469,12 +503,6 @@ static struct ceph_mount_args *parse_mount_args(int flags, char *options,
469 dout("got token %d\n", token); 503 dout("got token %d\n", token);
470 } 504 }
471 switch (token) { 505 switch (token) {
472 case Opt_fsidmajor:
473 *(__le64 *)&args->fsid.fsid[0] = cpu_to_le64(intval);
474 break;
475 case Opt_fsidminor:
476 *(__le64 *)&args->fsid.fsid[8] = cpu_to_le64(intval);
477 break;
478 case Opt_ip: 506 case Opt_ip:
479 err = ceph_parse_ips(argstr[0].from, 507 err = ceph_parse_ips(argstr[0].from,
480 argstr[0].to, 508 argstr[0].to,
@@ -485,6 +513,11 @@ static struct ceph_mount_args *parse_mount_args(int flags, char *options,
485 args->flags |= CEPH_OPT_MYIP; 513 args->flags |= CEPH_OPT_MYIP;
486 break; 514 break;
487 515
516 case Opt_fsid:
517 err = parse_fsid(argstr[0].from, &args->fsid);
518 if (err == 0)
519 args->flags |= CEPH_OPT_FSID;
520 break;
488 case Opt_snapdirname: 521 case Opt_snapdirname:
489 kfree(args->snapdir_name); 522 kfree(args->snapdir_name);
490 args->snapdir_name = kstrndup(argstr[0].from, 523 args->snapdir_name = kstrndup(argstr[0].from,
@@ -515,6 +548,9 @@ static struct ceph_mount_args *parse_mount_args(int flags, char *options,
515 case Opt_osdkeepalivetimeout: 548 case Opt_osdkeepalivetimeout:
516 args->osd_keepalive_timeout = intval; 549 args->osd_keepalive_timeout = intval;
517 break; 550 break;
551 case Opt_osd_idle_ttl:
552 args->osd_idle_ttl = intval;
553 break;
518 case Opt_mount_timeout: 554 case Opt_mount_timeout:
519 args->mount_timeout = intval; 555 args->mount_timeout = intval;
520 break; 556 break;
@@ -630,7 +666,6 @@ static struct ceph_client *ceph_create_client(struct ceph_mount_args *args)
630 666
631 /* caps */ 667 /* caps */
632 client->min_caps = args->max_readdir; 668 client->min_caps = args->max_readdir;
633 ceph_adjust_min_caps(client->min_caps);
634 669
635 /* subsystems */ 670 /* subsystems */
636 err = ceph_monc_init(&client->monc, client); 671 err = ceph_monc_init(&client->monc, client);
@@ -680,8 +715,6 @@ static void ceph_destroy_client(struct ceph_client *client)
680 715
681 ceph_monc_stop(&client->monc); 716 ceph_monc_stop(&client->monc);
682 717
683 ceph_adjust_min_caps(-client->min_caps);
684
685 ceph_debugfs_client_cleanup(client); 718 ceph_debugfs_client_cleanup(client);
686 destroy_workqueue(client->wb_wq); 719 destroy_workqueue(client->wb_wq);
687 destroy_workqueue(client->pg_inv_wq); 720 destroy_workqueue(client->pg_inv_wq);
@@ -706,13 +739,13 @@ int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid)
706{ 739{
707 if (client->have_fsid) { 740 if (client->have_fsid) {
708 if (ceph_fsid_compare(&client->fsid, fsid)) { 741 if (ceph_fsid_compare(&client->fsid, fsid)) {
709 pr_err("bad fsid, had " FSID_FORMAT " got " FSID_FORMAT, 742 pr_err("bad fsid, had %pU got %pU",
710 PR_FSID(&client->fsid), PR_FSID(fsid)); 743 &client->fsid, fsid);
711 return -1; 744 return -1;
712 } 745 }
713 } else { 746 } else {
714 pr_info("client%lld fsid " FSID_FORMAT "\n", 747 pr_info("client%lld fsid %pU\n", client->monc.auth->global_id,
715 client->monc.auth->global_id, PR_FSID(fsid)); 748 fsid);
716 memcpy(&client->fsid, fsid, sizeof(*fsid)); 749 memcpy(&client->fsid, fsid, sizeof(*fsid));
717 ceph_debugfs_client_init(client); 750 ceph_debugfs_client_init(client);
718 client->have_fsid = true; 751 client->have_fsid = true;
@@ -1043,8 +1076,6 @@ static int __init init_ceph(void)
1043 if (ret) 1076 if (ret)
1044 goto out_msgr; 1077 goto out_msgr;
1045 1078
1046 ceph_caps_init();
1047
1048 ret = register_filesystem(&ceph_fs_type); 1079 ret = register_filesystem(&ceph_fs_type);
1049 if (ret) 1080 if (ret)
1050 goto out_icache; 1081 goto out_icache;
@@ -1069,7 +1100,6 @@ static void __exit exit_ceph(void)
1069{ 1100{
1070 dout("exit_ceph\n"); 1101 dout("exit_ceph\n");
1071 unregister_filesystem(&ceph_fs_type); 1102 unregister_filesystem(&ceph_fs_type);
1072 ceph_caps_finalize();
1073 destroy_caches(); 1103 destroy_caches();
1074 ceph_msgr_exit(); 1104 ceph_msgr_exit();
1075 ceph_debugfs_cleanup(); 1105 ceph_debugfs_cleanup();
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 10a4a406e887..2482d696f0de 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -31,6 +31,12 @@
31#define CEPH_BLOCK (1 << CEPH_BLOCK_SHIFT) 31#define CEPH_BLOCK (1 << CEPH_BLOCK_SHIFT)
32 32
33/* 33/*
34 * Supported features
35 */
36#define CEPH_FEATURE_SUPPORTED CEPH_FEATURE_NOSRCADDR | CEPH_FEATURE_FLOCK
37#define CEPH_FEATURE_REQUIRED CEPH_FEATURE_NOSRCADDR
38
39/*
34 * mount options 40 * mount options
35 */ 41 */
36#define CEPH_OPT_FSID (1<<0) 42#define CEPH_OPT_FSID (1<<0)
@@ -560,11 +566,13 @@ static inline int __ceph_caps_wanted(struct ceph_inode_info *ci)
560/* what the mds thinks we want */ 566/* what the mds thinks we want */
561extern int __ceph_caps_mds_wanted(struct ceph_inode_info *ci); 567extern int __ceph_caps_mds_wanted(struct ceph_inode_info *ci);
562 568
563extern void ceph_caps_init(void); 569extern void ceph_caps_init(struct ceph_mds_client *mdsc);
564extern void ceph_caps_finalize(void); 570extern void ceph_caps_finalize(struct ceph_mds_client *mdsc);
565extern void ceph_adjust_min_caps(int delta); 571extern void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta);
566extern int ceph_reserve_caps(struct ceph_cap_reservation *ctx, int need); 572extern int ceph_reserve_caps(struct ceph_mds_client *mdsc,
567extern int ceph_unreserve_caps(struct ceph_cap_reservation *ctx); 573 struct ceph_cap_reservation *ctx, int need);
574extern int ceph_unreserve_caps(struct ceph_mds_client *mdsc,
575 struct ceph_cap_reservation *ctx);
568extern void ceph_reservation_status(struct ceph_client *client, 576extern void ceph_reservation_status(struct ceph_client *client,
569 int *total, int *avail, int *used, 577 int *total, int *avail, int *used,
570 int *reserved, int *min); 578 int *reserved, int *min);
@@ -738,13 +746,6 @@ extern struct kmem_cache *ceph_file_cachep;
738extern const char *ceph_msg_type_name(int type); 746extern const char *ceph_msg_type_name(int type);
739extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid); 747extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid);
740 748
741#define FSID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \
742 "%02x%02x%02x%02x%02x%02x"
743#define PR_FSID(f) (f)->fsid[0], (f)->fsid[1], (f)->fsid[2], (f)->fsid[3], \
744 (f)->fsid[4], (f)->fsid[5], (f)->fsid[6], (f)->fsid[7], \
745 (f)->fsid[8], (f)->fsid[9], (f)->fsid[10], (f)->fsid[11], \
746 (f)->fsid[12], (f)->fsid[13], (f)->fsid[14], (f)->fsid[15]
747
748/* inode.c */ 749/* inode.c */
749extern const struct inode_operations ceph_file_iops; 750extern const struct inode_operations ceph_file_iops;
750 751
@@ -806,13 +807,16 @@ static inline void ceph_remove_cap(struct ceph_cap *cap)
806 __ceph_remove_cap(cap); 807 __ceph_remove_cap(cap);
807 spin_unlock(&inode->i_lock); 808 spin_unlock(&inode->i_lock);
808} 809}
809extern void ceph_put_cap(struct ceph_cap *cap); 810extern void ceph_put_cap(struct ceph_mds_client *mdsc,
811 struct ceph_cap *cap);
810 812
811extern void ceph_queue_caps_release(struct inode *inode); 813extern void ceph_queue_caps_release(struct inode *inode);
812extern int ceph_write_inode(struct inode *inode, struct writeback_control *wbc); 814extern int ceph_write_inode(struct inode *inode, struct writeback_control *wbc);
813extern int ceph_fsync(struct file *file, int datasync); 815extern int ceph_fsync(struct file *file, int datasync);
814extern void ceph_kick_flushing_caps(struct ceph_mds_client *mdsc, 816extern void ceph_kick_flushing_caps(struct ceph_mds_client *mdsc,
815 struct ceph_mds_session *session); 817 struct ceph_mds_session *session);
818extern struct ceph_cap *ceph_get_cap_for_mds(struct ceph_inode_info *ci,
819 int mds);
816extern int ceph_get_cap_mds(struct inode *inode); 820extern int ceph_get_cap_mds(struct inode *inode);
817extern void ceph_get_cap_refs(struct ceph_inode_info *ci, int caps); 821extern void ceph_get_cap_refs(struct ceph_inode_info *ci, int caps);
818extern void ceph_put_cap_refs(struct ceph_inode_info *ci, int had); 822extern void ceph_put_cap_refs(struct ceph_inode_info *ci, int had);
@@ -857,7 +861,7 @@ extern void ceph_release_page_vector(struct page **pages, int num_pages);
857/* dir.c */ 861/* dir.c */
858extern const struct file_operations ceph_dir_fops; 862extern const struct file_operations ceph_dir_fops;
859extern const struct inode_operations ceph_dir_iops; 863extern const struct inode_operations ceph_dir_iops;
860extern struct dentry_operations ceph_dentry_ops, ceph_snap_dentry_ops, 864extern const struct dentry_operations ceph_dentry_ops, ceph_snap_dentry_ops,
861 ceph_snapdir_dentry_ops; 865 ceph_snapdir_dentry_ops;
862 866
863extern int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry); 867extern int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry);
@@ -888,6 +892,14 @@ extern void ceph_debugfs_cleanup(void);
888extern int ceph_debugfs_client_init(struct ceph_client *client); 892extern int ceph_debugfs_client_init(struct ceph_client *client);
889extern void ceph_debugfs_client_cleanup(struct ceph_client *client); 893extern void ceph_debugfs_client_cleanup(struct ceph_client *client);
890 894
895/* locks.c */
896extern int ceph_lock(struct file *file, int cmd, struct file_lock *fl);
897extern int ceph_flock(struct file *file, int cmd, struct file_lock *fl);
898extern void ceph_count_locks(struct inode *inode, int *p_num, int *f_num);
899extern int ceph_encode_locks(struct inode *i, struct ceph_pagelist *p,
900 int p_locks, int f_locks);
901extern int lock_to_ceph_filelock(struct file_lock *fl, struct ceph_filelock *c);
902
891static inline struct inode *get_dentry_parent_inode(struct dentry *dentry) 903static inline struct inode *get_dentry_parent_inode(struct dentry *dentry)
892{ 904{
893 if (dentry && dentry->d_parent) 905 if (dentry && dentry->d_parent)
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index 68aeebc69681..097a2654c00f 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -337,6 +337,8 @@ void __ceph_destroy_xattrs(struct ceph_inode_info *ci)
337} 337}
338 338
339static int __build_xattrs(struct inode *inode) 339static int __build_xattrs(struct inode *inode)
340 __releases(inode->i_lock)
341 __acquires(inode->i_lock)
340{ 342{
341 u32 namelen; 343 u32 namelen;
342 u32 numattr = 0; 344 u32 numattr = 0;
diff --git a/fs/cifs/README b/fs/cifs/README
index a7081eeeb85d..7099a526f775 100644
--- a/fs/cifs/README
+++ b/fs/cifs/README
@@ -301,6 +301,16 @@ A partial list of the supported mount options follows:
301 gid Set the default gid for inodes (similar to above). 301 gid Set the default gid for inodes (similar to above).
302 file_mode If CIFS Unix extensions are not supported by the server 302 file_mode If CIFS Unix extensions are not supported by the server
303 this overrides the default mode for file inodes. 303 this overrides the default mode for file inodes.
304 fsc Enable local disk caching using FS-Cache (off by default). This
305 option could be useful to improve performance on a slow link,
306 heavily loaded server and/or network where reading from the
307 disk is faster than reading from the server (over the network).
308 This could also impact scalability positively as the
309 number of calls to the server are reduced. However, local
310 caching is not suitable for all workloads for e.g. read-once
311 type workloads. So, you need to consider carefully your
312 workload/scenario before using this option. Currently, local
313 disk caching is functional for CIFS files opened as read-only.
304 dir_mode If CIFS Unix extensions are not supported by the server 314 dir_mode If CIFS Unix extensions are not supported by the server
305 this overrides the default mode for directory inodes. 315 this overrides the default mode for directory inodes.
306 port attempt to contact the server on this tcp port, before 316 port attempt to contact the server on this tcp port, before
diff --git a/fs/dcache.c b/fs/dcache.c
index 9f2c13417969..166d35d56868 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1905,48 +1905,30 @@ static int prepend_name(char **buffer, int *buflen, struct qstr *name)
1905} 1905}
1906 1906
1907/** 1907/**
1908 * __d_path - return the path of a dentry 1908 * Prepend path string to a buffer
1909 *
1909 * @path: the dentry/vfsmount to report 1910 * @path: the dentry/vfsmount to report
1910 * @root: root vfsmnt/dentry (may be modified by this function) 1911 * @root: root vfsmnt/dentry (may be modified by this function)
1911 * @buffer: buffer to return value in 1912 * @buffer: pointer to the end of the buffer
1912 * @buflen: buffer length 1913 * @buflen: pointer to buffer length
1913 * 1914 *
1914 * Convert a dentry into an ASCII path name. If the entry has been deleted 1915 * Caller holds the dcache_lock.
1915 * the string " (deleted)" is appended. Note that this is ambiguous.
1916 *
1917 * Returns a pointer into the buffer or an error code if the
1918 * path was too long.
1919 *
1920 * "buflen" should be positive. Caller holds the dcache_lock.
1921 * 1916 *
1922 * If path is not reachable from the supplied root, then the value of 1917 * If path is not reachable from the supplied root, then the value of
1923 * root is changed (without modifying refcounts). 1918 * root is changed (without modifying refcounts).
1924 */ 1919 */
1925char *__d_path(const struct path *path, struct path *root, 1920static int prepend_path(const struct path *path, struct path *root,
1926 char *buffer, int buflen) 1921 char **buffer, int *buflen)
1927{ 1922{
1928 struct dentry *dentry = path->dentry; 1923 struct dentry *dentry = path->dentry;
1929 struct vfsmount *vfsmnt = path->mnt; 1924 struct vfsmount *vfsmnt = path->mnt;
1930 char *end = buffer + buflen; 1925 bool slash = false;
1931 char *retval; 1926 int error = 0;
1932 1927
1933 spin_lock(&vfsmount_lock); 1928 spin_lock(&vfsmount_lock);
1934 prepend(&end, &buflen, "\0", 1); 1929 while (dentry != root->dentry || vfsmnt != root->mnt) {
1935 if (d_unlinked(dentry) &&
1936 (prepend(&end, &buflen, " (deleted)", 10) != 0))
1937 goto Elong;
1938
1939 if (buflen < 1)
1940 goto Elong;
1941 /* Get '/' right */
1942 retval = end-1;
1943 *retval = '/';
1944
1945 for (;;) {
1946 struct dentry * parent; 1930 struct dentry * parent;
1947 1931
1948 if (dentry == root->dentry && vfsmnt == root->mnt)
1949 break;
1950 if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) { 1932 if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
1951 /* Global root? */ 1933 /* Global root? */
1952 if (vfsmnt->mnt_parent == vfsmnt) { 1934 if (vfsmnt->mnt_parent == vfsmnt) {
@@ -1958,28 +1940,88 @@ char *__d_path(const struct path *path, struct path *root,
1958 } 1940 }
1959 parent = dentry->d_parent; 1941 parent = dentry->d_parent;
1960 prefetch(parent); 1942 prefetch(parent);
1961 if ((prepend_name(&end, &buflen, &dentry->d_name) != 0) || 1943 error = prepend_name(buffer, buflen, &dentry->d_name);
1962 (prepend(&end, &buflen, "/", 1) != 0)) 1944 if (!error)
1963 goto Elong; 1945 error = prepend(buffer, buflen, "/", 1);
1964 retval = end; 1946 if (error)
1947 break;
1948
1949 slash = true;
1965 dentry = parent; 1950 dentry = parent;
1966 } 1951 }
1967 1952
1968out: 1953out:
1954 if (!error && !slash)
1955 error = prepend(buffer, buflen, "/", 1);
1956
1969 spin_unlock(&vfsmount_lock); 1957 spin_unlock(&vfsmount_lock);
1970 return retval; 1958 return error;
1971 1959
1972global_root: 1960global_root:
1973 retval += 1; /* hit the slash */ 1961 /*
1974 if (prepend_name(&retval, &buflen, &dentry->d_name) != 0) 1962 * Filesystems needing to implement special "root names"
1975 goto Elong; 1963 * should do so with ->d_dname()
1964 */
1965 if (IS_ROOT(dentry) &&
1966 (dentry->d_name.len != 1 || dentry->d_name.name[0] != '/')) {
1967 WARN(1, "Root dentry has weird name <%.*s>\n",
1968 (int) dentry->d_name.len, dentry->d_name.name);
1969 }
1976 root->mnt = vfsmnt; 1970 root->mnt = vfsmnt;
1977 root->dentry = dentry; 1971 root->dentry = dentry;
1978 goto out; 1972 goto out;
1973}
1979 1974
1980Elong: 1975/**
1981 retval = ERR_PTR(-ENAMETOOLONG); 1976 * __d_path - return the path of a dentry
1982 goto out; 1977 * @path: the dentry/vfsmount to report
1978 * @root: root vfsmnt/dentry (may be modified by this function)
1979 * @buffer: buffer to return value in
1980 * @buflen: buffer length
1981 *
1982 * Convert a dentry into an ASCII path name.
1983 *
1984 * Returns a pointer into the buffer or an error code if the
1985 * path was too long.
1986 *
1987 * "buflen" should be positive. Caller holds the dcache_lock.
1988 *
1989 * If path is not reachable from the supplied root, then the value of
1990 * root is changed (without modifying refcounts).
1991 */
1992char *__d_path(const struct path *path, struct path *root,
1993 char *buf, int buflen)
1994{
1995 char *res = buf + buflen;
1996 int error;
1997
1998 prepend(&res, &buflen, "\0", 1);
1999 error = prepend_path(path, root, &res, &buflen);
2000 if (error)
2001 return ERR_PTR(error);
2002
2003 return res;
2004}
2005
2006/*
2007 * same as __d_path but appends "(deleted)" for unlinked files.
2008 */
2009static int path_with_deleted(const struct path *path, struct path *root,
2010 char **buf, int *buflen)
2011{
2012 prepend(buf, buflen, "\0", 1);
2013 if (d_unlinked(path->dentry)) {
2014 int error = prepend(buf, buflen, " (deleted)", 10);
2015 if (error)
2016 return error;
2017 }
2018
2019 return prepend_path(path, root, buf, buflen);
2020}
2021
2022static int prepend_unreachable(char **buffer, int *buflen)
2023{
2024 return prepend(buffer, buflen, "(unreachable)", 13);
1983} 2025}
1984 2026
1985/** 2027/**
@@ -2000,9 +2042,10 @@ Elong:
2000 */ 2042 */
2001char *d_path(const struct path *path, char *buf, int buflen) 2043char *d_path(const struct path *path, char *buf, int buflen)
2002{ 2044{
2003 char *res; 2045 char *res = buf + buflen;
2004 struct path root; 2046 struct path root;
2005 struct path tmp; 2047 struct path tmp;
2048 int error;
2006 2049
2007 /* 2050 /*
2008 * We have various synthetic filesystems that never get mounted. On 2051 * We have various synthetic filesystems that never get mounted. On
@@ -2014,19 +2057,51 @@ char *d_path(const struct path *path, char *buf, int buflen)
2014 if (path->dentry->d_op && path->dentry->d_op->d_dname) 2057 if (path->dentry->d_op && path->dentry->d_op->d_dname)
2015 return path->dentry->d_op->d_dname(path->dentry, buf, buflen); 2058 return path->dentry->d_op->d_dname(path->dentry, buf, buflen);
2016 2059
2017 read_lock(&current->fs->lock); 2060 get_fs_root(current->fs, &root);
2018 root = current->fs->root;
2019 path_get(&root);
2020 read_unlock(&current->fs->lock);
2021 spin_lock(&dcache_lock); 2061 spin_lock(&dcache_lock);
2022 tmp = root; 2062 tmp = root;
2023 res = __d_path(path, &tmp, buf, buflen); 2063 error = path_with_deleted(path, &tmp, &res, &buflen);
2064 if (error)
2065 res = ERR_PTR(error);
2024 spin_unlock(&dcache_lock); 2066 spin_unlock(&dcache_lock);
2025 path_put(&root); 2067 path_put(&root);
2026 return res; 2068 return res;
2027} 2069}
2028EXPORT_SYMBOL(d_path); 2070EXPORT_SYMBOL(d_path);
2029 2071
2072/**
2073 * d_path_with_unreachable - return the path of a dentry
2074 * @path: path to report
2075 * @buf: buffer to return value in
2076 * @buflen: buffer length
2077 *
2078 * The difference from d_path() is that this prepends "(unreachable)"
2079 * to paths which are unreachable from the current process' root.
2080 */
2081char *d_path_with_unreachable(const struct path *path, char *buf, int buflen)
2082{
2083 char *res = buf + buflen;
2084 struct path root;
2085 struct path tmp;
2086 int error;
2087
2088 if (path->dentry->d_op && path->dentry->d_op->d_dname)
2089 return path->dentry->d_op->d_dname(path->dentry, buf, buflen);
2090
2091 get_fs_root(current->fs, &root);
2092 spin_lock(&dcache_lock);
2093 tmp = root;
2094 error = path_with_deleted(path, &tmp, &res, &buflen);
2095 if (!error && !path_equal(&tmp, &root))
2096 error = prepend_unreachable(&res, &buflen);
2097 spin_unlock(&dcache_lock);
2098 path_put(&root);
2099 if (error)
2100 res = ERR_PTR(error);
2101
2102 return res;
2103}
2104
2030/* 2105/*
2031 * Helper function for dentry_operations.d_dname() members 2106 * Helper function for dentry_operations.d_dname() members
2032 */ 2107 */
@@ -2129,27 +2204,30 @@ SYSCALL_DEFINE2(getcwd, char __user *, buf, unsigned long, size)
2129 if (!page) 2204 if (!page)
2130 return -ENOMEM; 2205 return -ENOMEM;
2131 2206
2132 read_lock(&current->fs->lock); 2207 get_fs_root_and_pwd(current->fs, &root, &pwd);
2133 pwd = current->fs->pwd;
2134 path_get(&pwd);
2135 root = current->fs->root;
2136 path_get(&root);
2137 read_unlock(&current->fs->lock);
2138 2208
2139 error = -ENOENT; 2209 error = -ENOENT;
2140 spin_lock(&dcache_lock); 2210 spin_lock(&dcache_lock);
2141 if (!d_unlinked(pwd.dentry)) { 2211 if (!d_unlinked(pwd.dentry)) {
2142 unsigned long len; 2212 unsigned long len;
2143 struct path tmp = root; 2213 struct path tmp = root;
2144 char * cwd; 2214 char *cwd = page + PAGE_SIZE;
2215 int buflen = PAGE_SIZE;
2145 2216
2146 cwd = __d_path(&pwd, &tmp, page, PAGE_SIZE); 2217 prepend(&cwd, &buflen, "\0", 1);
2218 error = prepend_path(&pwd, &tmp, &cwd, &buflen);
2147 spin_unlock(&dcache_lock); 2219 spin_unlock(&dcache_lock);
2148 2220
2149 error = PTR_ERR(cwd); 2221 if (error)
2150 if (IS_ERR(cwd))
2151 goto out; 2222 goto out;
2152 2223
2224 /* Unreachable from current root */
2225 if (!path_equal(&tmp, &root)) {
2226 error = prepend_unreachable(&cwd, &buflen);
2227 if (error)
2228 goto out;
2229 }
2230
2153 error = -ERANGE; 2231 error = -ERANGE;
2154 len = PAGE_SIZE + page - cwd; 2232 len = PAGE_SIZE + page - cwd;
2155 if (len <= size) { 2233 if (len <= size) {
diff --git a/fs/exofs/file.c b/fs/exofs/file.c
index f9bfe2b501d5..68cb23e3bb98 100644
--- a/fs/exofs/file.c
+++ b/fs/exofs/file.c
@@ -30,9 +30,6 @@
30 * along with exofs; if not, write to the Free Software 30 * along with exofs; if not, write to the Free Software
31 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 31 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 */ 32 */
33
34#include <linux/buffer_head.h>
35
36#include "exofs.h" 33#include "exofs.h"
37 34
38static int exofs_release_file(struct inode *inode, struct file *filp) 35static int exofs_release_file(struct inode *inode, struct file *filp)
@@ -40,19 +37,27 @@ static int exofs_release_file(struct inode *inode, struct file *filp)
40 return 0; 37 return 0;
41} 38}
42 39
40/* exofs_file_fsync - flush the inode to disk
41 *
42 * Note, in exofs all metadata is written as part of inode, regardless.
43 * The writeout is synchronous
44 */
43static int exofs_file_fsync(struct file *filp, int datasync) 45static int exofs_file_fsync(struct file *filp, int datasync)
44{ 46{
45 int ret; 47 int ret;
46 struct address_space *mapping = filp->f_mapping; 48 struct inode *inode = filp->f_mapping->host;
47 struct inode *inode = mapping->host; 49 struct writeback_control wbc = {
50 .sync_mode = WB_SYNC_ALL,
51 .nr_to_write = 0, /* metadata-only; caller takes care of data */
52 };
48 struct super_block *sb; 53 struct super_block *sb;
49 54
50 ret = filemap_write_and_wait(mapping); 55 if (!(inode->i_state & I_DIRTY))
51 if (ret) 56 return 0;
52 return ret; 57 if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
58 return 0;
53 59
54 /* sync the inode attributes */ 60 ret = sync_inode(inode, &wbc);
55 ret = write_inode_now(inode, 1);
56 61
57 /* This is a good place to write the sb */ 62 /* This is a good place to write the sb */
58 /* TODO: Sechedule an sb-sync on create */ 63 /* TODO: Sechedule an sb-sync on create */
@@ -65,9 +70,9 @@ static int exofs_file_fsync(struct file *filp, int datasync)
65 70
66static int exofs_flush(struct file *file, fl_owner_t id) 71static int exofs_flush(struct file *file, fl_owner_t id)
67{ 72{
68 exofs_file_fsync(file, 1); 73 int ret = vfs_fsync(file, 0);
69 /* TODO: Flush the OSD target */ 74 /* TODO: Flush the OSD target */
70 return 0; 75 return ret;
71} 76}
72 77
73const struct file_operations exofs_file_operations = { 78const struct file_operations exofs_file_operations = {
diff --git a/fs/exofs/inode.c b/fs/exofs/inode.c
index 088cb476b68a..eb7368ebd8cd 100644
--- a/fs/exofs/inode.c
+++ b/fs/exofs/inode.c
@@ -32,9 +32,6 @@
32 */ 32 */
33 33
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/writeback.h>
36#include <linux/buffer_head.h>
37#include <scsi/scsi_device.h>
38 35
39#include "exofs.h" 36#include "exofs.h"
40 37
@@ -773,15 +770,13 @@ static int exofs_releasepage(struct page *page, gfp_t gfp)
773{ 770{
774 EXOFS_DBGMSG("page 0x%lx\n", page->index); 771 EXOFS_DBGMSG("page 0x%lx\n", page->index);
775 WARN_ON(1); 772 WARN_ON(1);
776 return try_to_free_buffers(page); 773 return 0;
777} 774}
778 775
779static void exofs_invalidatepage(struct page *page, unsigned long offset) 776static void exofs_invalidatepage(struct page *page, unsigned long offset)
780{ 777{
781 EXOFS_DBGMSG("page_has_buffers=>%d\n", page_has_buffers(page)); 778 EXOFS_DBGMSG("page 0x%lx offset 0x%lx\n", page->index, offset);
782 WARN_ON(1); 779 WARN_ON(1);
783
784 block_invalidatepage(page, offset);
785} 780}
786 781
787const struct address_space_operations exofs_aops = { 782const struct address_space_operations exofs_aops = {
diff --git a/fs/exofs/ios.c b/fs/exofs/ios.c
index e2732203fa93..6550bf70e41d 100644
--- a/fs/exofs/ios.c
+++ b/fs/exofs/ios.c
@@ -305,8 +305,6 @@ int exofs_check_io(struct exofs_io_state *ios, u64 *resid)
305struct _striping_info { 305struct _striping_info {
306 u64 obj_offset; 306 u64 obj_offset;
307 u64 group_length; 307 u64 group_length;
308 u64 total_group_length;
309 u64 Major;
310 unsigned dev; 308 unsigned dev;
311 unsigned unit_off; 309 unsigned unit_off;
312}; 310};
@@ -343,8 +341,6 @@ static void _calc_stripe_info(struct exofs_io_state *ios, u64 file_offset,
343 (M * group_depth * stripe_unit); 341 (M * group_depth * stripe_unit);
344 342
345 si->group_length = T - H; 343 si->group_length = T - H;
346 si->total_group_length = T;
347 si->Major = M;
348} 344}
349 345
350static int _add_stripe_unit(struct exofs_io_state *ios, unsigned *cur_pg, 346static int _add_stripe_unit(struct exofs_io_state *ios, unsigned *cur_pg,
@@ -392,20 +388,19 @@ static int _add_stripe_unit(struct exofs_io_state *ios, unsigned *cur_pg,
392} 388}
393 389
394static int _prepare_one_group(struct exofs_io_state *ios, u64 length, 390static int _prepare_one_group(struct exofs_io_state *ios, u64 length,
395 struct _striping_info *si, unsigned first_comp) 391 struct _striping_info *si)
396{ 392{
397 unsigned stripe_unit = ios->layout->stripe_unit; 393 unsigned stripe_unit = ios->layout->stripe_unit;
398 unsigned mirrors_p1 = ios->layout->mirrors_p1; 394 unsigned mirrors_p1 = ios->layout->mirrors_p1;
399 unsigned devs_in_group = ios->layout->group_width * mirrors_p1; 395 unsigned devs_in_group = ios->layout->group_width * mirrors_p1;
400 unsigned dev = si->dev; 396 unsigned dev = si->dev;
401 unsigned first_dev = dev - (dev % devs_in_group); 397 unsigned first_dev = dev - (dev % devs_in_group);
402 unsigned comp = first_comp + (dev - first_dev);
403 unsigned max_comp = ios->numdevs ? ios->numdevs - mirrors_p1 : 0; 398 unsigned max_comp = ios->numdevs ? ios->numdevs - mirrors_p1 : 0;
404 unsigned cur_pg = ios->pages_consumed; 399 unsigned cur_pg = ios->pages_consumed;
405 int ret = 0; 400 int ret = 0;
406 401
407 while (length) { 402 while (length) {
408 struct exofs_per_dev_state *per_dev = &ios->per_dev[comp]; 403 struct exofs_per_dev_state *per_dev = &ios->per_dev[dev];
409 unsigned cur_len, page_off = 0; 404 unsigned cur_len, page_off = 0;
410 405
411 if (!per_dev->length) { 406 if (!per_dev->length) {
@@ -424,11 +419,8 @@ static int _prepare_one_group(struct exofs_io_state *ios, u64 length,
424 cur_len = stripe_unit; 419 cur_len = stripe_unit;
425 } 420 }
426 421
427 if (max_comp < comp) 422 if (max_comp < dev)
428 max_comp = comp; 423 max_comp = dev;
429
430 dev += mirrors_p1;
431 dev = (dev % devs_in_group) + first_dev;
432 } else { 424 } else {
433 cur_len = stripe_unit; 425 cur_len = stripe_unit;
434 } 426 }
@@ -440,8 +432,8 @@ static int _prepare_one_group(struct exofs_io_state *ios, u64 length,
440 if (unlikely(ret)) 432 if (unlikely(ret))
441 goto out; 433 goto out;
442 434
443 comp += mirrors_p1; 435 dev += mirrors_p1;
444 comp = (comp % devs_in_group) + first_comp; 436 dev = (dev % devs_in_group) + first_dev;
445 437
446 length -= cur_len; 438 length -= cur_len;
447 } 439 }
@@ -454,18 +446,15 @@ out:
454static int _prepare_for_striping(struct exofs_io_state *ios) 446static int _prepare_for_striping(struct exofs_io_state *ios)
455{ 447{
456 u64 length = ios->length; 448 u64 length = ios->length;
449 u64 offset = ios->offset;
457 struct _striping_info si; 450 struct _striping_info si;
458 unsigned devs_in_group = ios->layout->group_width *
459 ios->layout->mirrors_p1;
460 unsigned first_comp = 0;
461 int ret = 0; 451 int ret = 0;
462 452
463 _calc_stripe_info(ios, ios->offset, &si);
464
465 if (!ios->pages) { 453 if (!ios->pages) {
466 if (ios->kern_buff) { 454 if (ios->kern_buff) {
467 struct exofs_per_dev_state *per_dev = &ios->per_dev[0]; 455 struct exofs_per_dev_state *per_dev = &ios->per_dev[0];
468 456
457 _calc_stripe_info(ios, ios->offset, &si);
469 per_dev->offset = si.obj_offset; 458 per_dev->offset = si.obj_offset;
470 per_dev->dev = si.dev; 459 per_dev->dev = si.dev;
471 460
@@ -479,26 +468,17 @@ static int _prepare_for_striping(struct exofs_io_state *ios)
479 } 468 }
480 469
481 while (length) { 470 while (length) {
471 _calc_stripe_info(ios, offset, &si);
472
482 if (length < si.group_length) 473 if (length < si.group_length)
483 si.group_length = length; 474 si.group_length = length;
484 475
485 ret = _prepare_one_group(ios, si.group_length, &si, first_comp); 476 ret = _prepare_one_group(ios, si.group_length, &si);
486 if (unlikely(ret)) 477 if (unlikely(ret))
487 goto out; 478 goto out;
488 479
480 offset += si.group_length;
489 length -= si.group_length; 481 length -= si.group_length;
490
491 si.group_length = si.total_group_length;
492 si.unit_off = 0;
493 ++si.Major;
494 si.obj_offset = si.Major * ios->layout->stripe_unit *
495 ios->layout->group_depth;
496
497 si.dev = (si.dev - (si.dev % devs_in_group)) + devs_in_group;
498 si.dev %= ios->layout->s_numdevs;
499
500 first_comp += devs_in_group;
501 first_comp %= ios->layout->s_numdevs;
502 } 482 }
503 483
504out: 484out:
diff --git a/fs/exofs/super.c b/fs/exofs/super.c
index 32cfd61def5f..047e92fa3af8 100644
--- a/fs/exofs/super.c
+++ b/fs/exofs/super.c
@@ -31,7 +31,6 @@
31 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 31 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 */ 32 */
33 33
34#include <linux/smp_lock.h>
35#include <linux/string.h> 34#include <linux/string.h>
36#include <linux/parser.h> 35#include <linux/parser.h>
37#include <linux/vfs.h> 36#include <linux/vfs.h>
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 9d175d623aab..6769fd0f35b8 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -767,11 +767,22 @@ void kill_fasync(struct fasync_struct **fp, int sig, int band)
767} 767}
768EXPORT_SYMBOL(kill_fasync); 768EXPORT_SYMBOL(kill_fasync);
769 769
770static int __init fasync_init(void) 770static int __init fcntl_init(void)
771{ 771{
772 /* please add new bits here to ensure allocation uniqueness */
773 BUILD_BUG_ON(19 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
774 O_RDONLY | O_WRONLY | O_RDWR |
775 O_CREAT | O_EXCL | O_NOCTTY |
776 O_TRUNC | O_APPEND | O_NONBLOCK |
777 __O_SYNC | O_DSYNC | FASYNC |
778 O_DIRECT | O_LARGEFILE | O_DIRECTORY |
779 O_NOFOLLOW | O_NOATIME | O_CLOEXEC |
780 FMODE_EXEC
781 ));
782
772 fasync_cache = kmem_cache_create("fasync_cache", 783 fasync_cache = kmem_cache_create("fasync_cache",
773 sizeof(struct fasync_struct), 0, SLAB_PANIC, NULL); 784 sizeof(struct fasync_struct), 0, SLAB_PANIC, NULL);
774 return 0; 785 return 0;
775} 786}
776 787
777module_init(fasync_init) 788module_init(fcntl_init)
diff --git a/fs/file.c b/fs/file.c
index cccaead962c2..0be344755c02 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -39,28 +39,27 @@ int sysctl_nr_open_max = 1024 * 1024; /* raised later */
39 */ 39 */
40static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); 40static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list);
41 41
42static inline void * alloc_fdmem(unsigned int size) 42static inline void *alloc_fdmem(unsigned int size)
43{ 43{
44 if (size <= PAGE_SIZE) 44 void *data;
45 return kmalloc(size, GFP_KERNEL); 45
46 else 46 data = kmalloc(size, GFP_KERNEL|__GFP_NOWARN);
47 return vmalloc(size); 47 if (data != NULL)
48 return data;
49
50 return vmalloc(size);
48} 51}
49 52
50static inline void free_fdarr(struct fdtable *fdt) 53static void free_fdmem(void *ptr)
51{ 54{
52 if (fdt->max_fds <= (PAGE_SIZE / sizeof(struct file *))) 55 is_vmalloc_addr(ptr) ? vfree(ptr) : kfree(ptr);
53 kfree(fdt->fd);
54 else
55 vfree(fdt->fd);
56} 56}
57 57
58static inline void free_fdset(struct fdtable *fdt) 58static void __free_fdtable(struct fdtable *fdt)
59{ 59{
60 if (fdt->max_fds <= (PAGE_SIZE * BITS_PER_BYTE / 2)) 60 free_fdmem(fdt->fd);
61 kfree(fdt->open_fds); 61 free_fdmem(fdt->open_fds);
62 else 62 kfree(fdt);
63 vfree(fdt->open_fds);
64} 63}
65 64
66static void free_fdtable_work(struct work_struct *work) 65static void free_fdtable_work(struct work_struct *work)
@@ -75,9 +74,8 @@ static void free_fdtable_work(struct work_struct *work)
75 spin_unlock_bh(&f->lock); 74 spin_unlock_bh(&f->lock);
76 while(fdt) { 75 while(fdt) {
77 struct fdtable *next = fdt->next; 76 struct fdtable *next = fdt->next;
78 vfree(fdt->fd); 77
79 free_fdset(fdt); 78 __free_fdtable(fdt);
80 kfree(fdt);
81 fdt = next; 79 fdt = next;
82 } 80 }
83} 81}
@@ -98,7 +96,7 @@ void free_fdtable_rcu(struct rcu_head *rcu)
98 container_of(fdt, struct files_struct, fdtab)); 96 container_of(fdt, struct files_struct, fdtab));
99 return; 97 return;
100 } 98 }
101 if (fdt->max_fds <= (PAGE_SIZE / sizeof(struct file *))) { 99 if (!is_vmalloc_addr(fdt->fd) && !is_vmalloc_addr(fdt->open_fds)) {
102 kfree(fdt->fd); 100 kfree(fdt->fd);
103 kfree(fdt->open_fds); 101 kfree(fdt->open_fds);
104 kfree(fdt); 102 kfree(fdt);
@@ -183,7 +181,7 @@ static struct fdtable * alloc_fdtable(unsigned int nr)
183 return fdt; 181 return fdt;
184 182
185out_arr: 183out_arr:
186 free_fdarr(fdt); 184 free_fdmem(fdt->fd);
187out_fdt: 185out_fdt:
188 kfree(fdt); 186 kfree(fdt);
189out: 187out:
@@ -213,9 +211,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
213 * caller and alloc_fdtable(). Cheaper to catch it here... 211 * caller and alloc_fdtable(). Cheaper to catch it here...
214 */ 212 */
215 if (unlikely(new_fdt->max_fds <= nr)) { 213 if (unlikely(new_fdt->max_fds <= nr)) {
216 free_fdarr(new_fdt); 214 __free_fdtable(new_fdt);
217 free_fdset(new_fdt);
218 kfree(new_fdt);
219 return -EMFILE; 215 return -EMFILE;
220 } 216 }
221 /* 217 /*
@@ -231,9 +227,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
231 free_fdtable(cur_fdt); 227 free_fdtable(cur_fdt);
232 } else { 228 } else {
233 /* Somebody else expanded, so undo our attempt */ 229 /* Somebody else expanded, so undo our attempt */
234 free_fdarr(new_fdt); 230 __free_fdtable(new_fdt);
235 free_fdset(new_fdt);
236 kfree(new_fdt);
237 } 231 }
238 return 1; 232 return 1;
239} 233}
@@ -323,11 +317,8 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
323 while (unlikely(open_files > new_fdt->max_fds)) { 317 while (unlikely(open_files > new_fdt->max_fds)) {
324 spin_unlock(&oldf->file_lock); 318 spin_unlock(&oldf->file_lock);
325 319
326 if (new_fdt != &newf->fdtab) { 320 if (new_fdt != &newf->fdtab)
327 free_fdarr(new_fdt); 321 __free_fdtable(new_fdt);
328 free_fdset(new_fdt);
329 kfree(new_fdt);
330 }
331 322
332 new_fdt = alloc_fdtable(open_files - 1); 323 new_fdt = alloc_fdtable(open_files - 1);
333 if (!new_fdt) { 324 if (!new_fdt) {
@@ -337,9 +328,7 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
337 328
338 /* beyond sysctl_nr_open; nothing to do */ 329 /* beyond sysctl_nr_open; nothing to do */
339 if (unlikely(new_fdt->max_fds < open_files)) { 330 if (unlikely(new_fdt->max_fds < open_files)) {
340 free_fdarr(new_fdt); 331 __free_fdtable(new_fdt);
341 free_fdset(new_fdt);
342 kfree(new_fdt);
343 *errorp = -EMFILE; 332 *errorp = -EMFILE;
344 goto out_release; 333 goto out_release;
345 } 334 }
diff --git a/fs/file_table.c b/fs/file_table.c
index b8a0bb63cbd7..edecd36fed9b 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -230,15 +230,6 @@ static void __fput(struct file *file)
230 might_sleep(); 230 might_sleep();
231 231
232 fsnotify_close(file); 232 fsnotify_close(file);
233
234 /*
235 * fsnotify_create_event may have taken one or more references on this
236 * file. If it did so it left one reference for us to drop to make sure
237 * its calls to fput could not prematurely destroy the file.
238 */
239 if (atomic_long_read(&file->f_count))
240 return fput(file);
241
242 /* 233 /*
243 * The function eventpoll_release() should be the first called 234 * The function eventpoll_release() should be the first called
244 * in the file cleanup chain. 235 * in the file cleanup chain.
@@ -298,11 +289,20 @@ struct file *fget(unsigned int fd)
298EXPORT_SYMBOL(fget); 289EXPORT_SYMBOL(fget);
299 290
300/* 291/*
301 * Lightweight file lookup - no refcnt increment if fd table isn't shared. 292 * Lightweight file lookup - no refcnt increment if fd table isn't shared.
302 * You can use this only if it is guranteed that the current task already 293 *
303 * holds a refcnt to that file. That check has to be done at fget() only 294 * You can use this instead of fget if you satisfy all of the following
304 * and a flag is returned to be passed to the corresponding fput_light(). 295 * conditions:
305 * There must not be a cloning between an fget_light/fput_light pair. 296 * 1) You must call fput_light before exiting the syscall and returning control
297 * to userspace (i.e. you cannot remember the returned struct file * after
298 * returning to userspace).
299 * 2) You must not call filp_close on the returned struct file * in between
300 * calls to fget_light and fput_light.
301 * 3) You must not clone the current task in between the calls to fget_light
302 * and fput_light.
303 *
304 * The fput_needed flag returned by fget_light should be passed to the
305 * corresponding fput_light.
306 */ 306 */
307struct file *fget_light(unsigned int fd, int *fput_needed) 307struct file *fget_light(unsigned int fd, int *fput_needed)
308{ 308{
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 2f76c4a081a2..7d9d06ba184b 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -68,7 +68,7 @@ int nr_pdflush_threads;
68 */ 68 */
69int writeback_in_progress(struct backing_dev_info *bdi) 69int writeback_in_progress(struct backing_dev_info *bdi)
70{ 70{
71 return !list_empty(&bdi->work_list); 71 return test_bit(BDI_writeback_running, &bdi->state);
72} 72}
73 73
74static void bdi_queue_work(struct backing_dev_info *bdi, 74static void bdi_queue_work(struct backing_dev_info *bdi,
@@ -249,10 +249,18 @@ static void move_expired_inodes(struct list_head *delaying_queue,
249 249
250/* 250/*
251 * Queue all expired dirty inodes for io, eldest first. 251 * Queue all expired dirty inodes for io, eldest first.
252 * Before
253 * newly dirtied b_dirty b_io b_more_io
254 * =============> gf edc BA
255 * After
256 * newly dirtied b_dirty b_io b_more_io
257 * =============> g fBAedc
258 * |
259 * +--> dequeue for IO
252 */ 260 */
253static void queue_io(struct bdi_writeback *wb, unsigned long *older_than_this) 261static void queue_io(struct bdi_writeback *wb, unsigned long *older_than_this)
254{ 262{
255 list_splice_init(&wb->b_more_io, wb->b_io.prev); 263 list_splice_init(&wb->b_more_io, &wb->b_io);
256 move_expired_inodes(&wb->b_dirty, &wb->b_io, older_than_this); 264 move_expired_inodes(&wb->b_dirty, &wb->b_io, older_than_this);
257} 265}
258 266
@@ -363,62 +371,35 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
363 spin_lock(&inode_lock); 371 spin_lock(&inode_lock);
364 inode->i_state &= ~I_SYNC; 372 inode->i_state &= ~I_SYNC;
365 if (!(inode->i_state & I_FREEING)) { 373 if (!(inode->i_state & I_FREEING)) {
366 if ((inode->i_state & I_DIRTY_PAGES) && wbc->for_kupdate) { 374 if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
367 /*
368 * More pages get dirtied by a fast dirtier.
369 */
370 goto select_queue;
371 } else if (inode->i_state & I_DIRTY) {
372 /*
373 * At least XFS will redirty the inode during the
374 * writeback (delalloc) and on io completion (isize).
375 */
376 redirty_tail(inode);
377 } else if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
378 /* 375 /*
379 * We didn't write back all the pages. nfs_writepages() 376 * We didn't write back all the pages. nfs_writepages()
380 * sometimes bales out without doing anything. Redirty 377 * sometimes bales out without doing anything.
381 * the inode; Move it from b_io onto b_more_io/b_dirty.
382 */ 378 */
383 /* 379 inode->i_state |= I_DIRTY_PAGES;
384 * akpm: if the caller was the kupdate function we put 380 if (wbc->nr_to_write <= 0) {
385 * this inode at the head of b_dirty so it gets first
386 * consideration. Otherwise, move it to the tail, for
387 * the reasons described there. I'm not really sure
388 * how much sense this makes. Presumably I had a good
389 * reasons for doing it this way, and I'd rather not
390 * muck with it at present.
391 */
392 if (wbc->for_kupdate) {
393 /* 381 /*
394 * For the kupdate function we move the inode 382 * slice used up: queue for next turn
395 * to b_more_io so it will get more writeout as
396 * soon as the queue becomes uncongested.
397 */ 383 */
398 inode->i_state |= I_DIRTY_PAGES; 384 requeue_io(inode);
399select_queue:
400 if (wbc->nr_to_write <= 0) {
401 /*
402 * slice used up: queue for next turn
403 */
404 requeue_io(inode);
405 } else {
406 /*
407 * somehow blocked: retry later
408 */
409 redirty_tail(inode);
410 }
411 } else { 385 } else {
412 /* 386 /*
413 * Otherwise fully redirty the inode so that 387 * Writeback blocked by something other than
414 * other inodes on this superblock will get some 388 * congestion. Delay the inode for some time to
415 * writeout. Otherwise heavy writing to one 389 * avoid spinning on the CPU (100% iowait)
416 * file would indefinitely suspend writeout of 390 * retrying writeback of the dirty page/inode
417 * all the other files. 391 * that cannot be performed immediately.
418 */ 392 */
419 inode->i_state |= I_DIRTY_PAGES;
420 redirty_tail(inode); 393 redirty_tail(inode);
421 } 394 }
395 } else if (inode->i_state & I_DIRTY) {
396 /*
397 * Filesystems can dirty the inode during writeback
398 * operations, such as delayed allocation during
399 * submission or metadata updates after data IO
400 * completion.
401 */
402 redirty_tail(inode);
422 } else if (atomic_read(&inode->i_count)) { 403 } else if (atomic_read(&inode->i_count)) {
423 /* 404 /*
424 * The inode is clean, inuse 405 * The inode is clean, inuse
@@ -590,7 +571,7 @@ static inline bool over_bground_thresh(void)
590{ 571{
591 unsigned long background_thresh, dirty_thresh; 572 unsigned long background_thresh, dirty_thresh;
592 573
593 get_dirty_limits(&background_thresh, &dirty_thresh, NULL, NULL); 574 global_dirty_limits(&background_thresh, &dirty_thresh);
594 575
595 return (global_page_state(NR_FILE_DIRTY) + 576 return (global_page_state(NR_FILE_DIRTY) +
596 global_page_state(NR_UNSTABLE_NFS) >= background_thresh); 577 global_page_state(NR_UNSTABLE_NFS) >= background_thresh);
@@ -759,6 +740,7 @@ long wb_do_writeback(struct bdi_writeback *wb, int force_wait)
759 struct wb_writeback_work *work; 740 struct wb_writeback_work *work;
760 long wrote = 0; 741 long wrote = 0;
761 742
743 set_bit(BDI_writeback_running, &wb->bdi->state);
762 while ((work = get_next_work_item(bdi)) != NULL) { 744 while ((work = get_next_work_item(bdi)) != NULL) {
763 /* 745 /*
764 * Override sync mode, in case we must wait for completion 746 * Override sync mode, in case we must wait for completion
@@ -785,6 +767,7 @@ long wb_do_writeback(struct bdi_writeback *wb, int force_wait)
785 * Check for periodic writeback, kupdated() style 767 * Check for periodic writeback, kupdated() style
786 */ 768 */
787 wrote += wb_check_old_data_flush(wb); 769 wrote += wb_check_old_data_flush(wb);
770 clear_bit(BDI_writeback_running, &wb->bdi->state);
788 771
789 return wrote; 772 return wrote;
790} 773}
diff --git a/fs/fs_struct.c b/fs/fs_struct.c
index eee059052db5..1ee40eb9a2c0 100644
--- a/fs/fs_struct.c
+++ b/fs/fs_struct.c
@@ -106,12 +106,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
106 fs->in_exec = 0; 106 fs->in_exec = 0;
107 rwlock_init(&fs->lock); 107 rwlock_init(&fs->lock);
108 fs->umask = old->umask; 108 fs->umask = old->umask;
109 read_lock(&old->lock); 109 get_fs_root_and_pwd(old, &fs->root, &fs->pwd);
110 fs->root = old->root;
111 path_get(&old->root);
112 fs->pwd = old->pwd;
113 path_get(&old->pwd);
114 read_unlock(&old->lock);
115 } 110 }
116 return fs; 111 return fs;
117} 112}
diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
index 6a026441c5a6..f6aad48d38a8 100644
--- a/fs/fscache/internal.h
+++ b/fs/fscache/internal.h
@@ -321,17 +321,11 @@ void fscache_put_context(struct fscache_cookie *cookie, void *context)
321#define dbgprintk(FMT, ...) \ 321#define dbgprintk(FMT, ...) \
322 printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__) 322 printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
323 323
324/* make sure we maintain the format strings, even when debugging is disabled */
325static inline __attribute__((format(printf, 1, 2)))
326void _dbprintk(const char *fmt, ...)
327{
328}
329
330#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__) 324#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
331#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__) 325#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
332#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__) 326#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
333 327
334#define kjournal(FMT, ...) _dbprintk(FMT, ##__VA_ARGS__) 328#define kjournal(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
335 329
336#ifdef __KDEBUG 330#ifdef __KDEBUG
337#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__) 331#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
@@ -358,9 +352,9 @@ do { \
358} while (0) 352} while (0)
359 353
360#else 354#else
361#define _enter(FMT, ...) _dbprintk("==> %s("FMT")", __func__, ##__VA_ARGS__) 355#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
362#define _leave(FMT, ...) _dbprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__) 356#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
363#define _debug(FMT, ...) _dbprintk(FMT, ##__VA_ARGS__) 357#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
364#endif 358#endif
365 359
366/* 360/*
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index 6b4dcd4f2943..5a44811b5027 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -722,7 +722,12 @@ root_found:
722 } 722 }
723 723
724 s->s_magic = ISOFS_SUPER_MAGIC; 724 s->s_magic = ISOFS_SUPER_MAGIC;
725 s->s_maxbytes = 0xffffffff; /* We can handle files up to 4 GB */ 725
726 /*
727 * With multi-extent files, file size is only limited by the maximum
728 * size of a file system, which is 8 TB.
729 */
730 s->s_maxbytes = 0x80000000000LL;
726 731
727 /* 732 /*
728 * The CDROM is read-only, has no nodes (devices) on it, and since 733 * The CDROM is read-only, has no nodes (devices) on it, and since
diff --git a/fs/namei.c b/fs/namei.c
index 13ff4abdbdca..17ea76bf2fbe 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -483,13 +483,8 @@ ok:
483 483
484static __always_inline void set_root(struct nameidata *nd) 484static __always_inline void set_root(struct nameidata *nd)
485{ 485{
486 if (!nd->root.mnt) { 486 if (!nd->root.mnt)
487 struct fs_struct *fs = current->fs; 487 get_fs_root(current->fs, &nd->root);
488 read_lock(&fs->lock);
489 nd->root = fs->root;
490 path_get(&nd->root);
491 read_unlock(&fs->lock);
492 }
493} 488}
494 489
495static int link_path_walk(const char *, struct nameidata *); 490static int link_path_walk(const char *, struct nameidata *);
@@ -1015,11 +1010,7 @@ static int path_init(int dfd, const char *name, unsigned int flags, struct namei
1015 nd->path = nd->root; 1010 nd->path = nd->root;
1016 path_get(&nd->root); 1011 path_get(&nd->root);
1017 } else if (dfd == AT_FDCWD) { 1012 } else if (dfd == AT_FDCWD) {
1018 struct fs_struct *fs = current->fs; 1013 get_fs_pwd(current->fs, &nd->path);
1019 read_lock(&fs->lock);
1020 nd->path = fs->pwd;
1021 path_get(&fs->pwd);
1022 read_unlock(&fs->lock);
1023 } else { 1014 } else {
1024 struct dentry *dentry; 1015 struct dentry *dentry;
1025 1016
diff --git a/fs/namespace.c b/fs/namespace.c
index 66c4f7e781cb..2e10cb19c5b0 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -788,7 +788,6 @@ static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt)
788 { MNT_NOATIME, ",noatime" }, 788 { MNT_NOATIME, ",noatime" },
789 { MNT_NODIRATIME, ",nodiratime" }, 789 { MNT_NODIRATIME, ",nodiratime" },
790 { MNT_RELATIME, ",relatime" }, 790 { MNT_RELATIME, ",relatime" },
791 { MNT_STRICTATIME, ",strictatime" },
792 { 0, NULL } 791 { 0, NULL }
793 }; 792 };
794 const struct proc_fs_info *fs_infop; 793 const struct proc_fs_info *fs_infop;
@@ -2213,10 +2212,7 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
2213 goto out1; 2212 goto out1;
2214 } 2213 }
2215 2214
2216 read_lock(&current->fs->lock); 2215 get_fs_root(current->fs, &root);
2217 root = current->fs->root;
2218 path_get(&current->fs->root);
2219 read_unlock(&current->fs->lock);
2220 down_write(&namespace_sem); 2216 down_write(&namespace_sem);
2221 mutex_lock(&old.dentry->d_inode->i_mutex); 2217 mutex_lock(&old.dentry->d_inode->i_mutex);
2222 error = -EINVAL; 2218 error = -EINVAL;
diff --git a/fs/nfs/Kconfig b/fs/nfs/Kconfig
index cc1bb33b59b8..26a510a7be09 100644
--- a/fs/nfs/Kconfig
+++ b/fs/nfs/Kconfig
@@ -100,3 +100,20 @@ config NFS_FSCACHE
100 help 100 help
101 Say Y here if you want NFS data to be cached locally on disc through 101 Say Y here if you want NFS data to be cached locally on disc through
102 the general filesystem cache manager 102 the general filesystem cache manager
103
104config NFS_USE_LEGACY_DNS
105 bool "Use the legacy NFS DNS resolver"
106 depends on NFS_V4
107 help
108 The kernel now provides a method for translating a host name into an
109 IP address. Select Y here if you would rather use your own DNS
110 resolver script.
111
112 If unsure, say N
113
114config NFS_USE_KERNEL_DNS
115 bool
116 depends on NFS_V4 && !NFS_USE_LEGACY_DNS
117 select DNS_RESOLVER
118 select KEYS
119 default y
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index 36dfdae95123..e17b49e2eabd 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -45,7 +45,7 @@ unsigned short nfs_callback_tcpport;
45unsigned short nfs_callback_tcpport6; 45unsigned short nfs_callback_tcpport6;
46#define NFS_CALLBACK_MAXPORTNR (65535U) 46#define NFS_CALLBACK_MAXPORTNR (65535U)
47 47
48static int param_set_portnr(const char *val, struct kernel_param *kp) 48static int param_set_portnr(const char *val, const struct kernel_param *kp)
49{ 49{
50 unsigned long num; 50 unsigned long num;
51 int ret; 51 int ret;
@@ -58,11 +58,10 @@ static int param_set_portnr(const char *val, struct kernel_param *kp)
58 *((unsigned int *)kp->arg) = num; 58 *((unsigned int *)kp->arg) = num;
59 return 0; 59 return 0;
60} 60}
61 61static struct kernel_param_ops param_ops_portnr = {
62static int param_get_portnr(char *buffer, struct kernel_param *kp) 62 .set = param_set_portnr,
63{ 63 .get = param_get_uint,
64 return param_get_uint(buffer, kp); 64};
65}
66#define param_check_portnr(name, p) __param_check(name, p, unsigned int); 65#define param_check_portnr(name, p) __param_check(name, p, unsigned int);
67 66
68module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644); 67module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
diff --git a/fs/nfs/dns_resolve.c b/fs/nfs/dns_resolve.c
index 76fd235d0024..dba50a5625db 100644
--- a/fs/nfs/dns_resolve.c
+++ b/fs/nfs/dns_resolve.c
@@ -6,6 +6,29 @@
6 * Resolves DNS hostnames into valid ip addresses 6 * Resolves DNS hostnames into valid ip addresses
7 */ 7 */
8 8
9#ifdef CONFIG_NFS_USE_KERNEL_DNS
10
11#include <linux/sunrpc/clnt.h>
12#include <linux/dns_resolver.h>
13
14ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
15 struct sockaddr *sa, size_t salen)
16{
17 ssize_t ret;
18 char *ip_addr = NULL;
19 int ip_len;
20
21 ip_len = dns_query(NULL, name, namelen, NULL, &ip_addr, NULL);
22 if (ip_len > 0)
23 ret = rpc_pton(ip_addr, ip_len, sa, salen);
24 else
25 ret = -ESRCH;
26 kfree(ip_addr);
27 return ret;
28}
29
30#else
31
9#include <linux/hash.h> 32#include <linux/hash.h>
10#include <linux/string.h> 33#include <linux/string.h>
11#include <linux/kmod.h> 34#include <linux/kmod.h>
@@ -346,3 +369,4 @@ void nfs_dns_resolver_destroy(void)
346 nfs_cache_unregister(&nfs_dns_resolve); 369 nfs_cache_unregister(&nfs_dns_resolve);
347} 370}
348 371
372#endif
diff --git a/fs/nfs/dns_resolve.h b/fs/nfs/dns_resolve.h
index a3f0938babf7..199bb5543a91 100644
--- a/fs/nfs/dns_resolve.h
+++ b/fs/nfs/dns_resolve.h
@@ -6,8 +6,20 @@
6 6
7#define NFS_DNS_HOSTNAME_MAXLEN (128) 7#define NFS_DNS_HOSTNAME_MAXLEN (128)
8 8
9
10#ifdef CONFIG_NFS_USE_KERNEL_DNS
11static inline int nfs_dns_resolver_init(void)
12{
13 return 0;
14}
15
16static inline void nfs_dns_resolver_destroy(void)
17{}
18#else
9extern int nfs_dns_resolver_init(void); 19extern int nfs_dns_resolver_init(void);
10extern void nfs_dns_resolver_destroy(void); 20extern void nfs_dns_resolver_destroy(void);
21#endif
22
11extern ssize_t nfs_dns_resolve_name(char *name, size_t namelen, 23extern ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
12 struct sockaddr *sa, size_t salen); 24 struct sockaddr *sa, size_t salen);
13 25
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index eb8f73c9c131..756566fe8449 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -17,9 +17,9 @@ static bool should_merge(struct fsnotify_event *old, struct fsnotify_event *new)
17 old->data_type == new->data_type && 17 old->data_type == new->data_type &&
18 old->tgid == new->tgid) { 18 old->tgid == new->tgid) {
19 switch (old->data_type) { 19 switch (old->data_type) {
20 case (FSNOTIFY_EVENT_FILE): 20 case (FSNOTIFY_EVENT_PATH):
21 if ((old->file->f_path.mnt == new->file->f_path.mnt) && 21 if ((old->path.mnt == new->path.mnt) &&
22 (old->file->f_path.dentry == new->file->f_path.dentry)) 22 (old->path.dentry == new->path.dentry))
23 return true; 23 return true;
24 case (FSNOTIFY_EVENT_NONE): 24 case (FSNOTIFY_EVENT_NONE):
25 return true; 25 return true;
@@ -174,7 +174,7 @@ static bool fanotify_should_send_event(struct fsnotify_group *group,
174 return false; 174 return false;
175 175
176 /* if we don't have enough info to send an event to userspace say no */ 176 /* if we don't have enough info to send an event to userspace say no */
177 if (data_type != FSNOTIFY_EVENT_FILE) 177 if (data_type != FSNOTIFY_EVENT_PATH)
178 return false; 178 return false;
179 179
180 if (inode_mark && vfsmnt_mark) { 180 if (inode_mark && vfsmnt_mark) {
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 25a3b4dfcf61..032b837fcd11 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -65,7 +65,7 @@ static int create_fd(struct fsnotify_group *group, struct fsnotify_event *event)
65 if (client_fd < 0) 65 if (client_fd < 0)
66 return client_fd; 66 return client_fd;
67 67
68 if (event->data_type != FSNOTIFY_EVENT_FILE) { 68 if (event->data_type != FSNOTIFY_EVENT_PATH) {
69 WARN_ON(1); 69 WARN_ON(1);
70 put_unused_fd(client_fd); 70 put_unused_fd(client_fd);
71 return -EINVAL; 71 return -EINVAL;
@@ -75,8 +75,8 @@ static int create_fd(struct fsnotify_group *group, struct fsnotify_event *event)
75 * we need a new file handle for the userspace program so it can read even if it was 75 * we need a new file handle for the userspace program so it can read even if it was
76 * originally opened O_WRONLY. 76 * originally opened O_WRONLY.
77 */ 77 */
78 dentry = dget(event->file->f_path.dentry); 78 dentry = dget(event->path.dentry);
79 mnt = mntget(event->file->f_path.mnt); 79 mnt = mntget(event->path.mnt);
80 /* it's possible this event was an overflow event. in that case dentry and mnt 80 /* it's possible this event was an overflow event. in that case dentry and mnt
81 * are NULL; That's fine, just don't call dentry open */ 81 * are NULL; That's fine, just don't call dentry open */
82 if (dentry && mnt) 82 if (dentry && mnt)
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index 4d2a82c1ceb1..3970392b2722 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -84,7 +84,7 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode)
84} 84}
85 85
86/* Notify this dentry's parent about a child's events. */ 86/* Notify this dentry's parent about a child's events. */
87void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask) 87void __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
88{ 88{
89 struct dentry *parent; 89 struct dentry *parent;
90 struct inode *p_inode; 90 struct inode *p_inode;
@@ -92,7 +92,7 @@ void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask)
92 bool should_update_children = false; 92 bool should_update_children = false;
93 93
94 if (!dentry) 94 if (!dentry)
95 dentry = file->f_path.dentry; 95 dentry = path->dentry;
96 96
97 if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED)) 97 if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED))
98 return; 98 return;
@@ -124,8 +124,8 @@ void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask)
124 * specifies these are events which came from a child. */ 124 * specifies these are events which came from a child. */
125 mask |= FS_EVENT_ON_CHILD; 125 mask |= FS_EVENT_ON_CHILD;
126 126
127 if (file) 127 if (path)
128 fsnotify(p_inode, mask, file, FSNOTIFY_EVENT_FILE, 128 fsnotify(p_inode, mask, path, FSNOTIFY_EVENT_PATH,
129 dentry->d_name.name, 0); 129 dentry->d_name.name, 0);
130 else 130 else
131 fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE, 131 fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE,
@@ -217,8 +217,8 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
217 /* global tests shouldn't care about events on child only the specific event */ 217 /* global tests shouldn't care about events on child only the specific event */
218 __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD); 218 __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD);
219 219
220 if (data_is == FSNOTIFY_EVENT_FILE) 220 if (data_is == FSNOTIFY_EVENT_PATH)
221 mnt = ((struct file *)data)->f_path.mnt; 221 mnt = ((struct path *)data)->mnt;
222 else 222 else
223 mnt = NULL; 223 mnt = NULL;
224 224
diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
index 5e73eeb2c697..a91b69a6a291 100644
--- a/fs/notify/inotify/inotify_fsnotify.c
+++ b/fs/notify/inotify/inotify_fsnotify.c
@@ -52,9 +52,9 @@ static bool event_compare(struct fsnotify_event *old, struct fsnotify_event *new
52 !strcmp(old->file_name, new->file_name)) 52 !strcmp(old->file_name, new->file_name))
53 return true; 53 return true;
54 break; 54 break;
55 case (FSNOTIFY_EVENT_FILE): 55 case (FSNOTIFY_EVENT_PATH):
56 if ((old->file->f_path.mnt == new->file->f_path.mnt) && 56 if ((old->path.mnt == new->path.mnt) &&
57 (old->file->f_path.dentry == new->file->f_path.dentry)) 57 (old->path.dentry == new->path.dentry))
58 return true; 58 return true;
59 break; 59 break;
60 case (FSNOTIFY_EVENT_NONE): 60 case (FSNOTIFY_EVENT_NONE):
@@ -147,10 +147,10 @@ static bool inotify_should_send_event(struct fsnotify_group *group, struct inode
147 __u32 mask, void *data, int data_type) 147 __u32 mask, void *data, int data_type)
148{ 148{
149 if ((inode_mark->mask & FS_EXCL_UNLINK) && 149 if ((inode_mark->mask & FS_EXCL_UNLINK) &&
150 (data_type == FSNOTIFY_EVENT_FILE)) { 150 (data_type == FSNOTIFY_EVENT_PATH)) {
151 struct file *file = data; 151 struct path *path = data;
152 152
153 if (d_unlinked(file->f_path.dentry)) 153 if (d_unlinked(path->dentry))
154 return false; 154 return false;
155 } 155 }
156 156
diff --git a/fs/notify/notification.c b/fs/notify/notification.c
index d6c435adc7a2..f39260f8f865 100644
--- a/fs/notify/notification.c
+++ b/fs/notify/notification.c
@@ -31,7 +31,6 @@
31 * allocated and used. 31 * allocated and used.
32 */ 32 */
33 33
34#include <linux/file.h>
35#include <linux/fs.h> 34#include <linux/fs.h>
36#include <linux/init.h> 35#include <linux/init.h>
37#include <linux/kernel.h> 36#include <linux/kernel.h>
@@ -90,8 +89,8 @@ void fsnotify_put_event(struct fsnotify_event *event)
90 if (atomic_dec_and_test(&event->refcnt)) { 89 if (atomic_dec_and_test(&event->refcnt)) {
91 pr_debug("%s: event=%p\n", __func__, event); 90 pr_debug("%s: event=%p\n", __func__, event);
92 91
93 if (event->data_type == FSNOTIFY_EVENT_FILE) 92 if (event->data_type == FSNOTIFY_EVENT_PATH)
94 fput(event->file); 93 path_put(&event->path);
95 94
96 BUG_ON(!list_empty(&event->private_data_list)); 95 BUG_ON(!list_empty(&event->private_data_list));
97 96
@@ -376,8 +375,8 @@ struct fsnotify_event *fsnotify_clone_event(struct fsnotify_event *old_event)
376 } 375 }
377 } 376 }
378 event->tgid = get_pid(old_event->tgid); 377 event->tgid = get_pid(old_event->tgid);
379 if (event->data_type == FSNOTIFY_EVENT_FILE) 378 if (event->data_type == FSNOTIFY_EVENT_PATH)
380 get_file(event->file); 379 path_get(&event->path);
381 380
382 return event; 381 return event;
383} 382}
@@ -424,22 +423,11 @@ struct fsnotify_event *fsnotify_create_event(struct inode *to_tell, __u32 mask,
424 event->data_type = data_type; 423 event->data_type = data_type;
425 424
426 switch (data_type) { 425 switch (data_type) {
427 case FSNOTIFY_EVENT_FILE: { 426 case FSNOTIFY_EVENT_PATH: {
428 event->file = data; 427 struct path *path = data;
429 /* 428 event->path.dentry = path->dentry;
430 * if this file is about to disappear hold an extra reference 429 event->path.mnt = path->mnt;
431 * until we return to __fput so we don't have to worry about 430 path_get(&event->path);
432 * future get/put destroying the file under us or generating
433 * additional events. Notice that we change f_mode without
434 * holding f_lock. This is safe since this is the only possible
435 * reference to this object in the kernel (it was about to be
436 * freed, remember?)
437 */
438 if (!atomic_long_read(&event->file->f_count)) {
439 event->file->f_mode |= FMODE_NONOTIFY;
440 get_file(event->file);
441 }
442 get_file(event->file);
443 break; 431 break;
444 } 432 }
445 case FSNOTIFY_EVENT_INODE: 433 case FSNOTIFY_EVENT_INODE:
@@ -447,7 +435,8 @@ struct fsnotify_event *fsnotify_create_event(struct inode *to_tell, __u32 mask,
447 break; 435 break;
448 case FSNOTIFY_EVENT_NONE: 436 case FSNOTIFY_EVENT_NONE:
449 event->inode = NULL; 437 event->inode = NULL;
450 event->file = NULL; 438 event->path.dentry = NULL;
439 event->path.mnt = NULL;
451 break; 440 break;
452 default: 441 default:
453 BUG(); 442 BUG();
diff --git a/fs/ocfs2/acl.c b/fs/ocfs2/acl.c
index da702294d7e7..a76e0aa5cd3f 100644
--- a/fs/ocfs2/acl.c
+++ b/fs/ocfs2/acl.c
@@ -290,12 +290,30 @@ static int ocfs2_set_acl(handle_t *handle,
290 290
291int ocfs2_check_acl(struct inode *inode, int mask) 291int ocfs2_check_acl(struct inode *inode, int mask)
292{ 292{
293 struct posix_acl *acl = ocfs2_get_acl(inode, ACL_TYPE_ACCESS); 293 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
294 struct buffer_head *di_bh = NULL;
295 struct posix_acl *acl;
296 int ret = -EAGAIN;
294 297
295 if (IS_ERR(acl)) 298 if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL))
299 return ret;
300
301 ret = ocfs2_read_inode_block(inode, &di_bh);
302 if (ret < 0) {
303 mlog_errno(ret);
304 return ret;
305 }
306
307 acl = ocfs2_get_acl_nolock(inode, ACL_TYPE_ACCESS, di_bh);
308
309 brelse(di_bh);
310
311 if (IS_ERR(acl)) {
312 mlog_errno(PTR_ERR(acl));
296 return PTR_ERR(acl); 313 return PTR_ERR(acl);
314 }
297 if (acl) { 315 if (acl) {
298 int ret = posix_acl_permission(inode, acl, mask); 316 ret = posix_acl_permission(inode, acl, mask);
299 posix_acl_release(acl); 317 posix_acl_release(acl);
300 return ret; 318 return ret;
301 } 319 }
@@ -344,7 +362,7 @@ int ocfs2_init_acl(handle_t *handle,
344{ 362{
345 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 363 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
346 struct posix_acl *acl = NULL; 364 struct posix_acl *acl = NULL;
347 int ret = 0; 365 int ret = 0, ret2;
348 mode_t mode; 366 mode_t mode;
349 367
350 if (!S_ISLNK(inode->i_mode)) { 368 if (!S_ISLNK(inode->i_mode)) {
@@ -381,7 +399,12 @@ int ocfs2_init_acl(handle_t *handle,
381 mode = inode->i_mode; 399 mode = inode->i_mode;
382 ret = posix_acl_create_masq(clone, &mode); 400 ret = posix_acl_create_masq(clone, &mode);
383 if (ret >= 0) { 401 if (ret >= 0) {
384 ret = ocfs2_acl_set_mode(inode, di_bh, handle, mode); 402 ret2 = ocfs2_acl_set_mode(inode, di_bh, handle, mode);
403 if (ret2) {
404 mlog_errno(ret2);
405 ret = ret2;
406 goto cleanup;
407 }
385 if (ret > 0) { 408 if (ret > 0) {
386 ret = ocfs2_set_acl(handle, inode, 409 ret = ocfs2_set_acl(handle, inode,
387 di_bh, ACL_TYPE_ACCESS, 410 di_bh, ACL_TYPE_ACCESS,
diff --git a/fs/ocfs2/cluster/tcp.c b/fs/ocfs2/cluster/tcp.c
index aa75ca3f78da..1361997cf205 100644
--- a/fs/ocfs2/cluster/tcp.c
+++ b/fs/ocfs2/cluster/tcp.c
@@ -1759,6 +1759,7 @@ static int o2net_accept_one(struct socket *sock)
1759 struct sockaddr_in sin; 1759 struct sockaddr_in sin;
1760 struct socket *new_sock = NULL; 1760 struct socket *new_sock = NULL;
1761 struct o2nm_node *node = NULL; 1761 struct o2nm_node *node = NULL;
1762 struct o2nm_node *local_node = NULL;
1762 struct o2net_sock_container *sc = NULL; 1763 struct o2net_sock_container *sc = NULL;
1763 struct o2net_node *nn; 1764 struct o2net_node *nn;
1764 1765
@@ -1796,11 +1797,15 @@ static int o2net_accept_one(struct socket *sock)
1796 goto out; 1797 goto out;
1797 } 1798 }
1798 1799
1799 if (o2nm_this_node() > node->nd_num) { 1800 if (o2nm_this_node() >= node->nd_num) {
1800 mlog(ML_NOTICE, "unexpected connect attempted from a lower " 1801 local_node = o2nm_get_node_by_num(o2nm_this_node());
1801 "numbered node '%s' at " "%pI4:%d with num %u\n", 1802 mlog(ML_NOTICE, "unexpected connect attempt seen at node '%s' ("
1802 node->nd_name, &sin.sin_addr.s_addr, 1803 "%u, %pI4:%d) from node '%s' (%u, %pI4:%d)\n",
1803 ntohs(sin.sin_port), node->nd_num); 1804 local_node->nd_name, local_node->nd_num,
1805 &(local_node->nd_ipv4_address),
1806 ntohs(local_node->nd_ipv4_port),
1807 node->nd_name, node->nd_num, &sin.sin_addr.s_addr,
1808 ntohs(sin.sin_port));
1804 ret = -EINVAL; 1809 ret = -EINVAL;
1805 goto out; 1810 goto out;
1806 } 1811 }
@@ -1857,6 +1862,8 @@ out:
1857 sock_release(new_sock); 1862 sock_release(new_sock);
1858 if (node) 1863 if (node)
1859 o2nm_node_put(node); 1864 o2nm_node_put(node);
1865 if (local_node)
1866 o2nm_node_put(local_node);
1860 if (sc) 1867 if (sc)
1861 sc_put(sc); 1868 sc_put(sc);
1862 return ret; 1869 return ret;
diff --git a/fs/ocfs2/dlm/dlmmaster.c b/fs/ocfs2/dlm/dlmmaster.c
index 94b97fc6a88e..ffb4c68dafa4 100644
--- a/fs/ocfs2/dlm/dlmmaster.c
+++ b/fs/ocfs2/dlm/dlmmaster.c
@@ -511,8 +511,6 @@ static void dlm_lockres_release(struct kref *kref)
511 511
512 atomic_dec(&dlm->res_cur_count); 512 atomic_dec(&dlm->res_cur_count);
513 513
514 dlm_put(dlm);
515
516 if (!hlist_unhashed(&res->hash_node) || 514 if (!hlist_unhashed(&res->hash_node) ||
517 !list_empty(&res->granted) || 515 !list_empty(&res->granted) ||
518 !list_empty(&res->converting) || 516 !list_empty(&res->converting) ||
@@ -585,8 +583,6 @@ static void dlm_init_lockres(struct dlm_ctxt *dlm,
585 res->migration_pending = 0; 583 res->migration_pending = 0;
586 res->inflight_locks = 0; 584 res->inflight_locks = 0;
587 585
588 /* put in dlm_lockres_release */
589 dlm_grab(dlm);
590 res->dlm = dlm; 586 res->dlm = dlm;
591 587
592 kref_init(&res->refs); 588 kref_init(&res->refs);
@@ -3050,8 +3046,6 @@ int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data,
3050 /* check for pre-existing lock */ 3046 /* check for pre-existing lock */
3051 spin_lock(&dlm->spinlock); 3047 spin_lock(&dlm->spinlock);
3052 res = __dlm_lookup_lockres(dlm, name, namelen, hash); 3048 res = __dlm_lookup_lockres(dlm, name, namelen, hash);
3053 spin_lock(&dlm->master_lock);
3054
3055 if (res) { 3049 if (res) {
3056 spin_lock(&res->spinlock); 3050 spin_lock(&res->spinlock);
3057 if (res->state & DLM_LOCK_RES_RECOVERING) { 3051 if (res->state & DLM_LOCK_RES_RECOVERING) {
@@ -3069,14 +3063,15 @@ int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data,
3069 spin_unlock(&res->spinlock); 3063 spin_unlock(&res->spinlock);
3070 } 3064 }
3071 3065
3066 spin_lock(&dlm->master_lock);
3072 /* ignore status. only nonzero status would BUG. */ 3067 /* ignore status. only nonzero status would BUG. */
3073 ret = dlm_add_migration_mle(dlm, res, mle, &oldmle, 3068 ret = dlm_add_migration_mle(dlm, res, mle, &oldmle,
3074 name, namelen, 3069 name, namelen,
3075 migrate->new_master, 3070 migrate->new_master,
3076 migrate->master); 3071 migrate->master);
3077 3072
3078unlock:
3079 spin_unlock(&dlm->master_lock); 3073 spin_unlock(&dlm->master_lock);
3074unlock:
3080 spin_unlock(&dlm->spinlock); 3075 spin_unlock(&dlm->spinlock);
3081 3076
3082 if (oldmle) { 3077 if (oldmle) {
diff --git a/fs/ocfs2/dlm/dlmrecovery.c b/fs/ocfs2/dlm/dlmrecovery.c
index 9dfaac73b36d..aaaffbcbe916 100644
--- a/fs/ocfs2/dlm/dlmrecovery.c
+++ b/fs/ocfs2/dlm/dlmrecovery.c
@@ -1997,6 +1997,8 @@ void dlm_move_lockres_to_recovery_list(struct dlm_ctxt *dlm,
1997 struct list_head *queue; 1997 struct list_head *queue;
1998 struct dlm_lock *lock, *next; 1998 struct dlm_lock *lock, *next;
1999 1999
2000 assert_spin_locked(&dlm->spinlock);
2001 assert_spin_locked(&res->spinlock);
2000 res->state |= DLM_LOCK_RES_RECOVERING; 2002 res->state |= DLM_LOCK_RES_RECOVERING;
2001 if (!list_empty(&res->recovering)) { 2003 if (!list_empty(&res->recovering)) {
2002 mlog(0, 2004 mlog(0,
@@ -2326,19 +2328,15 @@ static void dlm_do_local_recovery_cleanup(struct dlm_ctxt *dlm, u8 dead_node)
2326 /* zero the lvb if necessary */ 2328 /* zero the lvb if necessary */
2327 dlm_revalidate_lvb(dlm, res, dead_node); 2329 dlm_revalidate_lvb(dlm, res, dead_node);
2328 if (res->owner == dead_node) { 2330 if (res->owner == dead_node) {
2329 if (res->state & DLM_LOCK_RES_DROPPING_REF) 2331 if (res->state & DLM_LOCK_RES_DROPPING_REF) {
2330 mlog(0, "%s:%.*s: owned by " 2332 mlog(ML_NOTICE, "Ignore %.*s for "
2331 "dead node %u, this node was " 2333 "recovery as it is being freed\n",
2332 "dropping its ref when it died. " 2334 res->lockname.len,
2333 "continue, dropping the flag.\n", 2335 res->lockname.name);
2334 dlm->name, res->lockname.len, 2336 } else
2335 res->lockname.name, dead_node); 2337 dlm_move_lockres_to_recovery_list(dlm,
2336 2338 res);
2337 /* the wake_up for this will happen when the
2338 * RECOVERING flag is dropped later */
2339 res->state &= ~DLM_LOCK_RES_DROPPING_REF;
2340 2339
2341 dlm_move_lockres_to_recovery_list(dlm, res);
2342 } else if (res->owner == dlm->node_num) { 2340 } else if (res->owner == dlm->node_num) {
2343 dlm_free_dead_locks(dlm, res, dead_node); 2341 dlm_free_dead_locks(dlm, res, dead_node);
2344 __dlm_lockres_calc_usage(dlm, res); 2342 __dlm_lockres_calc_usage(dlm, res);
diff --git a/fs/ocfs2/dlm/dlmthread.c b/fs/ocfs2/dlm/dlmthread.c
index d4f73ca68fe5..2211acf33d9b 100644
--- a/fs/ocfs2/dlm/dlmthread.c
+++ b/fs/ocfs2/dlm/dlmthread.c
@@ -92,19 +92,27 @@ int __dlm_lockres_has_locks(struct dlm_lock_resource *res)
92 * truly ready to be freed. */ 92 * truly ready to be freed. */
93int __dlm_lockres_unused(struct dlm_lock_resource *res) 93int __dlm_lockres_unused(struct dlm_lock_resource *res)
94{ 94{
95 if (!__dlm_lockres_has_locks(res) && 95 int bit;
96 (list_empty(&res->dirty) && !(res->state & DLM_LOCK_RES_DIRTY))) { 96
97 /* try not to scan the bitmap unless the first two 97 if (__dlm_lockres_has_locks(res))
98 * conditions are already true */ 98 return 0;
99 int bit = find_next_bit(res->refmap, O2NM_MAX_NODES, 0); 99
100 if (bit >= O2NM_MAX_NODES) { 100 if (!list_empty(&res->dirty) || res->state & DLM_LOCK_RES_DIRTY)
101 /* since the bit for dlm->node_num is not 101 return 0;
102 * set, inflight_locks better be zero */ 102
103 BUG_ON(res->inflight_locks != 0); 103 if (res->state & DLM_LOCK_RES_RECOVERING)
104 return 1; 104 return 0;
105 } 105
106 } 106 bit = find_next_bit(res->refmap, O2NM_MAX_NODES, 0);
107 return 0; 107 if (bit < O2NM_MAX_NODES)
108 return 0;
109
110 /*
111 * since the bit for dlm->node_num is not set, inflight_locks better
112 * be zero
113 */
114 BUG_ON(res->inflight_locks != 0);
115 return 1;
108} 116}
109 117
110 118
@@ -152,45 +160,25 @@ void dlm_lockres_calc_usage(struct dlm_ctxt *dlm,
152 spin_unlock(&dlm->spinlock); 160 spin_unlock(&dlm->spinlock);
153} 161}
154 162
155static int dlm_purge_lockres(struct dlm_ctxt *dlm, 163static void dlm_purge_lockres(struct dlm_ctxt *dlm,
156 struct dlm_lock_resource *res) 164 struct dlm_lock_resource *res)
157{ 165{
158 int master; 166 int master;
159 int ret = 0; 167 int ret = 0;
160 168
161 spin_lock(&res->spinlock); 169 assert_spin_locked(&dlm->spinlock);
162 if (!__dlm_lockres_unused(res)) { 170 assert_spin_locked(&res->spinlock);
163 mlog(0, "%s:%.*s: tried to purge but not unused\n",
164 dlm->name, res->lockname.len, res->lockname.name);
165 __dlm_print_one_lock_resource(res);
166 spin_unlock(&res->spinlock);
167 BUG();
168 }
169
170 if (res->state & DLM_LOCK_RES_MIGRATING) {
171 mlog(0, "%s:%.*s: Delay dropref as this lockres is "
172 "being remastered\n", dlm->name, res->lockname.len,
173 res->lockname.name);
174 /* Re-add the lockres to the end of the purge list */
175 if (!list_empty(&res->purge)) {
176 list_del_init(&res->purge);
177 list_add_tail(&res->purge, &dlm->purge_list);
178 }
179 spin_unlock(&res->spinlock);
180 return 0;
181 }
182 171
183 master = (res->owner == dlm->node_num); 172 master = (res->owner == dlm->node_num);
184 173
185 if (!master)
186 res->state |= DLM_LOCK_RES_DROPPING_REF;
187 spin_unlock(&res->spinlock);
188 174
189 mlog(0, "purging lockres %.*s, master = %d\n", res->lockname.len, 175 mlog(0, "purging lockres %.*s, master = %d\n", res->lockname.len,
190 res->lockname.name, master); 176 res->lockname.name, master);
191 177
192 if (!master) { 178 if (!master) {
179 res->state |= DLM_LOCK_RES_DROPPING_REF;
193 /* drop spinlock... retake below */ 180 /* drop spinlock... retake below */
181 spin_unlock(&res->spinlock);
194 spin_unlock(&dlm->spinlock); 182 spin_unlock(&dlm->spinlock);
195 183
196 spin_lock(&res->spinlock); 184 spin_lock(&res->spinlock);
@@ -208,31 +196,35 @@ static int dlm_purge_lockres(struct dlm_ctxt *dlm,
208 mlog(0, "%s:%.*s: dlm_deref_lockres returned %d\n", 196 mlog(0, "%s:%.*s: dlm_deref_lockres returned %d\n",
209 dlm->name, res->lockname.len, res->lockname.name, ret); 197 dlm->name, res->lockname.len, res->lockname.name, ret);
210 spin_lock(&dlm->spinlock); 198 spin_lock(&dlm->spinlock);
199 spin_lock(&res->spinlock);
211 } 200 }
212 201
213 spin_lock(&res->spinlock);
214 if (!list_empty(&res->purge)) { 202 if (!list_empty(&res->purge)) {
215 mlog(0, "removing lockres %.*s:%p from purgelist, " 203 mlog(0, "removing lockres %.*s:%p from purgelist, "
216 "master = %d\n", res->lockname.len, res->lockname.name, 204 "master = %d\n", res->lockname.len, res->lockname.name,
217 res, master); 205 res, master);
218 list_del_init(&res->purge); 206 list_del_init(&res->purge);
219 spin_unlock(&res->spinlock);
220 dlm_lockres_put(res); 207 dlm_lockres_put(res);
221 dlm->purge_count--; 208 dlm->purge_count--;
222 } else 209 }
223 spin_unlock(&res->spinlock); 210
211 if (!__dlm_lockres_unused(res)) {
212 mlog(ML_ERROR, "found lockres %s:%.*s: in use after deref\n",
213 dlm->name, res->lockname.len, res->lockname.name);
214 __dlm_print_one_lock_resource(res);
215 BUG();
216 }
224 217
225 __dlm_unhash_lockres(res); 218 __dlm_unhash_lockres(res);
226 219
227 /* lockres is not in the hash now. drop the flag and wake up 220 /* lockres is not in the hash now. drop the flag and wake up
228 * any processes waiting in dlm_get_lock_resource. */ 221 * any processes waiting in dlm_get_lock_resource. */
229 if (!master) { 222 if (!master) {
230 spin_lock(&res->spinlock);
231 res->state &= ~DLM_LOCK_RES_DROPPING_REF; 223 res->state &= ~DLM_LOCK_RES_DROPPING_REF;
232 spin_unlock(&res->spinlock); 224 spin_unlock(&res->spinlock);
233 wake_up(&res->wq); 225 wake_up(&res->wq);
234 } 226 } else
235 return 0; 227 spin_unlock(&res->spinlock);
236} 228}
237 229
238static void dlm_run_purge_list(struct dlm_ctxt *dlm, 230static void dlm_run_purge_list(struct dlm_ctxt *dlm,
@@ -251,17 +243,7 @@ static void dlm_run_purge_list(struct dlm_ctxt *dlm,
251 lockres = list_entry(dlm->purge_list.next, 243 lockres = list_entry(dlm->purge_list.next,
252 struct dlm_lock_resource, purge); 244 struct dlm_lock_resource, purge);
253 245
254 /* Status of the lockres *might* change so double
255 * check. If the lockres is unused, holding the dlm
256 * spinlock will prevent people from getting and more
257 * refs on it -- there's no need to keep the lockres
258 * spinlock. */
259 spin_lock(&lockres->spinlock); 246 spin_lock(&lockres->spinlock);
260 unused = __dlm_lockres_unused(lockres);
261 spin_unlock(&lockres->spinlock);
262
263 if (!unused)
264 continue;
265 247
266 purge_jiffies = lockres->last_used + 248 purge_jiffies = lockres->last_used +
267 msecs_to_jiffies(DLM_PURGE_INTERVAL_MS); 249 msecs_to_jiffies(DLM_PURGE_INTERVAL_MS);
@@ -273,15 +255,29 @@ static void dlm_run_purge_list(struct dlm_ctxt *dlm,
273 * in tail order, we can stop at the first 255 * in tail order, we can stop at the first
274 * unpurgable resource -- anyone added after 256 * unpurgable resource -- anyone added after
275 * him will have a greater last_used value */ 257 * him will have a greater last_used value */
258 spin_unlock(&lockres->spinlock);
276 break; 259 break;
277 } 260 }
278 261
262 /* Status of the lockres *might* change so double
263 * check. If the lockres is unused, holding the dlm
264 * spinlock will prevent people from getting and more
265 * refs on it. */
266 unused = __dlm_lockres_unused(lockres);
267 if (!unused ||
268 (lockres->state & DLM_LOCK_RES_MIGRATING)) {
269 mlog(0, "lockres %s:%.*s: is in use or "
270 "being remastered, used %d, state %d\n",
271 dlm->name, lockres->lockname.len,
272 lockres->lockname.name, !unused, lockres->state);
273 list_move_tail(&dlm->purge_list, &lockres->purge);
274 spin_unlock(&lockres->spinlock);
275 continue;
276 }
277
279 dlm_lockres_get(lockres); 278 dlm_lockres_get(lockres);
280 279
281 /* This may drop and reacquire the dlm spinlock if it 280 dlm_purge_lockres(dlm, lockres);
282 * has to do migration. */
283 if (dlm_purge_lockres(dlm, lockres))
284 BUG();
285 281
286 dlm_lockres_put(lockres); 282 dlm_lockres_put(lockres);
287 283
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index 3ac5aa733e9c..73a11ccfd4c2 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -2436,16 +2436,26 @@ static int ocfs2_calc_refcount_meta_credits(struct super_block *sb,
2436 len = min((u64)cpos + clusters, le64_to_cpu(rec.r_cpos) + 2436 len = min((u64)cpos + clusters, le64_to_cpu(rec.r_cpos) +
2437 le32_to_cpu(rec.r_clusters)) - cpos; 2437 le32_to_cpu(rec.r_clusters)) - cpos;
2438 /* 2438 /*
2439 * If the refcount rec already exist, cool. We just need
2440 * to check whether there is a split. Otherwise we just need
2441 * to increase the refcount.
2442 * If we will insert one, increases recs_add.
2443 *
2444 * We record all the records which will be inserted to the 2439 * We record all the records which will be inserted to the
2445 * same refcount block, so that we can tell exactly whether 2440 * same refcount block, so that we can tell exactly whether
2446 * we need a new refcount block or not. 2441 * we need a new refcount block or not.
2442 *
2443 * If we will insert a new one, this is easy and only happens
2444 * during adding refcounted flag to the extent, so we don't
2445 * have a chance of spliting. We just need one record.
2446 *
2447 * If the refcount rec already exists, that would be a little
2448 * complicated. we may have to:
2449 * 1) split at the beginning if the start pos isn't aligned.
2450 * we need 1 more record in this case.
2451 * 2) split int the end if the end pos isn't aligned.
2452 * we need 1 more record in this case.
2453 * 3) split in the middle because of file system fragmentation.
2454 * we need 2 more records in this case(we can't detect this
2455 * beforehand, so always think of the worst case).
2447 */ 2456 */
2448 if (rec.r_refcount) { 2457 if (rec.r_refcount) {
2458 recs_add += 2;
2449 /* Check whether we need a split at the beginning. */ 2459 /* Check whether we need a split at the beginning. */
2450 if (cpos == start_cpos && 2460 if (cpos == start_cpos &&
2451 cpos != le64_to_cpu(rec.r_cpos)) 2461 cpos != le64_to_cpu(rec.r_cpos))
diff --git a/fs/open.c b/fs/open.c
index b715d06fbe36..630715f9f73d 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -1031,7 +1031,9 @@ EXPORT_SYMBOL(generic_file_open);
1031 1031
1032/* 1032/*
1033 * This is used by subsystems that don't want seekable 1033 * This is used by subsystems that don't want seekable
1034 * file descriptors 1034 * file descriptors. The function is not supposed to ever fail, the only
1035 * reason it returns an 'int' and not 'void' is so that it can be plugged
1036 * directly into file_operations structure.
1035 */ 1037 */
1036int nonseekable_open(struct inode *inode, struct file *filp) 1038int nonseekable_open(struct inode *inode, struct file *filp)
1037{ 1039{
diff --git a/fs/partitions/acorn.c b/fs/partitions/acorn.c
index 6921e7890be6..fbeb697374d5 100644
--- a/fs/partitions/acorn.c
+++ b/fs/partitions/acorn.c
@@ -45,8 +45,11 @@ adfs_partition(struct parsed_partitions *state, char *name, char *data,
45 nr_sects = (le32_to_cpu(dr->disc_size_high) << 23) | 45 nr_sects = (le32_to_cpu(dr->disc_size_high) << 23) |
46 (le32_to_cpu(dr->disc_size) >> 9); 46 (le32_to_cpu(dr->disc_size) >> 9);
47 47
48 if (name) 48 if (name) {
49 printk(" [%s]", name); 49 strlcat(state->pp_buf, " [", PAGE_SIZE);
50 strlcat(state->pp_buf, name, PAGE_SIZE);
51 strlcat(state->pp_buf, "]", PAGE_SIZE);
52 }
50 put_partition(state, slot, first_sector, nr_sects); 53 put_partition(state, slot, first_sector, nr_sects);
51 return dr; 54 return dr;
52} 55}
@@ -81,14 +84,14 @@ static int riscix_partition(struct parsed_partitions *state,
81 if (!rr) 84 if (!rr)
82 return -1; 85 return -1;
83 86
84 printk(" [RISCiX]"); 87 strlcat(state->pp_buf, " [RISCiX]", PAGE_SIZE);
85 88
86 89
87 if (rr->magic == RISCIX_MAGIC) { 90 if (rr->magic == RISCIX_MAGIC) {
88 unsigned long size = nr_sects > 2 ? 2 : nr_sects; 91 unsigned long size = nr_sects > 2 ? 2 : nr_sects;
89 int part; 92 int part;
90 93
91 printk(" <"); 94 strlcat(state->pp_buf, " <", PAGE_SIZE);
92 95
93 put_partition(state, slot++, first_sect, size); 96 put_partition(state, slot++, first_sect, size);
94 for (part = 0; part < 8; part++) { 97 for (part = 0; part < 8; part++) {
@@ -97,11 +100,13 @@ static int riscix_partition(struct parsed_partitions *state,
97 put_partition(state, slot++, 100 put_partition(state, slot++,
98 le32_to_cpu(rr->part[part].start), 101 le32_to_cpu(rr->part[part].start),
99 le32_to_cpu(rr->part[part].length)); 102 le32_to_cpu(rr->part[part].length));
100 printk("(%s)", rr->part[part].name); 103 strlcat(state->pp_buf, "(", PAGE_SIZE);
104 strlcat(state->pp_buf, rr->part[part].name, PAGE_SIZE);
105 strlcat(state->pp_buf, ")", PAGE_SIZE);
101 } 106 }
102 } 107 }
103 108
104 printk(" >\n"); 109 strlcat(state->pp_buf, " >\n", PAGE_SIZE);
105 } else { 110 } else {
106 put_partition(state, slot++, first_sect, nr_sects); 111 put_partition(state, slot++, first_sect, nr_sects);
107 } 112 }
@@ -131,7 +136,7 @@ static int linux_partition(struct parsed_partitions *state,
131 struct linux_part *linuxp; 136 struct linux_part *linuxp;
132 unsigned long size = nr_sects > 2 ? 2 : nr_sects; 137 unsigned long size = nr_sects > 2 ? 2 : nr_sects;
133 138
134 printk(" [Linux]"); 139 strlcat(state->pp_buf, " [Linux]", PAGE_SIZE);
135 140
136 put_partition(state, slot++, first_sect, size); 141 put_partition(state, slot++, first_sect, size);
137 142
@@ -139,7 +144,7 @@ static int linux_partition(struct parsed_partitions *state,
139 if (!linuxp) 144 if (!linuxp)
140 return -1; 145 return -1;
141 146
142 printk(" <"); 147 strlcat(state->pp_buf, " <", PAGE_SIZE);
143 while (linuxp->magic == cpu_to_le32(LINUX_NATIVE_MAGIC) || 148 while (linuxp->magic == cpu_to_le32(LINUX_NATIVE_MAGIC) ||
144 linuxp->magic == cpu_to_le32(LINUX_SWAP_MAGIC)) { 149 linuxp->magic == cpu_to_le32(LINUX_SWAP_MAGIC)) {
145 if (slot == state->limit) 150 if (slot == state->limit)
@@ -149,7 +154,7 @@ static int linux_partition(struct parsed_partitions *state,
149 le32_to_cpu(linuxp->nr_sects)); 154 le32_to_cpu(linuxp->nr_sects));
150 linuxp ++; 155 linuxp ++;
151 } 156 }
152 printk(" >"); 157 strlcat(state->pp_buf, " >", PAGE_SIZE);
153 158
154 put_dev_sector(sect); 159 put_dev_sector(sect);
155 return slot; 160 return slot;
@@ -294,7 +299,7 @@ int adfspart_check_ADFS(struct parsed_partitions *state)
294 break; 299 break;
295 } 300 }
296 } 301 }
297 printk("\n"); 302 strlcat(state->pp_buf, "\n", PAGE_SIZE);
298 return 1; 303 return 1;
299} 304}
300#endif 305#endif
@@ -367,7 +372,7 @@ int adfspart_check_ICS(struct parsed_partitions *state)
367 return 0; 372 return 0;
368 } 373 }
369 374
370 printk(" [ICS]"); 375 strlcat(state->pp_buf, " [ICS]", PAGE_SIZE);
371 376
372 for (slot = 1, p = (const struct ics_part *)data; p->size; p++) { 377 for (slot = 1, p = (const struct ics_part *)data; p->size; p++) {
373 u32 start = le32_to_cpu(p->start); 378 u32 start = le32_to_cpu(p->start);
@@ -401,7 +406,7 @@ int adfspart_check_ICS(struct parsed_partitions *state)
401 } 406 }
402 407
403 put_dev_sector(sect); 408 put_dev_sector(sect);
404 printk("\n"); 409 strlcat(state->pp_buf, "\n", PAGE_SIZE);
405 return 1; 410 return 1;
406} 411}
407#endif 412#endif
@@ -461,7 +466,7 @@ int adfspart_check_POWERTEC(struct parsed_partitions *state)
461 return 0; 466 return 0;
462 } 467 }
463 468
464 printk(" [POWERTEC]"); 469 strlcat(state->pp_buf, " [POWERTEC]", PAGE_SIZE);
465 470
466 for (i = 0, p = (const struct ptec_part *)data; i < 12; i++, p++) { 471 for (i = 0, p = (const struct ptec_part *)data; i < 12; i++, p++) {
467 u32 start = le32_to_cpu(p->start); 472 u32 start = le32_to_cpu(p->start);
@@ -472,7 +477,7 @@ int adfspart_check_POWERTEC(struct parsed_partitions *state)
472 } 477 }
473 478
474 put_dev_sector(sect); 479 put_dev_sector(sect);
475 printk("\n"); 480 strlcat(state->pp_buf, "\n", PAGE_SIZE);
476 return 1; 481 return 1;
477} 482}
478#endif 483#endif
@@ -543,7 +548,7 @@ int adfspart_check_EESOX(struct parsed_partitions *state)
543 548
544 size = get_capacity(state->bdev->bd_disk); 549 size = get_capacity(state->bdev->bd_disk);
545 put_partition(state, slot++, start, size - start); 550 put_partition(state, slot++, start, size - start);
546 printk("\n"); 551 strlcat(state->pp_buf, "\n", PAGE_SIZE);
547 } 552 }
548 553
549 return i ? 1 : 0; 554 return i ? 1 : 0;
diff --git a/fs/partitions/amiga.c b/fs/partitions/amiga.c
index ba443d4229f8..70cbf44a1560 100644
--- a/fs/partitions/amiga.c
+++ b/fs/partitions/amiga.c
@@ -69,7 +69,13 @@ int amiga_partition(struct parsed_partitions *state)
69 /* blksize is blocks per 512 byte standard block */ 69 /* blksize is blocks per 512 byte standard block */
70 blksize = be32_to_cpu( rdb->rdb_BlockBytes ) / 512; 70 blksize = be32_to_cpu( rdb->rdb_BlockBytes ) / 512;
71 71
72 printk(" RDSK (%d)", blksize * 512); /* Be more informative */ 72 {
73 char tmp[7 + 10 + 1 + 1];
74
75 /* Be more informative */
76 snprintf(tmp, sizeof(tmp), " RDSK (%d)", blksize * 512);
77 strlcat(state->pp_buf, tmp, PAGE_SIZE);
78 }
73 blk = be32_to_cpu(rdb->rdb_PartitionList); 79 blk = be32_to_cpu(rdb->rdb_PartitionList);
74 put_dev_sector(sect); 80 put_dev_sector(sect);
75 for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) { 81 for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) {
@@ -106,23 +112,27 @@ int amiga_partition(struct parsed_partitions *state)
106 { 112 {
107 /* Be even more informative to aid mounting */ 113 /* Be even more informative to aid mounting */
108 char dostype[4]; 114 char dostype[4];
115 char tmp[42];
116
109 __be32 *dt = (__be32 *)dostype; 117 __be32 *dt = (__be32 *)dostype;
110 *dt = pb->pb_Environment[16]; 118 *dt = pb->pb_Environment[16];
111 if (dostype[3] < ' ') 119 if (dostype[3] < ' ')
112 printk(" (%c%c%c^%c)", 120 snprintf(tmp, sizeof(tmp), " (%c%c%c^%c)",
113 dostype[0], dostype[1], 121 dostype[0], dostype[1],
114 dostype[2], dostype[3] + '@' ); 122 dostype[2], dostype[3] + '@' );
115 else 123 else
116 printk(" (%c%c%c%c)", 124 snprintf(tmp, sizeof(tmp), " (%c%c%c%c)",
117 dostype[0], dostype[1], 125 dostype[0], dostype[1],
118 dostype[2], dostype[3]); 126 dostype[2], dostype[3]);
119 printk("(res %d spb %d)", 127 strlcat(state->pp_buf, tmp, PAGE_SIZE);
128 snprintf(tmp, sizeof(tmp), "(res %d spb %d)",
120 be32_to_cpu(pb->pb_Environment[6]), 129 be32_to_cpu(pb->pb_Environment[6]),
121 be32_to_cpu(pb->pb_Environment[4])); 130 be32_to_cpu(pb->pb_Environment[4]));
131 strlcat(state->pp_buf, tmp, PAGE_SIZE);
122 } 132 }
123 res = 1; 133 res = 1;
124 } 134 }
125 printk("\n"); 135 strlcat(state->pp_buf, "\n", PAGE_SIZE);
126 136
127rdb_done: 137rdb_done:
128 return res; 138 return res;
diff --git a/fs/partitions/atari.c b/fs/partitions/atari.c
index 4439ff1b6cec..9875b05e80a2 100644
--- a/fs/partitions/atari.c
+++ b/fs/partitions/atari.c
@@ -62,7 +62,7 @@ int atari_partition(struct parsed_partitions *state)
62 } 62 }
63 63
64 pi = &rs->part[0]; 64 pi = &rs->part[0];
65 printk (" AHDI"); 65 strlcat(state->pp_buf, " AHDI", PAGE_SIZE);
66 for (slot = 1; pi < &rs->part[4] && slot < state->limit; slot++, pi++) { 66 for (slot = 1; pi < &rs->part[4] && slot < state->limit; slot++, pi++) {
67 struct rootsector *xrs; 67 struct rootsector *xrs;
68 Sector sect2; 68 Sector sect2;
@@ -81,7 +81,7 @@ int atari_partition(struct parsed_partitions *state)
81#ifdef ICD_PARTS 81#ifdef ICD_PARTS
82 part_fmt = 1; 82 part_fmt = 1;
83#endif 83#endif
84 printk(" XGM<"); 84 strlcat(state->pp_buf, " XGM<", PAGE_SIZE);
85 partsect = extensect = be32_to_cpu(pi->st); 85 partsect = extensect = be32_to_cpu(pi->st);
86 while (1) { 86 while (1) {
87 xrs = read_part_sector(state, partsect, &sect2); 87 xrs = read_part_sector(state, partsect, &sect2);
@@ -120,14 +120,14 @@ int atari_partition(struct parsed_partitions *state)
120 break; 120 break;
121 } 121 }
122 } 122 }
123 printk(" >"); 123 strlcat(state->pp_buf, " >", PAGE_SIZE);
124 } 124 }
125#ifdef ICD_PARTS 125#ifdef ICD_PARTS
126 if ( part_fmt!=1 ) { /* no extended partitions -> test ICD-format */ 126 if ( part_fmt!=1 ) { /* no extended partitions -> test ICD-format */
127 pi = &rs->icdpart[0]; 127 pi = &rs->icdpart[0];
128 /* sanity check: no ICD format if first partition invalid */ 128 /* sanity check: no ICD format if first partition invalid */
129 if (OK_id(pi->id)) { 129 if (OK_id(pi->id)) {
130 printk(" ICD<"); 130 strlcat(state->pp_buf, " ICD<", PAGE_SIZE);
131 for (; pi < &rs->icdpart[8] && slot < state->limit; slot++, pi++) { 131 for (; pi < &rs->icdpart[8] && slot < state->limit; slot++, pi++) {
132 /* accept only GEM,BGM,RAW,LNX,SWP partitions */ 132 /* accept only GEM,BGM,RAW,LNX,SWP partitions */
133 if (!((pi->flg & 1) && OK_id(pi->id))) 133 if (!((pi->flg & 1) && OK_id(pi->id)))
@@ -137,13 +137,13 @@ int atari_partition(struct parsed_partitions *state)
137 be32_to_cpu(pi->st), 137 be32_to_cpu(pi->st),
138 be32_to_cpu(pi->siz)); 138 be32_to_cpu(pi->siz));
139 } 139 }
140 printk(" >"); 140 strlcat(state->pp_buf, " >", PAGE_SIZE);
141 } 141 }
142 } 142 }
143#endif 143#endif
144 put_dev_sector(sect); 144 put_dev_sector(sect);
145 145
146 printk ("\n"); 146 strlcat(state->pp_buf, "\n", PAGE_SIZE);
147 147
148 return 1; 148 return 1;
149} 149}
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 72c52656dc2e..79fbf3f390f0 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -164,10 +164,16 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
164 state = kzalloc(sizeof(struct parsed_partitions), GFP_KERNEL); 164 state = kzalloc(sizeof(struct parsed_partitions), GFP_KERNEL);
165 if (!state) 165 if (!state)
166 return NULL; 166 return NULL;
167 state->pp_buf = (char *)__get_free_page(GFP_KERNEL);
168 if (!state->pp_buf) {
169 kfree(state);
170 return NULL;
171 }
172 state->pp_buf[0] = '\0';
167 173
168 state->bdev = bdev; 174 state->bdev = bdev;
169 disk_name(hd, 0, state->name); 175 disk_name(hd, 0, state->name);
170 printk(KERN_INFO " %s:", state->name); 176 snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name);
171 if (isdigit(state->name[strlen(state->name)-1])) 177 if (isdigit(state->name[strlen(state->name)-1]))
172 sprintf(state->name, "p"); 178 sprintf(state->name, "p");
173 179
@@ -185,17 +191,25 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
185 } 191 }
186 192
187 } 193 }
188 if (res > 0) 194 if (res > 0) {
195 printk(KERN_INFO "%s", state->pp_buf);
196
197 free_page((unsigned long)state->pp_buf);
189 return state; 198 return state;
199 }
190 if (state->access_beyond_eod) 200 if (state->access_beyond_eod)
191 err = -ENOSPC; 201 err = -ENOSPC;
192 if (err) 202 if (err)
193 /* The partition is unrecognized. So report I/O errors if there were any */ 203 /* The partition is unrecognized. So report I/O errors if there were any */
194 res = err; 204 res = err;
195 if (!res) 205 if (!res)
196 printk(" unknown partition table\n"); 206 strlcat(state->pp_buf, " unknown partition table\n", PAGE_SIZE);
197 else if (warn_no_part) 207 else if (warn_no_part)
198 printk(" unable to read partition table\n"); 208 strlcat(state->pp_buf, " unable to read partition table\n", PAGE_SIZE);
209
210 printk(KERN_INFO "%s", state->pp_buf);
211
212 free_page((unsigned long)state->pp_buf);
199 kfree(state); 213 kfree(state);
200 return ERR_PTR(res); 214 return ERR_PTR(res);
201} 215}
diff --git a/fs/partitions/check.h b/fs/partitions/check.h
index 52f8bd399396..8e4e103ba216 100644
--- a/fs/partitions/check.h
+++ b/fs/partitions/check.h
@@ -16,6 +16,7 @@ struct parsed_partitions {
16 int next; 16 int next;
17 int limit; 17 int limit;
18 bool access_beyond_eod; 18 bool access_beyond_eod;
19 char *pp_buf;
19}; 20};
20 21
21static inline void *read_part_sector(struct parsed_partitions *state, 22static inline void *read_part_sector(struct parsed_partitions *state,
@@ -32,9 +33,12 @@ static inline void
32put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size) 33put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size)
33{ 34{
34 if (n < p->limit) { 35 if (n < p->limit) {
36 char tmp[1 + BDEVNAME_SIZE + 10 + 1];
37
35 p->parts[n].from = from; 38 p->parts[n].from = from;
36 p->parts[n].size = size; 39 p->parts[n].size = size;
37 printk(" %s%d", p->name, n); 40 snprintf(tmp, sizeof(tmp), " %s%d", p->name, n);
41 strlcat(p->pp_buf, tmp, PAGE_SIZE);
38 } 42 }
39} 43}
40 44
diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
index 9efb2cfe2410..dbb44d4bb8a7 100644
--- a/fs/partitions/efi.c
+++ b/fs/partitions/efi.c
@@ -630,6 +630,6 @@ int efi_partition(struct parsed_partitions *state)
630 } 630 }
631 kfree(ptes); 631 kfree(ptes);
632 kfree(gpt); 632 kfree(gpt);
633 printk("\n"); 633 strlcat(state->pp_buf, "\n", PAGE_SIZE);
634 return 1; 634 return 1;
635} 635}
diff --git a/fs/partitions/ibm.c b/fs/partitions/ibm.c
index fc8497643fd0..d513a07f44bb 100644
--- a/fs/partitions/ibm.c
+++ b/fs/partitions/ibm.c
@@ -75,6 +75,7 @@ int ibm_partition(struct parsed_partitions *state)
75 unsigned char *data; 75 unsigned char *data;
76 Sector sect; 76 Sector sect;
77 sector_t labelsect; 77 sector_t labelsect;
78 char tmp[64];
78 79
79 res = 0; 80 res = 0;
80 blocksize = bdev_logical_block_size(bdev); 81 blocksize = bdev_logical_block_size(bdev);
@@ -144,13 +145,15 @@ int ibm_partition(struct parsed_partitions *state)
144 */ 145 */
145 blocksize = label->cms.block_size; 146 blocksize = label->cms.block_size;
146 if (label->cms.disk_offset != 0) { 147 if (label->cms.disk_offset != 0) {
147 printk("CMS1/%8s(MDSK):", name); 148 snprintf(tmp, sizeof(tmp), "CMS1/%8s(MDSK):", name);
149 strlcat(state->pp_buf, tmp, PAGE_SIZE);
148 /* disk is reserved minidisk */ 150 /* disk is reserved minidisk */
149 offset = label->cms.disk_offset; 151 offset = label->cms.disk_offset;
150 size = (label->cms.block_count - 1) 152 size = (label->cms.block_count - 1)
151 * (blocksize >> 9); 153 * (blocksize >> 9);
152 } else { 154 } else {
153 printk("CMS1/%8s:", name); 155 snprintf(tmp, sizeof(tmp), "CMS1/%8s:", name);
156 strlcat(state->pp_buf, tmp, PAGE_SIZE);
154 offset = (info->label_block + 1); 157 offset = (info->label_block + 1);
155 size = label->cms.block_count 158 size = label->cms.block_count
156 * (blocksize >> 9); 159 * (blocksize >> 9);
@@ -159,7 +162,8 @@ int ibm_partition(struct parsed_partitions *state)
159 size-offset*(blocksize >> 9)); 162 size-offset*(blocksize >> 9));
160 } else { 163 } else {
161 if (strncmp(type, "LNX1", 4) == 0) { 164 if (strncmp(type, "LNX1", 4) == 0) {
162 printk("LNX1/%8s:", name); 165 snprintf(tmp, sizeof(tmp), "LNX1/%8s:", name);
166 strlcat(state->pp_buf, tmp, PAGE_SIZE);
163 if (label->lnx.ldl_version == 0xf2) { 167 if (label->lnx.ldl_version == 0xf2) {
164 fmt_size = label->lnx.formatted_blocks 168 fmt_size = label->lnx.formatted_blocks
165 * (blocksize >> 9); 169 * (blocksize >> 9);
@@ -178,7 +182,7 @@ int ibm_partition(struct parsed_partitions *state)
178 offset = (info->label_block + 1); 182 offset = (info->label_block + 1);
179 } else { 183 } else {
180 /* unlabeled disk */ 184 /* unlabeled disk */
181 printk("(nonl)"); 185 strlcat(state->pp_buf, "(nonl)", PAGE_SIZE);
182 size = i_size >> 9; 186 size = i_size >> 9;
183 offset = (info->label_block + 1); 187 offset = (info->label_block + 1);
184 } 188 }
@@ -197,7 +201,8 @@ int ibm_partition(struct parsed_partitions *state)
197 * if not, something is wrong, skipping partition detection 201 * if not, something is wrong, skipping partition detection
198 */ 202 */
199 if (strncmp(type, "VOL1", 4) == 0) { 203 if (strncmp(type, "VOL1", 4) == 0) {
200 printk("VOL1/%8s:", name); 204 snprintf(tmp, sizeof(tmp), "VOL1/%8s:", name);
205 strlcat(state->pp_buf, tmp, PAGE_SIZE);
201 /* 206 /*
202 * get block number and read then go through format1 207 * get block number and read then go through format1
203 * labels 208 * labels
@@ -253,7 +258,7 @@ int ibm_partition(struct parsed_partitions *state)
253 258
254 } 259 }
255 260
256 printk("\n"); 261 strlcat(state->pp_buf, "\n", PAGE_SIZE);
257 goto out_freeall; 262 goto out_freeall;
258 263
259 264
diff --git a/fs/partitions/karma.c b/fs/partitions/karma.c
index 1cc928bb762f..0ea19312706b 100644
--- a/fs/partitions/karma.c
+++ b/fs/partitions/karma.c
@@ -50,7 +50,7 @@ int karma_partition(struct parsed_partitions *state)
50 } 50 }
51 slot++; 51 slot++;
52 } 52 }
53 printk("\n"); 53 strlcat(state->pp_buf, "\n", PAGE_SIZE);
54 put_dev_sector(sect); 54 put_dev_sector(sect);
55 return 1; 55 return 1;
56} 56}
diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
index 648c9d8f3357..5bf8a04b5d9b 100644
--- a/fs/partitions/ldm.c
+++ b/fs/partitions/ldm.c
@@ -643,7 +643,7 @@ static bool ldm_create_data_partitions (struct parsed_partitions *pp,
643 return false; 643 return false;
644 } 644 }
645 645
646 printk (" [LDM]"); 646 strlcat(pp->pp_buf, " [LDM]", PAGE_SIZE);
647 647
648 /* Create the data partitions */ 648 /* Create the data partitions */
649 list_for_each (item, &ldb->v_part) { 649 list_for_each (item, &ldb->v_part) {
@@ -658,7 +658,7 @@ static bool ldm_create_data_partitions (struct parsed_partitions *pp,
658 part_num++; 658 part_num++;
659 } 659 }
660 660
661 printk ("\n"); 661 strlcat(pp->pp_buf, "\n", PAGE_SIZE);
662 return true; 662 return true;
663} 663}
664 664
diff --git a/fs/partitions/mac.c b/fs/partitions/mac.c
index 74465ff7c263..68d6a216ee79 100644
--- a/fs/partitions/mac.c
+++ b/fs/partitions/mac.c
@@ -59,7 +59,7 @@ int mac_partition(struct parsed_partitions *state)
59 put_dev_sector(sect); 59 put_dev_sector(sect);
60 return 0; /* not a MacOS disk */ 60 return 0; /* not a MacOS disk */
61 } 61 }
62 printk(" [mac]"); 62 strlcat(state->pp_buf, " [mac]", PAGE_SIZE);
63 blocks_in_map = be32_to_cpu(part->map_count); 63 blocks_in_map = be32_to_cpu(part->map_count);
64 for (blk = 1; blk <= blocks_in_map; ++blk) { 64 for (blk = 1; blk <= blocks_in_map; ++blk) {
65 int pos = blk * secsize; 65 int pos = blk * secsize;
@@ -128,6 +128,6 @@ int mac_partition(struct parsed_partitions *state)
128#endif 128#endif
129 129
130 put_dev_sector(sect); 130 put_dev_sector(sect);
131 printk("\n"); 131 strlcat(state->pp_buf, "\n", PAGE_SIZE);
132 return 1; 132 return 1;
133} 133}
diff --git a/fs/partitions/msdos.c b/fs/partitions/msdos.c
index 15bfb7b1e044..5f79a6677c69 100644
--- a/fs/partitions/msdos.c
+++ b/fs/partitions/msdos.c
@@ -213,10 +213,18 @@ static void parse_solaris_x86(struct parsed_partitions *state,
213 put_dev_sector(sect); 213 put_dev_sector(sect);
214 return; 214 return;
215 } 215 }
216 printk(" %s%d: <solaris:", state->name, origin); 216 {
217 char tmp[1 + BDEVNAME_SIZE + 10 + 11 + 1];
218
219 snprintf(tmp, sizeof(tmp), " %s%d: <solaris:", state->name, origin);
220 strlcat(state->pp_buf, tmp, PAGE_SIZE);
221 }
217 if (le32_to_cpu(v->v_version) != 1) { 222 if (le32_to_cpu(v->v_version) != 1) {
218 printk(" cannot handle version %d vtoc>\n", 223 char tmp[64];
219 le32_to_cpu(v->v_version)); 224
225 snprintf(tmp, sizeof(tmp), " cannot handle version %d vtoc>\n",
226 le32_to_cpu(v->v_version));
227 strlcat(state->pp_buf, tmp, PAGE_SIZE);
220 put_dev_sector(sect); 228 put_dev_sector(sect);
221 return; 229 return;
222 } 230 }
@@ -224,9 +232,12 @@ static void parse_solaris_x86(struct parsed_partitions *state,
224 max_nparts = le16_to_cpu (v->v_nparts) > 8 ? SOLARIS_X86_NUMSLICE : 8; 232 max_nparts = le16_to_cpu (v->v_nparts) > 8 ? SOLARIS_X86_NUMSLICE : 8;
225 for (i=0; i<max_nparts && state->next<state->limit; i++) { 233 for (i=0; i<max_nparts && state->next<state->limit; i++) {
226 struct solaris_x86_slice *s = &v->v_slice[i]; 234 struct solaris_x86_slice *s = &v->v_slice[i];
235 char tmp[3 + 10 + 1 + 1];
236
227 if (s->s_size == 0) 237 if (s->s_size == 0)
228 continue; 238 continue;
229 printk(" [s%d]", i); 239 snprintf(tmp, sizeof(tmp), " [s%d]", i);
240 strlcat(state->pp_buf, tmp, PAGE_SIZE);
230 /* solaris partitions are relative to current MS-DOS 241 /* solaris partitions are relative to current MS-DOS
231 * one; must add the offset of the current partition */ 242 * one; must add the offset of the current partition */
232 put_partition(state, state->next++, 243 put_partition(state, state->next++,
@@ -234,7 +245,7 @@ static void parse_solaris_x86(struct parsed_partitions *state,
234 le32_to_cpu(s->s_size)); 245 le32_to_cpu(s->s_size));
235 } 246 }
236 put_dev_sector(sect); 247 put_dev_sector(sect);
237 printk(" >\n"); 248 strlcat(state->pp_buf, " >\n", PAGE_SIZE);
238#endif 249#endif
239} 250}
240 251
@@ -250,6 +261,7 @@ static void parse_bsd(struct parsed_partitions *state,
250 Sector sect; 261 Sector sect;
251 struct bsd_disklabel *l; 262 struct bsd_disklabel *l;
252 struct bsd_partition *p; 263 struct bsd_partition *p;
264 char tmp[64];
253 265
254 l = read_part_sector(state, offset + 1, &sect); 266 l = read_part_sector(state, offset + 1, &sect);
255 if (!l) 267 if (!l)
@@ -258,7 +270,9 @@ static void parse_bsd(struct parsed_partitions *state,
258 put_dev_sector(sect); 270 put_dev_sector(sect);
259 return; 271 return;
260 } 272 }
261 printk(" %s%d: <%s:", state->name, origin, flavour); 273
274 snprintf(tmp, sizeof(tmp), " %s%d: <%s:", state->name, origin, flavour);
275 strlcat(state->pp_buf, tmp, PAGE_SIZE);
262 276
263 if (le16_to_cpu(l->d_npartitions) < max_partitions) 277 if (le16_to_cpu(l->d_npartitions) < max_partitions)
264 max_partitions = le16_to_cpu(l->d_npartitions); 278 max_partitions = le16_to_cpu(l->d_npartitions);
@@ -275,16 +289,18 @@ static void parse_bsd(struct parsed_partitions *state,
275 /* full parent partition, we have it already */ 289 /* full parent partition, we have it already */
276 continue; 290 continue;
277 if (offset > bsd_start || offset+size < bsd_start+bsd_size) { 291 if (offset > bsd_start || offset+size < bsd_start+bsd_size) {
278 printk("bad subpartition - ignored\n"); 292 strlcat(state->pp_buf, "bad subpartition - ignored\n", PAGE_SIZE);
279 continue; 293 continue;
280 } 294 }
281 put_partition(state, state->next++, bsd_start, bsd_size); 295 put_partition(state, state->next++, bsd_start, bsd_size);
282 } 296 }
283 put_dev_sector(sect); 297 put_dev_sector(sect);
284 if (le16_to_cpu(l->d_npartitions) > max_partitions) 298 if (le16_to_cpu(l->d_npartitions) > max_partitions) {
285 printk(" (ignored %d more)", 299 snprintf(tmp, sizeof(tmp), " (ignored %d more)",
286 le16_to_cpu(l->d_npartitions) - max_partitions); 300 le16_to_cpu(l->d_npartitions) - max_partitions);
287 printk(" >\n"); 301 strlcat(state->pp_buf, tmp, PAGE_SIZE);
302 }
303 strlcat(state->pp_buf, " >\n", PAGE_SIZE);
288} 304}
289#endif 305#endif
290 306
@@ -333,7 +349,12 @@ static void parse_unixware(struct parsed_partitions *state,
333 put_dev_sector(sect); 349 put_dev_sector(sect);
334 return; 350 return;
335 } 351 }
336 printk(" %s%d: <unixware:", state->name, origin); 352 {
353 char tmp[1 + BDEVNAME_SIZE + 10 + 12 + 1];
354
355 snprintf(tmp, sizeof(tmp), " %s%d: <unixware:", state->name, origin);
356 strlcat(state->pp_buf, tmp, PAGE_SIZE);
357 }
337 p = &l->vtoc.v_slice[1]; 358 p = &l->vtoc.v_slice[1];
338 /* I omit the 0th slice as it is the same as whole disk. */ 359 /* I omit the 0th slice as it is the same as whole disk. */
339 while (p - &l->vtoc.v_slice[0] < UNIXWARE_NUMSLICE) { 360 while (p - &l->vtoc.v_slice[0] < UNIXWARE_NUMSLICE) {
@@ -347,7 +368,7 @@ static void parse_unixware(struct parsed_partitions *state,
347 p++; 368 p++;
348 } 369 }
349 put_dev_sector(sect); 370 put_dev_sector(sect);
350 printk(" >\n"); 371 strlcat(state->pp_buf, " >\n", PAGE_SIZE);
351#endif 372#endif
352} 373}
353 374
@@ -376,8 +397,10 @@ static void parse_minix(struct parsed_partitions *state,
376 * the normal boot sector. */ 397 * the normal boot sector. */
377 if (msdos_magic_present (data + 510) && 398 if (msdos_magic_present (data + 510) &&
378 SYS_IND(p) == MINIX_PARTITION) { /* subpartition table present */ 399 SYS_IND(p) == MINIX_PARTITION) { /* subpartition table present */
400 char tmp[1 + BDEVNAME_SIZE + 10 + 9 + 1];
379 401
380 printk(" %s%d: <minix:", state->name, origin); 402 snprintf(tmp, sizeof(tmp), " %s%d: <minix:", state->name, origin);
403 strlcat(state->pp_buf, tmp, PAGE_SIZE);
381 for (i = 0; i < MINIX_NR_SUBPARTITIONS; i++, p++) { 404 for (i = 0; i < MINIX_NR_SUBPARTITIONS; i++, p++) {
382 if (state->next == state->limit) 405 if (state->next == state->limit)
383 break; 406 break;
@@ -386,7 +409,7 @@ static void parse_minix(struct parsed_partitions *state,
386 put_partition(state, state->next++, 409 put_partition(state, state->next++,
387 start_sect(p), nr_sects(p)); 410 start_sect(p), nr_sects(p));
388 } 411 }
389 printk(" >\n"); 412 strlcat(state->pp_buf, " >\n", PAGE_SIZE);
390 } 413 }
391 put_dev_sector(sect); 414 put_dev_sector(sect);
392#endif /* CONFIG_MINIX_SUBPARTITION */ 415#endif /* CONFIG_MINIX_SUBPARTITION */
@@ -425,7 +448,7 @@ int msdos_partition(struct parsed_partitions *state)
425 448
426 if (aix_magic_present(state, data)) { 449 if (aix_magic_present(state, data)) {
427 put_dev_sector(sect); 450 put_dev_sector(sect);
428 printk( " [AIX]"); 451 strlcat(state->pp_buf, " [AIX]", PAGE_SIZE);
429 return 0; 452 return 0;
430 } 453 }
431 454
@@ -446,7 +469,7 @@ int msdos_partition(struct parsed_partitions *state)
446 fb = (struct fat_boot_sector *) data; 469 fb = (struct fat_boot_sector *) data;
447 if (slot == 1 && fb->reserved && fb->fats 470 if (slot == 1 && fb->reserved && fb->fats
448 && fat_valid_media(fb->media)) { 471 && fat_valid_media(fb->media)) {
449 printk("\n"); 472 strlcat(state->pp_buf, "\n", PAGE_SIZE);
450 put_dev_sector(sect); 473 put_dev_sector(sect);
451 return 1; 474 return 1;
452 } else { 475 } else {
@@ -491,21 +514,21 @@ int msdos_partition(struct parsed_partitions *state)
491 n = min(size, max(sector_size, n)); 514 n = min(size, max(sector_size, n));
492 put_partition(state, slot, start, n); 515 put_partition(state, slot, start, n);
493 516
494 printk(" <"); 517 strlcat(state->pp_buf, " <", PAGE_SIZE);
495 parse_extended(state, start, size); 518 parse_extended(state, start, size);
496 printk(" >"); 519 strlcat(state->pp_buf, " >", PAGE_SIZE);
497 continue; 520 continue;
498 } 521 }
499 put_partition(state, slot, start, size); 522 put_partition(state, slot, start, size);
500 if (SYS_IND(p) == LINUX_RAID_PARTITION) 523 if (SYS_IND(p) == LINUX_RAID_PARTITION)
501 state->parts[slot].flags = ADDPART_FLAG_RAID; 524 state->parts[slot].flags = ADDPART_FLAG_RAID;
502 if (SYS_IND(p) == DM6_PARTITION) 525 if (SYS_IND(p) == DM6_PARTITION)
503 printk("[DM]"); 526 strlcat(state->pp_buf, "[DM]", PAGE_SIZE);
504 if (SYS_IND(p) == EZD_PARTITION) 527 if (SYS_IND(p) == EZD_PARTITION)
505 printk("[EZD]"); 528 strlcat(state->pp_buf, "[EZD]", PAGE_SIZE);
506 } 529 }
507 530
508 printk("\n"); 531 strlcat(state->pp_buf, "\n", PAGE_SIZE);
509 532
510 /* second pass - output for each on a separate line */ 533 /* second pass - output for each on a separate line */
511 p = (struct partition *) (0x1be + data); 534 p = (struct partition *) (0x1be + data);
diff --git a/fs/partitions/osf.c b/fs/partitions/osf.c
index fc22b85d436a..48cec7cbca17 100644
--- a/fs/partitions/osf.c
+++ b/fs/partitions/osf.c
@@ -72,7 +72,7 @@ int osf_partition(struct parsed_partitions *state)
72 le32_to_cpu(partition->p_size)); 72 le32_to_cpu(partition->p_size));
73 slot++; 73 slot++;
74 } 74 }
75 printk("\n"); 75 strlcat(state->pp_buf, "\n", PAGE_SIZE);
76 put_dev_sector(sect); 76 put_dev_sector(sect);
77 return 1; 77 return 1;
78} 78}
diff --git a/fs/partitions/sgi.c b/fs/partitions/sgi.c
index 43b1df9aa16c..ea8a86dceaf4 100644
--- a/fs/partitions/sgi.c
+++ b/fs/partitions/sgi.c
@@ -76,7 +76,7 @@ int sgi_partition(struct parsed_partitions *state)
76 } 76 }
77 slot++; 77 slot++;
78 } 78 }
79 printk("\n"); 79 strlcat(state->pp_buf, "\n", PAGE_SIZE);
80 put_dev_sector(sect); 80 put_dev_sector(sect);
81 return 1; 81 return 1;
82} 82}
diff --git a/fs/partitions/sun.c b/fs/partitions/sun.c
index a32660e25f7f..b5b6fcfb3d36 100644
--- a/fs/partitions/sun.c
+++ b/fs/partitions/sun.c
@@ -116,7 +116,7 @@ int sun_partition(struct parsed_partitions *state)
116 } 116 }
117 slot++; 117 slot++;
118 } 118 }
119 printk("\n"); 119 strlcat(state->pp_buf, "\n", PAGE_SIZE);
120 put_dev_sector(sect); 120 put_dev_sector(sect);
121 return 1; 121 return 1;
122} 122}
diff --git a/fs/partitions/sysv68.c b/fs/partitions/sysv68.c
index 9030c864428e..9627ccffc1c4 100644
--- a/fs/partitions/sysv68.c
+++ b/fs/partitions/sysv68.c
@@ -54,6 +54,7 @@ int sysv68_partition(struct parsed_partitions *state)
54 unsigned char *data; 54 unsigned char *data;
55 struct dkblk0 *b; 55 struct dkblk0 *b;
56 struct slice *slice; 56 struct slice *slice;
57 char tmp[64];
57 58
58 data = read_part_sector(state, 0, &sect); 59 data = read_part_sector(state, 0, &sect);
59 if (!data) 60 if (!data)
@@ -73,7 +74,8 @@ int sysv68_partition(struct parsed_partitions *state)
73 return -1; 74 return -1;
74 75
75 slices -= 1; /* last slice is the whole disk */ 76 slices -= 1; /* last slice is the whole disk */
76 printk("sysV68: %s(s%u)", state->name, slices); 77 snprintf(tmp, sizeof(tmp), "sysV68: %s(s%u)", state->name, slices);
78 strlcat(state->pp_buf, tmp, PAGE_SIZE);
77 slice = (struct slice *)data; 79 slice = (struct slice *)data;
78 for (i = 0; i < slices; i++, slice++) { 80 for (i = 0; i < slices; i++, slice++) {
79 if (slot == state->limit) 81 if (slot == state->limit)
@@ -82,11 +84,12 @@ int sysv68_partition(struct parsed_partitions *state)
82 put_partition(state, slot, 84 put_partition(state, slot,
83 be32_to_cpu(slice->blkoff), 85 be32_to_cpu(slice->blkoff),
84 be32_to_cpu(slice->nblocks)); 86 be32_to_cpu(slice->nblocks));
85 printk("(s%u)", i); 87 snprintf(tmp, sizeof(tmp), "(s%u)", i);
88 strlcat(state->pp_buf, tmp, PAGE_SIZE);
86 } 89 }
87 slot++; 90 slot++;
88 } 91 }
89 printk("\n"); 92 strlcat(state->pp_buf, "\n", PAGE_SIZE);
90 put_dev_sector(sect); 93 put_dev_sector(sect);
91 return 1; 94 return 1;
92} 95}
diff --git a/fs/partitions/ultrix.c b/fs/partitions/ultrix.c
index db9eef260364..8dbaf9f77a99 100644
--- a/fs/partitions/ultrix.c
+++ b/fs/partitions/ultrix.c
@@ -39,7 +39,7 @@ int ultrix_partition(struct parsed_partitions *state)
39 label->pt_part[i].pi_blkoff, 39 label->pt_part[i].pi_blkoff,
40 label->pt_part[i].pi_nblocks); 40 label->pt_part[i].pi_nblocks);
41 put_dev_sector(sect); 41 put_dev_sector(sect);
42 printk ("\n"); 42 strlcat(state->pp_buf, "\n", PAGE_SIZE);
43 return 1; 43 return 1;
44 } else { 44 } else {
45 put_dev_sector(sect); 45 put_dev_sector(sect);
diff --git a/fs/proc/Makefile b/fs/proc/Makefile
index 11a7b5c68153..2758e2afc518 100644
--- a/fs/proc/Makefile
+++ b/fs/proc/Makefile
@@ -2,7 +2,7 @@
2# Makefile for the Linux proc filesystem routines. 2# Makefile for the Linux proc filesystem routines.
3# 3#
4 4
5obj-$(CONFIG_PROC_FS) += proc.o 5obj-y += proc.o
6 6
7proc-y := nommu.o task_nommu.o 7proc-y := nommu.o task_nommu.o
8proc-$(CONFIG_MMU) := mmu.o task_mmu.o 8proc-$(CONFIG_MMU) := mmu.o task_mmu.o
diff --git a/fs/proc/base.c b/fs/proc/base.c
index c806dfb24e08..a1c43e7c8a7b 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -149,18 +149,13 @@ static unsigned int pid_entry_count_dirs(const struct pid_entry *entries,
149 return count; 149 return count;
150} 150}
151 151
152static int get_fs_path(struct task_struct *task, struct path *path, bool root) 152static int get_task_root(struct task_struct *task, struct path *root)
153{ 153{
154 struct fs_struct *fs;
155 int result = -ENOENT; 154 int result = -ENOENT;
156 155
157 task_lock(task); 156 task_lock(task);
158 fs = task->fs; 157 if (task->fs) {
159 if (fs) { 158 get_fs_root(task->fs, root);
160 read_lock(&fs->lock);
161 *path = root ? fs->root : fs->pwd;
162 path_get(path);
163 read_unlock(&fs->lock);
164 result = 0; 159 result = 0;
165 } 160 }
166 task_unlock(task); 161 task_unlock(task);
@@ -173,7 +168,12 @@ static int proc_cwd_link(struct inode *inode, struct path *path)
173 int result = -ENOENT; 168 int result = -ENOENT;
174 169
175 if (task) { 170 if (task) {
176 result = get_fs_path(task, path, 0); 171 task_lock(task);
172 if (task->fs) {
173 get_fs_pwd(task->fs, path);
174 result = 0;
175 }
176 task_unlock(task);
177 put_task_struct(task); 177 put_task_struct(task);
178 } 178 }
179 return result; 179 return result;
@@ -185,7 +185,7 @@ static int proc_root_link(struct inode *inode, struct path *path)
185 int result = -ENOENT; 185 int result = -ENOENT;
186 186
187 if (task) { 187 if (task) {
188 result = get_fs_path(task, path, 1); 188 result = get_task_root(task, path);
189 put_task_struct(task); 189 put_task_struct(task);
190 } 190 }
191 return result; 191 return result;
@@ -597,7 +597,7 @@ static int mounts_open_common(struct inode *inode, struct file *file,
597 get_mnt_ns(ns); 597 get_mnt_ns(ns);
598 } 598 }
599 rcu_read_unlock(); 599 rcu_read_unlock();
600 if (ns && get_fs_path(task, &root, 1) == 0) 600 if (ns && get_task_root(task, &root) == 0)
601 ret = 0; 601 ret = 0;
602 put_task_struct(task); 602 put_task_struct(task);
603 } 603 }
@@ -1526,7 +1526,7 @@ static int do_proc_readlink(struct path *path, char __user *buffer, int buflen)
1526 if (!tmp) 1526 if (!tmp)
1527 return -ENOMEM; 1527 return -ENOMEM;
1528 1528
1529 pathname = d_path(path, tmp, PAGE_SIZE); 1529 pathname = d_path_with_unreachable(path, tmp, PAGE_SIZE);
1530 len = PTR_ERR(pathname); 1530 len = PTR_ERR(pathname);
1531 if (IS_ERR(pathname)) 1531 if (IS_ERR(pathname))
1532 goto out; 1532 goto out;
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index 19fbc810e8e7..1ec952b1f036 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -983,7 +983,6 @@ static int flush_older_commits(struct super_block *s,
983 983
984static int reiserfs_async_progress_wait(struct super_block *s) 984static int reiserfs_async_progress_wait(struct super_block *s)
985{ 985{
986 DEFINE_WAIT(wait);
987 struct reiserfs_journal *j = SB_JOURNAL(s); 986 struct reiserfs_journal *j = SB_JOURNAL(s);
988 987
989 if (atomic_read(&j->j_async_throttle)) { 988 if (atomic_read(&j->j_async_throttle)) {
diff --git a/fs/signalfd.c b/fs/signalfd.c
index f329849ce3c0..1c5a6add779d 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -88,6 +88,7 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
88 err |= __put_user(kinfo->si_tid, &uinfo->ssi_tid); 88 err |= __put_user(kinfo->si_tid, &uinfo->ssi_tid);
89 err |= __put_user(kinfo->si_overrun, &uinfo->ssi_overrun); 89 err |= __put_user(kinfo->si_overrun, &uinfo->ssi_overrun);
90 err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr); 90 err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr);
91 err |= __put_user(kinfo->si_int, &uinfo->ssi_int);
91 break; 92 break;
92 case __SI_POLL: 93 case __SI_POLL:
93 err |= __put_user(kinfo->si_band, &uinfo->ssi_band); 94 err |= __put_user(kinfo->si_band, &uinfo->ssi_band);
@@ -111,6 +112,7 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
111 err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid); 112 err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid);
112 err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid); 113 err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid);
113 err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr); 114 err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr);
115 err |= __put_user(kinfo->si_int, &uinfo->ssi_int);
114 break; 116 break;
115 default: 117 default:
116 /* 118 /*
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig
index cc6ce8a84c21..e5f63da64d04 100644
--- a/fs/squashfs/Kconfig
+++ b/fs/squashfs/Kconfig
@@ -5,13 +5,13 @@ config SQUASHFS
5 help 5 help
6 Saying Y here includes support for SquashFS 4.0 (a Compressed 6 Saying Y here includes support for SquashFS 4.0 (a Compressed
7 Read-Only File System). Squashfs is a highly compressed read-only 7 Read-Only File System). Squashfs is a highly compressed read-only
8 filesystem for Linux. It uses zlib compression to compress both 8 filesystem for Linux. It uses zlib/lzo compression to compress both
9 files, inodes and directories. Inodes in the system are very small 9 files, inodes and directories. Inodes in the system are very small
10 and all blocks are packed to minimise data overhead. Block sizes 10 and all blocks are packed to minimise data overhead. Block sizes
11 greater than 4K are supported up to a maximum of 1 Mbytes (default 11 greater than 4K are supported up to a maximum of 1 Mbytes (default
12 block size 128K). SquashFS 4.0 supports 64 bit filesystems and files 12 block size 128K). SquashFS 4.0 supports 64 bit filesystems and files
13 (larger than 4GB), full uid/gid information, hard links and 13 (larger than 4GB), full uid/gid information, hard links and
14 timestamps. 14 timestamps.
15 15
16 Squashfs is intended for general read-only filesystem use, for 16 Squashfs is intended for general read-only filesystem use, for
17 archival use (i.e. in cases where a .tar.gz file may be used), and in 17 archival use (i.e. in cases where a .tar.gz file may be used), and in
@@ -26,7 +26,7 @@ config SQUASHFS
26 26
27 If unsure, say N. 27 If unsure, say N.
28 28
29config SQUASHFS_XATTRS 29config SQUASHFS_XATTR
30 bool "Squashfs XATTR support" 30 bool "Squashfs XATTR support"
31 depends on SQUASHFS 31 depends on SQUASHFS
32 default n 32 default n
@@ -37,9 +37,24 @@ config SQUASHFS_XATTRS
37 37
38 If unsure, say N. 38 If unsure, say N.
39 39
40config SQUASHFS_EMBEDDED 40config SQUASHFS_LZO
41 bool "Include support for LZO compressed file systems"
42 depends on SQUASHFS
43 default n
44 select LZO_DECOMPRESS
45 help
46 Saying Y here includes support for reading Squashfs file systems
47 compressed with LZO compresssion. LZO compression is mainly
48 aimed at embedded systems with slower CPUs where the overheads
49 of zlib are too high.
41 50
42 bool "Additional option for memory-constrained systems" 51 LZO is not the standard compression used in Squashfs and so most
52 file systems will be readable without selecting this option.
53
54 If unsure, say N.
55
56config SQUASHFS_EMBEDDED
57 bool "Additional option for memory-constrained systems"
43 depends on SQUASHFS 58 depends on SQUASHFS
44 default n 59 default n
45 help 60 help
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile
index 2cee3e9fa452..7672bac8d328 100644
--- a/fs/squashfs/Makefile
+++ b/fs/squashfs/Makefile
@@ -5,5 +5,5 @@
5obj-$(CONFIG_SQUASHFS) += squashfs.o 5obj-$(CONFIG_SQUASHFS) += squashfs.o
6squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o 6squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o
7squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o 7squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o
8squashfs-$(CONFIG_SQUASHFS_XATTRS) += xattr.o xattr_id.o 8squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o
9 9squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o
diff --git a/fs/squashfs/decompressor.c b/fs/squashfs/decompressor.c
index 157478da6ac9..24af9ce9722f 100644
--- a/fs/squashfs/decompressor.c
+++ b/fs/squashfs/decompressor.c
@@ -40,9 +40,11 @@ static const struct squashfs_decompressor squashfs_lzma_unsupported_comp_ops = {
40 NULL, NULL, NULL, LZMA_COMPRESSION, "lzma", 0 40 NULL, NULL, NULL, LZMA_COMPRESSION, "lzma", 0
41}; 41};
42 42
43#ifndef CONFIG_SQUASHFS_LZO
43static const struct squashfs_decompressor squashfs_lzo_unsupported_comp_ops = { 44static const struct squashfs_decompressor squashfs_lzo_unsupported_comp_ops = {
44 NULL, NULL, NULL, LZO_COMPRESSION, "lzo", 0 45 NULL, NULL, NULL, LZO_COMPRESSION, "lzo", 0
45}; 46};
47#endif
46 48
47static const struct squashfs_decompressor squashfs_unknown_comp_ops = { 49static const struct squashfs_decompressor squashfs_unknown_comp_ops = {
48 NULL, NULL, NULL, 0, "unknown", 0 50 NULL, NULL, NULL, 0, "unknown", 0
@@ -51,7 +53,11 @@ static const struct squashfs_decompressor squashfs_unknown_comp_ops = {
51static const struct squashfs_decompressor *decompressor[] = { 53static const struct squashfs_decompressor *decompressor[] = {
52 &squashfs_zlib_comp_ops, 54 &squashfs_zlib_comp_ops,
53 &squashfs_lzma_unsupported_comp_ops, 55 &squashfs_lzma_unsupported_comp_ops,
56#ifdef CONFIG_SQUASHFS_LZO
57 &squashfs_lzo_comp_ops,
58#else
54 &squashfs_lzo_unsupported_comp_ops, 59 &squashfs_lzo_unsupported_comp_ops,
60#endif
55 &squashfs_unknown_comp_ops 61 &squashfs_unknown_comp_ops
56}; 62};
57 63
diff --git a/fs/squashfs/lzo_wrapper.c b/fs/squashfs/lzo_wrapper.c
new file mode 100644
index 000000000000..5d87789bf1c1
--- /dev/null
+++ b/fs/squashfs/lzo_wrapper.c
@@ -0,0 +1,136 @@
1/*
2 * Squashfs - a compressed read only filesystem for Linux
3 *
4 * Copyright (c) 2010 LG Electronics
5 * Chan Jeong <chan.jeong@lge.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 * lzo_wrapper.c
22 */
23
24#include <linux/mutex.h>
25#include <linux/buffer_head.h>
26#include <linux/slab.h>
27#include <linux/vmalloc.h>
28#include <linux/lzo.h>
29
30#include "squashfs_fs.h"
31#include "squashfs_fs_sb.h"
32#include "squashfs_fs_i.h"
33#include "squashfs.h"
34#include "decompressor.h"
35
36struct squashfs_lzo {
37 void *input;
38 void *output;
39};
40
41static void *lzo_init(struct squashfs_sb_info *msblk)
42{
43 int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE);
44
45 struct squashfs_lzo *stream = kzalloc(sizeof(*stream), GFP_KERNEL);
46 if (stream == NULL)
47 goto failed;
48 stream->input = vmalloc(block_size);
49 if (stream->input == NULL)
50 goto failed;
51 stream->output = vmalloc(block_size);
52 if (stream->output == NULL)
53 goto failed2;
54
55 return stream;
56
57failed2:
58 vfree(stream->input);
59failed:
60 ERROR("Failed to allocate lzo workspace\n");
61 kfree(stream);
62 return NULL;
63}
64
65
66static void lzo_free(void *strm)
67{
68 struct squashfs_lzo *stream = strm;
69
70 if (stream) {
71 vfree(stream->input);
72 vfree(stream->output);
73 }
74 kfree(stream);
75}
76
77
78static int lzo_uncompress(struct squashfs_sb_info *msblk, void **buffer,
79 struct buffer_head **bh, int b, int offset, int length, int srclength,
80 int pages)
81{
82 struct squashfs_lzo *stream = msblk->stream;
83 void *buff = stream->input;
84 int avail, i, bytes = length, res;
85 size_t out_len = srclength;
86
87 mutex_lock(&msblk->read_data_mutex);
88
89 for (i = 0; i < b; i++) {
90 wait_on_buffer(bh[i]);
91 if (!buffer_uptodate(bh[i]))
92 goto block_release;
93
94 avail = min(bytes, msblk->devblksize - offset);
95 memcpy(buff, bh[i]->b_data + offset, avail);
96 buff += avail;
97 bytes -= avail;
98 offset = 0;
99 put_bh(bh[i]);
100 }
101
102 res = lzo1x_decompress_safe(stream->input, (size_t)length,
103 stream->output, &out_len);
104 if (res != LZO_E_OK)
105 goto failed;
106
107 res = bytes = (int)out_len;
108 for (i = 0, buff = stream->output; bytes && i < pages; i++) {
109 avail = min_t(int, bytes, PAGE_CACHE_SIZE);
110 memcpy(buffer[i], buff, avail);
111 buff += avail;
112 bytes -= avail;
113 }
114
115 mutex_unlock(&msblk->read_data_mutex);
116 return res;
117
118block_release:
119 for (; i < b; i++)
120 put_bh(bh[i]);
121
122failed:
123 mutex_unlock(&msblk->read_data_mutex);
124
125 ERROR("lzo decompression failed, data probably corrupt\n");
126 return -EIO;
127}
128
129const struct squashfs_decompressor squashfs_lzo_comp_ops = {
130 .init = lzo_init,
131 .free = lzo_free,
132 .decompress = lzo_uncompress,
133 .id = LZO_COMPRESSION,
134 .name = "lzo",
135 .supported = 1
136};
diff --git a/fs/squashfs/squashfs.h b/fs/squashfs/squashfs.h
index 733a17c42945..5d45569d5f72 100644
--- a/fs/squashfs/squashfs.h
+++ b/fs/squashfs/squashfs.h
@@ -104,3 +104,6 @@ extern const struct xattr_handler *squashfs_xattr_handlers[];
104 104
105/* zlib_wrapper.c */ 105/* zlib_wrapper.c */
106extern const struct squashfs_decompressor squashfs_zlib_comp_ops; 106extern const struct squashfs_decompressor squashfs_zlib_comp_ops;
107
108/* lzo_wrapper.c */
109extern const struct squashfs_decompressor squashfs_lzo_comp_ops;
diff --git a/fs/squashfs/squashfs_fs.h b/fs/squashfs/squashfs_fs.h
index 8eabb808b78d..c5137fc9ab11 100644
--- a/fs/squashfs/squashfs_fs.h
+++ b/fs/squashfs/squashfs_fs.h
@@ -274,7 +274,7 @@ struct squashfs_base_inode {
274 __le16 uid; 274 __le16 uid;
275 __le16 guid; 275 __le16 guid;
276 __le32 mtime; 276 __le32 mtime;
277 __le32 inode_number; 277 __le32 inode_number;
278}; 278};
279 279
280struct squashfs_ipc_inode { 280struct squashfs_ipc_inode {
@@ -283,7 +283,7 @@ struct squashfs_ipc_inode {
283 __le16 uid; 283 __le16 uid;
284 __le16 guid; 284 __le16 guid;
285 __le32 mtime; 285 __le32 mtime;
286 __le32 inode_number; 286 __le32 inode_number;
287 __le32 nlink; 287 __le32 nlink;
288}; 288};
289 289
@@ -293,7 +293,7 @@ struct squashfs_lipc_inode {
293 __le16 uid; 293 __le16 uid;
294 __le16 guid; 294 __le16 guid;
295 __le32 mtime; 295 __le32 mtime;
296 __le32 inode_number; 296 __le32 inode_number;
297 __le32 nlink; 297 __le32 nlink;
298 __le32 xattr; 298 __le32 xattr;
299}; 299};
@@ -304,7 +304,7 @@ struct squashfs_dev_inode {
304 __le16 uid; 304 __le16 uid;
305 __le16 guid; 305 __le16 guid;
306 __le32 mtime; 306 __le32 mtime;
307 __le32 inode_number; 307 __le32 inode_number;
308 __le32 nlink; 308 __le32 nlink;
309 __le32 rdev; 309 __le32 rdev;
310}; 310};
@@ -315,7 +315,7 @@ struct squashfs_ldev_inode {
315 __le16 uid; 315 __le16 uid;
316 __le16 guid; 316 __le16 guid;
317 __le32 mtime; 317 __le32 mtime;
318 __le32 inode_number; 318 __le32 inode_number;
319 __le32 nlink; 319 __le32 nlink;
320 __le32 rdev; 320 __le32 rdev;
321 __le32 xattr; 321 __le32 xattr;
@@ -327,7 +327,7 @@ struct squashfs_symlink_inode {
327 __le16 uid; 327 __le16 uid;
328 __le16 guid; 328 __le16 guid;
329 __le32 mtime; 329 __le32 mtime;
330 __le32 inode_number; 330 __le32 inode_number;
331 __le32 nlink; 331 __le32 nlink;
332 __le32 symlink_size; 332 __le32 symlink_size;
333 char symlink[0]; 333 char symlink[0];
@@ -339,7 +339,7 @@ struct squashfs_reg_inode {
339 __le16 uid; 339 __le16 uid;
340 __le16 guid; 340 __le16 guid;
341 __le32 mtime; 341 __le32 mtime;
342 __le32 inode_number; 342 __le32 inode_number;
343 __le32 start_block; 343 __le32 start_block;
344 __le32 fragment; 344 __le32 fragment;
345 __le32 offset; 345 __le32 offset;
@@ -353,7 +353,7 @@ struct squashfs_lreg_inode {
353 __le16 uid; 353 __le16 uid;
354 __le16 guid; 354 __le16 guid;
355 __le32 mtime; 355 __le32 mtime;
356 __le32 inode_number; 356 __le32 inode_number;
357 __le64 start_block; 357 __le64 start_block;
358 __le64 file_size; 358 __le64 file_size;
359 __le64 sparse; 359 __le64 sparse;
@@ -370,7 +370,7 @@ struct squashfs_dir_inode {
370 __le16 uid; 370 __le16 uid;
371 __le16 guid; 371 __le16 guid;
372 __le32 mtime; 372 __le32 mtime;
373 __le32 inode_number; 373 __le32 inode_number;
374 __le32 start_block; 374 __le32 start_block;
375 __le32 nlink; 375 __le32 nlink;
376 __le16 file_size; 376 __le16 file_size;
@@ -384,7 +384,7 @@ struct squashfs_ldir_inode {
384 __le16 uid; 384 __le16 uid;
385 __le16 guid; 385 __le16 guid;
386 __le32 mtime; 386 __le32 mtime;
387 __le32 inode_number; 387 __le32 inode_number;
388 __le32 nlink; 388 __le32 nlink;
389 __le32 file_size; 389 __le32 file_size;
390 __le32 start_block; 390 __le32 start_block;
diff --git a/fs/squashfs/xattr.c b/fs/squashfs/xattr.c
index c7655e8b31cd..652b8541f9c6 100644
--- a/fs/squashfs/xattr.c
+++ b/fs/squashfs/xattr.c
@@ -18,7 +18,7 @@
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * 20 *
21 * xattr_id.c 21 * xattr.c
22 */ 22 */
23 23
24#include <linux/init.h> 24#include <linux/init.h>
@@ -295,7 +295,7 @@ static const struct xattr_handler squashfs_xattr_security_handler = {
295 .get = squashfs_security_get 295 .get = squashfs_security_get
296}; 296};
297 297
298static inline const struct xattr_handler *squashfs_xattr_handler(int type) 298static const struct xattr_handler *squashfs_xattr_handler(int type)
299{ 299{
300 if (type & ~(SQUASHFS_XATTR_PREFIX_MASK | SQUASHFS_XATTR_VALUE_OOL)) 300 if (type & ~(SQUASHFS_XATTR_PREFIX_MASK | SQUASHFS_XATTR_VALUE_OOL))
301 /* ignore unrecognised type */ 301 /* ignore unrecognised type */
diff --git a/fs/squashfs/xattr.h b/fs/squashfs/xattr.h
index 9da071ae181c..49fe0d719fbf 100644
--- a/fs/squashfs/xattr.h
+++ b/fs/squashfs/xattr.h
@@ -21,7 +21,7 @@
21 * xattr.h 21 * xattr.h
22 */ 22 */
23 23
24#ifdef CONFIG_SQUASHFS_XATTRS 24#ifdef CONFIG_SQUASHFS_XATTR
25extern __le64 *squashfs_read_xattr_id_table(struct super_block *, u64, 25extern __le64 *squashfs_read_xattr_id_table(struct super_block *, u64,
26 u64 *, int *); 26 u64 *, int *);
27extern int squashfs_xattr_lookup(struct super_block *, unsigned int, int *, 27extern int squashfs_xattr_lookup(struct super_block *, unsigned int, int *,
diff --git a/fs/sysv/super.c b/fs/sysv/super.c
index 0e44a6253352..a0b0cda6927e 100644
--- a/fs/sysv/super.c
+++ b/fs/sysv/super.c
@@ -434,12 +434,46 @@ Ebadsize:
434 goto failed; 434 goto failed;
435} 435}
436 436
437static int v7_fill_super(struct super_block *sb, void *data, int silent) 437static int v7_sanity_check(struct super_block *sb, struct buffer_head *bh)
438{ 438{
439 struct sysv_sb_info *sbi;
440 struct buffer_head *bh, *bh2 = NULL;
441 struct v7_super_block *v7sb; 439 struct v7_super_block *v7sb;
442 struct sysv_inode *v7i; 440 struct sysv_inode *v7i;
441 struct buffer_head *bh2;
442 struct sysv_sb_info *sbi;
443
444 sbi = sb->s_fs_info;
445
446 /* plausibility check on superblock */
447 v7sb = (struct v7_super_block *) bh->b_data;
448 if (fs16_to_cpu(sbi, v7sb->s_nfree) > V7_NICFREE ||
449 fs16_to_cpu(sbi, v7sb->s_ninode) > V7_NICINOD ||
450 fs32_to_cpu(sbi, v7sb->s_fsize) > V7_MAXSIZE)
451 return 0;
452
453 /* plausibility check on root inode: it is a directory,
454 with a nonzero size that is a multiple of 16 */
455 bh2 = sb_bread(sb, 2);
456 if (bh2 == NULL)
457 return 0;
458
459 v7i = (struct sysv_inode *)(bh2->b_data + 64);
460 if ((fs16_to_cpu(sbi, v7i->i_mode) & ~0777) != S_IFDIR ||
461 (fs32_to_cpu(sbi, v7i->i_size) == 0) ||
462 (fs32_to_cpu(sbi, v7i->i_size) & 017) ||
463 (fs32_to_cpu(sbi, v7i->i_size) > V7_NFILES *
464 sizeof(struct sysv_dir_entry))) {
465 brelse(bh2);
466 return 0;
467 }
468
469 brelse(bh2);
470 return 1;
471}
472
473static int v7_fill_super(struct super_block *sb, void *data, int silent)
474{
475 struct sysv_sb_info *sbi;
476 struct buffer_head *bh;
443 477
444 if (440 != sizeof (struct v7_super_block)) 478 if (440 != sizeof (struct v7_super_block))
445 panic("V7 FS: bad super-block size"); 479 panic("V7 FS: bad super-block size");
@@ -453,7 +487,6 @@ static int v7_fill_super(struct super_block *sb, void *data, int silent)
453 sbi->s_sb = sb; 487 sbi->s_sb = sb;
454 sbi->s_block_base = 0; 488 sbi->s_block_base = 0;
455 sbi->s_type = FSTYPE_V7; 489 sbi->s_type = FSTYPE_V7;
456 sbi->s_bytesex = BYTESEX_PDP;
457 sb->s_fs_info = sbi; 490 sb->s_fs_info = sbi;
458 491
459 sb_set_blocksize(sb, 512); 492 sb_set_blocksize(sb, 512);
@@ -465,32 +498,27 @@ static int v7_fill_super(struct super_block *sb, void *data, int silent)
465 goto failed; 498 goto failed;
466 } 499 }
467 500
468 /* plausibility check on superblock */ 501 /* Try PDP-11 UNIX */
469 v7sb = (struct v7_super_block *) bh->b_data; 502 sbi->s_bytesex = BYTESEX_PDP;
470 if (fs16_to_cpu(sbi, v7sb->s_nfree) > V7_NICFREE || 503 if (v7_sanity_check(sb, bh))
471 fs16_to_cpu(sbi, v7sb->s_ninode) > V7_NICINOD || 504 goto detected;
472 fs32_to_cpu(sbi, v7sb->s_time) == 0)
473 goto failed;
474 505
475 /* plausibility check on root inode: it is a directory, 506 /* Try PC/IX, v7/x86 */
476 with a nonzero size that is a multiple of 16 */ 507 sbi->s_bytesex = BYTESEX_LE;
477 if ((bh2 = sb_bread(sb, 2)) == NULL) 508 if (v7_sanity_check(sb, bh))
478 goto failed; 509 goto detected;
479 v7i = (struct sysv_inode *)(bh2->b_data + 64);
480 if ((fs16_to_cpu(sbi, v7i->i_mode) & ~0777) != S_IFDIR ||
481 (fs32_to_cpu(sbi, v7i->i_size) == 0) ||
482 (fs32_to_cpu(sbi, v7i->i_size) & 017) != 0)
483 goto failed;
484 brelse(bh2);
485 bh2 = NULL;
486 510
511 goto failed;
512
513detected:
487 sbi->s_bh1 = bh; 514 sbi->s_bh1 = bh;
488 sbi->s_bh2 = bh; 515 sbi->s_bh2 = bh;
489 if (complete_read_super(sb, silent, 1)) 516 if (complete_read_super(sb, silent, 1))
490 return 0; 517 return 0;
491 518
492failed: 519failed:
493 brelse(bh2); 520 printk(KERN_ERR "VFS: could not find a valid V7 on %s.\n",
521 sb->s_id);
494 brelse(bh); 522 brelse(bh);
495 kfree(sbi); 523 kfree(sbi);
496 return -EINVAL; 524 return -EINVAL;
@@ -559,4 +587,5 @@ static void __exit exit_sysv_fs(void)
559 587
560module_init(init_sysv_fs) 588module_init(init_sysv_fs)
561module_exit(exit_sysv_fs) 589module_exit(exit_sysv_fs)
590MODULE_ALIAS("v7");
562MODULE_LICENSE("GPL"); 591MODULE_LICENSE("GPL");
diff --git a/include/acpi/platform/aclinux.h b/include/acpi/platform/aclinux.h
index e5039a2856f8..103f08aca764 100644
--- a/include/acpi/platform/aclinux.h
+++ b/include/acpi/platform/aclinux.h
@@ -148,13 +148,17 @@ static inline void *acpi_os_acquire_object(acpi_cache_t * cache)
148#define ACPI_ALLOCATE_ZEROED(a) acpi_os_allocate_zeroed(a) 148#define ACPI_ALLOCATE_ZEROED(a) acpi_os_allocate_zeroed(a)
149#define ACPI_FREE(a) kfree(a) 149#define ACPI_FREE(a) kfree(a)
150 150
151/* Used within ACPICA to show where it is safe to preempt execution */ 151#ifndef CONFIG_PREEMPT
152#include <linux/hardirq.h> 152/*
153 * Used within ACPICA to show where it is safe to preempt execution
154 * when CONFIG_PREEMPT=n
155 */
153#define ACPI_PREEMPTION_POINT() \ 156#define ACPI_PREEMPTION_POINT() \
154 do { \ 157 do { \
155 if (!in_atomic_preempt_off() && !irqs_disabled()) \ 158 if (!irqs_disabled()) \
156 cond_resched(); \ 159 cond_resched(); \
157 } while (0) 160 } while (0)
161#endif
158 162
159#endif /* __KERNEL__ */ 163#endif /* __KERNEL__ */
160 164
diff --git a/include/asm-generic/dma-mapping-broken.h b/include/asm-generic/dma-mapping-broken.h
index 82cd0cb1c3fe..ccf7b4f34a3c 100644
--- a/include/asm-generic/dma-mapping-broken.h
+++ b/include/asm-generic/dma-mapping-broken.h
@@ -72,9 +72,6 @@ dma_set_mask(struct device *dev, u64 mask);
72extern int 72extern int
73dma_get_cache_alignment(void); 73dma_get_cache_alignment(void);
74 74
75extern int
76dma_is_consistent(struct device *dev, dma_addr_t dma_handle);
77
78extern void 75extern void
79dma_cache_sync(struct device *dev, void *vaddr, size_t size, 76dma_cache_sync(struct device *dev, void *vaddr, size_t size,
80 enum dma_data_direction direction); 77 enum dma_data_direction direction);
diff --git a/include/asm-generic/fcntl.h b/include/asm-generic/fcntl.h
index e3cbc38bdcc2..a70b2d2bfc14 100644
--- a/include/asm-generic/fcntl.h
+++ b/include/asm-generic/fcntl.h
@@ -11,6 +11,10 @@
11 * -Eric Paris 11 * -Eric Paris
12 */ 12 */
13 13
14/*
15 * When introducing new O_* bits, please check its uniqueness in fcntl_init().
16 */
17
14#define O_ACCMODE 00000003 18#define O_ACCMODE 00000003
15#define O_RDONLY 00000000 19#define O_RDONLY 00000000
16#define O_WRONLY 00000001 20#define O_WRONLY 00000001
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index e2a4da7d7fab..2a512bc0d4ab 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -1075,7 +1075,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev,
1075 return ((dev->driver->driver_features & feature) ? 1 : 0); 1075 return ((dev->driver->driver_features & feature) ? 1 : 0);
1076} 1076}
1077 1077
1078
1079static inline int drm_dev_to_irq(struct drm_device *dev) 1078static inline int drm_dev_to_irq(struct drm_device *dev)
1080{ 1079{
1081 if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE)) 1080 if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE))
@@ -1084,11 +1083,22 @@ static inline int drm_dev_to_irq(struct drm_device *dev)
1084 return dev->pdev->irq; 1083 return dev->pdev->irq;
1085} 1084}
1086 1085
1087#ifdef __alpha__ 1086static inline int drm_get_pci_domain(struct drm_device *dev)
1088#define drm_get_pci_domain(dev) dev->hose->index 1087{
1089#else 1088 if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE))
1090#define drm_get_pci_domain(dev) 0 1089 return 0;
1091#endif 1090
1091#ifndef __alpha__
1092 /* For historical reasons, drm_get_pci_domain() is busticated
1093 * on most archs and has to remain so for userspace interface
1094 * < 1.4, except on alpha which was right from the beginning
1095 */
1096 if (dev->if_version < 0x10004)
1097 return 0;
1098#endif /* __alpha__ */
1099
1100 return pci_domain_nr(dev->pdev->bus);
1101}
1092 1102
1093#if __OS_HAS_AGP 1103#if __OS_HAS_AGP
1094static inline int drm_core_has_AGP(struct drm_device *dev) 1104static inline int drm_core_has_AGP(struct drm_device *dev)
diff --git a/include/drm/drm_core.h b/include/drm/drm_core.h
index 316739036079..4e7523863a4b 100644
--- a/include/drm/drm_core.h
+++ b/include/drm/drm_core.h
@@ -27,7 +27,7 @@
27#define CORE_DATE "20060810" 27#define CORE_DATE "20060810"
28 28
29#define DRM_IF_MAJOR 1 29#define DRM_IF_MAJOR 1
30#define DRM_IF_MINOR 3 30#define DRM_IF_MINOR 4
31 31
32#define CORE_MAJOR 1 32#define CORE_MAJOR 1
33#define CORE_MINOR 1 33#define CORE_MINOR 1
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index c707270bff5a..c9f3cc5949a8 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -189,49 +189,16 @@ enum subpixel_order {
189 */ 189 */
190struct drm_display_info { 190struct drm_display_info {
191 char name[DRM_DISPLAY_INFO_LEN]; 191 char name[DRM_DISPLAY_INFO_LEN];
192 /* Input info */ 192
193 bool serration_vsync;
194 bool sync_on_green;
195 bool composite_sync;
196 bool separate_syncs;
197 bool blank_to_black;
198 unsigned char video_level;
199 bool digital;
200 /* Physical size */ 193 /* Physical size */
201 unsigned int width_mm; 194 unsigned int width_mm;
202 unsigned int height_mm; 195 unsigned int height_mm;
203 196
204 /* Display parameters */
205 unsigned char gamma; /* FIXME: storage format */
206 bool gtf_supported;
207 bool standard_color;
208 enum {
209 monochrome = 0,
210 rgb,
211 other,
212 unknown,
213 } display_type;
214 bool active_off_supported;
215 bool suspend_supported;
216 bool standby_supported;
217
218 /* Color info FIXME: storage format */
219 unsigned short redx, redy;
220 unsigned short greenx, greeny;
221 unsigned short bluex, bluey;
222 unsigned short whitex, whitey;
223
224 /* Clock limits FIXME: storage format */ 197 /* Clock limits FIXME: storage format */
225 unsigned int min_vfreq, max_vfreq; 198 unsigned int min_vfreq, max_vfreq;
226 unsigned int min_hfreq, max_hfreq; 199 unsigned int min_hfreq, max_hfreq;
227 unsigned int pixel_clock; 200 unsigned int pixel_clock;
228 201
229 /* White point indices FIXME: storage format */
230 unsigned int wpx1, wpy1;
231 unsigned int wpgamma1;
232 unsigned int wpx2, wpy2;
233 unsigned int wpgamma2;
234
235 enum subpixel_order subpixel_order; 202 enum subpixel_order subpixel_order;
236 203
237 char *raw_edid; /* if any */ 204 char *raw_edid; /* if any */
@@ -342,7 +309,7 @@ struct drm_crtc_funcs {
342 309
343 /* Set gamma on the CRTC */ 310 /* Set gamma on the CRTC */
344 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, 311 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
345 uint32_t size); 312 uint32_t start, uint32_t size);
346 /* Object destroy routine */ 313 /* Object destroy routine */
347 void (*destroy)(struct drm_crtc *crtc); 314 void (*destroy)(struct drm_crtc *crtc);
348 315
diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
index 39e2cc5c7e66..5881fad91faa 100644
--- a/include/drm/drm_edid.h
+++ b/include/drm/drm_edid.h
@@ -28,6 +28,12 @@
28#define EDID_LENGTH 128 28#define EDID_LENGTH 128
29#define DDC_ADDR 0x50 29#define DDC_ADDR 0x50
30 30
31#define CEA_EXT 0x02
32#define VTB_EXT 0x10
33#define DI_EXT 0x40
34#define LS_EXT 0x50
35#define MI_EXT 0x60
36
31struct est_timings { 37struct est_timings {
32 u8 t1; 38 u8 t1;
33 u8 t2; 39 u8 t2;
diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
index 7628219e5386..35b00746c712 100644
--- a/include/linux/backing-dev.h
+++ b/include/linux/backing-dev.h
@@ -31,6 +31,7 @@ enum bdi_state {
31 BDI_async_congested, /* The async (write) queue is getting full */ 31 BDI_async_congested, /* The async (write) queue is getting full */
32 BDI_sync_congested, /* The sync queue is getting full */ 32 BDI_sync_congested, /* The sync queue is getting full */
33 BDI_registered, /* bdi_register() was done */ 33 BDI_registered, /* bdi_register() was done */
34 BDI_writeback_running, /* Writeback is in progress */
34 BDI_unused, /* Available bits start here */ 35 BDI_unused, /* Available bits start here */
35}; 36};
36 37
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 53691774d34e..ca83a97c9715 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -150,6 +150,7 @@ enum rq_flag_bits {
150 __REQ_FLUSH, /* request for cache flush */ 150 __REQ_FLUSH, /* request for cache flush */
151 __REQ_IO_STAT, /* account I/O stat */ 151 __REQ_IO_STAT, /* account I/O stat */
152 __REQ_MIXED_MERGE, /* merge of different types, fail separately */ 152 __REQ_MIXED_MERGE, /* merge of different types, fail separately */
153 __REQ_SECURE, /* secure discard (used with __REQ_DISCARD) */
153 __REQ_NR_BITS, /* stops here */ 154 __REQ_NR_BITS, /* stops here */
154}; 155};
155 156
@@ -190,5 +191,6 @@ enum rq_flag_bits {
190#define REQ_FLUSH (1 << __REQ_FLUSH) 191#define REQ_FLUSH (1 << __REQ_FLUSH)
191#define REQ_IO_STAT (1 << __REQ_IO_STAT) 192#define REQ_IO_STAT (1 << __REQ_IO_STAT)
192#define REQ_MIXED_MERGE (1 << __REQ_MIXED_MERGE) 193#define REQ_MIXED_MERGE (1 << __REQ_MIXED_MERGE)
194#define REQ_SECURE (1 << __REQ_SECURE)
193 195
194#endif /* __LINUX_BLK_TYPES_H */ 196#endif /* __LINUX_BLK_TYPES_H */
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 89c855c5655c..2c54906f678f 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -389,6 +389,7 @@ struct request_queue
389#define QUEUE_FLAG_DISCARD 16 /* supports DISCARD */ 389#define QUEUE_FLAG_DISCARD 16 /* supports DISCARD */
390#define QUEUE_FLAG_NOXMERGES 17 /* No extended merges */ 390#define QUEUE_FLAG_NOXMERGES 17 /* No extended merges */
391#define QUEUE_FLAG_ADD_RANDOM 18 /* Contributes to random pool */ 391#define QUEUE_FLAG_ADD_RANDOM 18 /* Contributes to random pool */
392#define QUEUE_FLAG_SECDISCARD 19 /* supports SECDISCARD */
392 393
393#define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ 394#define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
394 (1 << QUEUE_FLAG_CLUSTER) | \ 395 (1 << QUEUE_FLAG_CLUSTER) | \
@@ -524,6 +525,8 @@ enum {
524#define blk_queue_stackable(q) \ 525#define blk_queue_stackable(q) \
525 test_bit(QUEUE_FLAG_STACKABLE, &(q)->queue_flags) 526 test_bit(QUEUE_FLAG_STACKABLE, &(q)->queue_flags)
526#define blk_queue_discard(q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags) 527#define blk_queue_discard(q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags)
528#define blk_queue_secdiscard(q) (blk_queue_discard(q) && \
529 test_bit(QUEUE_FLAG_SECDISCARD, &(q)->queue_flags))
527 530
528#define blk_noretry_request(rq) \ 531#define blk_noretry_request(rq) \
529 ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \ 532 ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
@@ -918,10 +921,12 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt,
918} 921}
919enum{ 922enum{
920 BLKDEV_WAIT, /* wait for completion */ 923 BLKDEV_WAIT, /* wait for completion */
921 BLKDEV_BARRIER, /*issue request with barrier */ 924 BLKDEV_BARRIER, /* issue request with barrier */
925 BLKDEV_SECURE, /* secure discard */
922}; 926};
923#define BLKDEV_IFL_WAIT (1 << BLKDEV_WAIT) 927#define BLKDEV_IFL_WAIT (1 << BLKDEV_WAIT)
924#define BLKDEV_IFL_BARRIER (1 << BLKDEV_BARRIER) 928#define BLKDEV_IFL_BARRIER (1 << BLKDEV_BARRIER)
929#define BLKDEV_IFL_SECURE (1 << BLKDEV_SECURE)
925extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *, 930extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *,
926 unsigned long); 931 unsigned long);
927extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector, 932extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index d23be0386e2d..6a4aea30aa09 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -315,6 +315,7 @@ extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
315 315
316extern char *__d_path(const struct path *path, struct path *root, char *, int); 316extern char *__d_path(const struct path *path, struct path *root, char *, int);
317extern char *d_path(const struct path *, char *, int); 317extern char *d_path(const struct path *, char *, int);
318extern char *d_path_with_unreachable(const struct path *, char *, int);
318extern char *__dentry_path(struct dentry *, char *, int); 319extern char *__dentry_path(struct dentry *, char *, int);
319extern char *dentry_path(struct dentry *, char *, int); 320extern char *dentry_path(struct dentry *, char *, int);
320 321
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index 1381cd97b4ed..2970022faa63 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -22,7 +22,7 @@ typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
22union map_info { 22union map_info {
23 void *ptr; 23 void *ptr;
24 unsigned long long ll; 24 unsigned long long ll;
25 unsigned flush_request; 25 unsigned target_request_nr;
26}; 26};
27 27
28/* 28/*
@@ -174,12 +174,18 @@ struct dm_target {
174 * A number of zero-length barrier requests that will be submitted 174 * A number of zero-length barrier requests that will be submitted
175 * to the target for the purpose of flushing cache. 175 * to the target for the purpose of flushing cache.
176 * 176 *
177 * The request number will be placed in union map_info->flush_request. 177 * The request number will be placed in union map_info->target_request_nr.
178 * It is a responsibility of the target driver to remap these requests 178 * It is a responsibility of the target driver to remap these requests
179 * to the real underlying devices. 179 * to the real underlying devices.
180 */ 180 */
181 unsigned num_flush_requests; 181 unsigned num_flush_requests;
182 182
183 /*
184 * The number of discard requests that will be submitted to the
185 * target. map_info->request_nr is used just like num_flush_requests.
186 */
187 unsigned num_discard_requests;
188
183 /* target specific data */ 189 /* target specific data */
184 void *private; 190 void *private;
185 191
@@ -392,6 +398,12 @@ void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size);
392#define dm_array_too_big(fixed, obj, num) \ 398#define dm_array_too_big(fixed, obj, num) \
393 ((num) > (UINT_MAX - (fixed)) / (obj)) 399 ((num) > (UINT_MAX - (fixed)) / (obj))
394 400
401/*
402 * Sector offset taken relative to the start of the target instead of
403 * relative to the start of the device.
404 */
405#define dm_target_offset(ti, sector) ((sector) - (ti)->begin)
406
395static inline sector_t to_sector(unsigned long n) 407static inline sector_t to_sector(unsigned long n)
396{ 408{
397 return (n >> SECTOR_SHIFT); 409 return (n >> SECTOR_SHIFT);
diff --git a/include/linux/dm-ioctl.h b/include/linux/dm-ioctl.h
index 2c445e113790..49eab360d5d4 100644
--- a/include/linux/dm-ioctl.h
+++ b/include/linux/dm-ioctl.h
@@ -11,6 +11,7 @@
11#include <linux/types.h> 11#include <linux/types.h>
12 12
13#define DM_DIR "mapper" /* Slashes not supported */ 13#define DM_DIR "mapper" /* Slashes not supported */
14#define DM_CONTROL_NODE "control"
14#define DM_MAX_TYPE_NAME 16 15#define DM_MAX_TYPE_NAME 16
15#define DM_NAME_LEN 128 16#define DM_NAME_LEN 128
16#define DM_UUID_LEN 129 17#define DM_UUID_LEN 129
@@ -266,9 +267,9 @@ enum {
266#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl) 267#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
267 268
268#define DM_VERSION_MAJOR 4 269#define DM_VERSION_MAJOR 4
269#define DM_VERSION_MINOR 17 270#define DM_VERSION_MINOR 18
270#define DM_VERSION_PATCHLEVEL 0 271#define DM_VERSION_PATCHLEVEL 0
271#define DM_VERSION_EXTRA "-ioctl (2010-03-05)" 272#define DM_VERSION_EXTRA "-ioctl (2010-06-29)"
272 273
273/* Status bits */ 274/* Status bits */
274#define DM_READONLY_FLAG (1 << 0) /* In/Out */ 275#define DM_READONLY_FLAG (1 << 0) /* In/Out */
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 89b7e1a605b8..e0670a512056 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -142,6 +142,14 @@ static inline int dma_set_seg_boundary(struct device *dev, unsigned long mask)
142 return -EIO; 142 return -EIO;
143} 143}
144 144
145static inline int dma_get_cache_alignment(void)
146{
147#ifdef ARCH_DMA_MINALIGN
148 return ARCH_DMA_MINALIGN;
149#endif
150 return 1;
151}
152
145/* flags for the coherent memory api */ 153/* flags for the coherent memory api */
146#define DMA_MEMORY_MAP 0x01 154#define DMA_MEMORY_MAP 0x01
147#define DMA_MEMORY_IO 0x02 155#define DMA_MEMORY_IO 0x02
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index 848480bc2bf9..2308fbb4523a 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -129,7 +129,7 @@ static inline void random_ether_addr(u8 *addr)
129/** 129/**
130 * dev_hw_addr_random - Create random MAC and set device flag 130 * dev_hw_addr_random - Create random MAC and set device flag
131 * @dev: pointer to net_device structure 131 * @dev: pointer to net_device structure
132 * @addr: Pointer to a six-byte array containing the Ethernet address 132 * @hwaddr: Pointer to a six-byte array containing the Ethernet address
133 * 133 *
134 * Generate random MAC to be used by a device and set addr_assign_type 134 * Generate random MAC to be used by a device and set addr_assign_type
135 * so the state can be read by sysfs and be used by udev. 135 * so the state can be read by sysfs and be used by udev.
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 1542e0e52b2e..7a0625e26a39 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -93,7 +93,7 @@ struct inodes_stat_t {
93#define FMODE_RANDOM ((__force fmode_t)0x1000) 93#define FMODE_RANDOM ((__force fmode_t)0x1000)
94 94
95/* File was opened by fanotify and shouldn't generate fanotify events */ 95/* File was opened by fanotify and shouldn't generate fanotify events */
96#define FMODE_NONOTIFY ((__force fmode_t)16777216) /* 0x1000000 */ 96#define FMODE_NONOTIFY ((__force fmode_t)0x1000000)
97 97
98/* 98/*
99 * The below are the various read and write types that we support. Some of 99 * The below are the various read and write types that we support. Some of
@@ -174,6 +174,7 @@ struct inodes_stat_t {
174 */ 174 */
175#define DISCARD_NOBARRIER (WRITE | REQ_DISCARD) 175#define DISCARD_NOBARRIER (WRITE | REQ_DISCARD)
176#define DISCARD_BARRIER (WRITE | REQ_DISCARD | REQ_HARDBARRIER) 176#define DISCARD_BARRIER (WRITE | REQ_DISCARD | REQ_HARDBARRIER)
177#define DISCARD_SECURE (DISCARD_NOBARRIER | REQ_SECURE)
177 178
178#define SEL_IN 1 179#define SEL_IN 1
179#define SEL_OUT 2 180#define SEL_OUT 2
@@ -317,6 +318,7 @@ struct inodes_stat_t {
317#define BLKALIGNOFF _IO(0x12,122) 318#define BLKALIGNOFF _IO(0x12,122)
318#define BLKPBSZGET _IO(0x12,123) 319#define BLKPBSZGET _IO(0x12,123)
319#define BLKDISCARDZEROES _IO(0x12,124) 320#define BLKDISCARDZEROES _IO(0x12,124)
321#define BLKSECDISCARD _IO(0x12,125)
320 322
321#define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ 323#define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
322#define FIBMAP _IO(0x00,1) /* bmap access */ 324#define FIBMAP _IO(0x00,1) /* bmap access */
diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
index 78a05bfcd8eb..eca3d5202138 100644
--- a/include/linux/fs_struct.h
+++ b/include/linux/fs_struct.h
@@ -21,4 +21,31 @@ extern void free_fs_struct(struct fs_struct *);
21extern void daemonize_fs_struct(void); 21extern void daemonize_fs_struct(void);
22extern int unshare_fs_struct(void); 22extern int unshare_fs_struct(void);
23 23
24static inline void get_fs_root(struct fs_struct *fs, struct path *root)
25{
26 read_lock(&fs->lock);
27 *root = fs->root;
28 path_get(root);
29 read_unlock(&fs->lock);
30}
31
32static inline void get_fs_pwd(struct fs_struct *fs, struct path *pwd)
33{
34 read_lock(&fs->lock);
35 *pwd = fs->pwd;
36 path_get(pwd);
37 read_unlock(&fs->lock);
38}
39
40static inline void get_fs_root_and_pwd(struct fs_struct *fs, struct path *root,
41 struct path *pwd)
42{
43 read_lock(&fs->lock);
44 *root = fs->root;
45 path_get(root);
46 *pwd = fs->pwd;
47 path_get(pwd);
48 read_unlock(&fs->lock);
49}
50
24#endif /* _LINUX_FS_STRUCT_H */ 51#endif /* _LINUX_FS_STRUCT_H */
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index e4e2204187ee..59d0df43ff9d 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -26,18 +26,19 @@ static inline void fsnotify_d_instantiate(struct dentry *dentry,
26} 26}
27 27
28/* Notify this dentry's parent about a child's events. */ 28/* Notify this dentry's parent about a child's events. */
29static inline void fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask) 29static inline void fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
30{ 30{
31 if (!dentry) 31 if (!dentry)
32 dentry = file->f_path.dentry; 32 dentry = path->dentry;
33 33
34 __fsnotify_parent(file, dentry, mask); 34 __fsnotify_parent(path, dentry, mask);
35} 35}
36 36
37/* simple call site for access decisions */ 37/* simple call site for access decisions */
38static inline int fsnotify_perm(struct file *file, int mask) 38static inline int fsnotify_perm(struct file *file, int mask)
39{ 39{
40 struct inode *inode = file->f_path.dentry->d_inode; 40 struct path *path = &file->f_path;
41 struct inode *inode = path->dentry->d_inode;
41 __u32 fsnotify_mask = 0; 42 __u32 fsnotify_mask = 0;
42 43
43 if (file->f_mode & FMODE_NONOTIFY) 44 if (file->f_mode & FMODE_NONOTIFY)
@@ -51,7 +52,7 @@ static inline int fsnotify_perm(struct file *file, int mask)
51 else 52 else
52 BUG(); 53 BUG();
53 54
54 return fsnotify(inode, fsnotify_mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); 55 return fsnotify(inode, fsnotify_mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
55} 56}
56 57
57/* 58/*
@@ -186,15 +187,16 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
186 */ 187 */
187static inline void fsnotify_access(struct file *file) 188static inline void fsnotify_access(struct file *file)
188{ 189{
189 struct inode *inode = file->f_path.dentry->d_inode; 190 struct path *path = &file->f_path;
191 struct inode *inode = path->dentry->d_inode;
190 __u32 mask = FS_ACCESS; 192 __u32 mask = FS_ACCESS;
191 193
192 if (S_ISDIR(inode->i_mode)) 194 if (S_ISDIR(inode->i_mode))
193 mask |= FS_IN_ISDIR; 195 mask |= FS_IN_ISDIR;
194 196
195 if (!(file->f_mode & FMODE_NONOTIFY)) { 197 if (!(file->f_mode & FMODE_NONOTIFY)) {
196 fsnotify_parent(file, NULL, mask); 198 fsnotify_parent(path, NULL, mask);
197 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); 199 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
198 } 200 }
199} 201}
200 202
@@ -203,15 +205,16 @@ static inline void fsnotify_access(struct file *file)
203 */ 205 */
204static inline void fsnotify_modify(struct file *file) 206static inline void fsnotify_modify(struct file *file)
205{ 207{
206 struct inode *inode = file->f_path.dentry->d_inode; 208 struct path *path = &file->f_path;
209 struct inode *inode = path->dentry->d_inode;
207 __u32 mask = FS_MODIFY; 210 __u32 mask = FS_MODIFY;
208 211
209 if (S_ISDIR(inode->i_mode)) 212 if (S_ISDIR(inode->i_mode))
210 mask |= FS_IN_ISDIR; 213 mask |= FS_IN_ISDIR;
211 214
212 if (!(file->f_mode & FMODE_NONOTIFY)) { 215 if (!(file->f_mode & FMODE_NONOTIFY)) {
213 fsnotify_parent(file, NULL, mask); 216 fsnotify_parent(path, NULL, mask);
214 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); 217 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
215 } 218 }
216} 219}
217 220
@@ -220,15 +223,16 @@ static inline void fsnotify_modify(struct file *file)
220 */ 223 */
221static inline void fsnotify_open(struct file *file) 224static inline void fsnotify_open(struct file *file)
222{ 225{
223 struct inode *inode = file->f_path.dentry->d_inode; 226 struct path *path = &file->f_path;
227 struct inode *inode = path->dentry->d_inode;
224 __u32 mask = FS_OPEN; 228 __u32 mask = FS_OPEN;
225 229
226 if (S_ISDIR(inode->i_mode)) 230 if (S_ISDIR(inode->i_mode))
227 mask |= FS_IN_ISDIR; 231 mask |= FS_IN_ISDIR;
228 232
229 if (!(file->f_mode & FMODE_NONOTIFY)) { 233 if (!(file->f_mode & FMODE_NONOTIFY)) {
230 fsnotify_parent(file, NULL, mask); 234 fsnotify_parent(path, NULL, mask);
231 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); 235 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
232 } 236 }
233} 237}
234 238
@@ -237,6 +241,7 @@ static inline void fsnotify_open(struct file *file)
237 */ 241 */
238static inline void fsnotify_close(struct file *file) 242static inline void fsnotify_close(struct file *file)
239{ 243{
244 struct path *path = &file->f_path;
240 struct inode *inode = file->f_path.dentry->d_inode; 245 struct inode *inode = file->f_path.dentry->d_inode;
241 fmode_t mode = file->f_mode; 246 fmode_t mode = file->f_mode;
242 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE; 247 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
@@ -245,8 +250,8 @@ static inline void fsnotify_close(struct file *file)
245 mask |= FS_IN_ISDIR; 250 mask |= FS_IN_ISDIR;
246 251
247 if (!(file->f_mode & FMODE_NONOTIFY)) { 252 if (!(file->f_mode & FMODE_NONOTIFY)) {
248 fsnotify_parent(file, NULL, mask); 253 fsnotify_parent(path, NULL, mask);
249 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); 254 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
250 } 255 }
251} 256}
252 257
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 9bbfd7204b04..ed36fb57c426 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -203,20 +203,20 @@ struct fsnotify_event {
203 /* to_tell may ONLY be dereferenced during handle_event(). */ 203 /* to_tell may ONLY be dereferenced during handle_event(). */
204 struct inode *to_tell; /* either the inode the event happened to or its parent */ 204 struct inode *to_tell; /* either the inode the event happened to or its parent */
205 /* 205 /*
206 * depending on the event type we should have either a file or inode 206 * depending on the event type we should have either a path or inode
207 * We hold a reference on file, but NOT on inode. Since we have the ref on 207 * We hold a reference on path, but NOT on inode. Since we have the ref on
208 * the file, it may be dereferenced at any point during this object's 208 * the path, it may be dereferenced at any point during this object's
209 * lifetime. That reference is dropped when this object's refcnt hits 209 * lifetime. That reference is dropped when this object's refcnt hits
210 * 0. If this event contains an inode instead of a file, the inode may 210 * 0. If this event contains an inode instead of a path, the inode may
211 * ONLY be used during handle_event(). 211 * ONLY be used during handle_event().
212 */ 212 */
213 union { 213 union {
214 struct file *file; 214 struct path path;
215 struct inode *inode; 215 struct inode *inode;
216 }; 216 };
217/* when calling fsnotify tell it if the data is a path or inode */ 217/* when calling fsnotify tell it if the data is a path or inode */
218#define FSNOTIFY_EVENT_NONE 0 218#define FSNOTIFY_EVENT_NONE 0
219#define FSNOTIFY_EVENT_FILE 1 219#define FSNOTIFY_EVENT_PATH 1
220#define FSNOTIFY_EVENT_INODE 2 220#define FSNOTIFY_EVENT_INODE 2
221 int data_type; /* which of the above union we have */ 221 int data_type; /* which of the above union we have */
222 atomic_t refcnt; /* how many groups still are using/need to send this event */ 222 atomic_t refcnt; /* how many groups still are using/need to send this event */
@@ -293,7 +293,7 @@ struct fsnotify_mark {
293/* main fsnotify call to send events */ 293/* main fsnotify call to send events */
294extern int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, 294extern int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
295 const unsigned char *name, u32 cookie); 295 const unsigned char *name, u32 cookie);
296extern void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask); 296extern void __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask);
297extern void __fsnotify_inode_delete(struct inode *inode); 297extern void __fsnotify_inode_delete(struct inode *inode);
298extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt); 298extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt);
299extern u32 fsnotify_get_cookie(void); 299extern u32 fsnotify_get_cookie(void);
@@ -422,7 +422,7 @@ static inline int fsnotify(struct inode *to_tell, __u32 mask, void *data, int da
422 return 0; 422 return 0;
423} 423}
424 424
425static inline void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask) 425static inline void __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
426{} 426{}
427 427
428static inline void __fsnotify_inode_delete(struct inode *inode) 428static inline void __fsnotify_inode_delete(struct inode *inode)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 78b4bc64c006..f479700df61b 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -2,6 +2,7 @@
2#define _LINUX_HUGETLB_H 2#define _LINUX_HUGETLB_H
3 3
4#include <linux/fs.h> 4#include <linux/fs.h>
5#include <linux/hugetlb_inline.h>
5 6
6struct ctl_table; 7struct ctl_table;
7struct user_struct; 8struct user_struct;
@@ -14,11 +15,6 @@ struct user_struct;
14 15
15int PageHuge(struct page *page); 16int PageHuge(struct page *page);
16 17
17static inline int is_vm_hugetlb_page(struct vm_area_struct *vma)
18{
19 return vma->vm_flags & VM_HUGETLB;
20}
21
22void reset_vma_resv_huge_pages(struct vm_area_struct *vma); 18void reset_vma_resv_huge_pages(struct vm_area_struct *vma);
23int hugetlb_sysctl_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *); 19int hugetlb_sysctl_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *);
24int hugetlb_overcommit_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *); 20int hugetlb_overcommit_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *);
@@ -47,6 +43,7 @@ int hugetlb_reserve_pages(struct inode *inode, long from, long to,
47 struct vm_area_struct *vma, 43 struct vm_area_struct *vma,
48 int acctflags); 44 int acctflags);
49void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed); 45void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed);
46void __isolate_hwpoisoned_huge_page(struct page *page);
50 47
51extern unsigned long hugepages_treat_as_movable; 48extern unsigned long hugepages_treat_as_movable;
52extern const unsigned long hugetlb_zero, hugetlb_infinity; 49extern const unsigned long hugetlb_zero, hugetlb_infinity;
@@ -77,11 +74,6 @@ static inline int PageHuge(struct page *page)
77 return 0; 74 return 0;
78} 75}
79 76
80static inline int is_vm_hugetlb_page(struct vm_area_struct *vma)
81{
82 return 0;
83}
84
85static inline void reset_vma_resv_huge_pages(struct vm_area_struct *vma) 77static inline void reset_vma_resv_huge_pages(struct vm_area_struct *vma)
86{ 78{
87} 79}
@@ -108,6 +100,8 @@ static inline void hugetlb_report_meminfo(struct seq_file *m)
108#define is_hugepage_only_range(mm, addr, len) 0 100#define is_hugepage_only_range(mm, addr, len) 0
109#define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) ({BUG(); 0; }) 101#define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) ({BUG(); 0; })
110#define hugetlb_fault(mm, vma, addr, flags) ({ BUG(); 0; }) 102#define hugetlb_fault(mm, vma, addr, flags) ({ BUG(); 0; })
103#define huge_pte_offset(mm, address) 0
104#define __isolate_hwpoisoned_huge_page(page) 0
111 105
112#define hugetlb_change_protection(vma, address, end, newprot) 106#define hugetlb_change_protection(vma, address, end, newprot)
113 107
diff --git a/include/linux/hugetlb_inline.h b/include/linux/hugetlb_inline.h
new file mode 100644
index 000000000000..6931489a5c14
--- /dev/null
+++ b/include/linux/hugetlb_inline.h
@@ -0,0 +1,22 @@
1#ifndef _LINUX_HUGETLB_INLINE_H
2#define _LINUX_HUGETLB_INLINE_H
3
4#ifdef CONFIG_HUGETLB_PAGE
5
6#include <linux/mm.h>
7
8static inline int is_vm_hugetlb_page(struct vm_area_struct *vma)
9{
10 return vma->vm_flags & VM_HUGETLB;
11}
12
13#else
14
15static inline int is_vm_hugetlb_page(struct vm_area_struct *vma)
16{
17 return 0;
18}
19
20#endif
21
22#endif
diff --git a/include/linux/i2c-mux.h b/include/linux/i2c-mux.h
new file mode 100644
index 000000000000..34536effd652
--- /dev/null
+++ b/include/linux/i2c-mux.h
@@ -0,0 +1,46 @@
1/*
2 *
3 * i2c-mux.h - functions for the i2c-bus mux support
4 *
5 * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it>
6 * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it>
7 * Michael Lawnick <michael.lawnick.ext@nsn.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#ifndef _LINUX_I2C_MUX_H
25#define _LINUX_I2C_MUX_H
26
27#ifdef __KERNEL__
28
29/*
30 * Called to create a i2c bus on a multiplexed bus segment.
31 * The mux_dev and chan_id parameters are passed to the select
32 * and deselect callback functions to perform hardware-specific
33 * mux control.
34 */
35struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
36 void *mux_dev, u32 force_nr, u32 chan_id,
37 int (*select) (struct i2c_adapter *,
38 void *mux_dev, u32 chan_id),
39 int (*deselect) (struct i2c_adapter *,
40 void *mux_dev, u32 chan_id));
41
42int i2c_del_mux_adapter(struct i2c_adapter *adap);
43
44#endif /* __KERNEL__ */
45
46#endif /* _LINUX_I2C_MUX_H */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 38dd4025aa4e..4bae0b72ed3c 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -37,6 +37,7 @@
37#include <linux/of.h> /* for struct device_node */ 37#include <linux/of.h> /* for struct device_node */
38 38
39extern struct bus_type i2c_bus_type; 39extern struct bus_type i2c_bus_type;
40extern struct device_type i2c_adapter_type;
40 41
41/* --- General options ------------------------------------------------ */ 42/* --- General options ------------------------------------------------ */
42 43
@@ -284,12 +285,18 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info);
284 285
285/* If you don't know the exact address of an I2C device, use this variant 286/* If you don't know the exact address of an I2C device, use this variant
286 * instead, which can probe for device presence in a list of possible 287 * instead, which can probe for device presence in a list of possible
287 * addresses. 288 * addresses. The "probe" callback function is optional. If it is provided,
289 * it must return 1 on successful probe, 0 otherwise. If it is not provided,
290 * a default probing method is used.
288 */ 291 */
289extern struct i2c_client * 292extern struct i2c_client *
290i2c_new_probed_device(struct i2c_adapter *adap, 293i2c_new_probed_device(struct i2c_adapter *adap,
291 struct i2c_board_info *info, 294 struct i2c_board_info *info,
292 unsigned short const *addr_list); 295 unsigned short const *addr_list,
296 int (*probe)(struct i2c_adapter *, unsigned short addr));
297
298/* Common custom probe functions */
299extern int i2c_probe_func_quick_read(struct i2c_adapter *, unsigned short addr);
293 300
294/* For devices that use several addresses, use i2c_new_dummy() to make 301/* For devices that use several addresses, use i2c_new_dummy() to make
295 * client handles for the extra addresses. 302 * client handles for the extra addresses.
@@ -362,6 +369,7 @@ struct i2c_adapter {
362 char name[48]; 369 char name[48];
363 struct completion dev_released; 370 struct completion dev_released;
364 371
372 struct mutex userspace_clients_lock;
365 struct list_head userspace_clients; 373 struct list_head userspace_clients;
366}; 374};
367#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) 375#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
@@ -376,23 +384,16 @@ static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data)
376 dev_set_drvdata(&dev->dev, data); 384 dev_set_drvdata(&dev->dev, data);
377} 385}
378 386
379/** 387static inline int i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter)
380 * i2c_lock_adapter - Prevent access to an I2C bus segment
381 * @adapter: Target I2C bus segment
382 */
383static inline void i2c_lock_adapter(struct i2c_adapter *adapter)
384{ 388{
385 rt_mutex_lock(&adapter->bus_lock); 389 return adapter->dev.parent != NULL
390 && adapter->dev.parent->bus == &i2c_bus_type
391 && adapter->dev.parent->type == &i2c_adapter_type;
386} 392}
387 393
388/** 394/* Adapter locking functions, exported for shared pin cases */
389 * i2c_unlock_adapter - Reauthorize access to an I2C bus segment 395void i2c_lock_adapter(struct i2c_adapter *);
390 * @adapter: Target I2C bus segment 396void i2c_unlock_adapter(struct i2c_adapter *);
391 */
392static inline void i2c_unlock_adapter(struct i2c_adapter *adapter)
393{
394 rt_mutex_unlock(&adapter->bus_lock);
395}
396 397
397/*flags for the client struct: */ 398/*flags for the client struct: */
398#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ 399#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */
diff --git a/include/linux/i2c/pca954x.h b/include/linux/i2c/pca954x.h
new file mode 100644
index 000000000000..28f1f8d5ab1f
--- /dev/null
+++ b/include/linux/i2c/pca954x.h
@@ -0,0 +1,47 @@
1/*
2 *
3 * pca954x.h - I2C multiplexer/switch support
4 *
5 * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it>
6 * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it>
7 * Michael Lawnick <michael.lawnick.ext@nsn.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24
25#ifndef _LINUX_I2C_PCA954X_H
26#define _LINUX_I2C_PCA954X_H
27
28/* Platform data for the PCA954x I2C multiplexers */
29
30/* Per channel initialisation data:
31 * @adap_id: bus number for the adapter. 0 = don't care
32 * @deselect_on_exit: set this entry to 1, if your H/W needs deselection
33 * of this channel after transaction.
34 *
35 */
36struct pca954x_platform_mode {
37 int adap_id;
38 unsigned int deselect_on_exit:1;
39};
40
41/* Per mux/switch data, used with i2c_register_board_info */
42struct pca954x_platform_data {
43 struct pca954x_platform_mode *modes;
44 int num_modes;
45};
46
47#endif /* _LINUX_I2C_PCA954X_H */
diff --git a/include/linux/i2c/sx150x.h b/include/linux/i2c/sx150x.h
new file mode 100644
index 000000000000..ee3049cb9ba5
--- /dev/null
+++ b/include/linux/i2c/sx150x.h
@@ -0,0 +1,78 @@
1/*
2 * Driver for the Semtech SX150x I2C GPIO Expanders
3 *
4 * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
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 and
8 * only version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA.
19 */
20#ifndef __LINUX_I2C_SX150X_H
21#define __LINUX_I2C_SX150X_H
22
23/**
24 * struct sx150x_platform_data - config data for SX150x driver
25 * @gpio_base: The index number of the first GPIO assigned to this
26 * GPIO expander. The expander will create a block of
27 * consecutively numbered gpios beginning at the given base,
28 * with the size of the block depending on the model of the
29 * expander chip.
30 * @oscio_is_gpo: If set to true, the driver will configure OSCIO as a GPO
31 * instead of as an oscillator, increasing the size of the
32 * GP(I)O pool created by this expander by one. The
33 * output-only GPO pin will be added at the end of the block.
34 * @io_pullup_ena: A bit-mask which enables or disables the pull-up resistor
35 * for each IO line in the expander. Setting the bit at
36 * position n will enable the pull-up for the IO at
37 * the corresponding offset. For chips with fewer than
38 * 16 IO pins, high-end bits are ignored.
39 * @io_pulldn_ena: A bit-mask which enables-or disables the pull-down
40 * resistor for each IO line in the expander. Setting the
41 * bit at position n will enable the pull-down for the IO at
42 * the corresponding offset. For chips with fewer than
43 * 16 IO pins, high-end bits are ignored.
44 * @io_open_drain_ena: A bit-mask which enables-or disables open-drain
45 * operation for each IO line in the expander. Setting the
46 * bit at position n enables open-drain operation for
47 * the IO at the corresponding offset. Clearing the bit
48 * enables regular push-pull operation for that IO.
49 * For chips with fewer than 16 IO pins, high-end bits
50 * are ignored.
51 * @io_polarity: A bit-mask which enables polarity inversion for each IO line
52 * in the expander. Setting the bit at position n inverts
53 * the polarity of that IO line, while clearing it results
54 * in normal polarity. For chips with fewer than 16 IO pins,
55 * high-end bits are ignored.
56 * @irq_summary: The 'summary IRQ' line to which the GPIO expander's INT line
57 * is connected, via which it reports interrupt events
58 * across all GPIO lines. This must be a real,
59 * pre-existing IRQ line.
60 * Setting this value < 0 disables the irq_chip functionality
61 * of the driver.
62 * @irq_base: The first 'virtual IRQ' line at which our block of GPIO-based
63 * IRQ lines will appear. Similarly to gpio_base, the expander
64 * will create a block of irqs beginning at this number.
65 * This value is ignored if irq_summary is < 0.
66 */
67struct sx150x_platform_data {
68 unsigned gpio_base;
69 bool oscio_is_gpo;
70 u16 io_pullup_ena;
71 u16 io_pulldn_ena;
72 u16 io_open_drain_ena;
73 u16 io_polarity;
74 int irq_summary;
75 unsigned irq_base;
76};
77
78#endif /* __LINUX_I2C_SX150X_H */
diff --git a/include/linux/io-mapping.h b/include/linux/io-mapping.h
index e0ea40f6c515..0a6b3d5c490c 100644
--- a/include/linux/io-mapping.h
+++ b/include/linux/io-mapping.h
@@ -22,7 +22,6 @@
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <asm/io.h> 23#include <asm/io.h>
24#include <asm/page.h> 24#include <asm/page.h>
25#include <asm/iomap.h>
26 25
27/* 26/*
28 * The io_mapping mechanism provides an abstraction for mapping 27 * The io_mapping mechanism provides an abstraction for mapping
@@ -33,6 +32,8 @@
33 32
34#ifdef CONFIG_HAVE_ATOMIC_IOMAP 33#ifdef CONFIG_HAVE_ATOMIC_IOMAP
35 34
35#include <asm/iomap.h>
36
36struct io_mapping { 37struct io_mapping {
37 resource_size_t base; 38 resource_size_t base;
38 unsigned long size; 39 unsigned long size;
diff --git a/include/linux/jz4740-adc.h b/include/linux/jz4740-adc.h
new file mode 100644
index 000000000000..9053f95e9687
--- /dev/null
+++ b/include/linux/jz4740-adc.h
@@ -0,0 +1,32 @@
1
2#ifndef __LINUX_JZ4740_ADC
3#define __LINUX_JZ4740_ADC
4
5#include <linux/device.h>
6
7/*
8 * jz4740_adc_set_config - Configure a JZ4740 adc device
9 * @dev: Pointer to a jz4740-adc device
10 * @mask: Mask for the config value to be set
11 * @val: Value to be set
12 *
13 * This function can be used by the JZ4740 ADC mfd cells to configure their
14 * options in the shared config register.
15*/
16int jz4740_adc_set_config(struct device *dev, uint32_t mask, uint32_t val);
17
18#define JZ_ADC_CONFIG_SPZZ BIT(31)
19#define JZ_ADC_CONFIG_EX_IN BIT(30)
20#define JZ_ADC_CONFIG_DNUM_MASK (0x7 << 16)
21#define JZ_ADC_CONFIG_DMA_ENABLE BIT(15)
22#define JZ_ADC_CONFIG_XYZ_MASK (0x2 << 13)
23#define JZ_ADC_CONFIG_SAMPLE_NUM_MASK (0x7 << 10)
24#define JZ_ADC_CONFIG_CLKDIV_MASK (0xf << 5)
25#define JZ_ADC_CONFIG_BAT_MB BIT(4)
26
27#define JZ_ADC_CONFIG_DNUM(dnum) ((dnum) << 16)
28#define JZ_ADC_CONFIG_XYZ_OFFSET(dnum) ((xyz) << 13)
29#define JZ_ADC_CONFIG_SAMPLE_NUM(x) ((x) << 10)
30#define JZ_ADC_CONFIG_CLKDIV(div) ((div) << 5)
31
32#endif
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 5b57236dfbd0..2b0a35e6bc69 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -177,11 +177,12 @@ struct va_format {
177}; 177};
178 178
179extern struct atomic_notifier_head panic_notifier_list; 179extern struct atomic_notifier_head panic_notifier_list;
180extern long (*panic_blink)(long time); 180extern long (*panic_blink)(int state);
181NORET_TYPE void panic(const char * fmt, ...) 181NORET_TYPE void panic(const char * fmt, ...)
182 __attribute__ ((NORET_AND format (printf, 1, 2))) __cold; 182 __attribute__ ((NORET_AND format (printf, 1, 2))) __cold;
183extern void oops_enter(void); 183extern void oops_enter(void);
184extern void oops_exit(void); 184extern void oops_exit(void);
185void print_oops_end_marker(void);
185extern int oops_may_print(void); 186extern int oops_may_print(void);
186NORET_TYPE void do_exit(long error_code) 187NORET_TYPE void do_exit(long error_code)
187 ATTRIB_NORET; 188 ATTRIB_NORET;
@@ -305,6 +306,13 @@ static inline void log_buf_kexec_setup(void)
305} 306}
306#endif 307#endif
307 308
309/*
310 * Dummy printk for disabled debugging statements to use whilst maintaining
311 * gcc's format and side-effect checking.
312 */
313static inline __attribute__ ((format (printf, 1, 2)))
314int no_printk(const char *s, ...) { return 0; }
315
308extern int printk_needs_cpu(int cpu); 316extern int printk_needs_cpu(int cpu);
309extern void printk_tick(void); 317extern void printk_tick(void);
310 318
diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h
index 9fad0527344f..311f8753d713 100644
--- a/include/linux/kfifo.h
+++ b/include/linux/kfifo.h
@@ -1,8 +1,7 @@
1/* 1/*
2 * A generic kernel FIFO implementation. 2 * A generic kernel FIFO implementation
3 * 3 *
4 * Copyright (C) 2009 Stefani Seibold <stefani@seibold.net> 4 * Copyright (C) 2009/2010 Stefani Seibold <stefani@seibold.net>
5 * Copyright (C) 2004 Stelian Pop <stelian@popies.net>
6 * 5 *
7 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -20,8 +19,11 @@
20 * 19 *
21 */ 20 */
22 21
22#ifndef _LINUX_KFIFO_H
23#define _LINUX_KFIFO_H
24
23/* 25/*
24 * Howto porting drivers to the new generic fifo API: 26 * How to porting drivers to the new generic FIFO API:
25 * 27 *
26 * - Modify the declaration of the "struct kfifo *" object into a 28 * - Modify the declaration of the "struct kfifo *" object into a
27 * in-place "struct kfifo" object 29 * in-place "struct kfifo" object
@@ -30,586 +32,813 @@
30 * passed as the first argument to this functions 32 * passed as the first argument to this functions
31 * - Replace the use of __kfifo_put into kfifo_in and __kfifo_get 33 * - Replace the use of __kfifo_put into kfifo_in and __kfifo_get
32 * into kfifo_out 34 * into kfifo_out
33 * - Replace the use of kfifo_put into kfifo_in_locked and kfifo_get 35 * - Replace the use of kfifo_put into kfifo_in_spinlocked and kfifo_get
34 * into kfifo_out_locked 36 * into kfifo_out_spinlocked
35 * Note: the spinlock pointer formerly passed to kfifo_init/kfifo_alloc 37 * Note: the spinlock pointer formerly passed to kfifo_init/kfifo_alloc
36 * must be passed now to the kfifo_in_locked and kfifo_out_locked 38 * must be passed now to the kfifo_in_spinlocked and kfifo_out_spinlocked
37 * as the last parameter. 39 * as the last parameter
38 * - All formerly name __kfifo_* functions has been renamed into kfifo_* 40 * - The formerly __kfifo_* functions are renamed into kfifo_*
39 */ 41 */
40 42
41#ifndef _LINUX_KFIFO_H 43/*
42#define _LINUX_KFIFO_H 44 * Note about locking : There is no locking required until only * one reader
45 * and one writer is using the fifo and no kfifo_reset() will be * called
46 * kfifo_reset_out() can be safely used, until it will be only called
47 * in the reader thread.
48 * For multiple writer and one reader there is only a need to lock the writer.
49 * And vice versa for only one writer and multiple reader there is only a need
50 * to lock the reader.
51 */
43 52
44#include <linux/kernel.h> 53#include <linux/kernel.h>
45#include <linux/spinlock.h> 54#include <linux/spinlock.h>
46 55#include <linux/stddef.h>
47struct kfifo { 56#include <linux/scatterlist.h>
48 unsigned char *buffer; /* the buffer holding the data */ 57
49 unsigned int size; /* the size of the allocated buffer */ 58struct __kfifo {
50 unsigned int in; /* data is added at offset (in % size) */ 59 unsigned int in;
51 unsigned int out; /* data is extracted from off. (out % size) */ 60 unsigned int out;
61 unsigned int mask;
62 unsigned int esize;
63 void *data;
52}; 64};
53 65
54/* 66#define __STRUCT_KFIFO_COMMON(datatype, recsize, ptrtype) \
55 * Macros for declaration and initialization of the kfifo datatype 67 union { \
56 */ 68 struct __kfifo kfifo; \
57 69 datatype *type; \
58/* helper macro */ 70 char (*rectype)[recsize]; \
59#define __kfifo_initializer(s, b) \ 71 ptrtype *ptr; \
60 (struct kfifo) { \ 72 const ptrtype *ptr_const; \
61 .size = s, \
62 .in = 0, \
63 .out = 0, \
64 .buffer = b \
65 } 73 }
66 74
67/** 75#define __STRUCT_KFIFO(type, size, recsize, ptrtype) \
68 * DECLARE_KFIFO - macro to declare a kfifo and the associated buffer 76{ \
69 * @name: name of the declared kfifo datatype 77 __STRUCT_KFIFO_COMMON(type, recsize, ptrtype); \
70 * @size: size of the fifo buffer. Must be a power of two. 78 type buf[((size < 2) || (size & (size - 1))) ? -1 : size]; \
71 *
72 * Note1: the macro can be used inside struct or union declaration
73 * Note2: the macro creates two objects:
74 * A kfifo object with the given name and a buffer for the kfifo
75 * object named name##kfifo_buffer
76 */
77#define DECLARE_KFIFO(name, size) \
78union { \
79 struct kfifo name; \
80 unsigned char name##kfifo_buffer[size + sizeof(struct kfifo)]; \
81} 79}
82 80
83/** 81#define STRUCT_KFIFO(type, size) \
84 * INIT_KFIFO - Initialize a kfifo declared by DECLARE_KFIFO 82 struct __STRUCT_KFIFO(type, size, 0, type)
85 * @name: name of the declared kfifo datatype 83
84#define __STRUCT_KFIFO_PTR(type, recsize, ptrtype) \
85{ \
86 __STRUCT_KFIFO_COMMON(type, recsize, ptrtype); \
87 type buf[0]; \
88}
89
90#define STRUCT_KFIFO_PTR(type) \
91 struct __STRUCT_KFIFO_PTR(type, 0, type)
92
93/*
94 * define compatibility "struct kfifo" for dynamic allocated fifos
86 */ 95 */
87#define INIT_KFIFO(name) \ 96struct kfifo __STRUCT_KFIFO_PTR(unsigned char, 0, void);
88 name = __kfifo_initializer(sizeof(name##kfifo_buffer) - \
89 sizeof(struct kfifo), \
90 name##kfifo_buffer + sizeof(struct kfifo))
91 97
92/** 98#define STRUCT_KFIFO_REC_1(size) \
93 * DEFINE_KFIFO - macro to define and initialize a kfifo 99 struct __STRUCT_KFIFO(unsigned char, size, 1, void)
94 * @name: name of the declared kfifo datatype 100
95 * @size: size of the fifo buffer. Must be a power of two. 101#define STRUCT_KFIFO_REC_2(size) \
96 * 102 struct __STRUCT_KFIFO(unsigned char, size, 2, void)
97 * Note1: the macro can be used for global and local kfifo data type variables 103
98 * Note2: the macro creates two objects: 104/*
99 * A kfifo object with the given name and a buffer for the kfifo 105 * define kfifo_rec types
100 * object named name##kfifo_buffer
101 */ 106 */
102#define DEFINE_KFIFO(name, size) \ 107struct kfifo_rec_ptr_1 __STRUCT_KFIFO_PTR(unsigned char, 1, void);
103 unsigned char name##kfifo_buffer[size]; \ 108struct kfifo_rec_ptr_2 __STRUCT_KFIFO_PTR(unsigned char, 2, void);
104 struct kfifo name = __kfifo_initializer(size, name##kfifo_buffer)
105 109
106extern void kfifo_init(struct kfifo *fifo, void *buffer, 110/*
107 unsigned int size); 111 * helper macro to distinguish between real in place fifo where the fifo
108extern __must_check int kfifo_alloc(struct kfifo *fifo, unsigned int size, 112 * array is a part of the structure and the fifo type where the array is
109 gfp_t gfp_mask); 113 * outside of the fifo structure.
110extern void kfifo_free(struct kfifo *fifo); 114 */
111extern unsigned int kfifo_in(struct kfifo *fifo, 115#define __is_kfifo_ptr(fifo) (sizeof(*fifo) == sizeof(struct __kfifo))
112 const void *from, unsigned int len);
113extern __must_check unsigned int kfifo_out(struct kfifo *fifo,
114 void *to, unsigned int len);
115extern __must_check unsigned int kfifo_out_peek(struct kfifo *fifo,
116 void *to, unsigned int len, unsigned offset);
117 116
118/** 117/**
119 * kfifo_initialized - Check if kfifo is initialized. 118 * DECLARE_KFIFO_PTR - macro to declare a fifo pointer object
120 * @fifo: fifo to check 119 * @fifo: name of the declared fifo
121 * Return %true if FIFO is initialized, otherwise %false. 120 * @type: type of the fifo elements
122 * Assumes the fifo was 0 before.
123 */ 121 */
124static inline bool kfifo_initialized(struct kfifo *fifo) 122#define DECLARE_KFIFO_PTR(fifo, type) STRUCT_KFIFO_PTR(type) fifo
125{
126 return fifo->buffer != NULL;
127}
128 123
129/** 124/**
130 * kfifo_reset - removes the entire FIFO contents 125 * DECLARE_KFIFO - macro to declare a fifo object
131 * @fifo: the fifo to be emptied. 126 * @fifo: name of the declared fifo
127 * @type: type of the fifo elements
128 * @size: the number of elements in the fifo, this must be a power of 2
132 */ 129 */
133static inline void kfifo_reset(struct kfifo *fifo) 130#define DECLARE_KFIFO(fifo, type, size) STRUCT_KFIFO(type, size) fifo
134{
135 fifo->in = fifo->out = 0;
136}
137 131
138/** 132/**
139 * kfifo_reset_out - skip FIFO contents 133 * INIT_KFIFO - Initialize a fifo declared by DECLARE_KFIFO
140 * @fifo: the fifo to be emptied. 134 * @fifo: name of the declared fifo datatype
141 */ 135 */
142static inline void kfifo_reset_out(struct kfifo *fifo) 136#define INIT_KFIFO(fifo) \
143{ 137(void)({ \
144 smp_mb(); 138 typeof(&(fifo)) __tmp = &(fifo); \
145 fifo->out = fifo->in; 139 struct __kfifo *__kfifo = &__tmp->kfifo; \
146} 140 __kfifo->in = 0; \
141 __kfifo->out = 0; \
142 __kfifo->mask = __is_kfifo_ptr(__tmp) ? 0 : ARRAY_SIZE(__tmp->buf) - 1;\
143 __kfifo->esize = sizeof(*__tmp->buf); \
144 __kfifo->data = __is_kfifo_ptr(__tmp) ? NULL : __tmp->buf; \
145})
147 146
148/** 147/**
149 * kfifo_size - returns the size of the fifo in bytes 148 * DEFINE_KFIFO - macro to define and initialize a fifo
150 * @fifo: the fifo to be used. 149 * @fifo: name of the declared fifo datatype
151 */ 150 * @type: type of the fifo elements
152static inline __must_check unsigned int kfifo_size(struct kfifo *fifo) 151 * @size: the number of elements in the fifo, this must be a power of 2
152 *
153 * Note: the macro can be used for global and local fifo data type variables.
154 */
155#define DEFINE_KFIFO(fifo, type, size) \
156 DECLARE_KFIFO(fifo, type, size) = \
157 (typeof(fifo)) { \
158 { \
159 { \
160 .in = 0, \
161 .out = 0, \
162 .mask = __is_kfifo_ptr(&(fifo)) ? \
163 0 : \
164 ARRAY_SIZE((fifo).buf) - 1, \
165 .esize = sizeof(*(fifo).buf), \
166 .data = __is_kfifo_ptr(&(fifo)) ? \
167 NULL : \
168 (fifo).buf, \
169 } \
170 } \
171 }
172
173
174static inline unsigned int __must_check
175__kfifo_must_check_helper(unsigned int val)
153{ 176{
154 return fifo->size; 177 return val;
155} 178}
156 179
157/** 180/**
158 * kfifo_len - returns the number of used bytes in the FIFO 181 * kfifo_initialized - Check if the fifo is initialized
159 * @fifo: the fifo to be used. 182 * @fifo: address of the fifo to check
183 *
184 * Return %true if fifo is initialized, otherwise %false.
185 * Assumes the fifo was 0 before.
160 */ 186 */
161static inline unsigned int kfifo_len(struct kfifo *fifo) 187#define kfifo_initialized(fifo) ((fifo)->kfifo.mask)
162{
163 register unsigned int out;
164
165 out = fifo->out;
166 smp_rmb();
167 return fifo->in - out;
168}
169 188
170/** 189/**
171 * kfifo_is_empty - returns true if the fifo is empty 190 * kfifo_esize - returns the size of the element managed by the fifo
172 * @fifo: the fifo to be used. 191 * @fifo: address of the fifo to be used
173 */ 192 */
174static inline __must_check int kfifo_is_empty(struct kfifo *fifo) 193#define kfifo_esize(fifo) ((fifo)->kfifo.esize)
175{
176 return fifo->in == fifo->out;
177}
178 194
179/** 195/**
180 * kfifo_is_full - returns true if the fifo is full 196 * kfifo_recsize - returns the size of the record length field
181 * @fifo: the fifo to be used. 197 * @fifo: address of the fifo to be used
182 */ 198 */
183static inline __must_check int kfifo_is_full(struct kfifo *fifo) 199#define kfifo_recsize(fifo) (sizeof(*(fifo)->rectype))
184{
185 return kfifo_len(fifo) == kfifo_size(fifo);
186}
187 200
188/** 201/**
189 * kfifo_avail - returns the number of bytes available in the FIFO 202 * kfifo_size - returns the size of the fifo in elements
190 * @fifo: the fifo to be used. 203 * @fifo: address of the fifo to be used
191 */ 204 */
192static inline __must_check unsigned int kfifo_avail(struct kfifo *fifo) 205#define kfifo_size(fifo) ((fifo)->kfifo.mask + 1)
193{
194 return kfifo_size(fifo) - kfifo_len(fifo);
195}
196 206
197/** 207/**
198 * kfifo_in_locked - puts some data into the FIFO using a spinlock for locking 208 * kfifo_reset - removes the entire fifo content
199 * @fifo: the fifo to be used. 209 * @fifo: address of the fifo to be used
200 * @from: the data to be added.
201 * @n: the length of the data to be added.
202 * @lock: pointer to the spinlock to use for locking.
203 * 210 *
204 * This function copies at most @n bytes from the @from buffer into 211 * Note: usage of kfifo_reset() is dangerous. It should be only called when the
205 * the FIFO depending on the free space, and returns the number of 212 * fifo is exclusived locked or when it is secured that no other thread is
206 * bytes copied. 213 * accessing the fifo.
207 */ 214 */
208static inline unsigned int kfifo_in_locked(struct kfifo *fifo, 215#define kfifo_reset(fifo) \
209 const void *from, unsigned int n, spinlock_t *lock) 216(void)({ \
210{ 217 typeof(fifo + 1) __tmp = (fifo); \
211 unsigned long flags; 218 __tmp->kfifo.in = __tmp->kfifo.out = 0; \
212 unsigned int ret; 219})
213
214 spin_lock_irqsave(lock, flags);
215
216 ret = kfifo_in(fifo, from, n);
217
218 spin_unlock_irqrestore(lock, flags);
219
220 return ret;
221}
222 220
223/** 221/**
224 * kfifo_out_locked - gets some data from the FIFO using a spinlock for locking 222 * kfifo_reset_out - skip fifo content
225 * @fifo: the fifo to be used. 223 * @fifo: address of the fifo to be used
226 * @to: where the data must be copied.
227 * @n: the size of the destination buffer.
228 * @lock: pointer to the spinlock to use for locking.
229 * 224 *
230 * This function copies at most @n bytes from the FIFO into the 225 * Note: The usage of kfifo_reset_out() is safe until it will be only called
231 * @to buffer and returns the number of copied bytes. 226 * from the reader thread and there is only one concurrent reader. Otherwise
232 */ 227 * it is dangerous and must be handled in the same way as kfifo_reset().
233static inline __must_check unsigned int kfifo_out_locked(struct kfifo *fifo,
234 void *to, unsigned int n, spinlock_t *lock)
235{
236 unsigned long flags;
237 unsigned int ret;
238
239 spin_lock_irqsave(lock, flags);
240
241 ret = kfifo_out(fifo, to, n);
242
243 spin_unlock_irqrestore(lock, flags);
244
245 return ret;
246}
247
248extern void kfifo_skip(struct kfifo *fifo, unsigned int len);
249
250extern __must_check int kfifo_from_user(struct kfifo *fifo,
251 const void __user *from, unsigned int n, unsigned *lenout);
252
253extern __must_check int kfifo_to_user(struct kfifo *fifo,
254 void __user *to, unsigned int n, unsigned *lenout);
255
256/*
257 * __kfifo_add_out internal helper function for updating the out offset
258 */ 228 */
259static inline void __kfifo_add_out(struct kfifo *fifo, 229#define kfifo_reset_out(fifo) \
260 unsigned int off) 230(void)({ \
261{ 231 typeof(fifo + 1) __tmp = (fifo); \
262 smp_mb(); 232 __tmp->kfifo.out = __tmp->kfifo.in; \
263 fifo->out += off; 233})
264}
265 234
266/* 235/**
267 * __kfifo_add_in internal helper function for updating the in offset 236 * kfifo_len - returns the number of used elements in the fifo
237 * @fifo: address of the fifo to be used
268 */ 238 */
269static inline void __kfifo_add_in(struct kfifo *fifo, 239#define kfifo_len(fifo) \
270 unsigned int off) 240({ \
271{ 241 typeof(fifo + 1) __tmpl = (fifo); \
272 smp_wmb(); 242 __tmpl->kfifo.in - __tmpl->kfifo.out; \
273 fifo->in += off; 243})
274}
275 244
276/* 245/**
277 * __kfifo_off internal helper function for calculating the index of a 246 * kfifo_is_empty - returns true if the fifo is empty
278 * given offeset 247 * @fifo: address of the fifo to be used
279 */ 248 */
280static inline unsigned int __kfifo_off(struct kfifo *fifo, unsigned int off) 249#define kfifo_is_empty(fifo) \
281{ 250({ \
282 return off & (fifo->size - 1); 251 typeof(fifo + 1) __tmpq = (fifo); \
283} 252 __tmpq->kfifo.in == __tmpq->kfifo.out; \
253})
284 254
285/* 255/**
286 * __kfifo_peek_n internal helper function for determinate the length of 256 * kfifo_is_full - returns true if the fifo is full
287 * the next record in the fifo 257 * @fifo: address of the fifo to be used
288 */ 258 */
289static inline unsigned int __kfifo_peek_n(struct kfifo *fifo, 259#define kfifo_is_full(fifo) \
290 unsigned int recsize) 260({ \
291{ 261 typeof(fifo + 1) __tmpq = (fifo); \
292#define __KFIFO_GET(fifo, off, shift) \ 262 kfifo_len(__tmpq) > __tmpq->kfifo.mask; \
293 ((fifo)->buffer[__kfifo_off((fifo), (fifo)->out+(off))] << (shift)) 263})
294 264
295 unsigned int l; 265/**
266 * kfifo_avail - returns the number of unused elements in the fifo
267 * @fifo: address of the fifo to be used
268 */
269#define kfifo_avail(fifo) \
270__kfifo_must_check_helper( \
271({ \
272 typeof(fifo + 1) __tmpq = (fifo); \
273 const size_t __recsize = sizeof(*__tmpq->rectype); \
274 unsigned int __avail = kfifo_size(__tmpq) - kfifo_len(__tmpq); \
275 (__recsize) ? ((__avail <= __recsize) ? 0 : \
276 __kfifo_max_r(__avail - __recsize, __recsize)) : \
277 __avail; \
278}) \
279)
296 280
297 l = __KFIFO_GET(fifo, 0, 0); 281/**
282 * kfifo_skip - skip output data
283 * @fifo: address of the fifo to be used
284 */
285#define kfifo_skip(fifo) \
286(void)({ \
287 typeof(fifo + 1) __tmp = (fifo); \
288 const size_t __recsize = sizeof(*__tmp->rectype); \
289 struct __kfifo *__kfifo = &__tmp->kfifo; \
290 if (__recsize) \
291 __kfifo_skip_r(__kfifo, __recsize); \
292 else \
293 __kfifo->out++; \
294})
298 295
299 if (--recsize) 296/**
300 l |= __KFIFO_GET(fifo, 1, 8); 297 * kfifo_peek_len - gets the size of the next fifo record
298 * @fifo: address of the fifo to be used
299 *
300 * This function returns the size of the next fifo record in number of bytes.
301 */
302#define kfifo_peek_len(fifo) \
303__kfifo_must_check_helper( \
304({ \
305 typeof(fifo + 1) __tmp = (fifo); \
306 const size_t __recsize = sizeof(*__tmp->rectype); \
307 struct __kfifo *__kfifo = &__tmp->kfifo; \
308 (!__recsize) ? kfifo_len(__tmp) * sizeof(*__tmp->type) : \
309 __kfifo_len_r(__kfifo, __recsize); \
310}) \
311)
301 312
302 return l; 313/**
303#undef __KFIFO_GET 314 * kfifo_alloc - dynamically allocates a new fifo buffer
304} 315 * @fifo: pointer to the fifo
316 * @size: the number of elements in the fifo, this must be a power of 2
317 * @gfp_mask: get_free_pages mask, passed to kmalloc()
318 *
319 * This macro dynamically allocates a new fifo buffer.
320 *
321 * The numer of elements will be rounded-up to a power of 2.
322 * The fifo will be release with kfifo_free().
323 * Return 0 if no error, otherwise an error code.
324 */
325#define kfifo_alloc(fifo, size, gfp_mask) \
326__kfifo_must_check_helper( \
327({ \
328 typeof(fifo + 1) __tmp = (fifo); \
329 struct __kfifo *__kfifo = &__tmp->kfifo; \
330 __is_kfifo_ptr(__tmp) ? \
331 __kfifo_alloc(__kfifo, size, sizeof(*__tmp->type), gfp_mask) : \
332 -EINVAL; \
333}) \
334)
305 335
306/* 336/**
307 * __kfifo_poke_n internal helper function for storing the length of 337 * kfifo_free - frees the fifo
308 * the next record into the fifo 338 * @fifo: the fifo to be freed
309 */ 339 */
310static inline void __kfifo_poke_n(struct kfifo *fifo, 340#define kfifo_free(fifo) \
311 unsigned int recsize, unsigned int n) 341({ \
312{ 342 typeof(fifo + 1) __tmp = (fifo); \
313#define __KFIFO_PUT(fifo, off, val, shift) \ 343 struct __kfifo *__kfifo = &__tmp->kfifo; \
314 ( \ 344 if (__is_kfifo_ptr(__tmp)) \
315 (fifo)->buffer[__kfifo_off((fifo), (fifo)->in+(off))] = \ 345 __kfifo_free(__kfifo); \
316 (unsigned char)((val) >> (shift)) \ 346})
317 )
318 347
319 __KFIFO_PUT(fifo, 0, n, 0); 348/**
349 * kfifo_init - initialize a fifo using a preallocated buffer
350 * @fifo: the fifo to assign the buffer
351 * @buffer: the preallocated buffer to be used
352 * @size: the size of the internal buffer, this have to be a power of 2
353 *
354 * This macro initialize a fifo using a preallocated buffer.
355 *
356 * The numer of elements will be rounded-up to a power of 2.
357 * Return 0 if no error, otherwise an error code.
358 */
359#define kfifo_init(fifo, buffer, size) \
360({ \
361 typeof(fifo + 1) __tmp = (fifo); \
362 struct __kfifo *__kfifo = &__tmp->kfifo; \
363 __is_kfifo_ptr(__tmp) ? \
364 __kfifo_init(__kfifo, buffer, size, sizeof(*__tmp->type)) : \
365 -EINVAL; \
366})
320 367
321 if (--recsize) 368/**
322 __KFIFO_PUT(fifo, 1, n, 8); 369 * kfifo_put - put data into the fifo
323#undef __KFIFO_PUT 370 * @fifo: address of the fifo to be used
324} 371 * @val: the data to be added
372 *
373 * This macro copies the given value into the fifo.
374 * It returns 0 if the fifo was full. Otherwise it returns the number
375 * processed elements.
376 *
377 * Note that with only one concurrent reader and one concurrent
378 * writer, you don't need extra locking to use these macro.
379 */
380#define kfifo_put(fifo, val) \
381({ \
382 typeof(fifo + 1) __tmp = (fifo); \
383 typeof(val + 1) __val = (val); \
384 unsigned int __ret; \
385 const size_t __recsize = sizeof(*__tmp->rectype); \
386 struct __kfifo *__kfifo = &__tmp->kfifo; \
387 if (0) { \
388 typeof(__tmp->ptr_const) __dummy __attribute__ ((unused)); \
389 __dummy = (typeof(__val))NULL; \
390 } \
391 if (__recsize) \
392 __ret = __kfifo_in_r(__kfifo, __val, sizeof(*__val), \
393 __recsize); \
394 else { \
395 __ret = !kfifo_is_full(__tmp); \
396 if (__ret) { \
397 (__is_kfifo_ptr(__tmp) ? \
398 ((typeof(__tmp->type))__kfifo->data) : \
399 (__tmp->buf) \
400 )[__kfifo->in & __tmp->kfifo.mask] = \
401 *(typeof(__tmp->type))__val; \
402 smp_wmb(); \
403 __kfifo->in++; \
404 } \
405 } \
406 __ret; \
407})
325 408
326/* 409/**
327 * __kfifo_in_... internal functions for put date into the fifo 410 * kfifo_get - get data from the fifo
328 * do not call it directly, use kfifo_in_rec() instead 411 * @fifo: address of the fifo to be used
329 */ 412 * @val: the var where to store the data to be added
330extern unsigned int __kfifo_in_n(struct kfifo *fifo, 413 *
331 const void *from, unsigned int n, unsigned int recsize); 414 * This macro reads the data from the fifo.
415 * It returns 0 if the fifo was empty. Otherwise it returns the number
416 * processed elements.
417 *
418 * Note that with only one concurrent reader and one concurrent
419 * writer, you don't need extra locking to use these macro.
420 */
421#define kfifo_get(fifo, val) \
422__kfifo_must_check_helper( \
423({ \
424 typeof(fifo + 1) __tmp = (fifo); \
425 typeof(val + 1) __val = (val); \
426 unsigned int __ret; \
427 const size_t __recsize = sizeof(*__tmp->rectype); \
428 struct __kfifo *__kfifo = &__tmp->kfifo; \
429 if (0) \
430 __val = (typeof(__tmp->ptr))0; \
431 if (__recsize) \
432 __ret = __kfifo_out_r(__kfifo, __val, sizeof(*__val), \
433 __recsize); \
434 else { \
435 __ret = !kfifo_is_empty(__tmp); \
436 if (__ret) { \
437 *(typeof(__tmp->type))__val = \
438 (__is_kfifo_ptr(__tmp) ? \
439 ((typeof(__tmp->type))__kfifo->data) : \
440 (__tmp->buf) \
441 )[__kfifo->out & __tmp->kfifo.mask]; \
442 smp_wmb(); \
443 __kfifo->out++; \
444 } \
445 } \
446 __ret; \
447}) \
448)
332 449
333extern unsigned int __kfifo_in_generic(struct kfifo *fifo, 450/**
334 const void *from, unsigned int n, unsigned int recsize); 451 * kfifo_peek - get data from the fifo without removing
452 * @fifo: address of the fifo to be used
453 * @val: the var where to store the data to be added
454 *
455 * This reads the data from the fifo without removing it from the fifo.
456 * It returns 0 if the fifo was empty. Otherwise it returns the number
457 * processed elements.
458 *
459 * Note that with only one concurrent reader and one concurrent
460 * writer, you don't need extra locking to use these macro.
461 */
462#define kfifo_peek(fifo, val) \
463__kfifo_must_check_helper( \
464({ \
465 typeof(fifo + 1) __tmp = (fifo); \
466 typeof(val + 1) __val = (val); \
467 unsigned int __ret; \
468 const size_t __recsize = sizeof(*__tmp->rectype); \
469 struct __kfifo *__kfifo = &__tmp->kfifo; \
470 if (0) \
471 __val = (typeof(__tmp->ptr))NULL; \
472 if (__recsize) \
473 __ret = __kfifo_out_peek_r(__kfifo, __val, sizeof(*__val), \
474 __recsize); \
475 else { \
476 __ret = !kfifo_is_empty(__tmp); \
477 if (__ret) { \
478 *(typeof(__tmp->type))__val = \
479 (__is_kfifo_ptr(__tmp) ? \
480 ((typeof(__tmp->type))__kfifo->data) : \
481 (__tmp->buf) \
482 )[__kfifo->out & __tmp->kfifo.mask]; \
483 smp_wmb(); \
484 } \
485 } \
486 __ret; \
487}) \
488)
335 489
336static inline unsigned int __kfifo_in_rec(struct kfifo *fifo, 490/**
337 const void *from, unsigned int n, unsigned int recsize) 491 * kfifo_in - put data into the fifo
338{ 492 * @fifo: address of the fifo to be used
339 unsigned int ret; 493 * @buf: the data to be added
494 * @n: number of elements to be added
495 *
496 * This macro copies the given buffer into the fifo and returns the
497 * number of copied elements.
498 *
499 * Note that with only one concurrent reader and one concurrent
500 * writer, you don't need extra locking to use these macro.
501 */
502#define kfifo_in(fifo, buf, n) \
503({ \
504 typeof(fifo + 1) __tmp = (fifo); \
505 typeof(buf + 1) __buf = (buf); \
506 unsigned long __n = (n); \
507 const size_t __recsize = sizeof(*__tmp->rectype); \
508 struct __kfifo *__kfifo = &__tmp->kfifo; \
509 if (0) { \
510 typeof(__tmp->ptr_const) __dummy __attribute__ ((unused)); \
511 __dummy = (typeof(__buf))NULL; \
512 } \
513 (__recsize) ?\
514 __kfifo_in_r(__kfifo, __buf, __n, __recsize) : \
515 __kfifo_in(__kfifo, __buf, __n); \
516})
340 517
341 ret = __kfifo_in_n(fifo, from, n, recsize); 518/**
519 * kfifo_in_spinlocked - put data into the fifo using a spinlock for locking
520 * @fifo: address of the fifo to be used
521 * @buf: the data to be added
522 * @n: number of elements to be added
523 * @lock: pointer to the spinlock to use for locking
524 *
525 * This macro copies the given values buffer into the fifo and returns the
526 * number of copied elements.
527 */
528#define kfifo_in_spinlocked(fifo, buf, n, lock) \
529({ \
530 unsigned long __flags; \
531 unsigned int __ret; \
532 spin_lock_irqsave(lock, __flags); \
533 __ret = kfifo_in(fifo, buf, n); \
534 spin_unlock_irqrestore(lock, __flags); \
535 __ret; \
536})
537
538/* alias for kfifo_in_spinlocked, will be removed in a future release */
539#define kfifo_in_locked(fifo, buf, n, lock) \
540 kfifo_in_spinlocked(fifo, buf, n, lock)
342 541
343 if (likely(ret == 0)) { 542/**
344 if (recsize) 543 * kfifo_out - get data from the fifo
345 __kfifo_poke_n(fifo, recsize, n); 544 * @fifo: address of the fifo to be used
346 __kfifo_add_in(fifo, n + recsize); 545 * @buf: pointer to the storage buffer
347 } 546 * @n: max. number of elements to get
348 return ret; 547 *
349} 548 * This macro get some data from the fifo and return the numbers of elements
549 * copied.
550 *
551 * Note that with only one concurrent reader and one concurrent
552 * writer, you don't need extra locking to use these macro.
553 */
554#define kfifo_out(fifo, buf, n) \
555__kfifo_must_check_helper( \
556({ \
557 typeof(fifo + 1) __tmp = (fifo); \
558 typeof(buf + 1) __buf = (buf); \
559 unsigned long __n = (n); \
560 const size_t __recsize = sizeof(*__tmp->rectype); \
561 struct __kfifo *__kfifo = &__tmp->kfifo; \
562 if (0) { \
563 typeof(__tmp->ptr) __dummy = NULL; \
564 __buf = __dummy; \
565 } \
566 (__recsize) ?\
567 __kfifo_out_r(__kfifo, __buf, __n, __recsize) : \
568 __kfifo_out(__kfifo, __buf, __n); \
569}) \
570)
571
572/**
573 * kfifo_out_spinlocked - get data from the fifo using a spinlock for locking
574 * @fifo: address of the fifo to be used
575 * @buf: pointer to the storage buffer
576 * @n: max. number of elements to get
577 * @lock: pointer to the spinlock to use for locking
578 *
579 * This macro get the data from the fifo and return the numbers of elements
580 * copied.
581 */
582#define kfifo_out_spinlocked(fifo, buf, n, lock) \
583__kfifo_must_check_helper( \
584({ \
585 unsigned long __flags; \
586 unsigned int __ret; \
587 spin_lock_irqsave(lock, __flags); \
588 __ret = kfifo_out(fifo, buf, n); \
589 spin_unlock_irqrestore(lock, __flags); \
590 __ret; \
591}) \
592)
593
594/* alias for kfifo_out_spinlocked, will be removed in a future release */
595#define kfifo_out_locked(fifo, buf, n, lock) \
596 kfifo_out_spinlocked(fifo, buf, n, lock)
350 597
351/** 598/**
352 * kfifo_in_rec - puts some record data into the FIFO 599 * kfifo_from_user - puts some data from user space into the fifo
353 * @fifo: the fifo to be used. 600 * @fifo: address of the fifo to be used
354 * @from: the data to be added. 601 * @from: pointer to the data to be added
355 * @n: the length of the data to be added. 602 * @len: the length of the data to be added
356 * @recsize: size of record field 603 * @copied: pointer to output variable to store the number of copied bytes
357 * 604 *
358 * This function copies @n bytes from the @from into the FIFO and returns 605 * This macro copies at most @len bytes from the @from into the
359 * the number of bytes which cannot be copied. 606 * fifo, depending of the available space and returns -EFAULT/0.
360 * A returned value greater than the @n value means that the record doesn't
361 * fit into the buffer.
362 * 607 *
363 * Note that with only one concurrent reader and one concurrent 608 * Note that with only one concurrent reader and one concurrent
364 * writer, you don't need extra locking to use these functions. 609 * writer, you don't need extra locking to use these macro.
365 */ 610 */
366static inline __must_check unsigned int kfifo_in_rec(struct kfifo *fifo, 611#define kfifo_from_user(fifo, from, len, copied) \
367 void *from, unsigned int n, unsigned int recsize) 612__kfifo_must_check_helper( \
368{ 613({ \
369 if (!__builtin_constant_p(recsize)) 614 typeof(fifo + 1) __tmp = (fifo); \
370 return __kfifo_in_generic(fifo, from, n, recsize); 615 const void __user *__from = (from); \
371 return __kfifo_in_rec(fifo, from, n, recsize); 616 unsigned int __len = (len); \
372} 617 unsigned int *__copied = (copied); \
618 const size_t __recsize = sizeof(*__tmp->rectype); \
619 struct __kfifo *__kfifo = &__tmp->kfifo; \
620 (__recsize) ? \
621 __kfifo_from_user_r(__kfifo, __from, __len, __copied, __recsize) : \
622 __kfifo_from_user(__kfifo, __from, __len, __copied); \
623}) \
624)
373 625
374/* 626/**
375 * __kfifo_out_... internal functions for get date from the fifo 627 * kfifo_to_user - copies data from the fifo into user space
376 * do not call it directly, use kfifo_out_rec() instead 628 * @fifo: address of the fifo to be used
377 */ 629 * @to: where the data must be copied
378extern unsigned int __kfifo_out_n(struct kfifo *fifo, 630 * @len: the size of the destination buffer
379 void *to, unsigned int reclen, unsigned int recsize); 631 * @copied: pointer to output variable to store the number of copied bytes
632 *
633 * This macro copies at most @len bytes from the fifo into the
634 * @to buffer and returns -EFAULT/0.
635 *
636 * Note that with only one concurrent reader and one concurrent
637 * writer, you don't need extra locking to use these macro.
638 */
639#define kfifo_to_user(fifo, to, len, copied) \
640__kfifo_must_check_helper( \
641({ \
642 typeof(fifo + 1) __tmp = (fifo); \
643 void __user *__to = (to); \
644 unsigned int __len = (len); \
645 unsigned int *__copied = (copied); \
646 const size_t __recsize = sizeof(*__tmp->rectype); \
647 struct __kfifo *__kfifo = &__tmp->kfifo; \
648 (__recsize) ? \
649 __kfifo_to_user_r(__kfifo, __to, __len, __copied, __recsize) : \
650 __kfifo_to_user(__kfifo, __to, __len, __copied); \
651}) \
652)
653
654/**
655 * kfifo_dma_in_prepare - setup a scatterlist for DMA input
656 * @fifo: address of the fifo to be used
657 * @sgl: pointer to the scatterlist array
658 * @nents: number of entries in the scatterlist array
659 * @len: number of elements to transfer
660 *
661 * This macro fills a scatterlist for DMA input.
662 * It returns the number entries in the scatterlist array.
663 *
664 * Note that with only one concurrent reader and one concurrent
665 * writer, you don't need extra locking to use these macros.
666 */
667#define kfifo_dma_in_prepare(fifo, sgl, nents, len) \
668({ \
669 typeof(fifo + 1) __tmp = (fifo); \
670 struct scatterlist *__sgl = (sgl); \
671 int __nents = (nents); \
672 unsigned int __len = (len); \
673 const size_t __recsize = sizeof(*__tmp->rectype); \
674 struct __kfifo *__kfifo = &__tmp->kfifo; \
675 (__recsize) ? \
676 __kfifo_dma_in_prepare_r(__kfifo, __sgl, __nents, __len, __recsize) : \
677 __kfifo_dma_in_prepare(__kfifo, __sgl, __nents, __len); \
678})
380 679
381extern unsigned int __kfifo_out_generic(struct kfifo *fifo, 680/**
382 void *to, unsigned int n, 681 * kfifo_dma_in_finish - finish a DMA IN operation
383 unsigned int recsize, unsigned int *total); 682 * @fifo: address of the fifo to be used
683 * @len: number of bytes to received
684 *
685 * This macro finish a DMA IN operation. The in counter will be updated by
686 * the len parameter. No error checking will be done.
687 *
688 * Note that with only one concurrent reader and one concurrent
689 * writer, you don't need extra locking to use these macros.
690 */
691#define kfifo_dma_in_finish(fifo, len) \
692(void)({ \
693 typeof(fifo + 1) __tmp = (fifo); \
694 unsigned int __len = (len); \
695 const size_t __recsize = sizeof(*__tmp->rectype); \
696 struct __kfifo *__kfifo = &__tmp->kfifo; \
697 if (__recsize) \
698 __kfifo_dma_in_finish_r(__kfifo, __len, __recsize); \
699 else \
700 __kfifo->in += __len / sizeof(*__tmp->type); \
701})
384 702
385static inline unsigned int __kfifo_out_rec(struct kfifo *fifo, 703/**
386 void *to, unsigned int n, unsigned int recsize, 704 * kfifo_dma_out_prepare - setup a scatterlist for DMA output
387 unsigned int *total) 705 * @fifo: address of the fifo to be used
388{ 706 * @sgl: pointer to the scatterlist array
389 unsigned int l; 707 * @nents: number of entries in the scatterlist array
390 708 * @len: number of elements to transfer
391 if (!recsize) { 709 *
392 l = n; 710 * This macro fills a scatterlist for DMA output which at most @len bytes
393 if (total) 711 * to transfer.
394 *total = l; 712 * It returns the number entries in the scatterlist array.
395 } else { 713 * A zero means there is no space available and the scatterlist is not filled.
396 l = __kfifo_peek_n(fifo, recsize); 714 *
397 if (total) 715 * Note that with only one concurrent reader and one concurrent
398 *total = l; 716 * writer, you don't need extra locking to use these macros.
399 if (n < l) 717 */
400 return l; 718#define kfifo_dma_out_prepare(fifo, sgl, nents, len) \
401 } 719({ \
720 typeof(fifo + 1) __tmp = (fifo); \
721 struct scatterlist *__sgl = (sgl); \
722 int __nents = (nents); \
723 unsigned int __len = (len); \
724 const size_t __recsize = sizeof(*__tmp->rectype); \
725 struct __kfifo *__kfifo = &__tmp->kfifo; \
726 (__recsize) ? \
727 __kfifo_dma_out_prepare_r(__kfifo, __sgl, __nents, __len, __recsize) : \
728 __kfifo_dma_out_prepare(__kfifo, __sgl, __nents, __len); \
729})
402 730
403 return __kfifo_out_n(fifo, to, l, recsize); 731/**
404} 732 * kfifo_dma_out_finish - finish a DMA OUT operation
733 * @fifo: address of the fifo to be used
734 * @len: number of bytes transferd
735 *
736 * This macro finish a DMA OUT operation. The out counter will be updated by
737 * the len parameter. No error checking will be done.
738 *
739 * Note that with only one concurrent reader and one concurrent
740 * writer, you don't need extra locking to use these macros.
741 */
742#define kfifo_dma_out_finish(fifo, len) \
743(void)({ \
744 typeof(fifo + 1) __tmp = (fifo); \
745 unsigned int __len = (len); \
746 const size_t __recsize = sizeof(*__tmp->rectype); \
747 struct __kfifo *__kfifo = &__tmp->kfifo; \
748 if (__recsize) \
749 __kfifo_dma_out_finish_r(__kfifo, __recsize); \
750 else \
751 __kfifo->out += __len / sizeof(*__tmp->type); \
752})
405 753
406/** 754/**
407 * kfifo_out_rec - gets some record data from the FIFO 755 * kfifo_out_peek - gets some data from the fifo
408 * @fifo: the fifo to be used. 756 * @fifo: address of the fifo to be used
409 * @to: where the data must be copied. 757 * @buf: pointer to the storage buffer
410 * @n: the size of the destination buffer. 758 * @n: max. number of elements to get
411 * @recsize: size of record field
412 * @total: pointer where the total number of to copied bytes should stored
413 * 759 *
414 * This function copies at most @n bytes from the FIFO to @to and returns the 760 * This macro get the data from the fifo and return the numbers of elements
415 * number of bytes which cannot be copied. 761 * copied. The data is not removed from the fifo.
416 * A returned value greater than the @n value means that the record doesn't
417 * fit into the @to buffer.
418 * 762 *
419 * Note that with only one concurrent reader and one concurrent 763 * Note that with only one concurrent reader and one concurrent
420 * writer, you don't need extra locking to use these functions. 764 * writer, you don't need extra locking to use these macro.
421 */ 765 */
422static inline __must_check unsigned int kfifo_out_rec(struct kfifo *fifo, 766#define kfifo_out_peek(fifo, buf, n) \
423 void *to, unsigned int n, unsigned int recsize, 767__kfifo_must_check_helper( \
424 unsigned int *total) 768({ \
769 typeof(fifo + 1) __tmp = (fifo); \
770 typeof(buf + 1) __buf = (buf); \
771 unsigned long __n = (n); \
772 const size_t __recsize = sizeof(*__tmp->rectype); \
773 struct __kfifo *__kfifo = &__tmp->kfifo; \
774 if (0) { \
775 typeof(__tmp->ptr) __dummy __attribute__ ((unused)) = NULL; \
776 __buf = __dummy; \
777 } \
778 (__recsize) ? \
779 __kfifo_out_peek_r(__kfifo, __buf, __n, __recsize) : \
780 __kfifo_out_peek(__kfifo, __buf, __n); \
781}) \
782)
425 783
426{ 784extern int __kfifo_alloc(struct __kfifo *fifo, unsigned int size,
427 if (!__builtin_constant_p(recsize)) 785 size_t esize, gfp_t gfp_mask);
428 return __kfifo_out_generic(fifo, to, n, recsize, total);
429 return __kfifo_out_rec(fifo, to, n, recsize, total);
430}
431 786
432/* 787extern void __kfifo_free(struct __kfifo *fifo);
433 * __kfifo_from_user_... internal functions for transfer from user space into
434 * the fifo. do not call it directly, use kfifo_from_user_rec() instead
435 */
436extern unsigned int __kfifo_from_user_n(struct kfifo *fifo,
437 const void __user *from, unsigned int n, unsigned int recsize);
438 788
439extern unsigned int __kfifo_from_user_generic(struct kfifo *fifo, 789extern int __kfifo_init(struct __kfifo *fifo, void *buffer,
440 const void __user *from, unsigned int n, unsigned int recsize); 790 unsigned int size, size_t esize);
441 791
442static inline unsigned int __kfifo_from_user_rec(struct kfifo *fifo, 792extern unsigned int __kfifo_in(struct __kfifo *fifo,
443 const void __user *from, unsigned int n, unsigned int recsize) 793 const void *buf, unsigned int len);
444{
445 unsigned int ret;
446 794
447 ret = __kfifo_from_user_n(fifo, from, n, recsize); 795extern unsigned int __kfifo_out(struct __kfifo *fifo,
796 void *buf, unsigned int len);
448 797
449 if (likely(ret == 0)) { 798extern int __kfifo_from_user(struct __kfifo *fifo,
450 if (recsize) 799 const void __user *from, unsigned long len, unsigned int *copied);
451 __kfifo_poke_n(fifo, recsize, n);
452 __kfifo_add_in(fifo, n + recsize);
453 }
454 return ret;
455}
456 800
457/** 801extern int __kfifo_to_user(struct __kfifo *fifo,
458 * kfifo_from_user_rec - puts some data from user space into the FIFO 802 void __user *to, unsigned long len, unsigned int *copied);
459 * @fifo: the fifo to be used.
460 * @from: pointer to the data to be added.
461 * @n: the length of the data to be added.
462 * @recsize: size of record field
463 *
464 * This function copies @n bytes from the @from into the
465 * FIFO and returns the number of bytes which cannot be copied.
466 *
467 * If the returned value is equal or less the @n value, the copy_from_user()
468 * functions has failed. Otherwise the record doesn't fit into the buffer.
469 *
470 * Note that with only one concurrent reader and one concurrent
471 * writer, you don't need extra locking to use these functions.
472 */
473static inline __must_check unsigned int kfifo_from_user_rec(struct kfifo *fifo,
474 const void __user *from, unsigned int n, unsigned int recsize)
475{
476 if (!__builtin_constant_p(recsize))
477 return __kfifo_from_user_generic(fifo, from, n, recsize);
478 return __kfifo_from_user_rec(fifo, from, n, recsize);
479}
480 803
481/* 804extern unsigned int __kfifo_dma_in_prepare(struct __kfifo *fifo,
482 * __kfifo_to_user_... internal functions for transfer fifo data into user space 805 struct scatterlist *sgl, int nents, unsigned int len);
483 * do not call it directly, use kfifo_to_user_rec() instead
484 */
485extern unsigned int __kfifo_to_user_n(struct kfifo *fifo,
486 void __user *to, unsigned int n, unsigned int reclen,
487 unsigned int recsize);
488 806
489extern unsigned int __kfifo_to_user_generic(struct kfifo *fifo, 807extern unsigned int __kfifo_dma_out_prepare(struct __kfifo *fifo,
490 void __user *to, unsigned int n, unsigned int recsize, 808 struct scatterlist *sgl, int nents, unsigned int len);
491 unsigned int *total);
492 809
493static inline unsigned int __kfifo_to_user_rec(struct kfifo *fifo, 810extern unsigned int __kfifo_out_peek(struct __kfifo *fifo,
494 void __user *to, unsigned int n, 811 void *buf, unsigned int len);
495 unsigned int recsize, unsigned int *total)
496{
497 unsigned int l;
498
499 if (!recsize) {
500 l = n;
501 if (total)
502 *total = l;
503 } else {
504 l = __kfifo_peek_n(fifo, recsize);
505 if (total)
506 *total = l;
507 if (n < l)
508 return l;
509 }
510 812
511 return __kfifo_to_user_n(fifo, to, n, l, recsize); 813extern unsigned int __kfifo_in_r(struct __kfifo *fifo,
512} 814 const void *buf, unsigned int len, size_t recsize);
513 815
514/** 816extern unsigned int __kfifo_out_r(struct __kfifo *fifo,
515 * kfifo_to_user_rec - gets data from the FIFO and write it to user space 817 void *buf, unsigned int len, size_t recsize);
516 * @fifo: the fifo to be used.
517 * @to: where the data must be copied.
518 * @n: the size of the destination buffer.
519 * @recsize: size of record field
520 * @total: pointer where the total number of to copied bytes should stored
521 *
522 * This function copies at most @n bytes from the FIFO to the @to.
523 * In case of an error, the function returns the number of bytes which cannot
524 * be copied.
525 * If the returned value is equal or less the @n value, the copy_to_user()
526 * functions has failed. Otherwise the record doesn't fit into the @to buffer.
527 *
528 * Note that with only one concurrent reader and one concurrent
529 * writer, you don't need extra locking to use these functions.
530 */
531static inline __must_check unsigned int kfifo_to_user_rec(struct kfifo *fifo,
532 void __user *to, unsigned int n, unsigned int recsize,
533 unsigned int *total)
534{
535 if (!__builtin_constant_p(recsize))
536 return __kfifo_to_user_generic(fifo, to, n, recsize, total);
537 return __kfifo_to_user_rec(fifo, to, n, recsize, total);
538}
539 818
540/* 819extern int __kfifo_from_user_r(struct __kfifo *fifo,
541 * __kfifo_peek_... internal functions for peek into the next fifo record 820 const void __user *from, unsigned long len, unsigned int *copied,
542 * do not call it directly, use kfifo_peek_rec() instead 821 size_t recsize);
543 */
544extern unsigned int __kfifo_peek_generic(struct kfifo *fifo,
545 unsigned int recsize);
546 822
547/** 823extern int __kfifo_to_user_r(struct __kfifo *fifo, void __user *to,
548 * kfifo_peek_rec - gets the size of the next FIFO record data 824 unsigned long len, unsigned int *copied, size_t recsize);
549 * @fifo: the fifo to be used.
550 * @recsize: size of record field
551 *
552 * This function returns the size of the next FIFO record in number of bytes
553 */
554static inline __must_check unsigned int kfifo_peek_rec(struct kfifo *fifo,
555 unsigned int recsize)
556{
557 if (!__builtin_constant_p(recsize))
558 return __kfifo_peek_generic(fifo, recsize);
559 if (!recsize)
560 return kfifo_len(fifo);
561 return __kfifo_peek_n(fifo, recsize);
562}
563 825
564/* 826extern unsigned int __kfifo_dma_in_prepare_r(struct __kfifo *fifo,
565 * __kfifo_skip_... internal functions for skip the next fifo record 827 struct scatterlist *sgl, int nents, unsigned int len, size_t recsize);
566 * do not call it directly, use kfifo_skip_rec() instead
567 */
568extern void __kfifo_skip_generic(struct kfifo *fifo, unsigned int recsize);
569 828
570static inline void __kfifo_skip_rec(struct kfifo *fifo, 829extern void __kfifo_dma_in_finish_r(struct __kfifo *fifo,
571 unsigned int recsize) 830 unsigned int len, size_t recsize);
572{
573 unsigned int l;
574 831
575 if (recsize) { 832extern unsigned int __kfifo_dma_out_prepare_r(struct __kfifo *fifo,
576 l = __kfifo_peek_n(fifo, recsize); 833 struct scatterlist *sgl, int nents, unsigned int len, size_t recsize);
577 834
578 if (l + recsize <= kfifo_len(fifo)) { 835extern void __kfifo_dma_out_finish_r(struct __kfifo *fifo, size_t recsize);
579 __kfifo_add_out(fifo, l + recsize);
580 return;
581 }
582 }
583 kfifo_reset_out(fifo);
584}
585 836
586/** 837extern unsigned int __kfifo_len_r(struct __kfifo *fifo, size_t recsize);
587 * kfifo_skip_rec - skip the next fifo out record
588 * @fifo: the fifo to be used.
589 * @recsize: size of record field
590 *
591 * This function skips the next FIFO record
592 */
593static inline void kfifo_skip_rec(struct kfifo *fifo,
594 unsigned int recsize)
595{
596 if (!__builtin_constant_p(recsize))
597 __kfifo_skip_generic(fifo, recsize);
598 else
599 __kfifo_skip_rec(fifo, recsize);
600}
601 838
602/** 839extern unsigned int __kfifo_out_peek_r(struct __kfifo *fifo,
603 * kfifo_avail_rec - returns the number of bytes available in a record FIFO 840 void *buf, unsigned int len, size_t recsize);
604 * @fifo: the fifo to be used.
605 * @recsize: size of record field
606 */
607static inline __must_check unsigned int kfifo_avail_rec(struct kfifo *fifo,
608 unsigned int recsize)
609{
610 unsigned int l = kfifo_size(fifo) - kfifo_len(fifo);
611 841
612 return (l > recsize) ? l - recsize : 0; 842extern unsigned int __kfifo_max_r(unsigned int len, size_t recsize);
613}
614 843
615#endif 844#endif
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 73564cac38c7..159a0762aeaf 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -123,8 +123,7 @@ static inline bool mem_cgroup_disabled(void)
123 123
124void mem_cgroup_update_file_mapped(struct page *page, int val); 124void mem_cgroup_update_file_mapped(struct page *page, int val);
125unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, 125unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
126 gfp_t gfp_mask, int nid, 126 gfp_t gfp_mask);
127 int zid);
128u64 mem_cgroup_get_limit(struct mem_cgroup *mem); 127u64 mem_cgroup_get_limit(struct mem_cgroup *mem);
129 128
130#else /* CONFIG_CGROUP_MEM_RES_CTLR */ 129#else /* CONFIG_CGROUP_MEM_RES_CTLR */
@@ -301,7 +300,7 @@ static inline void mem_cgroup_update_file_mapped(struct page *page,
301 300
302static inline 301static inline
303unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, 302unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
304 gfp_t gfp_mask, int nid, int zid) 303 gfp_t gfp_mask)
305{ 304{
306 return 0; 305 return 0;
307} 306}
diff --git a/include/linux/mfd/ab8500.h b/include/linux/mfd/ab8500.h
index b63ff3ba3351..f5cec4500f38 100644
--- a/include/linux/mfd/ab8500.h
+++ b/include/linux/mfd/ab8500.h
@@ -76,6 +76,8 @@
76#define AB8500_NR_IRQS 104 76#define AB8500_NR_IRQS 104
77#define AB8500_NUM_IRQ_REGS 13 77#define AB8500_NUM_IRQ_REGS 13
78 78
79#define AB8500_NUM_REGULATORS 15
80
79/** 81/**
80 * struct ab8500 - ab8500 internal structure 82 * struct ab8500 - ab8500 internal structure
81 * @dev: parent device 83 * @dev: parent device
@@ -108,14 +110,18 @@ struct ab8500 {
108 u8 oldmask[AB8500_NUM_IRQ_REGS]; 110 u8 oldmask[AB8500_NUM_IRQ_REGS];
109}; 111};
110 112
113struct regulator_init_data;
114
111/** 115/**
112 * struct ab8500_platform_data - AB8500 platform data 116 * struct ab8500_platform_data - AB8500 platform data
113 * @irq_base: start of AB8500 IRQs, AB8500_NR_IRQS will be used 117 * @irq_base: start of AB8500 IRQs, AB8500_NR_IRQS will be used
114 * @init: board-specific initialization after detection of ab8500 118 * @init: board-specific initialization after detection of ab8500
119 * @regulator: machine-specific constraints for regulators
115 */ 120 */
116struct ab8500_platform_data { 121struct ab8500_platform_data {
117 int irq_base; 122 int irq_base;
118 void (*init) (struct ab8500 *); 123 void (*init) (struct ab8500 *);
124 struct regulator_init_data *regulator[AB8500_NUM_REGULATORS];
119}; 125};
120 126
121extern int ab8500_write(struct ab8500 *a8500, u16 addr, u8 data); 127extern int ab8500_write(struct ab8500 *a8500, u16 addr, u8 data);
diff --git a/include/linux/mfd/max8998-private.h b/include/linux/mfd/max8998-private.h
new file mode 100644
index 000000000000..6dc75b3e2d33
--- /dev/null
+++ b/include/linux/mfd/max8998-private.h
@@ -0,0 +1,112 @@
1/*
2 * max8698.h - Voltage regulator driver for the Maxim 8998
3 *
4 * Copyright (C) 2009-2010 Samsung Electrnoics
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 * Marek Szyprowski <m.szyprowski@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
23#ifndef __LINUX_MFD_MAX8998_PRIV_H
24#define __LINUX_MFD_MAX8998_PRIV_H
25
26/* MAX 8998 registers */
27enum {
28 MAX8998_REG_IRQ1,
29 MAX8998_REG_IRQ2,
30 MAX8998_REG_IRQ3,
31 MAX8998_REG_IRQ4,
32 MAX8998_REG_IRQM1,
33 MAX8998_REG_IRQM2,
34 MAX8998_REG_IRQM3,
35 MAX8998_REG_IRQM4,
36 MAX8998_REG_STATUS1,
37 MAX8998_REG_STATUS2,
38 MAX8998_REG_STATUSM1,
39 MAX8998_REG_STATUSM2,
40 MAX8998_REG_CHGR1,
41 MAX8998_REG_CHGR2,
42 MAX8998_REG_LDO_ACTIVE_DISCHARGE1,
43 MAX8998_REG_LDO_ACTIVE_DISCHARGE2,
44 MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
45 MAX8998_REG_ONOFF1,
46 MAX8998_REG_ONOFF2,
47 MAX8998_REG_ONOFF3,
48 MAX8998_REG_ONOFF4,
49 MAX8998_REG_BUCK1_DVSARM1,
50 MAX8998_REG_BUCK1_DVSARM2,
51 MAX8998_REG_BUCK1_DVSARM3,
52 MAX8998_REG_BUCK1_DVSARM4,
53 MAX8998_REG_BUCK2_DVSINT1,
54 MAX8998_REG_BUCK2_DVSINT2,
55 MAX8998_REG_BUCK3,
56 MAX8998_REG_BUCK4,
57 MAX8998_REG_LDO2_LDO3,
58 MAX8998_REG_LDO4,
59 MAX8998_REG_LDO5,
60 MAX8998_REG_LDO6,
61 MAX8998_REG_LDO7,
62 MAX8998_REG_LDO8_LDO9,
63 MAX8998_REG_LDO10_LDO11,
64 MAX8998_REG_LDO12,
65 MAX8998_REG_LDO13,
66 MAX8998_REG_LDO14,
67 MAX8998_REG_LDO15,
68 MAX8998_REG_LDO16,
69 MAX8998_REG_LDO17,
70 MAX8998_REG_BKCHR,
71 MAX8998_REG_LBCNFG1,
72 MAX8998_REG_LBCNFG2,
73};
74
75/**
76 * struct max8998_dev - max8998 master device for sub-drivers
77 * @dev: master device of the chip (can be used to access platform data)
78 * @i2c_client: i2c client private data
79 * @dev_read(): chip register read function
80 * @dev_write(): chip register write function
81 * @dev_update(): chip register update function
82 * @iolock: mutex for serializing io access
83 */
84
85struct max8998_dev {
86 struct device *dev;
87 struct i2c_client *i2c_client;
88 int (*dev_read)(struct max8998_dev *max8998, u8 reg, u8 *dest);
89 int (*dev_write)(struct max8998_dev *max8998, u8 reg, u8 val);
90 int (*dev_update)(struct max8998_dev *max8998, u8 reg, u8 val, u8 mask);
91 struct mutex iolock;
92};
93
94static inline int max8998_read_reg(struct max8998_dev *max8998, u8 reg,
95 u8 *value)
96{
97 return max8998->dev_read(max8998, reg, value);
98}
99
100static inline int max8998_write_reg(struct max8998_dev *max8998, u8 reg,
101 u8 value)
102{
103 return max8998->dev_write(max8998, reg, value);
104}
105
106static inline int max8998_update_reg(struct max8998_dev *max8998, u8 reg,
107 u8 value, u8 mask)
108{
109 return max8998->dev_update(max8998, reg, value, mask);
110}
111
112#endif /* __LINUX_MFD_MAX8998_PRIV_H */
diff --git a/include/linux/mfd/max8998.h b/include/linux/mfd/max8998.h
new file mode 100644
index 000000000000..1d3601a2d853
--- /dev/null
+++ b/include/linux/mfd/max8998.h
@@ -0,0 +1,78 @@
1/*
2 * max8698.h - Voltage regulator driver for the Maxim 8998
3 *
4 * Copyright (C) 2009-2010 Samsung Electrnoics
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 * Marek Szyprowski <m.szyprowski@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
23#ifndef __LINUX_MFD_MAX8998_H
24#define __LINUX_MFD_MAX8998_H
25
26#include <linux/regulator/machine.h>
27
28/* MAX 8998 regulator ids */
29enum {
30 MAX8998_LDO2 = 2,
31 MAX8998_LDO3,
32 MAX8998_LDO4,
33 MAX8998_LDO5,
34 MAX8998_LDO6,
35 MAX8998_LDO7,
36 MAX8998_LDO8,
37 MAX8998_LDO9,
38 MAX8998_LDO10,
39 MAX8998_LDO11,
40 MAX8998_LDO12,
41 MAX8998_LDO13,
42 MAX8998_LDO14,
43 MAX8998_LDO15,
44 MAX8998_LDO16,
45 MAX8998_LDO17,
46 MAX8998_BUCK1,
47 MAX8998_BUCK2,
48 MAX8998_BUCK3,
49 MAX8998_BUCK4,
50 MAX8998_EN32KHZ_AP,
51 MAX8998_EN32KHZ_CP,
52 MAX8998_ENVICHG,
53 MAX8998_ESAFEOUT1,
54 MAX8998_ESAFEOUT2,
55};
56
57/**
58 * max8998_regulator_data - regulator data
59 * @id: regulator id
60 * @initdata: regulator init data (contraints, supplies, ...)
61 */
62struct max8998_regulator_data {
63 int id;
64 struct regulator_init_data *initdata;
65};
66
67/**
68 * struct max8998_board - packages regulator init data
69 * @num_regulators: number of regultors used
70 * @regulators: array of defined regulators
71 */
72
73struct max8998_platform_data {
74 int num_regulators;
75 struct max8998_regulator_data *regulators;
76};
77
78#endif /* __LINUX_MFD_MAX8998_H */
diff --git a/include/linux/mfd/mc13783-private.h b/include/linux/mfd/mc13783-private.h
deleted file mode 100644
index 95cf9360553f..000000000000
--- a/include/linux/mfd/mc13783-private.h
+++ /dev/null
@@ -1,220 +0,0 @@
1/*
2 * Copyright 2009 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de>
3 *
4 * Initial development of this code was funded by
5 * Phytec Messtechnik GmbH, http://www.phytec.de
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#ifndef __LINUX_MFD_MC13783_PRIV_H
23#define __LINUX_MFD_MC13783_PRIV_H
24
25#include <linux/platform_device.h>
26#include <linux/mfd/mc13783.h>
27#include <linux/mutex.h>
28#include <linux/interrupt.h>
29
30struct mc13783 {
31 struct spi_device *spidev;
32 struct mutex lock;
33 int irq;
34 int flags;
35
36 irq_handler_t irqhandler[MC13783_NUM_IRQ];
37 void *irqdata[MC13783_NUM_IRQ];
38
39 /* XXX these should go as platformdata to the regulator subdevice */
40 struct mc13783_regulator_init_data *regulators;
41 int num_regulators;
42};
43
44#define MC13783_REG_INTERRUPT_STATUS_0 0
45#define MC13783_REG_INTERRUPT_MASK_0 1
46#define MC13783_REG_INTERRUPT_SENSE_0 2
47#define MC13783_REG_INTERRUPT_STATUS_1 3
48#define MC13783_REG_INTERRUPT_MASK_1 4
49#define MC13783_REG_INTERRUPT_SENSE_1 5
50#define MC13783_REG_POWER_UP_MODE_SENSE 6
51#define MC13783_REG_REVISION 7
52#define MC13783_REG_SEMAPHORE 8
53#define MC13783_REG_ARBITRATION_PERIPHERAL_AUDIO 9
54#define MC13783_REG_ARBITRATION_SWITCHERS 10
55#define MC13783_REG_ARBITRATION_REGULATORS_0 11
56#define MC13783_REG_ARBITRATION_REGULATORS_1 12
57#define MC13783_REG_POWER_CONTROL_0 13
58#define MC13783_REG_POWER_CONTROL_1 14
59#define MC13783_REG_POWER_CONTROL_2 15
60#define MC13783_REG_REGEN_ASSIGNMENT 16
61#define MC13783_REG_CONTROL_SPARE 17
62#define MC13783_REG_MEMORY_A 18
63#define MC13783_REG_MEMORY_B 19
64#define MC13783_REG_RTC_TIME 20
65#define MC13783_REG_RTC_ALARM 21
66#define MC13783_REG_RTC_DAY 22
67#define MC13783_REG_RTC_DAY_ALARM 23
68#define MC13783_REG_SWITCHERS_0 24
69#define MC13783_REG_SWITCHERS_1 25
70#define MC13783_REG_SWITCHERS_2 26
71#define MC13783_REG_SWITCHERS_3 27
72#define MC13783_REG_SWITCHERS_4 28
73#define MC13783_REG_SWITCHERS_5 29
74#define MC13783_REG_REGULATOR_SETTING_0 30
75#define MC13783_REG_REGULATOR_SETTING_1 31
76#define MC13783_REG_REGULATOR_MODE_0 32
77#define MC13783_REG_REGULATOR_MODE_1 33
78#define MC13783_REG_POWER_MISCELLANEOUS 34
79#define MC13783_REG_POWER_SPARE 35
80#define MC13783_REG_AUDIO_RX_0 36
81#define MC13783_REG_AUDIO_RX_1 37
82#define MC13783_REG_AUDIO_TX 38
83#define MC13783_REG_AUDIO_SSI_NETWORK 39
84#define MC13783_REG_AUDIO_CODEC 40
85#define MC13783_REG_AUDIO_STEREO_DAC 41
86#define MC13783_REG_AUDIO_SPARE 42
87#define MC13783_REG_ADC_0 43
88#define MC13783_REG_ADC_1 44
89#define MC13783_REG_ADC_2 45
90#define MC13783_REG_ADC_3 46
91#define MC13783_REG_ADC_4 47
92#define MC13783_REG_CHARGER 48
93#define MC13783_REG_USB 49
94#define MC13783_REG_CHARGE_USB_SPARE 50
95#define MC13783_REG_LED_CONTROL_0 51
96#define MC13783_REG_LED_CONTROL_1 52
97#define MC13783_REG_LED_CONTROL_2 53
98#define MC13783_REG_LED_CONTROL_3 54
99#define MC13783_REG_LED_CONTROL_4 55
100#define MC13783_REG_LED_CONTROL_5 56
101#define MC13783_REG_SPARE 57
102#define MC13783_REG_TRIM_0 58
103#define MC13783_REG_TRIM_1 59
104#define MC13783_REG_TEST_0 60
105#define MC13783_REG_TEST_1 61
106#define MC13783_REG_TEST_2 62
107#define MC13783_REG_TEST_3 63
108#define MC13783_REG_NB 64
109
110/*
111 * Reg Regulator Mode 0
112 */
113#define MC13783_REGCTRL_VAUDIO_EN (1 << 0)
114#define MC13783_REGCTRL_VAUDIO_STBY (1 << 1)
115#define MC13783_REGCTRL_VAUDIO_MODE (1 << 2)
116#define MC13783_REGCTRL_VIOHI_EN (1 << 3)
117#define MC13783_REGCTRL_VIOHI_STBY (1 << 4)
118#define MC13783_REGCTRL_VIOHI_MODE (1 << 5)
119#define MC13783_REGCTRL_VIOLO_EN (1 << 6)
120#define MC13783_REGCTRL_VIOLO_STBY (1 << 7)
121#define MC13783_REGCTRL_VIOLO_MODE (1 << 8)
122#define MC13783_REGCTRL_VDIG_EN (1 << 9)
123#define MC13783_REGCTRL_VDIG_STBY (1 << 10)
124#define MC13783_REGCTRL_VDIG_MODE (1 << 11)
125#define MC13783_REGCTRL_VGEN_EN (1 << 12)
126#define MC13783_REGCTRL_VGEN_STBY (1 << 13)
127#define MC13783_REGCTRL_VGEN_MODE (1 << 14)
128#define MC13783_REGCTRL_VRFDIG_EN (1 << 15)
129#define MC13783_REGCTRL_VRFDIG_STBY (1 << 16)
130#define MC13783_REGCTRL_VRFDIG_MODE (1 << 17)
131#define MC13783_REGCTRL_VRFREF_EN (1 << 18)
132#define MC13783_REGCTRL_VRFREF_STBY (1 << 19)
133#define MC13783_REGCTRL_VRFREF_MODE (1 << 20)
134#define MC13783_REGCTRL_VRFCP_EN (1 << 21)
135#define MC13783_REGCTRL_VRFCP_STBY (1 << 22)
136#define MC13783_REGCTRL_VRFCP_MODE (1 << 23)
137
138/*
139 * Reg Regulator Mode 1
140 */
141#define MC13783_REGCTRL_VSIM_EN (1 << 0)
142#define MC13783_REGCTRL_VSIM_STBY (1 << 1)
143#define MC13783_REGCTRL_VSIM_MODE (1 << 2)
144#define MC13783_REGCTRL_VESIM_EN (1 << 3)
145#define MC13783_REGCTRL_VESIM_STBY (1 << 4)
146#define MC13783_REGCTRL_VESIM_MODE (1 << 5)
147#define MC13783_REGCTRL_VCAM_EN (1 << 6)
148#define MC13783_REGCTRL_VCAM_STBY (1 << 7)
149#define MC13783_REGCTRL_VCAM_MODE (1 << 8)
150#define MC13783_REGCTRL_VRFBG_EN (1 << 9)
151#define MC13783_REGCTRL_VRFBG_STBY (1 << 10)
152#define MC13783_REGCTRL_VVIB_EN (1 << 11)
153#define MC13783_REGCTRL_VRF1_EN (1 << 12)
154#define MC13783_REGCTRL_VRF1_STBY (1 << 13)
155#define MC13783_REGCTRL_VRF1_MODE (1 << 14)
156#define MC13783_REGCTRL_VRF2_EN (1 << 15)
157#define MC13783_REGCTRL_VRF2_STBY (1 << 16)
158#define MC13783_REGCTRL_VRF2_MODE (1 << 17)
159#define MC13783_REGCTRL_VMMC1_EN (1 << 18)
160#define MC13783_REGCTRL_VMMC1_STBY (1 << 19)
161#define MC13783_REGCTRL_VMMC1_MODE (1 << 20)
162#define MC13783_REGCTRL_VMMC2_EN (1 << 21)
163#define MC13783_REGCTRL_VMMC2_STBY (1 << 22)
164#define MC13783_REGCTRL_VMMC2_MODE (1 << 23)
165
166/*
167 * Reg Regulator Misc.
168 */
169#define MC13783_REGCTRL_GPO1_EN (1 << 6)
170#define MC13783_REGCTRL_GPO2_EN (1 << 8)
171#define MC13783_REGCTRL_GPO3_EN (1 << 10)
172#define MC13783_REGCTRL_GPO4_EN (1 << 12)
173#define MC13783_REGCTRL_VIBPINCTRL (1 << 14)
174
175/*
176 * Reg Switcher 4
177 */
178#define MC13783_SWCTRL_SW1A_MODE (1 << 0)
179#define MC13783_SWCTRL_SW1A_STBY_MODE (1 << 2)
180#define MC13783_SWCTRL_SW1A_DVS_SPEED (1 << 6)
181#define MC13783_SWCTRL_SW1A_PANIC_MODE (1 << 8)
182#define MC13783_SWCTRL_SW1A_SOFTSTART (1 << 9)
183#define MC13783_SWCTRL_SW1B_MODE (1 << 10)
184#define MC13783_SWCTRL_SW1B_STBY_MODE (1 << 12)
185#define MC13783_SWCTRL_SW1B_DVS_SPEED (1 << 14)
186#define MC13783_SWCTRL_SW1B_PANIC_MODE (1 << 16)
187#define MC13783_SWCTRL_SW1B_SOFTSTART (1 << 17)
188#define MC13783_SWCTRL_PLL_EN (1 << 18)
189#define MC13783_SWCTRL_PLL_FACTOR (1 << 19)
190
191/*
192 * Reg Switcher 5
193 */
194#define MC13783_SWCTRL_SW2A_MODE (1 << 0)
195#define MC13783_SWCTRL_SW2A_STBY_MODE (1 << 2)
196#define MC13783_SWCTRL_SW2A_DVS_SPEED (1 << 6)
197#define MC13783_SWCTRL_SW2A_PANIC_MODE (1 << 8)
198#define MC13783_SWCTRL_SW2A_SOFTSTART (1 << 9)
199#define MC13783_SWCTRL_SW2B_MODE (1 << 10)
200#define MC13783_SWCTRL_SW2B_STBY_MODE (1 << 12)
201#define MC13783_SWCTRL_SW2B_DVS_SPEED (1 << 14)
202#define MC13783_SWCTRL_SW2B_PANIC_MODE (1 << 16)
203#define MC13783_SWCTRL_SW2B_SOFTSTART (1 << 17)
204#define MC13783_SWSET_SW3 (1 << 18)
205#define MC13783_SWCTRL_SW3_EN (1 << 20)
206#define MC13783_SWCTRL_SW3_STBY (1 << 21)
207#define MC13783_SWCTRL_SW3_MODE (1 << 22)
208
209static inline int mc13783_set_bits(struct mc13783 *mc13783, unsigned int offset,
210 u32 mask, u32 val)
211{
212 int ret;
213 mc13783_lock(mc13783);
214 ret = mc13783_reg_rmw(mc13783, offset, mask, val);
215 mc13783_unlock(mc13783);
216
217 return ret;
218}
219
220#endif /* __LINUX_MFD_MC13783_PRIV_H */
diff --git a/include/linux/mfd/mc13783.h b/include/linux/mfd/mc13783.h
index 4a894f688549..0fa44fb8dd26 100644
--- a/include/linux/mfd/mc13783.h
+++ b/include/linux/mfd/mc13783.h
@@ -21,6 +21,8 @@ int mc13783_reg_write(struct mc13783 *mc13783, unsigned int offset, u32 val);
21int mc13783_reg_rmw(struct mc13783 *mc13783, unsigned int offset, 21int mc13783_reg_rmw(struct mc13783 *mc13783, unsigned int offset,
22 u32 mask, u32 val); 22 u32 mask, u32 val);
23 23
24int mc13783_get_flags(struct mc13783 *mc13783);
25
24int mc13783_irq_request(struct mc13783 *mc13783, int irq, 26int mc13783_irq_request(struct mc13783 *mc13783, int irq,
25 irq_handler_t handler, const char *name, void *dev); 27 irq_handler_t handler, const char *name, void *dev);
26int mc13783_irq_request_nounmask(struct mc13783 *mc13783, int irq, 28int mc13783_irq_request_nounmask(struct mc13783 *mc13783, int irq,
diff --git a/include/linux/mfd/stmpe.h b/include/linux/mfd/stmpe.h
new file mode 100644
index 000000000000..39ca7588659b
--- /dev/null
+++ b/include/linux/mfd/stmpe.h
@@ -0,0 +1,201 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
6 */
7
8#ifndef __LINUX_MFD_STMPE_H
9#define __LINUX_MFD_STMPE_H
10
11#include <linux/device.h>
12
13enum stmpe_block {
14 STMPE_BLOCK_GPIO = 1 << 0,
15 STMPE_BLOCK_KEYPAD = 1 << 1,
16 STMPE_BLOCK_TOUCHSCREEN = 1 << 2,
17 STMPE_BLOCK_ADC = 1 << 3,
18 STMPE_BLOCK_PWM = 1 << 4,
19 STMPE_BLOCK_ROTATOR = 1 << 5,
20};
21
22enum stmpe_partnum {
23 STMPE811,
24 STMPE1601,
25 STMPE2401,
26 STMPE2403,
27};
28
29/*
30 * For registers whose locations differ on variants, the correct address is
31 * obtained by indexing stmpe->regs with one of the following.
32 */
33enum {
34 STMPE_IDX_CHIP_ID,
35 STMPE_IDX_ICR_LSB,
36 STMPE_IDX_IER_LSB,
37 STMPE_IDX_ISR_MSB,
38 STMPE_IDX_GPMR_LSB,
39 STMPE_IDX_GPSR_LSB,
40 STMPE_IDX_GPCR_LSB,
41 STMPE_IDX_GPDR_LSB,
42 STMPE_IDX_GPEDR_MSB,
43 STMPE_IDX_GPRER_LSB,
44 STMPE_IDX_GPFER_LSB,
45 STMPE_IDX_GPAFR_U_MSB,
46 STMPE_IDX_IEGPIOR_LSB,
47 STMPE_IDX_ISGPIOR_MSB,
48 STMPE_IDX_MAX,
49};
50
51
52struct stmpe_variant_info;
53
54/**
55 * struct stmpe - STMPE MFD structure
56 * @lock: lock protecting I/O operations
57 * @irq_lock: IRQ bus lock
58 * @dev: device, mostly for dev_dbg()
59 * @i2c: i2c client
60 * @variant: the detected STMPE model number
61 * @regs: list of addresses of registers which are at different addresses on
62 * different variants. Indexed by one of STMPE_IDX_*.
63 * @irq_base: starting IRQ number for internal IRQs
64 * @num_gpios: number of gpios, differs for variants
65 * @ier: cache of IER registers for bus_lock
66 * @oldier: cache of IER registers for bus_lock
67 * @pdata: platform data
68 */
69struct stmpe {
70 struct mutex lock;
71 struct mutex irq_lock;
72 struct device *dev;
73 struct i2c_client *i2c;
74 enum stmpe_partnum partnum;
75 struct stmpe_variant_info *variant;
76 const u8 *regs;
77
78 int irq_base;
79 int num_gpios;
80 u8 ier[2];
81 u8 oldier[2];
82 struct stmpe_platform_data *pdata;
83};
84
85extern int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 data);
86extern int stmpe_reg_read(struct stmpe *stmpe, u8 reg);
87extern int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length,
88 u8 *values);
89extern int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
90 const u8 *values);
91extern int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val);
92extern int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins,
93 enum stmpe_block block);
94extern int stmpe_enable(struct stmpe *stmpe, unsigned int blocks);
95extern int stmpe_disable(struct stmpe *stmpe, unsigned int blocks);
96
97struct matrix_keymap_data;
98
99/**
100 * struct stmpe_keypad_platform_data - STMPE keypad platform data
101 * @keymap_data: key map table and size
102 * @debounce_ms: debounce interval, in ms. Maximum is
103 * %STMPE_KEYPAD_MAX_DEBOUNCE.
104 * @scan_count: number of key scanning cycles to confirm key data.
105 * Maximum is %STMPE_KEYPAD_MAX_SCAN_COUNT.
106 * @no_autorepeat: disable key autorepeat
107 */
108struct stmpe_keypad_platform_data {
109 struct matrix_keymap_data *keymap_data;
110 unsigned int debounce_ms;
111 unsigned int scan_count;
112 bool no_autorepeat;
113};
114
115/**
116 * struct stmpe_gpio_platform_data - STMPE GPIO platform data
117 * @gpio_base: first gpio number assigned. A maximum of
118 * %STMPE_NR_GPIOS GPIOs will be allocated.
119 */
120struct stmpe_gpio_platform_data {
121 int gpio_base;
122 void (*setup)(struct stmpe *stmpe, unsigned gpio_base);
123 void (*remove)(struct stmpe *stmpe, unsigned gpio_base);
124};
125
126/**
127 * struct stmpe_ts_platform_data - stmpe811 touch screen controller platform
128 * data
129 * @sample_time: ADC converstion time in number of clock.
130 * (0 -> 36 clocks, 1 -> 44 clocks, 2 -> 56 clocks, 3 -> 64 clocks,
131 * 4 -> 80 clocks, 5 -> 96 clocks, 6 -> 144 clocks),
132 * recommended is 4.
133 * @mod_12b: ADC Bit mode (0 -> 10bit ADC, 1 -> 12bit ADC)
134 * @ref_sel: ADC reference source
135 * (0 -> internal reference, 1 -> external reference)
136 * @adc_freq: ADC Clock speed
137 * (0 -> 1.625 MHz, 1 -> 3.25 MHz, 2 || 3 -> 6.5 MHz)
138 * @ave_ctrl: Sample average control
139 * (0 -> 1 sample, 1 -> 2 samples, 2 -> 4 samples, 3 -> 8 samples)
140 * @touch_det_delay: Touch detect interrupt delay
141 * (0 -> 10 us, 1 -> 50 us, 2 -> 100 us, 3 -> 500 us,
142 * 4-> 1 ms, 5 -> 5 ms, 6 -> 10 ms, 7 -> 50 ms)
143 * recommended is 3
144 * @settling: Panel driver settling time
145 * (0 -> 10 us, 1 -> 100 us, 2 -> 500 us, 3 -> 1 ms,
146 * 4 -> 5 ms, 5 -> 10 ms, 6 for 50 ms, 7 -> 100 ms)
147 * recommended is 2
148 * @fraction_z: Length of the fractional part in z
149 * (fraction_z ([0..7]) = Count of the fractional part)
150 * recommended is 7
151 * @i_drive: current limit value of the touchscreen drivers
152 * (0 -> 20 mA typical 35 mA max, 1 -> 50 mA typical 80 mA max)
153 *
154 * */
155struct stmpe_ts_platform_data {
156 u8 sample_time;
157 u8 mod_12b;
158 u8 ref_sel;
159 u8 adc_freq;
160 u8 ave_ctrl;
161 u8 touch_det_delay;
162 u8 settling;
163 u8 fraction_z;
164 u8 i_drive;
165};
166
167/**
168 * struct stmpe_platform_data - STMPE platform data
169 * @id: device id to distinguish between multiple STMPEs on the same board
170 * @blocks: bitmask of blocks to enable (use STMPE_BLOCK_*)
171 * @irq_trigger: IRQ trigger to use for the interrupt to the host
172 * @irq_invert_polarity: IRQ line is connected with reversed polarity
173 * @autosleep: bool to enable/disable stmpe autosleep
174 * @autosleep_timeout: inactivity timeout in milliseconds for autosleep
175 * @irq_base: base IRQ number. %STMPE_NR_IRQS irqs will be used, or
176 * %STMPE_NR_INTERNAL_IRQS if the GPIO driver is not used.
177 * @gpio: GPIO-specific platform data
178 * @keypad: keypad-specific platform data
179 * @ts: touchscreen-specific platform data
180 */
181struct stmpe_platform_data {
182 int id;
183 unsigned int blocks;
184 int irq_base;
185 unsigned int irq_trigger;
186 bool irq_invert_polarity;
187 bool autosleep;
188 int autosleep_timeout;
189
190 struct stmpe_gpio_platform_data *gpio;
191 struct stmpe_keypad_platform_data *keypad;
192 struct stmpe_ts_platform_data *ts;
193};
194
195#define STMPE_NR_INTERNAL_IRQS 9
196#define STMPE_INT_GPIO(x) (STMPE_NR_INTERNAL_IRQS + (x))
197
198#define STMPE_NR_GPIOS 24
199#define STMPE_NR_IRQS STMPE_INT_GPIO(STMPE_NR_GPIOS)
200
201#endif
diff --git a/include/linux/mfd/tps6586x.h b/include/linux/mfd/tps6586x.h
new file mode 100644
index 000000000000..772b3ae640af
--- /dev/null
+++ b/include/linux/mfd/tps6586x.h
@@ -0,0 +1,47 @@
1#ifndef __LINUX_MFD_TPS6586X_H
2#define __LINUX_MFD_TPS6586X_H
3
4enum {
5 TPS6586X_ID_SM_0,
6 TPS6586X_ID_SM_1,
7 TPS6586X_ID_SM_2,
8 TPS6586X_ID_LDO_0,
9 TPS6586X_ID_LDO_1,
10 TPS6586X_ID_LDO_2,
11 TPS6586X_ID_LDO_3,
12 TPS6586X_ID_LDO_4,
13 TPS6586X_ID_LDO_5,
14 TPS6586X_ID_LDO_6,
15 TPS6586X_ID_LDO_7,
16 TPS6586X_ID_LDO_8,
17 TPS6586X_ID_LDO_9,
18 TPS6586X_ID_LDO_RTC,
19};
20
21struct tps6586x_subdev_info {
22 int id;
23 const char *name;
24 void *platform_data;
25};
26
27struct tps6586x_platform_data {
28 int num_subdevs;
29 struct tps6586x_subdev_info *subdevs;
30
31 int gpio_base;
32};
33
34/*
35 * NOTE: the functions below are not intended for use outside
36 * of the TPS6586X sub-device drivers
37 */
38extern int tps6586x_write(struct device *dev, int reg, uint8_t val);
39extern int tps6586x_writes(struct device *dev, int reg, int len, uint8_t *val);
40extern int tps6586x_read(struct device *dev, int reg, uint8_t *val);
41extern int tps6586x_reads(struct device *dev, int reg, int len, uint8_t *val);
42extern int tps6586x_set_bits(struct device *dev, int reg, uint8_t bit_mask);
43extern int tps6586x_clr_bits(struct device *dev, int reg, uint8_t bit_mask);
44extern int tps6586x_update(struct device *dev, int reg, uint8_t val,
45 uint8_t mask);
46
47#endif /*__LINUX_MFD_TPS6586X_H */
diff --git a/include/linux/mfd/wm8994/gpio.h b/include/linux/mfd/wm8994/gpio.h
index b4d4c22991e8..0c79b5ff4b5a 100644
--- a/include/linux/mfd/wm8994/gpio.h
+++ b/include/linux/mfd/wm8994/gpio.h
@@ -36,6 +36,10 @@
36#define WM8994_GP_FN_WSEQ_STATUS 16 36#define WM8994_GP_FN_WSEQ_STATUS 16
37#define WM8994_GP_FN_FIFO_ERROR 17 37#define WM8994_GP_FN_FIFO_ERROR 17
38#define WM8994_GP_FN_OPCLK 18 38#define WM8994_GP_FN_OPCLK 18
39#define WM8994_GP_FN_THW 19
40#define WM8994_GP_FN_DCS_DONE 20
41#define WM8994_GP_FN_FLL1_OUT 21
42#define WM8994_GP_FN_FLL2_OUT 22
39 43
40#define WM8994_GPN_DIR 0x8000 /* GPN_DIR */ 44#define WM8994_GPN_DIR 0x8000 /* GPN_DIR */
41#define WM8994_GPN_DIR_MASK 0x8000 /* GPN_DIR */ 45#define WM8994_GPN_DIR_MASK 0x8000 /* GPN_DIR */
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index f6c9b7dcb9fd..bafffc737903 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -38,6 +38,7 @@
38#define KVM_MINOR 232 38#define KVM_MINOR 232
39#define BTRFS_MINOR 234 39#define BTRFS_MINOR 234
40#define AUTOFS_MINOR 235 40#define AUTOFS_MINOR 235
41#define MAPPER_CTRL_MINOR 236
41#define MISC_DYNAMIC_MINOR 255 42#define MISC_DYNAMIC_MINOR 255
42 43
43struct device; 44struct device;
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index d02d2c6e0cfe..6b7525099e56 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -24,12 +24,14 @@ struct mmc_cid {
24}; 24};
25 25
26struct mmc_csd { 26struct mmc_csd {
27 unsigned char structure;
27 unsigned char mmca_vsn; 28 unsigned char mmca_vsn;
28 unsigned short cmdclass; 29 unsigned short cmdclass;
29 unsigned short tacc_clks; 30 unsigned short tacc_clks;
30 unsigned int tacc_ns; 31 unsigned int tacc_ns;
31 unsigned int r2w_factor; 32 unsigned int r2w_factor;
32 unsigned int max_dtr; 33 unsigned int max_dtr;
34 unsigned int erase_size; /* In sectors */
33 unsigned int read_blkbits; 35 unsigned int read_blkbits;
34 unsigned int write_blkbits; 36 unsigned int write_blkbits;
35 unsigned int capacity; 37 unsigned int capacity;
@@ -41,9 +43,16 @@ struct mmc_csd {
41 43
42struct mmc_ext_csd { 44struct mmc_ext_csd {
43 u8 rev; 45 u8 rev;
46 u8 erase_group_def;
47 u8 sec_feature_support;
44 unsigned int sa_timeout; /* Units: 100ns */ 48 unsigned int sa_timeout; /* Units: 100ns */
45 unsigned int hs_max_dtr; 49 unsigned int hs_max_dtr;
46 unsigned int sectors; 50 unsigned int sectors;
51 unsigned int hc_erase_size; /* In sectors */
52 unsigned int hc_erase_timeout; /* In milliseconds */
53 unsigned int sec_trim_mult; /* Secure trim multiplier */
54 unsigned int sec_erase_mult; /* Secure erase multiplier */
55 unsigned int trim_timeout; /* In milliseconds */
47}; 56};
48 57
49struct sd_scr { 58struct sd_scr {
@@ -53,6 +62,12 @@ struct sd_scr {
53#define SD_SCR_BUS_WIDTH_4 (1<<2) 62#define SD_SCR_BUS_WIDTH_4 (1<<2)
54}; 63};
55 64
65struct sd_ssr {
66 unsigned int au; /* In sectors */
67 unsigned int erase_timeout; /* In milliseconds */
68 unsigned int erase_offset; /* In milliseconds */
69};
70
56struct sd_switch_caps { 71struct sd_switch_caps {
57 unsigned int hs_max_dtr; 72 unsigned int hs_max_dtr;
58}; 73};
@@ -92,6 +107,7 @@ struct mmc_card {
92#define MMC_TYPE_MMC 0 /* MMC card */ 107#define MMC_TYPE_MMC 0 /* MMC card */
93#define MMC_TYPE_SD 1 /* SD card */ 108#define MMC_TYPE_SD 1 /* SD card */
94#define MMC_TYPE_SDIO 2 /* SDIO card */ 109#define MMC_TYPE_SDIO 2 /* SDIO card */
110#define MMC_TYPE_SD_COMBO 3 /* SD combo (IO+mem) card */
95 unsigned int state; /* (our) card state */ 111 unsigned int state; /* (our) card state */
96#define MMC_STATE_PRESENT (1<<0) /* present in sysfs */ 112#define MMC_STATE_PRESENT (1<<0) /* present in sysfs */
97#define MMC_STATE_READONLY (1<<1) /* card is read-only */ 113#define MMC_STATE_READONLY (1<<1) /* card is read-only */
@@ -101,6 +117,13 @@ struct mmc_card {
101#define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */ 117#define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */
102#define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */ 118#define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */
103 /* for byte mode */ 119 /* for byte mode */
120#define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */
121 /* (missing CIA registers) */
122
123 unsigned int erase_size; /* erase size in sectors */
124 unsigned int erase_shift; /* if erase unit is power 2 */
125 unsigned int pref_erase; /* in sectors */
126 u8 erased_byte; /* value of erased bytes */
104 127
105 u32 raw_cid[4]; /* raw card CID */ 128 u32 raw_cid[4]; /* raw card CID */
106 u32 raw_csd[4]; /* raw card CSD */ 129 u32 raw_csd[4]; /* raw card CSD */
@@ -109,6 +132,7 @@ struct mmc_card {
109 struct mmc_csd csd; /* card specific */ 132 struct mmc_csd csd; /* card specific */
110 struct mmc_ext_csd ext_csd; /* mmc v4 extended card specific */ 133 struct mmc_ext_csd ext_csd; /* mmc v4 extended card specific */
111 struct sd_scr scr; /* extra SD information */ 134 struct sd_scr scr; /* extra SD information */
135 struct sd_ssr ssr; /* yet more SD information */
112 struct sd_switch_caps sw_caps; /* switch (CMD6) caps */ 136 struct sd_switch_caps sw_caps; /* switch (CMD6) caps */
113 137
114 unsigned int sdio_funcs; /* number of SDIO functions */ 138 unsigned int sdio_funcs; /* number of SDIO functions */
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index e4898e9eeb59..7429033acb66 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -92,6 +92,8 @@ struct mmc_command {
92 * actively failing requests 92 * actively failing requests
93 */ 93 */
94 94
95 unsigned int erase_timeout; /* in milliseconds */
96
95 struct mmc_data *data; /* data segment associated with cmd */ 97 struct mmc_data *data; /* data segment associated with cmd */
96 struct mmc_request *mrq; /* associated request */ 98 struct mmc_request *mrq; /* associated request */
97}; 99};
@@ -134,6 +136,23 @@ extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int);
134extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *, 136extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
135 struct mmc_command *, int); 137 struct mmc_command *, int);
136 138
139#define MMC_ERASE_ARG 0x00000000
140#define MMC_SECURE_ERASE_ARG 0x80000000
141#define MMC_TRIM_ARG 0x00000001
142#define MMC_SECURE_TRIM1_ARG 0x80000001
143#define MMC_SECURE_TRIM2_ARG 0x80008000
144
145#define MMC_SECURE_ARGS 0x80000000
146#define MMC_TRIM_ARGS 0x00008001
147
148extern int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
149 unsigned int arg);
150extern int mmc_can_erase(struct mmc_card *card);
151extern int mmc_can_trim(struct mmc_card *card);
152extern int mmc_can_secure_erase_trim(struct mmc_card *card);
153extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
154 unsigned int nr);
155
137extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *); 156extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
138extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int); 157extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
139 158
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index f65913c9f5a4..1575b52c3bfa 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -124,6 +124,7 @@ struct mmc_host {
124 unsigned int f_min; 124 unsigned int f_min;
125 unsigned int f_max; 125 unsigned int f_max;
126 u32 ocr_avail; 126 u32 ocr_avail;
127 struct notifier_block pm_notify;
127 128
128#define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */ 129#define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */
129#define MMC_VDD_20_21 0x00000100 /* VDD voltage 2.0 ~ 2.1 */ 130#define MMC_VDD_20_21 0x00000100 /* VDD voltage 2.0 ~ 2.1 */
@@ -155,6 +156,7 @@ struct mmc_host {
155#define MMC_CAP_DISABLE (1 << 7) /* Can the host be disabled */ 156#define MMC_CAP_DISABLE (1 << 7) /* Can the host be disabled */
156#define MMC_CAP_NONREMOVABLE (1 << 8) /* Nonremovable e.g. eMMC */ 157#define MMC_CAP_NONREMOVABLE (1 << 8) /* Nonremovable e.g. eMMC */
157#define MMC_CAP_WAIT_WHILE_BUSY (1 << 9) /* Waits while card is busy */ 158#define MMC_CAP_WAIT_WHILE_BUSY (1 << 9) /* Waits while card is busy */
159#define MMC_CAP_ERASE (1 << 10) /* Allow erase/trim commands */
158 160
159 mmc_pm_flag_t pm_caps; /* supported pm features */ 161 mmc_pm_flag_t pm_caps; /* supported pm features */
160 162
@@ -183,6 +185,7 @@ struct mmc_host {
183 185
184 /* Only used with MMC_CAP_DISABLE */ 186 /* Only used with MMC_CAP_DISABLE */
185 int enabled; /* host is enabled */ 187 int enabled; /* host is enabled */
188 int rescan_disable; /* disable card detection */
186 int nesting_cnt; /* "enable" nesting count */ 189 int nesting_cnt; /* "enable" nesting count */
187 int en_dis_recurs; /* detect recursion */ 190 int en_dis_recurs; /* detect recursion */
188 unsigned int disable_delay; /* disable delay in msecs */ 191 unsigned int disable_delay; /* disable delay in msecs */
@@ -257,6 +260,7 @@ int mmc_card_can_sleep(struct mmc_host *host);
257int mmc_host_enable(struct mmc_host *host); 260int mmc_host_enable(struct mmc_host *host);
258int mmc_host_disable(struct mmc_host *host); 261int mmc_host_disable(struct mmc_host *host);
259int mmc_host_lazy_disable(struct mmc_host *host); 262int mmc_host_lazy_disable(struct mmc_host *host);
263int mmc_pm_notify(struct notifier_block *notify_block, unsigned long, void *);
260 264
261static inline void mmc_set_disable_delay(struct mmc_host *host, 265static inline void mmc_set_disable_delay(struct mmc_host *host,
262 unsigned int disable_delay) 266 unsigned int disable_delay)
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 8a49cbf0376d..dd11ae51fb68 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -251,12 +251,21 @@ struct _mmc_csd {
251 * EXT_CSD fields 251 * EXT_CSD fields
252 */ 252 */
253 253
254#define EXT_CSD_BUS_WIDTH 183 /* R/W */ 254#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
255#define EXT_CSD_HS_TIMING 185 /* R/W */ 255#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */
256#define EXT_CSD_CARD_TYPE 196 /* RO */ 256#define EXT_CSD_BUS_WIDTH 183 /* R/W */
257#define EXT_CSD_REV 192 /* RO */ 257#define EXT_CSD_HS_TIMING 185 /* R/W */
258#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */ 258#define EXT_CSD_REV 192 /* RO */
259#define EXT_CSD_S_A_TIMEOUT 217 259#define EXT_CSD_STRUCTURE 194 /* RO */
260#define EXT_CSD_CARD_TYPE 196 /* RO */
261#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
262#define EXT_CSD_S_A_TIMEOUT 217 /* RO */
263#define EXT_CSD_ERASE_TIMEOUT_MULT 223 /* RO */
264#define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */
265#define EXT_CSD_SEC_TRIM_MULT 229 /* RO */
266#define EXT_CSD_SEC_ERASE_MULT 230 /* RO */
267#define EXT_CSD_SEC_FEATURE_SUPPORT 231 /* RO */
268#define EXT_CSD_TRIM_MULT 232 /* RO */
260 269
261/* 270/*
262 * EXT_CSD field definitions 271 * EXT_CSD field definitions
@@ -274,6 +283,10 @@ struct _mmc_csd {
274#define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */ 283#define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */
275#define EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */ 284#define EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */
276 285
286#define EXT_CSD_SEC_ER_EN BIT(0)
287#define EXT_CSD_SEC_BD_BLK_EN BIT(2)
288#define EXT_CSD_SEC_GB_CL_EN BIT(4)
289
277/* 290/*
278 * MMC_SWITCH access modes 291 * MMC_SWITCH access modes
279 */ 292 */
diff --git a/include/linux/mmc/sd.h b/include/linux/mmc/sd.h
index f310062cffb4..3fd85e088cc3 100644
--- a/include/linux/mmc/sd.h
+++ b/include/linux/mmc/sd.h
@@ -21,8 +21,13 @@
21 /* class 10 */ 21 /* class 10 */
22#define SD_SWITCH 6 /* adtc [31:0] See below R1 */ 22#define SD_SWITCH 6 /* adtc [31:0] See below R1 */
23 23
24 /* class 5 */
25#define SD_ERASE_WR_BLK_START 32 /* ac [31:0] data addr R1 */
26#define SD_ERASE_WR_BLK_END 33 /* ac [31:0] data addr R1 */
27
24 /* Application commands */ 28 /* Application commands */
25#define SD_APP_SET_BUS_WIDTH 6 /* ac [1:0] bus width R1 */ 29#define SD_APP_SET_BUS_WIDTH 6 /* ac [1:0] bus width R1 */
30#define SD_APP_SD_STATUS 13 /* adtc R1 */
26#define SD_APP_SEND_NUM_WR_BLKS 22 /* adtc R1 */ 31#define SD_APP_SEND_NUM_WR_BLKS 22 /* adtc R1 */
27#define SD_APP_OP_COND 41 /* bcr [31:0] OCR R3 */ 32#define SD_APP_OP_COND 41 /* bcr [31:0] OCR R3 */
28#define SD_APP_SEND_SCR 51 /* adtc R1 */ 33#define SD_APP_SEND_SCR 51 /* adtc R1 */
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 82a9124f7d75..9d2f1837b3d8 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -31,20 +31,23 @@ static const char __module_cat(name,__LINE__)[] \
31 31
32struct kernel_param; 32struct kernel_param;
33 33
34/* Returns 0, or -errno. arg is in kp->arg. */ 34struct kernel_param_ops {
35typedef int (*param_set_fn)(const char *val, struct kernel_param *kp); 35 /* Returns 0, or -errno. arg is in kp->arg. */
36/* Returns length written or -errno. Buffer is 4k (ie. be short!) */ 36 int (*set)(const char *val, const struct kernel_param *kp);
37typedef int (*param_get_fn)(char *buffer, struct kernel_param *kp); 37 /* Returns length written or -errno. Buffer is 4k (ie. be short!) */
38 int (*get)(char *buffer, const struct kernel_param *kp);
39 /* Optional function to free kp->arg when module unloaded. */
40 void (*free)(void *arg);
41};
38 42
39/* Flag bits for kernel_param.flags */ 43/* Flag bits for kernel_param.flags */
40#define KPARAM_ISBOOL 2 44#define KPARAM_ISBOOL 2
41 45
42struct kernel_param { 46struct kernel_param {
43 const char *name; 47 const char *name;
48 const struct kernel_param_ops *ops;
44 u16 perm; 49 u16 perm;
45 u16 flags; 50 u16 flags;
46 param_set_fn set;
47 param_get_fn get;
48 union { 51 union {
49 void *arg; 52 void *arg;
50 const struct kparam_string *str; 53 const struct kparam_string *str;
@@ -63,12 +66,67 @@ struct kparam_array
63{ 66{
64 unsigned int max; 67 unsigned int max;
65 unsigned int *num; 68 unsigned int *num;
66 param_set_fn set; 69 const struct kernel_param_ops *ops;
67 param_get_fn get;
68 unsigned int elemsize; 70 unsigned int elemsize;
69 void *elem; 71 void *elem;
70}; 72};
71 73
74/**
75 * module_param - typesafe helper for a module/cmdline parameter
76 * @value: the variable to alter, and exposed parameter name.
77 * @type: the type of the parameter
78 * @perm: visibility in sysfs.
79 *
80 * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a
81 * ".") the kernel commandline parameter. Note that - is changed to _, so
82 * the user can use "foo-bar=1" even for variable "foo_bar".
83 *
84 * @perm is 0 if the the variable is not to appear in sysfs, or 0444
85 * for world-readable, 0644 for root-writable, etc. Note that if it
86 * is writable, you may need to use kparam_block_sysfs_write() around
87 * accesses (esp. charp, which can be kfreed when it changes).
88 *
89 * The @type is simply pasted to refer to a param_ops_##type and a
90 * param_check_##type: for convenience many standard types are provided but
91 * you can create your own by defining those variables.
92 *
93 * Standard types are:
94 * byte, short, ushort, int, uint, long, ulong
95 * charp: a character pointer
96 * bool: a bool, values 0/1, y/n, Y/N.
97 * invbool: the above, only sense-reversed (N = true).
98 */
99#define module_param(name, type, perm) \
100 module_param_named(name, name, type, perm)
101
102/**
103 * module_param_named - typesafe helper for a renamed module/cmdline parameter
104 * @name: a valid C identifier which is the parameter name.
105 * @value: the actual lvalue to alter.
106 * @type: the type of the parameter
107 * @perm: visibility in sysfs.
108 *
109 * Usually it's a good idea to have variable names and user-exposed names the
110 * same, but that's harder if the variable must be non-static or is inside a
111 * structure. This allows exposure under a different name.
112 */
113#define module_param_named(name, value, type, perm) \
114 param_check_##type(name, &(value)); \
115 module_param_cb(name, &param_ops_##type, &value, perm); \
116 __MODULE_PARM_TYPE(name, #type)
117
118/**
119 * module_param_cb - general callback for a module/cmdline parameter
120 * @name: a valid C identifier which is the parameter name.
121 * @ops: the set & get operations for this parameter.
122 * @perm: visibility in sysfs.
123 *
124 * The ops can have NULL set or get functions.
125 */
126#define module_param_cb(name, ops, arg, perm) \
127 __module_param_call(MODULE_PARAM_PREFIX, \
128 name, ops, arg, __same_type((arg), bool *), perm)
129
72/* On alpha, ia64 and ppc64 relocations to global data cannot go into 130/* On alpha, ia64 and ppc64 relocations to global data cannot go into
73 read-only sections (which is part of respective UNIX ABI on these 131 read-only sections (which is part of respective UNIX ABI on these
74 platforms). So 'const' makes no sense and even causes compile failures 132 platforms). So 'const' makes no sense and even causes compile failures
@@ -80,10 +138,8 @@ struct kparam_array
80#endif 138#endif
81 139
82/* This is the fundamental function for registering boot/module 140/* This is the fundamental function for registering boot/module
83 parameters. perm sets the visibility in sysfs: 000 means it's 141 parameters. */
84 not there, read bits mean it's readable, write bits mean it's 142#define __module_param_call(prefix, name, ops, arg, isbool, perm) \
85 writable. */
86#define __module_param_call(prefix, name, set, get, arg, isbool, perm) \
87 /* Default value instead of permissions? */ \ 143 /* Default value instead of permissions? */ \
88 static int __param_perm_check_##name __attribute__((unused)) = \ 144 static int __param_perm_check_##name __attribute__((unused)) = \
89 BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)) \ 145 BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)) \
@@ -92,31 +148,87 @@ struct kparam_array
92 static struct kernel_param __moduleparam_const __param_##name \ 148 static struct kernel_param __moduleparam_const __param_##name \
93 __used \ 149 __used \
94 __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \ 150 __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
95 = { __param_str_##name, perm, isbool ? KPARAM_ISBOOL : 0, \ 151 = { __param_str_##name, ops, perm, isbool ? KPARAM_ISBOOL : 0, \
96 set, get, { arg } } 152 { arg } }
153
154/* Obsolete - use module_param_cb() */
155#define module_param_call(name, set, get, arg, perm) \
156 static struct kernel_param_ops __param_ops_##name = \
157 { (void *)set, (void *)get }; \
158 __module_param_call(MODULE_PARAM_PREFIX, \
159 name, &__param_ops_##name, arg, \
160 __same_type(arg, bool *), \
161 (perm) + sizeof(__check_old_set_param(set))*0)
162
163/* We don't get oldget: it's often a new-style param_get_uint, etc. */
164static inline int
165__check_old_set_param(int (*oldset)(const char *, struct kernel_param *))
166{
167 return 0;
168}
97 169
98#define module_param_call(name, set, get, arg, perm) \ 170/**
99 __module_param_call(MODULE_PARAM_PREFIX, \ 171 * kparam_block_sysfs_write - make sure a parameter isn't written via sysfs.
100 name, set, get, arg, \ 172 * @name: the name of the parameter
101 __same_type(*(arg), bool), perm) 173 *
174 * There's no point blocking write on a paramter that isn't writable via sysfs!
175 */
176#define kparam_block_sysfs_write(name) \
177 do { \
178 BUG_ON(!(__param_##name.perm & 0222)); \
179 __kernel_param_lock(); \
180 } while (0)
102 181
103/* Helper functions: type is byte, short, ushort, int, uint, long, 182/**
104 ulong, charp, bool or invbool, or XXX if you define param_get_XXX, 183 * kparam_unblock_sysfs_write - allows sysfs to write to a parameter again.
105 param_set_XXX and param_check_XXX. */ 184 * @name: the name of the parameter
106#define module_param_named(name, value, type, perm) \ 185 */
107 param_check_##type(name, &(value)); \ 186#define kparam_unblock_sysfs_write(name) \
108 module_param_call(name, param_set_##type, param_get_##type, &value, perm); \ 187 do { \
109 __MODULE_PARM_TYPE(name, #type) 188 BUG_ON(!(__param_##name.perm & 0222)); \
189 __kernel_param_unlock(); \
190 } while (0)
110 191
111#define module_param(name, type, perm) \ 192/**
112 module_param_named(name, name, type, perm) 193 * kparam_block_sysfs_read - make sure a parameter isn't read via sysfs.
194 * @name: the name of the parameter
195 *
196 * This also blocks sysfs writes.
197 */
198#define kparam_block_sysfs_read(name) \
199 do { \
200 BUG_ON(!(__param_##name.perm & 0444)); \
201 __kernel_param_lock(); \
202 } while (0)
203
204/**
205 * kparam_unblock_sysfs_read - allows sysfs to read a parameter again.
206 * @name: the name of the parameter
207 */
208#define kparam_unblock_sysfs_read(name) \
209 do { \
210 BUG_ON(!(__param_##name.perm & 0444)); \
211 __kernel_param_unlock(); \
212 } while (0)
213
214#ifdef CONFIG_SYSFS
215extern void __kernel_param_lock(void);
216extern void __kernel_param_unlock(void);
217#else
218static inline void __kernel_param_lock(void)
219{
220}
221static inline void __kernel_param_unlock(void)
222{
223}
224#endif
113 225
114#ifndef MODULE 226#ifndef MODULE
115/** 227/**
116 * core_param - define a historical core kernel parameter. 228 * core_param - define a historical core kernel parameter.
117 * @name: the name of the cmdline and sysfs parameter (often the same as var) 229 * @name: the name of the cmdline and sysfs parameter (often the same as var)
118 * @var: the variable 230 * @var: the variable
119 * @type: the type (for param_set_##type and param_get_##type) 231 * @type: the type of the parameter
120 * @perm: visibility in sysfs 232 * @perm: visibility in sysfs
121 * 233 *
122 * core_param is just like module_param(), but cannot be modular and 234 * core_param is just like module_param(), but cannot be modular and
@@ -126,23 +238,32 @@ struct kparam_array
126 */ 238 */
127#define core_param(name, var, type, perm) \ 239#define core_param(name, var, type, perm) \
128 param_check_##type(name, &(var)); \ 240 param_check_##type(name, &(var)); \
129 __module_param_call("", name, param_set_##type, param_get_##type, \ 241 __module_param_call("", name, &param_ops_##type, \
130 &var, __same_type(var, bool), perm) 242 &var, __same_type(var, bool), perm)
131#endif /* !MODULE */ 243#endif /* !MODULE */
132 244
133/* Actually copy string: maxlen param is usually sizeof(string). */ 245/**
246 * module_param_string - a char array parameter
247 * @name: the name of the parameter
248 * @string: the string variable
249 * @len: the maximum length of the string, incl. terminator
250 * @perm: visibility in sysfs.
251 *
252 * This actually copies the string when it's set (unlike type charp).
253 * @len is usually just sizeof(string).
254 */
134#define module_param_string(name, string, len, perm) \ 255#define module_param_string(name, string, len, perm) \
135 static const struct kparam_string __param_string_##name \ 256 static const struct kparam_string __param_string_##name \
136 = { len, string }; \ 257 = { len, string }; \
137 __module_param_call(MODULE_PARAM_PREFIX, name, \ 258 __module_param_call(MODULE_PARAM_PREFIX, name, \
138 param_set_copystring, param_get_string, \ 259 &param_ops_string, \
139 .str = &__param_string_##name, 0, perm); \ 260 .str = &__param_string_##name, 0, perm); \
140 __MODULE_PARM_TYPE(name, "string") 261 __MODULE_PARM_TYPE(name, "string")
141 262
142/* Called on module insert or kernel boot */ 263/* Called on module insert or kernel boot */
143extern int parse_args(const char *name, 264extern int parse_args(const char *name,
144 char *args, 265 char *args,
145 struct kernel_param *params, 266 const struct kernel_param *params,
146 unsigned num, 267 unsigned num,
147 int (*unknown)(char *param, char *val)); 268 int (*unknown)(char *param, char *val));
148 269
@@ -162,72 +283,105 @@ static inline void destroy_params(const struct kernel_param *params,
162#define __param_check(name, p, type) \ 283#define __param_check(name, p, type) \
163 static inline type *__check_##name(void) { return(p); } 284 static inline type *__check_##name(void) { return(p); }
164 285
165extern int param_set_byte(const char *val, struct kernel_param *kp); 286extern struct kernel_param_ops param_ops_byte;
166extern int param_get_byte(char *buffer, struct kernel_param *kp); 287extern int param_set_byte(const char *val, const struct kernel_param *kp);
288extern int param_get_byte(char *buffer, const struct kernel_param *kp);
167#define param_check_byte(name, p) __param_check(name, p, unsigned char) 289#define param_check_byte(name, p) __param_check(name, p, unsigned char)
168 290
169extern int param_set_short(const char *val, struct kernel_param *kp); 291extern struct kernel_param_ops param_ops_short;
170extern int param_get_short(char *buffer, struct kernel_param *kp); 292extern int param_set_short(const char *val, const struct kernel_param *kp);
293extern int param_get_short(char *buffer, const struct kernel_param *kp);
171#define param_check_short(name, p) __param_check(name, p, short) 294#define param_check_short(name, p) __param_check(name, p, short)
172 295
173extern int param_set_ushort(const char *val, struct kernel_param *kp); 296extern struct kernel_param_ops param_ops_ushort;
174extern int param_get_ushort(char *buffer, struct kernel_param *kp); 297extern int param_set_ushort(const char *val, const struct kernel_param *kp);
298extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
175#define param_check_ushort(name, p) __param_check(name, p, unsigned short) 299#define param_check_ushort(name, p) __param_check(name, p, unsigned short)
176 300
177extern int param_set_int(const char *val, struct kernel_param *kp); 301extern struct kernel_param_ops param_ops_int;
178extern int param_get_int(char *buffer, struct kernel_param *kp); 302extern int param_set_int(const char *val, const struct kernel_param *kp);
303extern int param_get_int(char *buffer, const struct kernel_param *kp);
179#define param_check_int(name, p) __param_check(name, p, int) 304#define param_check_int(name, p) __param_check(name, p, int)
180 305
181extern int param_set_uint(const char *val, struct kernel_param *kp); 306extern struct kernel_param_ops param_ops_uint;
182extern int param_get_uint(char *buffer, struct kernel_param *kp); 307extern int param_set_uint(const char *val, const struct kernel_param *kp);
308extern int param_get_uint(char *buffer, const struct kernel_param *kp);
183#define param_check_uint(name, p) __param_check(name, p, unsigned int) 309#define param_check_uint(name, p) __param_check(name, p, unsigned int)
184 310
185extern int param_set_long(const char *val, struct kernel_param *kp); 311extern struct kernel_param_ops param_ops_long;
186extern int param_get_long(char *buffer, struct kernel_param *kp); 312extern int param_set_long(const char *val, const struct kernel_param *kp);
313extern int param_get_long(char *buffer, const struct kernel_param *kp);
187#define param_check_long(name, p) __param_check(name, p, long) 314#define param_check_long(name, p) __param_check(name, p, long)
188 315
189extern int param_set_ulong(const char *val, struct kernel_param *kp); 316extern struct kernel_param_ops param_ops_ulong;
190extern int param_get_ulong(char *buffer, struct kernel_param *kp); 317extern int param_set_ulong(const char *val, const struct kernel_param *kp);
318extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
191#define param_check_ulong(name, p) __param_check(name, p, unsigned long) 319#define param_check_ulong(name, p) __param_check(name, p, unsigned long)
192 320
193extern int param_set_charp(const char *val, struct kernel_param *kp); 321extern struct kernel_param_ops param_ops_charp;
194extern int param_get_charp(char *buffer, struct kernel_param *kp); 322extern int param_set_charp(const char *val, const struct kernel_param *kp);
323extern int param_get_charp(char *buffer, const struct kernel_param *kp);
195#define param_check_charp(name, p) __param_check(name, p, char *) 324#define param_check_charp(name, p) __param_check(name, p, char *)
196 325
197/* For historical reasons "bool" parameters can be (unsigned) "int". */ 326/* For historical reasons "bool" parameters can be (unsigned) "int". */
198extern int param_set_bool(const char *val, struct kernel_param *kp); 327extern struct kernel_param_ops param_ops_bool;
199extern int param_get_bool(char *buffer, struct kernel_param *kp); 328extern int param_set_bool(const char *val, const struct kernel_param *kp);
329extern int param_get_bool(char *buffer, const struct kernel_param *kp);
200#define param_check_bool(name, p) \ 330#define param_check_bool(name, p) \
201 static inline void __check_##name(void) \ 331 static inline void __check_##name(void) \
202 { \ 332 { \
203 BUILD_BUG_ON(!__same_type(*(p), bool) && \ 333 BUILD_BUG_ON(!__same_type((p), bool *) && \
204 !__same_type(*(p), unsigned int) && \ 334 !__same_type((p), unsigned int *) && \
205 !__same_type(*(p), int)); \ 335 !__same_type((p), int *)); \
206 } 336 }
207 337
208extern int param_set_invbool(const char *val, struct kernel_param *kp); 338extern struct kernel_param_ops param_ops_invbool;
209extern int param_get_invbool(char *buffer, struct kernel_param *kp); 339extern int param_set_invbool(const char *val, const struct kernel_param *kp);
340extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
210#define param_check_invbool(name, p) __param_check(name, p, bool) 341#define param_check_invbool(name, p) __param_check(name, p, bool)
211 342
212/* Comma-separated array: *nump is set to number they actually specified. */ 343/**
344 * module_param_array - a parameter which is an array of some type
345 * @name: the name of the array variable
346 * @type: the type, as per module_param()
347 * @nump: optional pointer filled in with the number written
348 * @perm: visibility in sysfs
349 *
350 * Input and output are as comma-separated values. Commas inside values
351 * don't work properly (eg. an array of charp).
352 *
353 * ARRAY_SIZE(@name) is used to determine the number of elements in the
354 * array, so the definition must be visible.
355 */
356#define module_param_array(name, type, nump, perm) \
357 module_param_array_named(name, name, type, nump, perm)
358
359/**
360 * module_param_array_named - renamed parameter which is an array of some type
361 * @name: a valid C identifier which is the parameter name
362 * @array: the name of the array variable
363 * @type: the type, as per module_param()
364 * @nump: optional pointer filled in with the number written
365 * @perm: visibility in sysfs
366 *
367 * This exposes a different name than the actual variable name. See
368 * module_param_named() for why this might be necessary.
369 */
213#define module_param_array_named(name, array, type, nump, perm) \ 370#define module_param_array_named(name, array, type, nump, perm) \
214 static const struct kparam_array __param_arr_##name \ 371 static const struct kparam_array __param_arr_##name \
215 = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\ 372 = { ARRAY_SIZE(array), nump, &param_ops_##type, \
216 sizeof(array[0]), array }; \ 373 sizeof(array[0]), array }; \
217 __module_param_call(MODULE_PARAM_PREFIX, name, \ 374 __module_param_call(MODULE_PARAM_PREFIX, name, \
218 param_array_set, param_array_get, \ 375 &param_array_ops, \
219 .arr = &__param_arr_##name, \ 376 .arr = &__param_arr_##name, \
220 __same_type(array[0], bool), perm); \ 377 __same_type(array[0], bool), perm); \
221 __MODULE_PARM_TYPE(name, "array of " #type) 378 __MODULE_PARM_TYPE(name, "array of " #type)
222 379
223#define module_param_array(name, type, nump, perm) \ 380extern struct kernel_param_ops param_array_ops;
224 module_param_array_named(name, name, type, nump, perm)
225
226extern int param_array_set(const char *val, struct kernel_param *kp);
227extern int param_array_get(char *buffer, struct kernel_param *kp);
228 381
229extern int param_set_copystring(const char *val, struct kernel_param *kp); 382extern struct kernel_param_ops param_ops_string;
230extern int param_get_string(char *buffer, struct kernel_param *kp); 383extern int param_set_copystring(const char *val, const struct kernel_param *);
384extern int param_get_string(char *buffer, const struct kernel_param *kp);
231 385
232/* for exporting parameters in /sys/parameters */ 386/* for exporting parameters in /sys/parameters */
233 387
@@ -235,13 +389,13 @@ struct module;
235 389
236#if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES) 390#if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
237extern int module_param_sysfs_setup(struct module *mod, 391extern int module_param_sysfs_setup(struct module *mod,
238 struct kernel_param *kparam, 392 const struct kernel_param *kparam,
239 unsigned int num_params); 393 unsigned int num_params);
240 394
241extern void module_param_sysfs_remove(struct module *mod); 395extern void module_param_sysfs_remove(struct module *mod);
242#else 396#else
243static inline int module_param_sysfs_setup(struct module *mod, 397static inline int module_param_sysfs_setup(struct module *mod,
244 struct kernel_param *kparam, 398 const struct kernel_param *kparam,
245 unsigned int num_params) 399 unsigned int num_params)
246{ 400{
247 return 0; 401 return 0;
diff --git a/include/linux/mount.h b/include/linux/mount.h
index 907210bd9f9c..5e7a59408dd4 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -27,7 +27,6 @@ struct mnt_namespace;
27#define MNT_NODIRATIME 0x10 27#define MNT_NODIRATIME 0x10
28#define MNT_RELATIME 0x20 28#define MNT_RELATIME 0x20
29#define MNT_READONLY 0x40 /* does the user want this to be r/o? */ 29#define MNT_READONLY 0x40 /* does the user want this to be r/o? */
30#define MNT_STRICTATIME 0x80
31 30
32#define MNT_SHRINKABLE 0x100 31#define MNT_SHRINKABLE 0x100
33#define MNT_WRITE_HOLD 0x200 32#define MNT_WRITE_HOLD 0x200
diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h
index 413742c92d14..791d5109f34c 100644
--- a/include/linux/netpoll.h
+++ b/include/linux/netpoll.h
@@ -122,7 +122,7 @@ static inline int netpoll_tx_running(struct net_device *dev)
122} 122}
123 123
124#else 124#else
125static inline int netpoll_rx(struct sk_buff *skb) 125static inline bool netpoll_rx(struct sk_buff *skb)
126{ 126{
127 return 0; 127 return 0;
128} 128}
diff --git a/include/linux/of_device.h b/include/linux/of_device.h
index 35aa44ad9f2c..835f85ecd2de 100644
--- a/include/linux/of_device.h
+++ b/include/linux/of_device.h
@@ -1,20 +1,6 @@
1#ifndef _LINUX_OF_DEVICE_H 1#ifndef _LINUX_OF_DEVICE_H
2#define _LINUX_OF_DEVICE_H 2#define _LINUX_OF_DEVICE_H
3 3
4/*
5 * The of_device *was* a kind of "base class" that was a superset of
6 * struct device for use by devices attached to an OF node and probed
7 * using OF properties. However, the important bit of OF-style
8 * probing, namely the device node pointer, has been moved into the
9 * common struct device when CONFIG_OF is set to make OF-style probing
10 * available to all bus types. So now, just make of_device and
11 * platform_device equivalent so that current of_platform bus users
12 * can be transparently migrated over to using the platform bus.
13 *
14 * This line will go away once all references to of_device are removed
15 * from the kernel.
16 */
17#define of_device platform_device
18#include <linux/platform_device.h> 4#include <linux/platform_device.h>
19#include <linux/of_platform.h> /* temporary until merge */ 5#include <linux/of_platform.h> /* temporary until merge */
20 6
@@ -23,8 +9,6 @@
23#include <linux/of.h> 9#include <linux/of.h>
24#include <linux/mod_devicetable.h> 10#include <linux/mod_devicetable.h>
25 11
26#define to_of_device(d) container_of(d, struct of_device, dev)
27
28extern const struct of_device_id *of_match_device( 12extern const struct of_device_id *of_match_device(
29 const struct of_device_id *matches, const struct device *dev); 13 const struct of_device_id *matches, const struct device *dev);
30extern void of_device_make_bus_id(struct device *dev); 14extern void of_device_make_bus_id(struct device *dev);
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index 4e6d989c06df..a68716ad38ce 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -19,9 +19,17 @@
19#include <linux/of_device.h> 19#include <linux/of_device.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21 21
22/* 22/**
23 * An of_platform_driver driver is attached to a basic of_device on 23 * of_platform_driver - Legacy of-aware driver for platform devices.
24 * the "platform bus" (platform_bus_type). 24 *
25 * An of_platform_driver driver is attached to a basic platform_device on
26 * ether the "platform bus" (platform_bus_type), or the ibm ebus
27 * (ibmebus_bus_type).
28 *
29 * of_platform_driver is being phased out when used with the platform_bus_type,
30 * and regular platform_drivers should be used instead. When the transition
31 * is complete, only ibmebus will be using this structure, and the
32 * platform_driver member of this structure will be removed.
25 */ 33 */
26struct of_platform_driver 34struct of_platform_driver
27{ 35{
diff --git a/include/linux/oom.h b/include/linux/oom.h
index f209b683e118..5e3aa8311c5e 100644
--- a/include/linux/oom.h
+++ b/include/linux/oom.h
@@ -66,6 +66,8 @@ static inline void oom_killer_enable(void)
66extern unsigned long badness(struct task_struct *p, struct mem_cgroup *mem, 66extern unsigned long badness(struct task_struct *p, struct mem_cgroup *mem,
67 const nodemask_t *nodemask, unsigned long uptime); 67 const nodemask_t *nodemask, unsigned long uptime);
68 68
69extern struct task_struct *find_lock_task_mm(struct task_struct *p);
70
69/* sysctls */ 71/* sysctls */
70extern int sysctl_oom_dump_tasks; 72extern int sysctl_oom_dump_tasks;
71extern int sysctl_oom_kill_allocating_task; 73extern int sysctl_oom_kill_allocating_task;
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 78a702ce4fcb..e12cdc6d79ee 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -13,6 +13,7 @@
13#include <linux/gfp.h> 13#include <linux/gfp.h>
14#include <linux/bitops.h> 14#include <linux/bitops.h>
15#include <linux/hardirq.h> /* for in_interrupt() */ 15#include <linux/hardirq.h> /* for in_interrupt() */
16#include <linux/hugetlb_inline.h>
16 17
17/* 18/*
18 * Bits in mapping->flags. The lower __GFP_BITS_SHIFT bits are the page 19 * Bits in mapping->flags. The lower __GFP_BITS_SHIFT bits are the page
@@ -281,10 +282,16 @@ static inline loff_t page_offset(struct page *page)
281 return ((loff_t)page->index) << PAGE_CACHE_SHIFT; 282 return ((loff_t)page->index) << PAGE_CACHE_SHIFT;
282} 283}
283 284
285extern pgoff_t linear_hugepage_index(struct vm_area_struct *vma,
286 unsigned long address);
287
284static inline pgoff_t linear_page_index(struct vm_area_struct *vma, 288static inline pgoff_t linear_page_index(struct vm_area_struct *vma,
285 unsigned long address) 289 unsigned long address)
286{ 290{
287 pgoff_t pgoff = (address - vma->vm_start) >> PAGE_SHIFT; 291 pgoff_t pgoff;
292 if (unlikely(is_vm_hugetlb_page(vma)))
293 return linear_hugepage_index(vma, address);
294 pgoff = (address - vma->vm_start) >> PAGE_SHIFT;
288 pgoff += vma->vm_pgoff; 295 pgoff += vma->vm_pgoff;
289 return pgoff >> (PAGE_CACHE_SHIFT - PAGE_SHIFT); 296 return pgoff >> (PAGE_CACHE_SHIFT - PAGE_SHIFT);
290} 297}
diff --git a/include/linux/path.h b/include/linux/path.h
index 915e0c382a51..edc98dec6266 100644
--- a/include/linux/path.h
+++ b/include/linux/path.h
@@ -12,4 +12,9 @@ struct path {
12extern void path_get(struct path *); 12extern void path_get(struct path *);
13extern void path_put(struct path *); 13extern void path_put(struct path *);
14 14
15static inline int path_equal(const struct path *path1, const struct path *path2)
16{
17 return path1->mnt == path2->mnt && path1->dentry == path2->dentry;
18}
19
15#endif /* _LINUX_PATH_H */ 20#endif /* _LINUX_PATH_H */
diff --git a/include/linux/poison.h b/include/linux/poison.h
index 34066ffd893d..2110a81c5e2a 100644
--- a/include/linux/poison.h
+++ b/include/linux/poison.h
@@ -48,15 +48,6 @@
48#define POISON_FREE 0x6b /* for use-after-free poisoning */ 48#define POISON_FREE 0x6b /* for use-after-free poisoning */
49#define POISON_END 0xa5 /* end-byte of poisoning */ 49#define POISON_END 0xa5 /* end-byte of poisoning */
50 50
51/********** mm/hugetlb.c **********/
52/*
53 * Private mappings of hugetlb pages use this poisoned value for
54 * page->mapping. The core VM should not be doing anything with this mapping
55 * but futex requires the existence of some page->mapping value even though it
56 * is unused if PAGE_MAPPING_ANON is set.
57 */
58#define HUGETLB_POISON ((void *)(0x00300300 + POISON_POINTER_DELTA + PAGE_MAPPING_ANON))
59
60/********** arch/$ARCH/mm/init.c **********/ 51/********** arch/$ARCH/mm/init.c **********/
61#define POISON_FREE_INITMEM 0xcc 52#define POISON_FREE_INITMEM 0xcc
62 53
diff --git a/include/linux/raid/pq.h b/include/linux/raid/pq.h
index 1cbbd2c11aa9..2b59cc824395 100644
--- a/include/linux/raid/pq.h
+++ b/include/linux/raid/pq.h
@@ -62,7 +62,9 @@ extern const char raid6_empty_zero_page[PAGE_SIZE];
62#define disable_kernel_altivec() 62#define disable_kernel_altivec()
63 63
64#define EXPORT_SYMBOL(sym) 64#define EXPORT_SYMBOL(sym)
65#define EXPORT_SYMBOL_GPL(sym)
65#define MODULE_LICENSE(licence) 66#define MODULE_LICENSE(licence)
67#define MODULE_DESCRIPTION(desc)
66#define subsys_initcall(x) 68#define subsys_initcall(x)
67#define module_exit(x) 69#define module_exit(x)
68#endif /* __KERNEL__ */ 70#endif /* __KERNEL__ */
diff --git a/include/linux/regulator/ab8500.h b/include/linux/regulator/ab8500.h
new file mode 100644
index 000000000000..f509877c2ed4
--- /dev/null
+++ b/include/linux/regulator/ab8500.h
@@ -0,0 +1,25 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License v2
5 *
6 * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
7 *
8 */
9
10#ifndef __LINUX_MFD_AB8500_REGULATOR_H
11#define __LINUX_MFD_AB8500_REGULATOR_H
12
13/* AB8500 regulators */
14#define AB8500_LDO_AUX1 0
15#define AB8500_LDO_AUX2 1
16#define AB8500_LDO_AUX3 2
17#define AB8500_LDO_INTCORE 3
18#define AB8500_LDO_TVOUT 4
19#define AB8500_LDO_AUDIO 5
20#define AB8500_LDO_ANAMIC1 6
21#define AB8500_LDO_ANAMIC2 7
22#define AB8500_LDO_DMIC 8
23#define AB8500_LDO_ANA 9
24
25#endif
diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index d6661de56f30..31b2fd75dcba 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -168,6 +168,11 @@ void page_add_new_anon_rmap(struct page *, struct vm_area_struct *, unsigned lon
168void page_add_file_rmap(struct page *); 168void page_add_file_rmap(struct page *);
169void page_remove_rmap(struct page *); 169void page_remove_rmap(struct page *);
170 170
171void hugepage_add_anon_rmap(struct page *, struct vm_area_struct *,
172 unsigned long);
173void hugepage_add_new_anon_rmap(struct page *, struct vm_area_struct *,
174 unsigned long);
175
171static inline void page_dup_rmap(struct page *page) 176static inline void page_dup_rmap(struct page *page)
172{ 177{
173 atomic_inc(&page->_mapcount); 178 atomic_inc(&page->_mapcount);
diff --git a/include/linux/s3c_adc_battery.h b/include/linux/s3c_adc_battery.h
new file mode 100644
index 000000000000..dbce22faa660
--- /dev/null
+++ b/include/linux/s3c_adc_battery.h
@@ -0,0 +1,36 @@
1#ifndef _S3C_ADC_BATTERY_H
2#define _S3C_ADC_BATTERY_H
3
4struct s3c_adc_bat_thresh {
5 int volt; /* mV */
6 int cur; /* mA */
7 int level; /* percent */
8};
9
10struct s3c_adc_bat_pdata {
11 int (*init)(void);
12 void (*exit)(void);
13 void (*enable_charger)(void);
14 void (*disable_charger)(void);
15
16 int gpio_charge_finished;
17
18 const struct s3c_adc_bat_thresh *lut_noac;
19 unsigned int lut_noac_cnt;
20 const struct s3c_adc_bat_thresh *lut_acin;
21 unsigned int lut_acin_cnt;
22
23 const unsigned int volt_channel;
24 const unsigned int current_channel;
25 const unsigned int backup_volt_channel;
26
27 const unsigned int volt_mult;
28 const unsigned int current_mult;
29 const unsigned int backup_volt_mult;
30 const unsigned int internal_impedance;
31
32 const unsigned int backup_volt_max;
33 const unsigned int backup_volt_min;
34};
35
36#endif
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 8129ca2d57e3..3c2ad99fed34 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -186,6 +186,9 @@
186#define PORT_ALTERA_JTAGUART 91 186#define PORT_ALTERA_JTAGUART 91
187#define PORT_ALTERA_UART 92 187#define PORT_ALTERA_UART 92
188 188
189/* SH-SCI */
190#define PORT_SCIFB 93
191
189/* MAX3107 */ 192/* MAX3107 */
190#define PORT_MAX3107 94 193#define PORT_MAX3107 94
191 194
diff --git a/include/linux/sh_clk.h b/include/linux/sh_clk.h
index 1636d1e2a5f1..875ce50719a9 100644
--- a/include/linux/sh_clk.h
+++ b/include/linux/sh_clk.h
@@ -25,6 +25,10 @@ struct clk {
25 int id; 25 int id;
26 26
27 struct clk *parent; 27 struct clk *parent;
28 struct clk **parent_table; /* list of parents to */
29 unsigned short parent_num; /* choose between */
30 unsigned char src_shift; /* source clock field in the */
31 unsigned char src_width; /* configuration register */
28 struct clk_ops *ops; 32 struct clk_ops *ops;
29 33
30 struct list_head children; 34 struct list_head children;
@@ -138,13 +142,22 @@ int sh_clk_div4_enable_register(struct clk *clks, int nr,
138int sh_clk_div4_reparent_register(struct clk *clks, int nr, 142int sh_clk_div4_reparent_register(struct clk *clks, int nr,
139 struct clk_div4_table *table); 143 struct clk_div4_table *table);
140 144
141#define SH_CLK_DIV6(_parent, _reg, _flags) \ 145#define SH_CLK_DIV6_EXT(_parent, _reg, _flags, _parents, \
142{ \ 146 _num_parents, _src_shift, _src_width) \
143 .parent = _parent, \ 147{ \
144 .enable_reg = (void __iomem *)_reg, \ 148 .parent = _parent, \
145 .flags = _flags, \ 149 .enable_reg = (void __iomem *)_reg, \
150 .flags = _flags, \
151 .parent_table = _parents, \
152 .parent_num = _num_parents, \
153 .src_shift = _src_shift, \
154 .src_width = _src_width, \
146} 155}
147 156
157#define SH_CLK_DIV6(_parent, _reg, _flags) \
158 SH_CLK_DIV6_EXT(_parent, _reg, _flags, NULL, 0, 0, 0)
159
148int sh_clk_div6_register(struct clk *clks, int nr); 160int sh_clk_div6_register(struct clk *clks, int nr);
161int sh_clk_div6_reparent_register(struct clk *clks, int nr);
149 162
150#endif /* __SH_CLOCK_H */ 163#endif /* __SH_CLOCK_H */
diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
index 1acfa73ce2ac..791a502f6906 100644
--- a/include/linux/slab_def.h
+++ b/include/linux/slab_def.h
@@ -17,7 +17,6 @@
17 17
18#include <trace/events/kmem.h> 18#include <trace/events/kmem.h>
19 19
20#ifndef ARCH_KMALLOC_MINALIGN
21/* 20/*
22 * Enforce a minimum alignment for the kmalloc caches. 21 * Enforce a minimum alignment for the kmalloc caches.
23 * Usually, the kmalloc caches are cache_line_size() aligned, except when 22 * Usually, the kmalloc caches are cache_line_size() aligned, except when
@@ -27,6 +26,9 @@
27 * ARCH_KMALLOC_MINALIGN allows that. 26 * ARCH_KMALLOC_MINALIGN allows that.
28 * Note that increasing this value may disable some debug features. 27 * Note that increasing this value may disable some debug features.
29 */ 28 */
29#ifdef ARCH_DMA_MINALIGN
30#define ARCH_KMALLOC_MINALIGN ARCH_DMA_MINALIGN
31#else
30#define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long) 32#define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long)
31#endif 33#endif
32 34
diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
index 62667f72c2ef..4382db09df4f 100644
--- a/include/linux/slob_def.h
+++ b/include/linux/slob_def.h
@@ -1,7 +1,9 @@
1#ifndef __LINUX_SLOB_DEF_H 1#ifndef __LINUX_SLOB_DEF_H
2#define __LINUX_SLOB_DEF_H 2#define __LINUX_SLOB_DEF_H
3 3
4#ifndef ARCH_KMALLOC_MINALIGN 4#ifdef ARCH_DMA_MINALIGN
5#define ARCH_KMALLOC_MINALIGN ARCH_DMA_MINALIGN
6#else
5#define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long) 7#define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long)
6#endif 8#endif
7 9
diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
index 6447a723ecb1..6d14409c4d9a 100644
--- a/include/linux/slub_def.h
+++ b/include/linux/slub_def.h
@@ -106,15 +106,17 @@ struct kmem_cache {
106/* 106/*
107 * Kmalloc subsystem. 107 * Kmalloc subsystem.
108 */ 108 */
109#if defined(ARCH_KMALLOC_MINALIGN) && ARCH_KMALLOC_MINALIGN > 8 109#if defined(ARCH_DMA_MINALIGN) && ARCH_DMA_MINALIGN > 8
110#define KMALLOC_MIN_SIZE ARCH_KMALLOC_MINALIGN 110#define KMALLOC_MIN_SIZE ARCH_DMA_MINALIGN
111#else 111#else
112#define KMALLOC_MIN_SIZE 8 112#define KMALLOC_MIN_SIZE 8
113#endif 113#endif
114 114
115#define KMALLOC_SHIFT_LOW ilog2(KMALLOC_MIN_SIZE) 115#define KMALLOC_SHIFT_LOW ilog2(KMALLOC_MIN_SIZE)
116 116
117#ifndef ARCH_KMALLOC_MINALIGN 117#ifdef ARCH_DMA_MINALIGN
118#define ARCH_KMALLOC_MINALIGN ARCH_DMA_MINALIGN
119#else
118#define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long) 120#define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long)
119#endif 121#endif
120 122
diff --git a/include/linux/spi/max7301.h b/include/linux/spi/max7301.h
index 34af0a3477bf..bcaa2f762cc1 100644
--- a/include/linux/spi/max7301.h
+++ b/include/linux/spi/max7301.h
@@ -11,6 +11,7 @@ struct max7301 {
11 struct mutex lock; 11 struct mutex lock;
12 u8 port_config[8]; /* field 0 is unused */ 12 u8 port_config[8]; /* field 0 is unused */
13 u32 out_level; /* cached output levels */ 13 u32 out_level; /* cached output levels */
14 u32 input_pullup_active;
14 struct gpio_chip chip; 15 struct gpio_chip chip;
15 struct device *dev; 16 struct device *dev;
16 int (*write)(struct device *dev, unsigned int reg, unsigned int val); 17 int (*write)(struct device *dev, unsigned int reg, unsigned int val);
@@ -20,6 +21,13 @@ struct max7301 {
20struct max7301_platform_data { 21struct max7301_platform_data {
21 /* number assigned to the first GPIO */ 22 /* number assigned to the first GPIO */
22 unsigned base; 23 unsigned base;
24 /*
25 * bitmask controlling the pullup configuration,
26 *
27 * _note_ the 4 lowest bits are unused, because the first 4
28 * ports of the controller are not used, too.
29 */
30 u32 input_pullup_active;
23}; 31};
24 32
25extern int __max730x_remove(struct device *dev); 33extern int __max730x_remove(struct device *dev);
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 91c9d3fc8513..2fee51a11b73 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -244,8 +244,7 @@ extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem,
244extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, 244extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
245 gfp_t gfp_mask, bool noswap, 245 gfp_t gfp_mask, bool noswap,
246 unsigned int swappiness, 246 unsigned int swappiness,
247 struct zone *zone, 247 struct zone *zone);
248 int nid);
249extern int __isolate_lru_page(struct page *page, int mode, int file); 248extern int __isolate_lru_page(struct page *page, int mode, int file);
250extern unsigned long shrink_all_memory(unsigned long nr_pages); 249extern unsigned long shrink_all_memory(unsigned long nr_pages);
251extern int vm_swappiness; 250extern int vm_swappiness;
diff --git a/include/linux/sysv_fs.h b/include/linux/sysv_fs.h
index 96411306eec6..e47d6d90023d 100644
--- a/include/linux/sysv_fs.h
+++ b/include/linux/sysv_fs.h
@@ -148,6 +148,17 @@ struct v7_super_block {
148 char s_fname[6]; /* file system name */ 148 char s_fname[6]; /* file system name */
149 char s_fpack[6]; /* file system pack name */ 149 char s_fpack[6]; /* file system pack name */
150}; 150};
151/* Constants to aid sanity checking */
152/* This is not a hard limit, nor enforced by v7 kernel. It's actually just
153 * the limit used by Seventh Edition's ls, though is high enough to assume
154 * that no reasonable file system would have that much entries in root
155 * directory. Thus, if we see anything higher, we just probably got the
156 * endiannes wrong. */
157#define V7_NFILES 1024
158/* The disk addresses are three-byte (despite direct block addresses being
159 * aligned word-wise in inode). If the most significant byte is non-zero,
160 * something is most likely wrong (not a filesystem, bad bytesex). */
161#define V7_MAXSIZE 0x00ffffff
151 162
152/* Coherent super-block data on disk */ 163/* Coherent super-block data on disk */
153#define COH_NICINOD 100 /* number of inode cache entries */ 164#define COH_NICINOD 100 /* number of inode cache entries */
diff --git a/include/linux/time.h b/include/linux/time.h
index cb34e35fabac..12612701b1ae 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -38,7 +38,7 @@ extern struct timezone sys_tz;
38#define NSEC_PER_MSEC 1000000L 38#define NSEC_PER_MSEC 1000000L
39#define USEC_PER_SEC 1000000L 39#define USEC_PER_SEC 1000000L
40#define NSEC_PER_SEC 1000000000L 40#define NSEC_PER_SEC 1000000000L
41#define FSEC_PER_SEC 1000000000000000L 41#define FSEC_PER_SEC 1000000000000000LL
42 42
43#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1) 43#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)
44 44
diff --git a/include/linux/vgaarb.h b/include/linux/vgaarb.h
index 814f294d4cd0..6228b5b77d35 100644
--- a/include/linux/vgaarb.h
+++ b/include/linux/vgaarb.h
@@ -31,7 +31,6 @@
31#ifndef LINUX_VGA_H 31#ifndef LINUX_VGA_H
32#define LINUX_VGA_H 32#define LINUX_VGA_H
33 33
34#include <asm/vga.h>
35 34
36/* Legacy VGA regions */ 35/* Legacy VGA regions */
37#define VGA_RSRC_NONE 0x00 36#define VGA_RSRC_NONE 0x00
diff --git a/include/linux/virtio_9p.h b/include/linux/virtio_9p.h
index 395c38a47adb..1faa80d92f05 100644
--- a/include/linux/virtio_9p.h
+++ b/include/linux/virtio_9p.h
@@ -2,6 +2,7 @@
2#define _LINUX_VIRTIO_9P_H 2#define _LINUX_VIRTIO_9P_H
3/* This header is BSD licensed so anyone can use the definitions to implement 3/* This header is BSD licensed so anyone can use the definitions to implement
4 * compatible drivers/servers. */ 4 * compatible drivers/servers. */
5#include <linux/types.h>
5#include <linux/virtio_ids.h> 6#include <linux/virtio_ids.h>
6#include <linux/virtio_config.h> 7#include <linux/virtio_config.h>
7#include <linux/types.h> 8#include <linux/types.h>
diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index de05e96e0a70..01c2145118dc 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -7,6 +7,8 @@
7 7
8struct vm_area_struct; /* vma defining user mapping in mm_types.h */ 8struct vm_area_struct; /* vma defining user mapping in mm_types.h */
9 9
10extern bool vmap_lazy_unmap;
11
10/* bits in flags of vmalloc's vm_struct below */ 12/* bits in flags of vmalloc's vm_struct below */
11#define VM_IOREMAP 0x00000001 /* ioremap() and friends */ 13#define VM_IOREMAP 0x00000001 /* ioremap() and friends */
12#define VM_ALLOC 0x00000002 /* vmalloc() */ 14#define VM_ALLOC 0x00000002 /* vmalloc() */
diff --git a/include/linux/wm97xx_batt.h b/include/linux/wm97xx_batt.h
deleted file mode 100644
index a1d6419c2ff8..000000000000
--- a/include/linux/wm97xx_batt.h
+++ /dev/null
@@ -1,16 +0,0 @@
1#ifndef _LINUX_WM97XX_BAT_H
2#define _LINUX_WM97XX_BAT_H
3
4#include <linux/wm97xx.h>
5
6#warning This file will be removed soon, use wm97xx.h instead!
7
8#define wm97xx_batt_info wm97xx_batt_pdata
9
10#ifdef CONFIG_BATTERY_WM97XX
11void wm97xx_bat_set_pdata(struct wm97xx_batt_info *data);
12#else
13static inline void wm97xx_bat_set_pdata(struct wm97xx_batt_info *data) {}
14#endif
15
16#endif
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index c24eca71e80c..72a5d647a5f2 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -124,8 +124,9 @@ struct ctl_table;
124int dirty_writeback_centisecs_handler(struct ctl_table *, int, 124int dirty_writeback_centisecs_handler(struct ctl_table *, int,
125 void __user *, size_t *, loff_t *); 125 void __user *, size_t *, loff_t *);
126 126
127void get_dirty_limits(unsigned long *pbackground, unsigned long *pdirty, 127void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty);
128 unsigned long *pbdi_dirty, struct backing_dev_info *bdi); 128unsigned long bdi_dirty_limit(struct backing_dev_info *bdi,
129 unsigned long dirty);
129 130
130void page_writeback_init(void); 131void page_writeback_init(void);
131void balance_dirty_pages_ratelimited_nr(struct address_space *mapping, 132void balance_dirty_pages_ratelimited_nr(struct address_space *mapping,
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 636724b203ee..6c241444f902 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -33,9 +33,9 @@
33#define L2CAP_DEFAULT_FLUSH_TO 0xffff 33#define L2CAP_DEFAULT_FLUSH_TO 0xffff
34#define L2CAP_DEFAULT_TX_WINDOW 63 34#define L2CAP_DEFAULT_TX_WINDOW 63
35#define L2CAP_DEFAULT_MAX_TX 3 35#define L2CAP_DEFAULT_MAX_TX 3
36#define L2CAP_DEFAULT_RETRANS_TO 1000 /* 1 second */ 36#define L2CAP_DEFAULT_RETRANS_TO 2000 /* 2 seconds */
37#define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */ 37#define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */
38#define L2CAP_DEFAULT_MAX_PDU_SIZE 672 38#define L2CAP_DEFAULT_MAX_PDU_SIZE 1009 /* Sized for 3-DH5 packet */
39#define L2CAP_DEFAULT_ACK_TO 200 39#define L2CAP_DEFAULT_ACK_TO 200
40#define L2CAP_LOCAL_BUSY_TRIES 12 40#define L2CAP_LOCAL_BUSY_TRIES 12
41 41
diff --git a/include/net/sock.h b/include/net/sock.h
index a441c9cdd625..ac53bfbdfe16 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -195,7 +195,8 @@ struct sock_common {
195 * @sk_priority: %SO_PRIORITY setting 195 * @sk_priority: %SO_PRIORITY setting
196 * @sk_type: socket type (%SOCK_STREAM, etc) 196 * @sk_type: socket type (%SOCK_STREAM, etc)
197 * @sk_protocol: which protocol this socket belongs in this network family 197 * @sk_protocol: which protocol this socket belongs in this network family
198 * @sk_peercred: %SO_PEERCRED setting 198 * @sk_peer_pid: &struct pid for this socket's peer
199 * @sk_peer_cred: %SO_PEERCRED setting
199 * @sk_rcvlowat: %SO_RCVLOWAT setting 200 * @sk_rcvlowat: %SO_RCVLOWAT setting
200 * @sk_rcvtimeo: %SO_RCVTIMEO setting 201 * @sk_rcvtimeo: %SO_RCVTIMEO setting
201 * @sk_sndtimeo: %SO_SNDTIMEO setting 202 * @sk_sndtimeo: %SO_SNDTIMEO setting
@@ -211,6 +212,7 @@ struct sock_common {
211 * @sk_send_head: front of stuff to transmit 212 * @sk_send_head: front of stuff to transmit
212 * @sk_security: used by security modules 213 * @sk_security: used by security modules
213 * @sk_mark: generic packet mark 214 * @sk_mark: generic packet mark
215 * @sk_classid: this socket's cgroup classid
214 * @sk_write_pending: a write to stream socket waits to start 216 * @sk_write_pending: a write to stream socket waits to start
215 * @sk_state_change: callback to indicate change in the state of the sock 217 * @sk_state_change: callback to indicate change in the state of the sock
216 * @sk_data_ready: callback to indicate there is data to be processed 218 * @sk_data_ready: callback to indicate there is data to be processed
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index 9ae5c613131b..8fcb6e0e9e72 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -151,10 +151,10 @@ struct scsi_cmnd;
151 151
152/* defined in T10 SCSI Primary Commands-2 (SPC2) */ 152/* defined in T10 SCSI Primary Commands-2 (SPC2) */
153struct scsi_varlen_cdb_hdr { 153struct scsi_varlen_cdb_hdr {
154 u8 opcode; /* opcode always == VARIABLE_LENGTH_CMD */ 154 __u8 opcode; /* opcode always == VARIABLE_LENGTH_CMD */
155 u8 control; 155 __u8 control;
156 u8 misc[5]; 156 __u8 misc[5];
157 u8 additional_cdb_length; /* total cdb length - 8 */ 157 __u8 additional_cdb_length; /* total cdb length - 8 */
158 __be16 service_action; 158 __be16 service_action;
159 /* service specific data follows */ 159 /* service specific data follows */
160}; 160};
diff --git a/include/scsi/scsi_netlink.h b/include/scsi/scsi_netlink.h
index 536752c40d41..58ce8fe44783 100644
--- a/include/scsi/scsi_netlink.h
+++ b/include/scsi/scsi_netlink.h
@@ -105,8 +105,8 @@ struct scsi_nl_host_vendor_msg {
105 * PCI : ID data is the 16 bit PCI Registered Vendor ID 105 * PCI : ID data is the 16 bit PCI Registered Vendor ID
106 */ 106 */
107#define SCSI_NL_VID_TYPE_SHIFT 56 107#define SCSI_NL_VID_TYPE_SHIFT 56
108#define SCSI_NL_VID_TYPE_MASK ((u64)0xFF << SCSI_NL_VID_TYPE_SHIFT) 108#define SCSI_NL_VID_TYPE_MASK ((__u64)0xFF << SCSI_NL_VID_TYPE_SHIFT)
109#define SCSI_NL_VID_TYPE_PCI ((u64)0x01 << SCSI_NL_VID_TYPE_SHIFT) 109#define SCSI_NL_VID_TYPE_PCI ((__u64)0x01 << SCSI_NL_VID_TYPE_SHIFT)
110#define SCSI_NL_VID_ID_MASK (~ SCSI_NL_VID_TYPE_MASK) 110#define SCSI_NL_VID_ID_MASK (~ SCSI_NL_VID_TYPE_MASK)
111 111
112 112
diff --git a/include/video/mipi_display.h b/include/video/mipi_display.h
new file mode 100644
index 000000000000..ddcc8ca7316b
--- /dev/null
+++ b/include/video/mipi_display.h
@@ -0,0 +1,130 @@
1/*
2 * Defines for Mobile Industry Processor Interface (MIPI(R))
3 * Display Working Group standards: DSI, DCS, DBI, DPI
4 *
5 * Copyright (C) 2010 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
6 * Copyright (C) 2006 Nokia Corporation
7 * Author: Imre Deak <imre.deak@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#ifndef MIPI_DISPLAY_H
14#define MIPI_DISPLAY_H
15
16/* MIPI DSI Processor-to-Peripheral transaction types */
17enum {
18 MIPI_DSI_V_SYNC_START = 0x01,
19 MIPI_DSI_V_SYNC_END = 0x11,
20 MIPI_DSI_H_SYNC_START = 0x21,
21 MIPI_DSI_H_SYNC_END = 0x31,
22
23 MIPI_DSI_COLOR_MODE_OFF = 0x02,
24 MIPI_DSI_COLOR_MODE_ON = 0x12,
25 MIPI_DSI_SHUTDOWN_PERIPHERAL = 0x22,
26 MIPI_DSI_TURN_ON_PERIPHERAL = 0x32,
27
28 MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM = 0x03,
29 MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM = 0x13,
30 MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM = 0x23,
31
32 MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM = 0x04,
33 MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM = 0x14,
34 MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM = 0x24,
35
36 MIPI_DSI_DCS_SHORT_WRITE = 0x05,
37 MIPI_DSI_DCS_SHORT_WRITE_PARAM = 0x15,
38
39 MIPI_DSI_DCS_READ = 0x06,
40
41 MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE = 0x37,
42
43 MIPI_DSI_END_OF_TRANSMISSION = 0x08,
44
45 MIPI_DSI_NULL_PACKET = 0x09,
46 MIPI_DSI_BLANKING_PACKET = 0x19,
47 MIPI_DSI_GENERIC_LONG_WRITE = 0x29,
48 MIPI_DSI_DCS_LONG_WRITE = 0x39,
49
50 MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20 = 0x0c,
51 MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24 = 0x1c,
52 MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16 = 0x2c,
53
54 MIPI_DSI_PACKED_PIXEL_STREAM_30 = 0x0d,
55 MIPI_DSI_PACKED_PIXEL_STREAM_36 = 0x1d,
56 MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12 = 0x3d,
57
58 MIPI_DSI_PACKED_PIXEL_STREAM_16 = 0x0e,
59 MIPI_DSI_PACKED_PIXEL_STREAM_18 = 0x1e,
60 MIPI_DSI_PIXEL_STREAM_3BYTE_18 = 0x2e,
61 MIPI_DSI_PACKED_PIXEL_STREAM_24 = 0x3e,
62};
63
64/* MIPI DSI Peripheral-to-Processor transaction types */
65enum {
66 MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT = 0x02,
67 MIPI_DSI_RX_END_OF_TRANSMISSION = 0x08,
68 MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE = 0x11,
69 MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE = 0x12,
70 MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE = 0x1a,
71 MIPI_DSI_RX_DCS_LONG_READ_RESPONSE = 0x1c,
72 MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE = 0x21,
73 MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE = 0x22,
74};
75
76/* MIPI DCS commands */
77enum {
78 MIPI_DCS_NOP = 0x00,
79 MIPI_DCS_SOFT_RESET = 0x01,
80 MIPI_DCS_GET_DISPLAY_ID = 0x04,
81 MIPI_DCS_GET_RED_CHANNEL = 0x06,
82 MIPI_DCS_GET_GREEN_CHANNEL = 0x07,
83 MIPI_DCS_GET_BLUE_CHANNEL = 0x08,
84 MIPI_DCS_GET_DISPLAY_STATUS = 0x09,
85 MIPI_DCS_GET_POWER_MODE = 0x0A,
86 MIPI_DCS_GET_ADDRESS_MODE = 0x0B,
87 MIPI_DCS_GET_PIXEL_FORMAT = 0x0C,
88 MIPI_DCS_GET_DISPLAY_MODE = 0x0D,
89 MIPI_DCS_GET_SIGNAL_MODE = 0x0E,
90 MIPI_DCS_GET_DIAGNOSTIC_RESULT = 0x0F,
91 MIPI_DCS_ENTER_SLEEP_MODE = 0x10,
92 MIPI_DCS_EXIT_SLEEP_MODE = 0x11,
93 MIPI_DCS_ENTER_PARTIAL_MODE = 0x12,
94 MIPI_DCS_ENTER_NORMAL_MODE = 0x13,
95 MIPI_DCS_EXIT_INVERT_MODE = 0x20,
96 MIPI_DCS_ENTER_INVERT_MODE = 0x21,
97 MIPI_DCS_SET_GAMMA_CURVE = 0x26,
98 MIPI_DCS_SET_DISPLAY_OFF = 0x28,
99 MIPI_DCS_SET_DISPLAY_ON = 0x29,
100 MIPI_DCS_SET_COLUMN_ADDRESS = 0x2A,
101 MIPI_DCS_SET_PAGE_ADDRESS = 0x2B,
102 MIPI_DCS_WRITE_MEMORY_START = 0x2C,
103 MIPI_DCS_WRITE_LUT = 0x2D,
104 MIPI_DCS_READ_MEMORY_START = 0x2E,
105 MIPI_DCS_SET_PARTIAL_AREA = 0x30,
106 MIPI_DCS_SET_SCROLL_AREA = 0x33,
107 MIPI_DCS_SET_TEAR_OFF = 0x34,
108 MIPI_DCS_SET_TEAR_ON = 0x35,
109 MIPI_DCS_SET_ADDRESS_MODE = 0x36,
110 MIPI_DCS_SET_SCROLL_START = 0x37,
111 MIPI_DCS_EXIT_IDLE_MODE = 0x38,
112 MIPI_DCS_ENTER_IDLE_MODE = 0x39,
113 MIPI_DCS_SET_PIXEL_FORMAT = 0x3A,
114 MIPI_DCS_WRITE_MEMORY_CONTINUE = 0x3C,
115 MIPI_DCS_READ_MEMORY_CONTINUE = 0x3E,
116 MIPI_DCS_SET_TEAR_SCANLINE = 0x44,
117 MIPI_DCS_GET_SCANLINE = 0x45,
118 MIPI_DCS_READ_DDB_START = 0xA1,
119 MIPI_DCS_READ_DDB_CONTINUE = 0xA8,
120};
121
122/* MIPI DCS pixel formats */
123#define MIPI_DCS_PIXEL_FMT_24BIT 7
124#define MIPI_DCS_PIXEL_FMT_18BIT 6
125#define MIPI_DCS_PIXEL_FMT_16BIT 5
126#define MIPI_DCS_PIXEL_FMT_12BIT 3
127#define MIPI_DCS_PIXEL_FMT_8BIT 2
128#define MIPI_DCS_PIXEL_FMT_3BIT 1
129
130#endif
diff --git a/include/video/sh_mipi_dsi.h b/include/video/sh_mipi_dsi.h
new file mode 100644
index 000000000000..18bca08f9f59
--- /dev/null
+++ b/include/video/sh_mipi_dsi.h
@@ -0,0 +1,35 @@
1/*
2 * Public SH-mobile MIPI DSI header
3 *
4 * Copyright (C) 2010 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
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#ifndef VIDEO_SH_MIPI_DSI_H
11#define VIDEO_SH_MIPI_DSI_H
12
13enum sh_mipi_dsi_data_fmt {
14 MIPI_RGB888,
15 MIPI_RGB565,
16 MIPI_RGB666_LP,
17 MIPI_RGB666,
18 MIPI_BGR888,
19 MIPI_BGR565,
20 MIPI_BGR666_LP,
21 MIPI_BGR666,
22 MIPI_YUYV,
23 MIPI_UYVY,
24 MIPI_YUV420_L,
25 MIPI_YUV420,
26};
27
28struct sh_mobile_lcdc_chan_cfg;
29
30struct sh_mipi_dsi_info {
31 enum sh_mipi_dsi_data_fmt data_format;
32 struct sh_mobile_lcdc_chan_cfg *lcd_chan;
33};
34
35#endif
diff --git a/include/video/sh_mobile_hdmi.h b/include/video/sh_mobile_hdmi.h
new file mode 100644
index 000000000000..577cf18cce89
--- /dev/null
+++ b/include/video/sh_mobile_hdmi.h
@@ -0,0 +1,22 @@
1/*
2 * SH-Mobile High-Definition Multimedia Interface (HDMI)
3 *
4 * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef SH_MOBILE_HDMI_H
12#define SH_MOBILE_HDMI_H
13
14struct sh_mobile_lcdc_chan_cfg;
15struct device;
16
17struct sh_mobile_hdmi_info {
18 struct sh_mobile_lcdc_chan_cfg *lcd_chan;
19 struct device *lcd_dev;
20};
21
22#endif
diff --git a/include/video/sh_mobile_lcdc.h b/include/video/sh_mobile_lcdc.h
index 288205457713..55d700e8566e 100644
--- a/include/video/sh_mobile_lcdc.h
+++ b/include/video/sh_mobile_lcdc.h
@@ -3,24 +3,27 @@
3 3
4#include <linux/fb.h> 4#include <linux/fb.h>
5 5
6enum { RGB8, /* 24bpp, 8:8:8 */ 6enum {
7 RGB9, /* 18bpp, 9:9 */ 7 RGB8, /* 24bpp, 8:8:8 */
8 RGB12A, /* 24bpp, 12:12 */ 8 RGB9, /* 18bpp, 9:9 */
9 RGB12B, /* 12bpp */ 9 RGB12A, /* 24bpp, 12:12 */
10 RGB16, /* 16bpp */ 10 RGB12B, /* 12bpp */
11 RGB18, /* 18bpp */ 11 RGB16, /* 16bpp */
12 RGB24, /* 24bpp */ 12 RGB18, /* 18bpp */
13 SYS8A, /* 24bpp, 8:8:8 */ 13 RGB24, /* 24bpp */
14 SYS8B, /* 18bpp, 8:8:2 */ 14 YUV422, /* 16bpp */
15 SYS8C, /* 18bpp, 2:8:8 */ 15 SYS8A, /* 24bpp, 8:8:8 */
16 SYS8D, /* 16bpp, 8:8 */ 16 SYS8B, /* 18bpp, 8:8:2 */
17 SYS9, /* 18bpp, 9:9 */ 17 SYS8C, /* 18bpp, 2:8:8 */
18 SYS12, /* 24bpp, 12:12 */ 18 SYS8D, /* 16bpp, 8:8 */
19 SYS16A, /* 16bpp */ 19 SYS9, /* 18bpp, 9:9 */
20 SYS16B, /* 18bpp, 16:2 */ 20 SYS12, /* 24bpp, 12:12 */
21 SYS16C, /* 18bpp, 2:16 */ 21 SYS16A, /* 16bpp */
22 SYS18, /* 18bpp */ 22 SYS16B, /* 18bpp, 16:2 */
23 SYS24 };/* 24bpp */ 23 SYS16C, /* 18bpp, 2:16 */
24 SYS18, /* 18bpp */
25 SYS24, /* 24bpp */
26};
24 27
25enum { LCDC_CHAN_DISABLED = 0, 28enum { LCDC_CHAN_DISABLED = 0,
26 LCDC_CHAN_MAINLCD, 29 LCDC_CHAN_MAINLCD,
@@ -52,7 +55,7 @@ struct sh_mobile_lcdc_board_cfg {
52 struct sh_mobile_lcdc_sys_bus_ops *sys_ops); 55 struct sh_mobile_lcdc_sys_bus_ops *sys_ops);
53 void (*start_transfer)(void *board_data, void *sys_ops_handle, 56 void (*start_transfer)(void *board_data, void *sys_ops_handle,
54 struct sh_mobile_lcdc_sys_bus_ops *sys_ops); 57 struct sh_mobile_lcdc_sys_bus_ops *sys_ops);
55 void (*display_on)(void *board_data); 58 void (*display_on)(void *board_data, struct fb_info *info);
56 void (*display_off)(void *board_data); 59 void (*display_off)(void *board_data);
57}; 60};
58 61
diff --git a/include/xen/interface/memory.h b/include/xen/interface/memory.h
index af36ead16817..d3938d3e71f8 100644
--- a/include/xen/interface/memory.h
+++ b/include/xen/interface/memory.h
@@ -9,6 +9,8 @@
9#ifndef __XEN_PUBLIC_MEMORY_H__ 9#ifndef __XEN_PUBLIC_MEMORY_H__
10#define __XEN_PUBLIC_MEMORY_H__ 10#define __XEN_PUBLIC_MEMORY_H__
11 11
12#include <linux/spinlock.h>
13
12/* 14/*
13 * Increase or decrease the specified domain's memory reservation. Returns a 15 * Increase or decrease the specified domain's memory reservation. Returns a
14 * -ve errcode on failure, or the # extents successfully allocated or freed. 16 * -ve errcode on failure, or the # extents successfully allocated or freed.
@@ -53,6 +55,48 @@ struct xen_memory_reservation {
53DEFINE_GUEST_HANDLE_STRUCT(xen_memory_reservation); 55DEFINE_GUEST_HANDLE_STRUCT(xen_memory_reservation);
54 56
55/* 57/*
58 * An atomic exchange of memory pages. If return code is zero then
59 * @out.extent_list provides GMFNs of the newly-allocated memory.
60 * Returns zero on complete success, otherwise a negative error code.
61 * On complete success then always @nr_exchanged == @in.nr_extents.
62 * On partial success @nr_exchanged indicates how much work was done.
63 */
64#define XENMEM_exchange 11
65struct xen_memory_exchange {
66 /*
67 * [IN] Details of memory extents to be exchanged (GMFN bases).
68 * Note that @in.address_bits is ignored and unused.
69 */
70 struct xen_memory_reservation in;
71
72 /*
73 * [IN/OUT] Details of new memory extents.
74 * We require that:
75 * 1. @in.domid == @out.domid
76 * 2. @in.nr_extents << @in.extent_order ==
77 * @out.nr_extents << @out.extent_order
78 * 3. @in.extent_start and @out.extent_start lists must not overlap
79 * 4. @out.extent_start lists GPFN bases to be populated
80 * 5. @out.extent_start is overwritten with allocated GMFN bases
81 */
82 struct xen_memory_reservation out;
83
84 /*
85 * [OUT] Number of input extents that were successfully exchanged:
86 * 1. The first @nr_exchanged input extents were successfully
87 * deallocated.
88 * 2. The corresponding first entries in the output extent list correctly
89 * indicate the GMFNs that were successfully exchanged.
90 * 3. All other input and output extents are untouched.
91 * 4. If not all input exents are exchanged then the return code of this
92 * command will be non-zero.
93 * 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
94 */
95 unsigned long nr_exchanged;
96};
97
98DEFINE_GUEST_HANDLE_STRUCT(xen_memory_exchange);
99/*
56 * Returns the maximum machine frame number of mapped RAM in this system. 100 * Returns the maximum machine frame number of mapped RAM in this system.
57 * This command always succeeds (it never returns an error code). 101 * This command always succeeds (it never returns an error code).
58 * arg == NULL. 102 * arg == NULL.
@@ -142,4 +186,10 @@ struct xen_translate_gpfn_list {
142}; 186};
143DEFINE_GUEST_HANDLE_STRUCT(xen_translate_gpfn_list); 187DEFINE_GUEST_HANDLE_STRUCT(xen_translate_gpfn_list);
144 188
189
190/*
191 * Prevent the balloon driver from changing the memory reservation
192 * during a driver critical region.
193 */
194extern spinlock_t xen_reservation_lock;
145#endif /* __XEN_PUBLIC_MEMORY_H__ */ 195#endif /* __XEN_PUBLIC_MEMORY_H__ */
diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h
new file mode 100644
index 000000000000..2ea2fdc79c16
--- /dev/null
+++ b/include/xen/swiotlb-xen.h
@@ -0,0 +1,65 @@
1#ifndef __LINUX_SWIOTLB_XEN_H
2#define __LINUX_SWIOTLB_XEN_H
3
4#include <linux/swiotlb.h>
5
6extern void xen_swiotlb_init(int verbose);
7
8extern void
9*xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
10 dma_addr_t *dma_handle, gfp_t flags);
11
12extern void
13xen_swiotlb_free_coherent(struct device *hwdev, size_t size,
14 void *vaddr, dma_addr_t dma_handle);
15
16extern dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
17 unsigned long offset, size_t size,
18 enum dma_data_direction dir,
19 struct dma_attrs *attrs);
20
21extern void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr,
22 size_t size, enum dma_data_direction dir,
23 struct dma_attrs *attrs);
24/*
25extern int
26xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sg, int nents,
27 enum dma_data_direction dir);
28
29extern void
30xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
31 enum dma_data_direction dir);
32*/
33extern int
34xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
35 int nelems, enum dma_data_direction dir,
36 struct dma_attrs *attrs);
37
38extern void
39xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
40 int nelems, enum dma_data_direction dir,
41 struct dma_attrs *attrs);
42
43extern void
44xen_swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
45 size_t size, enum dma_data_direction dir);
46
47extern void
48xen_swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
49 int nelems, enum dma_data_direction dir);
50
51extern void
52xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
53 size_t size, enum dma_data_direction dir);
54
55extern void
56xen_swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
57 int nelems, enum dma_data_direction dir);
58
59extern int
60xen_swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr);
61
62extern int
63xen_swiotlb_dma_supported(struct device *hwdev, u64 mask);
64
65#endif /* __LINUX_SWIOTLB_XEN_H */
diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h
index 46bc81ef74c6..351f4051f6d8 100644
--- a/include/xen/xen-ops.h
+++ b/include/xen/xen-ops.h
@@ -17,4 +17,10 @@ void xen_arch_resume(void);
17 17
18int xen_setup_shutdown_event(void); 18int xen_setup_shutdown_event(void);
19 19
20extern unsigned long *xen_contiguous_bitmap;
21int xen_create_contiguous_region(unsigned long vstart, unsigned int order,
22 unsigned int address_bits);
23
24void xen_destroy_contiguous_region(unsigned long vstart, unsigned int order);
25
20#endif /* INCLUDE_XEN_OPS_H */ 26#endif /* INCLUDE_XEN_OPS_H */
diff --git a/init/Kconfig b/init/Kconfig
index 24932b9c03e8..2de5b1cbadd9 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -577,8 +577,8 @@ config CGROUP_MEM_RES_CTLR
577 could in turn add some fork/exit overhead. 577 could in turn add some fork/exit overhead.
578 578
579config CGROUP_MEM_RES_CTLR_SWAP 579config CGROUP_MEM_RES_CTLR_SWAP
580 bool "Memory Resource Controller Swap Extension(EXPERIMENTAL)" 580 bool "Memory Resource Controller Swap Extension"
581 depends on CGROUP_MEM_RES_CTLR && SWAP && EXPERIMENTAL 581 depends on CGROUP_MEM_RES_CTLR && SWAP
582 help 582 help
583 Add swap management feature to memory resource controller. When you 583 Add swap management feature to memory resource controller. When you
584 enable this, you can limit mem+swap usage per cgroup. In other words, 584 enable this, you can limit mem+swap usage per cgroup. In other words,
diff --git a/init/main.c b/init/main.c
index 86cbfd085b01..22d61cb06f98 100644
--- a/init/main.c
+++ b/init/main.c
@@ -201,11 +201,11 @@ static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
201char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, }; 201char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
202static const char *panic_later, *panic_param; 202static const char *panic_later, *panic_param;
203 203
204extern struct obs_kernel_param __setup_start[], __setup_end[]; 204extern const struct obs_kernel_param __setup_start[], __setup_end[];
205 205
206static int __init obsolete_checksetup(char *line) 206static int __init obsolete_checksetup(char *line)
207{ 207{
208 struct obs_kernel_param *p; 208 const struct obs_kernel_param *p;
209 int had_early_param = 0; 209 int had_early_param = 0;
210 210
211 p = __setup_start; 211 p = __setup_start;
@@ -458,7 +458,7 @@ static noinline void __init_refok rest_init(void)
458/* Check for early params. */ 458/* Check for early params. */
459static int __init do_early_param(char *param, char *val) 459static int __init do_early_param(char *param, char *val)
460{ 460{
461 struct obs_kernel_param *p; 461 const struct obs_kernel_param *p;
462 462
463 for (p = __setup_start; p < __setup_end; p++) { 463 for (p = __setup_start; p < __setup_end; p++) {
464 if ((p->early && strcmp(param, p->str) == 0) || 464 if ((p->early && strcmp(param, p->str) == 0) ||
@@ -536,7 +536,7 @@ static void __init mm_init(void)
536asmlinkage void __init start_kernel(void) 536asmlinkage void __init start_kernel(void)
537{ 537{
538 char * command_line; 538 char * command_line;
539 extern struct kernel_param __start___param[], __stop___param[]; 539 extern const struct kernel_param __start___param[], __stop___param[];
540 540
541 smp_setup_processor_id(); 541 smp_setup_processor_id();
542 542
diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c
index 6bf2306be7d6..f0c9b2e7542d 100644
--- a/kernel/audit_watch.c
+++ b/kernel/audit_watch.c
@@ -526,8 +526,8 @@ static int audit_watch_handle_event(struct fsnotify_group *group,
526 BUG_ON(group != audit_watch_group); 526 BUG_ON(group != audit_watch_group);
527 527
528 switch (event->data_type) { 528 switch (event->data_type) {
529 case (FSNOTIFY_EVENT_FILE): 529 case (FSNOTIFY_EVENT_PATH):
530 inode = event->file->f_path.dentry->d_inode; 530 inode = event->path.dentry->d_inode;
531 break; 531 break;
532 case (FSNOTIFY_EVENT_INODE): 532 case (FSNOTIFY_EVENT_INODE):
533 inode = event->inode; 533 inode = event->inode;
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index b87a63beb66c..1b31c130d034 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -1835,13 +1835,8 @@ void __audit_getname(const char *name)
1835 context->names[context->name_count].ino = (unsigned long)-1; 1835 context->names[context->name_count].ino = (unsigned long)-1;
1836 context->names[context->name_count].osid = 0; 1836 context->names[context->name_count].osid = 0;
1837 ++context->name_count; 1837 ++context->name_count;
1838 if (!context->pwd.dentry) { 1838 if (!context->pwd.dentry)
1839 read_lock(&current->fs->lock); 1839 get_fs_pwd(current->fs, &context->pwd);
1840 context->pwd = current->fs->pwd;
1841 path_get(&current->fs->pwd);
1842 read_unlock(&current->fs->lock);
1843 }
1844
1845} 1840}
1846 1841
1847/* audit_putname - intercept a putname request 1842/* audit_putname - intercept a putname request
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index d83cab06da87..192f88c5b0f9 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1102,7 +1102,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
1102 if (opts->release_agent) 1102 if (opts->release_agent)
1103 return -EINVAL; 1103 return -EINVAL;
1104 opts->release_agent = 1104 opts->release_agent =
1105 kstrndup(token + 14, PATH_MAX, GFP_KERNEL); 1105 kstrndup(token + 14, PATH_MAX - 1, GFP_KERNEL);
1106 if (!opts->release_agent) 1106 if (!opts->release_agent)
1107 return -ENOMEM; 1107 return -ENOMEM;
1108 } else if (!strncmp(token, "name=", 5)) { 1108 } else if (!strncmp(token, "name=", 5)) {
@@ -1123,7 +1123,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
1123 if (opts->name) 1123 if (opts->name)
1124 return -EINVAL; 1124 return -EINVAL;
1125 opts->name = kstrndup(name, 1125 opts->name = kstrndup(name,
1126 MAX_CGROUP_ROOT_NAMELEN, 1126 MAX_CGROUP_ROOT_NAMELEN - 1,
1127 GFP_KERNEL); 1127 GFP_KERNEL);
1128 if (!opts->name) 1128 if (!opts->name)
1129 return -ENOMEM; 1129 return -ENOMEM;
diff --git a/kernel/cred.c b/kernel/cred.c
index 60bc8b1e32e6..9a3e22641fe7 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -22,10 +22,6 @@
22#define kdebug(FMT, ...) \ 22#define kdebug(FMT, ...) \
23 printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__) 23 printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__)
24#else 24#else
25static inline __attribute__((format(printf, 1, 2)))
26void no_printk(const char *fmt, ...)
27{
28}
29#define kdebug(FMT, ...) \ 25#define kdebug(FMT, ...) \
30 no_printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__) 26 no_printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__)
31#endif 27#endif
diff --git a/kernel/exit.c b/kernel/exit.c
index ceffc67b564a..671ed56e0a49 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -771,9 +771,12 @@ static void forget_original_parent(struct task_struct *father)
771 struct task_struct *p, *n, *reaper; 771 struct task_struct *p, *n, *reaper;
772 LIST_HEAD(dead_children); 772 LIST_HEAD(dead_children);
773 773
774 exit_ptrace(father);
775
776 write_lock_irq(&tasklist_lock); 774 write_lock_irq(&tasklist_lock);
775 /*
776 * Note that exit_ptrace() and find_new_reaper() might
777 * drop tasklist_lock and reacquire it.
778 */
779 exit_ptrace(father);
777 reaper = find_new_reaper(father); 780 reaper = find_new_reaper(father);
778 781
779 list_for_each_entry_safe(p, n, &father->children, sibling) { 782 list_for_each_entry_safe(p, n, &father->children, sibling) {
diff --git a/kernel/kexec.c b/kernel/kexec.c
index 131b1703936f..c0613f7d6730 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -151,8 +151,10 @@ static int do_kimage_alloc(struct kimage **rimage, unsigned long entry,
151 image->nr_segments = nr_segments; 151 image->nr_segments = nr_segments;
152 segment_bytes = nr_segments * sizeof(*segments); 152 segment_bytes = nr_segments * sizeof(*segments);
153 result = copy_from_user(image->segment, segments, segment_bytes); 153 result = copy_from_user(image->segment, segments, segment_bytes);
154 if (result) 154 if (result) {
155 result = -EFAULT;
155 goto out; 156 goto out;
157 }
156 158
157 /* 159 /*
158 * Verify we have good destination addresses. The caller is 160 * Verify we have good destination addresses. The caller is
@@ -827,7 +829,7 @@ static int kimage_load_normal_segment(struct kimage *image,
827 result = copy_from_user(ptr, buf, uchunk); 829 result = copy_from_user(ptr, buf, uchunk);
828 kunmap(page); 830 kunmap(page);
829 if (result) { 831 if (result) {
830 result = (result < 0) ? result : -EIO; 832 result = -EFAULT;
831 goto out; 833 goto out;
832 } 834 }
833 ubytes -= uchunk; 835 ubytes -= uchunk;
@@ -882,7 +884,7 @@ static int kimage_load_crash_segment(struct kimage *image,
882 kexec_flush_icache_page(page); 884 kexec_flush_icache_page(page);
883 kunmap(page); 885 kunmap(page);
884 if (result) { 886 if (result) {
885 result = (result < 0) ? result : -EIO; 887 result = -EFAULT;
886 goto out; 888 goto out;
887 } 889 }
888 ubytes -= uchunk; 890 ubytes -= uchunk;
diff --git a/kernel/kfifo.c b/kernel/kfifo.c
index 35edbe22e9a9..4502604ecadf 100644
--- a/kernel/kfifo.c
+++ b/kernel/kfifo.c
@@ -1,8 +1,7 @@
1/* 1/*
2 * A generic kernel FIFO implementation. 2 * A generic kernel FIFO implementation
3 * 3 *
4 * Copyright (C) 2009 Stefani Seibold <stefani@seibold.net> 4 * Copyright (C) 2009/2010 Stefani Seibold <stefani@seibold.net>
5 * Copyright (C) 2004 Stelian Pop <stelian@popies.net>
6 * 5 *
7 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -11,7 +10,7 @@
11 * 10 *
12 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 14 * GNU General Public License for more details.
16 * 15 *
17 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
@@ -24,422 +23,579 @@
24#include <linux/module.h> 23#include <linux/module.h>
25#include <linux/slab.h> 24#include <linux/slab.h>
26#include <linux/err.h> 25#include <linux/err.h>
27#include <linux/kfifo.h>
28#include <linux/log2.h> 26#include <linux/log2.h>
29#include <linux/uaccess.h> 27#include <linux/uaccess.h>
28#include <linux/kfifo.h>
30 29
31static void _kfifo_init(struct kfifo *fifo, void *buffer, 30/*
32 unsigned int size) 31 * internal helper to calculate the unused elements in a fifo
33{
34 fifo->buffer = buffer;
35 fifo->size = size;
36
37 kfifo_reset(fifo);
38}
39
40/**
41 * kfifo_init - initialize a FIFO using a preallocated buffer
42 * @fifo: the fifo to assign the buffer
43 * @buffer: the preallocated buffer to be used.
44 * @size: the size of the internal buffer, this has to be a power of 2.
45 *
46 */ 32 */
47void kfifo_init(struct kfifo *fifo, void *buffer, unsigned int size) 33static inline unsigned int kfifo_unused(struct __kfifo *fifo)
48{ 34{
49 /* size must be a power of 2 */ 35 return (fifo->mask + 1) - (fifo->in - fifo->out);
50 BUG_ON(!is_power_of_2(size));
51
52 _kfifo_init(fifo, buffer, size);
53} 36}
54EXPORT_SYMBOL(kfifo_init);
55 37
56/** 38int __kfifo_alloc(struct __kfifo *fifo, unsigned int size,
57 * kfifo_alloc - allocates a new FIFO internal buffer 39 size_t esize, gfp_t gfp_mask)
58 * @fifo: the fifo to assign then new buffer
59 * @size: the size of the buffer to be allocated, this have to be a power of 2.
60 * @gfp_mask: get_free_pages mask, passed to kmalloc()
61 *
62 * This function dynamically allocates a new fifo internal buffer
63 *
64 * The size will be rounded-up to a power of 2.
65 * The buffer will be release with kfifo_free().
66 * Return 0 if no error, otherwise the an error code
67 */
68int kfifo_alloc(struct kfifo *fifo, unsigned int size, gfp_t gfp_mask)
69{ 40{
70 unsigned char *buffer;
71
72 /* 41 /*
73 * round up to the next power of 2, since our 'let the indices 42 * round down to the next power of 2, since our 'let the indices
74 * wrap' technique works only in this case. 43 * wrap' technique works only in this case.
75 */ 44 */
76 if (!is_power_of_2(size)) { 45 if (!is_power_of_2(size))
77 BUG_ON(size > 0x80000000); 46 size = rounddown_pow_of_two(size);
78 size = roundup_pow_of_two(size); 47
48 fifo->in = 0;
49 fifo->out = 0;
50 fifo->esize = esize;
51
52 if (size < 2) {
53 fifo->data = NULL;
54 fifo->mask = 0;
55 return -EINVAL;
79 } 56 }
80 57
81 buffer = kmalloc(size, gfp_mask); 58 fifo->data = kmalloc(size * esize, gfp_mask);
82 if (!buffer) { 59
83 _kfifo_init(fifo, NULL, 0); 60 if (!fifo->data) {
61 fifo->mask = 0;
84 return -ENOMEM; 62 return -ENOMEM;
85 } 63 }
86 64 fifo->mask = size - 1;
87 _kfifo_init(fifo, buffer, size);
88 65
89 return 0; 66 return 0;
90} 67}
91EXPORT_SYMBOL(kfifo_alloc); 68EXPORT_SYMBOL(__kfifo_alloc);
92 69
93/** 70void __kfifo_free(struct __kfifo *fifo)
94 * kfifo_free - frees the FIFO internal buffer
95 * @fifo: the fifo to be freed.
96 */
97void kfifo_free(struct kfifo *fifo)
98{ 71{
99 kfree(fifo->buffer); 72 kfree(fifo->data);
100 _kfifo_init(fifo, NULL, 0); 73 fifo->in = 0;
74 fifo->out = 0;
75 fifo->esize = 0;
76 fifo->data = NULL;
77 fifo->mask = 0;
101} 78}
102EXPORT_SYMBOL(kfifo_free); 79EXPORT_SYMBOL(__kfifo_free);
103 80
104/** 81int __kfifo_init(struct __kfifo *fifo, void *buffer,
105 * kfifo_skip - skip output data 82 unsigned int size, size_t esize)
106 * @fifo: the fifo to be used.
107 * @len: number of bytes to skip
108 */
109void kfifo_skip(struct kfifo *fifo, unsigned int len)
110{ 83{
111 if (len < kfifo_len(fifo)) { 84 size /= esize;
112 __kfifo_add_out(fifo, len); 85
113 return; 86 if (!is_power_of_2(size))
87 size = rounddown_pow_of_two(size);
88
89 fifo->in = 0;
90 fifo->out = 0;
91 fifo->esize = esize;
92 fifo->data = buffer;
93
94 if (size < 2) {
95 fifo->mask = 0;
96 return -EINVAL;
114 } 97 }
115 kfifo_reset_out(fifo); 98 fifo->mask = size - 1;
99
100 return 0;
116} 101}
117EXPORT_SYMBOL(kfifo_skip); 102EXPORT_SYMBOL(__kfifo_init);
118 103
119static inline void __kfifo_in_data(struct kfifo *fifo, 104static void kfifo_copy_in(struct __kfifo *fifo, const void *src,
120 const void *from, unsigned int len, unsigned int off) 105 unsigned int len, unsigned int off)
121{ 106{
107 unsigned int size = fifo->mask + 1;
108 unsigned int esize = fifo->esize;
122 unsigned int l; 109 unsigned int l;
123 110
111 off &= fifo->mask;
112 if (esize != 1) {
113 off *= esize;
114 size *= esize;
115 len *= esize;
116 }
117 l = min(len, size - off);
118
119 memcpy(fifo->data + off, src, l);
120 memcpy(fifo->data, src + l, len - l);
124 /* 121 /*
125 * Ensure that we sample the fifo->out index -before- we 122 * make sure that the data in the fifo is up to date before
126 * start putting bytes into the kfifo. 123 * incrementing the fifo->in index counter
127 */ 124 */
125 smp_wmb();
126}
128 127
129 smp_mb(); 128unsigned int __kfifo_in(struct __kfifo *fifo,
130 129 const void *buf, unsigned int len)
131 off = __kfifo_off(fifo, fifo->in + off); 130{
131 unsigned int l;
132 132
133 /* first put the data starting from fifo->in to buffer end */ 133 l = kfifo_unused(fifo);
134 l = min(len, fifo->size - off); 134 if (len > l)
135 memcpy(fifo->buffer + off, from, l); 135 len = l;
136 136
137 /* then put the rest (if any) at the beginning of the buffer */ 137 kfifo_copy_in(fifo, buf, len, fifo->in);
138 memcpy(fifo->buffer, from + l, len - l); 138 fifo->in += len;
139 return len;
139} 140}
141EXPORT_SYMBOL(__kfifo_in);
140 142
141static inline void __kfifo_out_data(struct kfifo *fifo, 143static void kfifo_copy_out(struct __kfifo *fifo, void *dst,
142 void *to, unsigned int len, unsigned int off) 144 unsigned int len, unsigned int off)
143{ 145{
146 unsigned int size = fifo->mask + 1;
147 unsigned int esize = fifo->esize;
144 unsigned int l; 148 unsigned int l;
145 149
150 off &= fifo->mask;
151 if (esize != 1) {
152 off *= esize;
153 size *= esize;
154 len *= esize;
155 }
156 l = min(len, size - off);
157
158 memcpy(dst, fifo->data + off, l);
159 memcpy(dst + l, fifo->data, len - l);
146 /* 160 /*
147 * Ensure that we sample the fifo->in index -before- we 161 * make sure that the data is copied before
148 * start removing bytes from the kfifo. 162 * incrementing the fifo->out index counter
149 */ 163 */
164 smp_wmb();
165}
150 166
151 smp_rmb(); 167unsigned int __kfifo_out_peek(struct __kfifo *fifo,
168 void *buf, unsigned int len)
169{
170 unsigned int l;
152 171
153 off = __kfifo_off(fifo, fifo->out + off); 172 l = fifo->in - fifo->out;
173 if (len > l)
174 len = l;
154 175
155 /* first get the data from fifo->out until the end of the buffer */ 176 kfifo_copy_out(fifo, buf, len, fifo->out);
156 l = min(len, fifo->size - off); 177 return len;
157 memcpy(to, fifo->buffer + off, l); 178}
179EXPORT_SYMBOL(__kfifo_out_peek);
158 180
159 /* then get the rest (if any) from the beginning of the buffer */ 181unsigned int __kfifo_out(struct __kfifo *fifo,
160 memcpy(to + l, fifo->buffer, len - l); 182 void *buf, unsigned int len)
183{
184 len = __kfifo_out_peek(fifo, buf, len);
185 fifo->out += len;
186 return len;
161} 187}
188EXPORT_SYMBOL(__kfifo_out);
162 189
163static inline int __kfifo_from_user_data(struct kfifo *fifo, 190static unsigned long kfifo_copy_from_user(struct __kfifo *fifo,
164 const void __user *from, unsigned int len, unsigned int off, 191 const void __user *from, unsigned int len, unsigned int off,
165 unsigned *lenout) 192 unsigned int *copied)
166{ 193{
194 unsigned int size = fifo->mask + 1;
195 unsigned int esize = fifo->esize;
167 unsigned int l; 196 unsigned int l;
168 int ret; 197 unsigned long ret;
169 198
199 off &= fifo->mask;
200 if (esize != 1) {
201 off *= esize;
202 size *= esize;
203 len *= esize;
204 }
205 l = min(len, size - off);
206
207 ret = copy_from_user(fifo->data + off, from, l);
208 if (unlikely(ret))
209 ret = DIV_ROUND_UP(ret + len - l, esize);
210 else {
211 ret = copy_from_user(fifo->data, from + l, len - l);
212 if (unlikely(ret))
213 ret = DIV_ROUND_UP(ret, esize);
214 }
170 /* 215 /*
171 * Ensure that we sample the fifo->out index -before- we 216 * make sure that the data in the fifo is up to date before
172 * start putting bytes into the kfifo. 217 * incrementing the fifo->in index counter
173 */ 218 */
219 smp_wmb();
220 *copied = len - ret;
221 /* return the number of elements which are not copied */
222 return ret;
223}
174 224
175 smp_mb(); 225int __kfifo_from_user(struct __kfifo *fifo, const void __user *from,
226 unsigned long len, unsigned int *copied)
227{
228 unsigned int l;
229 unsigned long ret;
230 unsigned int esize = fifo->esize;
231 int err;
176 232
177 off = __kfifo_off(fifo, fifo->in + off); 233 if (esize != 1)
234 len /= esize;
178 235
179 /* first put the data starting from fifo->in to buffer end */ 236 l = kfifo_unused(fifo);
180 l = min(len, fifo->size - off); 237 if (len > l)
181 ret = copy_from_user(fifo->buffer + off, from, l); 238 len = l;
182 if (unlikely(ret)) {
183 *lenout = ret;
184 return -EFAULT;
185 }
186 *lenout = l;
187 239
188 /* then put the rest (if any) at the beginning of the buffer */ 240 ret = kfifo_copy_from_user(fifo, from, len, fifo->in, copied);
189 ret = copy_from_user(fifo->buffer, from + l, len - l); 241 if (unlikely(ret)) {
190 *lenout += ret ? ret : len - l; 242 len -= ret;
191 return ret ? -EFAULT : 0; 243 err = -EFAULT;
244 } else
245 err = 0;
246 fifo->in += len;
247 return err;
192} 248}
249EXPORT_SYMBOL(__kfifo_from_user);
193 250
194static inline int __kfifo_to_user_data(struct kfifo *fifo, 251static unsigned long kfifo_copy_to_user(struct __kfifo *fifo, void __user *to,
195 void __user *to, unsigned int len, unsigned int off, unsigned *lenout) 252 unsigned int len, unsigned int off, unsigned int *copied)
196{ 253{
197 unsigned int l; 254 unsigned int l;
198 int ret; 255 unsigned long ret;
199 256 unsigned int size = fifo->mask + 1;
257 unsigned int esize = fifo->esize;
258
259 off &= fifo->mask;
260 if (esize != 1) {
261 off *= esize;
262 size *= esize;
263 len *= esize;
264 }
265 l = min(len, size - off);
266
267 ret = copy_to_user(to, fifo->data + off, l);
268 if (unlikely(ret))
269 ret = DIV_ROUND_UP(ret + len - l, esize);
270 else {
271 ret = copy_to_user(to + l, fifo->data, len - l);
272 if (unlikely(ret))
273 ret = DIV_ROUND_UP(ret, esize);
274 }
200 /* 275 /*
201 * Ensure that we sample the fifo->in index -before- we 276 * make sure that the data is copied before
202 * start removing bytes from the kfifo. 277 * incrementing the fifo->out index counter
203 */ 278 */
279 smp_wmb();
280 *copied = len - ret;
281 /* return the number of elements which are not copied */
282 return ret;
283}
204 284
205 smp_rmb(); 285int __kfifo_to_user(struct __kfifo *fifo, void __user *to,
286 unsigned long len, unsigned int *copied)
287{
288 unsigned int l;
289 unsigned long ret;
290 unsigned int esize = fifo->esize;
291 int err;
206 292
207 off = __kfifo_off(fifo, fifo->out + off); 293 if (esize != 1)
294 len /= esize;
208 295
209 /* first get the data from fifo->out until the end of the buffer */ 296 l = fifo->in - fifo->out;
210 l = min(len, fifo->size - off); 297 if (len > l)
211 ret = copy_to_user(to, fifo->buffer + off, l); 298 len = l;
212 *lenout = l; 299 ret = kfifo_copy_to_user(fifo, to, len, fifo->out, copied);
213 if (unlikely(ret)) { 300 if (unlikely(ret)) {
214 *lenout -= ret; 301 len -= ret;
215 return -EFAULT; 302 err = -EFAULT;
216 } 303 } else
304 err = 0;
305 fifo->out += len;
306 return err;
307}
308EXPORT_SYMBOL(__kfifo_to_user);
217 309
218 /* then get the rest (if any) from the beginning of the buffer */ 310static int setup_sgl_buf(struct scatterlist *sgl, void *buf,
219 len -= l; 311 int nents, unsigned int len)
220 ret = copy_to_user(to + l, fifo->buffer, len); 312{
221 if (unlikely(ret)) { 313 int n;
222 *lenout += len - ret; 314 unsigned int l;
223 return -EFAULT; 315 unsigned int off;
316 struct page *page;
317
318 if (!nents)
319 return 0;
320
321 if (!len)
322 return 0;
323
324 n = 0;
325 page = virt_to_page(buf);
326 off = offset_in_page(buf);
327 l = 0;
328
329 while (len >= l + PAGE_SIZE - off) {
330 struct page *npage;
331
332 l += PAGE_SIZE;
333 buf += PAGE_SIZE;
334 npage = virt_to_page(buf);
335 if (page_to_phys(page) != page_to_phys(npage) - l) {
336 sg_set_page(sgl, page, l - off, off);
337 sgl = sg_next(sgl);
338 if (++n == nents || sgl == NULL)
339 return n;
340 page = npage;
341 len -= l - off;
342 l = off = 0;
343 }
224 } 344 }
225 *lenout += len; 345 sg_set_page(sgl, page, len, off);
226 return 0; 346 return n + 1;
227} 347}
228 348
229unsigned int __kfifo_in_n(struct kfifo *fifo, 349static unsigned int setup_sgl(struct __kfifo *fifo, struct scatterlist *sgl,
230 const void *from, unsigned int len, unsigned int recsize) 350 int nents, unsigned int len, unsigned int off)
231{ 351{
232 if (kfifo_avail(fifo) < len + recsize) 352 unsigned int size = fifo->mask + 1;
233 return len + 1; 353 unsigned int esize = fifo->esize;
354 unsigned int l;
355 unsigned int n;
234 356
235 __kfifo_in_data(fifo, from, len, recsize); 357 off &= fifo->mask;
236 return 0; 358 if (esize != 1) {
359 off *= esize;
360 size *= esize;
361 len *= esize;
362 }
363 l = min(len, size - off);
364
365 n = setup_sgl_buf(sgl, fifo->data + off, nents, l);
366 n += setup_sgl_buf(sgl + n, fifo->data, nents - n, len - l);
367
368 if (n)
369 sg_mark_end(sgl + n - 1);
370 return n;
237} 371}
238EXPORT_SYMBOL(__kfifo_in_n);
239 372
240/** 373unsigned int __kfifo_dma_in_prepare(struct __kfifo *fifo,
241 * kfifo_in - puts some data into the FIFO 374 struct scatterlist *sgl, int nents, unsigned int len)
242 * @fifo: the fifo to be used.
243 * @from: the data to be added.
244 * @len: the length of the data to be added.
245 *
246 * This function copies at most @len bytes from the @from buffer into
247 * the FIFO depending on the free space, and returns the number of
248 * bytes copied.
249 *
250 * Note that with only one concurrent reader and one concurrent
251 * writer, you don't need extra locking to use these functions.
252 */
253unsigned int kfifo_in(struct kfifo *fifo, const void *from,
254 unsigned int len)
255{ 375{
256 len = min(kfifo_avail(fifo), len); 376 unsigned int l;
257 377
258 __kfifo_in_data(fifo, from, len, 0); 378 l = kfifo_unused(fifo);
259 __kfifo_add_in(fifo, len); 379 if (len > l)
260 return len; 380 len = l;
381
382 return setup_sgl(fifo, sgl, nents, len, fifo->in);
261} 383}
262EXPORT_SYMBOL(kfifo_in); 384EXPORT_SYMBOL(__kfifo_dma_in_prepare);
263 385
264unsigned int __kfifo_in_generic(struct kfifo *fifo, 386unsigned int __kfifo_dma_out_prepare(struct __kfifo *fifo,
265 const void *from, unsigned int len, unsigned int recsize) 387 struct scatterlist *sgl, int nents, unsigned int len)
266{ 388{
267 return __kfifo_in_rec(fifo, from, len, recsize); 389 unsigned int l;
390
391 l = fifo->in - fifo->out;
392 if (len > l)
393 len = l;
394
395 return setup_sgl(fifo, sgl, nents, len, fifo->out);
268} 396}
269EXPORT_SYMBOL(__kfifo_in_generic); 397EXPORT_SYMBOL(__kfifo_dma_out_prepare);
270 398
271unsigned int __kfifo_out_n(struct kfifo *fifo, 399unsigned int __kfifo_max_r(unsigned int len, size_t recsize)
272 void *to, unsigned int len, unsigned int recsize)
273{ 400{
274 if (kfifo_len(fifo) < len + recsize) 401 unsigned int max = (1 << (recsize << 3)) - 1;
275 return len;
276 402
277 __kfifo_out_data(fifo, to, len, recsize); 403 if (len > max)
278 __kfifo_add_out(fifo, len + recsize); 404 return max;
279 return 0; 405 return len;
280} 406}
281EXPORT_SYMBOL(__kfifo_out_n);
282 407
283/** 408#define __KFIFO_PEEK(data, out, mask) \
284 * kfifo_out - gets some data from the FIFO 409 ((data)[(out) & (mask)])
285 * @fifo: the fifo to be used. 410/*
286 * @to: where the data must be copied. 411 * __kfifo_peek_n internal helper function for determinate the length of
287 * @len: the size of the destination buffer. 412 * the next record in the fifo
288 *
289 * This function copies at most @len bytes from the FIFO into the
290 * @to buffer and returns the number of copied bytes.
291 *
292 * Note that with only one concurrent reader and one concurrent
293 * writer, you don't need extra locking to use these functions.
294 */ 413 */
295unsigned int kfifo_out(struct kfifo *fifo, void *to, unsigned int len) 414static unsigned int __kfifo_peek_n(struct __kfifo *fifo, size_t recsize)
296{ 415{
297 len = min(kfifo_len(fifo), len); 416 unsigned int l;
417 unsigned int mask = fifo->mask;
418 unsigned char *data = fifo->data;
298 419
299 __kfifo_out_data(fifo, to, len, 0); 420 l = __KFIFO_PEEK(data, fifo->out, mask);
300 __kfifo_add_out(fifo, len);
301 421
302 return len; 422 if (--recsize)
423 l |= __KFIFO_PEEK(data, fifo->out + 1, mask) << 8;
424
425 return l;
303} 426}
304EXPORT_SYMBOL(kfifo_out); 427
305 428#define __KFIFO_POKE(data, in, mask, val) \
306/** 429 ( \
307 * kfifo_out_peek - copy some data from the FIFO, but do not remove it 430 (data)[(in) & (mask)] = (unsigned char)(val) \
308 * @fifo: the fifo to be used. 431 )
309 * @to: where the data must be copied. 432
310 * @len: the size of the destination buffer. 433/*
311 * @offset: offset into the fifo 434 * __kfifo_poke_n internal helper function for storeing the length of
312 * 435 * the record into the fifo
313 * This function copies at most @len bytes at @offset from the FIFO
314 * into the @to buffer and returns the number of copied bytes.
315 * The data is not removed from the FIFO.
316 */ 436 */
317unsigned int kfifo_out_peek(struct kfifo *fifo, void *to, unsigned int len, 437static void __kfifo_poke_n(struct __kfifo *fifo, unsigned int n, size_t recsize)
318 unsigned offset)
319{ 438{
320 len = min(kfifo_len(fifo), len + offset); 439 unsigned int mask = fifo->mask;
440 unsigned char *data = fifo->data;
321 441
322 __kfifo_out_data(fifo, to, len, offset); 442 __KFIFO_POKE(data, fifo->in, mask, n);
323 return len; 443
444 if (recsize > 1)
445 __KFIFO_POKE(data, fifo->in + 1, mask, n >> 8);
324} 446}
325EXPORT_SYMBOL(kfifo_out_peek);
326 447
327unsigned int __kfifo_out_generic(struct kfifo *fifo, 448unsigned int __kfifo_len_r(struct __kfifo *fifo, size_t recsize)
328 void *to, unsigned int len, unsigned int recsize,
329 unsigned int *total)
330{ 449{
331 return __kfifo_out_rec(fifo, to, len, recsize, total); 450 return __kfifo_peek_n(fifo, recsize);
332} 451}
333EXPORT_SYMBOL(__kfifo_out_generic); 452EXPORT_SYMBOL(__kfifo_len_r);
334 453
335unsigned int __kfifo_from_user_n(struct kfifo *fifo, 454unsigned int __kfifo_in_r(struct __kfifo *fifo, const void *buf,
336 const void __user *from, unsigned int len, unsigned int recsize) 455 unsigned int len, size_t recsize)
337{ 456{
338 unsigned total; 457 if (len + recsize > kfifo_unused(fifo))
458 return 0;
339 459
340 if (kfifo_avail(fifo) < len + recsize) 460 __kfifo_poke_n(fifo, len, recsize);
341 return len + 1;
342 461
343 __kfifo_from_user_data(fifo, from, len, recsize, &total); 462 kfifo_copy_in(fifo, buf, len, fifo->in + recsize);
344 return total; 463 fifo->in += len + recsize;
464 return len;
345} 465}
346EXPORT_SYMBOL(__kfifo_from_user_n); 466EXPORT_SYMBOL(__kfifo_in_r);
347 467
348/** 468static unsigned int kfifo_out_copy_r(struct __kfifo *fifo,
349 * kfifo_from_user - puts some data from user space into the FIFO 469 void *buf, unsigned int len, size_t recsize, unsigned int *n)
350 * @fifo: the fifo to be used.
351 * @from: pointer to the data to be added.
352 * @len: the length of the data to be added.
353 * @total: the actual returned data length.
354 *
355 * This function copies at most @len bytes from the @from into the
356 * FIFO depending and returns -EFAULT/0.
357 *
358 * Note that with only one concurrent reader and one concurrent
359 * writer, you don't need extra locking to use these functions.
360 */
361int kfifo_from_user(struct kfifo *fifo,
362 const void __user *from, unsigned int len, unsigned *total)
363{ 470{
364 int ret; 471 *n = __kfifo_peek_n(fifo, recsize);
365 len = min(kfifo_avail(fifo), len); 472
366 ret = __kfifo_from_user_data(fifo, from, len, 0, total); 473 if (len > *n)
367 if (ret) 474 len = *n;
368 return ret; 475
369 __kfifo_add_in(fifo, len); 476 kfifo_copy_out(fifo, buf, len, fifo->out + recsize);
370 return 0; 477 return len;
478}
479
480unsigned int __kfifo_out_peek_r(struct __kfifo *fifo, void *buf,
481 unsigned int len, size_t recsize)
482{
483 unsigned int n;
484
485 if (fifo->in == fifo->out)
486 return 0;
487
488 return kfifo_out_copy_r(fifo, buf, len, recsize, &n);
371} 489}
372EXPORT_SYMBOL(kfifo_from_user); 490EXPORT_SYMBOL(__kfifo_out_peek_r);
373 491
374unsigned int __kfifo_from_user_generic(struct kfifo *fifo, 492unsigned int __kfifo_out_r(struct __kfifo *fifo, void *buf,
375 const void __user *from, unsigned int len, unsigned int recsize) 493 unsigned int len, size_t recsize)
376{ 494{
377 return __kfifo_from_user_rec(fifo, from, len, recsize); 495 unsigned int n;
496
497 if (fifo->in == fifo->out)
498 return 0;
499
500 len = kfifo_out_copy_r(fifo, buf, len, recsize, &n);
501 fifo->out += n + recsize;
502 return len;
378} 503}
379EXPORT_SYMBOL(__kfifo_from_user_generic); 504EXPORT_SYMBOL(__kfifo_out_r);
380 505
381unsigned int __kfifo_to_user_n(struct kfifo *fifo, 506int __kfifo_from_user_r(struct __kfifo *fifo, const void __user *from,
382 void __user *to, unsigned int len, unsigned int reclen, 507 unsigned long len, unsigned int *copied, size_t recsize)
383 unsigned int recsize)
384{ 508{
385 unsigned int ret, total; 509 unsigned long ret;
386 510
387 if (kfifo_len(fifo) < reclen + recsize) 511 len = __kfifo_max_r(len, recsize);
388 return len;
389 512
390 ret = __kfifo_to_user_data(fifo, to, reclen, recsize, &total); 513 if (len + recsize > kfifo_unused(fifo)) {
514 *copied = 0;
515 return 0;
516 }
391 517
392 if (likely(ret == 0)) 518 __kfifo_poke_n(fifo, len, recsize);
393 __kfifo_add_out(fifo, reclen + recsize);
394 519
395 return total; 520 ret = kfifo_copy_from_user(fifo, from, len, fifo->in + recsize, copied);
521 if (unlikely(ret)) {
522 *copied = 0;
523 return -EFAULT;
524 }
525 fifo->in += len + recsize;
526 return 0;
396} 527}
397EXPORT_SYMBOL(__kfifo_to_user_n); 528EXPORT_SYMBOL(__kfifo_from_user_r);
398 529
399/** 530int __kfifo_to_user_r(struct __kfifo *fifo, void __user *to,
400 * kfifo_to_user - gets data from the FIFO and write it to user space 531 unsigned long len, unsigned int *copied, size_t recsize)
401 * @fifo: the fifo to be used.
402 * @to: where the data must be copied.
403 * @len: the size of the destination buffer.
404 * @lenout: pointer to output variable with copied data
405 *
406 * This function copies at most @len bytes from the FIFO into the
407 * @to buffer and 0 or -EFAULT.
408 *
409 * Note that with only one concurrent reader and one concurrent
410 * writer, you don't need extra locking to use these functions.
411 */
412int kfifo_to_user(struct kfifo *fifo,
413 void __user *to, unsigned int len, unsigned *lenout)
414{ 532{
415 int ret; 533 unsigned long ret;
416 len = min(kfifo_len(fifo), len); 534 unsigned int n;
417 ret = __kfifo_to_user_data(fifo, to, len, 0, lenout); 535
418 __kfifo_add_out(fifo, *lenout); 536 if (fifo->in == fifo->out) {
419 return ret; 537 *copied = 0;
538 return 0;
539 }
540
541 n = __kfifo_peek_n(fifo, recsize);
542 if (len > n)
543 len = n;
544
545 ret = kfifo_copy_to_user(fifo, to, len, fifo->out + recsize, copied);
546 if (unlikely(ret)) {
547 *copied = 0;
548 return -EFAULT;
549 }
550 fifo->out += n + recsize;
551 return 0;
420} 552}
421EXPORT_SYMBOL(kfifo_to_user); 553EXPORT_SYMBOL(__kfifo_to_user_r);
422 554
423unsigned int __kfifo_to_user_generic(struct kfifo *fifo, 555unsigned int __kfifo_dma_in_prepare_r(struct __kfifo *fifo,
424 void __user *to, unsigned int len, unsigned int recsize, 556 struct scatterlist *sgl, int nents, unsigned int len, size_t recsize)
425 unsigned int *total)
426{ 557{
427 return __kfifo_to_user_rec(fifo, to, len, recsize, total); 558 if (!nents)
559 BUG();
560
561 len = __kfifo_max_r(len, recsize);
562
563 if (len + recsize > kfifo_unused(fifo))
564 return 0;
565
566 return setup_sgl(fifo, sgl, nents, len, fifo->in + recsize);
428} 567}
429EXPORT_SYMBOL(__kfifo_to_user_generic); 568EXPORT_SYMBOL(__kfifo_dma_in_prepare_r);
430 569
431unsigned int __kfifo_peek_generic(struct kfifo *fifo, unsigned int recsize) 570void __kfifo_dma_in_finish_r(struct __kfifo *fifo,
571 unsigned int len, size_t recsize)
432{ 572{
433 if (recsize == 0) 573 len = __kfifo_max_r(len, recsize);
434 return kfifo_avail(fifo); 574 __kfifo_poke_n(fifo, len, recsize);
435 575 fifo->in += len + recsize;
436 return __kfifo_peek_n(fifo, recsize);
437} 576}
438EXPORT_SYMBOL(__kfifo_peek_generic); 577EXPORT_SYMBOL(__kfifo_dma_in_finish_r);
439 578
440void __kfifo_skip_generic(struct kfifo *fifo, unsigned int recsize) 579unsigned int __kfifo_dma_out_prepare_r(struct __kfifo *fifo,
580 struct scatterlist *sgl, int nents, unsigned int len, size_t recsize)
441{ 581{
442 __kfifo_skip_rec(fifo, recsize); 582 if (!nents)
583 BUG();
584
585 len = __kfifo_max_r(len, recsize);
586
587 if (len + recsize > fifo->in - fifo->out)
588 return 0;
589
590 return setup_sgl(fifo, sgl, nents, len, fifo->out + recsize);
443} 591}
444EXPORT_SYMBOL(__kfifo_skip_generic); 592EXPORT_SYMBOL(__kfifo_dma_out_prepare_r);
593
594void __kfifo_dma_out_finish_r(struct __kfifo *fifo, size_t recsize)
595{
596 unsigned int len;
445 597
598 len = __kfifo_peek_n(fifo, recsize);
599 fifo->out += len + recsize;
600}
601EXPORT_SYMBOL(__kfifo_dma_out_finish_r);
diff --git a/kernel/panic.c b/kernel/panic.c
index 3b16cd93fa7d..4c13b1a88ebb 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -24,6 +24,9 @@
24#include <linux/nmi.h> 24#include <linux/nmi.h>
25#include <linux/dmi.h> 25#include <linux/dmi.h>
26 26
27#define PANIC_TIMER_STEP 100
28#define PANIC_BLINK_SPD 18
29
27int panic_on_oops; 30int panic_on_oops;
28static unsigned long tainted_mask; 31static unsigned long tainted_mask;
29static int pause_on_oops; 32static int pause_on_oops;
@@ -36,36 +39,15 @@ ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
36 39
37EXPORT_SYMBOL(panic_notifier_list); 40EXPORT_SYMBOL(panic_notifier_list);
38 41
39/* Returns how long it waited in ms */ 42static long no_blink(int state)
40long (*panic_blink)(long time);
41EXPORT_SYMBOL(panic_blink);
42
43static void panic_blink_one_second(void)
44{ 43{
45 static long i = 0, end; 44 return 0;
46
47 if (panic_blink) {
48 end = i + MSEC_PER_SEC;
49
50 while (i < end) {
51 i += panic_blink(i);
52 mdelay(1);
53 i++;
54 }
55 } else {
56 /*
57 * When running under a hypervisor a small mdelay may get
58 * rounded up to the hypervisor timeslice. For example, with
59 * a 1ms in 10ms hypervisor timeslice we might inflate a
60 * mdelay(1) loop by 10x.
61 *
62 * If we have nothing to blink, spin on 1 second calls to
63 * mdelay to avoid this.
64 */
65 mdelay(MSEC_PER_SEC);
66 }
67} 45}
68 46
47/* Returns how long it waited in ms */
48long (*panic_blink)(int state);
49EXPORT_SYMBOL(panic_blink);
50
69/** 51/**
70 * panic - halt the system 52 * panic - halt the system
71 * @fmt: The text string to print 53 * @fmt: The text string to print
@@ -78,7 +60,8 @@ NORET_TYPE void panic(const char * fmt, ...)
78{ 60{
79 static char buf[1024]; 61 static char buf[1024];
80 va_list args; 62 va_list args;
81 long i; 63 long i, i_next = 0;
64 int state = 0;
82 65
83 /* 66 /*
84 * It's possible to come here directly from a panic-assertion and 67 * It's possible to come here directly from a panic-assertion and
@@ -117,6 +100,9 @@ NORET_TYPE void panic(const char * fmt, ...)
117 100
118 bust_spinlocks(0); 101 bust_spinlocks(0);
119 102
103 if (!panic_blink)
104 panic_blink = no_blink;
105
120 if (panic_timeout > 0) { 106 if (panic_timeout > 0) {
121 /* 107 /*
122 * Delay timeout seconds before rebooting the machine. 108 * Delay timeout seconds before rebooting the machine.
@@ -124,9 +110,13 @@ NORET_TYPE void panic(const char * fmt, ...)
124 */ 110 */
125 printk(KERN_EMERG "Rebooting in %d seconds..", panic_timeout); 111 printk(KERN_EMERG "Rebooting in %d seconds..", panic_timeout);
126 112
127 for (i = 0; i < panic_timeout; i++) { 113 for (i = 0; i < panic_timeout * 1000; i += PANIC_TIMER_STEP) {
128 touch_nmi_watchdog(); 114 touch_nmi_watchdog();
129 panic_blink_one_second(); 115 if (i >= i_next) {
116 i += panic_blink(state ^= 1);
117 i_next = i + 3600 / PANIC_BLINK_SPD;
118 }
119 mdelay(PANIC_TIMER_STEP);
130 } 120 }
131 /* 121 /*
132 * This will not be a clean reboot, with everything 122 * This will not be a clean reboot, with everything
@@ -152,9 +142,13 @@ NORET_TYPE void panic(const char * fmt, ...)
152 } 142 }
153#endif 143#endif
154 local_irq_enable(); 144 local_irq_enable();
155 while (1) { 145 for (i = 0; ; i += PANIC_TIMER_STEP) {
156 touch_softlockup_watchdog(); 146 touch_softlockup_watchdog();
157 panic_blink_one_second(); 147 if (i >= i_next) {
148 i += panic_blink(state ^= 1);
149 i_next = i + 3600 / PANIC_BLINK_SPD;
150 }
151 mdelay(PANIC_TIMER_STEP);
158 } 152 }
159} 153}
160 154
@@ -344,7 +338,7 @@ static int init_oops_id(void)
344} 338}
345late_initcall(init_oops_id); 339late_initcall(init_oops_id);
346 340
347static void print_oops_end_marker(void) 341void print_oops_end_marker(void)
348{ 342{
349 init_oops_id(); 343 init_oops_id();
350 printk(KERN_WARNING "---[ end trace %016llx ]---\n", 344 printk(KERN_WARNING "---[ end trace %016llx ]---\n",
diff --git a/kernel/params.c b/kernel/params.c
index 0b30ecd53a52..08107d181758 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -31,6 +31,42 @@
31#define DEBUGP(fmt, a...) 31#define DEBUGP(fmt, a...)
32#endif 32#endif
33 33
34/* Protects all parameters, and incidentally kmalloced_param list. */
35static DEFINE_MUTEX(param_lock);
36
37/* This just allows us to keep track of which parameters are kmalloced. */
38struct kmalloced_param {
39 struct list_head list;
40 char val[];
41};
42static LIST_HEAD(kmalloced_params);
43
44static void *kmalloc_parameter(unsigned int size)
45{
46 struct kmalloced_param *p;
47
48 p = kmalloc(sizeof(*p) + size, GFP_KERNEL);
49 if (!p)
50 return NULL;
51
52 list_add(&p->list, &kmalloced_params);
53 return p->val;
54}
55
56/* Does nothing if parameter wasn't kmalloced above. */
57static void maybe_kfree_parameter(void *param)
58{
59 struct kmalloced_param *p;
60
61 list_for_each_entry(p, &kmalloced_params, list) {
62 if (p->val == param) {
63 list_del(&p->list);
64 kfree(p);
65 break;
66 }
67 }
68}
69
34static inline char dash2underscore(char c) 70static inline char dash2underscore(char c)
35{ 71{
36 if (c == '-') 72 if (c == '-')
@@ -49,18 +85,25 @@ static inline int parameq(const char *input, const char *paramname)
49 85
50static int parse_one(char *param, 86static int parse_one(char *param,
51 char *val, 87 char *val,
52 struct kernel_param *params, 88 const struct kernel_param *params,
53 unsigned num_params, 89 unsigned num_params,
54 int (*handle_unknown)(char *param, char *val)) 90 int (*handle_unknown)(char *param, char *val))
55{ 91{
56 unsigned int i; 92 unsigned int i;
93 int err;
57 94
58 /* Find parameter */ 95 /* Find parameter */
59 for (i = 0; i < num_params; i++) { 96 for (i = 0; i < num_params; i++) {
60 if (parameq(param, params[i].name)) { 97 if (parameq(param, params[i].name)) {
98 /* Noone handled NULL, so do it here. */
99 if (!val && params[i].ops->set != param_set_bool)
100 return -EINVAL;
61 DEBUGP("They are equal! Calling %p\n", 101 DEBUGP("They are equal! Calling %p\n",
62 params[i].set); 102 params[i].ops->set);
63 return params[i].set(val, &params[i]); 103 mutex_lock(&param_lock);
104 err = params[i].ops->set(val, &params[i]);
105 mutex_unlock(&param_lock);
106 return err;
64 } 107 }
65 } 108 }
66 109
@@ -128,7 +171,7 @@ static char *next_arg(char *args, char **param, char **val)
128/* Args looks like "foo=bar,bar2 baz=fuz wiz". */ 171/* Args looks like "foo=bar,bar2 baz=fuz wiz". */
129int parse_args(const char *name, 172int parse_args(const char *name,
130 char *args, 173 char *args,
131 struct kernel_param *params, 174 const struct kernel_param *params,
132 unsigned num, 175 unsigned num,
133 int (*unknown)(char *param, char *val)) 176 int (*unknown)(char *param, char *val))
134{ 177{
@@ -176,22 +219,29 @@ int parse_args(const char *name,
176 219
177/* Lazy bastard, eh? */ 220/* Lazy bastard, eh? */
178#define STANDARD_PARAM_DEF(name, type, format, tmptype, strtolfn) \ 221#define STANDARD_PARAM_DEF(name, type, format, tmptype, strtolfn) \
179 int param_set_##name(const char *val, struct kernel_param *kp) \ 222 int param_set_##name(const char *val, const struct kernel_param *kp) \
180 { \ 223 { \
181 tmptype l; \ 224 tmptype l; \
182 int ret; \ 225 int ret; \
183 \ 226 \
184 if (!val) return -EINVAL; \
185 ret = strtolfn(val, 0, &l); \ 227 ret = strtolfn(val, 0, &l); \
186 if (ret == -EINVAL || ((type)l != l)) \ 228 if (ret == -EINVAL || ((type)l != l)) \
187 return -EINVAL; \ 229 return -EINVAL; \
188 *((type *)kp->arg) = l; \ 230 *((type *)kp->arg) = l; \
189 return 0; \ 231 return 0; \
190 } \ 232 } \
191 int param_get_##name(char *buffer, struct kernel_param *kp) \ 233 int param_get_##name(char *buffer, const struct kernel_param *kp) \
192 { \ 234 { \
193 return sprintf(buffer, format, *((type *)kp->arg)); \ 235 return sprintf(buffer, format, *((type *)kp->arg)); \
194 } 236 } \
237 struct kernel_param_ops param_ops_##name = { \
238 .set = param_set_##name, \
239 .get = param_get_##name, \
240 }; \
241 EXPORT_SYMBOL(param_set_##name); \
242 EXPORT_SYMBOL(param_get_##name); \
243 EXPORT_SYMBOL(param_ops_##name)
244
195 245
196STANDARD_PARAM_DEF(byte, unsigned char, "%c", unsigned long, strict_strtoul); 246STANDARD_PARAM_DEF(byte, unsigned char, "%c", unsigned long, strict_strtoul);
197STANDARD_PARAM_DEF(short, short, "%hi", long, strict_strtol); 247STANDARD_PARAM_DEF(short, short, "%hi", long, strict_strtol);
@@ -201,39 +251,50 @@ STANDARD_PARAM_DEF(uint, unsigned int, "%u", unsigned long, strict_strtoul);
201STANDARD_PARAM_DEF(long, long, "%li", long, strict_strtol); 251STANDARD_PARAM_DEF(long, long, "%li", long, strict_strtol);
202STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, strict_strtoul); 252STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, strict_strtoul);
203 253
204int param_set_charp(const char *val, struct kernel_param *kp) 254int param_set_charp(const char *val, const struct kernel_param *kp)
205{ 255{
206 if (!val) {
207 printk(KERN_ERR "%s: string parameter expected\n",
208 kp->name);
209 return -EINVAL;
210 }
211
212 if (strlen(val) > 1024) { 256 if (strlen(val) > 1024) {
213 printk(KERN_ERR "%s: string parameter too long\n", 257 printk(KERN_ERR "%s: string parameter too long\n",
214 kp->name); 258 kp->name);
215 return -ENOSPC; 259 return -ENOSPC;
216 } 260 }
217 261
218 /* This is a hack. We can't need to strdup in early boot, and we 262 maybe_kfree_parameter(*(char **)kp->arg);
263
264 /* This is a hack. We can't kmalloc in early boot, and we
219 * don't need to; this mangled commandline is preserved. */ 265 * don't need to; this mangled commandline is preserved. */
220 if (slab_is_available()) { 266 if (slab_is_available()) {
221 *(char **)kp->arg = kstrdup(val, GFP_KERNEL); 267 *(char **)kp->arg = kmalloc_parameter(strlen(val)+1);
222 if (!*(char **)kp->arg) 268 if (!*(char **)kp->arg)
223 return -ENOMEM; 269 return -ENOMEM;
270 strcpy(*(char **)kp->arg, val);
224 } else 271 } else
225 *(const char **)kp->arg = val; 272 *(const char **)kp->arg = val;
226 273
227 return 0; 274 return 0;
228} 275}
276EXPORT_SYMBOL(param_set_charp);
229 277
230int param_get_charp(char *buffer, struct kernel_param *kp) 278int param_get_charp(char *buffer, const struct kernel_param *kp)
231{ 279{
232 return sprintf(buffer, "%s", *((char **)kp->arg)); 280 return sprintf(buffer, "%s", *((char **)kp->arg));
233} 281}
282EXPORT_SYMBOL(param_get_charp);
283
284static void param_free_charp(void *arg)
285{
286 maybe_kfree_parameter(*((char **)arg));
287}
288
289struct kernel_param_ops param_ops_charp = {
290 .set = param_set_charp,
291 .get = param_get_charp,
292 .free = param_free_charp,
293};
294EXPORT_SYMBOL(param_ops_charp);
234 295
235/* Actually could be a bool or an int, for historical reasons. */ 296/* Actually could be a bool or an int, for historical reasons. */
236int param_set_bool(const char *val, struct kernel_param *kp) 297int param_set_bool(const char *val, const struct kernel_param *kp)
237{ 298{
238 bool v; 299 bool v;
239 300
@@ -258,8 +319,9 @@ int param_set_bool(const char *val, struct kernel_param *kp)
258 *(int *)kp->arg = v; 319 *(int *)kp->arg = v;
259 return 0; 320 return 0;
260} 321}
322EXPORT_SYMBOL(param_set_bool);
261 323
262int param_get_bool(char *buffer, struct kernel_param *kp) 324int param_get_bool(char *buffer, const struct kernel_param *kp)
263{ 325{
264 bool val; 326 bool val;
265 if (kp->flags & KPARAM_ISBOOL) 327 if (kp->flags & KPARAM_ISBOOL)
@@ -270,9 +332,16 @@ int param_get_bool(char *buffer, struct kernel_param *kp)
270 /* Y and N chosen as being relatively non-coder friendly */ 332 /* Y and N chosen as being relatively non-coder friendly */
271 return sprintf(buffer, "%c", val ? 'Y' : 'N'); 333 return sprintf(buffer, "%c", val ? 'Y' : 'N');
272} 334}
335EXPORT_SYMBOL(param_get_bool);
336
337struct kernel_param_ops param_ops_bool = {
338 .set = param_set_bool,
339 .get = param_get_bool,
340};
341EXPORT_SYMBOL(param_ops_bool);
273 342
274/* This one must be bool. */ 343/* This one must be bool. */
275int param_set_invbool(const char *val, struct kernel_param *kp) 344int param_set_invbool(const char *val, const struct kernel_param *kp)
276{ 345{
277 int ret; 346 int ret;
278 bool boolval; 347 bool boolval;
@@ -285,18 +354,26 @@ int param_set_invbool(const char *val, struct kernel_param *kp)
285 *(bool *)kp->arg = !boolval; 354 *(bool *)kp->arg = !boolval;
286 return ret; 355 return ret;
287} 356}
357EXPORT_SYMBOL(param_set_invbool);
288 358
289int param_get_invbool(char *buffer, struct kernel_param *kp) 359int param_get_invbool(char *buffer, const struct kernel_param *kp)
290{ 360{
291 return sprintf(buffer, "%c", (*(bool *)kp->arg) ? 'N' : 'Y'); 361 return sprintf(buffer, "%c", (*(bool *)kp->arg) ? 'N' : 'Y');
292} 362}
363EXPORT_SYMBOL(param_get_invbool);
364
365struct kernel_param_ops param_ops_invbool = {
366 .set = param_set_invbool,
367 .get = param_get_invbool,
368};
369EXPORT_SYMBOL(param_ops_invbool);
293 370
294/* We break the rule and mangle the string. */ 371/* We break the rule and mangle the string. */
295static int param_array(const char *name, 372static int param_array(const char *name,
296 const char *val, 373 const char *val,
297 unsigned int min, unsigned int max, 374 unsigned int min, unsigned int max,
298 void *elem, int elemsize, 375 void *elem, int elemsize,
299 int (*set)(const char *, struct kernel_param *kp), 376 int (*set)(const char *, const struct kernel_param *kp),
300 u16 flags, 377 u16 flags,
301 unsigned int *num) 378 unsigned int *num)
302{ 379{
@@ -309,12 +386,6 @@ static int param_array(const char *name,
309 kp.arg = elem; 386 kp.arg = elem;
310 kp.flags = flags; 387 kp.flags = flags;
311 388
312 /* No equals sign? */
313 if (!val) {
314 printk(KERN_ERR "%s: expects arguments\n", name);
315 return -EINVAL;
316 }
317
318 *num = 0; 389 *num = 0;
319 /* We expect a comma-separated list of values. */ 390 /* We expect a comma-separated list of values. */
320 do { 391 do {
@@ -330,6 +401,7 @@ static int param_array(const char *name,
330 /* nul-terminate and parse */ 401 /* nul-terminate and parse */
331 save = val[len]; 402 save = val[len];
332 ((char *)val)[len] = '\0'; 403 ((char *)val)[len] = '\0';
404 BUG_ON(!mutex_is_locked(&param_lock));
333 ret = set(val, &kp); 405 ret = set(val, &kp);
334 406
335 if (ret != 0) 407 if (ret != 0)
@@ -347,17 +419,17 @@ static int param_array(const char *name,
347 return 0; 419 return 0;
348} 420}
349 421
350int param_array_set(const char *val, struct kernel_param *kp) 422static int param_array_set(const char *val, const struct kernel_param *kp)
351{ 423{
352 const struct kparam_array *arr = kp->arr; 424 const struct kparam_array *arr = kp->arr;
353 unsigned int temp_num; 425 unsigned int temp_num;
354 426
355 return param_array(kp->name, val, 1, arr->max, arr->elem, 427 return param_array(kp->name, val, 1, arr->max, arr->elem,
356 arr->elemsize, arr->set, kp->flags, 428 arr->elemsize, arr->ops->set, kp->flags,
357 arr->num ?: &temp_num); 429 arr->num ?: &temp_num);
358} 430}
359 431
360int param_array_get(char *buffer, struct kernel_param *kp) 432static int param_array_get(char *buffer, const struct kernel_param *kp)
361{ 433{
362 int i, off, ret; 434 int i, off, ret;
363 const struct kparam_array *arr = kp->arr; 435 const struct kparam_array *arr = kp->arr;
@@ -368,7 +440,8 @@ int param_array_get(char *buffer, struct kernel_param *kp)
368 if (i) 440 if (i)
369 buffer[off++] = ','; 441 buffer[off++] = ',';
370 p.arg = arr->elem + arr->elemsize * i; 442 p.arg = arr->elem + arr->elemsize * i;
371 ret = arr->get(buffer + off, &p); 443 BUG_ON(!mutex_is_locked(&param_lock));
444 ret = arr->ops->get(buffer + off, &p);
372 if (ret < 0) 445 if (ret < 0)
373 return ret; 446 return ret;
374 off += ret; 447 off += ret;
@@ -377,14 +450,27 @@ int param_array_get(char *buffer, struct kernel_param *kp)
377 return off; 450 return off;
378} 451}
379 452
380int param_set_copystring(const char *val, struct kernel_param *kp) 453static void param_array_free(void *arg)
454{
455 unsigned int i;
456 const struct kparam_array *arr = arg;
457
458 if (arr->ops->free)
459 for (i = 0; i < (arr->num ? *arr->num : arr->max); i++)
460 arr->ops->free(arr->elem + arr->elemsize * i);
461}
462
463struct kernel_param_ops param_array_ops = {
464 .set = param_array_set,
465 .get = param_array_get,
466 .free = param_array_free,
467};
468EXPORT_SYMBOL(param_array_ops);
469
470int param_set_copystring(const char *val, const struct kernel_param *kp)
381{ 471{
382 const struct kparam_string *kps = kp->str; 472 const struct kparam_string *kps = kp->str;
383 473
384 if (!val) {
385 printk(KERN_ERR "%s: missing param set value\n", kp->name);
386 return -EINVAL;
387 }
388 if (strlen(val)+1 > kps->maxlen) { 474 if (strlen(val)+1 > kps->maxlen) {
389 printk(KERN_ERR "%s: string doesn't fit in %u chars.\n", 475 printk(KERN_ERR "%s: string doesn't fit in %u chars.\n",
390 kp->name, kps->maxlen-1); 476 kp->name, kps->maxlen-1);
@@ -393,12 +479,20 @@ int param_set_copystring(const char *val, struct kernel_param *kp)
393 strcpy(kps->string, val); 479 strcpy(kps->string, val);
394 return 0; 480 return 0;
395} 481}
482EXPORT_SYMBOL(param_set_copystring);
396 483
397int param_get_string(char *buffer, struct kernel_param *kp) 484int param_get_string(char *buffer, const struct kernel_param *kp)
398{ 485{
399 const struct kparam_string *kps = kp->str; 486 const struct kparam_string *kps = kp->str;
400 return strlcpy(buffer, kps->string, kps->maxlen); 487 return strlcpy(buffer, kps->string, kps->maxlen);
401} 488}
489EXPORT_SYMBOL(param_get_string);
490
491struct kernel_param_ops param_ops_string = {
492 .set = param_set_copystring,
493 .get = param_get_string,
494};
495EXPORT_SYMBOL(param_ops_string);
402 496
403/* sysfs output in /sys/modules/XYZ/parameters/ */ 497/* sysfs output in /sys/modules/XYZ/parameters/ */
404#define to_module_attr(n) container_of(n, struct module_attribute, attr) 498#define to_module_attr(n) container_of(n, struct module_attribute, attr)
@@ -409,7 +503,7 @@ extern struct kernel_param __start___param[], __stop___param[];
409struct param_attribute 503struct param_attribute
410{ 504{
411 struct module_attribute mattr; 505 struct module_attribute mattr;
412 struct kernel_param *param; 506 const struct kernel_param *param;
413}; 507};
414 508
415struct module_param_attrs 509struct module_param_attrs
@@ -428,10 +522,12 @@ static ssize_t param_attr_show(struct module_attribute *mattr,
428 int count; 522 int count;
429 struct param_attribute *attribute = to_param_attr(mattr); 523 struct param_attribute *attribute = to_param_attr(mattr);
430 524
431 if (!attribute->param->get) 525 if (!attribute->param->ops->get)
432 return -EPERM; 526 return -EPERM;
433 527
434 count = attribute->param->get(buf, attribute->param); 528 mutex_lock(&param_lock);
529 count = attribute->param->ops->get(buf, attribute->param);
530 mutex_unlock(&param_lock);
435 if (count > 0) { 531 if (count > 0) {
436 strcat(buf, "\n"); 532 strcat(buf, "\n");
437 ++count; 533 ++count;
@@ -447,10 +543,12 @@ static ssize_t param_attr_store(struct module_attribute *mattr,
447 int err; 543 int err;
448 struct param_attribute *attribute = to_param_attr(mattr); 544 struct param_attribute *attribute = to_param_attr(mattr);
449 545
450 if (!attribute->param->set) 546 if (!attribute->param->ops->set)
451 return -EPERM; 547 return -EPERM;
452 548
453 err = attribute->param->set(buf, attribute->param); 549 mutex_lock(&param_lock);
550 err = attribute->param->ops->set(buf, attribute->param);
551 mutex_unlock(&param_lock);
454 if (!err) 552 if (!err)
455 return len; 553 return len;
456 return err; 554 return err;
@@ -464,6 +562,18 @@ static ssize_t param_attr_store(struct module_attribute *mattr,
464#endif 562#endif
465 563
466#ifdef CONFIG_SYSFS 564#ifdef CONFIG_SYSFS
565void __kernel_param_lock(void)
566{
567 mutex_lock(&param_lock);
568}
569EXPORT_SYMBOL(__kernel_param_lock);
570
571void __kernel_param_unlock(void)
572{
573 mutex_unlock(&param_lock);
574}
575EXPORT_SYMBOL(__kernel_param_unlock);
576
467/* 577/*
468 * add_sysfs_param - add a parameter to sysfs 578 * add_sysfs_param - add a parameter to sysfs
469 * @mk: struct module_kobject 579 * @mk: struct module_kobject
@@ -475,7 +585,7 @@ static ssize_t param_attr_store(struct module_attribute *mattr,
475 * if there's an error. 585 * if there's an error.
476 */ 586 */
477static __modinit int add_sysfs_param(struct module_kobject *mk, 587static __modinit int add_sysfs_param(struct module_kobject *mk,
478 struct kernel_param *kp, 588 const struct kernel_param *kp,
479 const char *name) 589 const char *name)
480{ 590{
481 struct module_param_attrs *new; 591 struct module_param_attrs *new;
@@ -557,7 +667,7 @@ static void free_module_param_attrs(struct module_kobject *mk)
557 * /sys/module/[mod->name]/parameters/ 667 * /sys/module/[mod->name]/parameters/
558 */ 668 */
559int module_param_sysfs_setup(struct module *mod, 669int module_param_sysfs_setup(struct module *mod,
560 struct kernel_param *kparam, 670 const struct kernel_param *kparam,
561 unsigned int num_params) 671 unsigned int num_params)
562{ 672{
563 int i, err; 673 int i, err;
@@ -602,7 +712,11 @@ void module_param_sysfs_remove(struct module *mod)
602 712
603void destroy_params(const struct kernel_param *params, unsigned num) 713void destroy_params(const struct kernel_param *params, unsigned num)
604{ 714{
605 /* FIXME: This should free kmalloced charp parameters. It doesn't. */ 715 unsigned int i;
716
717 for (i = 0; i < num; i++)
718 if (params[i].ops->free)
719 params[i].ops->free(params[i].arg);
606} 720}
607 721
608static void __init kernel_add_sysfs_param(const char *name, 722static void __init kernel_add_sysfs_param(const char *name,
@@ -768,28 +882,3 @@ static int __init param_sysfs_init(void)
768subsys_initcall(param_sysfs_init); 882subsys_initcall(param_sysfs_init);
769 883
770#endif /* CONFIG_SYSFS */ 884#endif /* CONFIG_SYSFS */
771
772EXPORT_SYMBOL(param_set_byte);
773EXPORT_SYMBOL(param_get_byte);
774EXPORT_SYMBOL(param_set_short);
775EXPORT_SYMBOL(param_get_short);
776EXPORT_SYMBOL(param_set_ushort);
777EXPORT_SYMBOL(param_get_ushort);
778EXPORT_SYMBOL(param_set_int);
779EXPORT_SYMBOL(param_get_int);
780EXPORT_SYMBOL(param_set_uint);
781EXPORT_SYMBOL(param_get_uint);
782EXPORT_SYMBOL(param_set_long);
783EXPORT_SYMBOL(param_get_long);
784EXPORT_SYMBOL(param_set_ulong);
785EXPORT_SYMBOL(param_get_ulong);
786EXPORT_SYMBOL(param_set_charp);
787EXPORT_SYMBOL(param_get_charp);
788EXPORT_SYMBOL(param_set_bool);
789EXPORT_SYMBOL(param_get_bool);
790EXPORT_SYMBOL(param_set_invbool);
791EXPORT_SYMBOL(param_get_invbool);
792EXPORT_SYMBOL(param_array_set);
793EXPORT_SYMBOL(param_array_get);
794EXPORT_SYMBOL(param_set_copystring);
795EXPORT_SYMBOL(param_get_string);
diff --git a/kernel/pid.c b/kernel/pid.c
index e9fd8c132d26..d55c6fb8d087 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -122,6 +122,43 @@ static void free_pidmap(struct upid *upid)
122 atomic_inc(&map->nr_free); 122 atomic_inc(&map->nr_free);
123} 123}
124 124
125/*
126 * If we started walking pids at 'base', is 'a' seen before 'b'?
127 */
128static int pid_before(int base, int a, int b)
129{
130 /*
131 * This is the same as saying
132 *
133 * (a - base + MAXUINT) % MAXUINT < (b - base + MAXUINT) % MAXUINT
134 * and that mapping orders 'a' and 'b' with respect to 'base'.
135 */
136 return (unsigned)(a - base) < (unsigned)(b - base);
137}
138
139/*
140 * We might be racing with someone else trying to set pid_ns->last_pid.
141 * We want the winner to have the "later" value, because if the
142 * "earlier" value prevails, then a pid may get reused immediately.
143 *
144 * Since pids rollover, it is not sufficient to just pick the bigger
145 * value. We have to consider where we started counting from.
146 *
147 * 'base' is the value of pid_ns->last_pid that we observed when
148 * we started looking for a pid.
149 *
150 * 'pid' is the pid that we eventually found.
151 */
152static void set_last_pid(struct pid_namespace *pid_ns, int base, int pid)
153{
154 int prev;
155 int last_write = base;
156 do {
157 prev = last_write;
158 last_write = cmpxchg(&pid_ns->last_pid, prev, pid);
159 } while ((prev != last_write) && (pid_before(base, last_write, pid)));
160}
161
125static int alloc_pidmap(struct pid_namespace *pid_ns) 162static int alloc_pidmap(struct pid_namespace *pid_ns)
126{ 163{
127 int i, offset, max_scan, pid, last = pid_ns->last_pid; 164 int i, offset, max_scan, pid, last = pid_ns->last_pid;
@@ -132,7 +169,12 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
132 pid = RESERVED_PIDS; 169 pid = RESERVED_PIDS;
133 offset = pid & BITS_PER_PAGE_MASK; 170 offset = pid & BITS_PER_PAGE_MASK;
134 map = &pid_ns->pidmap[pid/BITS_PER_PAGE]; 171 map = &pid_ns->pidmap[pid/BITS_PER_PAGE];
135 max_scan = (pid_max + BITS_PER_PAGE - 1)/BITS_PER_PAGE - !offset; 172 /*
173 * If last_pid points into the middle of the map->page we
174 * want to scan this bitmap block twice, the second time
175 * we start with offset == 0 (or RESERVED_PIDS).
176 */
177 max_scan = DIV_ROUND_UP(pid_max, BITS_PER_PAGE) - !offset;
136 for (i = 0; i <= max_scan; ++i) { 178 for (i = 0; i <= max_scan; ++i) {
137 if (unlikely(!map->page)) { 179 if (unlikely(!map->page)) {
138 void *page = kzalloc(PAGE_SIZE, GFP_KERNEL); 180 void *page = kzalloc(PAGE_SIZE, GFP_KERNEL);
@@ -154,20 +196,12 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
154 do { 196 do {
155 if (!test_and_set_bit(offset, map->page)) { 197 if (!test_and_set_bit(offset, map->page)) {
156 atomic_dec(&map->nr_free); 198 atomic_dec(&map->nr_free);
157 pid_ns->last_pid = pid; 199 set_last_pid(pid_ns, last, pid);
158 return pid; 200 return pid;
159 } 201 }
160 offset = find_next_offset(map, offset); 202 offset = find_next_offset(map, offset);
161 pid = mk_pid(pid_ns, map, offset); 203 pid = mk_pid(pid_ns, map, offset);
162 /* 204 } while (offset < BITS_PER_PAGE && pid < pid_max);
163 * find_next_offset() found a bit, the pid from it
164 * is in-bounds, and if we fell back to the last
165 * bitmap block and the final block was the same
166 * as the starting point, pid is before last_pid.
167 */
168 } while (offset < BITS_PER_PAGE && pid < pid_max &&
169 (i != max_scan || pid < last ||
170 !((last+1) & BITS_PER_PAGE_MASK)));
171 } 205 }
172 if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) { 206 if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) {
173 ++map; 207 ++map;
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 74a3d693c196..f34d798ef4a2 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -324,26 +324,32 @@ int ptrace_detach(struct task_struct *child, unsigned int data)
324} 324}
325 325
326/* 326/*
327 * Detach all tasks we were using ptrace on. 327 * Detach all tasks we were using ptrace on. Called with tasklist held
328 * for writing, and returns with it held too. But note it can release
329 * and reacquire the lock.
328 */ 330 */
329void exit_ptrace(struct task_struct *tracer) 331void exit_ptrace(struct task_struct *tracer)
330{ 332{
331 struct task_struct *p, *n; 333 struct task_struct *p, *n;
332 LIST_HEAD(ptrace_dead); 334 LIST_HEAD(ptrace_dead);
333 335
334 write_lock_irq(&tasklist_lock); 336 if (likely(list_empty(&tracer->ptraced)))
337 return;
338
335 list_for_each_entry_safe(p, n, &tracer->ptraced, ptrace_entry) { 339 list_for_each_entry_safe(p, n, &tracer->ptraced, ptrace_entry) {
336 if (__ptrace_detach(tracer, p)) 340 if (__ptrace_detach(tracer, p))
337 list_add(&p->ptrace_entry, &ptrace_dead); 341 list_add(&p->ptrace_entry, &ptrace_dead);
338 } 342 }
339 write_unlock_irq(&tasklist_lock);
340 343
344 write_unlock_irq(&tasklist_lock);
341 BUG_ON(!list_empty(&tracer->ptraced)); 345 BUG_ON(!list_empty(&tracer->ptraced));
342 346
343 list_for_each_entry_safe(p, n, &ptrace_dead, ptrace_entry) { 347 list_for_each_entry_safe(p, n, &ptrace_dead, ptrace_entry) {
344 list_del_init(&p->ptrace_entry); 348 list_del_init(&p->ptrace_entry);
345 release_task(p); 349 release_task(p);
346 } 350 }
351
352 write_lock_irq(&tasklist_lock);
347} 353}
348 354
349int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len) 355int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index e14c839e9faa..e960d824263f 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -690,6 +690,7 @@ static void timekeeping_adjust(s64 offset)
690static cycle_t logarithmic_accumulation(cycle_t offset, int shift) 690static cycle_t logarithmic_accumulation(cycle_t offset, int shift)
691{ 691{
692 u64 nsecps = (u64)NSEC_PER_SEC << timekeeper.shift; 692 u64 nsecps = (u64)NSEC_PER_SEC << timekeeper.shift;
693 u64 raw_nsecs;
693 694
694 /* If the offset is smaller then a shifted interval, do nothing */ 695 /* If the offset is smaller then a shifted interval, do nothing */
695 if (offset < timekeeper.cycle_interval<<shift) 696 if (offset < timekeeper.cycle_interval<<shift)
@@ -706,12 +707,14 @@ static cycle_t logarithmic_accumulation(cycle_t offset, int shift)
706 second_overflow(); 707 second_overflow();
707 } 708 }
708 709
709 /* Accumulate into raw time */ 710 /* Accumulate raw time */
710 raw_time.tv_nsec += timekeeper.raw_interval << shift;; 711 raw_nsecs = timekeeper.raw_interval << shift;
711 while (raw_time.tv_nsec >= NSEC_PER_SEC) { 712 raw_nsecs += raw_time.tv_nsec;
712 raw_time.tv_nsec -= NSEC_PER_SEC; 713 while (raw_nsecs >= NSEC_PER_SEC) {
714 raw_nsecs -= NSEC_PER_SEC;
713 raw_time.tv_sec++; 715 raw_time.tv_sec++;
714 } 716 }
717 raw_time.tv_nsec = raw_nsecs;
715 718
716 /* Accumulate error between NTP and clock interval */ 719 /* Accumulate error between NTP and clock interval */
717 timekeeper.ntp_error += tick_length << shift; 720 timekeeper.ntp_error += tick_length << shift;
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 82499a5bdcb7..959f8d6c8cc1 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -710,6 +710,9 @@ static void blk_add_trace_rq(struct request_queue *q, struct request *rq,
710 if (rq->cmd_flags & REQ_DISCARD) 710 if (rq->cmd_flags & REQ_DISCARD)
711 rw |= REQ_DISCARD; 711 rw |= REQ_DISCARD;
712 712
713 if (rq->cmd_flags & REQ_SECURE)
714 rw |= REQ_SECURE;
715
713 if (rq->cmd_type == REQ_TYPE_BLOCK_PC) { 716 if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
714 what |= BLK_TC_ACT(BLK_TC_PC); 717 what |= BLK_TC_ACT(BLK_TC_PC);
715 __blk_add_trace(bt, 0, blk_rq_bytes(rq), rw, 718 __blk_add_trace(bt, 0, blk_rq_bytes(rq), rw,
@@ -1816,6 +1819,8 @@ void blk_fill_rwbs(char *rwbs, u32 rw, int bytes)
1816 rwbs[i++] = 'S'; 1819 rwbs[i++] = 'S';
1817 if (rw & REQ_META) 1820 if (rw & REQ_META)
1818 rwbs[i++] = 'M'; 1821 rwbs[i++] = 'M';
1822 if (rw & REQ_SECURE)
1823 rwbs[i++] = 'E';
1819 1824
1820 rwbs[i] = '\0'; 1825 rwbs[i] = '\0';
1821} 1826}
@@ -1828,6 +1833,9 @@ void blk_fill_rwbs_rq(char *rwbs, struct request *rq)
1828 if (rq->cmd_flags & REQ_DISCARD) 1833 if (rq->cmd_flags & REQ_DISCARD)
1829 rw |= REQ_DISCARD; 1834 rw |= REQ_DISCARD;
1830 1835
1836 if (rq->cmd_flags & REQ_SECURE)
1837 rw |= REQ_SECURE;
1838
1831 bytes = blk_rq_bytes(rq); 1839 bytes = blk_rq_bytes(rq);
1832 1840
1833 blk_fill_rwbs(rwbs, rw, bytes); 1841 blk_fill_rwbs(rwbs, rw, bytes);
diff --git a/lib/bug.c b/lib/bug.c
index f13daf435211..7cdfad88128f 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -136,8 +136,6 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
136 136
137 bug = find_bug(bugaddr); 137 bug = find_bug(bugaddr);
138 138
139 printk(KERN_EMERG "------------[ cut here ]------------\n");
140
141 file = NULL; 139 file = NULL;
142 line = 0; 140 line = 0;
143 warning = 0; 141 warning = 0;
@@ -156,19 +154,25 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
156 154
157 if (warning) { 155 if (warning) {
158 /* this is a WARN_ON rather than BUG/BUG_ON */ 156 /* this is a WARN_ON rather than BUG/BUG_ON */
157 printk(KERN_WARNING "------------[ cut here ]------------\n");
158
159 if (file) 159 if (file)
160 printk(KERN_ERR "Badness at %s:%u\n", 160 printk(KERN_WARNING "WARNING: at %s:%u\n",
161 file, line); 161 file, line);
162 else 162 else
163 printk(KERN_ERR "Badness at %p " 163 printk(KERN_WARNING "WARNING: at %p "
164 "[verbose debug info unavailable]\n", 164 "[verbose debug info unavailable]\n",
165 (void *)bugaddr); 165 (void *)bugaddr);
166 166
167 print_modules();
167 show_regs(regs); 168 show_regs(regs);
169 print_oops_end_marker();
168 add_taint(BUG_GET_TAINT(bug)); 170 add_taint(BUG_GET_TAINT(bug));
169 return BUG_TRAP_TYPE_WARN; 171 return BUG_TRAP_TYPE_WARN;
170 } 172 }
171 173
174 printk(KERN_EMERG "------------[ cut here ]------------\n");
175
172 if (file) 176 if (file)
173 printk(KERN_CRIT "kernel BUG at %s:%u!\n", 177 printk(KERN_CRIT "kernel BUG at %s:%u!\n",
174 file, line); 178 file, line);
diff --git a/lib/decompress_bunzip2.c b/lib/decompress_bunzip2.c
index a4e971dee102..81c8bb1cc6aa 100644
--- a/lib/decompress_bunzip2.c
+++ b/lib/decompress_bunzip2.c
@@ -107,6 +107,8 @@ struct bunzip_data {
107 unsigned char selectors[32768]; /* nSelectors = 15 bits */ 107 unsigned char selectors[32768]; /* nSelectors = 15 bits */
108 struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */ 108 struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */
109 int io_error; /* non-zero if we have IO error */ 109 int io_error; /* non-zero if we have IO error */
110 int byteCount[256];
111 unsigned char symToByte[256], mtfSymbol[256];
110}; 112};
111 113
112 114
@@ -158,14 +160,16 @@ static int INIT get_next_block(struct bunzip_data *bd)
158 int *base = NULL; 160 int *base = NULL;
159 int *limit = NULL; 161 int *limit = NULL;
160 int dbufCount, nextSym, dbufSize, groupCount, selector, 162 int dbufCount, nextSym, dbufSize, groupCount, selector,
161 i, j, k, t, runPos, symCount, symTotal, nSelectors, 163 i, j, k, t, runPos, symCount, symTotal, nSelectors, *byteCount;
162 byteCount[256]; 164 unsigned char uc, *symToByte, *mtfSymbol, *selectors;
163 unsigned char uc, symToByte[256], mtfSymbol[256], *selectors;
164 unsigned int *dbuf, origPtr; 165 unsigned int *dbuf, origPtr;
165 166
166 dbuf = bd->dbuf; 167 dbuf = bd->dbuf;
167 dbufSize = bd->dbufSize; 168 dbufSize = bd->dbufSize;
168 selectors = bd->selectors; 169 selectors = bd->selectors;
170 byteCount = bd->byteCount;
171 symToByte = bd->symToByte;
172 mtfSymbol = bd->mtfSymbol;
169 173
170 /* Read in header signature and CRC, then validate signature. 174 /* Read in header signature and CRC, then validate signature.
171 (last block signature means CRC is for whole file, return now) */ 175 (last block signature means CRC is for whole file, return now) */
diff --git a/lib/inflate.c b/lib/inflate.c
index 677b738c2204..013a76193481 100644
--- a/lib/inflate.c
+++ b/lib/inflate.c
@@ -103,7 +103,9 @@
103 the two sets of lengths. 103 the two sets of lengths.
104 */ 104 */
105#include <linux/compiler.h> 105#include <linux/compiler.h>
106#ifdef NO_INFLATE_MALLOC
106#include <linux/slab.h> 107#include <linux/slab.h>
108#endif
107 109
108#ifdef RCSID 110#ifdef RCSID
109static char rcsid[] = "#Id: inflate.c,v 0.14 1993/06/10 13:27:04 jloup Exp #"; 111static char rcsid[] = "#Id: inflate.c,v 0.14 1993/06/10 13:27:04 jloup Exp #";
diff --git a/lib/raid6/Makefile b/lib/raid6/Makefile
index 19bf32da644f..8a38102770f3 100644
--- a/lib/raid6/Makefile
+++ b/lib/raid6/Makefile
@@ -1,11 +1,8 @@
1obj-$(CONFIG_RAID6_PQ) += raid6_pq.o 1obj-$(CONFIG_RAID6_PQ) += raid6_pq.o
2 2
3raid6_pq-y += raid6algos.o raid6recov.o raid6tables.o \ 3raid6_pq-y += algos.o recov.o tables.o int1.o int2.o int4.o \
4 raid6int1.o raid6int2.o raid6int4.o \ 4 int8.o int16.o int32.o altivec1.o altivec2.o altivec4.o \
5 raid6int8.o raid6int16.o raid6int32.o \ 5 altivec8.o mmx.o sse1.o sse2.o
6 raid6altivec1.o raid6altivec2.o raid6altivec4.o \
7 raid6altivec8.o \
8 raid6mmx.o raid6sse1.o raid6sse2.o
9hostprogs-y += mktables 6hostprogs-y += mktables
10 7
11quiet_cmd_unroll = UNROLL $@ 8quiet_cmd_unroll = UNROLL $@
@@ -16,63 +13,63 @@ ifeq ($(CONFIG_ALTIVEC),y)
16altivec_flags := -maltivec -mabi=altivec 13altivec_flags := -maltivec -mabi=altivec
17endif 14endif
18 15
19targets += raid6int1.c 16targets += int1.c
20$(obj)/raid6int1.c: UNROLL := 1 17$(obj)/int1.c: UNROLL := 1
21$(obj)/raid6int1.c: $(src)/raid6int.uc $(src)/unroll.awk FORCE 18$(obj)/int1.c: $(src)/int.uc $(src)/unroll.awk FORCE
22 $(call if_changed,unroll) 19 $(call if_changed,unroll)
23 20
24targets += raid6int2.c 21targets += int2.c
25$(obj)/raid6int2.c: UNROLL := 2 22$(obj)/int2.c: UNROLL := 2
26$(obj)/raid6int2.c: $(src)/raid6int.uc $(src)/unroll.awk FORCE 23$(obj)/int2.c: $(src)/int.uc $(src)/unroll.awk FORCE
27 $(call if_changed,unroll) 24 $(call if_changed,unroll)
28 25
29targets += raid6int4.c 26targets += int4.c
30$(obj)/raid6int4.c: UNROLL := 4 27$(obj)/int4.c: UNROLL := 4
31$(obj)/raid6int4.c: $(src)/raid6int.uc $(src)/unroll.awk FORCE 28$(obj)/int4.c: $(src)/int.uc $(src)/unroll.awk FORCE
32 $(call if_changed,unroll) 29 $(call if_changed,unroll)
33 30
34targets += raid6int8.c 31targets += int8.c
35$(obj)/raid6int8.c: UNROLL := 8 32$(obj)/int8.c: UNROLL := 8
36$(obj)/raid6int8.c: $(src)/raid6int.uc $(src)/unroll.awk FORCE 33$(obj)/int8.c: $(src)/int.uc $(src)/unroll.awk FORCE
37 $(call if_changed,unroll) 34 $(call if_changed,unroll)
38 35
39targets += raid6int16.c 36targets += int16.c
40$(obj)/raid6int16.c: UNROLL := 16 37$(obj)/int16.c: UNROLL := 16
41$(obj)/raid6int16.c: $(src)/raid6int.uc $(src)/unroll.awk FORCE 38$(obj)/int16.c: $(src)/int.uc $(src)/unroll.awk FORCE
42 $(call if_changed,unroll) 39 $(call if_changed,unroll)
43 40
44targets += raid6int32.c 41targets += int32.c
45$(obj)/raid6int32.c: UNROLL := 32 42$(obj)/int32.c: UNROLL := 32
46$(obj)/raid6int32.c: $(src)/raid6int.uc $(src)/unroll.awk FORCE 43$(obj)/int32.c: $(src)/int.uc $(src)/unroll.awk FORCE
47 $(call if_changed,unroll) 44 $(call if_changed,unroll)
48 45
49CFLAGS_raid6altivec1.o += $(altivec_flags) 46CFLAGS_altivec1.o += $(altivec_flags)
50targets += raid6altivec1.c 47targets += altivec1.c
51$(obj)/raid6altivec1.c: UNROLL := 1 48$(obj)/altivec1.c: UNROLL := 1
52$(obj)/raid6altivec1.c: $(src)/raid6altivec.uc $(src)/unroll.awk FORCE 49$(obj)/altivec1.c: $(src)/altivec.uc $(src)/unroll.awk FORCE
53 $(call if_changed,unroll) 50 $(call if_changed,unroll)
54 51
55CFLAGS_raid6altivec2.o += $(altivec_flags) 52CFLAGS_altivec2.o += $(altivec_flags)
56targets += raid6altivec2.c 53targets += altivec2.c
57$(obj)/raid6altivec2.c: UNROLL := 2 54$(obj)/altivec2.c: UNROLL := 2
58$(obj)/raid6altivec2.c: $(src)/raid6altivec.uc $(src)/unroll.awk FORCE 55$(obj)/altivec2.c: $(src)/altivec.uc $(src)/unroll.awk FORCE
59 $(call if_changed,unroll) 56 $(call if_changed,unroll)
60 57
61CFLAGS_raid6altivec4.o += $(altivec_flags) 58CFLAGS_altivec4.o += $(altivec_flags)
62targets += raid6altivec4.c 59targets += altivec4.c
63$(obj)/raid6altivec4.c: UNROLL := 4 60$(obj)/altivec4.c: UNROLL := 4
64$(obj)/raid6altivec4.c: $(src)/raid6altivec.uc $(src)/unroll.awk FORCE 61$(obj)/altivec4.c: $(src)/altivec.uc $(src)/unroll.awk FORCE
65 $(call if_changed,unroll) 62 $(call if_changed,unroll)
66 63
67CFLAGS_raid6altivec8.o += $(altivec_flags) 64CFLAGS_altivec8.o += $(altivec_flags)
68targets += raid6altivec8.c 65targets += altivec8.c
69$(obj)/raid6altivec8.c: UNROLL := 8 66$(obj)/altivec8.c: UNROLL := 8
70$(obj)/raid6altivec8.c: $(src)/raid6altivec.uc $(src)/unroll.awk FORCE 67$(obj)/altivec8.c: $(src)/altivec.uc $(src)/unroll.awk FORCE
71 $(call if_changed,unroll) 68 $(call if_changed,unroll)
72 69
73quiet_cmd_mktable = TABLE $@ 70quiet_cmd_mktable = TABLE $@
74 cmd_mktable = $(obj)/mktables > $@ || ( rm -f $@ && exit 1 ) 71 cmd_mktable = $(obj)/mktables > $@ || ( rm -f $@ && exit 1 )
75 72
76targets += raid6tables.c 73targets += tables.c
77$(obj)/raid6tables.c: $(obj)/mktables FORCE 74$(obj)/tables.c: $(obj)/mktables FORCE
78 $(call if_changed,mktable) 75 $(call if_changed,mktable)
diff --git a/lib/raid6/raid6algos.c b/lib/raid6/algos.c
index 1f8784bfd44d..b595f560bee7 100644
--- a/lib/raid6/raid6algos.c
+++ b/lib/raid6/algos.c
@@ -11,17 +11,17 @@
11 * ----------------------------------------------------------------------- */ 11 * ----------------------------------------------------------------------- */
12 12
13/* 13/*
14 * raid6algos.c 14 * raid6/algos.c
15 * 15 *
16 * Algorithm list and algorithm selection for RAID-6 16 * Algorithm list and algorithm selection for RAID-6
17 */ 17 */
18 18
19#include <linux/raid/pq.h> 19#include <linux/raid/pq.h>
20#include <linux/gfp.h>
21#ifndef __KERNEL__ 20#ifndef __KERNEL__
22#include <sys/mman.h> 21#include <sys/mman.h>
23#include <stdio.h> 22#include <stdio.h>
24#else 23#else
24#include <linux/gfp.h>
25#if !RAID6_USE_EMPTY_ZERO_PAGE 25#if !RAID6_USE_EMPTY_ZERO_PAGE
26/* In .bss so it's zeroed */ 26/* In .bss so it's zeroed */
27const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256))); 27const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256)));
diff --git a/lib/raid6/raid6altivec.uc b/lib/raid6/altivec.uc
index 2654d5c854be..2654d5c854be 100644
--- a/lib/raid6/raid6altivec.uc
+++ b/lib/raid6/altivec.uc
diff --git a/lib/raid6/raid6int.uc b/lib/raid6/int.uc
index d1e276a14fab..d1e276a14fab 100644
--- a/lib/raid6/raid6int.uc
+++ b/lib/raid6/int.uc
diff --git a/lib/raid6/raid6mmx.c b/lib/raid6/mmx.c
index e7f6c13132bf..279347f23094 100644
--- a/lib/raid6/raid6mmx.c
+++ b/lib/raid6/mmx.c
@@ -11,7 +11,7 @@
11 * ----------------------------------------------------------------------- */ 11 * ----------------------------------------------------------------------- */
12 12
13/* 13/*
14 * raid6mmx.c 14 * raid6/mmx.c
15 * 15 *
16 * MMX implementation of RAID-6 syndrome functions 16 * MMX implementation of RAID-6 syndrome functions
17 */ 17 */
@@ -19,9 +19,9 @@
19#if defined(__i386__) && !defined(__arch_um__) 19#if defined(__i386__) && !defined(__arch_um__)
20 20
21#include <linux/raid/pq.h> 21#include <linux/raid/pq.h>
22#include "raid6x86.h" 22#include "x86.h"
23 23
24/* Shared with raid6sse1.c */ 24/* Shared with raid6/sse1.c */
25const struct raid6_mmx_constants { 25const struct raid6_mmx_constants {
26 u64 x1d; 26 u64 x1d;
27} raid6_mmx_constants = { 27} raid6_mmx_constants = {
diff --git a/lib/raid6/raid6test/Makefile b/lib/raid6/raid6test/Makefile
deleted file mode 100644
index 2874cbef529d..000000000000
--- a/lib/raid6/raid6test/Makefile
+++ /dev/null
@@ -1,75 +0,0 @@
1#
2# This is a simple Makefile to test some of the RAID-6 code
3# from userspace.
4#
5
6CC = gcc
7OPTFLAGS = -O2 # Adjust as desired
8CFLAGS = -I.. -I ../../../include -g $(OPTFLAGS)
9LD = ld
10AWK = awk
11AR = ar
12RANLIB = ranlib
13
14.c.o:
15 $(CC) $(CFLAGS) -c -o $@ $<
16
17%.c: ../%.c
18 cp -f $< $@
19
20%.uc: ../%.uc
21 cp -f $< $@
22
23all: raid6.a raid6test
24
25raid6.a: raid6int1.o raid6int2.o raid6int4.o raid6int8.o raid6int16.o \
26 raid6int32.o \
27 raid6mmx.o raid6sse1.o raid6sse2.o \
28 raid6altivec1.o raid6altivec2.o raid6altivec4.o raid6altivec8.o \
29 raid6recov.o raid6algos.o \
30 raid6tables.o
31 rm -f $@
32 $(AR) cq $@ $^
33 $(RANLIB) $@
34
35raid6test: test.c raid6.a
36 $(CC) $(CFLAGS) -o raid6test $^
37
38raid6altivec1.c: raid6altivec.uc ../unroll.awk
39 $(AWK) ../unroll.awk -vN=1 < raid6altivec.uc > $@
40
41raid6altivec2.c: raid6altivec.uc ../unroll.awk
42 $(AWK) ../unroll.awk -vN=2 < raid6altivec.uc > $@
43
44raid6altivec4.c: raid6altivec.uc ../unroll.awk
45 $(AWK) ../unroll.awk -vN=4 < raid6altivec.uc > $@
46
47raid6altivec8.c: raid6altivec.uc ../unroll.awk
48 $(AWK) ../unroll.awk -vN=8 < raid6altivec.uc > $@
49
50raid6int1.c: raid6int.uc ../unroll.awk
51 $(AWK) ../unroll.awk -vN=1 < raid6int.uc > $@
52
53raid6int2.c: raid6int.uc ../unroll.awk
54 $(AWK) ../unroll.awk -vN=2 < raid6int.uc > $@
55
56raid6int4.c: raid6int.uc ../unroll.awk
57 $(AWK) ../unroll.awk -vN=4 < raid6int.uc > $@
58
59raid6int8.c: raid6int.uc ../unroll.awk
60 $(AWK) ../unroll.awk -vN=8 < raid6int.uc > $@
61
62raid6int16.c: raid6int.uc ../unroll.awk
63 $(AWK) ../unroll.awk -vN=16 < raid6int.uc > $@
64
65raid6int32.c: raid6int.uc ../unroll.awk
66 $(AWK) ../unroll.awk -vN=32 < raid6int.uc > $@
67
68raid6tables.c: mktables
69 ./mktables > raid6tables.c
70
71clean:
72 rm -f *.o *.a mktables mktables.c raid6int.uc raid6*.c raid6test
73
74spotless: clean
75 rm -f *~
diff --git a/lib/raid6/raid6recov.c b/lib/raid6/recov.c
index 2609f00e0d61..8590d19cf522 100644
--- a/lib/raid6/raid6recov.c
+++ b/lib/raid6/recov.c
@@ -11,7 +11,7 @@
11 * ----------------------------------------------------------------------- */ 11 * ----------------------------------------------------------------------- */
12 12
13/* 13/*
14 * raid6recov.c 14 * raid6/recov.c
15 * 15 *
16 * RAID-6 data recovery in dual failure mode. In single failure mode, 16 * RAID-6 data recovery in dual failure mode. In single failure mode,
17 * use the RAID-5 algorithm (or, in the case of Q failure, just reconstruct 17 * use the RAID-5 algorithm (or, in the case of Q failure, just reconstruct
diff --git a/lib/raid6/raid6sse1.c b/lib/raid6/sse1.c
index b274dd5eab8f..10dd91948c07 100644
--- a/lib/raid6/raid6sse1.c
+++ b/lib/raid6/sse1.c
@@ -11,7 +11,7 @@
11 * ----------------------------------------------------------------------- */ 11 * ----------------------------------------------------------------------- */
12 12
13/* 13/*
14 * raid6sse1.c 14 * raid6/sse1.c
15 * 15 *
16 * SSE-1/MMXEXT implementation of RAID-6 syndrome functions 16 * SSE-1/MMXEXT implementation of RAID-6 syndrome functions
17 * 17 *
@@ -24,9 +24,9 @@
24#if defined(__i386__) && !defined(__arch_um__) 24#if defined(__i386__) && !defined(__arch_um__)
25 25
26#include <linux/raid/pq.h> 26#include <linux/raid/pq.h>
27#include "raid6x86.h" 27#include "x86.h"
28 28
29/* Defined in raid6mmx.c */ 29/* Defined in raid6/mmx.c */
30extern const struct raid6_mmx_constants { 30extern const struct raid6_mmx_constants {
31 u64 x1d; 31 u64 x1d;
32} raid6_mmx_constants; 32} raid6_mmx_constants;
diff --git a/lib/raid6/raid6sse2.c b/lib/raid6/sse2.c
index 6ed6c6c0389f..bc2d57daa589 100644
--- a/lib/raid6/raid6sse2.c
+++ b/lib/raid6/sse2.c
@@ -11,7 +11,7 @@
11 * ----------------------------------------------------------------------- */ 11 * ----------------------------------------------------------------------- */
12 12
13/* 13/*
14 * raid6sse2.c 14 * raid6/sse2.c
15 * 15 *
16 * SSE-2 implementation of RAID-6 syndrome functions 16 * SSE-2 implementation of RAID-6 syndrome functions
17 * 17 *
@@ -20,7 +20,7 @@
20#if (defined(__i386__) || defined(__x86_64__)) && !defined(__arch_um__) 20#if (defined(__i386__) || defined(__x86_64__)) && !defined(__arch_um__)
21 21
22#include <linux/raid/pq.h> 22#include <linux/raid/pq.h>
23#include "raid6x86.h" 23#include "x86.h"
24 24
25static const struct raid6_sse_constants { 25static const struct raid6_sse_constants {
26 u64 x1d[2]; 26 u64 x1d[2];
diff --git a/lib/raid6/test/Makefile b/lib/raid6/test/Makefile
new file mode 100644
index 000000000000..aa651697b6dc
--- /dev/null
+++ b/lib/raid6/test/Makefile
@@ -0,0 +1,72 @@
1#
2# This is a simple Makefile to test some of the RAID-6 code
3# from userspace.
4#
5
6CC = gcc
7OPTFLAGS = -O2 # Adjust as desired
8CFLAGS = -I.. -I ../../../include -g $(OPTFLAGS)
9LD = ld
10AWK = awk -f
11AR = ar
12RANLIB = ranlib
13
14.c.o:
15 $(CC) $(CFLAGS) -c -o $@ $<
16
17%.c: ../%.c
18 cp -f $< $@
19
20%.uc: ../%.uc
21 cp -f $< $@
22
23all: raid6.a raid6test
24
25raid6.a: int1.o int2.o int4.o int8.o int16.o int32.o mmx.o sse1.o sse2.o \
26 altivec1.o altivec2.o altivec4.o altivec8.o recov.o algos.o \
27 tables.o
28 rm -f $@
29 $(AR) cq $@ $^
30 $(RANLIB) $@
31
32raid6test: test.c raid6.a
33 $(CC) $(CFLAGS) -o raid6test $^
34
35altivec1.c: altivec.uc ../unroll.awk
36 $(AWK) ../unroll.awk -vN=1 < altivec.uc > $@
37
38altivec2.c: altivec.uc ../unroll.awk
39 $(AWK) ../unroll.awk -vN=2 < altivec.uc > $@
40
41altivec4.c: altivec.uc ../unroll.awk
42 $(AWK) ../unroll.awk -vN=4 < altivec.uc > $@
43
44altivec8.c: altivec.uc ../unroll.awk
45 $(AWK) ../unroll.awk -vN=8 < altivec.uc > $@
46
47int1.c: int.uc ../unroll.awk
48 $(AWK) ../unroll.awk -vN=1 < int.uc > $@
49
50int2.c: int.uc ../unroll.awk
51 $(AWK) ../unroll.awk -vN=2 < int.uc > $@
52
53int4.c: int.uc ../unroll.awk
54 $(AWK) ../unroll.awk -vN=4 < int.uc > $@
55
56int8.c: int.uc ../unroll.awk
57 $(AWK) ../unroll.awk -vN=8 < int.uc > $@
58
59int16.c: int.uc ../unroll.awk
60 $(AWK) ../unroll.awk -vN=16 < int.uc > $@
61
62int32.c: int.uc ../unroll.awk
63 $(AWK) ../unroll.awk -vN=32 < int.uc > $@
64
65tables.c: mktables
66 ./mktables > tables.c
67
68clean:
69 rm -f *.o *.a mktables mktables.c *.uc int*.c altivec*.c tables.c raid6test
70
71spotless: clean
72 rm -f *~
diff --git a/lib/raid6/raid6test/test.c b/lib/raid6/test/test.c
index 7a930318b17d..7a930318b17d 100644
--- a/lib/raid6/raid6test/test.c
+++ b/lib/raid6/test/test.c
diff --git a/lib/raid6/raid6x86.h b/lib/raid6/x86.h
index 4c22c1568558..cb2a8c91c886 100644
--- a/lib/raid6/raid6x86.h
+++ b/lib/raid6/x86.h
@@ -11,7 +11,7 @@
11 * ----------------------------------------------------------------------- */ 11 * ----------------------------------------------------------------------- */
12 12
13/* 13/*
14 * raid6x86.h 14 * raid6/x86.h
15 * 15 *
16 * Definitions common to x86 and x86-64 RAID-6 code only 16 * Definitions common to x86 and x86-64 RAID-6 code only
17 */ 17 */
diff --git a/mm/backing-dev.c b/mm/backing-dev.c
index 08d357522e78..eaa4a5bbe063 100644
--- a/mm/backing-dev.c
+++ b/mm/backing-dev.c
@@ -81,7 +81,8 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
81 nr_more_io++; 81 nr_more_io++;
82 spin_unlock(&inode_lock); 82 spin_unlock(&inode_lock);
83 83
84 get_dirty_limits(&background_thresh, &dirty_thresh, &bdi_thresh, bdi); 84 global_dirty_limits(&background_thresh, &dirty_thresh);
85 bdi_thresh = bdi_dirty_limit(bdi, dirty_thresh);
85 86
86#define K(x) ((x) << (PAGE_SHIFT - 10)) 87#define K(x) ((x) << (PAGE_SHIFT - 10))
87 seq_printf(m, 88 seq_printf(m,
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index b61d2db9f34e..cc5be788a39f 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -18,6 +18,9 @@
18#include <linux/bootmem.h> 18#include <linux/bootmem.h>
19#include <linux/sysfs.h> 19#include <linux/sysfs.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/rmap.h>
22#include <linux/swap.h>
23#include <linux/swapops.h>
21 24
22#include <asm/page.h> 25#include <asm/page.h>
23#include <asm/pgtable.h> 26#include <asm/pgtable.h>
@@ -220,6 +223,12 @@ static pgoff_t vma_hugecache_offset(struct hstate *h,
220 (vma->vm_pgoff >> huge_page_order(h)); 223 (vma->vm_pgoff >> huge_page_order(h));
221} 224}
222 225
226pgoff_t linear_hugepage_index(struct vm_area_struct *vma,
227 unsigned long address)
228{
229 return vma_hugecache_offset(hstate_vma(vma), vma, address);
230}
231
223/* 232/*
224 * Return the size of the pages allocated when backing a VMA. In the majority 233 * Return the size of the pages allocated when backing a VMA. In the majority
225 * cases this will be same size as used by the page table entries. 234 * cases this will be same size as used by the page table entries.
@@ -552,6 +561,7 @@ static void free_huge_page(struct page *page)
552 set_page_private(page, 0); 561 set_page_private(page, 0);
553 page->mapping = NULL; 562 page->mapping = NULL;
554 BUG_ON(page_count(page)); 563 BUG_ON(page_count(page));
564 BUG_ON(page_mapcount(page));
555 INIT_LIST_HEAD(&page->lru); 565 INIT_LIST_HEAD(&page->lru);
556 566
557 spin_lock(&hugetlb_lock); 567 spin_lock(&hugetlb_lock);
@@ -605,6 +615,8 @@ int PageHuge(struct page *page)
605 return dtor == free_huge_page; 615 return dtor == free_huge_page;
606} 616}
607 617
618EXPORT_SYMBOL_GPL(PageHuge);
619
608static struct page *alloc_fresh_huge_page_node(struct hstate *h, int nid) 620static struct page *alloc_fresh_huge_page_node(struct hstate *h, int nid)
609{ 621{
610 struct page *page; 622 struct page *page;
@@ -2129,6 +2141,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
2129 entry = huge_ptep_get(src_pte); 2141 entry = huge_ptep_get(src_pte);
2130 ptepage = pte_page(entry); 2142 ptepage = pte_page(entry);
2131 get_page(ptepage); 2143 get_page(ptepage);
2144 page_dup_rmap(ptepage);
2132 set_huge_pte_at(dst, addr, dst_pte, entry); 2145 set_huge_pte_at(dst, addr, dst_pte, entry);
2133 } 2146 }
2134 spin_unlock(&src->page_table_lock); 2147 spin_unlock(&src->page_table_lock);
@@ -2140,6 +2153,19 @@ nomem:
2140 return -ENOMEM; 2153 return -ENOMEM;
2141} 2154}
2142 2155
2156static int is_hugetlb_entry_hwpoisoned(pte_t pte)
2157{
2158 swp_entry_t swp;
2159
2160 if (huge_pte_none(pte) || pte_present(pte))
2161 return 0;
2162 swp = pte_to_swp_entry(pte);
2163 if (non_swap_entry(swp) && is_hwpoison_entry(swp)) {
2164 return 1;
2165 } else
2166 return 0;
2167}
2168
2143void __unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start, 2169void __unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
2144 unsigned long end, struct page *ref_page) 2170 unsigned long end, struct page *ref_page)
2145{ 2171{
@@ -2198,6 +2224,12 @@ void __unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
2198 if (huge_pte_none(pte)) 2224 if (huge_pte_none(pte))
2199 continue; 2225 continue;
2200 2226
2227 /*
2228 * HWPoisoned hugepage is already unmapped and dropped reference
2229 */
2230 if (unlikely(is_hugetlb_entry_hwpoisoned(pte)))
2231 continue;
2232
2201 page = pte_page(pte); 2233 page = pte_page(pte);
2202 if (pte_dirty(pte)) 2234 if (pte_dirty(pte))
2203 set_page_dirty(page); 2235 set_page_dirty(page);
@@ -2207,6 +2239,7 @@ void __unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
2207 flush_tlb_range(vma, start, end); 2239 flush_tlb_range(vma, start, end);
2208 mmu_notifier_invalidate_range_end(mm, start, end); 2240 mmu_notifier_invalidate_range_end(mm, start, end);
2209 list_for_each_entry_safe(page, tmp, &page_list, lru) { 2241 list_for_each_entry_safe(page, tmp, &page_list, lru) {
2242 page_remove_rmap(page);
2210 list_del(&page->lru); 2243 list_del(&page->lru);
2211 put_page(page); 2244 put_page(page);
2212 } 2245 }
@@ -2272,6 +2305,9 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
2272 return 1; 2305 return 1;
2273} 2306}
2274 2307
2308/*
2309 * Hugetlb_cow() should be called with page lock of the original hugepage held.
2310 */
2275static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, 2311static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
2276 unsigned long address, pte_t *ptep, pte_t pte, 2312 unsigned long address, pte_t *ptep, pte_t pte,
2277 struct page *pagecache_page) 2313 struct page *pagecache_page)
@@ -2286,8 +2322,13 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
2286retry_avoidcopy: 2322retry_avoidcopy:
2287 /* If no-one else is actually using this page, avoid the copy 2323 /* If no-one else is actually using this page, avoid the copy
2288 * and just make the page writable */ 2324 * and just make the page writable */
2289 avoidcopy = (page_count(old_page) == 1); 2325 avoidcopy = (page_mapcount(old_page) == 1);
2290 if (avoidcopy) { 2326 if (avoidcopy) {
2327 if (!trylock_page(old_page)) {
2328 if (PageAnon(old_page))
2329 page_move_anon_rmap(old_page, vma, address);
2330 } else
2331 unlock_page(old_page);
2291 set_huge_ptep_writable(vma, address, ptep); 2332 set_huge_ptep_writable(vma, address, ptep);
2292 return 0; 2333 return 0;
2293 } 2334 }
@@ -2338,6 +2379,13 @@ retry_avoidcopy:
2338 return -PTR_ERR(new_page); 2379 return -PTR_ERR(new_page);
2339 } 2380 }
2340 2381
2382 /*
2383 * When the original hugepage is shared one, it does not have
2384 * anon_vma prepared.
2385 */
2386 if (unlikely(anon_vma_prepare(vma)))
2387 return VM_FAULT_OOM;
2388
2341 copy_huge_page(new_page, old_page, address, vma); 2389 copy_huge_page(new_page, old_page, address, vma);
2342 __SetPageUptodate(new_page); 2390 __SetPageUptodate(new_page);
2343 2391
@@ -2355,6 +2403,8 @@ retry_avoidcopy:
2355 huge_ptep_clear_flush(vma, address, ptep); 2403 huge_ptep_clear_flush(vma, address, ptep);
2356 set_huge_pte_at(mm, address, ptep, 2404 set_huge_pte_at(mm, address, ptep,
2357 make_huge_pte(vma, new_page, 1)); 2405 make_huge_pte(vma, new_page, 1));
2406 page_remove_rmap(old_page);
2407 hugepage_add_anon_rmap(new_page, vma, address);
2358 /* Make the old page be freed below */ 2408 /* Make the old page be freed below */
2359 new_page = old_page; 2409 new_page = old_page;
2360 mmu_notifier_invalidate_range_end(mm, 2410 mmu_notifier_invalidate_range_end(mm,
@@ -2458,10 +2508,29 @@ retry:
2458 spin_lock(&inode->i_lock); 2508 spin_lock(&inode->i_lock);
2459 inode->i_blocks += blocks_per_huge_page(h); 2509 inode->i_blocks += blocks_per_huge_page(h);
2460 spin_unlock(&inode->i_lock); 2510 spin_unlock(&inode->i_lock);
2511 page_dup_rmap(page);
2461 } else { 2512 } else {
2462 lock_page(page); 2513 lock_page(page);
2463 page->mapping = HUGETLB_POISON; 2514 if (unlikely(anon_vma_prepare(vma))) {
2515 ret = VM_FAULT_OOM;
2516 goto backout_unlocked;
2517 }
2518 hugepage_add_new_anon_rmap(page, vma, address);
2464 } 2519 }
2520 } else {
2521 page_dup_rmap(page);
2522 }
2523
2524 /*
2525 * Since memory error handler replaces pte into hwpoison swap entry
2526 * at the time of error handling, a process which reserved but not have
2527 * the mapping to the error hugepage does not have hwpoison swap entry.
2528 * So we need to block accesses from such a process by checking
2529 * PG_hwpoison bit here.
2530 */
2531 if (unlikely(PageHWPoison(page))) {
2532 ret = VM_FAULT_HWPOISON;
2533 goto backout_unlocked;
2465 } 2534 }
2466 2535
2467 /* 2536 /*
@@ -2513,10 +2582,18 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
2513 pte_t *ptep; 2582 pte_t *ptep;
2514 pte_t entry; 2583 pte_t entry;
2515 int ret; 2584 int ret;
2585 struct page *page = NULL;
2516 struct page *pagecache_page = NULL; 2586 struct page *pagecache_page = NULL;
2517 static DEFINE_MUTEX(hugetlb_instantiation_mutex); 2587 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
2518 struct hstate *h = hstate_vma(vma); 2588 struct hstate *h = hstate_vma(vma);
2519 2589
2590 ptep = huge_pte_offset(mm, address);
2591 if (ptep) {
2592 entry = huge_ptep_get(ptep);
2593 if (unlikely(is_hugetlb_entry_hwpoisoned(entry)))
2594 return VM_FAULT_HWPOISON;
2595 }
2596
2520 ptep = huge_pte_alloc(mm, address, huge_page_size(h)); 2597 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
2521 if (!ptep) 2598 if (!ptep)
2522 return VM_FAULT_OOM; 2599 return VM_FAULT_OOM;
@@ -2554,6 +2631,11 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
2554 vma, address); 2631 vma, address);
2555 } 2632 }
2556 2633
2634 if (!pagecache_page) {
2635 page = pte_page(entry);
2636 lock_page(page);
2637 }
2638
2557 spin_lock(&mm->page_table_lock); 2639 spin_lock(&mm->page_table_lock);
2558 /* Check for a racing update before calling hugetlb_cow */ 2640 /* Check for a racing update before calling hugetlb_cow */
2559 if (unlikely(!pte_same(entry, huge_ptep_get(ptep)))) 2641 if (unlikely(!pte_same(entry, huge_ptep_get(ptep))))
@@ -2579,6 +2661,8 @@ out_page_table_lock:
2579 if (pagecache_page) { 2661 if (pagecache_page) {
2580 unlock_page(pagecache_page); 2662 unlock_page(pagecache_page);
2581 put_page(pagecache_page); 2663 put_page(pagecache_page);
2664 } else {
2665 unlock_page(page);
2582 } 2666 }
2583 2667
2584out_mutex: 2668out_mutex:
@@ -2791,3 +2875,19 @@ void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed)
2791 hugetlb_put_quota(inode->i_mapping, (chg - freed)); 2875 hugetlb_put_quota(inode->i_mapping, (chg - freed));
2792 hugetlb_acct_memory(h, -(chg - freed)); 2876 hugetlb_acct_memory(h, -(chg - freed));
2793} 2877}
2878
2879/*
2880 * This function is called from memory failure code.
2881 * Assume the caller holds page lock of the head page.
2882 */
2883void __isolate_hwpoisoned_huge_page(struct page *hpage)
2884{
2885 struct hstate *h = page_hstate(hpage);
2886 int nid = page_to_nid(hpage);
2887
2888 spin_lock(&hugetlb_lock);
2889 list_del(&hpage->lru);
2890 h->free_huge_pages--;
2891 h->free_huge_pages_node[nid]--;
2892 spin_unlock(&hugetlb_lock);
2893}
diff --git a/mm/hwpoison-inject.c b/mm/hwpoison-inject.c
index 10ea71905c1f..0948f1072d6b 100644
--- a/mm/hwpoison-inject.c
+++ b/mm/hwpoison-inject.c
@@ -5,6 +5,7 @@
5#include <linux/mm.h> 5#include <linux/mm.h>
6#include <linux/swap.h> 6#include <linux/swap.h>
7#include <linux/pagemap.h> 7#include <linux/pagemap.h>
8#include <linux/hugetlb.h>
8#include "internal.h" 9#include "internal.h"
9 10
10static struct dentry *hwpoison_dir; 11static struct dentry *hwpoison_dir;
@@ -13,6 +14,7 @@ static int hwpoison_inject(void *data, u64 val)
13{ 14{
14 unsigned long pfn = val; 15 unsigned long pfn = val;
15 struct page *p; 16 struct page *p;
17 struct page *hpage;
16 int err; 18 int err;
17 19
18 if (!capable(CAP_SYS_ADMIN)) 20 if (!capable(CAP_SYS_ADMIN))
@@ -24,18 +26,19 @@ static int hwpoison_inject(void *data, u64 val)
24 return -ENXIO; 26 return -ENXIO;
25 27
26 p = pfn_to_page(pfn); 28 p = pfn_to_page(pfn);
29 hpage = compound_head(p);
27 /* 30 /*
28 * This implies unable to support free buddy pages. 31 * This implies unable to support free buddy pages.
29 */ 32 */
30 if (!get_page_unless_zero(p)) 33 if (!get_page_unless_zero(hpage))
31 return 0; 34 return 0;
32 35
33 if (!PageLRU(p)) 36 if (!PageLRU(p) && !PageHuge(p))
34 shake_page(p, 0); 37 shake_page(p, 0);
35 /* 38 /*
36 * This implies unable to support non-LRU pages. 39 * This implies unable to support non-LRU pages.
37 */ 40 */
38 if (!PageLRU(p)) 41 if (!PageLRU(p) && !PageHuge(p))
39 return 0; 42 return 0;
40 43
41 /* 44 /*
@@ -44,9 +47,9 @@ static int hwpoison_inject(void *data, u64 val)
44 * We temporarily take page lock for try_get_mem_cgroup_from_page(). 47 * We temporarily take page lock for try_get_mem_cgroup_from_page().
45 * __memory_failure() will redo the check reliably inside page lock. 48 * __memory_failure() will redo the check reliably inside page lock.
46 */ 49 */
47 lock_page(p); 50 lock_page(hpage);
48 err = hwpoison_filter(p); 51 err = hwpoison_filter(hpage);
49 unlock_page(p); 52 unlock_page(hpage);
50 if (err) 53 if (err)
51 return 0; 54 return 0;
52 55
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 0576e9e64586..3eed583895a6 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -47,6 +47,7 @@
47#include <linux/mm_inline.h> 47#include <linux/mm_inline.h>
48#include <linux/page_cgroup.h> 48#include <linux/page_cgroup.h>
49#include <linux/cpu.h> 49#include <linux/cpu.h>
50#include <linux/oom.h>
50#include "internal.h" 51#include "internal.h"
51 52
52#include <asm/uaccess.h> 53#include <asm/uaccess.h>
@@ -268,6 +269,7 @@ enum move_type {
268 269
269/* "mc" and its members are protected by cgroup_mutex */ 270/* "mc" and its members are protected by cgroup_mutex */
270static struct move_charge_struct { 271static struct move_charge_struct {
272 spinlock_t lock; /* for from, to, moving_task */
271 struct mem_cgroup *from; 273 struct mem_cgroup *from;
272 struct mem_cgroup *to; 274 struct mem_cgroup *to;
273 unsigned long precharge; 275 unsigned long precharge;
@@ -276,6 +278,7 @@ static struct move_charge_struct {
276 struct task_struct *moving_task; /* a task moving charges */ 278 struct task_struct *moving_task; /* a task moving charges */
277 wait_queue_head_t waitq; /* a waitq for other context */ 279 wait_queue_head_t waitq; /* a waitq for other context */
278} mc = { 280} mc = {
281 .lock = __SPIN_LOCK_UNLOCKED(mc.lock),
279 .waitq = __WAIT_QUEUE_HEAD_INITIALIZER(mc.waitq), 282 .waitq = __WAIT_QUEUE_HEAD_INITIALIZER(mc.waitq),
280}; 283};
281 284
@@ -836,12 +839,13 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem)
836{ 839{
837 int ret; 840 int ret;
838 struct mem_cgroup *curr = NULL; 841 struct mem_cgroup *curr = NULL;
842 struct task_struct *p;
839 843
840 task_lock(task); 844 p = find_lock_task_mm(task);
841 rcu_read_lock(); 845 if (!p)
842 curr = try_get_mem_cgroup_from_mm(task->mm); 846 return 0;
843 rcu_read_unlock(); 847 curr = try_get_mem_cgroup_from_mm(p->mm);
844 task_unlock(task); 848 task_unlock(p);
845 if (!curr) 849 if (!curr)
846 return 0; 850 return 0;
847 /* 851 /*
@@ -915,7 +919,7 @@ unsigned long mem_cgroup_zone_nr_pages(struct mem_cgroup *memcg,
915 struct zone *zone, 919 struct zone *zone,
916 enum lru_list lru) 920 enum lru_list lru)
917{ 921{
918 int nid = zone->zone_pgdat->node_id; 922 int nid = zone_to_nid(zone);
919 int zid = zone_idx(zone); 923 int zid = zone_idx(zone);
920 struct mem_cgroup_per_zone *mz = mem_cgroup_zoneinfo(memcg, nid, zid); 924 struct mem_cgroup_per_zone *mz = mem_cgroup_zoneinfo(memcg, nid, zid);
921 925
@@ -925,7 +929,7 @@ unsigned long mem_cgroup_zone_nr_pages(struct mem_cgroup *memcg,
925struct zone_reclaim_stat *mem_cgroup_get_reclaim_stat(struct mem_cgroup *memcg, 929struct zone_reclaim_stat *mem_cgroup_get_reclaim_stat(struct mem_cgroup *memcg,
926 struct zone *zone) 930 struct zone *zone)
927{ 931{
928 int nid = zone->zone_pgdat->node_id; 932 int nid = zone_to_nid(zone);
929 int zid = zone_idx(zone); 933 int zid = zone_idx(zone);
930 struct mem_cgroup_per_zone *mz = mem_cgroup_zoneinfo(memcg, nid, zid); 934 struct mem_cgroup_per_zone *mz = mem_cgroup_zoneinfo(memcg, nid, zid);
931 935
@@ -970,7 +974,7 @@ unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
970 LIST_HEAD(pc_list); 974 LIST_HEAD(pc_list);
971 struct list_head *src; 975 struct list_head *src;
972 struct page_cgroup *pc, *tmp; 976 struct page_cgroup *pc, *tmp;
973 int nid = z->zone_pgdat->node_id; 977 int nid = zone_to_nid(z);
974 int zid = zone_idx(z); 978 int zid = zone_idx(z);
975 struct mem_cgroup_per_zone *mz; 979 struct mem_cgroup_per_zone *mz;
976 int lru = LRU_FILE * file + active; 980 int lru = LRU_FILE * file + active;
@@ -1047,6 +1051,47 @@ static unsigned int get_swappiness(struct mem_cgroup *memcg)
1047 return swappiness; 1051 return swappiness;
1048} 1052}
1049 1053
1054/* A routine for testing mem is not under move_account */
1055
1056static bool mem_cgroup_under_move(struct mem_cgroup *mem)
1057{
1058 struct mem_cgroup *from;
1059 struct mem_cgroup *to;
1060 bool ret = false;
1061 /*
1062 * Unlike task_move routines, we access mc.to, mc.from not under
1063 * mutual exclusion by cgroup_mutex. Here, we take spinlock instead.
1064 */
1065 spin_lock(&mc.lock);
1066 from = mc.from;
1067 to = mc.to;
1068 if (!from)
1069 goto unlock;
1070 if (from == mem || to == mem
1071 || (mem->use_hierarchy && css_is_ancestor(&from->css, &mem->css))
1072 || (mem->use_hierarchy && css_is_ancestor(&to->css, &mem->css)))
1073 ret = true;
1074unlock:
1075 spin_unlock(&mc.lock);
1076 return ret;
1077}
1078
1079static bool mem_cgroup_wait_acct_move(struct mem_cgroup *mem)
1080{
1081 if (mc.moving_task && current != mc.moving_task) {
1082 if (mem_cgroup_under_move(mem)) {
1083 DEFINE_WAIT(wait);
1084 prepare_to_wait(&mc.waitq, &wait, TASK_INTERRUPTIBLE);
1085 /* moving charge context might have finished. */
1086 if (mc.moving_task)
1087 schedule();
1088 finish_wait(&mc.waitq, &wait);
1089 return true;
1090 }
1091 }
1092 return false;
1093}
1094
1050static int mem_cgroup_count_children_cb(struct mem_cgroup *mem, void *data) 1095static int mem_cgroup_count_children_cb(struct mem_cgroup *mem, void *data)
1051{ 1096{
1052 int *val = data; 1097 int *val = data;
@@ -1255,8 +1300,7 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem,
1255 /* we use swappiness of local cgroup */ 1300 /* we use swappiness of local cgroup */
1256 if (check_soft) 1301 if (check_soft)
1257 ret = mem_cgroup_shrink_node_zone(victim, gfp_mask, 1302 ret = mem_cgroup_shrink_node_zone(victim, gfp_mask,
1258 noswap, get_swappiness(victim), zone, 1303 noswap, get_swappiness(victim), zone);
1259 zone->zone_pgdat->node_id);
1260 else 1304 else
1261 ret = try_to_free_mem_cgroup_pages(victim, gfp_mask, 1305 ret = try_to_free_mem_cgroup_pages(victim, gfp_mask,
1262 noswap, get_swappiness(victim)); 1306 noswap, get_swappiness(victim));
@@ -1363,7 +1407,7 @@ static void memcg_wakeup_oom(struct mem_cgroup *mem)
1363 1407
1364static void memcg_oom_recover(struct mem_cgroup *mem) 1408static void memcg_oom_recover(struct mem_cgroup *mem)
1365{ 1409{
1366 if (atomic_read(&mem->oom_lock)) 1410 if (mem && atomic_read(&mem->oom_lock))
1367 memcg_wakeup_oom(mem); 1411 memcg_wakeup_oom(mem);
1368} 1412}
1369 1413
@@ -1575,16 +1619,83 @@ static int __cpuinit memcg_stock_cpu_callback(struct notifier_block *nb,
1575 return NOTIFY_OK; 1619 return NOTIFY_OK;
1576} 1620}
1577 1621
1622
1623/* See __mem_cgroup_try_charge() for details */
1624enum {
1625 CHARGE_OK, /* success */
1626 CHARGE_RETRY, /* need to retry but retry is not bad */
1627 CHARGE_NOMEM, /* we can't do more. return -ENOMEM */
1628 CHARGE_WOULDBLOCK, /* GFP_WAIT wasn't set and no enough res. */
1629 CHARGE_OOM_DIE, /* the current is killed because of OOM */
1630};
1631
1632static int __mem_cgroup_do_charge(struct mem_cgroup *mem, gfp_t gfp_mask,
1633 int csize, bool oom_check)
1634{
1635 struct mem_cgroup *mem_over_limit;
1636 struct res_counter *fail_res;
1637 unsigned long flags = 0;
1638 int ret;
1639
1640 ret = res_counter_charge(&mem->res, csize, &fail_res);
1641
1642 if (likely(!ret)) {
1643 if (!do_swap_account)
1644 return CHARGE_OK;
1645 ret = res_counter_charge(&mem->memsw, csize, &fail_res);
1646 if (likely(!ret))
1647 return CHARGE_OK;
1648
1649 mem_over_limit = mem_cgroup_from_res_counter(fail_res, memsw);
1650 flags |= MEM_CGROUP_RECLAIM_NOSWAP;
1651 } else
1652 mem_over_limit = mem_cgroup_from_res_counter(fail_res, res);
1653
1654 if (csize > PAGE_SIZE) /* change csize and retry */
1655 return CHARGE_RETRY;
1656
1657 if (!(gfp_mask & __GFP_WAIT))
1658 return CHARGE_WOULDBLOCK;
1659
1660 ret = mem_cgroup_hierarchical_reclaim(mem_over_limit, NULL,
1661 gfp_mask, flags);
1662 /*
1663 * try_to_free_mem_cgroup_pages() might not give us a full
1664 * picture of reclaim. Some pages are reclaimed and might be
1665 * moved to swap cache or just unmapped from the cgroup.
1666 * Check the limit again to see if the reclaim reduced the
1667 * current usage of the cgroup before giving up
1668 */
1669 if (ret || mem_cgroup_check_under_limit(mem_over_limit))
1670 return CHARGE_RETRY;
1671
1672 /*
1673 * At task move, charge accounts can be doubly counted. So, it's
1674 * better to wait until the end of task_move if something is going on.
1675 */
1676 if (mem_cgroup_wait_acct_move(mem_over_limit))
1677 return CHARGE_RETRY;
1678
1679 /* If we don't need to call oom-killer at el, return immediately */
1680 if (!oom_check)
1681 return CHARGE_NOMEM;
1682 /* check OOM */
1683 if (!mem_cgroup_handle_oom(mem_over_limit, gfp_mask))
1684 return CHARGE_OOM_DIE;
1685
1686 return CHARGE_RETRY;
1687}
1688
1578/* 1689/*
1579 * Unlike exported interface, "oom" parameter is added. if oom==true, 1690 * Unlike exported interface, "oom" parameter is added. if oom==true,
1580 * oom-killer can be invoked. 1691 * oom-killer can be invoked.
1581 */ 1692 */
1582static int __mem_cgroup_try_charge(struct mm_struct *mm, 1693static int __mem_cgroup_try_charge(struct mm_struct *mm,
1583 gfp_t gfp_mask, struct mem_cgroup **memcg, bool oom) 1694 gfp_t gfp_mask, struct mem_cgroup **memcg, bool oom)
1584{ 1695{
1585 struct mem_cgroup *mem, *mem_over_limit; 1696 int nr_oom_retries = MEM_CGROUP_RECLAIM_RETRIES;
1586 int nr_retries = MEM_CGROUP_RECLAIM_RETRIES; 1697 struct mem_cgroup *mem = NULL;
1587 struct res_counter *fail_res; 1698 int ret;
1588 int csize = CHARGE_SIZE; 1699 int csize = CHARGE_SIZE;
1589 1700
1590 /* 1701 /*
@@ -1602,126 +1713,108 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
1602 * thread group leader migrates. It's possible that mm is not 1713 * thread group leader migrates. It's possible that mm is not
1603 * set, if so charge the init_mm (happens for pagecache usage). 1714 * set, if so charge the init_mm (happens for pagecache usage).
1604 */ 1715 */
1605 mem = *memcg; 1716 if (!*memcg && !mm)
1606 if (likely(!mem)) { 1717 goto bypass;
1607 mem = try_get_mem_cgroup_from_mm(mm); 1718again:
1608 *memcg = mem; 1719 if (*memcg) { /* css should be a valid one */
1609 } else { 1720 mem = *memcg;
1610 css_get(&mem->css); 1721 VM_BUG_ON(css_is_removed(&mem->css));
1611 } 1722 if (mem_cgroup_is_root(mem))
1612 if (unlikely(!mem)) 1723 goto done;
1613 return 0;
1614
1615 VM_BUG_ON(css_is_removed(&mem->css));
1616 if (mem_cgroup_is_root(mem))
1617 goto done;
1618
1619 while (1) {
1620 int ret = 0;
1621 unsigned long flags = 0;
1622
1623 if (consume_stock(mem)) 1724 if (consume_stock(mem))
1624 goto done; 1725 goto done;
1726 css_get(&mem->css);
1727 } else {
1728 struct task_struct *p;
1625 1729
1626 ret = res_counter_charge(&mem->res, csize, &fail_res); 1730 rcu_read_lock();
1627 if (likely(!ret)) { 1731 p = rcu_dereference(mm->owner);
1628 if (!do_swap_account) 1732 VM_BUG_ON(!p);
1629 break;
1630 ret = res_counter_charge(&mem->memsw, csize, &fail_res);
1631 if (likely(!ret))
1632 break;
1633 /* mem+swap counter fails */
1634 res_counter_uncharge(&mem->res, csize);
1635 flags |= MEM_CGROUP_RECLAIM_NOSWAP;
1636 mem_over_limit = mem_cgroup_from_res_counter(fail_res,
1637 memsw);
1638 } else
1639 /* mem counter fails */
1640 mem_over_limit = mem_cgroup_from_res_counter(fail_res,
1641 res);
1642
1643 /* reduce request size and retry */
1644 if (csize > PAGE_SIZE) {
1645 csize = PAGE_SIZE;
1646 continue;
1647 }
1648 if (!(gfp_mask & __GFP_WAIT))
1649 goto nomem;
1650
1651 ret = mem_cgroup_hierarchical_reclaim(mem_over_limit, NULL,
1652 gfp_mask, flags);
1653 if (ret)
1654 continue;
1655
1656 /* 1733 /*
1657 * try_to_free_mem_cgroup_pages() might not give us a full 1734 * because we don't have task_lock(), "p" can exit while
1658 * picture of reclaim. Some pages are reclaimed and might be 1735 * we're here. In that case, "mem" can point to root
1659 * moved to swap cache or just unmapped from the cgroup. 1736 * cgroup but never be NULL. (and task_struct itself is freed
1660 * Check the limit again to see if the reclaim reduced the 1737 * by RCU, cgroup itself is RCU safe.) Then, we have small
1661 * current usage of the cgroup before giving up 1738 * risk here to get wrong cgroup. But such kind of mis-account
1662 * 1739 * by race always happens because we don't have cgroup_mutex().
1740 * It's overkill and we allow that small race, here.
1663 */ 1741 */
1664 if (mem_cgroup_check_under_limit(mem_over_limit)) 1742 mem = mem_cgroup_from_task(p);
1665 continue; 1743 VM_BUG_ON(!mem);
1666 1744 if (mem_cgroup_is_root(mem)) {
1667 /* try to avoid oom while someone is moving charge */ 1745 rcu_read_unlock();
1668 if (mc.moving_task && current != mc.moving_task) { 1746 goto done;
1669 struct mem_cgroup *from, *to; 1747 }
1670 bool do_continue = false; 1748 if (consume_stock(mem)) {
1671 /* 1749 /*
1672 * There is a small race that "from" or "to" can be 1750 * It seems dagerous to access memcg without css_get().
1673 * freed by rmdir, so we use css_tryget(). 1751 * But considering how consume_stok works, it's not
1752 * necessary. If consume_stock success, some charges
1753 * from this memcg are cached on this cpu. So, we
1754 * don't need to call css_get()/css_tryget() before
1755 * calling consume_stock().
1674 */ 1756 */
1675 from = mc.from; 1757 rcu_read_unlock();
1676 to = mc.to; 1758 goto done;
1677 if (from && css_tryget(&from->css)) { 1759 }
1678 if (mem_over_limit->use_hierarchy) 1760 /* after here, we may be blocked. we need to get refcnt */
1679 do_continue = css_is_ancestor( 1761 if (!css_tryget(&mem->css)) {
1680 &from->css, 1762 rcu_read_unlock();
1681 &mem_over_limit->css); 1763 goto again;
1682 else 1764 }
1683 do_continue = (from == mem_over_limit); 1765 rcu_read_unlock();
1684 css_put(&from->css); 1766 }
1685 } 1767
1686 if (!do_continue && to && css_tryget(&to->css)) { 1768 do {
1687 if (mem_over_limit->use_hierarchy) 1769 bool oom_check;
1688 do_continue = css_is_ancestor( 1770
1689 &to->css, 1771 /* If killed, bypass charge */
1690 &mem_over_limit->css); 1772 if (fatal_signal_pending(current)) {
1691 else 1773 css_put(&mem->css);
1692 do_continue = (to == mem_over_limit); 1774 goto bypass;
1693 css_put(&to->css);
1694 }
1695 if (do_continue) {
1696 DEFINE_WAIT(wait);
1697 prepare_to_wait(&mc.waitq, &wait,
1698 TASK_INTERRUPTIBLE);
1699 /* moving charge context might have finished. */
1700 if (mc.moving_task)
1701 schedule();
1702 finish_wait(&mc.waitq, &wait);
1703 continue;
1704 }
1705 } 1775 }
1706 1776
1707 if (!nr_retries--) { 1777 oom_check = false;
1708 if (!oom) 1778 if (oom && !nr_oom_retries) {
1779 oom_check = true;
1780 nr_oom_retries = MEM_CGROUP_RECLAIM_RETRIES;
1781 }
1782
1783 ret = __mem_cgroup_do_charge(mem, gfp_mask, csize, oom_check);
1784
1785 switch (ret) {
1786 case CHARGE_OK:
1787 break;
1788 case CHARGE_RETRY: /* not in OOM situation but retry */
1789 csize = PAGE_SIZE;
1790 css_put(&mem->css);
1791 mem = NULL;
1792 goto again;
1793 case CHARGE_WOULDBLOCK: /* !__GFP_WAIT */
1794 css_put(&mem->css);
1795 goto nomem;
1796 case CHARGE_NOMEM: /* OOM routine works */
1797 if (!oom) {
1798 css_put(&mem->css);
1709 goto nomem; 1799 goto nomem;
1710 if (mem_cgroup_handle_oom(mem_over_limit, gfp_mask)) {
1711 nr_retries = MEM_CGROUP_RECLAIM_RETRIES;
1712 continue;
1713 } 1800 }
1714 /* When we reach here, current task is dying .*/ 1801 /* If oom, we never return -ENOMEM */
1802 nr_oom_retries--;
1803 break;
1804 case CHARGE_OOM_DIE: /* Killed by OOM Killer */
1715 css_put(&mem->css); 1805 css_put(&mem->css);
1716 goto bypass; 1806 goto bypass;
1717 } 1807 }
1718 } 1808 } while (ret != CHARGE_OK);
1809
1719 if (csize > PAGE_SIZE) 1810 if (csize > PAGE_SIZE)
1720 refill_stock(mem, csize - PAGE_SIZE); 1811 refill_stock(mem, csize - PAGE_SIZE);
1812 css_put(&mem->css);
1721done: 1813done:
1814 *memcg = mem;
1722 return 0; 1815 return 0;
1723nomem: 1816nomem:
1724 css_put(&mem->css); 1817 *memcg = NULL;
1725 return -ENOMEM; 1818 return -ENOMEM;
1726bypass: 1819bypass:
1727 *memcg = NULL; 1820 *memcg = NULL;
@@ -1740,11 +1833,7 @@ static void __mem_cgroup_cancel_charge(struct mem_cgroup *mem,
1740 res_counter_uncharge(&mem->res, PAGE_SIZE * count); 1833 res_counter_uncharge(&mem->res, PAGE_SIZE * count);
1741 if (do_swap_account) 1834 if (do_swap_account)
1742 res_counter_uncharge(&mem->memsw, PAGE_SIZE * count); 1835 res_counter_uncharge(&mem->memsw, PAGE_SIZE * count);
1743 VM_BUG_ON(test_bit(CSS_ROOT, &mem->css.flags));
1744 WARN_ON_ONCE(count > INT_MAX);
1745 __css_put(&mem->css, (int)count);
1746 } 1836 }
1747 /* we don't need css_put for root */
1748} 1837}
1749 1838
1750static void mem_cgroup_cancel_charge(struct mem_cgroup *mem) 1839static void mem_cgroup_cancel_charge(struct mem_cgroup *mem)
@@ -1972,10 +2061,9 @@ out:
1972 * < 0 if the cgroup is over its limit 2061 * < 0 if the cgroup is over its limit
1973 */ 2062 */
1974static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm, 2063static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
1975 gfp_t gfp_mask, enum charge_type ctype, 2064 gfp_t gfp_mask, enum charge_type ctype)
1976 struct mem_cgroup *memcg)
1977{ 2065{
1978 struct mem_cgroup *mem; 2066 struct mem_cgroup *mem = NULL;
1979 struct page_cgroup *pc; 2067 struct page_cgroup *pc;
1980 int ret; 2068 int ret;
1981 2069
@@ -1985,7 +2073,6 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
1985 return 0; 2073 return 0;
1986 prefetchw(pc); 2074 prefetchw(pc);
1987 2075
1988 mem = memcg;
1989 ret = __mem_cgroup_try_charge(mm, gfp_mask, &mem, true); 2076 ret = __mem_cgroup_try_charge(mm, gfp_mask, &mem, true);
1990 if (ret || !mem) 2077 if (ret || !mem)
1991 return ret; 2078 return ret;
@@ -2013,7 +2100,7 @@ int mem_cgroup_newpage_charge(struct page *page,
2013 if (unlikely(!mm)) 2100 if (unlikely(!mm))
2014 mm = &init_mm; 2101 mm = &init_mm;
2015 return mem_cgroup_charge_common(page, mm, gfp_mask, 2102 return mem_cgroup_charge_common(page, mm, gfp_mask,
2016 MEM_CGROUP_CHARGE_TYPE_MAPPED, NULL); 2103 MEM_CGROUP_CHARGE_TYPE_MAPPED);
2017} 2104}
2018 2105
2019static void 2106static void
@@ -2023,7 +2110,6 @@ __mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *ptr,
2023int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm, 2110int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
2024 gfp_t gfp_mask) 2111 gfp_t gfp_mask)
2025{ 2112{
2026 struct mem_cgroup *mem = NULL;
2027 int ret; 2113 int ret;
2028 2114
2029 if (mem_cgroup_disabled()) 2115 if (mem_cgroup_disabled())
@@ -2044,7 +2130,6 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
2044 if (!(gfp_mask & __GFP_WAIT)) { 2130 if (!(gfp_mask & __GFP_WAIT)) {
2045 struct page_cgroup *pc; 2131 struct page_cgroup *pc;
2046 2132
2047
2048 pc = lookup_page_cgroup(page); 2133 pc = lookup_page_cgroup(page);
2049 if (!pc) 2134 if (!pc)
2050 return 0; 2135 return 0;
@@ -2056,22 +2141,24 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
2056 unlock_page_cgroup(pc); 2141 unlock_page_cgroup(pc);
2057 } 2142 }
2058 2143
2059 if (unlikely(!mm && !mem)) 2144 if (unlikely(!mm))
2060 mm = &init_mm; 2145 mm = &init_mm;
2061 2146
2062 if (page_is_file_cache(page)) 2147 if (page_is_file_cache(page))
2063 return mem_cgroup_charge_common(page, mm, gfp_mask, 2148 return mem_cgroup_charge_common(page, mm, gfp_mask,
2064 MEM_CGROUP_CHARGE_TYPE_CACHE, NULL); 2149 MEM_CGROUP_CHARGE_TYPE_CACHE);
2065 2150
2066 /* shmem */ 2151 /* shmem */
2067 if (PageSwapCache(page)) { 2152 if (PageSwapCache(page)) {
2153 struct mem_cgroup *mem = NULL;
2154
2068 ret = mem_cgroup_try_charge_swapin(mm, page, gfp_mask, &mem); 2155 ret = mem_cgroup_try_charge_swapin(mm, page, gfp_mask, &mem);
2069 if (!ret) 2156 if (!ret)
2070 __mem_cgroup_commit_charge_swapin(page, mem, 2157 __mem_cgroup_commit_charge_swapin(page, mem,
2071 MEM_CGROUP_CHARGE_TYPE_SHMEM); 2158 MEM_CGROUP_CHARGE_TYPE_SHMEM);
2072 } else 2159 } else
2073 ret = mem_cgroup_charge_common(page, mm, gfp_mask, 2160 ret = mem_cgroup_charge_common(page, mm, gfp_mask,
2074 MEM_CGROUP_CHARGE_TYPE_SHMEM, mem); 2161 MEM_CGROUP_CHARGE_TYPE_SHMEM);
2075 2162
2076 return ret; 2163 return ret;
2077} 2164}
@@ -2107,7 +2194,6 @@ int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
2107 goto charge_cur_mm; 2194 goto charge_cur_mm;
2108 *ptr = mem; 2195 *ptr = mem;
2109 ret = __mem_cgroup_try_charge(NULL, mask, ptr, true); 2196 ret = __mem_cgroup_try_charge(NULL, mask, ptr, true);
2110 /* drop extra refcnt from tryget */
2111 css_put(&mem->css); 2197 css_put(&mem->css);
2112 return ret; 2198 return ret;
2113charge_cur_mm: 2199charge_cur_mm:
@@ -2238,7 +2324,6 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
2238{ 2324{
2239 struct page_cgroup *pc; 2325 struct page_cgroup *pc;
2240 struct mem_cgroup *mem = NULL; 2326 struct mem_cgroup *mem = NULL;
2241 struct mem_cgroup_per_zone *mz;
2242 2327
2243 if (mem_cgroup_disabled()) 2328 if (mem_cgroup_disabled())
2244 return NULL; 2329 return NULL;
@@ -2278,10 +2363,6 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
2278 break; 2363 break;
2279 } 2364 }
2280 2365
2281 if (!mem_cgroup_is_root(mem))
2282 __do_uncharge(mem, ctype);
2283 if (ctype == MEM_CGROUP_CHARGE_TYPE_SWAPOUT)
2284 mem_cgroup_swap_statistics(mem, true);
2285 mem_cgroup_charge_statistics(mem, pc, false); 2366 mem_cgroup_charge_statistics(mem, pc, false);
2286 2367
2287 ClearPageCgroupUsed(pc); 2368 ClearPageCgroupUsed(pc);
@@ -2292,13 +2373,18 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
2292 * special functions. 2373 * special functions.
2293 */ 2374 */
2294 2375
2295 mz = page_cgroup_zoneinfo(pc);
2296 unlock_page_cgroup(pc); 2376 unlock_page_cgroup(pc);
2297 2377 /*
2378 * even after unlock, we have mem->res.usage here and this memcg
2379 * will never be freed.
2380 */
2298 memcg_check_events(mem, page); 2381 memcg_check_events(mem, page);
2299 /* at swapout, this memcg will be accessed to record to swap */ 2382 if (do_swap_account && ctype == MEM_CGROUP_CHARGE_TYPE_SWAPOUT) {
2300 if (ctype != MEM_CGROUP_CHARGE_TYPE_SWAPOUT) 2383 mem_cgroup_swap_statistics(mem, true);
2301 css_put(&mem->css); 2384 mem_cgroup_get(mem);
2385 }
2386 if (!mem_cgroup_is_root(mem))
2387 __do_uncharge(mem, ctype);
2302 2388
2303 return mem; 2389 return mem;
2304 2390
@@ -2385,13 +2471,12 @@ mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent, bool swapout)
2385 2471
2386 memcg = __mem_cgroup_uncharge_common(page, ctype); 2472 memcg = __mem_cgroup_uncharge_common(page, ctype);
2387 2473
2388 /* record memcg information */ 2474 /*
2389 if (do_swap_account && swapout && memcg) { 2475 * record memcg information, if swapout && memcg != NULL,
2476 * mem_cgroup_get() was called in uncharge().
2477 */
2478 if (do_swap_account && swapout && memcg)
2390 swap_cgroup_record(ent, css_id(&memcg->css)); 2479 swap_cgroup_record(ent, css_id(&memcg->css));
2391 mem_cgroup_get(memcg);
2392 }
2393 if (swapout && memcg)
2394 css_put(&memcg->css);
2395} 2480}
2396#endif 2481#endif
2397 2482
@@ -2469,7 +2554,6 @@ static int mem_cgroup_move_swap_account(swp_entry_t entry,
2469 */ 2554 */
2470 if (!mem_cgroup_is_root(to)) 2555 if (!mem_cgroup_is_root(to))
2471 res_counter_uncharge(&to->res, PAGE_SIZE); 2556 res_counter_uncharge(&to->res, PAGE_SIZE);
2472 css_put(&to->css);
2473 } 2557 }
2474 return 0; 2558 return 0;
2475 } 2559 }
@@ -2604,11 +2688,8 @@ void mem_cgroup_end_migration(struct mem_cgroup *mem,
2604 ClearPageCgroupMigration(pc); 2688 ClearPageCgroupMigration(pc);
2605 unlock_page_cgroup(pc); 2689 unlock_page_cgroup(pc);
2606 2690
2607 if (unused != oldpage)
2608 pc = lookup_page_cgroup(unused);
2609 __mem_cgroup_uncharge_common(unused, MEM_CGROUP_CHARGE_TYPE_FORCE); 2691 __mem_cgroup_uncharge_common(unused, MEM_CGROUP_CHARGE_TYPE_FORCE);
2610 2692
2611 pc = lookup_page_cgroup(used);
2612 /* 2693 /*
2613 * If a page is a file cache, radix-tree replacement is very atomic 2694 * If a page is a file cache, radix-tree replacement is very atomic
2614 * and we can skip this check. When it was an Anon page, its mapcount 2695 * and we can skip this check. When it was an Anon page, its mapcount
@@ -2784,8 +2865,7 @@ static int mem_cgroup_resize_memsw_limit(struct mem_cgroup *memcg,
2784} 2865}
2785 2866
2786unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, 2867unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
2787 gfp_t gfp_mask, int nid, 2868 gfp_t gfp_mask)
2788 int zid)
2789{ 2869{
2790 unsigned long nr_reclaimed = 0; 2870 unsigned long nr_reclaimed = 0;
2791 struct mem_cgroup_per_zone *mz, *next_mz = NULL; 2871 struct mem_cgroup_per_zone *mz, *next_mz = NULL;
@@ -2797,7 +2877,7 @@ unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
2797 if (order > 0) 2877 if (order > 0)
2798 return 0; 2878 return 0;
2799 2879
2800 mctz = soft_limit_tree_node_zone(nid, zid); 2880 mctz = soft_limit_tree_node_zone(zone_to_nid(zone), zone_idx(zone));
2801 /* 2881 /*
2802 * This loop can run a while, specially if mem_cgroup's continuously 2882 * This loop can run a while, specially if mem_cgroup's continuously
2803 * keep exceeding their soft limit and putting the system under 2883 * keep exceeding their soft limit and putting the system under
@@ -3752,8 +3832,6 @@ static int mem_cgroup_oom_control_read(struct cgroup *cgrp,
3752 return 0; 3832 return 0;
3753} 3833}
3754 3834
3755/*
3756 */
3757static int mem_cgroup_oom_control_write(struct cgroup *cgrp, 3835static int mem_cgroup_oom_control_write(struct cgroup *cgrp,
3758 struct cftype *cft, u64 val) 3836 struct cftype *cft, u64 val)
3759{ 3837{
@@ -4173,9 +4251,6 @@ static int mem_cgroup_do_precharge(unsigned long count)
4173 goto one_by_one; 4251 goto one_by_one;
4174 } 4252 }
4175 mc.precharge += count; 4253 mc.precharge += count;
4176 VM_BUG_ON(test_bit(CSS_ROOT, &mem->css.flags));
4177 WARN_ON_ONCE(count > INT_MAX);
4178 __css_get(&mem->css, (int)count);
4179 return ret; 4254 return ret;
4180 } 4255 }
4181one_by_one: 4256one_by_one:
@@ -4393,11 +4468,13 @@ static int mem_cgroup_precharge_mc(struct mm_struct *mm)
4393 4468
4394static void mem_cgroup_clear_mc(void) 4469static void mem_cgroup_clear_mc(void)
4395{ 4470{
4471 struct mem_cgroup *from = mc.from;
4472 struct mem_cgroup *to = mc.to;
4473
4396 /* we must uncharge all the leftover precharges from mc.to */ 4474 /* we must uncharge all the leftover precharges from mc.to */
4397 if (mc.precharge) { 4475 if (mc.precharge) {
4398 __mem_cgroup_cancel_charge(mc.to, mc.precharge); 4476 __mem_cgroup_cancel_charge(mc.to, mc.precharge);
4399 mc.precharge = 0; 4477 mc.precharge = 0;
4400 memcg_oom_recover(mc.to);
4401 } 4478 }
4402 /* 4479 /*
4403 * we didn't uncharge from mc.from at mem_cgroup_move_account(), so 4480 * we didn't uncharge from mc.from at mem_cgroup_move_account(), so
@@ -4406,11 +4483,9 @@ static void mem_cgroup_clear_mc(void)
4406 if (mc.moved_charge) { 4483 if (mc.moved_charge) {
4407 __mem_cgroup_cancel_charge(mc.from, mc.moved_charge); 4484 __mem_cgroup_cancel_charge(mc.from, mc.moved_charge);
4408 mc.moved_charge = 0; 4485 mc.moved_charge = 0;
4409 memcg_oom_recover(mc.from);
4410 } 4486 }
4411 /* we must fixup refcnts and charges */ 4487 /* we must fixup refcnts and charges */
4412 if (mc.moved_swap) { 4488 if (mc.moved_swap) {
4413 WARN_ON_ONCE(mc.moved_swap > INT_MAX);
4414 /* uncharge swap account from the old cgroup */ 4489 /* uncharge swap account from the old cgroup */
4415 if (!mem_cgroup_is_root(mc.from)) 4490 if (!mem_cgroup_is_root(mc.from))
4416 res_counter_uncharge(&mc.from->memsw, 4491 res_counter_uncharge(&mc.from->memsw,
@@ -4424,16 +4499,18 @@ static void mem_cgroup_clear_mc(void)
4424 */ 4499 */
4425 res_counter_uncharge(&mc.to->res, 4500 res_counter_uncharge(&mc.to->res,
4426 PAGE_SIZE * mc.moved_swap); 4501 PAGE_SIZE * mc.moved_swap);
4427 VM_BUG_ON(test_bit(CSS_ROOT, &mc.to->css.flags));
4428 __css_put(&mc.to->css, mc.moved_swap);
4429 } 4502 }
4430 /* we've already done mem_cgroup_get(mc.to) */ 4503 /* we've already done mem_cgroup_get(mc.to) */
4431 4504
4432 mc.moved_swap = 0; 4505 mc.moved_swap = 0;
4433 } 4506 }
4507 spin_lock(&mc.lock);
4434 mc.from = NULL; 4508 mc.from = NULL;
4435 mc.to = NULL; 4509 mc.to = NULL;
4436 mc.moving_task = NULL; 4510 mc.moving_task = NULL;
4511 spin_unlock(&mc.lock);
4512 memcg_oom_recover(from);
4513 memcg_oom_recover(to);
4437 wake_up_all(&mc.waitq); 4514 wake_up_all(&mc.waitq);
4438} 4515}
4439 4516
@@ -4462,12 +4539,14 @@ static int mem_cgroup_can_attach(struct cgroup_subsys *ss,
4462 VM_BUG_ON(mc.moved_charge); 4539 VM_BUG_ON(mc.moved_charge);
4463 VM_BUG_ON(mc.moved_swap); 4540 VM_BUG_ON(mc.moved_swap);
4464 VM_BUG_ON(mc.moving_task); 4541 VM_BUG_ON(mc.moving_task);
4542 spin_lock(&mc.lock);
4465 mc.from = from; 4543 mc.from = from;
4466 mc.to = mem; 4544 mc.to = mem;
4467 mc.precharge = 0; 4545 mc.precharge = 0;
4468 mc.moved_charge = 0; 4546 mc.moved_charge = 0;
4469 mc.moved_swap = 0; 4547 mc.moved_swap = 0;
4470 mc.moving_task = current; 4548 mc.moving_task = current;
4549 spin_unlock(&mc.lock);
4471 4550
4472 ret = mem_cgroup_precharge_mc(mm); 4551 ret = mem_cgroup_precharge_mc(mm);
4473 if (ret) 4552 if (ret)
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 6b44e52cacaa..9c26eeca1342 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -46,6 +46,7 @@
46#include <linux/suspend.h> 46#include <linux/suspend.h>
47#include <linux/slab.h> 47#include <linux/slab.h>
48#include <linux/swapops.h> 48#include <linux/swapops.h>
49#include <linux/hugetlb.h>
49#include "internal.h" 50#include "internal.h"
50 51
51int sysctl_memory_failure_early_kill __read_mostly = 0; 52int sysctl_memory_failure_early_kill __read_mostly = 0;
@@ -690,17 +691,29 @@ static int me_swapcache_clean(struct page *p, unsigned long pfn)
690/* 691/*
691 * Huge pages. Needs work. 692 * Huge pages. Needs work.
692 * Issues: 693 * Issues:
693 * No rmap support so we cannot find the original mapper. In theory could walk 694 * - Error on hugepage is contained in hugepage unit (not in raw page unit.)
694 * all MMs and look for the mappings, but that would be non atomic and racy. 695 * To narrow down kill region to one page, we need to break up pmd.
695 * Need rmap for hugepages for this. Alternatively we could employ a heuristic, 696 * - To support soft-offlining for hugepage, we need to support hugepage
696 * like just walking the current process and hoping it has it mapped (that 697 * migration.
697 * should be usually true for the common "shared database cache" case)
698 * Should handle free huge pages and dequeue them too, but this needs to
699 * handle huge page accounting correctly.
700 */ 698 */
701static int me_huge_page(struct page *p, unsigned long pfn) 699static int me_huge_page(struct page *p, unsigned long pfn)
702{ 700{
703 return FAILED; 701 struct page *hpage = compound_head(p);
702 /*
703 * We can safely recover from error on free or reserved (i.e.
704 * not in-use) hugepage by dequeuing it from freelist.
705 * To check whether a hugepage is in-use or not, we can't use
706 * page->lru because it can be used in other hugepage operations,
707 * such as __unmap_hugepage_range() and gather_surplus_pages().
708 * So instead we use page_mapping() and PageAnon().
709 * We assume that this function is called with page lock held,
710 * so there is no race between isolation and mapping/unmapping.
711 */
712 if (!(page_mapping(hpage) || PageAnon(hpage))) {
713 __isolate_hwpoisoned_huge_page(hpage);
714 return RECOVERED;
715 }
716 return DELAYED;
704} 717}
705 718
706/* 719/*
@@ -838,6 +851,7 @@ static int hwpoison_user_mappings(struct page *p, unsigned long pfn,
838 int ret; 851 int ret;
839 int i; 852 int i;
840 int kill = 1; 853 int kill = 1;
854 struct page *hpage = compound_head(p);
841 855
842 if (PageReserved(p) || PageSlab(p)) 856 if (PageReserved(p) || PageSlab(p))
843 return SWAP_SUCCESS; 857 return SWAP_SUCCESS;
@@ -846,10 +860,10 @@ static int hwpoison_user_mappings(struct page *p, unsigned long pfn,
846 * This check implies we don't kill processes if their pages 860 * This check implies we don't kill processes if their pages
847 * are in the swap cache early. Those are always late kills. 861 * are in the swap cache early. Those are always late kills.
848 */ 862 */
849 if (!page_mapped(p)) 863 if (!page_mapped(hpage))
850 return SWAP_SUCCESS; 864 return SWAP_SUCCESS;
851 865
852 if (PageCompound(p) || PageKsm(p)) 866 if (PageKsm(p))
853 return SWAP_FAIL; 867 return SWAP_FAIL;
854 868
855 if (PageSwapCache(p)) { 869 if (PageSwapCache(p)) {
@@ -864,10 +878,11 @@ static int hwpoison_user_mappings(struct page *p, unsigned long pfn,
864 * XXX: the dirty test could be racy: set_page_dirty() may not always 878 * XXX: the dirty test could be racy: set_page_dirty() may not always
865 * be called inside page lock (it's recommended but not enforced). 879 * be called inside page lock (it's recommended but not enforced).
866 */ 880 */
867 mapping = page_mapping(p); 881 mapping = page_mapping(hpage);
868 if (!PageDirty(p) && mapping && mapping_cap_writeback_dirty(mapping)) { 882 if (!PageDirty(hpage) && mapping &&
869 if (page_mkclean(p)) { 883 mapping_cap_writeback_dirty(mapping)) {
870 SetPageDirty(p); 884 if (page_mkclean(hpage)) {
885 SetPageDirty(hpage);
871 } else { 886 } else {
872 kill = 0; 887 kill = 0;
873 ttu |= TTU_IGNORE_HWPOISON; 888 ttu |= TTU_IGNORE_HWPOISON;
@@ -886,14 +901,14 @@ static int hwpoison_user_mappings(struct page *p, unsigned long pfn,
886 * there's nothing that can be done. 901 * there's nothing that can be done.
887 */ 902 */
888 if (kill) 903 if (kill)
889 collect_procs(p, &tokill); 904 collect_procs(hpage, &tokill);
890 905
891 /* 906 /*
892 * try_to_unmap can fail temporarily due to races. 907 * try_to_unmap can fail temporarily due to races.
893 * Try a few times (RED-PEN better strategy?) 908 * Try a few times (RED-PEN better strategy?)
894 */ 909 */
895 for (i = 0; i < N_UNMAP_TRIES; i++) { 910 for (i = 0; i < N_UNMAP_TRIES; i++) {
896 ret = try_to_unmap(p, ttu); 911 ret = try_to_unmap(hpage, ttu);
897 if (ret == SWAP_SUCCESS) 912 if (ret == SWAP_SUCCESS)
898 break; 913 break;
899 pr_debug("MCE %#lx: try_to_unmap retry needed %d\n", pfn, ret); 914 pr_debug("MCE %#lx: try_to_unmap retry needed %d\n", pfn, ret);
@@ -901,7 +916,7 @@ static int hwpoison_user_mappings(struct page *p, unsigned long pfn,
901 916
902 if (ret != SWAP_SUCCESS) 917 if (ret != SWAP_SUCCESS)
903 printk(KERN_ERR "MCE %#lx: failed to unmap page (mapcount=%d)\n", 918 printk(KERN_ERR "MCE %#lx: failed to unmap page (mapcount=%d)\n",
904 pfn, page_mapcount(p)); 919 pfn, page_mapcount(hpage));
905 920
906 /* 921 /*
907 * Now that the dirty bit has been propagated to the 922 * Now that the dirty bit has been propagated to the
@@ -912,17 +927,35 @@ static int hwpoison_user_mappings(struct page *p, unsigned long pfn,
912 * use a more force-full uncatchable kill to prevent 927 * use a more force-full uncatchable kill to prevent
913 * any accesses to the poisoned memory. 928 * any accesses to the poisoned memory.
914 */ 929 */
915 kill_procs_ao(&tokill, !!PageDirty(p), trapno, 930 kill_procs_ao(&tokill, !!PageDirty(hpage), trapno,
916 ret != SWAP_SUCCESS, pfn); 931 ret != SWAP_SUCCESS, pfn);
917 932
918 return ret; 933 return ret;
919} 934}
920 935
936static void set_page_hwpoison_huge_page(struct page *hpage)
937{
938 int i;
939 int nr_pages = 1 << compound_order(hpage);
940 for (i = 0; i < nr_pages; i++)
941 SetPageHWPoison(hpage + i);
942}
943
944static void clear_page_hwpoison_huge_page(struct page *hpage)
945{
946 int i;
947 int nr_pages = 1 << compound_order(hpage);
948 for (i = 0; i < nr_pages; i++)
949 ClearPageHWPoison(hpage + i);
950}
951
921int __memory_failure(unsigned long pfn, int trapno, int flags) 952int __memory_failure(unsigned long pfn, int trapno, int flags)
922{ 953{
923 struct page_state *ps; 954 struct page_state *ps;
924 struct page *p; 955 struct page *p;
956 struct page *hpage;
925 int res; 957 int res;
958 unsigned int nr_pages;
926 959
927 if (!sysctl_memory_failure_recovery) 960 if (!sysctl_memory_failure_recovery)
928 panic("Memory failure from trap %d on page %lx", trapno, pfn); 961 panic("Memory failure from trap %d on page %lx", trapno, pfn);
@@ -935,12 +968,14 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
935 } 968 }
936 969
937 p = pfn_to_page(pfn); 970 p = pfn_to_page(pfn);
971 hpage = compound_head(p);
938 if (TestSetPageHWPoison(p)) { 972 if (TestSetPageHWPoison(p)) {
939 printk(KERN_ERR "MCE %#lx: already hardware poisoned\n", pfn); 973 printk(KERN_ERR "MCE %#lx: already hardware poisoned\n", pfn);
940 return 0; 974 return 0;
941 } 975 }
942 976
943 atomic_long_add(1, &mce_bad_pages); 977 nr_pages = 1 << compound_order(hpage);
978 atomic_long_add(nr_pages, &mce_bad_pages);
944 979
945 /* 980 /*
946 * We need/can do nothing about count=0 pages. 981 * We need/can do nothing about count=0 pages.
@@ -954,7 +989,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
954 * that may make page_freeze_refs()/page_unfreeze_refs() mismatch. 989 * that may make page_freeze_refs()/page_unfreeze_refs() mismatch.
955 */ 990 */
956 if (!(flags & MF_COUNT_INCREASED) && 991 if (!(flags & MF_COUNT_INCREASED) &&
957 !get_page_unless_zero(compound_head(p))) { 992 !get_page_unless_zero(hpage)) {
958 if (is_free_buddy_page(p)) { 993 if (is_free_buddy_page(p)) {
959 action_result(pfn, "free buddy", DELAYED); 994 action_result(pfn, "free buddy", DELAYED);
960 return 0; 995 return 0;
@@ -972,9 +1007,9 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
972 * The check (unnecessarily) ignores LRU pages being isolated and 1007 * The check (unnecessarily) ignores LRU pages being isolated and
973 * walked by the page reclaim code, however that's not a big loss. 1008 * walked by the page reclaim code, however that's not a big loss.
974 */ 1009 */
975 if (!PageLRU(p)) 1010 if (!PageLRU(p) && !PageHuge(p))
976 shake_page(p, 0); 1011 shake_page(p, 0);
977 if (!PageLRU(p)) { 1012 if (!PageLRU(p) && !PageHuge(p)) {
978 /* 1013 /*
979 * shake_page could have turned it free. 1014 * shake_page could have turned it free.
980 */ 1015 */
@@ -992,7 +1027,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
992 * It's very difficult to mess with pages currently under IO 1027 * It's very difficult to mess with pages currently under IO
993 * and in many cases impossible, so we just avoid it here. 1028 * and in many cases impossible, so we just avoid it here.
994 */ 1029 */
995 lock_page_nosync(p); 1030 lock_page_nosync(hpage);
996 1031
997 /* 1032 /*
998 * unpoison always clear PG_hwpoison inside page lock 1033 * unpoison always clear PG_hwpoison inside page lock
@@ -1004,11 +1039,31 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
1004 } 1039 }
1005 if (hwpoison_filter(p)) { 1040 if (hwpoison_filter(p)) {
1006 if (TestClearPageHWPoison(p)) 1041 if (TestClearPageHWPoison(p))
1007 atomic_long_dec(&mce_bad_pages); 1042 atomic_long_sub(nr_pages, &mce_bad_pages);
1008 unlock_page(p); 1043 unlock_page(hpage);
1009 put_page(p); 1044 put_page(hpage);
1045 return 0;
1046 }
1047
1048 /*
1049 * For error on the tail page, we should set PG_hwpoison
1050 * on the head page to show that the hugepage is hwpoisoned
1051 */
1052 if (PageTail(p) && TestSetPageHWPoison(hpage)) {
1053 action_result(pfn, "hugepage already hardware poisoned",
1054 IGNORED);
1055 unlock_page(hpage);
1056 put_page(hpage);
1010 return 0; 1057 return 0;
1011 } 1058 }
1059 /*
1060 * Set PG_hwpoison on all pages in an error hugepage,
1061 * because containment is done in hugepage unit for now.
1062 * Since we have done TestSetPageHWPoison() for the head page with
1063 * page lock held, we can safely set PG_hwpoison bits on tail pages.
1064 */
1065 if (PageHuge(p))
1066 set_page_hwpoison_huge_page(hpage);
1012 1067
1013 wait_on_page_writeback(p); 1068 wait_on_page_writeback(p);
1014 1069
@@ -1039,7 +1094,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
1039 } 1094 }
1040 } 1095 }
1041out: 1096out:
1042 unlock_page(p); 1097 unlock_page(hpage);
1043 return res; 1098 return res;
1044} 1099}
1045EXPORT_SYMBOL_GPL(__memory_failure); 1100EXPORT_SYMBOL_GPL(__memory_failure);
@@ -1083,6 +1138,7 @@ int unpoison_memory(unsigned long pfn)
1083 struct page *page; 1138 struct page *page;
1084 struct page *p; 1139 struct page *p;
1085 int freeit = 0; 1140 int freeit = 0;
1141 unsigned int nr_pages;
1086 1142
1087 if (!pfn_valid(pfn)) 1143 if (!pfn_valid(pfn))
1088 return -ENXIO; 1144 return -ENXIO;
@@ -1095,9 +1151,11 @@ int unpoison_memory(unsigned long pfn)
1095 return 0; 1151 return 0;
1096 } 1152 }
1097 1153
1154 nr_pages = 1 << compound_order(page);
1155
1098 if (!get_page_unless_zero(page)) { 1156 if (!get_page_unless_zero(page)) {
1099 if (TestClearPageHWPoison(p)) 1157 if (TestClearPageHWPoison(p))
1100 atomic_long_dec(&mce_bad_pages); 1158 atomic_long_sub(nr_pages, &mce_bad_pages);
1101 pr_debug("MCE: Software-unpoisoned free page %#lx\n", pfn); 1159 pr_debug("MCE: Software-unpoisoned free page %#lx\n", pfn);
1102 return 0; 1160 return 0;
1103 } 1161 }
@@ -1109,11 +1167,13 @@ int unpoison_memory(unsigned long pfn)
1109 * the PG_hwpoison page will be caught and isolated on the entrance to 1167 * the PG_hwpoison page will be caught and isolated on the entrance to
1110 * the free buddy page pool. 1168 * the free buddy page pool.
1111 */ 1169 */
1112 if (TestClearPageHWPoison(p)) { 1170 if (TestClearPageHWPoison(page)) {
1113 pr_debug("MCE: Software-unpoisoned page %#lx\n", pfn); 1171 pr_debug("MCE: Software-unpoisoned page %#lx\n", pfn);
1114 atomic_long_dec(&mce_bad_pages); 1172 atomic_long_sub(nr_pages, &mce_bad_pages);
1115 freeit = 1; 1173 freeit = 1;
1116 } 1174 }
1175 if (PageHuge(p))
1176 clear_page_hwpoison_huge_page(page);
1117 unlock_page(page); 1177 unlock_page(page);
1118 1178
1119 put_page(page); 1179 put_page(page);
diff --git a/mm/memory.c b/mm/memory.c
index 858829d06a92..9b3b73f4ae9c 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2760,6 +2760,26 @@ out_release:
2760} 2760}
2761 2761
2762/* 2762/*
2763 * This is like a special single-page "expand_downwards()",
2764 * except we must first make sure that 'address-PAGE_SIZE'
2765 * doesn't hit another vma.
2766 *
2767 * The "find_vma()" will do the right thing even if we wrap
2768 */
2769static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
2770{
2771 address &= PAGE_MASK;
2772 if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
2773 address -= PAGE_SIZE;
2774 if (find_vma(vma->vm_mm, address) != vma)
2775 return -ENOMEM;
2776
2777 expand_stack(vma, address);
2778 }
2779 return 0;
2780}
2781
2782/*
2763 * We enter with non-exclusive mmap_sem (to exclude vma changes, 2783 * We enter with non-exclusive mmap_sem (to exclude vma changes,
2764 * but allow concurrent faults), and pte mapped but not yet locked. 2784 * but allow concurrent faults), and pte mapped but not yet locked.
2765 * We return with mmap_sem still held, but pte unmapped and unlocked. 2785 * We return with mmap_sem still held, but pte unmapped and unlocked.
@@ -2772,6 +2792,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
2772 spinlock_t *ptl; 2792 spinlock_t *ptl;
2773 pte_t entry; 2793 pte_t entry;
2774 2794
2795 if (check_stack_guard_page(vma, address) < 0) {
2796 pte_unmap(page_table);
2797 return VM_FAULT_SIGBUS;
2798 }
2799
2775 if (!(flags & FAULT_FLAG_WRITE)) { 2800 if (!(flags & FAULT_FLAG_WRITE)) {
2776 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address), 2801 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
2777 vma->vm_page_prot)); 2802 vma->vm_page_prot));
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index d3def05a33d9..5014e50644d1 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -106,7 +106,7 @@ static void boost_dying_task_prio(struct task_struct *p,
106 * pointer. Return p, or any of its subthreads with a valid ->mm, with 106 * pointer. Return p, or any of its subthreads with a valid ->mm, with
107 * task_lock() held. 107 * task_lock() held.
108 */ 108 */
109static struct task_struct *find_lock_task_mm(struct task_struct *p) 109struct task_struct *find_lock_task_mm(struct task_struct *p)
110{ 110{
111 struct task_struct *t = p; 111 struct task_struct *t = p;
112 112
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 0c6258bd1ba3..20890d80c7ef 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -253,32 +253,6 @@ static void bdi_writeout_fraction(struct backing_dev_info *bdi,
253 } 253 }
254} 254}
255 255
256/*
257 * Clip the earned share of dirty pages to that which is actually available.
258 * This avoids exceeding the total dirty_limit when the floating averages
259 * fluctuate too quickly.
260 */
261static void clip_bdi_dirty_limit(struct backing_dev_info *bdi,
262 unsigned long dirty, unsigned long *pbdi_dirty)
263{
264 unsigned long avail_dirty;
265
266 avail_dirty = global_page_state(NR_FILE_DIRTY) +
267 global_page_state(NR_WRITEBACK) +
268 global_page_state(NR_UNSTABLE_NFS) +
269 global_page_state(NR_WRITEBACK_TEMP);
270
271 if (avail_dirty < dirty)
272 avail_dirty = dirty - avail_dirty;
273 else
274 avail_dirty = 0;
275
276 avail_dirty += bdi_stat(bdi, BDI_RECLAIMABLE) +
277 bdi_stat(bdi, BDI_WRITEBACK);
278
279 *pbdi_dirty = min(*pbdi_dirty, avail_dirty);
280}
281
282static inline void task_dirties_fraction(struct task_struct *tsk, 256static inline void task_dirties_fraction(struct task_struct *tsk,
283 long *numerator, long *denominator) 257 long *numerator, long *denominator)
284{ 258{
@@ -287,16 +261,24 @@ static inline void task_dirties_fraction(struct task_struct *tsk,
287} 261}
288 262
289/* 263/*
290 * scale the dirty limit 264 * task_dirty_limit - scale down dirty throttling threshold for one task
291 * 265 *
292 * task specific dirty limit: 266 * task specific dirty limit:
293 * 267 *
294 * dirty -= (dirty/8) * p_{t} 268 * dirty -= (dirty/8) * p_{t}
269 *
270 * To protect light/slow dirtying tasks from heavier/fast ones, we start
271 * throttling individual tasks before reaching the bdi dirty limit.
272 * Relatively low thresholds will be allocated to heavy dirtiers. So when
273 * dirty pages grow large, heavy dirtiers will be throttled first, which will
274 * effectively curb the growth of dirty pages. Light dirtiers with high enough
275 * dirty threshold may never get throttled.
295 */ 276 */
296static void task_dirty_limit(struct task_struct *tsk, unsigned long *pdirty) 277static unsigned long task_dirty_limit(struct task_struct *tsk,
278 unsigned long bdi_dirty)
297{ 279{
298 long numerator, denominator; 280 long numerator, denominator;
299 unsigned long dirty = *pdirty; 281 unsigned long dirty = bdi_dirty;
300 u64 inv = dirty >> 3; 282 u64 inv = dirty >> 3;
301 283
302 task_dirties_fraction(tsk, &numerator, &denominator); 284 task_dirties_fraction(tsk, &numerator, &denominator);
@@ -304,10 +286,8 @@ static void task_dirty_limit(struct task_struct *tsk, unsigned long *pdirty)
304 do_div(inv, denominator); 286 do_div(inv, denominator);
305 287
306 dirty -= inv; 288 dirty -= inv;
307 if (dirty < *pdirty/2)
308 dirty = *pdirty/2;
309 289
310 *pdirty = dirty; 290 return max(dirty, bdi_dirty/2);
311} 291}
312 292
313/* 293/*
@@ -417,9 +397,16 @@ unsigned long determine_dirtyable_memory(void)
417 return x + 1; /* Ensure that we never return 0 */ 397 return x + 1; /* Ensure that we never return 0 */
418} 398}
419 399
420void 400/**
421get_dirty_limits(unsigned long *pbackground, unsigned long *pdirty, 401 * global_dirty_limits - background-writeback and dirty-throttling thresholds
422 unsigned long *pbdi_dirty, struct backing_dev_info *bdi) 402 *
403 * Calculate the dirty thresholds based on sysctl parameters
404 * - vm.dirty_background_ratio or vm.dirty_background_bytes
405 * - vm.dirty_ratio or vm.dirty_bytes
406 * The dirty limits will be lifted by 1/4 for PF_LESS_THROTTLE (ie. nfsd) and
407 * runtime tasks.
408 */
409void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty)
423{ 410{
424 unsigned long background; 411 unsigned long background;
425 unsigned long dirty; 412 unsigned long dirty;
@@ -451,27 +438,37 @@ get_dirty_limits(unsigned long *pbackground, unsigned long *pdirty,
451 } 438 }
452 *pbackground = background; 439 *pbackground = background;
453 *pdirty = dirty; 440 *pdirty = dirty;
441}
442
443/**
444 * bdi_dirty_limit - @bdi's share of dirty throttling threshold
445 *
446 * Allocate high/low dirty limits to fast/slow devices, in order to prevent
447 * - starving fast devices
448 * - piling up dirty pages (that will take long time to sync) on slow devices
449 *
450 * The bdi's share of dirty limit will be adapting to its throughput and
451 * bounded by the bdi->min_ratio and/or bdi->max_ratio parameters, if set.
452 */
453unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
454{
455 u64 bdi_dirty;
456 long numerator, denominator;
457
458 /*
459 * Calculate this BDI's share of the dirty ratio.
460 */
461 bdi_writeout_fraction(bdi, &numerator, &denominator);
454 462
455 if (bdi) { 463 bdi_dirty = (dirty * (100 - bdi_min_ratio)) / 100;
456 u64 bdi_dirty; 464 bdi_dirty *= numerator;
457 long numerator, denominator; 465 do_div(bdi_dirty, denominator);
458 466
459 /* 467 bdi_dirty += (dirty * bdi->min_ratio) / 100;
460 * Calculate this BDI's share of the dirty ratio. 468 if (bdi_dirty > (dirty * bdi->max_ratio) / 100)
461 */ 469 bdi_dirty = dirty * bdi->max_ratio / 100;
462 bdi_writeout_fraction(bdi, &numerator, &denominator); 470
463 471 return bdi_dirty;
464 bdi_dirty = (dirty * (100 - bdi_min_ratio)) / 100;
465 bdi_dirty *= numerator;
466 do_div(bdi_dirty, denominator);
467 bdi_dirty += (dirty * bdi->min_ratio) / 100;
468 if (bdi_dirty > (dirty * bdi->max_ratio) / 100)
469 bdi_dirty = dirty * bdi->max_ratio / 100;
470
471 *pbdi_dirty = bdi_dirty;
472 clip_bdi_dirty_limit(bdi, dirty, pbdi_dirty);
473 task_dirty_limit(current, pbdi_dirty);
474 }
475} 472}
476 473
477/* 474/*
@@ -491,7 +488,7 @@ static void balance_dirty_pages(struct address_space *mapping,
491 unsigned long bdi_thresh; 488 unsigned long bdi_thresh;
492 unsigned long pages_written = 0; 489 unsigned long pages_written = 0;
493 unsigned long pause = 1; 490 unsigned long pause = 1;
494 491 bool dirty_exceeded = false;
495 struct backing_dev_info *bdi = mapping->backing_dev_info; 492 struct backing_dev_info *bdi = mapping->backing_dev_info;
496 493
497 for (;;) { 494 for (;;) {
@@ -502,18 +499,11 @@ static void balance_dirty_pages(struct address_space *mapping,
502 .range_cyclic = 1, 499 .range_cyclic = 1,
503 }; 500 };
504 501
505 get_dirty_limits(&background_thresh, &dirty_thresh,
506 &bdi_thresh, bdi);
507
508 nr_reclaimable = global_page_state(NR_FILE_DIRTY) + 502 nr_reclaimable = global_page_state(NR_FILE_DIRTY) +
509 global_page_state(NR_UNSTABLE_NFS); 503 global_page_state(NR_UNSTABLE_NFS);
510 nr_writeback = global_page_state(NR_WRITEBACK); 504 nr_writeback = global_page_state(NR_WRITEBACK);
511 505
512 bdi_nr_reclaimable = bdi_stat(bdi, BDI_RECLAIMABLE); 506 global_dirty_limits(&background_thresh, &dirty_thresh);
513 bdi_nr_writeback = bdi_stat(bdi, BDI_WRITEBACK);
514
515 if (bdi_nr_reclaimable + bdi_nr_writeback <= bdi_thresh)
516 break;
517 507
518 /* 508 /*
519 * Throttle it only when the background writeback cannot 509 * Throttle it only when the background writeback cannot
@@ -524,26 +514,8 @@ static void balance_dirty_pages(struct address_space *mapping,
524 (background_thresh + dirty_thresh) / 2) 514 (background_thresh + dirty_thresh) / 2)
525 break; 515 break;
526 516
527 if (!bdi->dirty_exceeded) 517 bdi_thresh = bdi_dirty_limit(bdi, dirty_thresh);
528 bdi->dirty_exceeded = 1; 518 bdi_thresh = task_dirty_limit(current, bdi_thresh);
529
530 /* Note: nr_reclaimable denotes nr_dirty + nr_unstable.
531 * Unstable writes are a feature of certain networked
532 * filesystems (i.e. NFS) in which data may have been
533 * written to the server's write cache, but has not yet
534 * been flushed to permanent storage.
535 * Only move pages to writeback if this bdi is over its
536 * threshold otherwise wait until the disk writes catch
537 * up.
538 */
539 trace_wbc_balance_dirty_start(&wbc, bdi);
540 if (bdi_nr_reclaimable > bdi_thresh) {
541 writeback_inodes_wb(&bdi->wb, &wbc);
542 pages_written += write_chunk - wbc.nr_to_write;
543 get_dirty_limits(&background_thresh, &dirty_thresh,
544 &bdi_thresh, bdi);
545 trace_wbc_balance_dirty_written(&wbc, bdi);
546 }
547 519
548 /* 520 /*
549 * In order to avoid the stacked BDI deadlock we need 521 * In order to avoid the stacked BDI deadlock we need
@@ -558,16 +530,44 @@ static void balance_dirty_pages(struct address_space *mapping,
558 if (bdi_thresh < 2*bdi_stat_error(bdi)) { 530 if (bdi_thresh < 2*bdi_stat_error(bdi)) {
559 bdi_nr_reclaimable = bdi_stat_sum(bdi, BDI_RECLAIMABLE); 531 bdi_nr_reclaimable = bdi_stat_sum(bdi, BDI_RECLAIMABLE);
560 bdi_nr_writeback = bdi_stat_sum(bdi, BDI_WRITEBACK); 532 bdi_nr_writeback = bdi_stat_sum(bdi, BDI_WRITEBACK);
561 } else if (bdi_nr_reclaimable) { 533 } else {
562 bdi_nr_reclaimable = bdi_stat(bdi, BDI_RECLAIMABLE); 534 bdi_nr_reclaimable = bdi_stat(bdi, BDI_RECLAIMABLE);
563 bdi_nr_writeback = bdi_stat(bdi, BDI_WRITEBACK); 535 bdi_nr_writeback = bdi_stat(bdi, BDI_WRITEBACK);
564 } 536 }
565 537
566 if (bdi_nr_reclaimable + bdi_nr_writeback <= bdi_thresh) 538 /*
539 * The bdi thresh is somehow "soft" limit derived from the
540 * global "hard" limit. The former helps to prevent heavy IO
541 * bdi or process from holding back light ones; The latter is
542 * the last resort safeguard.
543 */
544 dirty_exceeded =
545 (bdi_nr_reclaimable + bdi_nr_writeback >= bdi_thresh)
546 || (nr_reclaimable + nr_writeback >= dirty_thresh);
547
548 if (!dirty_exceeded)
567 break; 549 break;
568 if (pages_written >= write_chunk)
569 break; /* We've done our duty */
570 550
551 if (!bdi->dirty_exceeded)
552 bdi->dirty_exceeded = 1;
553
554 /* Note: nr_reclaimable denotes nr_dirty + nr_unstable.
555 * Unstable writes are a feature of certain networked
556 * filesystems (i.e. NFS) in which data may have been
557 * written to the server's write cache, but has not yet
558 * been flushed to permanent storage.
559 * Only move pages to writeback if this bdi is over its
560 * threshold otherwise wait until the disk writes catch
561 * up.
562 */
563 trace_wbc_balance_dirty_start(&wbc, bdi);
564 if (bdi_nr_reclaimable > bdi_thresh) {
565 writeback_inodes_wb(&bdi->wb, &wbc);
566 pages_written += write_chunk - wbc.nr_to_write;
567 trace_wbc_balance_dirty_written(&wbc, bdi);
568 if (pages_written >= write_chunk)
569 break; /* We've done our duty */
570 }
571 trace_wbc_balance_dirty_wait(&wbc, bdi); 571 trace_wbc_balance_dirty_wait(&wbc, bdi);
572 __set_current_state(TASK_INTERRUPTIBLE); 572 __set_current_state(TASK_INTERRUPTIBLE);
573 io_schedule_timeout(pause); 573 io_schedule_timeout(pause);
@@ -581,8 +581,7 @@ static void balance_dirty_pages(struct address_space *mapping,
581 pause = HZ / 10; 581 pause = HZ / 10;
582 } 582 }
583 583
584 if (bdi_nr_reclaimable + bdi_nr_writeback < bdi_thresh && 584 if (!dirty_exceeded && bdi->dirty_exceeded)
585 bdi->dirty_exceeded)
586 bdi->dirty_exceeded = 0; 585 bdi->dirty_exceeded = 0;
587 586
588 if (writeback_in_progress(bdi)) 587 if (writeback_in_progress(bdi))
@@ -597,9 +596,7 @@ static void balance_dirty_pages(struct address_space *mapping,
597 * background_thresh, to keep the amount of dirty memory low. 596 * background_thresh, to keep the amount of dirty memory low.
598 */ 597 */
599 if ((laptop_mode && pages_written) || 598 if ((laptop_mode && pages_written) ||
600 (!laptop_mode && ((global_page_state(NR_FILE_DIRTY) 599 (!laptop_mode && (nr_reclaimable > background_thresh)))
601 + global_page_state(NR_UNSTABLE_NFS))
602 > background_thresh)))
603 bdi_start_background_writeback(bdi); 600 bdi_start_background_writeback(bdi);
604} 601}
605 602
@@ -663,7 +660,7 @@ void throttle_vm_writeout(gfp_t gfp_mask)
663 unsigned long dirty_thresh; 660 unsigned long dirty_thresh;
664 661
665 for ( ; ; ) { 662 for ( ; ; ) {
666 get_dirty_limits(&background_thresh, &dirty_thresh, NULL, NULL); 663 global_dirty_limits(&background_thresh, &dirty_thresh);
667 664
668 /* 665 /*
669 * Boost the allowable dirty threshold a bit for page 666 * Boost the allowable dirty threshold a bit for page
@@ -825,10 +822,10 @@ void __init page_writeback_init(void)
825/* 822/*
826 * We tag pages in batches of WRITEBACK_TAG_BATCH to reduce tree_lock latency. 823 * We tag pages in batches of WRITEBACK_TAG_BATCH to reduce tree_lock latency.
827 */ 824 */
828#define WRITEBACK_TAG_BATCH 4096
829void tag_pages_for_writeback(struct address_space *mapping, 825void tag_pages_for_writeback(struct address_space *mapping,
830 pgoff_t start, pgoff_t end) 826 pgoff_t start, pgoff_t end)
831{ 827{
828#define WRITEBACK_TAG_BATCH 4096
832 unsigned long tagged; 829 unsigned long tagged;
833 830
834 do { 831 do {
diff --git a/mm/rmap.c b/mm/rmap.c
index a7d0f5482634..87b9e8ad4509 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -56,6 +56,7 @@
56#include <linux/memcontrol.h> 56#include <linux/memcontrol.h>
57#include <linux/mmu_notifier.h> 57#include <linux/mmu_notifier.h>
58#include <linux/migrate.h> 58#include <linux/migrate.h>
59#include <linux/hugetlb.h>
59 60
60#include <asm/tlbflush.h> 61#include <asm/tlbflush.h>
61 62
@@ -350,6 +351,8 @@ vma_address(struct page *page, struct vm_area_struct *vma)
350 pgoff_t pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT); 351 pgoff_t pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
351 unsigned long address; 352 unsigned long address;
352 353
354 if (unlikely(is_vm_hugetlb_page(vma)))
355 pgoff = page->index << huge_page_order(page_hstate(page));
353 address = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT); 356 address = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
354 if (unlikely(address < vma->vm_start || address >= vma->vm_end)) { 357 if (unlikely(address < vma->vm_start || address >= vma->vm_end)) {
355 /* page should be within @vma mapping range */ 358 /* page should be within @vma mapping range */
@@ -394,6 +397,12 @@ pte_t *page_check_address(struct page *page, struct mm_struct *mm,
394 pte_t *pte; 397 pte_t *pte;
395 spinlock_t *ptl; 398 spinlock_t *ptl;
396 399
400 if (unlikely(PageHuge(page))) {
401 pte = huge_pte_offset(mm, address);
402 ptl = &mm->page_table_lock;
403 goto check;
404 }
405
397 pgd = pgd_offset(mm, address); 406 pgd = pgd_offset(mm, address);
398 if (!pgd_present(*pgd)) 407 if (!pgd_present(*pgd))
399 return NULL; 408 return NULL;
@@ -414,6 +423,7 @@ pte_t *page_check_address(struct page *page, struct mm_struct *mm,
414 } 423 }
415 424
416 ptl = pte_lockptr(mm, pmd); 425 ptl = pte_lockptr(mm, pmd);
426check:
417 spin_lock(ptl); 427 spin_lock(ptl);
418 if (pte_present(*pte) && page_to_pfn(page) == pte_pfn(*pte)) { 428 if (pte_present(*pte) && page_to_pfn(page) == pte_pfn(*pte)) {
419 *ptlp = ptl; 429 *ptlp = ptl;
@@ -916,6 +926,12 @@ void page_remove_rmap(struct page *page)
916 page_clear_dirty(page); 926 page_clear_dirty(page);
917 set_page_dirty(page); 927 set_page_dirty(page);
918 } 928 }
929 /*
930 * Hugepages are not counted in NR_ANON_PAGES nor NR_FILE_MAPPED
931 * and not charged by memcg for now.
932 */
933 if (unlikely(PageHuge(page)))
934 return;
919 if (PageAnon(page)) { 935 if (PageAnon(page)) {
920 mem_cgroup_uncharge_page(page); 936 mem_cgroup_uncharge_page(page);
921 __dec_zone_page_state(page, NR_ANON_PAGES); 937 __dec_zone_page_state(page, NR_ANON_PAGES);
@@ -1524,3 +1540,46 @@ int rmap_walk(struct page *page, int (*rmap_one)(struct page *,
1524 return rmap_walk_file(page, rmap_one, arg); 1540 return rmap_walk_file(page, rmap_one, arg);
1525} 1541}
1526#endif /* CONFIG_MIGRATION */ 1542#endif /* CONFIG_MIGRATION */
1543
1544#ifdef CONFIG_HUGETLB_PAGE
1545/*
1546 * The following three functions are for anonymous (private mapped) hugepages.
1547 * Unlike common anonymous pages, anonymous hugepages have no accounting code
1548 * and no lru code, because we handle hugepages differently from common pages.
1549 */
1550static void __hugepage_set_anon_rmap(struct page *page,
1551 struct vm_area_struct *vma, unsigned long address, int exclusive)
1552{
1553 struct anon_vma *anon_vma = vma->anon_vma;
1554 BUG_ON(!anon_vma);
1555 if (!exclusive) {
1556 struct anon_vma_chain *avc;
1557 avc = list_entry(vma->anon_vma_chain.prev,
1558 struct anon_vma_chain, same_vma);
1559 anon_vma = avc->anon_vma;
1560 }
1561 anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON;
1562 page->mapping = (struct address_space *) anon_vma;
1563 page->index = linear_page_index(vma, address);
1564}
1565
1566void hugepage_add_anon_rmap(struct page *page,
1567 struct vm_area_struct *vma, unsigned long address)
1568{
1569 struct anon_vma *anon_vma = vma->anon_vma;
1570 int first;
1571 BUG_ON(!anon_vma);
1572 BUG_ON(address < vma->vm_start || address >= vma->vm_end);
1573 first = atomic_inc_and_test(&page->_mapcount);
1574 if (first)
1575 __hugepage_set_anon_rmap(page, vma, address, 0);
1576}
1577
1578void hugepage_add_new_anon_rmap(struct page *page,
1579 struct vm_area_struct *vma, unsigned long address)
1580{
1581 BUG_ON(address < vma->vm_start || address >= vma->vm_end);
1582 atomic_set(&page->_mapcount, 0);
1583 __hugepage_set_anon_rmap(page, vma, address, 1);
1584}
1585#endif /* CONFIG_HUGETLB_PAGE */
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 918c51335d64..6b8889da69a6 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -31,6 +31,7 @@
31#include <asm/tlbflush.h> 31#include <asm/tlbflush.h>
32#include <asm/shmparam.h> 32#include <asm/shmparam.h>
33 33
34bool vmap_lazy_unmap __read_mostly = true;
34 35
35/*** Page table manipulation functions ***/ 36/*** Page table manipulation functions ***/
36 37
@@ -502,6 +503,9 @@ static unsigned long lazy_max_pages(void)
502{ 503{
503 unsigned int log; 504 unsigned int log;
504 505
506 if (!vmap_lazy_unmap)
507 return 0;
508
505 log = fls(num_online_cpus()); 509 log = fls(num_online_cpus());
506 510
507 return log * (32UL * 1024 * 1024 / PAGE_SIZE); 511 return log * (32UL * 1024 * 1024 / PAGE_SIZE);
diff --git a/mm/vmscan.c b/mm/vmscan.c
index ec5ddccbf82e..c391c320dbaf 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1969,9 +1969,10 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
1969unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, 1969unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
1970 gfp_t gfp_mask, bool noswap, 1970 gfp_t gfp_mask, bool noswap,
1971 unsigned int swappiness, 1971 unsigned int swappiness,
1972 struct zone *zone, int nid) 1972 struct zone *zone)
1973{ 1973{
1974 struct scan_control sc = { 1974 struct scan_control sc = {
1975 .nr_to_reclaim = SWAP_CLUSTER_MAX,
1975 .may_writepage = !laptop_mode, 1976 .may_writepage = !laptop_mode,
1976 .may_unmap = 1, 1977 .may_unmap = 1,
1977 .may_swap = !noswap, 1978 .may_swap = !noswap,
@@ -1979,13 +1980,8 @@ unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
1979 .order = 0, 1980 .order = 0,
1980 .mem_cgroup = mem, 1981 .mem_cgroup = mem,
1981 }; 1982 };
1982 nodemask_t nm = nodemask_of_node(nid);
1983
1984 sc.gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) | 1983 sc.gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) |
1985 (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK); 1984 (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK);
1986 sc.nodemask = &nm;
1987 sc.nr_reclaimed = 0;
1988 sc.nr_scanned = 0;
1989 1985
1990 trace_mm_vmscan_memcg_softlimit_reclaim_begin(0, 1986 trace_mm_vmscan_memcg_softlimit_reclaim_begin(0,
1991 sc.may_writepage, 1987 sc.may_writepage,
@@ -2172,7 +2168,6 @@ loop_again:
2172 for (i = 0; i <= end_zone; i++) { 2168 for (i = 0; i <= end_zone; i++) {
2173 struct zone *zone = pgdat->node_zones + i; 2169 struct zone *zone = pgdat->node_zones + i;
2174 int nr_slab; 2170 int nr_slab;
2175 int nid, zid;
2176 2171
2177 if (!populated_zone(zone)) 2172 if (!populated_zone(zone))
2178 continue; 2173 continue;
@@ -2182,14 +2177,12 @@ loop_again:
2182 2177
2183 sc.nr_scanned = 0; 2178 sc.nr_scanned = 0;
2184 2179
2185 nid = pgdat->node_id;
2186 zid = zone_idx(zone);
2187 /* 2180 /*
2188 * Call soft limit reclaim before calling shrink_zone. 2181 * Call soft limit reclaim before calling shrink_zone.
2189 * For now we ignore the return value 2182 * For now we ignore the return value
2190 */ 2183 */
2191 mem_cgroup_soft_limit_reclaim(zone, order, sc.gfp_mask, 2184 mem_cgroup_soft_limit_reclaim(zone, order, sc.gfp_mask);
2192 nid, zid); 2185
2193 /* 2186 /*
2194 * We put equal pressure on every zone, unless one 2187 * We put equal pressure on every zone, unless one
2195 * zone has way too many pages free already. 2188 * zone has way too many pages free already.
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 3e3cd9d4e52c..fadf26b4ed7c 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -2705,8 +2705,9 @@ done:
2705 case L2CAP_MODE_ERTM: 2705 case L2CAP_MODE_ERTM:
2706 pi->remote_tx_win = rfc.txwin_size; 2706 pi->remote_tx_win = rfc.txwin_size;
2707 pi->remote_max_tx = rfc.max_transmit; 2707 pi->remote_max_tx = rfc.max_transmit;
2708 if (rfc.max_pdu_size > pi->conn->mtu - 10) 2708
2709 rfc.max_pdu_size = le16_to_cpu(pi->conn->mtu - 10); 2709 if (le16_to_cpu(rfc.max_pdu_size) > pi->conn->mtu - 10)
2710 rfc.max_pdu_size = cpu_to_le16(pi->conn->mtu - 10);
2710 2711
2711 pi->remote_mps = le16_to_cpu(rfc.max_pdu_size); 2712 pi->remote_mps = le16_to_cpu(rfc.max_pdu_size);
2712 2713
@@ -2723,8 +2724,8 @@ done:
2723 break; 2724 break;
2724 2725
2725 case L2CAP_MODE_STREAMING: 2726 case L2CAP_MODE_STREAMING:
2726 if (rfc.max_pdu_size > pi->conn->mtu - 10) 2727 if (le16_to_cpu(rfc.max_pdu_size) > pi->conn->mtu - 10)
2727 rfc.max_pdu_size = le16_to_cpu(pi->conn->mtu - 10); 2728 rfc.max_pdu_size = cpu_to_le16(pi->conn->mtu - 10);
2728 2729
2729 pi->remote_mps = le16_to_cpu(rfc.max_pdu_size); 2730 pi->remote_mps = le16_to_cpu(rfc.max_pdu_size);
2730 2731
@@ -2806,7 +2807,6 @@ static int l2cap_parse_conf_rsp(struct sock *sk, void *rsp, int len, void *data,
2806 if (*result == L2CAP_CONF_SUCCESS) { 2807 if (*result == L2CAP_CONF_SUCCESS) {
2807 switch (rfc.mode) { 2808 switch (rfc.mode) {
2808 case L2CAP_MODE_ERTM: 2809 case L2CAP_MODE_ERTM:
2809 pi->remote_tx_win = rfc.txwin_size;
2810 pi->retrans_timeout = le16_to_cpu(rfc.retrans_timeout); 2810 pi->retrans_timeout = le16_to_cpu(rfc.retrans_timeout);
2811 pi->monitor_timeout = le16_to_cpu(rfc.monitor_timeout); 2811 pi->monitor_timeout = le16_to_cpu(rfc.monitor_timeout);
2812 pi->mps = le16_to_cpu(rfc.max_pdu_size); 2812 pi->mps = le16_to_cpu(rfc.max_pdu_size);
@@ -2862,7 +2862,6 @@ static void l2cap_conf_rfc_get(struct sock *sk, void *rsp, int len)
2862done: 2862done:
2863 switch (rfc.mode) { 2863 switch (rfc.mode) {
2864 case L2CAP_MODE_ERTM: 2864 case L2CAP_MODE_ERTM:
2865 pi->remote_tx_win = rfc.txwin_size;
2866 pi->retrans_timeout = le16_to_cpu(rfc.retrans_timeout); 2865 pi->retrans_timeout = le16_to_cpu(rfc.retrans_timeout);
2867 pi->monitor_timeout = le16_to_cpu(rfc.monitor_timeout); 2866 pi->monitor_timeout = le16_to_cpu(rfc.monitor_timeout);
2868 pi->mps = le16_to_cpu(rfc.max_pdu_size); 2867 pi->mps = le16_to_cpu(rfc.max_pdu_size);
diff --git a/net/caif/cfpkt_skbuff.c b/net/caif/cfpkt_skbuff.c
index 01f238ff2346..c49a6695793a 100644
--- a/net/caif/cfpkt_skbuff.c
+++ b/net/caif/cfpkt_skbuff.c
@@ -9,7 +9,7 @@
9#include <linux/hardirq.h> 9#include <linux/hardirq.h>
10#include <net/caif/cfpkt.h> 10#include <net/caif/cfpkt.h>
11 11
12#define PKT_PREFIX 16 12#define PKT_PREFIX 48
13#define PKT_POSTFIX 2 13#define PKT_POSTFIX 2
14#define PKT_LEN_WHEN_EXTENDING 128 14#define PKT_LEN_WHEN_EXTENDING 128
15#define PKT_ERROR(pkt, errmsg) do { \ 15#define PKT_ERROR(pkt, errmsg) do { \
diff --git a/net/can/bcm.c b/net/can/bcm.c
index 9c65e9deb9c3..08ffe9e4be20 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -60,6 +60,13 @@
60#include <net/sock.h> 60#include <net/sock.h>
61#include <net/net_namespace.h> 61#include <net/net_namespace.h>
62 62
63/*
64 * To send multiple CAN frame content within TX_SETUP or to filter
65 * CAN messages with multiplex index within RX_SETUP, the number of
66 * different filters is limited to 256 due to the one byte index value.
67 */
68#define MAX_NFRAMES 256
69
63/* use of last_frames[index].can_dlc */ 70/* use of last_frames[index].can_dlc */
64#define RX_RECV 0x40 /* received data for this element */ 71#define RX_RECV 0x40 /* received data for this element */
65#define RX_THR 0x80 /* element not been sent due to throttle feature */ 72#define RX_THR 0x80 /* element not been sent due to throttle feature */
@@ -89,16 +96,16 @@ struct bcm_op {
89 struct list_head list; 96 struct list_head list;
90 int ifindex; 97 int ifindex;
91 canid_t can_id; 98 canid_t can_id;
92 int flags; 99 u32 flags;
93 unsigned long frames_abs, frames_filtered; 100 unsigned long frames_abs, frames_filtered;
94 struct timeval ival1, ival2; 101 struct timeval ival1, ival2;
95 struct hrtimer timer, thrtimer; 102 struct hrtimer timer, thrtimer;
96 struct tasklet_struct tsklet, thrtsklet; 103 struct tasklet_struct tsklet, thrtsklet;
97 ktime_t rx_stamp, kt_ival1, kt_ival2, kt_lastmsg; 104 ktime_t rx_stamp, kt_ival1, kt_ival2, kt_lastmsg;
98 int rx_ifindex; 105 int rx_ifindex;
99 int count; 106 u32 count;
100 int nframes; 107 u32 nframes;
101 int currframe; 108 u32 currframe;
102 struct can_frame *frames; 109 struct can_frame *frames;
103 struct can_frame *last_frames; 110 struct can_frame *last_frames;
104 struct can_frame sframe; 111 struct can_frame sframe;
@@ -175,7 +182,7 @@ static int bcm_proc_show(struct seq_file *m, void *v)
175 182
176 seq_printf(m, "rx_op: %03X %-5s ", 183 seq_printf(m, "rx_op: %03X %-5s ",
177 op->can_id, bcm_proc_getifname(ifname, op->ifindex)); 184 op->can_id, bcm_proc_getifname(ifname, op->ifindex));
178 seq_printf(m, "[%d]%c ", op->nframes, 185 seq_printf(m, "[%u]%c ", op->nframes,
179 (op->flags & RX_CHECK_DLC)?'d':' '); 186 (op->flags & RX_CHECK_DLC)?'d':' ');
180 if (op->kt_ival1.tv64) 187 if (op->kt_ival1.tv64)
181 seq_printf(m, "timeo=%lld ", 188 seq_printf(m, "timeo=%lld ",
@@ -198,7 +205,7 @@ static int bcm_proc_show(struct seq_file *m, void *v)
198 205
199 list_for_each_entry(op, &bo->tx_ops, list) { 206 list_for_each_entry(op, &bo->tx_ops, list) {
200 207
201 seq_printf(m, "tx_op: %03X %s [%d] ", 208 seq_printf(m, "tx_op: %03X %s [%u] ",
202 op->can_id, 209 op->can_id,
203 bcm_proc_getifname(ifname, op->ifindex), 210 bcm_proc_getifname(ifname, op->ifindex),
204 op->nframes); 211 op->nframes);
@@ -283,7 +290,7 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
283 struct can_frame *firstframe; 290 struct can_frame *firstframe;
284 struct sockaddr_can *addr; 291 struct sockaddr_can *addr;
285 struct sock *sk = op->sk; 292 struct sock *sk = op->sk;
286 int datalen = head->nframes * CFSIZ; 293 unsigned int datalen = head->nframes * CFSIZ;
287 int err; 294 int err;
288 295
289 skb = alloc_skb(sizeof(*head) + datalen, gfp_any()); 296 skb = alloc_skb(sizeof(*head) + datalen, gfp_any());
@@ -468,7 +475,7 @@ rx_changed_settime:
468 * bcm_rx_cmp_to_index - (bit)compares the currently received data to formerly 475 * bcm_rx_cmp_to_index - (bit)compares the currently received data to formerly
469 * received data stored in op->last_frames[] 476 * received data stored in op->last_frames[]
470 */ 477 */
471static void bcm_rx_cmp_to_index(struct bcm_op *op, int index, 478static void bcm_rx_cmp_to_index(struct bcm_op *op, unsigned int index,
472 const struct can_frame *rxdata) 479 const struct can_frame *rxdata)
473{ 480{
474 /* 481 /*
@@ -554,7 +561,8 @@ static enum hrtimer_restart bcm_rx_timeout_handler(struct hrtimer *hrtimer)
554/* 561/*
555 * bcm_rx_do_flush - helper for bcm_rx_thr_flush 562 * bcm_rx_do_flush - helper for bcm_rx_thr_flush
556 */ 563 */
557static inline int bcm_rx_do_flush(struct bcm_op *op, int update, int index) 564static inline int bcm_rx_do_flush(struct bcm_op *op, int update,
565 unsigned int index)
558{ 566{
559 if ((op->last_frames) && (op->last_frames[index].can_dlc & RX_THR)) { 567 if ((op->last_frames) && (op->last_frames[index].can_dlc & RX_THR)) {
560 if (update) 568 if (update)
@@ -575,7 +583,7 @@ static int bcm_rx_thr_flush(struct bcm_op *op, int update)
575 int updated = 0; 583 int updated = 0;
576 584
577 if (op->nframes > 1) { 585 if (op->nframes > 1) {
578 int i; 586 unsigned int i;
579 587
580 /* for MUX filter we start at index 1 */ 588 /* for MUX filter we start at index 1 */
581 for (i = 1; i < op->nframes; i++) 589 for (i = 1; i < op->nframes; i++)
@@ -624,7 +632,7 @@ static void bcm_rx_handler(struct sk_buff *skb, void *data)
624{ 632{
625 struct bcm_op *op = (struct bcm_op *)data; 633 struct bcm_op *op = (struct bcm_op *)data;
626 const struct can_frame *rxframe = (struct can_frame *)skb->data; 634 const struct can_frame *rxframe = (struct can_frame *)skb->data;
627 int i; 635 unsigned int i;
628 636
629 /* disable timeout */ 637 /* disable timeout */
630 hrtimer_cancel(&op->timer); 638 hrtimer_cancel(&op->timer);
@@ -822,14 +830,15 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
822{ 830{
823 struct bcm_sock *bo = bcm_sk(sk); 831 struct bcm_sock *bo = bcm_sk(sk);
824 struct bcm_op *op; 832 struct bcm_op *op;
825 int i, err; 833 unsigned int i;
834 int err;
826 835
827 /* we need a real device to send frames */ 836 /* we need a real device to send frames */
828 if (!ifindex) 837 if (!ifindex)
829 return -ENODEV; 838 return -ENODEV;
830 839
831 /* we need at least one can_frame */ 840 /* check nframes boundaries - we need at least one can_frame */
832 if (msg_head->nframes < 1) 841 if (msg_head->nframes < 1 || msg_head->nframes > MAX_NFRAMES)
833 return -EINVAL; 842 return -EINVAL;
834 843
835 /* check the given can_id */ 844 /* check the given can_id */
@@ -993,6 +1002,10 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
993 msg_head->nframes = 0; 1002 msg_head->nframes = 0;
994 } 1003 }
995 1004
1005 /* the first element contains the mux-mask => MAX_NFRAMES + 1 */
1006 if (msg_head->nframes > MAX_NFRAMES + 1)
1007 return -EINVAL;
1008
996 if ((msg_head->flags & RX_RTR_FRAME) && 1009 if ((msg_head->flags & RX_RTR_FRAME) &&
997 ((msg_head->nframes != 1) || 1010 ((msg_head->nframes != 1) ||
998 (!(msg_head->can_id & CAN_RTR_FLAG)))) 1011 (!(msg_head->can_id & CAN_RTR_FLAG))))
diff --git a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c
index 400a04d5c9a1..739435a6af39 100644
--- a/net/dns_resolver/dns_key.c
+++ b/net/dns_resolver/dns_key.c
@@ -29,6 +29,7 @@
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/keyctl.h> 30#include <linux/keyctl.h>
31#include <linux/err.h> 31#include <linux/err.h>
32#include <linux/seq_file.h>
32#include <keys/dns_resolver-type.h> 33#include <keys/dns_resolver-type.h>
33#include <keys/user-type.h> 34#include <keys/user-type.h>
34#include "internal.h" 35#include "internal.h"
@@ -43,6 +44,8 @@ MODULE_PARM_DESC(debug, "DNS Resolver debugging mask");
43 44
44const struct cred *dns_resolver_cache; 45const struct cred *dns_resolver_cache;
45 46
47#define DNS_ERRORNO_OPTION "dnserror"
48
46/* 49/*
47 * Instantiate a user defined key for dns_resolver. 50 * Instantiate a user defined key for dns_resolver.
48 * 51 *
@@ -59,9 +62,10 @@ static int
59dns_resolver_instantiate(struct key *key, const void *_data, size_t datalen) 62dns_resolver_instantiate(struct key *key, const void *_data, size_t datalen)
60{ 63{
61 struct user_key_payload *upayload; 64 struct user_key_payload *upayload;
65 unsigned long derrno;
62 int ret; 66 int ret;
63 size_t result_len = 0; 67 size_t result_len = 0;
64 const char *data = _data, *opt; 68 const char *data = _data, *end, *opt;
65 69
66 kenter("%%%d,%s,'%s',%zu", 70 kenter("%%%d,%s,'%s',%zu",
67 key->serial, key->description, data, datalen); 71 key->serial, key->description, data, datalen);
@@ -71,13 +75,77 @@ dns_resolver_instantiate(struct key *key, const void *_data, size_t datalen)
71 datalen--; 75 datalen--;
72 76
73 /* deal with any options embedded in the data */ 77 /* deal with any options embedded in the data */
78 end = data + datalen;
74 opt = memchr(data, '#', datalen); 79 opt = memchr(data, '#', datalen);
75 if (!opt) { 80 if (!opt) {
76 kdebug("no options currently supported"); 81 /* no options: the entire data is the result */
77 return -EINVAL; 82 kdebug("no options");
83 result_len = datalen;
84 } else {
85 const char *next_opt;
86
87 result_len = opt - data;
88 opt++;
89 kdebug("options: '%s'", opt);
90 do {
91 const char *eq;
92 int opt_len, opt_nlen, opt_vlen, tmp;
93
94 next_opt = memchr(opt, '#', end - opt) ?: end;
95 opt_len = next_opt - opt;
96 if (!opt_len) {
97 printk(KERN_WARNING
98 "Empty option to dns_resolver key %d\n",
99 key->serial);
100 return -EINVAL;
101 }
102
103 eq = memchr(opt, '=', opt_len) ?: end;
104 opt_nlen = eq - opt;
105 eq++;
106 opt_vlen = next_opt - eq; /* will be -1 if no value */
107
108 tmp = opt_vlen >= 0 ? opt_vlen : 0;
109 kdebug("option '%*.*s' val '%*.*s'",
110 opt_nlen, opt_nlen, opt, tmp, tmp, eq);
111
112 /* see if it's an error number representing a DNS error
113 * that's to be recorded as the result in this key */
114 if (opt_nlen == sizeof(DNS_ERRORNO_OPTION) - 1 &&
115 memcmp(opt, DNS_ERRORNO_OPTION, opt_nlen) == 0) {
116 kdebug("dns error number option");
117 if (opt_vlen <= 0)
118 goto bad_option_value;
119
120 ret = strict_strtoul(eq, 10, &derrno);
121 if (ret < 0)
122 goto bad_option_value;
123
124 if (derrno < 1 || derrno > 511)
125 goto bad_option_value;
126
127 kdebug("dns error no. = %lu", derrno);
128 key->type_data.x[0] = -derrno;
129 continue;
130 }
131
132 bad_option_value:
133 printk(KERN_WARNING
134 "Option '%*.*s' to dns_resolver key %d:"
135 " bad/missing value\n",
136 opt_nlen, opt_nlen, opt, key->serial);
137 return -EINVAL;
138 } while (opt = next_opt + 1, opt < end);
139 }
140
141 /* don't cache the result if we're caching an error saying there's no
142 * result */
143 if (key->type_data.x[0]) {
144 kleave(" = 0 [h_error %ld]", key->type_data.x[0]);
145 return 0;
78 } 146 }
79 147
80 result_len = datalen; 148 kdebug("store result");
81 ret = key_payload_reserve(key, result_len); 149 ret = key_payload_reserve(key, result_len);
82 if (ret < 0) 150 if (ret < 0)
83 return -EINVAL; 151 return -EINVAL;
@@ -135,13 +203,27 @@ no_match:
135 return ret; 203 return ret;
136} 204}
137 205
206/*
207 * Describe a DNS key
208 */
209static void dns_resolver_describe(const struct key *key, struct seq_file *m)
210{
211 int err = key->type_data.x[0];
212
213 seq_puts(m, key->description);
214 if (err)
215 seq_printf(m, ": %d", err);
216 else
217 seq_printf(m, ": %u", key->datalen);
218}
219
138struct key_type key_type_dns_resolver = { 220struct key_type key_type_dns_resolver = {
139 .name = "dns_resolver", 221 .name = "dns_resolver",
140 .instantiate = dns_resolver_instantiate, 222 .instantiate = dns_resolver_instantiate,
141 .match = dns_resolver_match, 223 .match = dns_resolver_match,
142 .revoke = user_revoke, 224 .revoke = user_revoke,
143 .destroy = user_destroy, 225 .destroy = user_destroy,
144 .describe = user_describe, 226 .describe = dns_resolver_describe,
145 .read = user_read, 227 .read = user_read,
146}; 228};
147 229
diff --git a/net/dns_resolver/dns_query.c b/net/dns_resolver/dns_query.c
index 03d5255f5cf2..c32be292c7e3 100644
--- a/net/dns_resolver/dns_query.c
+++ b/net/dns_resolver/dns_query.c
@@ -136,6 +136,11 @@ int dns_query(const char *type, const char *name, size_t namelen,
136 if (ret < 0) 136 if (ret < 0)
137 goto put; 137 goto put;
138 138
139 /* If the DNS server gave an error, return that to the caller */
140 ret = rkey->type_data.x[0];
141 if (ret)
142 goto put;
143
139 upayload = rcu_dereference_protected(rkey->payload.data, 144 upayload = rcu_dereference_protected(rkey->payload.data,
140 lockdep_is_held(&rkey->sem)); 145 lockdep_is_held(&rkey->sem));
141 len = upayload->datalen; 146 len = upayload->datalen;
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index 11201784d29a..87bb5f4de0e8 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -1,7 +1,7 @@
1menuconfig NET_DSA 1menuconfig NET_DSA
2 bool "Distributed Switch Architecture support" 2 bool "Distributed Switch Architecture support"
3 default n 3 default n
4 depends on EXPERIMENTAL && NET_ETHERNET && !S390 4 depends on EXPERIMENTAL && NETDEVICES && !S390
5 select PHYLIB 5 select PHYLIB
6 ---help--- 6 ---help---
7 This allows you to use hardware switch chips that use 7 This allows you to use hardware switch chips that use
diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
index 6d0bd198af19..be04d46110fe 100644
--- a/net/mac80211/rate.c
+++ b/net/mac80211/rate.c
@@ -103,6 +103,7 @@ ieee80211_rate_control_ops_get(const char *name)
103 struct rate_control_ops *ops; 103 struct rate_control_ops *ops;
104 const char *alg_name; 104 const char *alg_name;
105 105
106 kparam_block_sysfs_write(ieee80211_default_rc_algo);
106 if (!name) 107 if (!name)
107 alg_name = ieee80211_default_rc_algo; 108 alg_name = ieee80211_default_rc_algo;
108 else 109 else
@@ -120,6 +121,7 @@ ieee80211_rate_control_ops_get(const char *name)
120 /* try built-in one if specific alg requested but not found */ 121 /* try built-in one if specific alg requested but not found */
121 if (!ops && strlen(CONFIG_MAC80211_RC_DEFAULT)) 122 if (!ops && strlen(CONFIG_MAC80211_RC_DEFAULT))
122 ops = ieee80211_try_rate_control_ops_get(CONFIG_MAC80211_RC_DEFAULT); 123 ops = ieee80211_try_rate_control_ops_get(CONFIG_MAC80211_RC_DEFAULT);
124 kparam_unblock_sysfs_write(ieee80211_default_rc_algo);
123 125
124 return ops; 126 return ops;
125} 127}
diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index 7043b294bb67..8e22bd345e71 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -597,12 +597,6 @@ extern unsigned rxrpc_debug;
597#define dbgprintk(FMT,...) \ 597#define dbgprintk(FMT,...) \
598 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 598 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
599 599
600/* make sure we maintain the format strings, even when debugging is disabled */
601static inline __attribute__((format(printf,1,2)))
602void _dbprintk(const char *fmt, ...)
603{
604}
605
606#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 600#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
607#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 601#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
608#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 602#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
@@ -655,11 +649,11 @@ do { \
655} while (0) 649} while (0)
656 650
657#else 651#else
658#define _enter(FMT,...) _dbprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 652#define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
659#define _leave(FMT,...) _dbprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 653#define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
660#define _debug(FMT,...) _dbprintk(" "FMT ,##__VA_ARGS__) 654#define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
661#define _proto(FMT,...) _dbprintk("### "FMT ,##__VA_ARGS__) 655#define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__)
662#define _net(FMT,...) _dbprintk("@@@ "FMT ,##__VA_ARGS__) 656#define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__)
663#endif 657#endif
664 658
665/* 659/*
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index b9e8c3b7d406..408eea7086aa 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -150,22 +150,34 @@ int register_qdisc(struct Qdisc_ops *qops)
150 if (qops->enqueue == NULL) 150 if (qops->enqueue == NULL)
151 qops->enqueue = noop_qdisc_ops.enqueue; 151 qops->enqueue = noop_qdisc_ops.enqueue;
152 if (qops->peek == NULL) { 152 if (qops->peek == NULL) {
153 if (qops->dequeue == NULL) { 153 if (qops->dequeue == NULL)
154 qops->peek = noop_qdisc_ops.peek; 154 qops->peek = noop_qdisc_ops.peek;
155 } else { 155 else
156 rc = -EINVAL; 156 goto out_einval;
157 goto out;
158 }
159 } 157 }
160 if (qops->dequeue == NULL) 158 if (qops->dequeue == NULL)
161 qops->dequeue = noop_qdisc_ops.dequeue; 159 qops->dequeue = noop_qdisc_ops.dequeue;
162 160
161 if (qops->cl_ops) {
162 const struct Qdisc_class_ops *cops = qops->cl_ops;
163
164 if (!(cops->get && cops->put && cops->walk && cops->leaf))
165 goto out_einval;
166
167 if (cops->tcf_chain && !(cops->bind_tcf && cops->unbind_tcf))
168 goto out_einval;
169 }
170
163 qops->next = NULL; 171 qops->next = NULL;
164 *qp = qops; 172 *qp = qops;
165 rc = 0; 173 rc = 0;
166out: 174out:
167 write_unlock(&qdisc_mod_lock); 175 write_unlock(&qdisc_mod_lock);
168 return rc; 176 return rc;
177
178out_einval:
179 rc = -EINVAL;
180 goto out;
169} 181}
170EXPORT_SYMBOL(register_qdisc); 182EXPORT_SYMBOL(register_qdisc);
171 183
diff --git a/net/sched/sch_atm.c b/net/sched/sch_atm.c
index e114f23d5eae..340662789529 100644
--- a/net/sched/sch_atm.c
+++ b/net/sched/sch_atm.c
@@ -418,7 +418,7 @@ static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
418 } 418 }
419 419
420 ret = qdisc_enqueue(skb, flow->q); 420 ret = qdisc_enqueue(skb, flow->q);
421 if (ret != 0) { 421 if (ret != NET_XMIT_SUCCESS) {
422drop: __maybe_unused 422drop: __maybe_unused
423 if (net_xmit_drop_count(ret)) { 423 if (net_xmit_drop_count(ret)) {
424 sch->qstats.drops++; 424 sch->qstats.drops++;
@@ -442,7 +442,7 @@ drop: __maybe_unused
442 */ 442 */
443 if (flow == &p->link) { 443 if (flow == &p->link) {
444 sch->q.qlen++; 444 sch->q.qlen++;
445 return 0; 445 return NET_XMIT_SUCCESS;
446 } 446 }
447 tasklet_schedule(&p->task); 447 tasklet_schedule(&p->task);
448 return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; 448 return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c
index 534f33231c17..201cbac2b32c 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -334,7 +334,7 @@ sfq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
334 if (++sch->q.qlen <= q->limit) { 334 if (++sch->q.qlen <= q->limit) {
335 sch->bstats.bytes += qdisc_pkt_len(skb); 335 sch->bstats.bytes += qdisc_pkt_len(skb);
336 sch->bstats.packets++; 336 sch->bstats.packets++;
337 return 0; 337 return NET_XMIT_SUCCESS;
338 } 338 }
339 339
340 sfq_drop(sch); 340 sfq_drop(sch);
@@ -508,6 +508,11 @@ nla_put_failure:
508 return -1; 508 return -1;
509} 509}
510 510
511static struct Qdisc *sfq_leaf(struct Qdisc *sch, unsigned long arg)
512{
513 return NULL;
514}
515
511static unsigned long sfq_get(struct Qdisc *sch, u32 classid) 516static unsigned long sfq_get(struct Qdisc *sch, u32 classid)
512{ 517{
513 return 0; 518 return 0;
@@ -519,6 +524,10 @@ static unsigned long sfq_bind(struct Qdisc *sch, unsigned long parent,
519 return 0; 524 return 0;
520} 525}
521 526
527static void sfq_put(struct Qdisc *q, unsigned long cl)
528{
529}
530
522static struct tcf_proto **sfq_find_tcf(struct Qdisc *sch, unsigned long cl) 531static struct tcf_proto **sfq_find_tcf(struct Qdisc *sch, unsigned long cl)
523{ 532{
524 struct sfq_sched_data *q = qdisc_priv(sch); 533 struct sfq_sched_data *q = qdisc_priv(sch);
@@ -571,9 +580,12 @@ static void sfq_walk(struct Qdisc *sch, struct qdisc_walker *arg)
571} 580}
572 581
573static const struct Qdisc_class_ops sfq_class_ops = { 582static const struct Qdisc_class_ops sfq_class_ops = {
583 .leaf = sfq_leaf,
574 .get = sfq_get, 584 .get = sfq_get,
585 .put = sfq_put,
575 .tcf_chain = sfq_find_tcf, 586 .tcf_chain = sfq_find_tcf,
576 .bind_tcf = sfq_bind, 587 .bind_tcf = sfq_bind,
588 .unbind_tcf = sfq_put,
577 .dump = sfq_dump_class, 589 .dump = sfq_dump_class,
578 .dump_stats = sfq_dump_class_stats, 590 .dump_stats = sfq_dump_class_stats,
579 .walk = sfq_walk, 591 .walk = sfq_walk,
diff --git a/net/sched/sch_tbf.c b/net/sched/sch_tbf.c
index 0991c640cd3e..641a30d64635 100644
--- a/net/sched/sch_tbf.c
+++ b/net/sched/sch_tbf.c
@@ -127,7 +127,7 @@ static int tbf_enqueue(struct sk_buff *skb, struct Qdisc* sch)
127 return qdisc_reshape_fail(skb, sch); 127 return qdisc_reshape_fail(skb, sch);
128 128
129 ret = qdisc_enqueue(skb, q->qdisc); 129 ret = qdisc_enqueue(skb, q->qdisc);
130 if (ret != 0) { 130 if (ret != NET_XMIT_SUCCESS) {
131 if (net_xmit_drop_count(ret)) 131 if (net_xmit_drop_count(ret))
132 sch->qstats.drops++; 132 sch->qstats.drops++;
133 return ret; 133 return ret;
@@ -136,7 +136,7 @@ static int tbf_enqueue(struct sk_buff *skb, struct Qdisc* sch)
136 sch->q.qlen++; 136 sch->q.qlen++;
137 sch->bstats.bytes += qdisc_pkt_len(skb); 137 sch->bstats.bytes += qdisc_pkt_len(skb);
138 sch->bstats.packets++; 138 sch->bstats.packets++;
139 return 0; 139 return NET_XMIT_SUCCESS;
140} 140}
141 141
142static unsigned int tbf_drop(struct Qdisc* sch) 142static unsigned int tbf_drop(struct Qdisc* sch)
diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c
index 807643bdcbac..feaabc103ce6 100644
--- a/net/sched/sch_teql.c
+++ b/net/sched/sch_teql.c
@@ -85,7 +85,7 @@ teql_enqueue(struct sk_buff *skb, struct Qdisc* sch)
85 __skb_queue_tail(&q->q, skb); 85 __skb_queue_tail(&q->q, skb);
86 sch->bstats.bytes += qdisc_pkt_len(skb); 86 sch->bstats.bytes += qdisc_pkt_len(skb);
87 sch->bstats.packets++; 87 sch->bstats.packets++;
88 return 0; 88 return NET_XMIT_SUCCESS;
89 } 89 }
90 90
91 kfree_skb(skb); 91 kfree_skb(skb);
diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index 880d0de3f50f..36cb66022a27 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -39,7 +39,7 @@ static LIST_HEAD(cred_unused);
39static unsigned long number_cred_unused; 39static unsigned long number_cred_unused;
40 40
41#define MAX_HASHTABLE_BITS (10) 41#define MAX_HASHTABLE_BITS (10)
42static int param_set_hashtbl_sz(const char *val, struct kernel_param *kp) 42static int param_set_hashtbl_sz(const char *val, const struct kernel_param *kp)
43{ 43{
44 unsigned long num; 44 unsigned long num;
45 unsigned int nbits; 45 unsigned int nbits;
@@ -61,7 +61,7 @@ out_inval:
61 return -EINVAL; 61 return -EINVAL;
62} 62}
63 63
64static int param_get_hashtbl_sz(char *buffer, struct kernel_param *kp) 64static int param_get_hashtbl_sz(char *buffer, const struct kernel_param *kp)
65{ 65{
66 unsigned int nbits; 66 unsigned int nbits;
67 67
@@ -71,6 +71,11 @@ static int param_get_hashtbl_sz(char *buffer, struct kernel_param *kp)
71 71
72#define param_check_hashtbl_sz(name, p) __param_check(name, p, unsigned int); 72#define param_check_hashtbl_sz(name, p) __param_check(name, p, unsigned int);
73 73
74static struct kernel_param_ops param_ops_hashtbl_sz = {
75 .set = param_set_hashtbl_sz,
76 .get = param_get_hashtbl_sz,
77};
78
74module_param_named(auth_hashtable_size, auth_hashbits, hashtbl_sz, 0644); 79module_param_named(auth_hashtable_size, auth_hashbits, hashtbl_sz, 0644);
75MODULE_PARM_DESC(auth_hashtable_size, "RPC credential cache hashtable size"); 80MODULE_PARM_DESC(auth_hashtable_size, "RPC credential cache hashtable size");
76 81
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 7ca65c7005ea..49a62f0c4b87 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -2577,7 +2577,8 @@ void cleanup_socket_xprt(void)
2577 xprt_unregister_transport(&xs_bc_tcp_transport); 2577 xprt_unregister_transport(&xs_bc_tcp_transport);
2578} 2578}
2579 2579
2580static int param_set_uint_minmax(const char *val, struct kernel_param *kp, 2580static int param_set_uint_minmax(const char *val,
2581 const struct kernel_param *kp,
2581 unsigned int min, unsigned int max) 2582 unsigned int min, unsigned int max)
2582{ 2583{
2583 unsigned long num; 2584 unsigned long num;
@@ -2592,34 +2593,37 @@ static int param_set_uint_minmax(const char *val, struct kernel_param *kp,
2592 return 0; 2593 return 0;
2593} 2594}
2594 2595
2595static int param_set_portnr(const char *val, struct kernel_param *kp) 2596static int param_set_portnr(const char *val, const struct kernel_param *kp)
2596{ 2597{
2597 return param_set_uint_minmax(val, kp, 2598 return param_set_uint_minmax(val, kp,
2598 RPC_MIN_RESVPORT, 2599 RPC_MIN_RESVPORT,
2599 RPC_MAX_RESVPORT); 2600 RPC_MAX_RESVPORT);
2600} 2601}
2601 2602
2602static int param_get_portnr(char *buffer, struct kernel_param *kp) 2603static struct kernel_param_ops param_ops_portnr = {
2603{ 2604 .set = param_set_portnr,
2604 return param_get_uint(buffer, kp); 2605 .get = param_get_uint,
2605} 2606};
2607
2606#define param_check_portnr(name, p) \ 2608#define param_check_portnr(name, p) \
2607 __param_check(name, p, unsigned int); 2609 __param_check(name, p, unsigned int);
2608 2610
2609module_param_named(min_resvport, xprt_min_resvport, portnr, 0644); 2611module_param_named(min_resvport, xprt_min_resvport, portnr, 0644);
2610module_param_named(max_resvport, xprt_max_resvport, portnr, 0644); 2612module_param_named(max_resvport, xprt_max_resvport, portnr, 0644);
2611 2613
2612static int param_set_slot_table_size(const char *val, struct kernel_param *kp) 2614static int param_set_slot_table_size(const char *val,
2615 const struct kernel_param *kp)
2613{ 2616{
2614 return param_set_uint_minmax(val, kp, 2617 return param_set_uint_minmax(val, kp,
2615 RPC_MIN_SLOT_TABLE, 2618 RPC_MIN_SLOT_TABLE,
2616 RPC_MAX_SLOT_TABLE); 2619 RPC_MAX_SLOT_TABLE);
2617} 2620}
2618 2621
2619static int param_get_slot_table_size(char *buffer, struct kernel_param *kp) 2622static struct kernel_param_ops param_ops_slot_table_size = {
2620{ 2623 .set = param_set_slot_table_size,
2621 return param_get_uint(buffer, kp); 2624 .get = param_get_uint,
2622} 2625};
2626
2623#define param_check_slot_table_size(name, p) \ 2627#define param_check_slot_table_size(name, p) \
2624 __param_check(name, p, unsigned int); 2628 __param_check(name, p, unsigned int);
2625 2629
diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c
index e74a1a2119d3..d1a3fb99fdf2 100644
--- a/net/wireless/mlme.c
+++ b/net/wireless/mlme.c
@@ -843,13 +843,19 @@ int cfg80211_mlme_action(struct cfg80211_registered_device *rdev,
843 return -EINVAL; 843 return -EINVAL;
844 if (mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) { 844 if (mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) {
845 /* Verify that we are associated with the destination AP */ 845 /* Verify that we are associated with the destination AP */
846 wdev_lock(wdev);
847
846 if (!wdev->current_bss || 848 if (!wdev->current_bss ||
847 memcmp(wdev->current_bss->pub.bssid, mgmt->bssid, 849 memcmp(wdev->current_bss->pub.bssid, mgmt->bssid,
848 ETH_ALEN) != 0 || 850 ETH_ALEN) != 0 ||
849 (wdev->iftype == NL80211_IFTYPE_STATION && 851 (wdev->iftype == NL80211_IFTYPE_STATION &&
850 memcmp(wdev->current_bss->pub.bssid, mgmt->da, 852 memcmp(wdev->current_bss->pub.bssid, mgmt->da,
851 ETH_ALEN) != 0)) 853 ETH_ALEN) != 0)) {
854 wdev_unlock(wdev);
852 return -ENOTCONN; 855 return -ENOTCONN;
856 }
857
858 wdev_unlock(wdev);
853 } 859 }
854 860
855 if (memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0) 861 if (memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0)
diff --git a/samples/Kconfig b/samples/Kconfig
index 8924f72f0629..954a1d550c5f 100644
--- a/samples/Kconfig
+++ b/samples/Kconfig
@@ -44,4 +44,14 @@ config SAMPLE_HW_BREAKPOINT
44 help 44 help
45 This builds kernel hardware breakpoint example modules. 45 This builds kernel hardware breakpoint example modules.
46 46
47config SAMPLE_KFIFO
48 tristate "Build kfifo examples -- loadable modules only"
49 depends on m
50 help
51 This config option will allow you to build a number of
52 different kfifo sample modules showing how to use the
53 generic kfifo API.
54
55 If in doubt, say "N" here.
56
47endif # SAMPLES 57endif # SAMPLES
diff --git a/samples/Makefile b/samples/Makefile
index 0f15e6d77fd6..76b3c3455c29 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -1,4 +1,4 @@
1# Makefile for Linux samples code 1# Makefile for Linux samples code
2 2
3obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ tracepoints/ trace_events/ \ 3obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ tracepoints/ trace_events/ \
4 hw_breakpoint/ 4 hw_breakpoint/ kfifo/
diff --git a/samples/kfifo/Makefile b/samples/kfifo/Makefile
new file mode 100644
index 000000000000..bcc9484a15b2
--- /dev/null
+++ b/samples/kfifo/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_SAMPLE_KFIFO) += bytestream-example.o dma-example.o inttype-example.o record-example.o
diff --git a/samples/kfifo/bytestream-example.c b/samples/kfifo/bytestream-example.c
new file mode 100644
index 000000000000..642eef3f6336
--- /dev/null
+++ b/samples/kfifo/bytestream-example.c
@@ -0,0 +1,163 @@
1/*
2 * Sample kfifo byte stream implementation
3 *
4 * Copyright (C) 2010 Stefani Seibold <stefani@seibold.net>
5 *
6 * Released under the GPL version 2 only.
7 *
8 */
9
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/proc_fs.h>
13#include <linux/mutex.h>
14#include <linux/kfifo.h>
15
16/*
17 * This module shows how to create a byte stream fifo.
18 */
19
20/* fifo size in elements (bytes) */
21#define FIFO_SIZE 32
22
23/* name of the proc entry */
24#define PROC_FIFO "bytestream-fifo"
25
26/* lock for procfs read access */
27static DEFINE_MUTEX(read_lock);
28
29/* lock for procfs write access */
30static DEFINE_MUTEX(write_lock);
31
32/*
33 * define DYNAMIC in this example for a dynamically allocated fifo.
34 *
35 * Otherwise the fifo storage will be a part of the fifo structure.
36 */
37#if 0
38#define DYNAMIC
39#endif
40
41#ifdef DYNAMIC
42static struct kfifo test;
43#else
44static DECLARE_KFIFO(test, unsigned char, FIFO_SIZE);
45#endif
46
47static int __init testfunc(void)
48{
49 unsigned char buf[6];
50 unsigned char i;
51 unsigned int ret;
52
53 printk(KERN_INFO "byte stream fifo test start\n");
54
55 /* put string into the fifo */
56 kfifo_in(&test, "hello", 5);
57
58 /* put values into the fifo */
59 for (i = 0; i != 10; i++)
60 kfifo_put(&test, &i);
61
62 /* show the number of used elements */
63 printk(KERN_INFO "fifo len: %u\n", kfifo_len(&test));
64
65 /* get max of 5 bytes from the fifo */
66 i = kfifo_out(&test, buf, 5);
67 printk(KERN_INFO "buf: %.*s\n", i, buf);
68
69 /* get max of 2 elements from the fifo */
70 ret = kfifo_out(&test, buf, 2);
71 printk(KERN_INFO "ret: %d\n", ret);
72 /* and put it back to the end of the fifo */
73 ret = kfifo_in(&test, buf, ret);
74 printk(KERN_INFO "ret: %d\n", ret);
75
76 /* put values into the fifo until is full */
77 for (i = 20; kfifo_put(&test, &i); i++)
78 ;
79
80 printk(KERN_INFO "queue len: %u\n", kfifo_len(&test));
81
82 /* print out all values in the fifo */
83 while (kfifo_get(&test, &i))
84 printk("%d ", i);
85 printk("\n");
86
87 return 0;
88}
89
90static ssize_t fifo_write(struct file *file, const char __user *buf,
91 size_t count, loff_t *ppos)
92{
93 int ret;
94 unsigned int copied;
95
96 if (mutex_lock_interruptible(&write_lock))
97 return -ERESTARTSYS;
98
99 ret = kfifo_from_user(&test, buf, count, &copied);
100
101 mutex_unlock(&write_lock);
102
103 return ret ? ret : copied;
104}
105
106static ssize_t fifo_read(struct file *file, char __user *buf,
107 size_t count, loff_t *ppos)
108{
109 int ret;
110 unsigned int copied;
111
112 if (mutex_lock_interruptible(&read_lock))
113 return -ERESTARTSYS;
114
115 ret = kfifo_to_user(&test, buf, count, &copied);
116
117 mutex_unlock(&read_lock);
118
119 return ret ? ret : copied;
120}
121
122static const struct file_operations fifo_fops = {
123 .owner = THIS_MODULE,
124 .read = fifo_read,
125 .write = fifo_write,
126};
127
128static int __init example_init(void)
129{
130#ifdef DYNAMIC
131 int ret;
132
133 ret = kfifo_alloc(&test, FIFO_SIZE, GFP_KERNEL);
134 if (ret) {
135 printk(KERN_ERR "error kfifo_alloc\n");
136 return ret;
137 }
138#else
139 INIT_KFIFO(test);
140#endif
141 testfunc();
142
143 if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) {
144#ifdef DYNAMIC
145 kfifo_free(&test);
146#endif
147 return -ENOMEM;
148 }
149 return 0;
150}
151
152static void __exit example_exit(void)
153{
154 remove_proc_entry(PROC_FIFO, NULL);
155#ifdef DYNAMIC
156 kfifo_free(&test);
157#endif
158}
159
160module_init(example_init);
161module_exit(example_exit);
162MODULE_LICENSE("GPL");
163MODULE_AUTHOR("Stefani Seibold <stefani@seibold.net>");
diff --git a/samples/kfifo/dma-example.c b/samples/kfifo/dma-example.c
new file mode 100644
index 000000000000..b9482c28b41a
--- /dev/null
+++ b/samples/kfifo/dma-example.c
@@ -0,0 +1,115 @@
1/*
2 * Sample fifo dma implementation
3 *
4 * Copyright (C) 2010 Stefani Seibold <stefani@seibold.net>
5 *
6 * Released under the GPL version 2 only.
7 *
8 */
9
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/kfifo.h>
13
14/*
15 * This module shows how to handle fifo dma operations.
16 */
17
18/* fifo size in elements (bytes) */
19#define FIFO_SIZE 32
20
21static struct kfifo fifo;
22
23static int __init example_init(void)
24{
25 int i;
26 unsigned int ret;
27 struct scatterlist sg[10];
28
29 printk(KERN_INFO "DMA fifo test start\n");
30
31 if (kfifo_alloc(&fifo, FIFO_SIZE, GFP_KERNEL)) {
32 printk(KERN_ERR "error kfifo_alloc\n");
33 return 1;
34 }
35
36 printk(KERN_INFO "queue size: %u\n", kfifo_size(&fifo));
37
38 kfifo_in(&fifo, "test", 4);
39
40 for (i = 0; i != 9; i++)
41 kfifo_put(&fifo, &i);
42
43 /* kick away first byte */
44 ret = kfifo_get(&fifo, &i);
45
46 printk(KERN_INFO "queue len: %u\n", kfifo_len(&fifo));
47
48 ret = kfifo_dma_in_prepare(&fifo, sg, ARRAY_SIZE(sg), FIFO_SIZE);
49 printk(KERN_INFO "DMA sgl entries: %d\n", ret);
50
51 /* if 0 was returned, fifo is full and no sgl was created */
52 if (ret) {
53 printk(KERN_INFO "scatterlist for receive:\n");
54 for (i = 0; i < ARRAY_SIZE(sg); i++) {
55 printk(KERN_INFO
56 "sg[%d] -> "
57 "page_link 0x%.8lx offset 0x%.8x length 0x%.8x\n",
58 i, sg[i].page_link, sg[i].offset, sg[i].length);
59
60 if (sg_is_last(&sg[i]))
61 break;
62 }
63
64 /* but here your code to setup and exectute the dma operation */
65 /* ... */
66
67 /* example: zero bytes received */
68 ret = 0;
69
70 /* finish the dma operation and update the received data */
71 kfifo_dma_in_finish(&fifo, ret);
72 }
73
74 ret = kfifo_dma_out_prepare(&fifo, sg, ARRAY_SIZE(sg), 8);
75 printk(KERN_INFO "DMA sgl entries: %d\n", ret);
76
77 /* if 0 was returned, no data was available and no sgl was created */
78 if (ret) {
79 printk(KERN_INFO "scatterlist for transmit:\n");
80 for (i = 0; i < ARRAY_SIZE(sg); i++) {
81 printk(KERN_INFO
82 "sg[%d] -> "
83 "page_link 0x%.8lx offset 0x%.8x length 0x%.8x\n",
84 i, sg[i].page_link, sg[i].offset, sg[i].length);
85
86 if (sg_is_last(&sg[i]))
87 break;
88 }
89
90 /* but here your code to setup and exectute the dma operation */
91 /* ... */
92
93 /* example: 5 bytes transmitted */
94 ret = 5;
95
96 /* finish the dma operation and update the transmitted data */
97 kfifo_dma_out_finish(&fifo, ret);
98 }
99
100 printk(KERN_INFO "queue len: %u\n", kfifo_len(&fifo));
101
102 return 0;
103}
104
105static void __exit example_exit(void)
106{
107#ifdef DYNAMIC
108 kfifo_free(&test);
109#endif
110}
111
112module_init(example_init);
113module_exit(example_exit);
114MODULE_LICENSE("GPL");
115MODULE_AUTHOR("Stefani Seibold <stefani@seibold.net>");
diff --git a/samples/kfifo/inttype-example.c b/samples/kfifo/inttype-example.c
new file mode 100644
index 000000000000..d6c5b7d9df64
--- /dev/null
+++ b/samples/kfifo/inttype-example.c
@@ -0,0 +1,157 @@
1/*
2 * Sample kfifo int type implementation
3 *
4 * Copyright (C) 2010 Stefani Seibold <stefani@seibold.net>
5 *
6 * Released under the GPL version 2 only.
7 *
8 */
9
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/proc_fs.h>
13#include <linux/mutex.h>
14#include <linux/kfifo.h>
15
16/*
17 * This module shows how to create a int type fifo.
18 */
19
20/* fifo size in elements (ints) */
21#define FIFO_SIZE 32
22
23/* name of the proc entry */
24#define PROC_FIFO "int-fifo"
25
26/* lock for procfs read access */
27static DEFINE_MUTEX(read_lock);
28
29/* lock for procfs write access */
30static DEFINE_MUTEX(write_lock);
31
32/*
33 * define DYNAMIC in this example for a dynamically allocated fifo.
34 *
35 * Otherwise the fifo storage will be a part of the fifo structure.
36 */
37#if 0
38#define DYNAMIC
39#endif
40
41#ifdef DYNAMIC
42static DECLARE_KFIFO_PTR(test, int);
43#else
44static DEFINE_KFIFO(test, int, FIFO_SIZE);
45#endif
46
47static int __init testfunc(void)
48{
49 int buf[6];
50 int i;
51 unsigned int ret;
52
53 printk(KERN_INFO "int fifo test start\n");
54
55 /* put values into the fifo */
56 for (i = 0; i != 10; i++)
57 kfifo_put(&test, &i);
58
59 /* show the number of used elements */
60 printk(KERN_INFO "fifo len: %u\n", kfifo_len(&test));
61
62 /* get max of 2 elements from the fifo */
63 ret = kfifo_out(&test, buf, 2);
64 printk(KERN_INFO "ret: %d\n", ret);
65 /* and put it back to the end of the fifo */
66 ret = kfifo_in(&test, buf, ret);
67 printk(KERN_INFO "ret: %d\n", ret);
68
69 for (i = 20; i != 30; i++)
70 kfifo_put(&test, &i);
71
72 printk(KERN_INFO "queue len: %u\n", kfifo_len(&test));
73
74 /* show the first value without removing from the fifo */
75 if (kfifo_peek(&test, &i))
76 printk(KERN_INFO "%d\n", i);
77
78 /* print out all values in the fifo */
79 while (kfifo_get(&test, &i))
80 printk("%d ", i);
81 printk("\n");
82
83 return 0;
84}
85
86static ssize_t fifo_write(struct file *file, const char __user *buf,
87 size_t count, loff_t *ppos)
88{
89 int ret;
90 unsigned int copied;
91
92 if (mutex_lock_interruptible(&write_lock))
93 return -ERESTARTSYS;
94
95 ret = kfifo_from_user(&test, buf, count, &copied);
96
97 mutex_unlock(&write_lock);
98
99 return ret ? ret : copied;
100}
101
102static ssize_t fifo_read(struct file *file, char __user *buf,
103 size_t count, loff_t *ppos)
104{
105 int ret;
106 unsigned int copied;
107
108 if (mutex_lock_interruptible(&read_lock))
109 return -ERESTARTSYS;
110
111 ret = kfifo_to_user(&test, buf, count, &copied);
112
113 mutex_unlock(&read_lock);
114
115 return ret ? ret : copied;
116}
117
118static const struct file_operations fifo_fops = {
119 .owner = THIS_MODULE,
120 .read = fifo_read,
121 .write = fifo_write,
122};
123
124static int __init example_init(void)
125{
126#ifdef DYNAMIC
127 int ret;
128
129 ret = kfifo_alloc(&test, FIFO_SIZE, GFP_KERNEL);
130 if (ret) {
131 printk(KERN_ERR "error kfifo_alloc\n");
132 return ret;
133 }
134#endif
135 testfunc();
136
137 if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) {
138#ifdef DYNAMIC
139 kfifo_free(&test);
140#endif
141 return -ENOMEM;
142 }
143 return 0;
144}
145
146static void __exit example_exit(void)
147{
148 remove_proc_entry(PROC_FIFO, NULL);
149#ifdef DYNAMIC
150 kfifo_free(&test);
151#endif
152}
153
154module_init(example_init);
155module_exit(example_exit);
156MODULE_LICENSE("GPL");
157MODULE_AUTHOR("Stefani Seibold <stefani@seibold.net>");
diff --git a/samples/kfifo/record-example.c b/samples/kfifo/record-example.c
new file mode 100644
index 000000000000..32c6e0bda744
--- /dev/null
+++ b/samples/kfifo/record-example.c
@@ -0,0 +1,167 @@
1/*
2 * Sample dynamic sized record fifo implementation
3 *
4 * Copyright (C) 2010 Stefani Seibold <stefani@seibold.net>
5 *
6 * Released under the GPL version 2 only.
7 *
8 */
9
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/proc_fs.h>
13#include <linux/mutex.h>
14#include <linux/kfifo.h>
15
16/*
17 * This module shows how to create a variable sized record fifo.
18 */
19
20/* fifo size in elements (bytes) */
21#define FIFO_SIZE 128
22
23/* name of the proc entry */
24#define PROC_FIFO "record-fifo"
25
26/* lock for procfs read access */
27static DEFINE_MUTEX(read_lock);
28
29/* lock for procfs write access */
30static DEFINE_MUTEX(write_lock);
31
32/*
33 * define DYNAMIC in this example for a dynamically allocated fifo.
34 *
35 * Otherwise the fifo storage will be a part of the fifo structure.
36 */
37#if 0
38#define DYNAMIC
39#endif
40
41/*
42 * struct kfifo_rec_ptr_1 and STRUCT_KFIFO_REC_1 can handle records of a
43 * length between 0 and 255 bytes.
44 *
45 * struct kfifo_rec_ptr_2 and STRUCT_KFIFO_REC_2 can handle records of a
46 * length between 0 and 65535 bytes.
47 */
48
49#ifdef DYNAMIC
50struct kfifo_rec_ptr_1 test;
51
52#else
53typedef STRUCT_KFIFO_REC_1(FIFO_SIZE) mytest;
54
55static mytest test;
56#endif
57
58static int __init testfunc(void)
59{
60 char buf[100];
61 unsigned int i;
62 unsigned int ret;
63 struct { unsigned char buf[6]; } hello = { "hello" };
64
65 printk(KERN_INFO "record fifo test start\n");
66
67 kfifo_in(&test, &hello, sizeof(hello));
68
69 /* show the size of the next record in the fifo */
70 printk(KERN_INFO "fifo peek len: %u\n", kfifo_peek_len(&test));
71
72 /* put in variable length data */
73 for (i = 0; i < 10; i++) {
74 memset(buf, 'a' + i, i + 1);
75 kfifo_in(&test, buf, i + 1);
76 }
77
78 printk(KERN_INFO "fifo len: %u\n", kfifo_len(&test));
79
80 /* show the first record without removing from the fifo */
81 ret = kfifo_out_peek(&test, buf, sizeof(buf));
82 if (ret)
83 printk(KERN_INFO "%.*s\n", ret, buf);
84
85 /* print out all records in the fifo */
86 while (!kfifo_is_empty(&test)) {
87 ret = kfifo_out(&test, buf, sizeof(buf));
88 printk(KERN_INFO "%.*s\n", ret, buf);
89 }
90
91 return 0;
92}
93
94static ssize_t fifo_write(struct file *file, const char __user *buf,
95 size_t count, loff_t *ppos)
96{
97 int ret;
98 unsigned int copied;
99
100 if (mutex_lock_interruptible(&write_lock))
101 return -ERESTARTSYS;
102
103 ret = kfifo_from_user(&test, buf, count, &copied);
104
105 mutex_unlock(&write_lock);
106
107 return ret ? ret : copied;
108}
109
110static ssize_t fifo_read(struct file *file, char __user *buf,
111 size_t count, loff_t *ppos)
112{
113 int ret;
114 unsigned int copied;
115
116 if (mutex_lock_interruptible(&read_lock))
117 return -ERESTARTSYS;
118
119 ret = kfifo_to_user(&test, buf, count, &copied);
120
121 mutex_unlock(&read_lock);
122
123 return ret ? ret : copied;
124}
125
126static const struct file_operations fifo_fops = {
127 .owner = THIS_MODULE,
128 .read = fifo_read,
129 .write = fifo_write,
130};
131
132static int __init example_init(void)
133{
134#ifdef DYNAMIC
135 int ret;
136
137 ret = kfifo_alloc(&test, FIFO_SIZE, GFP_KERNEL);
138 if (ret) {
139 printk(KERN_ERR "error kfifo_alloc\n");
140 return ret;
141 }
142#else
143 INIT_KFIFO(test);
144#endif
145 testfunc();
146
147 if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) {
148#ifdef DYNAMIC
149 kfifo_free(&test);
150#endif
151 return -ENOMEM;
152 }
153 return 0;
154}
155
156static void __exit example_exit(void)
157{
158 remove_proc_entry(PROC_FIFO, NULL);
159#ifdef DYNAMIC
160 kfifo_free(&test);
161#endif
162}
163
164module_init(example_init);
165module_exit(example_exit);
166MODULE_LICENSE("GPL");
167MODULE_AUTHOR("Stefani Seibold <stefani@seibold.net>");
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index fcdfb245a575..102e1235fd5c 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -1454,6 +1454,8 @@ sub dump_enum($$) {
1454 my $file = shift; 1454 my $file = shift;
1455 1455
1456 $x =~ s@/\*.*?\*/@@gos; # strip comments. 1456 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1457 $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums
1458
1457 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 1459 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1458 $declaration_name = $1; 1460 $declaration_name = $1;
1459 my $members = $2; 1461 my $members = $2;
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 1ce655dde99e..1ec7158b6c1f 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -14,6 +14,7 @@
14#define _GNU_SOURCE 14#define _GNU_SOURCE
15#include <stdio.h> 15#include <stdio.h>
16#include <ctype.h> 16#include <ctype.h>
17#include <string.h>
17#include "modpost.h" 18#include "modpost.h"
18#include "../../include/generated/autoconf.h" 19#include "../../include/generated/autoconf.h"
19#include "../../include/linux/license.h" 20#include "../../include/linux/license.h"
@@ -789,6 +790,7 @@ static const char *section_white_list[] =
789{ 790{
790 ".comment*", 791 ".comment*",
791 ".debug*", 792 ".debug*",
793 ".GCC-command-line", /* mn10300 */
792 ".mdebug*", /* alpha, score, mips etc. */ 794 ".mdebug*", /* alpha, score, mips etc. */
793 ".pdr", /* alpha, score, mips etc. */ 795 ".pdr", /* alpha, score, mips etc. */
794 ".stab*", 796 ".stab*",
@@ -1033,6 +1035,13 @@ static const struct sectioncheck *section_mismatch(
1033 * fromsec = .data* 1035 * fromsec = .data*
1034 * atsym =__param* 1036 * atsym =__param*
1035 * 1037 *
1038 * Pattern 1a:
1039 * module_param_call() ops can refer to __init set function if permissions=0
1040 * The pattern is identified by:
1041 * tosec = .init.text
1042 * fromsec = .data*
1043 * atsym = __param_ops_*
1044 *
1036 * Pattern 2: 1045 * Pattern 2:
1037 * Many drivers utilise a *driver container with references to 1046 * Many drivers utilise a *driver container with references to
1038 * add, remove, probe functions etc. 1047 * add, remove, probe functions etc.
@@ -1067,6 +1076,12 @@ static int secref_whitelist(const struct sectioncheck *mismatch,
1067 (strncmp(fromsym, "__param", strlen("__param")) == 0)) 1076 (strncmp(fromsym, "__param", strlen("__param")) == 0))
1068 return 0; 1077 return 0;
1069 1078
1079 /* Check for pattern 1a */
1080 if (strcmp(tosec, ".init.text") == 0 &&
1081 match(fromsec, data_sections) &&
1082 (strncmp(fromsym, "__param_ops_", strlen("__param_ops_")) == 0))
1083 return 0;
1084
1070 /* Check for pattern 2 */ 1085 /* Check for pattern 2 */
1071 if (match(tosec, init_exit_sections) && 1086 if (match(tosec, init_exit_sections) &&
1072 match(fromsec, data_sections) && 1087 match(fromsec, data_sections) &&
@@ -1217,7 +1232,7 @@ static char *sec2annotation(const char *s)
1217 strcat(p, " "); 1232 strcat(p, " ");
1218 return r; /* we leak her but we do not care */ 1233 return r; /* we leak her but we do not care */
1219 } else { 1234 } else {
1220 return ""; 1235 return strdup("");
1221 } 1236 }
1222} 1237}
1223 1238
@@ -1352,7 +1367,7 @@ static void report_sec_mismatch(const char *modname,
1352 "%s%s so it may be used outside an exit section.\n", 1367 "%s%s so it may be used outside an exit section.\n",
1353 from, prl_from, fromsym, from_p, 1368 from, prl_from, fromsym, from_p,
1354 to, prl_to, tosym, to_p, 1369 to, prl_to, tosym, to_p,
1355 sec2annotation(tosec), tosym, to_p); 1370 prl_to, tosym, to_p);
1356 free(prl_from); 1371 free(prl_from);
1357 free(prl_to); 1372 free(prl_to);
1358 break; 1373 break;
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index 8db33a8b50c4..d5666d3cc21b 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -667,17 +667,29 @@ static struct security_operations apparmor_ops = {
667 * AppArmor sysfs module parameters 667 * AppArmor sysfs module parameters
668 */ 668 */
669 669
670static int param_set_aabool(const char *val, struct kernel_param *kp); 670static int param_set_aabool(const char *val, const struct kernel_param *kp);
671static int param_get_aabool(char *buffer, struct kernel_param *kp); 671static int param_get_aabool(char *buffer, const struct kernel_param *kp);
672#define param_check_aabool(name, p) __param_check(name, p, int) 672#define param_check_aabool(name, p) __param_check(name, p, int)
673static struct kernel_param_ops param_ops_aabool = {
674 .set = param_set_aabool,
675 .get = param_get_aabool
676};
673 677
674static int param_set_aauint(const char *val, struct kernel_param *kp); 678static int param_set_aauint(const char *val, const struct kernel_param *kp);
675static int param_get_aauint(char *buffer, struct kernel_param *kp); 679static int param_get_aauint(char *buffer, const struct kernel_param *kp);
676#define param_check_aauint(name, p) __param_check(name, p, int) 680#define param_check_aauint(name, p) __param_check(name, p, int)
681static struct kernel_param_ops param_ops_aauint = {
682 .set = param_set_aauint,
683 .get = param_get_aauint
684};
677 685
678static int param_set_aalockpolicy(const char *val, struct kernel_param *kp); 686static int param_set_aalockpolicy(const char *val, const struct kernel_param *kp);
679static int param_get_aalockpolicy(char *buffer, struct kernel_param *kp); 687static int param_get_aalockpolicy(char *buffer, const struct kernel_param *kp);
680#define param_check_aalockpolicy(name, p) __param_check(name, p, int) 688#define param_check_aalockpolicy(name, p) __param_check(name, p, int)
689static struct kernel_param_ops param_ops_aalockpolicy = {
690 .set = param_set_aalockpolicy,
691 .get = param_get_aalockpolicy
692};
681 693
682static int param_set_audit(const char *val, struct kernel_param *kp); 694static int param_set_audit(const char *val, struct kernel_param *kp);
683static int param_get_audit(char *buffer, struct kernel_param *kp); 695static int param_get_audit(char *buffer, struct kernel_param *kp);
@@ -751,7 +763,7 @@ static int __init apparmor_enabled_setup(char *str)
751__setup("apparmor=", apparmor_enabled_setup); 763__setup("apparmor=", apparmor_enabled_setup);
752 764
753/* set global flag turning off the ability to load policy */ 765/* set global flag turning off the ability to load policy */
754static int param_set_aalockpolicy(const char *val, struct kernel_param *kp) 766static int param_set_aalockpolicy(const char *val, const struct kernel_param *kp)
755{ 767{
756 if (!capable(CAP_MAC_ADMIN)) 768 if (!capable(CAP_MAC_ADMIN))
757 return -EPERM; 769 return -EPERM;
@@ -760,35 +772,35 @@ static int param_set_aalockpolicy(const char *val, struct kernel_param *kp)
760 return param_set_bool(val, kp); 772 return param_set_bool(val, kp);
761} 773}
762 774
763static int param_get_aalockpolicy(char *buffer, struct kernel_param *kp) 775static int param_get_aalockpolicy(char *buffer, const struct kernel_param *kp)
764{ 776{
765 if (!capable(CAP_MAC_ADMIN)) 777 if (!capable(CAP_MAC_ADMIN))
766 return -EPERM; 778 return -EPERM;
767 return param_get_bool(buffer, kp); 779 return param_get_bool(buffer, kp);
768} 780}
769 781
770static int param_set_aabool(const char *val, struct kernel_param *kp) 782static int param_set_aabool(const char *val, const struct kernel_param *kp)
771{ 783{
772 if (!capable(CAP_MAC_ADMIN)) 784 if (!capable(CAP_MAC_ADMIN))
773 return -EPERM; 785 return -EPERM;
774 return param_set_bool(val, kp); 786 return param_set_bool(val, kp);
775} 787}
776 788
777static int param_get_aabool(char *buffer, struct kernel_param *kp) 789static int param_get_aabool(char *buffer, const struct kernel_param *kp)
778{ 790{
779 if (!capable(CAP_MAC_ADMIN)) 791 if (!capable(CAP_MAC_ADMIN))
780 return -EPERM; 792 return -EPERM;
781 return param_get_bool(buffer, kp); 793 return param_get_bool(buffer, kp);
782} 794}
783 795
784static int param_set_aauint(const char *val, struct kernel_param *kp) 796static int param_set_aauint(const char *val, const struct kernel_param *kp)
785{ 797{
786 if (!capable(CAP_MAC_ADMIN)) 798 if (!capable(CAP_MAC_ADMIN))
787 return -EPERM; 799 return -EPERM;
788 return param_set_uint(val, kp); 800 return param_set_uint(val, kp);
789} 801}
790 802
791static int param_get_aauint(char *buffer, struct kernel_param *kp) 803static int param_get_aauint(char *buffer, const struct kernel_param *kp)
792{ 804{
793 if (!capable(CAP_MAC_ADMIN)) 805 if (!capable(CAP_MAC_ADMIN))
794 return -EPERM; 806 return -EPERM;
diff --git a/security/keys/internal.h b/security/keys/internal.h
index addb67b169f4..56a133d8f37d 100644
--- a/security/keys/internal.h
+++ b/security/keys/internal.h
@@ -15,11 +15,6 @@
15#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/key-type.h> 16#include <linux/key-type.h>
17 17
18static inline __attribute__((format(printf, 1, 2)))
19void no_printk(const char *fmt, ...)
20{
21}
22
23#ifdef __KDEBUG 18#ifdef __KDEBUG
24#define kenter(FMT, ...) \ 19#define kenter(FMT, ...) \
25 printk(KERN_DEBUG "==> %s("FMT")\n", __func__, ##__VA_ARGS__) 20 printk(KERN_DEBUG "==> %s("FMT")\n", __func__, ##__VA_ARGS__)
diff --git a/sound/aoa/soundbus/core.c b/sound/aoa/soundbus/core.c
index 99ca7120e269..7487eb76e034 100644
--- a/sound/aoa/soundbus/core.c
+++ b/sound/aoa/soundbus/core.c
@@ -59,7 +59,7 @@ static int soundbus_probe(struct device *dev)
59static int soundbus_uevent(struct device *dev, struct kobj_uevent_env *env) 59static int soundbus_uevent(struct device *dev, struct kobj_uevent_env *env)
60{ 60{
61 struct soundbus_dev * soundbus_dev; 61 struct soundbus_dev * soundbus_dev;
62 struct of_device * of; 62 struct platform_device * of;
63 const char *compat; 63 const char *compat;
64 int retval = 0; 64 int retval = 0;
65 int cplen, seen = 0; 65 int cplen, seen = 0;
diff --git a/sound/aoa/soundbus/soundbus.h b/sound/aoa/soundbus/soundbus.h
index a0f223c13f66..adecbf36f4f6 100644
--- a/sound/aoa/soundbus/soundbus.h
+++ b/sound/aoa/soundbus/soundbus.h
@@ -141,7 +141,7 @@ struct soundbus_dev {
141 struct list_head onbuslist; 141 struct list_head onbuslist;
142 142
143 /* the of device it represents */ 143 /* the of device it represents */
144 struct of_device ofdev; 144 struct platform_device ofdev;
145 145
146 /* what modules go by */ 146 /* what modules go by */
147 char modalias[32]; 147 char modalias[32];
diff --git a/sound/aoa/soundbus/sysfs.c b/sound/aoa/soundbus/sysfs.c
index 6496e754f00a..e0980b5c2cd8 100644
--- a/sound/aoa/soundbus/sysfs.c
+++ b/sound/aoa/soundbus/sysfs.c
@@ -16,7 +16,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
16 char *buf) 16 char *buf)
17{ 17{
18 struct soundbus_dev *sdev = to_soundbus_device(dev); 18 struct soundbus_dev *sdev = to_soundbus_device(dev);
19 struct of_device *of = &sdev->ofdev; 19 struct platform_device *of = &sdev->ofdev;
20 int length; 20 int length;
21 21
22 if (*sdev->modalias) { 22 if (*sdev->modalias) {
diff --git a/sound/oss/ad1848.c b/sound/oss/ad1848.c
index 24793c5b65ac..4d2a6ae978f7 100644
--- a/sound/oss/ad1848.c
+++ b/sound/oss/ad1848.c
@@ -716,7 +716,7 @@ static int ad1848_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
716 716
717 default: 717 default:
718 if (get_user(val, (int __user *)arg)) 718 if (get_user(val, (int __user *)arg))
719 return -EFAULT; 719 return -EFAULT;
720 val = ad1848_mixer_set(devc, cmd & 0xff, val); 720 val = ad1848_mixer_set(devc, cmd & 0xff, val);
721 break; 721 break;
722 } 722 }
diff --git a/sound/oss/au1550_ac97.c b/sound/oss/au1550_ac97.c
index c4a4cdc07ab9..c6f2621221ba 100644
--- a/sound/oss/au1550_ac97.c
+++ b/sound/oss/au1550_ac97.c
@@ -50,7 +50,6 @@
50#include <linux/poll.h> 50#include <linux/poll.h>
51#include <linux/bitops.h> 51#include <linux/bitops.h>
52#include <linux/spinlock.h> 52#include <linux/spinlock.h>
53#include <linux/smp_lock.h>
54#include <linux/ac97_codec.h> 53#include <linux/ac97_codec.h>
55#include <linux/mutex.h> 54#include <linux/mutex.h>
56 55
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index a7802b99436c..720a81d711e3 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -971,6 +971,36 @@ static void restore_init_pincfgs(struct hda_codec *codec)
971} 971}
972 972
973/* 973/*
974 * audio-converter setup caches
975 */
976struct hda_cvt_setup {
977 hda_nid_t nid;
978 u8 stream_tag;
979 u8 channel_id;
980 u16 format_id;
981 unsigned char active; /* cvt is currently used */
982 unsigned char dirty; /* setups should be cleared */
983};
984
985/* get or create a cache entry for the given audio converter NID */
986static struct hda_cvt_setup *
987get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid)
988{
989 struct hda_cvt_setup *p;
990 int i;
991
992 for (i = 0; i < codec->cvt_setups.used; i++) {
993 p = snd_array_elem(&codec->cvt_setups, i);
994 if (p->nid == nid)
995 return p;
996 }
997 p = snd_array_new(&codec->cvt_setups);
998 if (p)
999 p->nid = nid;
1000 return p;
1001}
1002
1003/*
974 * codec destructor 1004 * codec destructor
975 */ 1005 */
976static void snd_hda_codec_free(struct hda_codec *codec) 1006static void snd_hda_codec_free(struct hda_codec *codec)
@@ -1038,12 +1068,14 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus,
1038 codec->addr = codec_addr; 1068 codec->addr = codec_addr;
1039 mutex_init(&codec->spdif_mutex); 1069 mutex_init(&codec->spdif_mutex);
1040 mutex_init(&codec->control_mutex); 1070 mutex_init(&codec->control_mutex);
1071 mutex_init(&codec->prepare_mutex);
1041 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); 1072 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
1042 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); 1073 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
1043 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); 1074 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32);
1044 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); 1075 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32);
1045 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); 1076 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
1046 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); 1077 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
1078 snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8);
1047 if (codec->bus->modelname) { 1079 if (codec->bus->modelname) {
1048 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); 1080 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
1049 if (!codec->modelname) { 1081 if (!codec->modelname) {
@@ -1181,16 +1213,51 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1181 u32 stream_tag, 1213 u32 stream_tag,
1182 int channel_id, int format) 1214 int channel_id, int format)
1183{ 1215{
1216 struct hda_cvt_setup *p;
1217 unsigned int oldval, newval;
1218 int i;
1219
1184 if (!nid) 1220 if (!nid)
1185 return; 1221 return;
1186 1222
1187 snd_printdd("hda_codec_setup_stream: " 1223 snd_printdd("hda_codec_setup_stream: "
1188 "NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n", 1224 "NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n",
1189 nid, stream_tag, channel_id, format); 1225 nid, stream_tag, channel_id, format);
1190 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 1226 p = get_hda_cvt_setup(codec, nid);
1191 (stream_tag << 4) | channel_id); 1227 if (!p)
1192 msleep(1); 1228 return;
1193 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format); 1229 /* update the stream-id if changed */
1230 if (p->stream_tag != stream_tag || p->channel_id != channel_id) {
1231 oldval = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
1232 newval = (stream_tag << 4) | channel_id;
1233 if (oldval != newval)
1234 snd_hda_codec_write(codec, nid, 0,
1235 AC_VERB_SET_CHANNEL_STREAMID,
1236 newval);
1237 p->stream_tag = stream_tag;
1238 p->channel_id = channel_id;
1239 }
1240 /* update the format-id if changed */
1241 if (p->format_id != format) {
1242 oldval = snd_hda_codec_read(codec, nid, 0,
1243 AC_VERB_GET_STREAM_FORMAT, 0);
1244 if (oldval != format) {
1245 msleep(1);
1246 snd_hda_codec_write(codec, nid, 0,
1247 AC_VERB_SET_STREAM_FORMAT,
1248 format);
1249 }
1250 p->format_id = format;
1251 }
1252 p->active = 1;
1253 p->dirty = 0;
1254
1255 /* make other inactive cvts with the same stream-tag dirty */
1256 for (i = 0; i < codec->cvt_setups.used; i++) {
1257 p = snd_array_elem(&codec->cvt_setups, i);
1258 if (!p->active && p->stream_tag == stream_tag)
1259 p->dirty = 1;
1260 }
1194} 1261}
1195EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream); 1262EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream);
1196 1263
@@ -1201,17 +1268,54 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream);
1201 */ 1268 */
1202void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid) 1269void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
1203{ 1270{
1271 struct hda_cvt_setup *p;
1272
1204 if (!nid) 1273 if (!nid)
1205 return; 1274 return;
1206 1275
1207 snd_printdd("hda_codec_cleanup_stream: NID=0x%x\n", nid); 1276 snd_printdd("hda_codec_cleanup_stream: NID=0x%x\n", nid);
1277 /* here we just clear the active flag; actual clean-ups will be done
1278 * in purify_inactive_streams()
1279 */
1280 p = get_hda_cvt_setup(codec, nid);
1281 if (p)
1282 p->active = 0;
1283}
1284EXPORT_SYMBOL_HDA(snd_hda_codec_cleanup_stream);
1285
1286static void really_cleanup_stream(struct hda_codec *codec,
1287 struct hda_cvt_setup *q)
1288{
1289 hda_nid_t nid = q->nid;
1208 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0); 1290 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
1209#if 0 /* keep the format */
1210 msleep(1);
1211 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0); 1291 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
1212#endif 1292 memset(q, 0, sizeof(*q));
1293 q->nid = nid;
1294}
1295
1296/* clean up the all conflicting obsolete streams */
1297static void purify_inactive_streams(struct hda_codec *codec)
1298{
1299 int i;
1300
1301 for (i = 0; i < codec->cvt_setups.used; i++) {
1302 struct hda_cvt_setup *p = snd_array_elem(&codec->cvt_setups, i);
1303 if (p->dirty)
1304 really_cleanup_stream(codec, p);
1305 }
1306}
1307
1308/* clean up all streams; called from suspend */
1309static void hda_cleanup_all_streams(struct hda_codec *codec)
1310{
1311 int i;
1312
1313 for (i = 0; i < codec->cvt_setups.used; i++) {
1314 struct hda_cvt_setup *p = snd_array_elem(&codec->cvt_setups, i);
1315 if (p->stream_tag)
1316 really_cleanup_stream(codec, p);
1317 }
1213} 1318}
1214EXPORT_SYMBOL_HDA(snd_hda_codec_cleanup_stream);
1215 1319
1216/* 1320/*
1217 * amp access functions 1321 * amp access functions
@@ -2928,6 +3032,7 @@ static void hda_call_codec_suspend(struct hda_codec *codec)
2928{ 3032{
2929 if (codec->patch_ops.suspend) 3033 if (codec->patch_ops.suspend)
2930 codec->patch_ops.suspend(codec, PMSG_SUSPEND); 3034 codec->patch_ops.suspend(codec, PMSG_SUSPEND);
3035 hda_cleanup_all_streams(codec);
2931 hda_set_power_state(codec, 3036 hda_set_power_state(codec,
2932 codec->afg ? codec->afg : codec->mfg, 3037 codec->afg ? codec->afg : codec->mfg,
2933 AC_PWRST_D3); 3038 AC_PWRST_D3);
@@ -3377,6 +3482,35 @@ static int set_pcm_default_values(struct hda_codec *codec,
3377 return 0; 3482 return 0;
3378} 3483}
3379 3484
3485/*
3486 * codec prepare/cleanup entries
3487 */
3488int snd_hda_codec_prepare(struct hda_codec *codec,
3489 struct hda_pcm_stream *hinfo,
3490 unsigned int stream,
3491 unsigned int format,
3492 struct snd_pcm_substream *substream)
3493{
3494 int ret;
3495 mutex_lock(&codec->prepare_mutex);
3496 ret = hinfo->ops.prepare(hinfo, codec, stream, format, substream);
3497 if (ret >= 0)
3498 purify_inactive_streams(codec);
3499 mutex_unlock(&codec->prepare_mutex);
3500 return ret;
3501}
3502EXPORT_SYMBOL_HDA(snd_hda_codec_prepare);
3503
3504void snd_hda_codec_cleanup(struct hda_codec *codec,
3505 struct hda_pcm_stream *hinfo,
3506 struct snd_pcm_substream *substream)
3507{
3508 mutex_lock(&codec->prepare_mutex);
3509 hinfo->ops.cleanup(hinfo, codec, substream);
3510 mutex_unlock(&codec->prepare_mutex);
3511}
3512EXPORT_SYMBOL_HDA(snd_hda_codec_cleanup);
3513
3380/* global */ 3514/* global */
3381const char *snd_hda_pcm_type_name[HDA_PCM_NTYPES] = { 3515const char *snd_hda_pcm_type_name[HDA_PCM_NTYPES] = {
3382 "Audio", "SPDIF", "HDMI", "Modem" 3516 "Audio", "SPDIF", "HDMI", "Modem"
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 0328cf55cdba..3f7a479881e5 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -826,12 +826,14 @@ struct hda_codec {
826 826
827 struct mutex spdif_mutex; 827 struct mutex spdif_mutex;
828 struct mutex control_mutex; 828 struct mutex control_mutex;
829 struct mutex prepare_mutex;
829 unsigned int spdif_status; /* IEC958 status bits */ 830 unsigned int spdif_status; /* IEC958 status bits */
830 unsigned short spdif_ctls; /* SPDIF control bits */ 831 unsigned short spdif_ctls; /* SPDIF control bits */
831 unsigned int spdif_in_enable; /* SPDIF input enable? */ 832 unsigned int spdif_in_enable; /* SPDIF input enable? */
832 hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */ 833 hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */
833 struct snd_array init_pins; /* initial (BIOS) pin configurations */ 834 struct snd_array init_pins; /* initial (BIOS) pin configurations */
834 struct snd_array driver_pins; /* pin configs set by codec parser */ 835 struct snd_array driver_pins; /* pin configs set by codec parser */
836 struct snd_array cvt_setups; /* audio convert setups */
835 837
836#ifdef CONFIG_SND_HDA_HWDEP 838#ifdef CONFIG_SND_HDA_HWDEP
837 struct snd_hwdep *hwdep; /* assigned hwdep device */ 839 struct snd_hwdep *hwdep; /* assigned hwdep device */
@@ -948,6 +950,16 @@ int snd_hda_codec_build_controls(struct hda_codec *codec);
948 */ 950 */
949int snd_hda_build_pcms(struct hda_bus *bus); 951int snd_hda_build_pcms(struct hda_bus *bus);
950int snd_hda_codec_build_pcms(struct hda_codec *codec); 952int snd_hda_codec_build_pcms(struct hda_codec *codec);
953
954int snd_hda_codec_prepare(struct hda_codec *codec,
955 struct hda_pcm_stream *hinfo,
956 unsigned int stream,
957 unsigned int format,
958 struct snd_pcm_substream *substream);
959void snd_hda_codec_cleanup(struct hda_codec *codec,
960 struct hda_pcm_stream *hinfo,
961 struct snd_pcm_substream *substream);
962
951void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, 963void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
952 u32 stream_tag, 964 u32 stream_tag,
953 int channel_id, int format); 965 int channel_id, int format);
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 66d420212d9a..1053fff4bd0a 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -1634,7 +1634,7 @@ static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
1634 azx_dev->period_bytes = 0; 1634 azx_dev->period_bytes = 0;
1635 azx_dev->format_val = 0; 1635 azx_dev->format_val = 0;
1636 1636
1637 hinfo->ops.cleanup(hinfo, apcm->codec, substream); 1637 snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
1638 1638
1639 return snd_pcm_lib_free_pages(substream); 1639 return snd_pcm_lib_free_pages(substream);
1640} 1640}
@@ -1688,8 +1688,8 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1688 else 1688 else
1689 azx_dev->fifo_size = 0; 1689 azx_dev->fifo_size = 0;
1690 1690
1691 return hinfo->ops.prepare(hinfo, apcm->codec, azx_dev->stream_tag, 1691 return snd_hda_codec_prepare(apcm->codec, hinfo, azx_dev->stream_tag,
1692 azx_dev->format_val, substream); 1692 azx_dev->format_val, substream);
1693} 1693}
1694 1694
1695static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 1695static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index df8b19b17308..f7e234e5ee96 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -3206,6 +3206,8 @@ static struct hda_codec_preset snd_hda_preset_conexant[] = {
3206 .patch = patch_cxt5066 }, 3206 .patch = patch_cxt5066 },
3207 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 3207 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
3208 .patch = patch_cxt5066 }, 3208 .patch = patch_cxt5066 },
3209 { .id = 0x14f15068, .name = "CX20584",
3210 .patch = patch_cxt5066 },
3209 { .id = 0x14f15069, .name = "CX20585", 3211 { .id = 0x14f15069, .name = "CX20585",
3210 .patch = patch_cxt5066 }, 3212 .patch = patch_cxt5066 },
3211 {} /* terminator */ 3213 {} /* terminator */
@@ -3216,6 +3218,7 @@ MODULE_ALIAS("snd-hda-codec-id:14f15047");
3216MODULE_ALIAS("snd-hda-codec-id:14f15051"); 3218MODULE_ALIAS("snd-hda-codec-id:14f15051");
3217MODULE_ALIAS("snd-hda-codec-id:14f15066"); 3219MODULE_ALIAS("snd-hda-codec-id:14f15066");
3218MODULE_ALIAS("snd-hda-codec-id:14f15067"); 3220MODULE_ALIAS("snd-hda-codec-id:14f15067");
3221MODULE_ALIAS("snd-hda-codec-id:14f15068");
3219MODULE_ALIAS("snd-hda-codec-id:14f15069"); 3222MODULE_ALIAS("snd-hda-codec-id:14f15069");
3220 3223
3221MODULE_LICENSE("GPL"); 3224MODULE_LICENSE("GPL");
diff --git a/sound/pci/hda/patch_nvhdmi.c b/sound/pci/hda/patch_nvhdmi.c
index a281836fd472..77e2b4028b9f 100644
--- a/sound/pci/hda/patch_nvhdmi.c
+++ b/sound/pci/hda/patch_nvhdmi.c
@@ -540,26 +540,32 @@ static int patch_nvhdmi_2ch(struct hda_codec *codec)
540 * patch entries 540 * patch entries
541 */ 541 */
542static struct hda_codec_preset snd_hda_preset_nvhdmi[] = { 542static struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
543 { .id = 0x10de0002, .name = "MCP77/78 HDMI", 543 { .id = 0x10de0002, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
544 .patch = patch_nvhdmi_8ch_7x }, 544 { .id = 0x10de0003, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
545 { .id = 0x10de0003, .name = "MCP77/78 HDMI", 545 { .id = 0x10de0005, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
546 .patch = patch_nvhdmi_8ch_7x }, 546 { .id = 0x10de0006, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
547 { .id = 0x10de0005, .name = "MCP77/78 HDMI", 547 { .id = 0x10de0007, .name = "MCP79/7A HDMI", .patch = patch_nvhdmi_8ch_7x },
548 .patch = patch_nvhdmi_8ch_7x }, 548 { .id = 0x10de000a, .name = "GPU 0a HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
549 { .id = 0x10de0006, .name = "MCP77/78 HDMI", 549 { .id = 0x10de000b, .name = "GPU 0b HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
550 .patch = patch_nvhdmi_8ch_7x }, 550 { .id = 0x10de000c, .name = "MCP89 HDMI", .patch = patch_nvhdmi_8ch_89 },
551 { .id = 0x10de0007, .name = "MCP79/7A HDMI", 551 { .id = 0x10de000d, .name = "GPU 0d HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
552 .patch = patch_nvhdmi_8ch_7x }, 552 { .id = 0x10de0010, .name = "GPU 10 HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
553 { .id = 0x10de000a, .name = "GT220 HDMI", 553 { .id = 0x10de0011, .name = "GPU 11 HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
554 .patch = patch_nvhdmi_8ch_89 }, 554 { .id = 0x10de0012, .name = "GPU 12 HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
555 { .id = 0x10de000b, .name = "GT21x HDMI", 555 { .id = 0x10de0013, .name = "GPU 13 HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
556 .patch = patch_nvhdmi_8ch_89 }, 556 { .id = 0x10de0014, .name = "GPU 14 HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
557 { .id = 0x10de000c, .name = "MCP89 HDMI", 557 { .id = 0x10de0018, .name = "GPU 18 HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
558 .patch = patch_nvhdmi_8ch_89 }, 558 { .id = 0x10de0019, .name = "GPU 19 HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
559 { .id = 0x10de000d, .name = "GT240 HDMI", 559 { .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
560 .patch = patch_nvhdmi_8ch_89 }, 560 { .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
561 { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch }, 561 { .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
562 { .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch }, 562 { .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
563 { .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
564 { .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
565 { .id = 0x10de0043, .name = "GPU 43 HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
566 { .id = 0x10de0044, .name = "GPU 44 HDMI/DP", .patch = patch_nvhdmi_8ch_89 },
567 { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
568 { .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch },
563 {} /* terminator */ 569 {} /* terminator */
564}; 570};
565 571
@@ -572,6 +578,21 @@ MODULE_ALIAS("snd-hda-codec-id:10de000a");
572MODULE_ALIAS("snd-hda-codec-id:10de000b"); 578MODULE_ALIAS("snd-hda-codec-id:10de000b");
573MODULE_ALIAS("snd-hda-codec-id:10de000c"); 579MODULE_ALIAS("snd-hda-codec-id:10de000c");
574MODULE_ALIAS("snd-hda-codec-id:10de000d"); 580MODULE_ALIAS("snd-hda-codec-id:10de000d");
581MODULE_ALIAS("snd-hda-codec-id:10de0010");
582MODULE_ALIAS("snd-hda-codec-id:10de0011");
583MODULE_ALIAS("snd-hda-codec-id:10de0012");
584MODULE_ALIAS("snd-hda-codec-id:10de0013");
585MODULE_ALIAS("snd-hda-codec-id:10de0014");
586MODULE_ALIAS("snd-hda-codec-id:10de0018");
587MODULE_ALIAS("snd-hda-codec-id:10de0019");
588MODULE_ALIAS("snd-hda-codec-id:10de001a");
589MODULE_ALIAS("snd-hda-codec-id:10de001b");
590MODULE_ALIAS("snd-hda-codec-id:10de001c");
591MODULE_ALIAS("snd-hda-codec-id:10de0040");
592MODULE_ALIAS("snd-hda-codec-id:10de0041");
593MODULE_ALIAS("snd-hda-codec-id:10de0042");
594MODULE_ALIAS("snd-hda-codec-id:10de0043");
595MODULE_ALIAS("snd-hda-codec-id:10de0044");
575MODULE_ALIAS("snd-hda-codec-id:10de0067"); 596MODULE_ALIAS("snd-hda-codec-id:10de0067");
576MODULE_ALIAS("snd-hda-codec-id:10de8001"); 597MODULE_ALIAS("snd-hda-codec-id:10de8001");
577 598
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 6ac53f7de549..55d6e5b6bb7d 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -137,6 +137,7 @@ enum {
137 ALC269VB_DMIC, 137 ALC269VB_DMIC,
138 ALC269_FUJITSU, 138 ALC269_FUJITSU,
139 ALC269_LIFEBOOK, 139 ALC269_LIFEBOOK,
140 ALC271_ACER,
140 ALC269_AUTO, 141 ALC269_AUTO,
141 ALC269_MODEL_LAST /* last tag */ 142 ALC269_MODEL_LAST /* last tag */
142}; 143};
@@ -7041,6 +7042,7 @@ static int patch_alc260(struct hda_codec *codec)
7041 7042
7042 spec->stream_analog_playback = &alc260_pcm_analog_playback; 7043 spec->stream_analog_playback = &alc260_pcm_analog_playback;
7043 spec->stream_analog_capture = &alc260_pcm_analog_capture; 7044 spec->stream_analog_capture = &alc260_pcm_analog_capture;
7045 spec->stream_analog_alt_capture = &alc260_pcm_analog_capture;
7044 7046
7045 spec->stream_digital_playback = &alc260_pcm_digital_playback; 7047 spec->stream_digital_playback = &alc260_pcm_digital_playback;
7046 spec->stream_digital_capture = &alc260_pcm_digital_capture; 7048 spec->stream_digital_capture = &alc260_pcm_digital_capture;
@@ -13475,7 +13477,6 @@ static struct snd_pci_quirk alc268_cfg_tbl[] = {
13475 SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA), 13477 SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
13476 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER), 13478 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
13477 SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1), 13479 SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
13478 SND_PCI_QUIRK(0x1854, 0x1775, "LG R510", ALC268_DELL),
13479 {} 13480 {}
13480}; 13481};
13481 13482
@@ -13866,6 +13867,12 @@ static struct snd_kcontrol_new alc269vb_laptop_mixer[] = {
13866 { } /* end */ 13867 { } /* end */
13867}; 13868};
13868 13869
13870static struct snd_kcontrol_new alc269_asus_mixer[] = {
13871 HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13872 HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x0, HDA_INPUT),
13873 { } /* end */
13874};
13875
13869/* capture mixer elements */ 13876/* capture mixer elements */
13870static struct snd_kcontrol_new alc269_laptop_analog_capture_mixer[] = { 13877static struct snd_kcontrol_new alc269_laptop_analog_capture_mixer[] = {
13871 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), 13878 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
@@ -14086,6 +14093,20 @@ static struct hda_verb alc269vb_laptop_amic_init_verbs[] = {
14086 {} 14093 {}
14087}; 14094};
14088 14095
14096static struct hda_verb alc271_acer_dmic_verbs[] = {
14097 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
14098 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
14099 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14100 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14101 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14102 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14103 {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},
14104 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14105 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14106 {0x22, AC_VERB_SET_CONNECT_SEL, 6},
14107 { }
14108};
14109
14089/* toggle speaker-output according to the hp-jack state */ 14110/* toggle speaker-output according to the hp-jack state */
14090static void alc269_speaker_automute(struct hda_codec *codec) 14111static void alc269_speaker_automute(struct hda_codec *codec)
14091{ 14112{
@@ -14465,6 +14486,7 @@ static const char *alc269_models[ALC269_MODEL_LAST] = {
14465 14486
14466static struct snd_pci_quirk alc269_cfg_tbl[] = { 14487static struct snd_pci_quirk alc269_cfg_tbl[] = {
14467 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1), 14488 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
14489 SND_PCI_QUIRK(0x1025, 0x047c, "ACER ZGA", ALC271_ACER),
14468 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A", 14490 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
14469 ALC269_AMIC), 14491 ALC269_AMIC),
14470 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269VB_AMIC), 14492 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269VB_AMIC),
@@ -14626,6 +14648,23 @@ static struct alc_config_preset alc269_presets[] = {
14626 .unsol_event = alc269_lifebook_unsol_event, 14648 .unsol_event = alc269_lifebook_unsol_event,
14627 .init_hook = alc269_lifebook_init_hook, 14649 .init_hook = alc269_lifebook_init_hook,
14628 }, 14650 },
14651 [ALC271_ACER] = {
14652 .mixers = { alc269_asus_mixer },
14653 .cap_mixer = alc269vb_laptop_digital_capture_mixer,
14654 .init_verbs = { alc269_init_verbs, alc271_acer_dmic_verbs },
14655 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
14656 .dac_nids = alc269_dac_nids,
14657 .adc_nids = alc262_dmic_adc_nids,
14658 .num_adc_nids = ARRAY_SIZE(alc262_dmic_adc_nids),
14659 .capsrc_nids = alc262_dmic_capsrc_nids,
14660 .num_channel_mode = ARRAY_SIZE(alc269_modes),
14661 .channel_mode = alc269_modes,
14662 .input_mux = &alc269_capture_source,
14663 .dig_out_nid = ALC880_DIGOUT_NID,
14664 .unsol_event = alc_sku_unsol_event,
14665 .setup = alc269vb_laptop_dmic_setup,
14666 .init_hook = alc_inithook,
14667 },
14629}; 14668};
14630 14669
14631static int patch_alc269(struct hda_codec *codec) 14670static int patch_alc269(struct hda_codec *codec)
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index b8d730c47df1..f3f861bd1bf8 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -94,6 +94,7 @@ enum {
94 STAC_92HD83XXX_PWR_REF, 94 STAC_92HD83XXX_PWR_REF,
95 STAC_DELL_S14, 95 STAC_DELL_S14,
96 STAC_92HD83XXX_HP, 96 STAC_92HD83XXX_HP,
97 STAC_HP_DV7_4000,
97 STAC_92HD83XXX_MODELS 98 STAC_92HD83XXX_MODELS
98}; 99};
99 100
@@ -1632,10 +1633,17 @@ static unsigned int dell_s14_pin_configs[10] = {
1632 0x40f000f0, 0x40f000f0, 1633 0x40f000f0, 0x40f000f0,
1633}; 1634};
1634 1635
1636static unsigned int hp_dv7_4000_pin_configs[10] = {
1637 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1638 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1639 0x40f000f0, 0x40f000f0,
1640};
1641
1635static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = { 1642static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1636 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs, 1643 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1637 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs, 1644 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1638 [STAC_DELL_S14] = dell_s14_pin_configs, 1645 [STAC_DELL_S14] = dell_s14_pin_configs,
1646 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
1639}; 1647};
1640 1648
1641static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = { 1649static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
@@ -1644,6 +1652,7 @@ static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1644 [STAC_92HD83XXX_PWR_REF] = "mic-ref", 1652 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1645 [STAC_DELL_S14] = "dell-s14", 1653 [STAC_DELL_S14] = "dell-s14",
1646 [STAC_92HD83XXX_HP] = "hp", 1654 [STAC_92HD83XXX_HP] = "hp",
1655 [STAC_HP_DV7_4000] = "hp-dv7-4000",
1647}; 1656};
1648 1657
1649static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = { 1658static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
@@ -5340,6 +5349,8 @@ again:
5340 case 0x111d7667: 5349 case 0x111d7667:
5341 case 0x111d7668: 5350 case 0x111d7668:
5342 case 0x111d7669: 5351 case 0x111d7669:
5352 case 0x111d76d1:
5353 case 0x111d76d9:
5343 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids); 5354 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5344 spec->pin_nids = stac92hd88xxx_pin_nids; 5355 spec->pin_nids = stac92hd88xxx_pin_nids;
5345 spec->mono_nid = 0; 5356 spec->mono_nid = 0;
@@ -6274,6 +6285,8 @@ static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
6274 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx}, 6285 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
6275 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx}, 6286 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
6276 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx}, 6287 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
6288 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6289 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
6277 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx}, 6290 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6278 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx}, 6291 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6279 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx}, 6292 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
diff --git a/sound/soc/blackfin/Kconfig b/sound/soc/blackfin/Kconfig
index 8ef25025f3dc..3abeeddc67d3 100644
--- a/sound/soc/blackfin/Kconfig
+++ b/sound/soc/blackfin/Kconfig
@@ -105,13 +105,18 @@ config SND_BF5XX_RESET_GPIO_NUM
105 Set the correct GPIO for RESET the sound chip. 105 Set the correct GPIO for RESET the sound chip.
106 106
107config SND_BF5XX_SOC_AD1980 107config SND_BF5XX_SOC_AD1980
108 tristate "SoC AD1980/1 Audio support for BF5xx" 108 tristate "SoC AD1980/1 Audio support for BF5xx (Obsolete)"
109 depends on SND_BF5XX_AC97 109 depends on SND_BF5XX_AC97
110 select SND_BF5XX_SOC_AC97 110 select SND_BF5XX_SOC_AC97
111 select SND_SOC_AD1980 111 select SND_SOC_AD1980
112 help 112 help
113 Say Y if you want to add support for SoC audio on BF5xx STAMP/EZKIT. 113 Say Y if you want to add support for SoC audio on BF5xx STAMP/EZKIT.
114 114
115 Warning:
116 Because Analog Devices Inc. discontinued the ad1980 sound chip since
117 Sep. 2009, this ad1980 driver is not maintained, tested and supported
118 by ADI now.
119
115config SND_BF5XX_SOC_SPORT 120config SND_BF5XX_SOC_SPORT
116 tristate 121 tristate
117 122
diff --git a/sound/soc/blackfin/bf5xx-ad1980.c b/sound/soc/blackfin/bf5xx-ad1980.c
index d8f591273778..92f7c327bb7a 100644
--- a/sound/soc/blackfin/bf5xx-ad1980.c
+++ b/sound/soc/blackfin/bf5xx-ad1980.c
@@ -26,6 +26,14 @@
26 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 */ 27 */
28 28
29/*
30 * WARNING:
31 *
32 * Because Analog Devices Inc. discontinued the ad1980 sound chip since
33 * Sep. 2009, this ad1980 driver is not maintained, tested and supported
34 * by ADI now.
35 */
36
29#include <linux/module.h> 37#include <linux/module.h>
30#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
31#include <linux/device.h> 39#include <linux/device.h>
@@ -109,5 +117,5 @@ module_exit(bf5xx_board_exit);
109 117
110/* Module information */ 118/* Module information */
111MODULE_AUTHOR("Cliff Cai"); 119MODULE_AUTHOR("Cliff Cai");
112MODULE_DESCRIPTION("ALSA SoC AD1980/1 BF5xx board"); 120MODULE_DESCRIPTION("ALSA SoC AD1980/1 BF5xx board (Obsolete)");
113MODULE_LICENSE("GPL"); 121MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ad1980.c b/sound/soc/codecs/ad1980.c
index 042072738cdc..70cfaec3be2c 100644
--- a/sound/soc/codecs/ad1980.c
+++ b/sound/soc/codecs/ad1980.c
@@ -11,6 +11,14 @@
11 * option) any later version. 11 * option) any later version.
12 */ 12 */
13 13
14/*
15 * WARNING:
16 *
17 * Because Analog Devices Inc. discontinued the ad1980 sound chip since
18 * Sep. 2009, this ad1980 driver is not maintained, tested and supported
19 * by ADI now.
20 */
21
14#include <linux/init.h> 22#include <linux/init.h>
15#include <linux/slab.h> 23#include <linux/slab.h>
16#include <linux/module.h> 24#include <linux/module.h>
@@ -298,6 +306,6 @@ struct snd_soc_codec_device soc_codec_dev_ad1980 = {
298}; 306};
299EXPORT_SYMBOL_GPL(soc_codec_dev_ad1980); 307EXPORT_SYMBOL_GPL(soc_codec_dev_ad1980);
300 308
301MODULE_DESCRIPTION("ASoC ad1980 driver"); 309MODULE_DESCRIPTION("ASoC ad1980 driver (Obsolete)");
302MODULE_AUTHOR("Roy Huang, Cliff Cai"); 310MODULE_AUTHOR("Roy Huang, Cliff Cai");
303MODULE_LICENSE("GPL"); 311MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ad1980.h b/sound/soc/codecs/ad1980.h
index db6c8500d66b..538f37c90806 100644
--- a/sound/soc/codecs/ad1980.h
+++ b/sound/soc/codecs/ad1980.h
@@ -1,5 +1,11 @@
1/* 1/*
2 * ad1980.h -- ad1980 Soc Audio driver 2 * ad1980.h -- ad1980 Soc Audio driver
3 *
4 * WARNING:
5 *
6 * Because Analog Devices Inc. discontinued the ad1980 sound chip since
7 * Sep. 2009, this ad1980 driver is not maintained, tested and supported
8 * by ADI now.
3 */ 9 */
4 10
5#ifndef _AD1980_H 11#ifndef _AD1980_H
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c
index c3571ee5c11b..72deeabef4fe 100644
--- a/sound/soc/codecs/wm8580.c
+++ b/sound/soc/codecs/wm8580.c
@@ -269,9 +269,9 @@ SOC_DOUBLE("DAC2 Invert Switch", WM8580_DAC_CONTROL4, 2, 3, 1, 0),
269SOC_DOUBLE("DAC3 Invert Switch", WM8580_DAC_CONTROL4, 4, 5, 1, 0), 269SOC_DOUBLE("DAC3 Invert Switch", WM8580_DAC_CONTROL4, 4, 5, 1, 0),
270 270
271SOC_SINGLE("DAC ZC Switch", WM8580_DAC_CONTROL5, 5, 1, 0), 271SOC_SINGLE("DAC ZC Switch", WM8580_DAC_CONTROL5, 5, 1, 0),
272SOC_SINGLE("DAC1 Switch", WM8580_DAC_CONTROL5, 0, 1, 0), 272SOC_SINGLE("DAC1 Switch", WM8580_DAC_CONTROL5, 0, 1, 1),
273SOC_SINGLE("DAC2 Switch", WM8580_DAC_CONTROL5, 1, 1, 0), 273SOC_SINGLE("DAC2 Switch", WM8580_DAC_CONTROL5, 1, 1, 1),
274SOC_SINGLE("DAC3 Switch", WM8580_DAC_CONTROL5, 2, 1, 0), 274SOC_SINGLE("DAC3 Switch", WM8580_DAC_CONTROL5, 2, 1, 1),
275 275
276SOC_DOUBLE("ADC Mute Switch", WM8580_ADC_CONTROL1, 0, 1, 1, 0), 276SOC_DOUBLE("ADC Mute Switch", WM8580_ADC_CONTROL1, 0, 1, 1, 0),
277SOC_SINGLE("ADC High-Pass Filter Switch", WM8580_ADC_CONTROL1, 4, 1, 0), 277SOC_SINGLE("ADC High-Pass Filter Switch", WM8580_ADC_CONTROL1, 4, 1, 0),
diff --git a/sound/soc/fsl/mpc5200_dma.c b/sound/soc/fsl/mpc5200_dma.c
index 1d4e7164e80a..3dcd1469f283 100644
--- a/sound/soc/fsl/mpc5200_dma.c
+++ b/sound/soc/fsl/mpc5200_dma.c
@@ -369,7 +369,7 @@ struct snd_soc_platform mpc5200_audio_dma_platform = {
369}; 369};
370EXPORT_SYMBOL_GPL(mpc5200_audio_dma_platform); 370EXPORT_SYMBOL_GPL(mpc5200_audio_dma_platform);
371 371
372int mpc5200_audio_dma_create(struct of_device *op) 372int mpc5200_audio_dma_create(struct platform_device *op)
373{ 373{
374 phys_addr_t fifo; 374 phys_addr_t fifo;
375 struct psc_dma *psc_dma; 375 struct psc_dma *psc_dma;
@@ -488,7 +488,7 @@ out_unmap:
488} 488}
489EXPORT_SYMBOL_GPL(mpc5200_audio_dma_create); 489EXPORT_SYMBOL_GPL(mpc5200_audio_dma_create);
490 490
491int mpc5200_audio_dma_destroy(struct of_device *op) 491int mpc5200_audio_dma_destroy(struct platform_device *op)
492{ 492{
493 struct psc_dma *psc_dma = dev_get_drvdata(&op->dev); 493 struct psc_dma *psc_dma = dev_get_drvdata(&op->dev);
494 494
diff --git a/sound/soc/fsl/mpc5200_dma.h b/sound/soc/fsl/mpc5200_dma.h
index e1ec6d91ea38..ca99586f2ad9 100644
--- a/sound/soc/fsl/mpc5200_dma.h
+++ b/sound/soc/fsl/mpc5200_dma.h
@@ -81,8 +81,8 @@ to_psc_dma_stream(struct snd_pcm_substream *substream, struct psc_dma *psc_dma)
81 return &psc_dma->playback; 81 return &psc_dma->playback;
82} 82}
83 83
84int mpc5200_audio_dma_create(struct of_device *op); 84int mpc5200_audio_dma_create(struct platform_device *op);
85int mpc5200_audio_dma_destroy(struct of_device *op); 85int mpc5200_audio_dma_destroy(struct platform_device *op);
86 86
87extern struct snd_soc_platform mpc5200_audio_dma_platform; 87extern struct snd_soc_platform mpc5200_audio_dma_platform;
88 88
diff --git a/sound/soc/fsl/mpc5200_psc_ac97.c b/sound/soc/fsl/mpc5200_psc_ac97.c
index e7f5d50ed084..a9560235daee 100644
--- a/sound/soc/fsl/mpc5200_psc_ac97.c
+++ b/sound/soc/fsl/mpc5200_psc_ac97.c
@@ -277,7 +277,7 @@ EXPORT_SYMBOL_GPL(psc_ac97_dai);
277 * - Probe/remove operations 277 * - Probe/remove operations
278 * - OF device match table 278 * - OF device match table
279 */ 279 */
280static int __devinit psc_ac97_of_probe(struct of_device *op, 280static int __devinit psc_ac97_of_probe(struct platform_device *op,
281 const struct of_device_id *match) 281 const struct of_device_id *match)
282{ 282{
283 int rc, i; 283 int rc, i;
@@ -317,7 +317,7 @@ static int __devinit psc_ac97_of_probe(struct of_device *op,
317 return 0; 317 return 0;
318} 318}
319 319
320static int __devexit psc_ac97_of_remove(struct of_device *op) 320static int __devexit psc_ac97_of_remove(struct platform_device *op)
321{ 321{
322 return mpc5200_audio_dma_destroy(op); 322 return mpc5200_audio_dma_destroy(op);
323} 323}
diff --git a/sound/soc/fsl/mpc5200_psc_i2s.c b/sound/soc/fsl/mpc5200_psc_i2s.c
index 676841cbae98..534f04cb15d7 100644
--- a/sound/soc/fsl/mpc5200_psc_i2s.c
+++ b/sound/soc/fsl/mpc5200_psc_i2s.c
@@ -152,7 +152,7 @@ EXPORT_SYMBOL_GPL(psc_i2s_dai);
152 * - Probe/remove operations 152 * - Probe/remove operations
153 * - OF device match table 153 * - OF device match table
154 */ 154 */
155static int __devinit psc_i2s_of_probe(struct of_device *op, 155static int __devinit psc_i2s_of_probe(struct platform_device *op,
156 const struct of_device_id *match) 156 const struct of_device_id *match)
157{ 157{
158 int rc; 158 int rc;
@@ -205,7 +205,7 @@ static int __devinit psc_i2s_of_probe(struct of_device *op,
205 205
206} 206}
207 207
208static int __devexit psc_i2s_of_remove(struct of_device *op) 208static int __devexit psc_i2s_of_remove(struct platform_device *op)
209{ 209{
210 return mpc5200_audio_dma_destroy(op); 210 return mpc5200_audio_dma_destroy(op);
211} 211}
diff --git a/sound/soc/fsl/mpc8610_hpcd.c b/sound/soc/fsl/mpc8610_hpcd.c
index 3a501062c244..3b13b8d65262 100644
--- a/sound/soc/fsl/mpc8610_hpcd.c
+++ b/sound/soc/fsl/mpc8610_hpcd.c
@@ -200,7 +200,7 @@ static struct snd_soc_ops mpc8610_hpcd_ops = {
200 * SSI devices. We also probably aren't compatible with the generic Elo DMA 200 * SSI devices. We also probably aren't compatible with the generic Elo DMA
201 * device driver. 201 * device driver.
202 */ 202 */
203static int mpc8610_hpcd_probe(struct of_device *ofdev, 203static int mpc8610_hpcd_probe(struct platform_device *ofdev,
204 const struct of_device_id *match) 204 const struct of_device_id *match)
205{ 205{
206 struct device_node *np = ofdev->dev.of_node; 206 struct device_node *np = ofdev->dev.of_node;
@@ -534,7 +534,7 @@ error:
534 * 534 *
535 * This function is called when the OF device is removed. 535 * This function is called when the OF device is removed.
536 */ 536 */
537static int mpc8610_hpcd_remove(struct of_device *ofdev) 537static int mpc8610_hpcd_remove(struct platform_device *ofdev)
538{ 538{
539 struct platform_device *sound_device = dev_get_drvdata(&ofdev->dev); 539 struct platform_device *sound_device = dev_get_drvdata(&ofdev->dev);
540 struct mpc8610_hpcd_data *machine_data = 540 struct mpc8610_hpcd_data *machine_data =
diff --git a/sound/soc/imx/Kconfig b/sound/soc/imx/Kconfig
index 52dac5e3874c..687c76fc0839 100644
--- a/sound/soc/imx/Kconfig
+++ b/sound/soc/imx/Kconfig
@@ -28,7 +28,9 @@ config SND_SOC_PHYCORE_AC97
28 28
29config SND_SOC_EUKREA_TLV320 29config SND_SOC_EUKREA_TLV320
30 tristate "Eukrea TLV320" 30 tristate "Eukrea TLV320"
31 depends on MACH_EUKREA_MBIMX27_BASEBOARD || MACH_EUKREA_MBIMXSD_BASEBOARD 31 depends on MACH_EUKREA_MBIMX27_BASEBOARD \
32 || MACH_EUKREA_MBIMXSD25_BASEBOARD \
33 || MACH_EUKREA_MBIMXSD35_BASEBOARD
32 select SND_SOC_TLV320AIC23 34 select SND_SOC_TLV320AIC23
33 help 35 help
34 Enable I2S based access to the TLV320AIC23B codec attached 36 Enable I2S based access to the TLV320AIC23B codec attached
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index 472af38188c1..adbc68ce9050 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -340,7 +340,7 @@ static unsigned int snd_soc_16_8_read_i2c(struct snd_soc_codec *codec,
340static unsigned int snd_soc_16_8_read(struct snd_soc_codec *codec, 340static unsigned int snd_soc_16_8_read(struct snd_soc_codec *codec,
341 unsigned int reg) 341 unsigned int reg)
342{ 342{
343 u16 *cache = codec->reg_cache; 343 u8 *cache = codec->reg_cache;
344 344
345 reg &= 0xff; 345 reg &= 0xff;
346 if (reg >= codec->reg_cache_size) 346 if (reg >= codec->reg_cache_size)
@@ -351,7 +351,7 @@ static unsigned int snd_soc_16_8_read(struct snd_soc_codec *codec,
351static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg, 351static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg,
352 unsigned int value) 352 unsigned int value)
353{ 353{
354 u16 *cache = codec->reg_cache; 354 u8 *cache = codec->reg_cache;
355 u8 data[3]; 355 u8 data[3];
356 int ret; 356 int ret;
357 357
diff --git a/sound/sparc/amd7930.c b/sound/sparc/amd7930.c
index 9eb1a4e0363b..f8bcfc30f800 100644
--- a/sound/sparc/amd7930.c
+++ b/sound/sparc/amd7930.c
@@ -336,7 +336,7 @@ struct snd_amd7930 {
336 int pgain; 336 int pgain;
337 int mgain; 337 int mgain;
338 338
339 struct of_device *op; 339 struct platform_device *op;
340 unsigned int irq; 340 unsigned int irq;
341 struct snd_amd7930 *next; 341 struct snd_amd7930 *next;
342}; 342};
@@ -906,7 +906,7 @@ static int __devinit snd_amd7930_mixer(struct snd_amd7930 *amd)
906 906
907static int snd_amd7930_free(struct snd_amd7930 *amd) 907static int snd_amd7930_free(struct snd_amd7930 *amd)
908{ 908{
909 struct of_device *op = amd->op; 909 struct platform_device *op = amd->op;
910 910
911 amd7930_idle(amd); 911 amd7930_idle(amd);
912 912
@@ -934,7 +934,7 @@ static struct snd_device_ops snd_amd7930_dev_ops = {
934}; 934};
935 935
936static int __devinit snd_amd7930_create(struct snd_card *card, 936static int __devinit snd_amd7930_create(struct snd_card *card,
937 struct of_device *op, 937 struct platform_device *op,
938 int irq, int dev, 938 int irq, int dev,
939 struct snd_amd7930 **ramd) 939 struct snd_amd7930 **ramd)
940{ 940{
@@ -1002,7 +1002,7 @@ static int __devinit snd_amd7930_create(struct snd_card *card,
1002 return 0; 1002 return 0;
1003} 1003}
1004 1004
1005static int __devinit amd7930_sbus_probe(struct of_device *op, const struct of_device_id *match) 1005static int __devinit amd7930_sbus_probe(struct platform_device *op, const struct of_device_id *match)
1006{ 1006{
1007 struct resource *rp = &op->resource[0]; 1007 struct resource *rp = &op->resource[0];
1008 static int dev_num; 1008 static int dev_num;
diff --git a/sound/sparc/cs4231.c b/sound/sparc/cs4231.c
index 68570ee2c9bb..c276086c3b57 100644
--- a/sound/sparc/cs4231.c
+++ b/sound/sparc/cs4231.c
@@ -111,7 +111,7 @@ struct snd_cs4231 {
111 struct mutex mce_mutex; /* mutex for mce register */ 111 struct mutex mce_mutex; /* mutex for mce register */
112 struct mutex open_mutex; /* mutex for ALSA open/close */ 112 struct mutex open_mutex; /* mutex for ALSA open/close */
113 113
114 struct of_device *op; 114 struct platform_device *op;
115 unsigned int irq[2]; 115 unsigned int irq[2];
116 unsigned int regs_size; 116 unsigned int regs_size;
117 struct snd_cs4231 *next; 117 struct snd_cs4231 *next;
@@ -1771,7 +1771,7 @@ static unsigned int sbus_dma_addr(struct cs4231_dma_control *dma_cont)
1771 1771
1772static int snd_cs4231_sbus_free(struct snd_cs4231 *chip) 1772static int snd_cs4231_sbus_free(struct snd_cs4231 *chip)
1773{ 1773{
1774 struct of_device *op = chip->op; 1774 struct platform_device *op = chip->op;
1775 1775
1776 if (chip->irq[0]) 1776 if (chip->irq[0])
1777 free_irq(chip->irq[0], chip); 1777 free_irq(chip->irq[0], chip);
@@ -1794,7 +1794,7 @@ static struct snd_device_ops snd_cs4231_sbus_dev_ops = {
1794}; 1794};
1795 1795
1796static int __devinit snd_cs4231_sbus_create(struct snd_card *card, 1796static int __devinit snd_cs4231_sbus_create(struct snd_card *card,
1797 struct of_device *op, 1797 struct platform_device *op,
1798 int dev) 1798 int dev)
1799{ 1799{
1800 struct snd_cs4231 *chip = card->private_data; 1800 struct snd_cs4231 *chip = card->private_data;
@@ -1856,7 +1856,7 @@ static int __devinit snd_cs4231_sbus_create(struct snd_card *card,
1856 return 0; 1856 return 0;
1857} 1857}
1858 1858
1859static int __devinit cs4231_sbus_probe(struct of_device *op, const struct of_device_id *match) 1859static int __devinit cs4231_sbus_probe(struct platform_device *op, const struct of_device_id *match)
1860{ 1860{
1861 struct resource *rp = &op->resource[0]; 1861 struct resource *rp = &op->resource[0];
1862 struct snd_card *card; 1862 struct snd_card *card;
@@ -1931,7 +1931,7 @@ static unsigned int _ebus_dma_addr(struct cs4231_dma_control *dma_cont)
1931 1931
1932static int snd_cs4231_ebus_free(struct snd_cs4231 *chip) 1932static int snd_cs4231_ebus_free(struct snd_cs4231 *chip)
1933{ 1933{
1934 struct of_device *op = chip->op; 1934 struct platform_device *op = chip->op;
1935 1935
1936 if (chip->c_dma.ebus_info.regs) { 1936 if (chip->c_dma.ebus_info.regs) {
1937 ebus_dma_unregister(&chip->c_dma.ebus_info); 1937 ebus_dma_unregister(&chip->c_dma.ebus_info);
@@ -1960,7 +1960,7 @@ static struct snd_device_ops snd_cs4231_ebus_dev_ops = {
1960}; 1960};
1961 1961
1962static int __devinit snd_cs4231_ebus_create(struct snd_card *card, 1962static int __devinit snd_cs4231_ebus_create(struct snd_card *card,
1963 struct of_device *op, 1963 struct platform_device *op,
1964 int dev) 1964 int dev)
1965{ 1965{
1966 struct snd_cs4231 *chip = card->private_data; 1966 struct snd_cs4231 *chip = card->private_data;
@@ -2048,7 +2048,7 @@ static int __devinit snd_cs4231_ebus_create(struct snd_card *card,
2048 return 0; 2048 return 0;
2049} 2049}
2050 2050
2051static int __devinit cs4231_ebus_probe(struct of_device *op, const struct of_device_id *match) 2051static int __devinit cs4231_ebus_probe(struct platform_device *op, const struct of_device_id *match)
2052{ 2052{
2053 struct snd_card *card; 2053 struct snd_card *card;
2054 int err; 2054 int err;
@@ -2072,7 +2072,7 @@ static int __devinit cs4231_ebus_probe(struct of_device *op, const struct of_dev
2072} 2072}
2073#endif 2073#endif
2074 2074
2075static int __devinit cs4231_probe(struct of_device *op, const struct of_device_id *match) 2075static int __devinit cs4231_probe(struct platform_device *op, const struct of_device_id *match)
2076{ 2076{
2077#ifdef EBUS_SUPPORT 2077#ifdef EBUS_SUPPORT
2078 if (!strcmp(op->dev.of_node->parent->name, "ebus")) 2078 if (!strcmp(op->dev.of_node->parent->name, "ebus"))
@@ -2086,7 +2086,7 @@ static int __devinit cs4231_probe(struct of_device *op, const struct of_device_i
2086 return -ENODEV; 2086 return -ENODEV;
2087} 2087}
2088 2088
2089static int __devexit cs4231_remove(struct of_device *op) 2089static int __devexit cs4231_remove(struct platform_device *op)
2090{ 2090{
2091 struct snd_cs4231 *chip = dev_get_drvdata(&op->dev); 2091 struct snd_cs4231 *chip = dev_get_drvdata(&op->dev);
2092 2092
diff --git a/sound/sparc/dbri.c b/sound/sparc/dbri.c
index c421901c48d0..39cd5d69d051 100644
--- a/sound/sparc/dbri.c
+++ b/sound/sparc/dbri.c
@@ -299,7 +299,7 @@ struct dbri_streaminfo {
299/* This structure holds the information for both chips (DBRI & CS4215) */ 299/* This structure holds the information for both chips (DBRI & CS4215) */
300struct snd_dbri { 300struct snd_dbri {
301 int regs_size, irq; /* Needed for unload */ 301 int regs_size, irq; /* Needed for unload */
302 struct of_device *op; /* OF device info */ 302 struct platform_device *op; /* OF device info */
303 spinlock_t lock; 303 spinlock_t lock;
304 304
305 struct dbri_dma *dma; /* Pointer to our DMA block */ 305 struct dbri_dma *dma; /* Pointer to our DMA block */
@@ -2523,7 +2523,7 @@ static void __devinit snd_dbri_proc(struct snd_card *card)
2523static void snd_dbri_free(struct snd_dbri *dbri); 2523static void snd_dbri_free(struct snd_dbri *dbri);
2524 2524
2525static int __devinit snd_dbri_create(struct snd_card *card, 2525static int __devinit snd_dbri_create(struct snd_card *card,
2526 struct of_device *op, 2526 struct platform_device *op,
2527 int irq, int dev) 2527 int irq, int dev)
2528{ 2528{
2529 struct snd_dbri *dbri = card->private_data; 2529 struct snd_dbri *dbri = card->private_data;
@@ -2592,7 +2592,7 @@ static void snd_dbri_free(struct snd_dbri *dbri)
2592 (void *)dbri->dma, dbri->dma_dvma); 2592 (void *)dbri->dma, dbri->dma_dvma);
2593} 2593}
2594 2594
2595static int __devinit dbri_probe(struct of_device *op, const struct of_device_id *match) 2595static int __devinit dbri_probe(struct platform_device *op, const struct of_device_id *match)
2596{ 2596{
2597 struct snd_dbri *dbri; 2597 struct snd_dbri *dbri;
2598 struct resource *rp; 2598 struct resource *rp;
@@ -2662,7 +2662,7 @@ _err:
2662 return err; 2662 return err;
2663} 2663}
2664 2664
2665static int __devexit dbri_remove(struct of_device *op) 2665static int __devexit dbri_remove(struct platform_device *op)
2666{ 2666{
2667 struct snd_card *card = dev_get_drvdata(&op->dev); 2667 struct snd_card *card = dev_get_drvdata(&op->dev);
2668 2668
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 26f626d45a9e..41abb90df50d 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -157,9 +157,8 @@ all::
157# 157#
158# Define NO_DWARF if you do not want debug-info analysis feature at all. 158# Define NO_DWARF if you do not want debug-info analysis feature at all.
159 159
160$(shell sh -c 'mkdir -p $(OUTPUT)scripts/python/Perf-Trace-Util/' 2> /dev/null) 160$(shell sh -c 'mkdir -p $(OUTPUT)scripts/{perl,python}/Perf-Trace-Util/' 2> /dev/null)
161$(shell sh -c 'mkdir -p $(OUTPUT)scripts/perl/Perf-Trace-Util/' 2> /dev/null) 161$(shell sh -c 'mkdir -p $(OUTPUT)util/{ui/browsers,scripting-engines}/' 2> /dev/null)
162$(shell sh -c 'mkdir -p $(OUTPUT)util/scripting-engines/' 2> /dev/null)
163$(shell sh -c 'mkdir $(OUTPUT)bench' 2> /dev/null) 162$(shell sh -c 'mkdir $(OUTPUT)bench' 2> /dev/null)
164 163
165$(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE 164$(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE
@@ -568,7 +567,20 @@ else
568 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h 567 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
569 BASIC_CFLAGS += -I/usr/include/slang 568 BASIC_CFLAGS += -I/usr/include/slang
570 EXTLIBS += -lnewt -lslang 569 EXTLIBS += -lnewt -lslang
571 LIB_OBJS += $(OUTPUT)util/newt.o 570 LIB_OBJS += $(OUTPUT)util/ui/setup.o
571 LIB_OBJS += $(OUTPUT)util/ui/browser.o
572 LIB_OBJS += $(OUTPUT)util/ui/browsers/annotate.o
573 LIB_OBJS += $(OUTPUT)util/ui/browsers/hists.o
574 LIB_OBJS += $(OUTPUT)util/ui/browsers/map.o
575 LIB_OBJS += $(OUTPUT)util/ui/helpline.o
576 LIB_OBJS += $(OUTPUT)util/ui/progress.o
577 LIB_OBJS += $(OUTPUT)util/ui/util.o
578 LIB_H += util/ui/browser.h
579 LIB_H += util/ui/browsers/map.h
580 LIB_H += util/ui/helpline.h
581 LIB_H += util/ui/libslang.h
582 LIB_H += util/ui/progress.h
583 LIB_H += util/ui/util.h
572 endif 584 endif
573endif 585endif
574 586
@@ -966,7 +978,16 @@ $(OUTPUT)builtin-init-db.o: builtin-init-db.c $(OUTPUT)PERF-CFLAGS
966$(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS 978$(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS
967 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< 979 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
968 980
969$(OUTPUT)util/newt.o: util/newt.c $(OUTPUT)PERF-CFLAGS 981$(OUTPUT)util/ui/browser.o: util/ui/browser.c $(OUTPUT)PERF-CFLAGS
982 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
983
984$(OUTPUT)util/ui/browsers/annotate.o: util/ui/browsers/annotate.c $(OUTPUT)PERF-CFLAGS
985 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
986
987$(OUTPUT)util/ui/browsers/hists.o: util/ui/browsers/hists.c $(OUTPUT)PERF-CFLAGS
988 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
989
990$(OUTPUT)util/ui/browsers/map.o: util/ui/browsers/map.c $(OUTPUT)PERF-CFLAGS
970 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 991 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
971 992
972$(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS 993$(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index fd20670ce986..1478dc64bf15 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -285,7 +285,7 @@ static int hist_entry__tty_annotate(struct hist_entry *he)
285 LIST_HEAD(head); 285 LIST_HEAD(head);
286 struct objdump_line *pos, *n; 286 struct objdump_line *pos, *n;
287 287
288 if (hist_entry__annotate(he, &head) < 0) 288 if (hist_entry__annotate(he, &head, 0) < 0)
289 return -1; 289 return -1;
290 290
291 if (full_paths) 291 if (full_paths)
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 2f4b92925b26..55fc1f46892a 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -348,7 +348,18 @@ static int __cmd_report(void)
348 hists__tty_browse_tree(&session->hists_tree, help); 348 hists__tty_browse_tree(&session->hists_tree, help);
349 349
350out_delete: 350out_delete:
351 perf_session__delete(session); 351 /*
352 * Speed up the exit process, for large files this can
353 * take quite a while.
354 *
355 * XXX Enable this when using valgrind or if we ever
356 * librarize this command.
357 *
358 * Also experiment with obstacks to see how much speed
359 * up we'll get here.
360 *
361 * perf_session__delete(session);
362 */
352 return ret; 363 return ret;
353} 364}
354 365
@@ -478,8 +489,24 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
478 * so don't allocate extra space that won't be used in the stdio 489 * so don't allocate extra space that won't be used in the stdio
479 * implementation. 490 * implementation.
480 */ 491 */
481 if (use_browser > 0) 492 if (use_browser > 0) {
482 symbol_conf.priv_size = sizeof(struct sym_priv); 493 symbol_conf.priv_size = sizeof(struct sym_priv);
494 /*
495 * For searching by name on the "Browse map details".
496 * providing it only in verbose mode not to bloat too
497 * much struct symbol.
498 */
499 if (verbose) {
500 /*
501 * XXX: Need to provide a less kludgy way to ask for
502 * more space per symbol, the u32 is for the index on
503 * the ui browser.
504 * See symbol__browser_index.
505 */
506 symbol_conf.priv_size += sizeof(u32);
507 symbol_conf.sort_by_name = true;
508 }
509 }
483 510
484 if (symbol__init() < 0) 511 if (symbol__init() < 0)
485 return -1; 512 return -1;
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 5161619d4714..9bcc38f0b706 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -455,8 +455,8 @@ static void sched_switch(int cpu, u64 timestamp, struct trace_entry *te)
455 if (p->current->state != TYPE_NONE) 455 if (p->current->state != TYPE_NONE)
456 pid_put_sample(sw->next_pid, p->current->state, cpu, p->current->state_since, timestamp); 456 pid_put_sample(sw->next_pid, p->current->state, cpu, p->current->state_since, timestamp);
457 457
458 p->current->state_since = timestamp; 458 p->current->state_since = timestamp;
459 p->current->state = TYPE_RUNNING; 459 p->current->state = TYPE_RUNNING;
460 } 460 }
461 461
462 if (prev_p->current) { 462 if (prev_p->current) {
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 294da725a57d..40a6a2992d15 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1,13 +1,16 @@
1#include "builtin.h" 1#include "builtin.h"
2 2
3#include "util/util.h" 3#include "perf.h"
4#include "util/cache.h" 4#include "util/cache.h"
5#include "util/debug.h"
6#include "util/exec_cmd.h"
7#include "util/header.h"
8#include "util/parse-options.h"
9#include "util/session.h"
5#include "util/symbol.h" 10#include "util/symbol.h"
6#include "util/thread.h" 11#include "util/thread.h"
7#include "util/header.h"
8#include "util/exec_cmd.h"
9#include "util/trace-event.h" 12#include "util/trace-event.h"
10#include "util/session.h" 13#include "util/util.h"
11 14
12static char const *script_name; 15static char const *script_name;
13static char const *generate_script_lang; 16static char const *generate_script_lang;
@@ -59,14 +62,6 @@ static int cleanup_scripting(void)
59 return scripting_ops->stop_script(); 62 return scripting_ops->stop_script();
60} 63}
61 64
62#include "util/parse-options.h"
63
64#include "perf.h"
65#include "util/debug.h"
66
67#include "util/trace-event.h"
68#include "util/exec_cmd.h"
69
70static char const *input_name = "perf.data"; 65static char const *input_name = "perf.data";
71 66
72static int process_sample_event(event_t *event, struct perf_session *session) 67static int process_sample_event(event_t *event, struct perf_session *session)
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index 318dab15d177..f9c7e3ad1aa7 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -23,7 +23,7 @@ int eprintf(int level, const char *fmt, ...)
23 if (verbose >= level) { 23 if (verbose >= level) {
24 va_start(args, fmt); 24 va_start(args, fmt);
25 if (use_browser > 0) 25 if (use_browser > 0)
26 ret = browser__show_help(fmt, args); 26 ret = ui_helpline__show_help(fmt, args);
27 else 27 else
28 ret = vfprintf(stderr, fmt, args); 28 ret = vfprintf(stderr, fmt, args);
29 va_end(args); 29 va_end(args);
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
index 047ac3324ebe..7a17ee061bcb 100644
--- a/tools/perf/util/debug.h
+++ b/tools/perf/util/debug.h
@@ -14,7 +14,7 @@ void trace_event(event_t *event);
14struct ui_progress; 14struct ui_progress;
15 15
16#ifdef NO_NEWT_SUPPORT 16#ifdef NO_NEWT_SUPPORT
17static inline int browser__show_help(const char *format __used, va_list ap __used) 17static inline int ui_helpline__show_help(const char *format __used, va_list ap __used)
18{ 18{
19 return 0; 19 return 0;
20} 20}
@@ -30,10 +30,9 @@ static inline void ui_progress__update(struct ui_progress *self __used,
30 30
31static inline void ui_progress__delete(struct ui_progress *self __used) {} 31static inline void ui_progress__delete(struct ui_progress *self __used) {}
32#else 32#else
33int browser__show_help(const char *format, va_list ap); 33extern char ui_helpline__last_msg[];
34struct ui_progress *ui_progress__new(const char *title, u64 total); 34int ui_helpline__show_help(const char *format, va_list ap);
35void ui_progress__update(struct ui_progress *self, u64 curr); 35#include "ui/progress.h"
36void ui_progress__delete(struct ui_progress *self);
37#endif 36#endif
38 37
39#endif /* __PERF_DEBUG_H */ 38#endif /* __PERF_DEBUG_H */
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index e7263d49bcf0..be22ae6ef055 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -876,6 +876,9 @@ unsigned int hists__sort_list_width(struct hists *self)
876 if (!se->elide) 876 if (!se->elide)
877 ret += 2 + hists__col_len(self, se->se_width_idx); 877 ret += 2 + hists__col_len(self, se->se_width_idx);
878 878
879 if (verbose) /* Addr + origin */
880 ret += 3 + BITS_PER_LONG / 4;
881
879 return ret; 882 return ret;
880} 883}
881 884
@@ -980,9 +983,9 @@ int hist_entry__inc_addr_samples(struct hist_entry *self, u64 ip)
980 return 0; 983 return 0;
981} 984}
982 985
983static struct objdump_line *objdump_line__new(s64 offset, char *line) 986static struct objdump_line *objdump_line__new(s64 offset, char *line, size_t privsize)
984{ 987{
985 struct objdump_line *self = malloc(sizeof(*self)); 988 struct objdump_line *self = malloc(sizeof(*self) + privsize);
986 989
987 if (self != NULL) { 990 if (self != NULL) {
988 self->offset = offset; 991 self->offset = offset;
@@ -1014,7 +1017,7 @@ struct objdump_line *objdump__get_next_ip_line(struct list_head *head,
1014} 1017}
1015 1018
1016static int hist_entry__parse_objdump_line(struct hist_entry *self, FILE *file, 1019static int hist_entry__parse_objdump_line(struct hist_entry *self, FILE *file,
1017 struct list_head *head) 1020 struct list_head *head, size_t privsize)
1018{ 1021{
1019 struct symbol *sym = self->ms.sym; 1022 struct symbol *sym = self->ms.sym;
1020 struct objdump_line *objdump_line; 1023 struct objdump_line *objdump_line;
@@ -1065,7 +1068,7 @@ static int hist_entry__parse_objdump_line(struct hist_entry *self, FILE *file,
1065 offset = -1; 1068 offset = -1;
1066 } 1069 }
1067 1070
1068 objdump_line = objdump_line__new(offset, line); 1071 objdump_line = objdump_line__new(offset, line, privsize);
1069 if (objdump_line == NULL) { 1072 if (objdump_line == NULL) {
1070 free(line); 1073 free(line);
1071 return -1; 1074 return -1;
@@ -1075,7 +1078,8 @@ static int hist_entry__parse_objdump_line(struct hist_entry *self, FILE *file,
1075 return 0; 1078 return 0;
1076} 1079}
1077 1080
1078int hist_entry__annotate(struct hist_entry *self, struct list_head *head) 1081int hist_entry__annotate(struct hist_entry *self, struct list_head *head,
1082 size_t privsize)
1079{ 1083{
1080 struct symbol *sym = self->ms.sym; 1084 struct symbol *sym = self->ms.sym;
1081 struct map *map = self->ms.map; 1085 struct map *map = self->ms.map;
@@ -1140,7 +1144,7 @@ fallback:
1140 goto out_free_filename; 1144 goto out_free_filename;
1141 1145
1142 while (!feof(file)) 1146 while (!feof(file))
1143 if (hist_entry__parse_objdump_line(self, file, head) < 0) 1147 if (hist_entry__parse_objdump_line(self, file, head, privsize) < 0)
1144 break; 1148 break;
1145 1149
1146 pclose(file); 1150 pclose(file);
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 65a48db46a29..587d375d3430 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -101,7 +101,8 @@ size_t hists__fprintf(struct hists *self, struct hists *pair,
101 bool show_displacement, FILE *fp); 101 bool show_displacement, FILE *fp);
102 102
103int hist_entry__inc_addr_samples(struct hist_entry *self, u64 ip); 103int hist_entry__inc_addr_samples(struct hist_entry *self, u64 ip);
104int hist_entry__annotate(struct hist_entry *self, struct list_head *head); 104int hist_entry__annotate(struct hist_entry *self, struct list_head *head,
105 size_t privsize);
105 106
106void hists__filter_by_dso(struct hists *self, const struct dso *dso); 107void hists__filter_by_dso(struct hists *self, const struct dso *dso);
107void hists__filter_by_thread(struct hists *self, const struct thread *thread); 108void hists__filter_by_thread(struct hists *self, const struct thread *thread);
diff --git a/tools/perf/util/include/linux/list.h b/tools/perf/util/include/linux/list.h
index dbe4b814382a..f5ca26e53fbb 100644
--- a/tools/perf/util/include/linux/list.h
+++ b/tools/perf/util/include/linux/list.h
@@ -15,4 +15,12 @@ static inline void list_del_range(struct list_head *begin,
15 begin->prev->next = end->next; 15 begin->prev->next = end->next;
16 end->next->prev = begin->prev; 16 end->next->prev = begin->prev;
17} 17}
18
19/**
20 * list_for_each_from - iterate over a list from one of its nodes
21 * @pos: the &struct list_head to use as a loop cursor, from where to start
22 * @head: the head for your list.
23 */
24#define list_for_each_from(pos, head) \
25 for (; prefetch(pos->next), pos != (head); pos = pos->next)
18#endif 26#endif
diff --git a/tools/perf/util/include/linux/types.h b/tools/perf/util/include/linux/types.h
index 196862a81a21..12de3b8112f9 100644
--- a/tools/perf/util/include/linux/types.h
+++ b/tools/perf/util/include/linux/types.h
@@ -6,4 +6,16 @@
6#define DECLARE_BITMAP(name,bits) \ 6#define DECLARE_BITMAP(name,bits) \
7 unsigned long name[BITS_TO_LONGS(bits)] 7 unsigned long name[BITS_TO_LONGS(bits)]
8 8
9struct list_head {
10 struct list_head *next, *prev;
11};
12
13struct hlist_head {
14 struct hlist_node *first;
15};
16
17struct hlist_node {
18 struct hlist_node *next, **pprev;
19};
20
9#endif 21#endif
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 2e665cb84055..e72f05c3bef0 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1606,8 +1606,10 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
1606 1606
1607 /* Init vmlinux path */ 1607 /* Init vmlinux path */
1608 ret = init_vmlinux(); 1608 ret = init_vmlinux();
1609 if (ret < 0) 1609 if (ret < 0) {
1610 free(pkgs);
1610 return ret; 1611 return ret;
1612 }
1611 1613
1612 /* Loop 1: convert all events */ 1614 /* Loop 1: convert all events */
1613 for (i = 0; i < npevs; i++) { 1615 for (i = 0; i < npevs; i++) {
@@ -1625,10 +1627,13 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
1625 ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs, 1627 ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs,
1626 pkgs[i].ntevs, force_add); 1628 pkgs[i].ntevs, force_add);
1627end: 1629end:
1628 /* Loop 3: cleanup trace events */ 1630 /* Loop 3: cleanup and free trace events */
1629 for (i = 0; i < npevs; i++) 1631 for (i = 0; i < npevs; i++) {
1630 for (j = 0; j < pkgs[i].ntevs; j++) 1632 for (j = 0; j < pkgs[i].ntevs; j++)
1631 clear_probe_trace_event(&pkgs[i].tevs[j]); 1633 clear_probe_trace_event(&pkgs[i].tevs[j]);
1634 free(pkgs[i].tevs);
1635 }
1636 free(pkgs);
1632 1637
1633 return ret; 1638 return ret;
1634} 1639}
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 840f1aabbb74..525136684d4e 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -33,7 +33,6 @@
33#include <ctype.h> 33#include <ctype.h>
34#include <dwarf-regs.h> 34#include <dwarf-regs.h>
35 35
36#include "string.h"
37#include "event.h" 36#include "event.h"
38#include "debug.h" 37#include "debug.h"
39#include "util.h" 38#include "util.h"
@@ -706,8 +705,12 @@ static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf)
706 pf->tvar->value = strdup(pf->pvar->var); 705 pf->tvar->value = strdup(pf->pvar->var);
707 if (pf->tvar->value == NULL) 706 if (pf->tvar->value == NULL)
708 return -ENOMEM; 707 return -ENOMEM;
709 else 708 if (pf->pvar->type) {
710 return 0; 709 pf->tvar->type = strdup(pf->pvar->type);
710 if (pf->tvar->type == NULL)
711 return -ENOMEM;
712 }
713 return 0;
711 } 714 }
712 715
713 pr_debug("Searching '%s' variable in context.\n", 716 pr_debug("Searching '%s' variable in context.\n",
diff --git a/tools/perf/util/pstack.h b/tools/perf/util/pstack.h
index 5ad07023504b..4cedea59f518 100644
--- a/tools/perf/util/pstack.h
+++ b/tools/perf/util/pstack.h
@@ -1,6 +1,8 @@
1#ifndef _PERF_PSTACK_ 1#ifndef _PERF_PSTACK_
2#define _PERF_PSTACK_ 2#define _PERF_PSTACK_
3 3
4#include <stdbool.h>
5
4struct pstack; 6struct pstack;
5struct pstack *pstack__new(unsigned short max_nr_entries); 7struct pstack *pstack__new(unsigned short max_nr_entries);
6void pstack__delete(struct pstack *self); 8void pstack__delete(struct pstack *self);
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 1c61a4f4aa8a..b62a553cc67d 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -196,7 +196,8 @@ static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf,
196 196
197 if (verbose) { 197 if (verbose) {
198 char o = self->ms.map ? dso__symtab_origin(self->ms.map->dso) : '!'; 198 char o = self->ms.map ? dso__symtab_origin(self->ms.map->dso) : '!';
199 ret += repsep_snprintf(bf, size, "%#018llx %c ", self->ip, o); 199 ret += repsep_snprintf(bf, size, "%*Lx %c ",
200 BITS_PER_LONG / 4, self->ip, o);
200 } 201 }
201 202
202 ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", self->level); 203 ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", self->level);
@@ -204,7 +205,8 @@ static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf,
204 ret += repsep_snprintf(bf + ret, size - ret, "%s", 205 ret += repsep_snprintf(bf + ret, size - ret, "%s",
205 self->ms.sym->name); 206 self->ms.sym->name);
206 else 207 else
207 ret += repsep_snprintf(bf + ret, size - ret, "%#016llx", self->ip); 208 ret += repsep_snprintf(bf + ret, size - ret, "%*Lx",
209 BITS_PER_LONG / 4, self->ip);
208 210
209 return ret; 211 return ret;
210} 212}
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 6f0dd90c36ce..1a367734e016 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -131,7 +131,8 @@ static void map_groups__fixup_end(struct map_groups *self)
131 __map_groups__fixup_end(self, i); 131 __map_groups__fixup_end(self, i);
132} 132}
133 133
134static struct symbol *symbol__new(u64 start, u64 len, const char *name) 134static struct symbol *symbol__new(u64 start, u64 len, u8 binding,
135 const char *name)
135{ 136{
136 size_t namelen = strlen(name) + 1; 137 size_t namelen = strlen(name) + 1;
137 struct symbol *self = calloc(1, (symbol_conf.priv_size + 138 struct symbol *self = calloc(1, (symbol_conf.priv_size +
@@ -144,6 +145,7 @@ static struct symbol *symbol__new(u64 start, u64 len, const char *name)
144 145
145 self->start = start; 146 self->start = start;
146 self->end = len ? start + len - 1 : start; 147 self->end = len ? start + len - 1 : start;
148 self->binding = binding;
147 self->namelen = namelen - 1; 149 self->namelen = namelen - 1;
148 150
149 pr_debug4("%s: %s %#Lx-%#Lx\n", __func__, name, start, self->end); 151 pr_debug4("%s: %s %#Lx-%#Lx\n", __func__, name, start, self->end);
@@ -160,8 +162,11 @@ void symbol__delete(struct symbol *self)
160 162
161static size_t symbol__fprintf(struct symbol *self, FILE *fp) 163static size_t symbol__fprintf(struct symbol *self, FILE *fp)
162{ 164{
163 return fprintf(fp, " %llx-%llx %s\n", 165 return fprintf(fp, " %llx-%llx %c %s\n",
164 self->start, self->end, self->name); 166 self->start, self->end,
167 self->binding == STB_GLOBAL ? 'g' :
168 self->binding == STB_LOCAL ? 'l' : 'w',
169 self->name);
165} 170}
166 171
167void dso__set_long_name(struct dso *self, char *name) 172void dso__set_long_name(struct dso *self, char *name)
@@ -453,6 +458,14 @@ struct process_kallsyms_args {
453 struct dso *dso; 458 struct dso *dso;
454}; 459};
455 460
461static u8 kallsyms2elf_type(char type)
462{
463 if (type == 'W')
464 return STB_WEAK;
465
466 return isupper(type) ? STB_GLOBAL : STB_LOCAL;
467}
468
456static int map__process_kallsym_symbol(void *arg, const char *name, 469static int map__process_kallsym_symbol(void *arg, const char *name,
457 char type, u64 start) 470 char type, u64 start)
458{ 471{
@@ -466,7 +479,7 @@ static int map__process_kallsym_symbol(void *arg, const char *name,
466 /* 479 /*
467 * Will fix up the end later, when we have all symbols sorted. 480 * Will fix up the end later, when we have all symbols sorted.
468 */ 481 */
469 sym = symbol__new(start, 0, name); 482 sym = symbol__new(start, 0, kallsyms2elf_type(type), name);
470 483
471 if (sym == NULL) 484 if (sym == NULL)
472 return -ENOMEM; 485 return -ENOMEM;
@@ -661,7 +674,7 @@ static int dso__load_perf_map(struct dso *self, struct map *map,
661 if (len + 2 >= line_len) 674 if (len + 2 >= line_len)
662 continue; 675 continue;
663 676
664 sym = symbol__new(start, size, line + len); 677 sym = symbol__new(start, size, STB_GLOBAL, line + len);
665 678
666 if (sym == NULL) 679 if (sym == NULL)
667 goto out_delete_line; 680 goto out_delete_line;
@@ -873,7 +886,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, struct map *map,
873 "%s@plt", elf_sym__name(&sym, symstrs)); 886 "%s@plt", elf_sym__name(&sym, symstrs));
874 887
875 f = symbol__new(plt_offset, shdr_plt.sh_entsize, 888 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
876 sympltname); 889 STB_GLOBAL, sympltname);
877 if (!f) 890 if (!f)
878 goto out_elf_end; 891 goto out_elf_end;
879 892
@@ -895,7 +908,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, struct map *map,
895 "%s@plt", elf_sym__name(&sym, symstrs)); 908 "%s@plt", elf_sym__name(&sym, symstrs));
896 909
897 f = symbol__new(plt_offset, shdr_plt.sh_entsize, 910 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
898 sympltname); 911 STB_GLOBAL, sympltname);
899 if (!f) 912 if (!f)
900 goto out_elf_end; 913 goto out_elf_end;
901 914
@@ -1066,6 +1079,16 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
1066 if (!is_label && !elf_sym__is_a(&sym, map->type)) 1079 if (!is_label && !elf_sym__is_a(&sym, map->type))
1067 continue; 1080 continue;
1068 1081
1082 /* Reject ARM ELF "mapping symbols": these aren't unique and
1083 * don't identify functions, so will confuse the profile
1084 * output: */
1085 if (ehdr.e_machine == EM_ARM) {
1086 if (!strcmp(elf_name, "$a") ||
1087 !strcmp(elf_name, "$d") ||
1088 !strcmp(elf_name, "$t"))
1089 continue;
1090 }
1091
1069 if (opdsec && sym.st_shndx == opdidx) { 1092 if (opdsec && sym.st_shndx == opdidx) {
1070 u32 offset = sym.st_value - opdshdr.sh_addr; 1093 u32 offset = sym.st_value - opdshdr.sh_addr;
1071 u64 *opd = opddata->d_buf + offset; 1094 u64 *opd = opddata->d_buf + offset;
@@ -1146,7 +1169,8 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
1146 if (demangled != NULL) 1169 if (demangled != NULL)
1147 elf_name = demangled; 1170 elf_name = demangled;
1148new_symbol: 1171new_symbol:
1149 f = symbol__new(sym.st_value, sym.st_size, elf_name); 1172 f = symbol__new(sym.st_value, sym.st_size,
1173 GELF_ST_BIND(sym.st_info), elf_name);
1150 free(demangled); 1174 free(demangled);
1151 if (!f) 1175 if (!f)
1152 goto out_elf_end; 1176 goto out_elf_end;
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 906be20011d9..b7a8da4af5a0 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -53,6 +53,7 @@ struct symbol {
53 u64 start; 53 u64 start;
54 u64 end; 54 u64 end;
55 u16 namelen; 55 u16 namelen;
56 u8 binding;
56 char name[0]; 57 char name[0];
57}; 58};
58 59
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c
new file mode 100644
index 000000000000..66f2d583d8c4
--- /dev/null
+++ b/tools/perf/util/ui/browser.c
@@ -0,0 +1,329 @@
1#define _GNU_SOURCE
2#include <stdio.h>
3#undef _GNU_SOURCE
4/*
5 * slang versions <= 2.0.6 have a "#if HAVE_LONG_LONG" that breaks
6 * the build if it isn't defined. Use the equivalent one that glibc
7 * has on features.h.
8 */
9#include <features.h>
10#ifndef HAVE_LONG_LONG
11#define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG
12#endif
13#include <slang.h>
14#include <linux/list.h>
15#include <linux/rbtree.h>
16#include <stdlib.h>
17#include <sys/ttydefaults.h>
18#include "browser.h"
19#include "helpline.h"
20#include "../color.h"
21#include "../util.h"
22
23#if SLANG_VERSION < 20104
24#define sltt_set_color(obj, name, fg, bg) \
25 SLtt_set_color(obj,(char *)name, (char *)fg, (char *)bg)
26#else
27#define sltt_set_color SLtt_set_color
28#endif
29
30newtComponent newt_form__new(void);
31
32int ui_browser__percent_color(double percent, bool current)
33{
34 if (current)
35 return HE_COLORSET_SELECTED;
36 if (percent >= MIN_RED)
37 return HE_COLORSET_TOP;
38 if (percent >= MIN_GREEN)
39 return HE_COLORSET_MEDIUM;
40 return HE_COLORSET_NORMAL;
41}
42
43void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence)
44{
45 struct list_head *head = self->entries;
46 struct list_head *pos;
47
48 switch (whence) {
49 case SEEK_SET:
50 pos = head->next;
51 break;
52 case SEEK_CUR:
53 pos = self->top;
54 break;
55 case SEEK_END:
56 pos = head->prev;
57 break;
58 default:
59 return;
60 }
61
62 if (offset > 0) {
63 while (offset-- != 0)
64 pos = pos->next;
65 } else {
66 while (offset++ != 0)
67 pos = pos->prev;
68 }
69
70 self->top = pos;
71}
72
73void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence)
74{
75 struct rb_root *root = self->entries;
76 struct rb_node *nd;
77
78 switch (whence) {
79 case SEEK_SET:
80 nd = rb_first(root);
81 break;
82 case SEEK_CUR:
83 nd = self->top;
84 break;
85 case SEEK_END:
86 nd = rb_last(root);
87 break;
88 default:
89 return;
90 }
91
92 if (offset > 0) {
93 while (offset-- != 0)
94 nd = rb_next(nd);
95 } else {
96 while (offset++ != 0)
97 nd = rb_prev(nd);
98 }
99
100 self->top = nd;
101}
102
103unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self)
104{
105 struct rb_node *nd;
106 int row = 0;
107
108 if (self->top == NULL)
109 self->top = rb_first(self->entries);
110
111 nd = self->top;
112
113 while (nd != NULL) {
114 SLsmg_gotorc(self->y + row, self->x);
115 self->write(self, nd, row);
116 if (++row == self->height)
117 break;
118 nd = rb_next(nd);
119 }
120
121 return row;
122}
123
124bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row)
125{
126 return self->top_idx + row == self->index;
127}
128
129void ui_browser__refresh_dimensions(struct ui_browser *self)
130{
131 int cols, rows;
132 newtGetScreenSize(&cols, &rows);
133
134 if (self->width > cols - 4)
135 self->width = cols - 4;
136 self->height = rows - 5;
137 if (self->height > self->nr_entries)
138 self->height = self->nr_entries;
139 self->y = (rows - self->height) / 2;
140 self->x = (cols - self->width) / 2;
141}
142
143void ui_browser__reset_index(struct ui_browser *self)
144{
145 self->index = self->top_idx = 0;
146 self->seek(self, 0, SEEK_SET);
147}
148
149int ui_browser__show(struct ui_browser *self, const char *title,
150 const char *helpline, ...)
151{
152 va_list ap;
153
154 if (self->form != NULL) {
155 newtFormDestroy(self->form);
156 newtPopWindow();
157 }
158 ui_browser__refresh_dimensions(self);
159 newtCenteredWindow(self->width, self->height, title);
160 self->form = newt_form__new();
161 if (self->form == NULL)
162 return -1;
163
164 self->sb = newtVerticalScrollbar(self->width, 0, self->height,
165 HE_COLORSET_NORMAL,
166 HE_COLORSET_SELECTED);
167 if (self->sb == NULL)
168 return -1;
169
170 newtFormAddHotKey(self->form, NEWT_KEY_UP);
171 newtFormAddHotKey(self->form, NEWT_KEY_DOWN);
172 newtFormAddHotKey(self->form, NEWT_KEY_PGUP);
173 newtFormAddHotKey(self->form, NEWT_KEY_PGDN);
174 newtFormAddHotKey(self->form, NEWT_KEY_HOME);
175 newtFormAddHotKey(self->form, NEWT_KEY_END);
176 newtFormAddHotKey(self->form, ' ');
177 newtFormAddComponent(self->form, self->sb);
178
179 va_start(ap, helpline);
180 ui_helpline__vpush(helpline, ap);
181 va_end(ap);
182 return 0;
183}
184
185void ui_browser__hide(struct ui_browser *self)
186{
187 newtFormDestroy(self->form);
188 newtPopWindow();
189 self->form = NULL;
190 ui_helpline__pop();
191}
192
193int ui_browser__refresh(struct ui_browser *self)
194{
195 int row;
196
197 newtScrollbarSet(self->sb, self->index, self->nr_entries - 1);
198 row = self->refresh(self);
199 SLsmg_set_color(HE_COLORSET_NORMAL);
200 SLsmg_fill_region(self->y + row, self->x,
201 self->height - row, self->width, ' ');
202
203 return 0;
204}
205
206int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es)
207{
208 if (ui_browser__refresh(self) < 0)
209 return -1;
210
211 while (1) {
212 off_t offset;
213
214 newtFormRun(self->form, es);
215
216 if (es->reason != NEWT_EXIT_HOTKEY)
217 break;
218 if (is_exit_key(es->u.key))
219 return es->u.key;
220 switch (es->u.key) {
221 case NEWT_KEY_DOWN:
222 if (self->index == self->nr_entries - 1)
223 break;
224 ++self->index;
225 if (self->index == self->top_idx + self->height) {
226 ++self->top_idx;
227 self->seek(self, +1, SEEK_CUR);
228 }
229 break;
230 case NEWT_KEY_UP:
231 if (self->index == 0)
232 break;
233 --self->index;
234 if (self->index < self->top_idx) {
235 --self->top_idx;
236 self->seek(self, -1, SEEK_CUR);
237 }
238 break;
239 case NEWT_KEY_PGDN:
240 case ' ':
241 if (self->top_idx + self->height > self->nr_entries - 1)
242 break;
243
244 offset = self->height;
245 if (self->index + offset > self->nr_entries - 1)
246 offset = self->nr_entries - 1 - self->index;
247 self->index += offset;
248 self->top_idx += offset;
249 self->seek(self, +offset, SEEK_CUR);
250 break;
251 case NEWT_KEY_PGUP:
252 if (self->top_idx == 0)
253 break;
254
255 if (self->top_idx < self->height)
256 offset = self->top_idx;
257 else
258 offset = self->height;
259
260 self->index -= offset;
261 self->top_idx -= offset;
262 self->seek(self, -offset, SEEK_CUR);
263 break;
264 case NEWT_KEY_HOME:
265 ui_browser__reset_index(self);
266 break;
267 case NEWT_KEY_END:
268 offset = self->height - 1;
269 if (offset >= self->nr_entries)
270 offset = self->nr_entries - 1;
271
272 self->index = self->nr_entries - 1;
273 self->top_idx = self->index - offset;
274 self->seek(self, -offset, SEEK_END);
275 break;
276 default:
277 return es->u.key;
278 }
279 if (ui_browser__refresh(self) < 0)
280 return -1;
281 }
282 return 0;
283}
284
285unsigned int ui_browser__list_head_refresh(struct ui_browser *self)
286{
287 struct list_head *pos;
288 struct list_head *head = self->entries;
289 int row = 0;
290
291 if (self->top == NULL || self->top == self->entries)
292 self->top = head->next;
293
294 pos = self->top;
295
296 list_for_each_from(pos, head) {
297 SLsmg_gotorc(self->y + row, self->x);
298 self->write(self, pos, row);
299 if (++row == self->height)
300 break;
301 }
302
303 return row;
304}
305
306static struct newtPercentTreeColors {
307 const char *topColorFg, *topColorBg;
308 const char *mediumColorFg, *mediumColorBg;
309 const char *normalColorFg, *normalColorBg;
310 const char *selColorFg, *selColorBg;
311 const char *codeColorFg, *codeColorBg;
312} defaultPercentTreeColors = {
313 "red", "lightgray",
314 "green", "lightgray",
315 "black", "lightgray",
316 "lightgray", "magenta",
317 "blue", "lightgray",
318};
319
320void ui_browser__init(void)
321{
322 struct newtPercentTreeColors *c = &defaultPercentTreeColors;
323
324 sltt_set_color(HE_COLORSET_TOP, NULL, c->topColorFg, c->topColorBg);
325 sltt_set_color(HE_COLORSET_MEDIUM, NULL, c->mediumColorFg, c->mediumColorBg);
326 sltt_set_color(HE_COLORSET_NORMAL, NULL, c->normalColorFg, c->normalColorBg);
327 sltt_set_color(HE_COLORSET_SELECTED, NULL, c->selColorFg, c->selColorBg);
328 sltt_set_color(HE_COLORSET_CODE, NULL, c->codeColorFg, c->codeColorBg);
329}
diff --git a/tools/perf/util/ui/browser.h b/tools/perf/util/ui/browser.h
new file mode 100644
index 000000000000..0b9f829214f7
--- /dev/null
+++ b/tools/perf/util/ui/browser.h
@@ -0,0 +1,46 @@
1#ifndef _PERF_UI_BROWSER_H_
2#define _PERF_UI_BROWSER_H_ 1
3
4#include <stdbool.h>
5#include <newt.h>
6#include <sys/types.h>
7#include "../types.h"
8
9#define HE_COLORSET_TOP 50
10#define HE_COLORSET_MEDIUM 51
11#define HE_COLORSET_NORMAL 52
12#define HE_COLORSET_SELECTED 53
13#define HE_COLORSET_CODE 54
14
15struct ui_browser {
16 newtComponent form, sb;
17 u64 index, top_idx;
18 void *top, *entries;
19 u16 y, x, width, height;
20 void *priv;
21 unsigned int (*refresh)(struct ui_browser *self);
22 void (*write)(struct ui_browser *self, void *entry, int row);
23 void (*seek)(struct ui_browser *self, off_t offset, int whence);
24 u32 nr_entries;
25};
26
27
28int ui_browser__percent_color(double percent, bool current);
29bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row);
30void ui_browser__refresh_dimensions(struct ui_browser *self);
31void ui_browser__reset_index(struct ui_browser *self);
32
33int ui_browser__show(struct ui_browser *self, const char *title,
34 const char *helpline, ...);
35void ui_browser__hide(struct ui_browser *self);
36int ui_browser__refresh(struct ui_browser *self);
37int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es);
38
39void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence);
40unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self);
41
42void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence);
43unsigned int ui_browser__list_head_refresh(struct ui_browser *self);
44
45void ui_browser__init(void);
46#endif /* _PERF_UI_BROWSER_H_ */
diff --git a/tools/perf/util/ui/browsers/annotate.c b/tools/perf/util/ui/browsers/annotate.c
new file mode 100644
index 000000000000..55ff792459ac
--- /dev/null
+++ b/tools/perf/util/ui/browsers/annotate.c
@@ -0,0 +1,240 @@
1#include "../browser.h"
2#include "../helpline.h"
3#include "../libslang.h"
4#include "../../hist.h"
5#include "../../sort.h"
6#include "../../symbol.h"
7
8static void ui__error_window(const char *fmt, ...)
9{
10 va_list ap;
11
12 va_start(ap, fmt);
13 newtWinMessagev((char *)"Error", (char *)"Ok", (char *)fmt, ap);
14 va_end(ap);
15}
16
17struct annotate_browser {
18 struct ui_browser b;
19 struct rb_root entries;
20 struct rb_node *curr_hot;
21};
22
23struct objdump_line_rb_node {
24 struct rb_node rb_node;
25 double percent;
26 u32 idx;
27};
28
29static inline
30struct objdump_line_rb_node *objdump_line__rb(struct objdump_line *self)
31{
32 return (struct objdump_line_rb_node *)(self + 1);
33}
34
35static void annotate_browser__write(struct ui_browser *self, void *entry, int row)
36{
37 struct objdump_line *ol = rb_entry(entry, struct objdump_line, node);
38 bool current_entry = ui_browser__is_current_entry(self, row);
39 int width = self->width;
40
41 if (ol->offset != -1) {
42 struct objdump_line_rb_node *olrb = objdump_line__rb(ol);
43 int color = ui_browser__percent_color(olrb->percent, current_entry);
44 SLsmg_set_color(color);
45 slsmg_printf(" %7.2f ", olrb->percent);
46 if (!current_entry)
47 SLsmg_set_color(HE_COLORSET_CODE);
48 } else {
49 int color = ui_browser__percent_color(0, current_entry);
50 SLsmg_set_color(color);
51 slsmg_write_nstring(" ", 9);
52 }
53
54 SLsmg_write_char(':');
55 slsmg_write_nstring(" ", 8);
56 if (!*ol->line)
57 slsmg_write_nstring(" ", width - 18);
58 else
59 slsmg_write_nstring(ol->line, width - 18);
60}
61
62static double objdump_line__calc_percent(struct objdump_line *self,
63 struct list_head *head,
64 struct symbol *sym)
65{
66 double percent = 0.0;
67
68 if (self->offset != -1) {
69 int len = sym->end - sym->start;
70 unsigned int hits = 0;
71 struct sym_priv *priv = symbol__priv(sym);
72 struct sym_ext *sym_ext = priv->ext;
73 struct sym_hist *h = priv->hist;
74 s64 offset = self->offset;
75 struct objdump_line *next = objdump__get_next_ip_line(head, self);
76
77
78 while (offset < (s64)len &&
79 (next == NULL || offset < next->offset)) {
80 if (sym_ext) {
81 percent += sym_ext[offset].percent;
82 } else
83 hits += h->ip[offset];
84
85 ++offset;
86 }
87
88 if (sym_ext == NULL && h->sum)
89 percent = 100.0 * hits / h->sum;
90 }
91
92 return percent;
93}
94
95static void objdump__insert_line(struct rb_root *self,
96 struct objdump_line_rb_node *line)
97{
98 struct rb_node **p = &self->rb_node;
99 struct rb_node *parent = NULL;
100 struct objdump_line_rb_node *l;
101
102 while (*p != NULL) {
103 parent = *p;
104 l = rb_entry(parent, struct objdump_line_rb_node, rb_node);
105 if (line->percent < l->percent)
106 p = &(*p)->rb_left;
107 else
108 p = &(*p)->rb_right;
109 }
110 rb_link_node(&line->rb_node, parent, p);
111 rb_insert_color(&line->rb_node, self);
112}
113
114static void annotate_browser__set_top(struct annotate_browser *self,
115 struct rb_node *nd)
116{
117 struct objdump_line_rb_node *rbpos;
118 struct objdump_line *pos;
119 unsigned back;
120
121 ui_browser__refresh_dimensions(&self->b);
122 back = self->b.height / 2;
123 rbpos = rb_entry(nd, struct objdump_line_rb_node, rb_node);
124 pos = ((struct objdump_line *)rbpos) - 1;
125 self->b.top_idx = self->b.index = rbpos->idx;
126
127 while (self->b.top_idx != 0 && back != 0) {
128 pos = list_entry(pos->node.prev, struct objdump_line, node);
129
130 --self->b.top_idx;
131 --back;
132 }
133
134 self->b.top = pos;
135 self->curr_hot = nd;
136}
137
138static int annotate_browser__run(struct annotate_browser *self,
139 struct newtExitStruct *es)
140{
141 struct rb_node *nd;
142 struct hist_entry *he = self->b.priv;
143
144 if (ui_browser__show(&self->b, he->ms.sym->name,
145 "<- or ESC: exit, TAB/shift+TAB: cycle thru samples") < 0)
146 return -1;
147
148 newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT);
149
150 nd = self->curr_hot;
151 if (nd) {
152 newtFormAddHotKey(self->b.form, NEWT_KEY_TAB);
153 newtFormAddHotKey(self->b.form, NEWT_KEY_UNTAB);
154 }
155
156 while (1) {
157 ui_browser__run(&self->b, es);
158
159 if (es->reason != NEWT_EXIT_HOTKEY)
160 break;
161
162 switch (es->u.key) {
163 case NEWT_KEY_TAB:
164 nd = rb_prev(nd);
165 if (nd == NULL)
166 nd = rb_last(&self->entries);
167 annotate_browser__set_top(self, nd);
168 break;
169 case NEWT_KEY_UNTAB:
170 nd = rb_next(nd);
171 if (nd == NULL)
172 nd = rb_first(&self->entries);
173 annotate_browser__set_top(self, nd);
174 break;
175 default:
176 goto out;
177 }
178 }
179out:
180 ui_browser__hide(&self->b);
181 return 0;
182}
183
184int hist_entry__tui_annotate(struct hist_entry *self)
185{
186 struct newtExitStruct es;
187 struct objdump_line *pos, *n;
188 struct objdump_line_rb_node *rbpos;
189 LIST_HEAD(head);
190 struct annotate_browser browser = {
191 .b = {
192 .entries = &head,
193 .refresh = ui_browser__list_head_refresh,
194 .seek = ui_browser__list_head_seek,
195 .write = annotate_browser__write,
196 .priv = self,
197 },
198 };
199 int ret;
200
201 if (self->ms.sym == NULL)
202 return -1;
203
204 if (self->ms.map->dso->annotate_warned)
205 return -1;
206
207 if (hist_entry__annotate(self, &head, sizeof(*rbpos)) < 0) {
208 ui__error_window(ui_helpline__last_msg);
209 return -1;
210 }
211
212 ui_helpline__push("Press <- or ESC to exit");
213
214 list_for_each_entry(pos, &head, node) {
215 size_t line_len = strlen(pos->line);
216 if (browser.b.width < line_len)
217 browser.b.width = line_len;
218 rbpos = objdump_line__rb(pos);
219 rbpos->idx = browser.b.nr_entries++;
220 rbpos->percent = objdump_line__calc_percent(pos, &head, self->ms.sym);
221 if (rbpos->percent < 0.01)
222 continue;
223 objdump__insert_line(&browser.entries, rbpos);
224 }
225
226 /*
227 * Position the browser at the hottest line.
228 */
229 browser.curr_hot = rb_last(&browser.entries);
230 if (browser.curr_hot)
231 annotate_browser__set_top(&browser, browser.curr_hot);
232
233 browser.b.width += 18; /* Percentage */
234 ret = annotate_browser__run(&browser, &es);
235 list_for_each_entry_safe(pos, n, &head, node) {
236 list_del(&pos->node);
237 objdump_line__free(pos);
238 }
239 return ret;
240}
diff --git a/tools/perf/util/newt.c b/tools/perf/util/ui/browsers/hists.c
index 91de99b58445..dafdf6775d77 100644
--- a/tools/perf/util/newt.c
+++ b/tools/perf/util/ui/browsers/hists.c
@@ -1,978 +1,272 @@
1#define _GNU_SOURCE 1#define _GNU_SOURCE
2#include <stdio.h> 2#include <stdio.h>
3#undef _GNU_SOURCE 3#undef _GNU_SOURCE
4/* 4#include "../libslang.h"
5 * slang versions <= 2.0.6 have a "#if HAVE_LONG_LONG" that breaks
6 * the build if it isn't defined. Use the equivalent one that glibc
7 * has on features.h.
8 */
9#include <features.h>
10#ifndef HAVE_LONG_LONG
11#define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG
12#endif
13#include <slang.h>
14#include <signal.h>
15#include <stdlib.h> 5#include <stdlib.h>
6#include <string.h>
16#include <newt.h> 7#include <newt.h>
17#include <sys/ttydefaults.h> 8#include <linux/rbtree.h>
18
19#include "cache.h"
20#include "hist.h"
21#include "pstack.h"
22#include "session.h"
23#include "sort.h"
24#include "symbol.h"
25
26#if SLANG_VERSION < 20104
27#define slsmg_printf(msg, args...) SLsmg_printf((char *)msg, ##args)
28#define slsmg_write_nstring(msg, len) SLsmg_write_nstring((char *)msg, len)
29#define sltt_set_color(obj, name, fg, bg) SLtt_set_color(obj,(char *)name,\
30 (char *)fg, (char *)bg)
31#else
32#define slsmg_printf SLsmg_printf
33#define slsmg_write_nstring SLsmg_write_nstring
34#define sltt_set_color SLtt_set_color
35#endif
36
37struct ui_progress {
38 newtComponent form, scale;
39};
40
41struct ui_progress *ui_progress__new(const char *title, u64 total)
42{
43 struct ui_progress *self = malloc(sizeof(*self));
44
45 if (self != NULL) {
46 int cols;
47
48 if (use_browser <= 0)
49 return self;
50 newtGetScreenSize(&cols, NULL);
51 cols -= 4;
52 newtCenteredWindow(cols, 1, title);
53 self->form = newtForm(NULL, NULL, 0);
54 if (self->form == NULL)
55 goto out_free_self;
56 self->scale = newtScale(0, 0, cols, total);
57 if (self->scale == NULL)
58 goto out_free_form;
59 newtFormAddComponent(self->form, self->scale);
60 newtRefresh();
61 }
62
63 return self;
64
65out_free_form:
66 newtFormDestroy(self->form);
67out_free_self:
68 free(self);
69 return NULL;
70}
71
72void ui_progress__update(struct ui_progress *self, u64 curr)
73{
74 /*
75 * FIXME: We should have a per UI backend way of showing progress,
76 * stdio will just show a percentage as NN%, etc.
77 */
78 if (use_browser <= 0)
79 return;
80 newtScaleSet(self->scale, curr);
81 newtRefresh();
82}
83 9
84void ui_progress__delete(struct ui_progress *self) 10#include "../../hist.h"
85{ 11#include "../../pstack.h"
86 if (use_browser > 0) { 12#include "../../sort.h"
87 newtFormDestroy(self->form); 13#include "../../util.h"
88 newtPopWindow();
89 }
90 free(self);
91}
92 14
93static void ui_helpline__pop(void) 15#include "../browser.h"
94{ 16#include "../helpline.h"
95 newtPopHelpLine(); 17#include "../util.h"
96} 18#include "map.h"
97 19
98static void ui_helpline__push(const char *msg) 20struct hist_browser {
99{ 21 struct ui_browser b;
100 newtPushHelpLine(msg); 22 struct hists *hists;
101} 23 struct hist_entry *he_selection;
24 struct map_symbol *selection;
25};
102 26
103static void ui_helpline__vpush(const char *fmt, va_list ap) 27static void hist_browser__refresh_dimensions(struct hist_browser *self)
104{ 28{
105 char *s; 29 /* 3 == +/- toggle symbol before actual hist_entry rendering */
106 30 self->b.width = 3 + (hists__sort_list_width(self->hists) +
107 if (vasprintf(&s, fmt, ap) < 0) 31 sizeof("[k]"));
108 vfprintf(stderr, fmt, ap);
109 else {
110 ui_helpline__push(s);
111 free(s);
112 }
113} 32}
114 33
115static void ui_helpline__fpush(const char *fmt, ...) 34static void hist_browser__reset(struct hist_browser *self)
116{ 35{
117 va_list ap; 36 self->b.nr_entries = self->hists->nr_entries;
118 37 hist_browser__refresh_dimensions(self);
119 va_start(ap, fmt); 38 ui_browser__reset_index(&self->b);
120 ui_helpline__vpush(fmt, ap);
121 va_end(ap);
122} 39}
123 40
124static void ui_helpline__puts(const char *msg) 41static char tree__folded_sign(bool unfolded)
125{ 42{
126 ui_helpline__pop(); 43 return unfolded ? '-' : '+';
127 ui_helpline__push(msg);
128} 44}
129 45
130static char browser__last_msg[1024]; 46static char map_symbol__folded(const struct map_symbol *self)
131
132int browser__show_help(const char *format, va_list ap)
133{ 47{
134 int ret; 48 return self->has_children ? tree__folded_sign(self->unfolded) : ' ';
135 static int backlog;
136
137 ret = vsnprintf(browser__last_msg + backlog,
138 sizeof(browser__last_msg) - backlog, format, ap);
139 backlog += ret;
140
141 if (browser__last_msg[backlog - 1] == '\n') {
142 ui_helpline__puts(browser__last_msg);
143 newtRefresh();
144 backlog = 0;
145 }
146
147 return ret;
148} 49}
149 50
150static void newt_form__set_exit_keys(newtComponent self) 51static char hist_entry__folded(const struct hist_entry *self)
151{ 52{
152 newtFormAddHotKey(self, NEWT_KEY_LEFT); 53 return map_symbol__folded(&self->ms);
153 newtFormAddHotKey(self, NEWT_KEY_ESCAPE);
154 newtFormAddHotKey(self, 'Q');
155 newtFormAddHotKey(self, 'q');
156 newtFormAddHotKey(self, CTRL('c'));
157} 54}
158 55
159static newtComponent newt_form__new(void) 56static char callchain_list__folded(const struct callchain_list *self)
160{ 57{
161 newtComponent self = newtForm(NULL, NULL, 0); 58 return map_symbol__folded(&self->ms);
162 if (self)
163 newt_form__set_exit_keys(self);
164 return self;
165} 59}
166 60
167static int popup_menu(int argc, char * const argv[]) 61static int callchain_node__count_rows_rb_tree(struct callchain_node *self)
168{ 62{
169 struct newtExitStruct es; 63 int n = 0;
170 int i, rc = -1, max_len = 5; 64 struct rb_node *nd;
171 newtComponent listbox, form = newt_form__new();
172
173 if (form == NULL)
174 return -1;
175 65
176 listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT); 66 for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) {
177 if (listbox == NULL) 67 struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node);
178 goto out_destroy_form; 68 struct callchain_list *chain;
69 char folded_sign = ' '; /* No children */
179 70
180 newtFormAddComponent(form, listbox); 71 list_for_each_entry(chain, &child->val, list) {
72 ++n;
73 /* We need this because we may not have children */
74 folded_sign = callchain_list__folded(chain);
75 if (folded_sign == '+')
76 break;
77 }
181 78
182 for (i = 0; i < argc; ++i) { 79 if (folded_sign == '-') /* Have children and they're unfolded */
183 int len = strlen(argv[i]); 80 n += callchain_node__count_rows_rb_tree(child);
184 if (len > max_len)
185 max_len = len;
186 if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i))
187 goto out_destroy_form;
188 } 81 }
189 82
190 newtCenteredWindow(max_len, argc, NULL); 83 return n;
191 newtFormRun(form, &es);
192 rc = newtListboxGetCurrent(listbox) - NULL;
193 if (es.reason == NEWT_EXIT_HOTKEY)
194 rc = -1;
195 newtPopWindow();
196out_destroy_form:
197 newtFormDestroy(form);
198 return rc;
199} 84}
200 85
201static int ui__help_window(const char *text) 86static int callchain_node__count_rows(struct callchain_node *node)
202{ 87{
203 struct newtExitStruct es; 88 struct callchain_list *chain;
204 newtComponent tb, form = newt_form__new(); 89 bool unfolded = false;
205 int rc = -1; 90 int n = 0;
206 int max_len = 0, nr_lines = 0;
207 const char *t;
208
209 if (form == NULL)
210 return -1;
211 91
212 t = text; 92 list_for_each_entry(chain, &node->val, list) {
213 while (1) { 93 ++n;
214 const char *sep = strchr(t, '\n'); 94 unfolded = chain->ms.unfolded;
215 int len;
216
217 if (sep == NULL)
218 sep = strchr(t, '\0');
219 len = sep - t;
220 if (max_len < len)
221 max_len = len;
222 ++nr_lines;
223 if (*sep == '\0')
224 break;
225 t = sep + 1;
226 } 95 }
227 96
228 tb = newtTextbox(0, 0, max_len, nr_lines, 0); 97 if (unfolded)
229 if (tb == NULL) 98 n += callchain_node__count_rows_rb_tree(node);
230 goto out_destroy_form;
231
232 newtTextboxSetText(tb, text);
233 newtFormAddComponent(form, tb);
234 newtCenteredWindow(max_len, nr_lines, NULL);
235 newtFormRun(form, &es);
236 newtPopWindow();
237 rc = 0;
238out_destroy_form:
239 newtFormDestroy(form);
240 return rc;
241}
242
243static bool dialog_yesno(const char *msg)
244{
245 /* newtWinChoice should really be accepting const char pointers... */
246 char yes[] = "Yes", no[] = "No";
247 return newtWinChoice(NULL, yes, no, (char *)msg) == 1;
248}
249
250static void ui__error_window(const char *fmt, ...)
251{
252 va_list ap;
253
254 va_start(ap, fmt);
255 newtWinMessagev((char *)"Error", (char *)"Ok", (char *)fmt, ap);
256 va_end(ap);
257}
258
259#define HE_COLORSET_TOP 50
260#define HE_COLORSET_MEDIUM 51
261#define HE_COLORSET_NORMAL 52
262#define HE_COLORSET_SELECTED 53
263#define HE_COLORSET_CODE 54
264 99
265static int ui_browser__percent_color(double percent, bool current) 100 return n;
266{
267 if (current)
268 return HE_COLORSET_SELECTED;
269 if (percent >= MIN_RED)
270 return HE_COLORSET_TOP;
271 if (percent >= MIN_GREEN)
272 return HE_COLORSET_MEDIUM;
273 return HE_COLORSET_NORMAL;
274} 101}
275 102
276struct ui_browser { 103static int callchain__count_rows(struct rb_root *chain)
277 newtComponent form, sb;
278 u64 index, first_visible_entry_idx;
279 void *first_visible_entry, *entries;
280 u16 top, left, width, height;
281 void *priv;
282 unsigned int (*refresh_entries)(struct ui_browser *self);
283 void (*seek)(struct ui_browser *self,
284 off_t offset, int whence);
285 u32 nr_entries;
286};
287
288static void ui_browser__list_head_seek(struct ui_browser *self,
289 off_t offset, int whence)
290{ 104{
291 struct list_head *head = self->entries; 105 struct rb_node *nd;
292 struct list_head *pos; 106 int n = 0;
293
294 switch (whence) {
295 case SEEK_SET:
296 pos = head->next;
297 break;
298 case SEEK_CUR:
299 pos = self->first_visible_entry;
300 break;
301 case SEEK_END:
302 pos = head->prev;
303 break;
304 default:
305 return;
306 }
307 107
308 if (offset > 0) { 108 for (nd = rb_first(chain); nd; nd = rb_next(nd)) {
309 while (offset-- != 0) 109 struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node);
310 pos = pos->next; 110 n += callchain_node__count_rows(node);
311 } else {
312 while (offset++ != 0)
313 pos = pos->prev;
314 } 111 }
315 112
316 self->first_visible_entry = pos; 113 return n;
317}
318
319static bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row)
320{
321 return (self->first_visible_entry_idx + row) == self->index;
322} 114}
323 115
324static void ui_browser__refresh_dimensions(struct ui_browser *self) 116static bool map_symbol__toggle_fold(struct map_symbol *self)
325{ 117{
326 int cols, rows; 118 if (!self->has_children)
327 newtGetScreenSize(&cols, &rows); 119 return false;
328
329 if (self->width > cols - 4)
330 self->width = cols - 4;
331 self->height = rows - 5;
332 if (self->height > self->nr_entries)
333 self->height = self->nr_entries;
334 self->top = (rows - self->height) / 2;
335 self->left = (cols - self->width) / 2;
336}
337 120
338static void ui_browser__reset_index(struct ui_browser *self) 121 self->unfolded = !self->unfolded;
339{ 122 return true;
340 self->index = self->first_visible_entry_idx = 0;
341 self->seek(self, 0, SEEK_SET);
342} 123}
343 124
344static int ui_browser__show(struct ui_browser *self, const char *title) 125static void callchain_node__init_have_children_rb_tree(struct callchain_node *self)
345{ 126{
346 if (self->form != NULL) { 127 struct rb_node *nd = rb_first(&self->rb_root);
347 newtFormDestroy(self->form);
348 newtPopWindow();
349 }
350 ui_browser__refresh_dimensions(self);
351 newtCenteredWindow(self->width, self->height, title);
352 self->form = newt_form__new();
353 if (self->form == NULL)
354 return -1;
355
356 self->sb = newtVerticalScrollbar(self->width, 0, self->height,
357 HE_COLORSET_NORMAL,
358 HE_COLORSET_SELECTED);
359 if (self->sb == NULL)
360 return -1;
361 128
362 newtFormAddHotKey(self->form, NEWT_KEY_UP); 129 for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) {
363 newtFormAddHotKey(self->form, NEWT_KEY_DOWN); 130 struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node);
364 newtFormAddHotKey(self->form, NEWT_KEY_PGUP); 131 struct callchain_list *chain;
365 newtFormAddHotKey(self->form, NEWT_KEY_PGDN); 132 int first = true;
366 newtFormAddHotKey(self->form, NEWT_KEY_HOME);
367 newtFormAddHotKey(self->form, NEWT_KEY_END);
368 newtFormAddComponent(self->form, self->sb);
369 return 0;
370}
371 133
372static int objdump_line__show(struct objdump_line *self, struct list_head *head, 134 list_for_each_entry(chain, &child->val, list) {
373 int width, struct hist_entry *he, int len, 135 if (first) {
374 bool current_entry) 136 first = false;
375{ 137 chain->ms.has_children = chain->list.next != &child->val ||
376 if (self->offset != -1) { 138 rb_first(&child->rb_root) != NULL;
377 struct symbol *sym = he->ms.sym;
378 unsigned int hits = 0;
379 double percent = 0.0;
380 int color;
381 struct sym_priv *priv = symbol__priv(sym);
382 struct sym_ext *sym_ext = priv->ext;
383 struct sym_hist *h = priv->hist;
384 s64 offset = self->offset;
385 struct objdump_line *next = objdump__get_next_ip_line(head, self);
386
387 while (offset < (s64)len &&
388 (next == NULL || offset < next->offset)) {
389 if (sym_ext) {
390 percent += sym_ext[offset].percent;
391 } else 139 } else
392 hits += h->ip[offset]; 140 chain->ms.has_children = chain->list.next == &child->val &&
393 141 rb_first(&child->rb_root) != NULL;
394 ++offset;
395 } 142 }
396 143
397 if (sym_ext == NULL && h->sum) 144 callchain_node__init_have_children_rb_tree(child);
398 percent = 100.0 * hits / h->sum;
399
400 color = ui_browser__percent_color(percent, current_entry);
401 SLsmg_set_color(color);
402 slsmg_printf(" %7.2f ", percent);
403 if (!current_entry)
404 SLsmg_set_color(HE_COLORSET_CODE);
405 } else {
406 int color = ui_browser__percent_color(0, current_entry);
407 SLsmg_set_color(color);
408 slsmg_write_nstring(" ", 9);
409 } 145 }
410
411 SLsmg_write_char(':');
412 slsmg_write_nstring(" ", 8);
413 if (!*self->line)
414 slsmg_write_nstring(" ", width - 18);
415 else
416 slsmg_write_nstring(self->line, width - 18);
417
418 return 0;
419} 146}
420 147
421static int ui_browser__refresh_entries(struct ui_browser *self) 148static void callchain_node__init_have_children(struct callchain_node *self)
422{ 149{
423 int row; 150 struct callchain_list *chain;
424 151
425 newtScrollbarSet(self->sb, self->index, self->nr_entries - 1); 152 list_for_each_entry(chain, &self->val, list)
426 row = self->refresh_entries(self); 153 chain->ms.has_children = rb_first(&self->rb_root) != NULL;
427 SLsmg_set_color(HE_COLORSET_NORMAL);
428 SLsmg_fill_region(self->top + row, self->left,
429 self->height - row, self->width, ' ');
430 154
431 return 0; 155 callchain_node__init_have_children_rb_tree(self);
432} 156}
433 157
434static int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es) 158static void callchain__init_have_children(struct rb_root *self)
435{ 159{
436 if (ui_browser__refresh_entries(self) < 0) 160 struct rb_node *nd;
437 return -1;
438
439 while (1) {
440 off_t offset;
441
442 newtFormRun(self->form, es);
443
444 if (es->reason != NEWT_EXIT_HOTKEY)
445 break;
446 if (is_exit_key(es->u.key))
447 return es->u.key;
448 switch (es->u.key) {
449 case NEWT_KEY_DOWN:
450 if (self->index == self->nr_entries - 1)
451 break;
452 ++self->index;
453 if (self->index == self->first_visible_entry_idx + self->height) {
454 ++self->first_visible_entry_idx;
455 self->seek(self, +1, SEEK_CUR);
456 }
457 break;
458 case NEWT_KEY_UP:
459 if (self->index == 0)
460 break;
461 --self->index;
462 if (self->index < self->first_visible_entry_idx) {
463 --self->first_visible_entry_idx;
464 self->seek(self, -1, SEEK_CUR);
465 }
466 break;
467 case NEWT_KEY_PGDN:
468 case ' ':
469 if (self->first_visible_entry_idx + self->height > self->nr_entries - 1)
470 break;
471
472 offset = self->height;
473 if (self->index + offset > self->nr_entries - 1)
474 offset = self->nr_entries - 1 - self->index;
475 self->index += offset;
476 self->first_visible_entry_idx += offset;
477 self->seek(self, +offset, SEEK_CUR);
478 break;
479 case NEWT_KEY_PGUP:
480 if (self->first_visible_entry_idx == 0)
481 break;
482
483 if (self->first_visible_entry_idx < self->height)
484 offset = self->first_visible_entry_idx;
485 else
486 offset = self->height;
487 161
488 self->index -= offset; 162 for (nd = rb_first(self); nd; nd = rb_next(nd)) {
489 self->first_visible_entry_idx -= offset; 163 struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node);
490 self->seek(self, -offset, SEEK_CUR); 164 callchain_node__init_have_children(node);
491 break;
492 case NEWT_KEY_HOME:
493 ui_browser__reset_index(self);
494 break;
495 case NEWT_KEY_END:
496 offset = self->height - 1;
497 if (offset >= self->nr_entries)
498 offset = self->nr_entries - 1;
499
500 self->index = self->nr_entries - 1;
501 self->first_visible_entry_idx = self->index - offset;
502 self->seek(self, -offset, SEEK_END);
503 break;
504 default:
505 return es->u.key;
506 }
507 if (ui_browser__refresh_entries(self) < 0)
508 return -1;
509 } 165 }
510 return 0;
511}
512
513static char *callchain_list__sym_name(struct callchain_list *self,
514 char *bf, size_t bfsize)
515{
516 if (self->ms.sym)
517 return self->ms.sym->name;
518
519 snprintf(bf, bfsize, "%#Lx", self->ip);
520 return bf;
521} 166}
522 167
523static unsigned int hist_entry__annotate_browser_refresh(struct ui_browser *self) 168static void hist_entry__init_have_children(struct hist_entry *self)
524{ 169{
525 struct objdump_line *pos; 170 if (!self->init_have_children) {
526 struct list_head *head = self->entries; 171 callchain__init_have_children(&self->sorted_chain);
527 struct hist_entry *he = self->priv; 172 self->init_have_children = true;
528 int row = 0;
529 int len = he->ms.sym->end - he->ms.sym->start;
530
531 if (self->first_visible_entry == NULL || self->first_visible_entry == self->entries)
532 self->first_visible_entry = head->next;
533
534 pos = list_entry(self->first_visible_entry, struct objdump_line, node);
535
536 list_for_each_entry_from(pos, head, node) {
537 bool current_entry = ui_browser__is_current_entry(self, row);
538 SLsmg_gotorc(self->top + row, self->left);
539 objdump_line__show(pos, head, self->width,
540 he, len, current_entry);
541 if (++row == self->height)
542 break;
543 } 173 }
544
545 return row;
546} 174}
547 175
548int hist_entry__tui_annotate(struct hist_entry *self) 176static bool hist_browser__toggle_fold(struct hist_browser *self)
549{ 177{
550 struct ui_browser browser; 178 if (map_symbol__toggle_fold(self->selection)) {
551 struct newtExitStruct es; 179 struct hist_entry *he = self->he_selection;
552 struct objdump_line *pos, *n;
553 LIST_HEAD(head);
554 int ret;
555
556 if (self->ms.sym == NULL)
557 return -1;
558 180
559 if (self->ms.map->dso->annotate_warned) 181 hist_entry__init_have_children(he);
560 return -1; 182 self->hists->nr_entries -= he->nr_rows;
561 183
562 if (hist_entry__annotate(self, &head) < 0) { 184 if (he->ms.unfolded)
563 ui__error_window(browser__last_msg); 185 he->nr_rows = callchain__count_rows(&he->sorted_chain);
564 return -1; 186 else
565 } 187 he->nr_rows = 0;
188 self->hists->nr_entries += he->nr_rows;
189 self->b.nr_entries = self->hists->nr_entries;
566 190
567 ui_helpline__push("Press <- or ESC to exit"); 191 return true;
568
569 memset(&browser, 0, sizeof(browser));
570 browser.entries = &head;
571 browser.refresh_entries = hist_entry__annotate_browser_refresh;
572 browser.seek = ui_browser__list_head_seek;
573 browser.priv = self;
574 list_for_each_entry(pos, &head, node) {
575 size_t line_len = strlen(pos->line);
576 if (browser.width < line_len)
577 browser.width = line_len;
578 ++browser.nr_entries;
579 } 192 }
580 193
581 browser.width += 18; /* Percentage */ 194 /* If it doesn't have children, no toggling performed */
582 ui_browser__show(&browser, self->ms.sym->name); 195 return false;
583 newtFormAddHotKey(browser.form, ' ');
584 ret = ui_browser__run(&browser, &es);
585 newtFormDestroy(browser.form);
586 newtPopWindow();
587 list_for_each_entry_safe(pos, n, &head, node) {
588 list_del(&pos->node);
589 objdump_line__free(pos);
590 }
591 ui_helpline__pop();
592 return ret;
593} 196}
594 197
595struct hist_browser {
596 struct ui_browser b;
597 struct hists *hists;
598 struct hist_entry *he_selection;
599 struct map_symbol *selection;
600};
601
602static void hist_browser__reset(struct hist_browser *self);
603static int hist_browser__run(struct hist_browser *self, const char *title, 198static int hist_browser__run(struct hist_browser *self, const char *title,
604 struct newtExitStruct *es); 199 struct newtExitStruct *es)
605static unsigned int hist_browser__refresh_entries(struct ui_browser *self);
606static void ui_browser__hists_seek(struct ui_browser *self,
607 off_t offset, int whence);
608
609static struct hist_browser *hist_browser__new(struct hists *hists)
610{
611 struct hist_browser *self = zalloc(sizeof(*self));
612
613 if (self) {
614 self->hists = hists;
615 self->b.refresh_entries = hist_browser__refresh_entries;
616 self->b.seek = ui_browser__hists_seek;
617 }
618
619 return self;
620}
621
622static void hist_browser__delete(struct hist_browser *self)
623{
624 newtFormDestroy(self->b.form);
625 newtPopWindow();
626 free(self);
627}
628
629static struct hist_entry *hist_browser__selected_entry(struct hist_browser *self)
630{
631 return self->he_selection;
632}
633
634static struct thread *hist_browser__selected_thread(struct hist_browser *self)
635{ 200{
636 return self->he_selection->thread; 201 char str[256], unit;
637} 202 unsigned long nr_events = self->hists->stats.nr_events[PERF_RECORD_SAMPLE];
638 203
639static int hist_browser__title(char *bf, size_t size, const char *ev_name, 204 self->b.entries = &self->hists->entries;
640 const struct dso *dso, const struct thread *thread) 205 self->b.nr_entries = self->hists->nr_entries;
641{
642 int printed = 0;
643 206
644 if (thread) 207 hist_browser__refresh_dimensions(self);
645 printed += snprintf(bf + printed, size - printed,
646 "Thread: %s(%d)",
647 (thread->comm_set ? thread->comm : ""),
648 thread->pid);
649 if (dso)
650 printed += snprintf(bf + printed, size - printed,
651 "%sDSO: %s", thread ? " " : "",
652 dso->short_name);
653 return printed ?: snprintf(bf, size, "Event: %s", ev_name);
654}
655 208
656int hists__browse(struct hists *self, const char *helpline, const char *ev_name) 209 nr_events = convert_unit(nr_events, &unit);
657{ 210 snprintf(str, sizeof(str), "Events: %lu%c ",
658 struct hist_browser *browser = hist_browser__new(self); 211 nr_events, unit);
659 struct pstack *fstack; 212 newtDrawRootText(0, 0, str);
660 const struct thread *thread_filter = NULL;
661 const struct dso *dso_filter = NULL;
662 struct newtExitStruct es;
663 char msg[160];
664 int key = -1;
665 213
666 if (browser == NULL) 214 if (ui_browser__show(&self->b, title,
215 "Press '?' for help on key bindings") < 0)
667 return -1; 216 return -1;
668 217
669 fstack = pstack__new(2); 218 newtFormAddHotKey(self->b.form, 'a');
670 if (fstack == NULL) 219 newtFormAddHotKey(self->b.form, '?');
671 goto out; 220 newtFormAddHotKey(self->b.form, 'h');
672 221 newtFormAddHotKey(self->b.form, 'd');
673 ui_helpline__push(helpline); 222 newtFormAddHotKey(self->b.form, 'D');
223 newtFormAddHotKey(self->b.form, 't');
674 224
675 hist_browser__title(msg, sizeof(msg), ev_name, 225 newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT);
676 dso_filter, thread_filter); 226 newtFormAddHotKey(self->b.form, NEWT_KEY_RIGHT);
227 newtFormAddHotKey(self->b.form, NEWT_KEY_ENTER);
677 228
678 while (1) { 229 while (1) {
679 const struct thread *thread; 230 ui_browser__run(&self->b, es);
680 const struct dso *dso;
681 char *options[16];
682 int nr_options = 0, choice = 0, i,
683 annotate = -2, zoom_dso = -2, zoom_thread = -2;
684 231
685 if (hist_browser__run(browser, msg, &es)) 232 if (es->reason != NEWT_EXIT_HOTKEY)
686 break; 233 break;
687 234 switch (es->u.key) {
688 thread = hist_browser__selected_thread(browser); 235 case 'D': { /* Debug */
689 dso = browser->selection->map ? browser->selection->map->dso : NULL; 236 static int seq;
690 237 struct hist_entry *h = rb_entry(self->b.top,
691 if (es.reason == NEWT_EXIT_HOTKEY) { 238 struct hist_entry, rb_node);
692 key = es.u.key; 239 ui_helpline__pop();
693 240 ui_helpline__fpush("%d: nr_ent=(%d,%d), height=%d, idx=%d, fve: idx=%d, row_off=%d, nrows=%d",
694 switch (key) { 241 seq++, self->b.nr_entries,
695 case NEWT_KEY_F1: 242 self->hists->nr_entries,
696 goto do_help; 243 self->b.height,
697 case NEWT_KEY_TAB: 244 self->b.index,
698 case NEWT_KEY_UNTAB: 245 self->b.top_idx,
699 /* 246 h->row_offset, h->nr_rows);
700 * Exit the browser, let hists__browser_tree
701 * go to the next or previous
702 */
703 goto out_free_stack;
704 default:;
705 }
706
707 key = toupper(key);
708 switch (key) {
709 case 'A':
710 if (browser->selection->map == NULL &&
711 browser->selection->map->dso->annotate_warned)
712 continue;
713 goto do_annotate;
714 case 'D':
715 goto zoom_dso;
716 case 'T':
717 goto zoom_thread;
718 case 'H':
719 case '?':
720do_help:
721 ui__help_window("-> Zoom into DSO/Threads & Annotate current symbol\n"
722 "<- Zoom out\n"
723 "a Annotate current symbol\n"
724 "h/?/F1 Show this window\n"
725 "d Zoom into current DSO\n"
726 "t Zoom into current Thread\n"
727 "q/CTRL+C Exit browser");
728 continue;
729 default:;
730 }
731 if (is_exit_key(key)) {
732 if (key == NEWT_KEY_ESCAPE) {
733 if (dialog_yesno("Do you really want to exit?"))
734 break;
735 else
736 continue;
737 } else
738 break;
739 }
740
741 if (es.u.key == NEWT_KEY_LEFT) {
742 const void *top;
743
744 if (pstack__empty(fstack))
745 continue;
746 top = pstack__pop(fstack);
747 if (top == &dso_filter)
748 goto zoom_out_dso;
749 if (top == &thread_filter)
750 goto zoom_out_thread;
751 continue;
752 }
753 } 247 }
754
755 if (browser->selection->sym != NULL &&
756 !browser->selection->map->dso->annotate_warned &&
757 asprintf(&options[nr_options], "Annotate %s",
758 browser->selection->sym->name) > 0)
759 annotate = nr_options++;
760
761 if (thread != NULL &&
762 asprintf(&options[nr_options], "Zoom %s %s(%d) thread",
763 (thread_filter ? "out of" : "into"),
764 (thread->comm_set ? thread->comm : ""),
765 thread->pid) > 0)
766 zoom_thread = nr_options++;
767
768 if (dso != NULL &&
769 asprintf(&options[nr_options], "Zoom %s %s DSO",
770 (dso_filter ? "out of" : "into"),
771 (dso->kernel ? "the Kernel" : dso->short_name)) > 0)
772 zoom_dso = nr_options++;
773
774 options[nr_options++] = (char *)"Exit";
775
776 choice = popup_menu(nr_options, options);
777
778 for (i = 0; i < nr_options - 1; ++i)
779 free(options[i]);
780
781 if (choice == nr_options - 1)
782 break;
783
784 if (choice == -1)
785 continue; 248 continue;
786 249 case NEWT_KEY_ENTER:
787 if (choice == annotate) { 250 if (hist_browser__toggle_fold(self))
788 struct hist_entry *he; 251 break;
789do_annotate: 252 /* fall thru */
790 if (browser->selection->map->dso->origin == DSO__ORIG_KERNEL) {
791 browser->selection->map->dso->annotate_warned = 1;
792 ui_helpline__puts("No vmlinux file found, can't "
793 "annotate with just a "
794 "kallsyms file");
795 continue;
796 }
797
798 he = hist_browser__selected_entry(browser);
799 if (he == NULL)
800 continue;
801
802 hist_entry__tui_annotate(he);
803 } else if (choice == zoom_dso) {
804zoom_dso:
805 if (dso_filter) {
806 pstack__remove(fstack, &dso_filter);
807zoom_out_dso:
808 ui_helpline__pop();
809 dso_filter = NULL;
810 } else {
811 if (dso == NULL)
812 continue;
813 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"",
814 dso->kernel ? "the Kernel" : dso->short_name);
815 dso_filter = dso;
816 pstack__push(fstack, &dso_filter);
817 }
818 hists__filter_by_dso(self, dso_filter);
819 hist_browser__title(msg, sizeof(msg), ev_name,
820 dso_filter, thread_filter);
821 hist_browser__reset(browser);
822 } else if (choice == zoom_thread) {
823zoom_thread:
824 if (thread_filter) {
825 pstack__remove(fstack, &thread_filter);
826zoom_out_thread:
827 ui_helpline__pop();
828 thread_filter = NULL;
829 } else {
830 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"",
831 thread->comm_set ? thread->comm : "",
832 thread->pid);
833 thread_filter = thread;
834 pstack__push(fstack, &thread_filter);
835 }
836 hists__filter_by_thread(self, thread_filter);
837 hist_browser__title(msg, sizeof(msg), ev_name,
838 dso_filter, thread_filter);
839 hist_browser__reset(browser);
840 }
841 }
842out_free_stack:
843 pstack__delete(fstack);
844out:
845 hist_browser__delete(browser);
846 return key;
847}
848
849int hists__tui_browse_tree(struct rb_root *self, const char *help)
850{
851 struct rb_node *first = rb_first(self), *nd = first, *next;
852 int key = 0;
853
854 while (nd) {
855 struct hists *hists = rb_entry(nd, struct hists, rb_node);
856 const char *ev_name = __event_name(hists->type, hists->config);
857
858 key = hists__browse(hists, help, ev_name);
859
860 if (is_exit_key(key))
861 break;
862
863 switch (key) {
864 case NEWT_KEY_TAB:
865 next = rb_next(nd);
866 if (next)
867 nd = next;
868 break;
869 case NEWT_KEY_UNTAB:
870 if (nd == first)
871 continue;
872 nd = rb_prev(nd);
873 default: 253 default:
874 break; 254 return 0;
875 }
876 }
877
878 return key;
879}
880
881static struct newtPercentTreeColors {
882 const char *topColorFg, *topColorBg;
883 const char *mediumColorFg, *mediumColorBg;
884 const char *normalColorFg, *normalColorBg;
885 const char *selColorFg, *selColorBg;
886 const char *codeColorFg, *codeColorBg;
887} defaultPercentTreeColors = {
888 "red", "lightgray",
889 "green", "lightgray",
890 "black", "lightgray",
891 "lightgray", "magenta",
892 "blue", "lightgray",
893};
894
895static void newt_suspend(void *d __used)
896{
897 newtSuspend();
898 raise(SIGTSTP);
899 newtResume();
900}
901
902void setup_browser(void)
903{
904 struct newtPercentTreeColors *c = &defaultPercentTreeColors;
905
906 if (!isatty(1) || !use_browser || dump_trace) {
907 use_browser = 0;
908 setup_pager();
909 return;
910 }
911
912 use_browser = 1;
913 newtInit();
914 newtCls();
915 newtSetSuspendCallback(newt_suspend, NULL);
916 ui_helpline__puts(" ");
917 sltt_set_color(HE_COLORSET_TOP, NULL, c->topColorFg, c->topColorBg);
918 sltt_set_color(HE_COLORSET_MEDIUM, NULL, c->mediumColorFg, c->mediumColorBg);
919 sltt_set_color(HE_COLORSET_NORMAL, NULL, c->normalColorFg, c->normalColorBg);
920 sltt_set_color(HE_COLORSET_SELECTED, NULL, c->selColorFg, c->selColorBg);
921 sltt_set_color(HE_COLORSET_CODE, NULL, c->codeColorFg, c->codeColorBg);
922}
923
924void exit_browser(bool wait_for_ok)
925{
926 if (use_browser > 0) {
927 if (wait_for_ok) {
928 char title[] = "Fatal Error", ok[] = "Ok";
929 newtWinMessage(title, ok, browser__last_msg);
930 } 255 }
931 newtFinished();
932 } 256 }
933}
934
935static void hist_browser__refresh_dimensions(struct hist_browser *self)
936{
937 /* 3 == +/- toggle symbol before actual hist_entry rendering */
938 self->b.width = 3 + (hists__sort_list_width(self->hists) +
939 sizeof("[k]"));
940}
941
942static void hist_browser__reset(struct hist_browser *self)
943{
944 self->b.nr_entries = self->hists->nr_entries;
945 hist_browser__refresh_dimensions(self);
946 ui_browser__reset_index(&self->b);
947}
948
949static char tree__folded_sign(bool unfolded)
950{
951 return unfolded ? '-' : '+';
952}
953
954static char map_symbol__folded(const struct map_symbol *self)
955{
956 return self->has_children ? tree__folded_sign(self->unfolded) : ' ';
957}
958
959static char hist_entry__folded(const struct hist_entry *self)
960{
961 return map_symbol__folded(&self->ms);
962}
963 257
964static char callchain_list__folded(const struct callchain_list *self) 258 ui_browser__hide(&self->b);
965{ 259 return 0;
966 return map_symbol__folded(&self->ms);
967} 260}
968 261
969static bool map_symbol__toggle_fold(struct map_symbol *self) 262static char *callchain_list__sym_name(struct callchain_list *self,
263 char *bf, size_t bfsize)
970{ 264{
971 if (!self->has_children) 265 if (self->ms.sym)
972 return false; 266 return self->ms.sym->name;
973 267
974 self->unfolded = !self->unfolded; 268 snprintf(bf, bfsize, "%#Lx", self->ip);
975 return true; 269 return bf;
976} 270}
977 271
978#define LEVEL_OFFSET_STEP 3 272#define LEVEL_OFFSET_STEP 3
@@ -1048,7 +342,7 @@ static int hist_browser__show_callchain_node_rb_tree(struct hist_browser *self,
1048 } 342 }
1049 343
1050 SLsmg_set_color(color); 344 SLsmg_set_color(color);
1051 SLsmg_gotorc(self->b.top + row, self->b.left); 345 SLsmg_gotorc(self->b.y + row, self->b.x);
1052 slsmg_write_nstring(" ", offset + extra_offset); 346 slsmg_write_nstring(" ", offset + extra_offset);
1053 slsmg_printf("%c ", folded_sign); 347 slsmg_printf("%c ", folded_sign);
1054 slsmg_write_nstring(str, width); 348 slsmg_write_nstring(str, width);
@@ -1111,7 +405,7 @@ static int hist_browser__show_callchain_node(struct hist_browser *self,
1111 } 405 }
1112 406
1113 s = callchain_list__sym_name(chain, ipstr, sizeof(ipstr)); 407 s = callchain_list__sym_name(chain, ipstr, sizeof(ipstr));
1114 SLsmg_gotorc(self->b.top + row, self->b.left); 408 SLsmg_gotorc(self->b.y + row, self->b.x);
1115 SLsmg_set_color(color); 409 SLsmg_set_color(color);
1116 slsmg_write_nstring(" ", offset); 410 slsmg_write_nstring(" ", offset);
1117 slsmg_printf("%c ", folded_sign); 411 slsmg_printf("%c ", folded_sign);
@@ -1191,7 +485,7 @@ static int hist_browser__show_entry(struct hist_browser *self,
1191 } 485 }
1192 486
1193 SLsmg_set_color(color); 487 SLsmg_set_color(color);
1194 SLsmg_gotorc(self->b.top + row, self->b.left); 488 SLsmg_gotorc(self->b.y + row, self->b.x);
1195 if (symbol_conf.use_callchain) { 489 if (symbol_conf.use_callchain) {
1196 slsmg_printf("%c ", folded_sign); 490 slsmg_printf("%c ", folded_sign);
1197 width -= 2; 491 width -= 2;
@@ -1213,16 +507,16 @@ static int hist_browser__show_entry(struct hist_browser *self,
1213 return printed; 507 return printed;
1214} 508}
1215 509
1216static unsigned int hist_browser__refresh_entries(struct ui_browser *self) 510static unsigned int hist_browser__refresh(struct ui_browser *self)
1217{ 511{
1218 unsigned row = 0; 512 unsigned row = 0;
1219 struct rb_node *nd; 513 struct rb_node *nd;
1220 struct hist_browser *hb = container_of(self, struct hist_browser, b); 514 struct hist_browser *hb = container_of(self, struct hist_browser, b);
1221 515
1222 if (self->first_visible_entry == NULL) 516 if (self->top == NULL)
1223 self->first_visible_entry = rb_first(&hb->hists->entries); 517 self->top = rb_first(&hb->hists->entries);
1224 518
1225 for (nd = self->first_visible_entry; nd; nd = rb_next(nd)) { 519 for (nd = self->top; nd; nd = rb_next(nd)) {
1226 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); 520 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1227 521
1228 if (h->filtered) 522 if (h->filtered)
@@ -1236,57 +530,6 @@ static unsigned int hist_browser__refresh_entries(struct ui_browser *self)
1236 return row; 530 return row;
1237} 531}
1238 532
1239static void callchain_node__init_have_children_rb_tree(struct callchain_node *self)
1240{
1241 struct rb_node *nd = rb_first(&self->rb_root);
1242
1243 for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) {
1244 struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node);
1245 struct callchain_list *chain;
1246 int first = true;
1247
1248 list_for_each_entry(chain, &child->val, list) {
1249 if (first) {
1250 first = false;
1251 chain->ms.has_children = chain->list.next != &child->val ||
1252 rb_first(&child->rb_root) != NULL;
1253 } else
1254 chain->ms.has_children = chain->list.next == &child->val &&
1255 rb_first(&child->rb_root) != NULL;
1256 }
1257
1258 callchain_node__init_have_children_rb_tree(child);
1259 }
1260}
1261
1262static void callchain_node__init_have_children(struct callchain_node *self)
1263{
1264 struct callchain_list *chain;
1265
1266 list_for_each_entry(chain, &self->val, list)
1267 chain->ms.has_children = rb_first(&self->rb_root) != NULL;
1268
1269 callchain_node__init_have_children_rb_tree(self);
1270}
1271
1272static void callchain__init_have_children(struct rb_root *self)
1273{
1274 struct rb_node *nd;
1275
1276 for (nd = rb_first(self); nd; nd = rb_next(nd)) {
1277 struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node);
1278 callchain_node__init_have_children(node);
1279 }
1280}
1281
1282static void hist_entry__init_have_children(struct hist_entry *self)
1283{
1284 if (!self->init_have_children) {
1285 callchain__init_have_children(&self->sorted_chain);
1286 self->init_have_children = true;
1287 }
1288}
1289
1290static struct rb_node *hists__filter_entries(struct rb_node *nd) 533static struct rb_node *hists__filter_entries(struct rb_node *nd)
1291{ 534{
1292 while (nd != NULL) { 535 while (nd != NULL) {
@@ -1325,7 +568,7 @@ static void ui_browser__hists_seek(struct ui_browser *self,
1325 nd = hists__filter_entries(rb_first(self->entries)); 568 nd = hists__filter_entries(rb_first(self->entries));
1326 break; 569 break;
1327 case SEEK_CUR: 570 case SEEK_CUR:
1328 nd = self->first_visible_entry; 571 nd = self->top;
1329 goto do_offset; 572 goto do_offset;
1330 case SEEK_END: 573 case SEEK_END:
1331 nd = hists__filter_prev_entries(rb_last(self->entries)); 574 nd = hists__filter_prev_entries(rb_last(self->entries));
@@ -1339,7 +582,7 @@ static void ui_browser__hists_seek(struct ui_browser *self,
1339 * Moves not relative to the first visible entry invalidates its 582 * Moves not relative to the first visible entry invalidates its
1340 * row_offset: 583 * row_offset:
1341 */ 584 */
1342 h = rb_entry(self->first_visible_entry, struct hist_entry, rb_node); 585 h = rb_entry(self->top, struct hist_entry, rb_node);
1343 h->row_offset = 0; 586 h->row_offset = 0;
1344 587
1345 /* 588 /*
@@ -1367,7 +610,7 @@ do_offset:
1367 } else { 610 } else {
1368 h->row_offset += offset; 611 h->row_offset += offset;
1369 offset = 0; 612 offset = 0;
1370 self->first_visible_entry = nd; 613 self->top = nd;
1371 break; 614 break;
1372 } 615 }
1373 } 616 }
@@ -1375,7 +618,7 @@ do_offset:
1375 if (nd == NULL) 618 if (nd == NULL)
1376 break; 619 break;
1377 --offset; 620 --offset;
1378 self->first_visible_entry = nd; 621 self->top = nd;
1379 } while (offset != 0); 622 } while (offset != 0);
1380 } else if (offset < 0) { 623 } else if (offset < 0) {
1381 while (1) { 624 while (1) {
@@ -1388,7 +631,7 @@ do_offset:
1388 } else { 631 } else {
1389 h->row_offset += offset; 632 h->row_offset += offset;
1390 offset = 0; 633 offset = 0;
1391 self->first_visible_entry = nd; 634 self->top = nd;
1392 break; 635 break;
1393 } 636 }
1394 } else { 637 } else {
@@ -1398,7 +641,7 @@ do_offset:
1398 } else { 641 } else {
1399 h->row_offset = h->nr_rows + offset; 642 h->row_offset = h->nr_rows + offset;
1400 offset = 0; 643 offset = 0;
1401 self->first_visible_entry = nd; 644 self->top = nd;
1402 break; 645 break;
1403 } 646 }
1404 } 647 }
@@ -1408,7 +651,7 @@ do_offset:
1408 if (nd == NULL) 651 if (nd == NULL)
1409 break; 652 break;
1410 ++offset; 653 ++offset;
1411 self->first_visible_entry = nd; 654 self->top = nd;
1412 if (offset == 0) { 655 if (offset == 0) {
1413 /* 656 /*
1414 * Last unfiltered hist_entry, check if it is 657 * Last unfiltered hist_entry, check if it is
@@ -1423,146 +666,283 @@ do_offset:
1423 first = false; 666 first = false;
1424 } 667 }
1425 } else { 668 } else {
1426 self->first_visible_entry = nd; 669 self->top = nd;
1427 h = rb_entry(nd, struct hist_entry, rb_node); 670 h = rb_entry(nd, struct hist_entry, rb_node);
1428 h->row_offset = 0; 671 h->row_offset = 0;
1429 } 672 }
1430} 673}
1431 674
1432static int callchain_node__count_rows_rb_tree(struct callchain_node *self) 675static struct hist_browser *hist_browser__new(struct hists *hists)
1433{ 676{
1434 int n = 0; 677 struct hist_browser *self = zalloc(sizeof(*self));
1435 struct rb_node *nd;
1436
1437 for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) {
1438 struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node);
1439 struct callchain_list *chain;
1440 char folded_sign = ' '; /* No children */
1441
1442 list_for_each_entry(chain, &child->val, list) {
1443 ++n;
1444 /* We need this because we may not have children */
1445 folded_sign = callchain_list__folded(chain);
1446 if (folded_sign == '+')
1447 break;
1448 }
1449 678
1450 if (folded_sign == '-') /* Have children and they're unfolded */ 679 if (self) {
1451 n += callchain_node__count_rows_rb_tree(child); 680 self->hists = hists;
681 self->b.refresh = hist_browser__refresh;
682 self->b.seek = ui_browser__hists_seek;
1452 } 683 }
1453 684
1454 return n; 685 return self;
1455} 686}
1456 687
1457static int callchain_node__count_rows(struct callchain_node *node) 688static void hist_browser__delete(struct hist_browser *self)
1458{ 689{
1459 struct callchain_list *chain; 690 newtFormDestroy(self->b.form);
1460 bool unfolded = false; 691 newtPopWindow();
1461 int n = 0; 692 free(self);
1462 693}
1463 list_for_each_entry(chain, &node->val, list) {
1464 ++n;
1465 unfolded = chain->ms.unfolded;
1466 }
1467
1468 if (unfolded)
1469 n += callchain_node__count_rows_rb_tree(node);
1470 694
1471 return n; 695static struct hist_entry *hist_browser__selected_entry(struct hist_browser *self)
696{
697 return self->he_selection;
1472} 698}
1473 699
1474static int callchain__count_rows(struct rb_root *chain) 700static struct thread *hist_browser__selected_thread(struct hist_browser *self)
1475{ 701{
1476 struct rb_node *nd; 702 return self->he_selection->thread;
1477 int n = 0; 703}
1478 704
1479 for (nd = rb_first(chain); nd; nd = rb_next(nd)) { 705static int hist_browser__title(char *bf, size_t size, const char *ev_name,
1480 struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); 706 const struct dso *dso, const struct thread *thread)
1481 n += callchain_node__count_rows(node); 707{
1482 } 708 int printed = 0;
1483 709
1484 return n; 710 if (thread)
711 printed += snprintf(bf + printed, size - printed,
712 "Thread: %s(%d)",
713 (thread->comm_set ? thread->comm : ""),
714 thread->pid);
715 if (dso)
716 printed += snprintf(bf + printed, size - printed,
717 "%sDSO: %s", thread ? " " : "",
718 dso->short_name);
719 return printed ?: snprintf(bf, size, "Event: %s", ev_name);
1485} 720}
1486 721
1487static bool hist_browser__toggle_fold(struct hist_browser *self) 722int hists__browse(struct hists *self, const char *helpline, const char *ev_name)
1488{ 723{
1489 if (map_symbol__toggle_fold(self->selection)) { 724 struct hist_browser *browser = hist_browser__new(self);
1490 struct hist_entry *he = self->he_selection; 725 struct pstack *fstack;
726 const struct thread *thread_filter = NULL;
727 const struct dso *dso_filter = NULL;
728 struct newtExitStruct es;
729 char msg[160];
730 int key = -1;
1491 731
1492 hist_entry__init_have_children(he); 732 if (browser == NULL)
1493 self->hists->nr_entries -= he->nr_rows; 733 return -1;
1494 734
1495 if (he->ms.unfolded) 735 fstack = pstack__new(2);
1496 he->nr_rows = callchain__count_rows(&he->sorted_chain); 736 if (fstack == NULL)
1497 else 737 goto out;
1498 he->nr_rows = 0;
1499 self->hists->nr_entries += he->nr_rows;
1500 self->b.nr_entries = self->hists->nr_entries;
1501 738
1502 return true; 739 ui_helpline__push(helpline);
1503 }
1504 740
1505 /* If it doesn't have children, no toggling performed */ 741 hist_browser__title(msg, sizeof(msg), ev_name,
1506 return false; 742 dso_filter, thread_filter);
1507}
1508 743
1509static int hist_browser__run(struct hist_browser *self, const char *title, 744 while (1) {
1510 struct newtExitStruct *es) 745 const struct thread *thread;
1511{ 746 const struct dso *dso;
1512 char str[256], unit; 747 char *options[16];
1513 unsigned long nr_events = self->hists->stats.nr_events[PERF_RECORD_SAMPLE]; 748 int nr_options = 0, choice = 0, i,
749 annotate = -2, zoom_dso = -2, zoom_thread = -2,
750 browse_map = -2;
1514 751
1515 self->b.entries = &self->hists->entries; 752 if (hist_browser__run(browser, msg, &es))
1516 self->b.nr_entries = self->hists->nr_entries; 753 break;
1517 754
1518 hist_browser__refresh_dimensions(self); 755 thread = hist_browser__selected_thread(browser);
756 dso = browser->selection->map ? browser->selection->map->dso : NULL;
1519 757
1520 nr_events = convert_unit(nr_events, &unit); 758 if (es.reason == NEWT_EXIT_HOTKEY) {
1521 snprintf(str, sizeof(str), "Events: %lu%c ", 759 key = es.u.key;
1522 nr_events, unit);
1523 newtDrawRootText(0, 0, str);
1524 760
1525 if (ui_browser__show(&self->b, title) < 0) 761 switch (key) {
1526 return -1; 762 case NEWT_KEY_F1:
763 goto do_help;
764 case NEWT_KEY_TAB:
765 case NEWT_KEY_UNTAB:
766 /*
767 * Exit the browser, let hists__browser_tree
768 * go to the next or previous
769 */
770 goto out_free_stack;
771 default:;
772 }
1527 773
1528 newtFormAddHotKey(self->b.form, 'A'); 774 switch (key) {
1529 newtFormAddHotKey(self->b.form, 'a'); 775 case 'a':
1530 newtFormAddHotKey(self->b.form, '?'); 776 if (browser->selection->map == NULL &&
1531 newtFormAddHotKey(self->b.form, 'h'); 777 browser->selection->map->dso->annotate_warned)
1532 newtFormAddHotKey(self->b.form, 'H'); 778 continue;
1533 newtFormAddHotKey(self->b.form, 'd'); 779 goto do_annotate;
780 case 'd':
781 goto zoom_dso;
782 case 't':
783 goto zoom_thread;
784 case 'h':
785 case '?':
786do_help:
787 ui__help_window("-> Zoom into DSO/Threads & Annotate current symbol\n"
788 "<- Zoom out\n"
789 "a Annotate current symbol\n"
790 "h/?/F1 Show this window\n"
791 "d Zoom into current DSO\n"
792 "t Zoom into current Thread\n"
793 "q/CTRL+C Exit browser");
794 continue;
795 default:;
796 }
797 if (is_exit_key(key)) {
798 if (key == NEWT_KEY_ESCAPE &&
799 !ui__dialog_yesno("Do you really want to exit?"))
800 continue;
801 break;
802 }
1534 803
1535 newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT); 804 if (es.u.key == NEWT_KEY_LEFT) {
1536 newtFormAddHotKey(self->b.form, NEWT_KEY_RIGHT); 805 const void *top;
1537 newtFormAddHotKey(self->b.form, NEWT_KEY_ENTER);
1538 806
1539 while (1) { 807 if (pstack__empty(fstack))
1540 ui_browser__run(&self->b, es); 808 continue;
809 top = pstack__pop(fstack);
810 if (top == &dso_filter)
811 goto zoom_out_dso;
812 if (top == &thread_filter)
813 goto zoom_out_thread;
814 continue;
815 }
816 }
1541 817
1542 if (es->reason != NEWT_EXIT_HOTKEY) 818 if (browser->selection->sym != NULL &&
819 !browser->selection->map->dso->annotate_warned &&
820 asprintf(&options[nr_options], "Annotate %s",
821 browser->selection->sym->name) > 0)
822 annotate = nr_options++;
823
824 if (thread != NULL &&
825 asprintf(&options[nr_options], "Zoom %s %s(%d) thread",
826 (thread_filter ? "out of" : "into"),
827 (thread->comm_set ? thread->comm : ""),
828 thread->pid) > 0)
829 zoom_thread = nr_options++;
830
831 if (dso != NULL &&
832 asprintf(&options[nr_options], "Zoom %s %s DSO",
833 (dso_filter ? "out of" : "into"),
834 (dso->kernel ? "the Kernel" : dso->short_name)) > 0)
835 zoom_dso = nr_options++;
836
837 if (browser->selection->map != NULL &&
838 asprintf(&options[nr_options], "Browse map details") > 0)
839 browse_map = nr_options++;
840
841 options[nr_options++] = (char *)"Exit";
842
843 choice = ui__popup_menu(nr_options, options);
844
845 for (i = 0; i < nr_options - 1; ++i)
846 free(options[i]);
847
848 if (choice == nr_options - 1)
1543 break; 849 break;
1544 switch (es->u.key) { 850
1545 case 'd': { /* Debug */ 851 if (choice == -1)
1546 static int seq;
1547 struct hist_entry *h = rb_entry(self->b.first_visible_entry,
1548 struct hist_entry, rb_node);
1549 ui_helpline__pop();
1550 ui_helpline__fpush("%d: nr_ent=(%d,%d), height=%d, idx=%d, fve: idx=%d, row_off=%d, nrows=%d",
1551 seq++, self->b.nr_entries,
1552 self->hists->nr_entries,
1553 self->b.height,
1554 self->b.index,
1555 self->b.first_visible_entry_idx,
1556 h->row_offset, h->nr_rows);
1557 }
1558 continue; 852 continue;
1559 case NEWT_KEY_ENTER: 853
1560 if (hist_browser__toggle_fold(self)) 854 if (choice == annotate) {
1561 break; 855 struct hist_entry *he;
1562 /* fall thru */ 856do_annotate:
857 if (browser->selection->map->dso->origin == DSO__ORIG_KERNEL) {
858 browser->selection->map->dso->annotate_warned = 1;
859 ui_helpline__puts("No vmlinux file found, can't "
860 "annotate with just a "
861 "kallsyms file");
862 continue;
863 }
864
865 he = hist_browser__selected_entry(browser);
866 if (he == NULL)
867 continue;
868
869 hist_entry__tui_annotate(he);
870 } else if (choice == browse_map)
871 map__browse(browser->selection->map);
872 else if (choice == zoom_dso) {
873zoom_dso:
874 if (dso_filter) {
875 pstack__remove(fstack, &dso_filter);
876zoom_out_dso:
877 ui_helpline__pop();
878 dso_filter = NULL;
879 } else {
880 if (dso == NULL)
881 continue;
882 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"",
883 dso->kernel ? "the Kernel" : dso->short_name);
884 dso_filter = dso;
885 pstack__push(fstack, &dso_filter);
886 }
887 hists__filter_by_dso(self, dso_filter);
888 hist_browser__title(msg, sizeof(msg), ev_name,
889 dso_filter, thread_filter);
890 hist_browser__reset(browser);
891 } else if (choice == zoom_thread) {
892zoom_thread:
893 if (thread_filter) {
894 pstack__remove(fstack, &thread_filter);
895zoom_out_thread:
896 ui_helpline__pop();
897 thread_filter = NULL;
898 } else {
899 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"",
900 thread->comm_set ? thread->comm : "",
901 thread->pid);
902 thread_filter = thread;
903 pstack__push(fstack, &thread_filter);
904 }
905 hists__filter_by_thread(self, thread_filter);
906 hist_browser__title(msg, sizeof(msg), ev_name,
907 dso_filter, thread_filter);
908 hist_browser__reset(browser);
909 }
910 }
911out_free_stack:
912 pstack__delete(fstack);
913out:
914 hist_browser__delete(browser);
915 return key;
916}
917
918int hists__tui_browse_tree(struct rb_root *self, const char *help)
919{
920 struct rb_node *first = rb_first(self), *nd = first, *next;
921 int key = 0;
922
923 while (nd) {
924 struct hists *hists = rb_entry(nd, struct hists, rb_node);
925 const char *ev_name = __event_name(hists->type, hists->config);
926
927 key = hists__browse(hists, help, ev_name);
928
929 if (is_exit_key(key))
930 break;
931
932 switch (key) {
933 case NEWT_KEY_TAB:
934 next = rb_next(nd);
935 if (next)
936 nd = next;
937 break;
938 case NEWT_KEY_UNTAB:
939 if (nd == first)
940 continue;
941 nd = rb_prev(nd);
1563 default: 942 default:
1564 return 0; 943 break;
1565 } 944 }
1566 } 945 }
1567 return 0; 946
947 return key;
1568} 948}
diff --git a/tools/perf/util/ui/browsers/map.c b/tools/perf/util/ui/browsers/map.c
new file mode 100644
index 000000000000..142b825b42bf
--- /dev/null
+++ b/tools/perf/util/ui/browsers/map.c
@@ -0,0 +1,161 @@
1#include "../libslang.h"
2#include <elf.h>
3#include <newt.h>
4#include <sys/ttydefaults.h>
5#include <ctype.h>
6#include <string.h>
7#include <linux/bitops.h>
8#include "../../debug.h"
9#include "../../symbol.h"
10#include "../browser.h"
11#include "../helpline.h"
12#include "map.h"
13
14static int ui_entry__read(const char *title, char *bf, size_t size, int width)
15{
16 struct newtExitStruct es;
17 newtComponent form, entry;
18 const char *result;
19 int err = -1;
20
21 newtCenteredWindow(width, 1, title);
22 form = newtForm(NULL, NULL, 0);
23 if (form == NULL)
24 return -1;
25
26 entry = newtEntry(0, 0, "0x", width, &result, NEWT_FLAG_SCROLL);
27 if (entry == NULL)
28 goto out_free_form;
29
30 newtFormAddComponent(form, entry);
31 newtFormAddHotKey(form, NEWT_KEY_ENTER);
32 newtFormAddHotKey(form, NEWT_KEY_ESCAPE);
33 newtFormAddHotKey(form, NEWT_KEY_LEFT);
34 newtFormAddHotKey(form, CTRL('c'));
35 newtFormRun(form, &es);
36
37 if (result != NULL) {
38 strncpy(bf, result, size);
39 err = 0;
40 }
41out_free_form:
42 newtPopWindow();
43 newtFormDestroy(form);
44 return 0;
45}
46
47struct map_browser {
48 struct ui_browser b;
49 struct map *map;
50 u16 namelen;
51 u8 addrlen;
52};
53
54static void map_browser__write(struct ui_browser *self, void *nd, int row)
55{
56 struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
57 struct map_browser *mb = container_of(self, struct map_browser, b);
58 bool current_entry = ui_browser__is_current_entry(self, row);
59 int color = ui_browser__percent_color(0, current_entry);
60
61 SLsmg_set_color(color);
62 slsmg_printf("%*llx %*llx %c ",
63 mb->addrlen, sym->start, mb->addrlen, sym->end,
64 sym->binding == STB_GLOBAL ? 'g' :
65 sym->binding == STB_LOCAL ? 'l' : 'w');
66 slsmg_write_nstring(sym->name, mb->namelen);
67}
68
69/* FIXME uber-kludgy, see comment on cmd_report... */
70static u32 *symbol__browser_index(struct symbol *self)
71{
72 return ((void *)self) - sizeof(struct rb_node) - sizeof(u32);
73}
74
75static int map_browser__search(struct map_browser *self)
76{
77 char target[512];
78 struct symbol *sym;
79 int err = ui_entry__read("Search by name/addr", target, sizeof(target), 40);
80
81 if (err)
82 return err;
83
84 if (target[0] == '0' && tolower(target[1]) == 'x') {
85 u64 addr = strtoull(target, NULL, 16);
86 sym = map__find_symbol(self->map, addr, NULL);
87 } else
88 sym = map__find_symbol_by_name(self->map, target, NULL);
89
90 if (sym != NULL) {
91 u32 *idx = symbol__browser_index(sym);
92
93 self->b.top = &sym->rb_node;
94 self->b.index = self->b.top_idx = *idx;
95 } else
96 ui_helpline__fpush("%s not found!", target);
97
98 return 0;
99}
100
101static int map_browser__run(struct map_browser *self, struct newtExitStruct *es)
102{
103 if (ui_browser__show(&self->b, self->map->dso->long_name,
104 "Press <- or ESC to exit, %s / to search",
105 verbose ? "" : "restart with -v to use") < 0)
106 return -1;
107
108 newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT);
109 newtFormAddHotKey(self->b.form, NEWT_KEY_ENTER);
110 if (verbose)
111 newtFormAddHotKey(self->b.form, '/');
112
113 while (1) {
114 ui_browser__run(&self->b, es);
115
116 if (es->reason != NEWT_EXIT_HOTKEY)
117 break;
118 if (verbose && es->u.key == '/')
119 map_browser__search(self);
120 else
121 break;
122 }
123
124 ui_browser__hide(&self->b);
125 return 0;
126}
127
128int map__browse(struct map *self)
129{
130 struct map_browser mb = {
131 .b = {
132 .entries = &self->dso->symbols[self->type],
133 .refresh = ui_browser__rb_tree_refresh,
134 .seek = ui_browser__rb_tree_seek,
135 .write = map_browser__write,
136 },
137 .map = self,
138 };
139 struct newtExitStruct es;
140 struct rb_node *nd;
141 char tmp[BITS_PER_LONG / 4];
142 u64 maxaddr = 0;
143
144 for (nd = rb_first(mb.b.entries); nd; nd = rb_next(nd)) {
145 struct symbol *pos = rb_entry(nd, struct symbol, rb_node);
146
147 if (mb.namelen < pos->namelen)
148 mb.namelen = pos->namelen;
149 if (maxaddr < pos->end)
150 maxaddr = pos->end;
151 if (verbose) {
152 u32 *idx = symbol__browser_index(pos);
153 *idx = mb.b.nr_entries;
154 }
155 ++mb.b.nr_entries;
156 }
157
158 mb.addrlen = snprintf(tmp, sizeof(tmp), "%llx", maxaddr);
159 mb.b.width += mb.addrlen * 2 + 4 + mb.namelen;
160 return map_browser__run(&mb, &es);
161}
diff --git a/tools/perf/util/ui/browsers/map.h b/tools/perf/util/ui/browsers/map.h
new file mode 100644
index 000000000000..df8581a43e17
--- /dev/null
+++ b/tools/perf/util/ui/browsers/map.h
@@ -0,0 +1,6 @@
1#ifndef _PERF_UI_MAP_BROWSER_H_
2#define _PERF_UI_MAP_BROWSER_H_ 1
3struct map;
4
5int map__browse(struct map *self);
6#endif /* _PERF_UI_MAP_BROWSER_H_ */
diff --git a/tools/perf/util/ui/helpline.c b/tools/perf/util/ui/helpline.c
new file mode 100644
index 000000000000..8d79daa4458a
--- /dev/null
+++ b/tools/perf/util/ui/helpline.c
@@ -0,0 +1,69 @@
1#define _GNU_SOURCE
2#include <stdio.h>
3#include <stdlib.h>
4#include <newt.h>
5
6#include "../debug.h"
7#include "helpline.h"
8
9void ui_helpline__pop(void)
10{
11 newtPopHelpLine();
12}
13
14void ui_helpline__push(const char *msg)
15{
16 newtPushHelpLine(msg);
17}
18
19void ui_helpline__vpush(const char *fmt, va_list ap)
20{
21 char *s;
22
23 if (vasprintf(&s, fmt, ap) < 0)
24 vfprintf(stderr, fmt, ap);
25 else {
26 ui_helpline__push(s);
27 free(s);
28 }
29}
30
31void ui_helpline__fpush(const char *fmt, ...)
32{
33 va_list ap;
34
35 va_start(ap, fmt);
36 ui_helpline__vpush(fmt, ap);
37 va_end(ap);
38}
39
40void ui_helpline__puts(const char *msg)
41{
42 ui_helpline__pop();
43 ui_helpline__push(msg);
44}
45
46void ui_helpline__init(void)
47{
48 ui_helpline__puts(" ");
49}
50
51char ui_helpline__last_msg[1024];
52
53int ui_helpline__show_help(const char *format, va_list ap)
54{
55 int ret;
56 static int backlog;
57
58 ret = vsnprintf(ui_helpline__last_msg + backlog,
59 sizeof(ui_helpline__last_msg) - backlog, format, ap);
60 backlog += ret;
61
62 if (ui_helpline__last_msg[backlog - 1] == '\n') {
63 ui_helpline__puts(ui_helpline__last_msg);
64 newtRefresh();
65 backlog = 0;
66 }
67
68 return ret;
69}
diff --git a/tools/perf/util/ui/helpline.h b/tools/perf/util/ui/helpline.h
new file mode 100644
index 000000000000..ab6028d0c401
--- /dev/null
+++ b/tools/perf/util/ui/helpline.h
@@ -0,0 +1,11 @@
1#ifndef _PERF_UI_HELPLINE_H_
2#define _PERF_UI_HELPLINE_H_ 1
3
4void ui_helpline__init(void);
5void ui_helpline__pop(void);
6void ui_helpline__push(const char *msg);
7void ui_helpline__vpush(const char *fmt, va_list ap);
8void ui_helpline__fpush(const char *fmt, ...);
9void ui_helpline__puts(const char *msg);
10
11#endif /* _PERF_UI_HELPLINE_H_ */
diff --git a/tools/perf/util/ui/libslang.h b/tools/perf/util/ui/libslang.h
new file mode 100644
index 000000000000..5623da8e8080
--- /dev/null
+++ b/tools/perf/util/ui/libslang.h
@@ -0,0 +1,27 @@
1#ifndef _PERF_UI_SLANG_H_
2#define _PERF_UI_SLANG_H_ 1
3/*
4 * slang versions <= 2.0.6 have a "#if HAVE_LONG_LONG" that breaks
5 * the build if it isn't defined. Use the equivalent one that glibc
6 * has on features.h.
7 */
8#include <features.h>
9#ifndef HAVE_LONG_LONG
10#define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG
11#endif
12#include <slang.h>
13
14#if SLANG_VERSION < 20104
15#define slsmg_printf(msg, args...) \
16 SLsmg_printf((char *)msg, ##args)
17#define slsmg_write_nstring(msg, len) \
18 SLsmg_write_nstring((char *)msg, len)
19#define sltt_set_color(obj, name, fg, bg) \
20 SLtt_set_color(obj,(char *)name, (char *)fg, (char *)bg)
21#else
22#define slsmg_printf SLsmg_printf
23#define slsmg_write_nstring SLsmg_write_nstring
24#define sltt_set_color SLtt_set_color
25#endif
26
27#endif /* _PERF_UI_SLANG_H_ */
diff --git a/tools/perf/util/ui/progress.c b/tools/perf/util/ui/progress.c
new file mode 100644
index 000000000000..d7fc399d36b3
--- /dev/null
+++ b/tools/perf/util/ui/progress.c
@@ -0,0 +1,60 @@
1#include <stdlib.h>
2#include <newt.h>
3#include "../cache.h"
4#include "progress.h"
5
6struct ui_progress {
7 newtComponent form, scale;
8};
9
10struct ui_progress *ui_progress__new(const char *title, u64 total)
11{
12 struct ui_progress *self = malloc(sizeof(*self));
13
14 if (self != NULL) {
15 int cols;
16
17 if (use_browser <= 0)
18 return self;
19 newtGetScreenSize(&cols, NULL);
20 cols -= 4;
21 newtCenteredWindow(cols, 1, title);
22 self->form = newtForm(NULL, NULL, 0);
23 if (self->form == NULL)
24 goto out_free_self;
25 self->scale = newtScale(0, 0, cols, total);
26 if (self->scale == NULL)
27 goto out_free_form;
28 newtFormAddComponent(self->form, self->scale);
29 newtRefresh();
30 }
31
32 return self;
33
34out_free_form:
35 newtFormDestroy(self->form);
36out_free_self:
37 free(self);
38 return NULL;
39}
40
41void ui_progress__update(struct ui_progress *self, u64 curr)
42{
43 /*
44 * FIXME: We should have a per UI backend way of showing progress,
45 * stdio will just show a percentage as NN%, etc.
46 */
47 if (use_browser <= 0)
48 return;
49 newtScaleSet(self->scale, curr);
50 newtRefresh();
51}
52
53void ui_progress__delete(struct ui_progress *self)
54{
55 if (use_browser > 0) {
56 newtFormDestroy(self->form);
57 newtPopWindow();
58 }
59 free(self);
60}
diff --git a/tools/perf/util/ui/progress.h b/tools/perf/util/ui/progress.h
new file mode 100644
index 000000000000..a3820a0beb5b
--- /dev/null
+++ b/tools/perf/util/ui/progress.h
@@ -0,0 +1,11 @@
1#ifndef _PERF_UI_PROGRESS_H_
2#define _PERF_UI_PROGRESS_H_ 1
3
4struct ui_progress;
5
6struct ui_progress *ui_progress__new(const char *title, u64 total);
7void ui_progress__delete(struct ui_progress *self);
8
9void ui_progress__update(struct ui_progress *self, u64 curr);
10
11#endif
diff --git a/tools/perf/util/ui/setup.c b/tools/perf/util/ui/setup.c
new file mode 100644
index 000000000000..662085032eb7
--- /dev/null
+++ b/tools/perf/util/ui/setup.c
@@ -0,0 +1,42 @@
1#include <newt.h>
2#include <signal.h>
3#include <stdbool.h>
4
5#include "../cache.h"
6#include "../debug.h"
7#include "browser.h"
8#include "helpline.h"
9
10static void newt_suspend(void *d __used)
11{
12 newtSuspend();
13 raise(SIGTSTP);
14 newtResume();
15}
16
17void setup_browser(void)
18{
19 if (!isatty(1) || !use_browser || dump_trace) {
20 use_browser = 0;
21 setup_pager();
22 return;
23 }
24
25 use_browser = 1;
26 newtInit();
27 newtCls();
28 newtSetSuspendCallback(newt_suspend, NULL);
29 ui_helpline__init();
30 ui_browser__init();
31}
32
33void exit_browser(bool wait_for_ok)
34{
35 if (use_browser > 0) {
36 if (wait_for_ok) {
37 char title[] = "Fatal Error", ok[] = "Ok";
38 newtWinMessage(title, ok, ui_helpline__last_msg);
39 }
40 newtFinished();
41 }
42}
diff --git a/tools/perf/util/ui/util.c b/tools/perf/util/ui/util.c
new file mode 100644
index 000000000000..04600e26ceea
--- /dev/null
+++ b/tools/perf/util/ui/util.c
@@ -0,0 +1,114 @@
1#include <newt.h>
2#include <signal.h>
3#include <stdio.h>
4#include <stdbool.h>
5#include <string.h>
6#include <sys/ttydefaults.h>
7
8#include "../cache.h"
9#include "../debug.h"
10#include "browser.h"
11#include "helpline.h"
12#include "util.h"
13
14newtComponent newt_form__new(void);
15
16static void newt_form__set_exit_keys(newtComponent self)
17{
18 newtFormAddHotKey(self, NEWT_KEY_LEFT);
19 newtFormAddHotKey(self, NEWT_KEY_ESCAPE);
20 newtFormAddHotKey(self, 'Q');
21 newtFormAddHotKey(self, 'q');
22 newtFormAddHotKey(self, CTRL('c'));
23}
24
25newtComponent newt_form__new(void)
26{
27 newtComponent self = newtForm(NULL, NULL, 0);
28 if (self)
29 newt_form__set_exit_keys(self);
30 return self;
31}
32
33int ui__popup_menu(int argc, char * const argv[])
34{
35 struct newtExitStruct es;
36 int i, rc = -1, max_len = 5;
37 newtComponent listbox, form = newt_form__new();
38
39 if (form == NULL)
40 return -1;
41
42 listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT);
43 if (listbox == NULL)
44 goto out_destroy_form;
45
46 newtFormAddComponent(form, listbox);
47
48 for (i = 0; i < argc; ++i) {
49 int len = strlen(argv[i]);
50 if (len > max_len)
51 max_len = len;
52 if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i))
53 goto out_destroy_form;
54 }
55
56 newtCenteredWindow(max_len, argc, NULL);
57 newtFormRun(form, &es);
58 rc = newtListboxGetCurrent(listbox) - NULL;
59 if (es.reason == NEWT_EXIT_HOTKEY)
60 rc = -1;
61 newtPopWindow();
62out_destroy_form:
63 newtFormDestroy(form);
64 return rc;
65}
66
67int ui__help_window(const char *text)
68{
69 struct newtExitStruct es;
70 newtComponent tb, form = newt_form__new();
71 int rc = -1;
72 int max_len = 0, nr_lines = 0;
73 const char *t;
74
75 if (form == NULL)
76 return -1;
77
78 t = text;
79 while (1) {
80 const char *sep = strchr(t, '\n');
81 int len;
82
83 if (sep == NULL)
84 sep = strchr(t, '\0');
85 len = sep - t;
86 if (max_len < len)
87 max_len = len;
88 ++nr_lines;
89 if (*sep == '\0')
90 break;
91 t = sep + 1;
92 }
93
94 tb = newtTextbox(0, 0, max_len, nr_lines, 0);
95 if (tb == NULL)
96 goto out_destroy_form;
97
98 newtTextboxSetText(tb, text);
99 newtFormAddComponent(form, tb);
100 newtCenteredWindow(max_len, nr_lines, NULL);
101 newtFormRun(form, &es);
102 newtPopWindow();
103 rc = 0;
104out_destroy_form:
105 newtFormDestroy(form);
106 return rc;
107}
108
109bool ui__dialog_yesno(const char *msg)
110{
111 /* newtWinChoice should really be accepting const char pointers... */
112 char yes[] = "Yes", no[] = "No";
113 return newtWinChoice(NULL, yes, no, (char *)msg) == 1;
114}
diff --git a/tools/perf/util/ui/util.h b/tools/perf/util/ui/util.h
new file mode 100644
index 000000000000..afcbc1d99531
--- /dev/null
+++ b/tools/perf/util/ui/util.h
@@ -0,0 +1,10 @@
1#ifndef _PERF_UI_UTIL_H_
2#define _PERF_UI_UTIL_H_ 1
3
4#include <stdbool.h>
5
6int ui__popup_menu(int argc, char * const argv[]);
7int ui__help_window(const char *text);
8bool ui__dialog_yesno(const char *msg);
9
10#endif /* _PERF_UI_UTIL_H_ */