aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/stable/sysfs-driver-ib_srp13
-rw-r--r--Documentation/ABI/stable/sysfs-transport-srp39
-rw-r--r--Documentation/devicetree/bindings/arc/pmu.txt24
-rw-r--r--Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt4
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-bcm-kona.txt35
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-exynos5.txt44
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-rcar.txt23
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-st.txt41
-rw-r--r--Documentation/devicetree/bindings/media/st-rc.txt29
-rw-r--r--Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt5
-rw-r--r--Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt9
-rw-r--r--Documentation/devicetree/bindings/power/twl-charger.txt20
-rw-r--r--Documentation/devicetree/bindings/power_supply/ti,bq24735.txt32
-rw-r--r--Documentation/devicetree/bindings/watchdog/dw_wdt.txt21
-rw-r--r--Documentation/devicetree/bindings/watchdog/men-a021-wdt.txt (renamed from Documentation/devicetree/bindings/gpio/men-a021-wdt.txt)0
-rw-r--r--Documentation/devicetree/bindings/watchdog/moxa,moxart-watchdog.txt15
-rw-r--r--Documentation/devicetree/bindings/watchdog/rt2880-wdt.txt19
-rw-r--r--Documentation/devicetree/bindings/watchdog/sirfsoc_wdt.txt14
-rw-r--r--Documentation/i2c/busses/i2c-i8011
-rw-r--r--Documentation/power/power_supply_class.txt8
-rw-r--r--MAINTAINERS17
-rw-r--r--arch/alpha/include/asm/thread_info.h2
-rw-r--r--arch/arc/boot/dts/abilis_tb100.dtsi172
-rw-r--r--arch/arc/boot/dts/abilis_tb100_dvk.dts24
-rw-r--r--arch/arc/boot/dts/abilis_tb101.dtsi178
-rw-r--r--arch/arc/boot/dts/abilis_tb101_dvk.dts24
-rw-r--r--arch/arc/boot/dts/abilis_tb10x.dtsi3
-rw-r--r--arch/arc/boot/dts/angel4.dts4
-rw-r--r--arch/arc/configs/fpga_noramfs_defconfig64
-rw-r--r--arch/arc/include/asm/perf_event.h204
-rw-r--r--arch/arc/include/asm/thread_info.h2
-rw-r--r--arch/arc/kernel/Makefile1
-rw-r--r--arch/arc/kernel/perf_event.c326
-rw-r--r--arch/arc/plat-tb10x/Kconfig2
-rw-r--r--arch/arm/boot/dts/ecx-2000.dts6
-rw-r--r--arch/arm/boot/dts/ecx-common.dtsi6
-rw-r--r--arch/arm/boot/dts/highbank.dts6
-rw-r--r--arch/arm/boot/dts/twl4030.dtsi6
-rw-r--r--arch/arm/configs/prima2_defconfig1
-rw-r--r--arch/arm/include/asm/thread_info.h6
-rw-r--r--arch/arm/mach-at91/board-sam9260ek.c2
-rw-r--r--arch/arm/mach-at91/board-sam9263ek.c2
-rw-r--r--arch/arm/mach-davinci/board-da830-evm.c2
-rw-r--r--arch/arm/mach-davinci/board-da850-evm.c2
-rw-r--r--arch/arm/mach-davinci/board-dm365-evm.c2
-rw-r--r--arch/arm/mach-davinci/board-dm644x-evm.c2
-rw-r--r--arch/arm/mach-davinci/board-dm646x-evm.c2
-rw-r--r--arch/arm/mach-davinci/board-mityomapl138.c2
-rw-r--r--arch/arm/mach-davinci/board-sffsdr.c2
-rw-r--r--arch/arm/mach-imx/mach-pca100.c2
-rw-r--r--arch/arm/mach-imx/mach-pcm037.c2
-rw-r--r--arch/arm/mach-imx/mach-pcm038.c2
-rw-r--r--arch/arm/mach-imx/mach-pcm043.c2
-rw-r--r--arch/arm/mach-imx/mach-vpr200.c2
-rw-r--r--arch/arm/mach-kirkwood/lacie_v2-common.c2
-rw-r--r--arch/arm/mach-omap1/board-osk.c2
-rw-r--r--arch/arm/mach-omap2/board-cm-t35.c2
-rw-r--r--arch/arm/mach-omap2/board-h4.c2
-rw-r--r--arch/arm/mach-omap2/board-omap3stalker.c2
-rw-r--r--arch/arm/mach-pxa/stargate2.c2
-rw-r--r--arch/arm/mach-s3c24xx/mach-mini2440.c2
-rw-r--r--arch/arm64/include/asm/thread_info.h6
-rw-r--r--arch/avr32/include/asm/thread_info.h2
-rw-r--r--arch/blackfin/include/asm/hardirq.h3
-rw-r--r--arch/blackfin/include/asm/thread_info.h2
-rw-r--r--arch/c6x/include/asm/thread_info.h2
-rw-r--r--arch/cris/include/asm/hardirq.h12
-rw-r--r--arch/cris/include/asm/thread_info.h2
-rw-r--r--arch/frv/include/asm/thread_info.h2
-rw-r--r--arch/hexagon/include/asm/thread_info.h4
-rw-r--r--arch/ia64/include/asm/thread_info.h3
-rw-r--r--arch/ia64/kernel/entry.S15
-rw-r--r--arch/m32r/include/asm/hardirq.h16
-rw-r--r--arch/m32r/include/asm/thread_info.h2
-rw-r--r--arch/m32r/kernel/entry.S8
-rw-r--r--arch/m68k/include/asm/hardirq.h11
-rw-r--r--arch/m68k/include/asm/thread_info.h2
-rw-r--r--arch/m68k/kernel/entry.S40
-rw-r--r--arch/m68k/kernel/ints.c6
-rw-r--r--arch/m68k/platform/68000/entry.S33
-rw-r--r--arch/m68k/platform/68360/entry.S24
-rw-r--r--arch/metag/include/asm/thread_info.h2
-rw-r--r--arch/microblaze/include/asm/thread_info.h2
-rw-r--r--arch/mips/configs/db1235_defconfig1
-rw-r--r--arch/mips/include/asm/thread_info.h2
-rw-r--r--arch/mn10300/include/asm/thread_info.h2
-rw-r--r--arch/parisc/include/asm/thread_info.h3
-rw-r--r--arch/powerpc/include/asm/thread_info.h2
-rw-r--r--arch/s390/boot/Makefile4
-rw-r--r--arch/s390/include/asm/ctl_reg.h2
-rw-r--r--arch/s390/include/asm/eadm.h13
-rw-r--r--arch/s390/include/asm/hardirq.h2
-rw-r--r--arch/s390/include/asm/pci.h6
-rw-r--r--arch/s390/include/asm/sclp.h3
-rw-r--r--arch/s390/include/asm/setup.h3
-rw-r--r--arch/s390/include/asm/thread_info.h2
-rw-r--r--arch/s390/kernel/crash_dump.c22
-rw-r--r--arch/s390/kernel/early.c2
-rw-r--r--arch/s390/kernel/setup.c7
-rw-r--r--arch/s390/pci/pci.c202
-rw-r--r--arch/s390/pci/pci_clp.c8
-rw-r--r--arch/s390/pci/pci_event.c79
-rw-r--r--arch/score/include/asm/thread_info.h2
-rw-r--r--arch/sh/boards/mach-ecovec24/setup.c1
-rw-r--r--arch/sh/include/asm/thread_info.h2
-rw-r--r--arch/sh/kernel/entry-common.S6
-rw-r--r--arch/sparc/include/asm/hardirq_32.h1
-rw-r--r--arch/sparc/include/asm/hardirq_64.h2
-rw-r--r--arch/sparc/include/asm/thread_info_32.h2
-rw-r--r--arch/sparc/include/asm/thread_info_64.h2
-rw-r--r--arch/sparc/kernel/rtrap_64.S6
-rw-r--r--arch/tile/include/asm/hardirq.h2
-rw-r--r--arch/tile/include/asm/thread_info.h2
-rw-r--r--arch/um/Kconfig.char4
-rw-r--r--arch/um/Kconfig.common5
-rw-r--r--arch/um/Makefile11
-rw-r--r--arch/um/configs/i386_defconfig76
-rw-r--r--arch/um/configs/x86_64_defconfig75
-rw-r--r--arch/um/defconfig899
-rw-r--r--arch/um/drivers/mconsole_kern.c6
-rw-r--r--arch/um/include/asm/processor-generic.h2
-rw-r--r--arch/um/include/asm/thread_info.h2
-rw-r--r--arch/um/include/shared/as-layout.h3
-rw-r--r--arch/um/include/shared/os.h1
-rw-r--r--arch/um/kernel/process.c15
-rw-r--r--arch/um/kernel/sysrq.c102
-rw-r--r--arch/um/kernel/trap.c14
-rw-r--r--arch/um/kernel/um_arch.c2
-rw-r--r--arch/um/os-Linux/signal.c8
-rw-r--r--arch/unicore32/include/asm/thread_info.h6
-rw-r--r--arch/x86/include/asm/thread_info.h2
-rw-r--r--arch/x86/kernel/apic/apic.c1
-rw-r--r--arch/x86/um/Kconfig5
-rw-r--r--arch/x86/um/asm/processor_32.h5
-rw-r--r--arch/x86/um/asm/processor_64.h5
-rw-r--r--arch/x86/um/sysrq_32.c66
-rw-r--r--arch/x86/um/sysrq_64.c8
-rw-r--r--arch/x86/um/vdso/.gitignore2
-rw-r--r--arch/xtensa/include/asm/thread_info.h2
-rw-r--r--drivers/edac/cell_edac.c1
-rw-r--r--drivers/edac/edac_device.c9
-rw-r--r--drivers/edac/edac_mc.c6
-rw-r--r--drivers/edac/edac_pci.c8
-rw-r--r--drivers/edac/highbank_l2_edac.c33
-rw-r--r--drivers/edac/highbank_mc_edac.c175
-rw-r--r--drivers/edac/mpc85xx_edac.c22
-rw-r--r--drivers/edac/sb_edac.c593
-rw-r--r--drivers/gpu/drm/drm_encoder_slave.c8
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/ic.c3
-rw-r--r--drivers/i2c/busses/Kconfig32
-rw-r--r--drivers/i2c/busses/Makefile3
-rw-r--r--drivers/i2c/busses/i2c-bcm-kona.c909
-rw-r--r--drivers/i2c/busses/i2c-bfin-twi.c6
-rw-r--r--drivers/i2c/busses/i2c-cbus-gpio.c2
-rw-r--r--drivers/i2c/busses/i2c-davinci.c2
-rw-r--r--drivers/i2c/busses/i2c-designware-platdrv.c2
-rw-r--r--drivers/i2c/busses/i2c-eg20t.c26
-rw-r--r--drivers/i2c/busses/i2c-exynos5.c769
-rw-r--r--drivers/i2c/busses/i2c-gpio.c1
-rw-r--r--drivers/i2c/busses/i2c-i801.c3
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c2
-rw-r--r--drivers/i2c/busses/i2c-mxs.c340
-rw-r--r--drivers/i2c/busses/i2c-pnx.c1
-rw-r--r--drivers/i2c/busses/i2c-rcar.c65
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c1
-rw-r--r--drivers/i2c/busses/i2c-scmi.c6
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c8
-rw-r--r--drivers/i2c/busses/i2c-st.c872
-rw-r--r--drivers/i2c/busses/i2c-wmt.c1
-rw-r--r--drivers/i2c/busses/i2c-xiic.c3
-rw-r--r--drivers/i2c/i2c-core.c16
-rw-r--r--drivers/i2c/i2c-dev.c19
-rw-r--r--drivers/i2c/i2c-smbus.c10
-rw-r--r--drivers/i2c/muxes/i2c-arb-gpio-challenge.c2
-rw-r--r--drivers/i2c/muxes/i2c-mux-gpio.c10
-rw-r--r--drivers/i2c/muxes/i2c-mux-pinctrl.c1
-rw-r--r--drivers/infiniband/Kconfig11
-rw-r--r--drivers/infiniband/core/cm.c5
-rw-r--r--drivers/infiniband/core/cma.c68
-rw-r--r--drivers/infiniband/core/netlink.c2
-rw-r--r--drivers/infiniband/core/sysfs.c1
-rw-r--r--drivers/infiniband/core/ucma.c4
-rw-r--r--drivers/infiniband/core/uverbs.h36
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c109
-rw-r--r--drivers/infiniband/core/uverbs_main.c128
-rw-r--r--drivers/infiniband/core/verbs.c17
-rw-r--r--drivers/infiniband/hw/cxgb4/device.c4
-rw-r--r--drivers/infiniband/hw/ipath/ipath_user_sdma.c7
-rw-r--r--drivers/infiniband/hw/mlx4/cq.c9
-rw-r--r--drivers/infiniband/hw/mlx4/main.c8
-rw-r--r--drivers/infiniband/hw/mlx5/cq.c25
-rw-r--r--drivers/infiniband/hw/mlx5/main.c3
-rw-r--r--drivers/infiniband/hw/mlx5/mlx5_ib.h6
-rw-r--r--drivers/infiniband/hw/mlx5/mr.c167
-rw-r--r--drivers/infiniband/hw/mlx5/qp.c21
-rw-r--r--drivers/infiniband/hw/mlx5/srq.c8
-rw-r--r--drivers/infiniband/hw/nes/nes_verbs.c2
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma.h53
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_hw.c2
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_main.c7
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_verbs.c6
-rw-r--r--drivers/infiniband/hw/qib/qib_iba7322.c11
-rw-r--r--drivers/infiniband/hw/qib/qib_mad.h14
-rw-r--r--drivers/infiniband/hw/qib/qib_user_sdma.c6
-rw-r--r--drivers/infiniband/hw/qib/qib_verbs.h10
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib.h4
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_cm.c14
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c24
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c12
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c29
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_netlink.c4
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_vlan.c10
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c500
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.h21
-rw-r--r--drivers/media/common/b2c2/flexcop-sram.c6
-rw-r--r--drivers/media/common/saa7146/saa7146_core.c4
-rw-r--r--drivers/media/common/siano/smscoreapi.c8
-rw-r--r--drivers/media/common/siano/smsdvb-main.c8
-rw-r--r--drivers/media/dvb-core/dvb_demux.c17
-rw-r--r--drivers/media/dvb-frontends/Kconfig7
-rw-r--r--drivers/media/dvb-frontends/Makefile1
-rw-r--r--drivers/media/dvb-frontends/af9013.c14
-rw-r--r--drivers/media/dvb-frontends/af9033.c23
-rw-r--r--drivers/media/dvb-frontends/bcm3510.c15
-rw-r--r--drivers/media/dvb-frontends/cx24110.c2
-rw-r--r--drivers/media/dvb-frontends/cx24117.c1650
-rw-r--r--drivers/media/dvb-frontends/cx24117.h47
-rw-r--r--drivers/media/dvb-frontends/cx24123.c2
-rw-r--r--drivers/media/dvb-frontends/cxd2820r_core.c25
-rw-r--r--drivers/media/dvb-frontends/dib9000.c4
-rw-r--r--drivers/media/dvb-frontends/drxd_hard.c12
-rw-r--r--drivers/media/dvb-frontends/drxk_hard.c4
-rw-r--r--drivers/media/dvb-frontends/itd1000.c13
-rw-r--r--drivers/media/dvb-frontends/mt312.c10
-rw-r--r--drivers/media/dvb-frontends/nxt200x.c11
-rw-r--r--drivers/media/dvb-frontends/rtl2830.c14
-rw-r--r--drivers/media/dvb-frontends/rtl2832.c15
-rw-r--r--drivers/media/dvb-frontends/rtl2832.h1
-rw-r--r--drivers/media/dvb-frontends/s5h1420.c11
-rw-r--r--drivers/media/dvb-frontends/stb0899_drv.c12
-rw-r--r--drivers/media/dvb-frontends/stb6100.c11
-rw-r--r--drivers/media/dvb-frontends/stv0367.c13
-rw-r--r--drivers/media/dvb-frontends/stv090x.c12
-rw-r--r--drivers/media/dvb-frontends/stv6110.c12
-rw-r--r--drivers/media/dvb-frontends/stv6110x.c13
-rw-r--r--drivers/media/dvb-frontends/tda10071.c25
-rw-r--r--drivers/media/dvb-frontends/tda18271c2dd.c14
-rw-r--r--drivers/media/dvb-frontends/tda8083.c4
-rw-r--r--drivers/media/dvb-frontends/ts2020.c7
-rw-r--r--drivers/media/dvb-frontends/ts2020.h1
-rw-r--r--drivers/media/dvb-frontends/zl10039.c12
-rw-r--r--drivers/media/i2c/Kconfig9
-rw-r--r--drivers/media/i2c/Makefile1
-rw-r--r--drivers/media/i2c/adv7343.c1
-rw-r--r--drivers/media/i2c/lm3560.c488
-rw-r--r--drivers/media/i2c/s5c73m3/s5c73m3-core.c2
-rw-r--r--drivers/media/i2c/soc_camera/imx074.c4
-rw-r--r--drivers/media/i2c/soc_camera/ov9640.c2
-rw-r--r--drivers/media/i2c/ths8200.c1
-rw-r--r--drivers/media/i2c/tvp514x.c1
-rw-r--r--drivers/media/i2c/tvp7002.c1
-rw-r--r--drivers/media/pci/b2c2/flexcop-pci.c2
-rw-r--r--drivers/media/pci/bt8xx/bt878.c4
-rw-r--r--drivers/media/pci/bt8xx/bttv-driver.c2
-rw-r--r--drivers/media/pci/cx18/cx18-driver.c23
-rw-r--r--drivers/media/pci/cx23885/Kconfig1
-rw-r--r--drivers/media/pci/cx23885/cimax2.c13
-rw-r--r--drivers/media/pci/cx23885/cx23885-cards.c108
-rw-r--r--drivers/media/pci/cx23885/cx23885-core.c2
-rw-r--r--drivers/media/pci/cx23885/cx23885-dvb.c24
-rw-r--r--drivers/media/pci/cx23885/cx23885-input.c12
-rw-r--r--drivers/media/pci/cx23885/cx23885-video.c3
-rw-r--r--drivers/media/pci/cx23885/cx23885.h3
-rw-r--r--drivers/media/pci/cx25821/cx25821-cards.c2
-rw-r--r--drivers/media/pci/cx25821/cx25821-medusa-video.c18
-rw-r--r--drivers/media/pci/cx25821/cx25821-medusa-video.h6
-rw-r--r--drivers/media/pci/cx25821/cx25821-video-upstream.c8
-rw-r--r--drivers/media/pci/cx88/cx88-alsa.c29
-rw-r--r--drivers/media/pci/cx88/cx88-mpeg.c17
-rw-r--r--drivers/media/pci/cx88/cx88-video.c18
-rw-r--r--drivers/media/pci/ddbridge/ddbridge-core.c2
-rw-r--r--drivers/media/pci/dm1105/dm1105.c5
-rw-r--r--drivers/media/pci/ivtv/ivtv-driver.c2
-rw-r--r--drivers/media/pci/mantis/mantis_pci.c2
-rw-r--r--drivers/media/pci/meye/meye.c2
-rw-r--r--drivers/media/pci/ngene/ngene-core.c4
-rw-r--r--drivers/media/pci/pluto2/pluto2.c2
-rw-r--r--drivers/media/pci/pt1/pt1.c2
-rw-r--r--drivers/media/pci/saa7134/saa7134-alsa.c2
-rw-r--r--drivers/media/pci/saa7134/saa7134-core.c2
-rw-r--r--drivers/media/pci/saa7164/saa7164-core.c3
-rw-r--r--drivers/media/pci/ttpci/av7110_hw.c19
-rw-r--r--drivers/media/pci/zoran/Kconfig1
-rw-r--r--drivers/media/pci/zoran/zoran_card.c2
-rw-r--r--drivers/media/platform/Kconfig19
-rw-r--r--drivers/media/platform/Makefile2
-rw-r--r--drivers/media/platform/coda.c278
-rw-r--r--drivers/media/platform/davinci/vpbe_display.c2
-rw-r--r--drivers/media/platform/davinci/vpfe_capture.c4
-rw-r--r--drivers/media/platform/davinci/vpif_capture.c2
-rw-r--r--drivers/media/platform/exynos-gsc/gsc-core.h1
-rw-r--r--drivers/media/platform/exynos-gsc/gsc-m2m.c29
-rw-r--r--drivers/media/platform/exynos4-is/fimc-isp.c2
-rw-r--r--drivers/media/platform/exynos4-is/media-dev.c6
-rw-r--r--drivers/media/platform/m2m-deinterlace.c3
-rw-r--r--drivers/media/platform/marvell-ccic/mcam-core.c14
-rw-r--r--drivers/media/platform/marvell-ccic/mmp-driver.c1
-rw-r--r--drivers/media/platform/mem2mem_testdev.c3
-rw-r--r--drivers/media/platform/s5p-g2d/g2d.c2
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc.c12
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v5.c2
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c2
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_enc.c8
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c2
-rw-r--r--drivers/media/platform/s5p-tv/mixer_grp_layer.c2
-rw-r--r--drivers/media/platform/s5p-tv/mixer_vp_layer.c2
-rw-r--r--drivers/media/platform/soc_camera/rcar_vin.c6
-rw-r--r--drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c2
-rw-r--r--drivers/media/platform/soc_camera/soc_camera.c46
-rw-r--r--drivers/media/platform/ti-vpe/Makefile5
-rw-r--r--drivers/media/platform/ti-vpe/vpdma.c846
-rw-r--r--drivers/media/platform/ti-vpe/vpdma.h203
-rw-r--r--drivers/media/platform/ti-vpe/vpdma_priv.h641
-rw-r--r--drivers/media/platform/ti-vpe/vpe.c2099
-rw-r--r--drivers/media/platform/ti-vpe/vpe_regs.h496
-rw-r--r--drivers/media/platform/timblogiw.c4
-rw-r--r--drivers/media/radio/radio-keene.c2
-rw-r--r--drivers/media/radio/radio-sf16fmr2.c5
-rw-r--r--drivers/media/radio/radio-shark.c2
-rw-r--r--drivers/media/radio/radio-shark2.c2
-rw-r--r--drivers/media/radio/si470x/radio-si470x-common.c2
-rw-r--r--drivers/media/radio/si470x/radio-si470x-i2c.c4
-rw-r--r--drivers/media/radio/si4713-i2c.c2
-rw-r--r--drivers/media/radio/tef6862.c20
-rw-r--r--drivers/media/radio/wl128x/fmdrv_common.c2
-rw-r--r--drivers/media/rc/Kconfig10
-rw-r--r--drivers/media/rc/Makefile1
-rw-r--r--drivers/media/rc/fintek-cir.h4
-rw-r--r--drivers/media/rc/gpio-ir-recv.c1
-rw-r--r--drivers/media/rc/iguanair.c22
-rw-r--r--drivers/media/rc/ir-rx51.c3
-rw-r--r--drivers/media/rc/nuvoton-cir.h4
-rw-r--r--drivers/media/rc/st_rc.c395
-rw-r--r--drivers/media/rc/winbond-cir.c2
-rw-r--r--drivers/media/tuners/e4000.c25
-rw-r--r--drivers/media/tuners/fc0012.c2
-rw-r--r--drivers/media/tuners/fc0013.c2
-rw-r--r--drivers/media/tuners/fc2580.c25
-rw-r--r--drivers/media/tuners/r820t.c22
-rw-r--r--drivers/media/tuners/tda18212.c25
-rw-r--r--drivers/media/tuners/tda18218.c23
-rw-r--r--drivers/media/tuners/tda9887.c4
-rw-r--r--drivers/media/tuners/tuner-xc2028.c12
-rw-r--r--drivers/media/usb/b2c2/flexcop-usb.c6
-rw-r--r--drivers/media/usb/cpia2/cpia2_usb.c2
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-cards.c110
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-pcb-cfg.c4
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9015.c3
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9035.c29
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf.c10
-rw-r--r--drivers/media/usb/dvb-usb-v2/rtl28xxu.c42
-rw-r--r--drivers/media/usb/dvb-usb-v2/rtl28xxu.h1
-rw-r--r--drivers/media/usb/dvb-usb/az6027.c4
-rw-r--r--drivers/media/usb/dvb-usb/cxusb.c41
-rw-r--r--drivers/media/usb/dvb-usb/dibusb-common.c10
-rw-r--r--drivers/media/usb/dvb-usb/dw2102.c103
-rw-r--r--drivers/media/usb/em28xx/em28xx-camera.c42
-rw-r--r--drivers/media/usb/em28xx/em28xx-cards.c121
-rw-r--r--drivers/media/usb/em28xx/em28xx-dvb.c63
-rw-r--r--drivers/media/usb/em28xx/em28xx-video.c7
-rw-r--r--drivers/media/usb/em28xx/em28xx.h2
-rw-r--r--drivers/media/usb/gspca/conex.c3
-rw-r--r--drivers/media/usb/gspca/cpia1.c4
-rw-r--r--drivers/media/usb/gspca/gspca.c48
-rw-r--r--drivers/media/usb/gspca/gspca.h10
-rw-r--r--drivers/media/usb/gspca/jeilinj.c5
-rw-r--r--drivers/media/usb/gspca/jl2005bcd.c2
-rw-r--r--drivers/media/usb/gspca/m5602/m5602_mt9m111.c2
-rw-r--r--drivers/media/usb/gspca/mars.c7
-rw-r--r--drivers/media/usb/gspca/mr97310a.c6
-rw-r--r--drivers/media/usb/gspca/nw80x.c11
-rw-r--r--drivers/media/usb/gspca/ov519.c52
-rw-r--r--drivers/media/usb/gspca/ov534.c5
-rw-r--r--drivers/media/usb/gspca/ov534_9.c334
-rw-r--r--drivers/media/usb/gspca/pac207.c4
-rw-r--r--drivers/media/usb/gspca/pac7311.c6
-rw-r--r--drivers/media/usb/gspca/se401.c6
-rw-r--r--drivers/media/usb/gspca/sn9c20x.c6
-rw-r--r--drivers/media/usb/gspca/sonixb.c7
-rw-r--r--drivers/media/usb/gspca/sonixj.c3
-rw-r--r--drivers/media/usb/gspca/spca1528.c3
-rw-r--r--drivers/media/usb/gspca/spca500.c3
-rw-r--r--drivers/media/usb/gspca/sq905c.c2
-rw-r--r--drivers/media/usb/gspca/sq930x.c3
-rw-r--r--drivers/media/usb/gspca/stk014.c5
-rw-r--r--drivers/media/usb/gspca/stk1135.c76
-rw-r--r--drivers/media/usb/gspca/stv06xx/stv06xx.c2
-rw-r--r--drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c2
-rw-r--r--drivers/media/usb/gspca/sunplus.c3
-rw-r--r--drivers/media/usb/gspca/topro.c13
-rw-r--r--drivers/media/usb/gspca/tv8532.c7
-rw-r--r--drivers/media/usb/gspca/vicam.c8
-rw-r--r--drivers/media/usb/gspca/w996Xcf.c28
-rw-r--r--drivers/media/usb/gspca/xirlink_cit.c46
-rw-r--r--drivers/media/usb/gspca/zc3xx.c3
-rw-r--r--drivers/media/usb/hdpvr/hdpvr-core.c11
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-hdw.c2
-rw-r--r--drivers/media/usb/siano/smsusb.c43
-rw-r--r--drivers/media/usb/tlg2300/pd-main.c2
-rw-r--r--drivers/media/usb/ttusb-dec/ttusb_dec.c152
-rw-r--r--drivers/media/usb/uvc/uvc_ctrl.c4
-rw-r--r--drivers/media/usb/uvc/uvc_video.c3
-rw-r--r--drivers/media/v4l2-core/tuner-core.c8
-rw-r--r--drivers/media/v4l2-core/v4l2-async.c30
-rw-r--r--drivers/media/v4l2-core/v4l2-clk.c39
-rw-r--r--drivers/media/v4l2-core/v4l2-common.c10
-rw-r--r--drivers/media/v4l2-core/v4l2-ctrls.c8
-rw-r--r--drivers/media/v4l2-core/v4l2-mem2mem.c16
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c19
-rw-r--r--drivers/media/v4l2-core/videobuf2-dma-sg.c149
-rw-r--r--drivers/misc/eeprom/at24.c2
-rw-r--r--drivers/mmc/card/block.c2
-rw-r--r--drivers/mmc/core/bus.c2
-rw-r--r--drivers/mmc/core/core.c154
-rw-r--r--drivers/mmc/core/core.h6
-rw-r--r--drivers/mmc/core/mmc.c127
-rw-r--r--drivers/mmc/core/mmc_ops.c96
-rw-r--r--drivers/mmc/core/sd.c118
-rw-r--r--drivers/mmc/core/sdio.c82
-rw-r--r--drivers/mmc/host/atmel-mci.c82
-rw-r--r--drivers/mmc/host/au1xmmc.c7
-rw-r--r--drivers/mmc/host/bfin_sdh.c15
-rw-r--r--drivers/mmc/host/cb710-mmc.c10
-rw-r--r--drivers/mmc/host/davinci_mmc.c26
-rw-r--r--drivers/mmc/host/dw_mmc-exynos.c291
-rw-r--r--drivers/mmc/host/dw_mmc-pltfm.c7
-rw-r--r--drivers/mmc/host/dw_mmc-socfpga.c34
-rw-r--r--drivers/mmc/host/dw_mmc.c604
-rw-r--r--drivers/mmc/host/dw_mmc.h55
-rw-r--r--drivers/mmc/host/jz4740_mmc.c4
-rw-r--r--drivers/mmc/host/mmci.c17
-rw-r--r--drivers/mmc/host/msm_sdcc.c27
-rw-r--r--drivers/mmc/host/mvsdio.c35
-rw-r--r--drivers/mmc/host/mxcmmc.c12
-rw-r--r--drivers/mmc/host/mxs-mmc.c12
-rw-r--r--drivers/mmc/host/omap.c53
-rw-r--r--drivers/mmc/host/omap_hsmmc.c112
-rw-r--r--drivers/mmc/host/pxamci.c32
-rw-r--r--drivers/mmc/host/rtsx_pci_sdmmc.c35
-rw-r--r--drivers/mmc/host/s3cmci.c29
-rw-r--r--drivers/mmc/host/sdhci-bcm-kona.c14
-rw-r--r--drivers/mmc/host/sdhci-bcm2835.c8
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c550
-rw-r--r--drivers/mmc/host/sdhci-esdhc.h37
-rw-r--r--drivers/mmc/host/sdhci-of-esdhc.c35
-rw-r--r--drivers/mmc/host/sdhci-pci.c76
-rw-r--r--drivers/mmc/host/sdhci.c44
-rw-r--r--drivers/mmc/host/sdhci.h3
-rw-r--r--drivers/mmc/host/sdricoh_cs.c3
-rw-r--r--drivers/mmc/host/sh_mmcif.c32
-rw-r--r--drivers/mmc/host/tifm_sd.c4
-rw-r--r--drivers/mmc/host/tmio_mmc_pio.c9
-rw-r--r--drivers/mmc/host/via-sdmmc.c7
-rw-r--r--drivers/mmc/host/vub300.c18
-rw-r--r--drivers/mmc/host/wbsd.c34
-rw-r--r--drivers/mmc/host/wmt-sdmmc.c57
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/cmd.c106
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/debugfs.c8
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/eq.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/main.c35
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/mr.c32
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c196
-rw-r--r--drivers/power/Kconfig6
-rw-r--r--drivers/power/Makefile1
-rw-r--r--drivers/power/ab8500_charger.c17
-rw-r--r--drivers/power/bq2415x_charger.c6
-rw-r--r--drivers/power/bq24735-charger.c419
-rw-r--r--drivers/power/charger-manager.c85
-rw-r--r--drivers/power/isp1704_charger.c91
-rw-r--r--drivers/power/max17042_battery.c373
-rw-r--r--drivers/power/pm2301_charger.c27
-rw-r--r--drivers/power/tps65090-charger.c30
-rw-r--r--drivers/power/twl4030_charger.c47
-rw-r--r--drivers/s390/block/scm_blk.c24
-rw-r--r--drivers/s390/block/scm_blk_cluster.c2
-rw-r--r--drivers/s390/char/Makefile3
-rw-r--r--drivers/s390/char/fs3270.c1
-rw-r--r--drivers/s390/char/sclp.h5
-rw-r--r--drivers/s390/char/sclp_cmd.c180
-rw-r--r--drivers/s390/char/sclp_early.c264
-rw-r--r--drivers/s390/char/sclp_sdias.c78
-rw-r--r--drivers/s390/char/sclp_sdias.h46
-rw-r--r--drivers/s390/char/zcore.c22
-rw-r--r--drivers/s390/cio/eadm_sch.c10
-rw-r--r--drivers/s390/cio/scm.c45
-rw-r--r--drivers/scsi/scsi_transport_srp.c540
-rw-r--r--drivers/staging/media/lirc/TODO5
-rw-r--r--drivers/staging/media/lirc/lirc_bt829.c33
-rw-r--r--drivers/staging/media/lirc/lirc_serial.c9
-rw-r--r--drivers/staging/media/lirc/lirc_zilog.c12
-rw-r--r--drivers/staging/media/msi3101/Kconfig3
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-disp.c25
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c170
-rw-r--r--drivers/staging/media/solo6x10/solo6x10.h1
-rw-r--r--drivers/watchdog/Kconfig27
-rw-r--r--drivers/watchdog/Makefile3
-rw-r--r--drivers/watchdog/acquirewdt.c4
-rw-r--r--drivers/watchdog/advantechwdt.c1
-rw-r--r--drivers/watchdog/alim1535_wdt.c1
-rw-r--r--drivers/watchdog/alim7101_wdt.c1
-rw-r--r--drivers/watchdog/ar7_wdt.c1
-rw-r--r--drivers/watchdog/at32ap700x_wdt.c1
-rw-r--r--drivers/watchdog/at91rm9200_wdt.c3
-rw-r--r--drivers/watchdog/ath79_wdt.c1
-rw-r--r--drivers/watchdog/bcm2835_wdt.c1
-rw-r--r--drivers/watchdog/bcm63xx_wdt.c1
-rw-r--r--drivers/watchdog/bfin_wdt.c1
-rw-r--r--drivers/watchdog/cpu5wdt.c1
-rw-r--r--drivers/watchdog/davinci_wdt.c1
-rw-r--r--drivers/watchdog/dw_wdt.c36
-rw-r--r--drivers/watchdog/ep93xx_wdt.c1
-rw-r--r--drivers/watchdog/eurotechwdt.c1
-rw-r--r--drivers/watchdog/gef_wdt.c1
-rw-r--r--drivers/watchdog/geodewdt.c1
-rw-r--r--drivers/watchdog/hpwdt.c1
-rw-r--r--drivers/watchdog/i6300esb.c1
-rw-r--r--drivers/watchdog/iTCO_wdt.c5
-rw-r--r--drivers/watchdog/ib700wdt.c1
-rw-r--r--drivers/watchdog/ibmasr.c1
-rw-r--r--drivers/watchdog/ie6xx_wdt.c1
-rw-r--r--drivers/watchdog/imx2_wdt.c2
-rw-r--r--drivers/watchdog/indydog.c1
-rw-r--r--drivers/watchdog/intel_scu_watchdog.c1
-rw-r--r--drivers/watchdog/iop_wdt.c1
-rw-r--r--drivers/watchdog/it8712f_wdt.c1
-rw-r--r--drivers/watchdog/it87_wdt.c1
-rw-r--r--drivers/watchdog/ixp4xx_wdt.c2
-rw-r--r--drivers/watchdog/jz4740_wdt.c1
-rw-r--r--drivers/watchdog/kempld_wdt.c5
-rw-r--r--drivers/watchdog/ks8695_wdt.c1
-rw-r--r--drivers/watchdog/lantiq_wdt.c1
-rw-r--r--drivers/watchdog/m54xx_wdt.c1
-rw-r--r--drivers/watchdog/machzwd.c1
-rw-r--r--drivers/watchdog/max63xx_wdt.c1
-rw-r--r--drivers/watchdog/mixcomwd.c1
-rw-r--r--drivers/watchdog/moxart_wdt.c165
-rw-r--r--drivers/watchdog/mpc8xxx_wdt.c1
-rw-r--r--drivers/watchdog/mtx-1_wdt.c1
-rw-r--r--drivers/watchdog/mv64x60_wdt.c3
-rw-r--r--drivers/watchdog/nuc900_wdt.c1
-rw-r--r--drivers/watchdog/nv_tco.c1
-rw-r--r--drivers/watchdog/of_xilinx_wdt.c1
-rw-r--r--drivers/watchdog/omap_wdt.c38
-rw-r--r--drivers/watchdog/orion_wdt.c3
-rw-r--r--drivers/watchdog/pc87413_wdt.c2
-rw-r--r--drivers/watchdog/pcwd.c4
-rw-r--r--drivers/watchdog/pcwd_pci.c4
-rw-r--r--drivers/watchdog/pcwd_usb.c16
-rw-r--r--drivers/watchdog/pika_wdt.c2
-rw-r--r--drivers/watchdog/pnx4008_wdt.c1
-rw-r--r--drivers/watchdog/pnx833x_wdt.c1
-rw-r--r--drivers/watchdog/rc32434_wdt.c4
-rw-r--r--drivers/watchdog/rdc321x_wdt.c3
-rw-r--r--drivers/watchdog/rt2880_wdt.c207
-rw-r--r--drivers/watchdog/s3c2410_wdt.c2
-rw-r--r--drivers/watchdog/sa1100_wdt.c1
-rw-r--r--drivers/watchdog/sb_wdog.c1
-rw-r--r--drivers/watchdog/sbc60xxwdt.c1
-rw-r--r--drivers/watchdog/sbc7240_wdt.c2
-rw-r--r--drivers/watchdog/sbc8360.c1
-rw-r--r--drivers/watchdog/sbc_epx_c3.c1
-rw-r--r--drivers/watchdog/sbc_fitpc2_wdt.c2
-rw-r--r--drivers/watchdog/sc1200wdt.c1
-rw-r--r--drivers/watchdog/sc520_wdt.c1
-rw-r--r--drivers/watchdog/sch311x_wdt.c5
-rw-r--r--drivers/watchdog/scx200_wdt.c1
-rw-r--r--drivers/watchdog/shwdt.c1
-rw-r--r--drivers/watchdog/sirfsoc_wdt.c226
-rw-r--r--drivers/watchdog/smsc37b787_wdt.c2
-rw-r--r--drivers/watchdog/softdog.c1
-rw-r--r--drivers/watchdog/sp5100_tco.c1
-rw-r--r--drivers/watchdog/sp805_wdt.c1
-rw-r--r--drivers/watchdog/stmp3xxx_rtc_wdt.c5
-rw-r--r--drivers/watchdog/sunxi_wdt.c2
-rw-r--r--drivers/watchdog/ts72xx_wdt.c38
-rw-r--r--drivers/watchdog/txx9wdt.c1
-rw-r--r--drivers/watchdog/ux500_wdt.c3
-rw-r--r--drivers/watchdog/w83627hf_wdt.c341
-rw-r--r--drivers/watchdog/w83697hf_wdt.c1
-rw-r--r--drivers/watchdog/w83697ug_wdt.c1
-rw-r--r--drivers/watchdog/w83877f_wdt.c1
-rw-r--r--drivers/watchdog/w83977f_wdt.c1
-rw-r--r--drivers/watchdog/wafer5823wdt.c1
-rw-r--r--drivers/watchdog/watchdog_core.c2
-rw-r--r--drivers/watchdog/wdrtas.c2
-rw-r--r--drivers/watchdog/wdt.c2
-rw-r--r--drivers/watchdog/wdt285.c1
-rw-r--r--drivers/watchdog/wdt977.c1
-rw-r--r--drivers/watchdog/wdt_pci.c2
-rw-r--r--drivers/watchdog/wm831x_wdt.c8
-rw-r--r--drivers/watchdog/xen_wdt.c1
-rw-r--r--fs/seq_file.c3
-rw-r--r--include/linux/i2c.h2
-rw-r--r--include/linux/irq.h7
-rw-r--r--include/linux/mlx5/device.h13
-rw-r--r--include/linux/mlx5/driver.h18
-rw-r--r--include/linux/mmc/card.h7
-rw-r--r--include/linux/mmc/core.h4
-rw-r--r--include/linux/mmc/dw_mmc.h4
-rw-r--r--include/linux/mmc/host.h5
-rw-r--r--include/linux/platform_data/at24.h (renamed from include/linux/i2c/at24.h)2
-rw-r--r--include/linux/platform_data/mmc-esdhc-imx.h5
-rw-r--r--include/linux/power/bq24735-charger.h39
-rw-r--r--include/linux/preempt_mask.h41
-rw-r--r--include/linux/sched.h2
-rw-r--r--include/media/lm3560.h97
-rw-r--r--include/media/soc_camera.h27
-rw-r--r--include/media/v4l2-clk.h17
-rw-r--r--include/media/v4l2-common.h4
-rw-r--r--include/media/v4l2-ctrls.h2
-rw-r--r--include/media/v4l2-fh.h2
-rw-r--r--include/media/v4l2-subdev.h19
-rw-r--r--include/media/videobuf2-core.h4
-rw-r--r--include/media/videobuf2-dma-sg.h10
-rw-r--r--include/rdma/ib_verbs.h20
-rw-r--r--include/scsi/scsi_transport_srp.h83
-rw-r--r--include/uapi/linux/v4l2-controls.h4
-rw-r--r--include/uapi/rdma/ib_user_verbs.h95
-rw-r--r--kernel/bounds.c2
-rw-r--r--kernel/irq/settings.h7
-rw-r--r--kernel/irq/spurious.c12
-rw-r--r--sound/ppc/keywest.c4
-rw-r--r--sound/soc/fsl/imx-wm8962.c2
633 files changed, 20493 insertions, 6144 deletions
diff --git a/Documentation/ABI/stable/sysfs-driver-ib_srp b/Documentation/ABI/stable/sysfs-driver-ib_srp
index 5c53d28f775c..b9688de8455b 100644
--- a/Documentation/ABI/stable/sysfs-driver-ib_srp
+++ b/Documentation/ABI/stable/sysfs-driver-ib_srp
@@ -61,6 +61,12 @@ Description: Interface for making ib_srp connect to a new target.
61 interrupt is handled by a different CPU then the comp_vector 61 interrupt is handled by a different CPU then the comp_vector
62 parameter can be used to spread the SRP completion workload 62 parameter can be used to spread the SRP completion workload
63 over multiple CPU's. 63 over multiple CPU's.
64 * tl_retry_count, a number in the range 2..7 specifying the
65 IB RC retry count.
66 * queue_size, the maximum number of commands that the
67 initiator is allowed to queue per SCSI host. The default
68 value for this parameter is 62. The lowest supported value
69 is 2.
64 70
65What: /sys/class/infiniband_srp/srp-<hca>-<port_number>/ibdev 71What: /sys/class/infiniband_srp/srp-<hca>-<port_number>/ibdev
66Date: January 2, 2006 72Date: January 2, 2006
@@ -153,6 +159,13 @@ Contact: linux-rdma@vger.kernel.org
153Description: InfiniBand service ID used for establishing communication with 159Description: InfiniBand service ID used for establishing communication with
154 the SRP target. 160 the SRP target.
155 161
162What: /sys/class/scsi_host/host<n>/sgid
163Date: February 1, 2014
164KernelVersion: 3.13
165Contact: linux-rdma@vger.kernel.org
166Description: InfiniBand GID of the source port used for communication with
167 the SRP target.
168
156What: /sys/class/scsi_host/host<n>/zero_req_lim 169What: /sys/class/scsi_host/host<n>/zero_req_lim
157Date: September 20, 2006 170Date: September 20, 2006
158KernelVersion: 2.6.18 171KernelVersion: 2.6.18
diff --git a/Documentation/ABI/stable/sysfs-transport-srp b/Documentation/ABI/stable/sysfs-transport-srp
index b36fb0dc13c8..ec7af69fea0a 100644
--- a/Documentation/ABI/stable/sysfs-transport-srp
+++ b/Documentation/ABI/stable/sysfs-transport-srp
@@ -5,6 +5,24 @@ Contact: linux-scsi@vger.kernel.org, linux-rdma@vger.kernel.org
5Description: Instructs an SRP initiator to disconnect from a target and to 5Description: Instructs an SRP initiator to disconnect from a target and to
6 remove all LUNs imported from that target. 6 remove all LUNs imported from that target.
7 7
8What: /sys/class/srp_remote_ports/port-<h>:<n>/dev_loss_tmo
9Date: February 1, 2014
10KernelVersion: 3.13
11Contact: linux-scsi@vger.kernel.org, linux-rdma@vger.kernel.org
12Description: Number of seconds the SCSI layer will wait after a transport
13 layer error has been observed before removing a target port.
14 Zero means immediate removal. Setting this attribute to "off"
15 will disable the dev_loss timer.
16
17What: /sys/class/srp_remote_ports/port-<h>:<n>/fast_io_fail_tmo
18Date: February 1, 2014
19KernelVersion: 3.13
20Contact: linux-scsi@vger.kernel.org, linux-rdma@vger.kernel.org
21Description: Number of seconds the SCSI layer will wait after a transport
22 layer error has been observed before failing I/O. Zero means
23 failing I/O immediately. Setting this attribute to "off" will
24 disable the fast_io_fail timer.
25
8What: /sys/class/srp_remote_ports/port-<h>:<n>/port_id 26What: /sys/class/srp_remote_ports/port-<h>:<n>/port_id
9Date: June 27, 2007 27Date: June 27, 2007
10KernelVersion: 2.6.24 28KernelVersion: 2.6.24
@@ -12,8 +30,29 @@ Contact: linux-scsi@vger.kernel.org
12Description: 16-byte local SRP port identifier in hexadecimal format. An 30Description: 16-byte local SRP port identifier in hexadecimal format. An
13 example: 4c:49:4e:55:58:20:56:49:4f:00:00:00:00:00:00:00. 31 example: 4c:49:4e:55:58:20:56:49:4f:00:00:00:00:00:00:00.
14 32
33What: /sys/class/srp_remote_ports/port-<h>:<n>/reconnect_delay
34Date: February 1, 2014
35KernelVersion: 3.13
36Contact: linux-scsi@vger.kernel.org, linux-rdma@vger.kernel.org
37Description: Number of seconds the SCSI layer will wait after a reconnect
38 attempt failed before retrying. Setting this attribute to
39 "off" will disable time-based reconnecting.
40
15What: /sys/class/srp_remote_ports/port-<h>:<n>/roles 41What: /sys/class/srp_remote_ports/port-<h>:<n>/roles
16Date: June 27, 2007 42Date: June 27, 2007
17KernelVersion: 2.6.24 43KernelVersion: 2.6.24
18Contact: linux-scsi@vger.kernel.org 44Contact: linux-scsi@vger.kernel.org
19Description: Role of the remote port. Either "SRP Initiator" or "SRP Target". 45Description: Role of the remote port. Either "SRP Initiator" or "SRP Target".
46
47What: /sys/class/srp_remote_ports/port-<h>:<n>/state
48Date: February 1, 2014
49KernelVersion: 3.13
50Contact: linux-scsi@vger.kernel.org, linux-rdma@vger.kernel.org
51Description: State of the transport layer used for communication with the
52 remote port. "running" if the transport layer is operational;
53 "blocked" if a transport layer error has been encountered but
54 the fast_io_fail_tmo timer has not yet fired; "fail-fast"
55 after the fast_io_fail_tmo timer has fired and before the
56 "dev_loss_tmo" timer has fired; "lost" after the
57 "dev_loss_tmo" timer has fired and before the port is finally
58 removed.
diff --git a/Documentation/devicetree/bindings/arc/pmu.txt b/Documentation/devicetree/bindings/arc/pmu.txt
new file mode 100644
index 000000000000..49d517340de3
--- /dev/null
+++ b/Documentation/devicetree/bindings/arc/pmu.txt
@@ -0,0 +1,24 @@
1* ARC Performance Monitor Unit
2
3The ARC 700 can be configured with a pipeline performance monitor for counting
4CPU and cache events like cache misses and hits.
5
6Note that:
7 * ARC 700 refers to a family of ARC processor cores;
8 - There is only one type of PMU available for the whole family;
9 - The PMU may support different sets of events; supported events are probed
10 at boot time, as required by the reference manual.
11
12 * The ARC 700 PMU does not support interrupts; although HW events may be
13 counted, the HW events themselves cannot serve as a trigger for a sample.
14
15Required properties:
16
17- compatible : should contain
18 "snps,arc700-pmu"
19
20Example:
21
22pmu {
23 compatible = "snps,arc700-pmu";
24};
diff --git a/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt b/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
index f770ac0893d4..049675944b78 100644
--- a/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
+++ b/Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
@@ -1,7 +1,9 @@
1Calxeda DDR memory controller 1Calxeda DDR memory controller
2 2
3Properties: 3Properties:
4- compatible : Should be "calxeda,hb-ddr-ctrl" 4- compatible : Should be:
5 - "calxeda,hb-ddr-ctrl" for ECX-1000
6 - "calxeda,ecx-2000-ddr-ctrl" for ECX-2000
5- reg : Address and size for DDR controller registers. 7- reg : Address and size for DDR controller registers.
6- interrupts : Interrupt for DDR controller. 8- interrupts : Interrupt for DDR controller.
7 9
diff --git a/Documentation/devicetree/bindings/i2c/i2c-bcm-kona.txt b/Documentation/devicetree/bindings/i2c/i2c-bcm-kona.txt
new file mode 100644
index 000000000000..1b87b741fa8e
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-bcm-kona.txt
@@ -0,0 +1,35 @@
1Broadcom Kona Family I2C
2=========================
3
4This I2C controller is used in the following Broadcom SoCs:
5
6 BCM11130
7 BCM11140
8 BCM11351
9 BCM28145
10 BCM28155
11
12Required Properties
13-------------------
14- compatible: "brcm,bcm11351-i2c", "brcm,kona-i2c"
15- reg: Physical base address and length of controller registers
16- interrupts: The interrupt number used by the controller
17- clocks: clock specifier for the kona i2c external clock
18- clock-frequency: The I2C bus frequency in Hz
19- #address-cells: Should be <1>
20- #size-cells: Should be <0>
21
22Refer to clocks/clock-bindings.txt for generic clock consumer
23properties.
24
25Example:
26
27i2c@3e016000 {
28 compatible = "brcm,bcm11351-i2c","brcm,kona-i2c";
29 reg = <0x3e016000 0x80>;
30 interrupts = <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>;
31 clocks = <&bsc1_clk>;
32 clock-frequency = <400000>;
33 #address-cells = <1>;
34 #size-cells = <0>;
35};
diff --git a/Documentation/devicetree/bindings/i2c/i2c-exynos5.txt b/Documentation/devicetree/bindings/i2c/i2c-exynos5.txt
new file mode 100644
index 000000000000..056732cfdcee
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-exynos5.txt
@@ -0,0 +1,44 @@
1* Samsung's High Speed I2C controller
2
3The Samsung's High Speed I2C controller is used to interface with I2C devices
4at various speeds ranging from 100khz to 3.4Mhz.
5
6Required properties:
7 - compatible: value should be.
8 -> "samsung,exynos5-hsi2c", for i2c compatible with exynos5 hsi2c.
9 - reg: physical base address of the controller and length of memory mapped
10 region.
11 - interrupts: interrupt number to the cpu.
12 - #address-cells: always 1 (for i2c addresses)
13 - #size-cells: always 0
14
15 - Pinctrl:
16 - pinctrl-0: Pin control group to be used for this controller.
17 - pinctrl-names: Should contain only one value - "default".
18
19Optional properties:
20 - clock-frequency: Desired operating frequency in Hz of the bus.
21 -> If not specified, the bus operates in fast-speed mode at
22 at 100khz.
23 -> If specified, the bus operates in high-speed mode only if the
24 clock-frequency is >= 1Mhz.
25
26Example:
27
28hsi2c@12ca0000 {
29 compatible = "samsung,exynos5-hsi2c";
30 reg = <0x12ca0000 0x100>;
31 interrupts = <56>;
32 clock-frequency = <100000>;
33
34 pinctrl-0 = <&i2c4_bus>;
35 pinctrl-names = "default";
36
37 #address-cells = <1>;
38 #size-cells = <0>;
39
40 s2mps11_pmic@66 {
41 compatible = "samsung,s2mps11-pmic";
42 reg = <0x66>;
43 };
44};
diff --git a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
new file mode 100644
index 000000000000..897cfcd5ce92
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
@@ -0,0 +1,23 @@
1I2C for R-Car platforms
2
3Required properties:
4- compatible: Must be one of
5 "renesas,i2c-rcar"
6 "renesas,i2c-r8a7778"
7 "renesas,i2c-r8a7779"
8 "renesas,i2c-r8a7790"
9- reg: physical base address of the controller and length of memory mapped
10 region.
11- interrupts: interrupt specifier.
12
13Optional properties:
14- clock-frequency: desired I2C bus clock frequency in Hz. The absence of this
15 propoerty indicates the default frequency 100 kHz.
16
17Examples :
18
19i2c0: i2c@e6500000 {
20 compatible = "renesas,i2c-rcar-h2";
21 reg = <0 0xe6500000 0 0x428>;
22 interrupts = <0 174 0x4>;
23};
diff --git a/Documentation/devicetree/bindings/i2c/i2c-st.txt b/Documentation/devicetree/bindings/i2c/i2c-st.txt
new file mode 100644
index 000000000000..437e0db3823c
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-st.txt
@@ -0,0 +1,41 @@
1ST SSC binding, for I2C mode operation
2
3Required properties :
4- compatible : Must be "st,comms-ssc-i2c" or "st,comms-ssc4-i2c"
5- reg : Offset and length of the register set for the device
6- interrupts : the interrupt specifier
7- clock-names: Must contain "ssc".
8- clocks: Must contain an entry for each name in clock-names. See the common
9 clock bindings.
10- A pinctrl state named "default" must be defined to set pins in mode of
11 operation for I2C transfer.
12
13Optional properties :
14- clock-frequency : Desired I2C bus clock frequency in Hz. If not specified,
15 the default 100 kHz frequency will be used. As only Normal and Fast modes
16 are supported, possible values are 100000 and 400000.
17- st,i2c-min-scl-pulse-width-us : The minimum valid SCL pulse width that is
18 allowed through the deglitch circuit. In units of us.
19- st,i2c-min-sda-pulse-width-us : The minimum valid SDA pulse width that is
20 allowed through the deglitch circuit. In units of us.
21- A pinctrl state named "idle" could be defined to set pins in idle state
22 when I2C instance is not performing a transfer.
23- A pinctrl state named "sleep" could be defined to set pins in sleep state
24 when driver enters in suspend.
25
26
27
28Example :
29
30i2c0: i2c@fed40000 {
31 compatible = "st,comms-ssc4-i2c";
32 reg = <0xfed40000 0x110>;
33 interrupts = <GIC_SPI 187 IRQ_TYPE_LEVEL_HIGH>;
34 clocks = <&CLK_S_ICN_REG_0>;
35 clock-names = "ssc";
36 clock-frequency = <400000>;
37 pinctrl-names = "default";
38 pinctrl-0 = <&pinctrl_i2c0_default>;
39 st,i2c-min-scl-pulse-width-us = <0>;
40 st,i2c-min-sda-pulse-width-us = <5>;
41};
diff --git a/Documentation/devicetree/bindings/media/st-rc.txt b/Documentation/devicetree/bindings/media/st-rc.txt
new file mode 100644
index 000000000000..05c432d08bca
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/st-rc.txt
@@ -0,0 +1,29 @@
1Device-Tree bindings for ST IRB IP
2
3Required properties:
4 - compatible: Should contain "st,comms-irb".
5 - reg: Base physical address of the controller and length of memory
6 mapped region.
7 - interrupts: interrupt-specifier for the sole interrupt generated by
8 the device. The interrupt specifier format depends on the interrupt
9 controller parent.
10 - rx-mode: can be "infrared" or "uhf". This property specifies the L1
11 protocol used for receiving remote control signals. rx-mode should
12 be present iff the rx pins are wired up.
13 - tx-mode: should be "infrared". This property specifies the L1
14 protocol used for transmitting remote control signals. tx-mode should
15 be present iff the tx pins are wired up.
16
17Optional properties:
18 - pinctrl-names, pinctrl-0: the pincontrol settings to configure muxing
19 properly for IRB pins.
20 - clocks : phandle with clock-specifier pair for IRB.
21
22Example node:
23
24 rc: rc@fe518000 {
25 compatible = "st,comms-irb";
26 reg = <0xfe518000 0x234>;
27 interrupts = <0 203 0>;
28 rx-mode = "infrared";
29 };
diff --git a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
index 1dd622546d06..9046ba06c47a 100644
--- a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
+++ b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
@@ -12,6 +12,11 @@ Required properties:
12Optional properties: 12Optional properties:
13- fsl,cd-controller : Indicate to use controller internal card detection 13- fsl,cd-controller : Indicate to use controller internal card detection
14- fsl,wp-controller : Indicate to use controller internal write protection 14- fsl,wp-controller : Indicate to use controller internal write protection
15- fsl,delay-line : Specify the number of delay cells for override mode.
16 This is used to set the clock delay for DLL(Delay Line) on override mode
17 to select a proper data sampling window in case the clock quality is not good
18 due to signal path is too long on the board. Please refer to eSDHC/uSDHC
19 chapter, DLL (Delay Line) section in RM for details.
15 20
16Examples: 21Examples:
17 22
diff --git a/Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt b/Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt
index 066a78b034ca..8f3f13315358 100644
--- a/Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt
+++ b/Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt
@@ -52,6 +52,9 @@ Optional properties:
52 is specified and the ciu clock is specified then we'll try to set the ciu 52 is specified and the ciu clock is specified then we'll try to set the ciu
53 clock to this at probe time. 53 clock to this at probe time.
54 54
55* clock-freq-min-max: Minimum and Maximum clock frequency for card output
56 clock(cclk_out). If it's not specified, max is 200MHZ and min is 400KHz by default.
57
55* num-slots: specifies the number of slots supported by the controller. 58* num-slots: specifies the number of slots supported by the controller.
56 The number of physical slots actually used could be equal or less than the 59 The number of physical slots actually used could be equal or less than the
57 value specified by num-slots. If this property is not specified, the value 60 value specified by num-slots. If this property is not specified, the value
@@ -66,6 +69,10 @@ Optional properties:
66 69
67* supports-highspeed: Enables support for high speed cards (up to 50MHz) 70* supports-highspeed: Enables support for high speed cards (up to 50MHz)
68 71
72* caps2-mmc-hs200-1_8v: Supports mmc HS200 SDR 1.8V mode
73
74* caps2-mmc-hs200-1_2v: Supports mmc HS200 SDR 1.2V mode
75
69* broken-cd: as documented in mmc core bindings. 76* broken-cd: as documented in mmc core bindings.
70 77
71* vmmc-supply: The phandle to the regulator to use for vmmc. If this is 78* vmmc-supply: The phandle to the regulator to use for vmmc. If this is
@@ -93,8 +100,10 @@ board specific portions as listed below.
93 100
94 dwmmc0@12200000 { 101 dwmmc0@12200000 {
95 clock-frequency = <400000000>; 102 clock-frequency = <400000000>;
103 clock-freq-min-max = <400000 200000000>;
96 num-slots = <1>; 104 num-slots = <1>;
97 supports-highspeed; 105 supports-highspeed;
106 caps2-mmc-hs200-1_8v;
98 broken-cd; 107 broken-cd;
99 fifo-depth = <0x80>; 108 fifo-depth = <0x80>;
100 card-detect-delay = <200>; 109 card-detect-delay = <200>;
diff --git a/Documentation/devicetree/bindings/power/twl-charger.txt b/Documentation/devicetree/bindings/power/twl-charger.txt
new file mode 100644
index 000000000000..d5c706216df5
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/twl-charger.txt
@@ -0,0 +1,20 @@
1TWL BCI (Battery Charger Interface)
2
3Required properties:
4- compatible:
5 - "ti,twl4030-bci"
6- interrupts: two interrupt lines from the TWL SIH (secondary
7 interrupt handler) - interrupts 9 and 2.
8
9Optional properties:
10- ti,bb-uvolt: microvolts for charging the backup battery.
11- ti,bb-uamp: microamps for charging the backup battery.
12
13Examples:
14
15bci {
16 compatible = "ti,twl4030-bci";
17 interrupts = <9>, <2>;
18 ti,bb-uvolt = <3200000>;
19 ti,bb-uamp = <150>;
20};
diff --git a/Documentation/devicetree/bindings/power_supply/ti,bq24735.txt b/Documentation/devicetree/bindings/power_supply/ti,bq24735.txt
new file mode 100644
index 000000000000..4f6a550184d0
--- /dev/null
+++ b/Documentation/devicetree/bindings/power_supply/ti,bq24735.txt
@@ -0,0 +1,32 @@
1TI BQ24735 Charge Controller
2~~~~~~~~~~
3
4Required properties :
5 - compatible : "ti,bq24735"
6
7Optional properties :
8 - interrupts : Specify the interrupt to be used to trigger when the AC
9 adapter is either plugged in or removed.
10 - ti,ac-detect-gpios : This GPIO is optionally used to read the AC adapter
11 presence. This is a Host GPIO that is configured as an input and
12 connected to the bq24735.
13 - ti,charge-current : Used to control and set the charging current. This value
14 must be between 128mA and 8.128A with a 64mA step resolution. The POR value
15 is 0x0000h. This number is in mA (e.g. 8192), see spec for more information
16 about the ChargeCurrent (0x14h) register.
17 - ti,charge-voltage : Used to control and set the charging voltage. This value
18 must be between 1.024V and 19.2V with a 16mV step resolution. The POR value
19 is 0x0000h. This number is in mV (e.g. 19200), see spec for more information
20 about the ChargeVoltage (0x15h) register.
21 - ti,input-current : Used to control and set the charger input current. This
22 value must be between 128mA and 8.064A with a 128mA step resolution. The
23 POR value is 0x1000h. This number is in mA (e.g. 8064), see the spec for
24 more information about the InputCurrent (0x3fh) register.
25
26Example:
27
28 bq24735@9 {
29 compatible = "ti,bq24735";
30 reg = <0x9>;
31 ti,ac-detect-gpios = <&gpio 72 0x1>;
32 }
diff --git a/Documentation/devicetree/bindings/watchdog/dw_wdt.txt b/Documentation/devicetree/bindings/watchdog/dw_wdt.txt
new file mode 100644
index 000000000000..08e16f684f2d
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/dw_wdt.txt
@@ -0,0 +1,21 @@
1Synopsys Designware Watchdog Timer
2
3Required Properties:
4
5- compatible : Should contain "snps,dw-wdt"
6- reg : Base address and size of the watchdog timer registers.
7- clocks : phandle + clock-specifier for the clock that drives the
8 watchdog timer.
9
10Optional Properties:
11
12- interrupts : The interrupt used for the watchdog timeout warning.
13
14Example:
15
16 watchdog0: wd@ffd02000 {
17 compatible = "snps,dw-wdt";
18 reg = <0xffd02000 0x1000>;
19 interrupts = <0 171 4>;
20 clocks = <&per_base_clk>;
21 };
diff --git a/Documentation/devicetree/bindings/gpio/men-a021-wdt.txt b/Documentation/devicetree/bindings/watchdog/men-a021-wdt.txt
index 370dee3226d9..370dee3226d9 100644
--- a/Documentation/devicetree/bindings/gpio/men-a021-wdt.txt
+++ b/Documentation/devicetree/bindings/watchdog/men-a021-wdt.txt
diff --git a/Documentation/devicetree/bindings/watchdog/moxa,moxart-watchdog.txt b/Documentation/devicetree/bindings/watchdog/moxa,moxart-watchdog.txt
new file mode 100644
index 000000000000..1169857d1d12
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/moxa,moxart-watchdog.txt
@@ -0,0 +1,15 @@
1MOXA ART Watchdog timer
2
3Required properties:
4
5- compatible : Must be "moxa,moxart-watchdog"
6- reg : Should contain registers location and length
7- clocks : Should contain phandle for the clock that drives the counter
8
9Example:
10
11 watchdog: watchdog@98500000 {
12 compatible = "moxa,moxart-watchdog";
13 reg = <0x98500000 0x10>;
14 clocks = <&coreclk>;
15 };
diff --git a/Documentation/devicetree/bindings/watchdog/rt2880-wdt.txt b/Documentation/devicetree/bindings/watchdog/rt2880-wdt.txt
new file mode 100644
index 000000000000..d7bab3db9d1f
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/rt2880-wdt.txt
@@ -0,0 +1,19 @@
1Ralink Watchdog Timers
2
3Required properties:
4- compatible: must be "ralink,rt2880-wdt"
5- reg: physical base address of the controller and length of the register range
6
7Optional properties:
8- interrupt-parent: phandle to the INTC device node
9- interrupts: Specify the INTC interrupt number
10
11Example:
12
13 watchdog@120 {
14 compatible = "ralink,rt2880-wdt";
15 reg = <0x120 0x10>;
16
17 interrupt-parent = <&intc>;
18 interrupts = <1>;
19 };
diff --git a/Documentation/devicetree/bindings/watchdog/sirfsoc_wdt.txt b/Documentation/devicetree/bindings/watchdog/sirfsoc_wdt.txt
new file mode 100644
index 000000000000..9cbc76c89b2b
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/sirfsoc_wdt.txt
@@ -0,0 +1,14 @@
1SiRFSoC Timer and Watchdog Timer(WDT) Controller
2
3Required properties:
4- compatible: "sirf,prima2-tick"
5- reg: Address range of tick timer/WDT register set
6- interrupts: interrupt number to the cpu
7
8Example:
9
10timer@b0020000 {
11 compatible = "sirf,prima2-tick";
12 reg = <0xb0020000 0x1000>;
13 interrupts = <0>;
14};
diff --git a/Documentation/i2c/busses/i2c-i801 b/Documentation/i2c/busses/i2c-i801
index d29dea0f3232..7b0dcdb57173 100644
--- a/Documentation/i2c/busses/i2c-i801
+++ b/Documentation/i2c/busses/i2c-i801
@@ -25,6 +25,7 @@ Supported adapters:
25 * Intel Avoton (SOC) 25 * Intel Avoton (SOC)
26 * Intel Wellsburg (PCH) 26 * Intel Wellsburg (PCH)
27 * Intel Coleto Creek (PCH) 27 * Intel Coleto Creek (PCH)
28 * Intel Wildcat Point-LP (PCH)
28 Datasheets: Publicly available at the Intel website 29 Datasheets: Publicly available at the Intel website
29 30
30On Intel Patsburg and later chipsets, both the normal host SMBus controller 31On Intel Patsburg and later chipsets, both the normal host SMBus controller
diff --git a/Documentation/power/power_supply_class.txt b/Documentation/power/power_supply_class.txt
index 3f10b39b0346..89a8816990ff 100644
--- a/Documentation/power/power_supply_class.txt
+++ b/Documentation/power/power_supply_class.txt
@@ -135,11 +135,11 @@ CAPACITY_LEVEL - capacity level. This corresponds to
135POWER_SUPPLY_CAPACITY_LEVEL_*. 135POWER_SUPPLY_CAPACITY_LEVEL_*.
136 136
137TEMP - temperature of the power supply. 137TEMP - temperature of the power supply.
138TEMP_ALERT_MIN - minimum battery temperature alert value in milli centigrade. 138TEMP_ALERT_MIN - minimum battery temperature alert.
139TEMP_ALERT_MAX - maximum battery temperature alert value in milli centigrade. 139TEMP_ALERT_MAX - maximum battery temperature alert.
140TEMP_AMBIENT - ambient temperature. 140TEMP_AMBIENT - ambient temperature.
141TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert value in milli centigrade. 141TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
142TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert value in milli centigrade. 142TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
143 143
144TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e. 144TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
145while battery powers a load) 145while battery powers a load)
diff --git a/MAINTAINERS b/MAINTAINERS
index 678f07430393..0e598aeed539 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1425,7 +1425,7 @@ M: Wolfram Sang <wsa@the-dreams.de>
1425L: linux-i2c@vger.kernel.org 1425L: linux-i2c@vger.kernel.org
1426S: Maintained 1426S: Maintained
1427F: drivers/misc/eeprom/at24.c 1427F: drivers/misc/eeprom/at24.c
1428F: include/linux/i2c/at24.h 1428F: include/linux/platform_data/at24.h
1429 1429
1430ATA OVER ETHERNET (AOE) DRIVER 1430ATA OVER ETHERNET (AOE) DRIVER
1431M: "Ed L. Cashin" <ecashin@coraid.com> 1431M: "Ed L. Cashin" <ecashin@coraid.com>
@@ -3063,6 +3063,14 @@ W: bluesmoke.sourceforge.net
3063S: Maintained 3063S: Maintained
3064F: drivers/edac/amd64_edac* 3064F: drivers/edac/amd64_edac*
3065 3065
3066EDAC-CALXEDA
3067M: Doug Thompson <dougthompson@xmission.com>
3068M: Robert Richter <rric@kernel.org>
3069L: linux-edac@vger.kernel.org
3070W: bluesmoke.sourceforge.net
3071S: Maintained
3072F: drivers/edac/highbank*
3073
3066EDAC-CAVIUM 3074EDAC-CAVIUM
3067M: Ralf Baechle <ralf@linux-mips.org> 3075M: Ralf Baechle <ralf@linux-mips.org>
3068M: David Daney <david.daney@cavium.com> 3076M: David Daney <david.daney@cavium.com>
@@ -3144,6 +3152,13 @@ W: bluesmoke.sourceforge.net
3144S: Maintained 3152S: Maintained
3145F: drivers/edac/i82975x_edac.c 3153F: drivers/edac/i82975x_edac.c
3146 3154
3155EDAC-MPC85XX
3156M: Johannes Thumshirn <johannes.thumshirn@men.de>
3157L: linux-edac@vger.kernel.org
3158W: bluesmoke.sourceforge.net
3159S: Maintained
3160F: drivers/edac/mpc85xx_edac.[ch]
3161
3147EDAC-PASEMI 3162EDAC-PASEMI
3148M: Egor Martovetsky <egor@pasemi.com> 3163M: Egor Martovetsky <egor@pasemi.com>
3149L: linux-edac@vger.kernel.org 3164L: linux-edac@vger.kernel.org
diff --git a/arch/alpha/include/asm/thread_info.h b/arch/alpha/include/asm/thread_info.h
index 52cd2a4a3ff4..453597b91f3a 100644
--- a/arch/alpha/include/asm/thread_info.h
+++ b/arch/alpha/include/asm/thread_info.h
@@ -58,8 +58,6 @@ register struct thread_info *__current_thread_info __asm__("$8");
58#define THREAD_SIZE_ORDER 1 58#define THREAD_SIZE_ORDER 1
59#define THREAD_SIZE (2*PAGE_SIZE) 59#define THREAD_SIZE (2*PAGE_SIZE)
60 60
61#define PREEMPT_ACTIVE 0x40000000
62
63/* 61/*
64 * Thread information flags: 62 * Thread information flags:
65 * - these are process state flags and used from assembly 63 * - these are process state flags and used from assembly
diff --git a/arch/arc/boot/dts/abilis_tb100.dtsi b/arch/arc/boot/dts/abilis_tb100.dtsi
index d9f8249aa66e..3942634f805a 100644
--- a/arch/arc/boot/dts/abilis_tb100.dtsi
+++ b/arch/arc/boot/dts/abilis_tb100.dtsi
@@ -43,124 +43,124 @@
43 iomux: iomux@FF10601c { 43 iomux: iomux@FF10601c {
44 /* Port 1 */ 44 /* Port 1 */
45 pctl_tsin_s0: pctl-tsin-s0 { /* Serial TS-in 0 */ 45 pctl_tsin_s0: pctl-tsin-s0 { /* Serial TS-in 0 */
46 pingrp = "mis0_pins"; 46 abilis,function = "mis0";
47 }; 47 };
48 pctl_tsin_s1: pctl-tsin-s1 { /* Serial TS-in 1 */ 48 pctl_tsin_s1: pctl-tsin-s1 { /* Serial TS-in 1 */
49 pingrp = "mis1_pins"; 49 abilis,function = "mis1";
50 }; 50 };
51 pctl_gpio_a: pctl-gpio-a { /* GPIO bank A */ 51 pctl_gpio_a: pctl-gpio-a { /* GPIO bank A */
52 pingrp = "gpioa_pins"; 52 abilis,function = "gpioa";
53 }; 53 };
54 pctl_tsin_p1: pctl-tsin-p1 { /* Parallel TS-in 1 */ 54 pctl_tsin_p1: pctl-tsin-p1 { /* Parallel TS-in 1 */
55 pingrp = "mip1_pins"; 55 abilis,function = "mip1";
56 }; 56 };
57 /* Port 2 */ 57 /* Port 2 */
58 pctl_tsin_s2: pctl-tsin-s2 { /* Serial TS-in 2 */ 58 pctl_tsin_s2: pctl-tsin-s2 { /* Serial TS-in 2 */
59 pingrp = "mis2_pins"; 59 abilis,function = "mis2";
60 }; 60 };
61 pctl_tsin_s3: pctl-tsin-s3 { /* Serial TS-in 3 */ 61 pctl_tsin_s3: pctl-tsin-s3 { /* Serial TS-in 3 */
62 pingrp = "mis3_pins"; 62 abilis,function = "mis3";
63 }; 63 };
64 pctl_gpio_c: pctl-gpio-c { /* GPIO bank C */ 64 pctl_gpio_c: pctl-gpio-c { /* GPIO bank C */
65 pingrp = "gpioc_pins"; 65 abilis,function = "gpioc";
66 }; 66 };
67 pctl_tsin_p3: pctl-tsin-p3 { /* Parallel TS-in 3 */ 67 pctl_tsin_p3: pctl-tsin-p3 { /* Parallel TS-in 3 */
68 pingrp = "mip3_pins"; 68 abilis,function = "mip3";
69 }; 69 };
70 /* Port 3 */ 70 /* Port 3 */
71 pctl_tsin_s4: pctl-tsin-s4 { /* Serial TS-in 4 */ 71 pctl_tsin_s4: pctl-tsin-s4 { /* Serial TS-in 4 */
72 pingrp = "mis4_pins"; 72 abilis,function = "mis4";
73 }; 73 };
74 pctl_tsin_s5: pctl-tsin-s5 { /* Serial TS-in 5 */ 74 pctl_tsin_s5: pctl-tsin-s5 { /* Serial TS-in 5 */
75 pingrp = "mis5_pins"; 75 abilis,function = "mis5";
76 }; 76 };
77 pctl_gpio_e: pctl-gpio-e { /* GPIO bank E */ 77 pctl_gpio_e: pctl-gpio-e { /* GPIO bank E */
78 pingrp = "gpioe_pins"; 78 abilis,function = "gpioe";
79 }; 79 };
80 pctl_tsin_p5: pctl-tsin-p5 { /* Parallel TS-in 5 */ 80 pctl_tsin_p5: pctl-tsin-p5 { /* Parallel TS-in 5 */
81 pingrp = "mip5_pins"; 81 abilis,function = "mip5";
82 }; 82 };
83 /* Port 4 */ 83 /* Port 4 */
84 pctl_tsin_s6: pctl-tsin-s6 { /* Serial TS-in 6 */ 84 pctl_tsin_s6: pctl-tsin-s6 { /* Serial TS-in 6 */
85 pingrp = "mis6_pins"; 85 abilis,function = "mis6";
86 }; 86 };
87 pctl_tsin_s7: pctl-tsin-s7 { /* Serial TS-in 7 */ 87 pctl_tsin_s7: pctl-tsin-s7 { /* Serial TS-in 7 */
88 pingrp = "mis7_pins"; 88 abilis,function = "mis7";
89 }; 89 };
90 pctl_gpio_g: pctl-gpio-g { /* GPIO bank G */ 90 pctl_gpio_g: pctl-gpio-g { /* GPIO bank G */
91 pingrp = "gpiog_pins"; 91 abilis,function = "gpiog";
92 }; 92 };
93 pctl_tsin_p7: pctl-tsin-p7 { /* Parallel TS-in 7 */ 93 pctl_tsin_p7: pctl-tsin-p7 { /* Parallel TS-in 7 */
94 pingrp = "mip7_pins"; 94 abilis,function = "mip7";
95 }; 95 };
96 /* Port 5 */ 96 /* Port 5 */
97 pctl_gpio_j: pctl-gpio-j { /* GPIO bank J */ 97 pctl_gpio_j: pctl-gpio-j { /* GPIO bank J */
98 pingrp = "gpioj_pins"; 98 abilis,function = "gpioj";
99 }; 99 };
100 pctl_gpio_k: pctl-gpio-k { /* GPIO bank K */ 100 pctl_gpio_k: pctl-gpio-k { /* GPIO bank K */
101 pingrp = "gpiok_pins"; 101 abilis,function = "gpiok";
102 }; 102 };
103 pctl_ciplus: pctl-ciplus { /* CI+ interface */ 103 pctl_ciplus: pctl-ciplus { /* CI+ interface */
104 pingrp = "ciplus_pins"; 104 abilis,function = "ciplus";
105 }; 105 };
106 pctl_mcard: pctl-mcard { /* M-Card interface */ 106 pctl_mcard: pctl-mcard { /* M-Card interface */
107 pingrp = "mcard_pins"; 107 abilis,function = "mcard";
108 }; 108 };
109 /* Port 6 */ 109 /* Port 6 */
110 pctl_tsout_p: pctl-tsout-p { /* Parallel TS-out */ 110 pctl_tsout_p: pctl-tsout-p { /* Parallel TS-out */
111 pingrp = "mop_pins"; 111 abilis,function = "mop";
112 }; 112 };
113 pctl_tsout_s0: pctl-tsout-s0 { /* Serial TS-out 0 */ 113 pctl_tsout_s0: pctl-tsout-s0 { /* Serial TS-out 0 */
114 pingrp = "mos0_pins"; 114 abilis,function = "mos0";
115 }; 115 };
116 pctl_tsout_s1: pctl-tsout-s1 { /* Serial TS-out 1 */ 116 pctl_tsout_s1: pctl-tsout-s1 { /* Serial TS-out 1 */
117 pingrp = "mos1_pins"; 117 abilis,function = "mos1";
118 }; 118 };
119 pctl_tsout_s2: pctl-tsout-s2 { /* Serial TS-out 2 */ 119 pctl_tsout_s2: pctl-tsout-s2 { /* Serial TS-out 2 */
120 pingrp = "mos2_pins"; 120 abilis,function = "mos2";
121 }; 121 };
122 pctl_tsout_s3: pctl-tsout-s3 { /* Serial TS-out 3 */ 122 pctl_tsout_s3: pctl-tsout-s3 { /* Serial TS-out 3 */
123 pingrp = "mos3_pins"; 123 abilis,function = "mos3";
124 }; 124 };
125 /* Port 7 */ 125 /* Port 7 */
126 pctl_uart0: pctl-uart0 { /* UART 0 */ 126 pctl_uart0: pctl-uart0 { /* UART 0 */
127 pingrp = "uart0_pins"; 127 abilis,function = "uart0";
128 }; 128 };
129 pctl_uart1: pctl-uart1 { /* UART 1 */ 129 pctl_uart1: pctl-uart1 { /* UART 1 */
130 pingrp = "uart1_pins"; 130 abilis,function = "uart1";
131 }; 131 };
132 pctl_gpio_l: pctl-gpio-l { /* GPIO bank L */ 132 pctl_gpio_l: pctl-gpio-l { /* GPIO bank L */
133 pingrp = "gpiol_pins"; 133 abilis,function = "gpiol";
134 }; 134 };
135 pctl_gpio_m: pctl-gpio-m { /* GPIO bank M */ 135 pctl_gpio_m: pctl-gpio-m { /* GPIO bank M */
136 pingrp = "gpiom_pins"; 136 abilis,function = "gpiom";
137 }; 137 };
138 /* Port 8 */ 138 /* Port 8 */
139 pctl_spi3: pctl-spi3 { 139 pctl_spi3: pctl-spi3 {
140 pingrp = "spi3_pins"; 140 abilis,function = "spi3";
141 }; 141 };
142 /* Port 9 */ 142 /* Port 9 */
143 pctl_spi1: pctl-spi1 { 143 pctl_spi1: pctl-spi1 {
144 pingrp = "spi1_pins"; 144 abilis,function = "spi1";
145 }; 145 };
146 pctl_gpio_n: pctl-gpio-n { 146 pctl_gpio_n: pctl-gpio-n {
147 pingrp = "gpion_pins"; 147 abilis,function = "gpion";
148 }; 148 };
149 /* Unmuxed GPIOs */ 149 /* Unmuxed GPIOs */
150 pctl_gpio_b: pctl-gpio-b { 150 pctl_gpio_b: pctl-gpio-b {
151 pingrp = "gpiob_pins"; 151 abilis,function = "gpiob";
152 }; 152 };
153 pctl_gpio_d: pctl-gpio-d { 153 pctl_gpio_d: pctl-gpio-d {
154 pingrp = "gpiod_pins"; 154 abilis,function = "gpiod";
155 }; 155 };
156 pctl_gpio_f: pctl-gpio-f { 156 pctl_gpio_f: pctl-gpio-f {
157 pingrp = "gpiof_pins"; 157 abilis,function = "gpiof";
158 }; 158 };
159 pctl_gpio_h: pctl-gpio-h { 159 pctl_gpio_h: pctl-gpio-h {
160 pingrp = "gpioh_pins"; 160 abilis,function = "gpioh";
161 }; 161 };
162 pctl_gpio_i: pctl-gpio-i { 162 pctl_gpio_i: pctl-gpio-i {
163 pingrp = "gpioi_pins"; 163 abilis,function = "gpioi";
164 }; 164 };
165 }; 165 };
166 166
@@ -172,9 +172,10 @@
172 interrupts = <27 2>; 172 interrupts = <27 2>;
173 reg = <0xFF140000 0x1000>; 173 reg = <0xFF140000 0x1000>;
174 gpio-controller; 174 gpio-controller;
175 #gpio-cells = <1>; 175 #gpio-cells = <2>;
176 gpio-base = <0>; 176 abilis,ngpio = <3>;
177 gpio-pins = <&pctl_gpio_a>; 177 gpio-ranges = <&iomux 0 0 0>;
178 gpio-ranges-group-names = "gpioa";
178 }; 179 };
179 gpiob: gpio@FF141000 { 180 gpiob: gpio@FF141000 {
180 compatible = "abilis,tb10x-gpio"; 181 compatible = "abilis,tb10x-gpio";
@@ -184,9 +185,10 @@
184 interrupts = <27 2>; 185 interrupts = <27 2>;
185 reg = <0xFF141000 0x1000>; 186 reg = <0xFF141000 0x1000>;
186 gpio-controller; 187 gpio-controller;
187 #gpio-cells = <1>; 188 #gpio-cells = <2>;
188 gpio-base = <3>; 189 abilis,ngpio = <2>;
189 gpio-pins = <&pctl_gpio_b>; 190 gpio-ranges = <&iomux 0 0 0>;
191 gpio-ranges-group-names = "gpiob";
190 }; 192 };
191 gpioc: gpio@FF142000 { 193 gpioc: gpio@FF142000 {
192 compatible = "abilis,tb10x-gpio"; 194 compatible = "abilis,tb10x-gpio";
@@ -196,9 +198,10 @@
196 interrupts = <27 2>; 198 interrupts = <27 2>;
197 reg = <0xFF142000 0x1000>; 199 reg = <0xFF142000 0x1000>;
198 gpio-controller; 200 gpio-controller;
199 #gpio-cells = <1>; 201 #gpio-cells = <2>;
200 gpio-base = <5>; 202 abilis,ngpio = <3>;
201 gpio-pins = <&pctl_gpio_c>; 203 gpio-ranges = <&iomux 0 0 0>;
204 gpio-ranges-group-names = "gpioc";
202 }; 205 };
203 gpiod: gpio@FF143000 { 206 gpiod: gpio@FF143000 {
204 compatible = "abilis,tb10x-gpio"; 207 compatible = "abilis,tb10x-gpio";
@@ -208,9 +211,10 @@
208 interrupts = <27 2>; 211 interrupts = <27 2>;
209 reg = <0xFF143000 0x1000>; 212 reg = <0xFF143000 0x1000>;
210 gpio-controller; 213 gpio-controller;
211 #gpio-cells = <1>; 214 #gpio-cells = <2>;
212 gpio-base = <8>; 215 abilis,ngpio = <2>;
213 gpio-pins = <&pctl_gpio_d>; 216 gpio-ranges = <&iomux 0 0 0>;
217 gpio-ranges-group-names = "gpiod";
214 }; 218 };
215 gpioe: gpio@FF144000 { 219 gpioe: gpio@FF144000 {
216 compatible = "abilis,tb10x-gpio"; 220 compatible = "abilis,tb10x-gpio";
@@ -220,9 +224,10 @@
220 interrupts = <27 2>; 224 interrupts = <27 2>;
221 reg = <0xFF144000 0x1000>; 225 reg = <0xFF144000 0x1000>;
222 gpio-controller; 226 gpio-controller;
223 #gpio-cells = <1>; 227 #gpio-cells = <2>;
224 gpio-base = <10>; 228 abilis,ngpio = <3>;
225 gpio-pins = <&pctl_gpio_e>; 229 gpio-ranges = <&iomux 0 0 0>;
230 gpio-ranges-group-names = "gpioe";
226 }; 231 };
227 gpiof: gpio@FF145000 { 232 gpiof: gpio@FF145000 {
228 compatible = "abilis,tb10x-gpio"; 233 compatible = "abilis,tb10x-gpio";
@@ -232,9 +237,10 @@
232 interrupts = <27 2>; 237 interrupts = <27 2>;
233 reg = <0xFF145000 0x1000>; 238 reg = <0xFF145000 0x1000>;
234 gpio-controller; 239 gpio-controller;
235 #gpio-cells = <1>; 240 #gpio-cells = <2>;
236 gpio-base = <13>; 241 abilis,ngpio = <2>;
237 gpio-pins = <&pctl_gpio_f>; 242 gpio-ranges = <&iomux 0 0 0>;
243 gpio-ranges-group-names = "gpiof";
238 }; 244 };
239 gpiog: gpio@FF146000 { 245 gpiog: gpio@FF146000 {
240 compatible = "abilis,tb10x-gpio"; 246 compatible = "abilis,tb10x-gpio";
@@ -244,9 +250,10 @@
244 interrupts = <27 2>; 250 interrupts = <27 2>;
245 reg = <0xFF146000 0x1000>; 251 reg = <0xFF146000 0x1000>;
246 gpio-controller; 252 gpio-controller;
247 #gpio-cells = <1>; 253 #gpio-cells = <2>;
248 gpio-base = <15>; 254 abilis,ngpio = <3>;
249 gpio-pins = <&pctl_gpio_g>; 255 gpio-ranges = <&iomux 0 0 0>;
256 gpio-ranges-group-names = "gpiog";
250 }; 257 };
251 gpioh: gpio@FF147000 { 258 gpioh: gpio@FF147000 {
252 compatible = "abilis,tb10x-gpio"; 259 compatible = "abilis,tb10x-gpio";
@@ -256,9 +263,10 @@
256 interrupts = <27 2>; 263 interrupts = <27 2>;
257 reg = <0xFF147000 0x1000>; 264 reg = <0xFF147000 0x1000>;
258 gpio-controller; 265 gpio-controller;
259 #gpio-cells = <1>; 266 #gpio-cells = <2>;
260 gpio-base = <18>; 267 abilis,ngpio = <2>;
261 gpio-pins = <&pctl_gpio_h>; 268 gpio-ranges = <&iomux 0 0 0>;
269 gpio-ranges-group-names = "gpioh";
262 }; 270 };
263 gpioi: gpio@FF148000 { 271 gpioi: gpio@FF148000 {
264 compatible = "abilis,tb10x-gpio"; 272 compatible = "abilis,tb10x-gpio";
@@ -268,9 +276,10 @@
268 interrupts = <27 2>; 276 interrupts = <27 2>;
269 reg = <0xFF148000 0x1000>; 277 reg = <0xFF148000 0x1000>;
270 gpio-controller; 278 gpio-controller;
271 #gpio-cells = <1>; 279 #gpio-cells = <2>;
272 gpio-base = <20>; 280 abilis,ngpio = <12>;
273 gpio-pins = <&pctl_gpio_i>; 281 gpio-ranges = <&iomux 0 0 0>;
282 gpio-ranges-group-names = "gpioi";
274 }; 283 };
275 gpioj: gpio@FF149000 { 284 gpioj: gpio@FF149000 {
276 compatible = "abilis,tb10x-gpio"; 285 compatible = "abilis,tb10x-gpio";
@@ -280,9 +289,10 @@
280 interrupts = <27 2>; 289 interrupts = <27 2>;
281 reg = <0xFF149000 0x1000>; 290 reg = <0xFF149000 0x1000>;
282 gpio-controller; 291 gpio-controller;
283 #gpio-cells = <1>; 292 #gpio-cells = <2>;
284 gpio-base = <32>; 293 abilis,ngpio = <32>;
285 gpio-pins = <&pctl_gpio_j>; 294 gpio-ranges = <&iomux 0 0 0>;
295 gpio-ranges-group-names = "gpioj";
286 }; 296 };
287 gpiok: gpio@FF14a000 { 297 gpiok: gpio@FF14a000 {
288 compatible = "abilis,tb10x-gpio"; 298 compatible = "abilis,tb10x-gpio";
@@ -292,9 +302,10 @@
292 interrupts = <27 2>; 302 interrupts = <27 2>;
293 reg = <0xFF14A000 0x1000>; 303 reg = <0xFF14A000 0x1000>;
294 gpio-controller; 304 gpio-controller;
295 #gpio-cells = <1>; 305 #gpio-cells = <2>;
296 gpio-base = <64>; 306 abilis,ngpio = <22>;
297 gpio-pins = <&pctl_gpio_k>; 307 gpio-ranges = <&iomux 0 0 0>;
308 gpio-ranges-group-names = "gpiok";
298 }; 309 };
299 gpiol: gpio@FF14b000 { 310 gpiol: gpio@FF14b000 {
300 compatible = "abilis,tb10x-gpio"; 311 compatible = "abilis,tb10x-gpio";
@@ -304,9 +315,10 @@
304 interrupts = <27 2>; 315 interrupts = <27 2>;
305 reg = <0xFF14B000 0x1000>; 316 reg = <0xFF14B000 0x1000>;
306 gpio-controller; 317 gpio-controller;
307 #gpio-cells = <1>; 318 #gpio-cells = <2>;
308 gpio-base = <86>; 319 abilis,ngpio = <4>;
309 gpio-pins = <&pctl_gpio_l>; 320 gpio-ranges = <&iomux 0 0 0>;
321 gpio-ranges-group-names = "gpiol";
310 }; 322 };
311 gpiom: gpio@FF14c000 { 323 gpiom: gpio@FF14c000 {
312 compatible = "abilis,tb10x-gpio"; 324 compatible = "abilis,tb10x-gpio";
@@ -316,9 +328,10 @@
316 interrupts = <27 2>; 328 interrupts = <27 2>;
317 reg = <0xFF14C000 0x1000>; 329 reg = <0xFF14C000 0x1000>;
318 gpio-controller; 330 gpio-controller;
319 #gpio-cells = <1>; 331 #gpio-cells = <2>;
320 gpio-base = <90>; 332 abilis,ngpio = <4>;
321 gpio-pins = <&pctl_gpio_m>; 333 gpio-ranges = <&iomux 0 0 0>;
334 gpio-ranges-group-names = "gpiom";
322 }; 335 };
323 gpion: gpio@FF14d000 { 336 gpion: gpio@FF14d000 {
324 compatible = "abilis,tb10x-gpio"; 337 compatible = "abilis,tb10x-gpio";
@@ -328,9 +341,10 @@
328 interrupts = <27 2>; 341 interrupts = <27 2>;
329 reg = <0xFF14D000 0x1000>; 342 reg = <0xFF14D000 0x1000>;
330 gpio-controller; 343 gpio-controller;
331 #gpio-cells = <1>; 344 #gpio-cells = <2>;
332 gpio-base = <94>; 345 abilis,ngpio = <5>;
333 gpio-pins = <&pctl_gpio_n>; 346 gpio-ranges = <&iomux 0 0 0>;
347 gpio-ranges-group-names = "gpion";
334 }; 348 };
335 }; 349 };
336}; 350};
diff --git a/arch/arc/boot/dts/abilis_tb100_dvk.dts b/arch/arc/boot/dts/abilis_tb100_dvk.dts
index ebc313a9f5b2..3dd6ed941464 100644
--- a/arch/arc/boot/dts/abilis_tb100_dvk.dts
+++ b/arch/arc/boot/dts/abilis_tb100_dvk.dts
@@ -64,62 +64,62 @@
64 compatible = "gpio-leds"; 64 compatible = "gpio-leds";
65 power { 65 power {
66 label = "Power"; 66 label = "Power";
67 gpios = <&gpioi 0>; 67 gpios = <&gpioi 0 0>;
68 linux,default-trigger = "default-on"; 68 linux,default-trigger = "default-on";
69 }; 69 };
70 heartbeat { 70 heartbeat {
71 label = "Heartbeat"; 71 label = "Heartbeat";
72 gpios = <&gpioi 1>; 72 gpios = <&gpioi 1 0>;
73 linux,default-trigger = "heartbeat"; 73 linux,default-trigger = "heartbeat";
74 }; 74 };
75 led2 { 75 led2 {
76 label = "LED2"; 76 label = "LED2";
77 gpios = <&gpioi 2>; 77 gpios = <&gpioi 2 0>;
78 default-state = "off"; 78 default-state = "off";
79 }; 79 };
80 led3 { 80 led3 {
81 label = "LED3"; 81 label = "LED3";
82 gpios = <&gpioi 3>; 82 gpios = <&gpioi 3 0>;
83 default-state = "off"; 83 default-state = "off";
84 }; 84 };
85 led4 { 85 led4 {
86 label = "LED4"; 86 label = "LED4";
87 gpios = <&gpioi 4>; 87 gpios = <&gpioi 4 0>;
88 default-state = "off"; 88 default-state = "off";
89 }; 89 };
90 led5 { 90 led5 {
91 label = "LED5"; 91 label = "LED5";
92 gpios = <&gpioi 5>; 92 gpios = <&gpioi 5 0>;
93 default-state = "off"; 93 default-state = "off";
94 }; 94 };
95 led6 { 95 led6 {
96 label = "LED6"; 96 label = "LED6";
97 gpios = <&gpioi 6>; 97 gpios = <&gpioi 6 0>;
98 default-state = "off"; 98 default-state = "off";
99 }; 99 };
100 led7 { 100 led7 {
101 label = "LED7"; 101 label = "LED7";
102 gpios = <&gpioi 7>; 102 gpios = <&gpioi 7 0>;
103 default-state = "off"; 103 default-state = "off";
104 }; 104 };
105 led8 { 105 led8 {
106 label = "LED8"; 106 label = "LED8";
107 gpios = <&gpioi 8>; 107 gpios = <&gpioi 8 0>;
108 default-state = "off"; 108 default-state = "off";
109 }; 109 };
110 led9 { 110 led9 {
111 label = "LED9"; 111 label = "LED9";
112 gpios = <&gpioi 9>; 112 gpios = <&gpioi 9 0>;
113 default-state = "off"; 113 default-state = "off";
114 }; 114 };
115 led10 { 115 led10 {
116 label = "LED10"; 116 label = "LED10";
117 gpios = <&gpioi 10>; 117 gpios = <&gpioi 10 0>;
118 default-state = "off"; 118 default-state = "off";
119 }; 119 };
120 led11 { 120 led11 {
121 label = "LED11"; 121 label = "LED11";
122 gpios = <&gpioi 11>; 122 gpios = <&gpioi 11 0>;
123 default-state = "off"; 123 default-state = "off";
124 }; 124 };
125 }; 125 };
diff --git a/arch/arc/boot/dts/abilis_tb101.dtsi b/arch/arc/boot/dts/abilis_tb101.dtsi
index da8ca7941e67..b0467229a5c4 100644
--- a/arch/arc/boot/dts/abilis_tb101.dtsi
+++ b/arch/arc/boot/dts/abilis_tb101.dtsi
@@ -43,133 +43,133 @@
43 iomux: iomux@FF10601c { 43 iomux: iomux@FF10601c {
44 /* Port 1 */ 44 /* Port 1 */
45 pctl_tsin_s0: pctl-tsin-s0 { /* Serial TS-in 0 */ 45 pctl_tsin_s0: pctl-tsin-s0 { /* Serial TS-in 0 */
46 pingrp = "mis0_pins"; 46 abilis,function = "mis0";
47 }; 47 };
48 pctl_tsin_s1: pctl-tsin-s1 { /* Serial TS-in 1 */ 48 pctl_tsin_s1: pctl-tsin-s1 { /* Serial TS-in 1 */
49 pingrp = "mis1_pins"; 49 abilis,function = "mis1";
50 }; 50 };
51 pctl_gpio_a: pctl-gpio-a { /* GPIO bank A */ 51 pctl_gpio_a: pctl-gpio-a { /* GPIO bank A */
52 pingrp = "gpioa_pins"; 52 abilis,function = "gpioa";
53 }; 53 };
54 pctl_tsin_p1: pctl-tsin-p1 { /* Parallel TS-in 1 */ 54 pctl_tsin_p1: pctl-tsin-p1 { /* Parallel TS-in 1 */
55 pingrp = "mip1_pins"; 55 abilis,function = "mip1";
56 }; 56 };
57 /* Port 2 */ 57 /* Port 2 */
58 pctl_tsin_s2: pctl-tsin-s2 { /* Serial TS-in 2 */ 58 pctl_tsin_s2: pctl-tsin-s2 { /* Serial TS-in 2 */
59 pingrp = "mis2_pins"; 59 abilis,function = "mis2";
60 }; 60 };
61 pctl_tsin_s3: pctl-tsin-s3 { /* Serial TS-in 3 */ 61 pctl_tsin_s3: pctl-tsin-s3 { /* Serial TS-in 3 */
62 pingrp = "mis3_pins"; 62 abilis,function = "mis3";
63 }; 63 };
64 pctl_gpio_c: pctl-gpio-c { /* GPIO bank C */ 64 pctl_gpio_c: pctl-gpio-c { /* GPIO bank C */
65 pingrp = "gpioc_pins"; 65 abilis,function = "gpioc";
66 }; 66 };
67 pctl_tsin_p3: pctl-tsin-p3 { /* Parallel TS-in 3 */ 67 pctl_tsin_p3: pctl-tsin-p3 { /* Parallel TS-in 3 */
68 pingrp = "mip3_pins"; 68 abilis,function = "mip3";
69 }; 69 };
70 /* Port 3 */ 70 /* Port 3 */
71 pctl_tsin_s4: pctl-tsin-s4 { /* Serial TS-in 4 */ 71 pctl_tsin_s4: pctl-tsin-s4 { /* Serial TS-in 4 */
72 pingrp = "mis4_pins"; 72 abilis,function = "mis4";
73 }; 73 };
74 pctl_tsin_s5: pctl-tsin-s5 { /* Serial TS-in 5 */ 74 pctl_tsin_s5: pctl-tsin-s5 { /* Serial TS-in 5 */
75 pingrp = "mis5_pins"; 75 abilis,function = "mis5";
76 }; 76 };
77 pctl_gpio_e: pctl-gpio-e { /* GPIO bank E */ 77 pctl_gpio_e: pctl-gpio-e { /* GPIO bank E */
78 pingrp = "gpioe_pins"; 78 abilis,function = "gpioe";
79 }; 79 };
80 pctl_tsin_p5: pctl-tsin-p5 { /* Parallel TS-in 5 */ 80 pctl_tsin_p5: pctl-tsin-p5 { /* Parallel TS-in 5 */
81 pingrp = "mip5_pins"; 81 abilis,function = "mip5";
82 }; 82 };
83 /* Port 4 */ 83 /* Port 4 */
84 pctl_tsin_s6: pctl-tsin-s6 { /* Serial TS-in 6 */ 84 pctl_tsin_s6: pctl-tsin-s6 { /* Serial TS-in 6 */
85 pingrp = "mis6_pins"; 85 abilis,function = "mis6";
86 }; 86 };
87 pctl_tsin_s7: pctl-tsin-s7 { /* Serial TS-in 7 */ 87 pctl_tsin_s7: pctl-tsin-s7 { /* Serial TS-in 7 */
88 pingrp = "mis7_pins"; 88 abilis,function = "mis7";
89 }; 89 };
90 pctl_gpio_g: pctl-gpio-g { /* GPIO bank G */ 90 pctl_gpio_g: pctl-gpio-g { /* GPIO bank G */
91 pingrp = "gpiog_pins"; 91 abilis,function = "gpiog";
92 }; 92 };
93 pctl_tsin_p7: pctl-tsin-p7 { /* Parallel TS-in 7 */ 93 pctl_tsin_p7: pctl-tsin-p7 { /* Parallel TS-in 7 */
94 pingrp = "mip7_pins"; 94 abilis,function = "mip7";
95 }; 95 };
96 /* Port 5 */ 96 /* Port 5 */
97 pctl_gpio_j: pctl-gpio-j { /* GPIO bank J */ 97 pctl_gpio_j: pctl-gpio-j { /* GPIO bank J */
98 pingrp = "gpioj_pins"; 98 abilis,function = "gpioj";
99 }; 99 };
100 pctl_gpio_k: pctl-gpio-k { /* GPIO bank K */ 100 pctl_gpio_k: pctl-gpio-k { /* GPIO bank K */
101 pingrp = "gpiok_pins"; 101 abilis,function = "gpiok";
102 }; 102 };
103 pctl_ciplus: pctl-ciplus { /* CI+ interface */ 103 pctl_ciplus: pctl-ciplus { /* CI+ interface */
104 pingrp = "ciplus_pins"; 104 abilis,function = "ciplus";
105 }; 105 };
106 pctl_mcard: pctl-mcard { /* M-Card interface */ 106 pctl_mcard: pctl-mcard { /* M-Card interface */
107 pingrp = "mcard_pins"; 107 abilis,function = "mcard";
108 }; 108 };
109 pctl_stc0: pctl-stc0 { /* Smart card I/F 0 */ 109 pctl_stc0: pctl-stc0 { /* Smart card I/F 0 */
110 pingrp = "stc0_pins"; 110 abilis,function = "stc0";
111 }; 111 };
112 pctl_stc1: pctl-stc1 { /* Smart card I/F 1 */ 112 pctl_stc1: pctl-stc1 { /* Smart card I/F 1 */
113 pingrp = "stc1_pins"; 113 abilis,function = "stc1";
114 }; 114 };
115 /* Port 6 */ 115 /* Port 6 */
116 pctl_tsout_p: pctl-tsout-p { /* Parallel TS-out */ 116 pctl_tsout_p: pctl-tsout-p { /* Parallel TS-out */
117 pingrp = "mop_pins"; 117 abilis,function = "mop";
118 }; 118 };
119 pctl_tsout_s0: pctl-tsout-s0 { /* Serial TS-out 0 */ 119 pctl_tsout_s0: pctl-tsout-s0 { /* Serial TS-out 0 */
120 pingrp = "mos0_pins"; 120 abilis,function = "mos0";
121 }; 121 };
122 pctl_tsout_s1: pctl-tsout-s1 { /* Serial TS-out 1 */ 122 pctl_tsout_s1: pctl-tsout-s1 { /* Serial TS-out 1 */
123 pingrp = "mos1_pins"; 123 abilis,function = "mos1";
124 }; 124 };
125 pctl_tsout_s2: pctl-tsout-s2 { /* Serial TS-out 2 */ 125 pctl_tsout_s2: pctl-tsout-s2 { /* Serial TS-out 2 */
126 pingrp = "mos2_pins"; 126 abilis,function = "mos2";
127 }; 127 };
128 pctl_tsout_s3: pctl-tsout-s3 { /* Serial TS-out 3 */ 128 pctl_tsout_s3: pctl-tsout-s3 { /* Serial TS-out 3 */
129 pingrp = "mos3_pins"; 129 abilis,function = "mos3";
130 }; 130 };
131 /* Port 7 */ 131 /* Port 7 */
132 pctl_uart0: pctl-uart0 { /* UART 0 */ 132 pctl_uart0: pctl-uart0 { /* UART 0 */
133 pingrp = "uart0_pins"; 133 abilis,function = "uart0";
134 }; 134 };
135 pctl_uart1: pctl-uart1 { /* UART 1 */ 135 pctl_uart1: pctl-uart1 { /* UART 1 */
136 pingrp = "uart1_pins"; 136 abilis,function = "uart1";
137 }; 137 };
138 pctl_gpio_l: pctl-gpio-l { /* GPIO bank L */ 138 pctl_gpio_l: pctl-gpio-l { /* GPIO bank L */
139 pingrp = "gpiol_pins"; 139 abilis,function = "gpiol";
140 }; 140 };
141 pctl_gpio_m: pctl-gpio-m { /* GPIO bank M */ 141 pctl_gpio_m: pctl-gpio-m { /* GPIO bank M */
142 pingrp = "gpiom_pins"; 142 abilis,function = "gpiom";
143 }; 143 };
144 /* Port 8 */ 144 /* Port 8 */
145 pctl_spi3: pctl-spi3 { 145 pctl_spi3: pctl-spi3 {
146 pingrp = "spi3_pins"; 146 abilis,function = "spi3";
147 }; 147 };
148 pctl_jtag: pctl-jtag { 148 pctl_jtag: pctl-jtag {
149 pingrp = "jtag_pins"; 149 abilis,function = "jtag";
150 }; 150 };
151 /* Port 9 */ 151 /* Port 9 */
152 pctl_spi1: pctl-spi1 { 152 pctl_spi1: pctl-spi1 {
153 pingrp = "spi1_pins"; 153 abilis,function = "spi1";
154 }; 154 };
155 pctl_gpio_n: pctl-gpio-n { 155 pctl_gpio_n: pctl-gpio-n {
156 pingrp = "gpion_pins"; 156 abilis,function = "gpion";
157 }; 157 };
158 /* Unmuxed GPIOs */ 158 /* Unmuxed GPIOs */
159 pctl_gpio_b: pctl-gpio-b { 159 pctl_gpio_b: pctl-gpio-b {
160 pingrp = "gpiob_pins"; 160 abilis,function = "gpiob";
161 }; 161 };
162 pctl_gpio_d: pctl-gpio-d { 162 pctl_gpio_d: pctl-gpio-d {
163 pingrp = "gpiod_pins"; 163 abilis,function = "gpiod";
164 }; 164 };
165 pctl_gpio_f: pctl-gpio-f { 165 pctl_gpio_f: pctl-gpio-f {
166 pingrp = "gpiof_pins"; 166 abilis,function = "gpiof";
167 }; 167 };
168 pctl_gpio_h: pctl-gpio-h { 168 pctl_gpio_h: pctl-gpio-h {
169 pingrp = "gpioh_pins"; 169 abilis,function = "gpioh";
170 }; 170 };
171 pctl_gpio_i: pctl-gpio-i { 171 pctl_gpio_i: pctl-gpio-i {
172 pingrp = "gpioi_pins"; 172 abilis,function = "gpioi";
173 }; 173 };
174 }; 174 };
175 175
@@ -181,9 +181,10 @@
181 interrupts = <27 2>; 181 interrupts = <27 2>;
182 reg = <0xFF140000 0x1000>; 182 reg = <0xFF140000 0x1000>;
183 gpio-controller; 183 gpio-controller;
184 #gpio-cells = <1>; 184 #gpio-cells = <2>;
185 gpio-base = <0>; 185 abilis,ngpio = <3>;
186 gpio-pins = <&pctl_gpio_a>; 186 gpio-ranges = <&iomux 0 0 0>;
187 gpio-ranges-group-names = "gpioa";
187 }; 188 };
188 gpiob: gpio@FF141000 { 189 gpiob: gpio@FF141000 {
189 compatible = "abilis,tb10x-gpio"; 190 compatible = "abilis,tb10x-gpio";
@@ -193,9 +194,10 @@
193 interrupts = <27 2>; 194 interrupts = <27 2>;
194 reg = <0xFF141000 0x1000>; 195 reg = <0xFF141000 0x1000>;
195 gpio-controller; 196 gpio-controller;
196 #gpio-cells = <1>; 197 #gpio-cells = <2>;
197 gpio-base = <3>; 198 abilis,ngpio = <2>;
198 gpio-pins = <&pctl_gpio_b>; 199 gpio-ranges = <&iomux 0 0 0>;
200 gpio-ranges-group-names = "gpiob";
199 }; 201 };
200 gpioc: gpio@FF142000 { 202 gpioc: gpio@FF142000 {
201 compatible = "abilis,tb10x-gpio"; 203 compatible = "abilis,tb10x-gpio";
@@ -205,9 +207,10 @@
205 interrupts = <27 2>; 207 interrupts = <27 2>;
206 reg = <0xFF142000 0x1000>; 208 reg = <0xFF142000 0x1000>;
207 gpio-controller; 209 gpio-controller;
208 #gpio-cells = <1>; 210 #gpio-cells = <2>;
209 gpio-base = <5>; 211 abilis,ngpio = <3>;
210 gpio-pins = <&pctl_gpio_c>; 212 gpio-ranges = <&iomux 0 0 0>;
213 gpio-ranges-group-names = "gpioc";
211 }; 214 };
212 gpiod: gpio@FF143000 { 215 gpiod: gpio@FF143000 {
213 compatible = "abilis,tb10x-gpio"; 216 compatible = "abilis,tb10x-gpio";
@@ -217,9 +220,10 @@
217 interrupts = <27 2>; 220 interrupts = <27 2>;
218 reg = <0xFF143000 0x1000>; 221 reg = <0xFF143000 0x1000>;
219 gpio-controller; 222 gpio-controller;
220 #gpio-cells = <1>; 223 #gpio-cells = <2>;
221 gpio-base = <8>; 224 abilis,ngpio = <2>;
222 gpio-pins = <&pctl_gpio_d>; 225 gpio-ranges = <&iomux 0 0 0>;
226 gpio-ranges-group-names = "gpiod";
223 }; 227 };
224 gpioe: gpio@FF144000 { 228 gpioe: gpio@FF144000 {
225 compatible = "abilis,tb10x-gpio"; 229 compatible = "abilis,tb10x-gpio";
@@ -229,9 +233,10 @@
229 interrupts = <27 2>; 233 interrupts = <27 2>;
230 reg = <0xFF144000 0x1000>; 234 reg = <0xFF144000 0x1000>;
231 gpio-controller; 235 gpio-controller;
232 #gpio-cells = <1>; 236 #gpio-cells = <2>;
233 gpio-base = <10>; 237 abilis,ngpio = <3>;
234 gpio-pins = <&pctl_gpio_e>; 238 gpio-ranges = <&iomux 0 0 0>;
239 gpio-ranges-group-names = "gpioe";
235 }; 240 };
236 gpiof: gpio@FF145000 { 241 gpiof: gpio@FF145000 {
237 compatible = "abilis,tb10x-gpio"; 242 compatible = "abilis,tb10x-gpio";
@@ -241,9 +246,10 @@
241 interrupts = <27 2>; 246 interrupts = <27 2>;
242 reg = <0xFF145000 0x1000>; 247 reg = <0xFF145000 0x1000>;
243 gpio-controller; 248 gpio-controller;
244 #gpio-cells = <1>; 249 #gpio-cells = <2>;
245 gpio-base = <13>; 250 abilis,ngpio = <2>;
246 gpio-pins = <&pctl_gpio_f>; 251 gpio-ranges = <&iomux 0 0 0>;
252 gpio-ranges-group-names = "gpiof";
247 }; 253 };
248 gpiog: gpio@FF146000 { 254 gpiog: gpio@FF146000 {
249 compatible = "abilis,tb10x-gpio"; 255 compatible = "abilis,tb10x-gpio";
@@ -253,9 +259,10 @@
253 interrupts = <27 2>; 259 interrupts = <27 2>;
254 reg = <0xFF146000 0x1000>; 260 reg = <0xFF146000 0x1000>;
255 gpio-controller; 261 gpio-controller;
256 #gpio-cells = <1>; 262 #gpio-cells = <2>;
257 gpio-base = <15>; 263 abilis,ngpio = <3>;
258 gpio-pins = <&pctl_gpio_g>; 264 gpio-ranges = <&iomux 0 0 0>;
265 gpio-ranges-group-names = "gpiog";
259 }; 266 };
260 gpioh: gpio@FF147000 { 267 gpioh: gpio@FF147000 {
261 compatible = "abilis,tb10x-gpio"; 268 compatible = "abilis,tb10x-gpio";
@@ -265,9 +272,10 @@
265 interrupts = <27 2>; 272 interrupts = <27 2>;
266 reg = <0xFF147000 0x1000>; 273 reg = <0xFF147000 0x1000>;
267 gpio-controller; 274 gpio-controller;
268 #gpio-cells = <1>; 275 #gpio-cells = <2>;
269 gpio-base = <18>; 276 abilis,ngpio = <2>;
270 gpio-pins = <&pctl_gpio_h>; 277 gpio-ranges = <&iomux 0 0 0>;
278 gpio-ranges-group-names = "gpioh";
271 }; 279 };
272 gpioi: gpio@FF148000 { 280 gpioi: gpio@FF148000 {
273 compatible = "abilis,tb10x-gpio"; 281 compatible = "abilis,tb10x-gpio";
@@ -277,9 +285,10 @@
277 interrupts = <27 2>; 285 interrupts = <27 2>;
278 reg = <0xFF148000 0x1000>; 286 reg = <0xFF148000 0x1000>;
279 gpio-controller; 287 gpio-controller;
280 #gpio-cells = <1>; 288 #gpio-cells = <2>;
281 gpio-base = <20>; 289 abilis,ngpio = <12>;
282 gpio-pins = <&pctl_gpio_i>; 290 gpio-ranges = <&iomux 0 0 0>;
291 gpio-ranges-group-names = "gpioi";
283 }; 292 };
284 gpioj: gpio@FF149000 { 293 gpioj: gpio@FF149000 {
285 compatible = "abilis,tb10x-gpio"; 294 compatible = "abilis,tb10x-gpio";
@@ -289,9 +298,10 @@
289 interrupts = <27 2>; 298 interrupts = <27 2>;
290 reg = <0xFF149000 0x1000>; 299 reg = <0xFF149000 0x1000>;
291 gpio-controller; 300 gpio-controller;
292 #gpio-cells = <1>; 301 #gpio-cells = <2>;
293 gpio-base = <32>; 302 abilis,ngpio = <32>;
294 gpio-pins = <&pctl_gpio_j>; 303 gpio-ranges = <&iomux 0 0 0>;
304 gpio-ranges-group-names = "gpioj";
295 }; 305 };
296 gpiok: gpio@FF14a000 { 306 gpiok: gpio@FF14a000 {
297 compatible = "abilis,tb10x-gpio"; 307 compatible = "abilis,tb10x-gpio";
@@ -301,9 +311,10 @@
301 interrupts = <27 2>; 311 interrupts = <27 2>;
302 reg = <0xFF14A000 0x1000>; 312 reg = <0xFF14A000 0x1000>;
303 gpio-controller; 313 gpio-controller;
304 #gpio-cells = <1>; 314 #gpio-cells = <2>;
305 gpio-base = <64>; 315 abilis,ngpio = <22>;
306 gpio-pins = <&pctl_gpio_k>; 316 gpio-ranges = <&iomux 0 0 0>;
317 gpio-ranges-group-names = "gpiok";
307 }; 318 };
308 gpiol: gpio@FF14b000 { 319 gpiol: gpio@FF14b000 {
309 compatible = "abilis,tb10x-gpio"; 320 compatible = "abilis,tb10x-gpio";
@@ -313,9 +324,10 @@
313 interrupts = <27 2>; 324 interrupts = <27 2>;
314 reg = <0xFF14B000 0x1000>; 325 reg = <0xFF14B000 0x1000>;
315 gpio-controller; 326 gpio-controller;
316 #gpio-cells = <1>; 327 #gpio-cells = <2>;
317 gpio-base = <86>; 328 abilis,ngpio = <4>;
318 gpio-pins = <&pctl_gpio_l>; 329 gpio-ranges = <&iomux 0 0 0>;
330 gpio-ranges-group-names = "gpiol";
319 }; 331 };
320 gpiom: gpio@FF14c000 { 332 gpiom: gpio@FF14c000 {
321 compatible = "abilis,tb10x-gpio"; 333 compatible = "abilis,tb10x-gpio";
@@ -325,9 +337,10 @@
325 interrupts = <27 2>; 337 interrupts = <27 2>;
326 reg = <0xFF14C000 0x1000>; 338 reg = <0xFF14C000 0x1000>;
327 gpio-controller; 339 gpio-controller;
328 #gpio-cells = <1>; 340 #gpio-cells = <2>;
329 gpio-base = <90>; 341 abilis,ngpio = <4>;
330 gpio-pins = <&pctl_gpio_m>; 342 gpio-ranges = <&iomux 0 0 0>;
343 gpio-ranges-group-names = "gpiom";
331 }; 344 };
332 gpion: gpio@FF14d000 { 345 gpion: gpio@FF14d000 {
333 compatible = "abilis,tb10x-gpio"; 346 compatible = "abilis,tb10x-gpio";
@@ -337,9 +350,10 @@
337 interrupts = <27 2>; 350 interrupts = <27 2>;
338 reg = <0xFF14D000 0x1000>; 351 reg = <0xFF14D000 0x1000>;
339 gpio-controller; 352 gpio-controller;
340 #gpio-cells = <1>; 353 #gpio-cells = <2>;
341 gpio-base = <94>; 354 abilis,ngpio = <5>;
342 gpio-pins = <&pctl_gpio_n>; 355 gpio-ranges = <&iomux 0 0 0>;
356 gpio-ranges-group-names = "gpion";
343 }; 357 };
344 }; 358 };
345}; 359};
diff --git a/arch/arc/boot/dts/abilis_tb101_dvk.dts b/arch/arc/boot/dts/abilis_tb101_dvk.dts
index b204657993aa..1cf51c280f28 100644
--- a/arch/arc/boot/dts/abilis_tb101_dvk.dts
+++ b/arch/arc/boot/dts/abilis_tb101_dvk.dts
@@ -64,62 +64,62 @@
64 compatible = "gpio-leds"; 64 compatible = "gpio-leds";
65 power { 65 power {
66 label = "Power"; 66 label = "Power";
67 gpios = <&gpioi 0>; 67 gpios = <&gpioi 0 0>;
68 linux,default-trigger = "default-on"; 68 linux,default-trigger = "default-on";
69 }; 69 };
70 heartbeat { 70 heartbeat {
71 label = "Heartbeat"; 71 label = "Heartbeat";
72 gpios = <&gpioi 1>; 72 gpios = <&gpioi 1 0>;
73 linux,default-trigger = "heartbeat"; 73 linux,default-trigger = "heartbeat";
74 }; 74 };
75 led2 { 75 led2 {
76 label = "LED2"; 76 label = "LED2";
77 gpios = <&gpioi 2>; 77 gpios = <&gpioi 2 0>;
78 default-state = "off"; 78 default-state = "off";
79 }; 79 };
80 led3 { 80 led3 {
81 label = "LED3"; 81 label = "LED3";
82 gpios = <&gpioi 3>; 82 gpios = <&gpioi 3 0>;
83 default-state = "off"; 83 default-state = "off";
84 }; 84 };
85 led4 { 85 led4 {
86 label = "LED4"; 86 label = "LED4";
87 gpios = <&gpioi 4>; 87 gpios = <&gpioi 4 0>;
88 default-state = "off"; 88 default-state = "off";
89 }; 89 };
90 led5 { 90 led5 {
91 label = "LED5"; 91 label = "LED5";
92 gpios = <&gpioi 5>; 92 gpios = <&gpioi 5 0>;
93 default-state = "off"; 93 default-state = "off";
94 }; 94 };
95 led6 { 95 led6 {
96 label = "LED6"; 96 label = "LED6";
97 gpios = <&gpioi 6>; 97 gpios = <&gpioi 6 0>;
98 default-state = "off"; 98 default-state = "off";
99 }; 99 };
100 led7 { 100 led7 {
101 label = "LED7"; 101 label = "LED7";
102 gpios = <&gpioi 7>; 102 gpios = <&gpioi 7 0>;
103 default-state = "off"; 103 default-state = "off";
104 }; 104 };
105 led8 { 105 led8 {
106 label = "LED8"; 106 label = "LED8";
107 gpios = <&gpioi 8>; 107 gpios = <&gpioi 8 0>;
108 default-state = "off"; 108 default-state = "off";
109 }; 109 };
110 led9 { 110 led9 {
111 label = "LED9"; 111 label = "LED9";
112 gpios = <&gpioi 9>; 112 gpios = <&gpioi 9 0>;
113 default-state = "off"; 113 default-state = "off";
114 }; 114 };
115 led10 { 115 led10 {
116 label = "LED10"; 116 label = "LED10";
117 gpios = <&gpioi 10>; 117 gpios = <&gpioi 10 0>;
118 default-state = "off"; 118 default-state = "off";
119 }; 119 };
120 led11 { 120 led11 {
121 label = "LED11"; 121 label = "LED11";
122 gpios = <&gpioi 11>; 122 gpios = <&gpioi 11 0>;
123 default-state = "off"; 123 default-state = "off";
124 }; 124 };
125 }; 125 };
diff --git a/arch/arc/boot/dts/abilis_tb10x.dtsi b/arch/arc/boot/dts/abilis_tb10x.dtsi
index edf56f4749e1..a098d7c05e96 100644
--- a/arch/arc/boot/dts/abilis_tb10x.dtsi
+++ b/arch/arc/boot/dts/abilis_tb10x.dtsi
@@ -62,9 +62,8 @@
62 }; 62 };
63 63
64 iomux: iomux@FF10601c { 64 iomux: iomux@FF10601c {
65 #address-cells = <1>;
66 #size-cells = <1>;
67 compatible = "abilis,tb10x-iomux"; 65 compatible = "abilis,tb10x-iomux";
66 #gpio-range-cells = <3>;
68 reg = <0xFF10601c 0x4>; 67 reg = <0xFF10601c 0x4>;
69 }; 68 };
70 69
diff --git a/arch/arc/boot/dts/angel4.dts b/arch/arc/boot/dts/angel4.dts
index 4fb2d6f655bd..bcf662d21a57 100644
--- a/arch/arc/boot/dts/angel4.dts
+++ b/arch/arc/boot/dts/angel4.dts
@@ -67,5 +67,9 @@
67 reg = <1>; 67 reg = <1>;
68 }; 68 };
69 }; 69 };
70
71 arcpmu0: pmu {
72 compatible = "snps,arc700-pmu";
73 };
70 }; 74 };
71}; 75};
diff --git a/arch/arc/configs/fpga_noramfs_defconfig b/arch/arc/configs/fpga_noramfs_defconfig
new file mode 100644
index 000000000000..5276a52f6a2f
--- /dev/null
+++ b/arch/arc/configs/fpga_noramfs_defconfig
@@ -0,0 +1,64 @@
1CONFIG_CROSS_COMPILE="arc-linux-uclibc-"
2# CONFIG_LOCALVERSION_AUTO is not set
3CONFIG_DEFAULT_HOSTNAME="ARCLinux"
4# CONFIG_SWAP is not set
5CONFIG_HIGH_RES_TIMERS=y
6CONFIG_IKCONFIG=y
7CONFIG_IKCONFIG_PROC=y
8CONFIG_NAMESPACES=y
9# CONFIG_UTS_NS is not set
10# CONFIG_PID_NS is not set
11CONFIG_BLK_DEV_INITRD=y
12CONFIG_KALLSYMS_ALL=y
13CONFIG_EMBEDDED=y
14# CONFIG_SLUB_DEBUG is not set
15# CONFIG_COMPAT_BRK is not set
16CONFIG_KPROBES=y
17CONFIG_MODULES=y
18# CONFIG_LBDAF is not set
19# CONFIG_BLK_DEV_BSG is not set
20# CONFIG_IOSCHED_DEADLINE is not set
21# CONFIG_IOSCHED_CFQ is not set
22CONFIG_ARC_PLAT_FPGA_LEGACY=y
23CONFIG_ARC_BOARD_ML509=y
24# CONFIG_ARC_HAS_RTSC is not set
25CONFIG_ARC_BUILTIN_DTB_NAME="angel4"
26CONFIG_PREEMPT=y
27# CONFIG_COMPACTION is not set
28# CONFIG_CROSS_MEMORY_ATTACH is not set
29CONFIG_NET=y
30CONFIG_PACKET=y
31CONFIG_UNIX=y
32CONFIG_UNIX_DIAG=y
33CONFIG_NET_KEY=y
34CONFIG_INET=y
35# CONFIG_IPV6 is not set
36# CONFIG_STANDALONE is not set
37# CONFIG_PREVENT_FIRMWARE_BUILD is not set
38# CONFIG_FIRMWARE_IN_KERNEL is not set
39# CONFIG_BLK_DEV is not set
40CONFIG_NETDEVICES=y
41CONFIG_ARC_EMAC=y
42CONFIG_LXT_PHY=y
43# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
44# CONFIG_INPUT_KEYBOARD is not set
45# CONFIG_INPUT_MOUSE is not set
46# CONFIG_SERIO is not set
47# CONFIG_LEGACY_PTYS is not set
48# CONFIG_DEVKMEM is not set
49CONFIG_SERIAL_ARC=y
50CONFIG_SERIAL_ARC_CONSOLE=y
51# CONFIG_HW_RANDOM is not set
52# CONFIG_HWMON is not set
53# CONFIG_VGA_CONSOLE is not set
54# CONFIG_HID is not set
55# CONFIG_USB_SUPPORT is not set
56# CONFIG_IOMMU_SUPPORT is not set
57CONFIG_EXT2_FS=y
58CONFIG_EXT2_FS_XATTR=y
59CONFIG_TMPFS=y
60# CONFIG_MISC_FILESYSTEMS is not set
61CONFIG_NFS_FS=y
62# CONFIG_ENABLE_WARN_DEPRECATED is not set
63# CONFIG_ENABLE_MUST_CHECK is not set
64CONFIG_XZ_DEC=y
diff --git a/arch/arc/include/asm/perf_event.h b/arch/arc/include/asm/perf_event.h
index 115ad96480e6..cbf755e32a03 100644
--- a/arch/arc/include/asm/perf_event.h
+++ b/arch/arc/include/asm/perf_event.h
@@ -1,5 +1,7 @@
1/* 1/*
2 * Copyright (C) 2011-2012 Synopsys, Inc. (www.synopsys.com) 2 * Linux performance counter support for ARC
3 *
4 * Copyright (C) 2011-2013 Synopsys, Inc. (www.synopsys.com)
3 * 5 *
4 * 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
5 * 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
@@ -10,4 +12,204 @@
10#ifndef __ASM_PERF_EVENT_H 12#ifndef __ASM_PERF_EVENT_H
11#define __ASM_PERF_EVENT_H 13#define __ASM_PERF_EVENT_H
12 14
15/* real maximum varies per CPU, this is the maximum supported by the driver */
16#define ARC_PMU_MAX_HWEVENTS 64
17
18#define ARC_REG_CC_BUILD 0xF6
19#define ARC_REG_CC_INDEX 0x240
20#define ARC_REG_CC_NAME0 0x241
21#define ARC_REG_CC_NAME1 0x242
22
23#define ARC_REG_PCT_BUILD 0xF5
24#define ARC_REG_PCT_COUNTL 0x250
25#define ARC_REG_PCT_COUNTH 0x251
26#define ARC_REG_PCT_SNAPL 0x252
27#define ARC_REG_PCT_SNAPH 0x253
28#define ARC_REG_PCT_CONFIG 0x254
29#define ARC_REG_PCT_CONTROL 0x255
30#define ARC_REG_PCT_INDEX 0x256
31
32#define ARC_REG_PCT_CONTROL_CC (1 << 16) /* clear counts */
33#define ARC_REG_PCT_CONTROL_SN (1 << 17) /* snapshot */
34
35struct arc_reg_pct_build {
36#ifdef CONFIG_CPU_BIG_ENDIAN
37 unsigned int m:8, c:8, r:6, s:2, v:8;
38#else
39 unsigned int v:8, s:2, r:6, c:8, m:8;
40#endif
41};
42
43struct arc_reg_cc_build {
44#ifdef CONFIG_CPU_BIG_ENDIAN
45 unsigned int c:16, r:8, v:8;
46#else
47 unsigned int v:8, r:8, c:16;
48#endif
49};
50
51#define PERF_COUNT_ARC_DCLM (PERF_COUNT_HW_MAX + 0)
52#define PERF_COUNT_ARC_DCSM (PERF_COUNT_HW_MAX + 1)
53#define PERF_COUNT_ARC_ICM (PERF_COUNT_HW_MAX + 2)
54#define PERF_COUNT_ARC_BPOK (PERF_COUNT_HW_MAX + 3)
55#define PERF_COUNT_ARC_EDTLB (PERF_COUNT_HW_MAX + 4)
56#define PERF_COUNT_ARC_EITLB (PERF_COUNT_HW_MAX + 5)
57#define PERF_COUNT_ARC_HW_MAX (PERF_COUNT_HW_MAX + 6)
58
59/*
60 * The "generalized" performance events seem to really be a copy
61 * of the available events on x86 processors; the mapping to ARC
62 * events is not always possible 1-to-1. Fortunately, there doesn't
63 * seem to be an exact definition for these events, so we can cheat
64 * a bit where necessary.
65 *
66 * In particular, the following PERF events may behave a bit differently
67 * compared to other architectures:
68 *
69 * PERF_COUNT_HW_CPU_CYCLES
70 * Cycles not in halted state
71 *
72 * PERF_COUNT_HW_REF_CPU_CYCLES
73 * Reference cycles not in halted state, same as PERF_COUNT_HW_CPU_CYCLES
74 * for now as we don't do Dynamic Voltage/Frequency Scaling (yet)
75 *
76 * PERF_COUNT_HW_BUS_CYCLES
77 * Unclear what this means, Intel uses 0x013c, which according to
78 * their datasheet means "unhalted reference cycles". It sounds similar
79 * to PERF_COUNT_HW_REF_CPU_CYCLES, and we use the same counter for it.
80 *
81 * PERF_COUNT_HW_STALLED_CYCLES_BACKEND
82 * PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
83 * The ARC 700 can either measure stalls per pipeline stage, or all stalls
84 * combined; for now we assign all stalls to STALLED_CYCLES_BACKEND
85 * and all pipeline flushes (e.g. caused by mispredicts, etc.) to
86 * STALLED_CYCLES_FRONTEND.
87 *
88 * We could start multiple performance counters and combine everything
89 * afterwards, but that makes it complicated.
90 *
91 * Note that I$ cache misses aren't counted by either of the two!
92 */
93
94static const char * const arc_pmu_ev_hw_map[] = {
95 [PERF_COUNT_HW_CPU_CYCLES] = "crun",
96 [PERF_COUNT_HW_REF_CPU_CYCLES] = "crun",
97 [PERF_COUNT_HW_BUS_CYCLES] = "crun",
98 [PERF_COUNT_HW_INSTRUCTIONS] = "iall",
99 [PERF_COUNT_HW_BRANCH_MISSES] = "bpfail",
100 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = "ijmp",
101 [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = "bflush",
102 [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = "bstall",
103 [PERF_COUNT_ARC_DCLM] = "dclm",
104 [PERF_COUNT_ARC_DCSM] = "dcsm",
105 [PERF_COUNT_ARC_ICM] = "icm",
106 [PERF_COUNT_ARC_BPOK] = "bpok",
107 [PERF_COUNT_ARC_EDTLB] = "edtlb",
108 [PERF_COUNT_ARC_EITLB] = "eitlb",
109};
110
111#define C(_x) PERF_COUNT_HW_CACHE_##_x
112#define CACHE_OP_UNSUPPORTED 0xffff
113
114static const unsigned arc_pmu_cache_map[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
115 [C(L1D)] = {
116 [C(OP_READ)] = {
117 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
118 [C(RESULT_MISS)] = PERF_COUNT_ARC_DCLM,
119 },
120 [C(OP_WRITE)] = {
121 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
122 [C(RESULT_MISS)] = PERF_COUNT_ARC_DCSM,
123 },
124 [C(OP_PREFETCH)] = {
125 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
126 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
127 },
128 },
129 [C(L1I)] = {
130 [C(OP_READ)] = {
131 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
132 [C(RESULT_MISS)] = PERF_COUNT_ARC_ICM,
133 },
134 [C(OP_WRITE)] = {
135 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
136 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
137 },
138 [C(OP_PREFETCH)] = {
139 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
140 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
141 },
142 },
143 [C(LL)] = {
144 [C(OP_READ)] = {
145 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
146 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
147 },
148 [C(OP_WRITE)] = {
149 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
150 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
151 },
152 [C(OP_PREFETCH)] = {
153 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
154 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
155 },
156 },
157 [C(DTLB)] = {
158 [C(OP_READ)] = {
159 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
160 [C(RESULT_MISS)] = PERF_COUNT_ARC_EDTLB,
161 },
162 [C(OP_WRITE)] = {
163 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
164 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
165 },
166 [C(OP_PREFETCH)] = {
167 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
168 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
169 },
170 },
171 [C(ITLB)] = {
172 [C(OP_READ)] = {
173 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
174 [C(RESULT_MISS)] = PERF_COUNT_ARC_EITLB,
175 },
176 [C(OP_WRITE)] = {
177 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
178 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
179 },
180 [C(OP_PREFETCH)] = {
181 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
182 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
183 },
184 },
185 [C(BPU)] = {
186 [C(OP_READ)] = {
187 [C(RESULT_ACCESS)] = PERF_COUNT_HW_BRANCH_INSTRUCTIONS,
188 [C(RESULT_MISS)] = PERF_COUNT_HW_BRANCH_MISSES,
189 },
190 [C(OP_WRITE)] = {
191 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
192 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
193 },
194 [C(OP_PREFETCH)] = {
195 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
196 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
197 },
198 },
199 [C(NODE)] = {
200 [C(OP_READ)] = {
201 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
202 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
203 },
204 [C(OP_WRITE)] = {
205 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
206 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
207 },
208 [C(OP_PREFETCH)] = {
209 [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
210 [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
211 },
212 },
213};
214
13#endif /* __ASM_PERF_EVENT_H */ 215#endif /* __ASM_PERF_EVENT_H */
diff --git a/arch/arc/include/asm/thread_info.h b/arch/arc/include/asm/thread_info.h
index 2d50a4cdd7f3..45be21672011 100644
--- a/arch/arc/include/asm/thread_info.h
+++ b/arch/arc/include/asm/thread_info.h
@@ -80,8 +80,6 @@ static inline __attribute_const__ struct thread_info *current_thread_info(void)
80 80
81#endif /* !__ASSEMBLY__ */ 81#endif /* !__ASSEMBLY__ */
82 82
83#define PREEMPT_ACTIVE 0x10000000
84
85/* 83/*
86 * thread information flags 84 * thread information flags
87 * - these are process state flags that various assembly files may need to 85 * - these are process state flags that various assembly files may need to
diff --git a/arch/arc/kernel/Makefile b/arch/arc/kernel/Makefile
index c242ef07ba70..8004b4fa6461 100644
--- a/arch/arc/kernel/Makefile
+++ b/arch/arc/kernel/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_KPROBES) += kprobes.o
19obj-$(CONFIG_ARC_MISALIGN_ACCESS) += unaligned.o 19obj-$(CONFIG_ARC_MISALIGN_ACCESS) += unaligned.o
20obj-$(CONFIG_KGDB) += kgdb.o 20obj-$(CONFIG_KGDB) += kgdb.o
21obj-$(CONFIG_ARC_METAWARE_HLINK) += arc_hostlink.o 21obj-$(CONFIG_ARC_METAWARE_HLINK) += arc_hostlink.o
22obj-$(CONFIG_PERF_EVENTS) += perf_event.o
22 23
23obj-$(CONFIG_ARC_FPU_SAVE_RESTORE) += fpu.o 24obj-$(CONFIG_ARC_FPU_SAVE_RESTORE) += fpu.o
24CFLAGS_fpu.o += -mdpfp 25CFLAGS_fpu.o += -mdpfp
diff --git a/arch/arc/kernel/perf_event.c b/arch/arc/kernel/perf_event.c
new file mode 100644
index 000000000000..e46d81f70979
--- /dev/null
+++ b/arch/arc/kernel/perf_event.c
@@ -0,0 +1,326 @@
1/*
2 * Linux performance counter support for ARC700 series
3 *
4 * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
5 *
6 * This code is inspired by the perf support of various other architectures.
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/errno.h>
14#include <linux/module.h>
15#include <linux/of.h>
16#include <linux/perf_event.h>
17#include <linux/platform_device.h>
18#include <asm/arcregs.h>
19
20struct arc_pmu {
21 struct pmu pmu;
22 int counter_size; /* in bits */
23 int n_counters;
24 unsigned long used_mask[BITS_TO_LONGS(ARC_PMU_MAX_HWEVENTS)];
25 int ev_hw_idx[PERF_COUNT_ARC_HW_MAX];
26};
27
28/* read counter #idx; note that counter# != event# on ARC! */
29static uint64_t arc_pmu_read_counter(int idx)
30{
31 uint32_t tmp;
32 uint64_t result;
33
34 /*
35 * ARC supports making 'snapshots' of the counters, so we don't
36 * need to care about counters wrapping to 0 underneath our feet
37 */
38 write_aux_reg(ARC_REG_PCT_INDEX, idx);
39 tmp = read_aux_reg(ARC_REG_PCT_CONTROL);
40 write_aux_reg(ARC_REG_PCT_CONTROL, tmp | ARC_REG_PCT_CONTROL_SN);
41 result = (uint64_t) (read_aux_reg(ARC_REG_PCT_SNAPH)) << 32;
42 result |= read_aux_reg(ARC_REG_PCT_SNAPL);
43
44 return result;
45}
46
47static void arc_perf_event_update(struct perf_event *event,
48 struct hw_perf_event *hwc, int idx)
49{
50 struct arc_pmu *arc_pmu = container_of(event->pmu, struct arc_pmu, pmu);
51 uint64_t prev_raw_count, new_raw_count;
52 int64_t delta;
53
54 do {
55 prev_raw_count = local64_read(&hwc->prev_count);
56 new_raw_count = arc_pmu_read_counter(idx);
57 } while (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
58 new_raw_count) != prev_raw_count);
59
60 delta = (new_raw_count - prev_raw_count) &
61 ((1ULL << arc_pmu->counter_size) - 1ULL);
62
63 local64_add(delta, &event->count);
64 local64_sub(delta, &hwc->period_left);
65}
66
67static void arc_pmu_read(struct perf_event *event)
68{
69 arc_perf_event_update(event, &event->hw, event->hw.idx);
70}
71
72static int arc_pmu_cache_event(u64 config)
73{
74 unsigned int cache_type, cache_op, cache_result;
75 int ret;
76
77 cache_type = (config >> 0) & 0xff;
78 cache_op = (config >> 8) & 0xff;
79 cache_result = (config >> 16) & 0xff;
80 if (cache_type >= PERF_COUNT_HW_CACHE_MAX)
81 return -EINVAL;
82 if (cache_type >= PERF_COUNT_HW_CACHE_OP_MAX)
83 return -EINVAL;
84 if (cache_type >= PERF_COUNT_HW_CACHE_RESULT_MAX)
85 return -EINVAL;
86
87 ret = arc_pmu_cache_map[cache_type][cache_op][cache_result];
88
89 if (ret == CACHE_OP_UNSUPPORTED)
90 return -ENOENT;
91
92 return ret;
93}
94
95/* initializes hw_perf_event structure if event is supported */
96static int arc_pmu_event_init(struct perf_event *event)
97{
98 struct arc_pmu *arc_pmu = container_of(event->pmu, struct arc_pmu, pmu);
99 struct hw_perf_event *hwc = &event->hw;
100 int ret;
101
102 /* ARC 700 PMU does not support sampling events */
103 if (is_sampling_event(event))
104 return -ENOENT;
105
106 switch (event->attr.type) {
107 case PERF_TYPE_HARDWARE:
108 if (event->attr.config >= PERF_COUNT_HW_MAX)
109 return -ENOENT;
110 if (arc_pmu->ev_hw_idx[event->attr.config] < 0)
111 return -ENOENT;
112 hwc->config = arc_pmu->ev_hw_idx[event->attr.config];
113 pr_debug("initializing event %d with cfg %d\n",
114 (int) event->attr.config, (int) hwc->config);
115 return 0;
116 case PERF_TYPE_HW_CACHE:
117 ret = arc_pmu_cache_event(event->attr.config);
118 if (ret < 0)
119 return ret;
120 hwc->config = arc_pmu->ev_hw_idx[ret];
121 return 0;
122 default:
123 return -ENOENT;
124 }
125}
126
127/* starts all counters */
128static void arc_pmu_enable(struct pmu *pmu)
129{
130 uint32_t tmp;
131 tmp = read_aux_reg(ARC_REG_PCT_CONTROL);
132 write_aux_reg(ARC_REG_PCT_CONTROL, (tmp & 0xffff0000) | 0x1);
133}
134
135/* stops all counters */
136static void arc_pmu_disable(struct pmu *pmu)
137{
138 uint32_t tmp;
139 tmp = read_aux_reg(ARC_REG_PCT_CONTROL);
140 write_aux_reg(ARC_REG_PCT_CONTROL, (tmp & 0xffff0000) | 0x0);
141}
142
143/*
144 * Assigns hardware counter to hardware condition.
145 * Note that there is no separate start/stop mechanism;
146 * stopping is achieved by assigning the 'never' condition
147 */
148static void arc_pmu_start(struct perf_event *event, int flags)
149{
150 struct hw_perf_event *hwc = &event->hw;
151 int idx = hwc->idx;
152
153 if (WARN_ON_ONCE(idx == -1))
154 return;
155
156 if (flags & PERF_EF_RELOAD)
157 WARN_ON_ONCE(!(event->hw.state & PERF_HES_UPTODATE));
158
159 event->hw.state = 0;
160
161 /* enable ARC pmu here */
162 write_aux_reg(ARC_REG_PCT_INDEX, idx);
163 write_aux_reg(ARC_REG_PCT_CONFIG, hwc->config);
164}
165
166static void arc_pmu_stop(struct perf_event *event, int flags)
167{
168 struct hw_perf_event *hwc = &event->hw;
169 int idx = hwc->idx;
170
171 if (!(event->hw.state & PERF_HES_STOPPED)) {
172 /* stop ARC pmu here */
173 write_aux_reg(ARC_REG_PCT_INDEX, idx);
174
175 /* condition code #0 is always "never" */
176 write_aux_reg(ARC_REG_PCT_CONFIG, 0);
177
178 event->hw.state |= PERF_HES_STOPPED;
179 }
180
181 if ((flags & PERF_EF_UPDATE) &&
182 !(event->hw.state & PERF_HES_UPTODATE)) {
183 arc_perf_event_update(event, &event->hw, idx);
184 event->hw.state |= PERF_HES_UPTODATE;
185 }
186}
187
188static void arc_pmu_del(struct perf_event *event, int flags)
189{
190 struct arc_pmu *arc_pmu = container_of(event->pmu, struct arc_pmu, pmu);
191
192 arc_pmu_stop(event, PERF_EF_UPDATE);
193 __clear_bit(event->hw.idx, arc_pmu->used_mask);
194
195 perf_event_update_userpage(event);
196}
197
198/* allocate hardware counter and optionally start counting */
199static int arc_pmu_add(struct perf_event *event, int flags)
200{
201 struct arc_pmu *arc_pmu = container_of(event->pmu, struct arc_pmu, pmu);
202 struct hw_perf_event *hwc = &event->hw;
203 int idx = hwc->idx;
204
205 if (__test_and_set_bit(idx, arc_pmu->used_mask)) {
206 idx = find_first_zero_bit(arc_pmu->used_mask,
207 arc_pmu->n_counters);
208 if (idx == arc_pmu->n_counters)
209 return -EAGAIN;
210
211 __set_bit(idx, arc_pmu->used_mask);
212 hwc->idx = idx;
213 }
214
215 write_aux_reg(ARC_REG_PCT_INDEX, idx);
216 write_aux_reg(ARC_REG_PCT_CONFIG, 0);
217 write_aux_reg(ARC_REG_PCT_COUNTL, 0);
218 write_aux_reg(ARC_REG_PCT_COUNTH, 0);
219 local64_set(&hwc->prev_count, 0);
220
221 hwc->state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
222 if (flags & PERF_EF_START)
223 arc_pmu_start(event, PERF_EF_RELOAD);
224
225 perf_event_update_userpage(event);
226
227 return 0;
228}
229
230static int arc_pmu_device_probe(struct platform_device *pdev)
231{
232 struct arc_pmu *arc_pmu;
233 struct arc_reg_pct_build pct_bcr;
234 struct arc_reg_cc_build cc_bcr;
235 int i, j, ret;
236
237 union cc_name {
238 struct {
239 uint32_t word0, word1;
240 char sentinel;
241 } indiv;
242 char str[9];
243 } cc_name;
244
245
246 READ_BCR(ARC_REG_PCT_BUILD, pct_bcr);
247 if (!pct_bcr.v) {
248 pr_err("This core does not have performance counters!\n");
249 return -ENODEV;
250 }
251
252 arc_pmu = devm_kzalloc(&pdev->dev, sizeof(struct arc_pmu),
253 GFP_KERNEL);
254 if (!arc_pmu)
255 return -ENOMEM;
256
257 arc_pmu->n_counters = pct_bcr.c;
258 BUG_ON(arc_pmu->n_counters > ARC_PMU_MAX_HWEVENTS);
259
260 arc_pmu->counter_size = 32 + (pct_bcr.s << 4);
261 pr_info("ARC PMU found with %d counters of size %d bits\n",
262 arc_pmu->n_counters, arc_pmu->counter_size);
263
264 READ_BCR(ARC_REG_CC_BUILD, cc_bcr);
265
266 if (!cc_bcr.v)
267 pr_err("Strange! Performance counters exist, but no countable conditions?\n");
268
269 pr_info("ARC PMU has %d countable conditions\n", cc_bcr.c);
270
271 cc_name.str[8] = 0;
272 for (i = 0; i < PERF_COUNT_HW_MAX; i++)
273 arc_pmu->ev_hw_idx[i] = -1;
274
275 for (j = 0; j < cc_bcr.c; j++) {
276 write_aux_reg(ARC_REG_CC_INDEX, j);
277 cc_name.indiv.word0 = read_aux_reg(ARC_REG_CC_NAME0);
278 cc_name.indiv.word1 = read_aux_reg(ARC_REG_CC_NAME1);
279 for (i = 0; i < ARRAY_SIZE(arc_pmu_ev_hw_map); i++) {
280 if (arc_pmu_ev_hw_map[i] &&
281 !strcmp(arc_pmu_ev_hw_map[i], cc_name.str) &&
282 strlen(arc_pmu_ev_hw_map[i])) {
283 pr_debug("mapping %d to idx %d with name %s\n",
284 i, j, cc_name.str);
285 arc_pmu->ev_hw_idx[i] = j;
286 }
287 }
288 }
289
290 arc_pmu->pmu = (struct pmu) {
291 .pmu_enable = arc_pmu_enable,
292 .pmu_disable = arc_pmu_disable,
293 .event_init = arc_pmu_event_init,
294 .add = arc_pmu_add,
295 .del = arc_pmu_del,
296 .start = arc_pmu_start,
297 .stop = arc_pmu_stop,
298 .read = arc_pmu_read,
299 };
300
301 ret = perf_pmu_register(&arc_pmu->pmu, pdev->name, PERF_TYPE_RAW);
302
303 return ret;
304}
305
306#ifdef CONFIG_OF
307static const struct of_device_id arc_pmu_match[] = {
308 { .compatible = "snps,arc700-pmu" },
309 {},
310};
311MODULE_DEVICE_TABLE(of, arc_pmu_match);
312#endif
313
314static struct platform_driver arc_pmu_driver = {
315 .driver = {
316 .name = "arc700-pmu",
317 .of_match_table = of_match_ptr(arc_pmu_match),
318 },
319 .probe = arc_pmu_device_probe,
320};
321
322module_platform_driver(arc_pmu_driver);
323
324MODULE_LICENSE("GPL");
325MODULE_AUTHOR("Mischa Jonker <mjonker@synopsys.com>");
326MODULE_DESCRIPTION("ARC PMU driver");
diff --git a/arch/arc/plat-tb10x/Kconfig b/arch/arc/plat-tb10x/Kconfig
index 1ab386bb5da8..6994c188dc88 100644
--- a/arch/arc/plat-tb10x/Kconfig
+++ b/arch/arc/plat-tb10x/Kconfig
@@ -20,8 +20,10 @@ menuconfig ARC_PLAT_TB10X
20 bool "Abilis TB10x" 20 bool "Abilis TB10x"
21 select COMMON_CLK 21 select COMMON_CLK
22 select PINCTRL 22 select PINCTRL
23 select PINCTRL_TB10X
23 select PINMUX 24 select PINMUX
24 select ARCH_REQUIRE_GPIOLIB 25 select ARCH_REQUIRE_GPIOLIB
26 select GPIO_TB10X
25 select TB10X_IRQC 27 select TB10X_IRQC
26 help 28 help
27 Support for platforms based on the TB10x home media gateway SOC by 29 Support for platforms based on the TB10x home media gateway SOC by
diff --git a/arch/arm/boot/dts/ecx-2000.dts b/arch/arm/boot/dts/ecx-2000.dts
index 139b40cc3a23..2ccbb57fbfa8 100644
--- a/arch/arm/boot/dts/ecx-2000.dts
+++ b/arch/arm/boot/dts/ecx-2000.dts
@@ -85,6 +85,12 @@
85 <1 10 0xf08>; 85 <1 10 0xf08>;
86 }; 86 };
87 87
88 memory-controller@fff00000 {
89 compatible = "calxeda,ecx-2000-ddr-ctrl";
90 reg = <0xfff00000 0x1000>;
91 interrupts = <0 91 4>;
92 };
93
88 intc: interrupt-controller@fff11000 { 94 intc: interrupt-controller@fff11000 {
89 compatible = "arm,cortex-a15-gic"; 95 compatible = "arm,cortex-a15-gic";
90 #interrupt-cells = <3>; 96 #interrupt-cells = <3>;
diff --git a/arch/arm/boot/dts/ecx-common.dtsi b/arch/arm/boot/dts/ecx-common.dtsi
index bc22557d7a6a..b90045a8f8e3 100644
--- a/arch/arm/boot/dts/ecx-common.dtsi
+++ b/arch/arm/boot/dts/ecx-common.dtsi
@@ -53,12 +53,6 @@
53 status = "disabled"; 53 status = "disabled";
54 }; 54 };
55 55
56 memory-controller@fff00000 {
57 compatible = "calxeda,hb-ddr-ctrl";
58 reg = <0xfff00000 0x1000>;
59 interrupts = <0 91 4>;
60 };
61
62 ipc@fff20000 { 56 ipc@fff20000 {
63 compatible = "arm,pl320", "arm,primecell"; 57 compatible = "arm,pl320", "arm,primecell";
64 reg = <0xfff20000 0x1000>; 58 reg = <0xfff20000 0x1000>;
diff --git a/arch/arm/boot/dts/highbank.dts b/arch/arm/boot/dts/highbank.dts
index 6aad34ad9517..ed14aeac0566 100644
--- a/arch/arm/boot/dts/highbank.dts
+++ b/arch/arm/boot/dts/highbank.dts
@@ -86,6 +86,12 @@
86 soc { 86 soc {
87 ranges = <0x00000000 0x00000000 0xffffffff>; 87 ranges = <0x00000000 0x00000000 0xffffffff>;
88 88
89 memory-controller@fff00000 {
90 compatible = "calxeda,hb-ddr-ctrl";
91 reg = <0xfff00000 0x1000>;
92 interrupts = <0 91 4>;
93 };
94
89 timer@fff10600 { 95 timer@fff10600 {
90 compatible = "arm,cortex-a9-twd-timer"; 96 compatible = "arm,cortex-a9-twd-timer";
91 reg = <0xfff10600 0x20>; 97 reg = <0xfff10600 0x20>;
diff --git a/arch/arm/boot/dts/twl4030.dtsi b/arch/arm/boot/dts/twl4030.dtsi
index fb1b2ec8eaa9..4217096ee677 100644
--- a/arch/arm/boot/dts/twl4030.dtsi
+++ b/arch/arm/boot/dts/twl4030.dtsi
@@ -19,6 +19,12 @@
19 interrupts = <11>; 19 interrupts = <11>;
20 }; 20 };
21 21
22 charger: bci {
23 compatible = "ti,twl4030-bci";
24 interrupts = <9>, <2>;
25 bci3v1-supply = <&vusb3v1>;
26 };
27
22 watchdog { 28 watchdog {
23 compatible = "ti,twl4030-wdt"; 29 compatible = "ti,twl4030-wdt";
24 }; 30 };
diff --git a/arch/arm/configs/prima2_defconfig b/arch/arm/configs/prima2_defconfig
index 002a1ceadceb..23591dba47a0 100644
--- a/arch/arm/configs/prima2_defconfig
+++ b/arch/arm/configs/prima2_defconfig
@@ -39,6 +39,7 @@ CONFIG_SPI=y
39CONFIG_SPI_SIRF=y 39CONFIG_SPI_SIRF=y
40CONFIG_SPI_SPIDEV=y 40CONFIG_SPI_SPIDEV=y
41# CONFIG_HWMON is not set 41# CONFIG_HWMON is not set
42CONFIG_WATCHDOG=y
42CONFIG_USB_GADGET=y 43CONFIG_USB_GADGET=y
43CONFIG_USB_MASS_STORAGE=m 44CONFIG_USB_MASS_STORAGE=m
44CONFIG_MMC=y 45CONFIG_MMC=y
diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
index df5e13d64f2c..71a06b293489 100644
--- a/arch/arm/include/asm/thread_info.h
+++ b/arch/arm/include/asm/thread_info.h
@@ -141,12 +141,6 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
141#endif 141#endif
142 142
143/* 143/*
144 * We use bit 30 of the preempt_count to indicate that kernel
145 * preemption is occurring. See <asm/hardirq.h>.
146 */
147#define PREEMPT_ACTIVE 0x40000000
148
149/*
150 * thread information flags: 144 * thread information flags:
151 * TIF_SYSCALL_TRACE - syscall trace active 145 * TIF_SYSCALL_TRACE - syscall trace active
152 * TIF_SYSCAL_AUDIT - syscall auditing active 146 * TIF_SYSCAL_AUDIT - syscall auditing active
diff --git a/arch/arm/mach-at91/board-sam9260ek.c b/arch/arm/mach-at91/board-sam9260ek.c
index 0b153c87521d..f4f8735315da 100644
--- a/arch/arm/mach-at91/board-sam9260ek.c
+++ b/arch/arm/mach-at91/board-sam9260ek.c
@@ -28,7 +28,7 @@
28#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
29#include <linux/spi/at73c213.h> 29#include <linux/spi/at73c213.h>
30#include <linux/clk.h> 30#include <linux/clk.h>
31#include <linux/i2c/at24.h> 31#include <linux/platform_data/at24.h>
32#include <linux/gpio_keys.h> 32#include <linux/gpio_keys.h>
33#include <linux/input.h> 33#include <linux/input.h>
34 34
diff --git a/arch/arm/mach-at91/board-sam9263ek.c b/arch/arm/mach-at91/board-sam9263ek.c
index 8b4942cbb6d9..2f931915c80c 100644
--- a/arch/arm/mach-at91/board-sam9263ek.c
+++ b/arch/arm/mach-at91/board-sam9263ek.c
@@ -27,7 +27,7 @@
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
29#include <linux/spi/ads7846.h> 29#include <linux/spi/ads7846.h>
30#include <linux/i2c/at24.h> 30#include <linux/platform_data/at24.h>
31#include <linux/fb.h> 31#include <linux/fb.h>
32#include <linux/gpio_keys.h> 32#include <linux/gpio_keys.h>
33#include <linux/input.h> 33#include <linux/input.h>
diff --git a/arch/arm/mach-davinci/board-da830-evm.c b/arch/arm/mach-davinci/board-da830-evm.c
index 40f15f133c55..d1f45af7a530 100644
--- a/arch/arm/mach-davinci/board-da830-evm.c
+++ b/arch/arm/mach-davinci/board-da830-evm.c
@@ -17,7 +17,7 @@
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/i2c/pcf857x.h> 19#include <linux/i2c/pcf857x.h>
20#include <linux/i2c/at24.h> 20#include <linux/platform_data/at24.h>
21#include <linux/mtd/mtd.h> 21#include <linux/mtd/mtd.h>
22#include <linux/mtd/partitions.h> 22#include <linux/mtd/partitions.h>
23#include <linux/spi/spi.h> 23#include <linux/spi/spi.h>
diff --git a/arch/arm/mach-davinci/board-da850-evm.c b/arch/arm/mach-davinci/board-da850-evm.c
index df16cb88a26b..e0af0eccde8f 100644
--- a/arch/arm/mach-davinci/board-da850-evm.c
+++ b/arch/arm/mach-davinci/board-da850-evm.c
@@ -18,7 +18,7 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/i2c/at24.h> 21#include <linux/platform_data/at24.h>
22#include <linux/platform_data/pca953x.h> 22#include <linux/platform_data/pca953x.h>
23#include <linux/input.h> 23#include <linux/input.h>
24#include <linux/input/tps6507x-ts.h> 24#include <linux/input/tps6507x-ts.h>
diff --git a/arch/arm/mach-davinci/board-dm365-evm.c b/arch/arm/mach-davinci/board-dm365-evm.c
index f4a6c18912ea..e08a8684ead2 100644
--- a/arch/arm/mach-davinci/board-dm365-evm.c
+++ b/arch/arm/mach-davinci/board-dm365-evm.c
@@ -18,7 +18,7 @@
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/io.h> 19#include <linux/io.h>
20#include <linux/clk.h> 20#include <linux/clk.h>
21#include <linux/i2c/at24.h> 21#include <linux/platform_data/at24.h>
22#include <linux/leds.h> 22#include <linux/leds.h>
23#include <linux/mtd/mtd.h> 23#include <linux/mtd/mtd.h>
24#include <linux/mtd/partitions.h> 24#include <linux/mtd/partitions.h>
diff --git a/arch/arm/mach-davinci/board-dm644x-evm.c b/arch/arm/mach-davinci/board-dm644x-evm.c
index 9cc32c283b8b..987605b78556 100644
--- a/arch/arm/mach-davinci/board-dm644x-evm.c
+++ b/arch/arm/mach-davinci/board-dm644x-evm.c
@@ -15,7 +15,7 @@
15#include <linux/gpio.h> 15#include <linux/gpio.h>
16#include <linux/i2c.h> 16#include <linux/i2c.h>
17#include <linux/i2c/pcf857x.h> 17#include <linux/i2c/pcf857x.h>
18#include <linux/i2c/at24.h> 18#include <linux/platform_data/at24.h>
19#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
20#include <linux/mtd/nand.h> 20#include <linux/mtd/nand.h>
21#include <linux/mtd/partitions.h> 21#include <linux/mtd/partitions.h>
diff --git a/arch/arm/mach-davinci/board-dm646x-evm.c b/arch/arm/mach-davinci/board-dm646x-evm.c
index 44b20191a9fe..13d0801fd6b1 100644
--- a/arch/arm/mach-davinci/board-dm646x-evm.c
+++ b/arch/arm/mach-davinci/board-dm646x-evm.c
@@ -22,7 +22,7 @@
22#include <linux/gpio.h> 22#include <linux/gpio.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/i2c/at24.h> 25#include <linux/platform_data/at24.h>
26#include <linux/i2c/pcf857x.h> 26#include <linux/i2c/pcf857x.h>
27 27
28#include <media/tvp514x.h> 28#include <media/tvp514x.h>
diff --git a/arch/arm/mach-davinci/board-mityomapl138.c b/arch/arm/mach-davinci/board-mityomapl138.c
index cd0f58730c2b..7aa105b1fd0f 100644
--- a/arch/arm/mach-davinci/board-mityomapl138.c
+++ b/arch/arm/mach-davinci/board-mityomapl138.c
@@ -15,7 +15,7 @@
15#include <linux/mtd/partitions.h> 15#include <linux/mtd/partitions.h>
16#include <linux/regulator/machine.h> 16#include <linux/regulator/machine.h>
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/i2c/at24.h> 18#include <linux/platform_data/at24.h>
19#include <linux/etherdevice.h> 19#include <linux/etherdevice.h>
20#include <linux/spi/spi.h> 20#include <linux/spi/spi.h>
21#include <linux/spi/flash.h> 21#include <linux/spi/flash.h>
diff --git a/arch/arm/mach-davinci/board-sffsdr.c b/arch/arm/mach-davinci/board-sffsdr.c
index d84360148100..41c7c9615791 100644
--- a/arch/arm/mach-davinci/board-sffsdr.c
+++ b/arch/arm/mach-davinci/board-sffsdr.c
@@ -26,7 +26,7 @@
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/i2c/at24.h> 29#include <linux/platform_data/at24.h>
30#include <linux/mtd/mtd.h> 30#include <linux/mtd/mtd.h>
31#include <linux/mtd/nand.h> 31#include <linux/mtd/nand.h>
32#include <linux/mtd/partitions.h> 32#include <linux/mtd/partitions.h>
diff --git a/arch/arm/mach-imx/mach-pca100.c b/arch/arm/mach-imx/mach-pca100.c
index 19bb6441a7d4..c5f95674e9b7 100644
--- a/arch/arm/mach-imx/mach-pca100.c
+++ b/arch/arm/mach-imx/mach-pca100.c
@@ -20,7 +20,7 @@
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/io.h> 21#include <linux/io.h>
22#include <linux/i2c.h> 22#include <linux/i2c.h>
23#include <linux/i2c/at24.h> 23#include <linux/platform_data/at24.h>
24#include <linux/dma-mapping.h> 24#include <linux/dma-mapping.h>
25#include <linux/spi/spi.h> 25#include <linux/spi/spi.h>
26#include <linux/spi/eeprom.h> 26#include <linux/spi/eeprom.h>
diff --git a/arch/arm/mach-imx/mach-pcm037.c b/arch/arm/mach-imx/mach-pcm037.c
index 45303bd62902..639a3dfb0092 100644
--- a/arch/arm/mach-imx/mach-pcm037.c
+++ b/arch/arm/mach-imx/mach-pcm037.c
@@ -23,7 +23,7 @@
23#include <linux/smsc911x.h> 23#include <linux/smsc911x.h>
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/i2c/at24.h> 26#include <linux/platform_data/at24.h>
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
29#include <linux/irq.h> 29#include <linux/irq.h>
diff --git a/arch/arm/mach-imx/mach-pcm038.c b/arch/arm/mach-imx/mach-pcm038.c
index e805ac273e9c..592ddbe031ac 100644
--- a/arch/arm/mach-imx/mach-pcm038.c
+++ b/arch/arm/mach-imx/mach-pcm038.c
@@ -18,7 +18,7 @@
18 */ 18 */
19 19
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/i2c/at24.h> 21#include <linux/platform_data/at24.h>
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/mtd/plat-ram.h> 23#include <linux/mtd/plat-ram.h>
24#include <linux/mtd/physmap.h> 24#include <linux/mtd/physmap.h>
diff --git a/arch/arm/mach-imx/mach-pcm043.c b/arch/arm/mach-imx/mach-pcm043.c
index b726cb1c5fdd..ac504b67326b 100644
--- a/arch/arm/mach-imx/mach-pcm043.c
+++ b/arch/arm/mach-imx/mach-pcm043.c
@@ -24,7 +24,7 @@
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/i2c/at24.h> 27#include <linux/platform_data/at24.h>
28#include <linux/usb/otg.h> 28#include <linux/usb/otg.h>
29#include <linux/usb/ulpi.h> 29#include <linux/usb/ulpi.h>
30 30
diff --git a/arch/arm/mach-imx/mach-vpr200.c b/arch/arm/mach-imx/mach-vpr200.c
index 0910761e8280..8825d1217d18 100644
--- a/arch/arm/mach-imx/mach-vpr200.c
+++ b/arch/arm/mach-imx/mach-vpr200.c
@@ -29,7 +29,7 @@
29#include <asm/mach/time.h> 29#include <asm/mach/time.h>
30 30
31#include <linux/i2c.h> 31#include <linux/i2c.h>
32#include <linux/i2c/at24.h> 32#include <linux/platform_data/at24.h>
33#include <linux/mfd/mc13xxx.h> 33#include <linux/mfd/mc13xxx.h>
34 34
35#include "common.h" 35#include "common.h"
diff --git a/arch/arm/mach-kirkwood/lacie_v2-common.c b/arch/arm/mach-kirkwood/lacie_v2-common.c
index 489495976fcd..8e3e4331c380 100644
--- a/arch/arm/mach-kirkwood/lacie_v2-common.c
+++ b/arch/arm/mach-kirkwood/lacie_v2-common.c
@@ -12,7 +12,7 @@
12#include <linux/spi/flash.h> 12#include <linux/spi/flash.h>
13#include <linux/spi/spi.h> 13#include <linux/spi/spi.h>
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/i2c/at24.h> 15#include <linux/platform_data/at24.h>
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <asm/mach/time.h> 17#include <asm/mach/time.h>
18#include <mach/kirkwood.h> 18#include <mach/kirkwood.h>
diff --git a/arch/arm/mach-omap1/board-osk.c b/arch/arm/mach-omap1/board-osk.c
index a7ce69286688..d68909b095f1 100644
--- a/arch/arm/mach-omap1/board-osk.c
+++ b/arch/arm/mach-omap1/board-osk.c
@@ -300,7 +300,7 @@ static struct omap_lcd_config osk_lcd_config __initdata = {
300#ifdef CONFIG_OMAP_OSK_MISTRAL 300#ifdef CONFIG_OMAP_OSK_MISTRAL
301 301
302#include <linux/input.h> 302#include <linux/input.h>
303#include <linux/i2c/at24.h> 303#include <linux/platform_data/at24.h>
304#include <linux/spi/spi.h> 304#include <linux/spi/spi.h>
305#include <linux/spi/ads7846.h> 305#include <linux/spi/ads7846.h>
306 306
diff --git a/arch/arm/mach-omap2/board-cm-t35.c b/arch/arm/mach-omap2/board-cm-t35.c
index 33d159e2386e..8dd0ec858cf1 100644
--- a/arch/arm/mach-omap2/board-cm-t35.c
+++ b/arch/arm/mach-omap2/board-cm-t35.c
@@ -25,7 +25,7 @@
25#include <linux/gpio.h> 25#include <linux/gpio.h>
26#include <linux/platform_data/gpio-omap.h> 26#include <linux/platform_data/gpio-omap.h>
27 27
28#include <linux/i2c/at24.h> 28#include <linux/platform_data/at24.h>
29#include <linux/i2c/twl.h> 29#include <linux/i2c/twl.h>
30#include <linux/regulator/fixed.h> 30#include <linux/regulator/fixed.h>
31#include <linux/regulator/machine.h> 31#include <linux/regulator/machine.h>
diff --git a/arch/arm/mach-omap2/board-h4.c b/arch/arm/mach-omap2/board-h4.c
index 87e41a8b8d46..f7808349a734 100644
--- a/arch/arm/mach-omap2/board-h4.c
+++ b/arch/arm/mach-omap2/board-h4.c
@@ -20,7 +20,7 @@
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/workqueue.h> 21#include <linux/workqueue.h>
22#include <linux/i2c.h> 22#include <linux/i2c.h>
23#include <linux/i2c/at24.h> 23#include <linux/platform_data/at24.h>
24#include <linux/input.h> 24#include <linux/input.h>
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/clk.h> 26#include <linux/clk.h>
diff --git a/arch/arm/mach-omap2/board-omap3stalker.c b/arch/arm/mach-omap2/board-omap3stalker.c
index ba8342fef799..119efaf5808a 100644
--- a/arch/arm/mach-omap2/board-omap3stalker.c
+++ b/arch/arm/mach-omap2/board-omap3stalker.c
@@ -32,7 +32,7 @@
32#include <linux/spi/spi.h> 32#include <linux/spi/spi.h>
33#include <linux/interrupt.h> 33#include <linux/interrupt.h>
34#include <linux/smsc911x.h> 34#include <linux/smsc911x.h>
35#include <linux/i2c/at24.h> 35#include <linux/platform_data/at24.h>
36#include <linux/usb/phy.h> 36#include <linux/usb/phy.h>
37 37
38#include <asm/mach-types.h> 38#include <asm/mach-types.h>
diff --git a/arch/arm/mach-pxa/stargate2.c b/arch/arm/mach-pxa/stargate2.c
index 62aea3e835f3..01de542432a6 100644
--- a/arch/arm/mach-pxa/stargate2.c
+++ b/arch/arm/mach-pxa/stargate2.c
@@ -27,7 +27,7 @@
27 27
28#include <linux/i2c/pxa-i2c.h> 28#include <linux/i2c/pxa-i2c.h>
29#include <linux/i2c/pcf857x.h> 29#include <linux/i2c/pcf857x.h>
30#include <linux/i2c/at24.h> 30#include <linux/platform_data/at24.h>
31#include <linux/smc91x.h> 31#include <linux/smc91x.h>
32#include <linux/gpio.h> 32#include <linux/gpio.h>
33#include <linux/leds.h> 33#include <linux/leds.h>
diff --git a/arch/arm/mach-s3c24xx/mach-mini2440.c b/arch/arm/mach-s3c24xx/mach-mini2440.c
index a83db46320bc..4a18d49a63e0 100644
--- a/arch/arm/mach-s3c24xx/mach-mini2440.c
+++ b/arch/arm/mach-s3c24xx/mach-mini2440.c
@@ -24,7 +24,7 @@
24#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/serial_core.h> 25#include <linux/serial_core.h>
26#include <linux/dm9000.h> 26#include <linux/dm9000.h>
27#include <linux/i2c/at24.h> 27#include <linux/platform_data/at24.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/gpio_keys.h> 29#include <linux/gpio_keys.h>
30#include <linux/i2c.h> 30#include <linux/i2c.h>
diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h
index 23a3c4791d86..720e70b66ffd 100644
--- a/arch/arm64/include/asm/thread_info.h
+++ b/arch/arm64/include/asm/thread_info.h
@@ -89,12 +89,6 @@ static inline struct thread_info *current_thread_info(void)
89#endif 89#endif
90 90
91/* 91/*
92 * We use bit 30 of the preempt_count to indicate that kernel
93 * preemption is occurring. See <asm/hardirq.h>.
94 */
95#define PREEMPT_ACTIVE 0x40000000
96
97/*
98 * thread information flags: 92 * thread information flags:
99 * TIF_SYSCALL_TRACE - syscall trace active 93 * TIF_SYSCALL_TRACE - syscall trace active
100 * TIF_SIGPENDING - signal pending 94 * TIF_SIGPENDING - signal pending
diff --git a/arch/avr32/include/asm/thread_info.h b/arch/avr32/include/asm/thread_info.h
index 6dc62e1f94c7..a978f3fe7c25 100644
--- a/arch/avr32/include/asm/thread_info.h
+++ b/arch/avr32/include/asm/thread_info.h
@@ -66,8 +66,6 @@ static inline struct thread_info *current_thread_info(void)
66 66
67#endif /* !__ASSEMBLY__ */ 67#endif /* !__ASSEMBLY__ */
68 68
69#define PREEMPT_ACTIVE 0x40000000
70
71/* 69/*
72 * Thread information flags 70 * Thread information flags
73 * - these are process state flags that various assembly files may need to access 71 * - these are process state flags that various assembly files may need to access
diff --git a/arch/blackfin/include/asm/hardirq.h b/arch/blackfin/include/asm/hardirq.h
index c078dd78d998..58b54a6d5a16 100644
--- a/arch/blackfin/include/asm/hardirq.h
+++ b/arch/blackfin/include/asm/hardirq.h
@@ -12,9 +12,6 @@
12extern void ack_bad_irq(unsigned int irq); 12extern void ack_bad_irq(unsigned int irq);
13#define ack_bad_irq ack_bad_irq 13#define ack_bad_irq ack_bad_irq
14 14
15/* Define until common code gets sane defaults */
16#define HARDIRQ_BITS 9
17
18#include <asm-generic/hardirq.h> 15#include <asm-generic/hardirq.h>
19 16
20#endif 17#endif
diff --git a/arch/blackfin/include/asm/thread_info.h b/arch/blackfin/include/asm/thread_info.h
index 3894005337ba..55f473bdad36 100644
--- a/arch/blackfin/include/asm/thread_info.h
+++ b/arch/blackfin/include/asm/thread_info.h
@@ -88,8 +88,6 @@ static inline struct thread_info *current_thread_info(void)
88#define TI_CPU 12 88#define TI_CPU 12
89#define TI_PREEMPT 16 89#define TI_PREEMPT 16
90 90
91#define PREEMPT_ACTIVE 0x4000000
92
93/* 91/*
94 * thread information flag bit numbers 92 * thread information flag bit numbers
95 */ 93 */
diff --git a/arch/c6x/include/asm/thread_info.h b/arch/c6x/include/asm/thread_info.h
index 4c8dc562bd90..d4e9ef87076d 100644
--- a/arch/c6x/include/asm/thread_info.h
+++ b/arch/c6x/include/asm/thread_info.h
@@ -84,8 +84,6 @@ struct thread_info *current_thread_info(void)
84#define put_thread_info(ti) put_task_struct((ti)->task) 84#define put_thread_info(ti) put_task_struct((ti)->task)
85#endif /* __ASSEMBLY__ */ 85#endif /* __ASSEMBLY__ */
86 86
87#define PREEMPT_ACTIVE 0x10000000
88
89/* 87/*
90 * thread information flag bit numbers 88 * thread information flag bit numbers
91 * - pending work-to-be-done flags are in LSW 89 * - pending work-to-be-done flags are in LSW
diff --git a/arch/cris/include/asm/hardirq.h b/arch/cris/include/asm/hardirq.h
index 17bb12d760b2..04126f7bfab2 100644
--- a/arch/cris/include/asm/hardirq.h
+++ b/arch/cris/include/asm/hardirq.h
@@ -2,18 +2,6 @@
2#define __ASM_HARDIRQ_H 2#define __ASM_HARDIRQ_H
3 3
4#include <asm/irq.h> 4#include <asm/irq.h>
5
6#define HARDIRQ_BITS 8
7
8/*
9 * The hardirq mask has to be large enough to have
10 * space for potentially all IRQ sources in the system
11 * nesting on a single CPU:
12 */
13#if (1 << HARDIRQ_BITS) < NR_IRQS
14# error HARDIRQ_BITS is too low!
15#endif
16
17#include <asm-generic/hardirq.h> 5#include <asm-generic/hardirq.h>
18 6
19#endif /* __ASM_HARDIRQ_H */ 7#endif /* __ASM_HARDIRQ_H */
diff --git a/arch/cris/include/asm/thread_info.h b/arch/cris/include/asm/thread_info.h
index 07c8c40c52b3..55dede18c032 100644
--- a/arch/cris/include/asm/thread_info.h
+++ b/arch/cris/include/asm/thread_info.h
@@ -44,8 +44,6 @@ struct thread_info {
44 44
45#endif 45#endif
46 46
47#define PREEMPT_ACTIVE 0x10000000
48
49/* 47/*
50 * macros/functions for gaining access to the thread information structure 48 * macros/functions for gaining access to the thread information structure
51 */ 49 */
diff --git a/arch/frv/include/asm/thread_info.h b/arch/frv/include/asm/thread_info.h
index bebd7eadc772..af29e17c0181 100644
--- a/arch/frv/include/asm/thread_info.h
+++ b/arch/frv/include/asm/thread_info.h
@@ -52,8 +52,6 @@ struct thread_info {
52 52
53#endif 53#endif
54 54
55#define PREEMPT_ACTIVE 0x10000000
56
57/* 55/*
58 * macros/functions for gaining access to the thread information structure 56 * macros/functions for gaining access to the thread information structure
59 */ 57 */
diff --git a/arch/hexagon/include/asm/thread_info.h b/arch/hexagon/include/asm/thread_info.h
index f7c32406a711..a59dad3b3695 100644
--- a/arch/hexagon/include/asm/thread_info.h
+++ b/arch/hexagon/include/asm/thread_info.h
@@ -73,10 +73,6 @@ struct thread_info {
73 73
74#endif /* __ASSEMBLY__ */ 74#endif /* __ASSEMBLY__ */
75 75
76/* looks like "linux/hardirq.h" uses this. */
77
78#define PREEMPT_ACTIVE 0x10000000
79
80#ifndef __ASSEMBLY__ 76#ifndef __ASSEMBLY__
81 77
82#define INIT_THREAD_INFO(tsk) \ 78#define INIT_THREAD_INFO(tsk) \
diff --git a/arch/ia64/include/asm/thread_info.h b/arch/ia64/include/asm/thread_info.h
index cade13dd0299..5957cf61f898 100644
--- a/arch/ia64/include/asm/thread_info.h
+++ b/arch/ia64/include/asm/thread_info.h
@@ -11,9 +11,6 @@
11#include <asm/processor.h> 11#include <asm/processor.h>
12#include <asm/ptrace.h> 12#include <asm/ptrace.h>
13 13
14#define PREEMPT_ACTIVE_BIT 30
15#define PREEMPT_ACTIVE (1 << PREEMPT_ACTIVE_BIT)
16
17#ifndef __ASSEMBLY__ 14#ifndef __ASSEMBLY__
18 15
19/* 16/*
diff --git a/arch/ia64/kernel/entry.S b/arch/ia64/kernel/entry.S
index 7a53530f22c2..ddea607f948a 100644
--- a/arch/ia64/kernel/entry.S
+++ b/arch/ia64/kernel/entry.S
@@ -1169,21 +1169,8 @@ skip_rbs_switch:
1169.work_pending: 1169.work_pending:
1170 tbit.z p6,p0=r31,TIF_NEED_RESCHED // is resched not needed? 1170 tbit.z p6,p0=r31,TIF_NEED_RESCHED // is resched not needed?
1171(p6) br.cond.sptk.few .notify 1171(p6) br.cond.sptk.few .notify
1172#ifdef CONFIG_PREEMPT 1172 br.call.spnt.many rp=preempt_schedule_irq
1173(pKStk) dep r21=-1,r0,PREEMPT_ACTIVE_BIT,1
1174 ;;
1175(pKStk) st4 [r20]=r21
1176#endif
1177 SSM_PSR_I(p0, p6, r2) // enable interrupts
1178 br.call.spnt.many rp=schedule
1179.ret9: cmp.eq p6,p0=r0,r0 // p6 <- 1 (re-check) 1173.ret9: cmp.eq p6,p0=r0,r0 // p6 <- 1 (re-check)
1180 RSM_PSR_I(p0, r2, r20) // disable interrupts
1181 ;;
1182#ifdef CONFIG_PREEMPT
1183(pKStk) adds r20=TI_PRE_COUNT+IA64_TASK_SIZE,r13
1184 ;;
1185(pKStk) st4 [r20]=r0 // preempt_count() <- 0
1186#endif
1187(pLvSys)br.cond.sptk.few __paravirt_pending_syscall_end 1174(pLvSys)br.cond.sptk.few __paravirt_pending_syscall_end
1188 br.cond.sptk.many .work_processed_kernel 1175 br.cond.sptk.many .work_processed_kernel
1189 1176
diff --git a/arch/m32r/include/asm/hardirq.h b/arch/m32r/include/asm/hardirq.h
index 4c31c0ae215e..5f2ac4f64ddf 100644
--- a/arch/m32r/include/asm/hardirq.h
+++ b/arch/m32r/include/asm/hardirq.h
@@ -3,22 +3,6 @@
3#define __ASM_HARDIRQ_H 3#define __ASM_HARDIRQ_H
4 4
5#include <asm/irq.h> 5#include <asm/irq.h>
6
7#if NR_IRQS > 256
8#define HARDIRQ_BITS 9
9#else
10#define HARDIRQ_BITS 8
11#endif
12
13/*
14 * The hardirq mask has to be large enough to have
15 * space for potentially all IRQ sources in the system
16 * nesting on a single CPU:
17 */
18#if (1 << HARDIRQ_BITS) < NR_IRQS
19# error HARDIRQ_BITS is too low!
20#endif
21
22#include <asm-generic/hardirq.h> 6#include <asm-generic/hardirq.h>
23 7
24#endif /* __ASM_HARDIRQ_H */ 8#endif /* __ASM_HARDIRQ_H */
diff --git a/arch/m32r/include/asm/thread_info.h b/arch/m32r/include/asm/thread_info.h
index c074f4c2e858..00171703402f 100644
--- a/arch/m32r/include/asm/thread_info.h
+++ b/arch/m32r/include/asm/thread_info.h
@@ -53,8 +53,6 @@ struct thread_info {
53 53
54#endif 54#endif
55 55
56#define PREEMPT_ACTIVE 0x10000000
57
58#define THREAD_SIZE (PAGE_SIZE << 1) 56#define THREAD_SIZE (PAGE_SIZE << 1)
59#define THREAD_SIZE_ORDER 1 57#define THREAD_SIZE_ORDER 1
60/* 58/*
diff --git a/arch/m32r/kernel/entry.S b/arch/m32r/kernel/entry.S
index 0c01543f10cd..7c3db9940ce1 100644
--- a/arch/m32r/kernel/entry.S
+++ b/arch/m32r/kernel/entry.S
@@ -182,13 +182,7 @@ need_resched:
182 ld r4, PSW(sp) ; interrupts off (exception path) ? 182 ld r4, PSW(sp) ; interrupts off (exception path) ?
183 and3 r4, r4, #0x4000 183 and3 r4, r4, #0x4000
184 beqz r4, restore_all 184 beqz r4, restore_all
185 LDIMM (r4, PREEMPT_ACTIVE) 185 bl preempt_schedule_irq
186 st r4, @(TI_PRE_COUNT, r8)
187 ENABLE_INTERRUPTS(r4)
188 bl schedule
189 ldi r4, #0
190 st r4, @(TI_PRE_COUNT, r8)
191 DISABLE_INTERRUPTS(r4)
192 bra need_resched 186 bra need_resched
193#endif 187#endif
194 188
diff --git a/arch/m68k/include/asm/hardirq.h b/arch/m68k/include/asm/hardirq.h
index db30ed276878..6c618529d9b9 100644
--- a/arch/m68k/include/asm/hardirq.h
+++ b/arch/m68k/include/asm/hardirq.h
@@ -5,17 +5,6 @@
5#include <linux/cache.h> 5#include <linux/cache.h>
6#include <asm/irq.h> 6#include <asm/irq.h>
7 7
8#define HARDIRQ_BITS 8
9
10/*
11 * The hardirq mask has to be large enough to have
12 * space for potentially all IRQ sources in the system
13 * nesting on a single CPU:
14 */
15#if (1 << HARDIRQ_BITS) < NR_IRQS
16# error HARDIRQ_BITS is too low!
17#endif
18
19#ifdef CONFIG_MMU 8#ifdef CONFIG_MMU
20 9
21static inline void ack_bad_irq(unsigned int irq) 10static inline void ack_bad_irq(unsigned int irq)
diff --git a/arch/m68k/include/asm/thread_info.h b/arch/m68k/include/asm/thread_info.h
index 126131f94a2c..21a4784ca5a1 100644
--- a/arch/m68k/include/asm/thread_info.h
+++ b/arch/m68k/include/asm/thread_info.h
@@ -35,8 +35,6 @@ struct thread_info {
35}; 35};
36#endif /* __ASSEMBLY__ */ 36#endif /* __ASSEMBLY__ */
37 37
38#define PREEMPT_ACTIVE 0x4000000
39
40#define INIT_THREAD_INFO(tsk) \ 38#define INIT_THREAD_INFO(tsk) \
41{ \ 39{ \
42 .task = &tsk, \ 40 .task = &tsk, \
diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S
index a78f5649e8de..b54ac7aba850 100644
--- a/arch/m68k/kernel/entry.S
+++ b/arch/m68k/kernel/entry.S
@@ -45,7 +45,7 @@
45.globl system_call, buserr, trap, resume 45.globl system_call, buserr, trap, resume
46.globl sys_call_table 46.globl sys_call_table
47.globl __sys_fork, __sys_clone, __sys_vfork 47.globl __sys_fork, __sys_clone, __sys_vfork
48.globl ret_from_interrupt, bad_interrupt 48.globl bad_interrupt
49.globl auto_irqhandler_fixup 49.globl auto_irqhandler_fixup
50.globl user_irqvec_fixup 50.globl user_irqvec_fixup
51 51
@@ -275,8 +275,6 @@ do_delayed_trace:
275ENTRY(auto_inthandler) 275ENTRY(auto_inthandler)
276 SAVE_ALL_INT 276 SAVE_ALL_INT
277 GET_CURRENT(%d0) 277 GET_CURRENT(%d0)
278 movel %d0,%a1
279 addqb #1,%a1@(TINFO_PREEMPT+1)
280 | put exception # in d0 278 | put exception # in d0
281 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0 279 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
282 subw #VEC_SPUR,%d0 280 subw #VEC_SPUR,%d0
@@ -286,32 +284,13 @@ ENTRY(auto_inthandler)
286auto_irqhandler_fixup = . + 2 284auto_irqhandler_fixup = . + 2
287 jsr do_IRQ | process the IRQ 285 jsr do_IRQ | process the IRQ
288 addql #8,%sp | pop parameters off stack 286 addql #8,%sp | pop parameters off stack
289 287 jra ret_from_exception
290ret_from_interrupt:
291 movel %curptr@(TASK_STACK),%a1
292 subqb #1,%a1@(TINFO_PREEMPT+1)
293 jeq ret_from_last_interrupt
2942: RESTORE_ALL
295
296 ALIGN
297ret_from_last_interrupt:
298 moveq #(~ALLOWINT>>8)&0xff,%d0
299 andb %sp@(PT_OFF_SR),%d0
300 jne 2b
301
302 /* check if we need to do software interrupts */
303 tstl irq_stat+CPUSTAT_SOFTIRQ_PENDING
304 jeq .Lret_from_exception
305 pea ret_from_exception
306 jra do_softirq
307 288
308/* Handler for user defined interrupt vectors */ 289/* Handler for user defined interrupt vectors */
309 290
310ENTRY(user_inthandler) 291ENTRY(user_inthandler)
311 SAVE_ALL_INT 292 SAVE_ALL_INT
312 GET_CURRENT(%d0) 293 GET_CURRENT(%d0)
313 movel %d0,%a1
314 addqb #1,%a1@(TINFO_PREEMPT+1)
315 | put exception # in d0 294 | put exception # in d0
316 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0 295 bfextu %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
317user_irqvec_fixup = . + 2 296user_irqvec_fixup = . + 2
@@ -321,29 +300,18 @@ user_irqvec_fixup = . + 2
321 movel %d0,%sp@- | put vector # on stack 300 movel %d0,%sp@- | put vector # on stack
322 jsr do_IRQ | process the IRQ 301 jsr do_IRQ | process the IRQ
323 addql #8,%sp | pop parameters off stack 302 addql #8,%sp | pop parameters off stack
324 303 jra ret_from_exception
325 movel %curptr@(TASK_STACK),%a1
326 subqb #1,%a1@(TINFO_PREEMPT+1)
327 jeq ret_from_last_interrupt
328 RESTORE_ALL
329 304
330/* Handler for uninitialized and spurious interrupts */ 305/* Handler for uninitialized and spurious interrupts */
331 306
332ENTRY(bad_inthandler) 307ENTRY(bad_inthandler)
333 SAVE_ALL_INT 308 SAVE_ALL_INT
334 GET_CURRENT(%d0) 309 GET_CURRENT(%d0)
335 movel %d0,%a1
336 addqb #1,%a1@(TINFO_PREEMPT+1)
337 310
338 movel %sp,%sp@- 311 movel %sp,%sp@-
339 jsr handle_badint 312 jsr handle_badint
340 addql #4,%sp 313 addql #4,%sp
341 314 jra ret_from_exception
342 movel %curptr@(TASK_STACK),%a1
343 subqb #1,%a1@(TINFO_PREEMPT+1)
344 jeq ret_from_last_interrupt
345 RESTORE_ALL
346
347 315
348resume: 316resume:
349 /* 317 /*
diff --git a/arch/m68k/kernel/ints.c b/arch/m68k/kernel/ints.c
index 4d7da384eea0..077d3a70fed1 100644
--- a/arch/m68k/kernel/ints.c
+++ b/arch/m68k/kernel/ints.c
@@ -58,12 +58,6 @@ void __init init_IRQ(void)
58{ 58{
59 int i; 59 int i;
60 60
61 /* assembly irq entry code relies on this... */
62 if (HARDIRQ_MASK != 0x00ff0000) {
63 extern void hardirq_mask_is_broken(void);
64 hardirq_mask_is_broken();
65 }
66
67 for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++) 61 for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
68 irq_set_chip_and_handler(i, &auto_irq_chip, handle_simple_irq); 62 irq_set_chip_and_handler(i, &auto_irq_chip, handle_simple_irq);
69 63
diff --git a/arch/m68k/platform/68000/entry.S b/arch/m68k/platform/68000/entry.S
index 7f91c2fde509..23ac054c6e1a 100644
--- a/arch/m68k/platform/68000/entry.S
+++ b/arch/m68k/platform/68000/entry.S
@@ -27,7 +27,6 @@
27.globl ret_from_exception 27.globl ret_from_exception
28.globl ret_from_signal 28.globl ret_from_signal
29.globl sys_call_table 29.globl sys_call_table
30.globl ret_from_interrupt
31.globl bad_interrupt 30.globl bad_interrupt
32.globl inthandler1 31.globl inthandler1
33.globl inthandler2 32.globl inthandler2
@@ -137,7 +136,7 @@ inthandler1:
137 movel #65,%sp@- /* put vector # on stack*/ 136 movel #65,%sp@- /* put vector # on stack*/
138 jbsr process_int /* process the IRQ*/ 137 jbsr process_int /* process the IRQ*/
1393: addql #8,%sp /* pop parameters off stack*/ 1383: addql #8,%sp /* pop parameters off stack*/
140 bra ret_from_interrupt 139 bra ret_from_exception
141 140
142inthandler2: 141inthandler2:
143 SAVE_ALL_INT 142 SAVE_ALL_INT
@@ -148,7 +147,7 @@ inthandler2:
148 movel #66,%sp@- /* put vector # on stack*/ 147 movel #66,%sp@- /* put vector # on stack*/
149 jbsr process_int /* process the IRQ*/ 148 jbsr process_int /* process the IRQ*/
1503: addql #8,%sp /* pop parameters off stack*/ 1493: addql #8,%sp /* pop parameters off stack*/
151 bra ret_from_interrupt 150 bra ret_from_exception
152 151
153inthandler3: 152inthandler3:
154 SAVE_ALL_INT 153 SAVE_ALL_INT
@@ -159,7 +158,7 @@ inthandler3:
159 movel #67,%sp@- /* put vector # on stack*/ 158 movel #67,%sp@- /* put vector # on stack*/
160 jbsr process_int /* process the IRQ*/ 159 jbsr process_int /* process the IRQ*/
1613: addql #8,%sp /* pop parameters off stack*/ 1603: addql #8,%sp /* pop parameters off stack*/
162 bra ret_from_interrupt 161 bra ret_from_exception
163 162
164inthandler4: 163inthandler4:
165 SAVE_ALL_INT 164 SAVE_ALL_INT
@@ -170,7 +169,7 @@ inthandler4:
170 movel #68,%sp@- /* put vector # on stack*/ 169 movel #68,%sp@- /* put vector # on stack*/
171 jbsr process_int /* process the IRQ*/ 170 jbsr process_int /* process the IRQ*/
1723: addql #8,%sp /* pop parameters off stack*/ 1713: addql #8,%sp /* pop parameters off stack*/
173 bra ret_from_interrupt 172 bra ret_from_exception
174 173
175inthandler5: 174inthandler5:
176 SAVE_ALL_INT 175 SAVE_ALL_INT
@@ -181,7 +180,7 @@ inthandler5:
181 movel #69,%sp@- /* put vector # on stack*/ 180 movel #69,%sp@- /* put vector # on stack*/
182 jbsr process_int /* process the IRQ*/ 181 jbsr process_int /* process the IRQ*/
1833: addql #8,%sp /* pop parameters off stack*/ 1823: addql #8,%sp /* pop parameters off stack*/
184 bra ret_from_interrupt 183 bra ret_from_exception
185 184
186inthandler6: 185inthandler6:
187 SAVE_ALL_INT 186 SAVE_ALL_INT
@@ -192,7 +191,7 @@ inthandler6:
192 movel #70,%sp@- /* put vector # on stack*/ 191 movel #70,%sp@- /* put vector # on stack*/
193 jbsr process_int /* process the IRQ*/ 192 jbsr process_int /* process the IRQ*/
1943: addql #8,%sp /* pop parameters off stack*/ 1933: addql #8,%sp /* pop parameters off stack*/
195 bra ret_from_interrupt 194 bra ret_from_exception
196 195
197inthandler7: 196inthandler7:
198 SAVE_ALL_INT 197 SAVE_ALL_INT
@@ -203,7 +202,7 @@ inthandler7:
203 movel #71,%sp@- /* put vector # on stack*/ 202 movel #71,%sp@- /* put vector # on stack*/
204 jbsr process_int /* process the IRQ*/ 203 jbsr process_int /* process the IRQ*/
2053: addql #8,%sp /* pop parameters off stack*/ 2043: addql #8,%sp /* pop parameters off stack*/
206 bra ret_from_interrupt 205 bra ret_from_exception
207 206
208inthandler: 207inthandler:
209 SAVE_ALL_INT 208 SAVE_ALL_INT
@@ -214,23 +213,7 @@ inthandler:
214 movel %d0,%sp@- /* put vector # on stack*/ 213 movel %d0,%sp@- /* put vector # on stack*/
215 jbsr process_int /* process the IRQ*/ 214 jbsr process_int /* process the IRQ*/
2163: addql #8,%sp /* pop parameters off stack*/ 2153: addql #8,%sp /* pop parameters off stack*/
217 bra ret_from_interrupt 216 bra ret_from_exception
218
219ret_from_interrupt:
220 jeq 1f
2212:
222 RESTORE_ALL
2231:
224 moveb %sp@(PT_OFF_SR), %d0
225 and #7, %d0
226 jhi 2b
227
228 /* check if we need to do software interrupts */
229 jeq ret_from_exception
230
231 pea ret_from_exception
232 jra do_softirq
233
234 217
235/* 218/*
236 * Handler for uninitialized and spurious interrupts. 219 * Handler for uninitialized and spurious interrupts.
diff --git a/arch/m68k/platform/68360/entry.S b/arch/m68k/platform/68360/entry.S
index 904fd9a4af4e..447c33ef37fd 100644
--- a/arch/m68k/platform/68360/entry.S
+++ b/arch/m68k/platform/68360/entry.S
@@ -29,7 +29,6 @@
29.globl ret_from_exception 29.globl ret_from_exception
30.globl ret_from_signal 30.globl ret_from_signal
31.globl sys_call_table 31.globl sys_call_table
32.globl ret_from_interrupt
33.globl bad_interrupt 32.globl bad_interrupt
34.globl inthandler 33.globl inthandler
35 34
@@ -132,26 +131,9 @@ inthandler:
132 131
133 movel %sp,%sp@- 132 movel %sp,%sp@-
134 movel %d0,%sp@- /* put vector # on stack*/ 133 movel %d0,%sp@- /* put vector # on stack*/
135 jbsr do_IRQ /* process the IRQ*/ 134 jbsr do_IRQ /* process the IRQ */
1363: addql #8,%sp /* pop parameters off stack*/ 135 addql #8,%sp /* pop parameters off stack*/
137 bra ret_from_interrupt 136 jra ret_from_exception
138
139ret_from_interrupt:
140 jeq 1f
1412:
142 RESTORE_ALL
1431:
144 moveb %sp@(PT_OFF_SR), %d0
145 and #7, %d0
146 jhi 2b
147 /* check if we need to do software interrupts */
148
149 movel irq_stat+CPUSTAT_SOFTIRQ_PENDING,%d0
150 jeq ret_from_exception
151
152 pea ret_from_exception
153 jra do_softirq
154
155 137
156/* 138/*
157 * Handler for uninitialized and spurious interrupts. 139 * Handler for uninitialized and spurious interrupts.
diff --git a/arch/metag/include/asm/thread_info.h b/arch/metag/include/asm/thread_info.h
index 7c4a33006142..b19e9c588a16 100644
--- a/arch/metag/include/asm/thread_info.h
+++ b/arch/metag/include/asm/thread_info.h
@@ -46,8 +46,6 @@ struct thread_info {
46 46
47#endif 47#endif
48 48
49#define PREEMPT_ACTIVE 0x10000000
50
51#ifdef CONFIG_4KSTACKS 49#ifdef CONFIG_4KSTACKS
52#define THREAD_SHIFT 12 50#define THREAD_SHIFT 12
53#else 51#else
diff --git a/arch/microblaze/include/asm/thread_info.h b/arch/microblaze/include/asm/thread_info.h
index de26ea6373de..8c9d36591a03 100644
--- a/arch/microblaze/include/asm/thread_info.h
+++ b/arch/microblaze/include/asm/thread_info.h
@@ -106,8 +106,6 @@ static inline struct thread_info *current_thread_info(void)
106/* thread information allocation */ 106/* thread information allocation */
107#endif /* __ASSEMBLY__ */ 107#endif /* __ASSEMBLY__ */
108 108
109#define PREEMPT_ACTIVE 0x10000000
110
111/* 109/*
112 * thread information flags 110 * thread information flags
113 * - these are process state flags that various assembly files may 111 * - these are process state flags that various assembly files may
diff --git a/arch/mips/configs/db1235_defconfig b/arch/mips/configs/db1235_defconfig
index e2b4ad55462f..28e49f226dc0 100644
--- a/arch/mips/configs/db1235_defconfig
+++ b/arch/mips/configs/db1235_defconfig
@@ -351,7 +351,6 @@ CONFIG_USB_OHCI_HCD=y
351CONFIG_USB_OHCI_HCD_PLATFORM=y 351CONFIG_USB_OHCI_HCD_PLATFORM=y
352CONFIG_USB_STORAGE=y 352CONFIG_USB_STORAGE=y
353CONFIG_MMC=y 353CONFIG_MMC=y
354CONFIG_MMC_CLKGATE=y
355CONFIG_MMC_AU1X=y 354CONFIG_MMC_AU1X=y
356CONFIG_NEW_LEDS=y 355CONFIG_NEW_LEDS=y
357CONFIG_LEDS_CLASS=y 356CONFIG_LEDS_CLASS=y
diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
index f9b24bfbdbae..4f58ef6d0eed 100644
--- a/arch/mips/include/asm/thread_info.h
+++ b/arch/mips/include/asm/thread_info.h
@@ -92,8 +92,6 @@ static inline struct thread_info *current_thread_info(void)
92 92
93#define STACK_WARN (THREAD_SIZE / 8) 93#define STACK_WARN (THREAD_SIZE / 8)
94 94
95#define PREEMPT_ACTIVE 0x10000000
96
97/* 95/*
98 * thread information flags 96 * thread information flags
99 * - these are process state flags that various assembly files may need to 97 * - these are process state flags that various assembly files may need to
diff --git a/arch/mn10300/include/asm/thread_info.h b/arch/mn10300/include/asm/thread_info.h
index 224b4262486d..bf280eaccd36 100644
--- a/arch/mn10300/include/asm/thread_info.h
+++ b/arch/mn10300/include/asm/thread_info.h
@@ -16,8 +16,6 @@
16 16
17#include <asm/page.h> 17#include <asm/page.h>
18 18
19#define PREEMPT_ACTIVE 0x10000000
20
21#ifdef CONFIG_4KSTACKS 19#ifdef CONFIG_4KSTACKS
22#define THREAD_SIZE (4096) 20#define THREAD_SIZE (4096)
23#define THREAD_SIZE_ORDER (0) 21#define THREAD_SIZE_ORDER (0)
diff --git a/arch/parisc/include/asm/thread_info.h b/arch/parisc/include/asm/thread_info.h
index bc7cf120106b..d5f97ea3a4e1 100644
--- a/arch/parisc/include/asm/thread_info.h
+++ b/arch/parisc/include/asm/thread_info.h
@@ -46,9 +46,6 @@ struct thread_info {
46#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) 46#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
47#define THREAD_SHIFT (PAGE_SHIFT + THREAD_SIZE_ORDER) 47#define THREAD_SHIFT (PAGE_SHIFT + THREAD_SIZE_ORDER)
48 48
49#define PREEMPT_ACTIVE_BIT 28
50#define PREEMPT_ACTIVE (1 << PREEMPT_ACTIVE_BIT)
51
52/* 49/*
53 * thread information flags 50 * thread information flags
54 */ 51 */
diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
index ba7b1973866e..8fd6cf6dcee8 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -82,8 +82,6 @@ static inline struct thread_info *current_thread_info(void)
82 82
83#endif /* __ASSEMBLY__ */ 83#endif /* __ASSEMBLY__ */
84 84
85#define PREEMPT_ACTIVE 0x10000000
86
87/* 85/*
88 * thread information flag bit numbers 86 * thread information flag bit numbers
89 */ 87 */
diff --git a/arch/s390/boot/Makefile b/arch/s390/boot/Makefile
index f2737a005afc..9a42ecec5647 100644
--- a/arch/s390/boot/Makefile
+++ b/arch/s390/boot/Makefile
@@ -21,6 +21,6 @@ $(obj)/bzImage: $(obj)/compressed/vmlinux FORCE
21$(obj)/compressed/vmlinux: FORCE 21$(obj)/compressed/vmlinux: FORCE
22 $(Q)$(MAKE) $(build)=$(obj)/compressed $@ 22 $(Q)$(MAKE) $(build)=$(obj)/compressed $@
23 23
24install: $(CONFIGURE) $(obj)/image 24install: $(CONFIGURE) $(obj)/bzImage
25 sh -x $(srctree)/$(obj)/install.sh $(KERNELRELEASE) $(obj)/image \ 25 sh -x $(srctree)/$(obj)/install.sh $(KERNELRELEASE) $(obj)/bzImage \
26 System.map "$(INSTALL_PATH)" 26 System.map "$(INSTALL_PATH)"
diff --git a/arch/s390/include/asm/ctl_reg.h b/arch/s390/include/asm/ctl_reg.h
index 9b69c0befdca..4e63f1a13600 100644
--- a/arch/s390/include/asm/ctl_reg.h
+++ b/arch/s390/include/asm/ctl_reg.h
@@ -7,6 +7,8 @@
7#ifndef __ASM_CTL_REG_H 7#ifndef __ASM_CTL_REG_H
8#define __ASM_CTL_REG_H 8#define __ASM_CTL_REG_H
9 9
10#include <linux/bug.h>
11
10#ifdef CONFIG_64BIT 12#ifdef CONFIG_64BIT
11# define __CTL_LOAD "lctlg" 13# define __CTL_LOAD "lctlg"
12# define __CTL_STORE "stctg" 14# define __CTL_STORE "stctg"
diff --git a/arch/s390/include/asm/eadm.h b/arch/s390/include/asm/eadm.h
index dc9200ca32ed..67026300c88e 100644
--- a/arch/s390/include/asm/eadm.h
+++ b/arch/s390/include/asm/eadm.h
@@ -111,18 +111,7 @@ struct scm_driver {
111int scm_driver_register(struct scm_driver *scmdrv); 111int scm_driver_register(struct scm_driver *scmdrv);
112void scm_driver_unregister(struct scm_driver *scmdrv); 112void scm_driver_unregister(struct scm_driver *scmdrv);
113 113
114int scm_start_aob(struct aob *aob); 114int eadm_start_aob(struct aob *aob);
115void scm_irq_handler(struct aob *aob, int error); 115void scm_irq_handler(struct aob *aob, int error);
116 116
117struct eadm_ops {
118 int (*eadm_start) (struct aob *aob);
119 struct module *owner;
120};
121
122int scm_get_ref(void);
123void scm_put_ref(void);
124
125void register_eadm_ops(struct eadm_ops *ops);
126void unregister_eadm_ops(struct eadm_ops *ops);
127
128#endif /* _ASM_S390_EADM_H */ 117#endif /* _ASM_S390_EADM_H */
diff --git a/arch/s390/include/asm/hardirq.h b/arch/s390/include/asm/hardirq.h
index a908d2941c5d..b7eabaaeffbd 100644
--- a/arch/s390/include/asm/hardirq.h
+++ b/arch/s390/include/asm/hardirq.h
@@ -18,8 +18,6 @@
18#define __ARCH_HAS_DO_SOFTIRQ 18#define __ARCH_HAS_DO_SOFTIRQ
19#define __ARCH_IRQ_EXIT_IRQS_DISABLED 19#define __ARCH_IRQ_EXIT_IRQS_DISABLED
20 20
21#define HARDIRQ_BITS 8
22
23static inline void ack_bad_irq(unsigned int irq) 21static inline void ack_bad_irq(unsigned int irq)
24{ 22{
25 printk(KERN_CRIT "unexpected IRQ trap at vector %02x\n", irq); 23 printk(KERN_CRIT "unexpected IRQ trap at vector %02x\n", irq);
diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h
index 1cc185da9d38..c129ab2ac731 100644
--- a/arch/s390/include/asm/pci.h
+++ b/arch/s390/include/asm/pci.h
@@ -63,9 +63,10 @@ enum zpci_state {
63}; 63};
64 64
65struct zpci_bar_struct { 65struct zpci_bar_struct {
66 struct resource *res; /* bus resource */
66 u32 val; /* bar start & 3 flag bits */ 67 u32 val; /* bar start & 3 flag bits */
67 u8 size; /* order 2 exponent */
68 u16 map_idx; /* index into bar mapping array */ 68 u16 map_idx; /* index into bar mapping array */
69 u8 size; /* order 2 exponent */
69}; 70};
70 71
71/* Private data per function */ 72/* Private data per function */
@@ -97,6 +98,7 @@ struct zpci_dev {
97 unsigned long iommu_pages; 98 unsigned long iommu_pages;
98 unsigned int next_bit; 99 unsigned int next_bit;
99 100
101 char res_name[16];
100 struct zpci_bar_struct bars[PCI_BAR_COUNT]; 102 struct zpci_bar_struct bars[PCI_BAR_COUNT];
101 103
102 u64 start_dma; /* Start of available DMA addresses */ 104 u64 start_dma; /* Start of available DMA addresses */
@@ -122,12 +124,10 @@ static inline bool zdev_enabled(struct zpci_dev *zdev)
122 Prototypes 124 Prototypes
123----------------------------------------------------------------------------- */ 125----------------------------------------------------------------------------- */
124/* Base stuff */ 126/* Base stuff */
125struct zpci_dev *zpci_alloc_device(void);
126int zpci_create_device(struct zpci_dev *); 127int zpci_create_device(struct zpci_dev *);
127int zpci_enable_device(struct zpci_dev *); 128int zpci_enable_device(struct zpci_dev *);
128int zpci_disable_device(struct zpci_dev *); 129int zpci_disable_device(struct zpci_dev *);
129void zpci_stop_device(struct zpci_dev *); 130void zpci_stop_device(struct zpci_dev *);
130void zpci_free_device(struct zpci_dev *);
131int zpci_register_ioat(struct zpci_dev *, u8, u64, u64, u64); 131int zpci_register_ioat(struct zpci_dev *, u8, u64, u64, u64);
132int zpci_unregister_ioat(struct zpci_dev *, u8); 132int zpci_unregister_ioat(struct zpci_dev *, u8);
133 133
diff --git a/arch/s390/include/asm/sclp.h b/arch/s390/include/asm/sclp.h
index 7dc7f9c63b65..30ef748bc161 100644
--- a/arch/s390/include/asm/sclp.h
+++ b/arch/s390/include/asm/sclp.h
@@ -43,7 +43,6 @@ struct sclp_cpu_info {
43int sclp_get_cpu_info(struct sclp_cpu_info *info); 43int sclp_get_cpu_info(struct sclp_cpu_info *info);
44int sclp_cpu_configure(u8 cpu); 44int sclp_cpu_configure(u8 cpu);
45int sclp_cpu_deconfigure(u8 cpu); 45int sclp_cpu_deconfigure(u8 cpu);
46void sclp_facilities_detect(void);
47unsigned long long sclp_get_rnmax(void); 46unsigned long long sclp_get_rnmax(void);
48unsigned long long sclp_get_rzm(void); 47unsigned long long sclp_get_rzm(void);
49int sclp_sdias_blk_count(void); 48int sclp_sdias_blk_count(void);
@@ -57,5 +56,7 @@ bool sclp_has_vt220(void);
57int sclp_pci_configure(u32 fid); 56int sclp_pci_configure(u32 fid);
58int sclp_pci_deconfigure(u32 fid); 57int sclp_pci_deconfigure(u32 fid);
59int memcpy_hsa(void *dest, unsigned long src, size_t count, int mode); 58int memcpy_hsa(void *dest, unsigned long src, size_t count, int mode);
59unsigned long sclp_get_hsa_size(void);
60void sclp_early_detect(void);
60 61
61#endif /* _ASM_S390_SCLP_H */ 62#endif /* _ASM_S390_SCLP_H */
diff --git a/arch/s390/include/asm/setup.h b/arch/s390/include/asm/setup.h
index df802ee14af6..94cfbe442f12 100644
--- a/arch/s390/include/asm/setup.h
+++ b/arch/s390/include/asm/setup.h
@@ -107,9 +107,6 @@ void create_mem_hole(struct mem_chunk mem_chunk[], unsigned long addr,
107#define MACHINE_HAS_RRBM (S390_lowcore.machine_flags & MACHINE_FLAG_RRBM) 107#define MACHINE_HAS_RRBM (S390_lowcore.machine_flags & MACHINE_FLAG_RRBM)
108#endif /* CONFIG_64BIT */ 108#endif /* CONFIG_64BIT */
109 109
110#define ZFCPDUMP_HSA_SIZE (32UL<<20)
111#define ZFCPDUMP_HSA_SIZE_MAX (64UL<<20)
112
113/* 110/*
114 * Console mode. Override with conmode= 111 * Console mode. Override with conmode=
115 */ 112 */
diff --git a/arch/s390/include/asm/thread_info.h b/arch/s390/include/asm/thread_info.h
index eb5f64d26d06..10e0fcd3633d 100644
--- a/arch/s390/include/asm/thread_info.h
+++ b/arch/s390/include/asm/thread_info.h
@@ -111,6 +111,4 @@ static inline struct thread_info *current_thread_info(void)
111#define is_32bit_task() (1) 111#define is_32bit_task() (1)
112#endif 112#endif
113 113
114#define PREEMPT_ACTIVE 0x4000000
115
116#endif /* _ASM_THREAD_INFO_H */ 114#endif /* _ASM_THREAD_INFO_H */
diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c
index f45b2ab0cb81..d7658c4b2ed5 100644
--- a/arch/s390/kernel/crash_dump.c
+++ b/arch/s390/kernel/crash_dump.c
@@ -95,7 +95,7 @@ static void *elfcorehdr_newmem;
95/* 95/*
96 * Copy one page from zfcpdump "oldmem" 96 * Copy one page from zfcpdump "oldmem"
97 * 97 *
98 * For pages below ZFCPDUMP_HSA_SIZE memory from the HSA is copied. Otherwise 98 * For pages below HSA size memory from the HSA is copied. Otherwise
99 * real memory copy is used. 99 * real memory copy is used.
100 */ 100 */
101static ssize_t copy_oldmem_page_zfcpdump(char *buf, size_t csize, 101static ssize_t copy_oldmem_page_zfcpdump(char *buf, size_t csize,
@@ -103,7 +103,7 @@ static ssize_t copy_oldmem_page_zfcpdump(char *buf, size_t csize,
103{ 103{
104 int rc; 104 int rc;
105 105
106 if (src < ZFCPDUMP_HSA_SIZE) { 106 if (src < sclp_get_hsa_size()) {
107 rc = memcpy_hsa(buf, src, csize, userbuf); 107 rc = memcpy_hsa(buf, src, csize, userbuf);
108 } else { 108 } else {
109 if (userbuf) 109 if (userbuf)
@@ -188,18 +188,19 @@ static int remap_oldmem_pfn_range_kdump(struct vm_area_struct *vma,
188/* 188/*
189 * Remap "oldmem" for zfcpdump 189 * Remap "oldmem" for zfcpdump
190 * 190 *
191 * We only map available memory above ZFCPDUMP_HSA_SIZE. Memory below 191 * We only map available memory above HSA size. Memory below HSA size
192 * ZFCPDUMP_HSA_SIZE is read on demand using the copy_oldmem_page() function. 192 * is read on demand using the copy_oldmem_page() function.
193 */ 193 */
194static int remap_oldmem_pfn_range_zfcpdump(struct vm_area_struct *vma, 194static int remap_oldmem_pfn_range_zfcpdump(struct vm_area_struct *vma,
195 unsigned long from, 195 unsigned long from,
196 unsigned long pfn, 196 unsigned long pfn,
197 unsigned long size, pgprot_t prot) 197 unsigned long size, pgprot_t prot)
198{ 198{
199 unsigned long hsa_end = sclp_get_hsa_size();
199 unsigned long size_hsa; 200 unsigned long size_hsa;
200 201
201 if (pfn < ZFCPDUMP_HSA_SIZE >> PAGE_SHIFT) { 202 if (pfn < hsa_end >> PAGE_SHIFT) {
202 size_hsa = min(size, ZFCPDUMP_HSA_SIZE - (pfn << PAGE_SHIFT)); 203 size_hsa = min(size, hsa_end - (pfn << PAGE_SHIFT));
203 if (size == size_hsa) 204 if (size == size_hsa)
204 return 0; 205 return 0;
205 size -= size_hsa; 206 size -= size_hsa;
@@ -238,9 +239,9 @@ int copy_from_oldmem(void *dest, void *src, size_t count)
238 return rc; 239 return rc;
239 } 240 }
240 } else { 241 } else {
241 if ((unsigned long) src < ZFCPDUMP_HSA_SIZE) { 242 unsigned long hsa_end = sclp_get_hsa_size();
242 copied = min(count, 243 if ((unsigned long) src < hsa_end) {
243 ZFCPDUMP_HSA_SIZE - (unsigned long) src); 244 copied = min(count, hsa_end - (unsigned long) src);
244 rc = memcpy_hsa(dest, (unsigned long) src, copied, 0); 245 rc = memcpy_hsa(dest, (unsigned long) src, copied, 0);
245 if (rc) 246 if (rc)
246 return rc; 247 return rc;
@@ -580,6 +581,9 @@ int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size)
580 /* If elfcorehdr= has been passed via cmdline, we use that one */ 581 /* If elfcorehdr= has been passed via cmdline, we use that one */
581 if (elfcorehdr_addr != ELFCORE_ADDR_MAX) 582 if (elfcorehdr_addr != ELFCORE_ADDR_MAX)
582 return 0; 583 return 0;
584 /* If we cannot get HSA size for zfcpdump return error */
585 if (ipl_info.type == IPL_TYPE_FCP_DUMP && !sclp_get_hsa_size())
586 return -ENODEV;
583 mem_chunk_cnt = get_mem_chunk_cnt(); 587 mem_chunk_cnt = get_mem_chunk_cnt();
584 588
585 alloc_size = 0x1000 + get_cpu_cnt() * 0x300 + 589 alloc_size = 0x1000 + get_cpu_cnt() * 0x300 +
diff --git a/arch/s390/kernel/early.c b/arch/s390/kernel/early.c
index 96543ac400a7..fca20b5fe79e 100644
--- a/arch/s390/kernel/early.c
+++ b/arch/s390/kernel/early.c
@@ -483,7 +483,7 @@ void __init startup_init(void)
483 detect_diag44(); 483 detect_diag44();
484 detect_machine_facilities(); 484 detect_machine_facilities();
485 setup_topology(); 485 setup_topology();
486 sclp_facilities_detect(); 486 sclp_early_detect();
487#ifdef CONFIG_DYNAMIC_FTRACE 487#ifdef CONFIG_DYNAMIC_FTRACE
488 S390_lowcore.ftrace_func = (unsigned long)ftrace_caller; 488 S390_lowcore.ftrace_func = (unsigned long)ftrace_caller;
489#endif 489#endif
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index ffe1c53264a7..4444875266ee 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -471,8 +471,9 @@ static void __init setup_memory_end(void)
471 471
472 472
473#ifdef CONFIG_ZFCPDUMP 473#ifdef CONFIG_ZFCPDUMP
474 if (ipl_info.type == IPL_TYPE_FCP_DUMP && !OLDMEM_BASE) { 474 if (ipl_info.type == IPL_TYPE_FCP_DUMP &&
475 memory_end = ZFCPDUMP_HSA_SIZE; 475 !OLDMEM_BASE && sclp_get_hsa_size()) {
476 memory_end = sclp_get_hsa_size();
476 memory_end_set = 1; 477 memory_end_set = 1;
477 } 478 }
478#endif 479#endif
@@ -586,7 +587,7 @@ static unsigned long __init find_crash_base(unsigned long crash_size,
586 crash_base = (chunk->addr + chunk->size) - crash_size; 587 crash_base = (chunk->addr + chunk->size) - crash_size;
587 if (crash_base < crash_size) 588 if (crash_base < crash_size)
588 continue; 589 continue;
589 if (crash_base < ZFCPDUMP_HSA_SIZE_MAX) 590 if (crash_base < sclp_get_hsa_size())
590 continue; 591 continue;
591 if (crash_base < (unsigned long) INITRD_START + INITRD_SIZE) 592 if (crash_base < (unsigned long) INITRD_START + INITRD_SIZE)
592 continue; 593 continue;
diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c
index 0c9a17780e4b..bf7c73d71eef 100644
--- a/arch/s390/pci/pci.c
+++ b/arch/s390/pci/pci.c
@@ -530,20 +530,6 @@ static void zpci_unmap_resources(struct zpci_dev *zdev)
530 } 530 }
531} 531}
532 532
533struct zpci_dev *zpci_alloc_device(void)
534{
535 struct zpci_dev *zdev;
536
537 /* Alloc memory for our private pci device data */
538 zdev = kzalloc(sizeof(*zdev), GFP_KERNEL);
539 return zdev ? : ERR_PTR(-ENOMEM);
540}
541
542void zpci_free_device(struct zpci_dev *zdev)
543{
544 kfree(zdev);
545}
546
547int pcibios_add_platform_entries(struct pci_dev *pdev) 533int pcibios_add_platform_entries(struct pci_dev *pdev)
548{ 534{
549 return zpci_sysfs_add_device(&pdev->dev); 535 return zpci_sysfs_add_device(&pdev->dev);
@@ -579,37 +565,6 @@ static void zpci_irq_exit(void)
579 unregister_adapter_interrupt(&zpci_airq); 565 unregister_adapter_interrupt(&zpci_airq);
580} 566}
581 567
582static struct resource *zpci_alloc_bus_resource(unsigned long start, unsigned long size,
583 unsigned long flags, int domain)
584{
585 struct resource *r;
586 char *name;
587 int rc;
588
589 r = kzalloc(sizeof(*r), GFP_KERNEL);
590 if (!r)
591 return ERR_PTR(-ENOMEM);
592 r->start = start;
593 r->end = r->start + size - 1;
594 r->flags = flags;
595 r->parent = &iomem_resource;
596 name = kmalloc(18, GFP_KERNEL);
597 if (!name) {
598 kfree(r);
599 return ERR_PTR(-ENOMEM);
600 }
601 sprintf(name, "PCI Bus: %04x:%02x", domain, ZPCI_BUS_NR);
602 r->name = name;
603
604 rc = request_resource(&iomem_resource, r);
605 if (rc) {
606 kfree(r->name);
607 kfree(r);
608 return ERR_PTR(-ENOMEM);
609 }
610 return r;
611}
612
613static int zpci_alloc_iomap(struct zpci_dev *zdev) 568static int zpci_alloc_iomap(struct zpci_dev *zdev)
614{ 569{
615 int entry; 570 int entry;
@@ -633,6 +588,82 @@ static void zpci_free_iomap(struct zpci_dev *zdev, int entry)
633 spin_unlock(&zpci_iomap_lock); 588 spin_unlock(&zpci_iomap_lock);
634} 589}
635 590
591static struct resource *__alloc_res(struct zpci_dev *zdev, unsigned long start,
592 unsigned long size, unsigned long flags)
593{
594 struct resource *r;
595
596 r = kzalloc(sizeof(*r), GFP_KERNEL);
597 if (!r)
598 return NULL;
599
600 r->start = start;
601 r->end = r->start + size - 1;
602 r->flags = flags;
603 r->name = zdev->res_name;
604
605 if (request_resource(&iomem_resource, r)) {
606 kfree(r);
607 return NULL;
608 }
609 return r;
610}
611
612static int zpci_setup_bus_resources(struct zpci_dev *zdev,
613 struct list_head *resources)
614{
615 unsigned long addr, size, flags;
616 struct resource *res;
617 int i, entry;
618
619 snprintf(zdev->res_name, sizeof(zdev->res_name),
620 "PCI Bus %04x:%02x", zdev->domain, ZPCI_BUS_NR);
621
622 for (i = 0; i < PCI_BAR_COUNT; i++) {
623 if (!zdev->bars[i].size)
624 continue;
625 entry = zpci_alloc_iomap(zdev);
626 if (entry < 0)
627 return entry;
628 zdev->bars[i].map_idx = entry;
629
630 /* only MMIO is supported */
631 flags = IORESOURCE_MEM;
632 if (zdev->bars[i].val & 8)
633 flags |= IORESOURCE_PREFETCH;
634 if (zdev->bars[i].val & 4)
635 flags |= IORESOURCE_MEM_64;
636
637 addr = ZPCI_IOMAP_ADDR_BASE + ((u64) entry << 48);
638
639 size = 1UL << zdev->bars[i].size;
640
641 res = __alloc_res(zdev, addr, size, flags);
642 if (!res) {
643 zpci_free_iomap(zdev, entry);
644 return -ENOMEM;
645 }
646 zdev->bars[i].res = res;
647 pci_add_resource(resources, res);
648 }
649
650 return 0;
651}
652
653static void zpci_cleanup_bus_resources(struct zpci_dev *zdev)
654{
655 int i;
656
657 for (i = 0; i < PCI_BAR_COUNT; i++) {
658 if (!zdev->bars[i].size)
659 continue;
660
661 zpci_free_iomap(zdev, zdev->bars[i].map_idx);
662 release_resource(zdev->bars[i].res);
663 kfree(zdev->bars[i].res);
664 }
665}
666
636int pcibios_add_device(struct pci_dev *pdev) 667int pcibios_add_device(struct pci_dev *pdev)
637{ 668{
638 struct zpci_dev *zdev = get_zdev(pdev); 669 struct zpci_dev *zdev = get_zdev(pdev);
@@ -729,52 +760,6 @@ struct dev_pm_ops pcibios_pm_ops = {
729}; 760};
730#endif /* CONFIG_HIBERNATE_CALLBACKS */ 761#endif /* CONFIG_HIBERNATE_CALLBACKS */
731 762
732static int zpci_scan_bus(struct zpci_dev *zdev)
733{
734 struct resource *res;
735 LIST_HEAD(resources);
736 int i;
737
738 /* allocate mapping entry for each used bar */
739 for (i = 0; i < PCI_BAR_COUNT; i++) {
740 unsigned long addr, size, flags;
741 int entry;
742
743 if (!zdev->bars[i].size)
744 continue;
745 entry = zpci_alloc_iomap(zdev);
746 if (entry < 0)
747 return entry;
748 zdev->bars[i].map_idx = entry;
749
750 /* only MMIO is supported */
751 flags = IORESOURCE_MEM;
752 if (zdev->bars[i].val & 8)
753 flags |= IORESOURCE_PREFETCH;
754 if (zdev->bars[i].val & 4)
755 flags |= IORESOURCE_MEM_64;
756
757 addr = ZPCI_IOMAP_ADDR_BASE + ((u64) entry << 48);
758
759 size = 1UL << zdev->bars[i].size;
760
761 res = zpci_alloc_bus_resource(addr, size, flags, zdev->domain);
762 if (IS_ERR(res)) {
763 zpci_free_iomap(zdev, entry);
764 return PTR_ERR(res);
765 }
766 pci_add_resource(&resources, res);
767 }
768
769 zdev->bus = pci_scan_root_bus(NULL, ZPCI_BUS_NR, &pci_root_ops,
770 zdev, &resources);
771 if (!zdev->bus)
772 return -EIO;
773
774 zdev->bus->max_bus_speed = zdev->max_bus_speed;
775 return 0;
776}
777
778static int zpci_alloc_domain(struct zpci_dev *zdev) 763static int zpci_alloc_domain(struct zpci_dev *zdev)
779{ 764{
780 spin_lock(&zpci_domain_lock); 765 spin_lock(&zpci_domain_lock);
@@ -795,6 +780,41 @@ static void zpci_free_domain(struct zpci_dev *zdev)
795 spin_unlock(&zpci_domain_lock); 780 spin_unlock(&zpci_domain_lock);
796} 781}
797 782
783void pcibios_remove_bus(struct pci_bus *bus)
784{
785 struct zpci_dev *zdev = get_zdev_by_bus(bus);
786
787 zpci_exit_slot(zdev);
788 zpci_cleanup_bus_resources(zdev);
789 zpci_free_domain(zdev);
790
791 spin_lock(&zpci_list_lock);
792 list_del(&zdev->entry);
793 spin_unlock(&zpci_list_lock);
794
795 kfree(zdev);
796}
797
798static int zpci_scan_bus(struct zpci_dev *zdev)
799{
800 LIST_HEAD(resources);
801 int ret;
802
803 ret = zpci_setup_bus_resources(zdev, &resources);
804 if (ret)
805 return ret;
806
807 zdev->bus = pci_scan_root_bus(NULL, ZPCI_BUS_NR, &pci_root_ops,
808 zdev, &resources);
809 if (!zdev->bus) {
810 zpci_cleanup_bus_resources(zdev);
811 return -EIO;
812 }
813
814 zdev->bus->max_bus_speed = zdev->max_bus_speed;
815 return 0;
816}
817
798int zpci_enable_device(struct zpci_dev *zdev) 818int zpci_enable_device(struct zpci_dev *zdev)
799{ 819{
800 int rc; 820 int rc;
diff --git a/arch/s390/pci/pci_clp.c b/arch/s390/pci/pci_clp.c
index 84147984224a..c747394029ee 100644
--- a/arch/s390/pci/pci_clp.c
+++ b/arch/s390/pci/pci_clp.c
@@ -155,9 +155,9 @@ int clp_add_pci_device(u32 fid, u32 fh, int configured)
155 int rc; 155 int rc;
156 156
157 zpci_dbg(3, "add fid:%x, fh:%x, c:%d\n", fid, fh, configured); 157 zpci_dbg(3, "add fid:%x, fh:%x, c:%d\n", fid, fh, configured);
158 zdev = zpci_alloc_device(); 158 zdev = kzalloc(sizeof(*zdev), GFP_KERNEL);
159 if (IS_ERR(zdev)) 159 if (!zdev)
160 return PTR_ERR(zdev); 160 return -ENOMEM;
161 161
162 zdev->fh = fh; 162 zdev->fh = fh;
163 zdev->fid = fid; 163 zdev->fid = fid;
@@ -178,7 +178,7 @@ int clp_add_pci_device(u32 fid, u32 fh, int configured)
178 return 0; 178 return 0;
179 179
180error: 180error:
181 zpci_free_device(zdev); 181 kfree(zdev);
182 return rc; 182 return rc;
183} 183}
184 184
diff --git a/arch/s390/pci/pci_event.c b/arch/s390/pci/pci_event.c
index 278e671ec9ac..800f064b0da7 100644
--- a/arch/s390/pci/pci_event.c
+++ b/arch/s390/pci/pci_event.c
@@ -11,6 +11,7 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/pci.h> 12#include <linux/pci.h>
13#include <asm/pci_debug.h> 13#include <asm/pci_debug.h>
14#include <asm/sclp.h>
14 15
15/* Content Code Description for PCI Function Error */ 16/* Content Code Description for PCI Function Error */
16struct zpci_ccdf_err { 17struct zpci_ccdf_err {
@@ -42,10 +43,27 @@ struct zpci_ccdf_avail {
42 u16 pec; /* PCI event code */ 43 u16 pec; /* PCI event code */
43} __packed; 44} __packed;
44 45
45static void zpci_event_log_avail(struct zpci_ccdf_avail *ccdf) 46void zpci_event_error(void *data)
46{ 47{
48 struct zpci_ccdf_err *ccdf = data;
49 struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
50
51 zpci_err("error CCDF:\n");
52 zpci_err_hex(ccdf, sizeof(*ccdf));
53
54 if (!zdev)
55 return;
56
57 pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
58 pci_name(zdev->pdev), ccdf->pec, ccdf->fid);
59}
60
61void zpci_event_availability(void *data)
62{
63 struct zpci_ccdf_avail *ccdf = data;
47 struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid); 64 struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
48 struct pci_dev *pdev = zdev ? zdev->pdev : NULL; 65 struct pci_dev *pdev = zdev ? zdev->pdev : NULL;
66 int ret;
49 67
50 pr_info("%s: Event 0x%x reconfigured PCI function 0x%x\n", 68 pr_info("%s: Event 0x%x reconfigured PCI function 0x%x\n",
51 pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid); 69 pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
@@ -53,36 +71,47 @@ static void zpci_event_log_avail(struct zpci_ccdf_avail *ccdf)
53 zpci_err_hex(ccdf, sizeof(*ccdf)); 71 zpci_err_hex(ccdf, sizeof(*ccdf));
54 72
55 switch (ccdf->pec) { 73 switch (ccdf->pec) {
56 case 0x0301: 74 case 0x0301: /* Standby -> Configured */
57 zpci_enable_device(zdev); 75 if (!zdev || zdev->state == ZPCI_FN_STATE_CONFIGURED)
76 break;
77 zdev->state = ZPCI_FN_STATE_CONFIGURED;
78 ret = zpci_enable_device(zdev);
79 if (ret)
80 break;
81 pci_rescan_bus(zdev->bus);
58 break; 82 break;
59 case 0x0302: 83 case 0x0302: /* Reserved -> Standby */
60 clp_add_pci_device(ccdf->fid, ccdf->fh, 0); 84 clp_add_pci_device(ccdf->fid, ccdf->fh, 0);
61 break; 85 break;
62 case 0x0306: 86 case 0x0303: /* Deconfiguration requested */
87 if (pdev)
88 pci_stop_and_remove_bus_device(pdev);
89
90 ret = zpci_disable_device(zdev);
91 if (ret)
92 break;
93
94 ret = sclp_pci_deconfigure(zdev->fid);
95 zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev->fid, ret);
96 if (!ret)
97 zdev->state = ZPCI_FN_STATE_STANDBY;
98
99 break;
100 case 0x0304: /* Configured -> Standby */
101 if (pdev)
102 pci_stop_and_remove_bus_device(pdev);
103
104 zpci_disable_device(zdev);
105 zdev->state = ZPCI_FN_STATE_STANDBY;
106 break;
107 case 0x0306: /* 0x308 or 0x302 for multiple devices */
63 clp_rescan_pci_devices(); 108 clp_rescan_pci_devices();
64 break; 109 break;
110 case 0x0308: /* Standby -> Reserved */
111 pci_stop_root_bus(zdev->bus);
112 pci_remove_root_bus(zdev->bus);
113 break;
65 default: 114 default:
66 break; 115 break;
67 } 116 }
68} 117}
69
70void zpci_event_error(void *data)
71{
72 struct zpci_ccdf_err *ccdf = data;
73 struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
74
75 zpci_err("error CCDF:\n");
76 zpci_err_hex(ccdf, sizeof(*ccdf));
77
78 if (!zdev)
79 return;
80
81 pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
82 pci_name(zdev->pdev), ccdf->pec, ccdf->fid);
83}
84
85void zpci_event_availability(void *data)
86{
87 zpci_event_log_avail(data);
88}
diff --git a/arch/score/include/asm/thread_info.h b/arch/score/include/asm/thread_info.h
index 1425cc034872..656b7ada9326 100644
--- a/arch/score/include/asm/thread_info.h
+++ b/arch/score/include/asm/thread_info.h
@@ -72,8 +72,6 @@ register struct thread_info *__current_thread_info __asm__("r28");
72 72
73#endif /* !__ASSEMBLY__ */ 73#endif /* !__ASSEMBLY__ */
74 74
75#define PREEMPT_ACTIVE 0x10000000
76
77/* 75/*
78 * thread information flags 76 * thread information flags
79 * - these are process state flags that various assembly files may need to 77 * - these are process state flags that various assembly files may need to
diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c
index 1fa8be409771..122f737a901f 100644
--- a/arch/sh/boards/mach-ecovec24/setup.c
+++ b/arch/sh/boards/mach-ecovec24/setup.c
@@ -15,6 +15,7 @@
15#include <linux/mmc/sh_mmcif.h> 15#include <linux/mmc/sh_mmcif.h>
16#include <linux/mmc/sh_mobile_sdhi.h> 16#include <linux/mmc/sh_mobile_sdhi.h>
17#include <linux/mtd/physmap.h> 17#include <linux/mtd/physmap.h>
18#include <linux/mfd/tmio.h>
18#include <linux/gpio.h> 19#include <linux/gpio.h>
19#include <linux/interrupt.h> 20#include <linux/interrupt.h>
20#include <linux/io.h> 21#include <linux/io.h>
diff --git a/arch/sh/include/asm/thread_info.h b/arch/sh/include/asm/thread_info.h
index 45a93669289d..ad27ffa65e2e 100644
--- a/arch/sh/include/asm/thread_info.h
+++ b/arch/sh/include/asm/thread_info.h
@@ -41,8 +41,6 @@ struct thread_info {
41 41
42#endif 42#endif
43 43
44#define PREEMPT_ACTIVE 0x10000000
45
46#if defined(CONFIG_4KSTACKS) 44#if defined(CONFIG_4KSTACKS)
47#define THREAD_SHIFT 12 45#define THREAD_SHIFT 12
48#else 46#else
diff --git a/arch/sh/kernel/entry-common.S b/arch/sh/kernel/entry-common.S
index 9b6e4beeb296..ca46834294b7 100644
--- a/arch/sh/kernel/entry-common.S
+++ b/arch/sh/kernel/entry-common.S
@@ -108,7 +108,7 @@ need_resched:
108 and #(0xf0>>1), r0 ! interrupts off (exception path)? 108 and #(0xf0>>1), r0 ! interrupts off (exception path)?
109 cmp/eq #(0xf0>>1), r0 109 cmp/eq #(0xf0>>1), r0
110 bt noresched 110 bt noresched
111 mov.l 3f, r0 111 mov.l 1f, r0
112 jsr @r0 ! call preempt_schedule_irq 112 jsr @r0 ! call preempt_schedule_irq
113 nop 113 nop
114 bra need_resched 114 bra need_resched
@@ -119,9 +119,7 @@ noresched:
119 nop 119 nop
120 120
121 .align 2 121 .align 2
1221: .long PREEMPT_ACTIVE 1221: .long preempt_schedule_irq
1232: .long schedule
1243: .long preempt_schedule_irq
125#endif 123#endif
126 124
127ENTRY(resume_userspace) 125ENTRY(resume_userspace)
diff --git a/arch/sparc/include/asm/hardirq_32.h b/arch/sparc/include/asm/hardirq_32.h
index 162007643cdc..ee93923b7f82 100644
--- a/arch/sparc/include/asm/hardirq_32.h
+++ b/arch/sparc/include/asm/hardirq_32.h
@@ -7,7 +7,6 @@
7#ifndef __SPARC_HARDIRQ_H 7#ifndef __SPARC_HARDIRQ_H
8#define __SPARC_HARDIRQ_H 8#define __SPARC_HARDIRQ_H
9 9
10#define HARDIRQ_BITS 8
11#include <asm-generic/hardirq.h> 10#include <asm-generic/hardirq.h>
12 11
13#endif /* __SPARC_HARDIRQ_H */ 12#endif /* __SPARC_HARDIRQ_H */
diff --git a/arch/sparc/include/asm/hardirq_64.h b/arch/sparc/include/asm/hardirq_64.h
index 7c29fd1a87aa..f478ff1ddd02 100644
--- a/arch/sparc/include/asm/hardirq_64.h
+++ b/arch/sparc/include/asm/hardirq_64.h
@@ -14,6 +14,4 @@
14 14
15void ack_bad_irq(unsigned int irq); 15void ack_bad_irq(unsigned int irq);
16 16
17#define HARDIRQ_BITS 8
18
19#endif /* !(__SPARC64_HARDIRQ_H) */ 17#endif /* !(__SPARC64_HARDIRQ_H) */
diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
index dd3807599bb9..96efa7adc223 100644
--- a/arch/sparc/include/asm/thread_info_32.h
+++ b/arch/sparc/include/asm/thread_info_32.h
@@ -105,8 +105,6 @@ register struct thread_info *current_thread_info_reg asm("g6");
105#define TI_W_SAVED 0x250 105#define TI_W_SAVED 0x250
106/* #define TI_RESTART_BLOCK 0x25n */ /* Nobody cares */ 106/* #define TI_RESTART_BLOCK 0x25n */ /* Nobody cares */
107 107
108#define PREEMPT_ACTIVE 0x4000000
109
110/* 108/*
111 * thread information flag bit numbers 109 * thread information flag bit numbers
112 */ 110 */
diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
index 5d9292ab1077..a5f01ac6d0f1 100644
--- a/arch/sparc/include/asm/thread_info_64.h
+++ b/arch/sparc/include/asm/thread_info_64.h
@@ -111,8 +111,6 @@ struct thread_info {
111#define THREAD_SHIFT PAGE_SHIFT 111#define THREAD_SHIFT PAGE_SHIFT
112#endif /* PAGE_SHIFT == 13 */ 112#endif /* PAGE_SHIFT == 13 */
113 113
114#define PREEMPT_ACTIVE 0x10000000
115
116/* 114/*
117 * macros/functions for gaining access to the thread information structure 115 * macros/functions for gaining access to the thread information structure
118 */ 116 */
diff --git a/arch/sparc/kernel/rtrap_64.S b/arch/sparc/kernel/rtrap_64.S
index a954eb81881b..39f0c662f4c8 100644
--- a/arch/sparc/kernel/rtrap_64.S
+++ b/arch/sparc/kernel/rtrap_64.S
@@ -312,12 +312,10 @@ to_kernel:
312 nop 312 nop
313 cmp %l4, 0 313 cmp %l4, 0
314 bne,pn %xcc, kern_fpucheck 314 bne,pn %xcc, kern_fpucheck
315 sethi %hi(PREEMPT_ACTIVE), %l6 315 nop
316 stw %l6, [%g6 + TI_PRE_COUNT] 316 call preempt_schedule_irq
317 call schedule
318 nop 317 nop
319 ba,pt %xcc, rtrap 318 ba,pt %xcc, rtrap
320 stw %g0, [%g6 + TI_PRE_COUNT]
321#endif 319#endif
322kern_fpucheck: ldub [%g6 + TI_FPDEPTH], %l5 320kern_fpucheck: ldub [%g6 + TI_FPDEPTH], %l5
323 brz,pt %l5, rt_continue 321 brz,pt %l5, rt_continue
diff --git a/arch/tile/include/asm/hardirq.h b/arch/tile/include/asm/hardirq.h
index 822390f9a154..54110af23985 100644
--- a/arch/tile/include/asm/hardirq.h
+++ b/arch/tile/include/asm/hardirq.h
@@ -42,6 +42,4 @@ DECLARE_PER_CPU(irq_cpustat_t, irq_stat);
42 42
43#include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */ 43#include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
44 44
45#define HARDIRQ_BITS 8
46
47#endif /* _ASM_TILE_HARDIRQ_H */ 45#endif /* _ASM_TILE_HARDIRQ_H */
diff --git a/arch/tile/include/asm/thread_info.h b/arch/tile/include/asm/thread_info.h
index b8aa6df3e102..729aa107f64e 100644
--- a/arch/tile/include/asm/thread_info.h
+++ b/arch/tile/include/asm/thread_info.h
@@ -113,8 +113,6 @@ extern void _cpu_idle(void);
113 113
114#endif /* !__ASSEMBLY__ */ 114#endif /* !__ASSEMBLY__ */
115 115
116#define PREEMPT_ACTIVE 0x10000000
117
118/* 116/*
119 * Thread information flags that various assembly files may need to access. 117 * Thread information flags that various assembly files may need to access.
120 * Keep flags accessed frequently in low bits, particular since it makes 118 * Keep flags accessed frequently in low bits, particular since it makes
diff --git a/arch/um/Kconfig.char b/arch/um/Kconfig.char
index b9d7c4276682..f10738d68b2d 100644
--- a/arch/um/Kconfig.char
+++ b/arch/um/Kconfig.char
@@ -6,10 +6,6 @@ config STDERR_CONSOLE
6 help 6 help
7 console driver which dumps all printk messages to stderr. 7 console driver which dumps all printk messages to stderr.
8 8
9config STDIO_CONSOLE
10 bool
11 default y
12
13config SSL 9config SSL
14 bool "Virtual serial line" 10 bool "Virtual serial line"
15 help 11 help
diff --git a/arch/um/Kconfig.common b/arch/um/Kconfig.common
index 8ddea1f8006a..21ca44c4f6d5 100644
--- a/arch/um/Kconfig.common
+++ b/arch/um/Kconfig.common
@@ -1,8 +1,3 @@
1config DEFCONFIG_LIST
2 string
3 option defconfig_list
4 default "arch/$ARCH/defconfig"
5
6config UML 1config UML
7 bool 2 bool
8 default y 3 default y
diff --git a/arch/um/Makefile b/arch/um/Makefile
index 133f7de2a13d..48d92bbe62e9 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -6,6 +6,17 @@
6# Licensed under the GPL 6# Licensed under the GPL
7# 7#
8 8
9# select defconfig based on actual architecture
10ifeq ($(SUBARCH),x86)
11 ifeq ($(shell uname -m),x86_64)
12 KBUILD_DEFCONFIG := x86_64_defconfig
13 else
14 KBUILD_DEFCONFIG := i386_defconfig
15 endif
16else
17 KBUILD_DEFCONFIG := $(SUBARCH)_defconfig
18endif
19
9ARCH_DIR := arch/um 20ARCH_DIR := arch/um
10OS := $(shell uname -s) 21OS := $(shell uname -s)
11# We require bash because the vmlinux link and loader script cpp use bash 22# We require bash because the vmlinux link and loader script cpp use bash
diff --git a/arch/um/configs/i386_defconfig b/arch/um/configs/i386_defconfig
new file mode 100644
index 000000000000..a12bf68c9f3a
--- /dev/null
+++ b/arch/um/configs/i386_defconfig
@@ -0,0 +1,76 @@
1CONFIG_3_LEVEL_PGTABLES=y
2# CONFIG_COMPACTION is not set
3CONFIG_BINFMT_MISC=m
4CONFIG_HOSTFS=y
5CONFIG_MAGIC_SYSRQ=y
6CONFIG_KERNEL_STACK_ORDER=1
7CONFIG_SYSVIPC=y
8CONFIG_POSIX_MQUEUE=y
9CONFIG_NO_HZ=y
10CONFIG_HIGH_RES_TIMERS=y
11CONFIG_BSD_PROCESS_ACCT=y
12CONFIG_IKCONFIG=y
13CONFIG_IKCONFIG_PROC=y
14CONFIG_LOG_BUF_SHIFT=14
15CONFIG_CGROUPS=y
16CONFIG_CGROUP_FREEZER=y
17CONFIG_CGROUP_DEVICE=y
18CONFIG_CPUSETS=y
19CONFIG_CGROUP_CPUACCT=y
20CONFIG_RESOURCE_COUNTERS=y
21CONFIG_CGROUP_SCHED=y
22CONFIG_BLK_CGROUP=y
23# CONFIG_PID_NS is not set
24CONFIG_SYSFS_DEPRECATED=y
25CONFIG_CC_OPTIMIZE_FOR_SIZE=y
26CONFIG_SLAB=y
27CONFIG_MODULES=y
28CONFIG_MODULE_UNLOAD=y
29# CONFIG_BLK_DEV_BSG is not set
30CONFIG_IOSCHED_CFQ=m
31CONFIG_SSL=y
32CONFIG_NULL_CHAN=y
33CONFIG_PORT_CHAN=y
34CONFIG_PTY_CHAN=y
35CONFIG_TTY_CHAN=y
36CONFIG_XTERM_CHAN=y
37CONFIG_CON_CHAN="pts"
38CONFIG_SSL_CHAN="pts"
39CONFIG_UML_SOUND=m
40CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
41CONFIG_DEVTMPFS=y
42CONFIG_DEVTMPFS_MOUNT=y
43CONFIG_BLK_DEV_UBD=y
44CONFIG_BLK_DEV_LOOP=m
45CONFIG_BLK_DEV_NBD=m
46CONFIG_DUMMY=m
47CONFIG_TUN=m
48CONFIG_PPP=m
49CONFIG_SLIP=m
50CONFIG_LEGACY_PTY_COUNT=32
51# CONFIG_HW_RANDOM is not set
52CONFIG_UML_RANDOM=y
53CONFIG_NET=y
54CONFIG_PACKET=y
55CONFIG_UNIX=y
56CONFIG_INET=y
57# CONFIG_INET_LRO is not set
58# CONFIG_IPV6 is not set
59CONFIG_UML_NET=y
60CONFIG_UML_NET_ETHERTAP=y
61CONFIG_UML_NET_TUNTAP=y
62CONFIG_UML_NET_SLIP=y
63CONFIG_UML_NET_DAEMON=y
64CONFIG_UML_NET_MCAST=y
65CONFIG_UML_NET_SLIRP=y
66CONFIG_EXT4_FS=y
67CONFIG_REISERFS_FS=y
68CONFIG_QUOTA=y
69CONFIG_AUTOFS4_FS=m
70CONFIG_ISO9660_FS=m
71CONFIG_JOLIET=y
72CONFIG_PROC_KCORE=y
73CONFIG_TMPFS=y
74CONFIG_NLS=y
75CONFIG_DEBUG_INFO=y
76CONFIG_DEBUG_KERNEL=y
diff --git a/arch/um/configs/x86_64_defconfig b/arch/um/configs/x86_64_defconfig
new file mode 100644
index 000000000000..3aab117bd553
--- /dev/null
+++ b/arch/um/configs/x86_64_defconfig
@@ -0,0 +1,75 @@
1# CONFIG_COMPACTION is not set
2CONFIG_BINFMT_MISC=m
3CONFIG_HOSTFS=y
4CONFIG_MAGIC_SYSRQ=y
5CONFIG_SYSVIPC=y
6CONFIG_POSIX_MQUEUE=y
7CONFIG_NO_HZ=y
8CONFIG_HIGH_RES_TIMERS=y
9CONFIG_BSD_PROCESS_ACCT=y
10CONFIG_IKCONFIG=y
11CONFIG_IKCONFIG_PROC=y
12CONFIG_LOG_BUF_SHIFT=14
13CONFIG_CGROUPS=y
14CONFIG_CGROUP_FREEZER=y
15CONFIG_CGROUP_DEVICE=y
16CONFIG_CPUSETS=y
17CONFIG_CGROUP_CPUACCT=y
18CONFIG_RESOURCE_COUNTERS=y
19CONFIG_CGROUP_SCHED=y
20CONFIG_BLK_CGROUP=y
21# CONFIG_PID_NS is not set
22CONFIG_SYSFS_DEPRECATED=y
23CONFIG_CC_OPTIMIZE_FOR_SIZE=y
24CONFIG_SLAB=y
25CONFIG_MODULES=y
26CONFIG_MODULE_UNLOAD=y
27# CONFIG_BLK_DEV_BSG is not set
28CONFIG_IOSCHED_CFQ=m
29CONFIG_SSL=y
30CONFIG_NULL_CHAN=y
31CONFIG_PORT_CHAN=y
32CONFIG_PTY_CHAN=y
33CONFIG_TTY_CHAN=y
34CONFIG_XTERM_CHAN=y
35CONFIG_CON_CHAN="pts"
36CONFIG_SSL_CHAN="pts"
37CONFIG_UML_SOUND=m
38CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
39CONFIG_DEVTMPFS=y
40CONFIG_DEVTMPFS_MOUNT=y
41CONFIG_BLK_DEV_UBD=y
42CONFIG_BLK_DEV_LOOP=m
43CONFIG_BLK_DEV_NBD=m
44CONFIG_DUMMY=m
45CONFIG_TUN=m
46CONFIG_PPP=m
47CONFIG_SLIP=m
48CONFIG_LEGACY_PTY_COUNT=32
49# CONFIG_HW_RANDOM is not set
50CONFIG_UML_RANDOM=y
51CONFIG_NET=y
52CONFIG_PACKET=y
53CONFIG_UNIX=y
54CONFIG_INET=y
55# CONFIG_INET_LRO is not set
56# CONFIG_IPV6 is not set
57CONFIG_UML_NET=y
58CONFIG_UML_NET_ETHERTAP=y
59CONFIG_UML_NET_TUNTAP=y
60CONFIG_UML_NET_SLIP=y
61CONFIG_UML_NET_DAEMON=y
62CONFIG_UML_NET_MCAST=y
63CONFIG_UML_NET_SLIRP=y
64CONFIG_EXT4_FS=y
65CONFIG_REISERFS_FS=y
66CONFIG_QUOTA=y
67CONFIG_AUTOFS4_FS=m
68CONFIG_ISO9660_FS=m
69CONFIG_JOLIET=y
70CONFIG_PROC_KCORE=y
71CONFIG_TMPFS=y
72CONFIG_NLS=y
73CONFIG_DEBUG_INFO=y
74CONFIG_FRAME_WARN=1024
75CONFIG_DEBUG_KERNEL=y
diff --git a/arch/um/defconfig b/arch/um/defconfig
deleted file mode 100644
index 2665e6b683f5..000000000000
--- a/arch/um/defconfig
+++ /dev/null
@@ -1,899 +0,0 @@
1#
2# Automatically generated file; DO NOT EDIT.
3# User Mode Linux/i386 3.3.0 Kernel Configuration
4#
5CONFIG_DEFCONFIG_LIST="arch/$ARCH/defconfig"
6CONFIG_UML=y
7CONFIG_MMU=y
8CONFIG_NO_IOMEM=y
9# CONFIG_TRACE_IRQFLAGS_SUPPORT is not set
10CONFIG_LOCKDEP_SUPPORT=y
11# CONFIG_STACKTRACE_SUPPORT is not set
12CONFIG_GENERIC_CALIBRATE_DELAY=y
13CONFIG_GENERIC_BUG=y
14CONFIG_GENERIC_CLOCKEVENTS=y
15CONFIG_HZ=100
16
17#
18# UML-specific options
19#
20
21#
22# Host processor type and features
23#
24# CONFIG_M486 is not set
25# CONFIG_M586 is not set
26# CONFIG_M586TSC is not set
27# CONFIG_M586MMX is not set
28CONFIG_M686=y
29# CONFIG_MPENTIUMII is not set
30# CONFIG_MPENTIUMIII is not set
31# CONFIG_MPENTIUMM is not set
32# CONFIG_MPENTIUM4 is not set
33# CONFIG_MK6 is not set
34# CONFIG_MK7 is not set
35# CONFIG_MK8 is not set
36# CONFIG_MCRUSOE is not set
37# CONFIG_MEFFICEON is not set
38# CONFIG_MWINCHIPC6 is not set
39# CONFIG_MWINCHIP3D is not set
40# CONFIG_MELAN is not set
41# CONFIG_MGEODEGX1 is not set
42# CONFIG_MGEODE_LX is not set
43# CONFIG_MCYRIXIII is not set
44# CONFIG_MVIAC3_2 is not set
45# CONFIG_MVIAC7 is not set
46# CONFIG_MCORE2 is not set
47# CONFIG_MATOM is not set
48# CONFIG_X86_GENERIC is not set
49CONFIG_X86_INTERNODE_CACHE_SHIFT=5
50CONFIG_X86_CMPXCHG=y
51CONFIG_X86_L1_CACHE_SHIFT=5
52CONFIG_X86_XADD=y
53CONFIG_X86_PPRO_FENCE=y
54CONFIG_X86_WP_WORKS_OK=y
55CONFIG_X86_INVLPG=y
56CONFIG_X86_BSWAP=y
57CONFIG_X86_POPAD_OK=y
58CONFIG_X86_USE_PPRO_CHECKSUM=y
59CONFIG_X86_TSC=y
60CONFIG_X86_CMPXCHG64=y
61CONFIG_X86_CMOV=y
62CONFIG_X86_MINIMUM_CPU_FAMILY=5
63CONFIG_CPU_SUP_INTEL=y
64CONFIG_CPU_SUP_CYRIX_32=y
65CONFIG_CPU_SUP_AMD=y
66CONFIG_CPU_SUP_CENTAUR=y
67CONFIG_CPU_SUP_TRANSMETA_32=y
68CONFIG_CPU_SUP_UMC_32=y
69CONFIG_UML_X86=y
70# CONFIG_64BIT is not set
71CONFIG_X86_32=y
72# CONFIG_X86_64 is not set
73# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
74CONFIG_RWSEM_GENERIC_SPINLOCK=y
75# CONFIG_3_LEVEL_PGTABLES is not set
76CONFIG_ARCH_HAS_SC_SIGNALS=y
77CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA=y
78CONFIG_GENERIC_HWEIGHT=y
79# CONFIG_STATIC_LINK is not set
80CONFIG_SELECT_MEMORY_MODEL=y
81CONFIG_FLATMEM_MANUAL=y
82CONFIG_FLATMEM=y
83CONFIG_FLAT_NODE_MEM_MAP=y
84CONFIG_PAGEFLAGS_EXTENDED=y
85CONFIG_SPLIT_PTLOCK_CPUS=4
86# CONFIG_COMPACTION is not set
87# CONFIG_PHYS_ADDR_T_64BIT is not set
88CONFIG_ZONE_DMA_FLAG=0
89CONFIG_VIRT_TO_BUS=y
90# CONFIG_KSM is not set
91CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
92CONFIG_NEED_PER_CPU_KM=y
93# CONFIG_CLEANCACHE is not set
94CONFIG_TICK_ONESHOT=y
95CONFIG_NO_HZ=y
96CONFIG_HIGH_RES_TIMERS=y
97CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
98CONFIG_LD_SCRIPT_DYN=y
99CONFIG_BINFMT_ELF=y
100CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
101CONFIG_HAVE_AOUT=y
102# CONFIG_BINFMT_AOUT is not set
103CONFIG_BINFMT_MISC=m
104CONFIG_HOSTFS=y
105# CONFIG_HPPFS is not set
106CONFIG_MCONSOLE=y
107CONFIG_MAGIC_SYSRQ=y
108CONFIG_KERNEL_STACK_ORDER=0
109# CONFIG_MMAPPER is not set
110CONFIG_NO_DMA=y
111
112#
113# General setup
114#
115CONFIG_EXPERIMENTAL=y
116CONFIG_BROKEN_ON_SMP=y
117CONFIG_INIT_ENV_ARG_LIMIT=128
118CONFIG_CROSS_COMPILE=""
119CONFIG_LOCALVERSION=""
120CONFIG_LOCALVERSION_AUTO=y
121CONFIG_DEFAULT_HOSTNAME="(none)"
122CONFIG_SWAP=y
123CONFIG_SYSVIPC=y
124CONFIG_SYSVIPC_SYSCTL=y
125CONFIG_POSIX_MQUEUE=y
126CONFIG_POSIX_MQUEUE_SYSCTL=y
127CONFIG_BSD_PROCESS_ACCT=y
128# CONFIG_BSD_PROCESS_ACCT_V3 is not set
129# CONFIG_FHANDLE is not set
130# CONFIG_TASKSTATS is not set
131# CONFIG_AUDIT is not set
132
133#
134# IRQ subsystem
135#
136CONFIG_GENERIC_IRQ_SHOW=y
137
138#
139# RCU Subsystem
140#
141CONFIG_TINY_RCU=y
142# CONFIG_PREEMPT_RCU is not set
143# CONFIG_RCU_TRACE is not set
144# CONFIG_TREE_RCU_TRACE is not set
145CONFIG_IKCONFIG=y
146CONFIG_IKCONFIG_PROC=y
147CONFIG_LOG_BUF_SHIFT=14
148CONFIG_CGROUPS=y
149# CONFIG_CGROUP_DEBUG is not set
150CONFIG_CGROUP_FREEZER=y
151CONFIG_CGROUP_DEVICE=y
152CONFIG_CPUSETS=y
153CONFIG_PROC_PID_CPUSET=y
154CONFIG_CGROUP_CPUACCT=y
155CONFIG_RESOURCE_COUNTERS=y
156CONFIG_CGROUP_MEMCG=y
157CONFIG_CGROUP_MEMCG_SWAP=y
158# CONFIG_CGROUP_MEMCG_SWAP_ENABLED is not set
159# CONFIG_CGROUP_MEMCG_KMEM is not set
160CONFIG_CGROUP_SCHED=y
161CONFIG_FAIR_GROUP_SCHED=y
162# CONFIG_CFS_BANDWIDTH is not set
163# CONFIG_RT_GROUP_SCHED is not set
164CONFIG_BLK_CGROUP=y
165# CONFIG_DEBUG_BLK_CGROUP is not set
166# CONFIG_CHECKPOINT_RESTORE is not set
167CONFIG_NAMESPACES=y
168CONFIG_UTS_NS=y
169CONFIG_IPC_NS=y
170# CONFIG_USER_NS is not set
171# CONFIG_PID_NS is not set
172CONFIG_NET_NS=y
173# CONFIG_SCHED_AUTOGROUP is not set
174CONFIG_MM_OWNER=y
175CONFIG_SYSFS_DEPRECATED=y
176# CONFIG_SYSFS_DEPRECATED_V2 is not set
177# CONFIG_RELAY is not set
178# CONFIG_BLK_DEV_INITRD is not set
179CONFIG_CC_OPTIMIZE_FOR_SIZE=y
180CONFIG_SYSCTL=y
181CONFIG_ANON_INODES=y
182# CONFIG_EXPERT is not set
183CONFIG_UID16=y
184# CONFIG_SYSCTL_SYSCALL is not set
185CONFIG_KALLSYMS=y
186# CONFIG_KALLSYMS_ALL is not set
187CONFIG_HOTPLUG=y
188CONFIG_PRINTK=y
189CONFIG_BUG=y
190CONFIG_ELF_CORE=y
191CONFIG_BASE_FULL=y
192CONFIG_FUTEX=y
193CONFIG_EPOLL=y
194CONFIG_SIGNALFD=y
195CONFIG_TIMERFD=y
196CONFIG_EVENTFD=y
197CONFIG_SHMEM=y
198CONFIG_AIO=y
199# CONFIG_EMBEDDED is not set
200
201#
202# Kernel Performance Events And Counters
203#
204CONFIG_VM_EVENT_COUNTERS=y
205CONFIG_COMPAT_BRK=y
206CONFIG_SLAB=y
207# CONFIG_SLUB is not set
208# CONFIG_PROFILING is not set
209
210#
211# GCOV-based kernel profiling
212#
213# CONFIG_HAVE_GENERIC_DMA_COHERENT is not set
214CONFIG_SLABINFO=y
215CONFIG_RT_MUTEXES=y
216CONFIG_BASE_SMALL=0
217CONFIG_MODULES=y
218# CONFIG_MODULE_FORCE_LOAD is not set
219CONFIG_MODULE_UNLOAD=y
220# CONFIG_MODULE_FORCE_UNLOAD is not set
221# CONFIG_MODVERSIONS is not set
222# CONFIG_MODULE_SRCVERSION_ALL is not set
223CONFIG_BLOCK=y
224CONFIG_LBDAF=y
225# CONFIG_BLK_DEV_BSG is not set
226# CONFIG_BLK_DEV_BSGLIB is not set
227# CONFIG_BLK_DEV_INTEGRITY is not set
228
229#
230# Partition Types
231#
232# CONFIG_PARTITION_ADVANCED is not set
233CONFIG_MSDOS_PARTITION=y
234
235#
236# IO Schedulers
237#
238CONFIG_IOSCHED_NOOP=y
239CONFIG_IOSCHED_DEADLINE=y
240CONFIG_IOSCHED_CFQ=m
241# CONFIG_CFQ_GROUP_IOSCHED is not set
242CONFIG_DEFAULT_DEADLINE=y
243# CONFIG_DEFAULT_CFQ is not set
244# CONFIG_DEFAULT_NOOP is not set
245CONFIG_DEFAULT_IOSCHED="deadline"
246# CONFIG_INLINE_SPIN_TRYLOCK is not set
247# CONFIG_INLINE_SPIN_TRYLOCK_BH is not set
248# CONFIG_INLINE_SPIN_LOCK is not set
249# CONFIG_INLINE_SPIN_LOCK_BH is not set
250# CONFIG_INLINE_SPIN_LOCK_IRQ is not set
251# CONFIG_INLINE_SPIN_LOCK_IRQSAVE is not set
252CONFIG_INLINE_SPIN_UNLOCK=y
253# CONFIG_INLINE_SPIN_UNLOCK_BH is not set
254CONFIG_INLINE_SPIN_UNLOCK_IRQ=y
255# CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE is not set
256# CONFIG_INLINE_READ_TRYLOCK is not set
257# CONFIG_INLINE_READ_LOCK is not set
258# CONFIG_INLINE_READ_LOCK_BH is not set
259# CONFIG_INLINE_READ_LOCK_IRQ is not set
260# CONFIG_INLINE_READ_LOCK_IRQSAVE is not set
261CONFIG_INLINE_READ_UNLOCK=y
262# CONFIG_INLINE_READ_UNLOCK_BH is not set
263CONFIG_INLINE_READ_UNLOCK_IRQ=y
264# CONFIG_INLINE_READ_UNLOCK_IRQRESTORE is not set
265# CONFIG_INLINE_WRITE_TRYLOCK is not set
266# CONFIG_INLINE_WRITE_LOCK is not set
267# CONFIG_INLINE_WRITE_LOCK_BH is not set
268# CONFIG_INLINE_WRITE_LOCK_IRQ is not set
269# CONFIG_INLINE_WRITE_LOCK_IRQSAVE is not set
270CONFIG_INLINE_WRITE_UNLOCK=y
271# CONFIG_INLINE_WRITE_UNLOCK_BH is not set
272CONFIG_INLINE_WRITE_UNLOCK_IRQ=y
273# CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE is not set
274# CONFIG_MUTEX_SPIN_ON_OWNER is not set
275CONFIG_FREEZER=y
276
277#
278# UML Character Devices
279#
280CONFIG_STDERR_CONSOLE=y
281CONFIG_STDIO_CONSOLE=y
282CONFIG_SSL=y
283CONFIG_NULL_CHAN=y
284CONFIG_PORT_CHAN=y
285CONFIG_PTY_CHAN=y
286CONFIG_TTY_CHAN=y
287CONFIG_XTERM_CHAN=y
288# CONFIG_NOCONFIG_CHAN is not set
289CONFIG_CON_ZERO_CHAN="fd:0,fd:1"
290CONFIG_CON_CHAN="xterm"
291CONFIG_SSL_CHAN="pts"
292CONFIG_UML_SOUND=m
293CONFIG_SOUND=m
294CONFIG_SOUND_OSS_CORE=y
295CONFIG_HOSTAUDIO=m
296
297#
298# Device Drivers
299#
300
301#
302# Generic Driver Options
303#
304CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
305CONFIG_DEVTMPFS=y
306CONFIG_DEVTMPFS_MOUNT=y
307CONFIG_STANDALONE=y
308CONFIG_PREVENT_FIRMWARE_BUILD=y
309CONFIG_FW_LOADER=y
310CONFIG_FIRMWARE_IN_KERNEL=y
311CONFIG_EXTRA_FIRMWARE=""
312# CONFIG_DEBUG_DRIVER is not set
313# CONFIG_DEBUG_DEVRES is not set
314# CONFIG_SYS_HYPERVISOR is not set
315CONFIG_GENERIC_CPU_DEVICES=y
316# CONFIG_DMA_SHARED_BUFFER is not set
317# CONFIG_CONNECTOR is not set
318# CONFIG_MTD is not set
319CONFIG_BLK_DEV=y
320CONFIG_BLK_DEV_UBD=y
321# CONFIG_BLK_DEV_UBD_SYNC is not set
322CONFIG_BLK_DEV_COW_COMMON=y
323CONFIG_BLK_DEV_LOOP=m
324CONFIG_BLK_DEV_LOOP_MIN_COUNT=8
325# CONFIG_BLK_DEV_CRYPTOLOOP is not set
326
327#
328# DRBD disabled because PROC_FS, INET or CONNECTOR not selected
329#
330CONFIG_BLK_DEV_NBD=m
331# CONFIG_BLK_DEV_RAM is not set
332# CONFIG_ATA_OVER_ETH is not set
333# CONFIG_BLK_DEV_RBD is not set
334
335#
336# Misc devices
337#
338# CONFIG_ENCLOSURE_SERVICES is not set
339# CONFIG_C2PORT is not set
340
341#
342# EEPROM support
343#
344# CONFIG_EEPROM_93CX6 is not set
345
346#
347# Texas Instruments shared transport line discipline
348#
349
350#
351# Altera FPGA firmware download module
352#
353
354#
355# SCSI device support
356#
357CONFIG_SCSI_MOD=y
358# CONFIG_RAID_ATTRS is not set
359# CONFIG_SCSI is not set
360# CONFIG_SCSI_DMA is not set
361# CONFIG_SCSI_NETLINK is not set
362# CONFIG_MD is not set
363CONFIG_NETDEVICES=y
364CONFIG_NET_CORE=y
365# CONFIG_BONDING is not set
366CONFIG_DUMMY=m
367# CONFIG_EQUALIZER is not set
368# CONFIG_MII is not set
369# CONFIG_NET_TEAM is not set
370# CONFIG_MACVLAN is not set
371# CONFIG_NETCONSOLE is not set
372# CONFIG_NETPOLL is not set
373# CONFIG_NET_POLL_CONTROLLER is not set
374CONFIG_TUN=m
375# CONFIG_VETH is not set
376
377#
378# CAIF transport drivers
379#
380CONFIG_ETHERNET=y
381CONFIG_NET_VENDOR_CHELSIO=y
382CONFIG_NET_VENDOR_INTEL=y
383CONFIG_NET_VENDOR_I825XX=y
384CONFIG_NET_VENDOR_MARVELL=y
385CONFIG_NET_VENDOR_NATSEMI=y
386CONFIG_NET_VENDOR_8390=y
387# CONFIG_PHYLIB is not set
388CONFIG_PPP=m
389# CONFIG_PPP_BSDCOMP is not set
390# CONFIG_PPP_DEFLATE is not set
391# CONFIG_PPP_FILTER is not set
392# CONFIG_PPP_MPPE is not set
393# CONFIG_PPP_MULTILINK is not set
394# CONFIG_PPPOE is not set
395# CONFIG_PPP_ASYNC is not set
396# CONFIG_PPP_SYNC_TTY is not set
397CONFIG_SLIP=m
398CONFIG_SLHC=m
399# CONFIG_SLIP_COMPRESSED is not set
400# CONFIG_SLIP_SMART is not set
401# CONFIG_SLIP_MODE_SLIP6 is not set
402CONFIG_WLAN=y
403# CONFIG_HOSTAP is not set
404
405#
406# Enable WiMAX (Networking options) to see the WiMAX drivers
407#
408# CONFIG_WAN is not set
409
410#
411# Character devices
412#
413CONFIG_UNIX98_PTYS=y
414# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
415CONFIG_LEGACY_PTYS=y
416CONFIG_LEGACY_PTY_COUNT=32
417# CONFIG_N_GSM is not set
418# CONFIG_TRACE_SINK is not set
419CONFIG_DEVKMEM=y
420# CONFIG_HW_RANDOM is not set
421CONFIG_UML_RANDOM=y
422# CONFIG_R3964 is not set
423# CONFIG_NSC_GPIO is not set
424# CONFIG_RAW_DRIVER is not set
425
426#
427# PPS support
428#
429# CONFIG_PPS is not set
430
431#
432# PPS generators support
433#
434
435#
436# PTP clock support
437#
438
439#
440# Enable Device Drivers -> PPS to see the PTP clock options.
441#
442# CONFIG_POWER_SUPPLY is not set
443# CONFIG_THERMAL is not set
444# CONFIG_WATCHDOG is not set
445# CONFIG_REGULATOR is not set
446CONFIG_SOUND_OSS_CORE_PRECLAIM=y
447# CONFIG_MEMSTICK is not set
448# CONFIG_NEW_LEDS is not set
449# CONFIG_ACCESSIBILITY is not set
450# CONFIG_AUXDISPLAY is not set
451# CONFIG_UIO is not set
452
453#
454# Virtio drivers
455#
456# CONFIG_VIRTIO_BALLOON is not set
457
458#
459# Microsoft Hyper-V guest support
460#
461# CONFIG_STAGING is not set
462
463#
464# Hardware Spinlock drivers
465#
466CONFIG_IOMMU_SUPPORT=y
467# CONFIG_VIRT_DRIVERS is not set
468# CONFIG_PM_DEVFREQ is not set
469CONFIG_NET=y
470
471#
472# Networking options
473#
474CONFIG_PACKET=y
475CONFIG_UNIX=y
476# CONFIG_UNIX_DIAG is not set
477CONFIG_XFRM=y
478# CONFIG_XFRM_USER is not set
479# CONFIG_XFRM_SUB_POLICY is not set
480# CONFIG_XFRM_MIGRATE is not set
481# CONFIG_XFRM_STATISTICS is not set
482# CONFIG_NET_KEY is not set
483CONFIG_INET=y
484# CONFIG_IP_MULTICAST is not set
485# CONFIG_IP_ADVANCED_ROUTER is not set
486# CONFIG_IP_PNP is not set
487# CONFIG_NET_IPIP is not set
488# CONFIG_NET_IPGRE_DEMUX is not set
489# CONFIG_ARPD is not set
490# CONFIG_SYN_COOKIES is not set
491# CONFIG_INET_AH is not set
492# CONFIG_INET_ESP is not set
493# CONFIG_INET_IPCOMP is not set
494# CONFIG_INET_XFRM_TUNNEL is not set
495# CONFIG_INET_TUNNEL is not set
496CONFIG_INET_XFRM_MODE_TRANSPORT=y
497CONFIG_INET_XFRM_MODE_TUNNEL=y
498CONFIG_INET_XFRM_MODE_BEET=y
499# CONFIG_INET_LRO is not set
500CONFIG_INET_DIAG=y
501CONFIG_INET_TCP_DIAG=y
502# CONFIG_INET_UDP_DIAG is not set
503# CONFIG_TCP_CONG_ADVANCED is not set
504CONFIG_TCP_CONG_CUBIC=y
505CONFIG_DEFAULT_TCP_CONG="cubic"
506# CONFIG_TCP_MD5SIG is not set
507# CONFIG_IPV6 is not set
508# CONFIG_NETWORK_SECMARK is not set
509# CONFIG_NETWORK_PHY_TIMESTAMPING is not set
510# CONFIG_NETFILTER is not set
511# CONFIG_IP_DCCP is not set
512# CONFIG_IP_SCTP is not set
513# CONFIG_RDS is not set
514# CONFIG_TIPC is not set
515# CONFIG_ATM is not set
516# CONFIG_L2TP is not set
517# CONFIG_BRIDGE is not set
518# CONFIG_NET_DSA is not set
519# CONFIG_VLAN_8021Q is not set
520# CONFIG_DECNET is not set
521# CONFIG_LLC2 is not set
522# CONFIG_IPX is not set
523# CONFIG_ATALK is not set
524# CONFIG_X25 is not set
525# CONFIG_LAPB is not set
526# CONFIG_ECONET is not set
527# CONFIG_WAN_ROUTER is not set
528# CONFIG_PHONET is not set
529# CONFIG_IEEE802154 is not set
530# CONFIG_NET_SCHED is not set
531# CONFIG_DCB is not set
532# CONFIG_BATMAN_ADV is not set
533# CONFIG_OPENVSWITCH is not set
534# CONFIG_NETPRIO_CGROUP is not set
535CONFIG_BQL=y
536
537#
538# Network testing
539#
540# CONFIG_NET_PKTGEN is not set
541# CONFIG_HAMRADIO is not set
542# CONFIG_CAN is not set
543# CONFIG_IRDA is not set
544# CONFIG_BT is not set
545# CONFIG_AF_RXRPC is not set
546CONFIG_WIRELESS=y
547# CONFIG_CFG80211 is not set
548# CONFIG_LIB80211 is not set
549
550#
551# CFG80211 needs to be enabled for MAC80211
552#
553# CONFIG_WIMAX is not set
554# CONFIG_RFKILL is not set
555# CONFIG_NET_9P is not set
556# CONFIG_CAIF is not set
557# CONFIG_CEPH_LIB is not set
558# CONFIG_NFC is not set
559
560#
561# UML Network Devices
562#
563CONFIG_UML_NET=y
564CONFIG_UML_NET_ETHERTAP=y
565CONFIG_UML_NET_TUNTAP=y
566CONFIG_UML_NET_SLIP=y
567CONFIG_UML_NET_DAEMON=y
568# CONFIG_UML_NET_VDE is not set
569CONFIG_UML_NET_MCAST=y
570# CONFIG_UML_NET_PCAP is not set
571CONFIG_UML_NET_SLIRP=y
572
573#
574# File systems
575#
576# CONFIG_EXT2_FS is not set
577# CONFIG_EXT3_FS is not set
578CONFIG_EXT4_FS=y
579CONFIG_EXT4_USE_FOR_EXT23=y
580CONFIG_EXT4_FS_XATTR=y
581# CONFIG_EXT4_FS_POSIX_ACL is not set
582# CONFIG_EXT4_FS_SECURITY is not set
583# CONFIG_EXT4_DEBUG is not set
584CONFIG_JBD2=y
585CONFIG_FS_MBCACHE=y
586CONFIG_REISERFS_FS=y
587# CONFIG_REISERFS_CHECK is not set
588# CONFIG_REISERFS_PROC_INFO is not set
589# CONFIG_REISERFS_FS_XATTR is not set
590# CONFIG_JFS_FS is not set
591# CONFIG_XFS_FS is not set
592# CONFIG_GFS2_FS is not set
593# CONFIG_BTRFS_FS is not set
594# CONFIG_NILFS2_FS is not set
595# CONFIG_FS_POSIX_ACL is not set
596CONFIG_FILE_LOCKING=y
597CONFIG_FSNOTIFY=y
598CONFIG_DNOTIFY=y
599CONFIG_INOTIFY_USER=y
600# CONFIG_FANOTIFY is not set
601CONFIG_QUOTA=y
602# CONFIG_QUOTA_NETLINK_INTERFACE is not set
603CONFIG_PRINT_QUOTA_WARNING=y
604# CONFIG_QUOTA_DEBUG is not set
605# CONFIG_QFMT_V1 is not set
606# CONFIG_QFMT_V2 is not set
607CONFIG_QUOTACTL=y
608CONFIG_AUTOFS4_FS=m
609# CONFIG_FUSE_FS is not set
610
611#
612# Caches
613#
614# CONFIG_FSCACHE is not set
615
616#
617# CD-ROM/DVD Filesystems
618#
619CONFIG_ISO9660_FS=m
620CONFIG_JOLIET=y
621# CONFIG_ZISOFS is not set
622# CONFIG_UDF_FS is not set
623
624#
625# DOS/FAT/NT Filesystems
626#
627# CONFIG_MSDOS_FS is not set
628# CONFIG_VFAT_FS is not set
629# CONFIG_NTFS_FS is not set
630
631#
632# Pseudo filesystems
633#
634CONFIG_PROC_FS=y
635CONFIG_PROC_KCORE=y
636CONFIG_PROC_SYSCTL=y
637CONFIG_PROC_PAGE_MONITOR=y
638CONFIG_SYSFS=y
639CONFIG_TMPFS=y
640# CONFIG_TMPFS_POSIX_ACL is not set
641# CONFIG_TMPFS_XATTR is not set
642# CONFIG_HUGETLB_PAGE is not set
643# CONFIG_CONFIGFS_FS is not set
644CONFIG_MISC_FILESYSTEMS=y
645# CONFIG_ADFS_FS is not set
646# CONFIG_AFFS_FS is not set
647# CONFIG_HFS_FS is not set
648# CONFIG_HFSPLUS_FS is not set
649# CONFIG_BEFS_FS is not set
650# CONFIG_BFS_FS is not set
651# CONFIG_EFS_FS is not set
652# CONFIG_LOGFS is not set
653# CONFIG_CRAMFS is not set
654# CONFIG_SQUASHFS is not set
655# CONFIG_VXFS_FS is not set
656# CONFIG_MINIX_FS is not set
657# CONFIG_OMFS_FS is not set
658# CONFIG_HPFS_FS is not set
659# CONFIG_QNX4FS_FS is not set
660# CONFIG_ROMFS_FS is not set
661# CONFIG_PSTORE is not set
662# CONFIG_SYSV_FS is not set
663# CONFIG_UFS_FS is not set
664CONFIG_NETWORK_FILESYSTEMS=y
665# CONFIG_NFS_FS is not set
666# CONFIG_NFSD is not set
667# CONFIG_CEPH_FS is not set
668# CONFIG_CIFS is not set
669# CONFIG_NCP_FS is not set
670# CONFIG_CODA_FS is not set
671# CONFIG_AFS_FS is not set
672CONFIG_NLS=y
673CONFIG_NLS_DEFAULT="iso8859-1"
674# CONFIG_NLS_CODEPAGE_437 is not set
675# CONFIG_NLS_CODEPAGE_737 is not set
676# CONFIG_NLS_CODEPAGE_775 is not set
677# CONFIG_NLS_CODEPAGE_850 is not set
678# CONFIG_NLS_CODEPAGE_852 is not set
679# CONFIG_NLS_CODEPAGE_855 is not set
680# CONFIG_NLS_CODEPAGE_857 is not set
681# CONFIG_NLS_CODEPAGE_860 is not set
682# CONFIG_NLS_CODEPAGE_861 is not set
683# CONFIG_NLS_CODEPAGE_862 is not set
684# CONFIG_NLS_CODEPAGE_863 is not set
685# CONFIG_NLS_CODEPAGE_864 is not set
686# CONFIG_NLS_CODEPAGE_865 is not set
687# CONFIG_NLS_CODEPAGE_866 is not set
688# CONFIG_NLS_CODEPAGE_869 is not set
689# CONFIG_NLS_CODEPAGE_936 is not set
690# CONFIG_NLS_CODEPAGE_950 is not set
691# CONFIG_NLS_CODEPAGE_932 is not set
692# CONFIG_NLS_CODEPAGE_949 is not set
693# CONFIG_NLS_CODEPAGE_874 is not set
694# CONFIG_NLS_ISO8859_8 is not set
695# CONFIG_NLS_CODEPAGE_1250 is not set
696# CONFIG_NLS_CODEPAGE_1251 is not set
697# CONFIG_NLS_ASCII is not set
698# CONFIG_NLS_ISO8859_1 is not set
699# CONFIG_NLS_ISO8859_2 is not set
700# CONFIG_NLS_ISO8859_3 is not set
701# CONFIG_NLS_ISO8859_4 is not set
702# CONFIG_NLS_ISO8859_5 is not set
703# CONFIG_NLS_ISO8859_6 is not set
704# CONFIG_NLS_ISO8859_7 is not set
705# CONFIG_NLS_ISO8859_9 is not set
706# CONFIG_NLS_ISO8859_13 is not set
707# CONFIG_NLS_ISO8859_14 is not set
708# CONFIG_NLS_ISO8859_15 is not set
709# CONFIG_NLS_KOI8_R is not set
710# CONFIG_NLS_KOI8_U is not set
711# CONFIG_NLS_UTF8 is not set
712
713#
714# Security options
715#
716# CONFIG_KEYS is not set
717# CONFIG_SECURITY_DMESG_RESTRICT is not set
718# CONFIG_SECURITY is not set
719# CONFIG_SECURITYFS is not set
720CONFIG_DEFAULT_SECURITY_DAC=y
721CONFIG_DEFAULT_SECURITY=""
722CONFIG_CRYPTO=y
723
724#
725# Crypto core or helper
726#
727# CONFIG_CRYPTO_FIPS is not set
728CONFIG_CRYPTO_ALGAPI=m
729CONFIG_CRYPTO_ALGAPI2=m
730CONFIG_CRYPTO_RNG=m
731CONFIG_CRYPTO_RNG2=m
732# CONFIG_CRYPTO_MANAGER is not set
733# CONFIG_CRYPTO_MANAGER2 is not set
734# CONFIG_CRYPTO_USER is not set
735# CONFIG_CRYPTO_GF128MUL is not set
736# CONFIG_CRYPTO_NULL is not set
737# CONFIG_CRYPTO_CRYPTD is not set
738# CONFIG_CRYPTO_AUTHENC is not set
739# CONFIG_CRYPTO_TEST is not set
740
741#
742# Authenticated Encryption with Associated Data
743#
744# CONFIG_CRYPTO_CCM is not set
745# CONFIG_CRYPTO_GCM is not set
746# CONFIG_CRYPTO_SEQIV is not set
747
748#
749# Block modes
750#
751# CONFIG_CRYPTO_CBC is not set
752# CONFIG_CRYPTO_CTR is not set
753# CONFIG_CRYPTO_CTS is not set
754# CONFIG_CRYPTO_ECB is not set
755# CONFIG_CRYPTO_LRW is not set
756# CONFIG_CRYPTO_PCBC is not set
757# CONFIG_CRYPTO_XTS is not set
758
759#
760# Hash modes
761#
762# CONFIG_CRYPTO_HMAC is not set
763# CONFIG_CRYPTO_XCBC is not set
764# CONFIG_CRYPTO_VMAC is not set
765
766#
767# Digest
768#
769# CONFIG_CRYPTO_CRC32C is not set
770# CONFIG_CRYPTO_GHASH is not set
771# CONFIG_CRYPTO_MD4 is not set
772# CONFIG_CRYPTO_MD5 is not set
773# CONFIG_CRYPTO_MICHAEL_MIC is not set
774# CONFIG_CRYPTO_RMD128 is not set
775# CONFIG_CRYPTO_RMD160 is not set
776# CONFIG_CRYPTO_RMD256 is not set
777# CONFIG_CRYPTO_RMD320 is not set
778# CONFIG_CRYPTO_SHA1 is not set
779# CONFIG_CRYPTO_SHA256 is not set
780# CONFIG_CRYPTO_SHA512 is not set
781# CONFIG_CRYPTO_TGR192 is not set
782# CONFIG_CRYPTO_WP512 is not set
783
784#
785# Ciphers
786#
787CONFIG_CRYPTO_AES=m
788# CONFIG_CRYPTO_AES_586 is not set
789# CONFIG_CRYPTO_ANUBIS is not set
790# CONFIG_CRYPTO_ARC4 is not set
791# CONFIG_CRYPTO_BLOWFISH is not set
792# CONFIG_CRYPTO_CAMELLIA is not set
793# CONFIG_CRYPTO_CAST5 is not set
794# CONFIG_CRYPTO_CAST6 is not set
795# CONFIG_CRYPTO_DES is not set
796# CONFIG_CRYPTO_FCRYPT is not set
797# CONFIG_CRYPTO_KHAZAD is not set
798# CONFIG_CRYPTO_SALSA20 is not set
799# CONFIG_CRYPTO_SALSA20_586 is not set
800# CONFIG_CRYPTO_SEED is not set
801# CONFIG_CRYPTO_SERPENT is not set
802# CONFIG_CRYPTO_TEA is not set
803# CONFIG_CRYPTO_TWOFISH is not set
804# CONFIG_CRYPTO_TWOFISH_586 is not set
805
806#
807# Compression
808#
809# CONFIG_CRYPTO_DEFLATE is not set
810# CONFIG_CRYPTO_ZLIB is not set
811# CONFIG_CRYPTO_LZO is not set
812
813#
814# Random Number Generation
815#
816CONFIG_CRYPTO_ANSI_CPRNG=m
817# CONFIG_CRYPTO_USER_API_HASH is not set
818# CONFIG_CRYPTO_USER_API_SKCIPHER is not set
819CONFIG_CRYPTO_HW=y
820# CONFIG_BINARY_PRINTF is not set
821
822#
823# Library routines
824#
825CONFIG_BITREVERSE=y
826CONFIG_GENERIC_FIND_FIRST_BIT=y
827CONFIG_GENERIC_IO=y
828# CONFIG_CRC_CCITT is not set
829CONFIG_CRC16=y
830# CONFIG_CRC_T10DIF is not set
831# CONFIG_CRC_ITU_T is not set
832CONFIG_CRC32=y
833# CONFIG_CRC7 is not set
834# CONFIG_LIBCRC32C is not set
835# CONFIG_CRC8 is not set
836# CONFIG_XZ_DEC is not set
837# CONFIG_XZ_DEC_BCJ is not set
838CONFIG_DQL=y
839CONFIG_NLATTR=y
840# CONFIG_AVERAGE is not set
841# CONFIG_CORDIC is not set
842
843#
844# Kernel hacking
845#
846# CONFIG_PRINTK_TIME is not set
847CONFIG_DEFAULT_MESSAGE_LOGLEVEL=4
848CONFIG_ENABLE_WARN_DEPRECATED=y
849CONFIG_ENABLE_MUST_CHECK=y
850CONFIG_FRAME_WARN=1024
851# CONFIG_STRIP_ASM_SYMS is not set
852# CONFIG_UNUSED_SYMBOLS is not set
853# CONFIG_DEBUG_FS is not set
854# CONFIG_DEBUG_SECTION_MISMATCH is not set
855CONFIG_DEBUG_KERNEL=y
856# CONFIG_DEBUG_SHIRQ is not set
857# CONFIG_LOCKUP_DETECTOR is not set
858# CONFIG_HARDLOCKUP_DETECTOR is not set
859# CONFIG_DETECT_HUNG_TASK is not set
860CONFIG_SCHED_DEBUG=y
861# CONFIG_SCHEDSTATS is not set
862# CONFIG_TIMER_STATS is not set
863# CONFIG_DEBUG_OBJECTS is not set
864# CONFIG_DEBUG_SLAB is not set
865# CONFIG_DEBUG_RT_MUTEXES is not set
866# CONFIG_RT_MUTEX_TESTER is not set
867# CONFIG_DEBUG_SPINLOCK is not set
868# CONFIG_DEBUG_MUTEXES is not set
869# CONFIG_SPARSE_RCU_POINTER is not set
870# CONFIG_DEBUG_ATOMIC_SLEEP is not set
871# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
872# CONFIG_DEBUG_STACK_USAGE is not set
873# CONFIG_DEBUG_KOBJECT is not set
874CONFIG_DEBUG_BUGVERBOSE=y
875CONFIG_DEBUG_INFO=y
876# CONFIG_DEBUG_INFO_REDUCED is not set
877# CONFIG_DEBUG_VM is not set
878# CONFIG_DEBUG_WRITECOUNT is not set
879CONFIG_DEBUG_MEMORY_INIT=y
880# CONFIG_DEBUG_LIST is not set
881# CONFIG_TEST_LIST_SORT is not set
882# CONFIG_DEBUG_SG is not set
883# CONFIG_DEBUG_NOTIFIERS is not set
884# CONFIG_DEBUG_CREDENTIALS is not set
885CONFIG_FRAME_POINTER=y
886# CONFIG_BOOT_PRINTK_DELAY is not set
887# CONFIG_RCU_TORTURE_TEST is not set
888# CONFIG_BACKTRACE_SELF_TEST is not set
889# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
890# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
891# CONFIG_FAULT_INJECTION is not set
892# CONFIG_SYSCTL_SYSCALL_CHECK is not set
893# CONFIG_DEBUG_PAGEALLOC is not set
894# CONFIG_ATOMIC64_SELFTEST is not set
895# CONFIG_SAMPLES is not set
896# CONFIG_TEST_KSTRTOX is not set
897# CONFIG_GPROF is not set
898# CONFIG_GCOV is not set
899CONFIG_EARLY_PRINTK=y
diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
index 3df3bd544492..29880c9b324e 100644
--- a/arch/um/drivers/mconsole_kern.c
+++ b/arch/um/drivers/mconsole_kern.c
@@ -645,11 +645,9 @@ void mconsole_sysrq(struct mc_request *req)
645 645
646static void stack_proc(void *arg) 646static void stack_proc(void *arg)
647{ 647{
648 struct task_struct *from = current, *to = arg; 648 struct task_struct *task = arg;
649 649
650 to->thread.saved_task = from; 650 show_stack(task, NULL);
651 rcu_user_hooks_switch(from, to);
652 switch_to(from, to, from);
653} 651}
654 652
655/* 653/*
diff --git a/arch/um/include/asm/processor-generic.h b/arch/um/include/asm/processor-generic.h
index c03cd5a02364..d89b02bb6262 100644
--- a/arch/um/include/asm/processor-generic.h
+++ b/arch/um/include/asm/processor-generic.h
@@ -19,8 +19,8 @@ struct task_struct;
19struct mm_struct; 19struct mm_struct;
20 20
21struct thread_struct { 21struct thread_struct {
22 struct task_struct *saved_task;
23 struct pt_regs regs; 22 struct pt_regs regs;
23 struct pt_regs *segv_regs;
24 int singlestep_syscall; 24 int singlestep_syscall;
25 void *fault_addr; 25 void *fault_addr;
26 jmp_buf *fault_catcher; 26 jmp_buf *fault_catcher;
diff --git a/arch/um/include/asm/thread_info.h b/arch/um/include/asm/thread_info.h
index 2c8eeb2df8b4..1c5b2a83046a 100644
--- a/arch/um/include/asm/thread_info.h
+++ b/arch/um/include/asm/thread_info.h
@@ -60,8 +60,6 @@ static inline struct thread_info *current_thread_info(void)
60 60
61#endif 61#endif
62 62
63#define PREEMPT_ACTIVE 0x10000000
64
65#define TIF_SYSCALL_TRACE 0 /* syscall trace active */ 63#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
66#define TIF_SIGPENDING 1 /* signal pending */ 64#define TIF_SIGPENDING 1 /* signal pending */
67#define TIF_NEED_RESCHED 2 /* rescheduling necessary */ 65#define TIF_NEED_RESCHED 2 /* rescheduling necessary */
diff --git a/arch/um/include/shared/as-layout.h b/arch/um/include/shared/as-layout.h
index 694c792bab4e..41c8c774ec10 100644
--- a/arch/um/include/shared/as-layout.h
+++ b/arch/um/include/shared/as-layout.h
@@ -44,7 +44,6 @@ struct cpu_task {
44 44
45extern struct cpu_task cpu_tasks[]; 45extern struct cpu_task cpu_tasks[];
46 46
47extern unsigned long low_physmem;
48extern unsigned long high_physmem; 47extern unsigned long high_physmem;
49extern unsigned long uml_physmem; 48extern unsigned long uml_physmem;
50extern unsigned long uml_reserved; 49extern unsigned long uml_reserved;
@@ -52,8 +51,6 @@ extern unsigned long end_vm;
52extern unsigned long start_vm; 51extern unsigned long start_vm;
53extern unsigned long long highmem; 52extern unsigned long long highmem;
54 53
55extern unsigned long _stext, _etext, _sdata, _edata, __bss_start, _end;
56extern unsigned long _unprotected_end;
57extern unsigned long brk_start; 54extern unsigned long brk_start;
58 55
59extern unsigned long host_task_size; 56extern unsigned long host_task_size;
diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
index 021104d98cb3..75298d3358e7 100644
--- a/arch/um/include/shared/os.h
+++ b/arch/um/include/shared/os.h
@@ -227,6 +227,7 @@ extern void block_signals(void);
227extern void unblock_signals(void); 227extern void unblock_signals(void);
228extern int get_signals(void); 228extern int get_signals(void);
229extern int set_signals(int enable); 229extern int set_signals(int enable);
230extern int os_is_signal_stack(void);
230 231
231/* util.c */ 232/* util.c */
232extern void stack_protections(unsigned long address); 233extern void stack_protections(unsigned long address);
diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
index bbcef522bcb1..eecc4142764c 100644
--- a/arch/um/kernel/process.c
+++ b/arch/um/kernel/process.c
@@ -82,19 +82,8 @@ void *__switch_to(struct task_struct *from, struct task_struct *to)
82 to->thread.prev_sched = from; 82 to->thread.prev_sched = from;
83 set_current(to); 83 set_current(to);
84 84
85 do { 85 switch_threads(&from->thread.switch_buf, &to->thread.switch_buf);
86 current->thread.saved_task = NULL; 86 arch_switch_to(current);
87
88 switch_threads(&from->thread.switch_buf,
89 &to->thread.switch_buf);
90
91 arch_switch_to(current);
92
93 if (current->thread.saved_task)
94 show_regs(&(current->thread.regs));
95 to = current->thread.saved_task;
96 from = current;
97 } while (current->thread.saved_task);
98 87
99 return current->thread.prev_sched; 88 return current->thread.prev_sched;
100} 89}
diff --git a/arch/um/kernel/sysrq.c b/arch/um/kernel/sysrq.c
index 0dc4d1c6f98a..4d6fdf68edf3 100644
--- a/arch/um/kernel/sysrq.c
+++ b/arch/um/kernel/sysrq.c
@@ -1,6 +1,10 @@
1/* 1/*
2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) 2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL 3 * Copyright (C) 2013 Richard Weinberger <richrd@nod.at>
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.
4 */ 8 */
5 9
6#include <linux/kallsyms.h> 10#include <linux/kallsyms.h>
@@ -8,59 +12,87 @@
8#include <linux/module.h> 12#include <linux/module.h>
9#include <linux/sched.h> 13#include <linux/sched.h>
10#include <asm/sysrq.h> 14#include <asm/sysrq.h>
15#include <os.h>
11 16
12/* Catch non-i386 SUBARCH's. */ 17struct stack_frame {
13#if !defined(CONFIG_UML_X86) || defined(CONFIG_64BIT) 18 struct stack_frame *next_frame;
14void show_trace(struct task_struct *task, unsigned long * stack) 19 unsigned long return_address;
20};
21
22static void print_stack_trace(unsigned long *sp, unsigned long bp)
15{ 23{
24 int reliable;
16 unsigned long addr; 25 unsigned long addr;
26 struct stack_frame *frame = (struct stack_frame *)bp;
17 27
18 if (!stack) { 28 printk(KERN_INFO "Call Trace:\n");
19 stack = (unsigned long*) &stack; 29 while (((long) sp & (THREAD_SIZE-1)) != 0) {
20 WARN_ON(1); 30 addr = *sp;
21 }
22
23 printk(KERN_INFO "Call Trace: \n");
24 while (((long) stack & (THREAD_SIZE-1)) != 0) {
25 addr = *stack;
26 if (__kernel_text_address(addr)) { 31 if (__kernel_text_address(addr)) {
27 printk(KERN_INFO "%08lx: [<%08lx>]", 32 reliable = 0;
28 (unsigned long) stack, addr); 33 if ((unsigned long) sp == bp + sizeof(long)) {
29 print_symbol(KERN_CONT " %s", addr); 34 frame = frame ? frame->next_frame : NULL;
35 bp = (unsigned long)frame;
36 reliable = 1;
37 }
38
39 printk(KERN_INFO " [<%08lx>]", addr);
40 printk(KERN_CONT " %s", reliable ? "" : "? ");
41 print_symbol(KERN_CONT "%s", addr);
30 printk(KERN_CONT "\n"); 42 printk(KERN_CONT "\n");
31 } 43 }
32 stack++; 44 sp++;
33 } 45 }
34 printk(KERN_INFO "\n"); 46 printk(KERN_INFO "\n");
35} 47}
36#endif
37 48
38/*Stolen from arch/i386/kernel/traps.c */ 49static unsigned long get_frame_pointer(struct task_struct *task,
39static const int kstack_depth_to_print = 24; 50 struct pt_regs *segv_regs)
51{
52 if (!task || task == current)
53 return segv_regs ? PT_REGS_BP(segv_regs) : current_bp();
54 else
55 return KSTK_EBP(task);
56}
40 57
41/* This recently started being used in arch-independent code too, as in 58static unsigned long *get_stack_pointer(struct task_struct *task,
42 * kernel/sched/core.c.*/ 59 struct pt_regs *segv_regs)
43void show_stack(struct task_struct *task, unsigned long *esp)
44{ 60{
45 unsigned long *stack; 61 if (!task || task == current)
62 return segv_regs ? (unsigned long *)PT_REGS_SP(segv_regs) : current_sp();
63 else
64 return (unsigned long *)KSTK_ESP(task);
65}
66
67void show_stack(struct task_struct *task, unsigned long *stack)
68{
69 unsigned long *sp = stack, bp = 0;
70 struct pt_regs *segv_regs = current->thread.segv_regs;
46 int i; 71 int i;
47 72
48 if (esp == NULL) { 73 if (!segv_regs && os_is_signal_stack()) {
49 if (task != current && task != NULL) { 74 printk(KERN_ERR "Received SIGSEGV in SIGSEGV handler,"
50 esp = (unsigned long *) KSTK_ESP(task); 75 " aborting stack trace!\n");
51 } else { 76 return;
52 esp = (unsigned long *) &esp;
53 }
54 } 77 }
55 78
56 stack = esp; 79#ifdef CONFIG_FRAME_POINTER
57 for (i = 0; i < kstack_depth_to_print; i++) { 80 bp = get_frame_pointer(task, segv_regs);
81#endif
82
83 if (!stack)
84 sp = get_stack_pointer(task, segv_regs);
85
86 printk(KERN_INFO "Stack:\n");
87 stack = sp;
88 for (i = 0; i < 3 * STACKSLOTS_PER_LINE; i++) {
58 if (kstack_end(stack)) 89 if (kstack_end(stack))
59 break; 90 break;
60 if (i && ((i % 8) == 0)) 91 if (i && ((i % STACKSLOTS_PER_LINE) == 0))
61 printk(KERN_INFO " "); 92 printk(KERN_CONT "\n");
62 printk(KERN_CONT "%08lx ", *stack++); 93 printk(KERN_CONT " %08lx", *stack++);
63 } 94 }
95 printk(KERN_CONT "\n");
64 96
65 show_trace(task, esp); 97 print_stack_trace(sp, bp);
66} 98}
diff --git a/arch/um/kernel/trap.c b/arch/um/kernel/trap.c
index 5c3aef74237f..974b87474a99 100644
--- a/arch/um/kernel/trap.c
+++ b/arch/um/kernel/trap.c
@@ -206,9 +206,12 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
206 int is_write = FAULT_WRITE(fi); 206 int is_write = FAULT_WRITE(fi);
207 unsigned long address = FAULT_ADDRESS(fi); 207 unsigned long address = FAULT_ADDRESS(fi);
208 208
209 if (regs)
210 current->thread.segv_regs = container_of(regs, struct pt_regs, regs);
211
209 if (!is_user && (address >= start_vm) && (address < end_vm)) { 212 if (!is_user && (address >= start_vm) && (address < end_vm)) {
210 flush_tlb_kernel_vm(); 213 flush_tlb_kernel_vm();
211 return 0; 214 goto out;
212 } 215 }
213 else if (current->mm == NULL) { 216 else if (current->mm == NULL) {
214 show_regs(container_of(regs, struct pt_regs, regs)); 217 show_regs(container_of(regs, struct pt_regs, regs));
@@ -230,7 +233,7 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
230 233
231 catcher = current->thread.fault_catcher; 234 catcher = current->thread.fault_catcher;
232 if (!err) 235 if (!err)
233 return 0; 236 goto out;
234 else if (catcher != NULL) { 237 else if (catcher != NULL) {
235 current->thread.fault_addr = (void *) address; 238 current->thread.fault_addr = (void *) address;
236 UML_LONGJMP(catcher, 1); 239 UML_LONGJMP(catcher, 1);
@@ -238,7 +241,7 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
238 else if (current->thread.fault_addr != NULL) 241 else if (current->thread.fault_addr != NULL)
239 panic("fault_addr set but no fault catcher"); 242 panic("fault_addr set but no fault catcher");
240 else if (!is_user && arch_fixup(ip, regs)) 243 else if (!is_user && arch_fixup(ip, regs))
241 return 0; 244 goto out;
242 245
243 if (!is_user) { 246 if (!is_user) {
244 show_regs(container_of(regs, struct pt_regs, regs)); 247 show_regs(container_of(regs, struct pt_regs, regs));
@@ -262,6 +265,11 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
262 current->thread.arch.faultinfo = fi; 265 current->thread.arch.faultinfo = fi;
263 force_sig_info(SIGSEGV, &si, current); 266 force_sig_info(SIGSEGV, &si, current);
264 } 267 }
268
269out:
270 if (regs)
271 current->thread.segv_regs = NULL;
272
265 return 0; 273 return 0;
266} 274}
267 275
diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c
index 87df5e3acc26..016adf0985d5 100644
--- a/arch/um/kernel/um_arch.c
+++ b/arch/um/kernel/um_arch.c
@@ -13,6 +13,7 @@
13#include <linux/sched.h> 13#include <linux/sched.h>
14#include <asm/pgtable.h> 14#include <asm/pgtable.h>
15#include <asm/processor.h> 15#include <asm/processor.h>
16#include <asm/sections.h>
16#include <asm/setup.h> 17#include <asm/setup.h>
17#include <as-layout.h> 18#include <as-layout.h>
18#include <arch.h> 19#include <arch.h>
@@ -234,7 +235,6 @@ static int panic_exit(struct notifier_block *self, unsigned long unused1,
234 void *unused2) 235 void *unused2)
235{ 236{
236 bust_spinlocks(1); 237 bust_spinlocks(1);
237 show_regs(&(current->thread.regs));
238 bust_spinlocks(0); 238 bust_spinlocks(0);
239 uml_exitcode = 1; 239 uml_exitcode = 1;
240 os_dump_core(); 240 os_dump_core();
diff --git a/arch/um/os-Linux/signal.c b/arch/um/os-Linux/signal.c
index 905924b773d3..7b605e4dfffa 100644
--- a/arch/um/os-Linux/signal.c
+++ b/arch/um/os-Linux/signal.c
@@ -304,3 +304,11 @@ int set_signals(int enable)
304 304
305 return ret; 305 return ret;
306} 306}
307
308int os_is_signal_stack(void)
309{
310 stack_t ss;
311 sigaltstack(NULL, &ss);
312
313 return ss.ss_flags & SS_ONSTACK;
314}
diff --git a/arch/unicore32/include/asm/thread_info.h b/arch/unicore32/include/asm/thread_info.h
index 818b4a1edb5b..af36d8eabdf1 100644
--- a/arch/unicore32/include/asm/thread_info.h
+++ b/arch/unicore32/include/asm/thread_info.h
@@ -118,12 +118,6 @@ static inline struct thread_info *current_thread_info(void)
118#endif 118#endif
119 119
120/* 120/*
121 * We use bit 30 of the preempt_count to indicate that kernel
122 * preemption is occurring. See <asm/hardirq.h>.
123 */
124#define PREEMPT_ACTIVE 0x40000000
125
126/*
127 * thread information flags: 121 * thread information flags:
128 * TIF_SYSCALL_TRACE - syscall trace active 122 * TIF_SYSCALL_TRACE - syscall trace active
129 * TIF_SIGPENDING - signal pending 123 * TIF_SIGPENDING - signal pending
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index c46a46be1ec6..3ba3de457d05 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -153,8 +153,6 @@ struct thread_info {
153#define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY) 153#define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
154#define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW) 154#define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
155 155
156#define PREEMPT_ACTIVE 0x10000000
157
158#ifdef CONFIG_X86_32 156#ifdef CONFIG_X86_32
159 157
160#define STACK_WARN (THREAD_SIZE/8) 158#define STACK_WARN (THREAD_SIZE/8)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index ed165d657380..d278736bf774 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -62,6 +62,7 @@ unsigned disabled_cpus;
62 62
63/* Processor that is doing the boot up */ 63/* Processor that is doing the boot up */
64unsigned int boot_cpu_physical_apicid = -1U; 64unsigned int boot_cpu_physical_apicid = -1U;
65EXPORT_SYMBOL_GPL(boot_cpu_physical_apicid);
65 66
66/* 67/*
67 * The highest APIC ID seen during enumeration. 68 * The highest APIC ID seen during enumeration.
diff --git a/arch/x86/um/Kconfig b/arch/x86/um/Kconfig
index 14ef8d1dbc33..ed56a1c4ae73 100644
--- a/arch/x86/um/Kconfig
+++ b/arch/x86/um/Kconfig
@@ -31,6 +31,11 @@ config X86_64
31 def_bool 64BIT 31 def_bool 64BIT
32 select MODULES_USE_ELF_RELA 32 select MODULES_USE_ELF_RELA
33 33
34config ARCH_DEFCONFIG
35 string
36 default "arch/um/configs/i386_defconfig" if X86_32
37 default "arch/um/configs/x86_64_defconfig" if X86_64
38
34config RWSEM_XCHGADD_ALGORITHM 39config RWSEM_XCHGADD_ALGORITHM
35 def_bool 64BIT 40 def_bool 64BIT
36 41
diff --git a/arch/x86/um/asm/processor_32.h b/arch/x86/um/asm/processor_32.h
index 6c6689e574ce..c112de81c9e1 100644
--- a/arch/x86/um/asm/processor_32.h
+++ b/arch/x86/um/asm/processor_32.h
@@ -33,6 +33,8 @@ struct arch_thread {
33 .faultinfo = { 0, 0, 0 } \ 33 .faultinfo = { 0, 0, 0 } \
34} 34}
35 35
36#define STACKSLOTS_PER_LINE 8
37
36static inline void arch_flush_thread(struct arch_thread *thread) 38static inline void arch_flush_thread(struct arch_thread *thread)
37{ 39{
38 /* Clear any TLS still hanging */ 40 /* Clear any TLS still hanging */
@@ -53,4 +55,7 @@ static inline void arch_copy_thread(struct arch_thread *from,
53#define current_text_addr() \ 55#define current_text_addr() \
54 ({ void *pc; __asm__("movl $1f,%0\n1:":"=g" (pc)); pc; }) 56 ({ void *pc; __asm__("movl $1f,%0\n1:":"=g" (pc)); pc; })
55 57
58#define current_sp() ({ void *sp; __asm__("movl %%esp, %0" : "=r" (sp) : ); sp; })
59#define current_bp() ({ unsigned long bp; __asm__("movl %%ebp, %0" : "=r" (bp) : ); bp; })
60
56#endif 61#endif
diff --git a/arch/x86/um/asm/processor_64.h b/arch/x86/um/asm/processor_64.h
index 4b02a8455bd1..c3be85205a65 100644
--- a/arch/x86/um/asm/processor_64.h
+++ b/arch/x86/um/asm/processor_64.h
@@ -19,6 +19,8 @@ struct arch_thread {
19 .fs = 0, \ 19 .fs = 0, \
20 .faultinfo = { 0, 0, 0 } } 20 .faultinfo = { 0, 0, 0 } }
21 21
22#define STACKSLOTS_PER_LINE 4
23
22static inline void arch_flush_thread(struct arch_thread *thread) 24static inline void arch_flush_thread(struct arch_thread *thread)
23{ 25{
24} 26}
@@ -32,4 +34,7 @@ static inline void arch_copy_thread(struct arch_thread *from,
32#define current_text_addr() \ 34#define current_text_addr() \
33 ({ void *pc; __asm__("movq $1f,%0\n1:":"=g" (pc)); pc; }) 35 ({ void *pc; __asm__("movq $1f,%0\n1:":"=g" (pc)); pc; })
34 36
37#define current_sp() ({ void *sp; __asm__("movq %%rsp, %0" : "=r" (sp) : ); sp; })
38#define current_bp() ({ unsigned long bp; __asm__("movq %%rbp, %0" : "=r" (bp) : ); bp; })
39
35#endif 40#endif
diff --git a/arch/x86/um/sysrq_32.c b/arch/x86/um/sysrq_32.c
index c9bee5b8c0d3..16ee0e450e3e 100644
--- a/arch/x86/um/sysrq_32.c
+++ b/arch/x86/um/sysrq_32.c
@@ -30,70 +30,4 @@ void show_regs(struct pt_regs *regs)
30 printk(" DS: %04lx ES: %04lx\n", 30 printk(" DS: %04lx ES: %04lx\n",
31 0xffff & PT_REGS_DS(regs), 31 0xffff & PT_REGS_DS(regs),
32 0xffff & PT_REGS_ES(regs)); 32 0xffff & PT_REGS_ES(regs));
33
34 show_trace(NULL, (unsigned long *) &regs);
35} 33}
36
37/* Copied from i386. */
38static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
39{
40 return p > (void *)tinfo &&
41 p < (void *)tinfo + THREAD_SIZE - 3;
42}
43
44/* Adapted from i386 (we also print the address we read from). */
45static inline unsigned long print_context_stack(struct thread_info *tinfo,
46 unsigned long *stack, unsigned long ebp)
47{
48 unsigned long addr;
49
50#ifdef CONFIG_FRAME_POINTER
51 while (valid_stack_ptr(tinfo, (void *)ebp)) {
52 addr = *(unsigned long *)(ebp + 4);
53 printk("%08lx: [<%08lx>]", ebp + 4, addr);
54 print_symbol(" %s", addr);
55 printk("\n");
56 ebp = *(unsigned long *)ebp;
57 }
58#else
59 while (valid_stack_ptr(tinfo, stack)) {
60 addr = *stack;
61 if (__kernel_text_address(addr)) {
62 printk("%08lx: [<%08lx>]", (unsigned long) stack, addr);
63 print_symbol(" %s", addr);
64 printk("\n");
65 }
66 stack++;
67 }
68#endif
69 return ebp;
70}
71
72void show_trace(struct task_struct* task, unsigned long * stack)
73{
74 unsigned long ebp;
75 struct thread_info *context;
76
77 /* Turn this into BUG_ON if possible. */
78 if (!stack) {
79 stack = (unsigned long*) &stack;
80 printk("show_trace: got NULL stack, implicit assumption task == current");
81 WARN_ON(1);
82 }
83
84 if (!task)
85 task = current;
86
87 if (task != current) {
88 ebp = (unsigned long) KSTK_EBP(task);
89 } else {
90 asm ("movl %%ebp, %0" : "=r" (ebp) : );
91 }
92
93 context = (struct thread_info *)
94 ((unsigned long)stack & (~(THREAD_SIZE - 1)));
95 print_context_stack(context, stack, ebp);
96
97 printk("\n");
98}
99
diff --git a/arch/x86/um/sysrq_64.c b/arch/x86/um/sysrq_64.c
index a0e7fb1134a0..38b4e4abd0f8 100644
--- a/arch/x86/um/sysrq_64.c
+++ b/arch/x86/um/sysrq_64.c
@@ -12,7 +12,7 @@
12#include <asm/ptrace.h> 12#include <asm/ptrace.h>
13#include <asm/sysrq.h> 13#include <asm/sysrq.h>
14 14
15void __show_regs(struct pt_regs *regs) 15void show_regs(struct pt_regs *regs)
16{ 16{
17 printk("\n"); 17 printk("\n");
18 print_modules(); 18 print_modules();
@@ -33,9 +33,3 @@ void __show_regs(struct pt_regs *regs)
33 printk(KERN_INFO "R13: %016lx R14: %016lx R15: %016lx\n", 33 printk(KERN_INFO "R13: %016lx R14: %016lx R15: %016lx\n",
34 PT_REGS_R13(regs), PT_REGS_R14(regs), PT_REGS_R15(regs)); 34 PT_REGS_R13(regs), PT_REGS_R14(regs), PT_REGS_R15(regs));
35} 35}
36
37void show_regs(struct pt_regs *regs)
38{
39 __show_regs(regs);
40 show_trace(current, (unsigned long *) &regs);
41}
diff --git a/arch/x86/um/vdso/.gitignore b/arch/x86/um/vdso/.gitignore
new file mode 100644
index 000000000000..9cac6d072199
--- /dev/null
+++ b/arch/x86/um/vdso/.gitignore
@@ -0,0 +1,2 @@
1vdso-syms.lds
2vdso.lds
diff --git a/arch/xtensa/include/asm/thread_info.h b/arch/xtensa/include/asm/thread_info.h
index 9481004ac119..470153e8547c 100644
--- a/arch/xtensa/include/asm/thread_info.h
+++ b/arch/xtensa/include/asm/thread_info.h
@@ -76,8 +76,6 @@ struct thread_info {
76 76
77#endif 77#endif
78 78
79#define PREEMPT_ACTIVE 0x10000000
80
81/* 79/*
82 * macros/functions for gaining access to the thread information structure 80 * macros/functions for gaining access to the thread information structure
83 */ 81 */
diff --git a/drivers/edac/cell_edac.c b/drivers/edac/cell_edac.c
index 9ee1c76da7b9..374b57fc596d 100644
--- a/drivers/edac/cell_edac.c
+++ b/drivers/edac/cell_edac.c
@@ -163,6 +163,7 @@ static void cell_edac_init_csrows(struct mem_ctl_info *mci)
163 csrow->first_page, nr_pages); 163 csrow->first_page, nr_pages);
164 break; 164 break;
165 } 165 }
166 of_node_put(np);
166} 167}
167 168
168static int cell_edac_probe(struct platform_device *pdev) 169static int cell_edac_probe(struct platform_device *pdev)
diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
index 211021dfec73..102674346035 100644
--- a/drivers/edac/edac_device.c
+++ b/drivers/edac/edac_device.c
@@ -530,12 +530,9 @@ int edac_device_add_device(struct edac_device_ctl_info *edac_dev)
530 530
531 /* Report action taken */ 531 /* Report action taken */
532 edac_device_printk(edac_dev, KERN_INFO, 532 edac_device_printk(edac_dev, KERN_INFO,
533 "Giving out device to module '%s' controller " 533 "Giving out device to module %s controller %s: DEV %s (%s)\n",
534 "'%s': DEV '%s' (%s)\n", 534 edac_dev->mod_name, edac_dev->ctl_name, edac_dev->dev_name,
535 edac_dev->mod_name, 535 edac_op_state_to_string(edac_dev->op_state));
536 edac_dev->ctl_name,
537 edac_dev_name(edac_dev),
538 edac_op_state_to_string(edac_dev->op_state));
539 536
540 mutex_unlock(&device_ctls_mutex); 537 mutex_unlock(&device_ctls_mutex);
541 return 0; 538 return 0;
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index 89e109022d78..e8c9ef03495b 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -788,8 +788,10 @@ int edac_mc_add_mc(struct mem_ctl_info *mci)
788 } 788 }
789 789
790 /* Report action taken */ 790 /* Report action taken */
791 edac_mc_printk(mci, KERN_INFO, "Giving out device to '%s' '%s':" 791 edac_mc_printk(mci, KERN_INFO,
792 " DEV %s\n", mci->mod_name, mci->ctl_name, edac_dev_name(mci)); 792 "Giving out device to module %s controller %s: DEV %s (%s)\n",
793 mci->mod_name, mci->ctl_name, mci->dev_name,
794 edac_op_state_to_string(mci->op_state));
793 795
794 edac_mc_owner = mci->mod_name; 796 edac_mc_owner = mci->mod_name;
795 797
diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
index dd370f92ace3..2cf44b4db80c 100644
--- a/drivers/edac/edac_pci.c
+++ b/drivers/edac/edac_pci.c
@@ -358,11 +358,9 @@ int edac_pci_add_device(struct edac_pci_ctl_info *pci, int edac_idx)
358 } 358 }
359 359
360 edac_pci_printk(pci, KERN_INFO, 360 edac_pci_printk(pci, KERN_INFO,
361 "Giving out device to module '%s' controller '%s':" 361 "Giving out device to module %s controller %s: DEV %s (%s)\n",
362 " DEV '%s' (%s)\n", 362 pci->mod_name, pci->ctl_name, pci->dev_name,
363 pci->mod_name, 363 edac_op_state_to_string(pci->op_state));
364 pci->ctl_name,
365 edac_dev_name(pci), edac_op_state_to_string(pci->op_state));
366 364
367 mutex_unlock(&edac_pci_ctls_mutex); 365 mutex_unlock(&edac_pci_ctls_mutex);
368 return 0; 366 return 0;
diff --git a/drivers/edac/highbank_l2_edac.c b/drivers/edac/highbank_l2_edac.c
index c2bd8c6a4349..2f193668ebc7 100644
--- a/drivers/edac/highbank_l2_edac.c
+++ b/drivers/edac/highbank_l2_edac.c
@@ -50,8 +50,15 @@ static irqreturn_t highbank_l2_err_handler(int irq, void *dev_id)
50 return IRQ_HANDLED; 50 return IRQ_HANDLED;
51} 51}
52 52
53static const struct of_device_id hb_l2_err_of_match[] = {
54 { .compatible = "calxeda,hb-sregs-l2-ecc", },
55 {},
56};
57MODULE_DEVICE_TABLE(of, hb_l2_err_of_match);
58
53static int highbank_l2_err_probe(struct platform_device *pdev) 59static int highbank_l2_err_probe(struct platform_device *pdev)
54{ 60{
61 const struct of_device_id *id;
55 struct edac_device_ctl_info *dci; 62 struct edac_device_ctl_info *dci;
56 struct hb_l2_drvdata *drvdata; 63 struct hb_l2_drvdata *drvdata;
57 struct resource *r; 64 struct resource *r;
@@ -90,28 +97,32 @@ static int highbank_l2_err_probe(struct platform_device *pdev)
90 goto err; 97 goto err;
91 } 98 }
92 99
100 id = of_match_device(hb_l2_err_of_match, &pdev->dev);
101 dci->mod_name = pdev->dev.driver->name;
102 dci->ctl_name = id ? id->compatible : "unknown";
103 dci->dev_name = dev_name(&pdev->dev);
104
105 if (edac_device_add_device(dci))
106 goto err;
107
93 drvdata->db_irq = platform_get_irq(pdev, 0); 108 drvdata->db_irq = platform_get_irq(pdev, 0);
94 res = devm_request_irq(&pdev->dev, drvdata->db_irq, 109 res = devm_request_irq(&pdev->dev, drvdata->db_irq,
95 highbank_l2_err_handler, 110 highbank_l2_err_handler,
96 0, dev_name(&pdev->dev), dci); 111 0, dev_name(&pdev->dev), dci);
97 if (res < 0) 112 if (res < 0)
98 goto err; 113 goto err2;
99 114
100 drvdata->sb_irq = platform_get_irq(pdev, 1); 115 drvdata->sb_irq = platform_get_irq(pdev, 1);
101 res = devm_request_irq(&pdev->dev, drvdata->sb_irq, 116 res = devm_request_irq(&pdev->dev, drvdata->sb_irq,
102 highbank_l2_err_handler, 117 highbank_l2_err_handler,
103 0, dev_name(&pdev->dev), dci); 118 0, dev_name(&pdev->dev), dci);
104 if (res < 0) 119 if (res < 0)
105 goto err; 120 goto err2;
106
107 dci->mod_name = dev_name(&pdev->dev);
108 dci->dev_name = dev_name(&pdev->dev);
109
110 if (edac_device_add_device(dci))
111 goto err;
112 121
113 devres_close_group(&pdev->dev, NULL); 122 devres_close_group(&pdev->dev, NULL);
114 return 0; 123 return 0;
124err2:
125 edac_device_del_device(&pdev->dev);
115err: 126err:
116 devres_release_group(&pdev->dev, NULL); 127 devres_release_group(&pdev->dev, NULL);
117 edac_device_free_ctl_info(dci); 128 edac_device_free_ctl_info(dci);
@@ -127,12 +138,6 @@ static int highbank_l2_err_remove(struct platform_device *pdev)
127 return 0; 138 return 0;
128} 139}
129 140
130static const struct of_device_id hb_l2_err_of_match[] = {
131 { .compatible = "calxeda,hb-sregs-l2-ecc", },
132 {},
133};
134MODULE_DEVICE_TABLE(of, hb_l2_err_of_match);
135
136static struct platform_driver highbank_l2_edac_driver = { 141static struct platform_driver highbank_l2_edac_driver = {
137 .probe = highbank_l2_err_probe, 142 .probe = highbank_l2_err_probe,
138 .remove = highbank_l2_err_remove, 143 .remove = highbank_l2_err_remove,
diff --git a/drivers/edac/highbank_mc_edac.c b/drivers/edac/highbank_mc_edac.c
index 4695dd2d71fd..f784de1dc793 100644
--- a/drivers/edac/highbank_mc_edac.c
+++ b/drivers/edac/highbank_mc_edac.c
@@ -26,31 +26,40 @@
26#include "edac_module.h" 26#include "edac_module.h"
27 27
28/* DDR Ctrlr Error Registers */ 28/* DDR Ctrlr Error Registers */
29#define HB_DDR_ECC_OPT 0x128
30#define HB_DDR_ECC_U_ERR_ADDR 0x130
31#define HB_DDR_ECC_U_ERR_STAT 0x134
32#define HB_DDR_ECC_U_ERR_DATAL 0x138
33#define HB_DDR_ECC_U_ERR_DATAH 0x13c
34#define HB_DDR_ECC_C_ERR_ADDR 0x140
35#define HB_DDR_ECC_C_ERR_STAT 0x144
36#define HB_DDR_ECC_C_ERR_DATAL 0x148
37#define HB_DDR_ECC_C_ERR_DATAH 0x14c
38#define HB_DDR_ECC_INT_STATUS 0x180
39#define HB_DDR_ECC_INT_ACK 0x184
40#define HB_DDR_ECC_U_ERR_ID 0x424
41#define HB_DDR_ECC_C_ERR_ID 0x428
42 29
43#define HB_DDR_ECC_INT_STAT_CE 0x8 30#define HB_DDR_ECC_ERR_BASE 0x128
44#define HB_DDR_ECC_INT_STAT_DOUBLE_CE 0x10 31#define MW_DDR_ECC_ERR_BASE 0x1b4
45#define HB_DDR_ECC_INT_STAT_UE 0x20 32
46#define HB_DDR_ECC_INT_STAT_DOUBLE_UE 0x40 33#define HB_DDR_ECC_OPT 0x00
34#define HB_DDR_ECC_U_ERR_ADDR 0x08
35#define HB_DDR_ECC_U_ERR_STAT 0x0c
36#define HB_DDR_ECC_U_ERR_DATAL 0x10
37#define HB_DDR_ECC_U_ERR_DATAH 0x14
38#define HB_DDR_ECC_C_ERR_ADDR 0x18
39#define HB_DDR_ECC_C_ERR_STAT 0x1c
40#define HB_DDR_ECC_C_ERR_DATAL 0x20
41#define HB_DDR_ECC_C_ERR_DATAH 0x24
47 42
48#define HB_DDR_ECC_OPT_MODE_MASK 0x3 43#define HB_DDR_ECC_OPT_MODE_MASK 0x3
49#define HB_DDR_ECC_OPT_FWC 0x100 44#define HB_DDR_ECC_OPT_FWC 0x100
50#define HB_DDR_ECC_OPT_XOR_SHIFT 16 45#define HB_DDR_ECC_OPT_XOR_SHIFT 16
51 46
47/* DDR Ctrlr Interrupt Registers */
48
49#define HB_DDR_ECC_INT_BASE 0x180
50#define MW_DDR_ECC_INT_BASE 0x218
51
52#define HB_DDR_ECC_INT_STATUS 0x00
53#define HB_DDR_ECC_INT_ACK 0x04
54
55#define HB_DDR_ECC_INT_STAT_CE 0x8
56#define HB_DDR_ECC_INT_STAT_DOUBLE_CE 0x10
57#define HB_DDR_ECC_INT_STAT_UE 0x20
58#define HB_DDR_ECC_INT_STAT_DOUBLE_UE 0x40
59
52struct hb_mc_drvdata { 60struct hb_mc_drvdata {
53 void __iomem *mc_vbase; 61 void __iomem *mc_err_base;
62 void __iomem *mc_int_base;
54}; 63};
55 64
56static irqreturn_t highbank_mc_err_handler(int irq, void *dev_id) 65static irqreturn_t highbank_mc_err_handler(int irq, void *dev_id)
@@ -60,10 +69,10 @@ static irqreturn_t highbank_mc_err_handler(int irq, void *dev_id)
60 u32 status, err_addr; 69 u32 status, err_addr;
61 70
62 /* Read the interrupt status register */ 71 /* Read the interrupt status register */
63 status = readl(drvdata->mc_vbase + HB_DDR_ECC_INT_STATUS); 72 status = readl(drvdata->mc_int_base + HB_DDR_ECC_INT_STATUS);
64 73
65 if (status & HB_DDR_ECC_INT_STAT_UE) { 74 if (status & HB_DDR_ECC_INT_STAT_UE) {
66 err_addr = readl(drvdata->mc_vbase + HB_DDR_ECC_U_ERR_ADDR); 75 err_addr = readl(drvdata->mc_err_base + HB_DDR_ECC_U_ERR_ADDR);
67 edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 76 edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
68 err_addr >> PAGE_SHIFT, 77 err_addr >> PAGE_SHIFT,
69 err_addr & ~PAGE_MASK, 0, 78 err_addr & ~PAGE_MASK, 0,
@@ -71,9 +80,9 @@ static irqreturn_t highbank_mc_err_handler(int irq, void *dev_id)
71 mci->ctl_name, ""); 80 mci->ctl_name, "");
72 } 81 }
73 if (status & HB_DDR_ECC_INT_STAT_CE) { 82 if (status & HB_DDR_ECC_INT_STAT_CE) {
74 u32 syndrome = readl(drvdata->mc_vbase + HB_DDR_ECC_C_ERR_STAT); 83 u32 syndrome = readl(drvdata->mc_err_base + HB_DDR_ECC_C_ERR_STAT);
75 syndrome = (syndrome >> 8) & 0xff; 84 syndrome = (syndrome >> 8) & 0xff;
76 err_addr = readl(drvdata->mc_vbase + HB_DDR_ECC_C_ERR_ADDR); 85 err_addr = readl(drvdata->mc_err_base + HB_DDR_ECC_C_ERR_ADDR);
77 edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1, 86 edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
78 err_addr >> PAGE_SHIFT, 87 err_addr >> PAGE_SHIFT,
79 err_addr & ~PAGE_MASK, syndrome, 88 err_addr & ~PAGE_MASK, syndrome,
@@ -82,66 +91,79 @@ static irqreturn_t highbank_mc_err_handler(int irq, void *dev_id)
82 } 91 }
83 92
84 /* clear the error, clears the interrupt */ 93 /* clear the error, clears the interrupt */
85 writel(status, drvdata->mc_vbase + HB_DDR_ECC_INT_ACK); 94 writel(status, drvdata->mc_int_base + HB_DDR_ECC_INT_ACK);
86 return IRQ_HANDLED; 95 return IRQ_HANDLED;
87} 96}
88 97
89#ifdef CONFIG_EDAC_DEBUG 98static void highbank_mc_err_inject(struct mem_ctl_info *mci, u8 synd)
90static ssize_t highbank_mc_err_inject_write(struct file *file,
91 const char __user *data,
92 size_t count, loff_t *ppos)
93{ 99{
94 struct mem_ctl_info *mci = file->private_data;
95 struct hb_mc_drvdata *pdata = mci->pvt_info; 100 struct hb_mc_drvdata *pdata = mci->pvt_info;
96 char buf[32];
97 size_t buf_size;
98 u32 reg; 101 u32 reg;
102
103 reg = readl(pdata->mc_err_base + HB_DDR_ECC_OPT);
104 reg &= HB_DDR_ECC_OPT_MODE_MASK;
105 reg |= (synd << HB_DDR_ECC_OPT_XOR_SHIFT) | HB_DDR_ECC_OPT_FWC;
106 writel(reg, pdata->mc_err_base + HB_DDR_ECC_OPT);
107}
108
109#define to_mci(k) container_of(k, struct mem_ctl_info, dev)
110
111static ssize_t highbank_mc_inject_ctrl(struct device *dev,
112 struct device_attribute *attr, const char *buf, size_t count)
113{
114 struct mem_ctl_info *mci = to_mci(dev);
99 u8 synd; 115 u8 synd;
100 116
101 buf_size = min(count, (sizeof(buf)-1)); 117 if (kstrtou8(buf, 16, &synd))
102 if (copy_from_user(buf, data, buf_size)) 118 return -EINVAL;
103 return -EFAULT;
104 buf[buf_size] = 0;
105 119
106 if (!kstrtou8(buf, 16, &synd)) { 120 highbank_mc_err_inject(mci, synd);
107 reg = readl(pdata->mc_vbase + HB_DDR_ECC_OPT);
108 reg &= HB_DDR_ECC_OPT_MODE_MASK;
109 reg |= (synd << HB_DDR_ECC_OPT_XOR_SHIFT) | HB_DDR_ECC_OPT_FWC;
110 writel(reg, pdata->mc_vbase + HB_DDR_ECC_OPT);
111 }
112 121
113 return count; 122 return count;
114} 123}
115 124
116static const struct file_operations highbank_mc_debug_inject_fops = { 125static DEVICE_ATTR(inject_ctrl, S_IWUSR, NULL, highbank_mc_inject_ctrl);
117 .open = simple_open, 126
118 .write = highbank_mc_err_inject_write, 127struct hb_mc_settings {
119 .llseek = generic_file_llseek, 128 int err_offset;
129 int int_offset;
120}; 130};
121 131
122static void highbank_mc_create_debugfs_nodes(struct mem_ctl_info *mci) 132static struct hb_mc_settings hb_settings = {
123{ 133 .err_offset = HB_DDR_ECC_ERR_BASE,
124 if (mci->debugfs) 134 .int_offset = HB_DDR_ECC_INT_BASE,
125 debugfs_create_file("inject_ctrl", S_IWUSR, mci->debugfs, mci, 135};
126 &highbank_mc_debug_inject_fops); 136
127; 137static struct hb_mc_settings mw_settings = {
128} 138 .err_offset = MW_DDR_ECC_ERR_BASE,
129#else 139 .int_offset = MW_DDR_ECC_INT_BASE,
130static void highbank_mc_create_debugfs_nodes(struct mem_ctl_info *mci) 140};
131{} 141
132#endif 142static struct of_device_id hb_ddr_ctrl_of_match[] = {
143 { .compatible = "calxeda,hb-ddr-ctrl", .data = &hb_settings },
144 { .compatible = "calxeda,ecx-2000-ddr-ctrl", .data = &mw_settings },
145 {},
146};
147MODULE_DEVICE_TABLE(of, hb_ddr_ctrl_of_match);
133 148
134static int highbank_mc_probe(struct platform_device *pdev) 149static int highbank_mc_probe(struct platform_device *pdev)
135{ 150{
151 const struct of_device_id *id;
152 const struct hb_mc_settings *settings;
136 struct edac_mc_layer layers[2]; 153 struct edac_mc_layer layers[2];
137 struct mem_ctl_info *mci; 154 struct mem_ctl_info *mci;
138 struct hb_mc_drvdata *drvdata; 155 struct hb_mc_drvdata *drvdata;
139 struct dimm_info *dimm; 156 struct dimm_info *dimm;
140 struct resource *r; 157 struct resource *r;
158 void __iomem *base;
141 u32 control; 159 u32 control;
142 int irq; 160 int irq;
143 int res = 0; 161 int res = 0;
144 162
163 id = of_match_device(hb_ddr_ctrl_of_match, &pdev->dev);
164 if (!id)
165 return -ENODEV;
166
145 layers[0].type = EDAC_MC_LAYER_CHIP_SELECT; 167 layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
146 layers[0].size = 1; 168 layers[0].size = 1;
147 layers[0].is_virt_csrow = true; 169 layers[0].is_virt_csrow = true;
@@ -174,35 +196,31 @@ static int highbank_mc_probe(struct platform_device *pdev)
174 goto err; 196 goto err;
175 } 197 }
176 198
177 drvdata->mc_vbase = devm_ioremap(&pdev->dev, 199 base = devm_ioremap(&pdev->dev, r->start, resource_size(r));
178 r->start, resource_size(r)); 200 if (!base) {
179 if (!drvdata->mc_vbase) {
180 dev_err(&pdev->dev, "Unable to map regs\n"); 201 dev_err(&pdev->dev, "Unable to map regs\n");
181 res = -ENOMEM; 202 res = -ENOMEM;
182 goto err; 203 goto err;
183 } 204 }
184 205
185 control = readl(drvdata->mc_vbase + HB_DDR_ECC_OPT) & 0x3; 206 settings = id->data;
207 drvdata->mc_err_base = base + settings->err_offset;
208 drvdata->mc_int_base = base + settings->int_offset;
209
210 control = readl(drvdata->mc_err_base + HB_DDR_ECC_OPT) & 0x3;
186 if (!control || (control == 0x2)) { 211 if (!control || (control == 0x2)) {
187 dev_err(&pdev->dev, "No ECC present, or ECC disabled\n"); 212 dev_err(&pdev->dev, "No ECC present, or ECC disabled\n");
188 res = -ENODEV; 213 res = -ENODEV;
189 goto err; 214 goto err;
190 } 215 }
191 216
192 irq = platform_get_irq(pdev, 0);
193 res = devm_request_irq(&pdev->dev, irq, highbank_mc_err_handler,
194 0, dev_name(&pdev->dev), mci);
195 if (res < 0) {
196 dev_err(&pdev->dev, "Unable to request irq %d\n", irq);
197 goto err;
198 }
199
200 mci->mtype_cap = MEM_FLAG_DDR3; 217 mci->mtype_cap = MEM_FLAG_DDR3;
201 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED; 218 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
202 mci->edac_cap = EDAC_FLAG_SECDED; 219 mci->edac_cap = EDAC_FLAG_SECDED;
203 mci->mod_name = dev_name(&pdev->dev); 220 mci->mod_name = pdev->dev.driver->name;
204 mci->mod_ver = "1"; 221 mci->mod_ver = "1";
205 mci->ctl_name = dev_name(&pdev->dev); 222 mci->ctl_name = id->compatible;
223 mci->dev_name = dev_name(&pdev->dev);
206 mci->scrub_mode = SCRUB_SW_SRC; 224 mci->scrub_mode = SCRUB_SW_SRC;
207 225
208 /* Only a single 4GB DIMM is supported */ 226 /* Only a single 4GB DIMM is supported */
@@ -217,10 +235,20 @@ static int highbank_mc_probe(struct platform_device *pdev)
217 if (res < 0) 235 if (res < 0)
218 goto err; 236 goto err;
219 237
220 highbank_mc_create_debugfs_nodes(mci); 238 irq = platform_get_irq(pdev, 0);
239 res = devm_request_irq(&pdev->dev, irq, highbank_mc_err_handler,
240 0, dev_name(&pdev->dev), mci);
241 if (res < 0) {
242 dev_err(&pdev->dev, "Unable to request irq %d\n", irq);
243 goto err2;
244 }
245
246 device_create_file(&mci->dev, &dev_attr_inject_ctrl);
221 247
222 devres_close_group(&pdev->dev, NULL); 248 devres_close_group(&pdev->dev, NULL);
223 return 0; 249 return 0;
250err2:
251 edac_mc_del_mc(&pdev->dev);
224err: 252err:
225 devres_release_group(&pdev->dev, NULL); 253 devres_release_group(&pdev->dev, NULL);
226 edac_mc_free(mci); 254 edac_mc_free(mci);
@@ -231,17 +259,12 @@ static int highbank_mc_remove(struct platform_device *pdev)
231{ 259{
232 struct mem_ctl_info *mci = platform_get_drvdata(pdev); 260 struct mem_ctl_info *mci = platform_get_drvdata(pdev);
233 261
262 device_remove_file(&mci->dev, &dev_attr_inject_ctrl);
234 edac_mc_del_mc(&pdev->dev); 263 edac_mc_del_mc(&pdev->dev);
235 edac_mc_free(mci); 264 edac_mc_free(mci);
236 return 0; 265 return 0;
237} 266}
238 267
239static const struct of_device_id hb_ddr_ctrl_of_match[] = {
240 { .compatible = "calxeda,hb-ddr-ctrl", },
241 {},
242};
243MODULE_DEVICE_TABLE(of, hb_ddr_ctrl_of_match);
244
245static struct platform_driver highbank_mc_edac_driver = { 268static struct platform_driver highbank_mc_edac_driver = {
246 .probe = highbank_mc_probe, 269 .probe = highbank_mc_probe,
247 .remove = highbank_mc_remove, 270 .remove = highbank_mc_remove,
diff --git a/drivers/edac/mpc85xx_edac.c b/drivers/edac/mpc85xx_edac.c
index 3eb32f62d72a..fd46b0bd5f2a 100644
--- a/drivers/edac/mpc85xx_edac.c
+++ b/drivers/edac/mpc85xx_edac.c
@@ -327,28 +327,6 @@ err:
327} 327}
328EXPORT_SYMBOL(mpc85xx_pci_err_probe); 328EXPORT_SYMBOL(mpc85xx_pci_err_probe);
329 329
330static int mpc85xx_pci_err_remove(struct platform_device *op)
331{
332 struct edac_pci_ctl_info *pci = dev_get_drvdata(&op->dev);
333 struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
334
335 edac_dbg(0, "\n");
336
337 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_CAP_DR,
338 orig_pci_err_cap_dr);
339
340 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN, orig_pci_err_en);
341
342 edac_pci_del_device(pci->dev);
343
344 if (edac_op_state == EDAC_OPSTATE_INT)
345 irq_dispose_mapping(pdata->irq);
346
347 edac_pci_free_ctl_info(pci);
348
349 return 0;
350}
351
352#endif /* CONFIG_PCI */ 330#endif /* CONFIG_PCI */
353 331
354/**************************** L2 Err device ***************************/ 332/**************************** L2 Err device ***************************/
diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
index 88f60c5fecbc..8472405c5586 100644
--- a/drivers/edac/sb_edac.c
+++ b/drivers/edac/sb_edac.c
@@ -34,7 +34,7 @@ static int probed;
34/* 34/*
35 * Alter this version for the module when modifications are made 35 * Alter this version for the module when modifications are made
36 */ 36 */
37#define SBRIDGE_REVISION " Ver: 1.0.0 " 37#define SBRIDGE_REVISION " Ver: 1.1.0 "
38#define EDAC_MOD_STR "sbridge_edac" 38#define EDAC_MOD_STR "sbridge_edac"
39 39
40/* 40/*
@@ -83,11 +83,17 @@ static int probed;
83#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_ERR3 0x3c77 /* 16.7 */ 83#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_ERR3 0x3c77 /* 16.7 */
84 84
85/* Devices 12 Function 6, Offsets 0x80 to 0xcc */ 85/* Devices 12 Function 6, Offsets 0x80 to 0xcc */
86static const u32 dram_rule[] = { 86static const u32 sbridge_dram_rule[] = {
87 0x80, 0x88, 0x90, 0x98, 0xa0, 87 0x80, 0x88, 0x90, 0x98, 0xa0,
88 0xa8, 0xb0, 0xb8, 0xc0, 0xc8, 88 0xa8, 0xb0, 0xb8, 0xc0, 0xc8,
89}; 89};
90#define MAX_SAD ARRAY_SIZE(dram_rule) 90
91static const u32 ibridge_dram_rule[] = {
92 0x60, 0x68, 0x70, 0x78, 0x80,
93 0x88, 0x90, 0x98, 0xa0, 0xa8,
94 0xb0, 0xb8, 0xc0, 0xc8, 0xd0,
95 0xd8, 0xe0, 0xe8, 0xf0, 0xf8,
96};
91 97
92#define SAD_LIMIT(reg) ((GET_BITFIELD(reg, 6, 25) << 26) | 0x3ffffff) 98#define SAD_LIMIT(reg) ((GET_BITFIELD(reg, 6, 25) << 26) | 0x3ffffff)
93#define DRAM_ATTR(reg) GET_BITFIELD(reg, 2, 3) 99#define DRAM_ATTR(reg) GET_BITFIELD(reg, 2, 3)
@@ -108,43 +114,50 @@ static char *get_dram_attr(u32 reg)
108 } 114 }
109} 115}
110 116
111static const u32 interleave_list[] = { 117static const u32 sbridge_interleave_list[] = {
112 0x84, 0x8c, 0x94, 0x9c, 0xa4, 118 0x84, 0x8c, 0x94, 0x9c, 0xa4,
113 0xac, 0xb4, 0xbc, 0xc4, 0xcc, 119 0xac, 0xb4, 0xbc, 0xc4, 0xcc,
114}; 120};
115#define MAX_INTERLEAVE ARRAY_SIZE(interleave_list) 121
116 122static const u32 ibridge_interleave_list[] = {
117#define SAD_PKG0(reg) GET_BITFIELD(reg, 0, 2) 123 0x64, 0x6c, 0x74, 0x7c, 0x84,
118#define SAD_PKG1(reg) GET_BITFIELD(reg, 3, 5) 124 0x8c, 0x94, 0x9c, 0xa4, 0xac,
119#define SAD_PKG2(reg) GET_BITFIELD(reg, 8, 10) 125 0xb4, 0xbc, 0xc4, 0xcc, 0xd4,
120#define SAD_PKG3(reg) GET_BITFIELD(reg, 11, 13) 126 0xdc, 0xe4, 0xec, 0xf4, 0xfc,
121#define SAD_PKG4(reg) GET_BITFIELD(reg, 16, 18) 127};
122#define SAD_PKG5(reg) GET_BITFIELD(reg, 19, 21) 128
123#define SAD_PKG6(reg) GET_BITFIELD(reg, 24, 26) 129struct interleave_pkg {
124#define SAD_PKG7(reg) GET_BITFIELD(reg, 27, 29) 130 unsigned char start;
125 131 unsigned char end;
126static inline int sad_pkg(u32 reg, int interleave) 132};
133
134static const struct interleave_pkg sbridge_interleave_pkg[] = {
135 { 0, 2 },
136 { 3, 5 },
137 { 8, 10 },
138 { 11, 13 },
139 { 16, 18 },
140 { 19, 21 },
141 { 24, 26 },
142 { 27, 29 },
143};
144
145static const struct interleave_pkg ibridge_interleave_pkg[] = {
146 { 0, 3 },
147 { 4, 7 },
148 { 8, 11 },
149 { 12, 15 },
150 { 16, 19 },
151 { 20, 23 },
152 { 24, 27 },
153 { 28, 31 },
154};
155
156static inline int sad_pkg(const struct interleave_pkg *table, u32 reg,
157 int interleave)
127{ 158{
128 switch (interleave) { 159 return GET_BITFIELD(reg, table[interleave].start,
129 case 0: 160 table[interleave].end);
130 return SAD_PKG0(reg);
131 case 1:
132 return SAD_PKG1(reg);
133 case 2:
134 return SAD_PKG2(reg);
135 case 3:
136 return SAD_PKG3(reg);
137 case 4:
138 return SAD_PKG4(reg);
139 case 5:
140 return SAD_PKG5(reg);
141 case 6:
142 return SAD_PKG6(reg);
143 case 7:
144 return SAD_PKG7(reg);
145 default:
146 return -EINVAL;
147 }
148} 161}
149 162
150/* Devices 12 Function 7 */ 163/* Devices 12 Function 7 */
@@ -262,7 +275,9 @@ static const u32 correrrthrsld[] = {
262 275
263/* Device 17, function 0 */ 276/* Device 17, function 0 */
264 277
265#define RANK_CFG_A 0x0328 278#define SB_RANK_CFG_A 0x0328
279
280#define IB_RANK_CFG_A 0x0320
266 281
267#define IS_RDIMM_ENABLED(reg) GET_BITFIELD(reg, 11, 11) 282#define IS_RDIMM_ENABLED(reg) GET_BITFIELD(reg, 11, 11)
268 283
@@ -273,8 +288,23 @@ static const u32 correrrthrsld[] = {
273#define NUM_CHANNELS 4 288#define NUM_CHANNELS 4
274#define MAX_DIMMS 3 /* Max DIMMS per channel */ 289#define MAX_DIMMS 3 /* Max DIMMS per channel */
275 290
291enum type {
292 SANDY_BRIDGE,
293 IVY_BRIDGE,
294};
295
296struct sbridge_pvt;
276struct sbridge_info { 297struct sbridge_info {
277 u32 mcmtr; 298 enum type type;
299 u32 mcmtr;
300 u32 rankcfgr;
301 u64 (*get_tolm)(struct sbridge_pvt *pvt);
302 u64 (*get_tohm)(struct sbridge_pvt *pvt);
303 const u32 *dram_rule;
304 const u32 *interleave_list;
305 const struct interleave_pkg *interleave_pkg;
306 u8 max_sad;
307 u8 max_interleave;
278}; 308};
279 309
280struct sbridge_channel { 310struct sbridge_channel {
@@ -305,8 +335,9 @@ struct sbridge_dev {
305 335
306struct sbridge_pvt { 336struct sbridge_pvt {
307 struct pci_dev *pci_ta, *pci_ddrio, *pci_ras; 337 struct pci_dev *pci_ta, *pci_ddrio, *pci_ras;
308 struct pci_dev *pci_sad0, *pci_sad1, *pci_ha0; 338 struct pci_dev *pci_sad0, *pci_sad1;
309 struct pci_dev *pci_br; 339 struct pci_dev *pci_ha0, *pci_ha1;
340 struct pci_dev *pci_br0, *pci_br1;
310 struct pci_dev *pci_tad[NUM_CHANNELS]; 341 struct pci_dev *pci_tad[NUM_CHANNELS];
311 342
312 struct sbridge_dev *sbridge_dev; 343 struct sbridge_dev *sbridge_dev;
@@ -364,11 +395,75 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
364 {0,} /* 0 terminated list. */ 395 {0,} /* 0 terminated list. */
365}; 396};
366 397
398/* This changes depending if 1HA or 2HA:
399 * 1HA:
400 * 0x0eb8 (17.0) is DDRIO0
401 * 2HA:
402 * 0x0ebc (17.4) is DDRIO0
403 */
404#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0 0x0eb8
405#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0 0x0ebc
406
407/* pci ids */
408#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0 0x0ea0
409#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA 0x0ea8
410#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS 0x0e71
411#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0 0x0eaa
412#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1 0x0eab
413#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2 0x0eac
414#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3 0x0ead
415#define PCI_DEVICE_ID_INTEL_IBRIDGE_SAD 0x0ec8
416#define PCI_DEVICE_ID_INTEL_IBRIDGE_BR0 0x0ec9
417#define PCI_DEVICE_ID_INTEL_IBRIDGE_BR1 0x0eca
418#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1 0x0e60
419#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TA 0x0e68
420#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_RAS 0x0e79
421#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0 0x0e6a
422#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1 0x0e6b
423
424static const struct pci_id_descr pci_dev_descr_ibridge[] = {
425 /* Processor Home Agent */
426 { PCI_DESCR(14, 0, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0, 0) },
427
428 /* Memory controller */
429 { PCI_DESCR(15, 0, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA, 0) },
430 { PCI_DESCR(15, 1, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS, 0) },
431 { PCI_DESCR(15, 2, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0, 0) },
432 { PCI_DESCR(15, 3, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1, 0) },
433 { PCI_DESCR(15, 4, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2, 0) },
434 { PCI_DESCR(15, 5, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3, 0) },
435
436 /* System Address Decoder */
437 { PCI_DESCR(22, 0, PCI_DEVICE_ID_INTEL_IBRIDGE_SAD, 0) },
438
439 /* Broadcast Registers */
440 { PCI_DESCR(22, 1, PCI_DEVICE_ID_INTEL_IBRIDGE_BR0, 1) },
441 { PCI_DESCR(22, 2, PCI_DEVICE_ID_INTEL_IBRIDGE_BR1, 0) },
442
443 /* Optional, mode 2HA */
444 { PCI_DESCR(28, 0, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1, 1) },
445#if 0
446 { PCI_DESCR(29, 0, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TA, 1) },
447 { PCI_DESCR(29, 1, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_RAS, 1) },
448#endif
449 { PCI_DESCR(29, 2, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0, 1) },
450 { PCI_DESCR(29, 3, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1, 1) },
451
452 { PCI_DESCR(17, 0, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0, 1) },
453 { PCI_DESCR(17, 4, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0, 1) },
454};
455
456static const struct pci_id_table pci_dev_descr_ibridge_table[] = {
457 PCI_ID_TABLE_ENTRY(pci_dev_descr_ibridge),
458 {0,} /* 0 terminated list. */
459};
460
367/* 461/*
368 * pci_device_id table for which devices we are looking for 462 * pci_device_id table for which devices we are looking for
369 */ 463 */
370static DEFINE_PCI_DEVICE_TABLE(sbridge_pci_tbl) = { 464static DEFINE_PCI_DEVICE_TABLE(sbridge_pci_tbl) = {
371 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)}, 465 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
466 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA)},
372 {0,} /* 0 terminated list. */ 467 {0,} /* 0 terminated list. */
373}; 468};
374 469
@@ -458,6 +553,52 @@ static void free_sbridge_dev(struct sbridge_dev *sbridge_dev)
458 kfree(sbridge_dev); 553 kfree(sbridge_dev);
459} 554}
460 555
556static u64 sbridge_get_tolm(struct sbridge_pvt *pvt)
557{
558 u32 reg;
559
560 /* Address range is 32:28 */
561 pci_read_config_dword(pvt->pci_sad1, TOLM, &reg);
562 return GET_TOLM(reg);
563}
564
565static u64 sbridge_get_tohm(struct sbridge_pvt *pvt)
566{
567 u32 reg;
568
569 pci_read_config_dword(pvt->pci_sad1, TOHM, &reg);
570 return GET_TOHM(reg);
571}
572
573static u64 ibridge_get_tolm(struct sbridge_pvt *pvt)
574{
575 u32 reg;
576
577 pci_read_config_dword(pvt->pci_br1, TOLM, &reg);
578
579 return GET_TOLM(reg);
580}
581
582static u64 ibridge_get_tohm(struct sbridge_pvt *pvt)
583{
584 u32 reg;
585
586 pci_read_config_dword(pvt->pci_br1, TOHM, &reg);
587
588 return GET_TOHM(reg);
589}
590
591static inline u8 sad_pkg_socket(u8 pkg)
592{
593 /* on Ivy Bridge, nodeID is SASS, where A is HA and S is node id */
594 return (pkg >> 3) | (pkg & 0x3);
595}
596
597static inline u8 sad_pkg_ha(u8 pkg)
598{
599 return (pkg >> 2) & 0x1;
600}
601
461/**************************************************************************** 602/****************************************************************************
462 Memory check routines 603 Memory check routines
463 ****************************************************************************/ 604 ****************************************************************************/
@@ -520,10 +661,10 @@ static int get_dimm_config(struct mem_ctl_info *mci)
520 enum edac_type mode; 661 enum edac_type mode;
521 enum mem_type mtype; 662 enum mem_type mtype;
522 663
523 pci_read_config_dword(pvt->pci_br, SAD_TARGET, &reg); 664 pci_read_config_dword(pvt->pci_br0, SAD_TARGET, &reg);
524 pvt->sbridge_dev->source_id = SOURCE_ID(reg); 665 pvt->sbridge_dev->source_id = SOURCE_ID(reg);
525 666
526 pci_read_config_dword(pvt->pci_br, SAD_CONTROL, &reg); 667 pci_read_config_dword(pvt->pci_br0, SAD_CONTROL, &reg);
527 pvt->sbridge_dev->node_id = NODE_ID(reg); 668 pvt->sbridge_dev->node_id = NODE_ID(reg);
528 edac_dbg(0, "mc#%d: Node ID: %d, source ID: %d\n", 669 edac_dbg(0, "mc#%d: Node ID: %d, source ID: %d\n",
529 pvt->sbridge_dev->mc, 670 pvt->sbridge_dev->mc,
@@ -558,7 +699,8 @@ static int get_dimm_config(struct mem_ctl_info *mci)
558 } 699 }
559 700
560 if (pvt->pci_ddrio) { 701 if (pvt->pci_ddrio) {
561 pci_read_config_dword(pvt->pci_ddrio, RANK_CFG_A, &reg); 702 pci_read_config_dword(pvt->pci_ddrio, pvt->info.rankcfgr,
703 &reg);
562 if (IS_RDIMM_ENABLED(reg)) { 704 if (IS_RDIMM_ENABLED(reg)) {
563 /* FIXME: Can also be LRDIMM */ 705 /* FIXME: Can also be LRDIMM */
564 edac_dbg(0, "Memory is registered\n"); 706 edac_dbg(0, "Memory is registered\n");
@@ -629,19 +771,14 @@ static void get_memory_layout(const struct mem_ctl_info *mci)
629 * Step 1) Get TOLM/TOHM ranges 771 * Step 1) Get TOLM/TOHM ranges
630 */ 772 */
631 773
632 /* Address range is 32:28 */ 774 pvt->tolm = pvt->info.get_tolm(pvt);
633 pci_read_config_dword(pvt->pci_sad1, TOLM,
634 &reg);
635 pvt->tolm = GET_TOLM(reg);
636 tmp_mb = (1 + pvt->tolm) >> 20; 775 tmp_mb = (1 + pvt->tolm) >> 20;
637 776
638 mb = div_u64_rem(tmp_mb, 1000, &kb); 777 mb = div_u64_rem(tmp_mb, 1000, &kb);
639 edac_dbg(0, "TOLM: %u.%03u GB (0x%016Lx)\n", mb, kb, (u64)pvt->tolm); 778 edac_dbg(0, "TOLM: %u.%03u GB (0x%016Lx)\n", mb, kb, (u64)pvt->tolm);
640 779
641 /* Address range is already 45:25 */ 780 /* Address range is already 45:25 */
642 pci_read_config_dword(pvt->pci_sad1, TOHM, 781 pvt->tohm = pvt->info.get_tohm(pvt);
643 &reg);
644 pvt->tohm = GET_TOHM(reg);
645 tmp_mb = (1 + pvt->tohm) >> 20; 782 tmp_mb = (1 + pvt->tohm) >> 20;
646 783
647 mb = div_u64_rem(tmp_mb, 1000, &kb); 784 mb = div_u64_rem(tmp_mb, 1000, &kb);
@@ -654,9 +791,9 @@ static void get_memory_layout(const struct mem_ctl_info *mci)
654 * algorithm bellow. 791 * algorithm bellow.
655 */ 792 */
656 prv = 0; 793 prv = 0;
657 for (n_sads = 0; n_sads < MAX_SAD; n_sads++) { 794 for (n_sads = 0; n_sads < pvt->info.max_sad; n_sads++) {
658 /* SAD_LIMIT Address range is 45:26 */ 795 /* SAD_LIMIT Address range is 45:26 */
659 pci_read_config_dword(pvt->pci_sad0, dram_rule[n_sads], 796 pci_read_config_dword(pvt->pci_sad0, pvt->info.dram_rule[n_sads],
660 &reg); 797 &reg);
661 limit = SAD_LIMIT(reg); 798 limit = SAD_LIMIT(reg);
662 799
@@ -677,15 +814,16 @@ static void get_memory_layout(const struct mem_ctl_info *mci)
677 reg); 814 reg);
678 prv = limit; 815 prv = limit;
679 816
680 pci_read_config_dword(pvt->pci_sad0, interleave_list[n_sads], 817 pci_read_config_dword(pvt->pci_sad0, pvt->info.interleave_list[n_sads],
681 &reg); 818 &reg);
682 sad_interl = sad_pkg(reg, 0); 819 sad_interl = sad_pkg(pvt->info.interleave_pkg, reg, 0);
683 for (j = 0; j < 8; j++) { 820 for (j = 0; j < 8; j++) {
684 if (j > 0 && sad_interl == sad_pkg(reg, j)) 821 u32 pkg = sad_pkg(pvt->info.interleave_pkg, reg, j);
822 if (j > 0 && sad_interl == pkg)
685 break; 823 break;
686 824
687 edac_dbg(0, "SAD#%d, interleave #%d: %d\n", 825 edac_dbg(0, "SAD#%d, interleave #%d: %d\n",
688 n_sads, j, sad_pkg(reg, j)); 826 n_sads, j, pkg);
689 } 827 }
690 } 828 }
691 829
@@ -797,12 +935,13 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
797{ 935{
798 struct mem_ctl_info *new_mci; 936 struct mem_ctl_info *new_mci;
799 struct sbridge_pvt *pvt = mci->pvt_info; 937 struct sbridge_pvt *pvt = mci->pvt_info;
938 struct pci_dev *pci_ha;
800 int n_rir, n_sads, n_tads, sad_way, sck_xch; 939 int n_rir, n_sads, n_tads, sad_way, sck_xch;
801 int sad_interl, idx, base_ch; 940 int sad_interl, idx, base_ch;
802 int interleave_mode; 941 int interleave_mode;
803 unsigned sad_interleave[MAX_INTERLEAVE]; 942 unsigned sad_interleave[pvt->info.max_interleave];
804 u32 reg; 943 u32 reg;
805 u8 ch_way,sck_way; 944 u8 ch_way, sck_way, pkg, sad_ha = 0;
806 u32 tad_offset; 945 u32 tad_offset;
807 u32 rir_way; 946 u32 rir_way;
808 u32 mb, kb; 947 u32 mb, kb;
@@ -828,8 +967,8 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
828 /* 967 /*
829 * Step 1) Get socket 968 * Step 1) Get socket
830 */ 969 */
831 for (n_sads = 0; n_sads < MAX_SAD; n_sads++) { 970 for (n_sads = 0; n_sads < pvt->info.max_sad; n_sads++) {
832 pci_read_config_dword(pvt->pci_sad0, dram_rule[n_sads], 971 pci_read_config_dword(pvt->pci_sad0, pvt->info.dram_rule[n_sads],
833 &reg); 972 &reg);
834 973
835 if (!DRAM_RULE_ENABLE(reg)) 974 if (!DRAM_RULE_ENABLE(reg))
@@ -844,53 +983,65 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
844 break; 983 break;
845 prv = limit; 984 prv = limit;
846 } 985 }
847 if (n_sads == MAX_SAD) { 986 if (n_sads == pvt->info.max_sad) {
848 sprintf(msg, "Can't discover the memory socket"); 987 sprintf(msg, "Can't discover the memory socket");
849 return -EINVAL; 988 return -EINVAL;
850 } 989 }
851 *area_type = get_dram_attr(reg); 990 *area_type = get_dram_attr(reg);
852 interleave_mode = INTERLEAVE_MODE(reg); 991 interleave_mode = INTERLEAVE_MODE(reg);
853 992
854 pci_read_config_dword(pvt->pci_sad0, interleave_list[n_sads], 993 pci_read_config_dword(pvt->pci_sad0, pvt->info.interleave_list[n_sads],
855 &reg); 994 &reg);
856 sad_interl = sad_pkg(reg, 0); 995
857 for (sad_way = 0; sad_way < 8; sad_way++) { 996 if (pvt->info.type == SANDY_BRIDGE) {
858 if (sad_way > 0 && sad_interl == sad_pkg(reg, sad_way)) 997 sad_interl = sad_pkg(pvt->info.interleave_pkg, reg, 0);
998 for (sad_way = 0; sad_way < 8; sad_way++) {
999 u32 pkg = sad_pkg(pvt->info.interleave_pkg, reg, sad_way);
1000 if (sad_way > 0 && sad_interl == pkg)
1001 break;
1002 sad_interleave[sad_way] = pkg;
1003 edac_dbg(0, "SAD interleave #%d: %d\n",
1004 sad_way, sad_interleave[sad_way]);
1005 }
1006 edac_dbg(0, "mc#%d: Error detected on SAD#%d: address 0x%016Lx < 0x%016Lx, Interleave [%d:6]%s\n",
1007 pvt->sbridge_dev->mc,
1008 n_sads,
1009 addr,
1010 limit,
1011 sad_way + 7,
1012 !interleave_mode ? "" : "XOR[18:16]");
1013 if (interleave_mode)
1014 idx = ((addr >> 6) ^ (addr >> 16)) & 7;
1015 else
1016 idx = (addr >> 6) & 7;
1017 switch (sad_way) {
1018 case 1:
1019 idx = 0;
859 break; 1020 break;
860 sad_interleave[sad_way] = sad_pkg(reg, sad_way); 1021 case 2:
861 edac_dbg(0, "SAD interleave #%d: %d\n", 1022 idx = idx & 1;
862 sad_way, sad_interleave[sad_way]); 1023 break;
863 } 1024 case 4:
864 edac_dbg(0, "mc#%d: Error detected on SAD#%d: address 0x%016Lx < 0x%016Lx, Interleave [%d:6]%s\n", 1025 idx = idx & 3;
865 pvt->sbridge_dev->mc, 1026 break;
866 n_sads, 1027 case 8:
867 addr, 1028 break;
868 limit, 1029 default:
869 sad_way + 7, 1030 sprintf(msg, "Can't discover socket interleave");
870 interleave_mode ? "" : "XOR[18:16]"); 1031 return -EINVAL;
871 if (interleave_mode) 1032 }
872 idx = ((addr >> 6) ^ (addr >> 16)) & 7; 1033 *socket = sad_interleave[idx];
873 else 1034 edac_dbg(0, "SAD interleave index: %d (wayness %d) = CPU socket %d\n",
1035 idx, sad_way, *socket);
1036 } else {
1037 /* Ivy Bridge's SAD mode doesn't support XOR interleave mode */
874 idx = (addr >> 6) & 7; 1038 idx = (addr >> 6) & 7;
875 switch (sad_way) { 1039 pkg = sad_pkg(pvt->info.interleave_pkg, reg, idx);
876 case 1: 1040 *socket = sad_pkg_socket(pkg);
877 idx = 0; 1041 sad_ha = sad_pkg_ha(pkg);
878 break; 1042 edac_dbg(0, "SAD interleave package: %d = CPU socket %d, HA %d\n",
879 case 2: 1043 idx, *socket, sad_ha);
880 idx = idx & 1;
881 break;
882 case 4:
883 idx = idx & 3;
884 break;
885 case 8:
886 break;
887 default:
888 sprintf(msg, "Can't discover socket interleave");
889 return -EINVAL;
890 } 1044 }
891 *socket = sad_interleave[idx];
892 edac_dbg(0, "SAD interleave index: %d (wayness %d) = CPU socket %d\n",
893 idx, sad_way, *socket);
894 1045
895 /* 1046 /*
896 * Move to the proper node structure, in order to access the 1047 * Move to the proper node structure, in order to access the
@@ -909,9 +1060,16 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
909 * Step 2) Get memory channel 1060 * Step 2) Get memory channel
910 */ 1061 */
911 prv = 0; 1062 prv = 0;
1063 if (pvt->info.type == SANDY_BRIDGE)
1064 pci_ha = pvt->pci_ha0;
1065 else {
1066 if (sad_ha)
1067 pci_ha = pvt->pci_ha1;
1068 else
1069 pci_ha = pvt->pci_ha0;
1070 }
912 for (n_tads = 0; n_tads < MAX_TAD; n_tads++) { 1071 for (n_tads = 0; n_tads < MAX_TAD; n_tads++) {
913 pci_read_config_dword(pvt->pci_ha0, tad_dram_rule[n_tads], 1072 pci_read_config_dword(pci_ha, tad_dram_rule[n_tads], &reg);
914 &reg);
915 limit = TAD_LIMIT(reg); 1073 limit = TAD_LIMIT(reg);
916 if (limit <= prv) { 1074 if (limit <= prv) {
917 sprintf(msg, "Can't discover the memory channel"); 1075 sprintf(msg, "Can't discover the memory channel");
@@ -921,14 +1079,13 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
921 break; 1079 break;
922 prv = limit; 1080 prv = limit;
923 } 1081 }
1082 if (n_tads == MAX_TAD) {
1083 sprintf(msg, "Can't discover the memory channel");
1084 return -EINVAL;
1085 }
1086
924 ch_way = TAD_CH(reg) + 1; 1087 ch_way = TAD_CH(reg) + 1;
925 sck_way = TAD_SOCK(reg) + 1; 1088 sck_way = TAD_SOCK(reg) + 1;
926 /*
927 * FIXME: Is it right to always use channel 0 for offsets?
928 */
929 pci_read_config_dword(pvt->pci_tad[0],
930 tad_ch_nilv_offset[n_tads],
931 &tad_offset);
932 1089
933 if (ch_way == 3) 1090 if (ch_way == 3)
934 idx = addr >> 6; 1091 idx = addr >> 6;
@@ -958,6 +1115,10 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
958 } 1115 }
959 *channel_mask = 1 << base_ch; 1116 *channel_mask = 1 << base_ch;
960 1117
1118 pci_read_config_dword(pvt->pci_tad[base_ch],
1119 tad_ch_nilv_offset[n_tads],
1120 &tad_offset);
1121
961 if (pvt->is_mirrored) { 1122 if (pvt->is_mirrored) {
962 *channel_mask |= 1 << ((base_ch + 2) % 4); 1123 *channel_mask |= 1 << ((base_ch + 2) % 4);
963 switch(ch_way) { 1124 switch(ch_way) {
@@ -1091,12 +1252,6 @@ static void sbridge_put_all_devices(void)
1091 } 1252 }
1092} 1253}
1093 1254
1094/*
1095 * sbridge_get_all_devices Find and perform 'get' operation on the MCH's
1096 * device/functions we want to reference for this driver
1097 *
1098 * Need to 'get' device 16 func 1 and func 2
1099 */
1100static int sbridge_get_onedevice(struct pci_dev **prev, 1255static int sbridge_get_onedevice(struct pci_dev **prev,
1101 u8 *num_mc, 1256 u8 *num_mc,
1102 const struct pci_id_table *table, 1257 const struct pci_id_table *table,
@@ -1198,11 +1353,21 @@ static int sbridge_get_onedevice(struct pci_dev **prev,
1198 return 0; 1353 return 0;
1199} 1354}
1200 1355
1201static int sbridge_get_all_devices(u8 *num_mc) 1356/*
1357 * sbridge_get_all_devices - Find and perform 'get' operation on the MCH's
1358 * device/functions we want to reference for this driver.
1359 * Need to 'get' device 16 func 1 and func 2.
1360 * @num_mc: pointer to the memory controllers count, to be incremented in case
1361 * of success.
1362 * @table: model specific table
1363 *
1364 * returns 0 in case of success or error code
1365 */
1366static int sbridge_get_all_devices(u8 *num_mc,
1367 const struct pci_id_table *table)
1202{ 1368{
1203 int i, rc; 1369 int i, rc;
1204 struct pci_dev *pdev = NULL; 1370 struct pci_dev *pdev = NULL;
1205 const struct pci_id_table *table = pci_dev_descr_sbridge_table;
1206 1371
1207 while (table && table->descr) { 1372 while (table && table->descr) {
1208 for (i = 0; i < table->n_devs; i++) { 1373 for (i = 0; i < table->n_devs; i++) {
@@ -1226,8 +1391,8 @@ static int sbridge_get_all_devices(u8 *num_mc)
1226 return 0; 1391 return 0;
1227} 1392}
1228 1393
1229static int mci_bind_devs(struct mem_ctl_info *mci, 1394static int sbridge_mci_bind_devs(struct mem_ctl_info *mci,
1230 struct sbridge_dev *sbridge_dev) 1395 struct sbridge_dev *sbridge_dev)
1231{ 1396{
1232 struct sbridge_pvt *pvt = mci->pvt_info; 1397 struct sbridge_pvt *pvt = mci->pvt_info;
1233 struct pci_dev *pdev; 1398 struct pci_dev *pdev;
@@ -1255,7 +1420,7 @@ static int mci_bind_devs(struct mem_ctl_info *mci,
1255 case 13: 1420 case 13:
1256 switch (func) { 1421 switch (func) {
1257 case 6: 1422 case 6:
1258 pvt->pci_br = pdev; 1423 pvt->pci_br0 = pdev;
1259 break; 1424 break;
1260 default: 1425 default:
1261 goto error; 1426 goto error;
@@ -1329,6 +1494,131 @@ error:
1329 return -EINVAL; 1494 return -EINVAL;
1330} 1495}
1331 1496
1497static int ibridge_mci_bind_devs(struct mem_ctl_info *mci,
1498 struct sbridge_dev *sbridge_dev)
1499{
1500 struct sbridge_pvt *pvt = mci->pvt_info;
1501 struct pci_dev *pdev, *tmp;
1502 int i, func, slot;
1503 bool mode_2ha = false;
1504
1505 tmp = pci_get_device(PCI_VENDOR_ID_INTEL,
1506 PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1, NULL);
1507 if (tmp) {
1508 mode_2ha = true;
1509 pci_dev_put(tmp);
1510 }
1511
1512 for (i = 0; i < sbridge_dev->n_devs; i++) {
1513 pdev = sbridge_dev->pdev[i];
1514 if (!pdev)
1515 continue;
1516 slot = PCI_SLOT(pdev->devfn);
1517 func = PCI_FUNC(pdev->devfn);
1518
1519 switch (slot) {
1520 case 14:
1521 if (func == 0) {
1522 pvt->pci_ha0 = pdev;
1523 break;
1524 }
1525 goto error;
1526 case 15:
1527 switch (func) {
1528 case 0:
1529 pvt->pci_ta = pdev;
1530 break;
1531 case 1:
1532 pvt->pci_ras = pdev;
1533 break;
1534 case 4:
1535 case 5:
1536 /* if we have 2 HAs active, channels 2 and 3
1537 * are in other device */
1538 if (mode_2ha)
1539 break;
1540 /* fall through */
1541 case 2:
1542 case 3:
1543 pvt->pci_tad[func - 2] = pdev;
1544 break;
1545 default:
1546 goto error;
1547 }
1548 break;
1549 case 17:
1550 if (func == 4) {
1551 pvt->pci_ddrio = pdev;
1552 break;
1553 } else if (func == 0) {
1554 if (!mode_2ha)
1555 pvt->pci_ddrio = pdev;
1556 break;
1557 }
1558 goto error;
1559 case 22:
1560 switch (func) {
1561 case 0:
1562 pvt->pci_sad0 = pdev;
1563 break;
1564 case 1:
1565 pvt->pci_br0 = pdev;
1566 break;
1567 case 2:
1568 pvt->pci_br1 = pdev;
1569 break;
1570 default:
1571 goto error;
1572 }
1573 break;
1574 case 28:
1575 if (func == 0) {
1576 pvt->pci_ha1 = pdev;
1577 break;
1578 }
1579 goto error;
1580 case 29:
1581 /* we shouldn't have this device if we have just one
1582 * HA present */
1583 WARN_ON(!mode_2ha);
1584 if (func == 2 || func == 3) {
1585 pvt->pci_tad[func] = pdev;
1586 break;
1587 }
1588 goto error;
1589 default:
1590 goto error;
1591 }
1592
1593 edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n",
1594 sbridge_dev->bus,
1595 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
1596 pdev);
1597 }
1598
1599 /* Check if everything were registered */
1600 if (!pvt->pci_sad0 || !pvt->pci_ha0 || !pvt->pci_br0 ||
1601 !pvt->pci_br1 || !pvt->pci_tad || !pvt->pci_ras ||
1602 !pvt->pci_ta)
1603 goto enodev;
1604
1605 for (i = 0; i < NUM_CHANNELS; i++) {
1606 if (!pvt->pci_tad[i])
1607 goto enodev;
1608 }
1609 return 0;
1610
1611enodev:
1612 sbridge_printk(KERN_ERR, "Some needed devices are missing\n");
1613 return -ENODEV;
1614
1615error:
1616 sbridge_printk(KERN_ERR,
1617 "Device %d, function %d is out of the expected range\n",
1618 slot, func);
1619 return -EINVAL;
1620}
1621
1332/**************************************************************************** 1622/****************************************************************************
1333 Error check routines 1623 Error check routines
1334 ****************************************************************************/ 1624 ****************************************************************************/
@@ -1349,7 +1639,7 @@ static void sbridge_mce_output_error(struct mem_ctl_info *mci,
1349 bool ripv = GET_BITFIELD(m->mcgstatus, 0, 0); 1639 bool ripv = GET_BITFIELD(m->mcgstatus, 0, 0);
1350 bool overflow = GET_BITFIELD(m->status, 62, 62); 1640 bool overflow = GET_BITFIELD(m->status, 62, 62);
1351 bool uncorrected_error = GET_BITFIELD(m->status, 61, 61); 1641 bool uncorrected_error = GET_BITFIELD(m->status, 61, 61);
1352 bool recoverable = GET_BITFIELD(m->status, 56, 56); 1642 bool recoverable;
1353 u32 core_err_cnt = GET_BITFIELD(m->status, 38, 52); 1643 u32 core_err_cnt = GET_BITFIELD(m->status, 38, 52);
1354 u32 mscod = GET_BITFIELD(m->status, 16, 31); 1644 u32 mscod = GET_BITFIELD(m->status, 16, 31);
1355 u32 errcode = GET_BITFIELD(m->status, 0, 15); 1645 u32 errcode = GET_BITFIELD(m->status, 0, 15);
@@ -1360,6 +1650,11 @@ static void sbridge_mce_output_error(struct mem_ctl_info *mci,
1360 int rc, dimm; 1650 int rc, dimm;
1361 char *area_type = NULL; 1651 char *area_type = NULL;
1362 1652
1653 if (pvt->info.type == IVY_BRIDGE)
1654 recoverable = true;
1655 else
1656 recoverable = GET_BITFIELD(m->status, 56, 56);
1657
1363 if (uncorrected_error) { 1658 if (uncorrected_error) {
1364 if (ripv) { 1659 if (ripv) {
1365 type = "FATAL"; 1660 type = "FATAL";
@@ -1409,6 +1704,10 @@ static void sbridge_mce_output_error(struct mem_ctl_info *mci,
1409 } 1704 }
1410 } 1705 }
1411 1706
1707 /* Only decode errors with an valid address (ADDRV) */
1708 if (!GET_BITFIELD(m->status, 58, 58))
1709 return;
1710
1412 rc = get_memory_error_data(mci, m->addr, &socket, 1711 rc = get_memory_error_data(mci, m->addr, &socket,
1413 &channel_mask, &rank, &area_type, msg); 1712 &channel_mask, &rank, &area_type, msg);
1414 if (rc < 0) 1713 if (rc < 0)
@@ -1614,11 +1913,12 @@ static void sbridge_unregister_mci(struct sbridge_dev *sbridge_dev)
1614 sbridge_dev->mci = NULL; 1913 sbridge_dev->mci = NULL;
1615} 1914}
1616 1915
1617static int sbridge_register_mci(struct sbridge_dev *sbridge_dev) 1916static int sbridge_register_mci(struct sbridge_dev *sbridge_dev, enum type type)
1618{ 1917{
1619 struct mem_ctl_info *mci; 1918 struct mem_ctl_info *mci;
1620 struct edac_mc_layer layers[2]; 1919 struct edac_mc_layer layers[2];
1621 struct sbridge_pvt *pvt; 1920 struct sbridge_pvt *pvt;
1921 struct pci_dev *pdev = sbridge_dev->pdev[0];
1622 int rc; 1922 int rc;
1623 1923
1624 /* Check the number of active and not disabled channels */ 1924 /* Check the number of active and not disabled channels */
@@ -1640,7 +1940,7 @@ static int sbridge_register_mci(struct sbridge_dev *sbridge_dev)
1640 return -ENOMEM; 1940 return -ENOMEM;
1641 1941
1642 edac_dbg(0, "MC: mci = %p, dev = %p\n", 1942 edac_dbg(0, "MC: mci = %p, dev = %p\n",
1643 mci, &sbridge_dev->pdev[0]->dev); 1943 mci, &pdev->dev);
1644 1944
1645 pvt = mci->pvt_info; 1945 pvt = mci->pvt_info;
1646 memset(pvt, 0, sizeof(*pvt)); 1946 memset(pvt, 0, sizeof(*pvt));
@@ -1654,24 +1954,52 @@ static int sbridge_register_mci(struct sbridge_dev *sbridge_dev)
1654 mci->edac_cap = EDAC_FLAG_NONE; 1954 mci->edac_cap = EDAC_FLAG_NONE;
1655 mci->mod_name = "sbridge_edac.c"; 1955 mci->mod_name = "sbridge_edac.c";
1656 mci->mod_ver = SBRIDGE_REVISION; 1956 mci->mod_ver = SBRIDGE_REVISION;
1657 mci->ctl_name = kasprintf(GFP_KERNEL, "Sandy Bridge Socket#%d", mci->mc_idx); 1957 mci->dev_name = pci_name(pdev);
1658 mci->dev_name = pci_name(sbridge_dev->pdev[0]);
1659 mci->ctl_page_to_phys = NULL; 1958 mci->ctl_page_to_phys = NULL;
1660 1959
1661 /* Set the function pointer to an actual operation function */ 1960 /* Set the function pointer to an actual operation function */
1662 mci->edac_check = sbridge_check_error; 1961 mci->edac_check = sbridge_check_error;
1663 1962
1664 /* Store pci devices at mci for faster access */ 1963 pvt->info.type = type;
1665 rc = mci_bind_devs(mci, sbridge_dev); 1964 if (type == IVY_BRIDGE) {
1666 if (unlikely(rc < 0)) 1965 pvt->info.rankcfgr = IB_RANK_CFG_A;
1667 goto fail0; 1966 pvt->info.get_tolm = ibridge_get_tolm;
1967 pvt->info.get_tohm = ibridge_get_tohm;
1968 pvt->info.dram_rule = ibridge_dram_rule;
1969 pvt->info.max_sad = ARRAY_SIZE(ibridge_dram_rule);
1970 pvt->info.interleave_list = ibridge_interleave_list;
1971 pvt->info.max_interleave = ARRAY_SIZE(ibridge_interleave_list);
1972 pvt->info.interleave_pkg = ibridge_interleave_pkg;
1973 mci->ctl_name = kasprintf(GFP_KERNEL, "Ivy Bridge Socket#%d", mci->mc_idx);
1974
1975 /* Store pci devices at mci for faster access */
1976 rc = ibridge_mci_bind_devs(mci, sbridge_dev);
1977 if (unlikely(rc < 0))
1978 goto fail0;
1979 } else {
1980 pvt->info.rankcfgr = SB_RANK_CFG_A;
1981 pvt->info.get_tolm = sbridge_get_tolm;
1982 pvt->info.get_tohm = sbridge_get_tohm;
1983 pvt->info.dram_rule = sbridge_dram_rule;
1984 pvt->info.max_sad = ARRAY_SIZE(sbridge_dram_rule);
1985 pvt->info.interleave_list = sbridge_interleave_list;
1986 pvt->info.max_interleave = ARRAY_SIZE(sbridge_interleave_list);
1987 pvt->info.interleave_pkg = sbridge_interleave_pkg;
1988 mci->ctl_name = kasprintf(GFP_KERNEL, "Sandy Bridge Socket#%d", mci->mc_idx);
1989
1990 /* Store pci devices at mci for faster access */
1991 rc = sbridge_mci_bind_devs(mci, sbridge_dev);
1992 if (unlikely(rc < 0))
1993 goto fail0;
1994 }
1995
1668 1996
1669 /* Get dimm basic config and the memory layout */ 1997 /* Get dimm basic config and the memory layout */
1670 get_dimm_config(mci); 1998 get_dimm_config(mci);
1671 get_memory_layout(mci); 1999 get_memory_layout(mci);
1672 2000
1673 /* record ptr to the generic device */ 2001 /* record ptr to the generic device */
1674 mci->pdev = &sbridge_dev->pdev[0]->dev; 2002 mci->pdev = &pdev->dev;
1675 2003
1676 /* add this new MC control structure to EDAC's list of MCs */ 2004 /* add this new MC control structure to EDAC's list of MCs */
1677 if (unlikely(edac_mc_add_mc(mci))) { 2005 if (unlikely(edac_mc_add_mc(mci))) {
@@ -1702,6 +2030,7 @@ static int sbridge_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1702 int rc; 2030 int rc;
1703 u8 mc, num_mc = 0; 2031 u8 mc, num_mc = 0;
1704 struct sbridge_dev *sbridge_dev; 2032 struct sbridge_dev *sbridge_dev;
2033 enum type type;
1705 2034
1706 /* get the pci devices we want to reserve for our use */ 2035 /* get the pci devices we want to reserve for our use */
1707 mutex_lock(&sbridge_edac_lock); 2036 mutex_lock(&sbridge_edac_lock);
@@ -1715,7 +2044,13 @@ static int sbridge_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1715 } 2044 }
1716 probed++; 2045 probed++;
1717 2046
1718 rc = sbridge_get_all_devices(&num_mc); 2047 if (pdev->device == PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA) {
2048 rc = sbridge_get_all_devices(&num_mc, pci_dev_descr_ibridge_table);
2049 type = IVY_BRIDGE;
2050 } else {
2051 rc = sbridge_get_all_devices(&num_mc, pci_dev_descr_sbridge_table);
2052 type = SANDY_BRIDGE;
2053 }
1719 if (unlikely(rc < 0)) 2054 if (unlikely(rc < 0))
1720 goto fail0; 2055 goto fail0;
1721 mc = 0; 2056 mc = 0;
@@ -1724,7 +2059,7 @@ static int sbridge_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1724 edac_dbg(0, "Registering MC#%d (%d of %d)\n", 2059 edac_dbg(0, "Registering MC#%d (%d of %d)\n",
1725 mc, mc + 1, num_mc); 2060 mc, mc + 1, num_mc);
1726 sbridge_dev->mc = mc++; 2061 sbridge_dev->mc = mc++;
1727 rc = sbridge_register_mci(sbridge_dev); 2062 rc = sbridge_register_mci(sbridge_dev, type);
1728 if (unlikely(rc < 0)) 2063 if (unlikely(rc < 0))
1729 goto fail1; 2064 goto fail1;
1730 } 2065 }
@@ -1839,5 +2174,5 @@ MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
1839MODULE_LICENSE("GPL"); 2174MODULE_LICENSE("GPL");
1840MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>"); 2175MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
1841MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)"); 2176MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
1842MODULE_DESCRIPTION("MC Driver for Intel Sandy Bridge memory controllers - " 2177MODULE_DESCRIPTION("MC Driver for Intel Sandy Bridge and Ivy Bridge memory controllers - "
1843 SBRIDGE_REVISION); 2178 SBRIDGE_REVISION);
diff --git a/drivers/gpu/drm/drm_encoder_slave.c b/drivers/gpu/drm/drm_encoder_slave.c
index 0cfb60f54766..d18b88b755c3 100644
--- a/drivers/gpu/drm/drm_encoder_slave.c
+++ b/drivers/gpu/drm/drm_encoder_slave.c
@@ -67,12 +67,12 @@ int drm_i2c_encoder_init(struct drm_device *dev,
67 goto fail; 67 goto fail;
68 } 68 }
69 69
70 if (!client->driver) { 70 if (!client->dev.driver) {
71 err = -ENODEV; 71 err = -ENODEV;
72 goto fail_unregister; 72 goto fail_unregister;
73 } 73 }
74 74
75 module = client->driver->driver.owner; 75 module = client->dev.driver->owner;
76 if (!try_module_get(module)) { 76 if (!try_module_get(module)) {
77 err = -ENODEV; 77 err = -ENODEV;
78 goto fail_unregister; 78 goto fail_unregister;
@@ -80,7 +80,7 @@ int drm_i2c_encoder_init(struct drm_device *dev,
80 80
81 encoder->bus_priv = client; 81 encoder->bus_priv = client;
82 82
83 encoder_drv = to_drm_i2c_encoder_driver(client->driver); 83 encoder_drv = to_drm_i2c_encoder_driver(to_i2c_driver(client->dev.driver));
84 84
85 err = encoder_drv->encoder_init(client, dev, encoder); 85 err = encoder_drv->encoder_init(client, dev, encoder);
86 if (err) 86 if (err)
@@ -111,7 +111,7 @@ void drm_i2c_encoder_destroy(struct drm_encoder *drm_encoder)
111{ 111{
112 struct drm_encoder_slave *encoder = to_encoder_slave(drm_encoder); 112 struct drm_encoder_slave *encoder = to_encoder_slave(drm_encoder);
113 struct i2c_client *client = drm_i2c_encoder_get_client(drm_encoder); 113 struct i2c_client *client = drm_i2c_encoder_get_client(drm_encoder);
114 struct module *module = client->driver->driver.owner; 114 struct module *module = client->dev.driver->owner;
115 115
116 i2c_unregister_device(client); 116 i2c_unregister_device(client);
117 encoder->bus_priv = NULL; 117 encoder->bus_priv = NULL;
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/ic.c b/drivers/gpu/drm/nouveau/core/subdev/therm/ic.c
index 13b850076443..e44ed7b93c6d 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/ic.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/ic.c
@@ -41,7 +41,8 @@ probe_monitoring_device(struct nouveau_i2c_port *i2c,
41 if (!client) 41 if (!client)
42 return false; 42 return false;
43 43
44 if (!client->driver || client->driver->detect(client, info)) { 44 if (!client->dev.driver ||
45 to_i2c_driver(client->dev.driver)->detect(client, info)) {
45 i2c_unregister_device(client); 46 i2c_unregister_device(client);
46 return false; 47 return false;
47 } 48 }
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index cdcbd8368ed3..3b26129f6055 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -109,6 +109,7 @@ config I2C_I801
109 Avoton (SOC) 109 Avoton (SOC)
110 Wellsburg (PCH) 110 Wellsburg (PCH)
111 Coleto Creek (PCH) 111 Coleto Creek (PCH)
112 Wildcat Point-LP (PCH)
112 113
113 This driver can also be built as a module. If so, the module 114 This driver can also be built as a module. If so, the module
114 will be called i2c-i801. 115 will be called i2c-i801.
@@ -345,6 +346,16 @@ config I2C_BCM2835
345 This support is also available as a module. If so, the module 346 This support is also available as a module. If so, the module
346 will be called i2c-bcm2835. 347 will be called i2c-bcm2835.
347 348
349config I2C_BCM_KONA
350 tristate "BCM Kona I2C adapter"
351 depends on ARCH_BCM_MOBILE
352 default y
353 help
354 If you say yes to this option, support will be included for the
355 I2C interface on the Broadcom Kona family of processors.
356
357 If you do not need KONA I2C inteface, say N.
358
348config I2C_BLACKFIN_TWI 359config I2C_BLACKFIN_TWI
349 tristate "Blackfin TWI I2C support" 360 tristate "Blackfin TWI I2C support"
350 depends on BLACKFIN 361 depends on BLACKFIN
@@ -436,6 +447,13 @@ config I2C_EG20T
436 ML7213/ML7223/ML7831 is companion chip for Intel Atom E6xx series. 447 ML7213/ML7223/ML7831 is companion chip for Intel Atom E6xx series.
437 ML7213/ML7223/ML7831 is completely compatible for Intel EG20T PCH. 448 ML7213/ML7223/ML7831 is completely compatible for Intel EG20T PCH.
438 449
450config I2C_EXYNOS5
451 tristate "Exynos5 high-speed I2C driver"
452 depends on ARCH_EXYNOS5 && OF
453 help
454 Say Y here to include support for high-speed I2C controller in the
455 Exynos5 based Samsung SoCs.
456
439config I2C_GPIO 457config I2C_GPIO
440 tristate "GPIO-based bitbanging I2C" 458 tristate "GPIO-based bitbanging I2C"
441 depends on GPIOLIB 459 depends on GPIOLIB
@@ -665,7 +683,7 @@ config I2C_SH7760
665 683
666config I2C_SH_MOBILE 684config I2C_SH_MOBILE
667 tristate "SuperH Mobile I2C Controller" 685 tristate "SuperH Mobile I2C Controller"
668 depends on SUPERH || ARCH_SHMOBILE 686 depends on SUPERH || ARM || COMPILE_TEST
669 help 687 help
670 If you say yes to this option, support will be included for the 688 If you say yes to this option, support will be included for the
671 built-in I2C interface on the Renesas SH-Mobile processor. 689 built-in I2C interface on the Renesas SH-Mobile processor.
@@ -695,6 +713,16 @@ config I2C_SIRF
695 This driver can also be built as a module. If so, the module 713 This driver can also be built as a module. If so, the module
696 will be called i2c-sirf. 714 will be called i2c-sirf.
697 715
716config I2C_ST
717 tristate "STMicroelectronics SSC I2C support"
718 depends on ARCH_STI
719 help
720 Enable this option to add support for STMicroelectronics SoCs
721 hardware SSC (Synchronous Serial Controller) as an I2C controller.
722
723 This driver can also be built as module. If so, the module
724 will be called i2c-st.
725
698config I2C_STU300 726config I2C_STU300
699 tristate "ST Microelectronics DDC I2C interface" 727 tristate "ST Microelectronics DDC I2C interface"
700 depends on MACH_U300 728 depends on MACH_U300
@@ -768,7 +796,7 @@ config I2C_XLR
768 796
769config I2C_RCAR 797config I2C_RCAR
770 tristate "Renesas R-Car I2C Controller" 798 tristate "Renesas R-Car I2C Controller"
771 depends on ARCH_SHMOBILE && I2C 799 depends on ARM || COMPILE_TEST
772 help 800 help
773 If you say yes to this option, support will be included for the 801 If you say yes to this option, support will be included for the
774 R-Car I2C controller. 802 R-Car I2C controller.
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index d00997f3eb3b..c73eb0ea788e 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -42,6 +42,7 @@ i2c-designware-platform-objs := i2c-designware-platdrv.o
42obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o 42obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o
43i2c-designware-pci-objs := i2c-designware-pcidrv.o 43i2c-designware-pci-objs := i2c-designware-pcidrv.o
44obj-$(CONFIG_I2C_EG20T) += i2c-eg20t.o 44obj-$(CONFIG_I2C_EG20T) += i2c-eg20t.o
45obj-$(CONFIG_I2C_EXYNOS5) += i2c-exynos5.o
45obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o 46obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o
46obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o 47obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o
47obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o 48obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o
@@ -68,6 +69,7 @@ obj-$(CONFIG_I2C_SH7760) += i2c-sh7760.o
68obj-$(CONFIG_I2C_SH_MOBILE) += i2c-sh_mobile.o 69obj-$(CONFIG_I2C_SH_MOBILE) += i2c-sh_mobile.o
69obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o 70obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o
70obj-$(CONFIG_I2C_SIRF) += i2c-sirf.o 71obj-$(CONFIG_I2C_SIRF) += i2c-sirf.o
72obj-$(CONFIG_I2C_ST) += i2c-st.o
71obj-$(CONFIG_I2C_STU300) += i2c-stu300.o 73obj-$(CONFIG_I2C_STU300) += i2c-stu300.o
72obj-$(CONFIG_I2C_TEGRA) += i2c-tegra.o 74obj-$(CONFIG_I2C_TEGRA) += i2c-tegra.o
73obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o 75obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o
@@ -87,6 +89,7 @@ obj-$(CONFIG_I2C_VIPERBOARD) += i2c-viperboard.o
87 89
88# Other I2C/SMBus bus drivers 90# Other I2C/SMBus bus drivers
89obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o 91obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o
92obj-$(CONFIG_I2C_BCM_KONA) += i2c-bcm-kona.o
90obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o 93obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o
91obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o 94obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
92obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o 95obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o
diff --git a/drivers/i2c/busses/i2c-bcm-kona.c b/drivers/i2c/busses/i2c-bcm-kona.c
new file mode 100644
index 000000000000..036cf03aeb61
--- /dev/null
+++ b/drivers/i2c/busses/i2c-bcm-kona.c
@@ -0,0 +1,909 @@
1/*
2 * Copyright (C) 2013 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
9 * kind, whether express or implied; without even the implied warranty
10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <linux/device.h>
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/sched.h>
18#include <linux/i2c.h>
19#include <linux/interrupt.h>
20#include <linux/platform_device.h>
21#include <linux/clk.h>
22#include <linux/io.h>
23#include <linux/clk.h>
24#include <linux/slab.h>
25
26/* Hardware register offsets and field defintions */
27#define CS_OFFSET 0x00000020
28#define CS_ACK_SHIFT 3
29#define CS_ACK_MASK 0x00000008
30#define CS_ACK_CMD_GEN_START 0x00000000
31#define CS_ACK_CMD_GEN_RESTART 0x00000001
32#define CS_CMD_SHIFT 1
33#define CS_CMD_CMD_NO_ACTION 0x00000000
34#define CS_CMD_CMD_START_RESTART 0x00000001
35#define CS_CMD_CMD_STOP 0x00000002
36#define CS_EN_SHIFT 0
37#define CS_EN_CMD_ENABLE_BSC 0x00000001
38
39#define TIM_OFFSET 0x00000024
40#define TIM_PRESCALE_SHIFT 6
41#define TIM_P_SHIFT 3
42#define TIM_NO_DIV_SHIFT 2
43#define TIM_DIV_SHIFT 0
44
45#define DAT_OFFSET 0x00000028
46
47#define TOUT_OFFSET 0x0000002c
48
49#define TXFCR_OFFSET 0x0000003c
50#define TXFCR_FIFO_FLUSH_MASK 0x00000080
51#define TXFCR_FIFO_EN_MASK 0x00000040
52
53#define IER_OFFSET 0x00000044
54#define IER_READ_COMPLETE_INT_MASK 0x00000010
55#define IER_I2C_INT_EN_MASK 0x00000008
56#define IER_FIFO_INT_EN_MASK 0x00000002
57#define IER_NOACK_EN_MASK 0x00000001
58
59#define ISR_OFFSET 0x00000048
60#define ISR_RESERVED_MASK 0xffffff60
61#define ISR_CMDBUSY_MASK 0x00000080
62#define ISR_READ_COMPLETE_MASK 0x00000010
63#define ISR_SES_DONE_MASK 0x00000008
64#define ISR_ERR_MASK 0x00000004
65#define ISR_TXFIFOEMPTY_MASK 0x00000002
66#define ISR_NOACK_MASK 0x00000001
67
68#define CLKEN_OFFSET 0x0000004C
69#define CLKEN_AUTOSENSE_OFF_MASK 0x00000080
70#define CLKEN_M_SHIFT 4
71#define CLKEN_N_SHIFT 1
72#define CLKEN_CLKEN_MASK 0x00000001
73
74#define FIFO_STATUS_OFFSET 0x00000054
75#define FIFO_STATUS_RXFIFO_EMPTY_MASK 0x00000004
76#define FIFO_STATUS_TXFIFO_EMPTY_MASK 0x00000010
77
78#define HSTIM_OFFSET 0x00000058
79#define HSTIM_HS_MODE_MASK 0x00008000
80#define HSTIM_HS_HOLD_SHIFT 10
81#define HSTIM_HS_HIGH_PHASE_SHIFT 5
82#define HSTIM_HS_SETUP_SHIFT 0
83
84#define PADCTL_OFFSET 0x0000005c
85#define PADCTL_PAD_OUT_EN_MASK 0x00000004
86
87#define RXFCR_OFFSET 0x00000068
88#define RXFCR_NACK_EN_SHIFT 7
89#define RXFCR_READ_COUNT_SHIFT 0
90#define RXFIFORDOUT_OFFSET 0x0000006c
91
92/* Locally used constants */
93#define MAX_RX_FIFO_SIZE 64U /* bytes */
94#define MAX_TX_FIFO_SIZE 64U /* bytes */
95
96#define STD_EXT_CLK_FREQ 13000000UL
97#define HS_EXT_CLK_FREQ 104000000UL
98
99#define MASTERCODE 0x08 /* Mastercodes are 0000_1xxxb */
100
101#define I2C_TIMEOUT 100 /* msecs */
102
103/* Operations that can be commanded to the controller */
104enum bcm_kona_cmd_t {
105 BCM_CMD_NOACTION = 0,
106 BCM_CMD_START,
107 BCM_CMD_RESTART,
108 BCM_CMD_STOP,
109};
110
111enum bus_speed_index {
112 BCM_SPD_100K = 0,
113 BCM_SPD_400K,
114 BCM_SPD_1MHZ,
115};
116
117enum hs_bus_speed_index {
118 BCM_SPD_3P4MHZ = 0,
119};
120
121/* Internal divider settings for standard mode, fast mode and fast mode plus */
122struct bus_speed_cfg {
123 uint8_t time_m; /* Number of cycles for setup time */
124 uint8_t time_n; /* Number of cycles for hold time */
125 uint8_t prescale; /* Prescale divider */
126 uint8_t time_p; /* Timing coefficient */
127 uint8_t no_div; /* Disable clock divider */
128 uint8_t time_div; /* Post-prescale divider */
129};
130
131/* Internal divider settings for high-speed mode */
132struct hs_bus_speed_cfg {
133 uint8_t hs_hold; /* Number of clock cycles SCL stays low until
134 the end of bit period */
135 uint8_t hs_high_phase; /* Number of clock cycles SCL stays high
136 before it falls */
137 uint8_t hs_setup; /* Number of clock cycles SCL stays low
138 before it rises */
139 uint8_t prescale; /* Prescale divider */
140 uint8_t time_p; /* Timing coefficient */
141 uint8_t no_div; /* Disable clock divider */
142 uint8_t time_div; /* Post-prescale divider */
143};
144
145static const struct bus_speed_cfg std_cfg_table[] = {
146 [BCM_SPD_100K] = {0x01, 0x01, 0x03, 0x06, 0x00, 0x02},
147 [BCM_SPD_400K] = {0x05, 0x01, 0x03, 0x05, 0x01, 0x02},
148 [BCM_SPD_1MHZ] = {0x01, 0x01, 0x03, 0x01, 0x01, 0x03},
149};
150
151static const struct hs_bus_speed_cfg hs_cfg_table[] = {
152 [BCM_SPD_3P4MHZ] = {0x01, 0x08, 0x14, 0x00, 0x06, 0x01, 0x00},
153};
154
155struct bcm_kona_i2c_dev {
156 struct device *device;
157
158 void __iomem *base;
159 int irq;
160 struct clk *external_clk;
161
162 struct i2c_adapter adapter;
163
164 struct completion done;
165
166 const struct bus_speed_cfg *std_cfg;
167 const struct hs_bus_speed_cfg *hs_cfg;
168};
169
170static void bcm_kona_i2c_send_cmd_to_ctrl(struct bcm_kona_i2c_dev *dev,
171 enum bcm_kona_cmd_t cmd)
172{
173 dev_dbg(dev->device, "%s, %d\n", __func__, cmd);
174
175 switch (cmd) {
176 case BCM_CMD_NOACTION:
177 writel((CS_CMD_CMD_NO_ACTION << CS_CMD_SHIFT) |
178 (CS_EN_CMD_ENABLE_BSC << CS_EN_SHIFT),
179 dev->base + CS_OFFSET);
180 break;
181
182 case BCM_CMD_START:
183 writel((CS_ACK_CMD_GEN_START << CS_ACK_SHIFT) |
184 (CS_CMD_CMD_START_RESTART << CS_CMD_SHIFT) |
185 (CS_EN_CMD_ENABLE_BSC << CS_EN_SHIFT),
186 dev->base + CS_OFFSET);
187 break;
188
189 case BCM_CMD_RESTART:
190 writel((CS_ACK_CMD_GEN_RESTART << CS_ACK_SHIFT) |
191 (CS_CMD_CMD_START_RESTART << CS_CMD_SHIFT) |
192 (CS_EN_CMD_ENABLE_BSC << CS_EN_SHIFT),
193 dev->base + CS_OFFSET);
194 break;
195
196 case BCM_CMD_STOP:
197 writel((CS_CMD_CMD_STOP << CS_CMD_SHIFT) |
198 (CS_EN_CMD_ENABLE_BSC << CS_EN_SHIFT),
199 dev->base + CS_OFFSET);
200 break;
201
202 default:
203 dev_err(dev->device, "Unknown command %d\n", cmd);
204 }
205}
206
207static void bcm_kona_i2c_enable_clock(struct bcm_kona_i2c_dev *dev)
208{
209 writel(readl(dev->base + CLKEN_OFFSET) | CLKEN_CLKEN_MASK,
210 dev->base + CLKEN_OFFSET);
211}
212
213static void bcm_kona_i2c_disable_clock(struct bcm_kona_i2c_dev *dev)
214{
215 writel(readl(dev->base + CLKEN_OFFSET) & ~CLKEN_CLKEN_MASK,
216 dev->base + CLKEN_OFFSET);
217}
218
219static irqreturn_t bcm_kona_i2c_isr(int irq, void *devid)
220{
221 struct bcm_kona_i2c_dev *dev = devid;
222 uint32_t status = readl(dev->base + ISR_OFFSET);
223
224 if ((status & ~ISR_RESERVED_MASK) == 0)
225 return IRQ_NONE;
226
227 /* Must flush the TX FIFO when NAK detected */
228 if (status & ISR_NOACK_MASK)
229 writel(TXFCR_FIFO_FLUSH_MASK | TXFCR_FIFO_EN_MASK,
230 dev->base + TXFCR_OFFSET);
231
232 writel(status & ~ISR_RESERVED_MASK, dev->base + ISR_OFFSET);
233 complete_all(&dev->done);
234
235 return IRQ_HANDLED;
236}
237
238/* Wait for ISR_CMDBUSY_MASK to go low before writing to CS, DAT, or RCD */
239static int bcm_kona_i2c_wait_if_busy(struct bcm_kona_i2c_dev *dev)
240{
241 unsigned long timeout = jiffies + msecs_to_jiffies(I2C_TIMEOUT);
242
243 while (readl(dev->base + ISR_OFFSET) & ISR_CMDBUSY_MASK)
244 if (time_after(jiffies, timeout)) {
245 dev_err(dev->device, "CMDBUSY timeout\n");
246 return -ETIMEDOUT;
247 }
248
249 return 0;
250}
251
252/* Send command to I2C bus */
253static int bcm_kona_send_i2c_cmd(struct bcm_kona_i2c_dev *dev,
254 enum bcm_kona_cmd_t cmd)
255{
256 int rc;
257 unsigned long time_left = msecs_to_jiffies(I2C_TIMEOUT);
258
259 /* Make sure the hardware is ready */
260 rc = bcm_kona_i2c_wait_if_busy(dev);
261 if (rc < 0)
262 return rc;
263
264 /* Unmask the session done interrupt */
265 writel(IER_I2C_INT_EN_MASK, dev->base + IER_OFFSET);
266
267 /* Mark as incomplete before sending the command */
268 reinit_completion(&dev->done);
269
270 /* Send the command */
271 bcm_kona_i2c_send_cmd_to_ctrl(dev, cmd);
272
273 /* Wait for transaction to finish or timeout */
274 time_left = wait_for_completion_timeout(&dev->done, time_left);
275
276 /* Mask all interrupts */
277 writel(0, dev->base + IER_OFFSET);
278
279 if (!time_left) {
280 dev_err(dev->device, "controller timed out\n");
281 rc = -ETIMEDOUT;
282 }
283
284 /* Clear command */
285 bcm_kona_i2c_send_cmd_to_ctrl(dev, BCM_CMD_NOACTION);
286
287 return rc;
288}
289
290/* Read a single RX FIFO worth of data from the i2c bus */
291static int bcm_kona_i2c_read_fifo_single(struct bcm_kona_i2c_dev *dev,
292 uint8_t *buf, unsigned int len,
293 unsigned int last_byte_nak)
294{
295 unsigned long time_left = msecs_to_jiffies(I2C_TIMEOUT);
296
297 /* Mark as incomplete before starting the RX FIFO */
298 reinit_completion(&dev->done);
299
300 /* Unmask the read complete interrupt */
301 writel(IER_READ_COMPLETE_INT_MASK, dev->base + IER_OFFSET);
302
303 /* Start the RX FIFO */
304 writel((last_byte_nak << RXFCR_NACK_EN_SHIFT) |
305 (len << RXFCR_READ_COUNT_SHIFT),
306 dev->base + RXFCR_OFFSET);
307
308 /* Wait for FIFO read to complete */
309 time_left = wait_for_completion_timeout(&dev->done, time_left);
310
311 /* Mask all interrupts */
312 writel(0, dev->base + IER_OFFSET);
313
314 if (!time_left) {
315 dev_err(dev->device, "RX FIFO time out\n");
316 return -EREMOTEIO;
317 }
318
319 /* Read data from FIFO */
320 for (; len > 0; len--, buf++)
321 *buf = readl(dev->base + RXFIFORDOUT_OFFSET);
322
323 return 0;
324}
325
326/* Read any amount of data using the RX FIFO from the i2c bus */
327static int bcm_kona_i2c_read_fifo(struct bcm_kona_i2c_dev *dev,
328 struct i2c_msg *msg)
329{
330 unsigned int bytes_to_read = MAX_RX_FIFO_SIZE;
331 unsigned int last_byte_nak = 0;
332 unsigned int bytes_read = 0;
333 int rc;
334
335 uint8_t *tmp_buf = msg->buf;
336
337 while (bytes_read < msg->len) {
338 if (msg->len - bytes_read <= MAX_RX_FIFO_SIZE) {
339 last_byte_nak = 1; /* NAK last byte of transfer */
340 bytes_to_read = msg->len - bytes_read;
341 }
342
343 rc = bcm_kona_i2c_read_fifo_single(dev, tmp_buf, bytes_to_read,
344 last_byte_nak);
345 if (rc < 0)
346 return -EREMOTEIO;
347
348 bytes_read += bytes_to_read;
349 tmp_buf += bytes_to_read;
350 }
351
352 return 0;
353}
354
355/* Write a single byte of data to the i2c bus */
356static int bcm_kona_i2c_write_byte(struct bcm_kona_i2c_dev *dev, uint8_t data,
357 unsigned int nak_expected)
358{
359 int rc;
360 unsigned long time_left = msecs_to_jiffies(I2C_TIMEOUT);
361 unsigned int nak_received;
362
363 /* Make sure the hardware is ready */
364 rc = bcm_kona_i2c_wait_if_busy(dev);
365 if (rc < 0)
366 return rc;
367
368 /* Clear pending session done interrupt */
369 writel(ISR_SES_DONE_MASK, dev->base + ISR_OFFSET);
370
371 /* Unmask the session done interrupt */
372 writel(IER_I2C_INT_EN_MASK, dev->base + IER_OFFSET);
373
374 /* Mark as incomplete before sending the data */
375 reinit_completion(&dev->done);
376
377 /* Send one byte of data */
378 writel(data, dev->base + DAT_OFFSET);
379
380 /* Wait for byte to be written */
381 time_left = wait_for_completion_timeout(&dev->done, time_left);
382
383 /* Mask all interrupts */
384 writel(0, dev->base + IER_OFFSET);
385
386 if (!time_left) {
387 dev_dbg(dev->device, "controller timed out\n");
388 return -ETIMEDOUT;
389 }
390
391 nak_received = readl(dev->base + CS_OFFSET) & CS_ACK_MASK ? 1 : 0;
392
393 if (nak_received ^ nak_expected) {
394 dev_dbg(dev->device, "unexpected NAK/ACK\n");
395 return -EREMOTEIO;
396 }
397
398 return 0;
399}
400
401/* Write a single TX FIFO worth of data to the i2c bus */
402static int bcm_kona_i2c_write_fifo_single(struct bcm_kona_i2c_dev *dev,
403 uint8_t *buf, unsigned int len)
404{
405 int k;
406 unsigned long time_left = msecs_to_jiffies(I2C_TIMEOUT);
407 unsigned int fifo_status;
408
409 /* Mark as incomplete before sending data to the TX FIFO */
410 reinit_completion(&dev->done);
411
412 /* Unmask the fifo empty and nak interrupt */
413 writel(IER_FIFO_INT_EN_MASK | IER_NOACK_EN_MASK,
414 dev->base + IER_OFFSET);
415
416 /* Disable IRQ to load a FIFO worth of data without interruption */
417 disable_irq(dev->irq);
418
419 /* Write data into FIFO */
420 for (k = 0; k < len; k++)
421 writel(buf[k], (dev->base + DAT_OFFSET));
422
423 /* Enable IRQ now that data has been loaded */
424 enable_irq(dev->irq);
425
426 /* Wait for FIFO to empty */
427 do {
428 time_left = wait_for_completion_timeout(&dev->done, time_left);
429 fifo_status = readl(dev->base + FIFO_STATUS_OFFSET);
430 } while (time_left && !(fifo_status & FIFO_STATUS_TXFIFO_EMPTY_MASK));
431
432 /* Mask all interrupts */
433 writel(0, dev->base + IER_OFFSET);
434
435 /* Check if there was a NAK */
436 if (readl(dev->base + CS_OFFSET) & CS_ACK_MASK) {
437 dev_err(dev->device, "unexpected NAK\n");
438 return -EREMOTEIO;
439 }
440
441 /* Check if a timeout occured */
442 if (!time_left) {
443 dev_err(dev->device, "completion timed out\n");
444 return -EREMOTEIO;
445 }
446
447 return 0;
448}
449
450
451/* Write any amount of data using TX FIFO to the i2c bus */
452static int bcm_kona_i2c_write_fifo(struct bcm_kona_i2c_dev *dev,
453 struct i2c_msg *msg)
454{
455 unsigned int bytes_to_write = MAX_TX_FIFO_SIZE;
456 unsigned int bytes_written = 0;
457 int rc;
458
459 uint8_t *tmp_buf = msg->buf;
460
461 while (bytes_written < msg->len) {
462 if (msg->len - bytes_written <= MAX_TX_FIFO_SIZE)
463 bytes_to_write = msg->len - bytes_written;
464
465 rc = bcm_kona_i2c_write_fifo_single(dev, tmp_buf,
466 bytes_to_write);
467 if (rc < 0)
468 return -EREMOTEIO;
469
470 bytes_written += bytes_to_write;
471 tmp_buf += bytes_to_write;
472 }
473
474 return 0;
475}
476
477/* Send i2c address */
478static int bcm_kona_i2c_do_addr(struct bcm_kona_i2c_dev *dev,
479 struct i2c_msg *msg)
480{
481 unsigned char addr;
482
483 if (msg->flags & I2C_M_TEN) {
484 /* First byte is 11110XX0 where XX is upper 2 bits */
485 addr = 0xF0 | ((msg->addr & 0x300) >> 7);
486 if (bcm_kona_i2c_write_byte(dev, addr, 0) < 0)
487 return -EREMOTEIO;
488
489 /* Second byte is the remaining 8 bits */
490 addr = msg->addr & 0xFF;
491 if (bcm_kona_i2c_write_byte(dev, addr, 0) < 0)
492 return -EREMOTEIO;
493
494 if (msg->flags & I2C_M_RD) {
495 /* For read, send restart command */
496 if (bcm_kona_send_i2c_cmd(dev, BCM_CMD_RESTART) < 0)
497 return -EREMOTEIO;
498
499 /* Then re-send the first byte with the read bit set */
500 addr = 0xF0 | ((msg->addr & 0x300) >> 7) | 0x01;
501 if (bcm_kona_i2c_write_byte(dev, addr, 0) < 0)
502 return -EREMOTEIO;
503 }
504 } else {
505 addr = msg->addr << 1;
506
507 if (msg->flags & I2C_M_RD)
508 addr |= 1;
509
510 if (bcm_kona_i2c_write_byte(dev, addr, 0) < 0)
511 return -EREMOTEIO;
512 }
513
514 return 0;
515}
516
517static void bcm_kona_i2c_enable_autosense(struct bcm_kona_i2c_dev *dev)
518{
519 writel(readl(dev->base + CLKEN_OFFSET) & ~CLKEN_AUTOSENSE_OFF_MASK,
520 dev->base + CLKEN_OFFSET);
521}
522
523static void bcm_kona_i2c_config_timing(struct bcm_kona_i2c_dev *dev)
524{
525 writel(readl(dev->base + HSTIM_OFFSET) & ~HSTIM_HS_MODE_MASK,
526 dev->base + HSTIM_OFFSET);
527
528 writel((dev->std_cfg->prescale << TIM_PRESCALE_SHIFT) |
529 (dev->std_cfg->time_p << TIM_P_SHIFT) |
530 (dev->std_cfg->no_div << TIM_NO_DIV_SHIFT) |
531 (dev->std_cfg->time_div << TIM_DIV_SHIFT),
532 dev->base + TIM_OFFSET);
533
534 writel((dev->std_cfg->time_m << CLKEN_M_SHIFT) |
535 (dev->std_cfg->time_n << CLKEN_N_SHIFT) |
536 CLKEN_CLKEN_MASK,
537 dev->base + CLKEN_OFFSET);
538}
539
540static void bcm_kona_i2c_config_timing_hs(struct bcm_kona_i2c_dev *dev)
541{
542 writel((dev->hs_cfg->prescale << TIM_PRESCALE_SHIFT) |
543 (dev->hs_cfg->time_p << TIM_P_SHIFT) |
544 (dev->hs_cfg->no_div << TIM_NO_DIV_SHIFT) |
545 (dev->hs_cfg->time_div << TIM_DIV_SHIFT),
546 dev->base + TIM_OFFSET);
547
548 writel((dev->hs_cfg->hs_hold << HSTIM_HS_HOLD_SHIFT) |
549 (dev->hs_cfg->hs_high_phase << HSTIM_HS_HIGH_PHASE_SHIFT) |
550 (dev->hs_cfg->hs_setup << HSTIM_HS_SETUP_SHIFT),
551 dev->base + HSTIM_OFFSET);
552
553 writel(readl(dev->base + HSTIM_OFFSET) | HSTIM_HS_MODE_MASK,
554 dev->base + HSTIM_OFFSET);
555}
556
557static int bcm_kona_i2c_switch_to_hs(struct bcm_kona_i2c_dev *dev)
558{
559 int rc;
560
561 /* Send mastercode at standard speed */
562 rc = bcm_kona_i2c_write_byte(dev, MASTERCODE, 1);
563 if (rc < 0) {
564 pr_err("High speed handshake failed\n");
565 return rc;
566 }
567
568 /* Configure external clock to higher frequency */
569 rc = clk_set_rate(dev->external_clk, HS_EXT_CLK_FREQ);
570 if (rc) {
571 dev_err(dev->device, "%s: clk_set_rate returned %d\n",
572 __func__, rc);
573 return rc;
574 }
575
576 /* Reconfigure internal dividers */
577 bcm_kona_i2c_config_timing_hs(dev);
578
579 /* Send a restart command */
580 rc = bcm_kona_send_i2c_cmd(dev, BCM_CMD_RESTART);
581 if (rc < 0)
582 dev_err(dev->device, "High speed restart command failed\n");
583
584 return rc;
585}
586
587static int bcm_kona_i2c_switch_to_std(struct bcm_kona_i2c_dev *dev)
588{
589 int rc;
590
591 /* Reconfigure internal dividers */
592 bcm_kona_i2c_config_timing(dev);
593
594 /* Configure external clock to lower frequency */
595 rc = clk_set_rate(dev->external_clk, STD_EXT_CLK_FREQ);
596 if (rc) {
597 dev_err(dev->device, "%s: clk_set_rate returned %d\n",
598 __func__, rc);
599 }
600
601 return rc;
602}
603
604/* Master transfer function */
605static int bcm_kona_i2c_xfer(struct i2c_adapter *adapter,
606 struct i2c_msg msgs[], int num)
607{
608 struct bcm_kona_i2c_dev *dev = i2c_get_adapdata(adapter);
609 struct i2c_msg *pmsg;
610 int rc = 0;
611 int i;
612
613 rc = clk_prepare_enable(dev->external_clk);
614 if (rc) {
615 dev_err(dev->device, "%s: peri clock enable failed. err %d\n",
616 __func__, rc);
617 return rc;
618 }
619
620 /* Enable pad output */
621 writel(0, dev->base + PADCTL_OFFSET);
622
623 /* Enable internal clocks */
624 bcm_kona_i2c_enable_clock(dev);
625
626 /* Send start command */
627 rc = bcm_kona_send_i2c_cmd(dev, BCM_CMD_START);
628 if (rc < 0) {
629 dev_err(dev->device, "Start command failed rc = %d\n", rc);
630 goto xfer_disable_pad;
631 }
632
633 /* Switch to high speed if applicable */
634 if (dev->hs_cfg) {
635 rc = bcm_kona_i2c_switch_to_hs(dev);
636 if (rc < 0)
637 goto xfer_send_stop;
638 }
639
640 /* Loop through all messages */
641 for (i = 0; i < num; i++) {
642 pmsg = &msgs[i];
643
644 /* Send restart for subsequent messages */
645 if ((i != 0) && ((pmsg->flags & I2C_M_NOSTART) == 0)) {
646 rc = bcm_kona_send_i2c_cmd(dev, BCM_CMD_RESTART);
647 if (rc < 0) {
648 dev_err(dev->device,
649 "restart cmd failed rc = %d\n", rc);
650 goto xfer_send_stop;
651 }
652 }
653
654 /* Send slave address */
655 if (!(pmsg->flags & I2C_M_NOSTART)) {
656 rc = bcm_kona_i2c_do_addr(dev, pmsg);
657 if (rc < 0) {
658 dev_err(dev->device,
659 "NAK from addr %2.2x msg#%d rc = %d\n",
660 pmsg->addr, i, rc);
661 goto xfer_send_stop;
662 }
663 }
664
665 /* Perform data transfer */
666 if (pmsg->flags & I2C_M_RD) {
667 rc = bcm_kona_i2c_read_fifo(dev, pmsg);
668 if (rc < 0) {
669 dev_err(dev->device, "read failure\n");
670 goto xfer_send_stop;
671 }
672 } else {
673 rc = bcm_kona_i2c_write_fifo(dev, pmsg);
674 if (rc < 0) {
675 dev_err(dev->device, "write failure");
676 goto xfer_send_stop;
677 }
678 }
679 }
680
681 rc = num;
682
683xfer_send_stop:
684 /* Send a STOP command */
685 bcm_kona_send_i2c_cmd(dev, BCM_CMD_STOP);
686
687 /* Return from high speed if applicable */
688 if (dev->hs_cfg) {
689 int hs_rc = bcm_kona_i2c_switch_to_std(dev);
690
691 if (hs_rc)
692 rc = hs_rc;
693 }
694
695xfer_disable_pad:
696 /* Disable pad output */
697 writel(PADCTL_PAD_OUT_EN_MASK, dev->base + PADCTL_OFFSET);
698
699 /* Stop internal clock */
700 bcm_kona_i2c_disable_clock(dev);
701
702 clk_disable_unprepare(dev->external_clk);
703
704 return rc;
705}
706
707static uint32_t bcm_kona_i2c_functionality(struct i2c_adapter *adap)
708{
709 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
710 I2C_FUNC_NOSTART;
711}
712
713static const struct i2c_algorithm bcm_algo = {
714 .master_xfer = bcm_kona_i2c_xfer,
715 .functionality = bcm_kona_i2c_functionality,
716};
717
718static int bcm_kona_i2c_assign_bus_speed(struct bcm_kona_i2c_dev *dev)
719{
720 unsigned int bus_speed;
721 int ret = of_property_read_u32(dev->device->of_node, "clock-frequency",
722 &bus_speed);
723 if (ret < 0) {
724 dev_err(dev->device, "missing clock-frequency property\n");
725 return -ENODEV;
726 }
727
728 switch (bus_speed) {
729 case 100000:
730 dev->std_cfg = &std_cfg_table[BCM_SPD_100K];
731 break;
732 case 400000:
733 dev->std_cfg = &std_cfg_table[BCM_SPD_400K];
734 break;
735 case 1000000:
736 dev->std_cfg = &std_cfg_table[BCM_SPD_1MHZ];
737 break;
738 case 3400000:
739 /* Send mastercode at 100k */
740 dev->std_cfg = &std_cfg_table[BCM_SPD_100K];
741 dev->hs_cfg = &hs_cfg_table[BCM_SPD_3P4MHZ];
742 break;
743 default:
744 pr_err("%d hz bus speed not supported\n", bus_speed);
745 pr_err("Valid speeds are 100khz, 400khz, 1mhz, and 3.4mhz\n");
746 return -EINVAL;
747 }
748
749 return 0;
750}
751
752static int bcm_kona_i2c_probe(struct platform_device *pdev)
753{
754 int rc = 0;
755 struct bcm_kona_i2c_dev *dev;
756 struct i2c_adapter *adap;
757 struct resource *iomem;
758
759 /* Allocate memory for private data structure */
760 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
761 if (!dev)
762 return -ENOMEM;
763
764 platform_set_drvdata(pdev, dev);
765 dev->device = &pdev->dev;
766 init_completion(&dev->done);
767
768 /* Map hardware registers */
769 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
770 dev->base = devm_ioremap_resource(dev->device, iomem);
771 if (IS_ERR(dev->base))
772 return -ENOMEM;
773
774 /* Get and enable external clock */
775 dev->external_clk = devm_clk_get(dev->device, NULL);
776 if (IS_ERR(dev->external_clk)) {
777 dev_err(dev->device, "couldn't get clock\n");
778 return -ENODEV;
779 }
780
781 rc = clk_set_rate(dev->external_clk, STD_EXT_CLK_FREQ);
782 if (rc) {
783 dev_err(dev->device, "%s: clk_set_rate returned %d\n",
784 __func__, rc);
785 return rc;
786 }
787
788 rc = clk_prepare_enable(dev->external_clk);
789 if (rc) {
790 dev_err(dev->device, "couldn't enable clock\n");
791 return rc;
792 }
793
794 /* Parse bus speed */
795 rc = bcm_kona_i2c_assign_bus_speed(dev);
796 if (rc)
797 goto probe_disable_clk;
798
799 /* Enable internal clocks */
800 bcm_kona_i2c_enable_clock(dev);
801
802 /* Configure internal dividers */
803 bcm_kona_i2c_config_timing(dev);
804
805 /* Disable timeout */
806 writel(0, dev->base + TOUT_OFFSET);
807
808 /* Enable autosense */
809 bcm_kona_i2c_enable_autosense(dev);
810
811 /* Enable TX FIFO */
812 writel(TXFCR_FIFO_FLUSH_MASK | TXFCR_FIFO_EN_MASK,
813 dev->base + TXFCR_OFFSET);
814
815 /* Mask all interrupts */
816 writel(0, dev->base + IER_OFFSET);
817
818 /* Clear all pending interrupts */
819 writel(ISR_CMDBUSY_MASK |
820 ISR_READ_COMPLETE_MASK |
821 ISR_SES_DONE_MASK |
822 ISR_ERR_MASK |
823 ISR_TXFIFOEMPTY_MASK |
824 ISR_NOACK_MASK,
825 dev->base + ISR_OFFSET);
826
827 /* Get the interrupt number */
828 dev->irq = platform_get_irq(pdev, 0);
829 if (dev->irq < 0) {
830 dev_err(dev->device, "no irq resource\n");
831 rc = -ENODEV;
832 goto probe_disable_clk;
833 }
834
835 /* register the ISR handler */
836 rc = devm_request_irq(&pdev->dev, dev->irq, bcm_kona_i2c_isr,
837 IRQF_SHARED, pdev->name, dev);
838 if (rc) {
839 dev_err(dev->device, "failed to request irq %i\n", dev->irq);
840 goto probe_disable_clk;
841 }
842
843 /* Enable the controller but leave it idle */
844 bcm_kona_i2c_send_cmd_to_ctrl(dev, BCM_CMD_NOACTION);
845
846 /* Disable pad output */
847 writel(PADCTL_PAD_OUT_EN_MASK, dev->base + PADCTL_OFFSET);
848
849 /* Disable internal clock */
850 bcm_kona_i2c_disable_clock(dev);
851
852 /* Disable external clock */
853 clk_disable_unprepare(dev->external_clk);
854
855 /* Add the i2c adapter */
856 adap = &dev->adapter;
857 i2c_set_adapdata(adap, dev);
858 adap->owner = THIS_MODULE;
859 strlcpy(adap->name, "Broadcom I2C adapter", sizeof(adap->name));
860 adap->algo = &bcm_algo;
861 adap->dev.parent = &pdev->dev;
862 adap->dev.of_node = pdev->dev.of_node;
863
864 rc = i2c_add_adapter(adap);
865 if (rc) {
866 dev_err(dev->device, "failed to add adapter\n");
867 return rc;
868 }
869
870 dev_info(dev->device, "device registered successfully\n");
871
872 return 0;
873
874probe_disable_clk:
875 bcm_kona_i2c_disable_clock(dev);
876 clk_disable_unprepare(dev->external_clk);
877
878 return rc;
879}
880
881static int bcm_kona_i2c_remove(struct platform_device *pdev)
882{
883 struct bcm_kona_i2c_dev *dev = platform_get_drvdata(pdev);
884
885 i2c_del_adapter(&dev->adapter);
886
887 return 0;
888}
889
890static const struct of_device_id bcm_kona_i2c_of_match[] = {
891 {.compatible = "brcm,kona-i2c",},
892 {},
893};
894MODULE_DEVICE_TABLE(of, kona_i2c_of_match);
895
896static struct platform_driver bcm_kona_i2c_driver = {
897 .driver = {
898 .name = "bcm-kona-i2c",
899 .owner = THIS_MODULE,
900 .of_match_table = bcm_kona_i2c_of_match,
901 },
902 .probe = bcm_kona_i2c_probe,
903 .remove = bcm_kona_i2c_remove,
904};
905module_platform_driver(bcm_kona_i2c_driver);
906
907MODULE_AUTHOR("Tim Kryger <tkryger@broadcom.com>");
908MODULE_DESCRIPTION("Broadcom Kona I2C Driver");
909MODULE_LICENSE("GPL v2");
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index 35a473ba3d81..3b9bd9a3f2b0 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -675,7 +675,7 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
675 p_adap->retries = 3; 675 p_adap->retries = 3;
676 676
677 rc = peripheral_request_list( 677 rc = peripheral_request_list(
678 (unsigned short *)dev_get_platdata(&pdev->dev), 678 dev_get_platdata(&pdev->dev),
679 "i2c-bfin-twi"); 679 "i2c-bfin-twi");
680 if (rc) { 680 if (rc) {
681 dev_err(&pdev->dev, "Can't setup pin mux!\n"); 681 dev_err(&pdev->dev, "Can't setup pin mux!\n");
@@ -723,7 +723,7 @@ out_error_add_adapter:
723 free_irq(iface->irq, iface); 723 free_irq(iface->irq, iface);
724out_error_req_irq: 724out_error_req_irq:
725out_error_no_irq: 725out_error_no_irq:
726 peripheral_free_list((unsigned short *)dev_get_platdata(&pdev->dev)); 726 peripheral_free_list(dev_get_platdata(&pdev->dev));
727out_error_pin_mux: 727out_error_pin_mux:
728 iounmap(iface->regs_base); 728 iounmap(iface->regs_base);
729out_error_ioremap: 729out_error_ioremap:
@@ -739,7 +739,7 @@ static int i2c_bfin_twi_remove(struct platform_device *pdev)
739 739
740 i2c_del_adapter(&(iface->adap)); 740 i2c_del_adapter(&(iface->adap));
741 free_irq(iface->irq, iface); 741 free_irq(iface->irq, iface);
742 peripheral_free_list((unsigned short *)dev_get_platdata(&pdev->dev)); 742 peripheral_free_list(dev_get_platdata(&pdev->dev));
743 iounmap(iface->regs_base); 743 iounmap(iface->regs_base);
744 kfree(iface); 744 kfree(iface);
745 745
diff --git a/drivers/i2c/busses/i2c-cbus-gpio.c b/drivers/i2c/busses/i2c-cbus-gpio.c
index 2d46f13adfdf..ce7ffba2b020 100644
--- a/drivers/i2c/busses/i2c-cbus-gpio.c
+++ b/drivers/i2c/busses/i2c-cbus-gpio.c
@@ -246,6 +246,7 @@ static int cbus_i2c_probe(struct platform_device *pdev)
246 adapter->owner = THIS_MODULE; 246 adapter->owner = THIS_MODULE;
247 adapter->class = I2C_CLASS_HWMON; 247 adapter->class = I2C_CLASS_HWMON;
248 adapter->dev.parent = &pdev->dev; 248 adapter->dev.parent = &pdev->dev;
249 adapter->dev.of_node = pdev->dev.of_node;
249 adapter->nr = pdev->id; 250 adapter->nr = pdev->id;
250 adapter->timeout = HZ; 251 adapter->timeout = HZ;
251 adapter->algo = &cbus_i2c_algo; 252 adapter->algo = &cbus_i2c_algo;
@@ -289,6 +290,7 @@ static struct platform_driver cbus_i2c_driver = {
289 .driver = { 290 .driver = {
290 .owner = THIS_MODULE, 291 .owner = THIS_MODULE,
291 .name = "i2c-cbus-gpio", 292 .name = "i2c-cbus-gpio",
293 .of_match_table = of_match_ptr(i2c_cbus_dt_ids),
292 }, 294 },
293}; 295};
294module_platform_driver(cbus_i2c_driver); 296module_platform_driver(cbus_i2c_driver);
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 960dec61c64e..ff05d9fef4a8 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -795,7 +795,7 @@ static struct platform_driver davinci_i2c_driver = {
795 .name = "i2c_davinci", 795 .name = "i2c_davinci",
796 .owner = THIS_MODULE, 796 .owner = THIS_MODULE,
797 .pm = davinci_i2c_pm_ops, 797 .pm = davinci_i2c_pm_ops,
798 .of_match_table = of_match_ptr(davinci_i2c_of_match), 798 .of_match_table = davinci_i2c_of_match,
799 }, 799 },
800}; 800};
801 801
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index 0aa01136f8d9..d0bdac0498ce 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -103,6 +103,8 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev)
103static const struct acpi_device_id dw_i2c_acpi_match[] = { 103static const struct acpi_device_id dw_i2c_acpi_match[] = {
104 { "INT33C2", 0 }, 104 { "INT33C2", 0 },
105 { "INT33C3", 0 }, 105 { "INT33C3", 0 },
106 { "INT3432", 0 },
107 { "INT3433", 0 },
106 { "80860F41", 0 }, 108 { "80860F41", 0 },
107 { } 109 { }
108}; 110};
diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c
index 0f3752967c4b..ff15ae90aaf5 100644
--- a/drivers/i2c/busses/i2c-eg20t.c
+++ b/drivers/i2c/busses/i2c-eg20t.c
@@ -312,24 +312,6 @@ static void pch_i2c_start(struct i2c_algo_pch_data *adap)
312} 312}
313 313
314/** 314/**
315 * pch_i2c_getack() - to confirm ACK/NACK
316 * @adap: Pointer to struct i2c_algo_pch_data.
317 */
318static s32 pch_i2c_getack(struct i2c_algo_pch_data *adap)
319{
320 u32 reg_val;
321 void __iomem *p = adap->pch_base_address;
322 reg_val = ioread32(p + PCH_I2CSR) & PCH_GETACK;
323
324 if (reg_val != 0) {
325 pch_err(adap, "return%d\n", -EPROTO);
326 return -EPROTO;
327 }
328
329 return 0;
330}
331
332/**
333 * pch_i2c_stop() - generate stop condition in normal mode. 315 * pch_i2c_stop() - generate stop condition in normal mode.
334 * @adap: Pointer to struct i2c_algo_pch_data. 316 * @adap: Pointer to struct i2c_algo_pch_data.
335 */ 317 */
@@ -344,6 +326,7 @@ static void pch_i2c_stop(struct i2c_algo_pch_data *adap)
344static int pch_i2c_wait_for_check_xfer(struct i2c_algo_pch_data *adap) 326static int pch_i2c_wait_for_check_xfer(struct i2c_algo_pch_data *adap)
345{ 327{
346 long ret; 328 long ret;
329 void __iomem *p = adap->pch_base_address;
347 330
348 ret = wait_event_timeout(pch_event, 331 ret = wait_event_timeout(pch_event,
349 (adap->pch_event_flag != 0), msecs_to_jiffies(1000)); 332 (adap->pch_event_flag != 0), msecs_to_jiffies(1000));
@@ -366,10 +349,9 @@ static int pch_i2c_wait_for_check_xfer(struct i2c_algo_pch_data *adap)
366 349
367 adap->pch_event_flag = 0; 350 adap->pch_event_flag = 0;
368 351
369 if (pch_i2c_getack(adap)) { 352 if (ioread32(p + PCH_I2CSR) & PCH_GETACK) {
370 pch_dbg(adap, "Receive NACK for slave address" 353 pch_dbg(adap, "Receive NACK for slave address setting\n");
371 "setting\n"); 354 return -ENXIO;
372 return -EIO;
373 } 355 }
374 356
375 return 0; 357 return 0;
diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
new file mode 100644
index 000000000000..c1ef228095b5
--- /dev/null
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -0,0 +1,769 @@
1/**
2 * i2c-exynos5.c - Samsung Exynos5 I2C Controller Driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
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/kernel.h>
12#include <linux/module.h>
13
14#include <linux/i2c.h>
15#include <linux/init.h>
16#include <linux/time.h>
17#include <linux/interrupt.h>
18#include <linux/delay.h>
19#include <linux/errno.h>
20#include <linux/err.h>
21#include <linux/platform_device.h>
22#include <linux/clk.h>
23#include <linux/slab.h>
24#include <linux/io.h>
25#include <linux/of_address.h>
26#include <linux/of_irq.h>
27#include <linux/spinlock.h>
28
29/*
30 * HSI2C controller from Samsung supports 2 modes of operation
31 * 1. Auto mode: Where in master automatically controls the whole transaction
32 * 2. Manual mode: Software controls the transaction by issuing commands
33 * START, READ, WRITE, STOP, RESTART in I2C_MANUAL_CMD register.
34 *
35 * Operation mode can be selected by setting AUTO_MODE bit in I2C_CONF register
36 *
37 * Special bits are available for both modes of operation to set commands
38 * and for checking transfer status
39 */
40
41/* Register Map */
42#define HSI2C_CTL 0x00
43#define HSI2C_FIFO_CTL 0x04
44#define HSI2C_TRAILIG_CTL 0x08
45#define HSI2C_CLK_CTL 0x0C
46#define HSI2C_CLK_SLOT 0x10
47#define HSI2C_INT_ENABLE 0x20
48#define HSI2C_INT_STATUS 0x24
49#define HSI2C_ERR_STATUS 0x2C
50#define HSI2C_FIFO_STATUS 0x30
51#define HSI2C_TX_DATA 0x34
52#define HSI2C_RX_DATA 0x38
53#define HSI2C_CONF 0x40
54#define HSI2C_AUTO_CONF 0x44
55#define HSI2C_TIMEOUT 0x48
56#define HSI2C_MANUAL_CMD 0x4C
57#define HSI2C_TRANS_STATUS 0x50
58#define HSI2C_TIMING_HS1 0x54
59#define HSI2C_TIMING_HS2 0x58
60#define HSI2C_TIMING_HS3 0x5C
61#define HSI2C_TIMING_FS1 0x60
62#define HSI2C_TIMING_FS2 0x64
63#define HSI2C_TIMING_FS3 0x68
64#define HSI2C_TIMING_SLA 0x6C
65#define HSI2C_ADDR 0x70
66
67/* I2C_CTL Register bits */
68#define HSI2C_FUNC_MODE_I2C (1u << 0)
69#define HSI2C_MASTER (1u << 3)
70#define HSI2C_RXCHON (1u << 6)
71#define HSI2C_TXCHON (1u << 7)
72#define HSI2C_SW_RST (1u << 31)
73
74/* I2C_FIFO_CTL Register bits */
75#define HSI2C_RXFIFO_EN (1u << 0)
76#define HSI2C_TXFIFO_EN (1u << 1)
77#define HSI2C_RXFIFO_TRIGGER_LEVEL(x) ((x) << 4)
78#define HSI2C_TXFIFO_TRIGGER_LEVEL(x) ((x) << 16)
79
80/* As per user manual FIFO max depth is 64bytes */
81#define HSI2C_FIFO_MAX 0x40
82/* default trigger levels for Tx and Rx FIFOs */
83#define HSI2C_DEF_TXFIFO_LVL (HSI2C_FIFO_MAX - 0x30)
84#define HSI2C_DEF_RXFIFO_LVL (HSI2C_FIFO_MAX - 0x10)
85
86/* I2C_TRAILING_CTL Register bits */
87#define HSI2C_TRAILING_COUNT (0xf)
88
89/* I2C_INT_EN Register bits */
90#define HSI2C_INT_TX_ALMOSTEMPTY_EN (1u << 0)
91#define HSI2C_INT_RX_ALMOSTFULL_EN (1u << 1)
92#define HSI2C_INT_TRAILING_EN (1u << 6)
93#define HSI2C_INT_I2C_EN (1u << 9)
94
95/* I2C_INT_STAT Register bits */
96#define HSI2C_INT_TX_ALMOSTEMPTY (1u << 0)
97#define HSI2C_INT_RX_ALMOSTFULL (1u << 1)
98#define HSI2C_INT_TX_UNDERRUN (1u << 2)
99#define HSI2C_INT_TX_OVERRUN (1u << 3)
100#define HSI2C_INT_RX_UNDERRUN (1u << 4)
101#define HSI2C_INT_RX_OVERRUN (1u << 5)
102#define HSI2C_INT_TRAILING (1u << 6)
103#define HSI2C_INT_I2C (1u << 9)
104
105/* I2C_FIFO_STAT Register bits */
106#define HSI2C_RX_FIFO_EMPTY (1u << 24)
107#define HSI2C_RX_FIFO_FULL (1u << 23)
108#define HSI2C_RX_FIFO_LVL(x) ((x >> 16) & 0x7f)
109#define HSI2C_TX_FIFO_EMPTY (1u << 8)
110#define HSI2C_TX_FIFO_FULL (1u << 7)
111#define HSI2C_TX_FIFO_LVL(x) ((x >> 0) & 0x7f)
112
113/* I2C_CONF Register bits */
114#define HSI2C_AUTO_MODE (1u << 31)
115#define HSI2C_10BIT_ADDR_MODE (1u << 30)
116#define HSI2C_HS_MODE (1u << 29)
117
118/* I2C_AUTO_CONF Register bits */
119#define HSI2C_READ_WRITE (1u << 16)
120#define HSI2C_STOP_AFTER_TRANS (1u << 17)
121#define HSI2C_MASTER_RUN (1u << 31)
122
123/* I2C_TIMEOUT Register bits */
124#define HSI2C_TIMEOUT_EN (1u << 31)
125#define HSI2C_TIMEOUT_MASK 0xff
126
127/* I2C_TRANS_STATUS register bits */
128#define HSI2C_MASTER_BUSY (1u << 17)
129#define HSI2C_SLAVE_BUSY (1u << 16)
130#define HSI2C_TIMEOUT_AUTO (1u << 4)
131#define HSI2C_NO_DEV (1u << 3)
132#define HSI2C_NO_DEV_ACK (1u << 2)
133#define HSI2C_TRANS_ABORT (1u << 1)
134#define HSI2C_TRANS_DONE (1u << 0)
135
136/* I2C_ADDR register bits */
137#define HSI2C_SLV_ADDR_SLV(x) ((x & 0x3ff) << 0)
138#define HSI2C_SLV_ADDR_MAS(x) ((x & 0x3ff) << 10)
139#define HSI2C_MASTER_ID(x) ((x & 0xff) << 24)
140#define MASTER_ID(x) ((x & 0x7) + 0x08)
141
142/*
143 * Controller operating frequency, timing values for operation
144 * are calculated against this frequency
145 */
146#define HSI2C_HS_TX_CLOCK 1000000
147#define HSI2C_FS_TX_CLOCK 100000
148#define HSI2C_HIGH_SPD 1
149#define HSI2C_FAST_SPD 0
150
151#define EXYNOS5_I2C_TIMEOUT (msecs_to_jiffies(1000))
152
153struct exynos5_i2c {
154 struct i2c_adapter adap;
155 unsigned int suspended:1;
156
157 struct i2c_msg *msg;
158 struct completion msg_complete;
159 unsigned int msg_ptr;
160
161 unsigned int irq;
162
163 void __iomem *regs;
164 struct clk *clk;
165 struct device *dev;
166 int state;
167
168 spinlock_t lock; /* IRQ synchronization */
169
170 /*
171 * Since the TRANS_DONE bit is cleared on read, and we may read it
172 * either during an IRQ or after a transaction, keep track of its
173 * state here.
174 */
175 int trans_done;
176
177 /* Controller operating frequency */
178 unsigned int fs_clock;
179 unsigned int hs_clock;
180
181 /*
182 * HSI2C Controller can operate in
183 * 1. High speed upto 3.4Mbps
184 * 2. Fast speed upto 1Mbps
185 */
186 int speed_mode;
187};
188
189static const struct of_device_id exynos5_i2c_match[] = {
190 { .compatible = "samsung,exynos5-hsi2c" },
191 {},
192};
193MODULE_DEVICE_TABLE(of, exynos5_i2c_match);
194
195static void exynos5_i2c_clr_pend_irq(struct exynos5_i2c *i2c)
196{
197 writel(readl(i2c->regs + HSI2C_INT_STATUS),
198 i2c->regs + HSI2C_INT_STATUS);
199}
200
201/*
202 * exynos5_i2c_set_timing: updates the registers with appropriate
203 * timing values calculated
204 *
205 * Returns 0 on success, -EINVAL if the cycle length cannot
206 * be calculated.
207 */
208static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, int mode)
209{
210 u32 i2c_timing_s1;
211 u32 i2c_timing_s2;
212 u32 i2c_timing_s3;
213 u32 i2c_timing_sla;
214 unsigned int t_start_su, t_start_hd;
215 unsigned int t_stop_su;
216 unsigned int t_data_su, t_data_hd;
217 unsigned int t_scl_l, t_scl_h;
218 unsigned int t_sr_release;
219 unsigned int t_ftl_cycle;
220 unsigned int clkin = clk_get_rate(i2c->clk);
221 unsigned int div, utemp0 = 0, utemp1 = 0, clk_cycle;
222 unsigned int op_clk = (mode == HSI2C_HIGH_SPD) ?
223 i2c->hs_clock : i2c->fs_clock;
224
225 /*
226 * FPCLK / FI2C =
227 * (CLK_DIV + 1) * (TSCLK_L + TSCLK_H + 2) + 8 + 2 * FLT_CYCLE
228 * utemp0 = (CLK_DIV + 1) * (TSCLK_L + TSCLK_H + 2)
229 * utemp1 = (TSCLK_L + TSCLK_H + 2)
230 */
231 t_ftl_cycle = (readl(i2c->regs + HSI2C_CONF) >> 16) & 0x7;
232 utemp0 = (clkin / op_clk) - 8 - 2 * t_ftl_cycle;
233
234 /* CLK_DIV max is 256 */
235 for (div = 0; div < 256; div++) {
236 utemp1 = utemp0 / (div + 1);
237
238 /*
239 * SCL_L and SCL_H each has max value of 255
240 * Hence, For the clk_cycle to the have right value
241 * utemp1 has to be less then 512 and more than 4.
242 */
243 if ((utemp1 < 512) && (utemp1 > 4)) {
244 clk_cycle = utemp1 - 2;
245 break;
246 } else if (div == 255) {
247 dev_warn(i2c->dev, "Failed to calculate divisor");
248 return -EINVAL;
249 }
250 }
251
252 t_scl_l = clk_cycle / 2;
253 t_scl_h = clk_cycle / 2;
254 t_start_su = t_scl_l;
255 t_start_hd = t_scl_l;
256 t_stop_su = t_scl_l;
257 t_data_su = t_scl_l / 2;
258 t_data_hd = t_scl_l / 2;
259 t_sr_release = clk_cycle;
260
261 i2c_timing_s1 = t_start_su << 24 | t_start_hd << 16 | t_stop_su << 8;
262 i2c_timing_s2 = t_data_su << 24 | t_scl_l << 8 | t_scl_h << 0;
263 i2c_timing_s3 = div << 16 | t_sr_release << 0;
264 i2c_timing_sla = t_data_hd << 0;
265
266 dev_dbg(i2c->dev, "tSTART_SU: %X, tSTART_HD: %X, tSTOP_SU: %X\n",
267 t_start_su, t_start_hd, t_stop_su);
268 dev_dbg(i2c->dev, "tDATA_SU: %X, tSCL_L: %X, tSCL_H: %X\n",
269 t_data_su, t_scl_l, t_scl_h);
270 dev_dbg(i2c->dev, "nClkDiv: %X, tSR_RELEASE: %X\n",
271 div, t_sr_release);
272 dev_dbg(i2c->dev, "tDATA_HD: %X\n", t_data_hd);
273
274 if (mode == HSI2C_HIGH_SPD) {
275 writel(i2c_timing_s1, i2c->regs + HSI2C_TIMING_HS1);
276 writel(i2c_timing_s2, i2c->regs + HSI2C_TIMING_HS2);
277 writel(i2c_timing_s3, i2c->regs + HSI2C_TIMING_HS3);
278 } else {
279 writel(i2c_timing_s1, i2c->regs + HSI2C_TIMING_FS1);
280 writel(i2c_timing_s2, i2c->regs + HSI2C_TIMING_FS2);
281 writel(i2c_timing_s3, i2c->regs + HSI2C_TIMING_FS3);
282 }
283 writel(i2c_timing_sla, i2c->regs + HSI2C_TIMING_SLA);
284
285 return 0;
286}
287
288static int exynos5_hsi2c_clock_setup(struct exynos5_i2c *i2c)
289{
290 /*
291 * Configure the Fast speed timing values
292 * Even the High Speed mode initially starts with Fast mode
293 */
294 if (exynos5_i2c_set_timing(i2c, HSI2C_FAST_SPD)) {
295 dev_err(i2c->dev, "HSI2C FS Clock set up failed\n");
296 return -EINVAL;
297 }
298
299 /* configure the High speed timing values */
300 if (i2c->speed_mode == HSI2C_HIGH_SPD) {
301 if (exynos5_i2c_set_timing(i2c, HSI2C_HIGH_SPD)) {
302 dev_err(i2c->dev, "HSI2C HS Clock set up failed\n");
303 return -EINVAL;
304 }
305 }
306
307 return 0;
308}
309
310/*
311 * exynos5_i2c_init: configures the controller for I2C functionality
312 * Programs I2C controller for Master mode operation
313 */
314static void exynos5_i2c_init(struct exynos5_i2c *i2c)
315{
316 u32 i2c_conf = readl(i2c->regs + HSI2C_CONF);
317 u32 i2c_timeout = readl(i2c->regs + HSI2C_TIMEOUT);
318
319 /* Clear to disable Timeout */
320 i2c_timeout &= ~HSI2C_TIMEOUT_EN;
321 writel(i2c_timeout, i2c->regs + HSI2C_TIMEOUT);
322
323 writel((HSI2C_FUNC_MODE_I2C | HSI2C_MASTER),
324 i2c->regs + HSI2C_CTL);
325 writel(HSI2C_TRAILING_COUNT, i2c->regs + HSI2C_TRAILIG_CTL);
326
327 if (i2c->speed_mode == HSI2C_HIGH_SPD) {
328 writel(HSI2C_MASTER_ID(MASTER_ID(i2c->adap.nr)),
329 i2c->regs + HSI2C_ADDR);
330 i2c_conf |= HSI2C_HS_MODE;
331 }
332
333 writel(i2c_conf | HSI2C_AUTO_MODE, i2c->regs + HSI2C_CONF);
334}
335
336static void exynos5_i2c_reset(struct exynos5_i2c *i2c)
337{
338 u32 i2c_ctl;
339
340 /* Set and clear the bit for reset */
341 i2c_ctl = readl(i2c->regs + HSI2C_CTL);
342 i2c_ctl |= HSI2C_SW_RST;
343 writel(i2c_ctl, i2c->regs + HSI2C_CTL);
344
345 i2c_ctl = readl(i2c->regs + HSI2C_CTL);
346 i2c_ctl &= ~HSI2C_SW_RST;
347 writel(i2c_ctl, i2c->regs + HSI2C_CTL);
348
349 /* We don't expect calculations to fail during the run */
350 exynos5_hsi2c_clock_setup(i2c);
351 /* Initialize the configure registers */
352 exynos5_i2c_init(i2c);
353}
354
355/*
356 * exynos5_i2c_irq: top level IRQ servicing routine
357 *
358 * INT_STATUS registers gives the interrupt details. Further,
359 * FIFO_STATUS or TRANS_STATUS registers are to be check for detailed
360 * state of the bus.
361 */
362static irqreturn_t exynos5_i2c_irq(int irqno, void *dev_id)
363{
364 struct exynos5_i2c *i2c = dev_id;
365 u32 fifo_level, int_status, fifo_status, trans_status;
366 unsigned char byte;
367 int len = 0;
368
369 i2c->state = -EINVAL;
370
371 spin_lock(&i2c->lock);
372
373 int_status = readl(i2c->regs + HSI2C_INT_STATUS);
374 writel(int_status, i2c->regs + HSI2C_INT_STATUS);
375 fifo_status = readl(i2c->regs + HSI2C_FIFO_STATUS);
376
377 /* handle interrupt related to the transfer status */
378 if (int_status & HSI2C_INT_I2C) {
379 trans_status = readl(i2c->regs + HSI2C_TRANS_STATUS);
380 if (trans_status & HSI2C_NO_DEV_ACK) {
381 dev_dbg(i2c->dev, "No ACK from device\n");
382 i2c->state = -ENXIO;
383 goto stop;
384 } else if (trans_status & HSI2C_NO_DEV) {
385 dev_dbg(i2c->dev, "No device\n");
386 i2c->state = -ENXIO;
387 goto stop;
388 } else if (trans_status & HSI2C_TRANS_ABORT) {
389 dev_dbg(i2c->dev, "Deal with arbitration lose\n");
390 i2c->state = -EAGAIN;
391 goto stop;
392 } else if (trans_status & HSI2C_TIMEOUT_AUTO) {
393 dev_dbg(i2c->dev, "Accessing device timed out\n");
394 i2c->state = -EAGAIN;
395 goto stop;
396 } else if (trans_status & HSI2C_TRANS_DONE) {
397 i2c->trans_done = 1;
398 i2c->state = 0;
399 }
400 }
401
402 if ((i2c->msg->flags & I2C_M_RD) && (int_status &
403 (HSI2C_INT_TRAILING | HSI2C_INT_RX_ALMOSTFULL))) {
404 fifo_status = readl(i2c->regs + HSI2C_FIFO_STATUS);
405 fifo_level = HSI2C_RX_FIFO_LVL(fifo_status);
406 len = min(fifo_level, i2c->msg->len - i2c->msg_ptr);
407
408 while (len > 0) {
409 byte = (unsigned char)
410 readl(i2c->regs + HSI2C_RX_DATA);
411 i2c->msg->buf[i2c->msg_ptr++] = byte;
412 len--;
413 }
414 i2c->state = 0;
415 } else if (int_status & HSI2C_INT_TX_ALMOSTEMPTY) {
416 fifo_status = readl(i2c->regs + HSI2C_FIFO_STATUS);
417 fifo_level = HSI2C_TX_FIFO_LVL(fifo_status);
418
419 len = HSI2C_FIFO_MAX - fifo_level;
420 if (len > (i2c->msg->len - i2c->msg_ptr))
421 len = i2c->msg->len - i2c->msg_ptr;
422
423 while (len > 0) {
424 byte = i2c->msg->buf[i2c->msg_ptr++];
425 writel(byte, i2c->regs + HSI2C_TX_DATA);
426 len--;
427 }
428 i2c->state = 0;
429 }
430
431 stop:
432 if ((i2c->trans_done && (i2c->msg->len == i2c->msg_ptr)) ||
433 (i2c->state < 0)) {
434 writel(0, i2c->regs + HSI2C_INT_ENABLE);
435 exynos5_i2c_clr_pend_irq(i2c);
436 complete(&i2c->msg_complete);
437 }
438
439 spin_unlock(&i2c->lock);
440
441 return IRQ_HANDLED;
442}
443
444/*
445 * exynos5_i2c_wait_bus_idle
446 *
447 * Wait for the bus to go idle, indicated by the MASTER_BUSY bit being
448 * cleared.
449 *
450 * Returns -EBUSY if the bus cannot be bought to idle
451 */
452static int exynos5_i2c_wait_bus_idle(struct exynos5_i2c *i2c)
453{
454 unsigned long stop_time;
455 u32 trans_status;
456
457 /* wait for 100 milli seconds for the bus to be idle */
458 stop_time = jiffies + msecs_to_jiffies(100) + 1;
459 do {
460 trans_status = readl(i2c->regs + HSI2C_TRANS_STATUS);
461 if (!(trans_status & HSI2C_MASTER_BUSY))
462 return 0;
463
464 usleep_range(50, 200);
465 } while (time_before(jiffies, stop_time));
466
467 return -EBUSY;
468}
469
470/*
471 * exynos5_i2c_message_start: Configures the bus and starts the xfer
472 * i2c: struct exynos5_i2c pointer for the current bus
473 * stop: Enables stop after transfer if set. Set for last transfer of
474 * in the list of messages.
475 *
476 * Configures the bus for read/write function
477 * Sets chip address to talk to, message length to be sent.
478 * Enables appropriate interrupts and sends start xfer command.
479 */
480static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop)
481{
482 u32 i2c_ctl;
483 u32 int_en = HSI2C_INT_I2C_EN;
484 u32 i2c_auto_conf = 0;
485 u32 fifo_ctl;
486 unsigned long flags;
487
488 i2c_ctl = readl(i2c->regs + HSI2C_CTL);
489 i2c_ctl &= ~(HSI2C_TXCHON | HSI2C_RXCHON);
490 fifo_ctl = HSI2C_RXFIFO_EN | HSI2C_TXFIFO_EN;
491
492 if (i2c->msg->flags & I2C_M_RD) {
493 i2c_ctl |= HSI2C_RXCHON;
494
495 i2c_auto_conf = HSI2C_READ_WRITE;
496
497 fifo_ctl |= HSI2C_RXFIFO_TRIGGER_LEVEL(HSI2C_DEF_TXFIFO_LVL);
498 int_en |= (HSI2C_INT_RX_ALMOSTFULL_EN |
499 HSI2C_INT_TRAILING_EN);
500 } else {
501 i2c_ctl |= HSI2C_TXCHON;
502
503 fifo_ctl |= HSI2C_TXFIFO_TRIGGER_LEVEL(HSI2C_DEF_RXFIFO_LVL);
504 int_en |= HSI2C_INT_TX_ALMOSTEMPTY_EN;
505 }
506
507 writel(HSI2C_SLV_ADDR_MAS(i2c->msg->addr), i2c->regs + HSI2C_ADDR);
508
509 writel(fifo_ctl, i2c->regs + HSI2C_FIFO_CTL);
510 writel(i2c_ctl, i2c->regs + HSI2C_CTL);
511
512
513 /*
514 * Enable interrupts before starting the transfer so that we don't
515 * miss any INT_I2C interrupts.
516 */
517 spin_lock_irqsave(&i2c->lock, flags);
518 writel(int_en, i2c->regs + HSI2C_INT_ENABLE);
519
520 if (stop == 1)
521 i2c_auto_conf |= HSI2C_STOP_AFTER_TRANS;
522 i2c_auto_conf |= i2c->msg->len;
523 i2c_auto_conf |= HSI2C_MASTER_RUN;
524 writel(i2c_auto_conf, i2c->regs + HSI2C_AUTO_CONF);
525 spin_unlock_irqrestore(&i2c->lock, flags);
526}
527
528static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c,
529 struct i2c_msg *msgs, int stop)
530{
531 unsigned long timeout;
532 int ret;
533
534 i2c->msg = msgs;
535 i2c->msg_ptr = 0;
536 i2c->trans_done = 0;
537
538 reinit_completion(&i2c->msg_complete);
539
540 exynos5_i2c_message_start(i2c, stop);
541
542 timeout = wait_for_completion_timeout(&i2c->msg_complete,
543 EXYNOS5_I2C_TIMEOUT);
544 if (timeout == 0)
545 ret = -ETIMEDOUT;
546 else
547 ret = i2c->state;
548
549 /*
550 * If this is the last message to be transfered (stop == 1)
551 * Then check if the bus can be brought back to idle.
552 */
553 if (ret == 0 && stop)
554 ret = exynos5_i2c_wait_bus_idle(i2c);
555
556 if (ret < 0) {
557 exynos5_i2c_reset(i2c);
558 if (ret == -ETIMEDOUT)
559 dev_warn(i2c->dev, "%s timeout\n",
560 (msgs->flags & I2C_M_RD) ? "rx" : "tx");
561 }
562
563 /* Return the state as in interrupt routine */
564 return ret;
565}
566
567static int exynos5_i2c_xfer(struct i2c_adapter *adap,
568 struct i2c_msg *msgs, int num)
569{
570 struct exynos5_i2c *i2c = (struct exynos5_i2c *)adap->algo_data;
571 int i = 0, ret = 0, stop = 0;
572
573 if (i2c->suspended) {
574 dev_err(i2c->dev, "HS-I2C is not initialzed.\n");
575 return -EIO;
576 }
577
578 clk_prepare_enable(i2c->clk);
579
580 for (i = 0; i < num; i++, msgs++) {
581 stop = (i == num - 1);
582
583 ret = exynos5_i2c_xfer_msg(i2c, msgs, stop);
584
585 if (ret < 0)
586 goto out;
587 }
588
589 if (i == num) {
590 ret = num;
591 } else {
592 /* Only one message, cannot access the device */
593 if (i == 1)
594 ret = -EREMOTEIO;
595 else
596 ret = i;
597
598 dev_warn(i2c->dev, "xfer message failed\n");
599 }
600
601 out:
602 clk_disable_unprepare(i2c->clk);
603 return ret;
604}
605
606static u32 exynos5_i2c_func(struct i2c_adapter *adap)
607{
608 return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
609}
610
611static const struct i2c_algorithm exynos5_i2c_algorithm = {
612 .master_xfer = exynos5_i2c_xfer,
613 .functionality = exynos5_i2c_func,
614};
615
616static int exynos5_i2c_probe(struct platform_device *pdev)
617{
618 struct device_node *np = pdev->dev.of_node;
619 struct exynos5_i2c *i2c;
620 struct resource *mem;
621 unsigned int op_clock;
622 int ret;
623
624 i2c = devm_kzalloc(&pdev->dev, sizeof(struct exynos5_i2c), GFP_KERNEL);
625 if (!i2c) {
626 dev_err(&pdev->dev, "no memory for state\n");
627 return -ENOMEM;
628 }
629
630 if (of_property_read_u32(np, "clock-frequency", &op_clock)) {
631 i2c->speed_mode = HSI2C_FAST_SPD;
632 i2c->fs_clock = HSI2C_FS_TX_CLOCK;
633 } else {
634 if (op_clock >= HSI2C_HS_TX_CLOCK) {
635 i2c->speed_mode = HSI2C_HIGH_SPD;
636 i2c->fs_clock = HSI2C_FS_TX_CLOCK;
637 i2c->hs_clock = op_clock;
638 } else {
639 i2c->speed_mode = HSI2C_FAST_SPD;
640 i2c->fs_clock = op_clock;
641 }
642 }
643
644 strlcpy(i2c->adap.name, "exynos5-i2c", sizeof(i2c->adap.name));
645 i2c->adap.owner = THIS_MODULE;
646 i2c->adap.algo = &exynos5_i2c_algorithm;
647 i2c->adap.retries = 3;
648
649 i2c->dev = &pdev->dev;
650 i2c->clk = devm_clk_get(&pdev->dev, "hsi2c");
651 if (IS_ERR(i2c->clk)) {
652 dev_err(&pdev->dev, "cannot get clock\n");
653 return -ENOENT;
654 }
655
656 clk_prepare_enable(i2c->clk);
657
658 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
659 i2c->regs = devm_ioremap_resource(&pdev->dev, mem);
660 if (IS_ERR(i2c->regs)) {
661 ret = PTR_ERR(i2c->regs);
662 goto err_clk;
663 }
664
665 i2c->adap.dev.of_node = np;
666 i2c->adap.algo_data = i2c;
667 i2c->adap.dev.parent = &pdev->dev;
668
669 /* Clear pending interrupts from u-boot or misc causes */
670 exynos5_i2c_clr_pend_irq(i2c);
671
672 spin_lock_init(&i2c->lock);
673 init_completion(&i2c->msg_complete);
674
675 i2c->irq = ret = platform_get_irq(pdev, 0);
676 if (ret <= 0) {
677 dev_err(&pdev->dev, "cannot find HS-I2C IRQ\n");
678 ret = -EINVAL;
679 goto err_clk;
680 }
681
682 ret = devm_request_irq(&pdev->dev, i2c->irq, exynos5_i2c_irq,
683 IRQF_NO_SUSPEND | IRQF_ONESHOT,
684 dev_name(&pdev->dev), i2c);
685
686 if (ret != 0) {
687 dev_err(&pdev->dev, "cannot request HS-I2C IRQ %d\n", i2c->irq);
688 goto err_clk;
689 }
690
691 ret = exynos5_hsi2c_clock_setup(i2c);
692 if (ret)
693 goto err_clk;
694
695 exynos5_i2c_init(i2c);
696
697 ret = i2c_add_adapter(&i2c->adap);
698 if (ret < 0) {
699 dev_err(&pdev->dev, "failed to add bus to i2c core\n");
700 goto err_clk;
701 }
702
703 platform_set_drvdata(pdev, i2c);
704
705 err_clk:
706 clk_disable_unprepare(i2c->clk);
707 return ret;
708}
709
710static int exynos5_i2c_remove(struct platform_device *pdev)
711{
712 struct exynos5_i2c *i2c = platform_get_drvdata(pdev);
713
714 i2c_del_adapter(&i2c->adap);
715
716 return 0;
717}
718
719static int exynos5_i2c_suspend_noirq(struct device *dev)
720{
721 struct platform_device *pdev = to_platform_device(dev);
722 struct exynos5_i2c *i2c = platform_get_drvdata(pdev);
723
724 i2c->suspended = 1;
725
726 return 0;
727}
728
729static int exynos5_i2c_resume_noirq(struct device *dev)
730{
731 struct platform_device *pdev = to_platform_device(dev);
732 struct exynos5_i2c *i2c = platform_get_drvdata(pdev);
733 int ret = 0;
734
735 clk_prepare_enable(i2c->clk);
736
737 ret = exynos5_hsi2c_clock_setup(i2c);
738 if (ret) {
739 clk_disable_unprepare(i2c->clk);
740 return ret;
741 }
742
743 exynos5_i2c_init(i2c);
744 clk_disable_unprepare(i2c->clk);
745 i2c->suspended = 0;
746
747 return 0;
748}
749
750static SIMPLE_DEV_PM_OPS(exynos5_i2c_dev_pm_ops, exynos5_i2c_suspend_noirq,
751 exynos5_i2c_resume_noirq);
752
753static struct platform_driver exynos5_i2c_driver = {
754 .probe = exynos5_i2c_probe,
755 .remove = exynos5_i2c_remove,
756 .driver = {
757 .owner = THIS_MODULE,
758 .name = "exynos5-hsi2c",
759 .pm = &exynos5_i2c_dev_pm_ops,
760 .of_match_table = exynos5_i2c_match,
761 },
762};
763
764module_platform_driver(exynos5_i2c_driver);
765
766MODULE_DESCRIPTION("Exynos5 HS-I2C Bus driver");
767MODULE_AUTHOR("Naveen Krishna Chatradhi, <ch.naveen@samsung.com>");
768MODULE_AUTHOR("Taekgyun Ko, <taeggyun.ko@samsung.com>");
769MODULE_LICENSE("GPL v2");
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index bfa02c6c2dda..d9f7e186a4c7 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -15,6 +15,7 @@
15#include <linux/slab.h> 15#include <linux/slab.h>
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/of.h>
18#include <linux/of_gpio.h> 19#include <linux/of_gpio.h>
19 20
20struct i2c_gpio_private_data { 21struct i2c_gpio_private_data {
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 4296d1721272..737e29866887 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -59,6 +59,7 @@
59 Wellsburg (PCH) MS 0x8d7e 32 hard yes yes yes 59 Wellsburg (PCH) MS 0x8d7e 32 hard yes yes yes
60 Wellsburg (PCH) MS 0x8d7f 32 hard yes yes yes 60 Wellsburg (PCH) MS 0x8d7f 32 hard yes yes yes
61 Coleto Creek (PCH) 0x23b0 32 hard yes yes yes 61 Coleto Creek (PCH) 0x23b0 32 hard yes yes yes
62 Wildcat Point-LP (PCH) 0x9ca2 32 hard yes yes yes
62 63
63 Features supported by this driver: 64 Features supported by this driver:
64 Software PEC no 65 Software PEC no
@@ -177,6 +178,7 @@
177#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1 0x8d7e 178#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1 0x8d7e
178#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2 0x8d7f 179#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2 0x8d7f
179#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22 180#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22
181#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS 0x9ca2
180 182
181struct i801_mux_config { 183struct i801_mux_config {
182 char *gpio_chip; 184 char *gpio_chip;
@@ -819,6 +821,7 @@ static DEFINE_PCI_DEVICE_TABLE(i801_ids) = {
819 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1) }, 821 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1) },
820 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) }, 822 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) },
821 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS) }, 823 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS) },
824 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS) },
822 { 0, } 825 { 0, }
823}; 826};
824 827
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index d3e9cc3153a9..8be7e42aa4de 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -911,7 +911,7 @@ static struct platform_driver mv64xxx_i2c_driver = {
911 .driver = { 911 .driver = {
912 .owner = THIS_MODULE, 912 .owner = THIS_MODULE,
913 .name = MV64XXX_I2C_CTLR_NAME, 913 .name = MV64XXX_I2C_CTLR_NAME,
914 .of_match_table = of_match_ptr(mv64xxx_i2c_of_match_table), 914 .of_match_table = mv64xxx_i2c_of_match_table,
915 }, 915 },
916}; 916};
917 917
diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c
index 3aedd86a6468..0cde4e6ab2b2 100644
--- a/drivers/i2c/busses/i2c-mxs.c
+++ b/drivers/i2c/busses/i2c-mxs.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Freescale MXS I2C bus driver 2 * Freescale MXS I2C bus driver
3 * 3 *
4 * Copyright (C) 2012-2013 Marek Vasut <marex@denx.de>
4 * Copyright (C) 2011-2012 Wolfram Sang, Pengutronix e.K. 5 * Copyright (C) 2011-2012 Wolfram Sang, Pengutronix e.K.
5 * 6 *
6 * based on a (non-working) driver which was: 7 * based on a (non-working) driver which was:
@@ -34,10 +35,12 @@
34 35
35#define MXS_I2C_CTRL0 (0x00) 36#define MXS_I2C_CTRL0 (0x00)
36#define MXS_I2C_CTRL0_SET (0x04) 37#define MXS_I2C_CTRL0_SET (0x04)
38#define MXS_I2C_CTRL0_CLR (0x08)
37 39
38#define MXS_I2C_CTRL0_SFTRST 0x80000000 40#define MXS_I2C_CTRL0_SFTRST 0x80000000
39#define MXS_I2C_CTRL0_RUN 0x20000000 41#define MXS_I2C_CTRL0_RUN 0x20000000
40#define MXS_I2C_CTRL0_SEND_NAK_ON_LAST 0x02000000 42#define MXS_I2C_CTRL0_SEND_NAK_ON_LAST 0x02000000
43#define MXS_I2C_CTRL0_PIO_MODE 0x01000000
41#define MXS_I2C_CTRL0_RETAIN_CLOCK 0x00200000 44#define MXS_I2C_CTRL0_RETAIN_CLOCK 0x00200000
42#define MXS_I2C_CTRL0_POST_SEND_STOP 0x00100000 45#define MXS_I2C_CTRL0_POST_SEND_STOP 0x00100000
43#define MXS_I2C_CTRL0_PRE_SEND_START 0x00080000 46#define MXS_I2C_CTRL0_PRE_SEND_START 0x00080000
@@ -64,13 +67,13 @@
64#define MXS_I2C_CTRL1_SLAVE_IRQ 0x01 67#define MXS_I2C_CTRL1_SLAVE_IRQ 0x01
65 68
66#define MXS_I2C_STAT (0x50) 69#define MXS_I2C_STAT (0x50)
70#define MXS_I2C_STAT_GOT_A_NAK 0x10000000
67#define MXS_I2C_STAT_BUS_BUSY 0x00000800 71#define MXS_I2C_STAT_BUS_BUSY 0x00000800
68#define MXS_I2C_STAT_CLK_GEN_BUSY 0x00000400 72#define MXS_I2C_STAT_CLK_GEN_BUSY 0x00000400
69 73
70#define MXS_I2C_DATA (0xa0) 74#define MXS_I2C_DATA(i2c) ((i2c->dev_type == MXS_I2C_V1) ? 0x60 : 0xa0)
71 75
72#define MXS_I2C_DEBUG0 (0xb0) 76#define MXS_I2C_DEBUG0_CLR(i2c) ((i2c->dev_type == MXS_I2C_V1) ? 0x78 : 0xb8)
73#define MXS_I2C_DEBUG0_CLR (0xb8)
74 77
75#define MXS_I2C_DEBUG0_DMAREQ 0x80000000 78#define MXS_I2C_DEBUG0_DMAREQ 0x80000000
76 79
@@ -95,10 +98,17 @@
95#define MXS_CMD_I2C_READ (MXS_I2C_CTRL0_SEND_NAK_ON_LAST | \ 98#define MXS_CMD_I2C_READ (MXS_I2C_CTRL0_SEND_NAK_ON_LAST | \
96 MXS_I2C_CTRL0_MASTER_MODE) 99 MXS_I2C_CTRL0_MASTER_MODE)
97 100
101enum mxs_i2c_devtype {
102 MXS_I2C_UNKNOWN = 0,
103 MXS_I2C_V1,
104 MXS_I2C_V2,
105};
106
98/** 107/**
99 * struct mxs_i2c_dev - per device, private MXS-I2C data 108 * struct mxs_i2c_dev - per device, private MXS-I2C data
100 * 109 *
101 * @dev: driver model device node 110 * @dev: driver model device node
111 * @dev_type: distinguish i.MX23/i.MX28 features
102 * @regs: IO registers pointer 112 * @regs: IO registers pointer
103 * @cmd_complete: completion object for transaction wait 113 * @cmd_complete: completion object for transaction wait
104 * @cmd_err: error code for last transaction 114 * @cmd_err: error code for last transaction
@@ -106,6 +116,7 @@
106 */ 116 */
107struct mxs_i2c_dev { 117struct mxs_i2c_dev {
108 struct device *dev; 118 struct device *dev;
119 enum mxs_i2c_devtype dev_type;
109 void __iomem *regs; 120 void __iomem *regs;
110 struct completion cmd_complete; 121 struct completion cmd_complete;
111 int cmd_err; 122 int cmd_err;
@@ -291,48 +302,11 @@ write_init_pio_fail:
291 return -EINVAL; 302 return -EINVAL;
292} 303}
293 304
294static int mxs_i2c_pio_wait_dmareq(struct mxs_i2c_dev *i2c) 305static int mxs_i2c_pio_wait_xfer_end(struct mxs_i2c_dev *i2c)
295{ 306{
296 unsigned long timeout = jiffies + msecs_to_jiffies(1000); 307 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
297 308
298 while (!(readl(i2c->regs + MXS_I2C_DEBUG0) & 309 while (readl(i2c->regs + MXS_I2C_CTRL0) & MXS_I2C_CTRL0_RUN) {
299 MXS_I2C_DEBUG0_DMAREQ)) {
300 if (time_after(jiffies, timeout))
301 return -ETIMEDOUT;
302 cond_resched();
303 }
304
305 return 0;
306}
307
308static int mxs_i2c_pio_wait_cplt(struct mxs_i2c_dev *i2c, int last)
309{
310 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
311
312 /*
313 * We do not use interrupts in the PIO mode. Due to the
314 * maximum transfer length being 8 bytes in PIO mode, the
315 * overhead of interrupt would be too large and this would
316 * neglect the gain from using the PIO mode.
317 */
318
319 while (!(readl(i2c->regs + MXS_I2C_CTRL1) &
320 MXS_I2C_CTRL1_DATA_ENGINE_CMPLT_IRQ)) {
321 if (time_after(jiffies, timeout))
322 return -ETIMEDOUT;
323 cond_resched();
324 }
325
326 writel(MXS_I2C_CTRL1_DATA_ENGINE_CMPLT_IRQ,
327 i2c->regs + MXS_I2C_CTRL1_CLR);
328
329 /*
330 * When ending a transfer with a stop, we have to wait for the bus to
331 * go idle before we report the transfer as completed. Otherwise the
332 * start of the next transfer may race with the end of the current one.
333 */
334 while (last && (readl(i2c->regs + MXS_I2C_STAT) &
335 (MXS_I2C_STAT_BUS_BUSY | MXS_I2C_STAT_CLK_GEN_BUSY))) {
336 if (time_after(jiffies, timeout)) 310 if (time_after(jiffies, timeout))
337 return -ETIMEDOUT; 311 return -ETIMEDOUT;
338 cond_resched(); 312 cond_resched();
@@ -370,106 +344,215 @@ static void mxs_i2c_pio_trigger_cmd(struct mxs_i2c_dev *i2c, u32 cmd)
370 writel(reg, i2c->regs + MXS_I2C_CTRL0); 344 writel(reg, i2c->regs + MXS_I2C_CTRL0);
371} 345}
372 346
347/*
348 * Start WRITE transaction on the I2C bus. By studying i.MX23 datasheet,
349 * CTRL0::PIO_MODE bit description clarifies the order in which the registers
350 * must be written during PIO mode operation. First, the CTRL0 register has
351 * to be programmed with all the necessary bits but the RUN bit. Then the
352 * payload has to be written into the DATA register. Finally, the transmission
353 * is executed by setting the RUN bit in CTRL0.
354 */
355static void mxs_i2c_pio_trigger_write_cmd(struct mxs_i2c_dev *i2c, u32 cmd,
356 u32 data)
357{
358 writel(cmd, i2c->regs + MXS_I2C_CTRL0);
359
360 if (i2c->dev_type == MXS_I2C_V1)
361 writel(MXS_I2C_CTRL0_PIO_MODE, i2c->regs + MXS_I2C_CTRL0_SET);
362
363 writel(data, i2c->regs + MXS_I2C_DATA(i2c));
364 writel(MXS_I2C_CTRL0_RUN, i2c->regs + MXS_I2C_CTRL0_SET);
365}
366
373static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap, 367static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap,
374 struct i2c_msg *msg, uint32_t flags) 368 struct i2c_msg *msg, uint32_t flags)
375{ 369{
376 struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap); 370 struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap);
377 uint32_t addr_data = msg->addr << 1; 371 uint32_t addr_data = msg->addr << 1;
378 uint32_t data = 0; 372 uint32_t data = 0;
379 int i, shifts_left, ret; 373 int i, ret, xlen = 0, xmit = 0;
374 uint32_t start;
380 375
381 /* Mute IRQs coming from this block. */ 376 /* Mute IRQs coming from this block. */
382 writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_CLR); 377 writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_CLR);
383 378
379 /*
380 * MX23 idea:
381 * - Enable CTRL0::PIO_MODE (1 << 24)
382 * - Enable CTRL1::ACK_MODE (1 << 27)
383 *
384 * WARNING! The MX23 is broken in some way, even if it claims
385 * to support PIO, when we try to transfer any amount of data
386 * that is not aligned to 4 bytes, the DMA engine will have
387 * bits in DEBUG1::DMA_BYTES_ENABLES still set even after the
388 * transfer. This in turn will mess up the next transfer as
389 * the block it emit one byte write onto the bus terminated
390 * with a NAK+STOP. A possible workaround is to reset the IP
391 * block after every PIO transmission, which might just work.
392 *
393 * NOTE: The CTRL0::PIO_MODE description is important, since
394 * it outlines how the PIO mode is really supposed to work.
395 */
384 if (msg->flags & I2C_M_RD) { 396 if (msg->flags & I2C_M_RD) {
397 /*
398 * PIO READ transfer:
399 *
400 * This transfer MUST be limited to 4 bytes maximum. It is not
401 * possible to transfer more than four bytes via PIO, since we
402 * can not in any way make sure we can read the data from the
403 * DATA register fast enough. Besides, the RX FIFO is only four
404 * bytes deep, thus we can only really read up to four bytes at
405 * time. Finally, there is no bit indicating us that new data
406 * arrived at the FIFO and can thus be fetched from the DATA
407 * register.
408 */
409 BUG_ON(msg->len > 4);
410
385 addr_data |= I2C_SMBUS_READ; 411 addr_data |= I2C_SMBUS_READ;
386 412
387 /* SELECT command. */ 413 /* SELECT command. */
388 mxs_i2c_pio_trigger_cmd(i2c, MXS_CMD_I2C_SELECT); 414 mxs_i2c_pio_trigger_write_cmd(i2c, MXS_CMD_I2C_SELECT,
389 415 addr_data);
390 ret = mxs_i2c_pio_wait_dmareq(i2c);
391 if (ret)
392 return ret;
393
394 writel(addr_data, i2c->regs + MXS_I2C_DATA);
395 writel(MXS_I2C_DEBUG0_DMAREQ, i2c->regs + MXS_I2C_DEBUG0_CLR);
396 416
397 ret = mxs_i2c_pio_wait_cplt(i2c, 0); 417 ret = mxs_i2c_pio_wait_xfer_end(i2c);
398 if (ret) 418 if (ret) {
399 return ret; 419 dev_err(i2c->dev,
400 420 "PIO: Failed to send SELECT command!\n");
401 if (mxs_i2c_pio_check_error_state(i2c))
402 goto cleanup; 421 goto cleanup;
422 }
403 423
404 /* READ command. */ 424 /* READ command. */
405 mxs_i2c_pio_trigger_cmd(i2c, 425 mxs_i2c_pio_trigger_cmd(i2c,
406 MXS_CMD_I2C_READ | flags | 426 MXS_CMD_I2C_READ | flags |
407 MXS_I2C_CTRL0_XFER_COUNT(msg->len)); 427 MXS_I2C_CTRL0_XFER_COUNT(msg->len));
408 428
429 ret = mxs_i2c_pio_wait_xfer_end(i2c);
430 if (ret) {
431 dev_err(i2c->dev,
432 "PIO: Failed to send SELECT command!\n");
433 goto cleanup;
434 }
435
436 data = readl(i2c->regs + MXS_I2C_DATA(i2c));
409 for (i = 0; i < msg->len; i++) { 437 for (i = 0; i < msg->len; i++) {
410 if ((i & 3) == 0) {
411 ret = mxs_i2c_pio_wait_dmareq(i2c);
412 if (ret)
413 return ret;
414 data = readl(i2c->regs + MXS_I2C_DATA);
415 writel(MXS_I2C_DEBUG0_DMAREQ,
416 i2c->regs + MXS_I2C_DEBUG0_CLR);
417 }
418 msg->buf[i] = data & 0xff; 438 msg->buf[i] = data & 0xff;
419 data >>= 8; 439 data >>= 8;
420 } 440 }
421 } else { 441 } else {
442 /*
443 * PIO WRITE transfer:
444 *
445 * The code below implements clock stretching to circumvent
446 * the possibility of kernel not being able to supply data
447 * fast enough. It is possible to transfer arbitrary amount
448 * of data using PIO write.
449 */
422 addr_data |= I2C_SMBUS_WRITE; 450 addr_data |= I2C_SMBUS_WRITE;
423 451
424 /* WRITE command. */
425 mxs_i2c_pio_trigger_cmd(i2c,
426 MXS_CMD_I2C_WRITE | flags |
427 MXS_I2C_CTRL0_XFER_COUNT(msg->len + 1));
428
429 /* 452 /*
430 * The LSB of data buffer is the first byte blasted across 453 * The LSB of data buffer is the first byte blasted across
431 * the bus. Higher order bytes follow. Thus the following 454 * the bus. Higher order bytes follow. Thus the following
432 * filling schematic. 455 * filling schematic.
433 */ 456 */
457
434 data = addr_data << 24; 458 data = addr_data << 24;
459
460 /* Start the transfer with START condition. */
461 start = MXS_I2C_CTRL0_PRE_SEND_START;
462
463 /* If the transfer is long, use clock stretching. */
464 if (msg->len > 3)
465 start |= MXS_I2C_CTRL0_RETAIN_CLOCK;
466
435 for (i = 0; i < msg->len; i++) { 467 for (i = 0; i < msg->len; i++) {
436 data >>= 8; 468 data >>= 8;
437 data |= (msg->buf[i] << 24); 469 data |= (msg->buf[i] << 24);
438 if ((i & 3) == 2) { 470
439 ret = mxs_i2c_pio_wait_dmareq(i2c); 471 xmit = 0;
440 if (ret) 472
441 return ret; 473 /* This is the last transfer of the message. */
442 writel(data, i2c->regs + MXS_I2C_DATA); 474 if (i + 1 == msg->len) {
443 writel(MXS_I2C_DEBUG0_DMAREQ, 475 /* Add optional STOP flag. */
444 i2c->regs + MXS_I2C_DEBUG0_CLR); 476 start |= flags;
477 /* Remove RETAIN_CLOCK bit. */
478 start &= ~MXS_I2C_CTRL0_RETAIN_CLOCK;
479 xmit = 1;
445 } 480 }
446 }
447 481
448 shifts_left = 24 - (i & 3) * 8; 482 /* Four bytes are ready in the "data" variable. */
449 if (shifts_left) { 483 if ((i & 3) == 2)
450 data >>= shifts_left; 484 xmit = 1;
451 ret = mxs_i2c_pio_wait_dmareq(i2c); 485
452 if (ret) 486 /* Nothing interesting happened, continue stuffing. */
453 return ret; 487 if (!xmit)
454 writel(data, i2c->regs + MXS_I2C_DATA); 488 continue;
489
490 /*
491 * Compute the size of the transfer and shift the
492 * data accordingly.
493 *
494 * i = (4k + 0) .... xlen = 2
495 * i = (4k + 1) .... xlen = 3
496 * i = (4k + 2) .... xlen = 4
497 * i = (4k + 3) .... xlen = 1
498 */
499
500 if ((i % 4) == 3)
501 xlen = 1;
502 else
503 xlen = (i % 4) + 2;
504
505 data >>= (4 - xlen) * 8;
506
507 dev_dbg(i2c->dev,
508 "PIO: len=%i pos=%i total=%i [W%s%s%s]\n",
509 xlen, i, msg->len,
510 start & MXS_I2C_CTRL0_PRE_SEND_START ? "S" : "",
511 start & MXS_I2C_CTRL0_POST_SEND_STOP ? "E" : "",
512 start & MXS_I2C_CTRL0_RETAIN_CLOCK ? "C" : "");
513
455 writel(MXS_I2C_DEBUG0_DMAREQ, 514 writel(MXS_I2C_DEBUG0_DMAREQ,
456 i2c->regs + MXS_I2C_DEBUG0_CLR); 515 i2c->regs + MXS_I2C_DEBUG0_CLR(i2c));
516
517 mxs_i2c_pio_trigger_write_cmd(i2c,
518 start | MXS_I2C_CTRL0_MASTER_MODE |
519 MXS_I2C_CTRL0_DIRECTION |
520 MXS_I2C_CTRL0_XFER_COUNT(xlen), data);
521
522 /* The START condition is sent only once. */
523 start &= ~MXS_I2C_CTRL0_PRE_SEND_START;
524
525 /* Wait for the end of the transfer. */
526 ret = mxs_i2c_pio_wait_xfer_end(i2c);
527 if (ret) {
528 dev_err(i2c->dev,
529 "PIO: Failed to finish WRITE cmd!\n");
530 break;
531 }
532
533 /* Check NAK here. */
534 ret = readl(i2c->regs + MXS_I2C_STAT) &
535 MXS_I2C_STAT_GOT_A_NAK;
536 if (ret) {
537 ret = -ENXIO;
538 goto cleanup;
539 }
457 } 540 }
458 } 541 }
459 542
460 ret = mxs_i2c_pio_wait_cplt(i2c, flags & MXS_I2C_CTRL0_POST_SEND_STOP);
461 if (ret)
462 return ret;
463
464 /* make sure we capture any occurred error into cmd_err */ 543 /* make sure we capture any occurred error into cmd_err */
465 mxs_i2c_pio_check_error_state(i2c); 544 ret = mxs_i2c_pio_check_error_state(i2c);
466 545
467cleanup: 546cleanup:
468 /* Clear any dangling IRQs and re-enable interrupts. */ 547 /* Clear any dangling IRQs and re-enable interrupts. */
469 writel(MXS_I2C_IRQ_MASK, i2c->regs + MXS_I2C_CTRL1_CLR); 548 writel(MXS_I2C_IRQ_MASK, i2c->regs + MXS_I2C_CTRL1_CLR);
470 writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_SET); 549 writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_SET);
471 550
472 return 0; 551 /* Clear the PIO_MODE on i.MX23 */
552 if (i2c->dev_type == MXS_I2C_V1)
553 writel(MXS_I2C_CTRL0_PIO_MODE, i2c->regs + MXS_I2C_CTRL0_CLR);
554
555 return ret;
473} 556}
474 557
475/* 558/*
@@ -479,8 +562,9 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
479 int stop) 562 int stop)
480{ 563{
481 struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap); 564 struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap);
482 int ret, err; 565 int ret;
483 int flags; 566 int flags;
567 int use_pio = 0;
484 568
485 flags = stop ? MXS_I2C_CTRL0_POST_SEND_STOP : 0; 569 flags = stop ? MXS_I2C_CTRL0_POST_SEND_STOP : 0;
486 570
@@ -491,19 +575,21 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
491 return -EINVAL; 575 return -EINVAL;
492 576
493 /* 577 /*
494 * The current boundary to select between PIO/DMA transfer method 578 * The MX28 I2C IP block can only do PIO READ for transfer of to up
495 * is set to 8 bytes, transfers shorter than 8 bytes are transfered 579 * 4 bytes of length. The write transfer is not limited as it can use
496 * using PIO mode while longer transfers use DMA. The 8 byte border is 580 * clock stretching to avoid FIFO underruns.
497 * based on this empirical measurement and a lot of previous frobbing.
498 */ 581 */
582 if ((msg->flags & I2C_M_RD) && (msg->len <= 4))
583 use_pio = 1;
584 if (!(msg->flags & I2C_M_RD) && (msg->len < 7))
585 use_pio = 1;
586
499 i2c->cmd_err = 0; 587 i2c->cmd_err = 0;
500 if (0) { /* disable PIO mode until a proper fix is made */ 588 if (use_pio) {
501 ret = mxs_i2c_pio_setup_xfer(adap, msg, flags); 589 ret = mxs_i2c_pio_setup_xfer(adap, msg, flags);
502 if (ret) { 590 /* No need to reset the block if NAK was received. */
503 err = mxs_i2c_reset(i2c); 591 if (ret && (ret != -ENXIO))
504 if (err) 592 mxs_i2c_reset(i2c);
505 return err;
506 }
507 } else { 593 } else {
508 reinit_completion(&i2c->cmd_complete); 594 reinit_completion(&i2c->cmd_complete);
509 ret = mxs_i2c_dma_setup_xfer(adap, msg, flags); 595 ret = mxs_i2c_dma_setup_xfer(adap, msg, flags);
@@ -514,9 +600,11 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
514 msecs_to_jiffies(1000)); 600 msecs_to_jiffies(1000));
515 if (ret == 0) 601 if (ret == 0)
516 goto timeout; 602 goto timeout;
603
604 ret = i2c->cmd_err;
517 } 605 }
518 606
519 if (i2c->cmd_err == -ENXIO) { 607 if (ret == -ENXIO) {
520 /* 608 /*
521 * If the transfer fails with a NAK from the slave the 609 * If the transfer fails with a NAK from the slave the
522 * controller halts until it gets told to return to idle state. 610 * controller halts until it gets told to return to idle state.
@@ -525,7 +613,19 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
525 i2c->regs + MXS_I2C_CTRL1_SET); 613 i2c->regs + MXS_I2C_CTRL1_SET);
526 } 614 }
527 615
528 ret = i2c->cmd_err; 616 /*
617 * WARNING!
618 * The i.MX23 is strange. After each and every operation, it's I2C IP
619 * block must be reset, otherwise the IP block will misbehave. This can
620 * be observed on the bus by the block sending out one single byte onto
621 * the bus. In case such an error happens, bit 27 will be set in the
622 * DEBUG0 register. This bit is not documented in the i.MX23 datasheet
623 * and is marked as "TBD" instead. To reset this bit to a correct state,
624 * reset the whole block. Since the block reset does not take long, do
625 * reset the block after every transfer to play safe.
626 */
627 if (i2c->dev_type == MXS_I2C_V1)
628 mxs_i2c_reset(i2c);
529 629
530 dev_dbg(i2c->dev, "Done with err=%d\n", ret); 630 dev_dbg(i2c->dev, "Done with err=%d\n", ret);
531 631
@@ -680,8 +780,28 @@ static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c)
680 return 0; 780 return 0;
681} 781}
682 782
783static struct platform_device_id mxs_i2c_devtype[] = {
784 {
785 .name = "imx23-i2c",
786 .driver_data = MXS_I2C_V1,
787 }, {
788 .name = "imx28-i2c",
789 .driver_data = MXS_I2C_V2,
790 }, { /* sentinel */ }
791};
792MODULE_DEVICE_TABLE(platform, mxs_i2c_devtype);
793
794static const struct of_device_id mxs_i2c_dt_ids[] = {
795 { .compatible = "fsl,imx23-i2c", .data = &mxs_i2c_devtype[0], },
796 { .compatible = "fsl,imx28-i2c", .data = &mxs_i2c_devtype[1], },
797 { /* sentinel */ }
798};
799MODULE_DEVICE_TABLE(of, mxs_i2c_dt_ids);
800
683static int mxs_i2c_probe(struct platform_device *pdev) 801static int mxs_i2c_probe(struct platform_device *pdev)
684{ 802{
803 const struct of_device_id *of_id =
804 of_match_device(mxs_i2c_dt_ids, &pdev->dev);
685 struct device *dev = &pdev->dev; 805 struct device *dev = &pdev->dev;
686 struct mxs_i2c_dev *i2c; 806 struct mxs_i2c_dev *i2c;
687 struct i2c_adapter *adap; 807 struct i2c_adapter *adap;
@@ -693,6 +813,11 @@ static int mxs_i2c_probe(struct platform_device *pdev)
693 if (!i2c) 813 if (!i2c)
694 return -ENOMEM; 814 return -ENOMEM;
695 815
816 if (of_id) {
817 const struct platform_device_id *device_id = of_id->data;
818 i2c->dev_type = device_id->driver_data;
819 }
820
696 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 821 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
697 irq = platform_get_irq(pdev, 0); 822 irq = platform_get_irq(pdev, 0);
698 823
@@ -768,12 +893,6 @@ static int mxs_i2c_remove(struct platform_device *pdev)
768 return 0; 893 return 0;
769} 894}
770 895
771static const struct of_device_id mxs_i2c_dt_ids[] = {
772 { .compatible = "fsl,imx28-i2c", },
773 { /* sentinel */ }
774};
775MODULE_DEVICE_TABLE(of, mxs_i2c_dt_ids);
776
777static struct platform_driver mxs_i2c_driver = { 896static struct platform_driver mxs_i2c_driver = {
778 .driver = { 897 .driver = {
779 .name = DRIVER_NAME, 898 .name = DRIVER_NAME,
@@ -796,6 +915,7 @@ static void __exit mxs_i2c_exit(void)
796} 915}
797module_exit(mxs_i2c_exit); 916module_exit(mxs_i2c_exit);
798 917
918MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
799MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>"); 919MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>");
800MODULE_DESCRIPTION("MXS I2C Bus Driver"); 920MODULE_DESCRIPTION("MXS I2C Bus Driver");
801MODULE_LICENSE("GPL"); 921MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index 1a9ea25f2314..c9a352f0a9a5 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -23,6 +23,7 @@
23#include <linux/err.h> 23#include <linux/err.h>
24#include <linux/clk.h> 24#include <linux/clk.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/of.h>
26 27
27#define I2C_PNX_TIMEOUT_DEFAULT 10 /* msec */ 28#define I2C_PNX_TIMEOUT_DEFAULT 10 /* msec */
28#define I2C_PNX_SPEED_KHZ_DEFAULT 100 29#define I2C_PNX_SPEED_KHZ_DEFAULT 100
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index d2fe11da5e82..2c2fd7c2b116 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -33,6 +33,7 @@
33#include <linux/i2c/i2c-rcar.h> 33#include <linux/i2c/i2c-rcar.h>
34#include <linux/kernel.h> 34#include <linux/kernel.h>
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/of_device.h>
36#include <linux/platform_device.h> 37#include <linux/platform_device.h>
37#include <linux/pm_runtime.h> 38#include <linux/pm_runtime.h>
38#include <linux/slab.h> 39#include <linux/slab.h>
@@ -102,8 +103,8 @@ enum {
102#define ID_NACK (1 << 4) 103#define ID_NACK (1 << 4)
103 104
104enum rcar_i2c_type { 105enum rcar_i2c_type {
105 I2C_RCAR_H1, 106 I2C_RCAR_GEN1,
106 I2C_RCAR_H2, 107 I2C_RCAR_GEN2,
107}; 108};
108 109
109struct rcar_i2c_priv { 110struct rcar_i2c_priv {
@@ -226,22 +227,23 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
226 u32 bus_speed, 227 u32 bus_speed,
227 struct device *dev) 228 struct device *dev)
228{ 229{
229 struct clk *clkp = clk_get(NULL, "peripheral_clk"); 230 struct clk *clkp = clk_get(dev, NULL);
230 u32 scgd, cdf; 231 u32 scgd, cdf;
231 u32 round, ick; 232 u32 round, ick;
232 u32 scl; 233 u32 scl;
233 u32 cdf_width; 234 u32 cdf_width;
235 unsigned long rate;
234 236
235 if (!clkp) { 237 if (IS_ERR(clkp)) {
236 dev_err(dev, "there is no peripheral_clk\n"); 238 dev_err(dev, "couldn't get clock\n");
237 return -EIO; 239 return PTR_ERR(clkp);
238 } 240 }
239 241
240 switch (priv->devtype) { 242 switch (priv->devtype) {
241 case I2C_RCAR_H1: 243 case I2C_RCAR_GEN1:
242 cdf_width = 2; 244 cdf_width = 2;
243 break; 245 break;
244 case I2C_RCAR_H2: 246 case I2C_RCAR_GEN2:
245 cdf_width = 3; 247 cdf_width = 3;
246 break; 248 break;
247 default: 249 default:
@@ -264,15 +266,14 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
264 * clkp : peripheral_clk 266 * clkp : peripheral_clk
265 * F[] : integer up-valuation 267 * F[] : integer up-valuation
266 */ 268 */
267 for (cdf = 0; cdf < (1 << cdf_width); cdf++) { 269 rate = clk_get_rate(clkp);
268 ick = clk_get_rate(clkp) / (1 + cdf); 270 cdf = rate / 20000000;
269 if (ick < 20000000) 271 if (cdf >= 1 << cdf_width) {
270 goto ick_find; 272 dev_err(dev, "Input clock %lu too high\n", rate);
273 return -EIO;
271 } 274 }
272 dev_err(dev, "there is no best CDF\n"); 275 ick = rate / (cdf + 1);
273 return -EIO;
274 276
275ick_find:
276 /* 277 /*
277 * it is impossible to calculate large scale 278 * it is impossible to calculate large scale
278 * number on u32. separate it 279 * number on u32. separate it
@@ -290,6 +291,12 @@ ick_find:
290 * 291 *
291 * Calculation result (= SCL) should be less than 292 * Calculation result (= SCL) should be less than
292 * bus_speed for hardware safety 293 * bus_speed for hardware safety
294 *
295 * We could use something along the lines of
296 * div = ick / (bus_speed + 1) + 1;
297 * scgd = (div - 20 - round + 7) / 8;
298 * scl = ick / (20 + (scgd * 8) + round);
299 * (not fully verified) but that would get pretty involved
293 */ 300 */
294 for (scgd = 0; scgd < 0x40; scgd++) { 301 for (scgd = 0; scgd < 0x40; scgd++) {
295 scl = ick / (20 + (scgd * 8) + round); 302 scl = ick / (20 + (scgd * 8) + round);
@@ -306,7 +313,7 @@ scgd_find:
306 /* 313 /*
307 * keep icccr value 314 * keep icccr value
308 */ 315 */
309 priv->icccr = (scgd << (cdf_width) | cdf); 316 priv->icccr = scgd << cdf_width | cdf;
310 317
311 return 0; 318 return 0;
312} 319}
@@ -632,6 +639,15 @@ static const struct i2c_algorithm rcar_i2c_algo = {
632 .functionality = rcar_i2c_func, 639 .functionality = rcar_i2c_func,
633}; 640};
634 641
642static const struct of_device_id rcar_i2c_dt_ids[] = {
643 { .compatible = "renesas,i2c-rcar", .data = (void *)I2C_RCAR_GEN1 },
644 { .compatible = "renesas,i2c-r8a7778", .data = (void *)I2C_RCAR_GEN1 },
645 { .compatible = "renesas,i2c-r8a7779", .data = (void *)I2C_RCAR_GEN1 },
646 { .compatible = "renesas,i2c-r8a7790", .data = (void *)I2C_RCAR_GEN2 },
647 {},
648};
649MODULE_DEVICE_TABLE(of, rcar_i2c_dt_ids);
650
635static int rcar_i2c_probe(struct platform_device *pdev) 651static int rcar_i2c_probe(struct platform_device *pdev)
636{ 652{
637 struct i2c_rcar_platform_data *pdata = dev_get_platdata(&pdev->dev); 653 struct i2c_rcar_platform_data *pdata = dev_get_platdata(&pdev->dev);
@@ -649,10 +665,15 @@ static int rcar_i2c_probe(struct platform_device *pdev)
649 } 665 }
650 666
651 bus_speed = 100000; /* default 100 kHz */ 667 bus_speed = 100000; /* default 100 kHz */
652 if (pdata && pdata->bus_speed) 668 ret = of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed);
669 if (ret < 0 && pdata && pdata->bus_speed)
653 bus_speed = pdata->bus_speed; 670 bus_speed = pdata->bus_speed;
654 671
655 priv->devtype = platform_get_device_id(pdev)->driver_data; 672 if (pdev->dev.of_node)
673 priv->devtype = (long)of_match_device(rcar_i2c_dt_ids,
674 dev)->data;
675 else
676 priv->devtype = platform_get_device_id(pdev)->driver_data;
656 677
657 ret = rcar_i2c_clock_calculate(priv, bus_speed, dev); 678 ret = rcar_i2c_clock_calculate(priv, bus_speed, dev);
658 if (ret < 0) 679 if (ret < 0)
@@ -673,6 +694,7 @@ static int rcar_i2c_probe(struct platform_device *pdev)
673 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 694 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
674 adap->retries = 3; 695 adap->retries = 3;
675 adap->dev.parent = dev; 696 adap->dev.parent = dev;
697 adap->dev.of_node = dev->of_node;
676 i2c_set_adapdata(adap, priv); 698 i2c_set_adapdata(adap, priv);
677 strlcpy(adap->name, pdev->name, sizeof(adap->name)); 699 strlcpy(adap->name, pdev->name, sizeof(adap->name));
678 700
@@ -709,9 +731,9 @@ static int rcar_i2c_remove(struct platform_device *pdev)
709} 731}
710 732
711static struct platform_device_id rcar_i2c_id_table[] = { 733static struct platform_device_id rcar_i2c_id_table[] = {
712 { "i2c-rcar", I2C_RCAR_H1 }, 734 { "i2c-rcar", I2C_RCAR_GEN1 },
713 { "i2c-rcar_h1", I2C_RCAR_H1 }, 735 { "i2c-rcar_gen1", I2C_RCAR_GEN1 },
714 { "i2c-rcar_h2", I2C_RCAR_H2 }, 736 { "i2c-rcar_gen2", I2C_RCAR_GEN2 },
715 {}, 737 {},
716}; 738};
717MODULE_DEVICE_TABLE(platform, rcar_i2c_id_table); 739MODULE_DEVICE_TABLE(platform, rcar_i2c_id_table);
@@ -720,6 +742,7 @@ static struct platform_driver rcar_i2c_driver = {
720 .driver = { 742 .driver = {
721 .name = "i2c-rcar", 743 .name = "i2c-rcar",
722 .owner = THIS_MODULE, 744 .owner = THIS_MODULE,
745 .of_match_table = rcar_i2c_dt_ids,
723 }, 746 },
724 .probe = rcar_i2c_probe, 747 .probe = rcar_i2c_probe,
725 .remove = rcar_i2c_remove, 748 .remove = rcar_i2c_remove,
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 3747b9bf67d6..bf8fb94ebc5d 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -36,6 +36,7 @@
36#include <linux/cpufreq.h> 36#include <linux/cpufreq.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/io.h> 38#include <linux/io.h>
39#include <linux/of.h>
39#include <linux/of_gpio.h> 40#include <linux/of_gpio.h>
40#include <linux/pinctrl/consumer.h> 41#include <linux/pinctrl/consumer.h>
41 42
diff --git a/drivers/i2c/busses/i2c-scmi.c b/drivers/i2c/busses/i2c-scmi.c
index c447e8d40b78..599235514138 100644
--- a/drivers/i2c/busses/i2c-scmi.c
+++ b/drivers/i2c/busses/i2c-scmi.c
@@ -223,7 +223,7 @@ acpi_smbus_cmi_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
223 goto out; 223 goto out;
224 224
225 obj = pkg->package.elements + 1; 225 obj = pkg->package.elements + 1;
226 if (obj == NULL || obj->type != ACPI_TYPE_INTEGER) { 226 if (obj->type != ACPI_TYPE_INTEGER) {
227 ACPI_ERROR((AE_INFO, "Invalid argument type")); 227 ACPI_ERROR((AE_INFO, "Invalid argument type"));
228 result = -EIO; 228 result = -EIO;
229 goto out; 229 goto out;
@@ -235,7 +235,7 @@ acpi_smbus_cmi_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
235 case I2C_SMBUS_BYTE: 235 case I2C_SMBUS_BYTE:
236 case I2C_SMBUS_BYTE_DATA: 236 case I2C_SMBUS_BYTE_DATA:
237 case I2C_SMBUS_WORD_DATA: 237 case I2C_SMBUS_WORD_DATA:
238 if (obj == NULL || obj->type != ACPI_TYPE_INTEGER) { 238 if (obj->type != ACPI_TYPE_INTEGER) {
239 ACPI_ERROR((AE_INFO, "Invalid argument type")); 239 ACPI_ERROR((AE_INFO, "Invalid argument type"));
240 result = -EIO; 240 result = -EIO;
241 goto out; 241 goto out;
@@ -246,7 +246,7 @@ acpi_smbus_cmi_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
246 data->byte = obj->integer.value; 246 data->byte = obj->integer.value;
247 break; 247 break;
248 case I2C_SMBUS_BLOCK_DATA: 248 case I2C_SMBUS_BLOCK_DATA:
249 if (obj == NULL || obj->type != ACPI_TYPE_BUFFER) { 249 if (obj->type != ACPI_TYPE_BUFFER) {
250 ACPI_ERROR((AE_INFO, "Invalid argument type")); 250 ACPI_ERROR((AE_INFO, "Invalid argument type"));
251 result = -EIO; 251 result = -EIO;
252 goto out; 252 goto out;
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index 55110ddbed1f..1d79585ba4b3 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -235,7 +235,7 @@ static void sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd)
235 int offset; 235 int offset;
236 236
237 /* Get clock rate after clock is enabled */ 237 /* Get clock rate after clock is enabled */
238 clk_enable(pd->clk); 238 clk_prepare_enable(pd->clk);
239 i2c_clk_khz = clk_get_rate(pd->clk) / 1000; 239 i2c_clk_khz = clk_get_rate(pd->clk) / 1000;
240 i2c_clk_khz /= pd->clks_per_count; 240 i2c_clk_khz /= pd->clks_per_count;
241 241
@@ -270,14 +270,14 @@ static void sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd)
270 pd->icic &= ~ICIC_ICCHB8; 270 pd->icic &= ~ICIC_ICCHB8;
271 271
272out: 272out:
273 clk_disable(pd->clk); 273 clk_disable_unprepare(pd->clk);
274} 274}
275 275
276static void activate_ch(struct sh_mobile_i2c_data *pd) 276static void activate_ch(struct sh_mobile_i2c_data *pd)
277{ 277{
278 /* Wake up device and enable clock */ 278 /* Wake up device and enable clock */
279 pm_runtime_get_sync(pd->dev); 279 pm_runtime_get_sync(pd->dev);
280 clk_enable(pd->clk); 280 clk_prepare_enable(pd->clk);
281 281
282 /* Enable channel and configure rx ack */ 282 /* Enable channel and configure rx ack */
283 iic_set_clr(pd, ICCR, ICCR_ICE, 0); 283 iic_set_clr(pd, ICCR, ICCR_ICE, 0);
@@ -300,7 +300,7 @@ static void deactivate_ch(struct sh_mobile_i2c_data *pd)
300 iic_set_clr(pd, ICCR, 0, ICCR_ICE); 300 iic_set_clr(pd, ICCR, 0, ICCR_ICE);
301 301
302 /* Disable clock and mark device as idle */ 302 /* Disable clock and mark device as idle */
303 clk_disable(pd->clk); 303 clk_disable_unprepare(pd->clk);
304 pm_runtime_put_sync(pd->dev); 304 pm_runtime_put_sync(pd->dev);
305} 305}
306 306
diff --git a/drivers/i2c/busses/i2c-st.c b/drivers/i2c/busses/i2c-st.c
new file mode 100644
index 000000000000..9cf715d69551
--- /dev/null
+++ b/drivers/i2c/busses/i2c-st.c
@@ -0,0 +1,872 @@
1/*
2 * Copyright (C) 2013 STMicroelectronics
3 *
4 * I2C master mode controller driver, used in STMicroelectronics devices.
5 *
6 * Author: Maxime Coquelin <maxime.coquelin@st.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/module.h>
14#include <linux/platform_device.h>
15#include <linux/i2c.h>
16#include <linux/clk.h>
17#include <linux/io.h>
18#include <linux/delay.h>
19#include <linux/interrupt.h>
20#include <linux/err.h>
21#include <linux/of.h>
22#include <linux/of_address.h>
23#include <linux/of_irq.h>
24
25/* SSC registers */
26#define SSC_BRG 0x000
27#define SSC_TBUF 0x004
28#define SSC_RBUF 0x008
29#define SSC_CTL 0x00C
30#define SSC_IEN 0x010
31#define SSC_STA 0x014
32#define SSC_I2C 0x018
33#define SSC_SLAD 0x01C
34#define SSC_REP_START_HOLD 0x020
35#define SSC_START_HOLD 0x024
36#define SSC_REP_START_SETUP 0x028
37#define SSC_DATA_SETUP 0x02C
38#define SSC_STOP_SETUP 0x030
39#define SSC_BUS_FREE 0x034
40#define SSC_TX_FSTAT 0x038
41#define SSC_RX_FSTAT 0x03C
42#define SSC_PRE_SCALER_BRG 0x040
43#define SSC_CLR 0x080
44#define SSC_NOISE_SUPP_WIDTH 0x100
45#define SSC_PRSCALER 0x104
46#define SSC_NOISE_SUPP_WIDTH_DATAOUT 0x108
47#define SSC_PRSCALER_DATAOUT 0x10c
48
49/* SSC Control */
50#define SSC_CTL_DATA_WIDTH_9 0x8
51#define SSC_CTL_DATA_WIDTH_MSK 0xf
52#define SSC_CTL_BM 0xf
53#define SSC_CTL_HB BIT(4)
54#define SSC_CTL_PH BIT(5)
55#define SSC_CTL_PO BIT(6)
56#define SSC_CTL_SR BIT(7)
57#define SSC_CTL_MS BIT(8)
58#define SSC_CTL_EN BIT(9)
59#define SSC_CTL_LPB BIT(10)
60#define SSC_CTL_EN_TX_FIFO BIT(11)
61#define SSC_CTL_EN_RX_FIFO BIT(12)
62#define SSC_CTL_EN_CLST_RX BIT(13)
63
64/* SSC Interrupt Enable */
65#define SSC_IEN_RIEN BIT(0)
66#define SSC_IEN_TIEN BIT(1)
67#define SSC_IEN_TEEN BIT(2)
68#define SSC_IEN_REEN BIT(3)
69#define SSC_IEN_PEEN BIT(4)
70#define SSC_IEN_AASEN BIT(6)
71#define SSC_IEN_STOPEN BIT(7)
72#define SSC_IEN_ARBLEN BIT(8)
73#define SSC_IEN_NACKEN BIT(10)
74#define SSC_IEN_REPSTRTEN BIT(11)
75#define SSC_IEN_TX_FIFO_HALF BIT(12)
76#define SSC_IEN_RX_FIFO_HALF_FULL BIT(14)
77
78/* SSC Status */
79#define SSC_STA_RIR BIT(0)
80#define SSC_STA_TIR BIT(1)
81#define SSC_STA_TE BIT(2)
82#define SSC_STA_RE BIT(3)
83#define SSC_STA_PE BIT(4)
84#define SSC_STA_CLST BIT(5)
85#define SSC_STA_AAS BIT(6)
86#define SSC_STA_STOP BIT(7)
87#define SSC_STA_ARBL BIT(8)
88#define SSC_STA_BUSY BIT(9)
89#define SSC_STA_NACK BIT(10)
90#define SSC_STA_REPSTRT BIT(11)
91#define SSC_STA_TX_FIFO_HALF BIT(12)
92#define SSC_STA_TX_FIFO_FULL BIT(13)
93#define SSC_STA_RX_FIFO_HALF BIT(14)
94
95/* SSC I2C Control */
96#define SSC_I2C_I2CM BIT(0)
97#define SSC_I2C_STRTG BIT(1)
98#define SSC_I2C_STOPG BIT(2)
99#define SSC_I2C_ACKG BIT(3)
100#define SSC_I2C_AD10 BIT(4)
101#define SSC_I2C_TXENB BIT(5)
102#define SSC_I2C_REPSTRTG BIT(11)
103#define SSC_I2C_SLAVE_DISABLE BIT(12)
104
105/* SSC Tx FIFO Status */
106#define SSC_TX_FSTAT_STATUS 0x07
107
108/* SSC Rx FIFO Status */
109#define SSC_RX_FSTAT_STATUS 0x07
110
111/* SSC Clear bit operation */
112#define SSC_CLR_SSCAAS BIT(6)
113#define SSC_CLR_SSCSTOP BIT(7)
114#define SSC_CLR_SSCARBL BIT(8)
115#define SSC_CLR_NACK BIT(10)
116#define SSC_CLR_REPSTRT BIT(11)
117
118/* SSC Clock Prescaler */
119#define SSC_PRSC_VALUE 0x0f
120
121
122#define SSC_TXFIFO_SIZE 0x8
123#define SSC_RXFIFO_SIZE 0x8
124
125enum st_i2c_mode {
126 I2C_MODE_STANDARD,
127 I2C_MODE_FAST,
128 I2C_MODE_END,
129};
130
131/**
132 * struct st_i2c_timings - per-Mode tuning parameters
133 * @rate: I2C bus rate
134 * @rep_start_hold: I2C repeated start hold time requirement
135 * @rep_start_setup: I2C repeated start set up time requirement
136 * @start_hold: I2C start hold time requirement
137 * @data_setup_time: I2C data set up time requirement
138 * @stop_setup_time: I2C stop set up time requirement
139 * @bus_free_time: I2C bus free time requirement
140 * @sda_pulse_min_limit: I2C SDA pulse mini width limit
141 */
142struct st_i2c_timings {
143 u32 rate;
144 u32 rep_start_hold;
145 u32 rep_start_setup;
146 u32 start_hold;
147 u32 data_setup_time;
148 u32 stop_setup_time;
149 u32 bus_free_time;
150 u32 sda_pulse_min_limit;
151};
152
153/**
154 * struct st_i2c_client - client specific data
155 * @addr: 8-bit slave addr, including r/w bit
156 * @count: number of bytes to be transfered
157 * @xfered: number of bytes already transferred
158 * @buf: data buffer
159 * @result: result of the transfer
160 * @stop: last I2C msg to be sent, i.e. STOP to be generated
161 */
162struct st_i2c_client {
163 u8 addr;
164 u32 count;
165 u32 xfered;
166 u8 *buf;
167 int result;
168 bool stop;
169};
170
171/**
172 * struct st_i2c_dev - private data of the controller
173 * @adap: I2C adapter for this controller
174 * @dev: device for this controller
175 * @base: virtual memory area
176 * @complete: completion of I2C message
177 * @irq: interrupt line for th controller
178 * @clk: hw ssc block clock
179 * @mode: I2C mode of the controller. Standard or Fast only supported
180 * @scl_min_width_us: SCL line minimum pulse width in us
181 * @sda_min_width_us: SDA line minimum pulse width in us
182 * @client: I2C transfert information
183 * @busy: I2C transfer on-going
184 */
185struct st_i2c_dev {
186 struct i2c_adapter adap;
187 struct device *dev;
188 void __iomem *base;
189 struct completion complete;
190 int irq;
191 struct clk *clk;
192 int mode;
193 u32 scl_min_width_us;
194 u32 sda_min_width_us;
195 struct st_i2c_client client;
196 bool busy;
197};
198
199static inline void st_i2c_set_bits(void __iomem *reg, u32 mask)
200{
201 writel_relaxed(readl_relaxed(reg) | mask, reg);
202}
203
204static inline void st_i2c_clr_bits(void __iomem *reg, u32 mask)
205{
206 writel_relaxed(readl_relaxed(reg) & ~mask, reg);
207}
208
209/* From I2C Specifications v0.5 */
210static struct st_i2c_timings i2c_timings[] = {
211 [I2C_MODE_STANDARD] = {
212 .rate = 100000,
213 .rep_start_hold = 4000,
214 .rep_start_setup = 4700,
215 .start_hold = 4000,
216 .data_setup_time = 250,
217 .stop_setup_time = 4000,
218 .bus_free_time = 4700,
219 },
220 [I2C_MODE_FAST] = {
221 .rate = 400000,
222 .rep_start_hold = 600,
223 .rep_start_setup = 600,
224 .start_hold = 600,
225 .data_setup_time = 100,
226 .stop_setup_time = 600,
227 .bus_free_time = 1300,
228 },
229};
230
231static void st_i2c_flush_rx_fifo(struct st_i2c_dev *i2c_dev)
232{
233 int count, i;
234
235 /*
236 * Counter only counts up to 7 but fifo size is 8...
237 * When fifo is full, counter is 0 and RIR bit of status register is
238 * set
239 */
240 if (readl_relaxed(i2c_dev->base + SSC_STA) & SSC_STA_RIR)
241 count = SSC_RXFIFO_SIZE;
242 else
243 count = readl_relaxed(i2c_dev->base + SSC_RX_FSTAT) &
244 SSC_RX_FSTAT_STATUS;
245
246 for (i = 0; i < count; i++)
247 readl_relaxed(i2c_dev->base + SSC_RBUF);
248}
249
250static void st_i2c_soft_reset(struct st_i2c_dev *i2c_dev)
251{
252 /*
253 * FIFO needs to be emptied before reseting the IP,
254 * else the controller raises a BUSY error.
255 */
256 st_i2c_flush_rx_fifo(i2c_dev);
257
258 st_i2c_set_bits(i2c_dev->base + SSC_CTL, SSC_CTL_SR);
259 st_i2c_clr_bits(i2c_dev->base + SSC_CTL, SSC_CTL_SR);
260}
261
262/**
263 * st_i2c_hw_config() - Prepare SSC block, calculate and apply tuning timings
264 * @i2c_dev: Controller's private data
265 */
266static void st_i2c_hw_config(struct st_i2c_dev *i2c_dev)
267{
268 unsigned long rate;
269 u32 val, ns_per_clk;
270 struct st_i2c_timings *t = &i2c_timings[i2c_dev->mode];
271
272 st_i2c_soft_reset(i2c_dev);
273
274 val = SSC_CLR_REPSTRT | SSC_CLR_NACK | SSC_CLR_SSCARBL |
275 SSC_CLR_SSCAAS | SSC_CLR_SSCSTOP;
276 writel_relaxed(val, i2c_dev->base + SSC_CLR);
277
278 /* SSC Control register setup */
279 val = SSC_CTL_PO | SSC_CTL_PH | SSC_CTL_HB | SSC_CTL_DATA_WIDTH_9;
280 writel_relaxed(val, i2c_dev->base + SSC_CTL);
281
282 rate = clk_get_rate(i2c_dev->clk);
283 ns_per_clk = 1000000000 / rate;
284
285 /* Baudrate */
286 val = rate / (2 * t->rate);
287 writel_relaxed(val, i2c_dev->base + SSC_BRG);
288
289 /* Pre-scaler baudrate */
290 writel_relaxed(1, i2c_dev->base + SSC_PRE_SCALER_BRG);
291
292 /* Enable I2C mode */
293 writel_relaxed(SSC_I2C_I2CM, i2c_dev->base + SSC_I2C);
294
295 /* Repeated start hold time */
296 val = t->rep_start_hold / ns_per_clk;
297 writel_relaxed(val, i2c_dev->base + SSC_REP_START_HOLD);
298
299 /* Repeated start set up time */
300 val = t->rep_start_setup / ns_per_clk;
301 writel_relaxed(val, i2c_dev->base + SSC_REP_START_SETUP);
302
303 /* Start hold time */
304 val = t->start_hold / ns_per_clk;
305 writel_relaxed(val, i2c_dev->base + SSC_START_HOLD);
306
307 /* Data set up time */
308 val = t->data_setup_time / ns_per_clk;
309 writel_relaxed(val, i2c_dev->base + SSC_DATA_SETUP);
310
311 /* Stop set up time */
312 val = t->stop_setup_time / ns_per_clk;
313 writel_relaxed(val, i2c_dev->base + SSC_STOP_SETUP);
314
315 /* Bus free time */
316 val = t->bus_free_time / ns_per_clk;
317 writel_relaxed(val, i2c_dev->base + SSC_BUS_FREE);
318
319 /* Prescalers set up */
320 val = rate / 10000000;
321 writel_relaxed(val, i2c_dev->base + SSC_PRSCALER);
322 writel_relaxed(val, i2c_dev->base + SSC_PRSCALER_DATAOUT);
323
324 /* Noise suppression witdh */
325 val = i2c_dev->scl_min_width_us * rate / 100000000;
326 writel_relaxed(val, i2c_dev->base + SSC_NOISE_SUPP_WIDTH);
327
328 /* Noise suppression max output data delay width */
329 val = i2c_dev->sda_min_width_us * rate / 100000000;
330 writel_relaxed(val, i2c_dev->base + SSC_NOISE_SUPP_WIDTH_DATAOUT);
331}
332
333static int st_i2c_wait_free_bus(struct st_i2c_dev *i2c_dev)
334{
335 u32 sta;
336 int i;
337
338 for (i = 0; i < 10; i++) {
339 sta = readl_relaxed(i2c_dev->base + SSC_STA);
340 if (!(sta & SSC_STA_BUSY))
341 return 0;
342
343 usleep_range(2000, 4000);
344 }
345
346 dev_err(i2c_dev->dev, "bus not free (status = 0x%08x)\n", sta);
347
348 return -EBUSY;
349}
350
351/**
352 * st_i2c_write_tx_fifo() - Write a byte in the Tx FIFO
353 * @i2c_dev: Controller's private data
354 * @byte: Data to write in the Tx FIFO
355 */
356static inline void st_i2c_write_tx_fifo(struct st_i2c_dev *i2c_dev, u8 byte)
357{
358 u16 tbuf = byte << 1;
359
360 writel_relaxed(tbuf | 1, i2c_dev->base + SSC_TBUF);
361}
362
363/**
364 * st_i2c_wr_fill_tx_fifo() - Fill the Tx FIFO in write mode
365 * @i2c_dev: Controller's private data
366 *
367 * This functions fills the Tx FIFO with I2C transfert buffer when
368 * in write mode.
369 */
370static void st_i2c_wr_fill_tx_fifo(struct st_i2c_dev *i2c_dev)
371{
372 struct st_i2c_client *c = &i2c_dev->client;
373 u32 tx_fstat, sta;
374 int i;
375
376 sta = readl_relaxed(i2c_dev->base + SSC_STA);
377 if (sta & SSC_STA_TX_FIFO_FULL)
378 return;
379
380 tx_fstat = readl_relaxed(i2c_dev->base + SSC_TX_FSTAT);
381 tx_fstat &= SSC_TX_FSTAT_STATUS;
382
383 if (c->count < (SSC_TXFIFO_SIZE - tx_fstat))
384 i = c->count;
385 else
386 i = SSC_TXFIFO_SIZE - tx_fstat;
387
388 for (; i > 0; i--, c->count--, c->buf++)
389 st_i2c_write_tx_fifo(i2c_dev, *c->buf);
390}
391
392/**
393 * st_i2c_rd_fill_tx_fifo() - Fill the Tx FIFO in read mode
394 * @i2c_dev: Controller's private data
395 *
396 * This functions fills the Tx FIFO with fixed pattern when
397 * in read mode to trigger clock.
398 */
399static void st_i2c_rd_fill_tx_fifo(struct st_i2c_dev *i2c_dev, int max)
400{
401 struct st_i2c_client *c = &i2c_dev->client;
402 u32 tx_fstat, sta;
403 int i;
404
405 sta = readl_relaxed(i2c_dev->base + SSC_STA);
406 if (sta & SSC_STA_TX_FIFO_FULL)
407 return;
408
409 tx_fstat = readl_relaxed(i2c_dev->base + SSC_TX_FSTAT);
410 tx_fstat &= SSC_TX_FSTAT_STATUS;
411
412 if (max < (SSC_TXFIFO_SIZE - tx_fstat))
413 i = max;
414 else
415 i = SSC_TXFIFO_SIZE - tx_fstat;
416
417 for (; i > 0; i--, c->xfered++)
418 st_i2c_write_tx_fifo(i2c_dev, 0xff);
419}
420
421static void st_i2c_read_rx_fifo(struct st_i2c_dev *i2c_dev)
422{
423 struct st_i2c_client *c = &i2c_dev->client;
424 u32 i, sta;
425 u16 rbuf;
426
427 sta = readl_relaxed(i2c_dev->base + SSC_STA);
428 if (sta & SSC_STA_RIR) {
429 i = SSC_RXFIFO_SIZE;
430 } else {
431 i = readl_relaxed(i2c_dev->base + SSC_RX_FSTAT);
432 i &= SSC_RX_FSTAT_STATUS;
433 }
434
435 for (; (i > 0) && (c->count > 0); i--, c->count--) {
436 rbuf = readl_relaxed(i2c_dev->base + SSC_RBUF) >> 1;
437 *c->buf++ = (u8)rbuf & 0xff;
438 }
439
440 if (i) {
441 dev_err(i2c_dev->dev, "Unexpected %d bytes in rx fifo\n", i);
442 st_i2c_flush_rx_fifo(i2c_dev);
443 }
444}
445
446/**
447 * st_i2c_terminate_xfer() - Send either STOP or REPSTART condition
448 * @i2c_dev: Controller's private data
449 */
450static void st_i2c_terminate_xfer(struct st_i2c_dev *i2c_dev)
451{
452 struct st_i2c_client *c = &i2c_dev->client;
453
454 st_i2c_clr_bits(i2c_dev->base + SSC_IEN, SSC_IEN_TEEN);
455 st_i2c_clr_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STRTG);
456
457 if (c->stop) {
458 st_i2c_set_bits(i2c_dev->base + SSC_IEN, SSC_IEN_STOPEN);
459 st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STOPG);
460 } else {
461 st_i2c_set_bits(i2c_dev->base + SSC_IEN, SSC_IEN_REPSTRTEN);
462 st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_REPSTRTG);
463 }
464}
465
466/**
467 * st_i2c_handle_write() - Handle FIFO empty interrupt in case of write
468 * @i2c_dev: Controller's private data
469 */
470static void st_i2c_handle_write(struct st_i2c_dev *i2c_dev)
471{
472 struct st_i2c_client *c = &i2c_dev->client;
473
474 st_i2c_flush_rx_fifo(i2c_dev);
475
476 if (!c->count)
477 /* End of xfer, send stop or repstart */
478 st_i2c_terminate_xfer(i2c_dev);
479 else
480 st_i2c_wr_fill_tx_fifo(i2c_dev);
481}
482
483/**
484 * st_i2c_handle_write() - Handle FIFO enmpty interrupt in case of read
485 * @i2c_dev: Controller's private data
486 */
487static void st_i2c_handle_read(struct st_i2c_dev *i2c_dev)
488{
489 struct st_i2c_client *c = &i2c_dev->client;
490 u32 ien;
491
492 /* Trash the address read back */
493 if (!c->xfered) {
494 readl_relaxed(i2c_dev->base + SSC_RBUF);
495 st_i2c_clr_bits(i2c_dev->base + SSC_I2C, SSC_I2C_TXENB);
496 } else {
497 st_i2c_read_rx_fifo(i2c_dev);
498 }
499
500 if (!c->count) {
501 /* End of xfer, send stop or repstart */
502 st_i2c_terminate_xfer(i2c_dev);
503 } else if (c->count == 1) {
504 /* Penultimate byte to xfer, disable ACK gen. */
505 st_i2c_clr_bits(i2c_dev->base + SSC_I2C, SSC_I2C_ACKG);
506
507 /* Last received byte is to be handled by NACK interrupt */
508 ien = SSC_IEN_NACKEN | SSC_IEN_ARBLEN;
509 writel_relaxed(ien, i2c_dev->base + SSC_IEN);
510
511 st_i2c_rd_fill_tx_fifo(i2c_dev, c->count);
512 } else {
513 st_i2c_rd_fill_tx_fifo(i2c_dev, c->count - 1);
514 }
515}
516
517/**
518 * st_i2c_isr() - Interrupt routine
519 * @irq: interrupt number
520 * @data: Controller's private data
521 */
522static irqreturn_t st_i2c_isr_thread(int irq, void *data)
523{
524 struct st_i2c_dev *i2c_dev = data;
525 struct st_i2c_client *c = &i2c_dev->client;
526 u32 sta, ien;
527 int it;
528
529 ien = readl_relaxed(i2c_dev->base + SSC_IEN);
530 sta = readl_relaxed(i2c_dev->base + SSC_STA);
531
532 /* Use __fls() to check error bits first */
533 it = __fls(sta & ien);
534 if (it < 0) {
535 dev_dbg(i2c_dev->dev, "spurious it (sta=0x%04x, ien=0x%04x)\n",
536 sta, ien);
537 return IRQ_NONE;
538 }
539
540 switch (1 << it) {
541 case SSC_STA_TE:
542 if (c->addr & I2C_M_RD)
543 st_i2c_handle_read(i2c_dev);
544 else
545 st_i2c_handle_write(i2c_dev);
546 break;
547
548 case SSC_STA_STOP:
549 case SSC_STA_REPSTRT:
550 writel_relaxed(0, i2c_dev->base + SSC_IEN);
551 complete(&i2c_dev->complete);
552 break;
553
554 case SSC_STA_NACK:
555 writel_relaxed(SSC_CLR_NACK, i2c_dev->base + SSC_CLR);
556
557 /* Last received byte handled by NACK interrupt */
558 if ((c->addr & I2C_M_RD) && (c->count == 1) && (c->xfered)) {
559 st_i2c_handle_read(i2c_dev);
560 break;
561 }
562
563 it = SSC_IEN_STOPEN | SSC_IEN_ARBLEN;
564 writel_relaxed(it, i2c_dev->base + SSC_IEN);
565
566 st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STOPG);
567 c->result = -EIO;
568 break;
569
570 case SSC_STA_ARBL:
571 writel_relaxed(SSC_CLR_SSCARBL, i2c_dev->base + SSC_CLR);
572
573 it = SSC_IEN_STOPEN | SSC_IEN_ARBLEN;
574 writel_relaxed(it, i2c_dev->base + SSC_IEN);
575
576 st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STOPG);
577 c->result = -EIO;
578 break;
579
580 default:
581 dev_err(i2c_dev->dev,
582 "it %d unhandled (sta=0x%04x)\n", it, sta);
583 }
584
585 /*
586 * Read IEN register to ensure interrupt mask write is effective
587 * before re-enabling interrupt at GIC level, and thus avoid spurious
588 * interrupts.
589 */
590 readl(i2c_dev->base + SSC_IEN);
591
592 return IRQ_HANDLED;
593}
594
595/**
596 * st_i2c_xfer_msg() - Transfer a single I2C message
597 * @i2c_dev: Controller's private data
598 * @msg: I2C message to transfer
599 * @is_first: first message of the sequence
600 * @is_last: last message of the sequence
601 */
602static int st_i2c_xfer_msg(struct st_i2c_dev *i2c_dev, struct i2c_msg *msg,
603 bool is_first, bool is_last)
604{
605 struct st_i2c_client *c = &i2c_dev->client;
606 u32 ctl, i2c, it;
607 unsigned long timeout;
608 int ret;
609
610 c->addr = (u8)(msg->addr << 1);
611 c->addr |= (msg->flags & I2C_M_RD);
612 c->buf = msg->buf;
613 c->count = msg->len;
614 c->xfered = 0;
615 c->result = 0;
616 c->stop = is_last;
617
618 reinit_completion(&i2c_dev->complete);
619
620 ctl = SSC_CTL_EN | SSC_CTL_MS | SSC_CTL_EN_RX_FIFO | SSC_CTL_EN_TX_FIFO;
621 st_i2c_set_bits(i2c_dev->base + SSC_CTL, ctl);
622
623 i2c = SSC_I2C_TXENB;
624 if (c->addr & I2C_M_RD)
625 i2c |= SSC_I2C_ACKG;
626 st_i2c_set_bits(i2c_dev->base + SSC_I2C, i2c);
627
628 /* Write slave address */
629 st_i2c_write_tx_fifo(i2c_dev, c->addr);
630
631 /* Pre-fill Tx fifo with data in case of write */
632 if (!(c->addr & I2C_M_RD))
633 st_i2c_wr_fill_tx_fifo(i2c_dev);
634
635 it = SSC_IEN_NACKEN | SSC_IEN_TEEN | SSC_IEN_ARBLEN;
636 writel_relaxed(it, i2c_dev->base + SSC_IEN);
637
638 if (is_first) {
639 ret = st_i2c_wait_free_bus(i2c_dev);
640 if (ret)
641 return ret;
642
643 st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STRTG);
644 }
645
646 timeout = wait_for_completion_timeout(&i2c_dev->complete,
647 i2c_dev->adap.timeout);
648 ret = c->result;
649
650 if (!timeout) {
651 dev_err(i2c_dev->dev, "Write to slave 0x%x timed out\n",
652 c->addr);
653 ret = -ETIMEDOUT;
654 }
655
656 i2c = SSC_I2C_STOPG | SSC_I2C_REPSTRTG;
657 st_i2c_clr_bits(i2c_dev->base + SSC_I2C, i2c);
658
659 writel_relaxed(SSC_CLR_SSCSTOP | SSC_CLR_REPSTRT,
660 i2c_dev->base + SSC_CLR);
661
662 return ret;
663}
664
665/**
666 * st_i2c_xfer() - Transfer a single I2C message
667 * @i2c_adap: Adapter pointer to the controller
668 * @msgs: Pointer to data to be written.
669 * @num: Number of messages to be executed
670 */
671static int st_i2c_xfer(struct i2c_adapter *i2c_adap,
672 struct i2c_msg msgs[], int num)
673{
674 struct st_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap);
675 int ret, i;
676
677 i2c_dev->busy = true;
678
679 ret = clk_prepare_enable(i2c_dev->clk);
680 if (ret) {
681 dev_err(i2c_dev->dev, "Failed to prepare_enable clock\n");
682 return ret;
683 }
684
685 pinctrl_pm_select_default_state(i2c_dev->dev);
686
687 st_i2c_hw_config(i2c_dev);
688
689 for (i = 0; (i < num) && !ret; i++)
690 ret = st_i2c_xfer_msg(i2c_dev, &msgs[i], i == 0, i == num - 1);
691
692 pinctrl_pm_select_idle_state(i2c_dev->dev);
693
694 clk_disable_unprepare(i2c_dev->clk);
695
696 i2c_dev->busy = false;
697
698 return (ret < 0) ? ret : i;
699}
700
701#ifdef CONFIG_PM_SLEEP
702static int st_i2c_suspend(struct device *dev)
703{
704 struct platform_device *pdev =
705 container_of(dev, struct platform_device, dev);
706 struct st_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
707
708 if (i2c_dev->busy)
709 return -EBUSY;
710
711 pinctrl_pm_select_sleep_state(dev);
712
713 return 0;
714}
715
716static int st_i2c_resume(struct device *dev)
717{
718 pinctrl_pm_select_default_state(dev);
719 /* Go in idle state if available */
720 pinctrl_pm_select_idle_state(dev);
721
722 return 0;
723}
724
725static SIMPLE_DEV_PM_OPS(st_i2c_pm, st_i2c_suspend, st_i2c_resume);
726#define ST_I2C_PM (&st_i2c_pm)
727#else
728#define ST_I2C_PM NULL
729#endif
730
731static u32 st_i2c_func(struct i2c_adapter *adap)
732{
733 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
734}
735
736static struct i2c_algorithm st_i2c_algo = {
737 .master_xfer = st_i2c_xfer,
738 .functionality = st_i2c_func,
739};
740
741static int st_i2c_of_get_deglitch(struct device_node *np,
742 struct st_i2c_dev *i2c_dev)
743{
744 int ret;
745
746 ret = of_property_read_u32(np, "st,i2c-min-scl-pulse-width-us",
747 &i2c_dev->scl_min_width_us);
748 if ((ret == -ENODATA) || (ret == -EOVERFLOW)) {
749 dev_err(i2c_dev->dev, "st,i2c-min-scl-pulse-width-us invalid\n");
750 return ret;
751 }
752
753 ret = of_property_read_u32(np, "st,i2c-min-sda-pulse-width-us",
754 &i2c_dev->sda_min_width_us);
755 if ((ret == -ENODATA) || (ret == -EOVERFLOW)) {
756 dev_err(i2c_dev->dev, "st,i2c-min-sda-pulse-width-us invalid\n");
757 return ret;
758 }
759
760 return 0;
761}
762
763static int st_i2c_probe(struct platform_device *pdev)
764{
765 struct device_node *np = pdev->dev.of_node;
766 struct st_i2c_dev *i2c_dev;
767 struct resource *res;
768 u32 clk_rate;
769 struct i2c_adapter *adap;
770 int ret;
771
772 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
773 if (!i2c_dev)
774 return -ENOMEM;
775
776 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
777 i2c_dev->base = devm_ioremap_resource(&pdev->dev, res);
778 if (IS_ERR(i2c_dev->base))
779 return PTR_ERR(i2c_dev->base);
780
781 i2c_dev->irq = irq_of_parse_and_map(np, 0);
782 if (!i2c_dev->irq) {
783 dev_err(&pdev->dev, "IRQ missing or invalid\n");
784 return -EINVAL;
785 }
786
787 i2c_dev->clk = of_clk_get_by_name(np, "ssc");
788 if (IS_ERR(i2c_dev->clk)) {
789 dev_err(&pdev->dev, "Unable to request clock\n");
790 return PTR_ERR(i2c_dev->clk);
791 }
792
793 i2c_dev->mode = I2C_MODE_STANDARD;
794 ret = of_property_read_u32(np, "clock-frequency", &clk_rate);
795 if ((!ret) && (clk_rate == 400000))
796 i2c_dev->mode = I2C_MODE_FAST;
797
798 i2c_dev->dev = &pdev->dev;
799
800 ret = devm_request_threaded_irq(&pdev->dev, i2c_dev->irq,
801 NULL, st_i2c_isr_thread,
802 IRQF_ONESHOT, pdev->name, i2c_dev);
803 if (ret) {
804 dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq);
805 return ret;
806 }
807
808 pinctrl_pm_select_default_state(i2c_dev->dev);
809 /* In case idle state available, select it */
810 pinctrl_pm_select_idle_state(i2c_dev->dev);
811
812 ret = st_i2c_of_get_deglitch(np, i2c_dev);
813 if (ret)
814 return ret;
815
816 adap = &i2c_dev->adap;
817 i2c_set_adapdata(adap, i2c_dev);
818 snprintf(adap->name, sizeof(adap->name), "ST I2C(0x%x)", res->start);
819 adap->owner = THIS_MODULE;
820 adap->timeout = 2 * HZ;
821 adap->retries = 0;
822 adap->algo = &st_i2c_algo;
823 adap->dev.parent = &pdev->dev;
824 adap->dev.of_node = pdev->dev.of_node;
825
826 init_completion(&i2c_dev->complete);
827
828 ret = i2c_add_adapter(adap);
829 if (ret) {
830 dev_err(&pdev->dev, "Failed to add adapter\n");
831 return ret;
832 }
833
834 platform_set_drvdata(pdev, i2c_dev);
835
836 dev_info(i2c_dev->dev, "%s initialized\n", adap->name);
837
838 return 0;
839}
840
841static int st_i2c_remove(struct platform_device *pdev)
842{
843 struct st_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
844
845 i2c_del_adapter(&i2c_dev->adap);
846
847 return 0;
848}
849
850static struct of_device_id st_i2c_match[] = {
851 { .compatible = "st,comms-ssc-i2c", },
852 { .compatible = "st,comms-ssc4-i2c", },
853 {},
854};
855MODULE_DEVICE_TABLE(of, st_i2c_match);
856
857static struct platform_driver st_i2c_driver = {
858 .driver = {
859 .name = "st-i2c",
860 .owner = THIS_MODULE,
861 .of_match_table = st_i2c_match,
862 .pm = ST_I2C_PM,
863 },
864 .probe = st_i2c_probe,
865 .remove = st_i2c_remove,
866};
867
868module_platform_driver(st_i2c_driver);
869
870MODULE_AUTHOR("Maxime Coquelin <maxime.coquelin@st.com>");
871MODULE_DESCRIPTION("STMicroelectronics I2C driver");
872MODULE_LICENSE("GPL v2");
diff --git a/drivers/i2c/busses/i2c-wmt.c b/drivers/i2c/busses/i2c-wmt.c
index 31395fa8121d..2c8a3e4f9008 100644
--- a/drivers/i2c/busses/i2c-wmt.c
+++ b/drivers/i2c/busses/i2c-wmt.c
@@ -349,6 +349,7 @@ static int wmt_i2c_reset_hardware(struct wmt_i2c_dev *i2c_dev)
349 err = clk_set_rate(i2c_dev->clk, 20000000); 349 err = clk_set_rate(i2c_dev->clk, 20000000);
350 if (err) { 350 if (err) {
351 dev_err(i2c_dev->dev, "failed to set clock = 20Mhz\n"); 351 dev_err(i2c_dev->dev, "failed to set clock = 20Mhz\n");
352 clk_disable_unprepare(i2c_dev->clk);
352 return err; 353 return err;
353 } 354 }
354 355
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 4c8b368d463b..fc2716afdfd9 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -40,6 +40,7 @@
40#include <linux/i2c-xiic.h> 40#include <linux/i2c-xiic.h>
41#include <linux/io.h> 41#include <linux/io.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/of.h>
43 44
44#define DRIVER_NAME "xiic-i2c" 45#define DRIVER_NAME "xiic-i2c"
45 46
@@ -702,7 +703,7 @@ static int xiic_i2c_probe(struct platform_device *pdev)
702 if (irq < 0) 703 if (irq < 0)
703 goto resource_missing; 704 goto resource_missing;
704 705
705 pdata = (struct xiic_i2c_platform_data *)dev_get_platdata(&pdev->dev); 706 pdata = dev_get_platdata(&pdev->dev);
706 707
707 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); 708 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
708 if (!i2c) 709 if (!i2c)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 75ba8608383e..5923cfa390c8 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -248,7 +248,7 @@ static int i2c_device_probe(struct device *dev)
248 driver = to_i2c_driver(dev->driver); 248 driver = to_i2c_driver(dev->driver);
249 if (!driver->probe || !driver->id_table) 249 if (!driver->probe || !driver->id_table)
250 return -ENODEV; 250 return -ENODEV;
251 client->driver = driver; 251
252 if (!device_can_wakeup(&client->dev)) 252 if (!device_can_wakeup(&client->dev))
253 device_init_wakeup(&client->dev, 253 device_init_wakeup(&client->dev,
254 client->flags & I2C_CLIENT_WAKE); 254 client->flags & I2C_CLIENT_WAKE);
@@ -257,7 +257,6 @@ static int i2c_device_probe(struct device *dev)
257 acpi_dev_pm_attach(&client->dev, true); 257 acpi_dev_pm_attach(&client->dev, true);
258 status = driver->probe(client, i2c_match_id(driver->id_table, client)); 258 status = driver->probe(client, i2c_match_id(driver->id_table, client));
259 if (status) { 259 if (status) {
260 client->driver = NULL;
261 i2c_set_clientdata(client, NULL); 260 i2c_set_clientdata(client, NULL);
262 acpi_dev_pm_detach(&client->dev, true); 261 acpi_dev_pm_detach(&client->dev, true);
263 } 262 }
@@ -281,10 +280,8 @@ static int i2c_device_remove(struct device *dev)
281 dev->driver = NULL; 280 dev->driver = NULL;
282 status = 0; 281 status = 0;
283 } 282 }
284 if (status == 0) { 283 if (status == 0)
285 client->driver = NULL;
286 i2c_set_clientdata(client, NULL); 284 i2c_set_clientdata(client, NULL);
287 }
288 acpi_dev_pm_detach(&client->dev, true); 285 acpi_dev_pm_detach(&client->dev, true);
289 return status; 286 return status;
290} 287}
@@ -1614,9 +1611,14 @@ static int i2c_cmd(struct device *dev, void *_arg)
1614{ 1611{
1615 struct i2c_client *client = i2c_verify_client(dev); 1612 struct i2c_client *client = i2c_verify_client(dev);
1616 struct i2c_cmd_arg *arg = _arg; 1613 struct i2c_cmd_arg *arg = _arg;
1614 struct i2c_driver *driver;
1615
1616 if (!client || !client->dev.driver)
1617 return 0;
1617 1618
1618 if (client && client->driver && client->driver->command) 1619 driver = to_i2c_driver(client->dev.driver);
1619 client->driver->command(client, arg->cmd, arg->arg); 1620 if (driver->command)
1621 driver->command(client, arg->cmd, arg->arg);
1620 return 0; 1622 return 0;
1621} 1623}
1622 1624
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index c3ccdea3d180..80b47e8ce030 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -102,8 +102,8 @@ static void return_i2c_dev(struct i2c_dev *i2c_dev)
102 kfree(i2c_dev); 102 kfree(i2c_dev);
103} 103}
104 104
105static ssize_t show_adapter_name(struct device *dev, 105static ssize_t name_show(struct device *dev,
106 struct device_attribute *attr, char *buf) 106 struct device_attribute *attr, char *buf)
107{ 107{
108 struct i2c_dev *i2c_dev = i2c_dev_get_by_minor(MINOR(dev->devt)); 108 struct i2c_dev *i2c_dev = i2c_dev_get_by_minor(MINOR(dev->devt));
109 109
@@ -111,7 +111,13 @@ static ssize_t show_adapter_name(struct device *dev,
111 return -ENODEV; 111 return -ENODEV;
112 return sprintf(buf, "%s\n", i2c_dev->adap->name); 112 return sprintf(buf, "%s\n", i2c_dev->adap->name);
113} 113}
114static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL); 114static DEVICE_ATTR_RO(name);
115
116static struct attribute *i2c_attrs[] = {
117 &dev_attr_name.attr,
118 NULL,
119};
120ATTRIBUTE_GROUPS(i2c);
115 121
116/* ------------------------------------------------------------------------- */ 122/* ------------------------------------------------------------------------- */
117 123
@@ -562,15 +568,10 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy)
562 res = PTR_ERR(i2c_dev->dev); 568 res = PTR_ERR(i2c_dev->dev);
563 goto error; 569 goto error;
564 } 570 }
565 res = device_create_file(i2c_dev->dev, &dev_attr_name);
566 if (res)
567 goto error_destroy;
568 571
569 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n", 572 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
570 adap->name, adap->nr); 573 adap->name, adap->nr);
571 return 0; 574 return 0;
572error_destroy:
573 device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
574error: 575error:
575 return_i2c_dev(i2c_dev); 576 return_i2c_dev(i2c_dev);
576 return res; 577 return res;
@@ -589,7 +590,6 @@ static int i2cdev_detach_adapter(struct device *dev, void *dummy)
589 if (!i2c_dev) /* attach_adapter must have failed */ 590 if (!i2c_dev) /* attach_adapter must have failed */
590 return 0; 591 return 0;
591 592
592 device_remove_file(i2c_dev->dev, &dev_attr_name);
593 return_i2c_dev(i2c_dev); 593 return_i2c_dev(i2c_dev);
594 device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); 594 device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
595 595
@@ -637,6 +637,7 @@ static int __init i2c_dev_init(void)
637 res = PTR_ERR(i2c_dev_class); 637 res = PTR_ERR(i2c_dev_class);
638 goto out_unreg_chrdev; 638 goto out_unreg_chrdev;
639 } 639 }
640 i2c_dev_class->dev_groups = i2c_groups;
640 641
641 /* Keep track of adapters which will be added or removed later */ 642 /* Keep track of adapters which will be added or removed later */
642 res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier); 643 res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier);
diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c
index 44d4c6071c15..c99b22987366 100644
--- a/drivers/i2c/i2c-smbus.c
+++ b/drivers/i2c/i2c-smbus.c
@@ -46,6 +46,7 @@ static int smbus_do_alert(struct device *dev, void *addrp)
46{ 46{
47 struct i2c_client *client = i2c_verify_client(dev); 47 struct i2c_client *client = i2c_verify_client(dev);
48 struct alert_data *data = addrp; 48 struct alert_data *data = addrp;
49 struct i2c_driver *driver;
49 50
50 if (!client || client->addr != data->addr) 51 if (!client || client->addr != data->addr)
51 return 0; 52 return 0;
@@ -54,12 +55,13 @@ static int smbus_do_alert(struct device *dev, void *addrp)
54 55
55 /* 56 /*
56 * Drivers should either disable alerts, or provide at least 57 * Drivers should either disable alerts, or provide at least
57 * a minimal handler. Lock so client->driver won't change. 58 * a minimal handler. Lock so the driver won't change.
58 */ 59 */
59 device_lock(dev); 60 device_lock(dev);
60 if (client->driver) { 61 if (client->dev.driver) {
61 if (client->driver->alert) 62 driver = to_i2c_driver(client->dev.driver);
62 client->driver->alert(client, data->flag); 63 if (driver->alert)
64 driver->alert(client, data->flag);
63 else 65 else
64 dev_warn(&client->dev, "no driver alert()!\n"); 66 dev_warn(&client->dev, "no driver alert()!\n");
65 } else 67 } else
diff --git a/drivers/i2c/muxes/i2c-arb-gpio-challenge.c b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
index 928656e241dd..c58e093b6032 100644
--- a/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
+++ b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
@@ -238,7 +238,7 @@ static struct platform_driver i2c_arbitrator_driver = {
238 .driver = { 238 .driver = {
239 .owner = THIS_MODULE, 239 .owner = THIS_MODULE,
240 .name = "i2c-arb-gpio-challenge", 240 .name = "i2c-arb-gpio-challenge",
241 .of_match_table = of_match_ptr(i2c_arbitrator_of_match), 241 .of_match_table = i2c_arbitrator_of_match,
242 }, 242 },
243}; 243};
244 244
diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c
index a764da777f08..8a8c56f4b026 100644
--- a/drivers/i2c/muxes/i2c-mux-gpio.c
+++ b/drivers/i2c/muxes/i2c-mux-gpio.c
@@ -30,15 +30,15 @@ static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val)
30 int i; 30 int i;
31 31
32 for (i = 0; i < mux->data.n_gpios; i++) 32 for (i = 0; i < mux->data.n_gpios; i++)
33 gpio_set_value(mux->gpio_base + mux->data.gpios[i], 33 gpio_set_value_cansleep(mux->gpio_base + mux->data.gpios[i],
34 val & (1 << i)); 34 val & (1 << i));
35} 35}
36 36
37static int i2c_mux_gpio_select(struct i2c_adapter *adap, void *data, u32 chan) 37static int i2c_mux_gpio_select(struct i2c_adapter *adap, void *data, u32 chan)
38{ 38{
39 struct gpiomux *mux = data; 39 struct gpiomux *mux = data;
40 40
41 i2c_mux_gpio_set(mux, mux->data.values[chan]); 41 i2c_mux_gpio_set(mux, chan);
42 42
43 return 0; 43 return 0;
44} 44}
@@ -228,7 +228,7 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
228 unsigned int class = mux->data.classes ? mux->data.classes[i] : 0; 228 unsigned int class = mux->data.classes ? mux->data.classes[i] : 0;
229 229
230 mux->adap[i] = i2c_add_mux_adapter(parent, &pdev->dev, mux, nr, 230 mux->adap[i] = i2c_add_mux_adapter(parent, &pdev->dev, mux, nr,
231 i, class, 231 mux->data.values[i], class,
232 i2c_mux_gpio_select, deselect); 232 i2c_mux_gpio_select, deselect);
233 if (!mux->adap[i]) { 233 if (!mux->adap[i]) {
234 ret = -ENODEV; 234 ret = -ENODEV;
@@ -283,7 +283,7 @@ static struct platform_driver i2c_mux_gpio_driver = {
283 .driver = { 283 .driver = {
284 .owner = THIS_MODULE, 284 .owner = THIS_MODULE,
285 .name = "i2c-mux-gpio", 285 .name = "i2c-mux-gpio",
286 .of_match_table = of_match_ptr(i2c_mux_gpio_of_match), 286 .of_match_table = i2c_mux_gpio_of_match,
287 }, 287 },
288}; 288};
289 289
diff --git a/drivers/i2c/muxes/i2c-mux-pinctrl.c b/drivers/i2c/muxes/i2c-mux-pinctrl.c
index 68a37157377d..d7978dc4ad0b 100644
--- a/drivers/i2c/muxes/i2c-mux-pinctrl.c
+++ b/drivers/i2c/muxes/i2c-mux-pinctrl.c
@@ -24,6 +24,7 @@
24#include <linux/i2c-mux-pinctrl.h> 24#include <linux/i2c-mux-pinctrl.h>
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/of.h>
27 28
28struct i2c_mux_pinctrl { 29struct i2c_mux_pinctrl {
29 struct device *dev; 30 struct device *dev;
diff --git a/drivers/infiniband/Kconfig b/drivers/infiniband/Kconfig
index b84791f03a27..5ceda710f516 100644
--- a/drivers/infiniband/Kconfig
+++ b/drivers/infiniband/Kconfig
@@ -31,17 +31,6 @@ config INFINIBAND_USER_ACCESS
31 libibverbs, libibcm and a hardware driver library from 31 libibverbs, libibcm and a hardware driver library from
32 <http://www.openfabrics.org/git/>. 32 <http://www.openfabrics.org/git/>.
33 33
34config INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
35 bool "Experimental and unstable ABI for userspace access to flow steering verbs"
36 depends on INFINIBAND_USER_ACCESS
37 depends on STAGING
38 ---help---
39 The final ABI for userspace access to flow steering verbs
40 has not been defined. To use the current ABI, *WHICH WILL
41 CHANGE IN THE FUTURE*, say Y here.
42
43 If unsure, say N.
44
45config INFINIBAND_USER_MEM 34config INFINIBAND_USER_MEM
46 bool 35 bool
47 depends on INFINIBAND_USER_ACCESS != n 36 depends on INFINIBAND_USER_ACCESS != n
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 784b97cb05b0..f2ef7ef0f36f 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -383,14 +383,11 @@ static int cm_alloc_id(struct cm_id_private *cm_id_priv)
383{ 383{
384 unsigned long flags; 384 unsigned long flags;
385 int id; 385 int id;
386 static int next_id;
387 386
388 idr_preload(GFP_KERNEL); 387 idr_preload(GFP_KERNEL);
389 spin_lock_irqsave(&cm.lock, flags); 388 spin_lock_irqsave(&cm.lock, flags);
390 389
391 id = idr_alloc(&cm.local_id_table, cm_id_priv, next_id, 0, GFP_NOWAIT); 390 id = idr_alloc_cyclic(&cm.local_id_table, cm_id_priv, 0, 0, GFP_NOWAIT);
392 if (id >= 0)
393 next_id = max(id + 1, 0);
394 391
395 spin_unlock_irqrestore(&cm.lock, flags); 392 spin_unlock_irqrestore(&cm.lock, flags);
396 idr_preload_end(); 393 idr_preload_end();
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index d2172e71f985..8e49db690f33 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -328,28 +328,6 @@ static int cma_set_qkey(struct rdma_id_private *id_priv, u32 qkey)
328 return ret; 328 return ret;
329} 329}
330 330
331static int find_gid_port(struct ib_device *device, union ib_gid *gid, u8 port_num)
332{
333 int i;
334 int err;
335 struct ib_port_attr props;
336 union ib_gid tmp;
337
338 err = ib_query_port(device, port_num, &props);
339 if (err)
340 return err;
341
342 for (i = 0; i < props.gid_tbl_len; ++i) {
343 err = ib_query_gid(device, port_num, i, &tmp);
344 if (err)
345 return err;
346 if (!memcmp(&tmp, gid, sizeof tmp))
347 return 0;
348 }
349
350 return -EADDRNOTAVAIL;
351}
352
353static void cma_translate_ib(struct sockaddr_ib *sib, struct rdma_dev_addr *dev_addr) 331static void cma_translate_ib(struct sockaddr_ib *sib, struct rdma_dev_addr *dev_addr)
354{ 332{
355 dev_addr->dev_type = ARPHRD_INFINIBAND; 333 dev_addr->dev_type = ARPHRD_INFINIBAND;
@@ -371,13 +349,14 @@ static int cma_translate_addr(struct sockaddr *addr, struct rdma_dev_addr *dev_a
371 return ret; 349 return ret;
372} 350}
373 351
374static int cma_acquire_dev(struct rdma_id_private *id_priv) 352static int cma_acquire_dev(struct rdma_id_private *id_priv,
353 struct rdma_id_private *listen_id_priv)
375{ 354{
376 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; 355 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
377 struct cma_device *cma_dev; 356 struct cma_device *cma_dev;
378 union ib_gid gid, iboe_gid; 357 union ib_gid gid, iboe_gid;
379 int ret = -ENODEV; 358 int ret = -ENODEV;
380 u8 port; 359 u8 port, found_port;
381 enum rdma_link_layer dev_ll = dev_addr->dev_type == ARPHRD_INFINIBAND ? 360 enum rdma_link_layer dev_ll = dev_addr->dev_type == ARPHRD_INFINIBAND ?
382 IB_LINK_LAYER_INFINIBAND : IB_LINK_LAYER_ETHERNET; 361 IB_LINK_LAYER_INFINIBAND : IB_LINK_LAYER_ETHERNET;
383 362
@@ -389,17 +368,39 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv)
389 iboe_addr_get_sgid(dev_addr, &iboe_gid); 368 iboe_addr_get_sgid(dev_addr, &iboe_gid);
390 memcpy(&gid, dev_addr->src_dev_addr + 369 memcpy(&gid, dev_addr->src_dev_addr +
391 rdma_addr_gid_offset(dev_addr), sizeof gid); 370 rdma_addr_gid_offset(dev_addr), sizeof gid);
371 if (listen_id_priv &&
372 rdma_port_get_link_layer(listen_id_priv->id.device,
373 listen_id_priv->id.port_num) == dev_ll) {
374 cma_dev = listen_id_priv->cma_dev;
375 port = listen_id_priv->id.port_num;
376 if (rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB &&
377 rdma_port_get_link_layer(cma_dev->device, port) == IB_LINK_LAYER_ETHERNET)
378 ret = ib_find_cached_gid(cma_dev->device, &iboe_gid,
379 &found_port, NULL);
380 else
381 ret = ib_find_cached_gid(cma_dev->device, &gid,
382 &found_port, NULL);
383
384 if (!ret && (port == found_port)) {
385 id_priv->id.port_num = found_port;
386 goto out;
387 }
388 }
392 list_for_each_entry(cma_dev, &dev_list, list) { 389 list_for_each_entry(cma_dev, &dev_list, list) {
393 for (port = 1; port <= cma_dev->device->phys_port_cnt; ++port) { 390 for (port = 1; port <= cma_dev->device->phys_port_cnt; ++port) {
391 if (listen_id_priv &&
392 listen_id_priv->cma_dev == cma_dev &&
393 listen_id_priv->id.port_num == port)
394 continue;
394 if (rdma_port_get_link_layer(cma_dev->device, port) == dev_ll) { 395 if (rdma_port_get_link_layer(cma_dev->device, port) == dev_ll) {
395 if (rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB && 396 if (rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB &&
396 rdma_port_get_link_layer(cma_dev->device, port) == IB_LINK_LAYER_ETHERNET) 397 rdma_port_get_link_layer(cma_dev->device, port) == IB_LINK_LAYER_ETHERNET)
397 ret = find_gid_port(cma_dev->device, &iboe_gid, port); 398 ret = ib_find_cached_gid(cma_dev->device, &iboe_gid, &found_port, NULL);
398 else 399 else
399 ret = find_gid_port(cma_dev->device, &gid, port); 400 ret = ib_find_cached_gid(cma_dev->device, &gid, &found_port, NULL);
400 401
401 if (!ret) { 402 if (!ret && (port == found_port)) {
402 id_priv->id.port_num = port; 403 id_priv->id.port_num = found_port;
403 goto out; 404 goto out;
404 } 405 }
405 } 406 }
@@ -1292,7 +1293,7 @@ static int cma_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
1292 } 1293 }
1293 1294
1294 mutex_lock_nested(&conn_id->handler_mutex, SINGLE_DEPTH_NESTING); 1295 mutex_lock_nested(&conn_id->handler_mutex, SINGLE_DEPTH_NESTING);
1295 ret = cma_acquire_dev(conn_id); 1296 ret = cma_acquire_dev(conn_id, listen_id);
1296 if (ret) 1297 if (ret)
1297 goto err2; 1298 goto err2;
1298 1299
@@ -1451,7 +1452,6 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id,
1451{ 1452{
1452 struct rdma_cm_id *new_cm_id; 1453 struct rdma_cm_id *new_cm_id;
1453 struct rdma_id_private *listen_id, *conn_id; 1454 struct rdma_id_private *listen_id, *conn_id;
1454 struct net_device *dev = NULL;
1455 struct rdma_cm_event event; 1455 struct rdma_cm_event event;
1456 int ret; 1456 int ret;
1457 struct ib_device_attr attr; 1457 struct ib_device_attr attr;
@@ -1481,7 +1481,7 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id,
1481 goto out; 1481 goto out;
1482 } 1482 }
1483 1483
1484 ret = cma_acquire_dev(conn_id); 1484 ret = cma_acquire_dev(conn_id, listen_id);
1485 if (ret) { 1485 if (ret) {
1486 mutex_unlock(&conn_id->handler_mutex); 1486 mutex_unlock(&conn_id->handler_mutex);
1487 rdma_destroy_id(new_cm_id); 1487 rdma_destroy_id(new_cm_id);
@@ -1529,8 +1529,6 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id,
1529 cma_deref_id(conn_id); 1529 cma_deref_id(conn_id);
1530 1530
1531out: 1531out:
1532 if (dev)
1533 dev_put(dev);
1534 mutex_unlock(&listen_id->handler_mutex); 1532 mutex_unlock(&listen_id->handler_mutex);
1535 return ret; 1533 return ret;
1536} 1534}
@@ -2066,7 +2064,7 @@ static void addr_handler(int status, struct sockaddr *src_addr,
2066 goto out; 2064 goto out;
2067 2065
2068 if (!status && !id_priv->cma_dev) 2066 if (!status && !id_priv->cma_dev)
2069 status = cma_acquire_dev(id_priv); 2067 status = cma_acquire_dev(id_priv, NULL);
2070 2068
2071 if (status) { 2069 if (status) {
2072 if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED, 2070 if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED,
@@ -2563,7 +2561,7 @@ int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr)
2563 if (ret) 2561 if (ret)
2564 goto err1; 2562 goto err1;
2565 2563
2566 ret = cma_acquire_dev(id_priv); 2564 ret = cma_acquire_dev(id_priv, NULL);
2567 if (ret) 2565 if (ret)
2568 goto err1; 2566 goto err1;
2569 } 2567 }
diff --git a/drivers/infiniband/core/netlink.c b/drivers/infiniband/core/netlink.c
index da06abde9e0d..a1e9cba84944 100644
--- a/drivers/infiniband/core/netlink.c
+++ b/drivers/infiniband/core/netlink.c
@@ -148,7 +148,7 @@ static int ibnl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
148 list_for_each_entry(client, &client_list, list) { 148 list_for_each_entry(client, &client_list, list) {
149 if (client->index == index) { 149 if (client->index == index) {
150 if (op < 0 || op >= client->nops || 150 if (op < 0 || op >= client->nops ||
151 !client->cb_table[RDMA_NL_GET_OP(op)].dump) 151 !client->cb_table[op].dump)
152 return -EINVAL; 152 return -EINVAL;
153 153
154 { 154 {
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index cde1e7b5b85d..faad2caf22b1 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -612,6 +612,7 @@ static ssize_t show_node_type(struct device *device,
612 switch (dev->node_type) { 612 switch (dev->node_type) {
613 case RDMA_NODE_IB_CA: return sprintf(buf, "%d: CA\n", dev->node_type); 613 case RDMA_NODE_IB_CA: return sprintf(buf, "%d: CA\n", dev->node_type);
614 case RDMA_NODE_RNIC: return sprintf(buf, "%d: RNIC\n", dev->node_type); 614 case RDMA_NODE_RNIC: return sprintf(buf, "%d: RNIC\n", dev->node_type);
615 case RDMA_NODE_USNIC: return sprintf(buf, "%d: usNIC\n", dev->node_type);
615 case RDMA_NODE_IB_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type); 616 case RDMA_NODE_IB_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type);
616 case RDMA_NODE_IB_ROUTER: return sprintf(buf, "%d: router\n", dev->node_type); 617 case RDMA_NODE_IB_ROUTER: return sprintf(buf, "%d: router\n", dev->node_type);
617 default: return sprintf(buf, "%d: <unknown>\n", dev->node_type); 618 default: return sprintf(buf, "%d: <unknown>\n", dev->node_type);
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index b0f189be543b..ab8b1c30b36b 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -57,7 +57,7 @@ MODULE_LICENSE("Dual BSD/GPL");
57static unsigned int max_backlog = 1024; 57static unsigned int max_backlog = 1024;
58 58
59static struct ctl_table_header *ucma_ctl_table_hdr; 59static struct ctl_table_header *ucma_ctl_table_hdr;
60static ctl_table ucma_ctl_table[] = { 60static struct ctl_table ucma_ctl_table[] = {
61 { 61 {
62 .procname = "max_backlog", 62 .procname = "max_backlog",
63 .data = &max_backlog, 63 .data = &max_backlog,
@@ -271,7 +271,7 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id,
271 goto out; 271 goto out;
272 } 272 }
273 ctx->backlog--; 273 ctx->backlog--;
274 } else if (!ctx->uid) { 274 } else if (!ctx->uid || ctx->cm_id != cm_id) {
275 /* 275 /*
276 * We ignore events for new connections until userspace has set 276 * We ignore events for new connections until userspace has set
277 * their context. This can only happen if an error occurs on a 277 * their context. This can only happen if an error occurs on a
diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
index d8f9c6c272d7..bdc842e9faef 100644
--- a/drivers/infiniband/core/uverbs.h
+++ b/drivers/infiniband/core/uverbs.h
@@ -47,6 +47,14 @@
47#include <rdma/ib_umem.h> 47#include <rdma/ib_umem.h>
48#include <rdma/ib_user_verbs.h> 48#include <rdma/ib_user_verbs.h>
49 49
50#define INIT_UDATA(udata, ibuf, obuf, ilen, olen) \
51 do { \
52 (udata)->inbuf = (void __user *) (ibuf); \
53 (udata)->outbuf = (void __user *) (obuf); \
54 (udata)->inlen = (ilen); \
55 (udata)->outlen = (olen); \
56 } while (0)
57
50/* 58/*
51 * Our lifetime rules for these structs are the following: 59 * Our lifetime rules for these structs are the following:
52 * 60 *
@@ -178,6 +186,22 @@ void ib_uverbs_event_handler(struct ib_event_handler *handler,
178 struct ib_event *event); 186 struct ib_event *event);
179void ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev, struct ib_xrcd *xrcd); 187void ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev, struct ib_xrcd *xrcd);
180 188
189struct ib_uverbs_flow_spec {
190 union {
191 union {
192 struct ib_uverbs_flow_spec_hdr hdr;
193 struct {
194 __u32 type;
195 __u16 size;
196 __u16 reserved;
197 };
198 };
199 struct ib_uverbs_flow_spec_eth eth;
200 struct ib_uverbs_flow_spec_ipv4 ipv4;
201 struct ib_uverbs_flow_spec_tcp_udp tcp_udp;
202 };
203};
204
181#define IB_UVERBS_DECLARE_CMD(name) \ 205#define IB_UVERBS_DECLARE_CMD(name) \
182 ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \ 206 ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \
183 const char __user *buf, int in_len, \ 207 const char __user *buf, int in_len, \
@@ -217,9 +241,13 @@ IB_UVERBS_DECLARE_CMD(destroy_srq);
217IB_UVERBS_DECLARE_CMD(create_xsrq); 241IB_UVERBS_DECLARE_CMD(create_xsrq);
218IB_UVERBS_DECLARE_CMD(open_xrcd); 242IB_UVERBS_DECLARE_CMD(open_xrcd);
219IB_UVERBS_DECLARE_CMD(close_xrcd); 243IB_UVERBS_DECLARE_CMD(close_xrcd);
220#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING 244
221IB_UVERBS_DECLARE_CMD(create_flow); 245#define IB_UVERBS_DECLARE_EX_CMD(name) \
222IB_UVERBS_DECLARE_CMD(destroy_flow); 246 int ib_uverbs_ex_##name(struct ib_uverbs_file *file, \
223#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */ 247 struct ib_udata *ucore, \
248 struct ib_udata *uhw)
249
250IB_UVERBS_DECLARE_EX_CMD(create_flow);
251IB_UVERBS_DECLARE_EX_CMD(destroy_flow);
224 252
225#endif /* UVERBS_H */ 253#endif /* UVERBS_H */
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 2f0f01b70e3b..65f6e7dc380c 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -54,17 +54,7 @@ static struct uverbs_lock_class qp_lock_class = { .name = "QP-uobj" };
54static struct uverbs_lock_class ah_lock_class = { .name = "AH-uobj" }; 54static struct uverbs_lock_class ah_lock_class = { .name = "AH-uobj" };
55static struct uverbs_lock_class srq_lock_class = { .name = "SRQ-uobj" }; 55static struct uverbs_lock_class srq_lock_class = { .name = "SRQ-uobj" };
56static struct uverbs_lock_class xrcd_lock_class = { .name = "XRCD-uobj" }; 56static struct uverbs_lock_class xrcd_lock_class = { .name = "XRCD-uobj" };
57#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
58static struct uverbs_lock_class rule_lock_class = { .name = "RULE-uobj" }; 57static struct uverbs_lock_class rule_lock_class = { .name = "RULE-uobj" };
59#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
60
61#define INIT_UDATA(udata, ibuf, obuf, ilen, olen) \
62 do { \
63 (udata)->inbuf = (void __user *) (ibuf); \
64 (udata)->outbuf = (void __user *) (obuf); \
65 (udata)->inlen = (ilen); \
66 (udata)->outlen = (olen); \
67 } while (0)
68 58
69/* 59/*
70 * The ib_uobject locking scheme is as follows: 60 * The ib_uobject locking scheme is as follows:
@@ -939,13 +929,9 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
939 if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK)) 929 if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
940 return -EINVAL; 930 return -EINVAL;
941 931
942 /* 932 ret = ib_check_mr_access(cmd.access_flags);
943 * Local write permission is required if remote write or 933 if (ret)
944 * remote atomic permission is also requested. 934 return ret;
945 */
946 if (cmd.access_flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
947 !(cmd.access_flags & IB_ACCESS_LOCAL_WRITE))
948 return -EINVAL;
949 935
950 uobj = kmalloc(sizeof *uobj, GFP_KERNEL); 936 uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
951 if (!uobj) 937 if (!uobj)
@@ -2128,6 +2114,9 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
2128 } 2114 }
2129 next->wr.ud.remote_qpn = user_wr->wr.ud.remote_qpn; 2115 next->wr.ud.remote_qpn = user_wr->wr.ud.remote_qpn;
2130 next->wr.ud.remote_qkey = user_wr->wr.ud.remote_qkey; 2116 next->wr.ud.remote_qkey = user_wr->wr.ud.remote_qkey;
2117 if (next->opcode == IB_WR_SEND_WITH_IMM)
2118 next->ex.imm_data =
2119 (__be32 __force) user_wr->ex.imm_data;
2131 } else { 2120 } else {
2132 switch (next->opcode) { 2121 switch (next->opcode) {
2133 case IB_WR_RDMA_WRITE_WITH_IMM: 2122 case IB_WR_RDMA_WRITE_WITH_IMM:
@@ -2601,8 +2590,7 @@ out_put:
2601 return ret ? ret : in_len; 2590 return ret ? ret : in_len;
2602} 2591}
2603 2592
2604#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING 2593static int kern_spec_to_ib_spec(struct ib_uverbs_flow_spec *kern_spec,
2605static int kern_spec_to_ib_spec(struct ib_kern_spec *kern_spec,
2606 union ib_flow_spec *ib_spec) 2594 union ib_flow_spec *ib_spec)
2607{ 2595{
2608 ib_spec->type = kern_spec->type; 2596 ib_spec->type = kern_spec->type;
@@ -2642,28 +2630,31 @@ static int kern_spec_to_ib_spec(struct ib_kern_spec *kern_spec,
2642 return 0; 2630 return 0;
2643} 2631}
2644 2632
2645ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file, 2633int ib_uverbs_ex_create_flow(struct ib_uverbs_file *file,
2646 const char __user *buf, int in_len, 2634 struct ib_udata *ucore,
2647 int out_len) 2635 struct ib_udata *uhw)
2648{ 2636{
2649 struct ib_uverbs_create_flow cmd; 2637 struct ib_uverbs_create_flow cmd;
2650 struct ib_uverbs_create_flow_resp resp; 2638 struct ib_uverbs_create_flow_resp resp;
2651 struct ib_uobject *uobj; 2639 struct ib_uobject *uobj;
2652 struct ib_flow *flow_id; 2640 struct ib_flow *flow_id;
2653 struct ib_kern_flow_attr *kern_flow_attr; 2641 struct ib_uverbs_flow_attr *kern_flow_attr;
2654 struct ib_flow_attr *flow_attr; 2642 struct ib_flow_attr *flow_attr;
2655 struct ib_qp *qp; 2643 struct ib_qp *qp;
2656 int err = 0; 2644 int err = 0;
2657 void *kern_spec; 2645 void *kern_spec;
2658 void *ib_spec; 2646 void *ib_spec;
2659 int i; 2647 int i;
2660 int kern_attr_size;
2661 2648
2662 if (out_len < sizeof(resp)) 2649 if (ucore->outlen < sizeof(resp))
2663 return -ENOSPC; 2650 return -ENOSPC;
2664 2651
2665 if (copy_from_user(&cmd, buf, sizeof(cmd))) 2652 err = ib_copy_from_udata(&cmd, ucore, sizeof(cmd));
2666 return -EFAULT; 2653 if (err)
2654 return err;
2655
2656 ucore->inbuf += sizeof(cmd);
2657 ucore->inlen -= sizeof(cmd);
2667 2658
2668 if (cmd.comp_mask) 2659 if (cmd.comp_mask)
2669 return -EINVAL; 2660 return -EINVAL;
@@ -2672,32 +2663,27 @@ ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file,
2672 !capable(CAP_NET_ADMIN)) || !capable(CAP_NET_RAW)) 2663 !capable(CAP_NET_ADMIN)) || !capable(CAP_NET_RAW))
2673 return -EPERM; 2664 return -EPERM;
2674 2665
2675 if (cmd.flow_attr.num_of_specs < 0 || 2666 if (cmd.flow_attr.num_of_specs > IB_FLOW_SPEC_SUPPORT_LAYERS)
2676 cmd.flow_attr.num_of_specs > IB_FLOW_SPEC_SUPPORT_LAYERS)
2677 return -EINVAL; 2667 return -EINVAL;
2678 2668
2679 kern_attr_size = cmd.flow_attr.size - sizeof(cmd) - 2669 if (cmd.flow_attr.size > ucore->inlen ||
2680 sizeof(struct ib_uverbs_cmd_hdr_ex); 2670 cmd.flow_attr.size >
2681 2671 (cmd.flow_attr.num_of_specs * sizeof(struct ib_uverbs_flow_spec)))
2682 if (cmd.flow_attr.size < 0 || cmd.flow_attr.size > in_len ||
2683 kern_attr_size < 0 || kern_attr_size >
2684 (cmd.flow_attr.num_of_specs * sizeof(struct ib_kern_spec)))
2685 return -EINVAL; 2672 return -EINVAL;
2686 2673
2687 if (cmd.flow_attr.num_of_specs) { 2674 if (cmd.flow_attr.num_of_specs) {
2688 kern_flow_attr = kmalloc(cmd.flow_attr.size, GFP_KERNEL); 2675 kern_flow_attr = kmalloc(sizeof(*kern_flow_attr) + cmd.flow_attr.size,
2676 GFP_KERNEL);
2689 if (!kern_flow_attr) 2677 if (!kern_flow_attr)
2690 return -ENOMEM; 2678 return -ENOMEM;
2691 2679
2692 memcpy(kern_flow_attr, &cmd.flow_attr, sizeof(*kern_flow_attr)); 2680 memcpy(kern_flow_attr, &cmd.flow_attr, sizeof(*kern_flow_attr));
2693 if (copy_from_user(kern_flow_attr + 1, buf + sizeof(cmd), 2681 err = ib_copy_from_udata(kern_flow_attr + 1, ucore,
2694 kern_attr_size)) { 2682 cmd.flow_attr.size);
2695 err = -EFAULT; 2683 if (err)
2696 goto err_free_attr; 2684 goto err_free_attr;
2697 }
2698 } else { 2685 } else {
2699 kern_flow_attr = &cmd.flow_attr; 2686 kern_flow_attr = &cmd.flow_attr;
2700 kern_attr_size = sizeof(cmd.flow_attr);
2701 } 2687 }
2702 2688
2703 uobj = kmalloc(sizeof(*uobj), GFP_KERNEL); 2689 uobj = kmalloc(sizeof(*uobj), GFP_KERNEL);
@@ -2714,7 +2700,7 @@ ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file,
2714 goto err_uobj; 2700 goto err_uobj;
2715 } 2701 }
2716 2702
2717 flow_attr = kmalloc(cmd.flow_attr.size, GFP_KERNEL); 2703 flow_attr = kmalloc(sizeof(*flow_attr) + cmd.flow_attr.size, GFP_KERNEL);
2718 if (!flow_attr) { 2704 if (!flow_attr) {
2719 err = -ENOMEM; 2705 err = -ENOMEM;
2720 goto err_put; 2706 goto err_put;
@@ -2729,19 +2715,22 @@ ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file,
2729 2715
2730 kern_spec = kern_flow_attr + 1; 2716 kern_spec = kern_flow_attr + 1;
2731 ib_spec = flow_attr + 1; 2717 ib_spec = flow_attr + 1;
2732 for (i = 0; i < flow_attr->num_of_specs && kern_attr_size > 0; i++) { 2718 for (i = 0; i < flow_attr->num_of_specs &&
2719 cmd.flow_attr.size > offsetof(struct ib_uverbs_flow_spec, reserved) &&
2720 cmd.flow_attr.size >=
2721 ((struct ib_uverbs_flow_spec *)kern_spec)->size; i++) {
2733 err = kern_spec_to_ib_spec(kern_spec, ib_spec); 2722 err = kern_spec_to_ib_spec(kern_spec, ib_spec);
2734 if (err) 2723 if (err)
2735 goto err_free; 2724 goto err_free;
2736 flow_attr->size += 2725 flow_attr->size +=
2737 ((union ib_flow_spec *) ib_spec)->size; 2726 ((union ib_flow_spec *) ib_spec)->size;
2738 kern_attr_size -= ((struct ib_kern_spec *) kern_spec)->size; 2727 cmd.flow_attr.size -= ((struct ib_uverbs_flow_spec *)kern_spec)->size;
2739 kern_spec += ((struct ib_kern_spec *) kern_spec)->size; 2728 kern_spec += ((struct ib_uverbs_flow_spec *) kern_spec)->size;
2740 ib_spec += ((union ib_flow_spec *) ib_spec)->size; 2729 ib_spec += ((union ib_flow_spec *) ib_spec)->size;
2741 } 2730 }
2742 if (kern_attr_size) { 2731 if (cmd.flow_attr.size || (i != flow_attr->num_of_specs)) {
2743 pr_warn("create flow failed, %d bytes left from uverb cmd\n", 2732 pr_warn("create flow failed, flow %d: %d bytes left from uverb cmd\n",
2744 kern_attr_size); 2733 i, cmd.flow_attr.size);
2745 goto err_free; 2734 goto err_free;
2746 } 2735 }
2747 flow_id = ib_create_flow(qp, flow_attr, IB_FLOW_DOMAIN_USER); 2736 flow_id = ib_create_flow(qp, flow_attr, IB_FLOW_DOMAIN_USER);
@@ -2760,11 +2749,10 @@ ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file,
2760 memset(&resp, 0, sizeof(resp)); 2749 memset(&resp, 0, sizeof(resp));
2761 resp.flow_handle = uobj->id; 2750 resp.flow_handle = uobj->id;
2762 2751
2763 if (copy_to_user((void __user *)(unsigned long) cmd.response, 2752 err = ib_copy_to_udata(ucore,
2764 &resp, sizeof(resp))) { 2753 &resp, sizeof(resp));
2765 err = -EFAULT; 2754 if (err)
2766 goto err_copy; 2755 goto err_copy;
2767 }
2768 2756
2769 put_qp_read(qp); 2757 put_qp_read(qp);
2770 mutex_lock(&file->mutex); 2758 mutex_lock(&file->mutex);
@@ -2777,7 +2765,7 @@ ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file,
2777 kfree(flow_attr); 2765 kfree(flow_attr);
2778 if (cmd.flow_attr.num_of_specs) 2766 if (cmd.flow_attr.num_of_specs)
2779 kfree(kern_flow_attr); 2767 kfree(kern_flow_attr);
2780 return in_len; 2768 return 0;
2781err_copy: 2769err_copy:
2782 idr_remove_uobj(&ib_uverbs_rule_idr, uobj); 2770 idr_remove_uobj(&ib_uverbs_rule_idr, uobj);
2783destroy_flow: 2771destroy_flow:
@@ -2794,16 +2782,18 @@ err_free_attr:
2794 return err; 2782 return err;
2795} 2783}
2796 2784
2797ssize_t ib_uverbs_destroy_flow(struct ib_uverbs_file *file, 2785int ib_uverbs_ex_destroy_flow(struct ib_uverbs_file *file,
2798 const char __user *buf, int in_len, 2786 struct ib_udata *ucore,
2799 int out_len) { 2787 struct ib_udata *uhw)
2788{
2800 struct ib_uverbs_destroy_flow cmd; 2789 struct ib_uverbs_destroy_flow cmd;
2801 struct ib_flow *flow_id; 2790 struct ib_flow *flow_id;
2802 struct ib_uobject *uobj; 2791 struct ib_uobject *uobj;
2803 int ret; 2792 int ret;
2804 2793
2805 if (copy_from_user(&cmd, buf, sizeof(cmd))) 2794 ret = ib_copy_from_udata(&cmd, ucore, sizeof(cmd));
2806 return -EFAULT; 2795 if (ret)
2796 return ret;
2807 2797
2808 uobj = idr_write_uobj(&ib_uverbs_rule_idr, cmd.flow_handle, 2798 uobj = idr_write_uobj(&ib_uverbs_rule_idr, cmd.flow_handle,
2809 file->ucontext); 2799 file->ucontext);
@@ -2825,9 +2815,8 @@ ssize_t ib_uverbs_destroy_flow(struct ib_uverbs_file *file,
2825 2815
2826 put_uobj(uobj); 2816 put_uobj(uobj);
2827 2817
2828 return ret ? ret : in_len; 2818 return ret;
2829} 2819}
2830#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
2831 2820
2832static int __uverbs_create_xsrq(struct ib_uverbs_file *file, 2821static int __uverbs_create_xsrq(struct ib_uverbs_file *file,
2833 struct ib_uverbs_create_xsrq *cmd, 2822 struct ib_uverbs_create_xsrq *cmd,
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 2df31f68ea09..34386943ebcf 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -115,10 +115,13 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
115 [IB_USER_VERBS_CMD_CLOSE_XRCD] = ib_uverbs_close_xrcd, 115 [IB_USER_VERBS_CMD_CLOSE_XRCD] = ib_uverbs_close_xrcd,
116 [IB_USER_VERBS_CMD_CREATE_XSRQ] = ib_uverbs_create_xsrq, 116 [IB_USER_VERBS_CMD_CREATE_XSRQ] = ib_uverbs_create_xsrq,
117 [IB_USER_VERBS_CMD_OPEN_QP] = ib_uverbs_open_qp, 117 [IB_USER_VERBS_CMD_OPEN_QP] = ib_uverbs_open_qp,
118#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING 118};
119 [IB_USER_VERBS_CMD_CREATE_FLOW] = ib_uverbs_create_flow, 119
120 [IB_USER_VERBS_CMD_DESTROY_FLOW] = ib_uverbs_destroy_flow 120static int (*uverbs_ex_cmd_table[])(struct ib_uverbs_file *file,
121#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */ 121 struct ib_udata *ucore,
122 struct ib_udata *uhw) = {
123 [IB_USER_VERBS_EX_CMD_CREATE_FLOW] = ib_uverbs_ex_create_flow,
124 [IB_USER_VERBS_EX_CMD_DESTROY_FLOW] = ib_uverbs_ex_destroy_flow
122}; 125};
123 126
124static void ib_uverbs_add_one(struct ib_device *device); 127static void ib_uverbs_add_one(struct ib_device *device);
@@ -589,6 +592,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
589{ 592{
590 struct ib_uverbs_file *file = filp->private_data; 593 struct ib_uverbs_file *file = filp->private_data;
591 struct ib_uverbs_cmd_hdr hdr; 594 struct ib_uverbs_cmd_hdr hdr;
595 __u32 flags;
592 596
593 if (count < sizeof hdr) 597 if (count < sizeof hdr)
594 return -EINVAL; 598 return -EINVAL;
@@ -596,45 +600,105 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
596 if (copy_from_user(&hdr, buf, sizeof hdr)) 600 if (copy_from_user(&hdr, buf, sizeof hdr))
597 return -EFAULT; 601 return -EFAULT;
598 602
599 if (hdr.command >= ARRAY_SIZE(uverbs_cmd_table) || 603 flags = (hdr.command &
600 !uverbs_cmd_table[hdr.command]) 604 IB_USER_VERBS_CMD_FLAGS_MASK) >> IB_USER_VERBS_CMD_FLAGS_SHIFT;
601 return -EINVAL;
602 605
603 if (!file->ucontext && 606 if (!flags) {
604 hdr.command != IB_USER_VERBS_CMD_GET_CONTEXT) 607 __u32 command;
605 return -EINVAL;
606 608
607 if (!(file->device->ib_dev->uverbs_cmd_mask & (1ull << hdr.command))) 609 if (hdr.command & ~(__u32)(IB_USER_VERBS_CMD_FLAGS_MASK |
608 return -ENOSYS; 610 IB_USER_VERBS_CMD_COMMAND_MASK))
611 return -EINVAL;
609 612
610#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING 613 command = hdr.command & IB_USER_VERBS_CMD_COMMAND_MASK;
611 if (hdr.command >= IB_USER_VERBS_CMD_THRESHOLD) {
612 struct ib_uverbs_cmd_hdr_ex hdr_ex;
613 614
614 if (copy_from_user(&hdr_ex, buf, sizeof(hdr_ex))) 615 if (command >= ARRAY_SIZE(uverbs_cmd_table) ||
615 return -EFAULT; 616 !uverbs_cmd_table[command])
617 return -EINVAL;
616 618
617 if (((hdr_ex.in_words + hdr_ex.provider_in_words) * 4) != count) 619 if (!file->ucontext &&
620 command != IB_USER_VERBS_CMD_GET_CONTEXT)
618 return -EINVAL; 621 return -EINVAL;
619 622
620 return uverbs_cmd_table[hdr.command](file, 623 if (!(file->device->ib_dev->uverbs_cmd_mask & (1ull << command)))
621 buf + sizeof(hdr_ex), 624 return -ENOSYS;
622 (hdr_ex.in_words + 625
623 hdr_ex.provider_in_words) * 4,
624 (hdr_ex.out_words +
625 hdr_ex.provider_out_words) * 4);
626 } else {
627#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
628 if (hdr.in_words * 4 != count) 626 if (hdr.in_words * 4 != count)
629 return -EINVAL; 627 return -EINVAL;
630 628
631 return uverbs_cmd_table[hdr.command](file, 629 return uverbs_cmd_table[command](file,
632 buf + sizeof(hdr), 630 buf + sizeof(hdr),
633 hdr.in_words * 4, 631 hdr.in_words * 4,
634 hdr.out_words * 4); 632 hdr.out_words * 4);
635#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING 633
634 } else if (flags == IB_USER_VERBS_CMD_FLAG_EXTENDED) {
635 __u32 command;
636
637 struct ib_uverbs_ex_cmd_hdr ex_hdr;
638 struct ib_udata ucore;
639 struct ib_udata uhw;
640 int err;
641 size_t written_count = count;
642
643 if (hdr.command & ~(__u32)(IB_USER_VERBS_CMD_FLAGS_MASK |
644 IB_USER_VERBS_CMD_COMMAND_MASK))
645 return -EINVAL;
646
647 command = hdr.command & IB_USER_VERBS_CMD_COMMAND_MASK;
648
649 if (command >= ARRAY_SIZE(uverbs_ex_cmd_table) ||
650 !uverbs_ex_cmd_table[command])
651 return -ENOSYS;
652
653 if (!file->ucontext)
654 return -EINVAL;
655
656 if (!(file->device->ib_dev->uverbs_ex_cmd_mask & (1ull << command)))
657 return -ENOSYS;
658
659 if (count < (sizeof(hdr) + sizeof(ex_hdr)))
660 return -EINVAL;
661
662 if (copy_from_user(&ex_hdr, buf + sizeof(hdr), sizeof(ex_hdr)))
663 return -EFAULT;
664
665 count -= sizeof(hdr) + sizeof(ex_hdr);
666 buf += sizeof(hdr) + sizeof(ex_hdr);
667
668 if ((hdr.in_words + ex_hdr.provider_in_words) * 8 != count)
669 return -EINVAL;
670
671 if (ex_hdr.response) {
672 if (!hdr.out_words && !ex_hdr.provider_out_words)
673 return -EINVAL;
674 } else {
675 if (hdr.out_words || ex_hdr.provider_out_words)
676 return -EINVAL;
677 }
678
679 INIT_UDATA(&ucore,
680 (hdr.in_words) ? buf : 0,
681 (unsigned long)ex_hdr.response,
682 hdr.in_words * 8,
683 hdr.out_words * 8);
684
685 INIT_UDATA(&uhw,
686 (ex_hdr.provider_in_words) ? buf + ucore.inlen : 0,
687 (ex_hdr.provider_out_words) ? (unsigned long)ex_hdr.response + ucore.outlen : 0,
688 ex_hdr.provider_in_words * 8,
689 ex_hdr.provider_out_words * 8);
690
691 err = uverbs_ex_cmd_table[command](file,
692 &ucore,
693 &uhw);
694
695 if (err)
696 return err;
697
698 return written_count;
636 } 699 }
637#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */ 700
701 return -ENOSYS;
638} 702}
639 703
640static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma) 704static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma)
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index a321df28bab2..d4f6ddf72ffa 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -114,6 +114,8 @@ rdma_node_get_transport(enum rdma_node_type node_type)
114 return RDMA_TRANSPORT_IB; 114 return RDMA_TRANSPORT_IB;
115 case RDMA_NODE_RNIC: 115 case RDMA_NODE_RNIC:
116 return RDMA_TRANSPORT_IWARP; 116 return RDMA_TRANSPORT_IWARP;
117 case RDMA_NODE_USNIC:
118 return RDMA_TRANSPORT_USNIC;
117 default: 119 default:
118 BUG(); 120 BUG();
119 return 0; 121 return 0;
@@ -130,6 +132,7 @@ enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device, u8 port_
130 case RDMA_TRANSPORT_IB: 132 case RDMA_TRANSPORT_IB:
131 return IB_LINK_LAYER_INFINIBAND; 133 return IB_LINK_LAYER_INFINIBAND;
132 case RDMA_TRANSPORT_IWARP: 134 case RDMA_TRANSPORT_IWARP:
135 case RDMA_TRANSPORT_USNIC:
133 return IB_LINK_LAYER_ETHERNET; 136 return IB_LINK_LAYER_ETHERNET;
134 default: 137 default:
135 return IB_LINK_LAYER_UNSPECIFIED; 138 return IB_LINK_LAYER_UNSPECIFIED;
@@ -958,6 +961,11 @@ EXPORT_SYMBOL(ib_resize_cq);
958struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags) 961struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags)
959{ 962{
960 struct ib_mr *mr; 963 struct ib_mr *mr;
964 int err;
965
966 err = ib_check_mr_access(mr_access_flags);
967 if (err)
968 return ERR_PTR(err);
961 969
962 mr = pd->device->get_dma_mr(pd, mr_access_flags); 970 mr = pd->device->get_dma_mr(pd, mr_access_flags);
963 971
@@ -980,6 +988,11 @@ struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
980 u64 *iova_start) 988 u64 *iova_start)
981{ 989{
982 struct ib_mr *mr; 990 struct ib_mr *mr;
991 int err;
992
993 err = ib_check_mr_access(mr_access_flags);
994 if (err)
995 return ERR_PTR(err);
983 996
984 if (!pd->device->reg_phys_mr) 997 if (!pd->device->reg_phys_mr)
985 return ERR_PTR(-ENOSYS); 998 return ERR_PTR(-ENOSYS);
@@ -1010,6 +1023,10 @@ int ib_rereg_phys_mr(struct ib_mr *mr,
1010 struct ib_pd *old_pd; 1023 struct ib_pd *old_pd;
1011 int ret; 1024 int ret;
1012 1025
1026 ret = ib_check_mr_access(mr_access_flags);
1027 if (ret)
1028 return ret;
1029
1013 if (!mr->device->rereg_phys_mr) 1030 if (!mr->device->rereg_phys_mr)
1014 return -ENOSYS; 1031 return -ENOSYS;
1015 1032
diff --git a/drivers/infiniband/hw/cxgb4/device.c b/drivers/infiniband/hw/cxgb4/device.c
index 33d2cc6ab562..4a033853312e 100644
--- a/drivers/infiniband/hw/cxgb4/device.c
+++ b/drivers/infiniband/hw/cxgb4/device.c
@@ -602,10 +602,10 @@ static int c4iw_rdev_open(struct c4iw_rdev *rdev)
602 rdev->lldi.vr->qp.size, 602 rdev->lldi.vr->qp.size,
603 rdev->lldi.vr->cq.start, 603 rdev->lldi.vr->cq.start,
604 rdev->lldi.vr->cq.size); 604 rdev->lldi.vr->cq.size);
605 PDBG("udb len 0x%x udb base %p db_reg %p gts_reg %p qpshift %lu " 605 PDBG("udb len 0x%x udb base %llx db_reg %p gts_reg %p qpshift %lu "
606 "qpmask 0x%x cqshift %lu cqmask 0x%x\n", 606 "qpmask 0x%x cqshift %lu cqmask 0x%x\n",
607 (unsigned)pci_resource_len(rdev->lldi.pdev, 2), 607 (unsigned)pci_resource_len(rdev->lldi.pdev, 2),
608 (void *)(unsigned long)pci_resource_start(rdev->lldi.pdev, 2), 608 (u64)pci_resource_start(rdev->lldi.pdev, 2),
609 rdev->lldi.db_reg, 609 rdev->lldi.db_reg,
610 rdev->lldi.gts_reg, 610 rdev->lldi.gts_reg,
611 rdev->qpshift, rdev->qpmask, 611 rdev->qpshift, rdev->qpmask,
diff --git a/drivers/infiniband/hw/ipath/ipath_user_sdma.c b/drivers/infiniband/hw/ipath/ipath_user_sdma.c
index f5cb13b21445..cc04b7ba3488 100644
--- a/drivers/infiniband/hw/ipath/ipath_user_sdma.c
+++ b/drivers/infiniband/hw/ipath/ipath_user_sdma.c
@@ -280,9 +280,7 @@ static int ipath_user_sdma_pin_pages(const struct ipath_devdata *dd,
280 int j; 280 int j;
281 int ret; 281 int ret;
282 282
283 ret = get_user_pages(current, current->mm, addr, 283 ret = get_user_pages_fast(addr, npages, 0, pages);
284 npages, 0, 1, pages, NULL);
285
286 if (ret != npages) { 284 if (ret != npages) {
287 int i; 285 int i;
288 286
@@ -811,10 +809,7 @@ int ipath_user_sdma_writev(struct ipath_devdata *dd,
811 while (dim) { 809 while (dim) {
812 const int mxp = 8; 810 const int mxp = 8;
813 811
814 down_write(&current->mm->mmap_sem);
815 ret = ipath_user_sdma_queue_pkts(dd, pq, &list, iov, dim, mxp); 812 ret = ipath_user_sdma_queue_pkts(dd, pq, &list, iov, dim, mxp);
816 up_write(&current->mm->mmap_sem);
817
818 if (ret <= 0) 813 if (ret <= 0)
819 goto done_unlock; 814 goto done_unlock;
820 else { 815 else {
diff --git a/drivers/infiniband/hw/mlx4/cq.c b/drivers/infiniband/hw/mlx4/cq.c
index d5e60f44ba5a..66dbf8062374 100644
--- a/drivers/infiniband/hw/mlx4/cq.c
+++ b/drivers/infiniband/hw/mlx4/cq.c
@@ -324,7 +324,7 @@ static int mlx4_ib_get_outstanding_cqes(struct mlx4_ib_cq *cq)
324 u32 i; 324 u32 i;
325 325
326 i = cq->mcq.cons_index; 326 i = cq->mcq.cons_index;
327 while (get_sw_cqe(cq, i & cq->ibcq.cqe)) 327 while (get_sw_cqe(cq, i))
328 ++i; 328 ++i;
329 329
330 return i - cq->mcq.cons_index; 330 return i - cq->mcq.cons_index;
@@ -365,7 +365,7 @@ int mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
365 365
366 mutex_lock(&cq->resize_mutex); 366 mutex_lock(&cq->resize_mutex);
367 367
368 if (entries < 1 || entries > dev->dev->caps.max_cqes) { 368 if (entries < 1) {
369 err = -EINVAL; 369 err = -EINVAL;
370 goto out; 370 goto out;
371 } 371 }
@@ -376,6 +376,11 @@ int mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
376 goto out; 376 goto out;
377 } 377 }
378 378
379 if (entries > dev->dev->caps.max_cqes) {
380 err = -EINVAL;
381 goto out;
382 }
383
379 if (ibcq->uobject) { 384 if (ibcq->uobject) {
380 err = mlx4_alloc_resize_umem(dev, cq, entries, udata); 385 err = mlx4_alloc_resize_umem(dev, cq, entries, udata);
381 if (err) 386 if (err)
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index 6a0a0d29660d..1958c5ca792a 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -1685,11 +1685,9 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
1685 ibdev->ib_dev.create_flow = mlx4_ib_create_flow; 1685 ibdev->ib_dev.create_flow = mlx4_ib_create_flow;
1686 ibdev->ib_dev.destroy_flow = mlx4_ib_destroy_flow; 1686 ibdev->ib_dev.destroy_flow = mlx4_ib_destroy_flow;
1687 1687
1688#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING 1688 ibdev->ib_dev.uverbs_ex_cmd_mask |=
1689 ibdev->ib_dev.uverbs_cmd_mask |= 1689 (1ull << IB_USER_VERBS_EX_CMD_CREATE_FLOW) |
1690 (1ull << IB_USER_VERBS_CMD_CREATE_FLOW) | 1690 (1ull << IB_USER_VERBS_EX_CMD_DESTROY_FLOW);
1691 (1ull << IB_USER_VERBS_CMD_DESTROY_FLOW);
1692#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
1693 } 1691 }
1694 1692
1695 mlx4_ib_alloc_eqs(dev, ibdev); 1693 mlx4_ib_alloc_eqs(dev, ibdev);
diff --git a/drivers/infiniband/hw/mlx5/cq.c b/drivers/infiniband/hw/mlx5/cq.c
index 344ab03948a3..b72627429745 100644
--- a/drivers/infiniband/hw/mlx5/cq.c
+++ b/drivers/infiniband/hw/mlx5/cq.c
@@ -556,7 +556,7 @@ static int create_cq_user(struct mlx5_ib_dev *dev, struct ib_udata *udata,
556 goto err_db; 556 goto err_db;
557 } 557 }
558 mlx5_ib_populate_pas(dev, cq->buf.umem, page_shift, (*cqb)->pas, 0); 558 mlx5_ib_populate_pas(dev, cq->buf.umem, page_shift, (*cqb)->pas, 0);
559 (*cqb)->ctx.log_pg_sz = page_shift - PAGE_SHIFT; 559 (*cqb)->ctx.log_pg_sz = page_shift - MLX5_ADAPTER_PAGE_SHIFT;
560 560
561 *index = to_mucontext(context)->uuari.uars[0].index; 561 *index = to_mucontext(context)->uuari.uars[0].index;
562 562
@@ -620,7 +620,7 @@ static int create_cq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_cq *cq,
620 } 620 }
621 mlx5_fill_page_array(&cq->buf.buf, (*cqb)->pas); 621 mlx5_fill_page_array(&cq->buf.buf, (*cqb)->pas);
622 622
623 (*cqb)->ctx.log_pg_sz = cq->buf.buf.page_shift - PAGE_SHIFT; 623 (*cqb)->ctx.log_pg_sz = cq->buf.buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT;
624 *index = dev->mdev.priv.uuari.uars[0].index; 624 *index = dev->mdev.priv.uuari.uars[0].index;
625 625
626 return 0; 626 return 0;
@@ -653,8 +653,11 @@ struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev, int entries,
653 int eqn; 653 int eqn;
654 int err; 654 int err;
655 655
656 if (entries < 0)
657 return ERR_PTR(-EINVAL);
658
656 entries = roundup_pow_of_two(entries + 1); 659 entries = roundup_pow_of_two(entries + 1);
657 if (entries < 1 || entries > dev->mdev.caps.max_cqes) 660 if (entries > dev->mdev.caps.max_cqes)
658 return ERR_PTR(-EINVAL); 661 return ERR_PTR(-EINVAL);
659 662
660 cq = kzalloc(sizeof(*cq), GFP_KERNEL); 663 cq = kzalloc(sizeof(*cq), GFP_KERNEL);
@@ -747,17 +750,9 @@ int mlx5_ib_destroy_cq(struct ib_cq *cq)
747 return 0; 750 return 0;
748} 751}
749 752
750static int is_equal_rsn(struct mlx5_cqe64 *cqe64, struct mlx5_ib_srq *srq, 753static int is_equal_rsn(struct mlx5_cqe64 *cqe64, u32 rsn)
751 u32 rsn)
752{ 754{
753 u32 lrsn; 755 return rsn == (ntohl(cqe64->sop_drop_qpn) & 0xffffff);
754
755 if (srq)
756 lrsn = be32_to_cpu(cqe64->srqn) & 0xffffff;
757 else
758 lrsn = be32_to_cpu(cqe64->sop_drop_qpn) & 0xffffff;
759
760 return rsn == lrsn;
761} 756}
762 757
763void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 rsn, struct mlx5_ib_srq *srq) 758void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 rsn, struct mlx5_ib_srq *srq)
@@ -787,8 +782,8 @@ void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 rsn, struct mlx5_ib_srq *srq)
787 while ((int) --prod_index - (int) cq->mcq.cons_index >= 0) { 782 while ((int) --prod_index - (int) cq->mcq.cons_index >= 0) {
788 cqe = get_cqe(cq, prod_index & cq->ibcq.cqe); 783 cqe = get_cqe(cq, prod_index & cq->ibcq.cqe);
789 cqe64 = (cq->mcq.cqe_sz == 64) ? cqe : cqe + 64; 784 cqe64 = (cq->mcq.cqe_sz == 64) ? cqe : cqe + 64;
790 if (is_equal_rsn(cqe64, srq, rsn)) { 785 if (is_equal_rsn(cqe64, rsn)) {
791 if (srq) 786 if (srq && (ntohl(cqe64->srqn) & 0xffffff))
792 mlx5_ib_free_srq_wqe(srq, be16_to_cpu(cqe64->wqe_counter)); 787 mlx5_ib_free_srq_wqe(srq, be16_to_cpu(cqe64->wqe_counter));
793 ++nfreed; 788 ++nfreed;
794 } else if (nfreed) { 789 } else if (nfreed) {
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index b1a6cb3a2809..306534109627 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -745,7 +745,8 @@ static int alloc_pa_mkey(struct mlx5_ib_dev *dev, u32 *key, u32 pdn)
745 seg->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8); 745 seg->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
746 seg->start_addr = 0; 746 seg->start_addr = 0;
747 747
748 err = mlx5_core_create_mkey(&dev->mdev, &mr, in, sizeof(*in)); 748 err = mlx5_core_create_mkey(&dev->mdev, &mr, in, sizeof(*in),
749 NULL, NULL, NULL);
749 if (err) { 750 if (err) {
750 mlx5_ib_warn(dev, "failed to create mkey, %d\n", err); 751 mlx5_ib_warn(dev, "failed to create mkey, %d\n", err);
751 goto err_in; 752 goto err_in;
diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h
index 836be9157242..4c134d93d4fc 100644
--- a/drivers/infiniband/hw/mlx5/mlx5_ib.h
+++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h
@@ -262,6 +262,9 @@ struct mlx5_ib_mr {
262 int npages; 262 int npages;
263 struct completion done; 263 struct completion done;
264 enum ib_wc_status status; 264 enum ib_wc_status status;
265 struct mlx5_ib_dev *dev;
266 struct mlx5_create_mkey_mbox_out out;
267 unsigned long start;
265}; 268};
266 269
267struct mlx5_ib_fast_reg_page_list { 270struct mlx5_ib_fast_reg_page_list {
@@ -323,6 +326,7 @@ struct mlx5_cache_ent {
323 struct mlx5_ib_dev *dev; 326 struct mlx5_ib_dev *dev;
324 struct work_struct work; 327 struct work_struct work;
325 struct delayed_work dwork; 328 struct delayed_work dwork;
329 int pending;
326}; 330};
327 331
328struct mlx5_mr_cache { 332struct mlx5_mr_cache {
@@ -358,6 +362,8 @@ struct mlx5_ib_dev {
358 spinlock_t mr_lock; 362 spinlock_t mr_lock;
359 struct mlx5_ib_resources devr; 363 struct mlx5_ib_resources devr;
360 struct mlx5_mr_cache cache; 364 struct mlx5_mr_cache cache;
365 struct timer_list delay_timer;
366 int fill_delay;
361}; 367};
362 368
363static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq) 369static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)
diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c
index 3453580b1eb2..039c3e40fcb4 100644
--- a/drivers/infiniband/hw/mlx5/mr.c
+++ b/drivers/infiniband/hw/mlx5/mr.c
@@ -35,11 +35,12 @@
35#include <linux/random.h> 35#include <linux/random.h>
36#include <linux/debugfs.h> 36#include <linux/debugfs.h>
37#include <linux/export.h> 37#include <linux/export.h>
38#include <linux/delay.h>
38#include <rdma/ib_umem.h> 39#include <rdma/ib_umem.h>
39#include "mlx5_ib.h" 40#include "mlx5_ib.h"
40 41
41enum { 42enum {
42 DEF_CACHE_SIZE = 10, 43 MAX_PENDING_REG_MR = 8,
43}; 44};
44 45
45enum { 46enum {
@@ -63,6 +64,51 @@ static int order2idx(struct mlx5_ib_dev *dev, int order)
63 return order - cache->ent[0].order; 64 return order - cache->ent[0].order;
64} 65}
65 66
67static void reg_mr_callback(int status, void *context)
68{
69 struct mlx5_ib_mr *mr = context;
70 struct mlx5_ib_dev *dev = mr->dev;
71 struct mlx5_mr_cache *cache = &dev->cache;
72 int c = order2idx(dev, mr->order);
73 struct mlx5_cache_ent *ent = &cache->ent[c];
74 u8 key;
75 unsigned long flags;
76
77 spin_lock_irqsave(&ent->lock, flags);
78 ent->pending--;
79 spin_unlock_irqrestore(&ent->lock, flags);
80 if (status) {
81 mlx5_ib_warn(dev, "async reg mr failed. status %d\n", status);
82 kfree(mr);
83 dev->fill_delay = 1;
84 mod_timer(&dev->delay_timer, jiffies + HZ);
85 return;
86 }
87
88 if (mr->out.hdr.status) {
89 mlx5_ib_warn(dev, "failed - status %d, syndorme 0x%x\n",
90 mr->out.hdr.status,
91 be32_to_cpu(mr->out.hdr.syndrome));
92 kfree(mr);
93 dev->fill_delay = 1;
94 mod_timer(&dev->delay_timer, jiffies + HZ);
95 return;
96 }
97
98 spin_lock_irqsave(&dev->mdev.priv.mkey_lock, flags);
99 key = dev->mdev.priv.mkey_key++;
100 spin_unlock_irqrestore(&dev->mdev.priv.mkey_lock, flags);
101 mr->mmr.key = mlx5_idx_to_mkey(be32_to_cpu(mr->out.mkey) & 0xffffff) | key;
102
103 cache->last_add = jiffies;
104
105 spin_lock_irqsave(&ent->lock, flags);
106 list_add_tail(&mr->list, &ent->head);
107 ent->cur++;
108 ent->size++;
109 spin_unlock_irqrestore(&ent->lock, flags);
110}
111
66static int add_keys(struct mlx5_ib_dev *dev, int c, int num) 112static int add_keys(struct mlx5_ib_dev *dev, int c, int num)
67{ 113{
68 struct mlx5_mr_cache *cache = &dev->cache; 114 struct mlx5_mr_cache *cache = &dev->cache;
@@ -78,36 +124,39 @@ static int add_keys(struct mlx5_ib_dev *dev, int c, int num)
78 return -ENOMEM; 124 return -ENOMEM;
79 125
80 for (i = 0; i < num; i++) { 126 for (i = 0; i < num; i++) {
127 if (ent->pending >= MAX_PENDING_REG_MR) {
128 err = -EAGAIN;
129 break;
130 }
131
81 mr = kzalloc(sizeof(*mr), GFP_KERNEL); 132 mr = kzalloc(sizeof(*mr), GFP_KERNEL);
82 if (!mr) { 133 if (!mr) {
83 err = -ENOMEM; 134 err = -ENOMEM;
84 goto out; 135 break;
85 } 136 }
86 mr->order = ent->order; 137 mr->order = ent->order;
87 mr->umred = 1; 138 mr->umred = 1;
139 mr->dev = dev;
88 in->seg.status = 1 << 6; 140 in->seg.status = 1 << 6;
89 in->seg.xlt_oct_size = cpu_to_be32((npages + 1) / 2); 141 in->seg.xlt_oct_size = cpu_to_be32((npages + 1) / 2);
90 in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << 8); 142 in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
91 in->seg.flags = MLX5_ACCESS_MODE_MTT | MLX5_PERM_UMR_EN; 143 in->seg.flags = MLX5_ACCESS_MODE_MTT | MLX5_PERM_UMR_EN;
92 in->seg.log2_page_size = 12; 144 in->seg.log2_page_size = 12;
93 145
146 spin_lock_irq(&ent->lock);
147 ent->pending++;
148 spin_unlock_irq(&ent->lock);
149 mr->start = jiffies;
94 err = mlx5_core_create_mkey(&dev->mdev, &mr->mmr, in, 150 err = mlx5_core_create_mkey(&dev->mdev, &mr->mmr, in,
95 sizeof(*in)); 151 sizeof(*in), reg_mr_callback,
152 mr, &mr->out);
96 if (err) { 153 if (err) {
97 mlx5_ib_warn(dev, "create mkey failed %d\n", err); 154 mlx5_ib_warn(dev, "create mkey failed %d\n", err);
98 kfree(mr); 155 kfree(mr);
99 goto out; 156 break;
100 } 157 }
101 cache->last_add = jiffies;
102
103 spin_lock(&ent->lock);
104 list_add_tail(&mr->list, &ent->head);
105 ent->cur++;
106 ent->size++;
107 spin_unlock(&ent->lock);
108 } 158 }
109 159
110out:
111 kfree(in); 160 kfree(in);
112 return err; 161 return err;
113} 162}
@@ -121,16 +170,16 @@ static void remove_keys(struct mlx5_ib_dev *dev, int c, int num)
121 int i; 170 int i;
122 171
123 for (i = 0; i < num; i++) { 172 for (i = 0; i < num; i++) {
124 spin_lock(&ent->lock); 173 spin_lock_irq(&ent->lock);
125 if (list_empty(&ent->head)) { 174 if (list_empty(&ent->head)) {
126 spin_unlock(&ent->lock); 175 spin_unlock_irq(&ent->lock);
127 return; 176 return;
128 } 177 }
129 mr = list_first_entry(&ent->head, struct mlx5_ib_mr, list); 178 mr = list_first_entry(&ent->head, struct mlx5_ib_mr, list);
130 list_del(&mr->list); 179 list_del(&mr->list);
131 ent->cur--; 180 ent->cur--;
132 ent->size--; 181 ent->size--;
133 spin_unlock(&ent->lock); 182 spin_unlock_irq(&ent->lock);
134 err = mlx5_core_destroy_mkey(&dev->mdev, &mr->mmr); 183 err = mlx5_core_destroy_mkey(&dev->mdev, &mr->mmr);
135 if (err) 184 if (err)
136 mlx5_ib_warn(dev, "failed destroy mkey\n"); 185 mlx5_ib_warn(dev, "failed destroy mkey\n");
@@ -162,9 +211,13 @@ static ssize_t size_write(struct file *filp, const char __user *buf,
162 return -EINVAL; 211 return -EINVAL;
163 212
164 if (var > ent->size) { 213 if (var > ent->size) {
165 err = add_keys(dev, c, var - ent->size); 214 do {
166 if (err) 215 err = add_keys(dev, c, var - ent->size);
167 return err; 216 if (err && err != -EAGAIN)
217 return err;
218
219 usleep_range(3000, 5000);
220 } while (err);
168 } else if (var < ent->size) { 221 } else if (var < ent->size) {
169 remove_keys(dev, c, ent->size - var); 222 remove_keys(dev, c, ent->size - var);
170 } 223 }
@@ -280,23 +333,37 @@ static void __cache_work_func(struct mlx5_cache_ent *ent)
280 struct mlx5_ib_dev *dev = ent->dev; 333 struct mlx5_ib_dev *dev = ent->dev;
281 struct mlx5_mr_cache *cache = &dev->cache; 334 struct mlx5_mr_cache *cache = &dev->cache;
282 int i = order2idx(dev, ent->order); 335 int i = order2idx(dev, ent->order);
336 int err;
283 337
284 if (cache->stopped) 338 if (cache->stopped)
285 return; 339 return;
286 340
287 ent = &dev->cache.ent[i]; 341 ent = &dev->cache.ent[i];
288 if (ent->cur < 2 * ent->limit) { 342 if (ent->cur < 2 * ent->limit && !dev->fill_delay) {
289 add_keys(dev, i, 1); 343 err = add_keys(dev, i, 1);
290 if (ent->cur < 2 * ent->limit) 344 if (ent->cur < 2 * ent->limit) {
291 queue_work(cache->wq, &ent->work); 345 if (err == -EAGAIN) {
346 mlx5_ib_dbg(dev, "returned eagain, order %d\n",
347 i + 2);
348 queue_delayed_work(cache->wq, &ent->dwork,
349 msecs_to_jiffies(3));
350 } else if (err) {
351 mlx5_ib_warn(dev, "command failed order %d, err %d\n",
352 i + 2, err);
353 queue_delayed_work(cache->wq, &ent->dwork,
354 msecs_to_jiffies(1000));
355 } else {
356 queue_work(cache->wq, &ent->work);
357 }
358 }
292 } else if (ent->cur > 2 * ent->limit) { 359 } else if (ent->cur > 2 * ent->limit) {
293 if (!someone_adding(cache) && 360 if (!someone_adding(cache) &&
294 time_after(jiffies, cache->last_add + 60 * HZ)) { 361 time_after(jiffies, cache->last_add + 300 * HZ)) {
295 remove_keys(dev, i, 1); 362 remove_keys(dev, i, 1);
296 if (ent->cur > ent->limit) 363 if (ent->cur > ent->limit)
297 queue_work(cache->wq, &ent->work); 364 queue_work(cache->wq, &ent->work);
298 } else { 365 } else {
299 queue_delayed_work(cache->wq, &ent->dwork, 60 * HZ); 366 queue_delayed_work(cache->wq, &ent->dwork, 300 * HZ);
300 } 367 }
301 } 368 }
302} 369}
@@ -336,18 +403,18 @@ static struct mlx5_ib_mr *alloc_cached_mr(struct mlx5_ib_dev *dev, int order)
336 403
337 mlx5_ib_dbg(dev, "order %d, cache index %d\n", ent->order, i); 404 mlx5_ib_dbg(dev, "order %d, cache index %d\n", ent->order, i);
338 405
339 spin_lock(&ent->lock); 406 spin_lock_irq(&ent->lock);
340 if (!list_empty(&ent->head)) { 407 if (!list_empty(&ent->head)) {
341 mr = list_first_entry(&ent->head, struct mlx5_ib_mr, 408 mr = list_first_entry(&ent->head, struct mlx5_ib_mr,
342 list); 409 list);
343 list_del(&mr->list); 410 list_del(&mr->list);
344 ent->cur--; 411 ent->cur--;
345 spin_unlock(&ent->lock); 412 spin_unlock_irq(&ent->lock);
346 if (ent->cur < ent->limit) 413 if (ent->cur < ent->limit)
347 queue_work(cache->wq, &ent->work); 414 queue_work(cache->wq, &ent->work);
348 break; 415 break;
349 } 416 }
350 spin_unlock(&ent->lock); 417 spin_unlock_irq(&ent->lock);
351 418
352 queue_work(cache->wq, &ent->work); 419 queue_work(cache->wq, &ent->work);
353 420
@@ -374,12 +441,12 @@ static void free_cached_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr)
374 return; 441 return;
375 } 442 }
376 ent = &cache->ent[c]; 443 ent = &cache->ent[c];
377 spin_lock(&ent->lock); 444 spin_lock_irq(&ent->lock);
378 list_add_tail(&mr->list, &ent->head); 445 list_add_tail(&mr->list, &ent->head);
379 ent->cur++; 446 ent->cur++;
380 if (ent->cur > 2 * ent->limit) 447 if (ent->cur > 2 * ent->limit)
381 shrink = 1; 448 shrink = 1;
382 spin_unlock(&ent->lock); 449 spin_unlock_irq(&ent->lock);
383 450
384 if (shrink) 451 if (shrink)
385 queue_work(cache->wq, &ent->work); 452 queue_work(cache->wq, &ent->work);
@@ -394,16 +461,16 @@ static void clean_keys(struct mlx5_ib_dev *dev, int c)
394 461
395 cancel_delayed_work(&ent->dwork); 462 cancel_delayed_work(&ent->dwork);
396 while (1) { 463 while (1) {
397 spin_lock(&ent->lock); 464 spin_lock_irq(&ent->lock);
398 if (list_empty(&ent->head)) { 465 if (list_empty(&ent->head)) {
399 spin_unlock(&ent->lock); 466 spin_unlock_irq(&ent->lock);
400 return; 467 return;
401 } 468 }
402 mr = list_first_entry(&ent->head, struct mlx5_ib_mr, list); 469 mr = list_first_entry(&ent->head, struct mlx5_ib_mr, list);
403 list_del(&mr->list); 470 list_del(&mr->list);
404 ent->cur--; 471 ent->cur--;
405 ent->size--; 472 ent->size--;
406 spin_unlock(&ent->lock); 473 spin_unlock_irq(&ent->lock);
407 err = mlx5_core_destroy_mkey(&dev->mdev, &mr->mmr); 474 err = mlx5_core_destroy_mkey(&dev->mdev, &mr->mmr);
408 if (err) 475 if (err)
409 mlx5_ib_warn(dev, "failed destroy mkey\n"); 476 mlx5_ib_warn(dev, "failed destroy mkey\n");
@@ -464,12 +531,18 @@ static void mlx5_mr_cache_debugfs_cleanup(struct mlx5_ib_dev *dev)
464 debugfs_remove_recursive(dev->cache.root); 531 debugfs_remove_recursive(dev->cache.root);
465} 532}
466 533
534static void delay_time_func(unsigned long ctx)
535{
536 struct mlx5_ib_dev *dev = (struct mlx5_ib_dev *)ctx;
537
538 dev->fill_delay = 0;
539}
540
467int mlx5_mr_cache_init(struct mlx5_ib_dev *dev) 541int mlx5_mr_cache_init(struct mlx5_ib_dev *dev)
468{ 542{
469 struct mlx5_mr_cache *cache = &dev->cache; 543 struct mlx5_mr_cache *cache = &dev->cache;
470 struct mlx5_cache_ent *ent; 544 struct mlx5_cache_ent *ent;
471 int limit; 545 int limit;
472 int size;
473 int err; 546 int err;
474 int i; 547 int i;
475 548
@@ -479,6 +552,7 @@ int mlx5_mr_cache_init(struct mlx5_ib_dev *dev)
479 return -ENOMEM; 552 return -ENOMEM;
480 } 553 }
481 554
555 setup_timer(&dev->delay_timer, delay_time_func, (unsigned long)dev);
482 for (i = 0; i < MAX_MR_CACHE_ENTRIES; i++) { 556 for (i = 0; i < MAX_MR_CACHE_ENTRIES; i++) {
483 INIT_LIST_HEAD(&cache->ent[i].head); 557 INIT_LIST_HEAD(&cache->ent[i].head);
484 spin_lock_init(&cache->ent[i].lock); 558 spin_lock_init(&cache->ent[i].lock);
@@ -489,13 +563,11 @@ int mlx5_mr_cache_init(struct mlx5_ib_dev *dev)
489 ent->order = i + 2; 563 ent->order = i + 2;
490 ent->dev = dev; 564 ent->dev = dev;
491 565
492 if (dev->mdev.profile->mask & MLX5_PROF_MASK_MR_CACHE) { 566 if (dev->mdev.profile->mask & MLX5_PROF_MASK_MR_CACHE)
493 size = dev->mdev.profile->mr_cache[i].size;
494 limit = dev->mdev.profile->mr_cache[i].limit; 567 limit = dev->mdev.profile->mr_cache[i].limit;
495 } else { 568 else
496 size = DEF_CACHE_SIZE;
497 limit = 0; 569 limit = 0;
498 } 570
499 INIT_WORK(&ent->work, cache_work_func); 571 INIT_WORK(&ent->work, cache_work_func);
500 INIT_DELAYED_WORK(&ent->dwork, delayed_cache_work_func); 572 INIT_DELAYED_WORK(&ent->dwork, delayed_cache_work_func);
501 ent->limit = limit; 573 ent->limit = limit;
@@ -522,6 +594,7 @@ int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev)
522 clean_keys(dev, i); 594 clean_keys(dev, i);
523 595
524 destroy_workqueue(dev->cache.wq); 596 destroy_workqueue(dev->cache.wq);
597 del_timer_sync(&dev->delay_timer);
525 598
526 return 0; 599 return 0;
527} 600}
@@ -551,7 +624,8 @@ struct ib_mr *mlx5_ib_get_dma_mr(struct ib_pd *pd, int acc)
551 seg->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8); 624 seg->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
552 seg->start_addr = 0; 625 seg->start_addr = 0;
553 626
554 err = mlx5_core_create_mkey(mdev, &mr->mmr, in, sizeof(*in)); 627 err = mlx5_core_create_mkey(mdev, &mr->mmr, in, sizeof(*in), NULL, NULL,
628 NULL);
555 if (err) 629 if (err)
556 goto err_in; 630 goto err_in;
557 631
@@ -660,14 +734,14 @@ static struct mlx5_ib_mr *reg_umr(struct ib_pd *pd, struct ib_umem *umem,
660 int err; 734 int err;
661 int i; 735 int i;
662 736
663 for (i = 0; i < 10; i++) { 737 for (i = 0; i < 1; i++) {
664 mr = alloc_cached_mr(dev, order); 738 mr = alloc_cached_mr(dev, order);
665 if (mr) 739 if (mr)
666 break; 740 break;
667 741
668 err = add_keys(dev, order2idx(dev, order), 1); 742 err = add_keys(dev, order2idx(dev, order), 1);
669 if (err) { 743 if (err && err != -EAGAIN) {
670 mlx5_ib_warn(dev, "add_keys failed\n"); 744 mlx5_ib_warn(dev, "add_keys failed, err %d\n", err);
671 break; 745 break;
672 } 746 }
673 } 747 }
@@ -759,8 +833,10 @@ static struct mlx5_ib_mr *reg_create(struct ib_pd *pd, u64 virt_addr,
759 in->seg.xlt_oct_size = cpu_to_be32(get_octo_len(virt_addr, length, 1 << page_shift)); 833 in->seg.xlt_oct_size = cpu_to_be32(get_octo_len(virt_addr, length, 1 << page_shift));
760 in->seg.log2_page_size = page_shift; 834 in->seg.log2_page_size = page_shift;
761 in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << 8); 835 in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
762 in->xlat_oct_act_size = cpu_to_be32(get_octo_len(virt_addr, length, 1 << page_shift)); 836 in->xlat_oct_act_size = cpu_to_be32(get_octo_len(virt_addr, length,
763 err = mlx5_core_create_mkey(&dev->mdev, &mr->mmr, in, inlen); 837 1 << page_shift));
838 err = mlx5_core_create_mkey(&dev->mdev, &mr->mmr, in, inlen, NULL,
839 NULL, NULL);
764 if (err) { 840 if (err) {
765 mlx5_ib_warn(dev, "create mkey failed\n"); 841 mlx5_ib_warn(dev, "create mkey failed\n");
766 goto err_2; 842 goto err_2;
@@ -944,7 +1020,8 @@ struct ib_mr *mlx5_ib_alloc_fast_reg_mr(struct ib_pd *pd,
944 * TBD not needed - issue 197292 */ 1020 * TBD not needed - issue 197292 */
945 in->seg.log2_page_size = PAGE_SHIFT; 1021 in->seg.log2_page_size = PAGE_SHIFT;
946 1022
947 err = mlx5_core_create_mkey(&dev->mdev, &mr->mmr, in, sizeof(*in)); 1023 err = mlx5_core_create_mkey(&dev->mdev, &mr->mmr, in, sizeof(*in), NULL,
1024 NULL, NULL);
948 kfree(in); 1025 kfree(in);
949 if (err) 1026 if (err)
950 goto err_free; 1027 goto err_free;
diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c
index 5659ea880741..7c6b4ba49bec 100644
--- a/drivers/infiniband/hw/mlx5/qp.c
+++ b/drivers/infiniband/hw/mlx5/qp.c
@@ -551,7 +551,7 @@ static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd,
551 } 551 }
552 mlx5_ib_populate_pas(dev, qp->umem, page_shift, (*in)->pas, 0); 552 mlx5_ib_populate_pas(dev, qp->umem, page_shift, (*in)->pas, 0);
553 (*in)->ctx.log_pg_sz_remote_qpn = 553 (*in)->ctx.log_pg_sz_remote_qpn =
554 cpu_to_be32((page_shift - PAGE_SHIFT) << 24); 554 cpu_to_be32((page_shift - MLX5_ADAPTER_PAGE_SHIFT) << 24);
555 (*in)->ctx.params2 = cpu_to_be32(offset << 6); 555 (*in)->ctx.params2 = cpu_to_be32(offset << 6);
556 556
557 (*in)->ctx.qp_counter_set_usr_page = cpu_to_be32(uar_index); 557 (*in)->ctx.qp_counter_set_usr_page = cpu_to_be32(uar_index);
@@ -648,7 +648,8 @@ static int create_kernel_qp(struct mlx5_ib_dev *dev,
648 goto err_buf; 648 goto err_buf;
649 } 649 }
650 (*in)->ctx.qp_counter_set_usr_page = cpu_to_be32(uar_index); 650 (*in)->ctx.qp_counter_set_usr_page = cpu_to_be32(uar_index);
651 (*in)->ctx.log_pg_sz_remote_qpn = cpu_to_be32((qp->buf.page_shift - PAGE_SHIFT) << 24); 651 (*in)->ctx.log_pg_sz_remote_qpn =
652 cpu_to_be32((qp->buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT) << 24);
652 /* Set "fast registration enabled" for all kernel QPs */ 653 /* Set "fast registration enabled" for all kernel QPs */
653 (*in)->ctx.params1 |= cpu_to_be32(1 << 11); 654 (*in)->ctx.params1 |= cpu_to_be32(1 << 11);
654 (*in)->ctx.sq_crq_size |= cpu_to_be16(1 << 4); 655 (*in)->ctx.sq_crq_size |= cpu_to_be16(1 << 4);
@@ -1317,9 +1318,11 @@ static enum mlx5_qp_optpar opt_mask[MLX5_QP_NUM_STATE][MLX5_QP_NUM_STATE][MLX5_Q
1317 MLX5_QP_OPTPAR_RAE | 1318 MLX5_QP_OPTPAR_RAE |
1318 MLX5_QP_OPTPAR_RWE | 1319 MLX5_QP_OPTPAR_RWE |
1319 MLX5_QP_OPTPAR_RNR_TIMEOUT | 1320 MLX5_QP_OPTPAR_RNR_TIMEOUT |
1320 MLX5_QP_OPTPAR_PM_STATE, 1321 MLX5_QP_OPTPAR_PM_STATE |
1322 MLX5_QP_OPTPAR_ALT_ADDR_PATH,
1321 [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE | 1323 [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE |
1322 MLX5_QP_OPTPAR_PM_STATE, 1324 MLX5_QP_OPTPAR_PM_STATE |
1325 MLX5_QP_OPTPAR_ALT_ADDR_PATH,
1323 [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY | 1326 [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY |
1324 MLX5_QP_OPTPAR_SRQN | 1327 MLX5_QP_OPTPAR_SRQN |
1325 MLX5_QP_OPTPAR_CQN_RCV, 1328 MLX5_QP_OPTPAR_CQN_RCV,
@@ -1550,7 +1553,7 @@ static int __mlx5_ib_modify_qp(struct ib_qp *ibqp,
1550 mlx5_cur = to_mlx5_state(cur_state); 1553 mlx5_cur = to_mlx5_state(cur_state);
1551 mlx5_new = to_mlx5_state(new_state); 1554 mlx5_new = to_mlx5_state(new_state);
1552 mlx5_st = to_mlx5_st(ibqp->qp_type); 1555 mlx5_st = to_mlx5_st(ibqp->qp_type);
1553 if (mlx5_cur < 0 || mlx5_new < 0 || mlx5_st < 0) 1556 if (mlx5_st < 0)
1554 goto out; 1557 goto out;
1555 1558
1556 optpar = ib_mask_to_mlx5_opt(attr_mask); 1559 optpar = ib_mask_to_mlx5_opt(attr_mask);
@@ -1744,6 +1747,7 @@ static void set_reg_umr_segment(struct mlx5_wqe_umr_ctrl_seg *umr,
1744 MLX5_MKEY_MASK_PD | 1747 MLX5_MKEY_MASK_PD |
1745 MLX5_MKEY_MASK_LR | 1748 MLX5_MKEY_MASK_LR |
1746 MLX5_MKEY_MASK_LW | 1749 MLX5_MKEY_MASK_LW |
1750 MLX5_MKEY_MASK_KEY |
1747 MLX5_MKEY_MASK_RR | 1751 MLX5_MKEY_MASK_RR |
1748 MLX5_MKEY_MASK_RW | 1752 MLX5_MKEY_MASK_RW |
1749 MLX5_MKEY_MASK_A | 1753 MLX5_MKEY_MASK_A |
@@ -1800,7 +1804,8 @@ static void set_reg_mkey_segment(struct mlx5_mkey_seg *seg, struct ib_send_wr *w
1800 seg->start_addr = cpu_to_be64(wr->wr.fast_reg.iova_start); 1804 seg->start_addr = cpu_to_be64(wr->wr.fast_reg.iova_start);
1801 seg->len = cpu_to_be64(wr->wr.fast_reg.length); 1805 seg->len = cpu_to_be64(wr->wr.fast_reg.length);
1802 seg->log2_page_size = wr->wr.fast_reg.page_shift; 1806 seg->log2_page_size = wr->wr.fast_reg.page_shift;
1803 seg->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8); 1807 seg->qpn_mkey7_0 = cpu_to_be32(0xffffff00 |
1808 mlx5_mkey_variant(wr->wr.fast_reg.rkey));
1804} 1809}
1805 1810
1806static void set_frwr_pages(struct mlx5_wqe_data_seg *dseg, 1811static void set_frwr_pages(struct mlx5_wqe_data_seg *dseg,
@@ -1913,6 +1918,10 @@ static int set_frwr_li_wr(void **seg, struct ib_send_wr *wr, int *size,
1913 if (unlikely((*seg == qp->sq.qend))) 1918 if (unlikely((*seg == qp->sq.qend)))
1914 *seg = mlx5_get_send_wqe(qp, 0); 1919 *seg = mlx5_get_send_wqe(qp, 0);
1915 if (!li) { 1920 if (!li) {
1921 if (unlikely(wr->wr.fast_reg.page_list_len >
1922 wr->wr.fast_reg.page_list->max_page_list_len))
1923 return -ENOMEM;
1924
1916 set_frwr_pages(*seg, wr, mdev, pd, writ); 1925 set_frwr_pages(*seg, wr, mdev, pd, writ);
1917 *seg += sizeof(struct mlx5_wqe_data_seg); 1926 *seg += sizeof(struct mlx5_wqe_data_seg);
1918 *size += (sizeof(struct mlx5_wqe_data_seg) / 16); 1927 *size += (sizeof(struct mlx5_wqe_data_seg) / 16);
diff --git a/drivers/infiniband/hw/mlx5/srq.c b/drivers/infiniband/hw/mlx5/srq.c
index 0aa478bc291a..210b3eaf188a 100644
--- a/drivers/infiniband/hw/mlx5/srq.c
+++ b/drivers/infiniband/hw/mlx5/srq.c
@@ -123,7 +123,7 @@ static int create_srq_user(struct ib_pd *pd, struct mlx5_ib_srq *srq,
123 goto err_in; 123 goto err_in;
124 } 124 }
125 125
126 (*in)->ctx.log_pg_sz = page_shift - PAGE_SHIFT; 126 (*in)->ctx.log_pg_sz = page_shift - MLX5_ADAPTER_PAGE_SHIFT;
127 (*in)->ctx.pgoff_cqn = cpu_to_be32(offset << 26); 127 (*in)->ctx.pgoff_cqn = cpu_to_be32(offset << 26);
128 128
129 return 0; 129 return 0;
@@ -192,7 +192,7 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq,
192 } 192 }
193 srq->wq_sig = !!srq_signature; 193 srq->wq_sig = !!srq_signature;
194 194
195 (*in)->ctx.log_pg_sz = page_shift - PAGE_SHIFT; 195 (*in)->ctx.log_pg_sz = page_shift - MLX5_ADAPTER_PAGE_SHIFT;
196 196
197 return 0; 197 return 0;
198 198
@@ -390,9 +390,7 @@ int mlx5_ib_destroy_srq(struct ib_srq *srq)
390 mlx5_ib_db_unmap_user(to_mucontext(srq->uobject->context), &msrq->db); 390 mlx5_ib_db_unmap_user(to_mucontext(srq->uobject->context), &msrq->db);
391 ib_umem_release(msrq->umem); 391 ib_umem_release(msrq->umem);
392 } else { 392 } else {
393 kfree(msrq->wrid); 393 destroy_srq_kernel(dev, msrq);
394 mlx5_buf_free(&dev->mdev, &msrq->buf);
395 mlx5_db_free(&dev->mdev, &msrq->db);
396 } 394 }
397 395
398 kfree(srq); 396 kfree(srq);
diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
index 5b53ca5a2284..8308e3634767 100644
--- a/drivers/infiniband/hw/nes/nes_verbs.c
+++ b/drivers/infiniband/hw/nes/nes_verbs.c
@@ -2834,7 +2834,7 @@ static int nes_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
2834 init_attr->qp_context = nesqp->ibqp.qp_context; 2834 init_attr->qp_context = nesqp->ibqp.qp_context;
2835 init_attr->send_cq = nesqp->ibqp.send_cq; 2835 init_attr->send_cq = nesqp->ibqp.send_cq;
2836 init_attr->recv_cq = nesqp->ibqp.recv_cq; 2836 init_attr->recv_cq = nesqp->ibqp.recv_cq;
2837 init_attr->srq = nesqp->ibqp.srq = nesqp->ibqp.srq; 2837 init_attr->srq = nesqp->ibqp.srq;
2838 init_attr->cap = attr->cap; 2838 init_attr->cap = attr->cap;
2839 2839
2840 return 0; 2840 return 0;
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma.h b/drivers/infiniband/hw/ocrdma/ocrdma.h
index adc11d14f878..294dd27b601e 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma.h
+++ b/drivers/infiniband/hw/ocrdma/ocrdma.h
@@ -122,6 +122,32 @@ struct mqe_ctx {
122 bool cmd_done; 122 bool cmd_done;
123}; 123};
124 124
125struct ocrdma_hw_mr {
126 u32 lkey;
127 u8 fr_mr;
128 u8 remote_atomic;
129 u8 remote_rd;
130 u8 remote_wr;
131 u8 local_rd;
132 u8 local_wr;
133 u8 mw_bind;
134 u8 rsvd;
135 u64 len;
136 struct ocrdma_pbl *pbl_table;
137 u32 num_pbls;
138 u32 num_pbes;
139 u32 pbl_size;
140 u32 pbe_size;
141 u64 fbo;
142 u64 va;
143};
144
145struct ocrdma_mr {
146 struct ib_mr ibmr;
147 struct ib_umem *umem;
148 struct ocrdma_hw_mr hwmr;
149};
150
125struct ocrdma_dev { 151struct ocrdma_dev {
126 struct ib_device ibdev; 152 struct ib_device ibdev;
127 struct ocrdma_dev_attr attr; 153 struct ocrdma_dev_attr attr;
@@ -169,7 +195,7 @@ struct ocrdma_dev {
169 struct list_head entry; 195 struct list_head entry;
170 struct rcu_head rcu; 196 struct rcu_head rcu;
171 int id; 197 int id;
172 u64 stag_arr[OCRDMA_MAX_STAG]; 198 struct ocrdma_mr *stag_arr[OCRDMA_MAX_STAG];
173 u16 pvid; 199 u16 pvid;
174}; 200};
175 201
@@ -294,31 +320,6 @@ struct ocrdma_qp {
294 u16 db_cache; 320 u16 db_cache;
295}; 321};
296 322
297struct ocrdma_hw_mr {
298 u32 lkey;
299 u8 fr_mr;
300 u8 remote_atomic;
301 u8 remote_rd;
302 u8 remote_wr;
303 u8 local_rd;
304 u8 local_wr;
305 u8 mw_bind;
306 u8 rsvd;
307 u64 len;
308 struct ocrdma_pbl *pbl_table;
309 u32 num_pbls;
310 u32 num_pbes;
311 u32 pbl_size;
312 u32 pbe_size;
313 u64 fbo;
314 u64 va;
315};
316
317struct ocrdma_mr {
318 struct ib_mr ibmr;
319 struct ib_umem *umem;
320 struct ocrdma_hw_mr hwmr;
321};
322 323
323struct ocrdma_ucontext { 324struct ocrdma_ucontext {
324 struct ib_ucontext ibucontext; 325 struct ib_ucontext ibucontext;
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
index 50219ab2279d..56bf32fcb62c 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
@@ -1783,7 +1783,7 @@ static int ocrdma_set_create_qp_sq_cmd(struct ocrdma_create_qp_req *cmd,
1783 u32 max_sges = attrs->cap.max_send_sge; 1783 u32 max_sges = attrs->cap.max_send_sge;
1784 1784
1785 /* QP1 may exceed 127 */ 1785 /* QP1 may exceed 127 */
1786 max_wqe_allocated = min_t(int, attrs->cap.max_send_wr + 1, 1786 max_wqe_allocated = min_t(u32, attrs->cap.max_send_wr + 1,
1787 dev->attr.max_wqe); 1787 dev->attr.max_wqe);
1788 1788
1789 status = ocrdma_build_q_conf(&max_wqe_allocated, 1789 status = ocrdma_build_q_conf(&max_wqe_allocated,
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
index 0ce7674621ea..91443bcb9e0e 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_main.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
@@ -452,9 +452,6 @@ static void ocrdma_remove_free(struct rcu_head *rcu)
452{ 452{
453 struct ocrdma_dev *dev = container_of(rcu, struct ocrdma_dev, rcu); 453 struct ocrdma_dev *dev = container_of(rcu, struct ocrdma_dev, rcu);
454 454
455 ocrdma_free_resources(dev);
456 ocrdma_cleanup_hw(dev);
457
458 idr_remove(&ocrdma_dev_id, dev->id); 455 idr_remove(&ocrdma_dev_id, dev->id);
459 kfree(dev->mbx_cmd); 456 kfree(dev->mbx_cmd);
460 ib_dealloc_device(&dev->ibdev); 457 ib_dealloc_device(&dev->ibdev);
@@ -470,6 +467,10 @@ static void ocrdma_remove(struct ocrdma_dev *dev)
470 spin_lock(&ocrdma_devlist_lock); 467 spin_lock(&ocrdma_devlist_lock);
471 list_del_rcu(&dev->entry); 468 list_del_rcu(&dev->entry);
472 spin_unlock(&ocrdma_devlist_lock); 469 spin_unlock(&ocrdma_devlist_lock);
470
471 ocrdma_free_resources(dev);
472 ocrdma_cleanup_hw(dev);
473
473 call_rcu(&dev->rcu, ocrdma_remove_free); 474 call_rcu(&dev->rcu, ocrdma_remove_free);
474} 475}
475 476
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index 69f1d1221a6b..7686dceadd29 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -1981,9 +1981,7 @@ static int ocrdma_build_fr(struct ocrdma_qp *qp, struct ocrdma_hdr_wqe *hdr,
1981 1981
1982 wqe_size = roundup(wqe_size, OCRDMA_WQE_ALIGN_BYTES); 1982 wqe_size = roundup(wqe_size, OCRDMA_WQE_ALIGN_BYTES);
1983 1983
1984 if ((wr->wr.fast_reg.page_list_len > 1984 if (wr->wr.fast_reg.page_list_len > qp->dev->attr.max_pages_per_frmr)
1985 qp->dev->attr.max_pages_per_frmr) ||
1986 (wr->wr.fast_reg.length > 0xffffffffULL))
1987 return -EINVAL; 1985 return -EINVAL;
1988 1986
1989 hdr->cw |= (OCRDMA_FR_MR << OCRDMA_WQE_OPCODE_SHIFT); 1987 hdr->cw |= (OCRDMA_FR_MR << OCRDMA_WQE_OPCODE_SHIFT);
@@ -2839,7 +2837,7 @@ struct ib_mr *ocrdma_alloc_frmr(struct ib_pd *ibpd, int max_page_list_len)
2839 goto mbx_err; 2837 goto mbx_err;
2840 mr->ibmr.rkey = mr->hwmr.lkey; 2838 mr->ibmr.rkey = mr->hwmr.lkey;
2841 mr->ibmr.lkey = mr->hwmr.lkey; 2839 mr->ibmr.lkey = mr->hwmr.lkey;
2842 dev->stag_arr[(mr->hwmr.lkey >> 8) & (OCRDMA_MAX_STAG - 1)] = (unsigned long) mr; 2840 dev->stag_arr[(mr->hwmr.lkey >> 8) & (OCRDMA_MAX_STAG - 1)] = mr;
2843 return &mr->ibmr; 2841 return &mr->ibmr;
2844mbx_err: 2842mbx_err:
2845 ocrdma_free_mr_pbl_tbl(dev, &mr->hwmr); 2843 ocrdma_free_mr_pbl_tbl(dev, &mr->hwmr);
diff --git a/drivers/infiniband/hw/qib/qib_iba7322.c b/drivers/infiniband/hw/qib/qib_iba7322.c
index 016e7429adf6..5bfc02f450e6 100644
--- a/drivers/infiniband/hw/qib/qib_iba7322.c
+++ b/drivers/infiniband/hw/qib/qib_iba7322.c
@@ -6190,21 +6190,20 @@ static int setup_txselect(const char *str, struct kernel_param *kp)
6190{ 6190{
6191 struct qib_devdata *dd; 6191 struct qib_devdata *dd;
6192 unsigned long val; 6192 unsigned long val;
6193 int ret; 6193 char *n;
6194
6195 if (strlen(str) >= MAX_ATTEN_LEN) { 6194 if (strlen(str) >= MAX_ATTEN_LEN) {
6196 pr_info("txselect_values string too long\n"); 6195 pr_info("txselect_values string too long\n");
6197 return -ENOSPC; 6196 return -ENOSPC;
6198 } 6197 }
6199 ret = kstrtoul(str, 0, &val); 6198 val = simple_strtoul(str, &n, 0);
6200 if (ret || val >= (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ + 6199 if (n == str || val >= (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
6201 TXDDS_MFG_SZ)) { 6200 TXDDS_MFG_SZ)) {
6202 pr_info("txselect_values must start with a number < %d\n", 6201 pr_info("txselect_values must start with a number < %d\n",
6203 TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ + TXDDS_MFG_SZ); 6202 TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ + TXDDS_MFG_SZ);
6204 return ret ? ret : -EINVAL; 6203 return -EINVAL;
6205 } 6204 }
6206
6207 strcpy(txselect_list, str); 6205 strcpy(txselect_list, str);
6206
6208 list_for_each_entry(dd, &qib_dev_list, list) 6207 list_for_each_entry(dd, &qib_dev_list, list)
6209 if (dd->deviceid == PCI_DEVICE_ID_QLOGIC_IB_7322) 6208 if (dd->deviceid == PCI_DEVICE_ID_QLOGIC_IB_7322)
6210 set_no_qsfp_atten(dd, 1); 6209 set_no_qsfp_atten(dd, 1);
diff --git a/drivers/infiniband/hw/qib/qib_mad.h b/drivers/infiniband/hw/qib/qib_mad.h
index 28874f8606f8..941d4d50d8e7 100644
--- a/drivers/infiniband/hw/qib/qib_mad.h
+++ b/drivers/infiniband/hw/qib/qib_mad.h
@@ -54,7 +54,7 @@ struct ib_node_info {
54 __be32 revision; 54 __be32 revision;
55 u8 local_port_num; 55 u8 local_port_num;
56 u8 vendor_id[3]; 56 u8 vendor_id[3];
57} __attribute__ ((packed)); 57} __packed;
58 58
59struct ib_mad_notice_attr { 59struct ib_mad_notice_attr {
60 u8 generic_type; 60 u8 generic_type;
@@ -73,7 +73,7 @@ struct ib_mad_notice_attr {
73 __be16 reserved; 73 __be16 reserved;
74 __be16 lid; /* where violation happened */ 74 __be16 lid; /* where violation happened */
75 u8 port_num; /* where violation happened */ 75 u8 port_num; /* where violation happened */
76 } __attribute__ ((packed)) ntc_129_131; 76 } __packed ntc_129_131;
77 77
78 struct { 78 struct {
79 __be16 reserved; 79 __be16 reserved;
@@ -83,14 +83,14 @@ struct ib_mad_notice_attr {
83 __be32 new_cap_mask; /* new capability mask */ 83 __be32 new_cap_mask; /* new capability mask */
84 u8 reserved3; 84 u8 reserved3;
85 u8 change_flags; /* low 3 bits only */ 85 u8 change_flags; /* low 3 bits only */
86 } __attribute__ ((packed)) ntc_144; 86 } __packed ntc_144;
87 87
88 struct { 88 struct {
89 __be16 reserved; 89 __be16 reserved;
90 __be16 lid; /* lid where sys guid changed */ 90 __be16 lid; /* lid where sys guid changed */
91 __be16 reserved2; 91 __be16 reserved2;
92 __be64 new_sys_guid; 92 __be64 new_sys_guid;
93 } __attribute__ ((packed)) ntc_145; 93 } __packed ntc_145;
94 94
95 struct { 95 struct {
96 __be16 reserved; 96 __be16 reserved;
@@ -104,7 +104,7 @@ struct ib_mad_notice_attr {
104 u8 reserved3; 104 u8 reserved3;
105 u8 dr_trunc_hop; 105 u8 dr_trunc_hop;
106 u8 dr_rtn_path[30]; 106 u8 dr_rtn_path[30];
107 } __attribute__ ((packed)) ntc_256; 107 } __packed ntc_256;
108 108
109 struct { 109 struct {
110 __be16 reserved; 110 __be16 reserved;
@@ -115,7 +115,7 @@ struct ib_mad_notice_attr {
115 __be32 qp2; /* high 8 bits reserved */ 115 __be32 qp2; /* high 8 bits reserved */
116 union ib_gid gid1; 116 union ib_gid gid1;
117 union ib_gid gid2; 117 union ib_gid gid2;
118 } __attribute__ ((packed)) ntc_257_258; 118 } __packed ntc_257_258;
119 119
120 } details; 120 } details;
121}; 121};
@@ -209,7 +209,7 @@ struct ib_pma_portcounters_cong {
209 __be64 port_rcv_packets; 209 __be64 port_rcv_packets;
210 __be64 port_xmit_wait; 210 __be64 port_xmit_wait;
211 __be64 port_adr_events; 211 __be64 port_adr_events;
212} __attribute__ ((packed)); 212} __packed;
213 213
214#define IB_PMA_CONG_HW_CONTROL_TIMER 0x00 214#define IB_PMA_CONG_HW_CONTROL_TIMER 0x00
215#define IB_PMA_CONG_HW_CONTROL_SAMPLE 0x01 215#define IB_PMA_CONG_HW_CONTROL_SAMPLE 0x01
diff --git a/drivers/infiniband/hw/qib/qib_user_sdma.c b/drivers/infiniband/hw/qib/qib_user_sdma.c
index d0a0ea0c14d6..165aee2ca8a0 100644
--- a/drivers/infiniband/hw/qib/qib_user_sdma.c
+++ b/drivers/infiniband/hw/qib/qib_user_sdma.c
@@ -594,8 +594,7 @@ static int qib_user_sdma_pin_pages(const struct qib_devdata *dd,
594 else 594 else
595 j = npages; 595 j = npages;
596 596
597 ret = get_user_pages(current, current->mm, addr, 597 ret = get_user_pages_fast(addr, j, 0, pages);
598 j, 0, 1, pages, NULL);
599 if (ret != j) { 598 if (ret != j) {
600 i = 0; 599 i = 0;
601 j = ret; 600 j = ret;
@@ -1294,11 +1293,8 @@ int qib_user_sdma_writev(struct qib_ctxtdata *rcd,
1294 int mxp = 8; 1293 int mxp = 8;
1295 int ndesc = 0; 1294 int ndesc = 0;
1296 1295
1297 down_write(&current->mm->mmap_sem);
1298 ret = qib_user_sdma_queue_pkts(dd, ppd, pq, 1296 ret = qib_user_sdma_queue_pkts(dd, ppd, pq,
1299 iov, dim, &list, &mxp, &ndesc); 1297 iov, dim, &list, &mxp, &ndesc);
1300 up_write(&current->mm->mmap_sem);
1301
1302 if (ret < 0) 1298 if (ret < 0)
1303 goto done_unlock; 1299 goto done_unlock;
1304 else { 1300 else {
diff --git a/drivers/infiniband/hw/qib/qib_verbs.h b/drivers/infiniband/hw/qib/qib_verbs.h
index 012e2c7575ad..a01c7d2cf541 100644
--- a/drivers/infiniband/hw/qib/qib_verbs.h
+++ b/drivers/infiniband/hw/qib/qib_verbs.h
@@ -150,14 +150,14 @@ struct ib_reth {
150 __be64 vaddr; 150 __be64 vaddr;
151 __be32 rkey; 151 __be32 rkey;
152 __be32 length; 152 __be32 length;
153} __attribute__ ((packed)); 153} __packed;
154 154
155struct ib_atomic_eth { 155struct ib_atomic_eth {
156 __be32 vaddr[2]; /* unaligned so access as 2 32-bit words */ 156 __be32 vaddr[2]; /* unaligned so access as 2 32-bit words */
157 __be32 rkey; 157 __be32 rkey;
158 __be64 swap_data; 158 __be64 swap_data;
159 __be64 compare_data; 159 __be64 compare_data;
160} __attribute__ ((packed)); 160} __packed;
161 161
162struct qib_other_headers { 162struct qib_other_headers {
163 __be32 bth[3]; 163 __be32 bth[3];
@@ -178,7 +178,7 @@ struct qib_other_headers {
178 __be32 aeth; 178 __be32 aeth;
179 struct ib_atomic_eth atomic_eth; 179 struct ib_atomic_eth atomic_eth;
180 } u; 180 } u;
181} __attribute__ ((packed)); 181} __packed;
182 182
183/* 183/*
184 * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes 184 * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes
@@ -195,12 +195,12 @@ struct qib_ib_header {
195 } l; 195 } l;
196 struct qib_other_headers oth; 196 struct qib_other_headers oth;
197 } u; 197 } u;
198} __attribute__ ((packed)); 198} __packed;
199 199
200struct qib_pio_header { 200struct qib_pio_header {
201 __le32 pbc[2]; 201 __le32 pbc[2];
202 struct qib_ib_header hdr; 202 struct qib_ib_header hdr;
203} __attribute__ ((packed)); 203} __packed;
204 204
205/* 205/*
206 * There is one struct qib_mcast for each multicast GID. 206 * There is one struct qib_mcast for each multicast GID.
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index eb71aaa26a9a..c639f90cfda4 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -101,6 +101,7 @@ enum {
101 IPOIB_MCAST_FLAG_SENDONLY = 1, 101 IPOIB_MCAST_FLAG_SENDONLY = 1,
102 IPOIB_MCAST_FLAG_BUSY = 2, /* joining or already joined */ 102 IPOIB_MCAST_FLAG_BUSY = 2, /* joining or already joined */
103 IPOIB_MCAST_FLAG_ATTACHED = 3, 103 IPOIB_MCAST_FLAG_ATTACHED = 3,
104 IPOIB_MCAST_JOIN_STARTED = 4,
104 105
105 MAX_SEND_CQE = 16, 106 MAX_SEND_CQE = 16,
106 IPOIB_CM_COPYBREAK = 256, 107 IPOIB_CM_COPYBREAK = 256,
@@ -151,6 +152,7 @@ struct ipoib_mcast {
151 struct sk_buff_head pkt_queue; 152 struct sk_buff_head pkt_queue;
152 153
153 struct net_device *dev; 154 struct net_device *dev;
155 struct completion done;
154}; 156};
155 157
156struct ipoib_rx_buf { 158struct ipoib_rx_buf {
@@ -299,7 +301,7 @@ struct ipoib_dev_priv {
299 301
300 unsigned long flags; 302 unsigned long flags;
301 303
302 struct mutex vlan_mutex; 304 struct rw_semaphore vlan_rwsem;
303 305
304 struct rb_root path_tree; 306 struct rb_root path_tree;
305 struct list_head path_list; 307 struct list_head path_list;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index 7a3175400b2a..1377f85911c2 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -140,7 +140,8 @@ static int ipoib_cm_post_receive_nonsrq(struct net_device *dev,
140static struct sk_buff *ipoib_cm_alloc_rx_skb(struct net_device *dev, 140static struct sk_buff *ipoib_cm_alloc_rx_skb(struct net_device *dev,
141 struct ipoib_cm_rx_buf *rx_ring, 141 struct ipoib_cm_rx_buf *rx_ring,
142 int id, int frags, 142 int id, int frags,
143 u64 mapping[IPOIB_CM_RX_SG]) 143 u64 mapping[IPOIB_CM_RX_SG],
144 gfp_t gfp)
144{ 145{
145 struct ipoib_dev_priv *priv = netdev_priv(dev); 146 struct ipoib_dev_priv *priv = netdev_priv(dev);
146 struct sk_buff *skb; 147 struct sk_buff *skb;
@@ -164,7 +165,7 @@ static struct sk_buff *ipoib_cm_alloc_rx_skb(struct net_device *dev,
164 } 165 }
165 166
166 for (i = 0; i < frags; i++) { 167 for (i = 0; i < frags; i++) {
167 struct page *page = alloc_page(GFP_ATOMIC); 168 struct page *page = alloc_page(gfp);
168 169
169 if (!page) 170 if (!page)
170 goto partial_error; 171 goto partial_error;
@@ -382,7 +383,8 @@ static int ipoib_cm_nonsrq_init_rx(struct net_device *dev, struct ib_cm_id *cm_i
382 383
383 for (i = 0; i < ipoib_recvq_size; ++i) { 384 for (i = 0; i < ipoib_recvq_size; ++i) {
384 if (!ipoib_cm_alloc_rx_skb(dev, rx->rx_ring, i, IPOIB_CM_RX_SG - 1, 385 if (!ipoib_cm_alloc_rx_skb(dev, rx->rx_ring, i, IPOIB_CM_RX_SG - 1,
385 rx->rx_ring[i].mapping)) { 386 rx->rx_ring[i].mapping,
387 GFP_KERNEL)) {
386 ipoib_warn(priv, "failed to allocate receive buffer %d\n", i); 388 ipoib_warn(priv, "failed to allocate receive buffer %d\n", i);
387 ret = -ENOMEM; 389 ret = -ENOMEM;
388 goto err_count; 390 goto err_count;
@@ -639,7 +641,8 @@ void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
639 frags = PAGE_ALIGN(wc->byte_len - min(wc->byte_len, 641 frags = PAGE_ALIGN(wc->byte_len - min(wc->byte_len,
640 (unsigned)IPOIB_CM_HEAD_SIZE)) / PAGE_SIZE; 642 (unsigned)IPOIB_CM_HEAD_SIZE)) / PAGE_SIZE;
641 643
642 newskb = ipoib_cm_alloc_rx_skb(dev, rx_ring, wr_id, frags, mapping); 644 newskb = ipoib_cm_alloc_rx_skb(dev, rx_ring, wr_id, frags,
645 mapping, GFP_ATOMIC);
643 if (unlikely(!newskb)) { 646 if (unlikely(!newskb)) {
644 /* 647 /*
645 * If we can't allocate a new RX buffer, dump 648 * If we can't allocate a new RX buffer, dump
@@ -1556,7 +1559,8 @@ int ipoib_cm_dev_init(struct net_device *dev)
1556 for (i = 0; i < ipoib_recvq_size; ++i) { 1559 for (i = 0; i < ipoib_recvq_size; ++i) {
1557 if (!ipoib_cm_alloc_rx_skb(dev, priv->cm.srq_ring, i, 1560 if (!ipoib_cm_alloc_rx_skb(dev, priv->cm.srq_ring, i,
1558 priv->cm.num_frags - 1, 1561 priv->cm.num_frags - 1,
1559 priv->cm.srq_ring[i].mapping)) { 1562 priv->cm.srq_ring[i].mapping,
1563 GFP_KERNEL)) {
1560 ipoib_warn(priv, "failed to allocate " 1564 ipoib_warn(priv, "failed to allocate "
1561 "receive buffer %d\n", i); 1565 "receive buffer %d\n", i);
1562 ipoib_cm_dev_cleanup(dev); 1566 ipoib_cm_dev_cleanup(dev);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index 196b1d13cbcb..6a7003ddb0be 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -685,15 +685,13 @@ int ipoib_ib_dev_open(struct net_device *dev)
685 ret = ipoib_ib_post_receives(dev); 685 ret = ipoib_ib_post_receives(dev);
686 if (ret) { 686 if (ret) {
687 ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret); 687 ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret);
688 ipoib_ib_dev_stop(dev, 1); 688 goto dev_stop;
689 return -1;
690 } 689 }
691 690
692 ret = ipoib_cm_dev_open(dev); 691 ret = ipoib_cm_dev_open(dev);
693 if (ret) { 692 if (ret) {
694 ipoib_warn(priv, "ipoib_cm_dev_open returned %d\n", ret); 693 ipoib_warn(priv, "ipoib_cm_dev_open returned %d\n", ret);
695 ipoib_ib_dev_stop(dev, 1); 694 goto dev_stop;
696 return -1;
697 } 695 }
698 696
699 clear_bit(IPOIB_STOP_REAPER, &priv->flags); 697 clear_bit(IPOIB_STOP_REAPER, &priv->flags);
@@ -704,6 +702,11 @@ int ipoib_ib_dev_open(struct net_device *dev)
704 napi_enable(&priv->napi); 702 napi_enable(&priv->napi);
705 703
706 return 0; 704 return 0;
705dev_stop:
706 if (!test_and_set_bit(IPOIB_FLAG_INITIALIZED, &priv->flags))
707 napi_enable(&priv->napi);
708 ipoib_ib_dev_stop(dev, 1);
709 return -1;
707} 710}
708 711
709static void ipoib_pkey_dev_check_presence(struct net_device *dev) 712static void ipoib_pkey_dev_check_presence(struct net_device *dev)
@@ -746,10 +749,8 @@ int ipoib_ib_dev_down(struct net_device *dev, int flush)
746 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { 749 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
747 mutex_lock(&pkey_mutex); 750 mutex_lock(&pkey_mutex);
748 set_bit(IPOIB_PKEY_STOP, &priv->flags); 751 set_bit(IPOIB_PKEY_STOP, &priv->flags);
749 cancel_delayed_work(&priv->pkey_poll_task); 752 cancel_delayed_work_sync(&priv->pkey_poll_task);
750 mutex_unlock(&pkey_mutex); 753 mutex_unlock(&pkey_mutex);
751 if (flush)
752 flush_workqueue(ipoib_workqueue);
753 } 754 }
754 755
755 ipoib_mcast_stop_thread(dev, flush); 756 ipoib_mcast_stop_thread(dev, flush);
@@ -974,7 +975,7 @@ static void __ipoib_ib_dev_flush(struct ipoib_dev_priv *priv,
974 u16 new_index; 975 u16 new_index;
975 int result; 976 int result;
976 977
977 mutex_lock(&priv->vlan_mutex); 978 down_read(&priv->vlan_rwsem);
978 979
979 /* 980 /*
980 * Flush any child interfaces too -- they might be up even if 981 * Flush any child interfaces too -- they might be up even if
@@ -983,7 +984,7 @@ static void __ipoib_ib_dev_flush(struct ipoib_dev_priv *priv,
983 list_for_each_entry(cpriv, &priv->child_intfs, list) 984 list_for_each_entry(cpriv, &priv->child_intfs, list)
984 __ipoib_ib_dev_flush(cpriv, level); 985 __ipoib_ib_dev_flush(cpriv, level);
985 986
986 mutex_unlock(&priv->vlan_mutex); 987 up_read(&priv->vlan_rwsem);
987 988
988 if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags)) { 989 if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags)) {
989 /* for non-child devices must check/update the pkey value here */ 990 /* for non-child devices must check/update the pkey value here */
@@ -1081,6 +1082,11 @@ void ipoib_ib_dev_cleanup(struct net_device *dev)
1081 struct ipoib_dev_priv *priv = netdev_priv(dev); 1082 struct ipoib_dev_priv *priv = netdev_priv(dev);
1082 1083
1083 ipoib_dbg(priv, "cleaning up ib_dev\n"); 1084 ipoib_dbg(priv, "cleaning up ib_dev\n");
1085 /*
1086 * We must make sure there are no more (path) completions
1087 * that may wish to touch priv fields that are no longer valid
1088 */
1089 ipoib_flush_paths(dev);
1084 1090
1085 ipoib_mcast_stop_thread(dev, 1); 1091 ipoib_mcast_stop_thread(dev, 1);
1086 ipoib_mcast_dev_flush(dev); 1092 ipoib_mcast_dev_flush(dev);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 82cec1af902c..d64ed05fb082 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -119,7 +119,7 @@ int ipoib_open(struct net_device *dev)
119 struct ipoib_dev_priv *cpriv; 119 struct ipoib_dev_priv *cpriv;
120 120
121 /* Bring up any child interfaces too */ 121 /* Bring up any child interfaces too */
122 mutex_lock(&priv->vlan_mutex); 122 down_read(&priv->vlan_rwsem);
123 list_for_each_entry(cpriv, &priv->child_intfs, list) { 123 list_for_each_entry(cpriv, &priv->child_intfs, list) {
124 int flags; 124 int flags;
125 125
@@ -129,7 +129,7 @@ int ipoib_open(struct net_device *dev)
129 129
130 dev_change_flags(cpriv->dev, flags | IFF_UP); 130 dev_change_flags(cpriv->dev, flags | IFF_UP);
131 } 131 }
132 mutex_unlock(&priv->vlan_mutex); 132 up_read(&priv->vlan_rwsem);
133 } 133 }
134 134
135 netif_start_queue(dev); 135 netif_start_queue(dev);
@@ -162,7 +162,7 @@ static int ipoib_stop(struct net_device *dev)
162 struct ipoib_dev_priv *cpriv; 162 struct ipoib_dev_priv *cpriv;
163 163
164 /* Bring down any child interfaces too */ 164 /* Bring down any child interfaces too */
165 mutex_lock(&priv->vlan_mutex); 165 down_read(&priv->vlan_rwsem);
166 list_for_each_entry(cpriv, &priv->child_intfs, list) { 166 list_for_each_entry(cpriv, &priv->child_intfs, list) {
167 int flags; 167 int flags;
168 168
@@ -172,7 +172,7 @@ static int ipoib_stop(struct net_device *dev)
172 172
173 dev_change_flags(cpriv->dev, flags & ~IFF_UP); 173 dev_change_flags(cpriv->dev, flags & ~IFF_UP);
174 } 174 }
175 mutex_unlock(&priv->vlan_mutex); 175 up_read(&priv->vlan_rwsem);
176 } 176 }
177 177
178 return 0; 178 return 0;
@@ -1350,7 +1350,7 @@ void ipoib_setup(struct net_device *dev)
1350 1350
1351 ipoib_set_ethtool_ops(dev); 1351 ipoib_set_ethtool_ops(dev);
1352 1352
1353 netif_napi_add(dev, &priv->napi, ipoib_poll, 100); 1353 netif_napi_add(dev, &priv->napi, ipoib_poll, NAPI_POLL_WEIGHT);
1354 1354
1355 dev->watchdog_timeo = HZ; 1355 dev->watchdog_timeo = HZ;
1356 1356
@@ -1372,7 +1372,7 @@ void ipoib_setup(struct net_device *dev)
1372 1372
1373 spin_lock_init(&priv->lock); 1373 spin_lock_init(&priv->lock);
1374 1374
1375 mutex_init(&priv->vlan_mutex); 1375 init_rwsem(&priv->vlan_rwsem);
1376 1376
1377 INIT_LIST_HEAD(&priv->path_list); 1377 INIT_LIST_HEAD(&priv->path_list);
1378 INIT_LIST_HEAD(&priv->child_intfs); 1378 INIT_LIST_HEAD(&priv->child_intfs);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index cecb98a4c662..d4e005720d01 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -386,8 +386,10 @@ static int ipoib_mcast_join_complete(int status,
386 mcast->mcmember.mgid.raw, status); 386 mcast->mcmember.mgid.raw, status);
387 387
388 /* We trap for port events ourselves. */ 388 /* We trap for port events ourselves. */
389 if (status == -ENETRESET) 389 if (status == -ENETRESET) {
390 return 0; 390 status = 0;
391 goto out;
392 }
391 393
392 if (!status) 394 if (!status)
393 status = ipoib_mcast_join_finish(mcast, &multicast->rec); 395 status = ipoib_mcast_join_finish(mcast, &multicast->rec);
@@ -407,7 +409,8 @@ static int ipoib_mcast_join_complete(int status,
407 if (mcast == priv->broadcast) 409 if (mcast == priv->broadcast)
408 queue_work(ipoib_workqueue, &priv->carrier_on_task); 410 queue_work(ipoib_workqueue, &priv->carrier_on_task);
409 411
410 return 0; 412 status = 0;
413 goto out;
411 } 414 }
412 415
413 if (mcast->logcount++ < 20) { 416 if (mcast->logcount++ < 20) {
@@ -434,7 +437,8 @@ static int ipoib_mcast_join_complete(int status,
434 mcast->backoff * HZ); 437 mcast->backoff * HZ);
435 spin_unlock_irq(&priv->lock); 438 spin_unlock_irq(&priv->lock);
436 mutex_unlock(&mcast_mutex); 439 mutex_unlock(&mcast_mutex);
437 440out:
441 complete(&mcast->done);
438 return status; 442 return status;
439} 443}
440 444
@@ -484,11 +488,15 @@ static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
484 } 488 }
485 489
486 set_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); 490 set_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
491 init_completion(&mcast->done);
492 set_bit(IPOIB_MCAST_JOIN_STARTED, &mcast->flags);
493
487 mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port, 494 mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port,
488 &rec, comp_mask, GFP_KERNEL, 495 &rec, comp_mask, GFP_KERNEL,
489 ipoib_mcast_join_complete, mcast); 496 ipoib_mcast_join_complete, mcast);
490 if (IS_ERR(mcast->mc)) { 497 if (IS_ERR(mcast->mc)) {
491 clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); 498 clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
499 complete(&mcast->done);
492 ret = PTR_ERR(mcast->mc); 500 ret = PTR_ERR(mcast->mc);
493 ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret); 501 ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret);
494 502
@@ -510,10 +518,18 @@ void ipoib_mcast_join_task(struct work_struct *work)
510 struct ipoib_dev_priv *priv = 518 struct ipoib_dev_priv *priv =
511 container_of(work, struct ipoib_dev_priv, mcast_task.work); 519 container_of(work, struct ipoib_dev_priv, mcast_task.work);
512 struct net_device *dev = priv->dev; 520 struct net_device *dev = priv->dev;
521 struct ib_port_attr port_attr;
513 522
514 if (!test_bit(IPOIB_MCAST_RUN, &priv->flags)) 523 if (!test_bit(IPOIB_MCAST_RUN, &priv->flags))
515 return; 524 return;
516 525
526 if (ib_query_port(priv->ca, priv->port, &port_attr) ||
527 port_attr.state != IB_PORT_ACTIVE) {
528 ipoib_dbg(priv, "port state is not ACTIVE (state = %d) suspending join task\n",
529 port_attr.state);
530 return;
531 }
532
517 if (ib_query_gid(priv->ca, priv->port, 0, &priv->local_gid)) 533 if (ib_query_gid(priv->ca, priv->port, 0, &priv->local_gid))
518 ipoib_warn(priv, "ib_query_gid() failed\n"); 534 ipoib_warn(priv, "ib_query_gid() failed\n");
519 else 535 else
@@ -751,6 +767,11 @@ void ipoib_mcast_dev_flush(struct net_device *dev)
751 767
752 spin_unlock_irqrestore(&priv->lock, flags); 768 spin_unlock_irqrestore(&priv->lock, flags);
753 769
770 /* seperate between the wait to the leave*/
771 list_for_each_entry_safe(mcast, tmcast, &remove_list, list)
772 if (test_bit(IPOIB_MCAST_JOIN_STARTED, &mcast->flags))
773 wait_for_completion(&mcast->done);
774
754 list_for_each_entry_safe(mcast, tmcast, &remove_list, list) { 775 list_for_each_entry_safe(mcast, tmcast, &remove_list, list) {
755 ipoib_mcast_leave(dev, mcast); 776 ipoib_mcast_leave(dev, mcast);
756 ipoib_mcast_free(mcast); 777 ipoib_mcast_free(mcast);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
index f81abe16cf09..c29b5c838833 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
@@ -142,10 +142,10 @@ static void ipoib_unregister_child_dev(struct net_device *dev, struct list_head
142 priv = netdev_priv(dev); 142 priv = netdev_priv(dev);
143 ppriv = netdev_priv(priv->parent); 143 ppriv = netdev_priv(priv->parent);
144 144
145 mutex_lock(&ppriv->vlan_mutex); 145 down_write(&ppriv->vlan_rwsem);
146 unregister_netdevice_queue(dev, head); 146 unregister_netdevice_queue(dev, head);
147 list_del(&priv->list); 147 list_del(&priv->list);
148 mutex_unlock(&ppriv->vlan_mutex); 148 up_write(&ppriv->vlan_rwsem);
149} 149}
150 150
151static size_t ipoib_get_size(const struct net_device *dev) 151static size_t ipoib_get_size(const struct net_device *dev)
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_vlan.c b/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
index 8292554bccb5..9fad7b5ac8b9 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
@@ -140,7 +140,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)
140 if (!rtnl_trylock()) 140 if (!rtnl_trylock())
141 return restart_syscall(); 141 return restart_syscall();
142 142
143 mutex_lock(&ppriv->vlan_mutex); 143 down_write(&ppriv->vlan_rwsem);
144 144
145 /* 145 /*
146 * First ensure this isn't a duplicate. We check the parent device and 146 * First ensure this isn't a duplicate. We check the parent device and
@@ -163,7 +163,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)
163 result = __ipoib_vlan_add(ppriv, priv, pkey, IPOIB_LEGACY_CHILD); 163 result = __ipoib_vlan_add(ppriv, priv, pkey, IPOIB_LEGACY_CHILD);
164 164
165out: 165out:
166 mutex_unlock(&ppriv->vlan_mutex); 166 up_write(&ppriv->vlan_rwsem);
167 167
168 if (result) 168 if (result)
169 free_netdev(priv->dev); 169 free_netdev(priv->dev);
@@ -185,7 +185,8 @@ int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey)
185 185
186 if (!rtnl_trylock()) 186 if (!rtnl_trylock())
187 return restart_syscall(); 187 return restart_syscall();
188 mutex_lock(&ppriv->vlan_mutex); 188
189 down_write(&ppriv->vlan_rwsem);
189 list_for_each_entry_safe(priv, tpriv, &ppriv->child_intfs, list) { 190 list_for_each_entry_safe(priv, tpriv, &ppriv->child_intfs, list) {
190 if (priv->pkey == pkey && 191 if (priv->pkey == pkey &&
191 priv->child_type == IPOIB_LEGACY_CHILD) { 192 priv->child_type == IPOIB_LEGACY_CHILD) {
@@ -195,7 +196,8 @@ int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey)
195 break; 196 break;
196 } 197 }
197 } 198 }
198 mutex_unlock(&ppriv->vlan_mutex); 199 up_write(&ppriv->vlan_rwsem);
200
199 rtnl_unlock(); 201 rtnl_unlock();
200 202
201 if (dev) { 203 if (dev) {
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index f93baf8254c4..a88631918e85 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -46,6 +46,7 @@
46#include <scsi/scsi.h> 46#include <scsi/scsi.h>
47#include <scsi/scsi_device.h> 47#include <scsi/scsi_device.h>
48#include <scsi/scsi_dbg.h> 48#include <scsi/scsi_dbg.h>
49#include <scsi/scsi_tcq.h>
49#include <scsi/srp.h> 50#include <scsi/srp.h>
50#include <scsi/scsi_transport_srp.h> 51#include <scsi/scsi_transport_srp.h>
51 52
@@ -86,6 +87,32 @@ module_param(topspin_workarounds, int, 0444);
86MODULE_PARM_DESC(topspin_workarounds, 87MODULE_PARM_DESC(topspin_workarounds,
87 "Enable workarounds for Topspin/Cisco SRP target bugs if != 0"); 88 "Enable workarounds for Topspin/Cisco SRP target bugs if != 0");
88 89
90static struct kernel_param_ops srp_tmo_ops;
91
92static int srp_reconnect_delay = 10;
93module_param_cb(reconnect_delay, &srp_tmo_ops, &srp_reconnect_delay,
94 S_IRUGO | S_IWUSR);
95MODULE_PARM_DESC(reconnect_delay, "Time between successive reconnect attempts");
96
97static int srp_fast_io_fail_tmo = 15;
98module_param_cb(fast_io_fail_tmo, &srp_tmo_ops, &srp_fast_io_fail_tmo,
99 S_IRUGO | S_IWUSR);
100MODULE_PARM_DESC(fast_io_fail_tmo,
101 "Number of seconds between the observation of a transport"
102 " layer error and failing all I/O. \"off\" means that this"
103 " functionality is disabled.");
104
105static int srp_dev_loss_tmo = 600;
106module_param_cb(dev_loss_tmo, &srp_tmo_ops, &srp_dev_loss_tmo,
107 S_IRUGO | S_IWUSR);
108MODULE_PARM_DESC(dev_loss_tmo,
109 "Maximum number of seconds that the SRP transport should"
110 " insulate transport layer errors. After this time has been"
111 " exceeded the SCSI host is removed. Should be"
112 " between 1 and " __stringify(SCSI_DEVICE_BLOCK_MAX_TIMEOUT)
113 " if fast_io_fail_tmo has not been set. \"off\" means that"
114 " this functionality is disabled.");
115
89static void srp_add_one(struct ib_device *device); 116static void srp_add_one(struct ib_device *device);
90static void srp_remove_one(struct ib_device *device); 117static void srp_remove_one(struct ib_device *device);
91static void srp_recv_completion(struct ib_cq *cq, void *target_ptr); 118static void srp_recv_completion(struct ib_cq *cq, void *target_ptr);
@@ -102,6 +129,48 @@ static struct ib_client srp_client = {
102 129
103static struct ib_sa_client srp_sa_client; 130static struct ib_sa_client srp_sa_client;
104 131
132static int srp_tmo_get(char *buffer, const struct kernel_param *kp)
133{
134 int tmo = *(int *)kp->arg;
135
136 if (tmo >= 0)
137 return sprintf(buffer, "%d", tmo);
138 else
139 return sprintf(buffer, "off");
140}
141
142static int srp_tmo_set(const char *val, const struct kernel_param *kp)
143{
144 int tmo, res;
145
146 if (strncmp(val, "off", 3) != 0) {
147 res = kstrtoint(val, 0, &tmo);
148 if (res)
149 goto out;
150 } else {
151 tmo = -1;
152 }
153 if (kp->arg == &srp_reconnect_delay)
154 res = srp_tmo_valid(tmo, srp_fast_io_fail_tmo,
155 srp_dev_loss_tmo);
156 else if (kp->arg == &srp_fast_io_fail_tmo)
157 res = srp_tmo_valid(srp_reconnect_delay, tmo, srp_dev_loss_tmo);
158 else
159 res = srp_tmo_valid(srp_reconnect_delay, srp_fast_io_fail_tmo,
160 tmo);
161 if (res)
162 goto out;
163 *(int *)kp->arg = tmo;
164
165out:
166 return res;
167}
168
169static struct kernel_param_ops srp_tmo_ops = {
170 .get = srp_tmo_get,
171 .set = srp_tmo_set,
172};
173
105static inline struct srp_target_port *host_to_target(struct Scsi_Host *host) 174static inline struct srp_target_port *host_to_target(struct Scsi_Host *host)
106{ 175{
107 return (struct srp_target_port *) host->hostdata; 176 return (struct srp_target_port *) host->hostdata;
@@ -231,16 +300,16 @@ static int srp_create_target_ib(struct srp_target_port *target)
231 return -ENOMEM; 300 return -ENOMEM;
232 301
233 recv_cq = ib_create_cq(target->srp_host->srp_dev->dev, 302 recv_cq = ib_create_cq(target->srp_host->srp_dev->dev,
234 srp_recv_completion, NULL, target, SRP_RQ_SIZE, 303 srp_recv_completion, NULL, target,
235 target->comp_vector); 304 target->queue_size, target->comp_vector);
236 if (IS_ERR(recv_cq)) { 305 if (IS_ERR(recv_cq)) {
237 ret = PTR_ERR(recv_cq); 306 ret = PTR_ERR(recv_cq);
238 goto err; 307 goto err;
239 } 308 }
240 309
241 send_cq = ib_create_cq(target->srp_host->srp_dev->dev, 310 send_cq = ib_create_cq(target->srp_host->srp_dev->dev,
242 srp_send_completion, NULL, target, SRP_SQ_SIZE, 311 srp_send_completion, NULL, target,
243 target->comp_vector); 312 target->queue_size, target->comp_vector);
244 if (IS_ERR(send_cq)) { 313 if (IS_ERR(send_cq)) {
245 ret = PTR_ERR(send_cq); 314 ret = PTR_ERR(send_cq);
246 goto err_recv_cq; 315 goto err_recv_cq;
@@ -249,8 +318,8 @@ static int srp_create_target_ib(struct srp_target_port *target)
249 ib_req_notify_cq(recv_cq, IB_CQ_NEXT_COMP); 318 ib_req_notify_cq(recv_cq, IB_CQ_NEXT_COMP);
250 319
251 init_attr->event_handler = srp_qp_event; 320 init_attr->event_handler = srp_qp_event;
252 init_attr->cap.max_send_wr = SRP_SQ_SIZE; 321 init_attr->cap.max_send_wr = target->queue_size;
253 init_attr->cap.max_recv_wr = SRP_RQ_SIZE; 322 init_attr->cap.max_recv_wr = target->queue_size;
254 init_attr->cap.max_recv_sge = 1; 323 init_attr->cap.max_recv_sge = 1;
255 init_attr->cap.max_send_sge = 1; 324 init_attr->cap.max_send_sge = 1;
256 init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; 325 init_attr->sq_sig_type = IB_SIGNAL_ALL_WR;
@@ -296,6 +365,10 @@ err:
296 return ret; 365 return ret;
297} 366}
298 367
368/*
369 * Note: this function may be called without srp_alloc_iu_bufs() having been
370 * invoked. Hence the target->[rt]x_ring checks.
371 */
299static void srp_free_target_ib(struct srp_target_port *target) 372static void srp_free_target_ib(struct srp_target_port *target)
300{ 373{
301 int i; 374 int i;
@@ -307,10 +380,18 @@ static void srp_free_target_ib(struct srp_target_port *target)
307 target->qp = NULL; 380 target->qp = NULL;
308 target->send_cq = target->recv_cq = NULL; 381 target->send_cq = target->recv_cq = NULL;
309 382
310 for (i = 0; i < SRP_RQ_SIZE; ++i) 383 if (target->rx_ring) {
311 srp_free_iu(target->srp_host, target->rx_ring[i]); 384 for (i = 0; i < target->queue_size; ++i)
312 for (i = 0; i < SRP_SQ_SIZE; ++i) 385 srp_free_iu(target->srp_host, target->rx_ring[i]);
313 srp_free_iu(target->srp_host, target->tx_ring[i]); 386 kfree(target->rx_ring);
387 target->rx_ring = NULL;
388 }
389 if (target->tx_ring) {
390 for (i = 0; i < target->queue_size; ++i)
391 srp_free_iu(target->srp_host, target->tx_ring[i]);
392 kfree(target->tx_ring);
393 target->tx_ring = NULL;
394 }
314} 395}
315 396
316static void srp_path_rec_completion(int status, 397static void srp_path_rec_completion(int status,
@@ -390,7 +471,7 @@ static int srp_send_req(struct srp_target_port *target)
390 req->param.responder_resources = 4; 471 req->param.responder_resources = 4;
391 req->param.remote_cm_response_timeout = 20; 472 req->param.remote_cm_response_timeout = 20;
392 req->param.local_cm_response_timeout = 20; 473 req->param.local_cm_response_timeout = 20;
393 req->param.retry_count = 7; 474 req->param.retry_count = target->tl_retry_count;
394 req->param.rnr_retry_count = 7; 475 req->param.rnr_retry_count = 7;
395 req->param.max_cm_retries = 15; 476 req->param.max_cm_retries = 15;
396 477
@@ -496,7 +577,11 @@ static void srp_free_req_data(struct srp_target_port *target)
496 struct srp_request *req; 577 struct srp_request *req;
497 int i; 578 int i;
498 579
499 for (i = 0, req = target->req_ring; i < SRP_CMD_SQ_SIZE; ++i, ++req) { 580 if (!target->req_ring)
581 return;
582
583 for (i = 0; i < target->req_ring_size; ++i) {
584 req = &target->req_ring[i];
500 kfree(req->fmr_list); 585 kfree(req->fmr_list);
501 kfree(req->map_page); 586 kfree(req->map_page);
502 if (req->indirect_dma_addr) { 587 if (req->indirect_dma_addr) {
@@ -506,6 +591,50 @@ static void srp_free_req_data(struct srp_target_port *target)
506 } 591 }
507 kfree(req->indirect_desc); 592 kfree(req->indirect_desc);
508 } 593 }
594
595 kfree(target->req_ring);
596 target->req_ring = NULL;
597}
598
599static int srp_alloc_req_data(struct srp_target_port *target)
600{
601 struct srp_device *srp_dev = target->srp_host->srp_dev;
602 struct ib_device *ibdev = srp_dev->dev;
603 struct srp_request *req;
604 dma_addr_t dma_addr;
605 int i, ret = -ENOMEM;
606
607 INIT_LIST_HEAD(&target->free_reqs);
608
609 target->req_ring = kzalloc(target->req_ring_size *
610 sizeof(*target->req_ring), GFP_KERNEL);
611 if (!target->req_ring)
612 goto out;
613
614 for (i = 0; i < target->req_ring_size; ++i) {
615 req = &target->req_ring[i];
616 req->fmr_list = kmalloc(target->cmd_sg_cnt * sizeof(void *),
617 GFP_KERNEL);
618 req->map_page = kmalloc(SRP_FMR_SIZE * sizeof(void *),
619 GFP_KERNEL);
620 req->indirect_desc = kmalloc(target->indirect_size, GFP_KERNEL);
621 if (!req->fmr_list || !req->map_page || !req->indirect_desc)
622 goto out;
623
624 dma_addr = ib_dma_map_single(ibdev, req->indirect_desc,
625 target->indirect_size,
626 DMA_TO_DEVICE);
627 if (ib_dma_mapping_error(ibdev, dma_addr))
628 goto out;
629
630 req->indirect_dma_addr = dma_addr;
631 req->index = i;
632 list_add_tail(&req->list, &target->free_reqs);
633 }
634 ret = 0;
635
636out:
637 return ret;
509} 638}
510 639
511/** 640/**
@@ -528,12 +657,20 @@ static void srp_remove_target(struct srp_target_port *target)
528 WARN_ON_ONCE(target->state != SRP_TARGET_REMOVED); 657 WARN_ON_ONCE(target->state != SRP_TARGET_REMOVED);
529 658
530 srp_del_scsi_host_attr(target->scsi_host); 659 srp_del_scsi_host_attr(target->scsi_host);
660 srp_rport_get(target->rport);
531 srp_remove_host(target->scsi_host); 661 srp_remove_host(target->scsi_host);
532 scsi_remove_host(target->scsi_host); 662 scsi_remove_host(target->scsi_host);
533 srp_disconnect_target(target); 663 srp_disconnect_target(target);
534 ib_destroy_cm_id(target->cm_id); 664 ib_destroy_cm_id(target->cm_id);
535 srp_free_target_ib(target); 665 srp_free_target_ib(target);
666 cancel_work_sync(&target->tl_err_work);
667 srp_rport_put(target->rport);
536 srp_free_req_data(target); 668 srp_free_req_data(target);
669
670 spin_lock(&target->srp_host->target_lock);
671 list_del(&target->list);
672 spin_unlock(&target->srp_host->target_lock);
673
537 scsi_host_put(target->scsi_host); 674 scsi_host_put(target->scsi_host);
538} 675}
539 676
@@ -545,10 +682,6 @@ static void srp_remove_work(struct work_struct *work)
545 WARN_ON_ONCE(target->state != SRP_TARGET_REMOVED); 682 WARN_ON_ONCE(target->state != SRP_TARGET_REMOVED);
546 683
547 srp_remove_target(target); 684 srp_remove_target(target);
548
549 spin_lock(&target->srp_host->target_lock);
550 list_del(&target->list);
551 spin_unlock(&target->srp_host->target_lock);
552} 685}
553 686
554static void srp_rport_delete(struct srp_rport *rport) 687static void srp_rport_delete(struct srp_rport *rport)
@@ -686,23 +819,42 @@ static void srp_free_req(struct srp_target_port *target,
686 spin_unlock_irqrestore(&target->lock, flags); 819 spin_unlock_irqrestore(&target->lock, flags);
687} 820}
688 821
689static void srp_reset_req(struct srp_target_port *target, struct srp_request *req) 822static void srp_finish_req(struct srp_target_port *target,
823 struct srp_request *req, int result)
690{ 824{
691 struct scsi_cmnd *scmnd = srp_claim_req(target, req, NULL); 825 struct scsi_cmnd *scmnd = srp_claim_req(target, req, NULL);
692 826
693 if (scmnd) { 827 if (scmnd) {
694 srp_free_req(target, req, scmnd, 0); 828 srp_free_req(target, req, scmnd, 0);
695 scmnd->result = DID_RESET << 16; 829 scmnd->result = result;
696 scmnd->scsi_done(scmnd); 830 scmnd->scsi_done(scmnd);
697 } 831 }
698} 832}
699 833
700static int srp_reconnect_target(struct srp_target_port *target) 834static void srp_terminate_io(struct srp_rport *rport)
701{ 835{
702 struct Scsi_Host *shost = target->scsi_host; 836 struct srp_target_port *target = rport->lld_data;
703 int i, ret; 837 int i;
704 838
705 scsi_target_block(&shost->shost_gendev); 839 for (i = 0; i < target->req_ring_size; ++i) {
840 struct srp_request *req = &target->req_ring[i];
841 srp_finish_req(target, req, DID_TRANSPORT_FAILFAST << 16);
842 }
843}
844
845/*
846 * It is up to the caller to ensure that srp_rport_reconnect() calls are
847 * serialized and that no concurrent srp_queuecommand(), srp_abort(),
848 * srp_reset_device() or srp_reset_host() calls will occur while this function
849 * is in progress. One way to realize that is not to call this function
850 * directly but to call srp_reconnect_rport() instead since that last function
851 * serializes calls of this function via rport->mutex and also blocks
852 * srp_queuecommand() calls before invoking this function.
853 */
854static int srp_rport_reconnect(struct srp_rport *rport)
855{
856 struct srp_target_port *target = rport->lld_data;
857 int i, ret;
706 858
707 srp_disconnect_target(target); 859 srp_disconnect_target(target);
708 /* 860 /*
@@ -721,41 +873,21 @@ static int srp_reconnect_target(struct srp_target_port *target)
721 else 873 else
722 srp_create_target_ib(target); 874 srp_create_target_ib(target);
723 875
724 for (i = 0; i < SRP_CMD_SQ_SIZE; ++i) { 876 for (i = 0; i < target->req_ring_size; ++i) {
725 struct srp_request *req = &target->req_ring[i]; 877 struct srp_request *req = &target->req_ring[i];
726 if (req->scmnd) 878 srp_finish_req(target, req, DID_RESET << 16);
727 srp_reset_req(target, req);
728 } 879 }
729 880
730 INIT_LIST_HEAD(&target->free_tx); 881 INIT_LIST_HEAD(&target->free_tx);
731 for (i = 0; i < SRP_SQ_SIZE; ++i) 882 for (i = 0; i < target->queue_size; ++i)
732 list_add(&target->tx_ring[i]->list, &target->free_tx); 883 list_add(&target->tx_ring[i]->list, &target->free_tx);
733 884
734 if (ret == 0) 885 if (ret == 0)
735 ret = srp_connect_target(target); 886 ret = srp_connect_target(target);
736 887
737 scsi_target_unblock(&shost->shost_gendev, ret == 0 ? SDEV_RUNNING : 888 if (ret == 0)
738 SDEV_TRANSPORT_OFFLINE); 889 shost_printk(KERN_INFO, target->scsi_host,
739 target->transport_offline = !!ret; 890 PFX "reconnect succeeded\n");
740
741 if (ret)
742 goto err;
743
744 shost_printk(KERN_INFO, target->scsi_host, PFX "reconnect succeeded\n");
745
746 return ret;
747
748err:
749 shost_printk(KERN_ERR, target->scsi_host,
750 PFX "reconnect failed (%d), removing target port.\n", ret);
751
752 /*
753 * We couldn't reconnect, so kill our target port off.
754 * However, we have to defer the real removal because we
755 * are in the context of the SCSI error handler now, which
756 * will deadlock if we call scsi_remove_host().
757 */
758 srp_queue_remove_work(target);
759 891
760 return ret; 892 return ret;
761} 893}
@@ -1302,15 +1434,30 @@ static void srp_handle_recv(struct srp_target_port *target, struct ib_wc *wc)
1302 PFX "Recv failed with error code %d\n", res); 1434 PFX "Recv failed with error code %d\n", res);
1303} 1435}
1304 1436
1305static void srp_handle_qp_err(enum ib_wc_status wc_status, 1437/**
1306 enum ib_wc_opcode wc_opcode, 1438 * srp_tl_err_work() - handle a transport layer error
1439 *
1440 * Note: This function may get invoked before the rport has been created,
1441 * hence the target->rport test.
1442 */
1443static void srp_tl_err_work(struct work_struct *work)
1444{
1445 struct srp_target_port *target;
1446
1447 target = container_of(work, struct srp_target_port, tl_err_work);
1448 if (target->rport)
1449 srp_start_tl_fail_timers(target->rport);
1450}
1451
1452static void srp_handle_qp_err(enum ib_wc_status wc_status, bool send_err,
1307 struct srp_target_port *target) 1453 struct srp_target_port *target)
1308{ 1454{
1309 if (target->connected && !target->qp_in_error) { 1455 if (target->connected && !target->qp_in_error) {
1310 shost_printk(KERN_ERR, target->scsi_host, 1456 shost_printk(KERN_ERR, target->scsi_host,
1311 PFX "failed %s status %d\n", 1457 PFX "failed %s status %d\n",
1312 wc_opcode & IB_WC_RECV ? "receive" : "send", 1458 send_err ? "send" : "receive",
1313 wc_status); 1459 wc_status);
1460 queue_work(system_long_wq, &target->tl_err_work);
1314 } 1461 }
1315 target->qp_in_error = true; 1462 target->qp_in_error = true;
1316} 1463}
@@ -1325,7 +1472,7 @@ static void srp_recv_completion(struct ib_cq *cq, void *target_ptr)
1325 if (likely(wc.status == IB_WC_SUCCESS)) { 1472 if (likely(wc.status == IB_WC_SUCCESS)) {
1326 srp_handle_recv(target, &wc); 1473 srp_handle_recv(target, &wc);
1327 } else { 1474 } else {
1328 srp_handle_qp_err(wc.status, wc.opcode, target); 1475 srp_handle_qp_err(wc.status, false, target);
1329 } 1476 }
1330 } 1477 }
1331} 1478}
@@ -1341,7 +1488,7 @@ static void srp_send_completion(struct ib_cq *cq, void *target_ptr)
1341 iu = (struct srp_iu *) (uintptr_t) wc.wr_id; 1488 iu = (struct srp_iu *) (uintptr_t) wc.wr_id;
1342 list_add(&iu->list, &target->free_tx); 1489 list_add(&iu->list, &target->free_tx);
1343 } else { 1490 } else {
1344 srp_handle_qp_err(wc.status, wc.opcode, target); 1491 srp_handle_qp_err(wc.status, true, target);
1345 } 1492 }
1346 } 1493 }
1347} 1494}
@@ -1349,17 +1496,29 @@ static void srp_send_completion(struct ib_cq *cq, void *target_ptr)
1349static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd) 1496static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
1350{ 1497{
1351 struct srp_target_port *target = host_to_target(shost); 1498 struct srp_target_port *target = host_to_target(shost);
1499 struct srp_rport *rport = target->rport;
1352 struct srp_request *req; 1500 struct srp_request *req;
1353 struct srp_iu *iu; 1501 struct srp_iu *iu;
1354 struct srp_cmd *cmd; 1502 struct srp_cmd *cmd;
1355 struct ib_device *dev; 1503 struct ib_device *dev;
1356 unsigned long flags; 1504 unsigned long flags;
1357 int len; 1505 int len, result;
1506 const bool in_scsi_eh = !in_interrupt() && current == shost->ehandler;
1507
1508 /*
1509 * The SCSI EH thread is the only context from which srp_queuecommand()
1510 * can get invoked for blocked devices (SDEV_BLOCK /
1511 * SDEV_CREATED_BLOCK). Avoid racing with srp_reconnect_rport() by
1512 * locking the rport mutex if invoked from inside the SCSI EH.
1513 */
1514 if (in_scsi_eh)
1515 mutex_lock(&rport->mutex);
1358 1516
1359 if (unlikely(target->transport_offline)) { 1517 result = srp_chkready(target->rport);
1360 scmnd->result = DID_NO_CONNECT << 16; 1518 if (unlikely(result)) {
1519 scmnd->result = result;
1361 scmnd->scsi_done(scmnd); 1520 scmnd->scsi_done(scmnd);
1362 return 0; 1521 goto unlock_rport;
1363 } 1522 }
1364 1523
1365 spin_lock_irqsave(&target->lock, flags); 1524 spin_lock_irqsave(&target->lock, flags);
@@ -1404,6 +1563,10 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
1404 goto err_unmap; 1563 goto err_unmap;
1405 } 1564 }
1406 1565
1566unlock_rport:
1567 if (in_scsi_eh)
1568 mutex_unlock(&rport->mutex);
1569
1407 return 0; 1570 return 0;
1408 1571
1409err_unmap: 1572err_unmap:
@@ -1418,14 +1581,30 @@ err_iu:
1418err_unlock: 1581err_unlock:
1419 spin_unlock_irqrestore(&target->lock, flags); 1582 spin_unlock_irqrestore(&target->lock, flags);
1420 1583
1584 if (in_scsi_eh)
1585 mutex_unlock(&rport->mutex);
1586
1421 return SCSI_MLQUEUE_HOST_BUSY; 1587 return SCSI_MLQUEUE_HOST_BUSY;
1422} 1588}
1423 1589
1590/*
1591 * Note: the resources allocated in this function are freed in
1592 * srp_free_target_ib().
1593 */
1424static int srp_alloc_iu_bufs(struct srp_target_port *target) 1594static int srp_alloc_iu_bufs(struct srp_target_port *target)
1425{ 1595{
1426 int i; 1596 int i;
1427 1597
1428 for (i = 0; i < SRP_RQ_SIZE; ++i) { 1598 target->rx_ring = kzalloc(target->queue_size * sizeof(*target->rx_ring),
1599 GFP_KERNEL);
1600 if (!target->rx_ring)
1601 goto err_no_ring;
1602 target->tx_ring = kzalloc(target->queue_size * sizeof(*target->tx_ring),
1603 GFP_KERNEL);
1604 if (!target->tx_ring)
1605 goto err_no_ring;
1606
1607 for (i = 0; i < target->queue_size; ++i) {
1429 target->rx_ring[i] = srp_alloc_iu(target->srp_host, 1608 target->rx_ring[i] = srp_alloc_iu(target->srp_host,
1430 target->max_ti_iu_len, 1609 target->max_ti_iu_len,
1431 GFP_KERNEL, DMA_FROM_DEVICE); 1610 GFP_KERNEL, DMA_FROM_DEVICE);
@@ -1433,7 +1612,7 @@ static int srp_alloc_iu_bufs(struct srp_target_port *target)
1433 goto err; 1612 goto err;
1434 } 1613 }
1435 1614
1436 for (i = 0; i < SRP_SQ_SIZE; ++i) { 1615 for (i = 0; i < target->queue_size; ++i) {
1437 target->tx_ring[i] = srp_alloc_iu(target->srp_host, 1616 target->tx_ring[i] = srp_alloc_iu(target->srp_host,
1438 target->max_iu_len, 1617 target->max_iu_len,
1439 GFP_KERNEL, DMA_TO_DEVICE); 1618 GFP_KERNEL, DMA_TO_DEVICE);
@@ -1446,16 +1625,18 @@ static int srp_alloc_iu_bufs(struct srp_target_port *target)
1446 return 0; 1625 return 0;
1447 1626
1448err: 1627err:
1449 for (i = 0; i < SRP_RQ_SIZE; ++i) { 1628 for (i = 0; i < target->queue_size; ++i) {
1450 srp_free_iu(target->srp_host, target->rx_ring[i]); 1629 srp_free_iu(target->srp_host, target->rx_ring[i]);
1451 target->rx_ring[i] = NULL;
1452 }
1453
1454 for (i = 0; i < SRP_SQ_SIZE; ++i) {
1455 srp_free_iu(target->srp_host, target->tx_ring[i]); 1630 srp_free_iu(target->srp_host, target->tx_ring[i]);
1456 target->tx_ring[i] = NULL;
1457 } 1631 }
1458 1632
1633
1634err_no_ring:
1635 kfree(target->tx_ring);
1636 target->tx_ring = NULL;
1637 kfree(target->rx_ring);
1638 target->rx_ring = NULL;
1639
1459 return -ENOMEM; 1640 return -ENOMEM;
1460} 1641}
1461 1642
@@ -1506,6 +1687,9 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
1506 target->scsi_host->can_queue 1687 target->scsi_host->can_queue
1507 = min(target->req_lim - SRP_TSK_MGMT_SQ_SIZE, 1688 = min(target->req_lim - SRP_TSK_MGMT_SQ_SIZE,
1508 target->scsi_host->can_queue); 1689 target->scsi_host->can_queue);
1690 target->scsi_host->cmd_per_lun
1691 = min_t(int, target->scsi_host->can_queue,
1692 target->scsi_host->cmd_per_lun);
1509 } else { 1693 } else {
1510 shost_printk(KERN_WARNING, target->scsi_host, 1694 shost_printk(KERN_WARNING, target->scsi_host,
1511 PFX "Unhandled RSP opcode %#x\n", lrsp->opcode); 1695 PFX "Unhandled RSP opcode %#x\n", lrsp->opcode);
@@ -1513,7 +1697,7 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
1513 goto error; 1697 goto error;
1514 } 1698 }
1515 1699
1516 if (!target->rx_ring[0]) { 1700 if (!target->rx_ring) {
1517 ret = srp_alloc_iu_bufs(target); 1701 ret = srp_alloc_iu_bufs(target);
1518 if (ret) 1702 if (ret)
1519 goto error; 1703 goto error;
@@ -1533,7 +1717,7 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
1533 if (ret) 1717 if (ret)
1534 goto error_free; 1718 goto error_free;
1535 1719
1536 for (i = 0; i < SRP_RQ_SIZE; i++) { 1720 for (i = 0; i < target->queue_size; i++) {
1537 struct srp_iu *iu = target->rx_ring[i]; 1721 struct srp_iu *iu = target->rx_ring[i];
1538 ret = srp_post_recv(target, iu); 1722 ret = srp_post_recv(target, iu);
1539 if (ret) 1723 if (ret)
@@ -1672,6 +1856,7 @@ static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
1672 if (ib_send_cm_drep(cm_id, NULL, 0)) 1856 if (ib_send_cm_drep(cm_id, NULL, 0))
1673 shost_printk(KERN_ERR, target->scsi_host, 1857 shost_printk(KERN_ERR, target->scsi_host,
1674 PFX "Sending CM DREP failed\n"); 1858 PFX "Sending CM DREP failed\n");
1859 queue_work(system_long_wq, &target->tl_err_work);
1675 break; 1860 break;
1676 1861
1677 case IB_CM_TIMEWAIT_EXIT: 1862 case IB_CM_TIMEWAIT_EXIT:
@@ -1698,9 +1883,61 @@ static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
1698 return 0; 1883 return 0;
1699} 1884}
1700 1885
1886/**
1887 * srp_change_queue_type - changing device queue tag type
1888 * @sdev: scsi device struct
1889 * @tag_type: requested tag type
1890 *
1891 * Returns queue tag type.
1892 */
1893static int
1894srp_change_queue_type(struct scsi_device *sdev, int tag_type)
1895{
1896 if (sdev->tagged_supported) {
1897 scsi_set_tag_type(sdev, tag_type);
1898 if (tag_type)
1899 scsi_activate_tcq(sdev, sdev->queue_depth);
1900 else
1901 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1902 } else
1903 tag_type = 0;
1904
1905 return tag_type;
1906}
1907
1908/**
1909 * srp_change_queue_depth - setting device queue depth
1910 * @sdev: scsi device struct
1911 * @qdepth: requested queue depth
1912 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1913 * (see include/scsi/scsi_host.h for definition)
1914 *
1915 * Returns queue depth.
1916 */
1917static int
1918srp_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1919{
1920 struct Scsi_Host *shost = sdev->host;
1921 int max_depth;
1922 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP) {
1923 max_depth = shost->can_queue;
1924 if (!sdev->tagged_supported)
1925 max_depth = 1;
1926 if (qdepth > max_depth)
1927 qdepth = max_depth;
1928 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1929 } else if (reason == SCSI_QDEPTH_QFULL)
1930 scsi_track_queue_full(sdev, qdepth);
1931 else
1932 return -EOPNOTSUPP;
1933
1934 return sdev->queue_depth;
1935}
1936
1701static int srp_send_tsk_mgmt(struct srp_target_port *target, 1937static int srp_send_tsk_mgmt(struct srp_target_port *target,
1702 u64 req_tag, unsigned int lun, u8 func) 1938 u64 req_tag, unsigned int lun, u8 func)
1703{ 1939{
1940 struct srp_rport *rport = target->rport;
1704 struct ib_device *dev = target->srp_host->srp_dev->dev; 1941 struct ib_device *dev = target->srp_host->srp_dev->dev;
1705 struct srp_iu *iu; 1942 struct srp_iu *iu;
1706 struct srp_tsk_mgmt *tsk_mgmt; 1943 struct srp_tsk_mgmt *tsk_mgmt;
@@ -1710,12 +1947,20 @@ static int srp_send_tsk_mgmt(struct srp_target_port *target,
1710 1947
1711 init_completion(&target->tsk_mgmt_done); 1948 init_completion(&target->tsk_mgmt_done);
1712 1949
1950 /*
1951 * Lock the rport mutex to avoid that srp_create_target_ib() is
1952 * invoked while a task management function is being sent.
1953 */
1954 mutex_lock(&rport->mutex);
1713 spin_lock_irq(&target->lock); 1955 spin_lock_irq(&target->lock);
1714 iu = __srp_get_tx_iu(target, SRP_IU_TSK_MGMT); 1956 iu = __srp_get_tx_iu(target, SRP_IU_TSK_MGMT);
1715 spin_unlock_irq(&target->lock); 1957 spin_unlock_irq(&target->lock);
1716 1958
1717 if (!iu) 1959 if (!iu) {
1960 mutex_unlock(&rport->mutex);
1961
1718 return -1; 1962 return -1;
1963 }
1719 1964
1720 ib_dma_sync_single_for_cpu(dev, iu->dma, sizeof *tsk_mgmt, 1965 ib_dma_sync_single_for_cpu(dev, iu->dma, sizeof *tsk_mgmt,
1721 DMA_TO_DEVICE); 1966 DMA_TO_DEVICE);
@@ -1732,8 +1977,11 @@ static int srp_send_tsk_mgmt(struct srp_target_port *target,
1732 DMA_TO_DEVICE); 1977 DMA_TO_DEVICE);
1733 if (srp_post_send(target, iu, sizeof *tsk_mgmt)) { 1978 if (srp_post_send(target, iu, sizeof *tsk_mgmt)) {
1734 srp_put_tx_iu(target, iu, SRP_IU_TSK_MGMT); 1979 srp_put_tx_iu(target, iu, SRP_IU_TSK_MGMT);
1980 mutex_unlock(&rport->mutex);
1981
1735 return -1; 1982 return -1;
1736 } 1983 }
1984 mutex_unlock(&rport->mutex);
1737 1985
1738 if (!wait_for_completion_timeout(&target->tsk_mgmt_done, 1986 if (!wait_for_completion_timeout(&target->tsk_mgmt_done,
1739 msecs_to_jiffies(SRP_ABORT_TIMEOUT_MS))) 1987 msecs_to_jiffies(SRP_ABORT_TIMEOUT_MS)))
@@ -1751,11 +1999,11 @@ static int srp_abort(struct scsi_cmnd *scmnd)
1751 shost_printk(KERN_ERR, target->scsi_host, "SRP abort called\n"); 1999 shost_printk(KERN_ERR, target->scsi_host, "SRP abort called\n");
1752 2000
1753 if (!req || !srp_claim_req(target, req, scmnd)) 2001 if (!req || !srp_claim_req(target, req, scmnd))
1754 return FAILED; 2002 return SUCCESS;
1755 if (srp_send_tsk_mgmt(target, req->index, scmnd->device->lun, 2003 if (srp_send_tsk_mgmt(target, req->index, scmnd->device->lun,
1756 SRP_TSK_ABORT_TASK) == 0) 2004 SRP_TSK_ABORT_TASK) == 0)
1757 ret = SUCCESS; 2005 ret = SUCCESS;
1758 else if (target->transport_offline) 2006 else if (target->rport->state == SRP_RPORT_LOST)
1759 ret = FAST_IO_FAIL; 2007 ret = FAST_IO_FAIL;
1760 else 2008 else
1761 ret = FAILED; 2009 ret = FAILED;
@@ -1779,10 +2027,10 @@ static int srp_reset_device(struct scsi_cmnd *scmnd)
1779 if (target->tsk_mgmt_status) 2027 if (target->tsk_mgmt_status)
1780 return FAILED; 2028 return FAILED;
1781 2029
1782 for (i = 0; i < SRP_CMD_SQ_SIZE; ++i) { 2030 for (i = 0; i < target->req_ring_size; ++i) {
1783 struct srp_request *req = &target->req_ring[i]; 2031 struct srp_request *req = &target->req_ring[i];
1784 if (req->scmnd && req->scmnd->device == scmnd->device) 2032 if (req->scmnd && req->scmnd->device == scmnd->device)
1785 srp_reset_req(target, req); 2033 srp_finish_req(target, req, DID_RESET << 16);
1786 } 2034 }
1787 2035
1788 return SUCCESS; 2036 return SUCCESS;
@@ -1791,14 +2039,10 @@ static int srp_reset_device(struct scsi_cmnd *scmnd)
1791static int srp_reset_host(struct scsi_cmnd *scmnd) 2039static int srp_reset_host(struct scsi_cmnd *scmnd)
1792{ 2040{
1793 struct srp_target_port *target = host_to_target(scmnd->device->host); 2041 struct srp_target_port *target = host_to_target(scmnd->device->host);
1794 int ret = FAILED;
1795 2042
1796 shost_printk(KERN_ERR, target->scsi_host, PFX "SRP reset_host called\n"); 2043 shost_printk(KERN_ERR, target->scsi_host, PFX "SRP reset_host called\n");
1797 2044
1798 if (!srp_reconnect_target(target)) 2045 return srp_reconnect_rport(target->rport) == 0 ? SUCCESS : FAILED;
1799 ret = SUCCESS;
1800
1801 return ret;
1802} 2046}
1803 2047
1804static int srp_slave_configure(struct scsi_device *sdev) 2048static int srp_slave_configure(struct scsi_device *sdev)
@@ -1851,6 +2095,14 @@ static ssize_t show_pkey(struct device *dev, struct device_attribute *attr,
1851 return sprintf(buf, "0x%04x\n", be16_to_cpu(target->path.pkey)); 2095 return sprintf(buf, "0x%04x\n", be16_to_cpu(target->path.pkey));
1852} 2096}
1853 2097
2098static ssize_t show_sgid(struct device *dev, struct device_attribute *attr,
2099 char *buf)
2100{
2101 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2102
2103 return sprintf(buf, "%pI6\n", target->path.sgid.raw);
2104}
2105
1854static ssize_t show_dgid(struct device *dev, struct device_attribute *attr, 2106static ssize_t show_dgid(struct device *dev, struct device_attribute *attr,
1855 char *buf) 2107 char *buf)
1856{ 2108{
@@ -1907,6 +2159,14 @@ static ssize_t show_comp_vector(struct device *dev,
1907 return sprintf(buf, "%d\n", target->comp_vector); 2159 return sprintf(buf, "%d\n", target->comp_vector);
1908} 2160}
1909 2161
2162static ssize_t show_tl_retry_count(struct device *dev,
2163 struct device_attribute *attr, char *buf)
2164{
2165 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2166
2167 return sprintf(buf, "%d\n", target->tl_retry_count);
2168}
2169
1910static ssize_t show_cmd_sg_entries(struct device *dev, 2170static ssize_t show_cmd_sg_entries(struct device *dev,
1911 struct device_attribute *attr, char *buf) 2171 struct device_attribute *attr, char *buf)
1912{ 2172{
@@ -1927,6 +2187,7 @@ static DEVICE_ATTR(id_ext, S_IRUGO, show_id_ext, NULL);
1927static DEVICE_ATTR(ioc_guid, S_IRUGO, show_ioc_guid, NULL); 2187static DEVICE_ATTR(ioc_guid, S_IRUGO, show_ioc_guid, NULL);
1928static DEVICE_ATTR(service_id, S_IRUGO, show_service_id, NULL); 2188static DEVICE_ATTR(service_id, S_IRUGO, show_service_id, NULL);
1929static DEVICE_ATTR(pkey, S_IRUGO, show_pkey, NULL); 2189static DEVICE_ATTR(pkey, S_IRUGO, show_pkey, NULL);
2190static DEVICE_ATTR(sgid, S_IRUGO, show_sgid, NULL);
1930static DEVICE_ATTR(dgid, S_IRUGO, show_dgid, NULL); 2191static DEVICE_ATTR(dgid, S_IRUGO, show_dgid, NULL);
1931static DEVICE_ATTR(orig_dgid, S_IRUGO, show_orig_dgid, NULL); 2192static DEVICE_ATTR(orig_dgid, S_IRUGO, show_orig_dgid, NULL);
1932static DEVICE_ATTR(req_lim, S_IRUGO, show_req_lim, NULL); 2193static DEVICE_ATTR(req_lim, S_IRUGO, show_req_lim, NULL);
@@ -1934,6 +2195,7 @@ static DEVICE_ATTR(zero_req_lim, S_IRUGO, show_zero_req_lim, NULL);
1934static DEVICE_ATTR(local_ib_port, S_IRUGO, show_local_ib_port, NULL); 2195static DEVICE_ATTR(local_ib_port, S_IRUGO, show_local_ib_port, NULL);
1935static DEVICE_ATTR(local_ib_device, S_IRUGO, show_local_ib_device, NULL); 2196static DEVICE_ATTR(local_ib_device, S_IRUGO, show_local_ib_device, NULL);
1936static DEVICE_ATTR(comp_vector, S_IRUGO, show_comp_vector, NULL); 2197static DEVICE_ATTR(comp_vector, S_IRUGO, show_comp_vector, NULL);
2198static DEVICE_ATTR(tl_retry_count, S_IRUGO, show_tl_retry_count, NULL);
1937static DEVICE_ATTR(cmd_sg_entries, S_IRUGO, show_cmd_sg_entries, NULL); 2199static DEVICE_ATTR(cmd_sg_entries, S_IRUGO, show_cmd_sg_entries, NULL);
1938static DEVICE_ATTR(allow_ext_sg, S_IRUGO, show_allow_ext_sg, NULL); 2200static DEVICE_ATTR(allow_ext_sg, S_IRUGO, show_allow_ext_sg, NULL);
1939 2201
@@ -1942,6 +2204,7 @@ static struct device_attribute *srp_host_attrs[] = {
1942 &dev_attr_ioc_guid, 2204 &dev_attr_ioc_guid,
1943 &dev_attr_service_id, 2205 &dev_attr_service_id,
1944 &dev_attr_pkey, 2206 &dev_attr_pkey,
2207 &dev_attr_sgid,
1945 &dev_attr_dgid, 2208 &dev_attr_dgid,
1946 &dev_attr_orig_dgid, 2209 &dev_attr_orig_dgid,
1947 &dev_attr_req_lim, 2210 &dev_attr_req_lim,
@@ -1949,6 +2212,7 @@ static struct device_attribute *srp_host_attrs[] = {
1949 &dev_attr_local_ib_port, 2212 &dev_attr_local_ib_port,
1950 &dev_attr_local_ib_device, 2213 &dev_attr_local_ib_device,
1951 &dev_attr_comp_vector, 2214 &dev_attr_comp_vector,
2215 &dev_attr_tl_retry_count,
1952 &dev_attr_cmd_sg_entries, 2216 &dev_attr_cmd_sg_entries,
1953 &dev_attr_allow_ext_sg, 2217 &dev_attr_allow_ext_sg,
1954 NULL 2218 NULL
@@ -1961,14 +2225,16 @@ static struct scsi_host_template srp_template = {
1961 .slave_configure = srp_slave_configure, 2225 .slave_configure = srp_slave_configure,
1962 .info = srp_target_info, 2226 .info = srp_target_info,
1963 .queuecommand = srp_queuecommand, 2227 .queuecommand = srp_queuecommand,
2228 .change_queue_depth = srp_change_queue_depth,
2229 .change_queue_type = srp_change_queue_type,
1964 .eh_abort_handler = srp_abort, 2230 .eh_abort_handler = srp_abort,
1965 .eh_device_reset_handler = srp_reset_device, 2231 .eh_device_reset_handler = srp_reset_device,
1966 .eh_host_reset_handler = srp_reset_host, 2232 .eh_host_reset_handler = srp_reset_host,
1967 .skip_settle_delay = true, 2233 .skip_settle_delay = true,
1968 .sg_tablesize = SRP_DEF_SG_TABLESIZE, 2234 .sg_tablesize = SRP_DEF_SG_TABLESIZE,
1969 .can_queue = SRP_CMD_SQ_SIZE, 2235 .can_queue = SRP_DEFAULT_CMD_SQ_SIZE,
1970 .this_id = -1, 2236 .this_id = -1,
1971 .cmd_per_lun = SRP_CMD_SQ_SIZE, 2237 .cmd_per_lun = SRP_DEFAULT_CMD_SQ_SIZE,
1972 .use_clustering = ENABLE_CLUSTERING, 2238 .use_clustering = ENABLE_CLUSTERING,
1973 .shost_attrs = srp_host_attrs 2239 .shost_attrs = srp_host_attrs
1974}; 2240};
@@ -1994,6 +2260,7 @@ static int srp_add_target(struct srp_host *host, struct srp_target_port *target)
1994 } 2260 }
1995 2261
1996 rport->lld_data = target; 2262 rport->lld_data = target;
2263 target->rport = rport;
1997 2264
1998 spin_lock(&host->target_lock); 2265 spin_lock(&host->target_lock);
1999 list_add_tail(&target->list, &host->target_list); 2266 list_add_tail(&target->list, &host->target_list);
@@ -2073,6 +2340,8 @@ enum {
2073 SRP_OPT_ALLOW_EXT_SG = 1 << 10, 2340 SRP_OPT_ALLOW_EXT_SG = 1 << 10,
2074 SRP_OPT_SG_TABLESIZE = 1 << 11, 2341 SRP_OPT_SG_TABLESIZE = 1 << 11,
2075 SRP_OPT_COMP_VECTOR = 1 << 12, 2342 SRP_OPT_COMP_VECTOR = 1 << 12,
2343 SRP_OPT_TL_RETRY_COUNT = 1 << 13,
2344 SRP_OPT_QUEUE_SIZE = 1 << 14,
2076 SRP_OPT_ALL = (SRP_OPT_ID_EXT | 2345 SRP_OPT_ALL = (SRP_OPT_ID_EXT |
2077 SRP_OPT_IOC_GUID | 2346 SRP_OPT_IOC_GUID |
2078 SRP_OPT_DGID | 2347 SRP_OPT_DGID |
@@ -2094,6 +2363,8 @@ static const match_table_t srp_opt_tokens = {
2094 { SRP_OPT_ALLOW_EXT_SG, "allow_ext_sg=%u" }, 2363 { SRP_OPT_ALLOW_EXT_SG, "allow_ext_sg=%u" },
2095 { SRP_OPT_SG_TABLESIZE, "sg_tablesize=%u" }, 2364 { SRP_OPT_SG_TABLESIZE, "sg_tablesize=%u" },
2096 { SRP_OPT_COMP_VECTOR, "comp_vector=%u" }, 2365 { SRP_OPT_COMP_VECTOR, "comp_vector=%u" },
2366 { SRP_OPT_TL_RETRY_COUNT, "tl_retry_count=%u" },
2367 { SRP_OPT_QUEUE_SIZE, "queue_size=%d" },
2097 { SRP_OPT_ERR, NULL } 2368 { SRP_OPT_ERR, NULL }
2098}; 2369};
2099 2370
@@ -2188,13 +2459,25 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
2188 target->scsi_host->max_sectors = token; 2459 target->scsi_host->max_sectors = token;
2189 break; 2460 break;
2190 2461
2462 case SRP_OPT_QUEUE_SIZE:
2463 if (match_int(args, &token) || token < 1) {
2464 pr_warn("bad queue_size parameter '%s'\n", p);
2465 goto out;
2466 }
2467 target->scsi_host->can_queue = token;
2468 target->queue_size = token + SRP_RSP_SQ_SIZE +
2469 SRP_TSK_MGMT_SQ_SIZE;
2470 if (!(opt_mask & SRP_OPT_MAX_CMD_PER_LUN))
2471 target->scsi_host->cmd_per_lun = token;
2472 break;
2473
2191 case SRP_OPT_MAX_CMD_PER_LUN: 2474 case SRP_OPT_MAX_CMD_PER_LUN:
2192 if (match_int(args, &token)) { 2475 if (match_int(args, &token) || token < 1) {
2193 pr_warn("bad max cmd_per_lun parameter '%s'\n", 2476 pr_warn("bad max cmd_per_lun parameter '%s'\n",
2194 p); 2477 p);
2195 goto out; 2478 goto out;
2196 } 2479 }
2197 target->scsi_host->cmd_per_lun = min(token, SRP_CMD_SQ_SIZE); 2480 target->scsi_host->cmd_per_lun = token;
2198 break; 2481 break;
2199 2482
2200 case SRP_OPT_IO_CLASS: 2483 case SRP_OPT_IO_CLASS:
@@ -2257,6 +2540,15 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
2257 target->comp_vector = token; 2540 target->comp_vector = token;
2258 break; 2541 break;
2259 2542
2543 case SRP_OPT_TL_RETRY_COUNT:
2544 if (match_int(args, &token) || token < 2 || token > 7) {
2545 pr_warn("bad tl_retry_count parameter '%s' (must be a number between 2 and 7)\n",
2546 p);
2547 goto out;
2548 }
2549 target->tl_retry_count = token;
2550 break;
2551
2260 default: 2552 default:
2261 pr_warn("unknown parameter or missing value '%s' in target creation request\n", 2553 pr_warn("unknown parameter or missing value '%s' in target creation request\n",
2262 p); 2554 p);
@@ -2273,6 +2565,12 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
2273 pr_warn("target creation request is missing parameter '%s'\n", 2565 pr_warn("target creation request is missing parameter '%s'\n",
2274 srp_opt_tokens[i].pattern); 2566 srp_opt_tokens[i].pattern);
2275 2567
2568 if (target->scsi_host->cmd_per_lun > target->scsi_host->can_queue
2569 && (opt_mask & SRP_OPT_MAX_CMD_PER_LUN))
2570 pr_warn("cmd_per_lun = %d > queue_size = %d\n",
2571 target->scsi_host->cmd_per_lun,
2572 target->scsi_host->can_queue);
2573
2276out: 2574out:
2277 kfree(options); 2575 kfree(options);
2278 return ret; 2576 return ret;
@@ -2287,8 +2585,7 @@ static ssize_t srp_create_target(struct device *dev,
2287 struct Scsi_Host *target_host; 2585 struct Scsi_Host *target_host;
2288 struct srp_target_port *target; 2586 struct srp_target_port *target;
2289 struct ib_device *ibdev = host->srp_dev->dev; 2587 struct ib_device *ibdev = host->srp_dev->dev;
2290 dma_addr_t dma_addr; 2588 int ret;
2291 int i, ret;
2292 2589
2293 target_host = scsi_host_alloc(&srp_template, 2590 target_host = scsi_host_alloc(&srp_template,
2294 sizeof (struct srp_target_port)); 2591 sizeof (struct srp_target_port));
@@ -2311,11 +2608,15 @@ static ssize_t srp_create_target(struct device *dev,
2311 target->cmd_sg_cnt = cmd_sg_entries; 2608 target->cmd_sg_cnt = cmd_sg_entries;
2312 target->sg_tablesize = indirect_sg_entries ? : cmd_sg_entries; 2609 target->sg_tablesize = indirect_sg_entries ? : cmd_sg_entries;
2313 target->allow_ext_sg = allow_ext_sg; 2610 target->allow_ext_sg = allow_ext_sg;
2611 target->tl_retry_count = 7;
2612 target->queue_size = SRP_DEFAULT_QUEUE_SIZE;
2314 2613
2315 ret = srp_parse_options(buf, target); 2614 ret = srp_parse_options(buf, target);
2316 if (ret) 2615 if (ret)
2317 goto err; 2616 goto err;
2318 2617
2618 target->req_ring_size = target->queue_size - SRP_TSK_MGMT_SQ_SIZE;
2619
2319 if (!srp_conn_unique(target->srp_host, target)) { 2620 if (!srp_conn_unique(target->srp_host, target)) {
2320 shost_printk(KERN_INFO, target->scsi_host, 2621 shost_printk(KERN_INFO, target->scsi_host,
2321 PFX "Already connected to target port with id_ext=%016llx;ioc_guid=%016llx;initiator_ext=%016llx\n", 2622 PFX "Already connected to target port with id_ext=%016llx;ioc_guid=%016llx;initiator_ext=%016llx\n",
@@ -2339,31 +2640,13 @@ static ssize_t srp_create_target(struct device *dev,
2339 sizeof (struct srp_indirect_buf) + 2640 sizeof (struct srp_indirect_buf) +
2340 target->cmd_sg_cnt * sizeof (struct srp_direct_buf); 2641 target->cmd_sg_cnt * sizeof (struct srp_direct_buf);
2341 2642
2643 INIT_WORK(&target->tl_err_work, srp_tl_err_work);
2342 INIT_WORK(&target->remove_work, srp_remove_work); 2644 INIT_WORK(&target->remove_work, srp_remove_work);
2343 spin_lock_init(&target->lock); 2645 spin_lock_init(&target->lock);
2344 INIT_LIST_HEAD(&target->free_tx); 2646 INIT_LIST_HEAD(&target->free_tx);
2345 INIT_LIST_HEAD(&target->free_reqs); 2647 ret = srp_alloc_req_data(target);
2346 for (i = 0; i < SRP_CMD_SQ_SIZE; ++i) { 2648 if (ret)
2347 struct srp_request *req = &target->req_ring[i]; 2649 goto err_free_mem;
2348
2349 req->fmr_list = kmalloc(target->cmd_sg_cnt * sizeof (void *),
2350 GFP_KERNEL);
2351 req->map_page = kmalloc(SRP_FMR_SIZE * sizeof (void *),
2352 GFP_KERNEL);
2353 req->indirect_desc = kmalloc(target->indirect_size, GFP_KERNEL);
2354 if (!req->fmr_list || !req->map_page || !req->indirect_desc)
2355 goto err_free_mem;
2356
2357 dma_addr = ib_dma_map_single(ibdev, req->indirect_desc,
2358 target->indirect_size,
2359 DMA_TO_DEVICE);
2360 if (ib_dma_mapping_error(ibdev, dma_addr))
2361 goto err_free_mem;
2362
2363 req->indirect_dma_addr = dma_addr;
2364 req->index = i;
2365 list_add_tail(&req->list, &target->free_reqs);
2366 }
2367 2650
2368 ib_query_gid(ibdev, host->port, 0, &target->path.sgid); 2651 ib_query_gid(ibdev, host->port, 0, &target->path.sgid);
2369 2652
@@ -2612,7 +2895,14 @@ static void srp_remove_one(struct ib_device *device)
2612} 2895}
2613 2896
2614static struct srp_function_template ib_srp_transport_functions = { 2897static struct srp_function_template ib_srp_transport_functions = {
2898 .has_rport_state = true,
2899 .reset_timer_if_blocked = true,
2900 .reconnect_delay = &srp_reconnect_delay,
2901 .fast_io_fail_tmo = &srp_fast_io_fail_tmo,
2902 .dev_loss_tmo = &srp_dev_loss_tmo,
2903 .reconnect = srp_rport_reconnect,
2615 .rport_delete = srp_rport_delete, 2904 .rport_delete = srp_rport_delete,
2905 .terminate_rport_io = srp_terminate_io,
2616}; 2906};
2617 2907
2618static int __init srp_init_module(void) 2908static int __init srp_init_module(void)
diff --git a/drivers/infiniband/ulp/srp/ib_srp.h b/drivers/infiniband/ulp/srp/ib_srp.h
index e641088c14dc..575681063f38 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.h
+++ b/drivers/infiniband/ulp/srp/ib_srp.h
@@ -57,14 +57,11 @@ enum {
57 SRP_MAX_LUN = 512, 57 SRP_MAX_LUN = 512,
58 SRP_DEF_SG_TABLESIZE = 12, 58 SRP_DEF_SG_TABLESIZE = 12,
59 59
60 SRP_RQ_SHIFT = 6, 60 SRP_DEFAULT_QUEUE_SIZE = 1 << 6,
61 SRP_RQ_SIZE = 1 << SRP_RQ_SHIFT,
62
63 SRP_SQ_SIZE = SRP_RQ_SIZE,
64 SRP_RSP_SQ_SIZE = 1, 61 SRP_RSP_SQ_SIZE = 1,
65 SRP_REQ_SQ_SIZE = SRP_SQ_SIZE - SRP_RSP_SQ_SIZE,
66 SRP_TSK_MGMT_SQ_SIZE = 1, 62 SRP_TSK_MGMT_SQ_SIZE = 1,
67 SRP_CMD_SQ_SIZE = SRP_REQ_SQ_SIZE - SRP_TSK_MGMT_SQ_SIZE, 63 SRP_DEFAULT_CMD_SQ_SIZE = SRP_DEFAULT_QUEUE_SIZE - SRP_RSP_SQ_SIZE -
64 SRP_TSK_MGMT_SQ_SIZE,
68 65
69 SRP_TAG_NO_REQ = ~0U, 66 SRP_TAG_NO_REQ = ~0U,
70 SRP_TAG_TSK_MGMT = 1U << 31, 67 SRP_TAG_TSK_MGMT = 1U << 31,
@@ -140,7 +137,6 @@ struct srp_target_port {
140 unsigned int cmd_sg_cnt; 137 unsigned int cmd_sg_cnt;
141 unsigned int indirect_size; 138 unsigned int indirect_size;
142 bool allow_ext_sg; 139 bool allow_ext_sg;
143 bool transport_offline;
144 140
145 /* Everything above this point is used in the hot path of 141 /* Everything above this point is used in the hot path of
146 * command processing. Try to keep them packed into cachelines. 142 * command processing. Try to keep them packed into cachelines.
@@ -153,10 +149,14 @@ struct srp_target_port {
153 u16 io_class; 149 u16 io_class;
154 struct srp_host *srp_host; 150 struct srp_host *srp_host;
155 struct Scsi_Host *scsi_host; 151 struct Scsi_Host *scsi_host;
152 struct srp_rport *rport;
156 char target_name[32]; 153 char target_name[32];
157 unsigned int scsi_id; 154 unsigned int scsi_id;
158 unsigned int sg_tablesize; 155 unsigned int sg_tablesize;
156 int queue_size;
157 int req_ring_size;
159 int comp_vector; 158 int comp_vector;
159 int tl_retry_count;
160 160
161 struct ib_sa_path_rec path; 161 struct ib_sa_path_rec path;
162 __be16 orig_dgid[8]; 162 __be16 orig_dgid[8];
@@ -172,10 +172,11 @@ struct srp_target_port {
172 172
173 int zero_req_lim; 173 int zero_req_lim;
174 174
175 struct srp_iu *tx_ring[SRP_SQ_SIZE]; 175 struct srp_iu **tx_ring;
176 struct srp_iu *rx_ring[SRP_RQ_SIZE]; 176 struct srp_iu **rx_ring;
177 struct srp_request req_ring[SRP_CMD_SQ_SIZE]; 177 struct srp_request *req_ring;
178 178
179 struct work_struct tl_err_work;
179 struct work_struct remove_work; 180 struct work_struct remove_work;
180 181
181 struct list_head list; 182 struct list_head list;
diff --git a/drivers/media/common/b2c2/flexcop-sram.c b/drivers/media/common/b2c2/flexcop-sram.c
index f2199e43e803..185c285f70fc 100644
--- a/drivers/media/common/b2c2/flexcop-sram.c
+++ b/drivers/media/common/b2c2/flexcop-sram.c
@@ -85,7 +85,7 @@ static void flexcop_sram_write(struct adapter *adapter, u32 bank, u32 addr, u8 *
85 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) { 85 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
86 mdelay(1); 86 mdelay(1);
87 retries--; 87 retries--;
88 }; 88 }
89 89
90 if (retries == 0) 90 if (retries == 0)
91 printk("%s: SRAM timeout\n", __func__); 91 printk("%s: SRAM timeout\n", __func__);
@@ -110,7 +110,7 @@ static void flex_sram_read(struct adapter *adapter, u32 bank, u32 addr, u8 *buf,
110 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) { 110 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
111 mdelay(1); 111 mdelay(1);
112 retries--; 112 retries--;
113 }; 113 }
114 114
115 if (retries == 0) 115 if (retries == 0)
116 printk("%s: SRAM timeout\n", __func__); 116 printk("%s: SRAM timeout\n", __func__);
@@ -122,7 +122,7 @@ static void flex_sram_read(struct adapter *adapter, u32 bank, u32 addr, u8 *buf,
122 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) { 122 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
123 mdelay(1); 123 mdelay(1);
124 retries--; 124 retries--;
125 }; 125 }
126 126
127 if (retries == 0) 127 if (retries == 0)
128 printk("%s: SRAM timeout\n", __func__); 128 printk("%s: SRAM timeout\n", __func__);
diff --git a/drivers/media/common/saa7146/saa7146_core.c b/drivers/media/common/saa7146/saa7146_core.c
index bb6ee5191eb1..34b0d0ddeef3 100644
--- a/drivers/media/common/saa7146/saa7146_core.c
+++ b/drivers/media/common/saa7146/saa7146_core.c
@@ -411,7 +411,7 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
411 saa7146_write(dev, MC2, 0xf8000000); 411 saa7146_write(dev, MC2, 0xf8000000);
412 412
413 /* request an interrupt for the saa7146 */ 413 /* request an interrupt for the saa7146 */
414 err = request_irq(pci->irq, interrupt_hw, IRQF_SHARED | IRQF_DISABLED, 414 err = request_irq(pci->irq, interrupt_hw, IRQF_SHARED,
415 dev->name, dev); 415 dev->name, dev);
416 if (err < 0) { 416 if (err < 0) {
417 ERR("request_irq() failed\n"); 417 ERR("request_irq() failed\n");
@@ -524,8 +524,6 @@ static void saa7146_remove_one(struct pci_dev *pdev)
524 DEB_EE("dev:%p\n", dev); 524 DEB_EE("dev:%p\n", dev);
525 525
526 dev->ext->detach(dev); 526 dev->ext->detach(dev);
527 /* Zero the PCI drvdata after use. */
528 pci_set_drvdata(pdev, NULL);
529 527
530 /* shut down all video dma transfers */ 528 /* shut down all video dma transfers */
531 saa7146_write(dev, MC1, 0x00ff0000); 529 saa7146_write(dev, MC1, 0x00ff0000);
diff --git a/drivers/media/common/siano/smscoreapi.c b/drivers/media/common/siano/smscoreapi.c
index a142f7942a01..050984c5b1e3 100644
--- a/drivers/media/common/siano/smscoreapi.c
+++ b/drivers/media/common/siano/smscoreapi.c
@@ -922,8 +922,8 @@ static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
922 u32 i, *ptr; 922 u32 i, *ptr;
923 u8 *payload = firmware->payload; 923 u8 *payload = firmware->payload;
924 int rc = 0; 924 int rc = 0;
925 firmware->start_address = le32_to_cpu(firmware->start_address); 925 firmware->start_address = le32_to_cpup((__le32 *)&firmware->start_address);
926 firmware->length = le32_to_cpu(firmware->length); 926 firmware->length = le32_to_cpup((__le32 *)&firmware->length);
927 927
928 mem_address = firmware->start_address; 928 mem_address = firmware->start_address;
929 929
@@ -982,7 +982,7 @@ static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
982 if (rc < 0) 982 if (rc < 0)
983 goto exit_fw_download; 983 goto exit_fw_download;
984 984
985 sms_err("sending MSG_SMS_DATA_VALIDITY_REQ expecting 0x%x", 985 sms_debug("sending MSG_SMS_DATA_VALIDITY_REQ expecting 0x%x",
986 calc_checksum); 986 calc_checksum);
987 SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_DATA_VALIDITY_REQ, 987 SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_DATA_VALIDITY_REQ,
988 sizeof(msg->x_msg_header) + 988 sizeof(msg->x_msg_header) +
@@ -1562,7 +1562,7 @@ void smscore_onresponse(struct smscore_device_t *coredev,
1562 { 1562 {
1563 struct sms_msg_data *validity = (struct sms_msg_data *) phdr; 1563 struct sms_msg_data *validity = (struct sms_msg_data *) phdr;
1564 1564
1565 sms_err("MSG_SMS_DATA_VALIDITY_RES, checksum = 0x%x", 1565 sms_debug("MSG_SMS_DATA_VALIDITY_RES, checksum = 0x%x",
1566 validity->msg_data[0]); 1566 validity->msg_data[0]);
1567 complete(&coredev->data_validity_done); 1567 complete(&coredev->data_validity_done);
1568 break; 1568 break;
diff --git a/drivers/media/common/siano/smsdvb-main.c b/drivers/media/common/siano/smsdvb-main.c
index 63676a8b024c..85151efdd94c 100644
--- a/drivers/media/common/siano/smsdvb-main.c
+++ b/drivers/media/common/siano/smsdvb-main.c
@@ -44,14 +44,14 @@ module_param_named(debug, sms_dbg, int, 0644);
44MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))"); 44MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))");
45 45
46 46
47u32 sms_to_guard_interval_table[] = { 47static u32 sms_to_guard_interval_table[] = {
48 [0] = GUARD_INTERVAL_1_32, 48 [0] = GUARD_INTERVAL_1_32,
49 [1] = GUARD_INTERVAL_1_16, 49 [1] = GUARD_INTERVAL_1_16,
50 [2] = GUARD_INTERVAL_1_8, 50 [2] = GUARD_INTERVAL_1_8,
51 [3] = GUARD_INTERVAL_1_4, 51 [3] = GUARD_INTERVAL_1_4,
52}; 52};
53 53
54u32 sms_to_code_rate_table[] = { 54static u32 sms_to_code_rate_table[] = {
55 [0] = FEC_1_2, 55 [0] = FEC_1_2,
56 [1] = FEC_2_3, 56 [1] = FEC_2_3,
57 [2] = FEC_3_4, 57 [2] = FEC_3_4,
@@ -60,14 +60,14 @@ u32 sms_to_code_rate_table[] = {
60}; 60};
61 61
62 62
63u32 sms_to_hierarchy_table[] = { 63static u32 sms_to_hierarchy_table[] = {
64 [0] = HIERARCHY_NONE, 64 [0] = HIERARCHY_NONE,
65 [1] = HIERARCHY_1, 65 [1] = HIERARCHY_1,
66 [2] = HIERARCHY_2, 66 [2] = HIERARCHY_2,
67 [3] = HIERARCHY_4, 67 [3] = HIERARCHY_4,
68}; 68};
69 69
70u32 sms_to_modulation_table[] = { 70static u32 sms_to_modulation_table[] = {
71 [0] = QPSK, 71 [0] = QPSK,
72 [1] = QAM_16, 72 [1] = QAM_16,
73 [2] = QAM_64, 73 [2] = QAM_64,
diff --git a/drivers/media/dvb-core/dvb_demux.c b/drivers/media/dvb-core/dvb_demux.c
index 3485655fa082..58de4410c525 100644
--- a/drivers/media/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb-core/dvb_demux.c
@@ -476,7 +476,9 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf)
476void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf, 476void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf,
477 size_t count) 477 size_t count)
478{ 478{
479 spin_lock(&demux->lock); 479 unsigned long flags;
480
481 spin_lock_irqsave(&demux->lock, flags);
480 482
481 while (count--) { 483 while (count--) {
482 if (buf[0] == 0x47) 484 if (buf[0] == 0x47)
@@ -484,7 +486,7 @@ void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf,
484 buf += 188; 486 buf += 188;
485 } 487 }
486 488
487 spin_unlock(&demux->lock); 489 spin_unlock_irqrestore(&demux->lock, flags);
488} 490}
489 491
490EXPORT_SYMBOL(dvb_dmx_swfilter_packets); 492EXPORT_SYMBOL(dvb_dmx_swfilter_packets);
@@ -519,8 +521,9 @@ static inline void _dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf,
519{ 521{
520 int p = 0, i, j; 522 int p = 0, i, j;
521 const u8 *q; 523 const u8 *q;
524 unsigned long flags;
522 525
523 spin_lock(&demux->lock); 526 spin_lock_irqsave(&demux->lock, flags);
524 527
525 if (demux->tsbufp) { /* tsbuf[0] is now 0x47. */ 528 if (demux->tsbufp) { /* tsbuf[0] is now 0x47. */
526 i = demux->tsbufp; 529 i = demux->tsbufp;
@@ -564,7 +567,7 @@ static inline void _dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf,
564 } 567 }
565 568
566bailout: 569bailout:
567 spin_unlock(&demux->lock); 570 spin_unlock_irqrestore(&demux->lock, flags);
568} 571}
569 572
570void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count) 573void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
@@ -581,11 +584,13 @@ EXPORT_SYMBOL(dvb_dmx_swfilter_204);
581 584
582void dvb_dmx_swfilter_raw(struct dvb_demux *demux, const u8 *buf, size_t count) 585void dvb_dmx_swfilter_raw(struct dvb_demux *demux, const u8 *buf, size_t count)
583{ 586{
584 spin_lock(&demux->lock); 587 unsigned long flags;
588
589 spin_lock_irqsave(&demux->lock, flags);
585 590
586 demux->feed->cb.ts(buf, count, NULL, 0, &demux->feed->feed.ts, DMX_OK); 591 demux->feed->cb.ts(buf, count, NULL, 0, &demux->feed->feed.ts, DMX_OK);
587 592
588 spin_unlock(&demux->lock); 593 spin_unlock_irqrestore(&demux->lock, flags);
589} 594}
590EXPORT_SYMBOL(dvb_dmx_swfilter_raw); 595EXPORT_SYMBOL(dvb_dmx_swfilter_raw);
591 596
diff --git a/drivers/media/dvb-frontends/Kconfig b/drivers/media/dvb-frontends/Kconfig
index 0e2ec6f73b05..bddbab43a2df 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -200,6 +200,13 @@ config DVB_CX24116
200 help 200 help
201 A DVB-S/S2 tuner module. Say Y when you want to support this frontend. 201 A DVB-S/S2 tuner module. Say Y when you want to support this frontend.
202 202
203config DVB_CX24117
204 tristate "Conexant CX24117 based"
205 depends on DVB_CORE && I2C
206 default m if !MEDIA_SUBDRV_AUTOSELECT
207 help
208 A Dual DVB-S/S2 tuner module. Say Y when you want to support this frontend.
209
203config DVB_SI21XX 210config DVB_SI21XX
204 tristate "Silicon Labs SI21XX based" 211 tristate "Silicon Labs SI21XX based"
205 depends on DVB_CORE && I2C 212 depends on DVB_CORE && I2C
diff --git a/drivers/media/dvb-frontends/Makefile b/drivers/media/dvb-frontends/Makefile
index cebc0faffab5..f9cb43d9aed9 100644
--- a/drivers/media/dvb-frontends/Makefile
+++ b/drivers/media/dvb-frontends/Makefile
@@ -76,6 +76,7 @@ obj-$(CONFIG_DVB_ATBM8830) += atbm8830.o
76obj-$(CONFIG_DVB_DUMMY_FE) += dvb_dummy_fe.o 76obj-$(CONFIG_DVB_DUMMY_FE) += dvb_dummy_fe.o
77obj-$(CONFIG_DVB_AF9013) += af9013.o 77obj-$(CONFIG_DVB_AF9013) += af9013.o
78obj-$(CONFIG_DVB_CX24116) += cx24116.o 78obj-$(CONFIG_DVB_CX24116) += cx24116.o
79obj-$(CONFIG_DVB_CX24117) += cx24117.o
79obj-$(CONFIG_DVB_SI21XX) += si21xx.o 80obj-$(CONFIG_DVB_SI21XX) += si21xx.o
80obj-$(CONFIG_DVB_STV0288) += stv0288.o 81obj-$(CONFIG_DVB_STV0288) += stv0288.o
81obj-$(CONFIG_DVB_STB6000) += stb6000.o 82obj-$(CONFIG_DVB_STB6000) += stb6000.o
diff --git a/drivers/media/dvb-frontends/af9013.c b/drivers/media/dvb-frontends/af9013.c
index a204f2828820..fb504f1e9125 100644
--- a/drivers/media/dvb-frontends/af9013.c
+++ b/drivers/media/dvb-frontends/af9013.c
@@ -24,6 +24,9 @@
24 24
25#include "af9013_priv.h" 25#include "af9013_priv.h"
26 26
27/* Max transfer size done by I2C transfer functions */
28#define MAX_XFER_SIZE 64
29
27struct af9013_state { 30struct af9013_state {
28 struct i2c_adapter *i2c; 31 struct i2c_adapter *i2c;
29 struct dvb_frontend fe; 32 struct dvb_frontend fe;
@@ -50,16 +53,23 @@ static int af9013_wr_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg,
50 const u8 *val, int len) 53 const u8 *val, int len)
51{ 54{
52 int ret; 55 int ret;
53 u8 buf[3+len]; 56 u8 buf[MAX_XFER_SIZE];
54 struct i2c_msg msg[1] = { 57 struct i2c_msg msg[1] = {
55 { 58 {
56 .addr = priv->config.i2c_addr, 59 .addr = priv->config.i2c_addr,
57 .flags = 0, 60 .flags = 0,
58 .len = sizeof(buf), 61 .len = 3 + len,
59 .buf = buf, 62 .buf = buf,
60 } 63 }
61 }; 64 };
62 65
66 if (3 + len > sizeof(buf)) {
67 dev_warn(&priv->i2c->dev,
68 "%s: i2c wr reg=%04x: len=%d is too big!\n",
69 KBUILD_MODNAME, reg, len);
70 return -EINVAL;
71 }
72
63 buf[0] = (reg >> 8) & 0xff; 73 buf[0] = (reg >> 8) & 0xff;
64 buf[1] = (reg >> 0) & 0xff; 74 buf[1] = (reg >> 0) & 0xff;
65 buf[2] = mbox; 75 buf[2] = mbox;
diff --git a/drivers/media/dvb-frontends/af9033.c b/drivers/media/dvb-frontends/af9033.c
index a777b4b944eb..30ee59052157 100644
--- a/drivers/media/dvb-frontends/af9033.c
+++ b/drivers/media/dvb-frontends/af9033.c
@@ -21,6 +21,9 @@
21 21
22#include "af9033_priv.h" 22#include "af9033_priv.h"
23 23
24/* Max transfer size done by I2C transfer functions */
25#define MAX_XFER_SIZE 64
26
24struct af9033_state { 27struct af9033_state {
25 struct i2c_adapter *i2c; 28 struct i2c_adapter *i2c;
26 struct dvb_frontend fe; 29 struct dvb_frontend fe;
@@ -40,16 +43,23 @@ static int af9033_wr_regs(struct af9033_state *state, u32 reg, const u8 *val,
40 int len) 43 int len)
41{ 44{
42 int ret; 45 int ret;
43 u8 buf[3 + len]; 46 u8 buf[MAX_XFER_SIZE];
44 struct i2c_msg msg[1] = { 47 struct i2c_msg msg[1] = {
45 { 48 {
46 .addr = state->cfg.i2c_addr, 49 .addr = state->cfg.i2c_addr,
47 .flags = 0, 50 .flags = 0,
48 .len = sizeof(buf), 51 .len = 3 + len,
49 .buf = buf, 52 .buf = buf,
50 } 53 }
51 }; 54 };
52 55
56 if (3 + len > sizeof(buf)) {
57 dev_warn(&state->i2c->dev,
58 "%s: i2c wr reg=%04x: len=%d is too big!\n",
59 KBUILD_MODNAME, reg, len);
60 return -EINVAL;
61 }
62
53 buf[0] = (reg >> 16) & 0xff; 63 buf[0] = (reg >> 16) & 0xff;
54 buf[1] = (reg >> 8) & 0xff; 64 buf[1] = (reg >> 8) & 0xff;
55 buf[2] = (reg >> 0) & 0xff; 65 buf[2] = (reg >> 0) & 0xff;
@@ -161,7 +171,14 @@ static int af9033_wr_reg_val_tab(struct af9033_state *state,
161 const struct reg_val *tab, int tab_len) 171 const struct reg_val *tab, int tab_len)
162{ 172{
163 int ret, i, j; 173 int ret, i, j;
164 u8 buf[tab_len]; 174 u8 buf[MAX_XFER_SIZE];
175
176 if (tab_len > sizeof(buf)) {
177 dev_warn(&state->i2c->dev,
178 "%s: i2c wr len=%d is too big!\n",
179 KBUILD_MODNAME, tab_len);
180 return -EINVAL;
181 }
165 182
166 dev_dbg(&state->i2c->dev, "%s: tab_len=%d\n", __func__, tab_len); 183 dev_dbg(&state->i2c->dev, "%s: tab_len=%d\n", __func__, tab_len);
167 184
diff --git a/drivers/media/dvb-frontends/bcm3510.c b/drivers/media/dvb-frontends/bcm3510.c
index 1b77909c0c71..39a29dd29519 100644
--- a/drivers/media/dvb-frontends/bcm3510.c
+++ b/drivers/media/dvb-frontends/bcm3510.c
@@ -44,6 +44,9 @@
44#include "bcm3510.h" 44#include "bcm3510.h"
45#include "bcm3510_priv.h" 45#include "bcm3510_priv.h"
46 46
47/* Max transfer size done by bcm3510_do_hab_cmd() function */
48#define MAX_XFER_SIZE 128
49
47struct bcm3510_state { 50struct bcm3510_state {
48 51
49 struct i2c_adapter* i2c; 52 struct i2c_adapter* i2c;
@@ -201,9 +204,19 @@ static int bcm3510_hab_send_request(struct bcm3510_state *st, u8 *buf, int len)
201 204
202static int bcm3510_do_hab_cmd(struct bcm3510_state *st, u8 cmd, u8 msgid, u8 *obuf, u8 olen, u8 *ibuf, u8 ilen) 205static int bcm3510_do_hab_cmd(struct bcm3510_state *st, u8 cmd, u8 msgid, u8 *obuf, u8 olen, u8 *ibuf, u8 ilen)
203{ 206{
204 u8 ob[olen+2],ib[ilen+2]; 207 u8 ob[MAX_XFER_SIZE], ib[MAX_XFER_SIZE];
205 int ret = 0; 208 int ret = 0;
206 209
210 if (ilen + 2 > sizeof(ib)) {
211 deb_hab("do_hab_cmd: ilen=%d is too big!\n", ilen);
212 return -EINVAL;
213 }
214
215 if (olen + 2 > sizeof(ob)) {
216 deb_hab("do_hab_cmd: olen=%d is too big!\n", olen);
217 return -EINVAL;
218 }
219
207 ob[0] = cmd; 220 ob[0] = cmd;
208 ob[1] = msgid; 221 ob[1] = msgid;
209 memcpy(&ob[2],obuf,olen); 222 memcpy(&ob[2],obuf,olen);
diff --git a/drivers/media/dvb-frontends/cx24110.c b/drivers/media/dvb-frontends/cx24110.c
index 0cd6927e654c..95b981cd7115 100644
--- a/drivers/media/dvb-frontends/cx24110.c
+++ b/drivers/media/dvb-frontends/cx24110.c
@@ -378,7 +378,7 @@ static int cx24110_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
378 return cx24110_writereg(state,0x76,(cx24110_readreg(state,0x76)&0x3b)|0x40); 378 return cx24110_writereg(state,0x76,(cx24110_readreg(state,0x76)&0x3b)|0x40);
379 default: 379 default:
380 return -EINVAL; 380 return -EINVAL;
381 }; 381 }
382} 382}
383 383
384static int cx24110_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) 384static int cx24110_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t burst)
diff --git a/drivers/media/dvb-frontends/cx24117.c b/drivers/media/dvb-frontends/cx24117.c
new file mode 100644
index 000000000000..476b422ccf19
--- /dev/null
+++ b/drivers/media/dvb-frontends/cx24117.c
@@ -0,0 +1,1650 @@
1/*
2 Conexant cx24117/cx24132 - Dual DVBS/S2 Satellite demod/tuner driver
3
4 Copyright (C) 2013 Luis Alves <ljalvs@gmail.com>
5 July, 6th 2013
6 First release based on cx24116 driver by:
7 Steven Toth and Georg Acher, Darron Broad, Igor Liplianin
8 Cards currently supported:
9 TBS6980 - Dual DVBS/S2 PCIe card
10 TBS6981 - Dual DVBS/S2 PCIe card
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 as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25*/
26
27#include <linux/slab.h>
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/moduleparam.h>
31#include <linux/init.h>
32#include <linux/firmware.h>
33
34#include "tuner-i2c.h"
35#include "dvb_frontend.h"
36#include "cx24117.h"
37
38
39#define CX24117_DEFAULT_FIRMWARE "dvb-fe-cx24117.fw"
40#define CX24117_SEARCH_RANGE_KHZ 5000
41
42/* known registers */
43#define CX24117_REG_COMMAND (0x00) /* command buffer */
44#define CX24117_REG_EXECUTE (0x1f) /* execute command */
45
46#define CX24117_REG_FREQ3_0 (0x34) /* frequency */
47#define CX24117_REG_FREQ2_0 (0x35)
48#define CX24117_REG_FREQ1_0 (0x36)
49#define CX24117_REG_STATE0 (0x39)
50#define CX24117_REG_SSTATUS0 (0x3a) /* demod0 signal high / status */
51#define CX24117_REG_SIGNAL0 (0x3b)
52#define CX24117_REG_FREQ5_0 (0x3c) /* +-freq */
53#define CX24117_REG_FREQ6_0 (0x3d)
54#define CX24117_REG_SRATE2_0 (0x3e) /* +- 1000 * srate */
55#define CX24117_REG_SRATE1_0 (0x3f)
56#define CX24117_REG_QUALITY2_0 (0x40)
57#define CX24117_REG_QUALITY1_0 (0x41)
58
59#define CX24117_REG_BER4_0 (0x47)
60#define CX24117_REG_BER3_0 (0x48)
61#define CX24117_REG_BER2_0 (0x49)
62#define CX24117_REG_BER1_0 (0x4a)
63#define CX24117_REG_DVBS_UCB2_0 (0x4b)
64#define CX24117_REG_DVBS_UCB1_0 (0x4c)
65#define CX24117_REG_DVBS2_UCB2_0 (0x50)
66#define CX24117_REG_DVBS2_UCB1_0 (0x51)
67#define CX24117_REG_QSTATUS0 (0x93)
68#define CX24117_REG_CLKDIV0 (0xe6)
69#define CX24117_REG_RATEDIV0 (0xf0)
70
71
72#define CX24117_REG_FREQ3_1 (0x55) /* frequency */
73#define CX24117_REG_FREQ2_1 (0x56)
74#define CX24117_REG_FREQ1_1 (0x57)
75#define CX24117_REG_STATE1 (0x5a)
76#define CX24117_REG_SSTATUS1 (0x5b) /* demod1 signal high / status */
77#define CX24117_REG_SIGNAL1 (0x5c)
78#define CX24117_REG_FREQ5_1 (0x5d) /* +- freq */
79#define CX24117_REG_FREQ4_1 (0x5e)
80#define CX24117_REG_SRATE2_1 (0x5f)
81#define CX24117_REG_SRATE1_1 (0x60)
82#define CX24117_REG_QUALITY2_1 (0x61)
83#define CX24117_REG_QUALITY1_1 (0x62)
84#define CX24117_REG_BER4_1 (0x68)
85#define CX24117_REG_BER3_1 (0x69)
86#define CX24117_REG_BER2_1 (0x6a)
87#define CX24117_REG_BER1_1 (0x6b)
88#define CX24117_REG_DVBS_UCB2_1 (0x6c)
89#define CX24117_REG_DVBS_UCB1_1 (0x6d)
90#define CX24117_REG_DVBS2_UCB2_1 (0x71)
91#define CX24117_REG_DVBS2_UCB1_1 (0x72)
92#define CX24117_REG_QSTATUS1 (0x9f)
93#define CX24117_REG_CLKDIV1 (0xe7)
94#define CX24117_REG_RATEDIV1 (0xf1)
95
96
97/* arg buffer size */
98#define CX24117_ARGLEN (0x1e)
99
100/* rolloff */
101#define CX24117_ROLLOFF_020 (0x00)
102#define CX24117_ROLLOFF_025 (0x01)
103#define CX24117_ROLLOFF_035 (0x02)
104
105/* pilot bit */
106#define CX24117_PILOT_OFF (0x00)
107#define CX24117_PILOT_ON (0x40)
108#define CX24117_PILOT_AUTO (0x80)
109
110/* signal status */
111#define CX24117_HAS_SIGNAL (0x01)
112#define CX24117_HAS_CARRIER (0x02)
113#define CX24117_HAS_VITERBI (0x04)
114#define CX24117_HAS_SYNCLOCK (0x08)
115#define CX24117_STATUS_MASK (0x0f)
116#define CX24117_SIGNAL_MASK (0xc0)
117
118
119/* arg offset for DiSEqC */
120#define CX24117_DISEQC_DEMOD (1)
121#define CX24117_DISEQC_BURST (2)
122#define CX24117_DISEQC_ARG3_2 (3) /* unknown value=2 */
123#define CX24117_DISEQC_ARG4_0 (4) /* unknown value=0 */
124#define CX24117_DISEQC_ARG5_0 (5) /* unknown value=0 */
125#define CX24117_DISEQC_MSGLEN (6)
126#define CX24117_DISEQC_MSGOFS (7)
127
128/* DiSEqC burst */
129#define CX24117_DISEQC_MINI_A (0)
130#define CX24117_DISEQC_MINI_B (1)
131
132
133#define CX24117_PNE (0) /* 0 disabled / 2 enabled */
134#define CX24117_OCC (1) /* 0 disabled / 1 enabled */
135
136
137enum cmds {
138 CMD_SET_VCO = 0x10,
139 CMD_TUNEREQUEST = 0x11,
140 CMD_MPEGCONFIG = 0x13,
141 CMD_TUNERINIT = 0x14,
142 CMD_LNBSEND = 0x21, /* Formerly CMD_SEND_DISEQC */
143 CMD_LNBDCLEVEL = 0x22,
144 CMD_SET_TONE = 0x23,
145 CMD_UPDFWVERS = 0x35,
146 CMD_TUNERSLEEP = 0x36,
147};
148
149static LIST_HEAD(hybrid_tuner_instance_list);
150static DEFINE_MUTEX(cx24117_list_mutex);
151
152/* The Demod/Tuner can't easily provide these, we cache them */
153struct cx24117_tuning {
154 u32 frequency;
155 u32 symbol_rate;
156 fe_spectral_inversion_t inversion;
157 fe_code_rate_t fec;
158
159 fe_delivery_system_t delsys;
160 fe_modulation_t modulation;
161 fe_pilot_t pilot;
162 fe_rolloff_t rolloff;
163
164 /* Demod values */
165 u8 fec_val;
166 u8 fec_mask;
167 u8 inversion_val;
168 u8 pilot_val;
169 u8 rolloff_val;
170};
171
172/* Basic commands that are sent to the firmware */
173struct cx24117_cmd {
174 u8 len;
175 u8 args[CX24117_ARGLEN];
176};
177
178/* common to both fe's */
179struct cx24117_priv {
180 u8 demod_address;
181 struct i2c_adapter *i2c;
182 u8 skip_fw_load;
183 struct mutex fe_lock;
184
185 /* Used for sharing this struct between demods */
186 struct tuner_i2c_props i2c_props;
187 struct list_head hybrid_tuner_instance_list;
188};
189
190/* one per each fe */
191struct cx24117_state {
192 struct cx24117_priv *priv;
193 struct dvb_frontend frontend;
194
195 struct cx24117_tuning dcur;
196 struct cx24117_tuning dnxt;
197 struct cx24117_cmd dsec_cmd;
198
199 int demod;
200};
201
202/* modfec (modulation and FEC) lookup table */
203/* Check cx24116.c for a detailed description of each field */
204static struct cx24117_modfec {
205 fe_delivery_system_t delivery_system;
206 fe_modulation_t modulation;
207 fe_code_rate_t fec;
208 u8 mask; /* In DVBS mode this is used to autodetect */
209 u8 val; /* Passed to the firmware to indicate mode selection */
210} cx24117_modfec_modes[] = {
211 /* QPSK. For unknown rates we set hardware to auto detect 0xfe 0x30 */
212
213 /*mod fec mask val */
214 { SYS_DVBS, QPSK, FEC_NONE, 0xfe, 0x30 },
215 { SYS_DVBS, QPSK, FEC_1_2, 0x02, 0x2e }, /* 00000010 00101110 */
216 { SYS_DVBS, QPSK, FEC_2_3, 0x04, 0x2f }, /* 00000100 00101111 */
217 { SYS_DVBS, QPSK, FEC_3_4, 0x08, 0x30 }, /* 00001000 00110000 */
218 { SYS_DVBS, QPSK, FEC_4_5, 0xfe, 0x30 }, /* 000?0000 ? */
219 { SYS_DVBS, QPSK, FEC_5_6, 0x20, 0x31 }, /* 00100000 00110001 */
220 { SYS_DVBS, QPSK, FEC_6_7, 0xfe, 0x30 }, /* 0?000000 ? */
221 { SYS_DVBS, QPSK, FEC_7_8, 0x80, 0x32 }, /* 10000000 00110010 */
222 { SYS_DVBS, QPSK, FEC_8_9, 0xfe, 0x30 }, /* 0000000? ? */
223 { SYS_DVBS, QPSK, FEC_AUTO, 0xfe, 0x30 },
224 /* NBC-QPSK */
225 { SYS_DVBS2, QPSK, FEC_NONE, 0x00, 0x00 },
226 { SYS_DVBS2, QPSK, FEC_1_2, 0x00, 0x04 },
227 { SYS_DVBS2, QPSK, FEC_3_5, 0x00, 0x05 },
228 { SYS_DVBS2, QPSK, FEC_2_3, 0x00, 0x06 },
229 { SYS_DVBS2, QPSK, FEC_3_4, 0x00, 0x07 },
230 { SYS_DVBS2, QPSK, FEC_4_5, 0x00, 0x08 },
231 { SYS_DVBS2, QPSK, FEC_5_6, 0x00, 0x09 },
232 { SYS_DVBS2, QPSK, FEC_8_9, 0x00, 0x0a },
233 { SYS_DVBS2, QPSK, FEC_9_10, 0x00, 0x0b },
234 { SYS_DVBS2, QPSK, FEC_AUTO, 0x00, 0x00 },
235 /* 8PSK */
236 { SYS_DVBS2, PSK_8, FEC_NONE, 0x00, 0x00 },
237 { SYS_DVBS2, PSK_8, FEC_3_5, 0x00, 0x0c },
238 { SYS_DVBS2, PSK_8, FEC_2_3, 0x00, 0x0d },
239 { SYS_DVBS2, PSK_8, FEC_3_4, 0x00, 0x0e },
240 { SYS_DVBS2, PSK_8, FEC_5_6, 0x00, 0x0f },
241 { SYS_DVBS2, PSK_8, FEC_8_9, 0x00, 0x10 },
242 { SYS_DVBS2, PSK_8, FEC_9_10, 0x00, 0x11 },
243 { SYS_DVBS2, PSK_8, FEC_AUTO, 0x00, 0x00 },
244 /*
245 * 'val' can be found in the FECSTATUS register when tuning.
246 * FECSTATUS will give the actual FEC in use if tuning was successful.
247 */
248};
249
250
251static int cx24117_writereg(struct cx24117_state *state, u8 reg, u8 data)
252{
253 u8 buf[] = { reg, data };
254 struct i2c_msg msg = { .addr = state->priv->demod_address,
255 .flags = 0, .buf = buf, .len = 2 };
256 int ret;
257
258 dev_dbg(&state->priv->i2c->dev,
259 "%s() demod%d i2c wr @0x%02x=0x%02x\n",
260 __func__, state->demod, reg, data);
261
262 ret = i2c_transfer(state->priv->i2c, &msg, 1);
263 if (ret < 0) {
264 dev_warn(&state->priv->i2c->dev,
265 "%s: demod%d i2c wr err(%i) @0x%02x=0x%02x\n",
266 KBUILD_MODNAME, state->demod, ret, reg, data);
267 return ret;
268 }
269 return 0;
270}
271
272static int cx24117_writecmd(struct cx24117_state *state,
273 struct cx24117_cmd *cmd)
274{
275 struct i2c_msg msg;
276 u8 buf[CX24117_ARGLEN+1];
277 int ret;
278
279 dev_dbg(&state->priv->i2c->dev,
280 "%s() demod%d i2c wr cmd len=%d\n",
281 __func__, state->demod, cmd->len);
282
283 buf[0] = CX24117_REG_COMMAND;
284 memcpy(&buf[1], cmd->args, cmd->len);
285
286 msg.addr = state->priv->demod_address;
287 msg.flags = 0;
288 msg.len = cmd->len+1;
289 msg.buf = buf;
290 ret = i2c_transfer(state->priv->i2c, &msg, 1);
291 if (ret < 0) {
292 dev_warn(&state->priv->i2c->dev,
293 "%s: demod%d i2c wr cmd err(%i) len=%d\n",
294 KBUILD_MODNAME, state->demod, ret, cmd->len);
295 return ret;
296 }
297 return 0;
298}
299
300static int cx24117_readreg(struct cx24117_state *state, u8 reg)
301{
302 int ret;
303 u8 recv = 0;
304 struct i2c_msg msg[] = {
305 { .addr = state->priv->demod_address, .flags = 0,
306 .buf = &reg, .len = 1 },
307 { .addr = state->priv->demod_address, .flags = I2C_M_RD,
308 .buf = &recv, .len = 1 }
309 };
310
311 ret = i2c_transfer(state->priv->i2c, msg, 2);
312 if (ret < 0) {
313 dev_warn(&state->priv->i2c->dev,
314 "%s: demod%d i2c rd err(%d) @0x%x\n",
315 KBUILD_MODNAME, state->demod, ret, reg);
316 return ret;
317 }
318
319 dev_dbg(&state->priv->i2c->dev, "%s() demod%d i2c rd @0x%02x=0x%02x\n",
320 __func__, state->demod, reg, recv);
321
322 return recv;
323}
324
325static int cx24117_readregN(struct cx24117_state *state,
326 u8 reg, u8 *buf, int len)
327{
328 int ret;
329 struct i2c_msg msg[] = {
330 { .addr = state->priv->demod_address, .flags = 0,
331 .buf = &reg, .len = 1 },
332 { .addr = state->priv->demod_address, .flags = I2C_M_RD,
333 .buf = buf, .len = len }
334 };
335
336 ret = i2c_transfer(state->priv->i2c, msg, 2);
337 if (ret < 0) {
338 dev_warn(&state->priv->i2c->dev,
339 "%s: demod%d i2c rd err(%d) @0x%x\n",
340 KBUILD_MODNAME, state->demod, ret, reg);
341 return ret;
342 }
343 return 0;
344}
345
346static int cx24117_set_inversion(struct cx24117_state *state,
347 fe_spectral_inversion_t inversion)
348{
349 dev_dbg(&state->priv->i2c->dev, "%s(%d) demod%d\n",
350 __func__, inversion, state->demod);
351
352 switch (inversion) {
353 case INVERSION_OFF:
354 state->dnxt.inversion_val = 0x00;
355 break;
356 case INVERSION_ON:
357 state->dnxt.inversion_val = 0x04;
358 break;
359 case INVERSION_AUTO:
360 state->dnxt.inversion_val = 0x0C;
361 break;
362 default:
363 return -EINVAL;
364 }
365
366 state->dnxt.inversion = inversion;
367
368 return 0;
369}
370
371static int cx24117_lookup_fecmod(struct cx24117_state *state,
372 fe_delivery_system_t d, fe_modulation_t m, fe_code_rate_t f)
373{
374 int i, ret = -EINVAL;
375
376 dev_dbg(&state->priv->i2c->dev,
377 "%s(demod(0x%02x,0x%02x) demod%d\n",
378 __func__, m, f, state->demod);
379
380 for (i = 0; i < ARRAY_SIZE(cx24117_modfec_modes); i++) {
381 if ((d == cx24117_modfec_modes[i].delivery_system) &&
382 (m == cx24117_modfec_modes[i].modulation) &&
383 (f == cx24117_modfec_modes[i].fec)) {
384 ret = i;
385 break;
386 }
387 }
388
389 return ret;
390}
391
392static int cx24117_set_fec(struct cx24117_state *state,
393 fe_delivery_system_t delsys, fe_modulation_t mod, fe_code_rate_t fec)
394{
395 int ret;
396
397 dev_dbg(&state->priv->i2c->dev,
398 "%s(0x%02x,0x%02x) demod%d\n",
399 __func__, mod, fec, state->demod);
400
401 ret = cx24117_lookup_fecmod(state, delsys, mod, fec);
402 if (ret < 0)
403 return ret;
404
405 state->dnxt.fec = fec;
406 state->dnxt.fec_val = cx24117_modfec_modes[ret].val;
407 state->dnxt.fec_mask = cx24117_modfec_modes[ret].mask;
408 dev_dbg(&state->priv->i2c->dev,
409 "%s() demod%d mask/val = 0x%02x/0x%02x\n", __func__,
410 state->demod, state->dnxt.fec_mask, state->dnxt.fec_val);
411
412 return 0;
413}
414
415static int cx24117_set_symbolrate(struct cx24117_state *state, u32 rate)
416{
417 dev_dbg(&state->priv->i2c->dev, "%s(%d) demod%d\n",
418 __func__, rate, state->demod);
419
420 state->dnxt.symbol_rate = rate;
421
422 dev_dbg(&state->priv->i2c->dev,
423 "%s() demod%d symbol_rate = %d\n",
424 __func__, state->demod, rate);
425
426 return 0;
427}
428
429static int cx24117_load_firmware(struct dvb_frontend *fe,
430 const struct firmware *fw);
431
432static int cx24117_firmware_ondemand(struct dvb_frontend *fe)
433{
434 struct cx24117_state *state = fe->demodulator_priv;
435 const struct firmware *fw;
436 int ret = 0;
437
438 dev_dbg(&state->priv->i2c->dev, "%s() demod%d skip_fw_load=%d\n",
439 __func__, state->demod, state->priv->skip_fw_load);
440
441 if (state->priv->skip_fw_load)
442 return 0;
443
444 /* check if firmware if already running */
445 if (cx24117_readreg(state, 0xeb) != 0xa) {
446 /* Load firmware */
447 /* request the firmware, this will block until loaded */
448 dev_dbg(&state->priv->i2c->dev,
449 "%s: Waiting for firmware upload (%s)...\n",
450 __func__, CX24117_DEFAULT_FIRMWARE);
451 ret = request_firmware(&fw, CX24117_DEFAULT_FIRMWARE,
452 state->priv->i2c->dev.parent);
453 dev_dbg(&state->priv->i2c->dev,
454 "%s: Waiting for firmware upload(2)...\n", __func__);
455 if (ret) {
456 dev_err(&state->priv->i2c->dev,
457 "%s: No firmware uploaded "
458 "(timeout or file not found?)\n", __func__);
459 return ret;
460 }
461
462 /* Make sure we don't recurse back through here
463 * during loading */
464 state->priv->skip_fw_load = 1;
465
466 ret = cx24117_load_firmware(fe, fw);
467 if (ret)
468 dev_err(&state->priv->i2c->dev,
469 "%s: Writing firmware failed\n", __func__);
470 release_firmware(fw);
471
472 dev_info(&state->priv->i2c->dev,
473 "%s: Firmware upload %s\n", __func__,
474 ret == 0 ? "complete" : "failed");
475
476 /* Ensure firmware is always loaded if required */
477 state->priv->skip_fw_load = 0;
478 }
479
480 return ret;
481}
482
483/* Take a basic firmware command structure, format it
484 * and forward it for processing
485 */
486static int cx24117_cmd_execute_nolock(struct dvb_frontend *fe,
487 struct cx24117_cmd *cmd)
488{
489 struct cx24117_state *state = fe->demodulator_priv;
490 int i, ret;
491
492 dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
493 __func__, state->demod);
494
495 /* Load the firmware if required */
496 ret = cx24117_firmware_ondemand(fe);
497 if (ret != 0)
498 return ret;
499
500 /* Write the command */
501 cx24117_writecmd(state, cmd);
502
503 /* Start execution and wait for cmd to terminate */
504 cx24117_writereg(state, CX24117_REG_EXECUTE, 0x01);
505 i = 0;
506 while (cx24117_readreg(state, CX24117_REG_EXECUTE)) {
507 msleep(20);
508 if (i++ > 40) {
509 /* Avoid looping forever if the firmware does
510 not respond */
511 dev_warn(&state->priv->i2c->dev,
512 "%s() Firmware not responding\n", __func__);
513 return -EIO;
514 }
515 }
516 return 0;
517}
518
519static int cx24117_cmd_execute(struct dvb_frontend *fe, struct cx24117_cmd *cmd)
520{
521 struct cx24117_state *state = fe->demodulator_priv;
522 int ret;
523
524 mutex_lock(&state->priv->fe_lock);
525 ret = cx24117_cmd_execute_nolock(fe, cmd);
526 mutex_unlock(&state->priv->fe_lock);
527
528 return ret;
529}
530
531static int cx24117_load_firmware(struct dvb_frontend *fe,
532 const struct firmware *fw)
533{
534 struct cx24117_state *state = fe->demodulator_priv;
535 struct cx24117_cmd cmd;
536 int i, ret;
537 unsigned char vers[4];
538
539 struct i2c_msg msg;
540 u8 *buf;
541
542 dev_dbg(&state->priv->i2c->dev,
543 "%s() demod%d FW is %zu bytes (%02x %02x .. %02x %02x)\n",
544 __func__, state->demod, fw->size, fw->data[0], fw->data[1],
545 fw->data[fw->size - 2], fw->data[fw->size - 1]);
546
547 cx24117_writereg(state, 0xea, 0x00);
548 cx24117_writereg(state, 0xea, 0x01);
549 cx24117_writereg(state, 0xea, 0x00);
550
551 cx24117_writereg(state, 0xce, 0x92);
552
553 cx24117_writereg(state, 0xfb, 0x00);
554 cx24117_writereg(state, 0xfc, 0x00);
555
556 cx24117_writereg(state, 0xc3, 0x04);
557 cx24117_writereg(state, 0xc4, 0x04);
558
559 cx24117_writereg(state, 0xce, 0x00);
560 cx24117_writereg(state, 0xcf, 0x00);
561
562 cx24117_writereg(state, 0xea, 0x00);
563 cx24117_writereg(state, 0xeb, 0x0c);
564 cx24117_writereg(state, 0xec, 0x06);
565 cx24117_writereg(state, 0xed, 0x05);
566 cx24117_writereg(state, 0xee, 0x03);
567 cx24117_writereg(state, 0xef, 0x05);
568
569 cx24117_writereg(state, 0xf3, 0x03);
570 cx24117_writereg(state, 0xf4, 0x44);
571
572 cx24117_writereg(state, CX24117_REG_RATEDIV0, 0x04);
573 cx24117_writereg(state, CX24117_REG_CLKDIV0, 0x02);
574
575 cx24117_writereg(state, CX24117_REG_RATEDIV1, 0x04);
576 cx24117_writereg(state, CX24117_REG_CLKDIV1, 0x02);
577
578 cx24117_writereg(state, 0xf2, 0x04);
579 cx24117_writereg(state, 0xe8, 0x02);
580 cx24117_writereg(state, 0xea, 0x01);
581 cx24117_writereg(state, 0xc8, 0x00);
582 cx24117_writereg(state, 0xc9, 0x00);
583 cx24117_writereg(state, 0xca, 0x00);
584 cx24117_writereg(state, 0xcb, 0x00);
585 cx24117_writereg(state, 0xcc, 0x00);
586 cx24117_writereg(state, 0xcd, 0x00);
587 cx24117_writereg(state, 0xe4, 0x03);
588 cx24117_writereg(state, 0xeb, 0x0a);
589
590 cx24117_writereg(state, 0xfb, 0x00);
591 cx24117_writereg(state, 0xe0, 0x76);
592 cx24117_writereg(state, 0xf7, 0x81);
593 cx24117_writereg(state, 0xf8, 0x00);
594 cx24117_writereg(state, 0xf9, 0x00);
595
596 buf = kmalloc(fw->size + 1, GFP_KERNEL);
597 if (buf == NULL) {
598 state->priv->skip_fw_load = 0;
599 return -ENOMEM;
600 }
601
602 /* fw upload reg */
603 buf[0] = 0xfa;
604 memcpy(&buf[1], fw->data, fw->size);
605
606 /* prepare i2c message to send */
607 msg.addr = state->priv->demod_address;
608 msg.flags = 0;
609 msg.len = fw->size + 1;
610 msg.buf = buf;
611
612 /* send fw */
613 ret = i2c_transfer(state->priv->i2c, &msg, 1);
614 if (ret < 0)
615 return ret;
616
617 kfree(buf);
618
619 cx24117_writereg(state, 0xf7, 0x0c);
620 cx24117_writereg(state, 0xe0, 0x00);
621
622 /* CMD 1B */
623 cmd.args[0] = 0x1b;
624 cmd.args[1] = 0x00;
625 cmd.args[2] = 0x01;
626 cmd.args[3] = 0x00;
627 cmd.len = 4;
628 ret = cx24117_cmd_execute_nolock(fe, &cmd);
629 if (ret != 0)
630 goto error;
631
632 /* CMD 10 */
633 cmd.args[0] = CMD_SET_VCO;
634 cmd.args[1] = 0x06;
635 cmd.args[2] = 0x2b;
636 cmd.args[3] = 0xd8;
637 cmd.args[4] = 0xa5;
638 cmd.args[5] = 0xee;
639 cmd.args[6] = 0x03;
640 cmd.args[7] = 0x9d;
641 cmd.args[8] = 0xfc;
642 cmd.args[9] = 0x06;
643 cmd.args[10] = 0x02;
644 cmd.args[11] = 0x9d;
645 cmd.args[12] = 0xfc;
646 cmd.len = 13;
647 ret = cx24117_cmd_execute_nolock(fe, &cmd);
648 if (ret != 0)
649 goto error;
650
651 /* CMD 15 */
652 cmd.args[0] = 0x15;
653 cmd.args[1] = 0x00;
654 cmd.args[2] = 0x01;
655 cmd.args[3] = 0x00;
656 cmd.args[4] = 0x00;
657 cmd.args[5] = 0x01;
658 cmd.args[6] = 0x01;
659 cmd.args[7] = 0x01;
660 cmd.args[8] = 0x00;
661 cmd.args[9] = 0x05;
662 cmd.args[10] = 0x02;
663 cmd.args[11] = 0x02;
664 cmd.args[12] = 0x00;
665 cmd.len = 13;
666 ret = cx24117_cmd_execute_nolock(fe, &cmd);
667 if (ret != 0)
668 goto error;
669
670 /* CMD 13 */
671 cmd.args[0] = CMD_MPEGCONFIG;
672 cmd.args[1] = 0x00;
673 cmd.args[2] = 0x00;
674 cmd.args[3] = 0x00;
675 cmd.args[4] = 0x01;
676 cmd.args[5] = 0x00;
677 cmd.len = 6;
678 ret = cx24117_cmd_execute_nolock(fe, &cmd);
679 if (ret != 0)
680 goto error;
681
682 /* CMD 14 */
683 for (i = 0; i < 2; i++) {
684 cmd.args[0] = CMD_TUNERINIT;
685 cmd.args[1] = (u8) i;
686 cmd.args[2] = 0x00;
687 cmd.args[3] = 0x05;
688 cmd.args[4] = 0x00;
689 cmd.args[5] = 0x00;
690 cmd.args[6] = 0x55;
691 cmd.args[7] = 0x00;
692 cmd.len = 8;
693 ret = cx24117_cmd_execute_nolock(fe, &cmd);
694 if (ret != 0)
695 goto error;
696 }
697
698 cx24117_writereg(state, 0xce, 0xc0);
699 cx24117_writereg(state, 0xcf, 0x00);
700 cx24117_writereg(state, 0xe5, 0x04);
701
702 /* Firmware CMD 35: Get firmware version */
703 cmd.args[0] = CMD_UPDFWVERS;
704 cmd.len = 2;
705 for (i = 0; i < 4; i++) {
706 cmd.args[1] = i;
707 ret = cx24117_cmd_execute_nolock(fe, &cmd);
708 if (ret != 0)
709 goto error;
710 vers[i] = cx24117_readreg(state, 0x33);
711 }
712 dev_info(&state->priv->i2c->dev,
713 "%s: FW version %i.%i.%i.%i\n", __func__,
714 vers[0], vers[1], vers[2], vers[3]);
715 return 0;
716error:
717 state->priv->skip_fw_load = 0;
718 dev_err(&state->priv->i2c->dev, "%s() Error running FW.\n", __func__);
719 return ret;
720}
721
722static int cx24117_read_status(struct dvb_frontend *fe, fe_status_t *status)
723{
724 struct cx24117_state *state = fe->demodulator_priv;
725 int lock;
726
727 lock = cx24117_readreg(state,
728 (state->demod == 0) ? CX24117_REG_SSTATUS0 :
729 CX24117_REG_SSTATUS1) &
730 CX24117_STATUS_MASK;
731
732 dev_dbg(&state->priv->i2c->dev, "%s() demod%d status = 0x%02x\n",
733 __func__, state->demod, lock);
734
735 *status = 0;
736
737 if (lock & CX24117_HAS_SIGNAL)
738 *status |= FE_HAS_SIGNAL;
739 if (lock & CX24117_HAS_CARRIER)
740 *status |= FE_HAS_CARRIER;
741 if (lock & CX24117_HAS_VITERBI)
742 *status |= FE_HAS_VITERBI;
743 if (lock & CX24117_HAS_SYNCLOCK)
744 *status |= FE_HAS_SYNC | FE_HAS_LOCK;
745
746 return 0;
747}
748
749static int cx24117_read_ber(struct dvb_frontend *fe, u32 *ber)
750{
751 struct cx24117_state *state = fe->demodulator_priv;
752 int ret;
753 u8 buf[4];
754 u8 base_reg = (state->demod == 0) ?
755 CX24117_REG_BER4_0 :
756 CX24117_REG_BER4_1;
757
758 ret = cx24117_readregN(state, base_reg, buf, 4);
759 if (ret != 0)
760 return ret;
761
762 *ber = (buf[0] << 24) | (buf[1] << 16) |
763 (buf[1] << 8) | buf[0];
764
765 dev_dbg(&state->priv->i2c->dev, "%s() demod%d ber=0x%04x\n",
766 __func__, state->demod, *ber);
767
768 return 0;
769}
770
771static int cx24117_read_signal_strength(struct dvb_frontend *fe,
772 u16 *signal_strength)
773{
774 struct cx24117_state *state = fe->demodulator_priv;
775 struct cx24117_cmd cmd;
776 int ret;
777 u16 sig_reading;
778 u8 buf[2];
779 u8 reg = (state->demod == 0) ?
780 CX24117_REG_SSTATUS0 : CX24117_REG_SSTATUS1;
781
782 /* Firmware CMD 1A */
783 cmd.args[0] = 0x1a;
784 cmd.args[1] = (u8) state->demod;
785 cmd.len = 2;
786 ret = cx24117_cmd_execute(fe, &cmd);
787 if (ret != 0)
788 return ret;
789
790 ret = cx24117_readregN(state, reg, buf, 2);
791 if (ret != 0)
792 return ret;
793 sig_reading = ((buf[0] & CX24117_SIGNAL_MASK) << 2) | buf[1];
794
795 *signal_strength = -100 * sig_reading + 94324;
796
797 dev_dbg(&state->priv->i2c->dev,
798 "%s() demod%d raw / cooked = 0x%04x / 0x%04x\n",
799 __func__, state->demod, sig_reading, *signal_strength);
800
801 return 0;
802}
803
804static int cx24117_read_snr(struct dvb_frontend *fe, u16 *snr)
805{
806 struct cx24117_state *state = fe->demodulator_priv;
807 int ret;
808 u8 buf[2];
809 u8 reg = (state->demod == 0) ?
810 CX24117_REG_QUALITY2_0 : CX24117_REG_QUALITY2_1;
811
812 ret = cx24117_readregN(state, reg, buf, 2);
813 if (ret != 0)
814 return ret;
815
816 *snr = (buf[0] << 8) | buf[1];
817
818 dev_dbg(&state->priv->i2c->dev,
819 "%s() demod%d snr = 0x%04x\n",
820 __func__, state->demod, *snr);
821
822 return ret;
823}
824
825static int cx24117_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
826{
827 struct cx24117_state *state = fe->demodulator_priv;
828 fe_delivery_system_t delsys = fe->dtv_property_cache.delivery_system;
829 int ret;
830 u8 buf[2];
831 u8 reg = (state->demod == 0) ?
832 CX24117_REG_DVBS_UCB2_0 :
833 CX24117_REG_DVBS_UCB2_1;
834
835 switch (delsys) {
836 case SYS_DVBS:
837 break;
838 case SYS_DVBS2:
839 reg += (CX24117_REG_DVBS2_UCB2_0 - CX24117_REG_DVBS_UCB2_0);
840 break;
841 default:
842 return -EINVAL;
843 }
844
845 ret = cx24117_readregN(state, reg, buf, 2);
846 if (ret != 0)
847 return ret;
848 *ucblocks = (buf[0] << 8) | buf[1];
849
850 dev_dbg(&state->priv->i2c->dev, "%s() demod%d ucb=0x%04x\n",
851 __func__, state->demod, *ucblocks);
852
853 return 0;
854}
855
856/* Overwrite the current tuning params, we are about to tune */
857static void cx24117_clone_params(struct dvb_frontend *fe)
858{
859 struct cx24117_state *state = fe->demodulator_priv;
860 state->dcur = state->dnxt;
861}
862
863/* Wait for LNB */
864static int cx24117_wait_for_lnb(struct dvb_frontend *fe)
865{
866 struct cx24117_state *state = fe->demodulator_priv;
867 int i;
868 u8 val, reg = (state->demod == 0) ? CX24117_REG_QSTATUS0 :
869 CX24117_REG_QSTATUS1;
870
871 dev_dbg(&state->priv->i2c->dev, "%s() demod%d qstatus = 0x%02x\n",
872 __func__, state->demod, cx24117_readreg(state, reg));
873
874 /* Wait for up to 300 ms */
875 for (i = 0; i < 10; i++) {
876 val = cx24117_readreg(state, reg) & 0x01;
877 if (val != 0)
878 return 0;
879 msleep(30);
880 }
881
882 dev_warn(&state->priv->i2c->dev, "%s: demod%d LNB not ready\n",
883 KBUILD_MODNAME, state->demod);
884
885 return -ETIMEDOUT; /* -EBUSY ? */
886}
887
888static int cx24117_set_voltage(struct dvb_frontend *fe,
889 fe_sec_voltage_t voltage)
890{
891 struct cx24117_state *state = fe->demodulator_priv;
892 struct cx24117_cmd cmd;
893 int ret;
894 u8 reg = (state->demod == 0) ? 0x10 : 0x20;
895
896 dev_dbg(&state->priv->i2c->dev, "%s() demod%d %s\n",
897 __func__, state->demod,
898 voltage == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" :
899 voltage == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" :
900 "SEC_VOLTAGE_OFF");
901
902 /* CMD 32 */
903 cmd.args[0] = 0x32;
904 cmd.args[1] = reg;
905 cmd.args[2] = reg;
906 cmd.len = 3;
907 ret = cx24117_cmd_execute(fe, &cmd);
908 if (ret)
909 return ret;
910
911 if ((voltage == SEC_VOLTAGE_13) ||
912 (voltage == SEC_VOLTAGE_18)) {
913 /* CMD 33 */
914 cmd.args[0] = 0x33;
915 cmd.args[1] = reg;
916 cmd.args[2] = reg;
917 cmd.len = 3;
918 ret = cx24117_cmd_execute(fe, &cmd);
919 if (ret != 0)
920 return ret;
921
922 ret = cx24117_wait_for_lnb(fe);
923 if (ret != 0)
924 return ret;
925
926 /* Wait for voltage/min repeat delay */
927 msleep(100);
928
929 /* CMD 22 - CMD_LNBDCLEVEL */
930 cmd.args[0] = CMD_LNBDCLEVEL;
931 cmd.args[1] = state->demod ? 0 : 1;
932 cmd.args[2] = (voltage == SEC_VOLTAGE_18 ? 0x01 : 0x00);
933 cmd.len = 3;
934
935 /* Min delay time before DiSEqC send */
936 msleep(20);
937 } else {
938 cmd.args[0] = 0x33;
939 cmd.args[1] = 0x00;
940 cmd.args[2] = reg;
941 cmd.len = 3;
942 }
943
944 return cx24117_cmd_execute(fe, &cmd);
945}
946
947static int cx24117_set_tone(struct dvb_frontend *fe,
948 fe_sec_tone_mode_t tone)
949{
950 struct cx24117_state *state = fe->demodulator_priv;
951 struct cx24117_cmd cmd;
952 int ret;
953
954 dev_dbg(&state->priv->i2c->dev, "%s(%d) demod%d\n",
955 __func__, state->demod, tone);
956 if ((tone != SEC_TONE_ON) && (tone != SEC_TONE_OFF)) {
957 dev_warn(&state->priv->i2c->dev, "%s: demod%d invalid tone=%d\n",
958 KBUILD_MODNAME, state->demod, tone);
959 return -EINVAL;
960 }
961
962 /* Wait for LNB ready */
963 ret = cx24117_wait_for_lnb(fe);
964 if (ret != 0)
965 return ret;
966
967 /* Min delay time after DiSEqC send */
968 msleep(20);
969
970 /* Set the tone */
971 /* CMD 23 - CMD_SET_TONE */
972 cmd.args[0] = CMD_SET_TONE;
973 cmd.args[1] = (state->demod ? 0 : 1);
974 cmd.args[2] = 0x00;
975 cmd.args[3] = 0x00;
976 cmd.len = 5;
977 switch (tone) {
978 case SEC_TONE_ON:
979 cmd.args[4] = 0x01;
980 break;
981 case SEC_TONE_OFF:
982 cmd.args[4] = 0x00;
983 break;
984 }
985
986 msleep(20);
987
988 return cx24117_cmd_execute(fe, &cmd);
989}
990
991/* Initialise DiSEqC */
992static int cx24117_diseqc_init(struct dvb_frontend *fe)
993{
994 struct cx24117_state *state = fe->demodulator_priv;
995
996 /* Prepare a DiSEqC command */
997 state->dsec_cmd.args[0] = CMD_LNBSEND;
998
999 /* demod */
1000 state->dsec_cmd.args[CX24117_DISEQC_DEMOD] = state->demod ? 0 : 1;
1001
1002 /* DiSEqC burst */
1003 state->dsec_cmd.args[CX24117_DISEQC_BURST] = CX24117_DISEQC_MINI_A;
1004
1005 /* Unknown */
1006 state->dsec_cmd.args[CX24117_DISEQC_ARG3_2] = 0x02;
1007 state->dsec_cmd.args[CX24117_DISEQC_ARG4_0] = 0x00;
1008
1009 /* Continuation flag? */
1010 state->dsec_cmd.args[CX24117_DISEQC_ARG5_0] = 0x00;
1011
1012 /* DiSEqC message length */
1013 state->dsec_cmd.args[CX24117_DISEQC_MSGLEN] = 0x00;
1014
1015 /* Command length */
1016 state->dsec_cmd.len = 7;
1017
1018 return 0;
1019}
1020
1021/* Send DiSEqC message */
1022static int cx24117_send_diseqc_msg(struct dvb_frontend *fe,
1023 struct dvb_diseqc_master_cmd *d)
1024{
1025 struct cx24117_state *state = fe->demodulator_priv;
1026 int i, ret;
1027
1028 /* Dump DiSEqC message */
1029 dev_dbg(&state->priv->i2c->dev, "%s: demod %d (",
1030 __func__, state->demod);
1031 for (i = 0; i < d->msg_len; i++)
1032 dev_dbg(&state->priv->i2c->dev, "0x%02x ", d->msg[i]);
1033 dev_dbg(&state->priv->i2c->dev, ")\n");
1034
1035 /* Validate length */
1036 if (d->msg_len > 15)
1037 return -EINVAL;
1038
1039 /* DiSEqC message */
1040 for (i = 0; i < d->msg_len; i++)
1041 state->dsec_cmd.args[CX24117_DISEQC_MSGOFS + i] = d->msg[i];
1042
1043 /* DiSEqC message length */
1044 state->dsec_cmd.args[CX24117_DISEQC_MSGLEN] = d->msg_len;
1045
1046 /* Command length */
1047 state->dsec_cmd.len = CX24117_DISEQC_MSGOFS +
1048 state->dsec_cmd.args[CX24117_DISEQC_MSGLEN];
1049
1050 /*
1051 * Message is sent with derived else cached burst
1052 *
1053 * WRITE PORT GROUP COMMAND 38
1054 *
1055 * 0/A/A: E0 10 38 F0..F3
1056 * 1/B/B: E0 10 38 F4..F7
1057 * 2/C/A: E0 10 38 F8..FB
1058 * 3/D/B: E0 10 38 FC..FF
1059 *
1060 * databyte[3]= 8421:8421
1061 * ABCD:WXYZ
1062 * CLR :SET
1063 *
1064 * WX= PORT SELECT 0..3 (X=TONEBURST)
1065 * Y = VOLTAGE (0=13V, 1=18V)
1066 * Z = BAND (0=LOW, 1=HIGH(22K))
1067 */
1068 if (d->msg_len >= 4 && d->msg[2] == 0x38)
1069 state->dsec_cmd.args[CX24117_DISEQC_BURST] =
1070 ((d->msg[3] & 4) >> 2);
1071
1072 dev_dbg(&state->priv->i2c->dev, "%s() demod%d burst=%d\n",
1073 __func__, state->demod,
1074 state->dsec_cmd.args[CX24117_DISEQC_BURST]);
1075
1076 /* Wait for LNB ready */
1077 ret = cx24117_wait_for_lnb(fe);
1078 if (ret != 0)
1079 return ret;
1080
1081 /* Wait for voltage/min repeat delay */
1082 msleep(100);
1083
1084 /* Command */
1085 ret = cx24117_cmd_execute(fe, &state->dsec_cmd);
1086 if (ret != 0)
1087 return ret;
1088 /*
1089 * Wait for send
1090 *
1091 * Eutelsat spec:
1092 * >15ms delay + (XXX determine if FW does this, see set_tone)
1093 * 13.5ms per byte +
1094 * >15ms delay +
1095 * 12.5ms burst +
1096 * >15ms delay (XXX determine if FW does this, see set_tone)
1097 */
1098 msleep((state->dsec_cmd.args[CX24117_DISEQC_MSGLEN] << 4) + 60);
1099
1100 return 0;
1101}
1102
1103/* Send DiSEqC burst */
1104static int cx24117_diseqc_send_burst(struct dvb_frontend *fe,
1105 fe_sec_mini_cmd_t burst)
1106{
1107 struct cx24117_state *state = fe->demodulator_priv;
1108
1109 dev_dbg(&state->priv->i2c->dev, "%s(%d) demod=%d\n",
1110 __func__, burst, state->demod);
1111
1112 /* DiSEqC burst */
1113 if (burst == SEC_MINI_A)
1114 state->dsec_cmd.args[CX24117_DISEQC_BURST] =
1115 CX24117_DISEQC_MINI_A;
1116 else if (burst == SEC_MINI_B)
1117 state->dsec_cmd.args[CX24117_DISEQC_BURST] =
1118 CX24117_DISEQC_MINI_B;
1119 else
1120 return -EINVAL;
1121
1122 return 0;
1123}
1124
1125static int cx24117_get_priv(struct cx24117_priv **priv,
1126 struct i2c_adapter *i2c, u8 client_address)
1127{
1128 int ret;
1129
1130 mutex_lock(&cx24117_list_mutex);
1131 ret = hybrid_tuner_request_state(struct cx24117_priv, (*priv),
1132 hybrid_tuner_instance_list, i2c, client_address, "cx24117");
1133 mutex_unlock(&cx24117_list_mutex);
1134
1135 return ret;
1136}
1137
1138static void cx24117_release_priv(struct cx24117_priv *priv)
1139{
1140 mutex_lock(&cx24117_list_mutex);
1141 if (priv != NULL)
1142 hybrid_tuner_release_state(priv);
1143 mutex_unlock(&cx24117_list_mutex);
1144}
1145
1146static void cx24117_release(struct dvb_frontend *fe)
1147{
1148 struct cx24117_state *state = fe->demodulator_priv;
1149 dev_dbg(&state->priv->i2c->dev, "%s demod%d\n",
1150 __func__, state->demod);
1151 cx24117_release_priv(state->priv);
1152 kfree(state);
1153}
1154
1155static struct dvb_frontend_ops cx24117_ops;
1156
1157struct dvb_frontend *cx24117_attach(const struct cx24117_config *config,
1158 struct i2c_adapter *i2c)
1159{
1160 struct cx24117_state *state = NULL;
1161 struct cx24117_priv *priv = NULL;
1162 int demod = 0;
1163
1164 /* get the common data struct for both demods */
1165 demod = cx24117_get_priv(&priv, i2c, config->demod_address);
1166
1167 switch (demod) {
1168 case 0:
1169 dev_err(&state->priv->i2c->dev,
1170 "%s: Error attaching frontend %d\n",
1171 KBUILD_MODNAME, demod);
1172 goto error1;
1173 break;
1174 case 1:
1175 /* new priv instance */
1176 priv->i2c = i2c;
1177 priv->demod_address = config->demod_address;
1178 mutex_init(&priv->fe_lock);
1179 break;
1180 default:
1181 /* existing priv instance */
1182 break;
1183 }
1184
1185 /* allocate memory for the internal state */
1186 state = kzalloc(sizeof(struct cx24117_state), GFP_KERNEL);
1187 if (state == NULL)
1188 goto error2;
1189
1190 state->demod = demod - 1;
1191 state->priv = priv;
1192
1193 /* test i2c bus for ack */
1194 if (demod == 0) {
1195 if (cx24117_readreg(state, 0x00) < 0)
1196 goto error3;
1197 }
1198
1199 dev_info(&state->priv->i2c->dev,
1200 "%s: Attaching frontend %d\n",
1201 KBUILD_MODNAME, state->demod);
1202
1203 /* create dvb_frontend */
1204 memcpy(&state->frontend.ops, &cx24117_ops,
1205 sizeof(struct dvb_frontend_ops));
1206 state->frontend.demodulator_priv = state;
1207 return &state->frontend;
1208
1209error3:
1210 kfree(state);
1211error2:
1212 cx24117_release_priv(priv);
1213error1:
1214 return NULL;
1215}
1216EXPORT_SYMBOL_GPL(cx24117_attach);
1217
1218/*
1219 * Initialise or wake up device
1220 *
1221 * Power config will reset and load initial firmware if required
1222 */
1223static int cx24117_initfe(struct dvb_frontend *fe)
1224{
1225 struct cx24117_state *state = fe->demodulator_priv;
1226 struct cx24117_cmd cmd;
1227 int ret;
1228
1229 dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
1230 __func__, state->demod);
1231
1232 mutex_lock(&state->priv->fe_lock);
1233
1234 /* Firmware CMD 36: Power config */
1235 cmd.args[0] = CMD_TUNERSLEEP;
1236 cmd.args[1] = (state->demod ? 1 : 0);
1237 cmd.args[2] = 0;
1238 cmd.len = 3;
1239 ret = cx24117_cmd_execute_nolock(fe, &cmd);
1240 if (ret != 0)
1241 goto exit;
1242
1243 ret = cx24117_diseqc_init(fe);
1244 if (ret != 0)
1245 goto exit;
1246
1247 /* CMD 3C */
1248 cmd.args[0] = 0x3c;
1249 cmd.args[1] = (state->demod ? 1 : 0);
1250 cmd.args[2] = 0x10;
1251 cmd.args[3] = 0x10;
1252 cmd.len = 4;
1253 ret = cx24117_cmd_execute_nolock(fe, &cmd);
1254 if (ret != 0)
1255 goto exit;
1256
1257 /* CMD 34 */
1258 cmd.args[0] = 0x34;
1259 cmd.args[1] = (state->demod ? 1 : 0);
1260 cmd.args[2] = CX24117_OCC;
1261 cmd.len = 3;
1262 ret = cx24117_cmd_execute_nolock(fe, &cmd);
1263
1264exit:
1265 mutex_unlock(&state->priv->fe_lock);
1266
1267 return ret;
1268}
1269
1270/*
1271 * Put device to sleep
1272 */
1273static int cx24117_sleep(struct dvb_frontend *fe)
1274{
1275 struct cx24117_state *state = fe->demodulator_priv;
1276 struct cx24117_cmd cmd;
1277
1278 dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
1279 __func__, state->demod);
1280
1281 /* Firmware CMD 36: Power config */
1282 cmd.args[0] = CMD_TUNERSLEEP;
1283 cmd.args[1] = (state->demod ? 1 : 0);
1284 cmd.args[2] = 1;
1285 cmd.len = 3;
1286 return cx24117_cmd_execute(fe, &cmd);
1287}
1288
1289/* dvb-core told us to tune, the tv property cache will be complete,
1290 * it's safe for is to pull values and use them for tuning purposes.
1291 */
1292static int cx24117_set_frontend(struct dvb_frontend *fe)
1293{
1294 struct cx24117_state *state = fe->demodulator_priv;
1295 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1296 struct cx24117_cmd cmd;
1297 fe_status_t tunerstat;
1298 int i, status, ret, retune = 1;
1299 u8 reg_clkdiv, reg_ratediv;
1300
1301 dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
1302 __func__, state->demod);
1303
1304 switch (c->delivery_system) {
1305 case SYS_DVBS:
1306 dev_dbg(&state->priv->i2c->dev, "%s() demod%d DVB-S\n",
1307 __func__, state->demod);
1308
1309 /* Only QPSK is supported for DVB-S */
1310 if (c->modulation != QPSK) {
1311 dev_dbg(&state->priv->i2c->dev,
1312 "%s() demod%d unsupported modulation (%d)\n",
1313 __func__, state->demod, c->modulation);
1314 return -EINVAL;
1315 }
1316
1317 /* Pilot doesn't exist in DVB-S, turn bit off */
1318 state->dnxt.pilot_val = CX24117_PILOT_OFF;
1319
1320 /* DVB-S only supports 0.35 */
1321 state->dnxt.rolloff_val = CX24117_ROLLOFF_035;
1322 break;
1323
1324 case SYS_DVBS2:
1325 dev_dbg(&state->priv->i2c->dev, "%s() demod%d DVB-S2\n",
1326 __func__, state->demod);
1327
1328 /*
1329 * NBC 8PSK/QPSK with DVB-S is supported for DVB-S2,
1330 * but not hardware auto detection
1331 */
1332 if (c->modulation != PSK_8 && c->modulation != QPSK) {
1333 dev_dbg(&state->priv->i2c->dev,
1334 "%s() demod%d unsupported modulation (%d)\n",
1335 __func__, state->demod, c->modulation);
1336 return -EOPNOTSUPP;
1337 }
1338
1339 switch (c->pilot) {
1340 case PILOT_AUTO:
1341 state->dnxt.pilot_val = CX24117_PILOT_AUTO;
1342 break;
1343 case PILOT_OFF:
1344 state->dnxt.pilot_val = CX24117_PILOT_OFF;
1345 break;
1346 case PILOT_ON:
1347 state->dnxt.pilot_val = CX24117_PILOT_ON;
1348 break;
1349 default:
1350 dev_dbg(&state->priv->i2c->dev,
1351 "%s() demod%d unsupported pilot mode (%d)\n",
1352 __func__, state->demod, c->pilot);
1353 return -EOPNOTSUPP;
1354 }
1355
1356 switch (c->rolloff) {
1357 case ROLLOFF_20:
1358 state->dnxt.rolloff_val = CX24117_ROLLOFF_020;
1359 break;
1360 case ROLLOFF_25:
1361 state->dnxt.rolloff_val = CX24117_ROLLOFF_025;
1362 break;
1363 case ROLLOFF_35:
1364 state->dnxt.rolloff_val = CX24117_ROLLOFF_035;
1365 break;
1366 case ROLLOFF_AUTO:
1367 state->dnxt.rolloff_val = CX24117_ROLLOFF_035;
1368 /* soft-auto rolloff */
1369 retune = 3;
1370 break;
1371 default:
1372 dev_warn(&state->priv->i2c->dev,
1373 "%s: demod%d unsupported rolloff (%d)\n",
1374 KBUILD_MODNAME, state->demod, c->rolloff);
1375 return -EOPNOTSUPP;
1376 }
1377 break;
1378
1379 default:
1380 dev_warn(&state->priv->i2c->dev,
1381 "%s: demod %d unsupported delivery system (%d)\n",
1382 KBUILD_MODNAME, state->demod, c->delivery_system);
1383 return -EINVAL;
1384 }
1385
1386 state->dnxt.delsys = c->delivery_system;
1387 state->dnxt.modulation = c->modulation;
1388 state->dnxt.frequency = c->frequency;
1389 state->dnxt.pilot = c->pilot;
1390 state->dnxt.rolloff = c->rolloff;
1391
1392 ret = cx24117_set_inversion(state, c->inversion);
1393 if (ret != 0)
1394 return ret;
1395
1396 ret = cx24117_set_fec(state,
1397 c->delivery_system, c->modulation, c->fec_inner);
1398 if (ret != 0)
1399 return ret;
1400
1401 ret = cx24117_set_symbolrate(state, c->symbol_rate);
1402 if (ret != 0)
1403 return ret;
1404
1405 /* discard the 'current' tuning parameters and prepare to tune */
1406 cx24117_clone_params(fe);
1407
1408 dev_dbg(&state->priv->i2c->dev,
1409 "%s: delsys = %d\n", __func__, state->dcur.delsys);
1410 dev_dbg(&state->priv->i2c->dev,
1411 "%s: modulation = %d\n", __func__, state->dcur.modulation);
1412 dev_dbg(&state->priv->i2c->dev,
1413 "%s: frequency = %d\n", __func__, state->dcur.frequency);
1414 dev_dbg(&state->priv->i2c->dev,
1415 "%s: pilot = %d (val = 0x%02x)\n", __func__,
1416 state->dcur.pilot, state->dcur.pilot_val);
1417 dev_dbg(&state->priv->i2c->dev,
1418 "%s: retune = %d\n", __func__, retune);
1419 dev_dbg(&state->priv->i2c->dev,
1420 "%s: rolloff = %d (val = 0x%02x)\n", __func__,
1421 state->dcur.rolloff, state->dcur.rolloff_val);
1422 dev_dbg(&state->priv->i2c->dev,
1423 "%s: symbol_rate = %d\n", __func__, state->dcur.symbol_rate);
1424 dev_dbg(&state->priv->i2c->dev,
1425 "%s: FEC = %d (mask/val = 0x%02x/0x%02x)\n", __func__,
1426 state->dcur.fec, state->dcur.fec_mask, state->dcur.fec_val);
1427 dev_dbg(&state->priv->i2c->dev,
1428 "%s: Inversion = %d (val = 0x%02x)\n", __func__,
1429 state->dcur.inversion, state->dcur.inversion_val);
1430
1431 /* Prepare a tune request */
1432 cmd.args[0] = CMD_TUNEREQUEST;
1433
1434 /* demod */
1435 cmd.args[1] = state->demod;
1436
1437 /* Frequency */
1438 cmd.args[2] = (state->dcur.frequency & 0xff0000) >> 16;
1439 cmd.args[3] = (state->dcur.frequency & 0x00ff00) >> 8;
1440 cmd.args[4] = (state->dcur.frequency & 0x0000ff);
1441
1442 /* Symbol Rate */
1443 cmd.args[5] = ((state->dcur.symbol_rate / 1000) & 0xff00) >> 8;
1444 cmd.args[6] = ((state->dcur.symbol_rate / 1000) & 0x00ff);
1445
1446 /* Automatic Inversion */
1447 cmd.args[7] = state->dcur.inversion_val;
1448
1449 /* Modulation / FEC / Pilot */
1450 cmd.args[8] = state->dcur.fec_val | state->dcur.pilot_val;
1451
1452 cmd.args[9] = CX24117_SEARCH_RANGE_KHZ >> 8;
1453 cmd.args[10] = CX24117_SEARCH_RANGE_KHZ & 0xff;
1454
1455 cmd.args[11] = state->dcur.rolloff_val;
1456 cmd.args[12] = state->dcur.fec_mask;
1457
1458 if (state->dcur.symbol_rate > 30000000) {
1459 reg_ratediv = 0x04;
1460 reg_clkdiv = 0x02;
1461 } else if (state->dcur.symbol_rate > 10000000) {
1462 reg_ratediv = 0x06;
1463 reg_clkdiv = 0x03;
1464 } else {
1465 reg_ratediv = 0x0a;
1466 reg_clkdiv = 0x05;
1467 }
1468
1469 cmd.args[13] = reg_ratediv;
1470 cmd.args[14] = reg_clkdiv;
1471
1472 cx24117_writereg(state, (state->demod == 0) ?
1473 CX24117_REG_CLKDIV0 : CX24117_REG_CLKDIV1, reg_clkdiv);
1474 cx24117_writereg(state, (state->demod == 0) ?
1475 CX24117_REG_RATEDIV0 : CX24117_REG_RATEDIV1, reg_ratediv);
1476
1477 cmd.args[15] = CX24117_PNE;
1478 cmd.len = 16;
1479
1480 do {
1481 /* Reset status register */
1482 status = cx24117_readreg(state, (state->demod == 0) ?
1483 CX24117_REG_SSTATUS0 : CX24117_REG_SSTATUS1) &
1484 CX24117_SIGNAL_MASK;
1485
1486 dev_dbg(&state->priv->i2c->dev,
1487 "%s() demod%d status_setfe = %02x\n",
1488 __func__, state->demod, status);
1489
1490 cx24117_writereg(state, (state->demod == 0) ?
1491 CX24117_REG_SSTATUS0 : CX24117_REG_SSTATUS1, status);
1492
1493 /* Tune */
1494 ret = cx24117_cmd_execute(fe, &cmd);
1495 if (ret != 0)
1496 break;
1497
1498 /*
1499 * Wait for up to 500 ms before retrying
1500 *
1501 * If we are able to tune then generally it occurs within 100ms.
1502 * If it takes longer, try a different rolloff setting.
1503 */
1504 for (i = 0; i < 50; i++) {
1505 cx24117_read_status(fe, &tunerstat);
1506 status = tunerstat & (FE_HAS_SIGNAL | FE_HAS_SYNC);
1507 if (status == (FE_HAS_SIGNAL | FE_HAS_SYNC)) {
1508 dev_dbg(&state->priv->i2c->dev,
1509 "%s() demod%d tuned\n",
1510 __func__, state->demod);
1511 return 0;
1512 }
1513 msleep(20);
1514 }
1515
1516 dev_dbg(&state->priv->i2c->dev, "%s() demod%d not tuned\n",
1517 __func__, state->demod);
1518
1519 /* try next rolloff value */
1520 if (state->dcur.rolloff == 3)
1521 cmd.args[11]--;
1522
1523 } while (--retune);
1524 return -EINVAL;
1525}
1526
1527static int cx24117_tune(struct dvb_frontend *fe, bool re_tune,
1528 unsigned int mode_flags, unsigned int *delay, fe_status_t *status)
1529{
1530 struct cx24117_state *state = fe->demodulator_priv;
1531
1532 dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
1533 __func__, state->demod);
1534
1535 *delay = HZ / 5;
1536 if (re_tune) {
1537 int ret = cx24117_set_frontend(fe);
1538 if (ret)
1539 return ret;
1540 }
1541 return cx24117_read_status(fe, status);
1542}
1543
1544static int cx24117_get_algo(struct dvb_frontend *fe)
1545{
1546 return DVBFE_ALGO_HW;
1547}
1548
1549static int cx24117_get_frontend(struct dvb_frontend *fe)
1550{
1551 struct cx24117_state *state = fe->demodulator_priv;
1552 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1553 struct cx24117_cmd cmd;
1554 u8 reg, st, inv;
1555 int ret, idx;
1556 unsigned int freq;
1557 short srate_os, freq_os;
1558
1559 u8 buf[0x1f-4];
1560
1561 cmd.args[0] = 0x1c;
1562 cmd.args[1] = (u8) state->demod;
1563 cmd.len = 2;
1564 ret = cx24117_cmd_execute(fe, &cmd);
1565 if (ret != 0)
1566 return ret;
1567
1568 /* read all required regs at once */
1569 reg = (state->demod == 0) ? CX24117_REG_FREQ3_0 : CX24117_REG_FREQ3_1;
1570 ret = cx24117_readregN(state, reg, buf, 0x1f-4);
1571 if (ret != 0)
1572 return ret;
1573
1574 st = buf[5];
1575
1576 /* get spectral inversion */
1577 inv = (((state->demod == 0) ? ~st : st) >> 6) & 1;
1578 if (inv == 0)
1579 c->inversion = INVERSION_OFF;
1580 else
1581 c->inversion = INVERSION_ON;
1582
1583 /* modulation and fec */
1584 idx = st & 0x3f;
1585 if (c->delivery_system == SYS_DVBS2) {
1586 if (idx > 11)
1587 idx += 9;
1588 else
1589 idx += 7;
1590 }
1591
1592 c->modulation = cx24117_modfec_modes[idx].modulation;
1593 c->fec_inner = cx24117_modfec_modes[idx].fec;
1594
1595 /* frequency */
1596 freq = (buf[0] << 16) | (buf[1] << 8) | buf[2];
1597 freq_os = (buf[8] << 8) | buf[9];
1598 c->frequency = freq + freq_os;
1599
1600 /* symbol rate */
1601 srate_os = (buf[10] << 8) | buf[11];
1602 c->symbol_rate = -1000 * srate_os + state->dcur.symbol_rate;
1603 return 0;
1604}
1605
1606static struct dvb_frontend_ops cx24117_ops = {
1607 .delsys = { SYS_DVBS, SYS_DVBS2 },
1608 .info = {
1609 .name = "Conexant CX24117/CX24132",
1610 .frequency_min = 950000,
1611 .frequency_max = 2150000,
1612 .frequency_stepsize = 1011, /* kHz for QPSK frontends */
1613 .frequency_tolerance = 5000,
1614 .symbol_rate_min = 1000000,
1615 .symbol_rate_max = 45000000,
1616 .caps = FE_CAN_INVERSION_AUTO |
1617 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
1618 FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |
1619 FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
1620 FE_CAN_2G_MODULATION |
1621 FE_CAN_QPSK | FE_CAN_RECOVER
1622 },
1623
1624 .release = cx24117_release,
1625
1626 .init = cx24117_initfe,
1627 .sleep = cx24117_sleep,
1628 .read_status = cx24117_read_status,
1629 .read_ber = cx24117_read_ber,
1630 .read_signal_strength = cx24117_read_signal_strength,
1631 .read_snr = cx24117_read_snr,
1632 .read_ucblocks = cx24117_read_ucblocks,
1633 .set_tone = cx24117_set_tone,
1634 .set_voltage = cx24117_set_voltage,
1635 .diseqc_send_master_cmd = cx24117_send_diseqc_msg,
1636 .diseqc_send_burst = cx24117_diseqc_send_burst,
1637 .get_frontend_algo = cx24117_get_algo,
1638 .tune = cx24117_tune,
1639
1640 .set_frontend = cx24117_set_frontend,
1641 .get_frontend = cx24117_get_frontend,
1642};
1643
1644
1645MODULE_DESCRIPTION("DVB Frontend module for Conexant cx24117/cx24132 hardware");
1646MODULE_AUTHOR("Luis Alves (ljalvs@gmail.com)");
1647MODULE_LICENSE("GPL");
1648MODULE_VERSION("1.1");
1649MODULE_FIRMWARE(CX24117_DEFAULT_FIRMWARE);
1650
diff --git a/drivers/media/dvb-frontends/cx24117.h b/drivers/media/dvb-frontends/cx24117.h
new file mode 100644
index 000000000000..4e59e9574fa7
--- /dev/null
+++ b/drivers/media/dvb-frontends/cx24117.h
@@ -0,0 +1,47 @@
1/*
2 Conexant cx24117/cx24132 - Dual DVBS/S2 Satellite demod/tuner driver
3
4 Copyright (C) 2013 Luis Alves <ljalvs@gmail.com>
5 (based on cx24116.h by Steven Toth)
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 CX24117_H
23#define CX24117_H
24
25#include <linux/kconfig.h>
26#include <linux/dvb/frontend.h>
27
28struct cx24117_config {
29 /* the demodulator's i2c address */
30 u8 demod_address;
31};
32
33#if IS_ENABLED(CONFIG_DVB_CX24117)
34extern struct dvb_frontend *cx24117_attach(
35 const struct cx24117_config *config,
36 struct i2c_adapter *i2c);
37#else
38static inline struct dvb_frontend *cx24117_attach(
39 const struct cx24117_config *config,
40 struct i2c_adapter *i2c)
41{
42 dev_warn(&i2c->dev, "%s: driver disabled by Kconfig\n", __func__);
43 return NULL;
44}
45#endif
46
47#endif /* CX24117_H */
diff --git a/drivers/media/dvb-frontends/cx24123.c b/drivers/media/dvb-frontends/cx24123.c
index a771da3e9f99..72fb5838cae0 100644
--- a/drivers/media/dvb-frontends/cx24123.c
+++ b/drivers/media/dvb-frontends/cx24123.c
@@ -739,7 +739,7 @@ static int cx24123_set_voltage(struct dvb_frontend *fe,
739 return 0; 739 return 0;
740 default: 740 default:
741 return -EINVAL; 741 return -EINVAL;
742 }; 742 }
743 743
744 return 0; 744 return 0;
745} 745}
diff --git a/drivers/media/dvb-frontends/cxd2820r_core.c b/drivers/media/dvb-frontends/cxd2820r_core.c
index 7ca5c69dd200..03930d5e9fea 100644
--- a/drivers/media/dvb-frontends/cxd2820r_core.c
+++ b/drivers/media/dvb-frontends/cxd2820r_core.c
@@ -21,21 +21,31 @@
21 21
22#include "cxd2820r_priv.h" 22#include "cxd2820r_priv.h"
23 23
24/* Max transfer size done by I2C transfer functions */
25#define MAX_XFER_SIZE 64
26
24/* write multiple registers */ 27/* write multiple registers */
25static int cxd2820r_wr_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg, 28static int cxd2820r_wr_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg,
26 u8 *val, int len) 29 u8 *val, int len)
27{ 30{
28 int ret; 31 int ret;
29 u8 buf[len+1]; 32 u8 buf[MAX_XFER_SIZE];
30 struct i2c_msg msg[1] = { 33 struct i2c_msg msg[1] = {
31 { 34 {
32 .addr = i2c, 35 .addr = i2c,
33 .flags = 0, 36 .flags = 0,
34 .len = sizeof(buf), 37 .len = len + 1,
35 .buf = buf, 38 .buf = buf,
36 } 39 }
37 }; 40 };
38 41
42 if (1 + len > sizeof(buf)) {
43 dev_warn(&priv->i2c->dev,
44 "%s: i2c wr reg=%04x: len=%d is too big!\n",
45 KBUILD_MODNAME, reg, len);
46 return -EINVAL;
47 }
48
39 buf[0] = reg; 49 buf[0] = reg;
40 memcpy(&buf[1], val, len); 50 memcpy(&buf[1], val, len);
41 51
@@ -55,7 +65,7 @@ static int cxd2820r_rd_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg,
55 u8 *val, int len) 65 u8 *val, int len)
56{ 66{
57 int ret; 67 int ret;
58 u8 buf[len]; 68 u8 buf[MAX_XFER_SIZE];
59 struct i2c_msg msg[2] = { 69 struct i2c_msg msg[2] = {
60 { 70 {
61 .addr = i2c, 71 .addr = i2c,
@@ -65,11 +75,18 @@ static int cxd2820r_rd_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg,
65 }, { 75 }, {
66 .addr = i2c, 76 .addr = i2c,
67 .flags = I2C_M_RD, 77 .flags = I2C_M_RD,
68 .len = sizeof(buf), 78 .len = len,
69 .buf = buf, 79 .buf = buf,
70 } 80 }
71 }; 81 };
72 82
83 if (len > sizeof(buf)) {
84 dev_warn(&priv->i2c->dev,
85 "%s: i2c wr reg=%04x: len=%d is too big!\n",
86 KBUILD_MODNAME, reg, len);
87 return -EINVAL;
88 }
89
73 ret = i2c_transfer(priv->i2c, msg, 2); 90 ret = i2c_transfer(priv->i2c, msg, 2);
74 if (ret == 2) { 91 if (ret == 2) {
75 memcpy(val, buf, len); 92 memcpy(val, buf, len);
diff --git a/drivers/media/dvb-frontends/dib9000.c b/drivers/media/dvb-frontends/dib9000.c
index 6201c59a78dd..e540cfb13bac 100644
--- a/drivers/media/dvb-frontends/dib9000.c
+++ b/drivers/media/dvb-frontends/dib9000.c
@@ -649,9 +649,9 @@ static int dib9000_risc_debug_buf(struct dib9000_state *state, u16 * data, u8 si
649 b[2 * (size - 2) - 1] = '\0'; /* Bullet proof the buffer */ 649 b[2 * (size - 2) - 1] = '\0'; /* Bullet proof the buffer */
650 if (*b == '~') { 650 if (*b == '~') {
651 b++; 651 b++;
652 dprintk(b); 652 dprintk("%s", b);
653 } else 653 } else
654 dprintk("RISC%d: %d.%04d %s", state->fe_id, ts / 10000, ts % 10000, *b ? b : "<emtpy>"); 654 dprintk("RISC%d: %d.%04d %s", state->fe_id, ts / 10000, ts % 10000, *b ? b : "<empty>");
655 return 1; 655 return 1;
656} 656}
657 657
diff --git a/drivers/media/dvb-frontends/drxd_hard.c b/drivers/media/dvb-frontends/drxd_hard.c
index 9a2134792cfa..959ae36403b8 100644
--- a/drivers/media/dvb-frontends/drxd_hard.c
+++ b/drivers/media/dvb-frontends/drxd_hard.c
@@ -46,10 +46,6 @@
46#define DRX_I2C_MODEFLAGS 0xC0 46#define DRX_I2C_MODEFLAGS 0xC0
47#define DRX_I2C_FLAGS 0xF0 47#define DRX_I2C_FLAGS 0xF0
48 48
49#ifndef SIZEOF_ARRAY
50#define SIZEOF_ARRAY(array) (sizeof((array))/sizeof((array)[0]))
51#endif
52
53#define DEFAULT_LOCK_TIMEOUT 1100 49#define DEFAULT_LOCK_TIMEOUT 1100
54 50
55#define DRX_CHANNEL_AUTO 0 51#define DRX_CHANNEL_AUTO 0
@@ -1018,7 +1014,7 @@ static int HI_CfgCommand(struct drxd_state *state)
1018 status = Write16(state, HI_RA_RAM_SRV_CMD__A, 1014 status = Write16(state, HI_RA_RAM_SRV_CMD__A,
1019 HI_RA_RAM_SRV_CMD_CONFIG, 0); 1015 HI_RA_RAM_SRV_CMD_CONFIG, 0);
1020 else 1016 else
1021 status = HI_Command(state, HI_RA_RAM_SRV_CMD_CONFIG, 0); 1017 status = HI_Command(state, HI_RA_RAM_SRV_CMD_CONFIG, NULL);
1022 mutex_unlock(&state->mutex); 1018 mutex_unlock(&state->mutex);
1023 return status; 1019 return status;
1024} 1020}
@@ -1039,7 +1035,7 @@ static int HI_ResetCommand(struct drxd_state *state)
1039 status = Write16(state, HI_RA_RAM_SRV_RST_KEY__A, 1035 status = Write16(state, HI_RA_RAM_SRV_RST_KEY__A,
1040 HI_RA_RAM_SRV_RST_KEY_ACT, 0); 1036 HI_RA_RAM_SRV_RST_KEY_ACT, 0);
1041 if (status == 0) 1037 if (status == 0)
1042 status = HI_Command(state, HI_RA_RAM_SRV_CMD_RESET, 0); 1038 status = HI_Command(state, HI_RA_RAM_SRV_CMD_RESET, NULL);
1043 mutex_unlock(&state->mutex); 1039 mutex_unlock(&state->mutex);
1044 msleep(1); 1040 msleep(1);
1045 return status; 1041 return status;
@@ -2837,7 +2833,7 @@ static int drxd_init(struct dvb_frontend *fe)
2837 int err = 0; 2833 int err = 0;
2838 2834
2839/* if (request_firmware(&state->fw, "drxd.fw", state->dev)<0) */ 2835/* if (request_firmware(&state->fw, "drxd.fw", state->dev)<0) */
2840 return DRXD_init(state, 0, 0); 2836 return DRXD_init(state, NULL, 0);
2841 2837
2842 err = DRXD_init(state, state->fw->data, state->fw->size); 2838 err = DRXD_init(state, state->fw->data, state->fw->size);
2843 release_firmware(state->fw); 2839 release_firmware(state->fw);
@@ -2973,7 +2969,7 @@ struct dvb_frontend *drxd_attach(const struct drxd_config *config,
2973 2969
2974 mutex_init(&state->mutex); 2970 mutex_init(&state->mutex);
2975 2971
2976 if (Read16(state, 0, 0, 0) < 0) 2972 if (Read16(state, 0, NULL, 0) < 0)
2977 goto error; 2973 goto error;
2978 2974
2979 state->frontend.ops = drxd_ops; 2975 state->frontend.ops = drxd_ops;
diff --git a/drivers/media/dvb-frontends/drxk_hard.c b/drivers/media/dvb-frontends/drxk_hard.c
index 082014de6875..d416c15691da 100644
--- a/drivers/media/dvb-frontends/drxk_hard.c
+++ b/drivers/media/dvb-frontends/drxk_hard.c
@@ -1083,7 +1083,7 @@ static int hi_cfg_command(struct drxk_state *state)
1083 SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY); 1083 SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY);
1084 if (status < 0) 1084 if (status < 0)
1085 goto error; 1085 goto error;
1086 status = hi_command(state, SIO_HI_RA_RAM_CMD_CONFIG, 0); 1086 status = hi_command(state, SIO_HI_RA_RAM_CMD_CONFIG, NULL);
1087 if (status < 0) 1087 if (status < 0)
1088 goto error; 1088 goto error;
1089 1089
@@ -2781,7 +2781,7 @@ static int ConfigureI2CBridge(struct drxk_state *state, bool b_enable_bridge)
2781 goto error; 2781 goto error;
2782 } 2782 }
2783 2783
2784 status = hi_command(state, SIO_HI_RA_RAM_CMD_BRDCTRL, 0); 2784 status = hi_command(state, SIO_HI_RA_RAM_CMD_BRDCTRL, NULL);
2785 2785
2786error: 2786error:
2787 if (status < 0) 2787 if (status < 0)
diff --git a/drivers/media/dvb-frontends/itd1000.c b/drivers/media/dvb-frontends/itd1000.c
index c1c3400b2173..cadcae4cff89 100644
--- a/drivers/media/dvb-frontends/itd1000.c
+++ b/drivers/media/dvb-frontends/itd1000.c
@@ -31,6 +31,9 @@
31#include "itd1000.h" 31#include "itd1000.h"
32#include "itd1000_priv.h" 32#include "itd1000_priv.h"
33 33
34/* Max transfer size done by I2C transfer functions */
35#define MAX_XFER_SIZE 64
36
34static int debug; 37static int debug;
35module_param(debug, int, 0644); 38module_param(debug, int, 0644);
36MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); 39MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
@@ -52,10 +55,18 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
52/* don't write more than one byte with flexcop behind */ 55/* don't write more than one byte with flexcop behind */
53static int itd1000_write_regs(struct itd1000_state *state, u8 reg, u8 v[], u8 len) 56static int itd1000_write_regs(struct itd1000_state *state, u8 reg, u8 v[], u8 len)
54{ 57{
55 u8 buf[1+len]; 58 u8 buf[MAX_XFER_SIZE];
56 struct i2c_msg msg = { 59 struct i2c_msg msg = {
57 .addr = state->cfg->i2c_address, .flags = 0, .buf = buf, .len = len+1 60 .addr = state->cfg->i2c_address, .flags = 0, .buf = buf, .len = len+1
58 }; 61 };
62
63 if (1 + len > sizeof(buf)) {
64 printk(KERN_WARNING
65 "itd1000: i2c wr reg=%04x: len=%d is too big!\n",
66 reg, len);
67 return -EINVAL;
68 }
69
59 buf[0] = reg; 70 buf[0] = reg;
60 memcpy(&buf[1], v, len); 71 memcpy(&buf[1], v, len);
61 72
diff --git a/drivers/media/dvb-frontends/mt312.c b/drivers/media/dvb-frontends/mt312.c
index ec388c1d6913..a74ac0ddb833 100644
--- a/drivers/media/dvb-frontends/mt312.c
+++ b/drivers/media/dvb-frontends/mt312.c
@@ -36,6 +36,8 @@
36#include "mt312_priv.h" 36#include "mt312_priv.h"
37#include "mt312.h" 37#include "mt312.h"
38 38
39/* Max transfer size done by I2C transfer functions */
40#define MAX_XFER_SIZE 64
39 41
40struct mt312_state { 42struct mt312_state {
41 struct i2c_adapter *i2c; 43 struct i2c_adapter *i2c;
@@ -96,9 +98,15 @@ static int mt312_write(struct mt312_state *state, const enum mt312_reg_addr reg,
96 const u8 *src, const size_t count) 98 const u8 *src, const size_t count)
97{ 99{
98 int ret; 100 int ret;
99 u8 buf[count + 1]; 101 u8 buf[MAX_XFER_SIZE];
100 struct i2c_msg msg; 102 struct i2c_msg msg;
101 103
104 if (1 + count > sizeof(buf)) {
105 printk(KERN_WARNING
106 "mt312: write: len=%zd is too big!\n", count);
107 return -EINVAL;
108 }
109
102 if (debug) { 110 if (debug) {
103 int i; 111 int i;
104 dprintk("W(%d):", reg & 0x7f); 112 dprintk("W(%d):", reg & 0x7f);
diff --git a/drivers/media/dvb-frontends/nxt200x.c b/drivers/media/dvb-frontends/nxt200x.c
index 8e288940a61f..fbca9856313a 100644
--- a/drivers/media/dvb-frontends/nxt200x.c
+++ b/drivers/media/dvb-frontends/nxt200x.c
@@ -39,6 +39,9 @@
39 */ 39 */
40#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 40#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
41 41
42/* Max transfer size done by I2C transfer functions */
43#define MAX_XFER_SIZE 64
44
42#define NXT2002_DEFAULT_FIRMWARE "dvb-fe-nxt2002.fw" 45#define NXT2002_DEFAULT_FIRMWARE "dvb-fe-nxt2002.fw"
43#define NXT2004_DEFAULT_FIRMWARE "dvb-fe-nxt2004.fw" 46#define NXT2004_DEFAULT_FIRMWARE "dvb-fe-nxt2004.fw"
44#define CRC_CCIT_MASK 0x1021 47#define CRC_CCIT_MASK 0x1021
@@ -95,10 +98,16 @@ static int i2c_readbytes(struct nxt200x_state *state, u8 addr, u8 *buf, u8 len)
95static int nxt200x_writebytes (struct nxt200x_state* state, u8 reg, 98static int nxt200x_writebytes (struct nxt200x_state* state, u8 reg,
96 const u8 *buf, u8 len) 99 const u8 *buf, u8 len)
97{ 100{
98 u8 buf2 [len+1]; 101 u8 buf2[MAX_XFER_SIZE];
99 int err; 102 int err;
100 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf2, .len = len + 1 }; 103 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf2, .len = len + 1 };
101 104
105 if (1 + len > sizeof(buf2)) {
106 pr_warn("%s: i2c wr reg=%04x: len=%d is too big!\n",
107 __func__, reg, len);
108 return -EINVAL;
109 }
110
102 buf2[0] = reg; 111 buf2[0] = reg;
103 memcpy(&buf2[1], buf, len); 112 memcpy(&buf2[1], buf, len);
104 113
diff --git a/drivers/media/dvb-frontends/rtl2830.c b/drivers/media/dvb-frontends/rtl2830.c
index 362d26d11e82..7efb796c472c 100644
--- a/drivers/media/dvb-frontends/rtl2830.c
+++ b/drivers/media/dvb-frontends/rtl2830.c
@@ -27,20 +27,30 @@
27 27
28#include "rtl2830_priv.h" 28#include "rtl2830_priv.h"
29 29
30/* Max transfer size done by I2C transfer functions */
31#define MAX_XFER_SIZE 64
32
30/* write multiple hardware registers */ 33/* write multiple hardware registers */
31static int rtl2830_wr(struct rtl2830_priv *priv, u8 reg, const u8 *val, int len) 34static int rtl2830_wr(struct rtl2830_priv *priv, u8 reg, const u8 *val, int len)
32{ 35{
33 int ret; 36 int ret;
34 u8 buf[1+len]; 37 u8 buf[MAX_XFER_SIZE];
35 struct i2c_msg msg[1] = { 38 struct i2c_msg msg[1] = {
36 { 39 {
37 .addr = priv->cfg.i2c_addr, 40 .addr = priv->cfg.i2c_addr,
38 .flags = 0, 41 .flags = 0,
39 .len = 1+len, 42 .len = 1 + len,
40 .buf = buf, 43 .buf = buf,
41 } 44 }
42 }; 45 };
43 46
47 if (1 + len > sizeof(buf)) {
48 dev_warn(&priv->i2c->dev,
49 "%s: i2c wr reg=%04x: len=%d is too big!\n",
50 KBUILD_MODNAME, reg, len);
51 return -EINVAL;
52 }
53
44 buf[0] = reg; 54 buf[0] = reg;
45 memcpy(&buf[1], val, len); 55 memcpy(&buf[1], val, len);
46 56
diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c
index facb84841518..ff73da9365e3 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -22,6 +22,9 @@
22#include "dvb_math.h" 22#include "dvb_math.h"
23#include <linux/bitops.h> 23#include <linux/bitops.h>
24 24
25/* Max transfer size done by I2C transfer functions */
26#define MAX_XFER_SIZE 64
27
25int rtl2832_debug; 28int rtl2832_debug;
26module_param_named(debug, rtl2832_debug, int, 0644); 29module_param_named(debug, rtl2832_debug, int, 0644);
27MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); 30MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
@@ -162,16 +165,23 @@ static const struct rtl2832_reg_entry registers[] = {
162static int rtl2832_wr(struct rtl2832_priv *priv, u8 reg, u8 *val, int len) 165static int rtl2832_wr(struct rtl2832_priv *priv, u8 reg, u8 *val, int len)
163{ 166{
164 int ret; 167 int ret;
165 u8 buf[1+len]; 168 u8 buf[MAX_XFER_SIZE];
166 struct i2c_msg msg[1] = { 169 struct i2c_msg msg[1] = {
167 { 170 {
168 .addr = priv->cfg.i2c_addr, 171 .addr = priv->cfg.i2c_addr,
169 .flags = 0, 172 .flags = 0,
170 .len = 1+len, 173 .len = 1 + len,
171 .buf = buf, 174 .buf = buf,
172 } 175 }
173 }; 176 };
174 177
178 if (1 + len > sizeof(buf)) {
179 dev_warn(&priv->i2c->dev,
180 "%s: i2c wr reg=%04x: len=%d is too big!\n",
181 KBUILD_MODNAME, reg, len);
182 return -EINVAL;
183 }
184
175 buf[0] = reg; 185 buf[0] = reg;
176 memcpy(&buf[1], val, len); 186 memcpy(&buf[1], val, len);
177 187
@@ -489,6 +499,7 @@ static int rtl2832_init(struct dvb_frontend *fe)
489 init = rtl2832_tuner_init_e4000; 499 init = rtl2832_tuner_init_e4000;
490 break; 500 break;
491 case RTL2832_TUNER_R820T: 501 case RTL2832_TUNER_R820T:
502 case RTL2832_TUNER_R828D:
492 len = ARRAY_SIZE(rtl2832_tuner_init_r820t); 503 len = ARRAY_SIZE(rtl2832_tuner_init_r820t);
493 init = rtl2832_tuner_init_r820t; 504 init = rtl2832_tuner_init_r820t;
494 break; 505 break;
diff --git a/drivers/media/dvb-frontends/rtl2832.h b/drivers/media/dvb-frontends/rtl2832.h
index 91b2dcf5a6ea..2cfbb6a97061 100644
--- a/drivers/media/dvb-frontends/rtl2832.h
+++ b/drivers/media/dvb-frontends/rtl2832.h
@@ -53,6 +53,7 @@ struct rtl2832_config {
53#define RTL2832_TUNER_E4000 0x27 53#define RTL2832_TUNER_E4000 0x27
54#define RTL2832_TUNER_FC0013 0x29 54#define RTL2832_TUNER_FC0013 0x29
55#define RTL2832_TUNER_R820T 0x2a 55#define RTL2832_TUNER_R820T 0x2a
56#define RTL2832_TUNER_R828D 0x2b
56 u8 tuner; 57 u8 tuner;
57}; 58};
58 59
diff --git a/drivers/media/dvb-frontends/s5h1420.c b/drivers/media/dvb-frontends/s5h1420.c
index e2fec9ebf947..93eeaf7118fd 100644
--- a/drivers/media/dvb-frontends/s5h1420.c
+++ b/drivers/media/dvb-frontends/s5h1420.c
@@ -836,9 +836,16 @@ static u32 s5h1420_tuner_i2c_func(struct i2c_adapter *adapter)
836static int s5h1420_tuner_i2c_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num) 836static int s5h1420_tuner_i2c_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
837{ 837{
838 struct s5h1420_state *state = i2c_get_adapdata(i2c_adap); 838 struct s5h1420_state *state = i2c_get_adapdata(i2c_adap);
839 struct i2c_msg m[1 + num]; 839 struct i2c_msg m[3];
840 u8 tx_open[2] = { CON_1, state->CON_1_val | 1 }; /* repeater stops once there was a stop condition */ 840 u8 tx_open[2] = { CON_1, state->CON_1_val | 1 }; /* repeater stops once there was a stop condition */
841 841
842 if (1 + num > ARRAY_SIZE(m)) {
843 printk(KERN_WARNING
844 "%s: i2c xfer: num=%d is too big!\n",
845 KBUILD_MODNAME, num);
846 return -EOPNOTSUPP;
847 }
848
842 memset(m, 0, sizeof(struct i2c_msg) * (1 + num)); 849 memset(m, 0, sizeof(struct i2c_msg) * (1 + num));
843 850
844 m[0].addr = state->config->demod_address; 851 m[0].addr = state->config->demod_address;
@@ -847,7 +854,7 @@ static int s5h1420_tuner_i2c_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c
847 854
848 memcpy(&m[1], msg, sizeof(struct i2c_msg) * num); 855 memcpy(&m[1], msg, sizeof(struct i2c_msg) * num);
849 856
850 return i2c_transfer(state->i2c, m, 1+num) == 1 + num ? num : -EIO; 857 return i2c_transfer(state->i2c, m, 1 + num) == 1 + num ? num : -EIO;
851} 858}
852 859
853static struct i2c_algorithm s5h1420_tuner_i2c_algo = { 860static struct i2c_algorithm s5h1420_tuner_i2c_algo = {
diff --git a/drivers/media/dvb-frontends/stb0899_drv.c b/drivers/media/dvb-frontends/stb0899_drv.c
index 3dd5714eadba..07cd5ea7a038 100644
--- a/drivers/media/dvb-frontends/stb0899_drv.c
+++ b/drivers/media/dvb-frontends/stb0899_drv.c
@@ -32,6 +32,9 @@
32#include "stb0899_priv.h" 32#include "stb0899_priv.h"
33#include "stb0899_reg.h" 33#include "stb0899_reg.h"
34 34
35/* Max transfer size done by I2C transfer functions */
36#define MAX_XFER_SIZE 64
37
35static unsigned int verbose = 0;//1; 38static unsigned int verbose = 0;//1;
36module_param(verbose, int, 0644); 39module_param(verbose, int, 0644);
37 40
@@ -499,7 +502,7 @@ err:
499int stb0899_write_regs(struct stb0899_state *state, unsigned int reg, u8 *data, u32 count) 502int stb0899_write_regs(struct stb0899_state *state, unsigned int reg, u8 *data, u32 count)
500{ 503{
501 int ret; 504 int ret;
502 u8 buf[2 + count]; 505 u8 buf[MAX_XFER_SIZE];
503 struct i2c_msg i2c_msg = { 506 struct i2c_msg i2c_msg = {
504 .addr = state->config->demod_address, 507 .addr = state->config->demod_address,
505 .flags = 0, 508 .flags = 0,
@@ -507,6 +510,13 @@ int stb0899_write_regs(struct stb0899_state *state, unsigned int reg, u8 *data,
507 .len = 2 + count 510 .len = 2 + count
508 }; 511 };
509 512
513 if (2 + count > sizeof(buf)) {
514 printk(KERN_WARNING
515 "%s: i2c wr reg=%04x: len=%d is too big!\n",
516 KBUILD_MODNAME, reg, count);
517 return -EINVAL;
518 }
519
510 buf[0] = reg >> 8; 520 buf[0] = reg >> 8;
511 buf[1] = reg & 0xff; 521 buf[1] = reg & 0xff;
512 memcpy(&buf[2], data, count); 522 memcpy(&buf[2], data, count);
diff --git a/drivers/media/dvb-frontends/stb6100.c b/drivers/media/dvb-frontends/stb6100.c
index 45f9523f968f..cea175d19890 100644
--- a/drivers/media/dvb-frontends/stb6100.c
+++ b/drivers/media/dvb-frontends/stb6100.c
@@ -31,6 +31,8 @@
31static unsigned int verbose; 31static unsigned int verbose;
32module_param(verbose, int, 0644); 32module_param(verbose, int, 0644);
33 33
34/* Max transfer size done by I2C transfer functions */
35#define MAX_XFER_SIZE 64
34 36
35#define FE_ERROR 0 37#define FE_ERROR 0
36#define FE_NOTICE 1 38#define FE_NOTICE 1
@@ -183,7 +185,7 @@ static int stb6100_read_reg(struct stb6100_state *state, u8 reg)
183static int stb6100_write_reg_range(struct stb6100_state *state, u8 buf[], int start, int len) 185static int stb6100_write_reg_range(struct stb6100_state *state, u8 buf[], int start, int len)
184{ 186{
185 int rc; 187 int rc;
186 u8 cmdbuf[len + 1]; 188 u8 cmdbuf[MAX_XFER_SIZE];
187 struct i2c_msg msg = { 189 struct i2c_msg msg = {
188 .addr = state->config->tuner_address, 190 .addr = state->config->tuner_address,
189 .flags = 0, 191 .flags = 0,
@@ -191,6 +193,13 @@ static int stb6100_write_reg_range(struct stb6100_state *state, u8 buf[], int st
191 .len = len + 1 193 .len = len + 1
192 }; 194 };
193 195
196 if (1 + len > sizeof(buf)) {
197 printk(KERN_WARNING
198 "%s: i2c wr: len=%d is too big!\n",
199 KBUILD_MODNAME, len);
200 return -EINVAL;
201 }
202
194 if (unlikely(start < 1 || start + len > STB6100_NUMREGS)) { 203 if (unlikely(start < 1 || start + len > STB6100_NUMREGS)) {
195 dprintk(verbose, FE_ERROR, 1, "Invalid register range %d:%d", 204 dprintk(verbose, FE_ERROR, 1, "Invalid register range %d:%d",
196 start, len); 205 start, len);
diff --git a/drivers/media/dvb-frontends/stv0367.c b/drivers/media/dvb-frontends/stv0367.c
index 7b6dba3ce55e..458772739423 100644
--- a/drivers/media/dvb-frontends/stv0367.c
+++ b/drivers/media/dvb-frontends/stv0367.c
@@ -33,6 +33,9 @@
33#include "stv0367_regs.h" 33#include "stv0367_regs.h"
34#include "stv0367_priv.h" 34#include "stv0367_priv.h"
35 35
36/* Max transfer size done by I2C transfer functions */
37#define MAX_XFER_SIZE 64
38
36static int stvdebug; 39static int stvdebug;
37module_param_named(debug, stvdebug, int, 0644); 40module_param_named(debug, stvdebug, int, 0644);
38 41
@@ -767,7 +770,7 @@ static struct st_register def0367cab[STV0367CAB_NBREGS] = {
767static 770static
768int stv0367_writeregs(struct stv0367_state *state, u16 reg, u8 *data, int len) 771int stv0367_writeregs(struct stv0367_state *state, u16 reg, u8 *data, int len)
769{ 772{
770 u8 buf[len + 2]; 773 u8 buf[MAX_XFER_SIZE];
771 struct i2c_msg msg = { 774 struct i2c_msg msg = {
772 .addr = state->config->demod_address, 775 .addr = state->config->demod_address,
773 .flags = 0, 776 .flags = 0,
@@ -776,6 +779,14 @@ int stv0367_writeregs(struct stv0367_state *state, u16 reg, u8 *data, int len)
776 }; 779 };
777 int ret; 780 int ret;
778 781
782 if (2 + len > sizeof(buf)) {
783 printk(KERN_WARNING
784 "%s: i2c wr reg=%04x: len=%d is too big!\n",
785 KBUILD_MODNAME, reg, len);
786 return -EINVAL;
787 }
788
789
779 buf[0] = MSB(reg); 790 buf[0] = MSB(reg);
780 buf[1] = LSB(reg); 791 buf[1] = LSB(reg);
781 memcpy(buf + 2, data, len); 792 memcpy(buf + 2, data, len);
diff --git a/drivers/media/dvb-frontends/stv090x.c b/drivers/media/dvb-frontends/stv090x.c
index 56d470ad5a82..23e872f84742 100644
--- a/drivers/media/dvb-frontends/stv090x.c
+++ b/drivers/media/dvb-frontends/stv090x.c
@@ -35,6 +35,9 @@
35#include "stv090x.h" 35#include "stv090x.h"
36#include "stv090x_priv.h" 36#include "stv090x_priv.h"
37 37
38/* Max transfer size done by I2C transfer functions */
39#define MAX_XFER_SIZE 64
40
38static unsigned int verbose; 41static unsigned int verbose;
39module_param(verbose, int, 0644); 42module_param(verbose, int, 0644);
40 43
@@ -722,9 +725,16 @@ static int stv090x_write_regs(struct stv090x_state *state, unsigned int reg, u8
722{ 725{
723 const struct stv090x_config *config = state->config; 726 const struct stv090x_config *config = state->config;
724 int ret; 727 int ret;
725 u8 buf[2 + count]; 728 u8 buf[MAX_XFER_SIZE];
726 struct i2c_msg i2c_msg = { .addr = config->address, .flags = 0, .buf = buf, .len = 2 + count }; 729 struct i2c_msg i2c_msg = { .addr = config->address, .flags = 0, .buf = buf, .len = 2 + count };
727 730
731 if (2 + count > sizeof(buf)) {
732 printk(KERN_WARNING
733 "%s: i2c wr reg=%04x: len=%d is too big!\n",
734 KBUILD_MODNAME, reg, count);
735 return -EINVAL;
736 }
737
728 buf[0] = reg >> 8; 738 buf[0] = reg >> 8;
729 buf[1] = reg & 0xff; 739 buf[1] = reg & 0xff;
730 memcpy(&buf[2], data, count); 740 memcpy(&buf[2], data, count);
diff --git a/drivers/media/dvb-frontends/stv6110.c b/drivers/media/dvb-frontends/stv6110.c
index 20b5fa92c53e..b1425830a24e 100644
--- a/drivers/media/dvb-frontends/stv6110.c
+++ b/drivers/media/dvb-frontends/stv6110.c
@@ -30,6 +30,9 @@
30 30
31#include "stv6110.h" 31#include "stv6110.h"
32 32
33/* Max transfer size done by I2C transfer functions */
34#define MAX_XFER_SIZE 64
35
33static int debug; 36static int debug;
34 37
35struct stv6110_priv { 38struct stv6110_priv {
@@ -68,7 +71,7 @@ static int stv6110_write_regs(struct dvb_frontend *fe, u8 buf[],
68{ 71{
69 struct stv6110_priv *priv = fe->tuner_priv; 72 struct stv6110_priv *priv = fe->tuner_priv;
70 int rc; 73 int rc;
71 u8 cmdbuf[len + 1]; 74 u8 cmdbuf[MAX_XFER_SIZE];
72 struct i2c_msg msg = { 75 struct i2c_msg msg = {
73 .addr = priv->i2c_address, 76 .addr = priv->i2c_address,
74 .flags = 0, 77 .flags = 0,
@@ -78,6 +81,13 @@ static int stv6110_write_regs(struct dvb_frontend *fe, u8 buf[],
78 81
79 dprintk("%s\n", __func__); 82 dprintk("%s\n", __func__);
80 83
84 if (1 + len > sizeof(cmdbuf)) {
85 printk(KERN_WARNING
86 "%s: i2c wr: len=%d is too big!\n",
87 KBUILD_MODNAME, len);
88 return -EINVAL;
89 }
90
81 if (start + len > 8) 91 if (start + len > 8)
82 return -EINVAL; 92 return -EINVAL;
83 93
diff --git a/drivers/media/dvb-frontends/stv6110x.c b/drivers/media/dvb-frontends/stv6110x.c
index f36cab12bdc7..e66154e5c1d7 100644
--- a/drivers/media/dvb-frontends/stv6110x.c
+++ b/drivers/media/dvb-frontends/stv6110x.c
@@ -32,6 +32,9 @@
32#include "stv6110x.h" 32#include "stv6110x.h"
33#include "stv6110x_priv.h" 33#include "stv6110x_priv.h"
34 34
35/* Max transfer size done by I2C transfer functions */
36#define MAX_XFER_SIZE 64
37
35static unsigned int verbose; 38static unsigned int verbose;
36module_param(verbose, int, 0644); 39module_param(verbose, int, 0644);
37MODULE_PARM_DESC(verbose, "Set Verbosity level"); 40MODULE_PARM_DESC(verbose, "Set Verbosity level");
@@ -61,7 +64,8 @@ static int stv6110x_write_regs(struct stv6110x_state *stv6110x, int start, u8 da
61{ 64{
62 int ret; 65 int ret;
63 const struct stv6110x_config *config = stv6110x->config; 66 const struct stv6110x_config *config = stv6110x->config;
64 u8 buf[len + 1]; 67 u8 buf[MAX_XFER_SIZE];
68
65 struct i2c_msg msg = { 69 struct i2c_msg msg = {
66 .addr = config->addr, 70 .addr = config->addr,
67 .flags = 0, 71 .flags = 0,
@@ -69,6 +73,13 @@ static int stv6110x_write_regs(struct stv6110x_state *stv6110x, int start, u8 da
69 .len = len + 1 73 .len = len + 1
70 }; 74 };
71 75
76 if (1 + len > sizeof(buf)) {
77 printk(KERN_WARNING
78 "%s: i2c wr: len=%d is too big!\n",
79 KBUILD_MODNAME, len);
80 return -EINVAL;
81 }
82
72 if (start + len > 8) 83 if (start + len > 8)
73 return -EINVAL; 84 return -EINVAL;
74 85
diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c
index e79749cfec81..8ad3a57cf640 100644
--- a/drivers/media/dvb-frontends/tda10071.c
+++ b/drivers/media/dvb-frontends/tda10071.c
@@ -20,6 +20,9 @@
20 20
21#include "tda10071_priv.h" 21#include "tda10071_priv.h"
22 22
23/* Max transfer size done by I2C transfer functions */
24#define MAX_XFER_SIZE 64
25
23static struct dvb_frontend_ops tda10071_ops; 26static struct dvb_frontend_ops tda10071_ops;
24 27
25/* write multiple registers */ 28/* write multiple registers */
@@ -27,16 +30,23 @@ static int tda10071_wr_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
27 int len) 30 int len)
28{ 31{
29 int ret; 32 int ret;
30 u8 buf[len+1]; 33 u8 buf[MAX_XFER_SIZE];
31 struct i2c_msg msg[1] = { 34 struct i2c_msg msg[1] = {
32 { 35 {
33 .addr = priv->cfg.demod_i2c_addr, 36 .addr = priv->cfg.demod_i2c_addr,
34 .flags = 0, 37 .flags = 0,
35 .len = sizeof(buf), 38 .len = 1 + len,
36 .buf = buf, 39 .buf = buf,
37 } 40 }
38 }; 41 };
39 42
43 if (1 + len > sizeof(buf)) {
44 dev_warn(&priv->i2c->dev,
45 "%s: i2c wr reg=%04x: len=%d is too big!\n",
46 KBUILD_MODNAME, reg, len);
47 return -EINVAL;
48 }
49
40 buf[0] = reg; 50 buf[0] = reg;
41 memcpy(&buf[1], val, len); 51 memcpy(&buf[1], val, len);
42 52
@@ -56,7 +66,7 @@ static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
56 int len) 66 int len)
57{ 67{
58 int ret; 68 int ret;
59 u8 buf[len]; 69 u8 buf[MAX_XFER_SIZE];
60 struct i2c_msg msg[2] = { 70 struct i2c_msg msg[2] = {
61 { 71 {
62 .addr = priv->cfg.demod_i2c_addr, 72 .addr = priv->cfg.demod_i2c_addr,
@@ -66,11 +76,18 @@ static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
66 }, { 76 }, {
67 .addr = priv->cfg.demod_i2c_addr, 77 .addr = priv->cfg.demod_i2c_addr,
68 .flags = I2C_M_RD, 78 .flags = I2C_M_RD,
69 .len = sizeof(buf), 79 .len = len,
70 .buf = buf, 80 .buf = buf,
71 } 81 }
72 }; 82 };
73 83
84 if (len > sizeof(buf)) {
85 dev_warn(&priv->i2c->dev,
86 "%s: i2c wr reg=%04x: len=%d is too big!\n",
87 KBUILD_MODNAME, reg, len);
88 return -EINVAL;
89 }
90
74 ret = i2c_transfer(priv->i2c, msg, 2); 91 ret = i2c_transfer(priv->i2c, msg, 2);
75 if (ret == 2) { 92 if (ret == 2) {
76 memcpy(val, buf, len); 93 memcpy(val, buf, len);
diff --git a/drivers/media/dvb-frontends/tda18271c2dd.c b/drivers/media/dvb-frontends/tda18271c2dd.c
index d281f77d5c28..2c54586ac07f 100644
--- a/drivers/media/dvb-frontends/tda18271c2dd.c
+++ b/drivers/media/dvb-frontends/tda18271c2dd.c
@@ -34,6 +34,9 @@
34#include "dvb_frontend.h" 34#include "dvb_frontend.h"
35#include "tda18271c2dd.h" 35#include "tda18271c2dd.h"
36 36
37/* Max transfer size done by I2C transfer functions */
38#define MAX_XFER_SIZE 64
39
37struct SStandardParam { 40struct SStandardParam {
38 s32 m_IFFrequency; 41 s32 m_IFFrequency;
39 u32 m_BandWidth; 42 u32 m_BandWidth;
@@ -139,11 +142,18 @@ static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len)
139static int WriteRegs(struct tda_state *state, 142static int WriteRegs(struct tda_state *state,
140 u8 SubAddr, u8 *Regs, u16 nRegs) 143 u8 SubAddr, u8 *Regs, u16 nRegs)
141{ 144{
142 u8 data[nRegs+1]; 145 u8 data[MAX_XFER_SIZE];
146
147 if (1 + nRegs > sizeof(data)) {
148 printk(KERN_WARNING
149 "%s: i2c wr: len=%d is too big!\n",
150 KBUILD_MODNAME, nRegs);
151 return -EINVAL;
152 }
143 153
144 data[0] = SubAddr; 154 data[0] = SubAddr;
145 memcpy(data + 1, Regs, nRegs); 155 memcpy(data + 1, Regs, nRegs);
146 return i2c_write(state->i2c, state->adr, data, nRegs+1); 156 return i2c_write(state->i2c, state->adr, data, nRegs + 1);
147} 157}
148 158
149static int WriteReg(struct tda_state *state, u8 SubAddr, u8 Reg) 159static int WriteReg(struct tda_state *state, u8 SubAddr, u8 Reg)
diff --git a/drivers/media/dvb-frontends/tda8083.c b/drivers/media/dvb-frontends/tda8083.c
index 9d08350fe4b0..69e62f42e2e1 100644
--- a/drivers/media/dvb-frontends/tda8083.c
+++ b/drivers/media/dvb-frontends/tda8083.c
@@ -189,7 +189,7 @@ static int tda8083_set_tone (struct tda8083_state* state, fe_sec_tone_mode_t ton
189 return tda8083_writereg (state, 0x29, 0x80); 189 return tda8083_writereg (state, 0x29, 0x80);
190 default: 190 default:
191 return -EINVAL; 191 return -EINVAL;
192 }; 192 }
193} 193}
194 194
195static int tda8083_set_voltage (struct tda8083_state* state, fe_sec_voltage_t voltage) 195static int tda8083_set_voltage (struct tda8083_state* state, fe_sec_voltage_t voltage)
@@ -201,7 +201,7 @@ static int tda8083_set_voltage (struct tda8083_state* state, fe_sec_voltage_t vo
201 return tda8083_writereg (state, 0x20, 0x11); 201 return tda8083_writereg (state, 0x20, 0x11);
202 default: 202 default:
203 return -EINVAL; 203 return -EINVAL;
204 }; 204 }
205} 205}
206 206
207static int tda8083_send_diseqc_burst (struct tda8083_state* state, fe_sec_mini_cmd_t burst) 207static int tda8083_send_diseqc_burst (struct tda8083_state* state, fe_sec_mini_cmd_t burst)
diff --git a/drivers/media/dvb-frontends/ts2020.c b/drivers/media/dvb-frontends/ts2020.c
index ad7ad857ab2a..9aba044dabed 100644
--- a/drivers/media/dvb-frontends/ts2020.c
+++ b/drivers/media/dvb-frontends/ts2020.c
@@ -31,6 +31,7 @@ struct ts2020_priv {
31 struct i2c_adapter *i2c; 31 struct i2c_adapter *i2c;
32 u8 clk_out_div; 32 u8 clk_out_div;
33 u32 frequency; 33 u32 frequency;
34 u32 frequency_div;
34}; 35};
35 36
36static int ts2020_release(struct dvb_frontend *fe) 37static int ts2020_release(struct dvb_frontend *fe)
@@ -193,7 +194,7 @@ static int ts2020_set_params(struct dvb_frontend *fe)
193 u8 lo = 0x01, div4 = 0x0; 194 u8 lo = 0x01, div4 = 0x0;
194 195
195 /* Calculate frequency divider */ 196 /* Calculate frequency divider */
196 if (frequency < 1060000) { 197 if (frequency < priv->frequency_div) {
197 lo |= 0x10; 198 lo |= 0x10;
198 div4 = 0x1; 199 div4 = 0x1;
199 ndiv = (frequency * 14 * 4) / TS2020_XTAL_FREQ; 200 ndiv = (frequency * 14 * 4) / TS2020_XTAL_FREQ;
@@ -340,8 +341,12 @@ struct dvb_frontend *ts2020_attach(struct dvb_frontend *fe,
340 priv->i2c_address = config->tuner_address; 341 priv->i2c_address = config->tuner_address;
341 priv->i2c = i2c; 342 priv->i2c = i2c;
342 priv->clk_out_div = config->clk_out_div; 343 priv->clk_out_div = config->clk_out_div;
344 priv->frequency_div = config->frequency_div;
343 fe->tuner_priv = priv; 345 fe->tuner_priv = priv;
344 346
347 if (!priv->frequency_div)
348 priv->frequency_div = 1060000;
349
345 /* Wake Up the tuner */ 350 /* Wake Up the tuner */
346 if ((0x03 & ts2020_readreg(fe, 0x00)) == 0x00) { 351 if ((0x03 & ts2020_readreg(fe, 0x00)) == 0x00) {
347 ts2020_writereg(fe, 0x00, 0x01); 352 ts2020_writereg(fe, 0x00, 0x01);
diff --git a/drivers/media/dvb-frontends/ts2020.h b/drivers/media/dvb-frontends/ts2020.h
index 5bcb9a71ca80..b2fe6bb3a38b 100644
--- a/drivers/media/dvb-frontends/ts2020.h
+++ b/drivers/media/dvb-frontends/ts2020.h
@@ -28,6 +28,7 @@
28struct ts2020_config { 28struct ts2020_config {
29 u8 tuner_address; 29 u8 tuner_address;
30 u8 clk_out_div; 30 u8 clk_out_div;
31 u32 frequency_div;
31}; 32};
32 33
33#if IS_ENABLED(CONFIG_DVB_TS2020) 34#if IS_ENABLED(CONFIG_DVB_TS2020)
diff --git a/drivers/media/dvb-frontends/zl10039.c b/drivers/media/dvb-frontends/zl10039.c
index eff9c5fde50a..91b6b2e9b792 100644
--- a/drivers/media/dvb-frontends/zl10039.c
+++ b/drivers/media/dvb-frontends/zl10039.c
@@ -30,6 +30,9 @@
30 30
31static int debug; 31static int debug;
32 32
33/* Max transfer size done by I2C transfer functions */
34#define MAX_XFER_SIZE 64
35
33#define dprintk(args...) \ 36#define dprintk(args...) \
34 do { \ 37 do { \
35 if (debug) \ 38 if (debug) \
@@ -98,7 +101,7 @@ static int zl10039_write(struct zl10039_state *state,
98 const enum zl10039_reg_addr reg, const u8 *src, 101 const enum zl10039_reg_addr reg, const u8 *src,
99 const size_t count) 102 const size_t count)
100{ 103{
101 u8 buf[count + 1]; 104 u8 buf[MAX_XFER_SIZE];
102 struct i2c_msg msg = { 105 struct i2c_msg msg = {
103 .addr = state->i2c_addr, 106 .addr = state->i2c_addr,
104 .flags = 0, 107 .flags = 0,
@@ -106,6 +109,13 @@ static int zl10039_write(struct zl10039_state *state,
106 .len = count + 1, 109 .len = count + 1,
107 }; 110 };
108 111
112 if (1 + count > sizeof(buf)) {
113 printk(KERN_WARNING
114 "%s: i2c wr reg=%04x: len=%zd is too big!\n",
115 KBUILD_MODNAME, reg, count);
116 return -EINVAL;
117 }
118
109 dprintk("%s\n", __func__); 119 dprintk("%s\n", __func__);
110 /* Write register address and data in one go */ 120 /* Write register address and data in one go */
111 buf[0] = reg; 121 buf[0] = reg;
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index cbc9ee9bec2b..842654d33317 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -621,6 +621,15 @@ config VIDEO_AS3645A
621 This is a driver for the AS3645A and LM3555 flash controllers. It has 621 This is a driver for the AS3645A and LM3555 flash controllers. It has
622 build in control for flash, torch and indicator LEDs. 622 build in control for flash, torch and indicator LEDs.
623 623
624config VIDEO_LM3560
625 tristate "LM3560 dual flash driver support"
626 depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
627 depends on MEDIA_CAMERA_SUPPORT
628 select REGMAP_I2C
629 ---help---
630 This is a driver for the lm3560 dual flash controllers. It controls
631 flash, torch LEDs.
632
624comment "Video improvement chips" 633comment "Video improvement chips"
625 634
626config VIDEO_UPD64031A 635config VIDEO_UPD64031A
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 9f462df77b4a..e03f1776f4f4 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_VIDEO_S5K4ECGX) += s5k4ecgx.o
70obj-$(CONFIG_VIDEO_S5C73M3) += s5c73m3/ 70obj-$(CONFIG_VIDEO_S5C73M3) += s5c73m3/
71obj-$(CONFIG_VIDEO_ADP1653) += adp1653.o 71obj-$(CONFIG_VIDEO_ADP1653) += adp1653.o
72obj-$(CONFIG_VIDEO_AS3645A) += as3645a.o 72obj-$(CONFIG_VIDEO_AS3645A) += as3645a.o
73obj-$(CONFIG_VIDEO_LM3560) += lm3560.o
73obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o 74obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o
74obj-$(CONFIG_VIDEO_AK881X) += ak881x.o 75obj-$(CONFIG_VIDEO_AK881X) += ak881x.o
75obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o 76obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o
diff --git a/drivers/media/i2c/adv7343.c b/drivers/media/i2c/adv7343.c
index aeb56c53e39f..d4e15a617c3b 100644
--- a/drivers/media/i2c/adv7343.c
+++ b/drivers/media/i2c/adv7343.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/videodev2.h> 26#include <linux/videodev2.h>
27#include <linux/uaccess.h> 27#include <linux/uaccess.h>
28#include <linux/of.h>
28 29
29#include <media/adv7343.h> 30#include <media/adv7343.h>
30#include <media/v4l2-async.h> 31#include <media/v4l2-async.h>
diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c
new file mode 100644
index 000000000000..3317a9ae3961
--- /dev/null
+++ b/drivers/media/i2c/lm3560.c
@@ -0,0 +1,488 @@
1/*
2 * drivers/media/i2c/lm3560.c
3 * General device driver for TI lm3560, FLASH LED Driver
4 *
5 * Copyright (C) 2013 Texas Instruments
6 *
7 * Contact: Daniel Jeong <gshark.jeong@gmail.com>
8 * Ldd-Mlp <ldd-mlp@list.ti.com>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 *
24 */
25
26#include <linux/delay.h>
27#include <linux/module.h>
28#include <linux/i2c.h>
29#include <linux/slab.h>
30#include <linux/mutex.h>
31#include <linux/regmap.h>
32#include <linux/videodev2.h>
33#include <media/lm3560.h>
34#include <media/v4l2-ctrls.h>
35#include <media/v4l2-device.h>
36
37/* registers definitions */
38#define REG_ENABLE 0x10
39#define REG_TORCH_BR 0xa0
40#define REG_FLASH_BR 0xb0
41#define REG_FLASH_TOUT 0xc0
42#define REG_FLAG 0xd0
43#define REG_CONFIG1 0xe0
44
45/* Fault Mask */
46#define FAULT_TIMEOUT (1<<0)
47#define FAULT_OVERTEMP (1<<1)
48#define FAULT_SHORT_CIRCUIT (1<<2)
49
50enum led_enable {
51 MODE_SHDN = 0x0,
52 MODE_TORCH = 0x2,
53 MODE_FLASH = 0x3,
54};
55
56/* struct lm3560_flash
57 *
58 * @pdata: platform data
59 * @regmap: reg. map for i2c
60 * @lock: muxtex for serial access.
61 * @led_mode: V4L2 LED mode
62 * @ctrls_led: V4L2 contols
63 * @subdev_led: V4L2 subdev
64 */
65struct lm3560_flash {
66 struct device *dev;
67 struct lm3560_platform_data *pdata;
68 struct regmap *regmap;
69 struct mutex lock;
70
71 enum v4l2_flash_led_mode led_mode;
72 struct v4l2_ctrl_handler ctrls_led[LM3560_LED_MAX];
73 struct v4l2_subdev subdev_led[LM3560_LED_MAX];
74};
75
76#define to_lm3560_flash(_ctrl, _no) \
77 container_of(_ctrl->handler, struct lm3560_flash, ctrls_led[_no])
78
79/* enable mode control */
80static int lm3560_mode_ctrl(struct lm3560_flash *flash)
81{
82 int rval = -EINVAL;
83
84 switch (flash->led_mode) {
85 case V4L2_FLASH_LED_MODE_NONE:
86 rval = regmap_update_bits(flash->regmap,
87 REG_ENABLE, 0x03, MODE_SHDN);
88 break;
89 case V4L2_FLASH_LED_MODE_TORCH:
90 rval = regmap_update_bits(flash->regmap,
91 REG_ENABLE, 0x03, MODE_TORCH);
92 break;
93 case V4L2_FLASH_LED_MODE_FLASH:
94 rval = regmap_update_bits(flash->regmap,
95 REG_ENABLE, 0x03, MODE_FLASH);
96 break;
97 }
98 return rval;
99}
100
101/* led1/2 enable/disable */
102static int lm3560_enable_ctrl(struct lm3560_flash *flash,
103 enum lm3560_led_id led_no, bool on)
104{
105 int rval;
106
107 if (led_no == LM3560_LED0) {
108 if (on == true)
109 rval = regmap_update_bits(flash->regmap,
110 REG_ENABLE, 0x08, 0x08);
111 else
112 rval = regmap_update_bits(flash->regmap,
113 REG_ENABLE, 0x08, 0x00);
114 } else {
115 if (on == true)
116 rval = regmap_update_bits(flash->regmap,
117 REG_ENABLE, 0x10, 0x10);
118 else
119 rval = regmap_update_bits(flash->regmap,
120 REG_ENABLE, 0x10, 0x00);
121 }
122 return rval;
123}
124
125/* torch1/2 brightness control */
126static int lm3560_torch_brt_ctrl(struct lm3560_flash *flash,
127 enum lm3560_led_id led_no, unsigned int brt)
128{
129 int rval;
130 u8 br_bits;
131
132 if (brt < LM3560_TORCH_BRT_MIN)
133 return lm3560_enable_ctrl(flash, led_no, false);
134 else
135 rval = lm3560_enable_ctrl(flash, led_no, true);
136
137 br_bits = LM3560_TORCH_BRT_uA_TO_REG(brt);
138 if (led_no == LM3560_LED0)
139 rval = regmap_update_bits(flash->regmap,
140 REG_TORCH_BR, 0x07, br_bits);
141 else
142 rval = regmap_update_bits(flash->regmap,
143 REG_TORCH_BR, 0x38, br_bits << 3);
144
145 return rval;
146}
147
148/* flash1/2 brightness control */
149static int lm3560_flash_brt_ctrl(struct lm3560_flash *flash,
150 enum lm3560_led_id led_no, unsigned int brt)
151{
152 int rval;
153 u8 br_bits;
154
155 if (brt < LM3560_FLASH_BRT_MIN)
156 return lm3560_enable_ctrl(flash, led_no, false);
157 else
158 rval = lm3560_enable_ctrl(flash, led_no, true);
159
160 br_bits = LM3560_FLASH_BRT_uA_TO_REG(brt);
161 if (led_no == LM3560_LED0)
162 rval = regmap_update_bits(flash->regmap,
163 REG_FLASH_BR, 0x0f, br_bits);
164 else
165 rval = regmap_update_bits(flash->regmap,
166 REG_FLASH_BR, 0xf0, br_bits << 4);
167
168 return rval;
169}
170
171/* V4L2 controls */
172static int lm3560_get_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
173{
174 struct lm3560_flash *flash = to_lm3560_flash(ctrl, led_no);
175
176 mutex_lock(&flash->lock);
177
178 if (ctrl->id == V4L2_CID_FLASH_FAULT) {
179 int rval;
180 s32 fault = 0;
181 unsigned int reg_val;
182 rval = regmap_read(flash->regmap, REG_FLAG, &reg_val);
183 if (rval < 0)
184 return rval;
185 if (rval & FAULT_SHORT_CIRCUIT)
186 fault |= V4L2_FLASH_FAULT_SHORT_CIRCUIT;
187 if (rval & FAULT_OVERTEMP)
188 fault |= V4L2_FLASH_FAULT_OVER_TEMPERATURE;
189 if (rval & FAULT_TIMEOUT)
190 fault |= V4L2_FLASH_FAULT_TIMEOUT;
191 ctrl->cur.val = fault;
192 return 0;
193 }
194
195 mutex_unlock(&flash->lock);
196 return -EINVAL;
197}
198
199static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
200{
201 struct lm3560_flash *flash = to_lm3560_flash(ctrl, led_no);
202 u8 tout_bits;
203 int rval = -EINVAL;
204
205 mutex_lock(&flash->lock);
206
207 switch (ctrl->id) {
208 case V4L2_CID_FLASH_LED_MODE:
209 flash->led_mode = ctrl->val;
210 if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH)
211 rval = lm3560_mode_ctrl(flash);
212 break;
213
214 case V4L2_CID_FLASH_STROBE_SOURCE:
215 rval = regmap_update_bits(flash->regmap,
216 REG_CONFIG1, 0x04, (ctrl->val) << 2);
217 if (rval < 0)
218 goto err_out;
219 break;
220
221 case V4L2_CID_FLASH_STROBE:
222 if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH)
223 return -EBUSY;
224 flash->led_mode = V4L2_FLASH_LED_MODE_FLASH;
225 rval = lm3560_mode_ctrl(flash);
226 break;
227
228 case V4L2_CID_FLASH_STROBE_STOP:
229 if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH)
230 return -EBUSY;
231 flash->led_mode = V4L2_FLASH_LED_MODE_NONE;
232 rval = lm3560_mode_ctrl(flash);
233 break;
234
235 case V4L2_CID_FLASH_TIMEOUT:
236 tout_bits = LM3560_FLASH_TOUT_ms_TO_REG(ctrl->val);
237 rval = regmap_update_bits(flash->regmap,
238 REG_FLASH_TOUT, 0x1f, tout_bits);
239 break;
240
241 case V4L2_CID_FLASH_INTENSITY:
242 rval = lm3560_flash_brt_ctrl(flash, led_no, ctrl->val);
243 break;
244
245 case V4L2_CID_FLASH_TORCH_INTENSITY:
246 rval = lm3560_torch_brt_ctrl(flash, led_no, ctrl->val);
247 break;
248 }
249
250 mutex_unlock(&flash->lock);
251err_out:
252 return rval;
253}
254
255static int lm3560_led1_get_ctrl(struct v4l2_ctrl *ctrl)
256{
257 return lm3560_get_ctrl(ctrl, LM3560_LED1);
258}
259
260static int lm3560_led1_set_ctrl(struct v4l2_ctrl *ctrl)
261{
262 return lm3560_set_ctrl(ctrl, LM3560_LED1);
263}
264
265static int lm3560_led0_get_ctrl(struct v4l2_ctrl *ctrl)
266{
267 return lm3560_get_ctrl(ctrl, LM3560_LED0);
268}
269
270static int lm3560_led0_set_ctrl(struct v4l2_ctrl *ctrl)
271{
272 return lm3560_set_ctrl(ctrl, LM3560_LED0);
273}
274
275static const struct v4l2_ctrl_ops lm3560_led_ctrl_ops[LM3560_LED_MAX] = {
276 [LM3560_LED0] = {
277 .g_volatile_ctrl = lm3560_led0_get_ctrl,
278 .s_ctrl = lm3560_led0_set_ctrl,
279 },
280 [LM3560_LED1] = {
281 .g_volatile_ctrl = lm3560_led1_get_ctrl,
282 .s_ctrl = lm3560_led1_set_ctrl,
283 }
284};
285
286static int lm3560_init_controls(struct lm3560_flash *flash,
287 enum lm3560_led_id led_no)
288{
289 struct v4l2_ctrl *fault;
290 u32 max_flash_brt = flash->pdata->max_flash_brt[led_no];
291 u32 max_torch_brt = flash->pdata->max_torch_brt[led_no];
292 struct v4l2_ctrl_handler *hdl = &flash->ctrls_led[led_no];
293 const struct v4l2_ctrl_ops *ops = &lm3560_led_ctrl_ops[led_no];
294
295 v4l2_ctrl_handler_init(hdl, 8);
296 /* flash mode */
297 v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_FLASH_LED_MODE,
298 V4L2_FLASH_LED_MODE_TORCH, ~0x7,
299 V4L2_FLASH_LED_MODE_NONE);
300 flash->led_mode = V4L2_FLASH_LED_MODE_NONE;
301
302 /* flash source */
303 v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_FLASH_STROBE_SOURCE,
304 0x1, ~0x3, V4L2_FLASH_STROBE_SOURCE_SOFTWARE);
305
306 /* flash strobe */
307 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_STROBE, 0, 0, 0, 0);
308 /* flash strobe stop */
309 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_STROBE_STOP, 0, 0, 0, 0);
310
311 /* flash strobe timeout */
312 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_TIMEOUT,
313 LM3560_FLASH_TOUT_MIN,
314 flash->pdata->max_flash_timeout,
315 LM3560_FLASH_TOUT_STEP,
316 flash->pdata->max_flash_timeout);
317
318 /* flash brt */
319 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_INTENSITY,
320 LM3560_FLASH_BRT_MIN, max_flash_brt,
321 LM3560_FLASH_BRT_STEP, max_flash_brt);
322
323 /* torch brt */
324 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_TORCH_INTENSITY,
325 LM3560_TORCH_BRT_MIN, max_torch_brt,
326 LM3560_TORCH_BRT_STEP, max_torch_brt);
327
328 /* fault */
329 fault = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_FAULT, 0,
330 V4L2_FLASH_FAULT_OVER_VOLTAGE
331 | V4L2_FLASH_FAULT_OVER_TEMPERATURE
332 | V4L2_FLASH_FAULT_SHORT_CIRCUIT
333 | V4L2_FLASH_FAULT_TIMEOUT, 0, 0);
334 if (fault != NULL)
335 fault->flags |= V4L2_CTRL_FLAG_VOLATILE;
336
337 if (hdl->error)
338 return hdl->error;
339
340 flash->subdev_led[led_no].ctrl_handler = hdl;
341 return 0;
342}
343
344/* initialize device */
345static const struct v4l2_subdev_ops lm3560_ops = {
346 .core = NULL,
347};
348
349static const struct regmap_config lm3560_regmap = {
350 .reg_bits = 8,
351 .val_bits = 8,
352 .max_register = 0xFF,
353};
354
355static int lm3560_subdev_init(struct lm3560_flash *flash,
356 enum lm3560_led_id led_no, char *led_name)
357{
358 struct i2c_client *client = to_i2c_client(flash->dev);
359 int rval;
360
361 v4l2_i2c_subdev_init(&flash->subdev_led[led_no], client, &lm3560_ops);
362 flash->subdev_led[led_no].flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
363 strcpy(flash->subdev_led[led_no].name, led_name);
364 rval = lm3560_init_controls(flash, led_no);
365 if (rval)
366 goto err_out;
367 rval = media_entity_init(&flash->subdev_led[led_no].entity, 0, NULL, 0);
368 if (rval < 0)
369 goto err_out;
370 flash->subdev_led[led_no].entity.type = MEDIA_ENT_T_V4L2_SUBDEV_FLASH;
371
372 return rval;
373
374err_out:
375 v4l2_ctrl_handler_free(&flash->ctrls_led[led_no]);
376 return rval;
377}
378
379static int lm3560_init_device(struct lm3560_flash *flash)
380{
381 int rval;
382 unsigned int reg_val;
383
384 /* set peak current */
385 rval = regmap_update_bits(flash->regmap,
386 REG_FLASH_TOUT, 0x60, flash->pdata->peak);
387 if (rval < 0)
388 return rval;
389 /* output disable */
390 flash->led_mode = V4L2_FLASH_LED_MODE_NONE;
391 rval = lm3560_mode_ctrl(flash);
392 if (rval < 0)
393 return rval;
394 /* Reset faults */
395 rval = regmap_read(flash->regmap, REG_FLAG, &reg_val);
396 return rval;
397}
398
399static int lm3560_probe(struct i2c_client *client,
400 const struct i2c_device_id *devid)
401{
402 struct lm3560_flash *flash;
403 struct lm3560_platform_data *pdata = dev_get_platdata(&client->dev);
404 int rval;
405
406 flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL);
407 if (flash == NULL)
408 return -ENOMEM;
409
410 flash->regmap = devm_regmap_init_i2c(client, &lm3560_regmap);
411 if (IS_ERR(flash->regmap)) {
412 rval = PTR_ERR(flash->regmap);
413 return rval;
414 }
415
416 /* if there is no platform data, use chip default value */
417 if (pdata == NULL) {
418 pdata =
419 kzalloc(sizeof(struct lm3560_platform_data), GFP_KERNEL);
420 if (pdata == NULL)
421 return -ENODEV;
422 pdata->peak = LM3560_PEAK_3600mA;
423 pdata->max_flash_timeout = LM3560_FLASH_TOUT_MAX;
424 /* led 1 */
425 pdata->max_flash_brt[LM3560_LED0] = LM3560_FLASH_BRT_MAX;
426 pdata->max_torch_brt[LM3560_LED0] = LM3560_TORCH_BRT_MAX;
427 /* led 2 */
428 pdata->max_flash_brt[LM3560_LED1] = LM3560_FLASH_BRT_MAX;
429 pdata->max_torch_brt[LM3560_LED1] = LM3560_TORCH_BRT_MAX;
430 }
431 flash->pdata = pdata;
432 flash->dev = &client->dev;
433 mutex_init(&flash->lock);
434
435 rval = lm3560_subdev_init(flash, LM3560_LED0, "lm3560-led0");
436 if (rval < 0)
437 return rval;
438
439 rval = lm3560_subdev_init(flash, LM3560_LED1, "lm3560-led1");
440 if (rval < 0)
441 return rval;
442
443 rval = lm3560_init_device(flash);
444 if (rval < 0)
445 return rval;
446
447 return 0;
448}
449
450static int lm3560_remove(struct i2c_client *client)
451{
452 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
453 struct lm3560_flash *flash = container_of(subdev, struct lm3560_flash,
454 subdev_led[LM3560_LED_MAX]);
455 unsigned int i;
456
457 for (i = LM3560_LED0; i < LM3560_LED_MAX; i++) {
458 v4l2_device_unregister_subdev(&flash->subdev_led[i]);
459 v4l2_ctrl_handler_free(&flash->ctrls_led[i]);
460 media_entity_cleanup(&flash->subdev_led[i].entity);
461 }
462
463 return 0;
464}
465
466static const struct i2c_device_id lm3560_id_table[] = {
467 {LM3560_NAME, 0},
468 {}
469};
470
471MODULE_DEVICE_TABLE(i2c, lm3560_id_table);
472
473static struct i2c_driver lm3560_i2c_driver = {
474 .driver = {
475 .name = LM3560_NAME,
476 .pm = NULL,
477 },
478 .probe = lm3560_probe,
479 .remove = lm3560_remove,
480 .id_table = lm3560_id_table,
481};
482
483module_i2c_driver(lm3560_i2c_driver);
484
485MODULE_AUTHOR("Daniel Jeong <gshark.jeong@gmail.com>");
486MODULE_AUTHOR("Ldd Mlp <ldd-mlp@list.ti.com>");
487MODULE_DESCRIPTION("Texas Instruments LM3560 LED flash driver");
488MODULE_LICENSE("GPL");
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 31f40b342049..6fec9384d86e 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1581,7 +1581,7 @@ static int s5c73m3_probe(struct i2c_client *client,
1581 oif_sd = &state->oif_sd; 1581 oif_sd = &state->oif_sd;
1582 1582
1583 v4l2_subdev_init(sd, &s5c73m3_subdev_ops); 1583 v4l2_subdev_init(sd, &s5c73m3_subdev_ops);
1584 sd->owner = client->driver->driver.owner; 1584 sd->owner = client->dev.driver->owner;
1585 v4l2_set_subdevdata(sd, state); 1585 v4l2_set_subdevdata(sd, state);
1586 strlcpy(sd->name, "S5C73M3", sizeof(sd->name)); 1586 strlcpy(sd->name, "S5C73M3", sizeof(sd->name));
1587 1587
diff --git a/drivers/media/i2c/soc_camera/imx074.c b/drivers/media/i2c/soc_camera/imx074.c
index 1d384a371b41..5b915936c3f3 100644
--- a/drivers/media/i2c/soc_camera/imx074.c
+++ b/drivers/media/i2c/soc_camera/imx074.c
@@ -451,7 +451,9 @@ static int imx074_probe(struct i2c_client *client,
451 if (ret < 0) 451 if (ret < 0)
452 goto eprobe; 452 goto eprobe;
453 453
454 return v4l2_async_register_subdev(&priv->subdev); 454 ret = v4l2_async_register_subdev(&priv->subdev);
455 if (!ret)
456 return 0;
455 457
456epwrinit: 458epwrinit:
457eprobe: 459eprobe:
diff --git a/drivers/media/i2c/soc_camera/ov9640.c b/drivers/media/i2c/soc_camera/ov9640.c
index e968c3fdbd9e..bc74224503e7 100644
--- a/drivers/media/i2c/soc_camera/ov9640.c
+++ b/drivers/media/i2c/soc_camera/ov9640.c
@@ -371,7 +371,7 @@ static void ov9640_alter_regs(enum v4l2_mbus_pixelcode code,
371 alt->com13 = OV9640_COM13_RGB_AVG; 371 alt->com13 = OV9640_COM13_RGB_AVG;
372 alt->com15 = OV9640_COM15_RGB_565; 372 alt->com15 = OV9640_COM15_RGB_565;
373 break; 373 break;
374 }; 374 }
375} 375}
376 376
377/* Setup registers according to resolution and color encoding */ 377/* Setup registers according to resolution and color encoding */
diff --git a/drivers/media/i2c/ths8200.c b/drivers/media/i2c/ths8200.c
index d9f65d7e3e58..04139eec8c4e 100644
--- a/drivers/media/i2c/ths8200.c
+++ b/drivers/media/i2c/ths8200.c
@@ -19,6 +19,7 @@
19 19
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/of.h>
22#include <linux/v4l2-dv-timings.h> 23#include <linux/v4l2-dv-timings.h>
23 24
24#include <media/v4l2-dv-timings.h> 25#include <media/v4l2-dv-timings.h>
diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index 91f3dd4cda1b..83d85df4853a 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -35,6 +35,7 @@
35#include <linux/videodev2.h> 35#include <linux/videodev2.h>
36#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/v4l2-mediabus.h> 37#include <linux/v4l2-mediabus.h>
38#include <linux/of.h>
38 39
39#include <media/v4l2-async.h> 40#include <media/v4l2-async.h>
40#include <media/v4l2-device.h> 41#include <media/v4l2-device.h>
diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c
index 24a08fa7e328..912e1cccdd1c 100644
--- a/drivers/media/i2c/tvp7002.c
+++ b/drivers/media/i2c/tvp7002.c
@@ -29,6 +29,7 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/videodev2.h> 30#include <linux/videodev2.h>
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/of.h>
32#include <linux/v4l2-dv-timings.h> 33#include <linux/v4l2-dv-timings.h>
33#include <media/tvp7002.h> 34#include <media/tvp7002.h>
34#include <media/v4l2-async.h> 35#include <media/v4l2-async.h>
diff --git a/drivers/media/pci/b2c2/flexcop-pci.c b/drivers/media/pci/b2c2/flexcop-pci.c
index 447afbd904a4..8b5e0b3a92a0 100644
--- a/drivers/media/pci/b2c2/flexcop-pci.c
+++ b/drivers/media/pci/b2c2/flexcop-pci.c
@@ -319,7 +319,6 @@ static int flexcop_pci_init(struct flexcop_pci *fc_pci)
319 319
320err_pci_iounmap: 320err_pci_iounmap:
321 pci_iounmap(fc_pci->pdev, fc_pci->io_mem); 321 pci_iounmap(fc_pci->pdev, fc_pci->io_mem);
322 pci_set_drvdata(fc_pci->pdev, NULL);
323err_pci_release_regions: 322err_pci_release_regions:
324 pci_release_regions(fc_pci->pdev); 323 pci_release_regions(fc_pci->pdev);
325err_pci_disable_device: 324err_pci_disable_device:
@@ -332,7 +331,6 @@ static void flexcop_pci_exit(struct flexcop_pci *fc_pci)
332 if (fc_pci->init_state & FC_PCI_INIT) { 331 if (fc_pci->init_state & FC_PCI_INIT) {
333 free_irq(fc_pci->pdev->irq, fc_pci); 332 free_irq(fc_pci->pdev->irq, fc_pci);
334 pci_iounmap(fc_pci->pdev, fc_pci->io_mem); 333 pci_iounmap(fc_pci->pdev, fc_pci->io_mem);
335 pci_set_drvdata(fc_pci->pdev, NULL);
336 pci_release_regions(fc_pci->pdev); 334 pci_release_regions(fc_pci->pdev);
337 pci_disable_device(fc_pci->pdev); 335 pci_disable_device(fc_pci->pdev);
338 } 336 }
diff --git a/drivers/media/pci/bt8xx/bt878.c b/drivers/media/pci/bt8xx/bt878.c
index 66eb0baab0e9..d0c281f41a0a 100644
--- a/drivers/media/pci/bt8xx/bt878.c
+++ b/drivers/media/pci/bt8xx/bt878.c
@@ -488,8 +488,7 @@ static int bt878_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
488 btwrite(0, BT848_INT_MASK); 488 btwrite(0, BT848_INT_MASK);
489 489
490 result = request_irq(bt->irq, bt878_irq, 490 result = request_irq(bt->irq, bt878_irq,
491 IRQF_SHARED | IRQF_DISABLED, "bt878", 491 IRQF_SHARED, "bt878", (void *) bt);
492 (void *) bt);
493 if (result == -EINVAL) { 492 if (result == -EINVAL) {
494 printk(KERN_ERR "bt878(%d): Bad irq number or handler\n", 493 printk(KERN_ERR "bt878(%d): Bad irq number or handler\n",
495 bt878_num); 494 bt878_num);
@@ -563,7 +562,6 @@ static void bt878_remove(struct pci_dev *pci_dev)
563 bt->shutdown = 1; 562 bt->shutdown = 1;
564 bt878_mem_free(bt); 563 bt878_mem_free(bt);
565 564
566 pci_set_drvdata(pci_dev, NULL);
567 pci_disable_device(pci_dev); 565 pci_disable_device(pci_dev);
568 return; 566 return;
569} 567}
diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index c6532de0eac7..a3b1ee9c00d7 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -4086,7 +4086,7 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
4086 /* disable irqs, register irq handler */ 4086 /* disable irqs, register irq handler */
4087 btwrite(0, BT848_INT_MASK); 4087 btwrite(0, BT848_INT_MASK);
4088 result = request_irq(btv->c.pci->irq, bttv_irq, 4088 result = request_irq(btv->c.pci->irq, bttv_irq,
4089 IRQF_SHARED | IRQF_DISABLED, btv->c.v4l2_dev.name, (void *)btv); 4089 IRQF_SHARED, btv->c.v4l2_dev.name, (void *)btv);
4090 if (result < 0) { 4090 if (result < 0) {
4091 pr_err("%d: can't get IRQ %d\n", 4091 pr_err("%d: can't get IRQ %d\n",
4092 bttv_num, btv->c.pci->irq); 4092 bttv_num, btv->c.pci->irq);
diff --git a/drivers/media/pci/cx18/cx18-driver.c b/drivers/media/pci/cx18/cx18-driver.c
index 004d8ace5019..c1f8cc6f14b2 100644
--- a/drivers/media/pci/cx18/cx18-driver.c
+++ b/drivers/media/pci/cx18/cx18-driver.c
@@ -324,23 +324,24 @@ static void cx18_eeprom_dump(struct cx18 *cx, unsigned char *eedata, int len)
324/* Hauppauge card? get values from tveeprom */ 324/* Hauppauge card? get values from tveeprom */
325void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv) 325void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
326{ 326{
327 struct i2c_client c; 327 struct i2c_client *c;
328 u8 eedata[256]; 328 u8 eedata[256];
329 329
330 memset(&c, 0, sizeof(c)); 330 c = kzalloc(sizeof(*c), GFP_KERNEL);
331 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name)); 331
332 c.adapter = &cx->i2c_adap[0]; 332 strlcpy(c->name, "cx18 tveeprom tmp", sizeof(c->name));
333 c.addr = 0xA0 >> 1; 333 c->adapter = &cx->i2c_adap[0];
334 c->addr = 0xa0 >> 1;
334 335
335 memset(tv, 0, sizeof(*tv)); 336 memset(tv, 0, sizeof(*tv));
336 if (tveeprom_read(&c, eedata, sizeof(eedata))) 337 if (tveeprom_read(c, eedata, sizeof(eedata)))
337 return; 338 goto ret;
338 339
339 switch (cx->card->type) { 340 switch (cx->card->type) {
340 case CX18_CARD_HVR_1600_ESMT: 341 case CX18_CARD_HVR_1600_ESMT:
341 case CX18_CARD_HVR_1600_SAMSUNG: 342 case CX18_CARD_HVR_1600_SAMSUNG:
342 case CX18_CARD_HVR_1600_S5H1411: 343 case CX18_CARD_HVR_1600_S5H1411:
343 tveeprom_hauppauge_analog(&c, tv, eedata); 344 tveeprom_hauppauge_analog(c, tv, eedata);
344 break; 345 break;
345 case CX18_CARD_YUAN_MPC718: 346 case CX18_CARD_YUAN_MPC718:
346 case CX18_CARD_GOTVIEW_PCI_DVD3: 347 case CX18_CARD_GOTVIEW_PCI_DVD3:
@@ -354,6 +355,9 @@ void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
354 cx18_eeprom_dump(cx, eedata, sizeof(eedata)); 355 cx18_eeprom_dump(cx, eedata, sizeof(eedata));
355 break; 356 break;
356 } 357 }
358
359ret:
360 kfree(c);
357} 361}
358 362
359static void cx18_process_eeprom(struct cx18 *cx) 363static void cx18_process_eeprom(struct cx18 *cx)
@@ -1031,8 +1035,7 @@ static int cx18_probe(struct pci_dev *pci_dev,
1031 1035
1032 /* Register IRQ */ 1036 /* Register IRQ */
1033 retval = request_irq(cx->pci_dev->irq, cx18_irq_handler, 1037 retval = request_irq(cx->pci_dev->irq, cx18_irq_handler,
1034 IRQF_SHARED | IRQF_DISABLED, 1038 IRQF_SHARED, cx->v4l2_dev.name, (void *)cx);
1035 cx->v4l2_dev.name, (void *)cx);
1036 if (retval) { 1039 if (retval) {
1037 CX18_ERR("Failed to register irq %d\n", retval); 1040 CX18_ERR("Failed to register irq %d\n", retval);
1038 goto free_i2c; 1041 goto free_i2c;
diff --git a/drivers/media/pci/cx23885/Kconfig b/drivers/media/pci/cx23885/Kconfig
index 5104c802f72f..d1dcb1d2e087 100644
--- a/drivers/media/pci/cx23885/Kconfig
+++ b/drivers/media/pci/cx23885/Kconfig
@@ -23,6 +23,7 @@ config VIDEO_CX23885
23 select DVB_STB6100 if MEDIA_SUBDRV_AUTOSELECT 23 select DVB_STB6100 if MEDIA_SUBDRV_AUTOSELECT
24 select DVB_STV6110 if MEDIA_SUBDRV_AUTOSELECT 24 select DVB_STV6110 if MEDIA_SUBDRV_AUTOSELECT
25 select DVB_CX24116 if MEDIA_SUBDRV_AUTOSELECT 25 select DVB_CX24116 if MEDIA_SUBDRV_AUTOSELECT
26 select DVB_CX24117 if MEDIA_SUBDRV_AUTOSELECT
26 select DVB_STV0900 if MEDIA_SUBDRV_AUTOSELECT 27 select DVB_STV0900 if MEDIA_SUBDRV_AUTOSELECT
27 select DVB_DS3000 if MEDIA_SUBDRV_AUTOSELECT 28 select DVB_DS3000 if MEDIA_SUBDRV_AUTOSELECT
28 select DVB_TS2020 if MEDIA_SUBDRV_AUTOSELECT 29 select DVB_TS2020 if MEDIA_SUBDRV_AUTOSELECT
diff --git a/drivers/media/pci/cx23885/cimax2.c b/drivers/media/pci/cx23885/cimax2.c
index 7344849183a7..16fa7ea4d4aa 100644
--- a/drivers/media/pci/cx23885/cimax2.c
+++ b/drivers/media/pci/cx23885/cimax2.c
@@ -26,6 +26,10 @@
26#include "cx23885.h" 26#include "cx23885.h"
27#include "cimax2.h" 27#include "cimax2.h"
28#include "dvb_ca_en50221.h" 28#include "dvb_ca_en50221.h"
29
30/* Max transfer size done by I2C transfer functions */
31#define MAX_XFER_SIZE 64
32
29/**** Bit definitions for MC417_RWD and MC417_OEN registers *** 33/**** Bit definitions for MC417_RWD and MC417_OEN registers ***
30 bits 31-16 34 bits 31-16
31+-----------+ 35+-----------+
@@ -125,7 +129,7 @@ static int netup_write_i2c(struct i2c_adapter *i2c_adap, u8 addr, u8 reg,
125 u8 *buf, int len) 129 u8 *buf, int len)
126{ 130{
127 int ret; 131 int ret;
128 u8 buffer[len + 1]; 132 u8 buffer[MAX_XFER_SIZE];
129 133
130 struct i2c_msg msg = { 134 struct i2c_msg msg = {
131 .addr = addr, 135 .addr = addr,
@@ -134,6 +138,13 @@ static int netup_write_i2c(struct i2c_adapter *i2c_adap, u8 addr, u8 reg,
134 .len = len + 1 138 .len = len + 1
135 }; 139 };
136 140
141 if (1 + len > sizeof(buffer)) {
142 printk(KERN_WARNING
143 "%s: i2c wr reg=%04x: len=%d is too big!\n",
144 KBUILD_MODNAME, reg, len);
145 return -EINVAL;
146 }
147
137 buffer[0] = reg; 148 buffer[0] = reg;
138 memcpy(&buffer[1], buf, len); 149 memcpy(&buffer[1], buf, len);
139 150
diff --git a/drivers/media/pci/cx23885/cx23885-cards.c b/drivers/media/pci/cx23885/cx23885-cards.c
index 6a71a965e757..79f20c8c842e 100644
--- a/drivers/media/pci/cx23885/cx23885-cards.c
+++ b/drivers/media/pci/cx23885/cx23885-cards.c
@@ -223,6 +223,39 @@ struct cx23885_board cx23885_boards[] = {
223 .name = "Leadtek Winfast PxDVR3200 H", 223 .name = "Leadtek Winfast PxDVR3200 H",
224 .portc = CX23885_MPEG_DVB, 224 .portc = CX23885_MPEG_DVB,
225 }, 225 },
226 [CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200] = {
227 .name = "Leadtek Winfast PxPVR2200",
228 .porta = CX23885_ANALOG_VIDEO,
229 .tuner_type = TUNER_XC2028,
230 .tuner_addr = 0x61,
231 .tuner_bus = 1,
232 .input = {{
233 .type = CX23885_VMUX_TELEVISION,
234 .vmux = CX25840_VIN2_CH1 |
235 CX25840_VIN5_CH2,
236 .amux = CX25840_AUDIO8,
237 .gpio0 = 0x704040,
238 }, {
239 .type = CX23885_VMUX_COMPOSITE1,
240 .vmux = CX25840_COMPOSITE1,
241 .amux = CX25840_AUDIO7,
242 .gpio0 = 0x704040,
243 }, {
244 .type = CX23885_VMUX_SVIDEO,
245 .vmux = CX25840_SVIDEO_LUMA3 |
246 CX25840_SVIDEO_CHROMA4,
247 .amux = CX25840_AUDIO7,
248 .gpio0 = 0x704040,
249 }, {
250 .type = CX23885_VMUX_COMPONENT,
251 .vmux = CX25840_VIN7_CH1 |
252 CX25840_VIN6_CH2 |
253 CX25840_VIN8_CH3 |
254 CX25840_COMPONENT_ON,
255 .amux = CX25840_AUDIO7,
256 .gpio0 = 0x704040,
257 } },
258 },
226 [CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000] = { 259 [CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000] = {
227 .name = "Leadtek Winfast PxDVR3200 H XC4000", 260 .name = "Leadtek Winfast PxDVR3200 H XC4000",
228 .porta = CX23885_ANALOG_VIDEO, 261 .porta = CX23885_ANALOG_VIDEO,
@@ -259,6 +292,16 @@ struct cx23885_board cx23885_boards[] = {
259 .name = "TurboSight TBS 6920", 292 .name = "TurboSight TBS 6920",
260 .portb = CX23885_MPEG_DVB, 293 .portb = CX23885_MPEG_DVB,
261 }, 294 },
295 [CX23885_BOARD_TBS_6980] = {
296 .name = "TurboSight TBS 6980",
297 .portb = CX23885_MPEG_DVB,
298 .portc = CX23885_MPEG_DVB,
299 },
300 [CX23885_BOARD_TBS_6981] = {
301 .name = "TurboSight TBS 6981",
302 .portb = CX23885_MPEG_DVB,
303 .portc = CX23885_MPEG_DVB,
304 },
262 [CX23885_BOARD_TEVII_S470] = { 305 [CX23885_BOARD_TEVII_S470] = {
263 .name = "TeVii S470", 306 .name = "TeVii S470",
264 .portb = CX23885_MPEG_DVB, 307 .portb = CX23885_MPEG_DVB,
@@ -688,6 +731,10 @@ struct cx23885_subid cx23885_subids[] = {
688 .card = CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H, 731 .card = CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H,
689 }, { 732 }, {
690 .subvendor = 0x107d, 733 .subvendor = 0x107d,
734 .subdevice = 0x6f21,
735 .card = CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200,
736 }, {
737 .subvendor = 0x107d,
691 .subdevice = 0x6f39, 738 .subdevice = 0x6f39,
692 .card = CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000, 739 .card = CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000,
693 }, { 740 }, {
@@ -699,6 +746,14 @@ struct cx23885_subid cx23885_subids[] = {
699 .subdevice = 0x8888, 746 .subdevice = 0x8888,
700 .card = CX23885_BOARD_TBS_6920, 747 .card = CX23885_BOARD_TBS_6920,
701 }, { 748 }, {
749 .subvendor = 0x6980,
750 .subdevice = 0x8888,
751 .card = CX23885_BOARD_TBS_6980,
752 }, {
753 .subvendor = 0x6981,
754 .subdevice = 0x8888,
755 .card = CX23885_BOARD_TBS_6981,
756 }, {
702 .subvendor = 0xd470, 757 .subvendor = 0xd470,
703 .subdevice = 0x9022, 758 .subdevice = 0x9022,
704 .card = CX23885_BOARD_TEVII_S470, 759 .card = CX23885_BOARD_TEVII_S470,
@@ -1023,6 +1078,35 @@ static void hauppauge_eeprom(struct cx23885_dev *dev, u8 *eeprom_data)
1023 dev->name, tv.model); 1078 dev->name, tv.model);
1024} 1079}
1025 1080
1081/* Some TBS cards require initing a chip using a bitbanged SPI attached
1082 to the cx23885 gpio's. If this chip doesn't get init'ed the demod
1083 doesn't respond to any command. */
1084static void tbs_card_init(struct cx23885_dev *dev)
1085{
1086 int i;
1087 const u8 buf[] = {
1088 0xe0, 0x06, 0x66, 0x33, 0x65,
1089 0x01, 0x17, 0x06, 0xde};
1090
1091 switch (dev->board) {
1092 case CX23885_BOARD_TBS_6980:
1093 case CX23885_BOARD_TBS_6981:
1094 cx_set(GP0_IO, 0x00070007);
1095 usleep_range(1000, 10000);
1096 cx_clear(GP0_IO, 2);
1097 usleep_range(1000, 10000);
1098 for (i = 0; i < 9 * 8; i++) {
1099 cx_clear(GP0_IO, 7);
1100 usleep_range(1000, 10000);
1101 cx_set(GP0_IO,
1102 ((buf[i >> 3] >> (7 - (i & 7))) & 1) | 4);
1103 usleep_range(1000, 10000);
1104 }
1105 cx_set(GP0_IO, 7);
1106 break;
1107 }
1108}
1109
1026int cx23885_tuner_callback(void *priv, int component, int command, int arg) 1110int cx23885_tuner_callback(void *priv, int component, int command, int arg)
1027{ 1111{
1028 struct cx23885_tsport *port = priv; 1112 struct cx23885_tsport *port = priv;
@@ -1043,6 +1127,7 @@ int cx23885_tuner_callback(void *priv, int component, int command, int arg)
1043 case CX23885_BOARD_HAUPPAUGE_HVR1500: 1127 case CX23885_BOARD_HAUPPAUGE_HVR1500:
1044 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 1128 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
1045 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H: 1129 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
1130 case CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200:
1046 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000: 1131 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
1047 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F: 1132 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
1048 case CX23885_BOARD_COMPRO_VIDEOMATE_E800: 1133 case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
@@ -1208,6 +1293,7 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
1208 cx_set(GP0_IO, 0x000f000f); 1293 cx_set(GP0_IO, 0x000f000f);
1209 break; 1294 break;
1210 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H: 1295 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
1296 case CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200:
1211 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000: 1297 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
1212 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F: 1298 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
1213 case CX23885_BOARD_COMPRO_VIDEOMATE_E800: 1299 case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
@@ -1225,6 +1311,8 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
1225 cx_set(GP0_IO, 0x00040004); 1311 cx_set(GP0_IO, 0x00040004);
1226 break; 1312 break;
1227 case CX23885_BOARD_TBS_6920: 1313 case CX23885_BOARD_TBS_6920:
1314 case CX23885_BOARD_TBS_6980:
1315 case CX23885_BOARD_TBS_6981:
1228 case CX23885_BOARD_PROF_8000: 1316 case CX23885_BOARD_PROF_8000:
1229 cx_write(MC417_CTL, 0x00000036); 1317 cx_write(MC417_CTL, 0x00000036);
1230 cx_write(MC417_OEN, 0x00001000); 1318 cx_write(MC417_OEN, 0x00001000);
@@ -1473,6 +1561,8 @@ int cx23885_ir_init(struct cx23885_dev *dev)
1473 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL: 1561 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
1474 case CX23885_BOARD_TEVII_S470: 1562 case CX23885_BOARD_TEVII_S470:
1475 case CX23885_BOARD_MYGICA_X8507: 1563 case CX23885_BOARD_MYGICA_X8507:
1564 case CX23885_BOARD_TBS_6980:
1565 case CX23885_BOARD_TBS_6981:
1476 if (!enable_885_ir) 1566 if (!enable_885_ir)
1477 break; 1567 break;
1478 dev->sd_ir = cx23885_find_hw(dev, CX23885_HW_AV_CORE); 1568 dev->sd_ir = cx23885_find_hw(dev, CX23885_HW_AV_CORE);
@@ -1516,6 +1606,8 @@ void cx23885_ir_fini(struct cx23885_dev *dev)
1516 case CX23885_BOARD_TEVII_S470: 1606 case CX23885_BOARD_TEVII_S470:
1517 case CX23885_BOARD_HAUPPAUGE_HVR1250: 1607 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1518 case CX23885_BOARD_MYGICA_X8507: 1608 case CX23885_BOARD_MYGICA_X8507:
1609 case CX23885_BOARD_TBS_6980:
1610 case CX23885_BOARD_TBS_6981:
1519 cx23885_irq_remove(dev, PCI_MSK_AV_CORE); 1611 cx23885_irq_remove(dev, PCI_MSK_AV_CORE);
1520 /* sd_ir is a duplicate pointer to the AV Core, just clear it */ 1612 /* sd_ir is a duplicate pointer to the AV Core, just clear it */
1521 dev->sd_ir = NULL; 1613 dev->sd_ir = NULL;
@@ -1561,6 +1653,8 @@ void cx23885_ir_pci_int_enable(struct cx23885_dev *dev)
1561 case CX23885_BOARD_TEVII_S470: 1653 case CX23885_BOARD_TEVII_S470:
1562 case CX23885_BOARD_HAUPPAUGE_HVR1250: 1654 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1563 case CX23885_BOARD_MYGICA_X8507: 1655 case CX23885_BOARD_MYGICA_X8507:
1656 case CX23885_BOARD_TBS_6980:
1657 case CX23885_BOARD_TBS_6981:
1564 if (dev->sd_ir) 1658 if (dev->sd_ir)
1565 cx23885_irq_add_enable(dev, PCI_MSK_AV_CORE); 1659 cx23885_irq_add_enable(dev, PCI_MSK_AV_CORE);
1566 break; 1660 break;
@@ -1676,6 +1770,16 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1676 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */ 1770 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
1677 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; 1771 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
1678 break; 1772 break;
1773 case CX23885_BOARD_TBS_6980:
1774 case CX23885_BOARD_TBS_6981:
1775 ts1->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
1776 ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */
1777 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
1778 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
1779 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
1780 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
1781 tbs_card_init(dev);
1782 break;
1679 case CX23885_BOARD_MYGICA_X8506: 1783 case CX23885_BOARD_MYGICA_X8506:
1680 case CX23885_BOARD_MAGICPRO_PROHDTVE2: 1784 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
1681 case CX23885_BOARD_MYGICA_X8507: 1785 case CX23885_BOARD_MYGICA_X8507:
@@ -1704,6 +1808,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1704 case CX23885_BOARD_HAUPPAUGE_HVR1700: 1808 case CX23885_BOARD_HAUPPAUGE_HVR1700:
1705 case CX23885_BOARD_HAUPPAUGE_HVR1400: 1809 case CX23885_BOARD_HAUPPAUGE_HVR1400:
1706 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H: 1810 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
1811 case CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200:
1707 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000: 1812 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
1708 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F: 1813 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
1709 case CX23885_BOARD_HAUPPAUGE_HVR1270: 1814 case CX23885_BOARD_HAUPPAUGE_HVR1270:
@@ -1733,6 +1838,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1733 case CX23885_BOARD_HAUPPAUGE_HVR1800lp: 1838 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
1734 case CX23885_BOARD_HAUPPAUGE_HVR1700: 1839 case CX23885_BOARD_HAUPPAUGE_HVR1700:
1735 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H: 1840 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
1841 case CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200:
1736 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000: 1842 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
1737 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F: 1843 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
1738 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: 1844 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
@@ -1752,6 +1858,8 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1752 case CX23885_BOARD_MYGICA_X8507: 1858 case CX23885_BOARD_MYGICA_X8507:
1753 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL: 1859 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
1754 case CX23885_BOARD_AVERMEDIA_HC81R: 1860 case CX23885_BOARD_AVERMEDIA_HC81R:
1861 case CX23885_BOARD_TBS_6980:
1862 case CX23885_BOARD_TBS_6981:
1755 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, 1863 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1756 &dev->i2c_bus[2].i2c_adap, 1864 &dev->i2c_bus[2].i2c_adap,
1757 "cx25840", 0x88 >> 1, NULL); 1865 "cx25840", 0x88 >> 1, NULL);
diff --git a/drivers/media/pci/cx23885/cx23885-core.c b/drivers/media/pci/cx23885/cx23885-core.c
index 9f63d93239ec..edcd79db1e4e 100644
--- a/drivers/media/pci/cx23885/cx23885-core.c
+++ b/drivers/media/pci/cx23885/cx23885-core.c
@@ -2129,7 +2129,7 @@ static int cx23885_initdev(struct pci_dev *pci_dev,
2129 } 2129 }
2130 2130
2131 err = request_irq(pci_dev->irq, cx23885_irq, 2131 err = request_irq(pci_dev->irq, cx23885_irq,
2132 IRQF_SHARED | IRQF_DISABLED, dev->name, dev); 2132 IRQF_SHARED, dev->name, dev);
2133 if (err < 0) { 2133 if (err < 0) {
2134 printk(KERN_ERR "%s: can't get IRQ %d\n", 2134 printk(KERN_ERR "%s: can't get IRQ %d\n",
2135 dev->name, pci_dev->irq); 2135 dev->name, pci_dev->irq);
diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c
index 971e4ff1b87f..05492053b473 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -51,6 +51,7 @@
51#include "stv6110.h" 51#include "stv6110.h"
52#include "lnbh24.h" 52#include "lnbh24.h"
53#include "cx24116.h" 53#include "cx24116.h"
54#include "cx24117.h"
54#include "cimax2.h" 55#include "cimax2.h"
55#include "lgs8gxx.h" 56#include "lgs8gxx.h"
56#include "netup-eeprom.h" 57#include "netup-eeprom.h"
@@ -461,6 +462,10 @@ static struct cx24116_config tbs_cx24116_config = {
461 .demod_address = 0x55, 462 .demod_address = 0x55,
462}; 463};
463 464
465static struct cx24117_config tbs_cx24117_config = {
466 .demod_address = 0x55,
467};
468
464static struct ds3000_config tevii_ds3000_config = { 469static struct ds3000_config tevii_ds3000_config = {
465 .demod_address = 0x68, 470 .demod_address = 0x68,
466}; 471};
@@ -1044,6 +1049,25 @@ static int dvb_register(struct cx23885_tsport *port)
1044 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage; 1049 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
1045 1050
1046 break; 1051 break;
1052 case CX23885_BOARD_TBS_6980:
1053 case CX23885_BOARD_TBS_6981:
1054 i2c_bus = &dev->i2c_bus[1];
1055
1056 switch (port->nr) {
1057 /* PORT B */
1058 case 1:
1059 fe0->dvb.frontend = dvb_attach(cx24117_attach,
1060 &tbs_cx24117_config,
1061 &i2c_bus->i2c_adap);
1062 break;
1063 /* PORT C */
1064 case 2:
1065 fe0->dvb.frontend = dvb_attach(cx24117_attach,
1066 &tbs_cx24117_config,
1067 &i2c_bus->i2c_adap);
1068 break;
1069 }
1070 break;
1047 case CX23885_BOARD_TEVII_S470: 1071 case CX23885_BOARD_TEVII_S470:
1048 i2c_bus = &dev->i2c_bus[1]; 1072 i2c_bus = &dev->i2c_bus[1];
1049 1073
diff --git a/drivers/media/pci/cx23885/cx23885-input.c b/drivers/media/pci/cx23885/cx23885-input.c
index 7875dfbe09ff..8a49e7c9eddd 100644
--- a/drivers/media/pci/cx23885/cx23885-input.c
+++ b/drivers/media/pci/cx23885/cx23885-input.c
@@ -90,6 +90,8 @@ void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events)
90 case CX23885_BOARD_TEVII_S470: 90 case CX23885_BOARD_TEVII_S470:
91 case CX23885_BOARD_HAUPPAUGE_HVR1250: 91 case CX23885_BOARD_HAUPPAUGE_HVR1250:
92 case CX23885_BOARD_MYGICA_X8507: 92 case CX23885_BOARD_MYGICA_X8507:
93 case CX23885_BOARD_TBS_6980:
94 case CX23885_BOARD_TBS_6981:
93 /* 95 /*
94 * The only boards we handle right now. However other boards 96 * The only boards we handle right now. However other boards
95 * using the CX2388x integrated IR controller should be similar 97 * using the CX2388x integrated IR controller should be similar
@@ -168,6 +170,8 @@ static int cx23885_input_ir_start(struct cx23885_dev *dev)
168 break; 170 break;
169 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL: 171 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
170 case CX23885_BOARD_TEVII_S470: 172 case CX23885_BOARD_TEVII_S470:
173 case CX23885_BOARD_TBS_6980:
174 case CX23885_BOARD_TBS_6981:
171 /* 175 /*
172 * The IR controller on this board only returns pulse widths. 176 * The IR controller on this board only returns pulse widths.
173 * Any other mode setting will fail to set up the device. 177 * Any other mode setting will fail to set up the device.
@@ -298,6 +302,14 @@ int cx23885_input_init(struct cx23885_dev *dev)
298 /* A guess at the remote */ 302 /* A guess at the remote */
299 rc_map = RC_MAP_TOTAL_MEDIA_IN_HAND_02; 303 rc_map = RC_MAP_TOTAL_MEDIA_IN_HAND_02;
300 break; 304 break;
305 case CX23885_BOARD_TBS_6980:
306 case CX23885_BOARD_TBS_6981:
307 /* Integrated CX23885 IR controller */
308 driver_type = RC_DRIVER_IR_RAW;
309 allowed_protos = RC_BIT_ALL;
310 /* A guess at the remote */
311 rc_map = RC_MAP_TBS_NEC;
312 break;
301 default: 313 default:
302 return -ENODEV; 314 return -ENODEV;
303 } 315 }
diff --git a/drivers/media/pci/cx23885/cx23885-video.c b/drivers/media/pci/cx23885/cx23885-video.c
index 161686832b20..7891f34157d1 100644
--- a/drivers/media/pci/cx23885/cx23885-video.c
+++ b/drivers/media/pci/cx23885/cx23885-video.c
@@ -1865,7 +1865,8 @@ int cx23885_video_register(struct cx23885_dev *dev)
1865 1865
1866 v4l2_subdev_call(sd, tuner, s_type_addr, &tun_setup); 1866 v4l2_subdev_call(sd, tuner, s_type_addr, &tun_setup);
1867 1867
1868 if (dev->board == CX23885_BOARD_LEADTEK_WINFAST_PXTV1200) { 1868 if ((dev->board == CX23885_BOARD_LEADTEK_WINFAST_PXTV1200) ||
1869 (dev->board == CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200)) {
1869 struct xc2028_ctrl ctrl = { 1870 struct xc2028_ctrl ctrl = {
1870 .fname = XC2028_DEFAULT_FIRMWARE, 1871 .fname = XC2028_DEFAULT_FIRMWARE,
1871 .max_len = 64 1872 .max_len = 64
diff --git a/drivers/media/pci/cx23885/cx23885.h b/drivers/media/pci/cx23885/cx23885.h
index 038caf53908b..0fa4048ab872 100644
--- a/drivers/media/pci/cx23885/cx23885.h
+++ b/drivers/media/pci/cx23885/cx23885.h
@@ -93,6 +93,9 @@
93#define CX23885_BOARD_PROF_8000 37 93#define CX23885_BOARD_PROF_8000 37
94#define CX23885_BOARD_HAUPPAUGE_HVR4400 38 94#define CX23885_BOARD_HAUPPAUGE_HVR4400 38
95#define CX23885_BOARD_AVERMEDIA_HC81R 39 95#define CX23885_BOARD_AVERMEDIA_HC81R 39
96#define CX23885_BOARD_TBS_6981 40
97#define CX23885_BOARD_TBS_6980 41
98#define CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200 42
96 99
97#define GPIO_0 0x00000001 100#define GPIO_0 0x00000001
98#define GPIO_1 0x00000002 101#define GPIO_1 0x00000002
diff --git a/drivers/media/pci/cx25821/cx25821-cards.c b/drivers/media/pci/cx25821/cx25821-cards.c
index 3b409feb03d8..f2ebc989b303 100644
--- a/drivers/media/pci/cx25821/cx25821-cards.c
+++ b/drivers/media/pci/cx25821/cx25821-cards.c
@@ -45,5 +45,3 @@ struct cx25821_board cx25821_boards[] = {
45 }, 45 },
46 46
47}; 47};
48
49const unsigned int cx25821_bcount = ARRAY_SIZE(cx25821_boards);
diff --git a/drivers/media/pci/cx25821/cx25821-medusa-video.c b/drivers/media/pci/cx25821/cx25821-medusa-video.c
index 22fa04415ccc..43bdfa4dfba1 100644
--- a/drivers/media/pci/cx25821/cx25821-medusa-video.c
+++ b/drivers/media/pci/cx25821/cx25821-medusa-video.c
@@ -438,7 +438,7 @@ void medusa_set_resolution(struct cx25821_dev *dev, int width,
438 decoder_count = decoder_select + 1; 438 decoder_count = decoder_select + 1;
439 } else { 439 } else {
440 decoder = 0; 440 decoder = 0;
441 decoder_count = _num_decoders; 441 decoder_count = dev->_max_num_decoders;
442 } 442 }
443 443
444 switch (width) { 444 switch (width) {
@@ -506,8 +506,6 @@ static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder,
506 break; 506 break;
507 } 507 }
508 508
509 _display_field_cnt[decoder] = duration;
510
511 /* update hardware */ 509 /* update hardware */
512 fld_cnt = cx25821_i2c_read(&dev->i2c_bus[0], disp_cnt_reg, &tmp); 510 fld_cnt = cx25821_i2c_read(&dev->i2c_bus[0], disp_cnt_reg, &tmp);
513 511
@@ -667,8 +665,6 @@ int medusa_video_init(struct cx25821_dev *dev)
667 int ret_val = 0; 665 int ret_val = 0;
668 int i = 0; 666 int i = 0;
669 667
670 _num_decoders = dev->_max_num_decoders;
671
672 /* disable Auto source selection on all video decoders */ 668 /* disable Auto source selection on all video decoders */
673 value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp); 669 value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp);
674 value &= 0xFFFFF0FF; 670 value &= 0xFFFFF0FF;
@@ -685,8 +681,14 @@ int medusa_video_init(struct cx25821_dev *dev)
685 if (ret_val < 0) 681 if (ret_val < 0)
686 goto error; 682 goto error;
687 683
688 for (i = 0; i < _num_decoders; i++) 684 /*
689 medusa_set_decoderduration(dev, i, _display_field_cnt[i]); 685 * FIXME: due to a coding bug the duration was always 0. It's
686 * likely that it really should be something else, but due to the
687 * lack of documentation I have no idea what it should be. For
688 * now just fill in 0 as the duration.
689 */
690 for (i = 0; i < dev->_max_num_decoders; i++)
691 medusa_set_decoderduration(dev, i, 0);
690 692
691 /* Select monitor as DENC A input, power up the DAC */ 693 /* Select monitor as DENC A input, power up the DAC */
692 value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_AB_CTRL, &tmp); 694 value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_AB_CTRL, &tmp);
@@ -717,7 +719,7 @@ int medusa_video_init(struct cx25821_dev *dev)
717 /* Turn on all of the data out and control output pins. */ 719 /* Turn on all of the data out and control output pins. */
718 value = cx25821_i2c_read(&dev->i2c_bus[0], PIN_OE_CTRL, &tmp); 720 value = cx25821_i2c_read(&dev->i2c_bus[0], PIN_OE_CTRL, &tmp);
719 value &= 0xFEF0FE00; 721 value &= 0xFEF0FE00;
720 if (_num_decoders == MAX_DECODERS) { 722 if (dev->_max_num_decoders == MAX_DECODERS) {
721 /* 723 /*
722 * Note: The octal board does not support control pins(bit16-19) 724 * Note: The octal board does not support control pins(bit16-19)
723 * These bits are ignored in the octal board. 725 * These bits are ignored in the octal board.
diff --git a/drivers/media/pci/cx25821/cx25821-medusa-video.h b/drivers/media/pci/cx25821/cx25821-medusa-video.h
index 6175e0961855..8bf602ff27b1 100644
--- a/drivers/media/pci/cx25821/cx25821-medusa-video.h
+++ b/drivers/media/pci/cx25821/cx25821-medusa-video.h
@@ -40,10 +40,4 @@
40#define CONTRAST_DEFAULT 5000 40#define CONTRAST_DEFAULT 5000
41#define HUE_DEFAULT 5000 41#define HUE_DEFAULT 5000
42 42
43unsigned short _num_decoders;
44unsigned short _num_cameras;
45
46unsigned int _video_standard;
47int _display_field_cnt[MAX_DECODERS];
48
49#endif 43#endif
diff --git a/drivers/media/pci/cx25821/cx25821-video-upstream.c b/drivers/media/pci/cx25821/cx25821-video-upstream.c
index 88ffef410c50..1f43be0b04c8 100644
--- a/drivers/media/pci/cx25821/cx25821-video-upstream.c
+++ b/drivers/media/pci/cx25821/cx25821-video-upstream.c
@@ -159,10 +159,10 @@ static __le32 *cx25821_risc_field_upstream(struct cx25821_channel *chan, __le32
159 * For the upstream video channel, the risc engine will enable 159 * For the upstream video channel, the risc engine will enable
160 * the FIFO. */ 160 * the FIFO. */
161 if (fifo_enable && line == 3) { 161 if (fifo_enable && line == 3) {
162 *(rp++) = RISC_WRITECR; 162 *(rp++) = cpu_to_le32(RISC_WRITECR);
163 *(rp++) = sram_ch->dma_ctl; 163 *(rp++) = cpu_to_le32(sram_ch->dma_ctl);
164 *(rp++) = FLD_VID_FIFO_EN; 164 *(rp++) = cpu_to_le32(FLD_VID_FIFO_EN);
165 *(rp++) = 0x00000001; 165 *(rp++) = cpu_to_le32(0x00000001);
166 } 166 }
167 } 167 }
168 168
diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
index aba5b1c649e6..400eb1c42d3f 100644
--- a/drivers/media/pci/cx88/cx88-alsa.c
+++ b/drivers/media/pci/cx88/cx88-alsa.c
@@ -834,7 +834,7 @@ static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
834 834
835 /* get irq */ 835 /* get irq */
836 err = request_irq(chip->pci->irq, cx8801_irq, 836 err = request_irq(chip->pci->irq, cx8801_irq,
837 IRQF_SHARED | IRQF_DISABLED, chip->core->name, chip); 837 IRQF_SHARED, chip->core->name, chip);
838 if (err < 0) { 838 if (err < 0) {
839 dprintk(0, "%s: can't get IRQ %d\n", 839 dprintk(0, "%s: can't get IRQ %d\n",
840 chip->core->name, chip->pci->irq); 840 chip->core->name, chip->pci->irq);
@@ -935,8 +935,6 @@ static void cx88_audio_finidev(struct pci_dev *pci)
935 935
936 snd_card_free((void *)card); 936 snd_card_free((void *)card);
937 937
938 pci_set_drvdata(pci, NULL);
939
940 devno--; 938 devno--;
941} 939}
942 940
@@ -951,27 +949,4 @@ static struct pci_driver cx88_audio_pci_driver = {
951 .remove = cx88_audio_finidev, 949 .remove = cx88_audio_finidev,
952}; 950};
953 951
954/**************************************************************************** 952module_pci_driver(cx88_audio_pci_driver);
955 LINUX MODULE INIT
956 ****************************************************************************/
957
958/*
959 * module init
960 */
961static int __init cx88_audio_init(void)
962{
963 printk(KERN_INFO "cx2388x alsa driver version %s loaded\n",
964 CX88_VERSION);
965 return pci_register_driver(&cx88_audio_pci_driver);
966}
967
968/*
969 * module remove
970 */
971static void __exit cx88_audio_fini(void)
972{
973 pci_unregister_driver(&cx88_audio_pci_driver);
974}
975
976module_init(cx88_audio_init);
977module_exit(cx88_audio_fini);
diff --git a/drivers/media/pci/cx88/cx88-mpeg.c b/drivers/media/pci/cx88/cx88-mpeg.c
index 2d3507eb4897..74b7b8614c23 100644
--- a/drivers/media/pci/cx88/cx88-mpeg.c
+++ b/drivers/media/pci/cx88/cx88-mpeg.c
@@ -499,7 +499,7 @@ static int cx8802_init_common(struct cx8802_dev *dev)
499 499
500 /* get irq */ 500 /* get irq */
501 err = request_irq(dev->pci->irq, cx8802_irq, 501 err = request_irq(dev->pci->irq, cx8802_irq,
502 IRQF_SHARED | IRQF_DISABLED, dev->core->name, dev); 502 IRQF_SHARED, dev->core->name, dev);
503 if (err < 0) { 503 if (err < 0) {
504 printk(KERN_ERR "%s: can't get IRQ %d\n", 504 printk(KERN_ERR "%s: can't get IRQ %d\n",
505 dev->core->name, dev->pci->irq); 505 dev->core->name, dev->pci->irq);
@@ -520,7 +520,6 @@ static void cx8802_fini_common(struct cx8802_dev *dev)
520 520
521 /* unregister stuff */ 521 /* unregister stuff */
522 free_irq(dev->pci->irq, dev); 522 free_irq(dev->pci->irq, dev);
523 pci_set_drvdata(dev->pci, NULL);
524 523
525 /* free memory */ 524 /* free memory */
526 btcx_riscmem_free(dev->pci,&dev->mpegq.stopper); 525 btcx_riscmem_free(dev->pci,&dev->mpegq.stopper);
@@ -903,20 +902,8 @@ static struct pci_driver cx8802_pci_driver = {
903 .remove = cx8802_remove, 902 .remove = cx8802_remove,
904}; 903};
905 904
906static int __init cx8802_init(void) 905module_pci_driver(cx8802_pci_driver);
907{
908 printk(KERN_INFO "cx88/2: cx2388x MPEG-TS Driver Manager version %s loaded\n",
909 CX88_VERSION);
910 return pci_register_driver(&cx8802_pci_driver);
911}
912
913static void __exit cx8802_fini(void)
914{
915 pci_unregister_driver(&cx8802_pci_driver);
916}
917 906
918module_init(cx8802_init);
919module_exit(cx8802_fini);
920EXPORT_SYMBOL(cx8802_buf_prepare); 907EXPORT_SYMBOL(cx8802_buf_prepare);
921EXPORT_SYMBOL(cx8802_buf_queue); 908EXPORT_SYMBOL(cx8802_buf_queue);
922EXPORT_SYMBOL(cx8802_cancel_buffers); 909EXPORT_SYMBOL(cx8802_cancel_buffers);
diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
index ecf21d9f1f34..ed8cb9037b6f 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -1738,7 +1738,7 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
1738 1738
1739 /* get irq */ 1739 /* get irq */
1740 err = request_irq(pci_dev->irq, cx8800_irq, 1740 err = request_irq(pci_dev->irq, cx8800_irq,
1741 IRQF_SHARED | IRQF_DISABLED, core->name, dev); 1741 IRQF_SHARED, core->name, dev);
1742 if (err < 0) { 1742 if (err < 0) {
1743 printk(KERN_ERR "%s/0: can't get IRQ %d\n", 1743 printk(KERN_ERR "%s/0: can't get IRQ %d\n",
1744 core->name,pci_dev->irq); 1744 core->name,pci_dev->irq);
@@ -1922,7 +1922,6 @@ static void cx8800_finidev(struct pci_dev *pci_dev)
1922 1922
1923 free_irq(pci_dev->irq, dev); 1923 free_irq(pci_dev->irq, dev);
1924 cx8800_unregister_video(dev); 1924 cx8800_unregister_video(dev);
1925 pci_set_drvdata(pci_dev, NULL);
1926 1925
1927 /* free memory */ 1926 /* free memory */
1928 btcx_riscmem_free(dev->pci,&dev->vidq.stopper); 1927 btcx_riscmem_free(dev->pci,&dev->vidq.stopper);
@@ -2039,17 +2038,4 @@ static struct pci_driver cx8800_pci_driver = {
2039#endif 2038#endif
2040}; 2039};
2041 2040
2042static int __init cx8800_init(void) 2041module_pci_driver(cx8800_pci_driver);
2043{
2044 printk(KERN_INFO "cx88/0: cx2388x v4l2 driver version %s loaded\n",
2045 CX88_VERSION);
2046 return pci_register_driver(&cx8800_pci_driver);
2047}
2048
2049static void __exit cx8800_fini(void)
2050{
2051 pci_unregister_driver(&cx8800_pci_driver);
2052}
2053
2054module_init(cx8800_init);
2055module_exit(cx8800_fini);
diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
index 36e34522b9a8..9375f30d9a81 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1544,7 +1544,7 @@ static void ddb_unmap(struct ddb *dev)
1544 1544
1545static void ddb_remove(struct pci_dev *pdev) 1545static void ddb_remove(struct pci_dev *pdev)
1546{ 1546{
1547 struct ddb *dev = (struct ddb *) pci_get_drvdata(pdev); 1547 struct ddb *dev = pci_get_drvdata(pdev);
1548 1548
1549 ddb_ports_detach(dev); 1549 ddb_ports_detach(dev);
1550 ddb_i2c_release(dev); 1550 ddb_i2c_release(dev);
diff --git a/drivers/media/pci/dm1105/dm1105.c b/drivers/media/pci/dm1105/dm1105.c
index ab797fe466d2..e60ac35fc10c 100644
--- a/drivers/media/pci/dm1105/dm1105.c
+++ b/drivers/media/pci/dm1105/dm1105.c
@@ -1178,7 +1178,6 @@ err_pci_release_regions:
1178err_pci_disable_device: 1178err_pci_disable_device:
1179 pci_disable_device(pdev); 1179 pci_disable_device(pdev);
1180err_kfree: 1180err_kfree:
1181 pci_set_drvdata(pdev, NULL);
1182 kfree(dev); 1181 kfree(dev);
1183 return ret; 1182 return ret;
1184} 1183}
@@ -1202,8 +1201,7 @@ static void dm1105_remove(struct pci_dev *pdev)
1202 dvb_dmxdev_release(&dev->dmxdev); 1201 dvb_dmxdev_release(&dev->dmxdev);
1203 dvb_dmx_release(dvbdemux); 1202 dvb_dmx_release(dvbdemux);
1204 dvb_unregister_adapter(dvb_adapter); 1203 dvb_unregister_adapter(dvb_adapter);
1205 if (&dev->i2c_adap) 1204 i2c_del_adapter(&dev->i2c_adap);
1206 i2c_del_adapter(&dev->i2c_adap);
1207 1205
1208 dm1105_hw_exit(dev); 1206 dm1105_hw_exit(dev);
1209 synchronize_irq(pdev->irq); 1207 synchronize_irq(pdev->irq);
@@ -1211,7 +1209,6 @@ static void dm1105_remove(struct pci_dev *pdev)
1211 pci_iounmap(pdev, dev->io_mem); 1209 pci_iounmap(pdev, dev->io_mem);
1212 pci_release_regions(pdev); 1210 pci_release_regions(pdev);
1213 pci_disable_device(pdev); 1211 pci_disable_device(pdev);
1214 pci_set_drvdata(pdev, NULL);
1215 dm1105_devcount--; 1212 dm1105_devcount--;
1216 kfree(dev); 1213 kfree(dev);
1217} 1214}
diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
index c08ae3eb9554..802642d26643 100644
--- a/drivers/media/pci/ivtv/ivtv-driver.c
+++ b/drivers/media/pci/ivtv/ivtv-driver.c
@@ -1261,7 +1261,7 @@ static int ivtv_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
1261 1261
1262 /* Register IRQ */ 1262 /* Register IRQ */
1263 retval = request_irq(itv->pdev->irq, ivtv_irq_handler, 1263 retval = request_irq(itv->pdev->irq, ivtv_irq_handler,
1264 IRQF_SHARED | IRQF_DISABLED, itv->v4l2_dev.name, (void *)itv); 1264 IRQF_SHARED, itv->v4l2_dev.name, (void *)itv);
1265 if (retval) { 1265 if (retval) {
1266 IVTV_ERR("Failed to register irq %d\n", retval); 1266 IVTV_ERR("Failed to register irq %d\n", retval);
1267 goto free_i2c; 1267 goto free_i2c;
diff --git a/drivers/media/pci/mantis/mantis_pci.c b/drivers/media/pci/mantis/mantis_pci.c
index a846036ea022..9e89e045213a 100644
--- a/drivers/media/pci/mantis/mantis_pci.c
+++ b/drivers/media/pci/mantis/mantis_pci.c
@@ -143,7 +143,6 @@ fail1:
143 143
144fail0: 144fail0:
145 dprintk(MANTIS_ERROR, 1, "ERROR: <%d> exiting", ret); 145 dprintk(MANTIS_ERROR, 1, "ERROR: <%d> exiting", ret);
146 pci_set_drvdata(pdev, NULL);
147 return ret; 146 return ret;
148} 147}
149EXPORT_SYMBOL_GPL(mantis_pci_init); 148EXPORT_SYMBOL_GPL(mantis_pci_init);
@@ -161,7 +160,6 @@ void mantis_pci_exit(struct mantis_pci *mantis)
161 } 160 }
162 161
163 pci_disable_device(pdev); 162 pci_disable_device(pdev);
164 pci_set_drvdata(pdev, NULL);
165} 163}
166EXPORT_SYMBOL_GPL(mantis_pci_exit); 164EXPORT_SYMBOL_GPL(mantis_pci_exit);
167 165
diff --git a/drivers/media/pci/meye/meye.c b/drivers/media/pci/meye/meye.c
index 2381b05432e6..54d5c821007c 100644
--- a/drivers/media/pci/meye/meye.c
+++ b/drivers/media/pci/meye/meye.c
@@ -1698,7 +1698,7 @@ static int meye_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
1698 1698
1699 meye.mchip_irq = pcidev->irq; 1699 meye.mchip_irq = pcidev->irq;
1700 if (request_irq(meye.mchip_irq, meye_irq, 1700 if (request_irq(meye.mchip_irq, meye_irq,
1701 IRQF_DISABLED | IRQF_SHARED, "meye", meye_irq)) { 1701 IRQF_SHARED, "meye", meye_irq)) {
1702 v4l2_err(v4l2_dev, "request_irq failed\n"); 1702 v4l2_err(v4l2_dev, "request_irq failed\n");
1703 goto outreqirq; 1703 goto outreqirq;
1704 } 1704 }
diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c
index 37ebc42392ad..970e83308525 100644
--- a/drivers/media/pci/ngene/ngene-core.c
+++ b/drivers/media/pci/ngene/ngene-core.c
@@ -1622,7 +1622,7 @@ static void ngene_unlink(struct ngene *dev)
1622 1622
1623void ngene_shutdown(struct pci_dev *pdev) 1623void ngene_shutdown(struct pci_dev *pdev)
1624{ 1624{
1625 struct ngene *dev = (struct ngene *)pci_get_drvdata(pdev); 1625 struct ngene *dev = pci_get_drvdata(pdev);
1626 1626
1627 if (!dev || !shutdown_workaround) 1627 if (!dev || !shutdown_workaround)
1628 return; 1628 return;
@@ -1648,7 +1648,6 @@ void ngene_remove(struct pci_dev *pdev)
1648 cxd_detach(dev); 1648 cxd_detach(dev);
1649 ngene_stop(dev); 1649 ngene_stop(dev);
1650 ngene_release_buffers(dev); 1650 ngene_release_buffers(dev);
1651 pci_set_drvdata(pdev, NULL);
1652 pci_disable_device(pdev); 1651 pci_disable_device(pdev);
1653} 1652}
1654 1653
@@ -1702,6 +1701,5 @@ fail1:
1702 ngene_release_buffers(dev); 1701 ngene_release_buffers(dev);
1703fail0: 1702fail0:
1704 pci_disable_device(pci_dev); 1703 pci_disable_device(pci_dev);
1705 pci_set_drvdata(pci_dev, NULL);
1706 return stat; 1704 return stat;
1707} 1705}
diff --git a/drivers/media/pci/pluto2/pluto2.c b/drivers/media/pci/pluto2/pluto2.c
index 493828500055..8164d74b46a4 100644
--- a/drivers/media/pci/pluto2/pluto2.c
+++ b/drivers/media/pci/pluto2/pluto2.c
@@ -736,7 +736,6 @@ err_pci_release_regions:
736err_pci_disable_device: 736err_pci_disable_device:
737 pci_disable_device(pdev); 737 pci_disable_device(pdev);
738err_kfree: 738err_kfree:
739 pci_set_drvdata(pdev, NULL);
740 kfree(pluto); 739 kfree(pluto);
741 goto out; 740 goto out;
742} 741}
@@ -765,7 +764,6 @@ static void pluto2_remove(struct pci_dev *pdev)
765 pci_iounmap(pdev, pluto->io_mem); 764 pci_iounmap(pdev, pluto->io_mem);
766 pci_release_regions(pdev); 765 pci_release_regions(pdev);
767 pci_disable_device(pdev); 766 pci_disable_device(pdev);
768 pci_set_drvdata(pdev, NULL);
769 kfree(pluto); 767 kfree(pluto);
770} 768}
771 769
diff --git a/drivers/media/pci/pt1/pt1.c b/drivers/media/pci/pt1/pt1.c
index 75ce14229e03..db887b0c37b1 100644
--- a/drivers/media/pci/pt1/pt1.c
+++ b/drivers/media/pci/pt1/pt1.c
@@ -1076,7 +1076,6 @@ static void pt1_remove(struct pci_dev *pdev)
1076 pt1_update_power(pt1); 1076 pt1_update_power(pt1);
1077 pt1_cleanup_adapters(pt1); 1077 pt1_cleanup_adapters(pt1);
1078 i2c_del_adapter(&pt1->i2c_adap); 1078 i2c_del_adapter(&pt1->i2c_adap);
1079 pci_set_drvdata(pdev, NULL);
1080 kfree(pt1); 1079 kfree(pt1);
1081 pci_iounmap(pdev, regs); 1080 pci_iounmap(pdev, regs);
1082 pci_release_regions(pdev); 1081 pci_release_regions(pdev);
@@ -1198,7 +1197,6 @@ err_i2c_del_adapter:
1198err_pt1_cleanup_adapters: 1197err_pt1_cleanup_adapters:
1199 pt1_cleanup_adapters(pt1); 1198 pt1_cleanup_adapters(pt1);
1200err_kfree: 1199err_kfree:
1201 pci_set_drvdata(pdev, NULL);
1202 kfree(pt1); 1200 kfree(pt1);
1203err_pci_iounmap: 1201err_pci_iounmap:
1204 pci_iounmap(pdev, regs); 1202 pci_iounmap(pdev, regs);
diff --git a/drivers/media/pci/saa7134/saa7134-alsa.c b/drivers/media/pci/saa7134/saa7134-alsa.c
index dbcdfbf8aed0..dd67c8a400cc 100644
--- a/drivers/media/pci/saa7134/saa7134-alsa.c
+++ b/drivers/media/pci/saa7134/saa7134-alsa.c
@@ -1096,7 +1096,7 @@ static int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
1096 1096
1097 1097
1098 err = request_irq(dev->pci->irq, saa7134_alsa_irq, 1098 err = request_irq(dev->pci->irq, saa7134_alsa_irq,
1099 IRQF_SHARED | IRQF_DISABLED, dev->name, 1099 IRQF_SHARED, dev->name,
1100 (void*) &dev->dmasound); 1100 (void*) &dev->dmasound);
1101 1101
1102 if (err < 0) { 1102 if (err < 0) {
diff --git a/drivers/media/pci/saa7134/saa7134-core.c b/drivers/media/pci/saa7134/saa7134-core.c
index 45f0aca597ae..27d7ee709c58 100644
--- a/drivers/media/pci/saa7134/saa7134-core.c
+++ b/drivers/media/pci/saa7134/saa7134-core.c
@@ -992,7 +992,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
992 992
993 /* get irq */ 993 /* get irq */
994 err = request_irq(pci_dev->irq, saa7134_irq, 994 err = request_irq(pci_dev->irq, saa7134_irq,
995 IRQF_SHARED | IRQF_DISABLED, dev->name, dev); 995 IRQF_SHARED, dev->name, dev);
996 if (err < 0) { 996 if (err < 0) {
997 printk(KERN_ERR "%s: can't get IRQ %d\n", 997 printk(KERN_ERR "%s: can't get IRQ %d\n",
998 dev->name,pci_dev->irq); 998 dev->name,pci_dev->irq);
diff --git a/drivers/media/pci/saa7164/saa7164-core.c b/drivers/media/pci/saa7164/saa7164-core.c
index d37ee37aaefe..57ef5456f1e8 100644
--- a/drivers/media/pci/saa7164/saa7164-core.c
+++ b/drivers/media/pci/saa7164/saa7164-core.c
@@ -1232,7 +1232,7 @@ static int saa7164_initdev(struct pci_dev *pci_dev,
1232 } 1232 }
1233 1233
1234 err = request_irq(pci_dev->irq, saa7164_irq, 1234 err = request_irq(pci_dev->irq, saa7164_irq,
1235 IRQF_SHARED | IRQF_DISABLED, dev->name, dev); 1235 IRQF_SHARED, dev->name, dev);
1236 if (err < 0) { 1236 if (err < 0) {
1237 printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name, 1237 printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name,
1238 pci_dev->irq); 1238 pci_dev->irq);
@@ -1439,7 +1439,6 @@ static void saa7164_finidev(struct pci_dev *pci_dev)
1439 1439
1440 /* unregister stuff */ 1440 /* unregister stuff */
1441 free_irq(pci_dev->irq, dev); 1441 free_irq(pci_dev->irq, dev);
1442 pci_set_drvdata(pci_dev, NULL);
1443 1442
1444 mutex_lock(&devlist); 1443 mutex_lock(&devlist);
1445 list_del(&dev->devlist); 1444 list_del(&dev->devlist);
diff --git a/drivers/media/pci/ttpci/av7110_hw.c b/drivers/media/pci/ttpci/av7110_hw.c
index f1cbfe526989..6299d5dadb82 100644
--- a/drivers/media/pci/ttpci/av7110_hw.c
+++ b/drivers/media/pci/ttpci/av7110_hw.c
@@ -22,7 +22,7 @@
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 23 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
24 * 24 *
25 * the project's page is at http://www.linuxtv.org/ 25 * the project's page is at http://www.linuxtv.org/
26 */ 26 */
27 27
28/* for debugging ARM communication: */ 28/* for debugging ARM communication: */
@@ -40,6 +40,14 @@
40 40
41#define _NOHANDSHAKE 41#define _NOHANDSHAKE
42 42
43/*
44 * Max transfer size done by av7110_fw_cmd()
45 *
46 * The maximum size passed to this function is 6 bytes. The buffer also
47 * uses two additional ones for type and size. So, 8 bytes is enough.
48 */
49#define MAX_XFER_SIZE 8
50
43/**************************************************************************** 51/****************************************************************************
44 * DEBI functions 52 * DEBI functions
45 ****************************************************************************/ 53 ****************************************************************************/
@@ -488,11 +496,18 @@ static int av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
488int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...) 496int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...)
489{ 497{
490 va_list args; 498 va_list args;
491 u16 buf[num + 2]; 499 u16 buf[MAX_XFER_SIZE];
492 int i, ret; 500 int i, ret;
493 501
494// dprintk(4, "%p\n", av7110); 502// dprintk(4, "%p\n", av7110);
495 503
504 if (2 + num > sizeof(buf)) {
505 printk(KERN_WARNING
506 "%s: %s len=%d is too big!\n",
507 KBUILD_MODNAME, __func__, num);
508 return -EINVAL;
509 }
510
496 buf[0] = ((type << 8) | com); 511 buf[0] = ((type << 8) | com);
497 buf[1] = num; 512 buf[1] = num;
498 513
diff --git a/drivers/media/pci/zoran/Kconfig b/drivers/media/pci/zoran/Kconfig
index 26ca8702e33f..39ec35bd21a5 100644
--- a/drivers/media/pci/zoran/Kconfig
+++ b/drivers/media/pci/zoran/Kconfig
@@ -1,6 +1,7 @@
1config VIDEO_ZORAN 1config VIDEO_ZORAN
2 tristate "Zoran ZR36057/36067 Video For Linux" 2 tristate "Zoran ZR36057/36067 Video For Linux"
3 depends on PCI && I2C_ALGOBIT && VIDEO_V4L2 && VIRT_TO_BUS 3 depends on PCI && I2C_ALGOBIT && VIDEO_V4L2 && VIRT_TO_BUS
4 depends on !ALPHA
4 help 5 help
5 Say Y for support for MJPEG capture cards based on the Zoran 6 Say Y for support for MJPEG capture cards based on the Zoran
6 36057/36067 PCI controller chipset. This includes the Iomega 7 36057/36067 PCI controller chipset. This includes the Iomega
diff --git a/drivers/media/pci/zoran/zoran_card.c b/drivers/media/pci/zoran/zoran_card.c
index 923d59a321f8..cec5b7553f28 100644
--- a/drivers/media/pci/zoran/zoran_card.c
+++ b/drivers/media/pci/zoran/zoran_card.c
@@ -1293,7 +1293,7 @@ static int zoran_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1293 } 1293 }
1294 1294
1295 result = request_irq(zr->pci_dev->irq, zoran_irq, 1295 result = request_irq(zr->pci_dev->irq, zoran_irq,
1296 IRQF_SHARED | IRQF_DISABLED, ZR_DEVNAME(zr), zr); 1296 IRQF_SHARED, ZR_DEVNAME(zr), zr);
1297 if (result < 0) { 1297 if (result < 0) {
1298 if (result == -EINVAL) { 1298 if (result == -EINVAL) {
1299 dprintk(1, 1299 dprintk(1,
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index eb70dda8cbf3..d7f0249e4050 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -143,6 +143,7 @@ if V4L_MEM2MEM_DRIVERS
143config VIDEO_CODA 143config VIDEO_CODA
144 tristate "Chips&Media Coda multi-standard codec IP" 144 tristate "Chips&Media Coda multi-standard codec IP"
145 depends on VIDEO_DEV && VIDEO_V4L2 && ARCH_MXC 145 depends on VIDEO_DEV && VIDEO_V4L2 && ARCH_MXC
146 select SRAM
146 select VIDEOBUF2_DMA_CONTIG 147 select VIDEOBUF2_DMA_CONTIG
147 select V4L2_MEM2MEM_DEV 148 select V4L2_MEM2MEM_DEV
148 ---help--- 149 ---help---
@@ -212,7 +213,7 @@ config VIDEO_SH_VEU
212 213
213config VIDEO_RENESAS_VSP1 214config VIDEO_RENESAS_VSP1
214 tristate "Renesas VSP1 Video Processing Engine" 215 tristate "Renesas VSP1 Video Processing Engine"
215 depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API 216 depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && HAS_DMA
216 select VIDEOBUF2_DMA_CONTIG 217 select VIDEOBUF2_DMA_CONTIG
217 ---help--- 218 ---help---
218 This is a V4L2 driver for the Renesas VSP1 video processing engine. 219 This is a V4L2 driver for the Renesas VSP1 video processing engine.
@@ -220,6 +221,22 @@ config VIDEO_RENESAS_VSP1
220 To compile this driver as a module, choose M here: the module 221 To compile this driver as a module, choose M here: the module
221 will be called vsp1. 222 will be called vsp1.
222 223
224config VIDEO_TI_VPE
225 tristate "TI VPE (Video Processing Engine) driver"
226 depends on VIDEO_DEV && VIDEO_V4L2 && SOC_DRA7XX
227 select VIDEOBUF2_DMA_CONTIG
228 select V4L2_MEM2MEM_DEV
229 default n
230 ---help---
231 Support for the TI VPE(Video Processing Engine) block
232 found on DRA7XX SoC.
233
234config VIDEO_TI_VPE_DEBUG
235 bool "VPE debug messages"
236 depends on VIDEO_TI_VPE
237 ---help---
238 Enable debug messages on VPE driver.
239
223endif # V4L_MEM2MEM_DRIVERS 240endif # V4L_MEM2MEM_DRIVERS
224 241
225menuconfig V4L_TEST_DRIVERS 242menuconfig V4L_TEST_DRIVERS
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 4e4da482c522..1348ba1faf92 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -22,6 +22,8 @@ obj-$(CONFIG_VIDEO_VIVI) += vivi.o
22 22
23obj-$(CONFIG_VIDEO_MEM2MEM_TESTDEV) += mem2mem_testdev.o 23obj-$(CONFIG_VIDEO_MEM2MEM_TESTDEV) += mem2mem_testdev.o
24 24
25obj-$(CONFIG_VIDEO_TI_VPE) += ti-vpe/
26
25obj-$(CONFIG_VIDEO_MX2_EMMAPRP) += mx2_emmaprp.o 27obj-$(CONFIG_VIDEO_MX2_EMMAPRP) += mx2_emmaprp.o
26obj-$(CONFIG_VIDEO_CODA) += coda.o 28obj-$(CONFIG_VIDEO_CODA) += coda.o
27 29
diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 4993610051ee..bd72fb97fea5 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -39,7 +39,7 @@
39 39
40#define CODA_NAME "coda" 40#define CODA_NAME "coda"
41 41
42#define CODA_MAX_INSTANCES 4 42#define CODADX6_MAX_INSTANCES 4
43 43
44#define CODA_FMO_BUF_SIZE 32 44#define CODA_FMO_BUF_SIZE 32
45#define CODADX6_WORK_BUF_SIZE (288 * 1024 + CODA_FMO_BUF_SIZE * 8 * 1024) 45#define CODADX6_WORK_BUF_SIZE (288 * 1024 + CODA_FMO_BUF_SIZE * 8 * 1024)
@@ -54,8 +54,6 @@
54 54
55#define CODA_MAX_FRAMEBUFFERS 8 55#define CODA_MAX_FRAMEBUFFERS 8
56 56
57#define MAX_W 8192
58#define MAX_H 8192
59#define CODA_MAX_FRAME_SIZE 0x100000 57#define CODA_MAX_FRAME_SIZE 0x100000
60#define FMO_SLICE_SAVE_BUF_SIZE (32) 58#define FMO_SLICE_SAVE_BUF_SIZE (32)
61#define CODA_DEFAULT_GAMMA 4096 59#define CODA_DEFAULT_GAMMA 4096
@@ -394,14 +392,57 @@ static struct coda_codec *coda_find_codec(struct coda_dev *dev, int src_fourcc,
394 return &codecs[k]; 392 return &codecs[k];
395} 393}
396 394
395static void coda_get_max_dimensions(struct coda_dev *dev,
396 struct coda_codec *codec,
397 int *max_w, int *max_h)
398{
399 struct coda_codec *codecs = dev->devtype->codecs;
400 int num_codecs = dev->devtype->num_codecs;
401 unsigned int w, h;
402 int k;
403
404 if (codec) {
405 w = codec->max_w;
406 h = codec->max_h;
407 } else {
408 for (k = 0, w = 0, h = 0; k < num_codecs; k++) {
409 w = max(w, codecs[k].max_w);
410 h = max(h, codecs[k].max_h);
411 }
412 }
413
414 if (max_w)
415 *max_w = w;
416 if (max_h)
417 *max_h = h;
418}
419
420static char *coda_product_name(int product)
421{
422 static char buf[9];
423
424 switch (product) {
425 case CODA_DX6:
426 return "CodaDx6";
427 case CODA_7541:
428 return "CODA7541";
429 default:
430 snprintf(buf, sizeof(buf), "(0x%04x)", product);
431 return buf;
432 }
433}
434
397/* 435/*
398 * V4L2 ioctl() operations. 436 * V4L2 ioctl() operations.
399 */ 437 */
400static int vidioc_querycap(struct file *file, void *priv, 438static int coda_querycap(struct file *file, void *priv,
401 struct v4l2_capability *cap) 439 struct v4l2_capability *cap)
402{ 440{
441 struct coda_ctx *ctx = fh_to_ctx(priv);
442
403 strlcpy(cap->driver, CODA_NAME, sizeof(cap->driver)); 443 strlcpy(cap->driver, CODA_NAME, sizeof(cap->driver));
404 strlcpy(cap->card, CODA_NAME, sizeof(cap->card)); 444 strlcpy(cap->card, coda_product_name(ctx->dev->devtype->product),
445 sizeof(cap->card));
405 strlcpy(cap->bus_info, "platform:" CODA_NAME, sizeof(cap->bus_info)); 446 strlcpy(cap->bus_info, "platform:" CODA_NAME, sizeof(cap->bus_info));
406 /* 447 /*
407 * This is only a mem-to-mem video device. The capture and output 448 * This is only a mem-to-mem video device. The capture and output
@@ -457,6 +498,8 @@ static int enum_fmt(void *priv, struct v4l2_fmtdesc *f,
457 fmt = &formats[i]; 498 fmt = &formats[i];
458 strlcpy(f->description, fmt->name, sizeof(f->description)); 499 strlcpy(f->description, fmt->name, sizeof(f->description));
459 f->pixelformat = fmt->fourcc; 500 f->pixelformat = fmt->fourcc;
501 if (!coda_format_is_yuv(fmt->fourcc))
502 f->flags |= V4L2_FMT_FLAG_COMPRESSED;
460 return 0; 503 return 0;
461 } 504 }
462 505
@@ -464,8 +507,8 @@ static int enum_fmt(void *priv, struct v4l2_fmtdesc *f,
464 return -EINVAL; 507 return -EINVAL;
465} 508}
466 509
467static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, 510static int coda_enum_fmt_vid_cap(struct file *file, void *priv,
468 struct v4l2_fmtdesc *f) 511 struct v4l2_fmtdesc *f)
469{ 512{
470 struct coda_ctx *ctx = fh_to_ctx(priv); 513 struct coda_ctx *ctx = fh_to_ctx(priv);
471 struct vb2_queue *src_vq; 514 struct vb2_queue *src_vq;
@@ -483,13 +526,14 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
483 return enum_fmt(priv, f, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0); 526 return enum_fmt(priv, f, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0);
484} 527}
485 528
486static int vidioc_enum_fmt_vid_out(struct file *file, void *priv, 529static int coda_enum_fmt_vid_out(struct file *file, void *priv,
487 struct v4l2_fmtdesc *f) 530 struct v4l2_fmtdesc *f)
488{ 531{
489 return enum_fmt(priv, f, V4L2_BUF_TYPE_VIDEO_OUTPUT, 0); 532 return enum_fmt(priv, f, V4L2_BUF_TYPE_VIDEO_OUTPUT, 0);
490} 533}
491 534
492static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f) 535static int coda_g_fmt(struct file *file, void *priv,
536 struct v4l2_format *f)
493{ 537{
494 struct vb2_queue *vq; 538 struct vb2_queue *vq;
495 struct coda_q_data *q_data; 539 struct coda_q_data *q_data;
@@ -516,8 +560,11 @@ static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
516 return 0; 560 return 0;
517} 561}
518 562
519static int vidioc_try_fmt(struct coda_codec *codec, struct v4l2_format *f) 563static int coda_try_fmt(struct coda_ctx *ctx, struct coda_codec *codec,
564 struct v4l2_format *f)
520{ 565{
566 struct coda_dev *dev = ctx->dev;
567 struct coda_q_data *q_data;
521 unsigned int max_w, max_h; 568 unsigned int max_w, max_h;
522 enum v4l2_field field; 569 enum v4l2_field field;
523 570
@@ -531,32 +578,48 @@ static int vidioc_try_fmt(struct coda_codec *codec, struct v4l2_format *f)
531 * if any of the dimensions is unsupported */ 578 * if any of the dimensions is unsupported */
532 f->fmt.pix.field = field; 579 f->fmt.pix.field = field;
533 580
534 if (codec) { 581 coda_get_max_dimensions(dev, codec, &max_w, &max_h);
535 max_w = codec->max_w; 582 v4l_bound_align_image(&f->fmt.pix.width, MIN_W, max_w, W_ALIGN,
536 max_h = codec->max_h; 583 &f->fmt.pix.height, MIN_H, max_h, H_ALIGN,
537 } else { 584 S_ALIGN);
538 max_w = MAX_W; 585
539 max_h = MAX_H; 586 switch (f->fmt.pix.pixelformat) {
587 case V4L2_PIX_FMT_YUV420:
588 case V4L2_PIX_FMT_YVU420:
589 case V4L2_PIX_FMT_H264:
590 case V4L2_PIX_FMT_MPEG4:
591 case V4L2_PIX_FMT_JPEG:
592 break;
593 default:
594 q_data = get_q_data(ctx, f->type);
595 f->fmt.pix.pixelformat = q_data->fourcc;
540 } 596 }
541 v4l_bound_align_image(&f->fmt.pix.width, MIN_W, max_w,
542 W_ALIGN, &f->fmt.pix.height,
543 MIN_H, max_h, H_ALIGN, S_ALIGN);
544 597
545 if (coda_format_is_yuv(f->fmt.pix.pixelformat)) { 598 switch (f->fmt.pix.pixelformat) {
599 case V4L2_PIX_FMT_YUV420:
600 case V4L2_PIX_FMT_YVU420:
546 /* Frame stride must be multiple of 8 */ 601 /* Frame stride must be multiple of 8 */
547 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 8); 602 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 8);
548 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * 603 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
549 f->fmt.pix.height * 3 / 2; 604 f->fmt.pix.height * 3 / 2;
550 } else { /*encoded formats h.264/mpeg4 */ 605 break;
606 case V4L2_PIX_FMT_H264:
607 case V4L2_PIX_FMT_MPEG4:
608 case V4L2_PIX_FMT_JPEG:
551 f->fmt.pix.bytesperline = 0; 609 f->fmt.pix.bytesperline = 0;
552 f->fmt.pix.sizeimage = CODA_MAX_FRAME_SIZE; 610 f->fmt.pix.sizeimage = CODA_MAX_FRAME_SIZE;
611 break;
612 default:
613 BUG();
553 } 614 }
554 615
616 f->fmt.pix.priv = 0;
617
555 return 0; 618 return 0;
556} 619}
557 620
558static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, 621static int coda_try_fmt_vid_cap(struct file *file, void *priv,
559 struct v4l2_format *f) 622 struct v4l2_format *f)
560{ 623{
561 struct coda_ctx *ctx = fh_to_ctx(priv); 624 struct coda_ctx *ctx = fh_to_ctx(priv);
562 struct coda_codec *codec; 625 struct coda_codec *codec;
@@ -584,7 +647,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
584 647
585 f->fmt.pix.colorspace = ctx->colorspace; 648 f->fmt.pix.colorspace = ctx->colorspace;
586 649
587 ret = vidioc_try_fmt(codec, f); 650 ret = coda_try_fmt(ctx, codec, f);
588 if (ret < 0) 651 if (ret < 0)
589 return ret; 652 return ret;
590 653
@@ -600,8 +663,8 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
600 return 0; 663 return 0;
601} 664}
602 665
603static int vidioc_try_fmt_vid_out(struct file *file, void *priv, 666static int coda_try_fmt_vid_out(struct file *file, void *priv,
604 struct v4l2_format *f) 667 struct v4l2_format *f)
605{ 668{
606 struct coda_ctx *ctx = fh_to_ctx(priv); 669 struct coda_ctx *ctx = fh_to_ctx(priv);
607 struct coda_codec *codec; 670 struct coda_codec *codec;
@@ -613,10 +676,10 @@ static int vidioc_try_fmt_vid_out(struct file *file, void *priv,
613 if (!f->fmt.pix.colorspace) 676 if (!f->fmt.pix.colorspace)
614 f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709; 677 f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709;
615 678
616 return vidioc_try_fmt(codec, f); 679 return coda_try_fmt(ctx, codec, f);
617} 680}
618 681
619static int vidioc_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f) 682static int coda_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f)
620{ 683{
621 struct coda_q_data *q_data; 684 struct coda_q_data *q_data;
622 struct vb2_queue *vq; 685 struct vb2_queue *vq;
@@ -646,61 +709,62 @@ static int vidioc_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f)
646 return 0; 709 return 0;
647} 710}
648 711
649static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 712static int coda_s_fmt_vid_cap(struct file *file, void *priv,
650 struct v4l2_format *f) 713 struct v4l2_format *f)
651{ 714{
652 struct coda_ctx *ctx = fh_to_ctx(priv); 715 struct coda_ctx *ctx = fh_to_ctx(priv);
653 int ret; 716 int ret;
654 717
655 ret = vidioc_try_fmt_vid_cap(file, priv, f); 718 ret = coda_try_fmt_vid_cap(file, priv, f);
656 if (ret) 719 if (ret)
657 return ret; 720 return ret;
658 721
659 return vidioc_s_fmt(ctx, f); 722 return coda_s_fmt(ctx, f);
660} 723}
661 724
662static int vidioc_s_fmt_vid_out(struct file *file, void *priv, 725static int coda_s_fmt_vid_out(struct file *file, void *priv,
663 struct v4l2_format *f) 726 struct v4l2_format *f)
664{ 727{
665 struct coda_ctx *ctx = fh_to_ctx(priv); 728 struct coda_ctx *ctx = fh_to_ctx(priv);
666 int ret; 729 int ret;
667 730
668 ret = vidioc_try_fmt_vid_out(file, priv, f); 731 ret = coda_try_fmt_vid_out(file, priv, f);
669 if (ret) 732 if (ret)
670 return ret; 733 return ret;
671 734
672 ret = vidioc_s_fmt(ctx, f); 735 ret = coda_s_fmt(ctx, f);
673 if (ret) 736 if (ret)
674 ctx->colorspace = f->fmt.pix.colorspace; 737 ctx->colorspace = f->fmt.pix.colorspace;
675 738
676 return ret; 739 return ret;
677} 740}
678 741
679static int vidioc_reqbufs(struct file *file, void *priv, 742static int coda_reqbufs(struct file *file, void *priv,
680 struct v4l2_requestbuffers *reqbufs) 743 struct v4l2_requestbuffers *reqbufs)
681{ 744{
682 struct coda_ctx *ctx = fh_to_ctx(priv); 745 struct coda_ctx *ctx = fh_to_ctx(priv);
683 746
684 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs); 747 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
685} 748}
686 749
687static int vidioc_querybuf(struct file *file, void *priv, 750static int coda_querybuf(struct file *file, void *priv,
688 struct v4l2_buffer *buf) 751 struct v4l2_buffer *buf)
689{ 752{
690 struct coda_ctx *ctx = fh_to_ctx(priv); 753 struct coda_ctx *ctx = fh_to_ctx(priv);
691 754
692 return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf); 755 return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
693} 756}
694 757
695static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) 758static int coda_qbuf(struct file *file, void *priv,
759 struct v4l2_buffer *buf)
696{ 760{
697 struct coda_ctx *ctx = fh_to_ctx(priv); 761 struct coda_ctx *ctx = fh_to_ctx(priv);
698 762
699 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf); 763 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
700} 764}
701 765
702static int vidioc_expbuf(struct file *file, void *priv, 766static int coda_expbuf(struct file *file, void *priv,
703 struct v4l2_exportbuffer *eb) 767 struct v4l2_exportbuffer *eb)
704{ 768{
705 struct coda_ctx *ctx = fh_to_ctx(priv); 769 struct coda_ctx *ctx = fh_to_ctx(priv);
706 770
@@ -718,7 +782,8 @@ static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx,
718 (buf->sequence == (ctx->qsequence - 1))); 782 (buf->sequence == (ctx->qsequence - 1)));
719} 783}
720 784
721static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf) 785static int coda_dqbuf(struct file *file, void *priv,
786 struct v4l2_buffer *buf)
722{ 787{
723 struct coda_ctx *ctx = fh_to_ctx(priv); 788 struct coda_ctx *ctx = fh_to_ctx(priv);
724 int ret; 789 int ret;
@@ -738,24 +803,24 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
738 return ret; 803 return ret;
739} 804}
740 805
741static int vidioc_create_bufs(struct file *file, void *priv, 806static int coda_create_bufs(struct file *file, void *priv,
742 struct v4l2_create_buffers *create) 807 struct v4l2_create_buffers *create)
743{ 808{
744 struct coda_ctx *ctx = fh_to_ctx(priv); 809 struct coda_ctx *ctx = fh_to_ctx(priv);
745 810
746 return v4l2_m2m_create_bufs(file, ctx->m2m_ctx, create); 811 return v4l2_m2m_create_bufs(file, ctx->m2m_ctx, create);
747} 812}
748 813
749static int vidioc_streamon(struct file *file, void *priv, 814static int coda_streamon(struct file *file, void *priv,
750 enum v4l2_buf_type type) 815 enum v4l2_buf_type type)
751{ 816{
752 struct coda_ctx *ctx = fh_to_ctx(priv); 817 struct coda_ctx *ctx = fh_to_ctx(priv);
753 818
754 return v4l2_m2m_streamon(file, ctx->m2m_ctx, type); 819 return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
755} 820}
756 821
757static int vidioc_streamoff(struct file *file, void *priv, 822static int coda_streamoff(struct file *file, void *priv,
758 enum v4l2_buf_type type) 823 enum v4l2_buf_type type)
759{ 824{
760 struct coda_ctx *ctx = fh_to_ctx(priv); 825 struct coda_ctx *ctx = fh_to_ctx(priv);
761 int ret; 826 int ret;
@@ -772,23 +837,34 @@ static int vidioc_streamoff(struct file *file, void *priv,
772 return ret; 837 return ret;
773} 838}
774 839
775static int vidioc_decoder_cmd(struct file *file, void *fh, 840static int coda_try_decoder_cmd(struct file *file, void *fh,
776 struct v4l2_decoder_cmd *dc) 841 struct v4l2_decoder_cmd *dc)
777{ 842{
778 struct coda_ctx *ctx = fh_to_ctx(fh);
779
780 if (dc->cmd != V4L2_DEC_CMD_STOP) 843 if (dc->cmd != V4L2_DEC_CMD_STOP)
781 return -EINVAL; 844 return -EINVAL;
782 845
783 if ((dc->flags & V4L2_DEC_CMD_STOP_TO_BLACK) || 846 if (dc->flags & V4L2_DEC_CMD_STOP_TO_BLACK)
784 (dc->flags & V4L2_DEC_CMD_STOP_IMMEDIATELY))
785 return -EINVAL; 847 return -EINVAL;
786 848
787 if (dc->stop.pts != 0) 849 if (!(dc->flags & V4L2_DEC_CMD_STOP_IMMEDIATELY) && (dc->stop.pts != 0))
788 return -EINVAL; 850 return -EINVAL;
789 851
852 return 0;
853}
854
855static int coda_decoder_cmd(struct file *file, void *fh,
856 struct v4l2_decoder_cmd *dc)
857{
858 struct coda_ctx *ctx = fh_to_ctx(fh);
859 int ret;
860
861 ret = coda_try_decoder_cmd(file, fh, dc);
862 if (ret < 0)
863 return ret;
864
865 /* Ignore decoder stop command silently in encoder context */
790 if (ctx->inst_type != CODA_INST_DECODER) 866 if (ctx->inst_type != CODA_INST_DECODER)
791 return -EINVAL; 867 return 0;
792 868
793 /* Set the strem-end flag on this context */ 869 /* Set the strem-end flag on this context */
794 ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; 870 ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG;
@@ -796,8 +872,8 @@ static int vidioc_decoder_cmd(struct file *file, void *fh,
796 return 0; 872 return 0;
797} 873}
798 874
799static int vidioc_subscribe_event(struct v4l2_fh *fh, 875static int coda_subscribe_event(struct v4l2_fh *fh,
800 const struct v4l2_event_subscription *sub) 876 const struct v4l2_event_subscription *sub)
801{ 877{
802 switch (sub->type) { 878 switch (sub->type) {
803 case V4L2_EVENT_EOS: 879 case V4L2_EVENT_EOS:
@@ -808,32 +884,33 @@ static int vidioc_subscribe_event(struct v4l2_fh *fh,
808} 884}
809 885
810static const struct v4l2_ioctl_ops coda_ioctl_ops = { 886static const struct v4l2_ioctl_ops coda_ioctl_ops = {
811 .vidioc_querycap = vidioc_querycap, 887 .vidioc_querycap = coda_querycap,
812 888
813 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 889 .vidioc_enum_fmt_vid_cap = coda_enum_fmt_vid_cap,
814 .vidioc_g_fmt_vid_cap = vidioc_g_fmt, 890 .vidioc_g_fmt_vid_cap = coda_g_fmt,
815 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, 891 .vidioc_try_fmt_vid_cap = coda_try_fmt_vid_cap,
816 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 892 .vidioc_s_fmt_vid_cap = coda_s_fmt_vid_cap,
817 893
818 .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out, 894 .vidioc_enum_fmt_vid_out = coda_enum_fmt_vid_out,
819 .vidioc_g_fmt_vid_out = vidioc_g_fmt, 895 .vidioc_g_fmt_vid_out = coda_g_fmt,
820 .vidioc_try_fmt_vid_out = vidioc_try_fmt_vid_out, 896 .vidioc_try_fmt_vid_out = coda_try_fmt_vid_out,
821 .vidioc_s_fmt_vid_out = vidioc_s_fmt_vid_out, 897 .vidioc_s_fmt_vid_out = coda_s_fmt_vid_out,
822 898
823 .vidioc_reqbufs = vidioc_reqbufs, 899 .vidioc_reqbufs = coda_reqbufs,
824 .vidioc_querybuf = vidioc_querybuf, 900 .vidioc_querybuf = coda_querybuf,
825 901
826 .vidioc_qbuf = vidioc_qbuf, 902 .vidioc_qbuf = coda_qbuf,
827 .vidioc_expbuf = vidioc_expbuf, 903 .vidioc_expbuf = coda_expbuf,
828 .vidioc_dqbuf = vidioc_dqbuf, 904 .vidioc_dqbuf = coda_dqbuf,
829 .vidioc_create_bufs = vidioc_create_bufs, 905 .vidioc_create_bufs = coda_create_bufs,
830 906
831 .vidioc_streamon = vidioc_streamon, 907 .vidioc_streamon = coda_streamon,
832 .vidioc_streamoff = vidioc_streamoff, 908 .vidioc_streamoff = coda_streamoff,
833 909
834 .vidioc_decoder_cmd = vidioc_decoder_cmd, 910 .vidioc_try_decoder_cmd = coda_try_decoder_cmd,
911 .vidioc_decoder_cmd = coda_decoder_cmd,
835 912
836 .vidioc_subscribe_event = vidioc_subscribe_event, 913 .vidioc_subscribe_event = coda_subscribe_event,
837 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 914 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
838}; 915};
839 916
@@ -1928,8 +2005,9 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
1928 if (!(ctx->streamon_out & ctx->streamon_cap)) 2005 if (!(ctx->streamon_out & ctx->streamon_cap))
1929 return 0; 2006 return 0;
1930 2007
1931 /* Allow device_run with no buffers queued and after streamoff */ 2008 /* Allow decoder device_run with no new buffers queued */
1932 v4l2_m2m_set_src_buffered(ctx->m2m_ctx, true); 2009 if (ctx->inst_type == CODA_INST_DECODER)
2010 v4l2_m2m_set_src_buffered(ctx->m2m_ctx, true);
1933 2011
1934 ctx->gopcounter = ctx->params.gop_size - 1; 2012 ctx->gopcounter = ctx->params.gop_size - 1;
1935 buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); 2013 buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
@@ -2071,10 +2149,8 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
2071 coda_setup_iram(ctx); 2149 coda_setup_iram(ctx);
2072 2150
2073 if (dst_fourcc == V4L2_PIX_FMT_H264) { 2151 if (dst_fourcc == V4L2_PIX_FMT_H264) {
2074 value = (FMO_SLICE_SAVE_BUF_SIZE << 7);
2075 value |= (0 & CODA_FMOPARAM_TYPE_MASK) << CODA_FMOPARAM_TYPE_OFFSET;
2076 value |= 0 & CODA_FMOPARAM_SLICENUM_MASK;
2077 if (dev->devtype->product == CODA_DX6) { 2152 if (dev->devtype->product == CODA_DX6) {
2153 value = FMO_SLICE_SAVE_BUF_SIZE << 7;
2078 coda_write(dev, value, CODADX6_CMD_ENC_SEQ_FMO); 2154 coda_write(dev, value, CODADX6_CMD_ENC_SEQ_FMO);
2079 } else { 2155 } else {
2080 coda_write(dev, ctx->iram_info.search_ram_paddr, 2156 coda_write(dev, ctx->iram_info.search_ram_paddr,
@@ -2371,7 +2447,13 @@ static int coda_queue_init(void *priv, struct vb2_queue *src_vq,
2371 2447
2372static int coda_next_free_instance(struct coda_dev *dev) 2448static int coda_next_free_instance(struct coda_dev *dev)
2373{ 2449{
2374 return ffz(dev->instance_mask); 2450 int idx = ffz(dev->instance_mask);
2451
2452 if ((idx < 0) ||
2453 (dev->devtype->product == CODA_DX6 && idx > CODADX6_MAX_INSTANCES))
2454 return -EBUSY;
2455
2456 return idx;
2375} 2457}
2376 2458
2377static int coda_open(struct file *file) 2459static int coda_open(struct file *file)
@@ -2386,8 +2468,8 @@ static int coda_open(struct file *file)
2386 return -ENOMEM; 2468 return -ENOMEM;
2387 2469
2388 idx = coda_next_free_instance(dev); 2470 idx = coda_next_free_instance(dev);
2389 if (idx >= CODA_MAX_INSTANCES) { 2471 if (idx < 0) {
2390 ret = -EBUSY; 2472 ret = idx;
2391 goto err_coda_max; 2473 goto err_coda_max;
2392 } 2474 }
2393 set_bit(idx, &dev->instance_mask); 2475 set_bit(idx, &dev->instance_mask);
@@ -2719,7 +2801,6 @@ static void coda_finish_encode(struct coda_ctx *ctx)
2719 dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); 2801 dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
2720 2802
2721 /* Get results from the coda */ 2803 /* Get results from the coda */
2722 coda_read(dev, CODA_RET_ENC_PIC_TYPE);
2723 start_ptr = coda_read(dev, CODA_CMD_ENC_PIC_BB_START); 2804 start_ptr = coda_read(dev, CODA_CMD_ENC_PIC_BB_START);
2724 wr_ptr = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); 2805 wr_ptr = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx));
2725 2806
@@ -2739,7 +2820,7 @@ static void coda_finish_encode(struct coda_ctx *ctx)
2739 coda_read(dev, CODA_RET_ENC_PIC_SLICE_NUM); 2820 coda_read(dev, CODA_RET_ENC_PIC_SLICE_NUM);
2740 coda_read(dev, CODA_RET_ENC_PIC_FLAG); 2821 coda_read(dev, CODA_RET_ENC_PIC_FLAG);
2741 2822
2742 if (src_buf->v4l2_buf.flags & V4L2_BUF_FLAG_KEYFRAME) { 2823 if (coda_read(dev, CODA_RET_ENC_PIC_TYPE) == 0) {
2743 dst_buf->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME; 2824 dst_buf->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
2744 dst_buf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_PFRAME; 2825 dst_buf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_PFRAME;
2745 } else { 2826 } else {
@@ -2861,21 +2942,6 @@ static bool coda_firmware_supported(u32 vernum)
2861 return false; 2942 return false;
2862} 2943}
2863 2944
2864static char *coda_product_name(int product)
2865{
2866 static char buf[9];
2867
2868 switch (product) {
2869 case CODA_DX6:
2870 return "CodaDx6";
2871 case CODA_7541:
2872 return "CODA7541";
2873 default:
2874 snprintf(buf, sizeof(buf), "(0x%04x)", product);
2875 return buf;
2876 }
2877}
2878
2879static int coda_hw_init(struct coda_dev *dev) 2945static int coda_hw_init(struct coda_dev *dev)
2880{ 2946{
2881 u16 product, major, minor, release; 2947 u16 product, major, minor, release;
diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index 04609cc6eba7..eac472b5ae83 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -1785,7 +1785,7 @@ static int vpbe_display_probe(struct platform_device *pdev)
1785 } 1785 }
1786 1786
1787 irq = res->start; 1787 irq = res->start;
1788 err = devm_request_irq(&pdev->dev, irq, venc_isr, IRQF_DISABLED, 1788 err = devm_request_irq(&pdev->dev, irq, venc_isr, 0,
1789 VPBE_DISPLAY_DRIVER, disp_dev); 1789 VPBE_DISPLAY_DRIVER, disp_dev);
1790 if (err) { 1790 if (err) {
1791 v4l2_err(&disp_dev->vpbe_dev->v4l2_dev, 1791 v4l2_err(&disp_dev->vpbe_dev->v4l2_dev,
diff --git a/drivers/media/platform/davinci/vpfe_capture.c b/drivers/media/platform/davinci/vpfe_capture.c
index 93609091cb23..d762246eabf5 100644
--- a/drivers/media/platform/davinci/vpfe_capture.c
+++ b/drivers/media/platform/davinci/vpfe_capture.c
@@ -688,7 +688,7 @@ static int vpfe_attach_irq(struct vpfe_device *vpfe_dev)
688 frame_format = ccdc_dev->hw_ops.get_frame_format(); 688 frame_format = ccdc_dev->hw_ops.get_frame_format();
689 if (frame_format == CCDC_FRMFMT_PROGRESSIVE) { 689 if (frame_format == CCDC_FRMFMT_PROGRESSIVE) {
690 return request_irq(vpfe_dev->ccdc_irq1, vdint1_isr, 690 return request_irq(vpfe_dev->ccdc_irq1, vdint1_isr,
691 IRQF_DISABLED, "vpfe_capture1", 691 0, "vpfe_capture1",
692 vpfe_dev); 692 vpfe_dev);
693 } 693 }
694 return 0; 694 return 0;
@@ -1863,7 +1863,7 @@ static int vpfe_probe(struct platform_device *pdev)
1863 } 1863 }
1864 vpfe_dev->ccdc_irq1 = res1->start; 1864 vpfe_dev->ccdc_irq1 = res1->start;
1865 1865
1866 ret = request_irq(vpfe_dev->ccdc_irq0, vpfe_isr, IRQF_DISABLED, 1866 ret = request_irq(vpfe_dev->ccdc_irq0, vpfe_isr, 0,
1867 "vpfe_capture0", vpfe_dev); 1867 "vpfe_capture0", vpfe_dev);
1868 1868
1869 if (0 != ret) { 1869 if (0 != ret) {
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index 1089834a4efe..52ac5e6c8625 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -2154,7 +2154,7 @@ static __init int vpif_probe(struct platform_device *pdev)
2154 2154
2155 if (!vpif_obj.sd[i]) { 2155 if (!vpif_obj.sd[i]) {
2156 vpif_err("Error registering v4l2 subdevice\n"); 2156 vpif_err("Error registering v4l2 subdevice\n");
2157 err = -ENOMEM; 2157 err = -ENODEV;
2158 goto probe_subdev_out; 2158 goto probe_subdev_out;
2159 } 2159 }
2160 v4l2_info(&vpif_obj.v4l2_dev, 2160 v4l2_info(&vpif_obj.v4l2_dev,
diff --git a/drivers/media/platform/exynos-gsc/gsc-core.h b/drivers/media/platform/exynos-gsc/gsc-core.h
index 76435d3bf62d..ef0a6564cef9 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.h
+++ b/drivers/media/platform/exynos-gsc/gsc-core.h
@@ -45,6 +45,7 @@
45#define GSC_DST_FMT (1 << 2) 45#define GSC_DST_FMT (1 << 2)
46#define GSC_CTX_M2M (1 << 3) 46#define GSC_CTX_M2M (1 << 3)
47#define GSC_CTX_STOP_REQ (1 << 6) 47#define GSC_CTX_STOP_REQ (1 << 6)
48#define GSC_CTX_ABORT (1 << 7)
48 49
49enum gsc_dev_flags { 50enum gsc_dev_flags {
50 /* for global */ 51 /* for global */
diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index e576ff2de3de..810c3e13970c 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -46,6 +46,17 @@ static int gsc_m2m_ctx_stop_req(struct gsc_ctx *ctx)
46 return ret == 0 ? -ETIMEDOUT : ret; 46 return ret == 0 ? -ETIMEDOUT : ret;
47} 47}
48 48
49static void __gsc_m2m_job_abort(struct gsc_ctx *ctx)
50{
51 int ret;
52
53 ret = gsc_m2m_ctx_stop_req(ctx);
54 if ((ret == -ETIMEDOUT) || (ctx->state & GSC_CTX_ABORT)) {
55 gsc_ctx_state_lock_clear(GSC_CTX_STOP_REQ | GSC_CTX_ABORT, ctx);
56 gsc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
57 }
58}
59
49static int gsc_m2m_start_streaming(struct vb2_queue *q, unsigned int count) 60static int gsc_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
50{ 61{
51 struct gsc_ctx *ctx = q->drv_priv; 62 struct gsc_ctx *ctx = q->drv_priv;
@@ -58,11 +69,8 @@ static int gsc_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
58static int gsc_m2m_stop_streaming(struct vb2_queue *q) 69static int gsc_m2m_stop_streaming(struct vb2_queue *q)
59{ 70{
60 struct gsc_ctx *ctx = q->drv_priv; 71 struct gsc_ctx *ctx = q->drv_priv;
61 int ret;
62 72
63 ret = gsc_m2m_ctx_stop_req(ctx); 73 __gsc_m2m_job_abort(ctx);
64 if (ret == -ETIMEDOUT)
65 gsc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
66 74
67 pm_runtime_put(&ctx->gsc_dev->pdev->dev); 75 pm_runtime_put(&ctx->gsc_dev->pdev->dev);
68 76
@@ -91,15 +99,9 @@ void gsc_m2m_job_finish(struct gsc_ctx *ctx, int vb_state)
91 } 99 }
92} 100}
93 101
94
95static void gsc_m2m_job_abort(void *priv) 102static void gsc_m2m_job_abort(void *priv)
96{ 103{
97 struct gsc_ctx *ctx = priv; 104 __gsc_m2m_job_abort((struct gsc_ctx *)priv);
98 int ret;
99
100 ret = gsc_m2m_ctx_stop_req(ctx);
101 if (ret == -ETIMEDOUT)
102 gsc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
103} 105}
104 106
105static int gsc_get_bufs(struct gsc_ctx *ctx) 107static int gsc_get_bufs(struct gsc_ctx *ctx)
@@ -150,9 +152,10 @@ static void gsc_m2m_device_run(void *priv)
150 gsc->m2m.ctx = ctx; 152 gsc->m2m.ctx = ctx;
151 } 153 }
152 154
153 is_set = (ctx->state & GSC_CTX_STOP_REQ) ? 1 : 0; 155 is_set = ctx->state & GSC_CTX_STOP_REQ;
154 ctx->state &= ~GSC_CTX_STOP_REQ;
155 if (is_set) { 156 if (is_set) {
157 ctx->state &= ~GSC_CTX_STOP_REQ;
158 ctx->state |= GSC_CTX_ABORT;
156 wake_up(&gsc->irq_queue); 159 wake_up(&gsc->irq_queue);
157 goto put_device; 160 goto put_device;
158 } 161 }
diff --git a/drivers/media/platform/exynos4-is/fimc-isp.c b/drivers/media/platform/exynos4-is/fimc-isp.c
index d2e6cba3566d..f3c6136aa5b4 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp.c
@@ -511,7 +511,7 @@ static int __ctrl_set_metering(struct fimc_is *is, unsigned int value)
511 break; 511 break;
512 default: 512 default:
513 return -EINVAL; 513 return -EINVAL;
514 }; 514 }
515 515
516 __is_set_isp_metering(is, IS_METERING_CONFIG_CMD, val); 516 __is_set_isp_metering(is, IS_METERING_CONFIG_CMD, val);
517 return 0; 517 return 0;
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index a83511278317..7a4ee4c0449d 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -411,8 +411,8 @@ static int fimc_md_of_add_sensor(struct fimc_md *fmd,
411 411
412 device_lock(&client->dev); 412 device_lock(&client->dev);
413 413
414 if (!client->driver || 414 if (!client->dev.driver ||
415 !try_module_get(client->driver->driver.owner)) { 415 !try_module_get(client->dev.driver->owner)) {
416 ret = -EPROBE_DEFER; 416 ret = -EPROBE_DEFER;
417 v4l2_info(&fmd->v4l2_dev, "No driver found for %s\n", 417 v4l2_info(&fmd->v4l2_dev, "No driver found for %s\n",
418 node->full_name); 418 node->full_name);
@@ -442,7 +442,7 @@ static int fimc_md_of_add_sensor(struct fimc_md *fmd,
442 fmd->num_sensors++; 442 fmd->num_sensors++;
443 443
444mod_put: 444mod_put:
445 module_put(client->driver->driver.owner); 445 module_put(client->dev.driver->owner);
446dev_put: 446dev_put:
447 device_unlock(&client->dev); 447 device_unlock(&client->dev);
448 put_device(&client->dev); 448 put_device(&client->dev);
diff --git a/drivers/media/platform/m2m-deinterlace.c b/drivers/media/platform/m2m-deinterlace.c
index 540516ca872c..36513e896413 100644
--- a/drivers/media/platform/m2m-deinterlace.c
+++ b/drivers/media/platform/m2m-deinterlace.c
@@ -1084,8 +1084,7 @@ free_dev:
1084 1084
1085static int deinterlace_remove(struct platform_device *pdev) 1085static int deinterlace_remove(struct platform_device *pdev)
1086{ 1086{
1087 struct deinterlace_dev *pcdev = 1087 struct deinterlace_dev *pcdev = platform_get_drvdata(pdev);
1088 (struct deinterlace_dev *)platform_get_drvdata(pdev);
1089 1088
1090 v4l2_info(&pcdev->v4l2_dev, "Removing " MEM2MEM_TEST_MODULE_NAME); 1089 v4l2_info(&pcdev->v4l2_dev, "Removing " MEM2MEM_TEST_MODULE_NAME);
1091 v4l2_m2m_release(pcdev->m2m_dev); 1090 v4l2_m2m_release(pcdev->m2m_dev);
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index 5184887b155c..32fab30a9105 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -1221,16 +1221,16 @@ static int mcam_vb_sg_buf_prepare(struct vb2_buffer *vb)
1221{ 1221{
1222 struct mcam_vb_buffer *mvb = vb_to_mvb(vb); 1222 struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
1223 struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue); 1223 struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue);
1224 struct vb2_dma_sg_desc *sgd = vb2_dma_sg_plane_desc(vb, 0); 1224 struct sg_table *sg_table = vb2_dma_sg_plane_desc(vb, 0);
1225 struct mcam_dma_desc *desc = mvb->dma_desc; 1225 struct mcam_dma_desc *desc = mvb->dma_desc;
1226 struct scatterlist *sg; 1226 struct scatterlist *sg;
1227 int i; 1227 int i;
1228 1228
1229 mvb->dma_desc_nent = dma_map_sg(cam->dev, sgd->sglist, sgd->num_pages, 1229 mvb->dma_desc_nent = dma_map_sg(cam->dev, sg_table->sgl,
1230 DMA_FROM_DEVICE); 1230 sg_table->nents, DMA_FROM_DEVICE);
1231 if (mvb->dma_desc_nent <= 0) 1231 if (mvb->dma_desc_nent <= 0)
1232 return -EIO; /* Not sure what's right here */ 1232 return -EIO; /* Not sure what's right here */
1233 for_each_sg(sgd->sglist, sg, mvb->dma_desc_nent, i) { 1233 for_each_sg(sg_table->sgl, sg, mvb->dma_desc_nent, i) {
1234 desc->dma_addr = sg_dma_address(sg); 1234 desc->dma_addr = sg_dma_address(sg);
1235 desc->segment_len = sg_dma_len(sg); 1235 desc->segment_len = sg_dma_len(sg);
1236 desc++; 1236 desc++;
@@ -1241,9 +1241,11 @@ static int mcam_vb_sg_buf_prepare(struct vb2_buffer *vb)
1241static int mcam_vb_sg_buf_finish(struct vb2_buffer *vb) 1241static int mcam_vb_sg_buf_finish(struct vb2_buffer *vb)
1242{ 1242{
1243 struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue); 1243 struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue);
1244 struct vb2_dma_sg_desc *sgd = vb2_dma_sg_plane_desc(vb, 0); 1244 struct sg_table *sg_table = vb2_dma_sg_plane_desc(vb, 0);
1245 1245
1246 dma_unmap_sg(cam->dev, sgd->sglist, sgd->num_pages, DMA_FROM_DEVICE); 1246 if (sg_table)
1247 dma_unmap_sg(cam->dev, sg_table->sgl,
1248 sg_table->nents, DMA_FROM_DEVICE);
1247 return 0; 1249 return 0;
1248} 1250}
1249 1251
diff --git a/drivers/media/platform/marvell-ccic/mmp-driver.c b/drivers/media/platform/marvell-ccic/mmp-driver.c
index b5a19af5c587..3458fa0e2fd5 100644
--- a/drivers/media/platform/marvell-ccic/mmp-driver.c
+++ b/drivers/media/platform/marvell-ccic/mmp-driver.c
@@ -481,7 +481,6 @@ static int mmpcam_remove(struct mmp_camera *cam)
481 struct mmp_camera_platform_data *pdata; 481 struct mmp_camera_platform_data *pdata;
482 482
483 mmpcam_remove_device(cam); 483 mmpcam_remove_device(cam);
484 free_irq(cam->irq, mcam);
485 mccic_shutdown(mcam); 484 mccic_shutdown(mcam);
486 mmpcam_power_down(mcam); 485 mmpcam_power_down(mcam);
487 pdata = cam->pdev->dev.platform_data; 486 pdata = cam->pdev->dev.platform_data;
diff --git a/drivers/media/platform/mem2mem_testdev.c b/drivers/media/platform/mem2mem_testdev.c
index 6a17676f9d72..8df5975b700a 100644
--- a/drivers/media/platform/mem2mem_testdev.c
+++ b/drivers/media/platform/mem2mem_testdev.c
@@ -1090,8 +1090,7 @@ unreg_dev:
1090 1090
1091static int m2mtest_remove(struct platform_device *pdev) 1091static int m2mtest_remove(struct platform_device *pdev)
1092{ 1092{
1093 struct m2mtest_dev *dev = 1093 struct m2mtest_dev *dev = platform_get_drvdata(pdev);
1094 (struct m2mtest_dev *)platform_get_drvdata(pdev);
1095 1094
1096 v4l2_info(&dev->v4l2_dev, "Removing " MEM2MEM_TEST_MODULE_NAME); 1095 v4l2_info(&dev->v4l2_dev, "Removing " MEM2MEM_TEST_MODULE_NAME);
1097 v4l2_m2m_release(dev->m2m_dev); 1096 v4l2_m2m_release(dev->m2m_dev);
diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
index fd6289d60cde..0b2948376aee 100644
--- a/drivers/media/platform/s5p-g2d/g2d.c
+++ b/drivers/media/platform/s5p-g2d/g2d.c
@@ -840,7 +840,7 @@ put_clk:
840 840
841static int g2d_remove(struct platform_device *pdev) 841static int g2d_remove(struct platform_device *pdev)
842{ 842{
843 struct g2d_dev *dev = (struct g2d_dev *)platform_get_drvdata(pdev); 843 struct g2d_dev *dev = platform_get_drvdata(pdev);
844 844
845 v4l2_info(&dev->v4l2_dev, "Removing " G2D_NAME); 845 v4l2_info(&dev->v4l2_dev, "Removing " G2D_NAME);
846 v4l2_m2m_release(dev->m2m_dev); 846 v4l2_m2m_release(dev->m2m_dev);
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 084263dd126f..5f2c4ad6c2cb 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -404,7 +404,11 @@ leave_handle_frame:
404 if (test_and_clear_bit(0, &dev->hw_lock) == 0) 404 if (test_and_clear_bit(0, &dev->hw_lock) == 0)
405 BUG(); 405 BUG();
406 s5p_mfc_clock_off(); 406 s5p_mfc_clock_off();
407 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev); 407 /* if suspending, wake up device and do not try_run again*/
408 if (test_bit(0, &dev->enter_suspend))
409 wake_up_dev(dev, reason, err);
410 else
411 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
408} 412}
409 413
410/* Error handling for interrupt */ 414/* Error handling for interrupt */
@@ -1101,7 +1105,7 @@ static int s5p_mfc_probe(struct platform_device *pdev)
1101 } 1105 }
1102 dev->irq = res->start; 1106 dev->irq = res->start;
1103 ret = devm_request_irq(&pdev->dev, dev->irq, s5p_mfc_irq, 1107 ret = devm_request_irq(&pdev->dev, dev->irq, s5p_mfc_irq,
1104 IRQF_DISABLED, pdev->name, dev); 1108 0, pdev->name, dev);
1105 if (ret) { 1109 if (ret) {
1106 dev_err(&pdev->dev, "Failed to install irq (%d)\n", ret); 1110 dev_err(&pdev->dev, "Failed to install irq (%d)\n", ret);
1107 goto err_res; 1111 goto err_res;
@@ -1286,9 +1290,7 @@ static int s5p_mfc_suspend(struct device *dev)
1286 /* Try and lock the HW */ 1290 /* Try and lock the HW */
1287 /* Wait on the interrupt waitqueue */ 1291 /* Wait on the interrupt waitqueue */
1288 ret = wait_event_interruptible_timeout(m_dev->queue, 1292 ret = wait_event_interruptible_timeout(m_dev->queue,
1289 m_dev->int_cond || m_dev->ctx[m_dev->curr_ctx]->int_cond, 1293 m_dev->int_cond, msecs_to_jiffies(MFC_INT_TIMEOUT));
1290 msecs_to_jiffies(MFC_INT_TIMEOUT));
1291
1292 if (ret == 0) { 1294 if (ret == 0) {
1293 mfc_err("Waiting for hardware to finish timed out\n"); 1295 mfc_err("Waiting for hardware to finish timed out\n");
1294 return -EIO; 1296 return -EIO;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v5.c b/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v5.c
index ad4f1df0a18e..9a6efd6c1329 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v5.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v5.c
@@ -111,7 +111,7 @@ static int s5p_mfc_open_inst_cmd_v5(struct s5p_mfc_ctx *ctx)
111 break; 111 break;
112 default: 112 default:
113 h2r_args.arg[0] = S5P_FIMV_CODEC_NONE; 113 h2r_args.arg[0] = S5P_FIMV_CODEC_NONE;
114 }; 114 }
115 h2r_args.arg[1] = 0; /* no crc & no pixelcache */ 115 h2r_args.arg[1] = 0; /* no crc & no pixelcache */
116 h2r_args.arg[2] = ctx->ctx.ofs; 116 h2r_args.arg[2] = ctx->ctx.ofs;
117 h2r_args.arg[3] = ctx->ctx.size; 117 h2r_args.arg[3] = ctx->ctx.size;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c b/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c
index db796c8e7874..ec1a5947ed7d 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c
@@ -113,7 +113,7 @@ static int s5p_mfc_open_inst_cmd_v6(struct s5p_mfc_ctx *ctx)
113 break; 113 break;
114 default: 114 default:
115 codec_type = S5P_FIMV_CODEC_NONE_V6; 115 codec_type = S5P_FIMV_CODEC_NONE_V6;
116 }; 116 }
117 mfc_write(dev, codec_type, S5P_FIMV_CODEC_TYPE_V6); 117 mfc_write(dev, codec_type, S5P_FIMV_CODEC_TYPE_V6);
118 mfc_write(dev, ctx->ctx.dma, S5P_FIMV_CONTEXT_MEM_ADDR_V6); 118 mfc_write(dev, ctx->ctx.dma, S5P_FIMV_CONTEXT_MEM_ADDR_V6);
119 mfc_write(dev, ctx->ctx.size, S5P_FIMV_CONTEXT_MEM_SIZE_V6); 119 mfc_write(dev, ctx->ctx.size, S5P_FIMV_CONTEXT_MEM_SIZE_V6);
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index 41f5a3c10dbd..4ff3b6cd6842 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -113,7 +113,7 @@ static struct mfc_control controls[] = {
113 .minimum = 0, 113 .minimum = 0,
114 .maximum = (1 << 16) - 1, 114 .maximum = (1 << 16) - 1,
115 .step = 1, 115 .step = 1,
116 .default_value = 0, 116 .default_value = 12,
117 }, 117 },
118 { 118 {
119 .id = V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE, 119 .id = V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE,
@@ -356,7 +356,7 @@ static struct mfc_control controls[] = {
356 .minimum = 0, 356 .minimum = 0,
357 .maximum = 51, 357 .maximum = 51,
358 .step = 1, 358 .step = 1,
359 .default_value = 1, 359 .default_value = 51,
360 }, 360 },
361 { 361 {
362 .id = V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP, 362 .id = V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP,
@@ -399,7 +399,7 @@ static struct mfc_control controls[] = {
399 .minimum = 1, 399 .minimum = 1,
400 .maximum = 31, 400 .maximum = 31,
401 .step = 1, 401 .step = 1,
402 .default_value = 1, 402 .default_value = 31,
403 }, 403 },
404 { 404 {
405 .id = V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP, 405 .id = V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP,
@@ -444,7 +444,7 @@ static struct mfc_control controls[] = {
444 .minimum = 0, 444 .minimum = 0,
445 .maximum = 51, 445 .maximum = 51,
446 .step = 1, 446 .step = 1,
447 .default_value = 1, 447 .default_value = 51,
448 }, 448 },
449 { 449 {
450 .id = V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP, 450 .id = V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP,
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
index 368582b091bf..58ec7bb26ebc 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
@@ -1582,7 +1582,7 @@ static int s5p_mfc_get_int_reason_v5(struct s5p_mfc_dev *dev)
1582 break; 1582 break;
1583 default: 1583 default:
1584 reason = S5P_MFC_R2H_CMD_EMPTY; 1584 reason = S5P_MFC_R2H_CMD_EMPTY;
1585 }; 1585 }
1586 return reason; 1586 return reason;
1587} 1587}
1588 1588
diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
index b93a21f5aa13..74344c764daa 100644
--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
@@ -226,7 +226,7 @@ static void mxr_graph_fix_geometry(struct mxr_layer *layer,
226 src->width + src->x_offset, 32767); 226 src->width + src->x_offset, 32767);
227 src->full_height = clamp_val(src->full_height, 227 src->full_height = clamp_val(src->full_height,
228 src->height + src->y_offset, 2047); 228 src->height + src->y_offset, 2047);
229 }; 229 }
230} 230}
231 231
232/* PUBLIC API */ 232/* PUBLIC API */
diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
index 3d13a636877b..c9388c45ad75 100644
--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
@@ -197,7 +197,7 @@ static void mxr_vp_fix_geometry(struct mxr_layer *layer,
197 ALIGN(src->width + src->x_offset, 8), 8192U); 197 ALIGN(src->width + src->x_offset, 8), 8192U);
198 src->full_height = clamp(src->full_height, 198 src->full_height = clamp(src->full_height,
199 src->height + src->y_offset, 8192U); 199 src->height + src->y_offset, 8192U);
200 }; 200 }
201} 201}
202 202
203/* PUBLIC API */ 203/* PUBLIC API */
diff --git a/drivers/media/platform/soc_camera/rcar_vin.c b/drivers/media/platform/soc_camera/rcar_vin.c
index d02a7e0b773f..6866bb4fbebc 100644
--- a/drivers/media/platform/soc_camera/rcar_vin.c
+++ b/drivers/media/platform/soc_camera/rcar_vin.c
@@ -16,6 +16,7 @@
16 16
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/io.h>
19#include <linux/kernel.h> 20#include <linux/kernel.h>
20#include <linux/module.h> 21#include <linux/module.h>
21#include <linux/platform_data/camera-rcar.h> 22#include <linux/platform_data/camera-rcar.h>
@@ -105,6 +106,7 @@
105#define VIN_MAX_HEIGHT 2048 106#define VIN_MAX_HEIGHT 2048
106 107
107enum chip_id { 108enum chip_id {
109 RCAR_H2,
108 RCAR_H1, 110 RCAR_H1,
109 RCAR_M1, 111 RCAR_M1,
110 RCAR_E1, 112 RCAR_E1,
@@ -300,7 +302,8 @@ static int rcar_vin_setup(struct rcar_vin_priv *priv)
300 dmr = 0; 302 dmr = 0;
301 break; 303 break;
302 case V4L2_PIX_FMT_RGB32: 304 case V4L2_PIX_FMT_RGB32:
303 if (priv->chip == RCAR_H1 || priv->chip == RCAR_E1) { 305 if (priv->chip == RCAR_H2 || priv->chip == RCAR_H1 ||
306 priv->chip == RCAR_E1) {
304 dmr = VNDMR_EXRGB; 307 dmr = VNDMR_EXRGB;
305 break; 308 break;
306 } 309 }
@@ -1381,6 +1384,7 @@ static struct soc_camera_host_ops rcar_vin_host_ops = {
1381}; 1384};
1382 1385
1383static struct platform_device_id rcar_vin_id_table[] = { 1386static struct platform_device_id rcar_vin_id_table[] = {
1387 { "r8a7790-vin", RCAR_H2 },
1384 { "r8a7779-vin", RCAR_H1 }, 1388 { "r8a7779-vin", RCAR_H1 },
1385 { "r8a7778-vin", RCAR_M1 }, 1389 { "r8a7778-vin", RCAR_M1 },
1386 { "uPD35004-vin", RCAR_E1 }, 1390 { "uPD35004-vin", RCAR_E1 },
diff --git a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
index 8df22f779175..150bd4df413c 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
@@ -1800,7 +1800,7 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev)
1800 1800
1801 /* request irq */ 1801 /* request irq */
1802 err = devm_request_irq(&pdev->dev, pcdev->irq, sh_mobile_ceu_irq, 1802 err = devm_request_irq(&pdev->dev, pcdev->irq, sh_mobile_ceu_irq,
1803 IRQF_DISABLED, dev_name(&pdev->dev), pcdev); 1803 0, dev_name(&pdev->dev), pcdev);
1804 if (err) { 1804 if (err) {
1805 dev_err(&pdev->dev, "Unable to register CEU interrupt.\n"); 1805 dev_err(&pdev->dev, "Unable to register CEU interrupt.\n");
1806 goto exit_release_mem; 1806 goto exit_release_mem;
diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index 387a232d95a4..4b8c024fc487 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -71,13 +71,23 @@ static int video_dev_create(struct soc_camera_device *icd);
71int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd, 71int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd,
72 struct v4l2_clk *clk) 72 struct v4l2_clk *clk)
73{ 73{
74 int ret = clk ? v4l2_clk_enable(clk) : 0; 74 int ret;
75 if (ret < 0) { 75 bool clock_toggle;
76 dev_err(dev, "Cannot enable clock: %d\n", ret); 76
77 return ret; 77 if (clk && (!ssdd->unbalanced_power ||
78 !test_and_set_bit(0, &ssdd->clock_state))) {
79 ret = v4l2_clk_enable(clk);
80 if (ret < 0) {
81 dev_err(dev, "Cannot enable clock: %d\n", ret);
82 return ret;
83 }
84 clock_toggle = true;
85 } else {
86 clock_toggle = false;
78 } 87 }
79 ret = regulator_bulk_enable(ssdd->num_regulators, 88
80 ssdd->regulators); 89 ret = regulator_bulk_enable(ssdd->sd_pdata.num_regulators,
90 ssdd->sd_pdata.regulators);
81 if (ret < 0) { 91 if (ret < 0) {
82 dev_err(dev, "Cannot enable regulators\n"); 92 dev_err(dev, "Cannot enable regulators\n");
83 goto eregenable; 93 goto eregenable;
@@ -95,10 +105,10 @@ int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd,
95 return 0; 105 return 0;
96 106
97epwron: 107epwron:
98 regulator_bulk_disable(ssdd->num_regulators, 108 regulator_bulk_disable(ssdd->sd_pdata.num_regulators,
99 ssdd->regulators); 109 ssdd->sd_pdata.regulators);
100eregenable: 110eregenable:
101 if (clk) 111 if (clock_toggle)
102 v4l2_clk_disable(clk); 112 v4l2_clk_disable(clk);
103 113
104 return ret; 114 return ret;
@@ -120,14 +130,14 @@ int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd
120 } 130 }
121 } 131 }
122 132
123 err = regulator_bulk_disable(ssdd->num_regulators, 133 err = regulator_bulk_disable(ssdd->sd_pdata.num_regulators,
124 ssdd->regulators); 134 ssdd->sd_pdata.regulators);
125 if (err < 0) { 135 if (err < 0) {
126 dev_err(dev, "Cannot disable regulators\n"); 136 dev_err(dev, "Cannot disable regulators\n");
127 ret = ret ? : err; 137 ret = ret ? : err;
128 } 138 }
129 139
130 if (clk) 140 if (clk && (!ssdd->unbalanced_power || test_and_clear_bit(0, &ssdd->clock_state)))
131 v4l2_clk_disable(clk); 141 v4l2_clk_disable(clk);
132 142
133 return ret; 143 return ret;
@@ -137,8 +147,8 @@ EXPORT_SYMBOL(soc_camera_power_off);
137int soc_camera_power_init(struct device *dev, struct soc_camera_subdev_desc *ssdd) 147int soc_camera_power_init(struct device *dev, struct soc_camera_subdev_desc *ssdd)
138{ 148{
139 /* Should not have any effect in synchronous case */ 149 /* Should not have any effect in synchronous case */
140 return devm_regulator_bulk_get(dev, ssdd->num_regulators, 150 return devm_regulator_bulk_get(dev, ssdd->sd_pdata.num_regulators,
141 ssdd->regulators); 151 ssdd->sd_pdata.regulators);
142} 152}
143EXPORT_SYMBOL(soc_camera_power_init); 153EXPORT_SYMBOL(soc_camera_power_init);
144 154
@@ -1346,8 +1356,8 @@ static int soc_camera_i2c_init(struct soc_camera_device *icd,
1346 * soc_camera_pdrv_probe(), make sure the subdevice driver doesn't try 1356 * soc_camera_pdrv_probe(), make sure the subdevice driver doesn't try
1347 * to allocate them again. 1357 * to allocate them again.
1348 */ 1358 */
1349 ssdd->num_regulators = 0; 1359 ssdd->sd_pdata.num_regulators = 0;
1350 ssdd->regulators = NULL; 1360 ssdd->sd_pdata.regulators = NULL;
1351 shd->board_info->platform_data = ssdd; 1361 shd->board_info->platform_data = ssdd;
1352 1362
1353 snprintf(clk_name, sizeof(clk_name), "%d-%04x", 1363 snprintf(clk_name, sizeof(clk_name), "%d-%04x",
@@ -2020,8 +2030,8 @@ static int soc_camera_pdrv_probe(struct platform_device *pdev)
2020 * that case regulators are attached to the I2C device and not to the 2030 * that case regulators are attached to the I2C device and not to the
2021 * camera platform device. 2031 * camera platform device.
2022 */ 2032 */
2023 ret = devm_regulator_bulk_get(&pdev->dev, ssdd->num_regulators, 2033 ret = devm_regulator_bulk_get(&pdev->dev, ssdd->sd_pdata.num_regulators,
2024 ssdd->regulators); 2034 ssdd->sd_pdata.regulators);
2025 if (ret < 0) 2035 if (ret < 0)
2026 return ret; 2036 return ret;
2027 2037
diff --git a/drivers/media/platform/ti-vpe/Makefile b/drivers/media/platform/ti-vpe/Makefile
new file mode 100644
index 000000000000..cbf0a806ba1d
--- /dev/null
+++ b/drivers/media/platform/ti-vpe/Makefile
@@ -0,0 +1,5 @@
1obj-$(CONFIG_VIDEO_TI_VPE) += ti-vpe.o
2
3ti-vpe-y := vpe.o vpdma.o
4
5ccflags-$(CONFIG_VIDEO_TI_VPE_DEBUG) += -DDEBUG
diff --git a/drivers/media/platform/ti-vpe/vpdma.c b/drivers/media/platform/ti-vpe/vpdma.c
new file mode 100644
index 000000000000..af0a5ffcaa98
--- /dev/null
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -0,0 +1,846 @@
1/*
2 * VPDMA helper library
3 *
4 * Copyright (c) 2013 Texas Instruments Inc.
5 *
6 * David Griego, <dagriego@biglakesoftware.com>
7 * Dale Farnsworth, <dale@farnsworth.org>
8 * Archit Taneja, <archit@ti.com>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 */
14
15#include <linux/delay.h>
16#include <linux/dma-mapping.h>
17#include <linux/err.h>
18#include <linux/firmware.h>
19#include <linux/io.h>
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/sched.h>
23#include <linux/slab.h>
24#include <linux/videodev2.h>
25
26#include "vpdma.h"
27#include "vpdma_priv.h"
28
29#define VPDMA_FIRMWARE "vpdma-1b8.bin"
30
31const struct vpdma_data_format vpdma_yuv_fmts[] = {
32 [VPDMA_DATA_FMT_Y444] = {
33 .data_type = DATA_TYPE_Y444,
34 .depth = 8,
35 },
36 [VPDMA_DATA_FMT_Y422] = {
37 .data_type = DATA_TYPE_Y422,
38 .depth = 8,
39 },
40 [VPDMA_DATA_FMT_Y420] = {
41 .data_type = DATA_TYPE_Y420,
42 .depth = 8,
43 },
44 [VPDMA_DATA_FMT_C444] = {
45 .data_type = DATA_TYPE_C444,
46 .depth = 8,
47 },
48 [VPDMA_DATA_FMT_C422] = {
49 .data_type = DATA_TYPE_C422,
50 .depth = 8,
51 },
52 [VPDMA_DATA_FMT_C420] = {
53 .data_type = DATA_TYPE_C420,
54 .depth = 4,
55 },
56 [VPDMA_DATA_FMT_YC422] = {
57 .data_type = DATA_TYPE_YC422,
58 .depth = 16,
59 },
60 [VPDMA_DATA_FMT_YC444] = {
61 .data_type = DATA_TYPE_YC444,
62 .depth = 24,
63 },
64 [VPDMA_DATA_FMT_CY422] = {
65 .data_type = DATA_TYPE_CY422,
66 .depth = 16,
67 },
68};
69
70const struct vpdma_data_format vpdma_rgb_fmts[] = {
71 [VPDMA_DATA_FMT_RGB565] = {
72 .data_type = DATA_TYPE_RGB16_565,
73 .depth = 16,
74 },
75 [VPDMA_DATA_FMT_ARGB16_1555] = {
76 .data_type = DATA_TYPE_ARGB_1555,
77 .depth = 16,
78 },
79 [VPDMA_DATA_FMT_ARGB16] = {
80 .data_type = DATA_TYPE_ARGB_4444,
81 .depth = 16,
82 },
83 [VPDMA_DATA_FMT_RGBA16_5551] = {
84 .data_type = DATA_TYPE_RGBA_5551,
85 .depth = 16,
86 },
87 [VPDMA_DATA_FMT_RGBA16] = {
88 .data_type = DATA_TYPE_RGBA_4444,
89 .depth = 16,
90 },
91 [VPDMA_DATA_FMT_ARGB24] = {
92 .data_type = DATA_TYPE_ARGB24_6666,
93 .depth = 24,
94 },
95 [VPDMA_DATA_FMT_RGB24] = {
96 .data_type = DATA_TYPE_RGB24_888,
97 .depth = 24,
98 },
99 [VPDMA_DATA_FMT_ARGB32] = {
100 .data_type = DATA_TYPE_ARGB32_8888,
101 .depth = 32,
102 },
103 [VPDMA_DATA_FMT_RGBA24] = {
104 .data_type = DATA_TYPE_RGBA24_6666,
105 .depth = 24,
106 },
107 [VPDMA_DATA_FMT_RGBA32] = {
108 .data_type = DATA_TYPE_RGBA32_8888,
109 .depth = 32,
110 },
111 [VPDMA_DATA_FMT_BGR565] = {
112 .data_type = DATA_TYPE_BGR16_565,
113 .depth = 16,
114 },
115 [VPDMA_DATA_FMT_ABGR16_1555] = {
116 .data_type = DATA_TYPE_ABGR_1555,
117 .depth = 16,
118 },
119 [VPDMA_DATA_FMT_ABGR16] = {
120 .data_type = DATA_TYPE_ABGR_4444,
121 .depth = 16,
122 },
123 [VPDMA_DATA_FMT_BGRA16_5551] = {
124 .data_type = DATA_TYPE_BGRA_5551,
125 .depth = 16,
126 },
127 [VPDMA_DATA_FMT_BGRA16] = {
128 .data_type = DATA_TYPE_BGRA_4444,
129 .depth = 16,
130 },
131 [VPDMA_DATA_FMT_ABGR24] = {
132 .data_type = DATA_TYPE_ABGR24_6666,
133 .depth = 24,
134 },
135 [VPDMA_DATA_FMT_BGR24] = {
136 .data_type = DATA_TYPE_BGR24_888,
137 .depth = 24,
138 },
139 [VPDMA_DATA_FMT_ABGR32] = {
140 .data_type = DATA_TYPE_ABGR32_8888,
141 .depth = 32,
142 },
143 [VPDMA_DATA_FMT_BGRA24] = {
144 .data_type = DATA_TYPE_BGRA24_6666,
145 .depth = 24,
146 },
147 [VPDMA_DATA_FMT_BGRA32] = {
148 .data_type = DATA_TYPE_BGRA32_8888,
149 .depth = 32,
150 },
151};
152
153const struct vpdma_data_format vpdma_misc_fmts[] = {
154 [VPDMA_DATA_FMT_MV] = {
155 .data_type = DATA_TYPE_MV,
156 .depth = 4,
157 },
158};
159
160struct vpdma_channel_info {
161 int num; /* VPDMA channel number */
162 int cstat_offset; /* client CSTAT register offset */
163};
164
165static const struct vpdma_channel_info chan_info[] = {
166 [VPE_CHAN_LUMA1_IN] = {
167 .num = VPE_CHAN_NUM_LUMA1_IN,
168 .cstat_offset = VPDMA_DEI_LUMA1_CSTAT,
169 },
170 [VPE_CHAN_CHROMA1_IN] = {
171 .num = VPE_CHAN_NUM_CHROMA1_IN,
172 .cstat_offset = VPDMA_DEI_CHROMA1_CSTAT,
173 },
174 [VPE_CHAN_LUMA2_IN] = {
175 .num = VPE_CHAN_NUM_LUMA2_IN,
176 .cstat_offset = VPDMA_DEI_LUMA2_CSTAT,
177 },
178 [VPE_CHAN_CHROMA2_IN] = {
179 .num = VPE_CHAN_NUM_CHROMA2_IN,
180 .cstat_offset = VPDMA_DEI_CHROMA2_CSTAT,
181 },
182 [VPE_CHAN_LUMA3_IN] = {
183 .num = VPE_CHAN_NUM_LUMA3_IN,
184 .cstat_offset = VPDMA_DEI_LUMA3_CSTAT,
185 },
186 [VPE_CHAN_CHROMA3_IN] = {
187 .num = VPE_CHAN_NUM_CHROMA3_IN,
188 .cstat_offset = VPDMA_DEI_CHROMA3_CSTAT,
189 },
190 [VPE_CHAN_MV_IN] = {
191 .num = VPE_CHAN_NUM_MV_IN,
192 .cstat_offset = VPDMA_DEI_MV_IN_CSTAT,
193 },
194 [VPE_CHAN_MV_OUT] = {
195 .num = VPE_CHAN_NUM_MV_OUT,
196 .cstat_offset = VPDMA_DEI_MV_OUT_CSTAT,
197 },
198 [VPE_CHAN_LUMA_OUT] = {
199 .num = VPE_CHAN_NUM_LUMA_OUT,
200 .cstat_offset = VPDMA_VIP_UP_Y_CSTAT,
201 },
202 [VPE_CHAN_CHROMA_OUT] = {
203 .num = VPE_CHAN_NUM_CHROMA_OUT,
204 .cstat_offset = VPDMA_VIP_UP_UV_CSTAT,
205 },
206 [VPE_CHAN_RGB_OUT] = {
207 .num = VPE_CHAN_NUM_RGB_OUT,
208 .cstat_offset = VPDMA_VIP_UP_Y_CSTAT,
209 },
210};
211
212static u32 read_reg(struct vpdma_data *vpdma, int offset)
213{
214 return ioread32(vpdma->base + offset);
215}
216
217static void write_reg(struct vpdma_data *vpdma, int offset, u32 value)
218{
219 iowrite32(value, vpdma->base + offset);
220}
221
222static int read_field_reg(struct vpdma_data *vpdma, int offset,
223 u32 mask, int shift)
224{
225 return (read_reg(vpdma, offset) & (mask << shift)) >> shift;
226}
227
228static void write_field_reg(struct vpdma_data *vpdma, int offset, u32 field,
229 u32 mask, int shift)
230{
231 u32 val = read_reg(vpdma, offset);
232
233 val &= ~(mask << shift);
234 val |= (field & mask) << shift;
235
236 write_reg(vpdma, offset, val);
237}
238
239void vpdma_dump_regs(struct vpdma_data *vpdma)
240{
241 struct device *dev = &vpdma->pdev->dev;
242
243#define DUMPREG(r) dev_dbg(dev, "%-35s %08x\n", #r, read_reg(vpdma, VPDMA_##r))
244
245 dev_dbg(dev, "VPDMA Registers:\n");
246
247 DUMPREG(PID);
248 DUMPREG(LIST_ADDR);
249 DUMPREG(LIST_ATTR);
250 DUMPREG(LIST_STAT_SYNC);
251 DUMPREG(BG_RGB);
252 DUMPREG(BG_YUV);
253 DUMPREG(SETUP);
254 DUMPREG(MAX_SIZE1);
255 DUMPREG(MAX_SIZE2);
256 DUMPREG(MAX_SIZE3);
257
258 /*
259 * dumping registers of only group0 and group3, because VPE channels
260 * lie within group0 and group3 registers
261 */
262 DUMPREG(INT_CHAN_STAT(0));
263 DUMPREG(INT_CHAN_MASK(0));
264 DUMPREG(INT_CHAN_STAT(3));
265 DUMPREG(INT_CHAN_MASK(3));
266 DUMPREG(INT_CLIENT0_STAT);
267 DUMPREG(INT_CLIENT0_MASK);
268 DUMPREG(INT_CLIENT1_STAT);
269 DUMPREG(INT_CLIENT1_MASK);
270 DUMPREG(INT_LIST0_STAT);
271 DUMPREG(INT_LIST0_MASK);
272
273 /*
274 * these are registers specific to VPE clients, we can make this
275 * function dump client registers specific to VPE or VIP based on
276 * who is using it
277 */
278 DUMPREG(DEI_CHROMA1_CSTAT);
279 DUMPREG(DEI_LUMA1_CSTAT);
280 DUMPREG(DEI_CHROMA2_CSTAT);
281 DUMPREG(DEI_LUMA2_CSTAT);
282 DUMPREG(DEI_CHROMA3_CSTAT);
283 DUMPREG(DEI_LUMA3_CSTAT);
284 DUMPREG(DEI_MV_IN_CSTAT);
285 DUMPREG(DEI_MV_OUT_CSTAT);
286 DUMPREG(VIP_UP_Y_CSTAT);
287 DUMPREG(VIP_UP_UV_CSTAT);
288 DUMPREG(VPI_CTL_CSTAT);
289}
290
291/*
292 * Allocate a DMA buffer
293 */
294int vpdma_alloc_desc_buf(struct vpdma_buf *buf, size_t size)
295{
296 buf->size = size;
297 buf->mapped = false;
298 buf->addr = kzalloc(size, GFP_KERNEL);
299 if (!buf->addr)
300 return -ENOMEM;
301
302 WARN_ON((u32) buf->addr & VPDMA_DESC_ALIGN);
303
304 return 0;
305}
306
307void vpdma_free_desc_buf(struct vpdma_buf *buf)
308{
309 WARN_ON(buf->mapped);
310 kfree(buf->addr);
311 buf->addr = NULL;
312 buf->size = 0;
313}
314
315/*
316 * map descriptor/payload DMA buffer, enabling DMA access
317 */
318int vpdma_map_desc_buf(struct vpdma_data *vpdma, struct vpdma_buf *buf)
319{
320 struct device *dev = &vpdma->pdev->dev;
321
322 WARN_ON(buf->mapped);
323 buf->dma_addr = dma_map_single(dev, buf->addr, buf->size,
324 DMA_TO_DEVICE);
325 if (dma_mapping_error(dev, buf->dma_addr)) {
326 dev_err(dev, "failed to map buffer\n");
327 return -EINVAL;
328 }
329
330 buf->mapped = true;
331
332 return 0;
333}
334
335/*
336 * unmap descriptor/payload DMA buffer, disabling DMA access and
337 * allowing the main processor to acces the data
338 */
339void vpdma_unmap_desc_buf(struct vpdma_data *vpdma, struct vpdma_buf *buf)
340{
341 struct device *dev = &vpdma->pdev->dev;
342
343 if (buf->mapped)
344 dma_unmap_single(dev, buf->dma_addr, buf->size, DMA_TO_DEVICE);
345
346 buf->mapped = false;
347}
348
349/*
350 * create a descriptor list, the user of this list will append configuration,
351 * control and data descriptors to this list, this list will be submitted to
352 * VPDMA. VPDMA's list parser will go through each descriptor and perform the
353 * required DMA operations
354 */
355int vpdma_create_desc_list(struct vpdma_desc_list *list, size_t size, int type)
356{
357 int r;
358
359 r = vpdma_alloc_desc_buf(&list->buf, size);
360 if (r)
361 return r;
362
363 list->next = list->buf.addr;
364
365 list->type = type;
366
367 return 0;
368}
369
370/*
371 * once a descriptor list is parsed by VPDMA, we reset the list by emptying it,
372 * to allow new descriptors to be added to the list.
373 */
374void vpdma_reset_desc_list(struct vpdma_desc_list *list)
375{
376 list->next = list->buf.addr;
377}
378
379/*
380 * free the buffer allocated fot the VPDMA descriptor list, this should be
381 * called when the user doesn't want to use VPDMA any more.
382 */
383void vpdma_free_desc_list(struct vpdma_desc_list *list)
384{
385 vpdma_free_desc_buf(&list->buf);
386
387 list->next = NULL;
388}
389
390static bool vpdma_list_busy(struct vpdma_data *vpdma, int list_num)
391{
392 return read_reg(vpdma, VPDMA_LIST_STAT_SYNC) & BIT(list_num + 16);
393}
394
395/*
396 * submit a list of DMA descriptors to the VPE VPDMA, do not wait for completion
397 */
398int vpdma_submit_descs(struct vpdma_data *vpdma, struct vpdma_desc_list *list)
399{
400 /* we always use the first list */
401 int list_num = 0;
402 int list_size;
403
404 if (vpdma_list_busy(vpdma, list_num))
405 return -EBUSY;
406
407 /* 16-byte granularity */
408 list_size = (list->next - list->buf.addr) >> 4;
409
410 write_reg(vpdma, VPDMA_LIST_ADDR, (u32) list->buf.dma_addr);
411
412 write_reg(vpdma, VPDMA_LIST_ATTR,
413 (list_num << VPDMA_LIST_NUM_SHFT) |
414 (list->type << VPDMA_LIST_TYPE_SHFT) |
415 list_size);
416
417 return 0;
418}
419
420static void dump_cfd(struct vpdma_cfd *cfd)
421{
422 int class;
423
424 class = cfd_get_class(cfd);
425
426 pr_debug("config descriptor of payload class: %s\n",
427 class == CFD_CLS_BLOCK ? "simple block" :
428 "address data block");
429
430 if (class == CFD_CLS_BLOCK)
431 pr_debug("word0: dst_addr_offset = 0x%08x\n",
432 cfd->dest_addr_offset);
433
434 if (class == CFD_CLS_BLOCK)
435 pr_debug("word1: num_data_wrds = %d\n", cfd->block_len);
436
437 pr_debug("word2: payload_addr = 0x%08x\n", cfd->payload_addr);
438
439 pr_debug("word3: pkt_type = %d, direct = %d, class = %d, dest = %d, "
440 "payload_len = %d\n", cfd_get_pkt_type(cfd),
441 cfd_get_direct(cfd), class, cfd_get_dest(cfd),
442 cfd_get_payload_len(cfd));
443}
444
445/*
446 * append a configuration descriptor to the given descriptor list, where the
447 * payload is in the form of a simple data block specified in the descriptor
448 * header, this is used to upload scaler coefficients to the scaler module
449 */
450void vpdma_add_cfd_block(struct vpdma_desc_list *list, int client,
451 struct vpdma_buf *blk, u32 dest_offset)
452{
453 struct vpdma_cfd *cfd;
454 int len = blk->size;
455
456 WARN_ON(blk->dma_addr & VPDMA_DESC_ALIGN);
457
458 cfd = list->next;
459 WARN_ON((void *)(cfd + 1) > (list->buf.addr + list->buf.size));
460
461 cfd->dest_addr_offset = dest_offset;
462 cfd->block_len = len;
463 cfd->payload_addr = (u32) blk->dma_addr;
464 cfd->ctl_payload_len = cfd_pkt_payload_len(CFD_INDIRECT, CFD_CLS_BLOCK,
465 client, len >> 4);
466
467 list->next = cfd + 1;
468
469 dump_cfd(cfd);
470}
471
472/*
473 * append a configuration descriptor to the given descriptor list, where the
474 * payload is in the address data block format, this is used to a configure a
475 * discontiguous set of MMRs
476 */
477void vpdma_add_cfd_adb(struct vpdma_desc_list *list, int client,
478 struct vpdma_buf *adb)
479{
480 struct vpdma_cfd *cfd;
481 unsigned int len = adb->size;
482
483 WARN_ON(len & VPDMA_ADB_SIZE_ALIGN);
484 WARN_ON(adb->dma_addr & VPDMA_DESC_ALIGN);
485
486 cfd = list->next;
487 BUG_ON((void *)(cfd + 1) > (list->buf.addr + list->buf.size));
488
489 cfd->w0 = 0;
490 cfd->w1 = 0;
491 cfd->payload_addr = (u32) adb->dma_addr;
492 cfd->ctl_payload_len = cfd_pkt_payload_len(CFD_INDIRECT, CFD_CLS_ADB,
493 client, len >> 4);
494
495 list->next = cfd + 1;
496
497 dump_cfd(cfd);
498};
499
500/*
501 * control descriptor format change based on what type of control descriptor it
502 * is, we only use 'sync on channel' control descriptors for now, so assume it's
503 * that
504 */
505static void dump_ctd(struct vpdma_ctd *ctd)
506{
507 pr_debug("control descriptor\n");
508
509 pr_debug("word3: pkt_type = %d, source = %d, ctl_type = %d\n",
510 ctd_get_pkt_type(ctd), ctd_get_source(ctd), ctd_get_ctl(ctd));
511}
512
513/*
514 * append a 'sync on channel' type control descriptor to the given descriptor
515 * list, this descriptor stalls the VPDMA list till the time DMA is completed
516 * on the specified channel
517 */
518void vpdma_add_sync_on_channel_ctd(struct vpdma_desc_list *list,
519 enum vpdma_channel chan)
520{
521 struct vpdma_ctd *ctd;
522
523 ctd = list->next;
524 WARN_ON((void *)(ctd + 1) > (list->buf.addr + list->buf.size));
525
526 ctd->w0 = 0;
527 ctd->w1 = 0;
528 ctd->w2 = 0;
529 ctd->type_source_ctl = ctd_type_source_ctl(chan_info[chan].num,
530 CTD_TYPE_SYNC_ON_CHANNEL);
531
532 list->next = ctd + 1;
533
534 dump_ctd(ctd);
535}
536
537static void dump_dtd(struct vpdma_dtd *dtd)
538{
539 int dir, chan;
540
541 dir = dtd_get_dir(dtd);
542 chan = dtd_get_chan(dtd);
543
544 pr_debug("%s data transfer descriptor for channel %d\n",
545 dir == DTD_DIR_OUT ? "outbound" : "inbound", chan);
546
547 pr_debug("word0: data_type = %d, notify = %d, field = %d, 1D = %d, "
548 "even_ln_skp = %d, odd_ln_skp = %d, line_stride = %d\n",
549 dtd_get_data_type(dtd), dtd_get_notify(dtd), dtd_get_field(dtd),
550 dtd_get_1d(dtd), dtd_get_even_line_skip(dtd),
551 dtd_get_odd_line_skip(dtd), dtd_get_line_stride(dtd));
552
553 if (dir == DTD_DIR_IN)
554 pr_debug("word1: line_length = %d, xfer_height = %d\n",
555 dtd_get_line_length(dtd), dtd_get_xfer_height(dtd));
556
557 pr_debug("word2: start_addr = 0x%08x\n", dtd->start_addr);
558
559 pr_debug("word3: pkt_type = %d, mode = %d, dir = %d, chan = %d, "
560 "pri = %d, next_chan = %d\n", dtd_get_pkt_type(dtd),
561 dtd_get_mode(dtd), dir, chan, dtd_get_priority(dtd),
562 dtd_get_next_chan(dtd));
563
564 if (dir == DTD_DIR_IN)
565 pr_debug("word4: frame_width = %d, frame_height = %d\n",
566 dtd_get_frame_width(dtd), dtd_get_frame_height(dtd));
567 else
568 pr_debug("word4: desc_write_addr = 0x%08x, write_desc = %d, "
569 "drp_data = %d, use_desc_reg = %d\n",
570 dtd_get_desc_write_addr(dtd), dtd_get_write_desc(dtd),
571 dtd_get_drop_data(dtd), dtd_get_use_desc(dtd));
572
573 if (dir == DTD_DIR_IN)
574 pr_debug("word5: hor_start = %d, ver_start = %d\n",
575 dtd_get_h_start(dtd), dtd_get_v_start(dtd));
576 else
577 pr_debug("word5: max_width %d, max_height %d\n",
578 dtd_get_max_width(dtd), dtd_get_max_height(dtd));
579
580 pr_debug("word6: client specfic attr0 = 0x%08x\n", dtd->client_attr0);
581 pr_debug("word7: client specfic attr1 = 0x%08x\n", dtd->client_attr1);
582}
583
584/*
585 * append an outbound data transfer descriptor to the given descriptor list,
586 * this sets up a 'client to memory' VPDMA transfer for the given VPDMA channel
587 */
588void vpdma_add_out_dtd(struct vpdma_desc_list *list, struct v4l2_rect *c_rect,
589 const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
590 enum vpdma_channel chan, u32 flags)
591{
592 int priority = 0;
593 int field = 0;
594 int notify = 1;
595 int channel, next_chan;
596 int depth = fmt->depth;
597 int stride;
598 struct vpdma_dtd *dtd;
599
600 channel = next_chan = chan_info[chan].num;
601
602 if (fmt->data_type == DATA_TYPE_C420)
603 depth = 8;
604
605 stride = (depth * c_rect->width) >> 3;
606 dma_addr += (c_rect->left * depth) >> 3;
607
608 dtd = list->next;
609 WARN_ON((void *)(dtd + 1) > (list->buf.addr + list->buf.size));
610
611 dtd->type_ctl_stride = dtd_type_ctl_stride(fmt->data_type,
612 notify,
613 field,
614 !!(flags & VPDMA_DATA_FRAME_1D),
615 !!(flags & VPDMA_DATA_EVEN_LINE_SKIP),
616 !!(flags & VPDMA_DATA_ODD_LINE_SKIP),
617 stride);
618 dtd->w1 = 0;
619 dtd->start_addr = (u32) dma_addr;
620 dtd->pkt_ctl = dtd_pkt_ctl(!!(flags & VPDMA_DATA_MODE_TILED),
621 DTD_DIR_OUT, channel, priority, next_chan);
622 dtd->desc_write_addr = dtd_desc_write_addr(0, 0, 0, 0);
623 dtd->max_width_height = dtd_max_width_height(MAX_OUT_WIDTH_1920,
624 MAX_OUT_HEIGHT_1080);
625 dtd->client_attr0 = 0;
626 dtd->client_attr1 = 0;
627
628 list->next = dtd + 1;
629
630 dump_dtd(dtd);
631}
632
633/*
634 * append an inbound data transfer descriptor to the given descriptor list,
635 * this sets up a 'memory to client' VPDMA transfer for the given VPDMA channel
636 */
637void vpdma_add_in_dtd(struct vpdma_desc_list *list, int frame_width,
638 int frame_height, struct v4l2_rect *c_rect,
639 const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
640 enum vpdma_channel chan, int field, u32 flags)
641{
642 int priority = 0;
643 int notify = 1;
644 int depth = fmt->depth;
645 int channel, next_chan;
646 int stride;
647 int height = c_rect->height;
648 struct vpdma_dtd *dtd;
649
650 channel = next_chan = chan_info[chan].num;
651
652 if (fmt->data_type == DATA_TYPE_C420) {
653 height >>= 1;
654 frame_height >>= 1;
655 depth = 8;
656 }
657
658 stride = (depth * c_rect->width) >> 3;
659 dma_addr += (c_rect->left * depth) >> 3;
660
661 dtd = list->next;
662 WARN_ON((void *)(dtd + 1) > (list->buf.addr + list->buf.size));
663
664 dtd->type_ctl_stride = dtd_type_ctl_stride(fmt->data_type,
665 notify,
666 field,
667 !!(flags & VPDMA_DATA_FRAME_1D),
668 !!(flags & VPDMA_DATA_EVEN_LINE_SKIP),
669 !!(flags & VPDMA_DATA_ODD_LINE_SKIP),
670 stride);
671
672 dtd->xfer_length_height = dtd_xfer_length_height(c_rect->width, height);
673 dtd->start_addr = (u32) dma_addr;
674 dtd->pkt_ctl = dtd_pkt_ctl(!!(flags & VPDMA_DATA_MODE_TILED),
675 DTD_DIR_IN, channel, priority, next_chan);
676 dtd->frame_width_height = dtd_frame_width_height(frame_width,
677 frame_height);
678 dtd->start_h_v = dtd_start_h_v(c_rect->left, c_rect->top);
679 dtd->client_attr0 = 0;
680 dtd->client_attr1 = 0;
681
682 list->next = dtd + 1;
683
684 dump_dtd(dtd);
685}
686
687/* set or clear the mask for list complete interrupt */
688void vpdma_enable_list_complete_irq(struct vpdma_data *vpdma, int list_num,
689 bool enable)
690{
691 u32 val;
692
693 val = read_reg(vpdma, VPDMA_INT_LIST0_MASK);
694 if (enable)
695 val |= (1 << (list_num * 2));
696 else
697 val &= ~(1 << (list_num * 2));
698 write_reg(vpdma, VPDMA_INT_LIST0_MASK, val);
699}
700
701/* clear previosuly occured list intterupts in the LIST_STAT register */
702void vpdma_clear_list_stat(struct vpdma_data *vpdma)
703{
704 write_reg(vpdma, VPDMA_INT_LIST0_STAT,
705 read_reg(vpdma, VPDMA_INT_LIST0_STAT));
706}
707
708/*
709 * configures the output mode of the line buffer for the given client, the
710 * line buffer content can either be mirrored(each line repeated twice) or
711 * passed to the client as is
712 */
713void vpdma_set_line_mode(struct vpdma_data *vpdma, int line_mode,
714 enum vpdma_channel chan)
715{
716 int client_cstat = chan_info[chan].cstat_offset;
717
718 write_field_reg(vpdma, client_cstat, line_mode,
719 VPDMA_CSTAT_LINE_MODE_MASK, VPDMA_CSTAT_LINE_MODE_SHIFT);
720}
721
722/*
723 * configures the event which should trigger VPDMA transfer for the given
724 * client
725 */
726void vpdma_set_frame_start_event(struct vpdma_data *vpdma,
727 enum vpdma_frame_start_event fs_event,
728 enum vpdma_channel chan)
729{
730 int client_cstat = chan_info[chan].cstat_offset;
731
732 write_field_reg(vpdma, client_cstat, fs_event,
733 VPDMA_CSTAT_FRAME_START_MASK, VPDMA_CSTAT_FRAME_START_SHIFT);
734}
735
736static void vpdma_firmware_cb(const struct firmware *f, void *context)
737{
738 struct vpdma_data *vpdma = context;
739 struct vpdma_buf fw_dma_buf;
740 int i, r;
741
742 dev_dbg(&vpdma->pdev->dev, "firmware callback\n");
743
744 if (!f || !f->data) {
745 dev_err(&vpdma->pdev->dev, "couldn't get firmware\n");
746 return;
747 }
748
749 /* already initialized */
750 if (read_field_reg(vpdma, VPDMA_LIST_ATTR, VPDMA_LIST_RDY_MASK,
751 VPDMA_LIST_RDY_SHFT)) {
752 vpdma->ready = true;
753 return;
754 }
755
756 r = vpdma_alloc_desc_buf(&fw_dma_buf, f->size);
757 if (r) {
758 dev_err(&vpdma->pdev->dev,
759 "failed to allocate dma buffer for firmware\n");
760 goto rel_fw;
761 }
762
763 memcpy(fw_dma_buf.addr, f->data, f->size);
764
765 vpdma_map_desc_buf(vpdma, &fw_dma_buf);
766
767 write_reg(vpdma, VPDMA_LIST_ADDR, (u32) fw_dma_buf.dma_addr);
768
769 for (i = 0; i < 100; i++) { /* max 1 second */
770 msleep_interruptible(10);
771
772 if (read_field_reg(vpdma, VPDMA_LIST_ATTR, VPDMA_LIST_RDY_MASK,
773 VPDMA_LIST_RDY_SHFT))
774 break;
775 }
776
777 if (i == 100) {
778 dev_err(&vpdma->pdev->dev, "firmware upload failed\n");
779 goto free_buf;
780 }
781
782 vpdma->ready = true;
783
784free_buf:
785 vpdma_unmap_desc_buf(vpdma, &fw_dma_buf);
786
787 vpdma_free_desc_buf(&fw_dma_buf);
788rel_fw:
789 release_firmware(f);
790}
791
792static int vpdma_load_firmware(struct vpdma_data *vpdma)
793{
794 int r;
795 struct device *dev = &vpdma->pdev->dev;
796
797 r = request_firmware_nowait(THIS_MODULE, 1,
798 (const char *) VPDMA_FIRMWARE, dev, GFP_KERNEL, vpdma,
799 vpdma_firmware_cb);
800 if (r) {
801 dev_err(dev, "firmware not available %s\n", VPDMA_FIRMWARE);
802 return r;
803 } else {
804 dev_info(dev, "loading firmware %s\n", VPDMA_FIRMWARE);
805 }
806
807 return 0;
808}
809
810struct vpdma_data *vpdma_create(struct platform_device *pdev)
811{
812 struct resource *res;
813 struct vpdma_data *vpdma;
814 int r;
815
816 dev_dbg(&pdev->dev, "vpdma_create\n");
817
818 vpdma = devm_kzalloc(&pdev->dev, sizeof(*vpdma), GFP_KERNEL);
819 if (!vpdma) {
820 dev_err(&pdev->dev, "couldn't alloc vpdma_dev\n");
821 return ERR_PTR(-ENOMEM);
822 }
823
824 vpdma->pdev = pdev;
825
826 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vpdma");
827 if (res == NULL) {
828 dev_err(&pdev->dev, "missing platform resources data\n");
829 return ERR_PTR(-ENODEV);
830 }
831
832 vpdma->base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
833 if (!vpdma->base) {
834 dev_err(&pdev->dev, "failed to ioremap\n");
835 return ERR_PTR(-ENOMEM);
836 }
837
838 r = vpdma_load_firmware(vpdma);
839 if (r) {
840 pr_err("failed to load firmware %s\n", VPDMA_FIRMWARE);
841 return ERR_PTR(r);
842 }
843
844 return vpdma;
845}
846MODULE_FIRMWARE(VPDMA_FIRMWARE);
diff --git a/drivers/media/platform/ti-vpe/vpdma.h b/drivers/media/platform/ti-vpe/vpdma.h
new file mode 100644
index 000000000000..eaa2a71a5db9
--- /dev/null
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -0,0 +1,203 @@
1/*
2 * Copyright (c) 2013 Texas Instruments Inc.
3 *
4 * David Griego, <dagriego@biglakesoftware.com>
5 * Dale Farnsworth, <dale@farnsworth.org>
6 * Archit Taneja, <archit@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
13#ifndef __TI_VPDMA_H_
14#define __TI_VPDMA_H_
15
16/*
17 * A vpdma_buf tracks the size, DMA address and mapping status of each
18 * driver DMA area.
19 */
20struct vpdma_buf {
21 void *addr;
22 dma_addr_t dma_addr;
23 size_t size;
24 bool mapped;
25};
26
27struct vpdma_desc_list {
28 struct vpdma_buf buf;
29 void *next;
30 int type;
31};
32
33struct vpdma_data {
34 void __iomem *base;
35
36 struct platform_device *pdev;
37
38 /* tells whether vpdma firmware is loaded or not */
39 bool ready;
40};
41
42struct vpdma_data_format {
43 int data_type;
44 u8 depth;
45};
46
47#define VPDMA_DESC_ALIGN 16 /* 16-byte descriptor alignment */
48
49#define VPDMA_DTD_DESC_SIZE 32 /* 8 words */
50#define VPDMA_CFD_CTD_DESC_SIZE 16 /* 4 words */
51
52#define VPDMA_LIST_TYPE_NORMAL 0
53#define VPDMA_LIST_TYPE_SELF_MODIFYING 1
54#define VPDMA_LIST_TYPE_DOORBELL 2
55
56enum vpdma_yuv_formats {
57 VPDMA_DATA_FMT_Y444 = 0,
58 VPDMA_DATA_FMT_Y422,
59 VPDMA_DATA_FMT_Y420,
60 VPDMA_DATA_FMT_C444,
61 VPDMA_DATA_FMT_C422,
62 VPDMA_DATA_FMT_C420,
63 VPDMA_DATA_FMT_YC422,
64 VPDMA_DATA_FMT_YC444,
65 VPDMA_DATA_FMT_CY422,
66};
67
68enum vpdma_rgb_formats {
69 VPDMA_DATA_FMT_RGB565 = 0,
70 VPDMA_DATA_FMT_ARGB16_1555,
71 VPDMA_DATA_FMT_ARGB16,
72 VPDMA_DATA_FMT_RGBA16_5551,
73 VPDMA_DATA_FMT_RGBA16,
74 VPDMA_DATA_FMT_ARGB24,
75 VPDMA_DATA_FMT_RGB24,
76 VPDMA_DATA_FMT_ARGB32,
77 VPDMA_DATA_FMT_RGBA24,
78 VPDMA_DATA_FMT_RGBA32,
79 VPDMA_DATA_FMT_BGR565,
80 VPDMA_DATA_FMT_ABGR16_1555,
81 VPDMA_DATA_FMT_ABGR16,
82 VPDMA_DATA_FMT_BGRA16_5551,
83 VPDMA_DATA_FMT_BGRA16,
84 VPDMA_DATA_FMT_ABGR24,
85 VPDMA_DATA_FMT_BGR24,
86 VPDMA_DATA_FMT_ABGR32,
87 VPDMA_DATA_FMT_BGRA24,
88 VPDMA_DATA_FMT_BGRA32,
89};
90
91enum vpdma_misc_formats {
92 VPDMA_DATA_FMT_MV = 0,
93};
94
95extern const struct vpdma_data_format vpdma_yuv_fmts[];
96extern const struct vpdma_data_format vpdma_rgb_fmts[];
97extern const struct vpdma_data_format vpdma_misc_fmts[];
98
99enum vpdma_frame_start_event {
100 VPDMA_FSEVENT_HDMI_FID = 0,
101 VPDMA_FSEVENT_DVO2_FID,
102 VPDMA_FSEVENT_HDCOMP_FID,
103 VPDMA_FSEVENT_SD_FID,
104 VPDMA_FSEVENT_LM_FID0,
105 VPDMA_FSEVENT_LM_FID1,
106 VPDMA_FSEVENT_LM_FID2,
107 VPDMA_FSEVENT_CHANNEL_ACTIVE,
108};
109
110/*
111 * VPDMA channel numbers
112 */
113enum vpdma_channel {
114 VPE_CHAN_LUMA1_IN,
115 VPE_CHAN_CHROMA1_IN,
116 VPE_CHAN_LUMA2_IN,
117 VPE_CHAN_CHROMA2_IN,
118 VPE_CHAN_LUMA3_IN,
119 VPE_CHAN_CHROMA3_IN,
120 VPE_CHAN_MV_IN,
121 VPE_CHAN_MV_OUT,
122 VPE_CHAN_LUMA_OUT,
123 VPE_CHAN_CHROMA_OUT,
124 VPE_CHAN_RGB_OUT,
125};
126
127/* flags for VPDMA data descriptors */
128#define VPDMA_DATA_ODD_LINE_SKIP (1 << 0)
129#define VPDMA_DATA_EVEN_LINE_SKIP (1 << 1)
130#define VPDMA_DATA_FRAME_1D (1 << 2)
131#define VPDMA_DATA_MODE_TILED (1 << 3)
132
133/*
134 * client identifiers used for configuration descriptors
135 */
136#define CFD_MMR_CLIENT 0
137#define CFD_SC_CLIENT 4
138
139/* Address data block header format */
140struct vpdma_adb_hdr {
141 u32 offset;
142 u32 nwords;
143 u32 reserved0;
144 u32 reserved1;
145};
146
147/* helpers for creating ADB headers for config descriptors MMRs as client */
148#define ADB_ADDR(dma_buf, str, fld) ((dma_buf)->addr + offsetof(str, fld))
149#define MMR_ADB_ADDR(buf, str, fld) ADB_ADDR(&(buf), struct str, fld)
150
151#define VPDMA_SET_MMR_ADB_HDR(buf, str, hdr, regs, offset_a) \
152 do { \
153 struct vpdma_adb_hdr *h; \
154 struct str *adb = NULL; \
155 h = MMR_ADB_ADDR(buf, str, hdr); \
156 h->offset = (offset_a); \
157 h->nwords = sizeof(adb->regs) >> 2; \
158 } while (0)
159
160/* vpdma descriptor buffer allocation and management */
161int vpdma_alloc_desc_buf(struct vpdma_buf *buf, size_t size);
162void vpdma_free_desc_buf(struct vpdma_buf *buf);
163int vpdma_map_desc_buf(struct vpdma_data *vpdma, struct vpdma_buf *buf);
164void vpdma_unmap_desc_buf(struct vpdma_data *vpdma, struct vpdma_buf *buf);
165
166/* vpdma descriptor list funcs */
167int vpdma_create_desc_list(struct vpdma_desc_list *list, size_t size, int type);
168void vpdma_reset_desc_list(struct vpdma_desc_list *list);
169void vpdma_free_desc_list(struct vpdma_desc_list *list);
170int vpdma_submit_descs(struct vpdma_data *vpdma, struct vpdma_desc_list *list);
171
172/* helpers for creating vpdma descriptors */
173void vpdma_add_cfd_block(struct vpdma_desc_list *list, int client,
174 struct vpdma_buf *blk, u32 dest_offset);
175void vpdma_add_cfd_adb(struct vpdma_desc_list *list, int client,
176 struct vpdma_buf *adb);
177void vpdma_add_sync_on_channel_ctd(struct vpdma_desc_list *list,
178 enum vpdma_channel chan);
179void vpdma_add_out_dtd(struct vpdma_desc_list *list, struct v4l2_rect *c_rect,
180 const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
181 enum vpdma_channel chan, u32 flags);
182void vpdma_add_in_dtd(struct vpdma_desc_list *list, int frame_width,
183 int frame_height, struct v4l2_rect *c_rect,
184 const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
185 enum vpdma_channel chan, int field, u32 flags);
186
187/* vpdma list interrupt management */
188void vpdma_enable_list_complete_irq(struct vpdma_data *vpdma, int list_num,
189 bool enable);
190void vpdma_clear_list_stat(struct vpdma_data *vpdma);
191
192/* vpdma client configuration */
193void vpdma_set_line_mode(struct vpdma_data *vpdma, int line_mode,
194 enum vpdma_channel chan);
195void vpdma_set_frame_start_event(struct vpdma_data *vpdma,
196 enum vpdma_frame_start_event fs_event, enum vpdma_channel chan);
197
198void vpdma_dump_regs(struct vpdma_data *vpdma);
199
200/* initialize vpdma, passed with VPE's platform device pointer */
201struct vpdma_data *vpdma_create(struct platform_device *pdev);
202
203#endif
diff --git a/drivers/media/platform/ti-vpe/vpdma_priv.h b/drivers/media/platform/ti-vpe/vpdma_priv.h
new file mode 100644
index 000000000000..f0e9a8038c1b
--- /dev/null
+++ b/drivers/media/platform/ti-vpe/vpdma_priv.h
@@ -0,0 +1,641 @@
1/*
2 * Copyright (c) 2013 Texas Instruments Inc.
3 *
4 * David Griego, <dagriego@biglakesoftware.com>
5 * Dale Farnsworth, <dale@farnsworth.org>
6 * Archit Taneja, <archit@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
13#ifndef _TI_VPDMA_PRIV_H_
14#define _TI_VPDMA_PRIV_H_
15
16/*
17 * VPDMA Register offsets
18 */
19
20/* Top level */
21#define VPDMA_PID 0x00
22#define VPDMA_LIST_ADDR 0x04
23#define VPDMA_LIST_ATTR 0x08
24#define VPDMA_LIST_STAT_SYNC 0x0c
25#define VPDMA_BG_RGB 0x18
26#define VPDMA_BG_YUV 0x1c
27#define VPDMA_SETUP 0x30
28#define VPDMA_MAX_SIZE1 0x34
29#define VPDMA_MAX_SIZE2 0x38
30#define VPDMA_MAX_SIZE3 0x3c
31
32/* Interrupts */
33#define VPDMA_INT_CHAN_STAT(grp) (0x40 + grp * 8)
34#define VPDMA_INT_CHAN_MASK(grp) (VPDMA_INT_CHAN_STAT(grp) + 4)
35#define VPDMA_INT_CLIENT0_STAT 0x78
36#define VPDMA_INT_CLIENT0_MASK 0x7c
37#define VPDMA_INT_CLIENT1_STAT 0x80
38#define VPDMA_INT_CLIENT1_MASK 0x84
39#define VPDMA_INT_LIST0_STAT 0x88
40#define VPDMA_INT_LIST0_MASK 0x8c
41
42#define VPDMA_PERFMON(i) (0x200 + i * 4)
43
44/* VPE specific client registers */
45#define VPDMA_DEI_CHROMA1_CSTAT 0x0300
46#define VPDMA_DEI_LUMA1_CSTAT 0x0304
47#define VPDMA_DEI_LUMA2_CSTAT 0x0308
48#define VPDMA_DEI_CHROMA2_CSTAT 0x030c
49#define VPDMA_DEI_LUMA3_CSTAT 0x0310
50#define VPDMA_DEI_CHROMA3_CSTAT 0x0314
51#define VPDMA_DEI_MV_IN_CSTAT 0x0330
52#define VPDMA_DEI_MV_OUT_CSTAT 0x033c
53#define VPDMA_VIP_UP_Y_CSTAT 0x0390
54#define VPDMA_VIP_UP_UV_CSTAT 0x0394
55#define VPDMA_VPI_CTL_CSTAT 0x03d0
56
57/* Reg field info for VPDMA_CLIENT_CSTAT registers */
58#define VPDMA_CSTAT_LINE_MODE_MASK 0x03
59#define VPDMA_CSTAT_LINE_MODE_SHIFT 8
60#define VPDMA_CSTAT_FRAME_START_MASK 0xf
61#define VPDMA_CSTAT_FRAME_START_SHIFT 10
62
63#define VPDMA_LIST_NUM_MASK 0x07
64#define VPDMA_LIST_NUM_SHFT 24
65#define VPDMA_LIST_STOP_SHFT 20
66#define VPDMA_LIST_RDY_MASK 0x01
67#define VPDMA_LIST_RDY_SHFT 19
68#define VPDMA_LIST_TYPE_MASK 0x03
69#define VPDMA_LIST_TYPE_SHFT 16
70#define VPDMA_LIST_SIZE_MASK 0xffff
71
72/* VPDMA data type values for data formats */
73#define DATA_TYPE_Y444 0x0
74#define DATA_TYPE_Y422 0x1
75#define DATA_TYPE_Y420 0x2
76#define DATA_TYPE_C444 0x4
77#define DATA_TYPE_C422 0x5
78#define DATA_TYPE_C420 0x6
79#define DATA_TYPE_YC422 0x7
80#define DATA_TYPE_YC444 0x8
81#define DATA_TYPE_CY422 0x23
82
83#define DATA_TYPE_RGB16_565 0x0
84#define DATA_TYPE_ARGB_1555 0x1
85#define DATA_TYPE_ARGB_4444 0x2
86#define DATA_TYPE_RGBA_5551 0x3
87#define DATA_TYPE_RGBA_4444 0x4
88#define DATA_TYPE_ARGB24_6666 0x5
89#define DATA_TYPE_RGB24_888 0x6
90#define DATA_TYPE_ARGB32_8888 0x7
91#define DATA_TYPE_RGBA24_6666 0x8
92#define DATA_TYPE_RGBA32_8888 0x9
93#define DATA_TYPE_BGR16_565 0x10
94#define DATA_TYPE_ABGR_1555 0x11
95#define DATA_TYPE_ABGR_4444 0x12
96#define DATA_TYPE_BGRA_5551 0x13
97#define DATA_TYPE_BGRA_4444 0x14
98#define DATA_TYPE_ABGR24_6666 0x15
99#define DATA_TYPE_BGR24_888 0x16
100#define DATA_TYPE_ABGR32_8888 0x17
101#define DATA_TYPE_BGRA24_6666 0x18
102#define DATA_TYPE_BGRA32_8888 0x19
103
104#define DATA_TYPE_MV 0x3
105
106/* VPDMA channel numbers(only VPE channels for now) */
107#define VPE_CHAN_NUM_LUMA1_IN 0
108#define VPE_CHAN_NUM_CHROMA1_IN 1
109#define VPE_CHAN_NUM_LUMA2_IN 2
110#define VPE_CHAN_NUM_CHROMA2_IN 3
111#define VPE_CHAN_NUM_LUMA3_IN 4
112#define VPE_CHAN_NUM_CHROMA3_IN 5
113#define VPE_CHAN_NUM_MV_IN 12
114#define VPE_CHAN_NUM_MV_OUT 15
115#define VPE_CHAN_NUM_LUMA_OUT 102
116#define VPE_CHAN_NUM_CHROMA_OUT 103
117#define VPE_CHAN_NUM_RGB_OUT 106
118
119/*
120 * a VPDMA address data block payload for a configuration descriptor needs to
121 * have each sub block length as a multiple of 16 bytes. Therefore, the overall
122 * size of the payload also needs to be a multiple of 16 bytes. The sub block
123 * lengths should be ensured to be aligned by the VPDMA user.
124 */
125#define VPDMA_ADB_SIZE_ALIGN 0x0f
126
127/*
128 * data transfer descriptor
129 */
130struct vpdma_dtd {
131 u32 type_ctl_stride;
132 union {
133 u32 xfer_length_height;
134 u32 w1;
135 };
136 dma_addr_t start_addr;
137 u32 pkt_ctl;
138 union {
139 u32 frame_width_height; /* inbound */
140 dma_addr_t desc_write_addr; /* outbound */
141 };
142 union {
143 u32 start_h_v; /* inbound */
144 u32 max_width_height; /* outbound */
145 };
146 u32 client_attr0;
147 u32 client_attr1;
148};
149
150/* Data Transfer Descriptor specifics */
151#define DTD_NO_NOTIFY 0
152#define DTD_NOTIFY 1
153
154#define DTD_PKT_TYPE 0xa
155#define DTD_DIR_IN 0
156#define DTD_DIR_OUT 1
157
158/* type_ctl_stride */
159#define DTD_DATA_TYPE_MASK 0x3f
160#define DTD_DATA_TYPE_SHFT 26
161#define DTD_NOTIFY_MASK 0x01
162#define DTD_NOTIFY_SHFT 25
163#define DTD_FIELD_MASK 0x01
164#define DTD_FIELD_SHFT 24
165#define DTD_1D_MASK 0x01
166#define DTD_1D_SHFT 23
167#define DTD_EVEN_LINE_SKIP_MASK 0x01
168#define DTD_EVEN_LINE_SKIP_SHFT 20
169#define DTD_ODD_LINE_SKIP_MASK 0x01
170#define DTD_ODD_LINE_SKIP_SHFT 16
171#define DTD_LINE_STRIDE_MASK 0xffff
172#define DTD_LINE_STRIDE_SHFT 0
173
174/* xfer_length_height */
175#define DTD_LINE_LENGTH_MASK 0xffff
176#define DTD_LINE_LENGTH_SHFT 16
177#define DTD_XFER_HEIGHT_MASK 0xffff
178#define DTD_XFER_HEIGHT_SHFT 0
179
180/* pkt_ctl */
181#define DTD_PKT_TYPE_MASK 0x1f
182#define DTD_PKT_TYPE_SHFT 27
183#define DTD_MODE_MASK 0x01
184#define DTD_MODE_SHFT 26
185#define DTD_DIR_MASK 0x01
186#define DTD_DIR_SHFT 25
187#define DTD_CHAN_MASK 0x01ff
188#define DTD_CHAN_SHFT 16
189#define DTD_PRI_MASK 0x0f
190#define DTD_PRI_SHFT 9
191#define DTD_NEXT_CHAN_MASK 0x01ff
192#define DTD_NEXT_CHAN_SHFT 0
193
194/* frame_width_height */
195#define DTD_FRAME_WIDTH_MASK 0xffff
196#define DTD_FRAME_WIDTH_SHFT 16
197#define DTD_FRAME_HEIGHT_MASK 0xffff
198#define DTD_FRAME_HEIGHT_SHFT 0
199
200/* start_h_v */
201#define DTD_H_START_MASK 0xffff
202#define DTD_H_START_SHFT 16
203#define DTD_V_START_MASK 0xffff
204#define DTD_V_START_SHFT 0
205
206#define DTD_DESC_START_SHIFT 5
207#define DTD_WRITE_DESC_MASK 0x01
208#define DTD_WRITE_DESC_SHIFT 2
209#define DTD_DROP_DATA_MASK 0x01
210#define DTD_DROP_DATA_SHIFT 1
211#define DTD_USE_DESC_MASK 0x01
212#define DTD_USE_DESC_SHIFT 0
213
214/* max_width_height */
215#define DTD_MAX_WIDTH_MASK 0x07
216#define DTD_MAX_WIDTH_SHFT 4
217#define DTD_MAX_HEIGHT_MASK 0x07
218#define DTD_MAX_HEIGHT_SHFT 0
219
220/* max width configurations */
221 /* unlimited width */
222#define MAX_OUT_WIDTH_UNLIMITED 0
223/* as specified in max_size1 reg */
224#define MAX_OUT_WIDTH_REG1 1
225/* as specified in max_size2 reg */
226#define MAX_OUT_WIDTH_REG2 2
227/* as specified in max_size3 reg */
228#define MAX_OUT_WIDTH_REG3 3
229/* maximum of 352 pixels as width */
230#define MAX_OUT_WIDTH_352 4
231/* maximum of 768 pixels as width */
232#define MAX_OUT_WIDTH_768 5
233/* maximum of 1280 pixels width */
234#define MAX_OUT_WIDTH_1280 6
235/* maximum of 1920 pixels as width */
236#define MAX_OUT_WIDTH_1920 7
237
238/* max height configurations */
239 /* unlimited height */
240#define MAX_OUT_HEIGHT_UNLIMITED 0
241/* as specified in max_size1 reg */
242#define MAX_OUT_HEIGHT_REG1 1
243/* as specified in max_size2 reg */
244#define MAX_OUT_HEIGHT_REG2 2
245/* as specified in max_size3 reg */
246#define MAX_OUT_HEIGHT_REG3 3
247/* maximum of 288 lines as height */
248#define MAX_OUT_HEIGHT_288 4
249/* maximum of 576 lines as height */
250#define MAX_OUT_HEIGHT_576 5
251/* maximum of 720 lines as height */
252#define MAX_OUT_HEIGHT_720 6
253/* maximum of 1080 lines as height */
254#define MAX_OUT_HEIGHT_1080 7
255
256static inline u32 dtd_type_ctl_stride(int type, bool notify, int field,
257 bool one_d, bool even_line_skip, bool odd_line_skip,
258 int line_stride)
259{
260 return (type << DTD_DATA_TYPE_SHFT) | (notify << DTD_NOTIFY_SHFT) |
261 (field << DTD_FIELD_SHFT) | (one_d << DTD_1D_SHFT) |
262 (even_line_skip << DTD_EVEN_LINE_SKIP_SHFT) |
263 (odd_line_skip << DTD_ODD_LINE_SKIP_SHFT) |
264 line_stride;
265}
266
267static inline u32 dtd_xfer_length_height(int line_length, int xfer_height)
268{
269 return (line_length << DTD_LINE_LENGTH_SHFT) | xfer_height;
270}
271
272static inline u32 dtd_pkt_ctl(bool mode, bool dir, int chan, int pri,
273 int next_chan)
274{
275 return (DTD_PKT_TYPE << DTD_PKT_TYPE_SHFT) | (mode << DTD_MODE_SHFT) |
276 (dir << DTD_DIR_SHFT) | (chan << DTD_CHAN_SHFT) |
277 (pri << DTD_PRI_SHFT) | next_chan;
278}
279
280static inline u32 dtd_frame_width_height(int width, int height)
281{
282 return (width << DTD_FRAME_WIDTH_SHFT) | height;
283}
284
285static inline u32 dtd_desc_write_addr(unsigned int addr, bool write_desc,
286 bool drop_data, bool use_desc)
287{
288 return (addr << DTD_DESC_START_SHIFT) |
289 (write_desc << DTD_WRITE_DESC_SHIFT) |
290 (drop_data << DTD_DROP_DATA_SHIFT) |
291 use_desc;
292}
293
294static inline u32 dtd_start_h_v(int h_start, int v_start)
295{
296 return (h_start << DTD_H_START_SHFT) | v_start;
297}
298
299static inline u32 dtd_max_width_height(int max_width, int max_height)
300{
301 return (max_width << DTD_MAX_WIDTH_SHFT) | max_height;
302}
303
304static inline int dtd_get_data_type(struct vpdma_dtd *dtd)
305{
306 return dtd->type_ctl_stride >> DTD_DATA_TYPE_SHFT;
307}
308
309static inline bool dtd_get_notify(struct vpdma_dtd *dtd)
310{
311 return (dtd->type_ctl_stride >> DTD_NOTIFY_SHFT) & DTD_NOTIFY_MASK;
312}
313
314static inline int dtd_get_field(struct vpdma_dtd *dtd)
315{
316 return (dtd->type_ctl_stride >> DTD_FIELD_SHFT) & DTD_FIELD_MASK;
317}
318
319static inline bool dtd_get_1d(struct vpdma_dtd *dtd)
320{
321 return (dtd->type_ctl_stride >> DTD_1D_SHFT) & DTD_1D_MASK;
322}
323
324static inline bool dtd_get_even_line_skip(struct vpdma_dtd *dtd)
325{
326 return (dtd->type_ctl_stride >> DTD_EVEN_LINE_SKIP_SHFT)
327 & DTD_EVEN_LINE_SKIP_MASK;
328}
329
330static inline bool dtd_get_odd_line_skip(struct vpdma_dtd *dtd)
331{
332 return (dtd->type_ctl_stride >> DTD_ODD_LINE_SKIP_SHFT)
333 & DTD_ODD_LINE_SKIP_MASK;
334}
335
336static inline int dtd_get_line_stride(struct vpdma_dtd *dtd)
337{
338 return dtd->type_ctl_stride & DTD_LINE_STRIDE_MASK;
339}
340
341static inline int dtd_get_line_length(struct vpdma_dtd *dtd)
342{
343 return dtd->xfer_length_height >> DTD_LINE_LENGTH_SHFT;
344}
345
346static inline int dtd_get_xfer_height(struct vpdma_dtd *dtd)
347{
348 return dtd->xfer_length_height & DTD_XFER_HEIGHT_MASK;
349}
350
351static inline int dtd_get_pkt_type(struct vpdma_dtd *dtd)
352{
353 return dtd->pkt_ctl >> DTD_PKT_TYPE_SHFT;
354}
355
356static inline bool dtd_get_mode(struct vpdma_dtd *dtd)
357{
358 return (dtd->pkt_ctl >> DTD_MODE_SHFT) & DTD_MODE_MASK;
359}
360
361static inline bool dtd_get_dir(struct vpdma_dtd *dtd)
362{
363 return (dtd->pkt_ctl >> DTD_DIR_SHFT) & DTD_DIR_MASK;
364}
365
366static inline int dtd_get_chan(struct vpdma_dtd *dtd)
367{
368 return (dtd->pkt_ctl >> DTD_CHAN_SHFT) & DTD_CHAN_MASK;
369}
370
371static inline int dtd_get_priority(struct vpdma_dtd *dtd)
372{
373 return (dtd->pkt_ctl >> DTD_PRI_SHFT) & DTD_PRI_MASK;
374}
375
376static inline int dtd_get_next_chan(struct vpdma_dtd *dtd)
377{
378 return (dtd->pkt_ctl >> DTD_NEXT_CHAN_SHFT) & DTD_NEXT_CHAN_MASK;
379}
380
381static inline int dtd_get_frame_width(struct vpdma_dtd *dtd)
382{
383 return dtd->frame_width_height >> DTD_FRAME_WIDTH_SHFT;
384}
385
386static inline int dtd_get_frame_height(struct vpdma_dtd *dtd)
387{
388 return dtd->frame_width_height & DTD_FRAME_HEIGHT_MASK;
389}
390
391static inline int dtd_get_desc_write_addr(struct vpdma_dtd *dtd)
392{
393 return dtd->desc_write_addr >> DTD_DESC_START_SHIFT;
394}
395
396static inline bool dtd_get_write_desc(struct vpdma_dtd *dtd)
397{
398 return (dtd->desc_write_addr >> DTD_WRITE_DESC_SHIFT) &
399 DTD_WRITE_DESC_MASK;
400}
401
402static inline bool dtd_get_drop_data(struct vpdma_dtd *dtd)
403{
404 return (dtd->desc_write_addr >> DTD_DROP_DATA_SHIFT) &
405 DTD_DROP_DATA_MASK;
406}
407
408static inline bool dtd_get_use_desc(struct vpdma_dtd *dtd)
409{
410 return dtd->desc_write_addr & DTD_USE_DESC_MASK;
411}
412
413static inline int dtd_get_h_start(struct vpdma_dtd *dtd)
414{
415 return dtd->start_h_v >> DTD_H_START_SHFT;
416}
417
418static inline int dtd_get_v_start(struct vpdma_dtd *dtd)
419{
420 return dtd->start_h_v & DTD_V_START_MASK;
421}
422
423static inline int dtd_get_max_width(struct vpdma_dtd *dtd)
424{
425 return (dtd->max_width_height >> DTD_MAX_WIDTH_SHFT) &
426 DTD_MAX_WIDTH_MASK;
427}
428
429static inline int dtd_get_max_height(struct vpdma_dtd *dtd)
430{
431 return (dtd->max_width_height >> DTD_MAX_HEIGHT_SHFT) &
432 DTD_MAX_HEIGHT_MASK;
433}
434
435/*
436 * configuration descriptor
437 */
438struct vpdma_cfd {
439 union {
440 u32 dest_addr_offset;
441 u32 w0;
442 };
443 union {
444 u32 block_len; /* in words */
445 u32 w1;
446 };
447 u32 payload_addr;
448 u32 ctl_payload_len; /* in words */
449};
450
451/* Configuration descriptor specifics */
452
453#define CFD_PKT_TYPE 0xb
454
455#define CFD_DIRECT 1
456#define CFD_INDIRECT 0
457#define CFD_CLS_ADB 0
458#define CFD_CLS_BLOCK 1
459
460/* block_len */
461#define CFD__BLOCK_LEN_MASK 0xffff
462#define CFD__BLOCK_LEN_SHFT 0
463
464/* ctl_payload_len */
465#define CFD_PKT_TYPE_MASK 0x1f
466#define CFD_PKT_TYPE_SHFT 27
467#define CFD_DIRECT_MASK 0x01
468#define CFD_DIRECT_SHFT 26
469#define CFD_CLASS_MASK 0x03
470#define CFD_CLASS_SHFT 24
471#define CFD_DEST_MASK 0xff
472#define CFD_DEST_SHFT 16
473#define CFD_PAYLOAD_LEN_MASK 0xffff
474#define CFD_PAYLOAD_LEN_SHFT 0
475
476static inline u32 cfd_pkt_payload_len(bool direct, int cls, int dest,
477 int payload_len)
478{
479 return (CFD_PKT_TYPE << CFD_PKT_TYPE_SHFT) |
480 (direct << CFD_DIRECT_SHFT) |
481 (cls << CFD_CLASS_SHFT) |
482 (dest << CFD_DEST_SHFT) |
483 payload_len;
484}
485
486static inline int cfd_get_pkt_type(struct vpdma_cfd *cfd)
487{
488 return cfd->ctl_payload_len >> CFD_PKT_TYPE_SHFT;
489}
490
491static inline bool cfd_get_direct(struct vpdma_cfd *cfd)
492{
493 return (cfd->ctl_payload_len >> CFD_DIRECT_SHFT) & CFD_DIRECT_MASK;
494}
495
496static inline bool cfd_get_class(struct vpdma_cfd *cfd)
497{
498 return (cfd->ctl_payload_len >> CFD_CLASS_SHFT) & CFD_CLASS_MASK;
499}
500
501static inline int cfd_get_dest(struct vpdma_cfd *cfd)
502{
503 return (cfd->ctl_payload_len >> CFD_DEST_SHFT) & CFD_DEST_MASK;
504}
505
506static inline int cfd_get_payload_len(struct vpdma_cfd *cfd)
507{
508 return cfd->ctl_payload_len & CFD_PAYLOAD_LEN_MASK;
509}
510
511/*
512 * control descriptor
513 */
514struct vpdma_ctd {
515 union {
516 u32 timer_value;
517 u32 list_addr;
518 u32 w0;
519 };
520 union {
521 u32 pixel_line_count;
522 u32 list_size;
523 u32 w1;
524 };
525 union {
526 u32 event;
527 u32 fid_ctl;
528 u32 w2;
529 };
530 u32 type_source_ctl;
531};
532
533/* control descriptor types */
534#define CTD_TYPE_SYNC_ON_CLIENT 0
535#define CTD_TYPE_SYNC_ON_LIST 1
536#define CTD_TYPE_SYNC_ON_EXT 2
537#define CTD_TYPE_SYNC_ON_LM_TIMER 3
538#define CTD_TYPE_SYNC_ON_CHANNEL 4
539#define CTD_TYPE_CHNG_CLIENT_IRQ 5
540#define CTD_TYPE_SEND_IRQ 6
541#define CTD_TYPE_RELOAD_LIST 7
542#define CTD_TYPE_ABORT_CHANNEL 8
543
544#define CTD_PKT_TYPE 0xc
545
546/* timer_value */
547#define CTD_TIMER_VALUE_MASK 0xffff
548#define CTD_TIMER_VALUE_SHFT 0
549
550/* pixel_line_count */
551#define CTD_PIXEL_COUNT_MASK 0xffff
552#define CTD_PIXEL_COUNT_SHFT 16
553#define CTD_LINE_COUNT_MASK 0xffff
554#define CTD_LINE_COUNT_SHFT 0
555
556/* list_size */
557#define CTD_LIST_SIZE_MASK 0xffff
558#define CTD_LIST_SIZE_SHFT 0
559
560/* event */
561#define CTD_EVENT_MASK 0x0f
562#define CTD_EVENT_SHFT 0
563
564/* fid_ctl */
565#define CTD_FID2_MASK 0x03
566#define CTD_FID2_SHFT 4
567#define CTD_FID1_MASK 0x03
568#define CTD_FID1_SHFT 2
569#define CTD_FID0_MASK 0x03
570#define CTD_FID0_SHFT 0
571
572/* type_source_ctl */
573#define CTD_PKT_TYPE_MASK 0x1f
574#define CTD_PKT_TYPE_SHFT 27
575#define CTD_SOURCE_MASK 0xff
576#define CTD_SOURCE_SHFT 16
577#define CTD_CONTROL_MASK 0x0f
578#define CTD_CONTROL_SHFT 0
579
580static inline u32 ctd_pixel_line_count(int pixel_count, int line_count)
581{
582 return (pixel_count << CTD_PIXEL_COUNT_SHFT) | line_count;
583}
584
585static inline u32 ctd_set_fid_ctl(int fid0, int fid1, int fid2)
586{
587 return (fid2 << CTD_FID2_SHFT) | (fid1 << CTD_FID1_SHFT) | fid0;
588}
589
590static inline u32 ctd_type_source_ctl(int source, int control)
591{
592 return (CTD_PKT_TYPE << CTD_PKT_TYPE_SHFT) |
593 (source << CTD_SOURCE_SHFT) | control;
594}
595
596static inline u32 ctd_get_pixel_count(struct vpdma_ctd *ctd)
597{
598 return ctd->pixel_line_count >> CTD_PIXEL_COUNT_SHFT;
599}
600
601static inline int ctd_get_line_count(struct vpdma_ctd *ctd)
602{
603 return ctd->pixel_line_count & CTD_LINE_COUNT_MASK;
604}
605
606static inline int ctd_get_event(struct vpdma_ctd *ctd)
607{
608 return ctd->event & CTD_EVENT_MASK;
609}
610
611static inline int ctd_get_fid2_ctl(struct vpdma_ctd *ctd)
612{
613 return (ctd->fid_ctl >> CTD_FID2_SHFT) & CTD_FID2_MASK;
614}
615
616static inline int ctd_get_fid1_ctl(struct vpdma_ctd *ctd)
617{
618 return (ctd->fid_ctl >> CTD_FID1_SHFT) & CTD_FID1_MASK;
619}
620
621static inline int ctd_get_fid0_ctl(struct vpdma_ctd *ctd)
622{
623 return ctd->fid_ctl & CTD_FID2_MASK;
624}
625
626static inline int ctd_get_pkt_type(struct vpdma_ctd *ctd)
627{
628 return ctd->type_source_ctl >> CTD_PKT_TYPE_SHFT;
629}
630
631static inline int ctd_get_source(struct vpdma_ctd *ctd)
632{
633 return (ctd->type_source_ctl >> CTD_SOURCE_SHFT) & CTD_SOURCE_MASK;
634}
635
636static inline int ctd_get_ctl(struct vpdma_ctd *ctd)
637{
638 return ctd->type_source_ctl & CTD_CONTROL_MASK;
639}
640
641#endif
diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
new file mode 100644
index 000000000000..4e58069e24ff
--- /dev/null
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -0,0 +1,2099 @@
1/*
2 * TI VPE mem2mem driver, based on the virtual v4l2-mem2mem example driver
3 *
4 * Copyright (c) 2013 Texas Instruments Inc.
5 * David Griego, <dagriego@biglakesoftware.com>
6 * Dale Farnsworth, <dale@farnsworth.org>
7 * Archit Taneja, <archit@ti.com>
8 *
9 * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
10 * Pawel Osciak, <pawel@osciak.com>
11 * Marek Szyprowski, <m.szyprowski@samsung.com>
12 *
13 * Based on the virtual v4l2-mem2mem example device
14 *
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License version 2 as published by
17 * the Free Software Foundation
18 */
19
20#include <linux/delay.h>
21#include <linux/dma-mapping.h>
22#include <linux/err.h>
23#include <linux/fs.h>
24#include <linux/interrupt.h>
25#include <linux/io.h>
26#include <linux/ioctl.h>
27#include <linux/module.h>
28#include <linux/platform_device.h>
29#include <linux/pm_runtime.h>
30#include <linux/sched.h>
31#include <linux/slab.h>
32#include <linux/videodev2.h>
33
34#include <media/v4l2-common.h>
35#include <media/v4l2-ctrls.h>
36#include <media/v4l2-device.h>
37#include <media/v4l2-event.h>
38#include <media/v4l2-ioctl.h>
39#include <media/v4l2-mem2mem.h>
40#include <media/videobuf2-core.h>
41#include <media/videobuf2-dma-contig.h>
42
43#include "vpdma.h"
44#include "vpe_regs.h"
45
46#define VPE_MODULE_NAME "vpe"
47
48/* minimum and maximum frame sizes */
49#define MIN_W 128
50#define MIN_H 128
51#define MAX_W 1920
52#define MAX_H 1080
53
54/* required alignments */
55#define S_ALIGN 0 /* multiple of 1 */
56#define H_ALIGN 1 /* multiple of 2 */
57#define W_ALIGN 1 /* multiple of 2 */
58
59/* multiple of 128 bits, line stride, 16 bytes */
60#define L_ALIGN 4
61
62/* flags that indicate a format can be used for capture/output */
63#define VPE_FMT_TYPE_CAPTURE (1 << 0)
64#define VPE_FMT_TYPE_OUTPUT (1 << 1)
65
66/* used as plane indices */
67#define VPE_MAX_PLANES 2
68#define VPE_LUMA 0
69#define VPE_CHROMA 1
70
71/* per m2m context info */
72#define VPE_MAX_SRC_BUFS 3 /* need 3 src fields to de-interlace */
73
74#define VPE_DEF_BUFS_PER_JOB 1 /* default one buffer per batch job */
75
76/*
77 * each VPE context can need up to 3 config desciptors, 7 input descriptors,
78 * 3 output descriptors, and 10 control descriptors
79 */
80#define VPE_DESC_LIST_SIZE (10 * VPDMA_DTD_DESC_SIZE + \
81 13 * VPDMA_CFD_CTD_DESC_SIZE)
82
83#define vpe_dbg(vpedev, fmt, arg...) \
84 dev_dbg((vpedev)->v4l2_dev.dev, fmt, ##arg)
85#define vpe_err(vpedev, fmt, arg...) \
86 dev_err((vpedev)->v4l2_dev.dev, fmt, ##arg)
87
88struct vpe_us_coeffs {
89 unsigned short anchor_fid0_c0;
90 unsigned short anchor_fid0_c1;
91 unsigned short anchor_fid0_c2;
92 unsigned short anchor_fid0_c3;
93 unsigned short interp_fid0_c0;
94 unsigned short interp_fid0_c1;
95 unsigned short interp_fid0_c2;
96 unsigned short interp_fid0_c3;
97 unsigned short anchor_fid1_c0;
98 unsigned short anchor_fid1_c1;
99 unsigned short anchor_fid1_c2;
100 unsigned short anchor_fid1_c3;
101 unsigned short interp_fid1_c0;
102 unsigned short interp_fid1_c1;
103 unsigned short interp_fid1_c2;
104 unsigned short interp_fid1_c3;
105};
106
107/*
108 * Default upsampler coefficients
109 */
110static const struct vpe_us_coeffs us_coeffs[] = {
111 {
112 /* Coefficients for progressive input */
113 0x00C8, 0x0348, 0x0018, 0x3FD8, 0x3FB8, 0x0378, 0x00E8, 0x3FE8,
114 0x00C8, 0x0348, 0x0018, 0x3FD8, 0x3FB8, 0x0378, 0x00E8, 0x3FE8,
115 },
116 {
117 /* Coefficients for Top Field Interlaced input */
118 0x0051, 0x03D5, 0x3FE3, 0x3FF7, 0x3FB5, 0x02E9, 0x018F, 0x3FD3,
119 /* Coefficients for Bottom Field Interlaced input */
120 0x016B, 0x0247, 0x00B1, 0x3F9D, 0x3FCF, 0x03DB, 0x005D, 0x3FF9,
121 },
122};
123
124/*
125 * the following registers are for configuring some of the parameters of the
126 * motion and edge detection blocks inside DEI, these generally remain the same,
127 * these could be passed later via userspace if some one needs to tweak these.
128 */
129struct vpe_dei_regs {
130 unsigned long mdt_spacial_freq_thr_reg; /* VPE_DEI_REG2 */
131 unsigned long edi_config_reg; /* VPE_DEI_REG3 */
132 unsigned long edi_lut_reg0; /* VPE_DEI_REG4 */
133 unsigned long edi_lut_reg1; /* VPE_DEI_REG5 */
134 unsigned long edi_lut_reg2; /* VPE_DEI_REG6 */
135 unsigned long edi_lut_reg3; /* VPE_DEI_REG7 */
136};
137
138/*
139 * default expert DEI register values, unlikely to be modified.
140 */
141static const struct vpe_dei_regs dei_regs = {
142 0x020C0804u,
143 0x0118100Fu,
144 0x08040200u,
145 0x1010100Cu,
146 0x10101010u,
147 0x10101010u,
148};
149
150/*
151 * The port_data structure contains per-port data.
152 */
153struct vpe_port_data {
154 enum vpdma_channel channel; /* VPDMA channel */
155 u8 vb_index; /* input frame f, f-1, f-2 index */
156 u8 vb_part; /* plane index for co-panar formats */
157};
158
159/*
160 * Define indices into the port_data tables
161 */
162#define VPE_PORT_LUMA1_IN 0
163#define VPE_PORT_CHROMA1_IN 1
164#define VPE_PORT_LUMA2_IN 2
165#define VPE_PORT_CHROMA2_IN 3
166#define VPE_PORT_LUMA3_IN 4
167#define VPE_PORT_CHROMA3_IN 5
168#define VPE_PORT_MV_IN 6
169#define VPE_PORT_MV_OUT 7
170#define VPE_PORT_LUMA_OUT 8
171#define VPE_PORT_CHROMA_OUT 9
172#define VPE_PORT_RGB_OUT 10
173
174static const struct vpe_port_data port_data[11] = {
175 [VPE_PORT_LUMA1_IN] = {
176 .channel = VPE_CHAN_LUMA1_IN,
177 .vb_index = 0,
178 .vb_part = VPE_LUMA,
179 },
180 [VPE_PORT_CHROMA1_IN] = {
181 .channel = VPE_CHAN_CHROMA1_IN,
182 .vb_index = 0,
183 .vb_part = VPE_CHROMA,
184 },
185 [VPE_PORT_LUMA2_IN] = {
186 .channel = VPE_CHAN_LUMA2_IN,
187 .vb_index = 1,
188 .vb_part = VPE_LUMA,
189 },
190 [VPE_PORT_CHROMA2_IN] = {
191 .channel = VPE_CHAN_CHROMA2_IN,
192 .vb_index = 1,
193 .vb_part = VPE_CHROMA,
194 },
195 [VPE_PORT_LUMA3_IN] = {
196 .channel = VPE_CHAN_LUMA3_IN,
197 .vb_index = 2,
198 .vb_part = VPE_LUMA,
199 },
200 [VPE_PORT_CHROMA3_IN] = {
201 .channel = VPE_CHAN_CHROMA3_IN,
202 .vb_index = 2,
203 .vb_part = VPE_CHROMA,
204 },
205 [VPE_PORT_MV_IN] = {
206 .channel = VPE_CHAN_MV_IN,
207 },
208 [VPE_PORT_MV_OUT] = {
209 .channel = VPE_CHAN_MV_OUT,
210 },
211 [VPE_PORT_LUMA_OUT] = {
212 .channel = VPE_CHAN_LUMA_OUT,
213 .vb_part = VPE_LUMA,
214 },
215 [VPE_PORT_CHROMA_OUT] = {
216 .channel = VPE_CHAN_CHROMA_OUT,
217 .vb_part = VPE_CHROMA,
218 },
219 [VPE_PORT_RGB_OUT] = {
220 .channel = VPE_CHAN_RGB_OUT,
221 .vb_part = VPE_LUMA,
222 },
223};
224
225
226/* driver info for each of the supported video formats */
227struct vpe_fmt {
228 char *name; /* human-readable name */
229 u32 fourcc; /* standard format identifier */
230 u8 types; /* CAPTURE and/or OUTPUT */
231 u8 coplanar; /* set for unpacked Luma and Chroma */
232 /* vpdma format info for each plane */
233 struct vpdma_data_format const *vpdma_fmt[VPE_MAX_PLANES];
234};
235
236static struct vpe_fmt vpe_formats[] = {
237 {
238 .name = "YUV 422 co-planar",
239 .fourcc = V4L2_PIX_FMT_NV16,
240 .types = VPE_FMT_TYPE_CAPTURE | VPE_FMT_TYPE_OUTPUT,
241 .coplanar = 1,
242 .vpdma_fmt = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_Y444],
243 &vpdma_yuv_fmts[VPDMA_DATA_FMT_C444],
244 },
245 },
246 {
247 .name = "YUV 420 co-planar",
248 .fourcc = V4L2_PIX_FMT_NV12,
249 .types = VPE_FMT_TYPE_CAPTURE | VPE_FMT_TYPE_OUTPUT,
250 .coplanar = 1,
251 .vpdma_fmt = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_Y420],
252 &vpdma_yuv_fmts[VPDMA_DATA_FMT_C420],
253 },
254 },
255 {
256 .name = "YUYV 422 packed",
257 .fourcc = V4L2_PIX_FMT_YUYV,
258 .types = VPE_FMT_TYPE_CAPTURE | VPE_FMT_TYPE_OUTPUT,
259 .coplanar = 0,
260 .vpdma_fmt = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_YC422],
261 },
262 },
263 {
264 .name = "UYVY 422 packed",
265 .fourcc = V4L2_PIX_FMT_UYVY,
266 .types = VPE_FMT_TYPE_CAPTURE | VPE_FMT_TYPE_OUTPUT,
267 .coplanar = 0,
268 .vpdma_fmt = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_CY422],
269 },
270 },
271};
272
273/*
274 * per-queue, driver-specific private data.
275 * there is one source queue and one destination queue for each m2m context.
276 */
277struct vpe_q_data {
278 unsigned int width; /* frame width */
279 unsigned int height; /* frame height */
280 unsigned int bytesperline[VPE_MAX_PLANES]; /* bytes per line in memory */
281 enum v4l2_colorspace colorspace;
282 enum v4l2_field field; /* supported field value */
283 unsigned int flags;
284 unsigned int sizeimage[VPE_MAX_PLANES]; /* image size in memory */
285 struct v4l2_rect c_rect; /* crop/compose rectangle */
286 struct vpe_fmt *fmt; /* format info */
287};
288
289/* vpe_q_data flag bits */
290#define Q_DATA_FRAME_1D (1 << 0)
291#define Q_DATA_MODE_TILED (1 << 1)
292#define Q_DATA_INTERLACED (1 << 2)
293
294enum {
295 Q_DATA_SRC = 0,
296 Q_DATA_DST = 1,
297};
298
299/* find our format description corresponding to the passed v4l2_format */
300static struct vpe_fmt *find_format(struct v4l2_format *f)
301{
302 struct vpe_fmt *fmt;
303 unsigned int k;
304
305 for (k = 0; k < ARRAY_SIZE(vpe_formats); k++) {
306 fmt = &vpe_formats[k];
307 if (fmt->fourcc == f->fmt.pix.pixelformat)
308 return fmt;
309 }
310
311 return NULL;
312}
313
314/*
315 * there is one vpe_dev structure in the driver, it is shared by
316 * all instances.
317 */
318struct vpe_dev {
319 struct v4l2_device v4l2_dev;
320 struct video_device vfd;
321 struct v4l2_m2m_dev *m2m_dev;
322
323 atomic_t num_instances; /* count of driver instances */
324 dma_addr_t loaded_mmrs; /* shadow mmrs in device */
325 struct mutex dev_mutex;
326 spinlock_t lock;
327
328 int irq;
329 void __iomem *base;
330
331 struct vb2_alloc_ctx *alloc_ctx;
332 struct vpdma_data *vpdma; /* vpdma data handle */
333};
334
335/*
336 * There is one vpe_ctx structure for each m2m context.
337 */
338struct vpe_ctx {
339 struct v4l2_fh fh;
340 struct vpe_dev *dev;
341 struct v4l2_m2m_ctx *m2m_ctx;
342 struct v4l2_ctrl_handler hdl;
343
344 unsigned int field; /* current field */
345 unsigned int sequence; /* current frame/field seq */
346 unsigned int aborting; /* abort after next irq */
347
348 unsigned int bufs_per_job; /* input buffers per batch */
349 unsigned int bufs_completed; /* bufs done in this batch */
350
351 struct vpe_q_data q_data[2]; /* src & dst queue data */
352 struct vb2_buffer *src_vbs[VPE_MAX_SRC_BUFS];
353 struct vb2_buffer *dst_vb;
354
355 dma_addr_t mv_buf_dma[2]; /* dma addrs of motion vector in/out bufs */
356 void *mv_buf[2]; /* virtual addrs of motion vector bufs */
357 size_t mv_buf_size; /* current motion vector buffer size */
358 struct vpdma_buf mmr_adb; /* shadow reg addr/data block */
359 struct vpdma_desc_list desc_list; /* DMA descriptor list */
360
361 bool deinterlacing; /* using de-interlacer */
362 bool load_mmrs; /* have new shadow reg values */
363
364 unsigned int src_mv_buf_selector;
365};
366
367
368/*
369 * M2M devices get 2 queues.
370 * Return the queue given the type.
371 */
372static struct vpe_q_data *get_q_data(struct vpe_ctx *ctx,
373 enum v4l2_buf_type type)
374{
375 switch (type) {
376 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
377 return &ctx->q_data[Q_DATA_SRC];
378 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
379 return &ctx->q_data[Q_DATA_DST];
380 default:
381 BUG();
382 }
383 return NULL;
384}
385
386static u32 read_reg(struct vpe_dev *dev, int offset)
387{
388 return ioread32(dev->base + offset);
389}
390
391static void write_reg(struct vpe_dev *dev, int offset, u32 value)
392{
393 iowrite32(value, dev->base + offset);
394}
395
396/* register field read/write helpers */
397static int get_field(u32 value, u32 mask, int shift)
398{
399 return (value & (mask << shift)) >> shift;
400}
401
402static int read_field_reg(struct vpe_dev *dev, int offset, u32 mask, int shift)
403{
404 return get_field(read_reg(dev, offset), mask, shift);
405}
406
407static void write_field(u32 *valp, u32 field, u32 mask, int shift)
408{
409 u32 val = *valp;
410
411 val &= ~(mask << shift);
412 val |= (field & mask) << shift;
413 *valp = val;
414}
415
416static void write_field_reg(struct vpe_dev *dev, int offset, u32 field,
417 u32 mask, int shift)
418{
419 u32 val = read_reg(dev, offset);
420
421 write_field(&val, field, mask, shift);
422
423 write_reg(dev, offset, val);
424}
425
426/*
427 * DMA address/data block for the shadow registers
428 */
429struct vpe_mmr_adb {
430 struct vpdma_adb_hdr out_fmt_hdr;
431 u32 out_fmt_reg[1];
432 u32 out_fmt_pad[3];
433 struct vpdma_adb_hdr us1_hdr;
434 u32 us1_regs[8];
435 struct vpdma_adb_hdr us2_hdr;
436 u32 us2_regs[8];
437 struct vpdma_adb_hdr us3_hdr;
438 u32 us3_regs[8];
439 struct vpdma_adb_hdr dei_hdr;
440 u32 dei_regs[8];
441 struct vpdma_adb_hdr sc_hdr;
442 u32 sc_regs[1];
443 u32 sc_pad[3];
444 struct vpdma_adb_hdr csc_hdr;
445 u32 csc_regs[6];
446 u32 csc_pad[2];
447};
448
449#define VPE_SET_MMR_ADB_HDR(ctx, hdr, regs, offset_a) \
450 VPDMA_SET_MMR_ADB_HDR(ctx->mmr_adb, vpe_mmr_adb, hdr, regs, offset_a)
451/*
452 * Set the headers for all of the address/data block structures.
453 */
454static void init_adb_hdrs(struct vpe_ctx *ctx)
455{
456 VPE_SET_MMR_ADB_HDR(ctx, out_fmt_hdr, out_fmt_reg, VPE_CLK_FORMAT_SELECT);
457 VPE_SET_MMR_ADB_HDR(ctx, us1_hdr, us1_regs, VPE_US1_R0);
458 VPE_SET_MMR_ADB_HDR(ctx, us2_hdr, us2_regs, VPE_US2_R0);
459 VPE_SET_MMR_ADB_HDR(ctx, us3_hdr, us3_regs, VPE_US3_R0);
460 VPE_SET_MMR_ADB_HDR(ctx, dei_hdr, dei_regs, VPE_DEI_FRAME_SIZE);
461 VPE_SET_MMR_ADB_HDR(ctx, sc_hdr, sc_regs, VPE_SC_MP_SC0);
462 VPE_SET_MMR_ADB_HDR(ctx, csc_hdr, csc_regs, VPE_CSC_CSC00);
463};
464
465/*
466 * Allocate or re-allocate the motion vector DMA buffers
467 * There are two buffers, one for input and one for output.
468 * However, the roles are reversed after each field is processed.
469 * In other words, after each field is processed, the previous
470 * output (dst) MV buffer becomes the new input (src) MV buffer.
471 */
472static int realloc_mv_buffers(struct vpe_ctx *ctx, size_t size)
473{
474 struct device *dev = ctx->dev->v4l2_dev.dev;
475
476 if (ctx->mv_buf_size == size)
477 return 0;
478
479 if (ctx->mv_buf[0])
480 dma_free_coherent(dev, ctx->mv_buf_size, ctx->mv_buf[0],
481 ctx->mv_buf_dma[0]);
482
483 if (ctx->mv_buf[1])
484 dma_free_coherent(dev, ctx->mv_buf_size, ctx->mv_buf[1],
485 ctx->mv_buf_dma[1]);
486
487 if (size == 0)
488 return 0;
489
490 ctx->mv_buf[0] = dma_alloc_coherent(dev, size, &ctx->mv_buf_dma[0],
491 GFP_KERNEL);
492 if (!ctx->mv_buf[0]) {
493 vpe_err(ctx->dev, "failed to allocate motion vector buffer\n");
494 return -ENOMEM;
495 }
496
497 ctx->mv_buf[1] = dma_alloc_coherent(dev, size, &ctx->mv_buf_dma[1],
498 GFP_KERNEL);
499 if (!ctx->mv_buf[1]) {
500 vpe_err(ctx->dev, "failed to allocate motion vector buffer\n");
501 dma_free_coherent(dev, size, ctx->mv_buf[0],
502 ctx->mv_buf_dma[0]);
503
504 return -ENOMEM;
505 }
506
507 ctx->mv_buf_size = size;
508 ctx->src_mv_buf_selector = 0;
509
510 return 0;
511}
512
513static void free_mv_buffers(struct vpe_ctx *ctx)
514{
515 realloc_mv_buffers(ctx, 0);
516}
517
518/*
519 * While de-interlacing, we keep the two most recent input buffers
520 * around. This function frees those two buffers when we have
521 * finished processing the current stream.
522 */
523static void free_vbs(struct vpe_ctx *ctx)
524{
525 struct vpe_dev *dev = ctx->dev;
526 unsigned long flags;
527
528 if (ctx->src_vbs[2] == NULL)
529 return;
530
531 spin_lock_irqsave(&dev->lock, flags);
532 if (ctx->src_vbs[2]) {
533 v4l2_m2m_buf_done(ctx->src_vbs[2], VB2_BUF_STATE_DONE);
534 v4l2_m2m_buf_done(ctx->src_vbs[1], VB2_BUF_STATE_DONE);
535 }
536 spin_unlock_irqrestore(&dev->lock, flags);
537}
538
539/*
540 * Enable or disable the VPE clocks
541 */
542static void vpe_set_clock_enable(struct vpe_dev *dev, bool on)
543{
544 u32 val = 0;
545
546 if (on)
547 val = VPE_DATA_PATH_CLK_ENABLE | VPE_VPEDMA_CLK_ENABLE;
548 write_reg(dev, VPE_CLK_ENABLE, val);
549}
550
551static void vpe_top_reset(struct vpe_dev *dev)
552{
553
554 write_field_reg(dev, VPE_CLK_RESET, 1, VPE_DATA_PATH_CLK_RESET_MASK,
555 VPE_DATA_PATH_CLK_RESET_SHIFT);
556
557 usleep_range(100, 150);
558
559 write_field_reg(dev, VPE_CLK_RESET, 0, VPE_DATA_PATH_CLK_RESET_MASK,
560 VPE_DATA_PATH_CLK_RESET_SHIFT);
561}
562
563static void vpe_top_vpdma_reset(struct vpe_dev *dev)
564{
565 write_field_reg(dev, VPE_CLK_RESET, 1, VPE_VPDMA_CLK_RESET_MASK,
566 VPE_VPDMA_CLK_RESET_SHIFT);
567
568 usleep_range(100, 150);
569
570 write_field_reg(dev, VPE_CLK_RESET, 0, VPE_VPDMA_CLK_RESET_MASK,
571 VPE_VPDMA_CLK_RESET_SHIFT);
572}
573
574/*
575 * Load the correct of upsampler coefficients into the shadow MMRs
576 */
577static void set_us_coefficients(struct vpe_ctx *ctx)
578{
579 struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
580 struct vpe_q_data *s_q_data = &ctx->q_data[Q_DATA_SRC];
581 u32 *us1_reg = &mmr_adb->us1_regs[0];
582 u32 *us2_reg = &mmr_adb->us2_regs[0];
583 u32 *us3_reg = &mmr_adb->us3_regs[0];
584 const unsigned short *cp, *end_cp;
585
586 cp = &us_coeffs[0].anchor_fid0_c0;
587
588 if (s_q_data->flags & Q_DATA_INTERLACED) /* interlaced */
589 cp += sizeof(us_coeffs[0]) / sizeof(*cp);
590
591 end_cp = cp + sizeof(us_coeffs[0]) / sizeof(*cp);
592
593 while (cp < end_cp) {
594 write_field(us1_reg, *cp++, VPE_US_C0_MASK, VPE_US_C0_SHIFT);
595 write_field(us1_reg, *cp++, VPE_US_C1_MASK, VPE_US_C1_SHIFT);
596 *us2_reg++ = *us1_reg;
597 *us3_reg++ = *us1_reg++;
598 }
599 ctx->load_mmrs = true;
600}
601
602/*
603 * Set the upsampler config mode and the VPDMA line mode in the shadow MMRs.
604 */
605static void set_cfg_and_line_modes(struct vpe_ctx *ctx)
606{
607 struct vpe_fmt *fmt = ctx->q_data[Q_DATA_SRC].fmt;
608 struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
609 u32 *us1_reg0 = &mmr_adb->us1_regs[0];
610 u32 *us2_reg0 = &mmr_adb->us2_regs[0];
611 u32 *us3_reg0 = &mmr_adb->us3_regs[0];
612 int line_mode = 1;
613 int cfg_mode = 1;
614
615 /*
616 * Cfg Mode 0: YUV420 source, enable upsampler, DEI is de-interlacing.
617 * Cfg Mode 1: YUV422 source, disable upsampler, DEI is de-interlacing.
618 */
619
620 if (fmt->fourcc == V4L2_PIX_FMT_NV12) {
621 cfg_mode = 0;
622 line_mode = 0; /* double lines to line buffer */
623 }
624
625 write_field(us1_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
626 write_field(us2_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
627 write_field(us3_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
628
629 /* regs for now */
630 vpdma_set_line_mode(ctx->dev->vpdma, line_mode, VPE_CHAN_CHROMA1_IN);
631 vpdma_set_line_mode(ctx->dev->vpdma, line_mode, VPE_CHAN_CHROMA2_IN);
632 vpdma_set_line_mode(ctx->dev->vpdma, line_mode, VPE_CHAN_CHROMA3_IN);
633
634 /* frame start for input luma */
635 vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
636 VPE_CHAN_LUMA1_IN);
637 vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
638 VPE_CHAN_LUMA2_IN);
639 vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
640 VPE_CHAN_LUMA3_IN);
641
642 /* frame start for input chroma */
643 vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
644 VPE_CHAN_CHROMA1_IN);
645 vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
646 VPE_CHAN_CHROMA2_IN);
647 vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
648 VPE_CHAN_CHROMA3_IN);
649
650 /* frame start for MV in client */
651 vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
652 VPE_CHAN_MV_IN);
653
654 ctx->load_mmrs = true;
655}
656
657/*
658 * Set the shadow registers that are modified when the source
659 * format changes.
660 */
661static void set_src_registers(struct vpe_ctx *ctx)
662{
663 set_us_coefficients(ctx);
664}
665
666/*
667 * Set the shadow registers that are modified when the destination
668 * format changes.
669 */
670static void set_dst_registers(struct vpe_ctx *ctx)
671{
672 struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
673 struct vpe_fmt *fmt = ctx->q_data[Q_DATA_DST].fmt;
674 u32 val = 0;
675
676 /* select RGB path when color space conversion is supported in future */
677 if (fmt->fourcc == V4L2_PIX_FMT_RGB24)
678 val |= VPE_RGB_OUT_SELECT | VPE_CSC_SRC_DEI_SCALER;
679 else if (fmt->fourcc == V4L2_PIX_FMT_NV16)
680 val |= VPE_COLOR_SEPARATE_422;
681
682 /* The source of CHR_DS is always the scaler, whether it's used or not */
683 val |= VPE_DS_SRC_DEI_SCALER;
684
685 if (fmt->fourcc != V4L2_PIX_FMT_NV12)
686 val |= VPE_DS_BYPASS;
687
688 mmr_adb->out_fmt_reg[0] = val;
689
690 ctx->load_mmrs = true;
691}
692
693/*
694 * Set the de-interlacer shadow register values
695 */
696static void set_dei_regs(struct vpe_ctx *ctx)
697{
698 struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
699 struct vpe_q_data *s_q_data = &ctx->q_data[Q_DATA_SRC];
700 unsigned int src_h = s_q_data->c_rect.height;
701 unsigned int src_w = s_q_data->c_rect.width;
702 u32 *dei_mmr0 = &mmr_adb->dei_regs[0];
703 bool deinterlace = true;
704 u32 val = 0;
705
706 /*
707 * according to TRM, we should set DEI in progressive bypass mode when
708 * the input content is progressive, however, DEI is bypassed correctly
709 * for both progressive and interlace content in interlace bypass mode.
710 * It has been recommended not to use progressive bypass mode.
711 */
712 if ((!ctx->deinterlacing && (s_q_data->flags & Q_DATA_INTERLACED)) ||
713 !(s_q_data->flags & Q_DATA_INTERLACED)) {
714 deinterlace = false;
715 val = VPE_DEI_INTERLACE_BYPASS;
716 }
717
718 src_h = deinterlace ? src_h * 2 : src_h;
719
720 val |= (src_h << VPE_DEI_HEIGHT_SHIFT) |
721 (src_w << VPE_DEI_WIDTH_SHIFT) |
722 VPE_DEI_FIELD_FLUSH;
723
724 *dei_mmr0 = val;
725
726 ctx->load_mmrs = true;
727}
728
729static void set_dei_shadow_registers(struct vpe_ctx *ctx)
730{
731 struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
732 u32 *dei_mmr = &mmr_adb->dei_regs[0];
733 const struct vpe_dei_regs *cur = &dei_regs;
734
735 dei_mmr[2] = cur->mdt_spacial_freq_thr_reg;
736 dei_mmr[3] = cur->edi_config_reg;
737 dei_mmr[4] = cur->edi_lut_reg0;
738 dei_mmr[5] = cur->edi_lut_reg1;
739 dei_mmr[6] = cur->edi_lut_reg2;
740 dei_mmr[7] = cur->edi_lut_reg3;
741
742 ctx->load_mmrs = true;
743}
744
745static void set_csc_coeff_bypass(struct vpe_ctx *ctx)
746{
747 struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
748 u32 *shadow_csc_reg5 = &mmr_adb->csc_regs[5];
749
750 *shadow_csc_reg5 |= VPE_CSC_BYPASS;
751
752 ctx->load_mmrs = true;
753}
754
755static void set_sc_regs_bypass(struct vpe_ctx *ctx)
756{
757 struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
758 u32 *sc_reg0 = &mmr_adb->sc_regs[0];
759 u32 val = 0;
760
761 val |= VPE_SC_BYPASS;
762 *sc_reg0 = val;
763
764 ctx->load_mmrs = true;
765}
766
767/*
768 * Set the shadow registers whose values are modified when either the
769 * source or destination format is changed.
770 */
771static int set_srcdst_params(struct vpe_ctx *ctx)
772{
773 struct vpe_q_data *s_q_data = &ctx->q_data[Q_DATA_SRC];
774 struct vpe_q_data *d_q_data = &ctx->q_data[Q_DATA_DST];
775 size_t mv_buf_size;
776 int ret;
777
778 ctx->sequence = 0;
779 ctx->field = V4L2_FIELD_TOP;
780
781 if ((s_q_data->flags & Q_DATA_INTERLACED) &&
782 !(d_q_data->flags & Q_DATA_INTERLACED)) {
783 const struct vpdma_data_format *mv =
784 &vpdma_misc_fmts[VPDMA_DATA_FMT_MV];
785
786 ctx->deinterlacing = 1;
787 mv_buf_size =
788 (s_q_data->width * s_q_data->height * mv->depth) >> 3;
789 } else {
790 ctx->deinterlacing = 0;
791 mv_buf_size = 0;
792 }
793
794 free_vbs(ctx);
795
796 ret = realloc_mv_buffers(ctx, mv_buf_size);
797 if (ret)
798 return ret;
799
800 set_cfg_and_line_modes(ctx);
801 set_dei_regs(ctx);
802 set_csc_coeff_bypass(ctx);
803 set_sc_regs_bypass(ctx);
804
805 return 0;
806}
807
808/*
809 * Return the vpe_ctx structure for a given struct file
810 */
811static struct vpe_ctx *file2ctx(struct file *file)
812{
813 return container_of(file->private_data, struct vpe_ctx, fh);
814}
815
816/*
817 * mem2mem callbacks
818 */
819
820/**
821 * job_ready() - check whether an instance is ready to be scheduled to run
822 */
823static int job_ready(void *priv)
824{
825 struct vpe_ctx *ctx = priv;
826 int needed = ctx->bufs_per_job;
827
828 if (ctx->deinterlacing && ctx->src_vbs[2] == NULL)
829 needed += 2; /* need additional two most recent fields */
830
831 if (v4l2_m2m_num_src_bufs_ready(ctx->m2m_ctx) < needed)
832 return 0;
833
834 return 1;
835}
836
837static void job_abort(void *priv)
838{
839 struct vpe_ctx *ctx = priv;
840
841 /* Will cancel the transaction in the next interrupt handler */
842 ctx->aborting = 1;
843}
844
845/*
846 * Lock access to the device
847 */
848static void vpe_lock(void *priv)
849{
850 struct vpe_ctx *ctx = priv;
851 struct vpe_dev *dev = ctx->dev;
852 mutex_lock(&dev->dev_mutex);
853}
854
855static void vpe_unlock(void *priv)
856{
857 struct vpe_ctx *ctx = priv;
858 struct vpe_dev *dev = ctx->dev;
859 mutex_unlock(&dev->dev_mutex);
860}
861
862static void vpe_dump_regs(struct vpe_dev *dev)
863{
864#define DUMPREG(r) vpe_dbg(dev, "%-35s %08x\n", #r, read_reg(dev, VPE_##r))
865
866 vpe_dbg(dev, "VPE Registers:\n");
867
868 DUMPREG(PID);
869 DUMPREG(SYSCONFIG);
870 DUMPREG(INT0_STATUS0_RAW);
871 DUMPREG(INT0_STATUS0);
872 DUMPREG(INT0_ENABLE0);
873 DUMPREG(INT0_STATUS1_RAW);
874 DUMPREG(INT0_STATUS1);
875 DUMPREG(INT0_ENABLE1);
876 DUMPREG(CLK_ENABLE);
877 DUMPREG(CLK_RESET);
878 DUMPREG(CLK_FORMAT_SELECT);
879 DUMPREG(CLK_RANGE_MAP);
880 DUMPREG(US1_R0);
881 DUMPREG(US1_R1);
882 DUMPREG(US1_R2);
883 DUMPREG(US1_R3);
884 DUMPREG(US1_R4);
885 DUMPREG(US1_R5);
886 DUMPREG(US1_R6);
887 DUMPREG(US1_R7);
888 DUMPREG(US2_R0);
889 DUMPREG(US2_R1);
890 DUMPREG(US2_R2);
891 DUMPREG(US2_R3);
892 DUMPREG(US2_R4);
893 DUMPREG(US2_R5);
894 DUMPREG(US2_R6);
895 DUMPREG(US2_R7);
896 DUMPREG(US3_R0);
897 DUMPREG(US3_R1);
898 DUMPREG(US3_R2);
899 DUMPREG(US3_R3);
900 DUMPREG(US3_R4);
901 DUMPREG(US3_R5);
902 DUMPREG(US3_R6);
903 DUMPREG(US3_R7);
904 DUMPREG(DEI_FRAME_SIZE);
905 DUMPREG(MDT_BYPASS);
906 DUMPREG(MDT_SF_THRESHOLD);
907 DUMPREG(EDI_CONFIG);
908 DUMPREG(DEI_EDI_LUT_R0);
909 DUMPREG(DEI_EDI_LUT_R1);
910 DUMPREG(DEI_EDI_LUT_R2);
911 DUMPREG(DEI_EDI_LUT_R3);
912 DUMPREG(DEI_FMD_WINDOW_R0);
913 DUMPREG(DEI_FMD_WINDOW_R1);
914 DUMPREG(DEI_FMD_CONTROL_R0);
915 DUMPREG(DEI_FMD_CONTROL_R1);
916 DUMPREG(DEI_FMD_STATUS_R0);
917 DUMPREG(DEI_FMD_STATUS_R1);
918 DUMPREG(DEI_FMD_STATUS_R2);
919 DUMPREG(SC_MP_SC0);
920 DUMPREG(SC_MP_SC1);
921 DUMPREG(SC_MP_SC2);
922 DUMPREG(SC_MP_SC3);
923 DUMPREG(SC_MP_SC4);
924 DUMPREG(SC_MP_SC5);
925 DUMPREG(SC_MP_SC6);
926 DUMPREG(SC_MP_SC8);
927 DUMPREG(SC_MP_SC9);
928 DUMPREG(SC_MP_SC10);
929 DUMPREG(SC_MP_SC11);
930 DUMPREG(SC_MP_SC12);
931 DUMPREG(SC_MP_SC13);
932 DUMPREG(SC_MP_SC17);
933 DUMPREG(SC_MP_SC18);
934 DUMPREG(SC_MP_SC19);
935 DUMPREG(SC_MP_SC20);
936 DUMPREG(SC_MP_SC21);
937 DUMPREG(SC_MP_SC22);
938 DUMPREG(SC_MP_SC23);
939 DUMPREG(SC_MP_SC24);
940 DUMPREG(SC_MP_SC25);
941 DUMPREG(CSC_CSC00);
942 DUMPREG(CSC_CSC01);
943 DUMPREG(CSC_CSC02);
944 DUMPREG(CSC_CSC03);
945 DUMPREG(CSC_CSC04);
946 DUMPREG(CSC_CSC05);
947#undef DUMPREG
948}
949
950static void add_out_dtd(struct vpe_ctx *ctx, int port)
951{
952 struct vpe_q_data *q_data = &ctx->q_data[Q_DATA_DST];
953 const struct vpe_port_data *p_data = &port_data[port];
954 struct vb2_buffer *vb = ctx->dst_vb;
955 struct v4l2_rect *c_rect = &q_data->c_rect;
956 struct vpe_fmt *fmt = q_data->fmt;
957 const struct vpdma_data_format *vpdma_fmt;
958 int mv_buf_selector = !ctx->src_mv_buf_selector;
959 dma_addr_t dma_addr;
960 u32 flags = 0;
961
962 if (port == VPE_PORT_MV_OUT) {
963 vpdma_fmt = &vpdma_misc_fmts[VPDMA_DATA_FMT_MV];
964 dma_addr = ctx->mv_buf_dma[mv_buf_selector];
965 } else {
966 /* to incorporate interleaved formats */
967 int plane = fmt->coplanar ? p_data->vb_part : 0;
968
969 vpdma_fmt = fmt->vpdma_fmt[plane];
970 dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
971 if (!dma_addr) {
972 vpe_err(ctx->dev,
973 "acquiring output buffer(%d) dma_addr failed\n",
974 port);
975 return;
976 }
977 }
978
979 if (q_data->flags & Q_DATA_FRAME_1D)
980 flags |= VPDMA_DATA_FRAME_1D;
981 if (q_data->flags & Q_DATA_MODE_TILED)
982 flags |= VPDMA_DATA_MODE_TILED;
983
984 vpdma_add_out_dtd(&ctx->desc_list, c_rect, vpdma_fmt, dma_addr,
985 p_data->channel, flags);
986}
987
988static void add_in_dtd(struct vpe_ctx *ctx, int port)
989{
990 struct vpe_q_data *q_data = &ctx->q_data[Q_DATA_SRC];
991 const struct vpe_port_data *p_data = &port_data[port];
992 struct vb2_buffer *vb = ctx->src_vbs[p_data->vb_index];
993 struct v4l2_rect *c_rect = &q_data->c_rect;
994 struct vpe_fmt *fmt = q_data->fmt;
995 const struct vpdma_data_format *vpdma_fmt;
996 int mv_buf_selector = ctx->src_mv_buf_selector;
997 int field = vb->v4l2_buf.field == V4L2_FIELD_BOTTOM;
998 dma_addr_t dma_addr;
999 u32 flags = 0;
1000
1001 if (port == VPE_PORT_MV_IN) {
1002 vpdma_fmt = &vpdma_misc_fmts[VPDMA_DATA_FMT_MV];
1003 dma_addr = ctx->mv_buf_dma[mv_buf_selector];
1004 } else {
1005 /* to incorporate interleaved formats */
1006 int plane = fmt->coplanar ? p_data->vb_part : 0;
1007
1008 vpdma_fmt = fmt->vpdma_fmt[plane];
1009
1010 dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
1011 if (!dma_addr) {
1012 vpe_err(ctx->dev,
1013 "acquiring input buffer(%d) dma_addr failed\n",
1014 port);
1015 return;
1016 }
1017 }
1018
1019 if (q_data->flags & Q_DATA_FRAME_1D)
1020 flags |= VPDMA_DATA_FRAME_1D;
1021 if (q_data->flags & Q_DATA_MODE_TILED)
1022 flags |= VPDMA_DATA_MODE_TILED;
1023
1024 vpdma_add_in_dtd(&ctx->desc_list, q_data->width, q_data->height,
1025 c_rect, vpdma_fmt, dma_addr, p_data->channel, field, flags);
1026}
1027
1028/*
1029 * Enable the expected IRQ sources
1030 */
1031static void enable_irqs(struct vpe_ctx *ctx)
1032{
1033 write_reg(ctx->dev, VPE_INT0_ENABLE0_SET, VPE_INT0_LIST0_COMPLETE);
1034 write_reg(ctx->dev, VPE_INT0_ENABLE1_SET, VPE_DEI_ERROR_INT |
1035 VPE_DS1_UV_ERROR_INT);
1036
1037 vpdma_enable_list_complete_irq(ctx->dev->vpdma, 0, true);
1038}
1039
1040static void disable_irqs(struct vpe_ctx *ctx)
1041{
1042 write_reg(ctx->dev, VPE_INT0_ENABLE0_CLR, 0xffffffff);
1043 write_reg(ctx->dev, VPE_INT0_ENABLE1_CLR, 0xffffffff);
1044
1045 vpdma_enable_list_complete_irq(ctx->dev->vpdma, 0, false);
1046}
1047
1048/* device_run() - prepares and starts the device
1049 *
1050 * This function is only called when both the source and destination
1051 * buffers are in place.
1052 */
1053static void device_run(void *priv)
1054{
1055 struct vpe_ctx *ctx = priv;
1056 struct vpe_q_data *d_q_data = &ctx->q_data[Q_DATA_DST];
1057
1058 if (ctx->deinterlacing && ctx->src_vbs[2] == NULL) {
1059 ctx->src_vbs[2] = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
1060 WARN_ON(ctx->src_vbs[2] == NULL);
1061 ctx->src_vbs[1] = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
1062 WARN_ON(ctx->src_vbs[1] == NULL);
1063 }
1064
1065 ctx->src_vbs[0] = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
1066 WARN_ON(ctx->src_vbs[0] == NULL);
1067 ctx->dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
1068 WARN_ON(ctx->dst_vb == NULL);
1069
1070 /* config descriptors */
1071 if (ctx->dev->loaded_mmrs != ctx->mmr_adb.dma_addr || ctx->load_mmrs) {
1072 vpdma_map_desc_buf(ctx->dev->vpdma, &ctx->mmr_adb);
1073 vpdma_add_cfd_adb(&ctx->desc_list, CFD_MMR_CLIENT, &ctx->mmr_adb);
1074 ctx->dev->loaded_mmrs = ctx->mmr_adb.dma_addr;
1075 ctx->load_mmrs = false;
1076 }
1077
1078 /* output data descriptors */
1079 if (ctx->deinterlacing)
1080 add_out_dtd(ctx, VPE_PORT_MV_OUT);
1081
1082 add_out_dtd(ctx, VPE_PORT_LUMA_OUT);
1083 if (d_q_data->fmt->coplanar)
1084 add_out_dtd(ctx, VPE_PORT_CHROMA_OUT);
1085
1086 /* input data descriptors */
1087 if (ctx->deinterlacing) {
1088 add_in_dtd(ctx, VPE_PORT_LUMA3_IN);
1089 add_in_dtd(ctx, VPE_PORT_CHROMA3_IN);
1090
1091 add_in_dtd(ctx, VPE_PORT_LUMA2_IN);
1092 add_in_dtd(ctx, VPE_PORT_CHROMA2_IN);
1093 }
1094
1095 add_in_dtd(ctx, VPE_PORT_LUMA1_IN);
1096 add_in_dtd(ctx, VPE_PORT_CHROMA1_IN);
1097
1098 if (ctx->deinterlacing)
1099 add_in_dtd(ctx, VPE_PORT_MV_IN);
1100
1101 /* sync on channel control descriptors for input ports */
1102 vpdma_add_sync_on_channel_ctd(&ctx->desc_list, VPE_CHAN_LUMA1_IN);
1103 vpdma_add_sync_on_channel_ctd(&ctx->desc_list, VPE_CHAN_CHROMA1_IN);
1104
1105 if (ctx->deinterlacing) {
1106 vpdma_add_sync_on_channel_ctd(&ctx->desc_list,
1107 VPE_CHAN_LUMA2_IN);
1108 vpdma_add_sync_on_channel_ctd(&ctx->desc_list,
1109 VPE_CHAN_CHROMA2_IN);
1110
1111 vpdma_add_sync_on_channel_ctd(&ctx->desc_list,
1112 VPE_CHAN_LUMA3_IN);
1113 vpdma_add_sync_on_channel_ctd(&ctx->desc_list,
1114 VPE_CHAN_CHROMA3_IN);
1115
1116 vpdma_add_sync_on_channel_ctd(&ctx->desc_list, VPE_CHAN_MV_IN);
1117 }
1118
1119 /* sync on channel control descriptors for output ports */
1120 vpdma_add_sync_on_channel_ctd(&ctx->desc_list, VPE_CHAN_LUMA_OUT);
1121 if (d_q_data->fmt->coplanar)
1122 vpdma_add_sync_on_channel_ctd(&ctx->desc_list, VPE_CHAN_CHROMA_OUT);
1123
1124 if (ctx->deinterlacing)
1125 vpdma_add_sync_on_channel_ctd(&ctx->desc_list, VPE_CHAN_MV_OUT);
1126
1127 enable_irqs(ctx);
1128
1129 vpdma_map_desc_buf(ctx->dev->vpdma, &ctx->desc_list.buf);
1130 vpdma_submit_descs(ctx->dev->vpdma, &ctx->desc_list);
1131}
1132
1133static void dei_error(struct vpe_ctx *ctx)
1134{
1135 dev_warn(ctx->dev->v4l2_dev.dev,
1136 "received DEI error interrupt\n");
1137}
1138
1139static void ds1_uv_error(struct vpe_ctx *ctx)
1140{
1141 dev_warn(ctx->dev->v4l2_dev.dev,
1142 "received downsampler error interrupt\n");
1143}
1144
1145static irqreturn_t vpe_irq(int irq_vpe, void *data)
1146{
1147 struct vpe_dev *dev = (struct vpe_dev *)data;
1148 struct vpe_ctx *ctx;
1149 struct vpe_q_data *d_q_data;
1150 struct vb2_buffer *s_vb, *d_vb;
1151 struct v4l2_buffer *s_buf, *d_buf;
1152 unsigned long flags;
1153 u32 irqst0, irqst1;
1154
1155 irqst0 = read_reg(dev, VPE_INT0_STATUS0);
1156 if (irqst0) {
1157 write_reg(dev, VPE_INT0_STATUS0_CLR, irqst0);
1158 vpe_dbg(dev, "INT0_STATUS0 = 0x%08x\n", irqst0);
1159 }
1160
1161 irqst1 = read_reg(dev, VPE_INT0_STATUS1);
1162 if (irqst1) {
1163 write_reg(dev, VPE_INT0_STATUS1_CLR, irqst1);
1164 vpe_dbg(dev, "INT0_STATUS1 = 0x%08x\n", irqst1);
1165 }
1166
1167 ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev);
1168 if (!ctx) {
1169 vpe_err(dev, "instance released before end of transaction\n");
1170 goto handled;
1171 }
1172
1173 if (irqst1) {
1174 if (irqst1 & VPE_DEI_ERROR_INT) {
1175 irqst1 &= ~VPE_DEI_ERROR_INT;
1176 dei_error(ctx);
1177 }
1178 if (irqst1 & VPE_DS1_UV_ERROR_INT) {
1179 irqst1 &= ~VPE_DS1_UV_ERROR_INT;
1180 ds1_uv_error(ctx);
1181 }
1182 }
1183
1184 if (irqst0) {
1185 if (irqst0 & VPE_INT0_LIST0_COMPLETE)
1186 vpdma_clear_list_stat(ctx->dev->vpdma);
1187
1188 irqst0 &= ~(VPE_INT0_LIST0_COMPLETE);
1189 }
1190
1191 if (irqst0 | irqst1) {
1192 dev_warn(dev->v4l2_dev.dev, "Unexpected interrupt: "
1193 "INT0_STATUS0 = 0x%08x, INT0_STATUS1 = 0x%08x\n",
1194 irqst0, irqst1);
1195 }
1196
1197 disable_irqs(ctx);
1198
1199 vpdma_unmap_desc_buf(dev->vpdma, &ctx->desc_list.buf);
1200 vpdma_unmap_desc_buf(dev->vpdma, &ctx->mmr_adb);
1201
1202 vpdma_reset_desc_list(&ctx->desc_list);
1203
1204 /* the previous dst mv buffer becomes the next src mv buffer */
1205 ctx->src_mv_buf_selector = !ctx->src_mv_buf_selector;
1206
1207 if (ctx->aborting)
1208 goto finished;
1209
1210 s_vb = ctx->src_vbs[0];
1211 d_vb = ctx->dst_vb;
1212 s_buf = &s_vb->v4l2_buf;
1213 d_buf = &d_vb->v4l2_buf;
1214
1215 d_buf->timestamp = s_buf->timestamp;
1216 if (s_buf->flags & V4L2_BUF_FLAG_TIMECODE) {
1217 d_buf->flags |= V4L2_BUF_FLAG_TIMECODE;
1218 d_buf->timecode = s_buf->timecode;
1219 }
1220 d_buf->sequence = ctx->sequence;
1221 d_buf->field = ctx->field;
1222
1223 d_q_data = &ctx->q_data[Q_DATA_DST];
1224 if (d_q_data->flags & Q_DATA_INTERLACED) {
1225 if (ctx->field == V4L2_FIELD_BOTTOM) {
1226 ctx->sequence++;
1227 ctx->field = V4L2_FIELD_TOP;
1228 } else {
1229 WARN_ON(ctx->field != V4L2_FIELD_TOP);
1230 ctx->field = V4L2_FIELD_BOTTOM;
1231 }
1232 } else {
1233 ctx->sequence++;
1234 }
1235
1236 if (ctx->deinterlacing)
1237 s_vb = ctx->src_vbs[2];
1238
1239 spin_lock_irqsave(&dev->lock, flags);
1240 v4l2_m2m_buf_done(s_vb, VB2_BUF_STATE_DONE);
1241 v4l2_m2m_buf_done(d_vb, VB2_BUF_STATE_DONE);
1242 spin_unlock_irqrestore(&dev->lock, flags);
1243
1244 if (ctx->deinterlacing) {
1245 ctx->src_vbs[2] = ctx->src_vbs[1];
1246 ctx->src_vbs[1] = ctx->src_vbs[0];
1247 }
1248
1249 ctx->bufs_completed++;
1250 if (ctx->bufs_completed < ctx->bufs_per_job) {
1251 device_run(ctx);
1252 goto handled;
1253 }
1254
1255finished:
1256 vpe_dbg(ctx->dev, "finishing transaction\n");
1257 ctx->bufs_completed = 0;
1258 v4l2_m2m_job_finish(dev->m2m_dev, ctx->m2m_ctx);
1259handled:
1260 return IRQ_HANDLED;
1261}
1262
1263/*
1264 * video ioctls
1265 */
1266static int vpe_querycap(struct file *file, void *priv,
1267 struct v4l2_capability *cap)
1268{
1269 strncpy(cap->driver, VPE_MODULE_NAME, sizeof(cap->driver) - 1);
1270 strncpy(cap->card, VPE_MODULE_NAME, sizeof(cap->card) - 1);
1271 strlcpy(cap->bus_info, VPE_MODULE_NAME, sizeof(cap->bus_info));
1272 cap->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING;
1273 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
1274 return 0;
1275}
1276
1277static int __enum_fmt(struct v4l2_fmtdesc *f, u32 type)
1278{
1279 int i, index;
1280 struct vpe_fmt *fmt = NULL;
1281
1282 index = 0;
1283 for (i = 0; i < ARRAY_SIZE(vpe_formats); ++i) {
1284 if (vpe_formats[i].types & type) {
1285 if (index == f->index) {
1286 fmt = &vpe_formats[i];
1287 break;
1288 }
1289 index++;
1290 }
1291 }
1292
1293 if (!fmt)
1294 return -EINVAL;
1295
1296 strncpy(f->description, fmt->name, sizeof(f->description) - 1);
1297 f->pixelformat = fmt->fourcc;
1298 return 0;
1299}
1300
1301static int vpe_enum_fmt(struct file *file, void *priv,
1302 struct v4l2_fmtdesc *f)
1303{
1304 if (V4L2_TYPE_IS_OUTPUT(f->type))
1305 return __enum_fmt(f, VPE_FMT_TYPE_OUTPUT);
1306
1307 return __enum_fmt(f, VPE_FMT_TYPE_CAPTURE);
1308}
1309
1310static int vpe_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
1311{
1312 struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
1313 struct vpe_ctx *ctx = file2ctx(file);
1314 struct vb2_queue *vq;
1315 struct vpe_q_data *q_data;
1316 int i;
1317
1318 vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
1319 if (!vq)
1320 return -EINVAL;
1321
1322 q_data = get_q_data(ctx, f->type);
1323
1324 pix->width = q_data->width;
1325 pix->height = q_data->height;
1326 pix->pixelformat = q_data->fmt->fourcc;
1327 pix->field = q_data->field;
1328
1329 if (V4L2_TYPE_IS_OUTPUT(f->type)) {
1330 pix->colorspace = q_data->colorspace;
1331 } else {
1332 struct vpe_q_data *s_q_data;
1333
1334 /* get colorspace from the source queue */
1335 s_q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
1336
1337 pix->colorspace = s_q_data->colorspace;
1338 }
1339
1340 pix->num_planes = q_data->fmt->coplanar ? 2 : 1;
1341
1342 for (i = 0; i < pix->num_planes; i++) {
1343 pix->plane_fmt[i].bytesperline = q_data->bytesperline[i];
1344 pix->plane_fmt[i].sizeimage = q_data->sizeimage[i];
1345 }
1346
1347 return 0;
1348}
1349
1350static int __vpe_try_fmt(struct vpe_ctx *ctx, struct v4l2_format *f,
1351 struct vpe_fmt *fmt, int type)
1352{
1353 struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
1354 struct v4l2_plane_pix_format *plane_fmt;
1355 int i;
1356
1357 if (!fmt || !(fmt->types & type)) {
1358 vpe_err(ctx->dev, "Fourcc format (0x%08x) invalid.\n",
1359 pix->pixelformat);
1360 return -EINVAL;
1361 }
1362
1363 if (pix->field != V4L2_FIELD_NONE && pix->field != V4L2_FIELD_ALTERNATE)
1364 pix->field = V4L2_FIELD_NONE;
1365
1366 v4l_bound_align_image(&pix->width, MIN_W, MAX_W, W_ALIGN,
1367 &pix->height, MIN_H, MAX_H, H_ALIGN,
1368 S_ALIGN);
1369
1370 pix->num_planes = fmt->coplanar ? 2 : 1;
1371 pix->pixelformat = fmt->fourcc;
1372
1373 if (type == VPE_FMT_TYPE_CAPTURE) {
1374 struct vpe_q_data *s_q_data;
1375
1376 /* get colorspace from the source queue */
1377 s_q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
1378
1379 pix->colorspace = s_q_data->colorspace;
1380 } else {
1381 if (!pix->colorspace)
1382 pix->colorspace = V4L2_COLORSPACE_SMPTE240M;
1383 }
1384
1385 for (i = 0; i < pix->num_planes; i++) {
1386 int depth;
1387
1388 plane_fmt = &pix->plane_fmt[i];
1389 depth = fmt->vpdma_fmt[i]->depth;
1390
1391 if (i == VPE_LUMA)
1392 plane_fmt->bytesperline =
1393 round_up((pix->width * depth) >> 3,
1394 1 << L_ALIGN);
1395 else
1396 plane_fmt->bytesperline = pix->width;
1397
1398 plane_fmt->sizeimage =
1399 (pix->height * pix->width * depth) >> 3;
1400 }
1401
1402 return 0;
1403}
1404
1405static int vpe_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
1406{
1407 struct vpe_ctx *ctx = file2ctx(file);
1408 struct vpe_fmt *fmt = find_format(f);
1409
1410 if (V4L2_TYPE_IS_OUTPUT(f->type))
1411 return __vpe_try_fmt(ctx, f, fmt, VPE_FMT_TYPE_OUTPUT);
1412 else
1413 return __vpe_try_fmt(ctx, f, fmt, VPE_FMT_TYPE_CAPTURE);
1414}
1415
1416static int __vpe_s_fmt(struct vpe_ctx *ctx, struct v4l2_format *f)
1417{
1418 struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
1419 struct v4l2_plane_pix_format *plane_fmt;
1420 struct vpe_q_data *q_data;
1421 struct vb2_queue *vq;
1422 int i;
1423
1424 vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
1425 if (!vq)
1426 return -EINVAL;
1427
1428 if (vb2_is_busy(vq)) {
1429 vpe_err(ctx->dev, "queue busy\n");
1430 return -EBUSY;
1431 }
1432
1433 q_data = get_q_data(ctx, f->type);
1434 if (!q_data)
1435 return -EINVAL;
1436
1437 q_data->fmt = find_format(f);
1438 q_data->width = pix->width;
1439 q_data->height = pix->height;
1440 q_data->colorspace = pix->colorspace;
1441 q_data->field = pix->field;
1442
1443 for (i = 0; i < pix->num_planes; i++) {
1444 plane_fmt = &pix->plane_fmt[i];
1445
1446 q_data->bytesperline[i] = plane_fmt->bytesperline;
1447 q_data->sizeimage[i] = plane_fmt->sizeimage;
1448 }
1449
1450 q_data->c_rect.left = 0;
1451 q_data->c_rect.top = 0;
1452 q_data->c_rect.width = q_data->width;
1453 q_data->c_rect.height = q_data->height;
1454
1455 if (q_data->field == V4L2_FIELD_ALTERNATE)
1456 q_data->flags |= Q_DATA_INTERLACED;
1457 else
1458 q_data->flags &= ~Q_DATA_INTERLACED;
1459
1460 vpe_dbg(ctx->dev, "Setting format for type %d, wxh: %dx%d, fmt: %d bpl_y %d",
1461 f->type, q_data->width, q_data->height, q_data->fmt->fourcc,
1462 q_data->bytesperline[VPE_LUMA]);
1463 if (q_data->fmt->coplanar)
1464 vpe_dbg(ctx->dev, " bpl_uv %d\n",
1465 q_data->bytesperline[VPE_CHROMA]);
1466
1467 return 0;
1468}
1469
1470static int vpe_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
1471{
1472 int ret;
1473 struct vpe_ctx *ctx = file2ctx(file);
1474
1475 ret = vpe_try_fmt(file, priv, f);
1476 if (ret)
1477 return ret;
1478
1479 ret = __vpe_s_fmt(ctx, f);
1480 if (ret)
1481 return ret;
1482
1483 if (V4L2_TYPE_IS_OUTPUT(f->type))
1484 set_src_registers(ctx);
1485 else
1486 set_dst_registers(ctx);
1487
1488 return set_srcdst_params(ctx);
1489}
1490
1491static int vpe_reqbufs(struct file *file, void *priv,
1492 struct v4l2_requestbuffers *reqbufs)
1493{
1494 struct vpe_ctx *ctx = file2ctx(file);
1495
1496 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
1497}
1498
1499static int vpe_querybuf(struct file *file, void *priv, struct v4l2_buffer *buf)
1500{
1501 struct vpe_ctx *ctx = file2ctx(file);
1502
1503 return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
1504}
1505
1506static int vpe_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
1507{
1508 struct vpe_ctx *ctx = file2ctx(file);
1509
1510 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
1511}
1512
1513static int vpe_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
1514{
1515 struct vpe_ctx *ctx = file2ctx(file);
1516
1517 return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
1518}
1519
1520static int vpe_streamon(struct file *file, void *priv, enum v4l2_buf_type type)
1521{
1522 struct vpe_ctx *ctx = file2ctx(file);
1523
1524 return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
1525}
1526
1527static int vpe_streamoff(struct file *file, void *priv, enum v4l2_buf_type type)
1528{
1529 struct vpe_ctx *ctx = file2ctx(file);
1530
1531 vpe_dump_regs(ctx->dev);
1532 vpdma_dump_regs(ctx->dev->vpdma);
1533
1534 return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
1535}
1536
1537/*
1538 * defines number of buffers/frames a context can process with VPE before
1539 * switching to a different context. default value is 1 buffer per context
1540 */
1541#define V4L2_CID_VPE_BUFS_PER_JOB (V4L2_CID_USER_TI_VPE_BASE + 0)
1542
1543static int vpe_s_ctrl(struct v4l2_ctrl *ctrl)
1544{
1545 struct vpe_ctx *ctx =
1546 container_of(ctrl->handler, struct vpe_ctx, hdl);
1547
1548 switch (ctrl->id) {
1549 case V4L2_CID_VPE_BUFS_PER_JOB:
1550 ctx->bufs_per_job = ctrl->val;
1551 break;
1552
1553 default:
1554 vpe_err(ctx->dev, "Invalid control\n");
1555 return -EINVAL;
1556 }
1557
1558 return 0;
1559}
1560
1561static const struct v4l2_ctrl_ops vpe_ctrl_ops = {
1562 .s_ctrl = vpe_s_ctrl,
1563};
1564
1565static const struct v4l2_ioctl_ops vpe_ioctl_ops = {
1566 .vidioc_querycap = vpe_querycap,
1567
1568 .vidioc_enum_fmt_vid_cap_mplane = vpe_enum_fmt,
1569 .vidioc_g_fmt_vid_cap_mplane = vpe_g_fmt,
1570 .vidioc_try_fmt_vid_cap_mplane = vpe_try_fmt,
1571 .vidioc_s_fmt_vid_cap_mplane = vpe_s_fmt,
1572
1573 .vidioc_enum_fmt_vid_out_mplane = vpe_enum_fmt,
1574 .vidioc_g_fmt_vid_out_mplane = vpe_g_fmt,
1575 .vidioc_try_fmt_vid_out_mplane = vpe_try_fmt,
1576 .vidioc_s_fmt_vid_out_mplane = vpe_s_fmt,
1577
1578 .vidioc_reqbufs = vpe_reqbufs,
1579 .vidioc_querybuf = vpe_querybuf,
1580
1581 .vidioc_qbuf = vpe_qbuf,
1582 .vidioc_dqbuf = vpe_dqbuf,
1583
1584 .vidioc_streamon = vpe_streamon,
1585 .vidioc_streamoff = vpe_streamoff,
1586 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1587 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1588};
1589
1590/*
1591 * Queue operations
1592 */
1593static int vpe_queue_setup(struct vb2_queue *vq,
1594 const struct v4l2_format *fmt,
1595 unsigned int *nbuffers, unsigned int *nplanes,
1596 unsigned int sizes[], void *alloc_ctxs[])
1597{
1598 int i;
1599 struct vpe_ctx *ctx = vb2_get_drv_priv(vq);
1600 struct vpe_q_data *q_data;
1601
1602 q_data = get_q_data(ctx, vq->type);
1603
1604 *nplanes = q_data->fmt->coplanar ? 2 : 1;
1605
1606 for (i = 0; i < *nplanes; i++) {
1607 sizes[i] = q_data->sizeimage[i];
1608 alloc_ctxs[i] = ctx->dev->alloc_ctx;
1609 }
1610
1611 vpe_dbg(ctx->dev, "get %d buffer(s) of size %d", *nbuffers,
1612 sizes[VPE_LUMA]);
1613 if (q_data->fmt->coplanar)
1614 vpe_dbg(ctx->dev, " and %d\n", sizes[VPE_CHROMA]);
1615
1616 return 0;
1617}
1618
1619static int vpe_buf_prepare(struct vb2_buffer *vb)
1620{
1621 struct vpe_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
1622 struct vpe_q_data *q_data;
1623 int i, num_planes;
1624
1625 vpe_dbg(ctx->dev, "type: %d\n", vb->vb2_queue->type);
1626
1627 q_data = get_q_data(ctx, vb->vb2_queue->type);
1628 num_planes = q_data->fmt->coplanar ? 2 : 1;
1629
1630 for (i = 0; i < num_planes; i++) {
1631 if (vb2_plane_size(vb, i) < q_data->sizeimage[i]) {
1632 vpe_err(ctx->dev,
1633 "data will not fit into plane (%lu < %lu)\n",
1634 vb2_plane_size(vb, i),
1635 (long) q_data->sizeimage[i]);
1636 return -EINVAL;
1637 }
1638 }
1639
1640 for (i = 0; i < num_planes; i++)
1641 vb2_set_plane_payload(vb, i, q_data->sizeimage[i]);
1642
1643 return 0;
1644}
1645
1646static void vpe_buf_queue(struct vb2_buffer *vb)
1647{
1648 struct vpe_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
1649 v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
1650}
1651
1652static void vpe_wait_prepare(struct vb2_queue *q)
1653{
1654 struct vpe_ctx *ctx = vb2_get_drv_priv(q);
1655 vpe_unlock(ctx);
1656}
1657
1658static void vpe_wait_finish(struct vb2_queue *q)
1659{
1660 struct vpe_ctx *ctx = vb2_get_drv_priv(q);
1661 vpe_lock(ctx);
1662}
1663
1664static struct vb2_ops vpe_qops = {
1665 .queue_setup = vpe_queue_setup,
1666 .buf_prepare = vpe_buf_prepare,
1667 .buf_queue = vpe_buf_queue,
1668 .wait_prepare = vpe_wait_prepare,
1669 .wait_finish = vpe_wait_finish,
1670};
1671
1672static int queue_init(void *priv, struct vb2_queue *src_vq,
1673 struct vb2_queue *dst_vq)
1674{
1675 struct vpe_ctx *ctx = priv;
1676 int ret;
1677
1678 memset(src_vq, 0, sizeof(*src_vq));
1679 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1680 src_vq->io_modes = VB2_MMAP;
1681 src_vq->drv_priv = ctx;
1682 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
1683 src_vq->ops = &vpe_qops;
1684 src_vq->mem_ops = &vb2_dma_contig_memops;
1685 src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
1686
1687 ret = vb2_queue_init(src_vq);
1688 if (ret)
1689 return ret;
1690
1691 memset(dst_vq, 0, sizeof(*dst_vq));
1692 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1693 dst_vq->io_modes = VB2_MMAP;
1694 dst_vq->drv_priv = ctx;
1695 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
1696 dst_vq->ops = &vpe_qops;
1697 dst_vq->mem_ops = &vb2_dma_contig_memops;
1698 dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
1699
1700 return vb2_queue_init(dst_vq);
1701}
1702
1703static const struct v4l2_ctrl_config vpe_bufs_per_job = {
1704 .ops = &vpe_ctrl_ops,
1705 .id = V4L2_CID_VPE_BUFS_PER_JOB,
1706 .name = "Buffers Per Transaction",
1707 .type = V4L2_CTRL_TYPE_INTEGER,
1708 .def = VPE_DEF_BUFS_PER_JOB,
1709 .min = 1,
1710 .max = VIDEO_MAX_FRAME,
1711 .step = 1,
1712};
1713
1714/*
1715 * File operations
1716 */
1717static int vpe_open(struct file *file)
1718{
1719 struct vpe_dev *dev = video_drvdata(file);
1720 struct vpe_ctx *ctx = NULL;
1721 struct vpe_q_data *s_q_data;
1722 struct v4l2_ctrl_handler *hdl;
1723 int ret;
1724
1725 vpe_dbg(dev, "vpe_open\n");
1726
1727 if (!dev->vpdma->ready) {
1728 vpe_err(dev, "vpdma firmware not loaded\n");
1729 return -ENODEV;
1730 }
1731
1732 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
1733 if (!ctx)
1734 return -ENOMEM;
1735
1736 ctx->dev = dev;
1737
1738 if (mutex_lock_interruptible(&dev->dev_mutex)) {
1739 ret = -ERESTARTSYS;
1740 goto free_ctx;
1741 }
1742
1743 ret = vpdma_create_desc_list(&ctx->desc_list, VPE_DESC_LIST_SIZE,
1744 VPDMA_LIST_TYPE_NORMAL);
1745 if (ret != 0)
1746 goto unlock;
1747
1748 ret = vpdma_alloc_desc_buf(&ctx->mmr_adb, sizeof(struct vpe_mmr_adb));
1749 if (ret != 0)
1750 goto free_desc_list;
1751
1752 init_adb_hdrs(ctx);
1753
1754 v4l2_fh_init(&ctx->fh, video_devdata(file));
1755 file->private_data = &ctx->fh;
1756
1757 hdl = &ctx->hdl;
1758 v4l2_ctrl_handler_init(hdl, 1);
1759 v4l2_ctrl_new_custom(hdl, &vpe_bufs_per_job, NULL);
1760 if (hdl->error) {
1761 ret = hdl->error;
1762 goto exit_fh;
1763 }
1764 ctx->fh.ctrl_handler = hdl;
1765 v4l2_ctrl_handler_setup(hdl);
1766
1767 s_q_data = &ctx->q_data[Q_DATA_SRC];
1768 s_q_data->fmt = &vpe_formats[2];
1769 s_q_data->width = 1920;
1770 s_q_data->height = 1080;
1771 s_q_data->sizeimage[VPE_LUMA] = (s_q_data->width * s_q_data->height *
1772 s_q_data->fmt->vpdma_fmt[VPE_LUMA]->depth) >> 3;
1773 s_q_data->colorspace = V4L2_COLORSPACE_SMPTE240M;
1774 s_q_data->field = V4L2_FIELD_NONE;
1775 s_q_data->c_rect.left = 0;
1776 s_q_data->c_rect.top = 0;
1777 s_q_data->c_rect.width = s_q_data->width;
1778 s_q_data->c_rect.height = s_q_data->height;
1779 s_q_data->flags = 0;
1780
1781 ctx->q_data[Q_DATA_DST] = *s_q_data;
1782
1783 set_dei_shadow_registers(ctx);
1784 set_src_registers(ctx);
1785 set_dst_registers(ctx);
1786 ret = set_srcdst_params(ctx);
1787 if (ret)
1788 goto exit_fh;
1789
1790 ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init);
1791
1792 if (IS_ERR(ctx->m2m_ctx)) {
1793 ret = PTR_ERR(ctx->m2m_ctx);
1794 goto exit_fh;
1795 }
1796
1797 v4l2_fh_add(&ctx->fh);
1798
1799 /*
1800 * for now, just report the creation of the first instance, we can later
1801 * optimize the driver to enable or disable clocks when the first
1802 * instance is created or the last instance released
1803 */
1804 if (atomic_inc_return(&dev->num_instances) == 1)
1805 vpe_dbg(dev, "first instance created\n");
1806
1807 ctx->bufs_per_job = VPE_DEF_BUFS_PER_JOB;
1808
1809 ctx->load_mmrs = true;
1810
1811 vpe_dbg(dev, "created instance %p, m2m_ctx: %p\n",
1812 ctx, ctx->m2m_ctx);
1813
1814 mutex_unlock(&dev->dev_mutex);
1815
1816 return 0;
1817exit_fh:
1818 v4l2_ctrl_handler_free(hdl);
1819 v4l2_fh_exit(&ctx->fh);
1820 vpdma_free_desc_buf(&ctx->mmr_adb);
1821free_desc_list:
1822 vpdma_free_desc_list(&ctx->desc_list);
1823unlock:
1824 mutex_unlock(&dev->dev_mutex);
1825free_ctx:
1826 kfree(ctx);
1827 return ret;
1828}
1829
1830static int vpe_release(struct file *file)
1831{
1832 struct vpe_dev *dev = video_drvdata(file);
1833 struct vpe_ctx *ctx = file2ctx(file);
1834
1835 vpe_dbg(dev, "releasing instance %p\n", ctx);
1836
1837 mutex_lock(&dev->dev_mutex);
1838 free_vbs(ctx);
1839 free_mv_buffers(ctx);
1840 vpdma_free_desc_list(&ctx->desc_list);
1841 vpdma_free_desc_buf(&ctx->mmr_adb);
1842
1843 v4l2_fh_del(&ctx->fh);
1844 v4l2_fh_exit(&ctx->fh);
1845 v4l2_ctrl_handler_free(&ctx->hdl);
1846 v4l2_m2m_ctx_release(ctx->m2m_ctx);
1847
1848 kfree(ctx);
1849
1850 /*
1851 * for now, just report the release of the last instance, we can later
1852 * optimize the driver to enable or disable clocks when the first
1853 * instance is created or the last instance released
1854 */
1855 if (atomic_dec_return(&dev->num_instances) == 0)
1856 vpe_dbg(dev, "last instance released\n");
1857
1858 mutex_unlock(&dev->dev_mutex);
1859
1860 return 0;
1861}
1862
1863static unsigned int vpe_poll(struct file *file,
1864 struct poll_table_struct *wait)
1865{
1866 struct vpe_ctx *ctx = file2ctx(file);
1867 struct vpe_dev *dev = ctx->dev;
1868 int ret;
1869
1870 mutex_lock(&dev->dev_mutex);
1871 ret = v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
1872 mutex_unlock(&dev->dev_mutex);
1873 return ret;
1874}
1875
1876static int vpe_mmap(struct file *file, struct vm_area_struct *vma)
1877{
1878 struct vpe_ctx *ctx = file2ctx(file);
1879 struct vpe_dev *dev = ctx->dev;
1880 int ret;
1881
1882 if (mutex_lock_interruptible(&dev->dev_mutex))
1883 return -ERESTARTSYS;
1884 ret = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
1885 mutex_unlock(&dev->dev_mutex);
1886 return ret;
1887}
1888
1889static const struct v4l2_file_operations vpe_fops = {
1890 .owner = THIS_MODULE,
1891 .open = vpe_open,
1892 .release = vpe_release,
1893 .poll = vpe_poll,
1894 .unlocked_ioctl = video_ioctl2,
1895 .mmap = vpe_mmap,
1896};
1897
1898static struct video_device vpe_videodev = {
1899 .name = VPE_MODULE_NAME,
1900 .fops = &vpe_fops,
1901 .ioctl_ops = &vpe_ioctl_ops,
1902 .minor = -1,
1903 .release = video_device_release,
1904 .vfl_dir = VFL_DIR_M2M,
1905};
1906
1907static struct v4l2_m2m_ops m2m_ops = {
1908 .device_run = device_run,
1909 .job_ready = job_ready,
1910 .job_abort = job_abort,
1911 .lock = vpe_lock,
1912 .unlock = vpe_unlock,
1913};
1914
1915static int vpe_runtime_get(struct platform_device *pdev)
1916{
1917 int r;
1918
1919 dev_dbg(&pdev->dev, "vpe_runtime_get\n");
1920
1921 r = pm_runtime_get_sync(&pdev->dev);
1922 WARN_ON(r < 0);
1923 return r < 0 ? r : 0;
1924}
1925
1926static void vpe_runtime_put(struct platform_device *pdev)
1927{
1928
1929 int r;
1930
1931 dev_dbg(&pdev->dev, "vpe_runtime_put\n");
1932
1933 r = pm_runtime_put_sync(&pdev->dev);
1934 WARN_ON(r < 0 && r != -ENOSYS);
1935}
1936
1937static int vpe_probe(struct platform_device *pdev)
1938{
1939 struct vpe_dev *dev;
1940 struct video_device *vfd;
1941 struct resource *res;
1942 int ret, irq, func;
1943
1944 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
1945 if (IS_ERR(dev))
1946 return PTR_ERR(dev);
1947
1948 spin_lock_init(&dev->lock);
1949
1950 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
1951 if (ret)
1952 return ret;
1953
1954 atomic_set(&dev->num_instances, 0);
1955 mutex_init(&dev->dev_mutex);
1956
1957 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vpe_top");
1958 /*
1959 * HACK: we get resource info from device tree in the form of a list of
1960 * VPE sub blocks, the driver currently uses only the base of vpe_top
1961 * for register access, the driver should be changed later to access
1962 * registers based on the sub block base addresses
1963 */
1964 dev->base = devm_ioremap(&pdev->dev, res->start, SZ_32K);
1965 if (IS_ERR(dev->base)) {
1966 ret = PTR_ERR(dev->base);
1967 goto v4l2_dev_unreg;
1968 }
1969
1970 irq = platform_get_irq(pdev, 0);
1971 ret = devm_request_irq(&pdev->dev, irq, vpe_irq, 0, VPE_MODULE_NAME,
1972 dev);
1973 if (ret)
1974 goto v4l2_dev_unreg;
1975
1976 platform_set_drvdata(pdev, dev);
1977
1978 dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
1979 if (IS_ERR(dev->alloc_ctx)) {
1980 vpe_err(dev, "Failed to alloc vb2 context\n");
1981 ret = PTR_ERR(dev->alloc_ctx);
1982 goto v4l2_dev_unreg;
1983 }
1984
1985 dev->m2m_dev = v4l2_m2m_init(&m2m_ops);
1986 if (IS_ERR(dev->m2m_dev)) {
1987 vpe_err(dev, "Failed to init mem2mem device\n");
1988 ret = PTR_ERR(dev->m2m_dev);
1989 goto rel_ctx;
1990 }
1991
1992 pm_runtime_enable(&pdev->dev);
1993
1994 ret = vpe_runtime_get(pdev);
1995 if (ret)
1996 goto rel_m2m;
1997
1998 /* Perform clk enable followed by reset */
1999 vpe_set_clock_enable(dev, 1);
2000
2001 vpe_top_reset(dev);
2002
2003 func = read_field_reg(dev, VPE_PID, VPE_PID_FUNC_MASK,
2004 VPE_PID_FUNC_SHIFT);
2005 vpe_dbg(dev, "VPE PID function %x\n", func);
2006
2007 vpe_top_vpdma_reset(dev);
2008
2009 dev->vpdma = vpdma_create(pdev);
2010 if (IS_ERR(dev->vpdma))
2011 goto runtime_put;
2012
2013 vfd = &dev->vfd;
2014 *vfd = vpe_videodev;
2015 vfd->lock = &dev->dev_mutex;
2016 vfd->v4l2_dev = &dev->v4l2_dev;
2017
2018 ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
2019 if (ret) {
2020 vpe_err(dev, "Failed to register video device\n");
2021 goto runtime_put;
2022 }
2023
2024 video_set_drvdata(vfd, dev);
2025 snprintf(vfd->name, sizeof(vfd->name), "%s", vpe_videodev.name);
2026 dev_info(dev->v4l2_dev.dev, "Device registered as /dev/video%d\n",
2027 vfd->num);
2028
2029 return 0;
2030
2031runtime_put:
2032 vpe_runtime_put(pdev);
2033rel_m2m:
2034 pm_runtime_disable(&pdev->dev);
2035 v4l2_m2m_release(dev->m2m_dev);
2036rel_ctx:
2037 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
2038v4l2_dev_unreg:
2039 v4l2_device_unregister(&dev->v4l2_dev);
2040
2041 return ret;
2042}
2043
2044static int vpe_remove(struct platform_device *pdev)
2045{
2046 struct vpe_dev *dev =
2047 (struct vpe_dev *) platform_get_drvdata(pdev);
2048
2049 v4l2_info(&dev->v4l2_dev, "Removing " VPE_MODULE_NAME);
2050
2051 v4l2_m2m_release(dev->m2m_dev);
2052 video_unregister_device(&dev->vfd);
2053 v4l2_device_unregister(&dev->v4l2_dev);
2054 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
2055
2056 vpe_set_clock_enable(dev, 0);
2057 vpe_runtime_put(pdev);
2058 pm_runtime_disable(&pdev->dev);
2059
2060 return 0;
2061}
2062
2063#if defined(CONFIG_OF)
2064static const struct of_device_id vpe_of_match[] = {
2065 {
2066 .compatible = "ti,vpe",
2067 },
2068 {},
2069};
2070#else
2071#define vpe_of_match NULL
2072#endif
2073
2074static struct platform_driver vpe_pdrv = {
2075 .probe = vpe_probe,
2076 .remove = vpe_remove,
2077 .driver = {
2078 .name = VPE_MODULE_NAME,
2079 .owner = THIS_MODULE,
2080 .of_match_table = vpe_of_match,
2081 },
2082};
2083
2084static void __exit vpe_exit(void)
2085{
2086 platform_driver_unregister(&vpe_pdrv);
2087}
2088
2089static int __init vpe_init(void)
2090{
2091 return platform_driver_register(&vpe_pdrv);
2092}
2093
2094module_init(vpe_init);
2095module_exit(vpe_exit);
2096
2097MODULE_DESCRIPTION("TI VPE driver");
2098MODULE_AUTHOR("Dale Farnsworth, <dale@farnsworth.org>");
2099MODULE_LICENSE("GPL");
diff --git a/drivers/media/platform/ti-vpe/vpe_regs.h b/drivers/media/platform/ti-vpe/vpe_regs.h
new file mode 100644
index 000000000000..ed214e828398
--- /dev/null
+++ b/drivers/media/platform/ti-vpe/vpe_regs.h
@@ -0,0 +1,496 @@
1/*
2 * Copyright (c) 2013 Texas Instruments Inc.
3 *
4 * David Griego, <dagriego@biglakesoftware.com>
5 * Dale Farnsworth, <dale@farnsworth.org>
6 * Archit Taneja, <archit@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
13#ifndef __TI_VPE_REGS_H
14#define __TI_VPE_REGS_H
15
16/* VPE register offsets and field selectors */
17
18/* VPE top level regs */
19#define VPE_PID 0x0000
20#define VPE_PID_MINOR_MASK 0x3f
21#define VPE_PID_MINOR_SHIFT 0
22#define VPE_PID_CUSTOM_MASK 0x03
23#define VPE_PID_CUSTOM_SHIFT 6
24#define VPE_PID_MAJOR_MASK 0x07
25#define VPE_PID_MAJOR_SHIFT 8
26#define VPE_PID_RTL_MASK 0x1f
27#define VPE_PID_RTL_SHIFT 11
28#define VPE_PID_FUNC_MASK 0xfff
29#define VPE_PID_FUNC_SHIFT 16
30#define VPE_PID_SCHEME_MASK 0x03
31#define VPE_PID_SCHEME_SHIFT 30
32
33#define VPE_SYSCONFIG 0x0010
34#define VPE_SYSCONFIG_IDLE_MASK 0x03
35#define VPE_SYSCONFIG_IDLE_SHIFT 2
36#define VPE_SYSCONFIG_STANDBY_MASK 0x03
37#define VPE_SYSCONFIG_STANDBY_SHIFT 4
38#define VPE_FORCE_IDLE_MODE 0
39#define VPE_NO_IDLE_MODE 1
40#define VPE_SMART_IDLE_MODE 2
41#define VPE_SMART_IDLE_WAKEUP_MODE 3
42#define VPE_FORCE_STANDBY_MODE 0
43#define VPE_NO_STANDBY_MODE 1
44#define VPE_SMART_STANDBY_MODE 2
45#define VPE_SMART_STANDBY_WAKEUP_MODE 3
46
47#define VPE_INT0_STATUS0_RAW_SET 0x0020
48#define VPE_INT0_STATUS0_RAW VPE_INT0_STATUS0_RAW_SET
49#define VPE_INT0_STATUS0_CLR 0x0028
50#define VPE_INT0_STATUS0 VPE_INT0_STATUS0_CLR
51#define VPE_INT0_ENABLE0_SET 0x0030
52#define VPE_INT0_ENABLE0 VPE_INT0_ENABLE0_SET
53#define VPE_INT0_ENABLE0_CLR 0x0038
54#define VPE_INT0_LIST0_COMPLETE (1 << 0)
55#define VPE_INT0_LIST0_NOTIFY (1 << 1)
56#define VPE_INT0_LIST1_COMPLETE (1 << 2)
57#define VPE_INT0_LIST1_NOTIFY (1 << 3)
58#define VPE_INT0_LIST2_COMPLETE (1 << 4)
59#define VPE_INT0_LIST2_NOTIFY (1 << 5)
60#define VPE_INT0_LIST3_COMPLETE (1 << 6)
61#define VPE_INT0_LIST3_NOTIFY (1 << 7)
62#define VPE_INT0_LIST4_COMPLETE (1 << 8)
63#define VPE_INT0_LIST4_NOTIFY (1 << 9)
64#define VPE_INT0_LIST5_COMPLETE (1 << 10)
65#define VPE_INT0_LIST5_NOTIFY (1 << 11)
66#define VPE_INT0_LIST6_COMPLETE (1 << 12)
67#define VPE_INT0_LIST6_NOTIFY (1 << 13)
68#define VPE_INT0_LIST7_COMPLETE (1 << 14)
69#define VPE_INT0_LIST7_NOTIFY (1 << 15)
70#define VPE_INT0_DESCRIPTOR (1 << 16)
71#define VPE_DEI_FMD_INT (1 << 18)
72
73#define VPE_INT0_STATUS1_RAW_SET 0x0024
74#define VPE_INT0_STATUS1_RAW VPE_INT0_STATUS1_RAW_SET
75#define VPE_INT0_STATUS1_CLR 0x002c
76#define VPE_INT0_STATUS1 VPE_INT0_STATUS1_CLR
77#define VPE_INT0_ENABLE1_SET 0x0034
78#define VPE_INT0_ENABLE1 VPE_INT0_ENABLE1_SET
79#define VPE_INT0_ENABLE1_CLR 0x003c
80#define VPE_INT0_CHANNEL_GROUP0 (1 << 0)
81#define VPE_INT0_CHANNEL_GROUP1 (1 << 1)
82#define VPE_INT0_CHANNEL_GROUP2 (1 << 2)
83#define VPE_INT0_CHANNEL_GROUP3 (1 << 3)
84#define VPE_INT0_CHANNEL_GROUP4 (1 << 4)
85#define VPE_INT0_CHANNEL_GROUP5 (1 << 5)
86#define VPE_INT0_CLIENT (1 << 7)
87#define VPE_DEI_ERROR_INT (1 << 16)
88#define VPE_DS1_UV_ERROR_INT (1 << 22)
89
90#define VPE_INTC_EOI 0x00a0
91
92#define VPE_CLK_ENABLE 0x0100
93#define VPE_VPEDMA_CLK_ENABLE (1 << 0)
94#define VPE_DATA_PATH_CLK_ENABLE (1 << 1)
95
96#define VPE_CLK_RESET 0x0104
97#define VPE_VPDMA_CLK_RESET_MASK 0x1
98#define VPE_VPDMA_CLK_RESET_SHIFT 0
99#define VPE_DATA_PATH_CLK_RESET_MASK 0x1
100#define VPE_DATA_PATH_CLK_RESET_SHIFT 1
101#define VPE_MAIN_RESET_MASK 0x1
102#define VPE_MAIN_RESET_SHIFT 31
103
104#define VPE_CLK_FORMAT_SELECT 0x010c
105#define VPE_CSC_SRC_SELECT_MASK 0x03
106#define VPE_CSC_SRC_SELECT_SHIFT 0
107#define VPE_RGB_OUT_SELECT (1 << 8)
108#define VPE_DS_SRC_SELECT_MASK 0x07
109#define VPE_DS_SRC_SELECT_SHIFT 9
110#define VPE_DS_BYPASS (1 << 16)
111#define VPE_COLOR_SEPARATE_422 (1 << 18)
112
113#define VPE_DS_SRC_DEI_SCALER (5 << VPE_DS_SRC_SELECT_SHIFT)
114#define VPE_CSC_SRC_DEI_SCALER (3 << VPE_CSC_SRC_SELECT_SHIFT)
115
116#define VPE_CLK_RANGE_MAP 0x011c
117#define VPE_RANGE_RANGE_MAP_Y_MASK 0x07
118#define VPE_RANGE_RANGE_MAP_Y_SHIFT 0
119#define VPE_RANGE_RANGE_MAP_UV_MASK 0x07
120#define VPE_RANGE_RANGE_MAP_UV_SHIFT 3
121#define VPE_RANGE_MAP_ON (1 << 6)
122#define VPE_RANGE_REDUCTION_ON (1 << 28)
123
124/* VPE chrominance upsampler regs */
125#define VPE_US1_R0 0x0304
126#define VPE_US2_R0 0x0404
127#define VPE_US3_R0 0x0504
128#define VPE_US_C1_MASK 0x3fff
129#define VPE_US_C1_SHIFT 2
130#define VPE_US_C0_MASK 0x3fff
131#define VPE_US_C0_SHIFT 18
132#define VPE_US_MODE_MASK 0x03
133#define VPE_US_MODE_SHIFT 16
134#define VPE_ANCHOR_FID0_C1_MASK 0x3fff
135#define VPE_ANCHOR_FID0_C1_SHIFT 2
136#define VPE_ANCHOR_FID0_C0_MASK 0x3fff
137#define VPE_ANCHOR_FID0_C0_SHIFT 18
138
139#define VPE_US1_R1 0x0308
140#define VPE_US2_R1 0x0408
141#define VPE_US3_R1 0x0508
142#define VPE_ANCHOR_FID0_C3_MASK 0x3fff
143#define VPE_ANCHOR_FID0_C3_SHIFT 2
144#define VPE_ANCHOR_FID0_C2_MASK 0x3fff
145#define VPE_ANCHOR_FID0_C2_SHIFT 18
146
147#define VPE_US1_R2 0x030c
148#define VPE_US2_R2 0x040c
149#define VPE_US3_R2 0x050c
150#define VPE_INTERP_FID0_C1_MASK 0x3fff
151#define VPE_INTERP_FID0_C1_SHIFT 2
152#define VPE_INTERP_FID0_C0_MASK 0x3fff
153#define VPE_INTERP_FID0_C0_SHIFT 18
154
155#define VPE_US1_R3 0x0310
156#define VPE_US2_R3 0x0410
157#define VPE_US3_R3 0x0510
158#define VPE_INTERP_FID0_C3_MASK 0x3fff
159#define VPE_INTERP_FID0_C3_SHIFT 2
160#define VPE_INTERP_FID0_C2_MASK 0x3fff
161#define VPE_INTERP_FID0_C2_SHIFT 18
162
163#define VPE_US1_R4 0x0314
164#define VPE_US2_R4 0x0414
165#define VPE_US3_R4 0x0514
166#define VPE_ANCHOR_FID1_C1_MASK 0x3fff
167#define VPE_ANCHOR_FID1_C1_SHIFT 2
168#define VPE_ANCHOR_FID1_C0_MASK 0x3fff
169#define VPE_ANCHOR_FID1_C0_SHIFT 18
170
171#define VPE_US1_R5 0x0318
172#define VPE_US2_R5 0x0418
173#define VPE_US3_R5 0x0518
174#define VPE_ANCHOR_FID1_C3_MASK 0x3fff
175#define VPE_ANCHOR_FID1_C3_SHIFT 2
176#define VPE_ANCHOR_FID1_C2_MASK 0x3fff
177#define VPE_ANCHOR_FID1_C2_SHIFT 18
178
179#define VPE_US1_R6 0x031c
180#define VPE_US2_R6 0x041c
181#define VPE_US3_R6 0x051c
182#define VPE_INTERP_FID1_C1_MASK 0x3fff
183#define VPE_INTERP_FID1_C1_SHIFT 2
184#define VPE_INTERP_FID1_C0_MASK 0x3fff
185#define VPE_INTERP_FID1_C0_SHIFT 18
186
187#define VPE_US1_R7 0x0320
188#define VPE_US2_R7 0x0420
189#define VPE_US3_R7 0x0520
190#define VPE_INTERP_FID0_C3_MASK 0x3fff
191#define VPE_INTERP_FID0_C3_SHIFT 2
192#define VPE_INTERP_FID0_C2_MASK 0x3fff
193#define VPE_INTERP_FID0_C2_SHIFT 18
194
195/* VPE de-interlacer regs */
196#define VPE_DEI_FRAME_SIZE 0x0600
197#define VPE_DEI_WIDTH_MASK 0x07ff
198#define VPE_DEI_WIDTH_SHIFT 0
199#define VPE_DEI_HEIGHT_MASK 0x07ff
200#define VPE_DEI_HEIGHT_SHIFT 16
201#define VPE_DEI_INTERLACE_BYPASS (1 << 29)
202#define VPE_DEI_FIELD_FLUSH (1 << 30)
203#define VPE_DEI_PROGRESSIVE (1 << 31)
204
205#define VPE_MDT_BYPASS 0x0604
206#define VPE_MDT_TEMPMAX_BYPASS (1 << 0)
207#define VPE_MDT_SPATMAX_BYPASS (1 << 1)
208
209#define VPE_MDT_SF_THRESHOLD 0x0608
210#define VPE_MDT_SF_SC_THR1_MASK 0xff
211#define VPE_MDT_SF_SC_THR1_SHIFT 0
212#define VPE_MDT_SF_SC_THR2_MASK 0xff
213#define VPE_MDT_SF_SC_THR2_SHIFT 0
214#define VPE_MDT_SF_SC_THR3_MASK 0xff
215#define VPE_MDT_SF_SC_THR3_SHIFT 0
216
217#define VPE_EDI_CONFIG 0x060c
218#define VPE_EDI_INP_MODE_MASK 0x03
219#define VPE_EDI_INP_MODE_SHIFT 0
220#define VPE_EDI_ENABLE_3D (1 << 2)
221#define VPE_EDI_ENABLE_CHROMA_3D (1 << 3)
222#define VPE_EDI_CHROMA3D_COR_THR_MASK 0xff
223#define VPE_EDI_CHROMA3D_COR_THR_SHIFT 8
224#define VPE_EDI_DIR_COR_LOWER_THR_MASK 0xff
225#define VPE_EDI_DIR_COR_LOWER_THR_SHIFT 16
226#define VPE_EDI_COR_SCALE_FACTOR_MASK 0xff
227#define VPE_EDI_COR_SCALE_FACTOR_SHIFT 23
228
229#define VPE_DEI_EDI_LUT_R0 0x0610
230#define VPE_EDI_LUT0_MASK 0x1f
231#define VPE_EDI_LUT0_SHIFT 0
232#define VPE_EDI_LUT1_MASK 0x1f
233#define VPE_EDI_LUT1_SHIFT 8
234#define VPE_EDI_LUT2_MASK 0x1f
235#define VPE_EDI_LUT2_SHIFT 16
236#define VPE_EDI_LUT3_MASK 0x1f
237#define VPE_EDI_LUT3_SHIFT 24
238
239#define VPE_DEI_EDI_LUT_R1 0x0614
240#define VPE_EDI_LUT0_MASK 0x1f
241#define VPE_EDI_LUT0_SHIFT 0
242#define VPE_EDI_LUT1_MASK 0x1f
243#define VPE_EDI_LUT1_SHIFT 8
244#define VPE_EDI_LUT2_MASK 0x1f
245#define VPE_EDI_LUT2_SHIFT 16
246#define VPE_EDI_LUT3_MASK 0x1f
247#define VPE_EDI_LUT3_SHIFT 24
248
249#define VPE_DEI_EDI_LUT_R2 0x0618
250#define VPE_EDI_LUT4_MASK 0x1f
251#define VPE_EDI_LUT4_SHIFT 0
252#define VPE_EDI_LUT5_MASK 0x1f
253#define VPE_EDI_LUT5_SHIFT 8
254#define VPE_EDI_LUT6_MASK 0x1f
255#define VPE_EDI_LUT6_SHIFT 16
256#define VPE_EDI_LUT7_MASK 0x1f
257#define VPE_EDI_LUT7_SHIFT 24
258
259#define VPE_DEI_EDI_LUT_R3 0x061c
260#define VPE_EDI_LUT8_MASK 0x1f
261#define VPE_EDI_LUT8_SHIFT 0
262#define VPE_EDI_LUT9_MASK 0x1f
263#define VPE_EDI_LUT9_SHIFT 8
264#define VPE_EDI_LUT10_MASK 0x1f
265#define VPE_EDI_LUT10_SHIFT 16
266#define VPE_EDI_LUT11_MASK 0x1f
267#define VPE_EDI_LUT11_SHIFT 24
268
269#define VPE_DEI_FMD_WINDOW_R0 0x0620
270#define VPE_FMD_WINDOW_MINX_MASK 0x07ff
271#define VPE_FMD_WINDOW_MINX_SHIFT 0
272#define VPE_FMD_WINDOW_MAXX_MASK 0x07ff
273#define VPE_FMD_WINDOW_MAXX_SHIFT 16
274#define VPE_FMD_WINDOW_ENABLE (1 << 31)
275
276#define VPE_DEI_FMD_WINDOW_R1 0x0624
277#define VPE_FMD_WINDOW_MINY_MASK 0x07ff
278#define VPE_FMD_WINDOW_MINY_SHIFT 0
279#define VPE_FMD_WINDOW_MAXY_MASK 0x07ff
280#define VPE_FMD_WINDOW_MAXY_SHIFT 16
281
282#define VPE_DEI_FMD_CONTROL_R0 0x0628
283#define VPE_FMD_ENABLE (1 << 0)
284#define VPE_FMD_LOCK (1 << 1)
285#define VPE_FMD_JAM_DIR (1 << 2)
286#define VPE_FMD_BED_ENABLE (1 << 3)
287#define VPE_FMD_CAF_FIELD_THR_MASK 0xff
288#define VPE_FMD_CAF_FIELD_THR_SHIFT 16
289#define VPE_FMD_CAF_LINE_THR_MASK 0xff
290#define VPE_FMD_CAF_LINE_THR_SHIFT 24
291
292#define VPE_DEI_FMD_CONTROL_R1 0x062c
293#define VPE_FMD_CAF_THR_MASK 0x000fffff
294#define VPE_FMD_CAF_THR_SHIFT 0
295
296#define VPE_DEI_FMD_STATUS_R0 0x0630
297#define VPE_FMD_CAF_MASK 0x000fffff
298#define VPE_FMD_CAF_SHIFT 0
299#define VPE_FMD_RESET (1 << 24)
300
301#define VPE_DEI_FMD_STATUS_R1 0x0634
302#define VPE_FMD_FIELD_DIFF_MASK 0x0fffffff
303#define VPE_FMD_FIELD_DIFF_SHIFT 0
304
305#define VPE_DEI_FMD_STATUS_R2 0x0638
306#define VPE_FMD_FRAME_DIFF_MASK 0x000fffff
307#define VPE_FMD_FRAME_DIFF_SHIFT 0
308
309/* VPE scaler regs */
310#define VPE_SC_MP_SC0 0x0700
311#define VPE_INTERLACE_O (1 << 0)
312#define VPE_LINEAR (1 << 1)
313#define VPE_SC_BYPASS (1 << 2)
314#define VPE_INVT_FID (1 << 3)
315#define VPE_USE_RAV (1 << 4)
316#define VPE_ENABLE_EV (1 << 5)
317#define VPE_AUTO_HS (1 << 6)
318#define VPE_DCM_2X (1 << 7)
319#define VPE_DCM_4X (1 << 8)
320#define VPE_HP_BYPASS (1 << 9)
321#define VPE_INTERLACE_I (1 << 10)
322#define VPE_ENABLE_SIN2_VER_INTP (1 << 11)
323#define VPE_Y_PK_EN (1 << 14)
324#define VPE_TRIM (1 << 15)
325#define VPE_SELFGEN_FID (1 << 16)
326
327#define VPE_SC_MP_SC1 0x0704
328#define VPE_ROW_ACC_INC_MASK 0x07ffffff
329#define VPE_ROW_ACC_INC_SHIFT 0
330
331#define VPE_SC_MP_SC2 0x0708
332#define VPE_ROW_ACC_OFFSET_MASK 0x0fffffff
333#define VPE_ROW_ACC_OFFSET_SHIFT 0
334
335#define VPE_SC_MP_SC3 0x070c
336#define VPE_ROW_ACC_OFFSET_B_MASK 0x0fffffff
337#define VPE_ROW_ACC_OFFSET_B_SHIFT 0
338
339#define VPE_SC_MP_SC4 0x0710
340#define VPE_TAR_H_MASK 0x07ff
341#define VPE_TAR_H_SHIFT 0
342#define VPE_TAR_W_MASK 0x07ff
343#define VPE_TAR_W_SHIFT 12
344#define VPE_LIN_ACC_INC_U_MASK 0x07
345#define VPE_LIN_ACC_INC_U_SHIFT 24
346#define VPE_NLIN_ACC_INIT_U_MASK 0x07
347#define VPE_NLIN_ACC_INIT_U_SHIFT 28
348
349#define VPE_SC_MP_SC5 0x0714
350#define VPE_SRC_H_MASK 0x07ff
351#define VPE_SRC_H_SHIFT 0
352#define VPE_SRC_W_MASK 0x07ff
353#define VPE_SRC_W_SHIFT 12
354#define VPE_NLIN_ACC_INC_U_MASK 0x07
355#define VPE_NLIN_ACC_INC_U_SHIFT 24
356
357#define VPE_SC_MP_SC6 0x0718
358#define VPE_ROW_ACC_INIT_RAV_MASK 0x03ff
359#define VPE_ROW_ACC_INIT_RAV_SHIFT 0
360#define VPE_ROW_ACC_INIT_RAV_B_MASK 0x03ff
361#define VPE_ROW_ACC_INIT_RAV_B_SHIFT 10
362
363#define VPE_SC_MP_SC8 0x0720
364#define VPE_NLIN_LEFT_MASK 0x07ff
365#define VPE_NLIN_LEFT_SHIFT 0
366#define VPE_NLIN_RIGHT_MASK 0x07ff
367#define VPE_NLIN_RIGHT_SHIFT 12
368
369#define VPE_SC_MP_SC9 0x0724
370#define VPE_LIN_ACC_INC VPE_SC_MP_SC9
371
372#define VPE_SC_MP_SC10 0x0728
373#define VPE_NLIN_ACC_INIT VPE_SC_MP_SC10
374
375#define VPE_SC_MP_SC11 0x072c
376#define VPE_NLIN_ACC_INC VPE_SC_MP_SC11
377
378#define VPE_SC_MP_SC12 0x0730
379#define VPE_COL_ACC_OFFSET_MASK 0x01ffffff
380#define VPE_COL_ACC_OFFSET_SHIFT 0
381
382#define VPE_SC_MP_SC13 0x0734
383#define VPE_SC_FACTOR_RAV_MASK 0x03ff
384#define VPE_SC_FACTOR_RAV_SHIFT 0
385#define VPE_CHROMA_INTP_THR_MASK 0x03ff
386#define VPE_CHROMA_INTP_THR_SHIFT 12
387#define VPE_DELTA_CHROMA_THR_MASK 0x0f
388#define VPE_DELTA_CHROMA_THR_SHIFT 24
389
390#define VPE_SC_MP_SC17 0x0744
391#define VPE_EV_THR_MASK 0x03ff
392#define VPE_EV_THR_SHIFT 12
393#define VPE_DELTA_LUMA_THR_MASK 0x0f
394#define VPE_DELTA_LUMA_THR_SHIFT 24
395#define VPE_DELTA_EV_THR_MASK 0x0f
396#define VPE_DELTA_EV_THR_SHIFT 28
397
398#define VPE_SC_MP_SC18 0x0748
399#define VPE_HS_FACTOR_MASK 0x03ff
400#define VPE_HS_FACTOR_SHIFT 0
401#define VPE_CONF_DEFAULT_MASK 0x01ff
402#define VPE_CONF_DEFAULT_SHIFT 16
403
404#define VPE_SC_MP_SC19 0x074c
405#define VPE_HPF_COEFF0_MASK 0xff
406#define VPE_HPF_COEFF0_SHIFT 0
407#define VPE_HPF_COEFF1_MASK 0xff
408#define VPE_HPF_COEFF1_SHIFT 8
409#define VPE_HPF_COEFF2_MASK 0xff
410#define VPE_HPF_COEFF2_SHIFT 16
411#define VPE_HPF_COEFF3_MASK 0xff
412#define VPE_HPF_COEFF3_SHIFT 23
413
414#define VPE_SC_MP_SC20 0x0750
415#define VPE_HPF_COEFF4_MASK 0xff
416#define VPE_HPF_COEFF4_SHIFT 0
417#define VPE_HPF_COEFF5_MASK 0xff
418#define VPE_HPF_COEFF5_SHIFT 8
419#define VPE_HPF_NORM_SHIFT_MASK 0x07
420#define VPE_HPF_NORM_SHIFT_SHIFT 16
421#define VPE_NL_LIMIT_MASK 0x1ff
422#define VPE_NL_LIMIT_SHIFT 20
423
424#define VPE_SC_MP_SC21 0x0754
425#define VPE_NL_LO_THR_MASK 0x01ff
426#define VPE_NL_LO_THR_SHIFT 0
427#define VPE_NL_LO_SLOPE_MASK 0xff
428#define VPE_NL_LO_SLOPE_SHIFT 16
429
430#define VPE_SC_MP_SC22 0x0758
431#define VPE_NL_HI_THR_MASK 0x01ff
432#define VPE_NL_HI_THR_SHIFT 0
433#define VPE_NL_HI_SLOPE_SH_MASK 0x07
434#define VPE_NL_HI_SLOPE_SH_SHIFT 16
435
436#define VPE_SC_MP_SC23 0x075c
437#define VPE_GRADIENT_THR_MASK 0x07ff
438#define VPE_GRADIENT_THR_SHIFT 0
439#define VPE_GRADIENT_THR_RANGE_MASK 0x0f
440#define VPE_GRADIENT_THR_RANGE_SHIFT 12
441#define VPE_MIN_GY_THR_MASK 0xff
442#define VPE_MIN_GY_THR_SHIFT 16
443#define VPE_MIN_GY_THR_RANGE_MASK 0x0f
444#define VPE_MIN_GY_THR_RANGE_SHIFT 28
445
446#define VPE_SC_MP_SC24 0x0760
447#define VPE_ORG_H_MASK 0x07ff
448#define VPE_ORG_H_SHIFT 0
449#define VPE_ORG_W_MASK 0x07ff
450#define VPE_ORG_W_SHIFT 16
451
452#define VPE_SC_MP_SC25 0x0764
453#define VPE_OFF_H_MASK 0x07ff
454#define VPE_OFF_H_SHIFT 0
455#define VPE_OFF_W_MASK 0x07ff
456#define VPE_OFF_W_SHIFT 16
457
458/* VPE color space converter regs */
459#define VPE_CSC_CSC00 0x5700
460#define VPE_CSC_A0_MASK 0x1fff
461#define VPE_CSC_A0_SHIFT 0
462#define VPE_CSC_B0_MASK 0x1fff
463#define VPE_CSC_B0_SHIFT 16
464
465#define VPE_CSC_CSC01 0x5704
466#define VPE_CSC_C0_MASK 0x1fff
467#define VPE_CSC_C0_SHIFT 0
468#define VPE_CSC_A1_MASK 0x1fff
469#define VPE_CSC_A1_SHIFT 16
470
471#define VPE_CSC_CSC02 0x5708
472#define VPE_CSC_B1_MASK 0x1fff
473#define VPE_CSC_B1_SHIFT 0
474#define VPE_CSC_C1_MASK 0x1fff
475#define VPE_CSC_C1_SHIFT 16
476
477#define VPE_CSC_CSC03 0x570c
478#define VPE_CSC_A2_MASK 0x1fff
479#define VPE_CSC_A2_SHIFT 0
480#define VPE_CSC_B2_MASK 0x1fff
481#define VPE_CSC_B2_SHIFT 16
482
483#define VPE_CSC_CSC04 0x5710
484#define VPE_CSC_C2_MASK 0x1fff
485#define VPE_CSC_C2_SHIFT 0
486#define VPE_CSC_D0_MASK 0x0fff
487#define VPE_CSC_D0_SHIFT 16
488
489#define VPE_CSC_CSC05 0x5714
490#define VPE_CSC_D1_MASK 0x0fff
491#define VPE_CSC_D1_SHIFT 0
492#define VPE_CSC_D2_MASK 0x0fff
493#define VPE_CSC_D2_SHIFT 16
494#define VPE_CSC_BYPASS (1 << 28)
495
496#endif
diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
index b557caf5b1a4..6a74ce040d28 100644
--- a/drivers/media/platform/timblogiw.c
+++ b/drivers/media/platform/timblogiw.c
@@ -403,7 +403,7 @@ static int timblogiw_s_input(struct file *file, void *priv, unsigned int input)
403 return 0; 403 return 0;
404} 404}
405 405
406static int timblogiw_streamon(struct file *file, void *priv, unsigned int type) 406static int timblogiw_streamon(struct file *file, void *priv, enum v4l2_buf_type type)
407{ 407{
408 struct video_device *vdev = video_devdata(file); 408 struct video_device *vdev = video_devdata(file);
409 struct timblogiw_fh *fh = priv; 409 struct timblogiw_fh *fh = priv;
@@ -420,7 +420,7 @@ static int timblogiw_streamon(struct file *file, void *priv, unsigned int type)
420} 420}
421 421
422static int timblogiw_streamoff(struct file *file, void *priv, 422static int timblogiw_streamoff(struct file *file, void *priv,
423 unsigned int type) 423 enum v4l2_buf_type type)
424{ 424{
425 struct video_device *vdev = video_devdata(file); 425 struct video_device *vdev = video_devdata(file);
426 struct timblogiw_fh *fh = priv; 426 struct timblogiw_fh *fh = priv;
diff --git a/drivers/media/radio/radio-keene.c b/drivers/media/radio/radio-keene.c
index 21db23b196be..fa3964022b96 100644
--- a/drivers/media/radio/radio-keene.c
+++ b/drivers/media/radio/radio-keene.c
@@ -123,7 +123,7 @@ static int keene_cmd_set(struct keene_device *radio)
123 /* If bit 0 is set, then transmit mono, otherwise stereo. 123 /* If bit 0 is set, then transmit mono, otherwise stereo.
124 If bit 2 is set, then enable 75 us preemphasis, otherwise 124 If bit 2 is set, then enable 75 us preemphasis, otherwise
125 it is 50 us. */ 125 it is 50 us. */
126 radio->buffer[3] = (!radio->stereo) | (radio->preemph_75_us ? 4 : 0); 126 radio->buffer[3] = (radio->stereo ? 0 : 1) | (radio->preemph_75_us ? 4 : 0);
127 radio->buffer[4] = 0x00; 127 radio->buffer[4] = 0x00;
128 radio->buffer[5] = 0x00; 128 radio->buffer[5] = 0x00;
129 radio->buffer[6] = 0x00; 129 radio->buffer[6] = 0x00;
diff --git a/drivers/media/radio/radio-sf16fmr2.c b/drivers/media/radio/radio-sf16fmr2.c
index f1e3714b5f16..93d864eb8306 100644
--- a/drivers/media/radio/radio-sf16fmr2.c
+++ b/drivers/media/radio/radio-sf16fmr2.c
@@ -74,8 +74,8 @@ static u8 fmr2_tea575x_get_pins(struct snd_tea575x *tea)
74 struct fmr2 *fmr2 = tea->private_data; 74 struct fmr2 *fmr2 = tea->private_data;
75 u8 bits = inb(fmr2->io); 75 u8 bits = inb(fmr2->io);
76 76
77 return (bits & STR_DATA) ? TEA575X_DATA : 0 | 77 return ((bits & STR_DATA) ? TEA575X_DATA : 0) |
78 (bits & STR_MOST) ? TEA575X_MOST : 0; 78 ((bits & STR_MOST) ? TEA575X_MOST : 0);
79} 79}
80 80
81static void fmr2_tea575x_set_direction(struct snd_tea575x *tea, bool output) 81static void fmr2_tea575x_set_direction(struct snd_tea575x *tea, bool output)
@@ -295,7 +295,6 @@ static void fmr2_remove(struct fmr2 *fmr2)
295static int fmr2_isa_remove(struct device *pdev, unsigned int ndev) 295static int fmr2_isa_remove(struct device *pdev, unsigned int ndev)
296{ 296{
297 fmr2_remove(dev_get_drvdata(pdev)); 297 fmr2_remove(dev_get_drvdata(pdev));
298 dev_set_drvdata(pdev, NULL);
299 298
300 return 0; 299 return 0;
301} 300}
diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
index b91477212413..3db8a8cfe1a8 100644
--- a/drivers/media/radio/radio-shark.c
+++ b/drivers/media/radio/radio-shark.c
@@ -271,6 +271,7 @@ static void shark_unregister_leds(struct shark_device *shark)
271 cancel_work_sync(&shark->led_work); 271 cancel_work_sync(&shark->led_work);
272} 272}
273 273
274#ifdef CONFIG_PM
274static void shark_resume_leds(struct shark_device *shark) 275static void shark_resume_leds(struct shark_device *shark)
275{ 276{
276 if (test_bit(BLUE_IS_PULSE, &shark->brightness_new)) 277 if (test_bit(BLUE_IS_PULSE, &shark->brightness_new))
@@ -280,6 +281,7 @@ static void shark_resume_leds(struct shark_device *shark)
280 set_bit(RED_LED, &shark->brightness_new); 281 set_bit(RED_LED, &shark->brightness_new);
281 schedule_work(&shark->led_work); 282 schedule_work(&shark->led_work);
282} 283}
284#endif
283#else 285#else
284static int shark_register_leds(struct shark_device *shark, struct device *dev) 286static int shark_register_leds(struct shark_device *shark, struct device *dev)
285{ 287{
diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
index 9fb669721e66..d86d90dab8bf 100644
--- a/drivers/media/radio/radio-shark2.c
+++ b/drivers/media/radio/radio-shark2.c
@@ -237,6 +237,7 @@ static void shark_unregister_leds(struct shark_device *shark)
237 cancel_work_sync(&shark->led_work); 237 cancel_work_sync(&shark->led_work);
238} 238}
239 239
240#ifdef CONFIG_PM
240static void shark_resume_leds(struct shark_device *shark) 241static void shark_resume_leds(struct shark_device *shark)
241{ 242{
242 int i; 243 int i;
@@ -246,6 +247,7 @@ static void shark_resume_leds(struct shark_device *shark)
246 247
247 schedule_work(&shark->led_work); 248 schedule_work(&shark->led_work);
248} 249}
250#endif
249#else 251#else
250static int shark_register_leds(struct shark_device *shark, struct device *dev) 252static int shark_register_leds(struct shark_device *shark, struct device *dev)
251{ 253{
diff --git a/drivers/media/radio/si470x/radio-si470x-common.c b/drivers/media/radio/si470x/radio-si470x-common.c
index 0bd250068285..0e750aef656a 100644
--- a/drivers/media/radio/si470x/radio-si470x-common.c
+++ b/drivers/media/radio/si470x/radio-si470x-common.c
@@ -254,7 +254,7 @@ static unsigned int si470x_get_step(struct si470x_device *radio)
254 /* 2: 50 kHz */ 254 /* 2: 50 kHz */
255 default: 255 default:
256 return 50 * 16; 256 return 50 * 16;
257 }; 257 }
258} 258}
259 259
260 260
diff --git a/drivers/media/radio/si470x/radio-si470x-i2c.c b/drivers/media/radio/si470x/radio-si470x-i2c.c
index e5fc9acd0c4f..2a497c80c77f 100644
--- a/drivers/media/radio/si470x/radio-si470x-i2c.c
+++ b/drivers/media/radio/si470x/radio-si470x-i2c.c
@@ -463,7 +463,7 @@ static int si470x_i2c_remove(struct i2c_client *client)
463} 463}
464 464
465 465
466#ifdef CONFIG_PM 466#ifdef CONFIG_PM_SLEEP
467/* 467/*
468 * si470x_i2c_suspend - suspend the device 468 * si470x_i2c_suspend - suspend the device
469 */ 469 */
@@ -509,7 +509,7 @@ static struct i2c_driver si470x_i2c_driver = {
509 .driver = { 509 .driver = {
510 .name = "si470x", 510 .name = "si470x",
511 .owner = THIS_MODULE, 511 .owner = THIS_MODULE,
512#ifdef CONFIG_PM 512#ifdef CONFIG_PM_SLEEP
513 .pm = &si470x_i2c_pm, 513 .pm = &si470x_i2c_pm,
514#endif 514#endif
515 }, 515 },
diff --git a/drivers/media/radio/si4713-i2c.c b/drivers/media/radio/si4713-i2c.c
index fe160882ee10..9ec48ccbcf0b 100644
--- a/drivers/media/radio/si4713-i2c.c
+++ b/drivers/media/radio/si4713-i2c.c
@@ -1456,7 +1456,7 @@ static int si4713_probe(struct i2c_client *client,
1456 1456
1457 if (client->irq) { 1457 if (client->irq) {
1458 rval = request_irq(client->irq, 1458 rval = request_irq(client->irq,
1459 si4713_handler, IRQF_TRIGGER_FALLING | IRQF_DISABLED, 1459 si4713_handler, IRQF_TRIGGER_FALLING,
1460 client->name, sdev); 1460 client->name, sdev);
1461 if (rval < 0) { 1461 if (rval < 0) {
1462 v4l2_err(&sdev->sd, "Could not request IRQ\n"); 1462 v4l2_err(&sdev->sd, "Could not request IRQ\n");
diff --git a/drivers/media/radio/tef6862.c b/drivers/media/radio/tef6862.c
index 06ac69245ca1..69e3245a58a0 100644
--- a/drivers/media/radio/tef6862.c
+++ b/drivers/media/radio/tef6862.c
@@ -48,15 +48,15 @@
48#define WM_SUB_TEST 0xF 48#define WM_SUB_TEST 0xF
49 49
50/* Different modes of the MSA register */ 50/* Different modes of the MSA register */
51#define MODE_BUFFER 0x0 51#define MSA_MODE_BUFFER 0x0
52#define MODE_PRESET 0x1 52#define MSA_MODE_PRESET 0x1
53#define MODE_SEARCH 0x2 53#define MSA_MODE_SEARCH 0x2
54#define MODE_AF_UPDATE 0x3 54#define MSA_MODE_AF_UPDATE 0x3
55#define MODE_JUMP 0x4 55#define MSA_MODE_JUMP 0x4
56#define MODE_CHECK 0x5 56#define MSA_MODE_CHECK 0x5
57#define MODE_LOAD 0x6 57#define MSA_MODE_LOAD 0x6
58#define MODE_END 0x7 58#define MSA_MODE_END 0x7
59#define MODE_SHIFT 5 59#define MSA_MODE_SHIFT 5
60 60
61struct tef6862_state { 61struct tef6862_state {
62 struct v4l2_subdev sd; 62 struct v4l2_subdev sd;
@@ -114,7 +114,7 @@ static int tef6862_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequen
114 114
115 clamp(freq, TEF6862_LO_FREQ, TEF6862_HI_FREQ); 115 clamp(freq, TEF6862_LO_FREQ, TEF6862_HI_FREQ);
116 pll = 1964 + ((freq - TEF6862_LO_FREQ) * 20) / FREQ_MUL; 116 pll = 1964 + ((freq - TEF6862_LO_FREQ) * 20) / FREQ_MUL;
117 i2cmsg[0] = (MODE_PRESET << MODE_SHIFT) | WM_SUB_PLLM; 117 i2cmsg[0] = (MSA_MODE_PRESET << MSA_MODE_SHIFT) | WM_SUB_PLLM;
118 i2cmsg[1] = (pll >> 8) & 0xff; 118 i2cmsg[1] = (pll >> 8) & 0xff;
119 i2cmsg[2] = pll & 0xff; 119 i2cmsg[2] = pll & 0xff;
120 120
diff --git a/drivers/media/radio/wl128x/fmdrv_common.c b/drivers/media/radio/wl128x/fmdrv_common.c
index 253f307f0b37..4b2e9e8298e1 100644
--- a/drivers/media/radio/wl128x/fmdrv_common.c
+++ b/drivers/media/radio/wl128x/fmdrv_common.c
@@ -175,7 +175,7 @@ static int_handler_prototype int_handler_table[] = {
175 fm_irq_handle_intmsk_cmd_resp 175 fm_irq_handle_intmsk_cmd_resp
176}; 176};
177 177
178long (*g_st_write) (struct sk_buff *skb); 178static long (*g_st_write) (struct sk_buff *skb);
179static struct completion wait_for_fmdrv_reg_comp; 179static struct completion wait_for_fmdrv_reg_comp;
180 180
181static inline void fm_irq_call(struct fmdev *fmdev) 181static inline void fm_irq_call(struct fmdev *fmdev)
diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 11e84bcc23a1..904f11367c29 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -322,4 +322,14 @@ config IR_GPIO_CIR
322 To compile this driver as a module, choose M here: the module will 322 To compile this driver as a module, choose M here: the module will
323 be called gpio-ir-recv. 323 be called gpio-ir-recv.
324 324
325config RC_ST
326 tristate "ST remote control receiver"
327 depends on ARCH_STI && RC_CORE
328 help
329 Say Y here if you want support for ST remote control driver
330 which allows both IR and UHF RX.
331 The driver passes raw pulse and space information to the LIRC decoder.
332
333 If you're not sure, select N here.
334
325endif #RC_DEVICES 335endif #RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index 56bacf07b361..f4eb32c0a455 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -30,3 +30,4 @@ obj-$(CONFIG_RC_LOOPBACK) += rc-loopback.o
30obj-$(CONFIG_IR_GPIO_CIR) += gpio-ir-recv.o 30obj-$(CONFIG_IR_GPIO_CIR) += gpio-ir-recv.o
31obj-$(CONFIG_IR_IGUANA) += iguanair.o 31obj-$(CONFIG_IR_IGUANA) += iguanair.o
32obj-$(CONFIG_IR_TTUSBIR) += ttusbir.o 32obj-$(CONFIG_IR_TTUSBIR) += ttusbir.o
33obj-$(CONFIG_RC_ST) += st_rc.o
diff --git a/drivers/media/rc/fintek-cir.h b/drivers/media/rc/fintek-cir.h
index 82516a1d39b0..b698f3d2ced9 100644
--- a/drivers/media/rc/fintek-cir.h
+++ b/drivers/media/rc/fintek-cir.h
@@ -76,8 +76,8 @@ struct fintek_dev {
76 } tx; 76 } tx;
77 77
78 /* Config register index/data port pair */ 78 /* Config register index/data port pair */
79 u8 cr_ip; 79 u32 cr_ip;
80 u8 cr_dp; 80 u32 cr_dp;
81 81
82 /* hardware I/O settings */ 82 /* hardware I/O settings */
83 unsigned long cir_addr; 83 unsigned long cir_addr;
diff --git a/drivers/media/rc/gpio-ir-recv.c b/drivers/media/rc/gpio-ir-recv.c
index 07aacfa5903d..80c611c2e8c2 100644
--- a/drivers/media/rc/gpio-ir-recv.c
+++ b/drivers/media/rc/gpio-ir-recv.c
@@ -16,6 +16,7 @@
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/gpio.h> 17#include <linux/gpio.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/of.h>
19#include <linux/of_gpio.h> 20#include <linux/of_gpio.h>
20#include <linux/platform_device.h> 21#include <linux/platform_device.h>
21#include <linux/irq.h> 22#include <linux/irq.h>
diff --git a/drivers/media/rc/iguanair.c b/drivers/media/rc/iguanair.c
index b53626ba6f49..fdae05c4f377 100644
--- a/drivers/media/rc/iguanair.c
+++ b/drivers/media/rc/iguanair.c
@@ -308,22 +308,12 @@ static int iguanair_set_tx_carrier(struct rc_dev *dev, uint32_t carrier)
308 cycles = DIV_ROUND_CLOSEST(24000000, carrier * 2) - 308 cycles = DIV_ROUND_CLOSEST(24000000, carrier * 2) -
309 ir->cycle_overhead; 309 ir->cycle_overhead;
310 310
311 /* make up the the remainer of 4-cycle blocks */ 311 /*
312 switch (cycles & 3) { 312 * Calculate minimum number of 7 cycles needed so
313 case 0: 313 * we are left with a multiple of 4; so we want to have
314 sevens = 0; 314 * (sevens * 7) & 3 == cycles & 3
315 break; 315 */
316 case 1: 316 sevens = (4 - cycles) & 3;
317 sevens = 3;
318 break;
319 case 2:
320 sevens = 2;
321 break;
322 case 3:
323 sevens = 1;
324 break;
325 }
326
327 fours = (cycles - sevens * 7) / 4; 317 fours = (cycles - sevens * 7) / 4;
328 318
329 /* magic happens here */ 319 /* magic happens here */
diff --git a/drivers/media/rc/ir-rx51.c b/drivers/media/rc/ir-rx51.c
index 31b955bf7664..b1e19a26208d 100644
--- a/drivers/media/rc/ir-rx51.c
+++ b/drivers/media/rc/ir-rx51.c
@@ -201,8 +201,7 @@ static int lirc_rx51_init_port(struct lirc_rx51 *lirc_rx51)
201 201
202 lirc_rx51->irq_num = omap_dm_timer_get_irq(lirc_rx51->pulse_timer); 202 lirc_rx51->irq_num = omap_dm_timer_get_irq(lirc_rx51->pulse_timer);
203 retval = request_irq(lirc_rx51->irq_num, lirc_rx51_interrupt_handler, 203 retval = request_irq(lirc_rx51->irq_num, lirc_rx51_interrupt_handler,
204 IRQF_DISABLED | IRQF_SHARED, 204 IRQF_SHARED, "lirc_pulse_timer", lirc_rx51);
205 "lirc_pulse_timer", lirc_rx51);
206 if (retval) { 205 if (retval) {
207 dev_err(lirc_rx51->dev, ": Failed to request interrupt line\n"); 206 dev_err(lirc_rx51->dev, ": Failed to request interrupt line\n");
208 goto err2; 207 goto err2;
diff --git a/drivers/media/rc/nuvoton-cir.h b/drivers/media/rc/nuvoton-cir.h
index 7c3674ff5ea2..07e83108df0f 100644
--- a/drivers/media/rc/nuvoton-cir.h
+++ b/drivers/media/rc/nuvoton-cir.h
@@ -84,8 +84,8 @@ struct nvt_dev {
84 } tx; 84 } tx;
85 85
86 /* EFER Config register index/data pair */ 86 /* EFER Config register index/data pair */
87 u8 cr_efir; 87 u32 cr_efir;
88 u8 cr_efdr; 88 u32 cr_efdr;
89 89
90 /* hardware I/O settings */ 90 /* hardware I/O settings */
91 unsigned long cir_addr; 91 unsigned long cir_addr;
diff --git a/drivers/media/rc/st_rc.c b/drivers/media/rc/st_rc.c
new file mode 100644
index 000000000000..65120c2d47ad
--- /dev/null
+++ b/drivers/media/rc/st_rc.c
@@ -0,0 +1,395 @@
1/*
2 * Copyright (C) 2013 STMicroelectronics Limited
3 * Author: Srinivas Kandagatla <srinivas.kandagatla@st.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */
10#include <linux/kernel.h>
11#include <linux/clk.h>
12#include <linux/interrupt.h>
13#include <linux/module.h>
14#include <linux/of.h>
15#include <linux/platform_device.h>
16#include <media/rc-core.h>
17#include <linux/pinctrl/consumer.h>
18
19struct st_rc_device {
20 struct device *dev;
21 int irq;
22 int irq_wake;
23 struct clk *sys_clock;
24 void *base; /* Register base address */
25 void *rx_base;/* RX Register base address */
26 struct rc_dev *rdev;
27 bool overclocking;
28 int sample_mult;
29 int sample_div;
30 bool rxuhfmode;
31};
32
33/* Registers */
34#define IRB_SAMPLE_RATE_COMM 0x64 /* sample freq divisor*/
35#define IRB_CLOCK_SEL 0x70 /* clock select */
36#define IRB_CLOCK_SEL_STATUS 0x74 /* clock status */
37/* IRB IR/UHF receiver registers */
38#define IRB_RX_ON 0x40 /* pulse time capture */
39#define IRB_RX_SYS 0X44 /* sym period capture */
40#define IRB_RX_INT_EN 0x48 /* IRQ enable (R/W) */
41#define IRB_RX_INT_STATUS 0x4c /* IRQ status (R/W) */
42#define IRB_RX_EN 0x50 /* Receive enable */
43#define IRB_MAX_SYM_PERIOD 0x54 /* max sym value */
44#define IRB_RX_INT_CLEAR 0x58 /* overrun status */
45#define IRB_RX_STATUS 0x6c /* receive status */
46#define IRB_RX_NOISE_SUPPR 0x5c /* noise suppression */
47#define IRB_RX_POLARITY_INV 0x68 /* polarity inverter */
48
49/**
50 * IRQ set: Enable full FIFO 1 -> bit 3;
51 * Enable overrun IRQ 1 -> bit 2;
52 * Enable last symbol IRQ 1 -> bit 1:
53 * Enable RX interrupt 1 -> bit 0;
54 */
55#define IRB_RX_INTS 0x0f
56#define IRB_RX_OVERRUN_INT 0x04
57 /* maximum symbol period (microsecs),timeout to detect end of symbol train */
58#define MAX_SYMB_TIME 0x5000
59#define IRB_SAMPLE_FREQ 10000000
60#define IRB_FIFO_NOT_EMPTY 0xff00
61#define IRB_OVERFLOW 0x4
62#define IRB_TIMEOUT 0xffff
63#define IR_ST_NAME "st-rc"
64
65static void st_rc_send_lirc_timeout(struct rc_dev *rdev)
66{
67 DEFINE_IR_RAW_EVENT(ev);
68 ev.timeout = true;
69 ir_raw_event_store(rdev, &ev);
70}
71
72/**
73 * RX graphical example to better understand the difference between ST IR block
74 * output and standard definition used by LIRC (and most of the world!)
75 *
76 * mark mark
77 * |-IRB_RX_ON-| |-IRB_RX_ON-|
78 * ___ ___ ___ ___ ___ ___ _
79 * | | | | | | | | | | | | |
80 * | | | | | | space 0 | | | | | | space 1 |
81 * _____| |__| |__| |____________________________| |__| |__| |_____________|
82 *
83 * |--------------- IRB_RX_SYS -------------|------ IRB_RX_SYS -------|
84 *
85 * |------------- encoding bit 0 -----------|---- encoding bit 1 -----|
86 *
87 * ST hardware returns mark (IRB_RX_ON) and total symbol time (IRB_RX_SYS), so
88 * convert to standard mark/space we have to calculate space=(IRB_RX_SYS-mark)
89 * The mark time represents the amount of time the carrier (usually 36-40kHz)
90 * is detected.The above examples shows Pulse Width Modulation encoding where
91 * bit 0 is represented by space>mark.
92 */
93
94static irqreturn_t st_rc_rx_interrupt(int irq, void *data)
95{
96 unsigned int symbol, mark = 0;
97 struct st_rc_device *dev = data;
98 int last_symbol = 0;
99 u32 status;
100 DEFINE_IR_RAW_EVENT(ev);
101
102 if (dev->irq_wake)
103 pm_wakeup_event(dev->dev, 0);
104
105 status = readl(dev->rx_base + IRB_RX_STATUS);
106
107 while (status & (IRB_FIFO_NOT_EMPTY | IRB_OVERFLOW)) {
108 u32 int_status = readl(dev->rx_base + IRB_RX_INT_STATUS);
109 if (unlikely(int_status & IRB_RX_OVERRUN_INT)) {
110 /* discard the entire collection in case of errors! */
111 ir_raw_event_reset(dev->rdev);
112 dev_info(dev->dev, "IR RX overrun\n");
113 writel(IRB_RX_OVERRUN_INT,
114 dev->rx_base + IRB_RX_INT_CLEAR);
115 continue;
116 }
117
118 symbol = readl(dev->rx_base + IRB_RX_SYS);
119 mark = readl(dev->rx_base + IRB_RX_ON);
120
121 if (symbol == IRB_TIMEOUT)
122 last_symbol = 1;
123
124 /* Ignore any noise */
125 if ((mark > 2) && (symbol > 1)) {
126 symbol -= mark;
127 if (dev->overclocking) { /* adjustments to timings */
128 symbol *= dev->sample_mult;
129 symbol /= dev->sample_div;
130 mark *= dev->sample_mult;
131 mark /= dev->sample_div;
132 }
133
134 ev.duration = US_TO_NS(mark);
135 ev.pulse = true;
136 ir_raw_event_store(dev->rdev, &ev);
137
138 if (!last_symbol) {
139 ev.duration = US_TO_NS(symbol);
140 ev.pulse = false;
141 ir_raw_event_store(dev->rdev, &ev);
142 } else {
143 st_rc_send_lirc_timeout(dev->rdev);
144 }
145
146 }
147 last_symbol = 0;
148 status = readl(dev->rx_base + IRB_RX_STATUS);
149 }
150
151 writel(IRB_RX_INTS, dev->rx_base + IRB_RX_INT_CLEAR);
152
153 /* Empty software fifo */
154 ir_raw_event_handle(dev->rdev);
155 return IRQ_HANDLED;
156}
157
158static void st_rc_hardware_init(struct st_rc_device *dev)
159{
160 int baseclock, freqdiff;
161 unsigned int rx_max_symbol_per = MAX_SYMB_TIME;
162 unsigned int rx_sampling_freq_div;
163
164 clk_prepare_enable(dev->sys_clock);
165 baseclock = clk_get_rate(dev->sys_clock);
166
167 /* IRB input pins are inverted internally from high to low. */
168 writel(1, dev->rx_base + IRB_RX_POLARITY_INV);
169
170 rx_sampling_freq_div = baseclock / IRB_SAMPLE_FREQ;
171 writel(rx_sampling_freq_div, dev->base + IRB_SAMPLE_RATE_COMM);
172
173 freqdiff = baseclock - (rx_sampling_freq_div * IRB_SAMPLE_FREQ);
174 if (freqdiff) { /* over clocking, workout the adjustment factors */
175 dev->overclocking = true;
176 dev->sample_mult = 1000;
177 dev->sample_div = baseclock / (10000 * rx_sampling_freq_div);
178 rx_max_symbol_per = (rx_max_symbol_per * 1000)/dev->sample_div;
179 }
180
181 writel(rx_max_symbol_per, dev->rx_base + IRB_MAX_SYM_PERIOD);
182}
183
184static int st_rc_remove(struct platform_device *pdev)
185{
186 struct st_rc_device *rc_dev = platform_get_drvdata(pdev);
187 clk_disable_unprepare(rc_dev->sys_clock);
188 rc_unregister_device(rc_dev->rdev);
189 return 0;
190}
191
192static int st_rc_open(struct rc_dev *rdev)
193{
194 struct st_rc_device *dev = rdev->priv;
195 unsigned long flags;
196 local_irq_save(flags);
197 /* enable interrupts and receiver */
198 writel(IRB_RX_INTS, dev->rx_base + IRB_RX_INT_EN);
199 writel(0x01, dev->rx_base + IRB_RX_EN);
200 local_irq_restore(flags);
201
202 return 0;
203}
204
205static void st_rc_close(struct rc_dev *rdev)
206{
207 struct st_rc_device *dev = rdev->priv;
208 /* disable interrupts and receiver */
209 writel(0x00, dev->rx_base + IRB_RX_EN);
210 writel(0x00, dev->rx_base + IRB_RX_INT_EN);
211}
212
213static int st_rc_probe(struct platform_device *pdev)
214{
215 int ret = -EINVAL;
216 struct rc_dev *rdev;
217 struct device *dev = &pdev->dev;
218 struct resource *res;
219 struct st_rc_device *rc_dev;
220 struct device_node *np = pdev->dev.of_node;
221 const char *rx_mode;
222
223 rc_dev = devm_kzalloc(dev, sizeof(struct st_rc_device), GFP_KERNEL);
224
225 if (!rc_dev)
226 return -ENOMEM;
227
228 rdev = rc_allocate_device();
229
230 if (!rdev)
231 return -ENOMEM;
232
233 if (np && !of_property_read_string(np, "rx-mode", &rx_mode)) {
234
235 if (!strcmp(rx_mode, "uhf")) {
236 rc_dev->rxuhfmode = true;
237 } else if (!strcmp(rx_mode, "infrared")) {
238 rc_dev->rxuhfmode = false;
239 } else {
240 dev_err(dev, "Unsupported rx mode [%s]\n", rx_mode);
241 goto err;
242 }
243
244 } else {
245 goto err;
246 }
247
248 rc_dev->sys_clock = devm_clk_get(dev, NULL);
249 if (IS_ERR(rc_dev->sys_clock)) {
250 dev_err(dev, "System clock not found\n");
251 ret = PTR_ERR(rc_dev->sys_clock);
252 goto err;
253 }
254
255 rc_dev->irq = platform_get_irq(pdev, 0);
256 if (rc_dev->irq < 0) {
257 ret = rc_dev->irq;
258 goto err;
259 }
260
261 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
262
263 rc_dev->base = devm_ioremap_resource(dev, res);
264 if (IS_ERR(rc_dev->base)) {
265 ret = PTR_ERR(rc_dev->base);
266 goto err;
267 }
268
269 if (rc_dev->rxuhfmode)
270 rc_dev->rx_base = rc_dev->base + 0x40;
271 else
272 rc_dev->rx_base = rc_dev->base;
273
274 rc_dev->dev = dev;
275 platform_set_drvdata(pdev, rc_dev);
276 st_rc_hardware_init(rc_dev);
277
278 rdev->driver_type = RC_DRIVER_IR_RAW;
279 rdev->allowed_protos = RC_BIT_ALL;
280 /* rx sampling rate is 10Mhz */
281 rdev->rx_resolution = 100;
282 rdev->timeout = US_TO_NS(MAX_SYMB_TIME);
283 rdev->priv = rc_dev;
284 rdev->open = st_rc_open;
285 rdev->close = st_rc_close;
286 rdev->driver_name = IR_ST_NAME;
287 rdev->map_name = RC_MAP_LIRC;
288 rdev->input_name = "ST Remote Control Receiver";
289
290 /* enable wake via this device */
291 device_set_wakeup_capable(dev, true);
292 device_set_wakeup_enable(dev, true);
293
294 ret = rc_register_device(rdev);
295 if (ret < 0)
296 goto clkerr;
297
298 rc_dev->rdev = rdev;
299 if (devm_request_irq(dev, rc_dev->irq, st_rc_rx_interrupt,
300 IRQF_NO_SUSPEND, IR_ST_NAME, rc_dev) < 0) {
301 dev_err(dev, "IRQ %d register failed\n", rc_dev->irq);
302 ret = -EINVAL;
303 goto rcerr;
304 }
305
306 /**
307 * for LIRC_MODE_MODE2 or LIRC_MODE_PULSE or LIRC_MODE_RAW
308 * lircd expects a long space first before a signal train to sync.
309 */
310 st_rc_send_lirc_timeout(rdev);
311
312 dev_info(dev, "setup in %s mode\n", rc_dev->rxuhfmode ? "UHF" : "IR");
313
314 return ret;
315rcerr:
316 rc_unregister_device(rdev);
317 rdev = NULL;
318clkerr:
319 clk_disable_unprepare(rc_dev->sys_clock);
320err:
321 rc_free_device(rdev);
322 dev_err(dev, "Unable to register device (%d)\n", ret);
323 return ret;
324}
325
326#ifdef CONFIG_PM
327static int st_rc_suspend(struct device *dev)
328{
329 struct st_rc_device *rc_dev = dev_get_drvdata(dev);
330
331 if (device_may_wakeup(dev)) {
332 if (!enable_irq_wake(rc_dev->irq))
333 rc_dev->irq_wake = 1;
334 else
335 return -EINVAL;
336 } else {
337 pinctrl_pm_select_sleep_state(dev);
338 writel(0x00, rc_dev->rx_base + IRB_RX_EN);
339 writel(0x00, rc_dev->rx_base + IRB_RX_INT_EN);
340 clk_disable_unprepare(rc_dev->sys_clock);
341 }
342
343 return 0;
344}
345
346static int st_rc_resume(struct device *dev)
347{
348 struct st_rc_device *rc_dev = dev_get_drvdata(dev);
349 struct rc_dev *rdev = rc_dev->rdev;
350
351 if (rc_dev->irq_wake) {
352 disable_irq_wake(rc_dev->irq);
353 rc_dev->irq_wake = 0;
354 } else {
355 pinctrl_pm_select_default_state(dev);
356 st_rc_hardware_init(rc_dev);
357 if (rdev->users) {
358 writel(IRB_RX_INTS, rc_dev->rx_base + IRB_RX_INT_EN);
359 writel(0x01, rc_dev->rx_base + IRB_RX_EN);
360 }
361 }
362
363 return 0;
364}
365
366static SIMPLE_DEV_PM_OPS(st_rc_pm_ops, st_rc_suspend, st_rc_resume);
367#endif
368
369#ifdef CONFIG_OF
370static struct of_device_id st_rc_match[] = {
371 { .compatible = "st,comms-irb", },
372 {},
373};
374
375MODULE_DEVICE_TABLE(of, st_rc_match);
376#endif
377
378static struct platform_driver st_rc_driver = {
379 .driver = {
380 .name = IR_ST_NAME,
381 .owner = THIS_MODULE,
382 .of_match_table = of_match_ptr(st_rc_match),
383#ifdef CONFIG_PM
384 .pm = &st_rc_pm_ops,
385#endif
386 },
387 .probe = st_rc_probe,
388 .remove = st_rc_remove,
389};
390
391module_platform_driver(st_rc_driver);
392
393MODULE_DESCRIPTION("RC Transceiver driver for STMicroelectronics platforms");
394MODULE_AUTHOR("STMicroelectronics (R&D) Ltd");
395MODULE_LICENSE("GPL");
diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index 98bd4960c75e..904baf4eec28 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -1110,7 +1110,7 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id)
1110 } 1110 }
1111 1111
1112 err = request_irq(data->irq, wbcir_irq_handler, 1112 err = request_irq(data->irq, wbcir_irq_handler,
1113 IRQF_DISABLED, DRVNAME, device); 1113 0, DRVNAME, device);
1114 if (err) { 1114 if (err) {
1115 dev_err(dev, "Failed to claim IRQ %u\n", data->irq); 1115 dev_err(dev, "Failed to claim IRQ %u\n", data->irq);
1116 err = -EBUSY; 1116 err = -EBUSY;
diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index 6c96e4898777..72971a8d3c37 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -21,20 +21,30 @@
21#include "e4000_priv.h" 21#include "e4000_priv.h"
22#include <linux/math64.h> 22#include <linux/math64.h>
23 23
24/* Max transfer size done by I2C transfer functions */
25#define MAX_XFER_SIZE 64
26
24/* write multiple registers */ 27/* write multiple registers */
25static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len) 28static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
26{ 29{
27 int ret; 30 int ret;
28 u8 buf[1 + len]; 31 u8 buf[MAX_XFER_SIZE];
29 struct i2c_msg msg[1] = { 32 struct i2c_msg msg[1] = {
30 { 33 {
31 .addr = priv->cfg->i2c_addr, 34 .addr = priv->cfg->i2c_addr,
32 .flags = 0, 35 .flags = 0,
33 .len = sizeof(buf), 36 .len = 1 + len,
34 .buf = buf, 37 .buf = buf,
35 } 38 }
36 }; 39 };
37 40
41 if (1 + len > sizeof(buf)) {
42 dev_warn(&priv->i2c->dev,
43 "%s: i2c wr reg=%04x: len=%d is too big!\n",
44 KBUILD_MODNAME, reg, len);
45 return -EINVAL;
46 }
47
38 buf[0] = reg; 48 buf[0] = reg;
39 memcpy(&buf[1], val, len); 49 memcpy(&buf[1], val, len);
40 50
@@ -54,7 +64,7 @@ static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
54static int e4000_rd_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len) 64static int e4000_rd_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
55{ 65{
56 int ret; 66 int ret;
57 u8 buf[len]; 67 u8 buf[MAX_XFER_SIZE];
58 struct i2c_msg msg[2] = { 68 struct i2c_msg msg[2] = {
59 { 69 {
60 .addr = priv->cfg->i2c_addr, 70 .addr = priv->cfg->i2c_addr,
@@ -64,11 +74,18 @@ static int e4000_rd_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
64 }, { 74 }, {
65 .addr = priv->cfg->i2c_addr, 75 .addr = priv->cfg->i2c_addr,
66 .flags = I2C_M_RD, 76 .flags = I2C_M_RD,
67 .len = sizeof(buf), 77 .len = len,
68 .buf = buf, 78 .buf = buf,
69 } 79 }
70 }; 80 };
71 81
82 if (len > sizeof(buf)) {
83 dev_warn(&priv->i2c->dev,
84 "%s: i2c rd reg=%04x: len=%d is too big!\n",
85 KBUILD_MODNAME, reg, len);
86 return -EINVAL;
87 }
88
72 ret = i2c_transfer(priv->i2c, msg, 2); 89 ret = i2c_transfer(priv->i2c, msg, 2);
73 if (ret == 2) { 90 if (ret == 2) {
74 memcpy(val, buf, len); 91 memcpy(val, buf, len);
diff --git a/drivers/media/tuners/fc0012.c b/drivers/media/tuners/fc0012.c
index f4d0e797a6cc..d74e92056810 100644
--- a/drivers/media/tuners/fc0012.c
+++ b/drivers/media/tuners/fc0012.c
@@ -139,7 +139,7 @@ static int fc0012_set_params(struct dvb_frontend *fe)
139 unsigned char reg[7], am, pm, multi, tmp; 139 unsigned char reg[7], am, pm, multi, tmp;
140 unsigned long f_vco; 140 unsigned long f_vco;
141 unsigned short xtal_freq_khz_2, xin, xdiv; 141 unsigned short xtal_freq_khz_2, xin, xdiv;
142 int vco_select = false; 142 bool vco_select = false;
143 143
144 if (fe->callback) { 144 if (fe->callback) {
145 ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, 145 ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
diff --git a/drivers/media/tuners/fc0013.c b/drivers/media/tuners/fc0013.c
index bd8f0f1e8f3b..b4162315773d 100644
--- a/drivers/media/tuners/fc0013.c
+++ b/drivers/media/tuners/fc0013.c
@@ -233,7 +233,7 @@ static int fc0013_set_params(struct dvb_frontend *fe)
233 unsigned char reg[7], am, pm, multi, tmp; 233 unsigned char reg[7], am, pm, multi, tmp;
234 unsigned long f_vco; 234 unsigned long f_vco;
235 unsigned short xtal_freq_khz_2, xin, xdiv; 235 unsigned short xtal_freq_khz_2, xin, xdiv;
236 int vco_select = false; 236 bool vco_select = false;
237 237
238 if (fe->callback) { 238 if (fe->callback) {
239 ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, 239 ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
diff --git a/drivers/media/tuners/fc2580.c b/drivers/media/tuners/fc2580.c
index 81f38aae9c66..3aecaf465094 100644
--- a/drivers/media/tuners/fc2580.c
+++ b/drivers/media/tuners/fc2580.c
@@ -20,6 +20,9 @@
20 20
21#include "fc2580_priv.h" 21#include "fc2580_priv.h"
22 22
23/* Max transfer size done by I2C transfer functions */
24#define MAX_XFER_SIZE 64
25
23/* 26/*
24 * TODO: 27 * TODO:
25 * I2C write and read works only for one single register. Multiple registers 28 * I2C write and read works only for one single register. Multiple registers
@@ -41,16 +44,23 @@
41static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len) 44static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
42{ 45{
43 int ret; 46 int ret;
44 u8 buf[1 + len]; 47 u8 buf[MAX_XFER_SIZE];
45 struct i2c_msg msg[1] = { 48 struct i2c_msg msg[1] = {
46 { 49 {
47 .addr = priv->cfg->i2c_addr, 50 .addr = priv->cfg->i2c_addr,
48 .flags = 0, 51 .flags = 0,
49 .len = sizeof(buf), 52 .len = 1 + len,
50 .buf = buf, 53 .buf = buf,
51 } 54 }
52 }; 55 };
53 56
57 if (1 + len > sizeof(buf)) {
58 dev_warn(&priv->i2c->dev,
59 "%s: i2c wr reg=%04x: len=%d is too big!\n",
60 KBUILD_MODNAME, reg, len);
61 return -EINVAL;
62 }
63
54 buf[0] = reg; 64 buf[0] = reg;
55 memcpy(&buf[1], val, len); 65 memcpy(&buf[1], val, len);
56 66
@@ -69,7 +79,7 @@ static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
69static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len) 79static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
70{ 80{
71 int ret; 81 int ret;
72 u8 buf[len]; 82 u8 buf[MAX_XFER_SIZE];
73 struct i2c_msg msg[2] = { 83 struct i2c_msg msg[2] = {
74 { 84 {
75 .addr = priv->cfg->i2c_addr, 85 .addr = priv->cfg->i2c_addr,
@@ -79,11 +89,18 @@ static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
79 }, { 89 }, {
80 .addr = priv->cfg->i2c_addr, 90 .addr = priv->cfg->i2c_addr,
81 .flags = I2C_M_RD, 91 .flags = I2C_M_RD,
82 .len = sizeof(buf), 92 .len = len,
83 .buf = buf, 93 .buf = buf,
84 } 94 }
85 }; 95 };
86 96
97 if (len > sizeof(buf)) {
98 dev_warn(&priv->i2c->dev,
99 "%s: i2c rd reg=%04x: len=%d is too big!\n",
100 KBUILD_MODNAME, reg, len);
101 return -EINVAL;
102 }
103
87 ret = i2c_transfer(priv->i2c, msg, 2); 104 ret = i2c_transfer(priv->i2c, msg, 2);
88 if (ret == 2) { 105 if (ret == 2) {
89 memcpy(val, buf, len); 106 memcpy(val, buf, len);
diff --git a/drivers/media/tuners/r820t.c b/drivers/media/tuners/r820t.c
index 1c23666468cf..d9ee43fae62d 100644
--- a/drivers/media/tuners/r820t.c
+++ b/drivers/media/tuners/r820t.c
@@ -612,10 +612,19 @@ static int r820t_set_pll(struct r820t_priv *priv, enum v4l2_tuner_type type,
612 612
613 vco_fine_tune = (data[4] & 0x30) >> 4; 613 vco_fine_tune = (data[4] & 0x30) >> 4;
614 614
615 if (vco_fine_tune > VCO_POWER_REF) 615 tuner_dbg("mix_div=%d div_num=%d vco_fine_tune=%d\n",
616 div_num = div_num - 1; 616 mix_div, div_num, vco_fine_tune);
617 else if (vco_fine_tune < VCO_POWER_REF) 617
618 div_num = div_num + 1; 618 /*
619 * XXX: R828D/16MHz seems to have always vco_fine_tune=1.
620 * Due to that, this calculation goes wrong.
621 */
622 if (priv->cfg->rafael_chip != CHIP_R828D) {
623 if (vco_fine_tune > VCO_POWER_REF)
624 div_num = div_num - 1;
625 else if (vco_fine_tune < VCO_POWER_REF)
626 div_num = div_num + 1;
627 }
619 628
620 rc = r820t_write_reg_mask(priv, 0x10, div_num << 5, 0xe0); 629 rc = r820t_write_reg_mask(priv, 0x10, div_num << 5, 0xe0);
621 if (rc < 0) 630 if (rc < 0)
@@ -637,11 +646,6 @@ static int r820t_set_pll(struct r820t_priv *priv, enum v4l2_tuner_type type,
637 vco_fra = pll_ref * 129 / 128; 646 vco_fra = pll_ref * 129 / 128;
638 } 647 }
639 648
640 if (nint > 63) {
641 tuner_info("No valid PLL values for %u kHz!\n", freq);
642 return -EINVAL;
643 }
644
645 ni = (nint - 13) / 4; 649 ni = (nint - 13) / 4;
646 si = nint - 4 * ni - 13; 650 si = nint - 4 * ni - 13;
647 651
diff --git a/drivers/media/tuners/tda18212.c b/drivers/media/tuners/tda18212.c
index e4a84ee231cf..abe256e1f843 100644
--- a/drivers/media/tuners/tda18212.c
+++ b/drivers/media/tuners/tda18212.c
@@ -20,6 +20,9 @@
20 20
21#include "tda18212.h" 21#include "tda18212.h"
22 22
23/* Max transfer size done by I2C transfer functions */
24#define MAX_XFER_SIZE 64
25
23struct tda18212_priv { 26struct tda18212_priv {
24 struct tda18212_config *cfg; 27 struct tda18212_config *cfg;
25 struct i2c_adapter *i2c; 28 struct i2c_adapter *i2c;
@@ -32,16 +35,23 @@ static int tda18212_wr_regs(struct tda18212_priv *priv, u8 reg, u8 *val,
32 int len) 35 int len)
33{ 36{
34 int ret; 37 int ret;
35 u8 buf[len+1]; 38 u8 buf[MAX_XFER_SIZE];
36 struct i2c_msg msg[1] = { 39 struct i2c_msg msg[1] = {
37 { 40 {
38 .addr = priv->cfg->i2c_address, 41 .addr = priv->cfg->i2c_address,
39 .flags = 0, 42 .flags = 0,
40 .len = sizeof(buf), 43 .len = 1 + len,
41 .buf = buf, 44 .buf = buf,
42 } 45 }
43 }; 46 };
44 47
48 if (1 + len > sizeof(buf)) {
49 dev_warn(&priv->i2c->dev,
50 "%s: i2c wr reg=%04x: len=%d is too big!\n",
51 KBUILD_MODNAME, reg, len);
52 return -EINVAL;
53 }
54
45 buf[0] = reg; 55 buf[0] = reg;
46 memcpy(&buf[1], val, len); 56 memcpy(&buf[1], val, len);
47 57
@@ -61,7 +71,7 @@ static int tda18212_rd_regs(struct tda18212_priv *priv, u8 reg, u8 *val,
61 int len) 71 int len)
62{ 72{
63 int ret; 73 int ret;
64 u8 buf[len]; 74 u8 buf[MAX_XFER_SIZE];
65 struct i2c_msg msg[2] = { 75 struct i2c_msg msg[2] = {
66 { 76 {
67 .addr = priv->cfg->i2c_address, 77 .addr = priv->cfg->i2c_address,
@@ -71,11 +81,18 @@ static int tda18212_rd_regs(struct tda18212_priv *priv, u8 reg, u8 *val,
71 }, { 81 }, {
72 .addr = priv->cfg->i2c_address, 82 .addr = priv->cfg->i2c_address,
73 .flags = I2C_M_RD, 83 .flags = I2C_M_RD,
74 .len = sizeof(buf), 84 .len = len,
75 .buf = buf, 85 .buf = buf,
76 } 86 }
77 }; 87 };
78 88
89 if (len > sizeof(buf)) {
90 dev_warn(&priv->i2c->dev,
91 "%s: i2c rd reg=%04x: len=%d is too big!\n",
92 KBUILD_MODNAME, reg, len);
93 return -EINVAL;
94 }
95
79 ret = i2c_transfer(priv->i2c, msg, 2); 96 ret = i2c_transfer(priv->i2c, msg, 2);
80 if (ret == 2) { 97 if (ret == 2) {
81 memcpy(val, buf, len); 98 memcpy(val, buf, len);
diff --git a/drivers/media/tuners/tda18218.c b/drivers/media/tuners/tda18218.c
index 2d31aeb6b088..9300e9361e3b 100644
--- a/drivers/media/tuners/tda18218.c
+++ b/drivers/media/tuners/tda18218.c
@@ -20,11 +20,14 @@
20 20
21#include "tda18218_priv.h" 21#include "tda18218_priv.h"
22 22
23/* Max transfer size done by I2C transfer functions */
24#define MAX_XFER_SIZE 64
25
23/* write multiple registers */ 26/* write multiple registers */
24static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len) 27static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
25{ 28{
26 int ret = 0, len2, remaining; 29 int ret = 0, len2, remaining;
27 u8 buf[1 + len]; 30 u8 buf[MAX_XFER_SIZE];
28 struct i2c_msg msg[1] = { 31 struct i2c_msg msg[1] = {
29 { 32 {
30 .addr = priv->cfg->i2c_address, 33 .addr = priv->cfg->i2c_address,
@@ -33,6 +36,13 @@ static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
33 } 36 }
34 }; 37 };
35 38
39 if (1 + len > sizeof(buf)) {
40 dev_warn(&priv->i2c->dev,
41 "%s: i2c wr reg=%04x: len=%d is too big!\n",
42 KBUILD_MODNAME, reg, len);
43 return -EINVAL;
44 }
45
36 for (remaining = len; remaining > 0; 46 for (remaining = len; remaining > 0;
37 remaining -= (priv->cfg->i2c_wr_max - 1)) { 47 remaining -= (priv->cfg->i2c_wr_max - 1)) {
38 len2 = remaining; 48 len2 = remaining;
@@ -63,7 +73,7 @@ static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
63static int tda18218_rd_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len) 73static int tda18218_rd_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
64{ 74{
65 int ret; 75 int ret;
66 u8 buf[reg+len]; /* we must start read always from reg 0x00 */ 76 u8 buf[MAX_XFER_SIZE]; /* we must start read always from reg 0x00 */
67 struct i2c_msg msg[2] = { 77 struct i2c_msg msg[2] = {
68 { 78 {
69 .addr = priv->cfg->i2c_address, 79 .addr = priv->cfg->i2c_address,
@@ -73,11 +83,18 @@ static int tda18218_rd_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
73 }, { 83 }, {
74 .addr = priv->cfg->i2c_address, 84 .addr = priv->cfg->i2c_address,
75 .flags = I2C_M_RD, 85 .flags = I2C_M_RD,
76 .len = sizeof(buf), 86 .len = reg + len,
77 .buf = buf, 87 .buf = buf,
78 } 88 }
79 }; 89 };
80 90
91 if (reg + len > sizeof(buf)) {
92 dev_warn(&priv->i2c->dev,
93 "%s: i2c wr reg=%04x: len=%d is too big!\n",
94 KBUILD_MODNAME, reg, len);
95 return -EINVAL;
96 }
97
81 ret = i2c_transfer(priv->i2c, msg, 2); 98 ret = i2c_transfer(priv->i2c, msg, 2);
82 if (ret == 2) { 99 if (ret == 2) {
83 memcpy(val, &buf[reg], len); 100 memcpy(val, &buf[reg], len);
diff --git a/drivers/media/tuners/tda9887.c b/drivers/media/tuners/tda9887.c
index 300005c535ba..9823248d743f 100644
--- a/drivers/media/tuners/tda9887.c
+++ b/drivers/media/tuners/tda9887.c
@@ -536,8 +536,8 @@ static int tda9887_status(struct dvb_frontend *fe)
536 unsigned char buf[1]; 536 unsigned char buf[1];
537 int rc; 537 int rc;
538 538
539 memset(buf,0,sizeof(buf)); 539 rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, 1);
540 if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,buf,1))) 540 if (rc != 1)
541 tuner_info("i2c i/o error: rc == %d (should be 1)\n", rc); 541 tuner_info("i2c i/o error: rc == %d (should be 1)\n", rc);
542 dump_read_message(fe, buf); 542 dump_read_message(fe, buf);
543 return 0; 543 return 0;
diff --git a/drivers/media/tuners/tuner-xc2028.c b/drivers/media/tuners/tuner-xc2028.c
index 878d2c4d9e8e..4be5cf808a40 100644
--- a/drivers/media/tuners/tuner-xc2028.c
+++ b/drivers/media/tuners/tuner-xc2028.c
@@ -24,6 +24,9 @@
24#include <linux/dvb/frontend.h> 24#include <linux/dvb/frontend.h>
25#include "dvb_frontend.h" 25#include "dvb_frontend.h"
26 26
27/* Max transfer size done by I2C transfer functions */
28#define MAX_XFER_SIZE 80
29
27/* Registers (Write-only) */ 30/* Registers (Write-only) */
28#define XREG_INIT 0x00 31#define XREG_INIT 0x00
29#define XREG_RF_FREQ 0x02 32#define XREG_RF_FREQ 0x02
@@ -547,7 +550,10 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
547{ 550{
548 struct xc2028_data *priv = fe->tuner_priv; 551 struct xc2028_data *priv = fe->tuner_priv;
549 int pos, rc; 552 int pos, rc;
550 unsigned char *p, *endp, buf[priv->ctrl.max_len]; 553 unsigned char *p, *endp, buf[MAX_XFER_SIZE];
554
555 if (priv->ctrl.max_len > sizeof(buf))
556 priv->ctrl.max_len = sizeof(buf);
551 557
552 tuner_dbg("%s called\n", __func__); 558 tuner_dbg("%s called\n", __func__);
553 559
@@ -572,7 +578,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
572 return -EINVAL; 578 return -EINVAL;
573 } 579 }
574 580
575 size = le16_to_cpu(*(__u16 *) p); 581 size = le16_to_cpu(*(__le16 *) p);
576 p += sizeof(size); 582 p += sizeof(size);
577 583
578 if (size == 0xffff) 584 if (size == 0xffff)
@@ -683,7 +689,7 @@ static int load_scode(struct dvb_frontend *fe, unsigned int type,
683 /* 16 SCODE entries per file; each SCODE entry is 12 bytes and 689 /* 16 SCODE entries per file; each SCODE entry is 12 bytes and
684 * has a 2-byte size header in the firmware format. */ 690 * has a 2-byte size header in the firmware format. */
685 if (priv->firm[pos].size != 14 * 16 || scode >= 16 || 691 if (priv->firm[pos].size != 14 * 16 || scode >= 16 ||
686 le16_to_cpu(*(__u16 *)(p + 14 * scode)) != 12) 692 le16_to_cpu(*(__le16 *)(p + 14 * scode)) != 12)
687 return -EINVAL; 693 return -EINVAL;
688 p += 14 * scode + 2; 694 p += 14 * scode + 2;
689 } 695 }
diff --git a/drivers/media/usb/b2c2/flexcop-usb.c b/drivers/media/usb/b2c2/flexcop-usb.c
index 8b6275f85908..0bd969063392 100644
--- a/drivers/media/usb/b2c2/flexcop-usb.c
+++ b/drivers/media/usb/b2c2/flexcop-usb.c
@@ -390,7 +390,7 @@ static void flexcop_usb_transfer_exit(struct flexcop_usb *fc_usb)
390 } 390 }
391 391
392 if (fc_usb->iso_buffer != NULL) 392 if (fc_usb->iso_buffer != NULL)
393 pci_free_consistent(NULL, 393 usb_free_coherent(fc_usb->udev,
394 fc_usb->buffer_size, fc_usb->iso_buffer, 394 fc_usb->buffer_size, fc_usb->iso_buffer,
395 fc_usb->dma_addr); 395 fc_usb->dma_addr);
396} 396}
@@ -407,8 +407,8 @@ static int flexcop_usb_transfer_init(struct flexcop_usb *fc_usb)
407 "each of %d bytes size = %d.\n", B2C2_USB_NUM_ISO_URB, 407 "each of %d bytes size = %d.\n", B2C2_USB_NUM_ISO_URB,
408 B2C2_USB_FRAMES_PER_ISO, frame_size, bufsize); 408 B2C2_USB_FRAMES_PER_ISO, frame_size, bufsize);
409 409
410 fc_usb->iso_buffer = pci_alloc_consistent(NULL, 410 fc_usb->iso_buffer = usb_alloc_coherent(fc_usb->udev,
411 bufsize, &fc_usb->dma_addr); 411 bufsize, GFP_KERNEL, &fc_usb->dma_addr);
412 if (fc_usb->iso_buffer == NULL) 412 if (fc_usb->iso_buffer == NULL)
413 return -ENOMEM; 413 return -ENOMEM;
414 414
diff --git a/drivers/media/usb/cpia2/cpia2_usb.c b/drivers/media/usb/cpia2/cpia2_usb.c
index be1719283609..351a78a84c3d 100644
--- a/drivers/media/usb/cpia2/cpia2_usb.c
+++ b/drivers/media/usb/cpia2/cpia2_usb.c
@@ -209,7 +209,7 @@ static void cpia2_usb_complete(struct urb *urb)
209{ 209{
210 int i; 210 int i;
211 unsigned char *cdata; 211 unsigned char *cdata;
212 static int frame_ready = false; 212 static bool frame_ready = false;
213 struct camera_data *cam = (struct camera_data *) urb->context; 213 struct camera_data *cam = (struct camera_data *) urb->context;
214 214
215 if (urb->status!=0) { 215 if (urb->status!=0) {
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index a384f80f595e..e9d017bea377 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -978,7 +978,6 @@ static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
978 int minor) 978 int minor)
979{ 979{
980 int retval = -ENOMEM; 980 int retval = -ENOMEM;
981 int errCode;
982 unsigned int maxh, maxw; 981 unsigned int maxh, maxw;
983 982
984 dev->udev = udev; 983 dev->udev = udev;
@@ -1014,8 +1013,8 @@ static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
1014 /* Cx231xx pre card setup */ 1013 /* Cx231xx pre card setup */
1015 cx231xx_pre_card_setup(dev); 1014 cx231xx_pre_card_setup(dev);
1016 1015
1017 errCode = cx231xx_config(dev); 1016 retval = cx231xx_config(dev);
1018 if (errCode) { 1017 if (retval) {
1019 cx231xx_errdev("error configuring device\n"); 1018 cx231xx_errdev("error configuring device\n");
1020 return -ENOMEM; 1019 return -ENOMEM;
1021 } 1020 }
@@ -1024,12 +1023,11 @@ static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
1024 dev->norm = dev->board.norm; 1023 dev->norm = dev->board.norm;
1025 1024
1026 /* register i2c bus */ 1025 /* register i2c bus */
1027 errCode = cx231xx_dev_init(dev); 1026 retval = cx231xx_dev_init(dev);
1028 if (errCode < 0) { 1027 if (retval) {
1029 cx231xx_dev_uninit(dev);
1030 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n", 1028 cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
1031 __func__, errCode); 1029 __func__, retval);
1032 return errCode; 1030 goto err_dev_init;
1033 } 1031 }
1034 1032
1035 /* Do board specific init */ 1033 /* Do board specific init */
@@ -1047,11 +1045,11 @@ static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
1047 dev->interlaced = 0; 1045 dev->interlaced = 0;
1048 dev->video_input = 0; 1046 dev->video_input = 0;
1049 1047
1050 errCode = cx231xx_config(dev); 1048 retval = cx231xx_config(dev);
1051 if (errCode < 0) { 1049 if (retval) {
1052 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n", 1050 cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
1053 __func__, errCode); 1051 __func__, retval);
1054 return errCode; 1052 goto err_dev_init;
1055 } 1053 }
1056 1054
1057 /* init video dma queues */ 1055 /* init video dma queues */
@@ -1075,9 +1073,9 @@ static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
1075 } 1073 }
1076 1074
1077 retval = cx231xx_register_analog_devices(dev); 1075 retval = cx231xx_register_analog_devices(dev);
1078 if (retval < 0) { 1076 if (retval) {
1079 cx231xx_release_resources(dev); 1077 cx231xx_release_analog_resources(dev);
1080 return retval; 1078 goto err_analog;
1081 } 1079 }
1082 1080
1083 cx231xx_ir_init(dev); 1081 cx231xx_ir_init(dev);
@@ -1085,6 +1083,11 @@ static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
1085 cx231xx_init_extension(dev); 1083 cx231xx_init_extension(dev);
1086 1084
1087 return 0; 1085 return 0;
1086err_analog:
1087 cx231xx_remove_from_devlist(dev);
1088err_dev_init:
1089 cx231xx_dev_uninit(dev);
1090 return retval;
1088} 1091}
1089 1092
1090#if defined(CONFIG_MODULES) && defined(MODULE) 1093#if defined(CONFIG_MODULES) && defined(MODULE)
@@ -1132,7 +1135,6 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1132 char *speed; 1135 char *speed;
1133 struct usb_interface_assoc_descriptor *assoc_desc; 1136 struct usb_interface_assoc_descriptor *assoc_desc;
1134 1137
1135 udev = usb_get_dev(interface_to_usbdev(interface));
1136 ifnum = interface->altsetting[0].desc.bInterfaceNumber; 1138 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
1137 1139
1138 /* 1140 /*
@@ -1161,6 +1163,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1161 return -ENOMEM; 1163 return -ENOMEM;
1162 } 1164 }
1163 1165
1166 udev = usb_get_dev(interface_to_usbdev(interface));
1167
1164 snprintf(dev->name, 29, "cx231xx #%d", nr); 1168 snprintf(dev->name, 29, "cx231xx #%d", nr);
1165 dev->devno = nr; 1169 dev->devno = nr;
1166 dev->model = id->driver_info; 1170 dev->model = id->driver_info;
@@ -1223,10 +1227,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1223 if (assoc_desc->bFirstInterface != ifnum) { 1227 if (assoc_desc->bFirstInterface != ifnum) {
1224 cx231xx_err(DRIVER_NAME ": Not found " 1228 cx231xx_err(DRIVER_NAME ": Not found "
1225 "matching IAD interface\n"); 1229 "matching IAD interface\n");
1226 clear_bit(dev->devno, &cx231xx_devused); 1230 retval = -ENODEV;
1227 kfree(dev); 1231 goto err_if;
1228 dev = NULL;
1229 return -ENODEV;
1230 } 1232 }
1231 1233
1232 cx231xx_info("registering interface %d\n", ifnum); 1234 cx231xx_info("registering interface %d\n", ifnum);
@@ -1242,22 +1244,13 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1242 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev); 1244 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
1243 if (retval) { 1245 if (retval) {
1244 cx231xx_errdev("v4l2_device_register failed\n"); 1246 cx231xx_errdev("v4l2_device_register failed\n");
1245 clear_bit(dev->devno, &cx231xx_devused); 1247 retval = -EIO;
1246 kfree(dev); 1248 goto err_v4l2;
1247 dev = NULL;
1248 return -EIO;
1249 } 1249 }
1250 /* allocate device struct */ 1250 /* allocate device struct */
1251 retval = cx231xx_init_dev(dev, udev, nr); 1251 retval = cx231xx_init_dev(dev, udev, nr);
1252 if (retval) { 1252 if (retval)
1253 clear_bit(dev->devno, &cx231xx_devused); 1253 goto err_init;
1254 v4l2_device_unregister(&dev->v4l2_dev);
1255 kfree(dev);
1256 dev = NULL;
1257 usb_set_intfdata(interface, NULL);
1258
1259 return retval;
1260 }
1261 1254
1262 /* compute alternate max packet sizes for video */ 1255 /* compute alternate max packet sizes for video */
1263 uif = udev->actconfig->interface[dev->current_pcb_config. 1256 uif = udev->actconfig->interface[dev->current_pcb_config.
@@ -1275,11 +1268,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1275 1268
1276 if (dev->video_mode.alt_max_pkt_size == NULL) { 1269 if (dev->video_mode.alt_max_pkt_size == NULL) {
1277 cx231xx_errdev("out of memory!\n"); 1270 cx231xx_errdev("out of memory!\n");
1278 clear_bit(dev->devno, &cx231xx_devused); 1271 retval = -ENOMEM;
1279 v4l2_device_unregister(&dev->v4l2_dev); 1272 goto err_video_alt;
1280 kfree(dev);
1281 dev = NULL;
1282 return -ENOMEM;
1283 } 1273 }
1284 1274
1285 for (i = 0; i < dev->video_mode.num_alt; i++) { 1275 for (i = 0; i < dev->video_mode.num_alt; i++) {
@@ -1309,11 +1299,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1309 1299
1310 if (dev->vbi_mode.alt_max_pkt_size == NULL) { 1300 if (dev->vbi_mode.alt_max_pkt_size == NULL) {
1311 cx231xx_errdev("out of memory!\n"); 1301 cx231xx_errdev("out of memory!\n");
1312 clear_bit(dev->devno, &cx231xx_devused); 1302 retval = -ENOMEM;
1313 v4l2_device_unregister(&dev->v4l2_dev); 1303 goto err_vbi_alt;
1314 kfree(dev);
1315 dev = NULL;
1316 return -ENOMEM;
1317 } 1304 }
1318 1305
1319 for (i = 0; i < dev->vbi_mode.num_alt; i++) { 1306 for (i = 0; i < dev->vbi_mode.num_alt; i++) {
@@ -1344,11 +1331,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1344 1331
1345 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) { 1332 if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
1346 cx231xx_errdev("out of memory!\n"); 1333 cx231xx_errdev("out of memory!\n");
1347 clear_bit(dev->devno, &cx231xx_devused); 1334 retval = -ENOMEM;
1348 v4l2_device_unregister(&dev->v4l2_dev); 1335 goto err_sliced_cc_alt;
1349 kfree(dev);
1350 dev = NULL;
1351 return -ENOMEM;
1352 } 1336 }
1353 1337
1354 for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) { 1338 for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
@@ -1380,11 +1364,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1380 1364
1381 if (dev->ts1_mode.alt_max_pkt_size == NULL) { 1365 if (dev->ts1_mode.alt_max_pkt_size == NULL) {
1382 cx231xx_errdev("out of memory!\n"); 1366 cx231xx_errdev("out of memory!\n");
1383 clear_bit(dev->devno, &cx231xx_devused); 1367 retval = -ENOMEM;
1384 v4l2_device_unregister(&dev->v4l2_dev); 1368 goto err_ts1_alt;
1385 kfree(dev);
1386 dev = NULL;
1387 return -ENOMEM;
1388 } 1369 }
1389 1370
1390 for (i = 0; i < dev->ts1_mode.num_alt; i++) { 1371 for (i = 0; i < dev->ts1_mode.num_alt; i++) {
@@ -1411,6 +1392,29 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1411 request_modules(dev); 1392 request_modules(dev);
1412 1393
1413 return 0; 1394 return 0;
1395err_ts1_alt:
1396 kfree(dev->sliced_cc_mode.alt_max_pkt_size);
1397err_sliced_cc_alt:
1398 kfree(dev->vbi_mode.alt_max_pkt_size);
1399err_vbi_alt:
1400 kfree(dev->video_mode.alt_max_pkt_size);
1401err_video_alt:
1402 /* cx231xx_uninit_dev: */
1403 cx231xx_close_extension(dev);
1404 cx231xx_ir_exit(dev);
1405 cx231xx_release_analog_resources(dev);
1406 cx231xx_417_unregister(dev);
1407 cx231xx_remove_from_devlist(dev);
1408 cx231xx_dev_uninit(dev);
1409err_init:
1410 v4l2_device_unregister(&dev->v4l2_dev);
1411err_v4l2:
1412 usb_set_intfdata(interface, NULL);
1413err_if:
1414 usb_put_dev(udev);
1415 kfree(dev);
1416 clear_bit(dev->devno, &cx231xx_devused);
1417 return retval;
1414} 1418}
1415 1419
1416/* 1420/*
diff --git a/drivers/media/usb/cx231xx/cx231xx-pcb-cfg.c b/drivers/media/usb/cx231xx/cx231xx-pcb-cfg.c
index d7308ab7a90f..2a34ceee4802 100644
--- a/drivers/media/usb/cx231xx/cx231xx-pcb-cfg.c
+++ b/drivers/media/usb/cx231xx/cx231xx-pcb-cfg.c
@@ -28,7 +28,7 @@ MODULE_PARM_DESC(pcb_debug, "enable pcb config debug messages [video]");
28 28
29/******************************************************************************/ 29/******************************************************************************/
30 30
31struct pcb_config cx231xx_Scenario[] = { 31static struct pcb_config cx231xx_Scenario[] = {
32 { 32 {
33 INDEX_SELFPOWER_DIGITAL_ONLY, /* index */ 33 INDEX_SELFPOWER_DIGITAL_ONLY, /* index */
34 USB_SELF_POWER, /* power_type */ 34 USB_SELF_POWER, /* power_type */
@@ -672,7 +672,7 @@ u32 initialize_cx231xx(struct cx231xx *dev)
672 pcb config it is related to */ 672 pcb config it is related to */
673 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, BOARD_CFG_STAT, data, 4); 673 cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, BOARD_CFG_STAT, data, 4);
674 674
675 config_info = le32_to_cpu(*((u32 *) data)); 675 config_info = le32_to_cpu(*((__le32 *)data));
676 usb_speed = (u8) (config_info & 0x1); 676 usb_speed = (u8) (config_info & 0x1);
677 677
678 /* Verify this device belongs to Bus power or Self power device */ 678 /* Verify this device belongs to Bus power or Self power device */
diff --git a/drivers/media/usb/dvb-usb-v2/af9015.c b/drivers/media/usb/dvb-usb-v2/af9015.c
index d556042cf312..da47d2392f2a 100644
--- a/drivers/media/usb/dvb-usb-v2/af9015.c
+++ b/drivers/media/usb/dvb-usb-v2/af9015.c
@@ -397,12 +397,13 @@ error:
397 return ret; 397 return ret;
398} 398}
399 399
400#define AF9015_EEPROM_SIZE 256
401
400/* hash (and dump) eeprom */ 402/* hash (and dump) eeprom */
401static int af9015_eeprom_hash(struct dvb_usb_device *d) 403static int af9015_eeprom_hash(struct dvb_usb_device *d)
402{ 404{
403 struct af9015_state *state = d_to_priv(d); 405 struct af9015_state *state = d_to_priv(d);
404 int ret, i; 406 int ret, i;
405 static const unsigned int AF9015_EEPROM_SIZE = 256;
406 u8 buf[AF9015_EEPROM_SIZE]; 407 u8 buf[AF9015_EEPROM_SIZE];
407 struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, NULL}; 408 struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, NULL};
408 409
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c
index 1ea17dc2a76e..c8fcd78425bd 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -21,6 +21,9 @@
21 21
22#include "af9035.h" 22#include "af9035.h"
23 23
24/* Max transfer size done by I2C transfer functions */
25#define MAX_XFER_SIZE 64
26
24DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 27DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
25 28
26static u16 af9035_checksum(const u8 *buf, size_t len) 29static u16 af9035_checksum(const u8 *buf, size_t len)
@@ -126,10 +129,16 @@ exit:
126/* write multiple registers */ 129/* write multiple registers */
127static int af9035_wr_regs(struct dvb_usb_device *d, u32 reg, u8 *val, int len) 130static int af9035_wr_regs(struct dvb_usb_device *d, u32 reg, u8 *val, int len)
128{ 131{
129 u8 wbuf[6 + len]; 132 u8 wbuf[MAX_XFER_SIZE];
130 u8 mbox = (reg >> 16) & 0xff; 133 u8 mbox = (reg >> 16) & 0xff;
131 struct usb_req req = { CMD_MEM_WR, mbox, sizeof(wbuf), wbuf, 0, NULL }; 134 struct usb_req req = { CMD_MEM_WR, mbox, sizeof(wbuf), wbuf, 0, NULL };
132 135
136 if (6 + len > sizeof(wbuf)) {
137 dev_warn(&d->udev->dev, "%s: i2c wr: len=%d is too big!\n",
138 KBUILD_MODNAME, len);
139 return -EOPNOTSUPP;
140 }
141
133 wbuf[0] = len; 142 wbuf[0] = len;
134 wbuf[1] = 2; 143 wbuf[1] = 2;
135 wbuf[2] = 0; 144 wbuf[2] = 0;
@@ -228,9 +237,16 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
228 msg[1].len); 237 msg[1].len);
229 } else { 238 } else {
230 /* I2C */ 239 /* I2C */
231 u8 buf[5 + msg[0].len]; 240 u8 buf[MAX_XFER_SIZE];
232 struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf), 241 struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf),
233 buf, msg[1].len, msg[1].buf }; 242 buf, msg[1].len, msg[1].buf };
243
244 if (5 + msg[0].len > sizeof(buf)) {
245 dev_warn(&d->udev->dev,
246 "%s: i2c xfer: len=%d is too big!\n",
247 KBUILD_MODNAME, msg[0].len);
248 return -EOPNOTSUPP;
249 }
234 req.mbox |= ((msg[0].addr & 0x80) >> 3); 250 req.mbox |= ((msg[0].addr & 0x80) >> 3);
235 buf[0] = msg[1].len; 251 buf[0] = msg[1].len;
236 buf[1] = msg[0].addr << 1; 252 buf[1] = msg[0].addr << 1;
@@ -257,9 +273,16 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
257 msg[0].len - 3); 273 msg[0].len - 3);
258 } else { 274 } else {
259 /* I2C */ 275 /* I2C */
260 u8 buf[5 + msg[0].len]; 276 u8 buf[MAX_XFER_SIZE];
261 struct usb_req req = { CMD_I2C_WR, 0, sizeof(buf), buf, 277 struct usb_req req = { CMD_I2C_WR, 0, sizeof(buf), buf,
262 0, NULL }; 278 0, NULL };
279
280 if (5 + msg[0].len > sizeof(buf)) {
281 dev_warn(&d->udev->dev,
282 "%s: i2c xfer: len=%d is too big!\n",
283 KBUILD_MODNAME, msg[0].len);
284 return -EOPNOTSUPP;
285 }
263 req.mbox |= ((msg[0].addr & 0x80) >> 3); 286 req.mbox |= ((msg[0].addr & 0x80) >> 3);
264 buf[0] = msg[0].len; 287 buf[0] = msg[0].len;
265 buf[1] = msg[0].addr << 1; 288 buf[1] = msg[0].addr << 1;
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf.c b/drivers/media/usb/dvb-usb-v2/mxl111sf.c
index e97964ef7f56..2627553f7de1 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf.c
@@ -23,6 +23,9 @@
23#include "lgdt3305.h" 23#include "lgdt3305.h"
24#include "lg2160.h" 24#include "lg2160.h"
25 25
26/* Max transfer size done by I2C transfer functions */
27#define MAX_XFER_SIZE 64
28
26int dvb_usb_mxl111sf_debug; 29int dvb_usb_mxl111sf_debug;
27module_param_named(debug, dvb_usb_mxl111sf_debug, int, 0644); 30module_param_named(debug, dvb_usb_mxl111sf_debug, int, 0644);
28MODULE_PARM_DESC(debug, "set debugging level " 31MODULE_PARM_DESC(debug, "set debugging level "
@@ -57,7 +60,12 @@ int mxl111sf_ctrl_msg(struct dvb_usb_device *d,
57{ 60{
58 int wo = (rbuf == NULL || rlen == 0); /* write-only */ 61 int wo = (rbuf == NULL || rlen == 0); /* write-only */
59 int ret; 62 int ret;
60 u8 sndbuf[1+wlen]; 63 u8 sndbuf[MAX_XFER_SIZE];
64
65 if (1 + wlen > sizeof(sndbuf)) {
66 pr_warn("%s: len=%d is too big!\n", __func__, wlen);
67 return -EOPNOTSUPP;
68 }
61 69
62 pr_debug("%s(wlen = %d, rlen = %d)\n", __func__, wlen, rlen); 70 pr_debug("%s(wlen = %d, rlen = %d)\n", __func__, wlen, rlen);
63 71
diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index c0cd0848631b..ecca03667f98 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -377,6 +377,7 @@ static int rtl2832u_read_config(struct dvb_usb_device *d)
377 struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf}; 377 struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf};
378 struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf}; 378 struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
379 struct rtl28xxu_req req_r820t = {0x0034, CMD_I2C_RD, 1, buf}; 379 struct rtl28xxu_req req_r820t = {0x0034, CMD_I2C_RD, 1, buf};
380 struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf};
380 381
381 dev_dbg(&d->udev->dev, "%s:\n", __func__); 382 dev_dbg(&d->udev->dev, "%s:\n", __func__);
382 383
@@ -489,6 +490,15 @@ static int rtl2832u_read_config(struct dvb_usb_device *d)
489 goto found; 490 goto found;
490 } 491 }
491 492
493 /* check R828D ID register; reg=00 val=69 */
494 ret = rtl28xxu_ctrl_msg(d, &req_r828d);
495 if (ret == 0 && buf[0] == 0x69) {
496 priv->tuner = TUNER_RTL2832_R828D;
497 priv->tuner_name = "R828D";
498 goto found;
499 }
500
501
492found: 502found:
493 dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name); 503 dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name);
494 504
@@ -745,6 +755,7 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
745 rtl2832_config = &rtl28xxu_rtl2832_e4000_config; 755 rtl2832_config = &rtl28xxu_rtl2832_e4000_config;
746 break; 756 break;
747 case TUNER_RTL2832_R820T: 757 case TUNER_RTL2832_R820T:
758 case TUNER_RTL2832_R828D:
748 rtl2832_config = &rtl28xxu_rtl2832_r820t_config; 759 rtl2832_config = &rtl28xxu_rtl2832_r820t_config;
749 break; 760 break;
750 default: 761 default:
@@ -866,6 +877,13 @@ static const struct r820t_config rtl2832u_r820t_config = {
866 .rafael_chip = CHIP_R820T, 877 .rafael_chip = CHIP_R820T,
867}; 878};
868 879
880static const struct r820t_config rtl2832u_r828d_config = {
881 .i2c_addr = 0x3a,
882 .xtal = 16000000,
883 .max_i2c_msg_len = 2,
884 .rafael_chip = CHIP_R828D,
885};
886
869static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap) 887static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
870{ 888{
871 int ret; 889 int ret;
@@ -923,6 +941,27 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
923 adap->fe[0]->ops.read_signal_strength = 941 adap->fe[0]->ops.read_signal_strength =
924 adap->fe[0]->ops.tuner_ops.get_rf_strength; 942 adap->fe[0]->ops.tuner_ops.get_rf_strength;
925 break; 943 break;
944 case TUNER_RTL2832_R828D:
945 /* power off mn88472 demod on GPIO0 */
946 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x00, 0x01);
947 if (ret)
948 goto err;
949
950 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x01);
951 if (ret)
952 goto err;
953
954 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x01, 0x01);
955 if (ret)
956 goto err;
957
958 fe = dvb_attach(r820t_attach, adap->fe[0], &d->i2c_adap,
959 &rtl2832u_r828d_config);
960
961 /* Use tuner to get the signal strength */
962 adap->fe[0]->ops.read_signal_strength =
963 adap->fe[0]->ops.tuner_ops.get_rf_strength;
964 break;
926 default: 965 default:
927 fe = NULL; 966 fe = NULL;
928 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME, 967 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
@@ -1388,6 +1427,9 @@ static const struct usb_device_id rtl28xxu_id_table[] = {
1388 &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) }, 1427 &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
1389 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A, 1428 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
1390 &rtl2832u_props, "Crypto ReDi PC 50 A", NULL) }, 1429 &rtl2832u_props, "Crypto ReDi PC 50 A", NULL) },
1430
1431 { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131,
1432 &rtl2832u_props, "Astrometa DVB-T2", NULL) },
1391 { } 1433 { }
1392}; 1434};
1393MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table); 1435MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.h b/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
index 729b3540c2f9..2142bcb41b41 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
@@ -83,6 +83,7 @@ enum rtl28xxu_tuner {
83 TUNER_RTL2832_TDA18272, 83 TUNER_RTL2832_TDA18272,
84 TUNER_RTL2832_FC0013, 84 TUNER_RTL2832_FC0013,
85 TUNER_RTL2832_R820T, 85 TUNER_RTL2832_R820T,
86 TUNER_RTL2832_R828D,
86}; 87};
87 88
88struct rtl28xxu_req { 89struct rtl28xxu_req {
diff --git a/drivers/media/usb/dvb-usb/az6027.c b/drivers/media/usb/dvb-usb/az6027.c
index ea2d5ee86576..c11138ebf6fb 100644
--- a/drivers/media/usb/dvb-usb/az6027.c
+++ b/drivers/media/usb/dvb-usb/az6027.c
@@ -254,7 +254,7 @@ static const struct stb0899_s1_reg az6027_stb0899_s1_init_3[] = {
254 254
255 255
256 256
257struct stb0899_config az6027_stb0899_config = { 257static struct stb0899_config az6027_stb0899_config = {
258 .init_dev = az6027_stb0899_s1_init_1, 258 .init_dev = az6027_stb0899_s1_init_1,
259 .init_s2_demod = stb0899_s2_init_2, 259 .init_s2_demod = stb0899_s2_init_2,
260 .init_s1_demod = az6027_stb0899_s1_init_3, 260 .init_s1_demod = az6027_stb0899_s1_init_3,
@@ -291,7 +291,7 @@ struct stb0899_config az6027_stb0899_config = {
291 .tuner_set_rfsiggain = NULL, 291 .tuner_set_rfsiggain = NULL,
292}; 292};
293 293
294struct stb6100_config az6027_stb6100_config = { 294static struct stb6100_config az6027_stb6100_config = {
295 .tuner_address = 0xc0, 295 .tuner_address = 0xc0,
296 .refclock = 27000000, 296 .refclock = 27000000,
297}; 297};
diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
index 3940bb0f9ef6..20e345d9fe8f 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -43,6 +43,9 @@
43#include "lgs8gxx.h" 43#include "lgs8gxx.h"
44#include "atbm8830.h" 44#include "atbm8830.h"
45 45
46/* Max transfer size done by I2C transfer functions */
47#define MAX_XFER_SIZE 64
48
46/* debug */ 49/* debug */
47static int dvb_usb_cxusb_debug; 50static int dvb_usb_cxusb_debug;
48module_param_named(debug, dvb_usb_cxusb_debug, int, 0644); 51module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
@@ -57,7 +60,14 @@ static int cxusb_ctrl_msg(struct dvb_usb_device *d,
57 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen) 60 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
58{ 61{
59 int wo = (rbuf == NULL || rlen == 0); /* write-only */ 62 int wo = (rbuf == NULL || rlen == 0); /* write-only */
60 u8 sndbuf[1+wlen]; 63 u8 sndbuf[MAX_XFER_SIZE];
64
65 if (1 + wlen > sizeof(sndbuf)) {
66 warn("i2c wr: len=%d is too big!\n",
67 wlen);
68 return -EOPNOTSUPP;
69 }
70
61 memset(sndbuf, 0, 1+wlen); 71 memset(sndbuf, 0, 1+wlen);
62 72
63 sndbuf[0] = cmd; 73 sndbuf[0] = cmd;
@@ -158,7 +168,13 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
158 168
159 if (msg[i].flags & I2C_M_RD) { 169 if (msg[i].flags & I2C_M_RD) {
160 /* read only */ 170 /* read only */
161 u8 obuf[3], ibuf[1+msg[i].len]; 171 u8 obuf[3], ibuf[MAX_XFER_SIZE];
172
173 if (1 + msg[i].len > sizeof(ibuf)) {
174 warn("i2c rd: len=%d is too big!\n",
175 msg[i].len);
176 return -EOPNOTSUPP;
177 }
162 obuf[0] = 0; 178 obuf[0] = 0;
163 obuf[1] = msg[i].len; 179 obuf[1] = msg[i].len;
164 obuf[2] = msg[i].addr; 180 obuf[2] = msg[i].addr;
@@ -172,7 +188,18 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
172 } else if (i+1 < num && (msg[i+1].flags & I2C_M_RD) && 188 } else if (i+1 < num && (msg[i+1].flags & I2C_M_RD) &&
173 msg[i].addr == msg[i+1].addr) { 189 msg[i].addr == msg[i+1].addr) {
174 /* write to then read from same address */ 190 /* write to then read from same address */
175 u8 obuf[3+msg[i].len], ibuf[1+msg[i+1].len]; 191 u8 obuf[MAX_XFER_SIZE], ibuf[MAX_XFER_SIZE];
192
193 if (3 + msg[i].len > sizeof(obuf)) {
194 warn("i2c wr: len=%d is too big!\n",
195 msg[i].len);
196 return -EOPNOTSUPP;
197 }
198 if (1 + msg[i + 1].len > sizeof(ibuf)) {
199 warn("i2c rd: len=%d is too big!\n",
200 msg[i + 1].len);
201 return -EOPNOTSUPP;
202 }
176 obuf[0] = msg[i].len; 203 obuf[0] = msg[i].len;
177 obuf[1] = msg[i+1].len; 204 obuf[1] = msg[i+1].len;
178 obuf[2] = msg[i].addr; 205 obuf[2] = msg[i].addr;
@@ -191,7 +218,13 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
191 i++; 218 i++;
192 } else { 219 } else {
193 /* write only */ 220 /* write only */
194 u8 obuf[2+msg[i].len], ibuf; 221 u8 obuf[MAX_XFER_SIZE], ibuf;
222
223 if (2 + msg[i].len > sizeof(obuf)) {
224 warn("i2c wr: len=%d is too big!\n",
225 msg[i].len);
226 return -EOPNOTSUPP;
227 }
195 obuf[0] = msg[i].addr; 228 obuf[0] = msg[i].addr;
196 obuf[1] = msg[i].len; 229 obuf[1] = msg[i].len;
197 memcpy(&obuf[2], msg[i].buf, msg[i].len); 230 memcpy(&obuf[2], msg[i].buf, msg[i].len);
diff --git a/drivers/media/usb/dvb-usb/dibusb-common.c b/drivers/media/usb/dvb-usb/dibusb-common.c
index c2dded92f1d3..6d68af0c49c8 100644
--- a/drivers/media/usb/dvb-usb/dibusb-common.c
+++ b/drivers/media/usb/dvb-usb/dibusb-common.c
@@ -12,6 +12,9 @@
12#include <linux/kconfig.h> 12#include <linux/kconfig.h>
13#include "dibusb.h" 13#include "dibusb.h"
14 14
15/* Max transfer size done by I2C transfer functions */
16#define MAX_XFER_SIZE 64
17
15static int debug; 18static int debug;
16module_param(debug, int, 0644); 19module_param(debug, int, 0644);
17MODULE_PARM_DESC(debug, "set debugging level (1=info (|-able))." DVB_USB_DEBUG_STATUS); 20MODULE_PARM_DESC(debug, "set debugging level (1=info (|-able))." DVB_USB_DEBUG_STATUS);
@@ -105,11 +108,16 @@ EXPORT_SYMBOL(dibusb2_0_power_ctrl);
105static int dibusb_i2c_msg(struct dvb_usb_device *d, u8 addr, 108static int dibusb_i2c_msg(struct dvb_usb_device *d, u8 addr,
106 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen) 109 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
107{ 110{
108 u8 sndbuf[wlen+4]; /* lead(1) devaddr,direction(1) addr(2) data(wlen) (len(2) (when reading)) */ 111 u8 sndbuf[MAX_XFER_SIZE]; /* lead(1) devaddr,direction(1) addr(2) data(wlen) (len(2) (when reading)) */
109 /* write only ? */ 112 /* write only ? */
110 int wo = (rbuf == NULL || rlen == 0), 113 int wo = (rbuf == NULL || rlen == 0),
111 len = 2 + wlen + (wo ? 0 : 2); 114 len = 2 + wlen + (wo ? 0 : 2);
112 115
116 if (4 + wlen > sizeof(sndbuf)) {
117 warn("i2c wr: len=%d is too big!\n", wlen);
118 return -EOPNOTSUPP;
119 }
120
113 sndbuf[0] = wo ? DIBUSB_REQ_I2C_WRITE : DIBUSB_REQ_I2C_READ; 121 sndbuf[0] = wo ? DIBUSB_REQ_I2C_WRITE : DIBUSB_REQ_I2C_READ;
114 sndbuf[1] = (addr << 1) | (wo ? 0 : 1); 122 sndbuf[1] = (addr << 1) | (wo ? 0 : 1);
115 123
diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
index 6e237b6dd0a8..c1a63b2a6baa 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -30,6 +30,9 @@
30#include "stb6100_proc.h" 30#include "stb6100_proc.h"
31#include "m88rs2000.h" 31#include "m88rs2000.h"
32 32
33/* Max transfer size done by I2C transfer functions */
34#define MAX_XFER_SIZE 64
35
33#ifndef USB_PID_DW2102 36#ifndef USB_PID_DW2102
34#define USB_PID_DW2102 0x2102 37#define USB_PID_DW2102 0x2102
35#endif 38#endif
@@ -308,7 +311,14 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg ms
308 case 2: { 311 case 2: {
309 /* read */ 312 /* read */
310 /* first write first register number */ 313 /* first write first register number */
311 u8 ibuf[msg[1].len + 2], obuf[3]; 314 u8 ibuf[MAX_XFER_SIZE], obuf[3];
315
316 if (2 + msg[1].len > sizeof(ibuf)) {
317 warn("i2c rd: len=%d is too big!\n",
318 msg[1].len);
319 return -EOPNOTSUPP;
320 }
321
312 obuf[0] = msg[0].addr << 1; 322 obuf[0] = msg[0].addr << 1;
313 obuf[1] = msg[0].len; 323 obuf[1] = msg[0].len;
314 obuf[2] = msg[0].buf[0]; 324 obuf[2] = msg[0].buf[0];
@@ -325,7 +335,14 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg ms
325 switch (msg[0].addr) { 335 switch (msg[0].addr) {
326 case 0x68: { 336 case 0x68: {
327 /* write to register */ 337 /* write to register */
328 u8 obuf[msg[0].len + 2]; 338 u8 obuf[MAX_XFER_SIZE];
339
340 if (2 + msg[0].len > sizeof(obuf)) {
341 warn("i2c wr: len=%d is too big!\n",
342 msg[1].len);
343 return -EOPNOTSUPP;
344 }
345
329 obuf[0] = msg[0].addr << 1; 346 obuf[0] = msg[0].addr << 1;
330 obuf[1] = msg[0].len; 347 obuf[1] = msg[0].len;
331 memcpy(obuf + 2, msg[0].buf, msg[0].len); 348 memcpy(obuf + 2, msg[0].buf, msg[0].len);
@@ -335,7 +352,14 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg ms
335 } 352 }
336 case 0x61: { 353 case 0x61: {
337 /* write to tuner */ 354 /* write to tuner */
338 u8 obuf[msg[0].len + 2]; 355 u8 obuf[MAX_XFER_SIZE];
356
357 if (2 + msg[0].len > sizeof(obuf)) {
358 warn("i2c wr: len=%d is too big!\n",
359 msg[1].len);
360 return -EOPNOTSUPP;
361 }
362
339 obuf[0] = msg[0].addr << 1; 363 obuf[0] = msg[0].addr << 1;
340 obuf[1] = msg[0].len; 364 obuf[1] = msg[0].len;
341 memcpy(obuf + 2, msg[0].buf, msg[0].len); 365 memcpy(obuf + 2, msg[0].buf, msg[0].len);
@@ -401,7 +425,14 @@ static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], i
401 default: { 425 default: {
402 if (msg[j].flags == I2C_M_RD) { 426 if (msg[j].flags == I2C_M_RD) {
403 /* read registers */ 427 /* read registers */
404 u8 ibuf[msg[j].len + 2]; 428 u8 ibuf[MAX_XFER_SIZE];
429
430 if (2 + msg[j].len > sizeof(ibuf)) {
431 warn("i2c rd: len=%d is too big!\n",
432 msg[j].len);
433 return -EOPNOTSUPP;
434 }
435
405 dw210x_op_rw(d->udev, 0xc3, 436 dw210x_op_rw(d->udev, 0xc3,
406 (msg[j].addr << 1) + 1, 0, 437 (msg[j].addr << 1) + 1, 0,
407 ibuf, msg[j].len + 2, 438 ibuf, msg[j].len + 2,
@@ -430,7 +461,14 @@ static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], i
430 } while (len > 0); 461 } while (len > 0);
431 } else { 462 } else {
432 /* write registers */ 463 /* write registers */
433 u8 obuf[msg[j].len + 2]; 464 u8 obuf[MAX_XFER_SIZE];
465
466 if (2 + msg[j].len > sizeof(obuf)) {
467 warn("i2c wr: len=%d is too big!\n",
468 msg[j].len);
469 return -EOPNOTSUPP;
470 }
471
434 obuf[0] = msg[j].addr << 1; 472 obuf[0] = msg[j].addr << 1;
435 obuf[1] = msg[j].len; 473 obuf[1] = msg[j].len;
436 memcpy(obuf + 2, msg[j].buf, msg[j].len); 474 memcpy(obuf + 2, msg[j].buf, msg[j].len);
@@ -463,7 +501,13 @@ static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
463 case 2: { 501 case 2: {
464 /* read */ 502 /* read */
465 /* first write first register number */ 503 /* first write first register number */
466 u8 ibuf[msg[1].len + 2], obuf[3]; 504 u8 ibuf[MAX_XFER_SIZE], obuf[3];
505
506 if (2 + msg[1].len > sizeof(ibuf)) {
507 warn("i2c rd: len=%d is too big!\n",
508 msg[1].len);
509 return -EOPNOTSUPP;
510 }
467 obuf[0] = msg[0].addr << 1; 511 obuf[0] = msg[0].addr << 1;
468 obuf[1] = msg[0].len; 512 obuf[1] = msg[0].len;
469 obuf[2] = msg[0].buf[0]; 513 obuf[2] = msg[0].buf[0];
@@ -481,7 +525,13 @@ static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
481 case 0x60: 525 case 0x60:
482 case 0x0c: { 526 case 0x0c: {
483 /* write to register */ 527 /* write to register */
484 u8 obuf[msg[0].len + 2]; 528 u8 obuf[MAX_XFER_SIZE];
529
530 if (2 + msg[0].len > sizeof(obuf)) {
531 warn("i2c wr: len=%d is too big!\n",
532 msg[0].len);
533 return -EOPNOTSUPP;
534 }
485 obuf[0] = msg[0].addr << 1; 535 obuf[0] = msg[0].addr << 1;
486 obuf[1] = msg[0].len; 536 obuf[1] = msg[0].len;
487 memcpy(obuf + 2, msg[0].buf, msg[0].len); 537 memcpy(obuf + 2, msg[0].buf, msg[0].len);
@@ -563,7 +613,14 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
563 default: { 613 default: {
564 if (msg[j].flags == I2C_M_RD) { 614 if (msg[j].flags == I2C_M_RD) {
565 /* read registers */ 615 /* read registers */
566 u8 ibuf[msg[j].len]; 616 u8 ibuf[MAX_XFER_SIZE];
617
618 if (msg[j].len > sizeof(ibuf)) {
619 warn("i2c rd: len=%d is too big!\n",
620 msg[j].len);
621 return -EOPNOTSUPP;
622 }
623
567 dw210x_op_rw(d->udev, 0x91, 0, 0, 624 dw210x_op_rw(d->udev, 0x91, 0, 0,
568 ibuf, msg[j].len, 625 ibuf, msg[j].len,
569 DW210X_READ_MSG); 626 DW210X_READ_MSG);
@@ -590,7 +647,14 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
590 } while (len > 0); 647 } while (len > 0);
591 } else if (j < (num - 1)) { 648 } else if (j < (num - 1)) {
592 /* write register addr before read */ 649 /* write register addr before read */
593 u8 obuf[msg[j].len + 2]; 650 u8 obuf[MAX_XFER_SIZE];
651
652 if (2 + msg[j].len > sizeof(obuf)) {
653 warn("i2c wr: len=%d is too big!\n",
654 msg[j].len);
655 return -EOPNOTSUPP;
656 }
657
594 obuf[0] = msg[j + 1].len; 658 obuf[0] = msg[j + 1].len;
595 obuf[1] = (msg[j].addr << 1); 659 obuf[1] = (msg[j].addr << 1);
596 memcpy(obuf + 2, msg[j].buf, msg[j].len); 660 memcpy(obuf + 2, msg[j].buf, msg[j].len);
@@ -602,7 +666,13 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
602 break; 666 break;
603 } else { 667 } else {
604 /* write registers */ 668 /* write registers */
605 u8 obuf[msg[j].len + 2]; 669 u8 obuf[MAX_XFER_SIZE];
670
671 if (2 + msg[j].len > sizeof(obuf)) {
672 warn("i2c wr: len=%d is too big!\n",
673 msg[j].len);
674 return -EOPNOTSUPP;
675 }
606 obuf[0] = msg[j].len + 1; 676 obuf[0] = msg[j].len + 1;
607 obuf[1] = (msg[j].addr << 1); 677 obuf[1] = (msg[j].addr << 1);
608 memcpy(obuf + 2, msg[j].buf, msg[j].len); 678 memcpy(obuf + 2, msg[j].buf, msg[j].len);
@@ -955,9 +1025,10 @@ static struct ds3000_config dw2104_ds3000_config = {
955 .demod_address = 0x68, 1025 .demod_address = 0x68,
956}; 1026};
957 1027
958static struct ts2020_config dw2104_ts2020_config = { 1028static struct ts2020_config dw2104_ts2020_config = {
959 .tuner_address = 0x60, 1029 .tuner_address = 0x60,
960 .clk_out_div = 1, 1030 .clk_out_div = 1,
1031 .frequency_div = 1060000,
961}; 1032};
962 1033
963static struct ds3000_config s660_ds3000_config = { 1034static struct ds3000_config s660_ds3000_config = {
@@ -966,6 +1037,12 @@ static struct ds3000_config s660_ds3000_config = {
966 .set_lock_led = dw210x_led_ctrl, 1037 .set_lock_led = dw210x_led_ctrl,
967}; 1038};
968 1039
1040static struct ts2020_config s660_ts2020_config = {
1041 .tuner_address = 0x60,
1042 .clk_out_div = 1,
1043 .frequency_div = 1146000,
1044};
1045
969static struct stv0900_config dw2104a_stv0900_config = { 1046static struct stv0900_config dw2104a_stv0900_config = {
970 .demod_address = 0x6a, 1047 .demod_address = 0x6a,
971 .demod_mode = 0, 1048 .demod_mode = 0,
@@ -1205,7 +1282,7 @@ static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1205 if (d->fe_adap[0].fe == NULL) 1282 if (d->fe_adap[0].fe == NULL)
1206 return -EIO; 1283 return -EIO;
1207 1284
1208 dvb_attach(ts2020_attach, d->fe_adap[0].fe, &dw2104_ts2020_config, 1285 dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config,
1209 &d->dev->i2c_adap); 1286 &d->dev->i2c_adap);
1210 1287
1211 st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage; 1288 st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
@@ -1213,7 +1290,7 @@ static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1213 1290
1214 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG); 1291 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1215 1292
1216 info("Attached ds3000+ds2020!\n"); 1293 info("Attached ds3000+ts2020!\n");
1217 1294
1218 return 0; 1295 return 0;
1219} 1296}
diff --git a/drivers/media/usb/em28xx/em28xx-camera.c b/drivers/media/usb/em28xx/em28xx-camera.c
index 73cc50afa5e1..d666741797d4 100644
--- a/drivers/media/usb/em28xx/em28xx-camera.c
+++ b/drivers/media/usb/em28xx/em28xx-camera.c
@@ -22,6 +22,7 @@
22#include <linux/i2c.h> 22#include <linux/i2c.h>
23#include <media/soc_camera.h> 23#include <media/soc_camera.h>
24#include <media/mt9v011.h> 24#include <media/mt9v011.h>
25#include <media/v4l2-clk.h>
25#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
26 27
27#include "em28xx.h" 28#include "em28xx.h"
@@ -47,6 +48,7 @@ static struct soc_camera_link camlink = {
47 .bus_id = 0, 48 .bus_id = 0,
48 .flags = 0, 49 .flags = 0,
49 .module_name = "em28xx", 50 .module_name = "em28xx",
51 .unbalanced_power = true,
50}; 52};
51 53
52 54
@@ -325,13 +327,24 @@ int em28xx_detect_sensor(struct em28xx *dev)
325 327
326int em28xx_init_camera(struct em28xx *dev) 328int em28xx_init_camera(struct em28xx *dev)
327{ 329{
330 char clk_name[V4L2_SUBDEV_NAME_SIZE];
331 struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus];
332 struct i2c_adapter *adap = &dev->i2c_adap[dev->def_i2c_bus];
333 int ret = 0;
334
335 v4l2_clk_name_i2c(clk_name, sizeof(clk_name),
336 i2c_adapter_id(adap), client->addr);
337 dev->clk = v4l2_clk_register_fixed(clk_name, "mclk", -EINVAL);
338 if (IS_ERR(dev->clk))
339 return PTR_ERR(dev->clk);
340
328 switch (dev->em28xx_sensor) { 341 switch (dev->em28xx_sensor) {
329 case EM28XX_MT9V011: 342 case EM28XX_MT9V011:
330 { 343 {
331 struct mt9v011_platform_data pdata; 344 struct mt9v011_platform_data pdata;
332 struct i2c_board_info mt9v011_info = { 345 struct i2c_board_info mt9v011_info = {
333 .type = "mt9v011", 346 .type = "mt9v011",
334 .addr = dev->i2c_client[dev->def_i2c_bus].addr, 347 .addr = client->addr,
335 .platform_data = &pdata, 348 .platform_data = &pdata,
336 }; 349 };
337 350
@@ -352,10 +365,11 @@ int em28xx_init_camera(struct em28xx *dev)
352 dev->sensor_xtal = 4300000; 365 dev->sensor_xtal = 4300000;
353 pdata.xtal = dev->sensor_xtal; 366 pdata.xtal = dev->sensor_xtal;
354 if (NULL == 367 if (NULL ==
355 v4l2_i2c_new_subdev_board(&dev->v4l2_dev, 368 v4l2_i2c_new_subdev_board(&dev->v4l2_dev, adap,
356 &dev->i2c_adap[dev->def_i2c_bus], 369 &mt9v011_info, NULL)) {
357 &mt9v011_info, NULL)) 370 ret = -ENODEV;
358 return -ENODEV; 371 break;
372 }
359 /* probably means GRGB 16 bit bayer */ 373 /* probably means GRGB 16 bit bayer */
360 dev->vinmode = 0x0d; 374 dev->vinmode = 0x0d;
361 dev->vinctl = 0x00; 375 dev->vinctl = 0x00;
@@ -391,7 +405,7 @@ int em28xx_init_camera(struct em28xx *dev)
391 struct i2c_board_info ov2640_info = { 405 struct i2c_board_info ov2640_info = {
392 .type = "ov2640", 406 .type = "ov2640",
393 .flags = I2C_CLIENT_SCCB, 407 .flags = I2C_CLIENT_SCCB,
394 .addr = dev->i2c_client[dev->def_i2c_bus].addr, 408 .addr = client->addr,
395 .platform_data = &camlink, 409 .platform_data = &camlink,
396 }; 410 };
397 struct v4l2_mbus_framefmt fmt; 411 struct v4l2_mbus_framefmt fmt;
@@ -408,9 +422,12 @@ int em28xx_init_camera(struct em28xx *dev)
408 dev->sensor_yres = 480; 422 dev->sensor_yres = 480;
409 423
410 subdev = 424 subdev =
411 v4l2_i2c_new_subdev_board(&dev->v4l2_dev, 425 v4l2_i2c_new_subdev_board(&dev->v4l2_dev, adap,
412 &dev->i2c_adap[dev->def_i2c_bus],
413 &ov2640_info, NULL); 426 &ov2640_info, NULL);
427 if (NULL == subdev) {
428 ret = -ENODEV;
429 break;
430 }
414 431
415 fmt.code = V4L2_MBUS_FMT_YUYV8_2X8; 432 fmt.code = V4L2_MBUS_FMT_YUYV8_2X8;
416 fmt.width = 640; 433 fmt.width = 640;
@@ -427,8 +444,13 @@ int em28xx_init_camera(struct em28xx *dev)
427 } 444 }
428 case EM28XX_NOSENSOR: 445 case EM28XX_NOSENSOR:
429 default: 446 default:
430 return -EINVAL; 447 ret = -EINVAL;
431 } 448 }
432 449
433 return 0; 450 if (ret < 0) {
451 v4l2_clk_unregister_fixed(dev->clk);
452 dev->clk = NULL;
453 }
454
455 return ret;
434} 456}
diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
index dc65742c4bbc..a5196697627f 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -36,6 +36,7 @@
36#include <media/tvaudio.h> 36#include <media/tvaudio.h>
37#include <media/i2c-addr.h> 37#include <media/i2c-addr.h>
38#include <media/tveeprom.h> 38#include <media/tveeprom.h>
39#include <media/v4l2-clk.h>
39#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
40 41
41#include "em28xx.h" 42#include "em28xx.h"
@@ -95,8 +96,8 @@ static struct em28xx_reg_seq default_digital[] = {
95/* Board Hauppauge WinTV HVR 900 analog */ 96/* Board Hauppauge WinTV HVR 900 analog */
96static struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = { 97static struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = {
97 {EM2820_R08_GPIO_CTRL, 0x2d, ~EM_GPIO_4, 10}, 98 {EM2820_R08_GPIO_CTRL, 0x2d, ~EM_GPIO_4, 10},
98 {0x05, 0xff, 0x10, 10}, 99 { 0x05, 0xff, 0x10, 10},
99 { -1, -1, -1, -1}, 100 { -1, -1, -1, -1},
100}; 101};
101 102
102/* Board Hauppauge WinTV HVR 900 digital */ 103/* Board Hauppauge WinTV HVR 900 digital */
@@ -104,20 +105,20 @@ static struct em28xx_reg_seq hauppauge_wintv_hvr_900_digital[] = {
104 {EM2820_R08_GPIO_CTRL, 0x2e, ~EM_GPIO_4, 10}, 105 {EM2820_R08_GPIO_CTRL, 0x2e, ~EM_GPIO_4, 10},
105 {EM2880_R04_GPO, 0x04, 0x0f, 10}, 106 {EM2880_R04_GPO, 0x04, 0x0f, 10},
106 {EM2880_R04_GPO, 0x0c, 0x0f, 10}, 107 {EM2880_R04_GPO, 0x0c, 0x0f, 10},
107 { -1, -1, -1, -1}, 108 { -1, -1, -1, -1},
108}; 109};
109 110
110/* Board Hauppauge WinTV HVR 900 (R2) digital */ 111/* Board Hauppauge WinTV HVR 900 (R2) digital */
111static struct em28xx_reg_seq hauppauge_wintv_hvr_900R2_digital[] = { 112static struct em28xx_reg_seq hauppauge_wintv_hvr_900R2_digital[] = {
112 {EM2820_R08_GPIO_CTRL, 0x2e, ~EM_GPIO_4, 10}, 113 {EM2820_R08_GPIO_CTRL, 0x2e, ~EM_GPIO_4, 10},
113 {EM2880_R04_GPO, 0x0c, 0x0f, 10}, 114 {EM2880_R04_GPO, 0x0c, 0x0f, 10},
114 { -1, -1, -1, -1}, 115 { -1, -1, -1, -1},
115}; 116};
116 117
117/* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */ 118/* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */
118static struct em28xx_reg_seq em2880_msi_digivox_ad_analog[] = { 119static struct em28xx_reg_seq em2880_msi_digivox_ad_analog[] = {
119 {EM2820_R08_GPIO_CTRL, 0x69, ~EM_GPIO_4, 10}, 120 {EM2820_R08_GPIO_CTRL, 0x69, ~EM_GPIO_4, 10},
120 { -1, -1, -1, -1}, 121 { -1, -1, -1, -1},
121}; 122};
122 123
123/* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */ 124/* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */
@@ -132,7 +133,7 @@ static struct em28xx_reg_seq em2882_kworld_315u_digital[] = {
132 {EM2880_R04_GPO, 0x04, 0xff, 10}, 133 {EM2880_R04_GPO, 0x04, 0xff, 10},
133 {EM2880_R04_GPO, 0x0c, 0xff, 10}, 134 {EM2880_R04_GPO, 0x0c, 0xff, 10},
134 {EM2820_R08_GPIO_CTRL, 0x7e, 0xff, 10}, 135 {EM2820_R08_GPIO_CTRL, 0x7e, 0xff, 10},
135 { -1, -1, -1, -1}, 136 { -1, -1, -1, -1},
136}; 137};
137 138
138static struct em28xx_reg_seq em2882_kworld_315u_tuner_gpio[] = { 139static struct em28xx_reg_seq em2882_kworld_315u_tuner_gpio[] = {
@@ -140,19 +141,19 @@ static struct em28xx_reg_seq em2882_kworld_315u_tuner_gpio[] = {
140 {EM2880_R04_GPO, 0x0c, 0xff, 10}, 141 {EM2880_R04_GPO, 0x0c, 0xff, 10},
141 {EM2880_R04_GPO, 0x08, 0xff, 10}, 142 {EM2880_R04_GPO, 0x08, 0xff, 10},
142 {EM2880_R04_GPO, 0x0c, 0xff, 10}, 143 {EM2880_R04_GPO, 0x0c, 0xff, 10},
143 { -1, -1, -1, -1}, 144 { -1, -1, -1, -1},
144}; 145};
145 146
146static struct em28xx_reg_seq kworld_330u_analog[] = { 147static struct em28xx_reg_seq kworld_330u_analog[] = {
147 {EM2820_R08_GPIO_CTRL, 0x6d, ~EM_GPIO_4, 10}, 148 {EM2820_R08_GPIO_CTRL, 0x6d, ~EM_GPIO_4, 10},
148 {EM2880_R04_GPO, 0x00, 0xff, 10}, 149 {EM2880_R04_GPO, 0x00, 0xff, 10},
149 { -1, -1, -1, -1}, 150 { -1, -1, -1, -1},
150}; 151};
151 152
152static struct em28xx_reg_seq kworld_330u_digital[] = { 153static struct em28xx_reg_seq kworld_330u_digital[] = {
153 {EM2820_R08_GPIO_CTRL, 0x6e, ~EM_GPIO_4, 10}, 154 {EM2820_R08_GPIO_CTRL, 0x6e, ~EM_GPIO_4, 10},
154 {EM2880_R04_GPO, 0x08, 0xff, 10}, 155 {EM2880_R04_GPO, 0x08, 0xff, 10},
155 { -1, -1, -1, -1}, 156 { -1, -1, -1, -1},
156}; 157};
157 158
158/* Evga inDtube 159/* Evga inDtube
@@ -170,11 +171,11 @@ static struct em28xx_reg_seq evga_indtube_digital[] = {
170 {EM2820_R08_GPIO_CTRL, 0x7a, 0xff, 1}, 171 {EM2820_R08_GPIO_CTRL, 0x7a, 0xff, 1},
171 {EM2880_R04_GPO, 0x04, 0xff, 10}, 172 {EM2880_R04_GPO, 0x04, 0xff, 10},
172 {EM2880_R04_GPO, 0x0c, 0xff, 1}, 173 {EM2880_R04_GPO, 0x0c, 0xff, 1},
173 { -1, -1, -1, -1}, 174 { -1, -1, -1, -1},
174}; 175};
175 176
176/* 177/*
177 * KWorld PlusTV 340U and UB435-Q (ATSC) GPIOs map: 178 * KWorld PlusTV 340U, UB435-Q and UB435-Q V2 (ATSC) GPIOs map:
178 * EM_GPIO_0 - currently unknown 179 * EM_GPIO_0 - currently unknown
179 * EM_GPIO_1 - LED disable/enable (1 = off, 0 = on) 180 * EM_GPIO_1 - LED disable/enable (1 = off, 0 = on)
180 * EM_GPIO_2 - currently unknown 181 * EM_GPIO_2 - currently unknown
@@ -185,8 +186,8 @@ static struct em28xx_reg_seq evga_indtube_digital[] = {
185 * EM_GPIO_7 - currently unknown 186 * EM_GPIO_7 - currently unknown
186 */ 187 */
187static struct em28xx_reg_seq kworld_a340_digital[] = { 188static struct em28xx_reg_seq kworld_a340_digital[] = {
188 {EM2820_R08_GPIO_CTRL, 0x6d, ~EM_GPIO_4, 10}, 189 {EM2820_R08_GPIO_CTRL, 0x6d, ~EM_GPIO_4, 10},
189 { -1, -1, -1, -1}, 190 { -1, -1, -1, -1},
190}; 191};
191 192
192/* Pinnacle Hybrid Pro eb1a:2881 */ 193/* Pinnacle Hybrid Pro eb1a:2881 */
@@ -205,13 +206,13 @@ static struct em28xx_reg_seq pinnacle_hybrid_pro_digital[] = {
205static struct em28xx_reg_seq terratec_cinergy_USB_XS_FR_analog[] = { 206static struct em28xx_reg_seq terratec_cinergy_USB_XS_FR_analog[] = {
206 {EM2820_R08_GPIO_CTRL, 0x6d, ~EM_GPIO_4, 10}, 207 {EM2820_R08_GPIO_CTRL, 0x6d, ~EM_GPIO_4, 10},
207 {EM2880_R04_GPO, 0x00, 0xff, 10}, 208 {EM2880_R04_GPO, 0x00, 0xff, 10},
208 { -1, -1, -1, -1}, 209 { -1, -1, -1, -1},
209}; 210};
210 211
211static struct em28xx_reg_seq terratec_cinergy_USB_XS_FR_digital[] = { 212static struct em28xx_reg_seq terratec_cinergy_USB_XS_FR_digital[] = {
212 {EM2820_R08_GPIO_CTRL, 0x6e, ~EM_GPIO_4, 10}, 213 {EM2820_R08_GPIO_CTRL, 0x6e, ~EM_GPIO_4, 10},
213 {EM2880_R04_GPO, 0x08, 0xff, 10}, 214 {EM2880_R04_GPO, 0x08, 0xff, 10},
214 { -1, -1, -1, -1}, 215 { -1, -1, -1, -1},
215}; 216};
216 217
217/* eb1a:2868 Reddo DVB-C USB TV Box 218/* eb1a:2868 Reddo DVB-C USB TV Box
@@ -225,7 +226,7 @@ static struct em28xx_reg_seq reddo_dvb_c_usb_box[] = {
225 {EM2820_R08_GPIO_CTRL, 0x7f, 0xff, 10}, 226 {EM2820_R08_GPIO_CTRL, 0x7f, 0xff, 10},
226 {EM2820_R08_GPIO_CTRL, 0x6f, 0xff, 10}, 227 {EM2820_R08_GPIO_CTRL, 0x6f, 0xff, 10},
227 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10}, 228 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
228 {-1, -1, -1, -1}, 229 { -1, -1, -1, -1},
229}; 230};
230 231
231/* Callback for the most boards */ 232/* Callback for the most boards */
@@ -233,23 +234,23 @@ static struct em28xx_reg_seq default_tuner_gpio[] = {
233 {EM2820_R08_GPIO_CTRL, EM_GPIO_4, EM_GPIO_4, 10}, 234 {EM2820_R08_GPIO_CTRL, EM_GPIO_4, EM_GPIO_4, 10},
234 {EM2820_R08_GPIO_CTRL, 0, EM_GPIO_4, 10}, 235 {EM2820_R08_GPIO_CTRL, 0, EM_GPIO_4, 10},
235 {EM2820_R08_GPIO_CTRL, EM_GPIO_4, EM_GPIO_4, 10}, 236 {EM2820_R08_GPIO_CTRL, EM_GPIO_4, EM_GPIO_4, 10},
236 { -1, -1, -1, -1}, 237 { -1, -1, -1, -1},
237}; 238};
238 239
239/* Mute/unmute */ 240/* Mute/unmute */
240static struct em28xx_reg_seq compro_unmute_tv_gpio[] = { 241static struct em28xx_reg_seq compro_unmute_tv_gpio[] = {
241 {EM2820_R08_GPIO_CTRL, 5, 7, 10}, 242 {EM2820_R08_GPIO_CTRL, 5, 7, 10},
242 { -1, -1, -1, -1}, 243 { -1, -1, -1, -1},
243}; 244};
244 245
245static struct em28xx_reg_seq compro_unmute_svid_gpio[] = { 246static struct em28xx_reg_seq compro_unmute_svid_gpio[] = {
246 {EM2820_R08_GPIO_CTRL, 4, 7, 10}, 247 {EM2820_R08_GPIO_CTRL, 4, 7, 10},
247 { -1, -1, -1, -1}, 248 { -1, -1, -1, -1},
248}; 249};
249 250
250static struct em28xx_reg_seq compro_mute_gpio[] = { 251static struct em28xx_reg_seq compro_mute_gpio[] = {
251 {EM2820_R08_GPIO_CTRL, 6, 7, 10}, 252 {EM2820_R08_GPIO_CTRL, 6, 7, 10},
252 { -1, -1, -1, -1}, 253 { -1, -1, -1, -1},
253}; 254};
254 255
255/* Terratec AV350 */ 256/* Terratec AV350 */
@@ -279,21 +280,21 @@ static struct em28xx_reg_seq vc211a_enable[] = {
279static struct em28xx_reg_seq dikom_dk300_digital[] = { 280static struct em28xx_reg_seq dikom_dk300_digital[] = {
280 {EM2820_R08_GPIO_CTRL, 0x6e, ~EM_GPIO_4, 10}, 281 {EM2820_R08_GPIO_CTRL, 0x6e, ~EM_GPIO_4, 10},
281 {EM2880_R04_GPO, 0x08, 0xff, 10}, 282 {EM2880_R04_GPO, 0x08, 0xff, 10},
282 { -1, -1, -1, -1}, 283 { -1, -1, -1, -1},
283}; 284};
284 285
285 286
286/* Reset for the most [digital] boards */ 287/* Reset for the most [digital] boards */
287static struct em28xx_reg_seq leadership_digital[] = { 288static struct em28xx_reg_seq leadership_digital[] = {
288 {EM2874_R80_GPIO_P0_CTRL, 0x70, 0xff, 10}, 289 {EM2874_R80_GPIO_P0_CTRL, 0x70, 0xff, 10},
289 { -1, -1, -1, -1}, 290 { -1, -1, -1, -1},
290}; 291};
291 292
292static struct em28xx_reg_seq leadership_reset[] = { 293static struct em28xx_reg_seq leadership_reset[] = {
293 {EM2874_R80_GPIO_P0_CTRL, 0xf0, 0xff, 10}, 294 {EM2874_R80_GPIO_P0_CTRL, 0xf0, 0xff, 10},
294 {EM2874_R80_GPIO_P0_CTRL, 0xb0, 0xff, 10}, 295 {EM2874_R80_GPIO_P0_CTRL, 0xb0, 0xff, 10},
295 {EM2874_R80_GPIO_P0_CTRL, 0xf0, 0xff, 10}, 296 {EM2874_R80_GPIO_P0_CTRL, 0xf0, 0xff, 10},
296 { -1, -1, -1, -1}, 297 { -1, -1, -1, -1},
297}; 298};
298 299
299/* 2013:024f PCTV nanoStick T2 290e 300/* 2013:024f PCTV nanoStick T2 290e
@@ -304,7 +305,7 @@ static struct em28xx_reg_seq pctv_290e[] = {
304 {EM2874_R80_GPIO_P0_CTRL, 0x00, 0xff, 80}, 305 {EM2874_R80_GPIO_P0_CTRL, 0x00, 0xff, 80},
305 {EM2874_R80_GPIO_P0_CTRL, 0x40, 0xff, 80}, /* GPIO_6 = 1 */ 306 {EM2874_R80_GPIO_P0_CTRL, 0x40, 0xff, 80}, /* GPIO_6 = 1 */
306 {EM2874_R80_GPIO_P0_CTRL, 0xc0, 0xff, 80}, /* GPIO_7 = 1 */ 307 {EM2874_R80_GPIO_P0_CTRL, 0xc0, 0xff, 80}, /* GPIO_7 = 1 */
307 {-1, -1, -1, -1}, 308 { -1, -1, -1, -1},
308}; 309};
309 310
310#if 0 311#if 0
@@ -313,14 +314,14 @@ static struct em28xx_reg_seq terratec_h5_gpio[] = {
313 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100}, 314 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
314 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50}, 315 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
315 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50}, 316 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
316 { -1, -1, -1, -1}, 317 { -1, -1, -1, -1},
317}; 318};
318 319
319static struct em28xx_reg_seq terratec_h5_digital[] = { 320static struct em28xx_reg_seq terratec_h5_digital[] = {
320 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 10}, 321 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 10},
321 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100}, 322 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
322 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 10}, 323 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 10},
323 { -1, -1, -1, -1}, 324 { -1, -1, -1, -1},
324}; 325};
325#endif 326#endif
326 327
@@ -335,12 +336,12 @@ static struct em28xx_reg_seq terratec_h5_digital[] = {
335 * GPIO_7 - LED (green LED) 336 * GPIO_7 - LED (green LED)
336 */ 337 */
337static struct em28xx_reg_seq pctv_460e[] = { 338static struct em28xx_reg_seq pctv_460e[] = {
338 {EM2874_R80_GPIO_P0_CTRL, 0x01, 0xff, 50}, 339 {EM2874_R80_GPIO_P0_CTRL, 0x01, 0xff, 50},
339 {0x0d, 0xff, 0xff, 50}, 340 { 0x0d, 0xff, 0xff, 50},
340 {EM2874_R80_GPIO_P0_CTRL, 0x41, 0xff, 50}, /* GPIO_6=1 */ 341 {EM2874_R80_GPIO_P0_CTRL, 0x41, 0xff, 50}, /* GPIO_6=1 */
341 {0x0d, 0x42, 0xff, 50}, 342 { 0x0d, 0x42, 0xff, 50},
342 {EM2874_R80_GPIO_P0_CTRL, 0x61, 0xff, 50}, /* GPIO_5=1 */ 343 {EM2874_R80_GPIO_P0_CTRL, 0x61, 0xff, 50}, /* GPIO_5=1 */
343 { -1, -1, -1, -1}, 344 { -1, -1, -1, -1},
344}; 345};
345 346
346static struct em28xx_reg_seq c3tech_digital_duo_digital[] = { 347static struct em28xx_reg_seq c3tech_digital_duo_digital[] = {
@@ -352,7 +353,7 @@ static struct em28xx_reg_seq c3tech_digital_duo_digital[] = {
352 {EM2874_R80_GPIO_P0_CTRL, 0xfe, 0xff, 10}, 353 {EM2874_R80_GPIO_P0_CTRL, 0xfe, 0xff, 10},
353 {EM2874_R80_GPIO_P0_CTRL, 0xbe, 0xff, 10}, 354 {EM2874_R80_GPIO_P0_CTRL, 0xbe, 0xff, 10},
354 {EM2874_R80_GPIO_P0_CTRL, 0xfe, 0xff, 20}, 355 {EM2874_R80_GPIO_P0_CTRL, 0xfe, 0xff, 20},
355 { -1, -1, -1, -1}, 356 { -1, -1, -1, -1},
356}; 357};
357 358
358#if 0 359#if 0
@@ -361,14 +362,14 @@ static struct em28xx_reg_seq hauppauge_930c_gpio[] = {
361 {EM2874_R80_GPIO_P0_CTRL, 0x4f, 0xff, 10}, /* xc5000 reset */ 362 {EM2874_R80_GPIO_P0_CTRL, 0x4f, 0xff, 10}, /* xc5000 reset */
362 {EM2874_R80_GPIO_P0_CTRL, 0x6f, 0xff, 10}, 363 {EM2874_R80_GPIO_P0_CTRL, 0x6f, 0xff, 10},
363 {EM2874_R80_GPIO_P0_CTRL, 0x4f, 0xff, 10}, 364 {EM2874_R80_GPIO_P0_CTRL, 0x4f, 0xff, 10},
364 { -1, -1, -1, -1}, 365 { -1, -1, -1, -1},
365}; 366};
366 367
367static struct em28xx_reg_seq hauppauge_930c_digital[] = { 368static struct em28xx_reg_seq hauppauge_930c_digital[] = {
368 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 10}, 369 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 10},
369 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100}, 370 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
370 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 10}, 371 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 10},
371 { -1, -1, -1, -1}, 372 { -1, -1, -1, -1},
372}; 373};
373#endif 374#endif
374 375
@@ -378,10 +379,10 @@ static struct em28xx_reg_seq hauppauge_930c_digital[] = {
378 * GPIO_7 - LED, 0=active 379 * GPIO_7 - LED, 0=active
379 */ 380 */
380static struct em28xx_reg_seq maxmedia_ub425_tc[] = { 381static struct em28xx_reg_seq maxmedia_ub425_tc[] = {
381 {EM2874_R80_GPIO_P0_CTRL, 0x83, 0xff, 100}, 382 {EM2874_R80_GPIO_P0_CTRL, 0x83, 0xff, 100},
382 {EM2874_R80_GPIO_P0_CTRL, 0xc3, 0xff, 100}, /* GPIO_6 = 1 */ 383 {EM2874_R80_GPIO_P0_CTRL, 0xc3, 0xff, 100}, /* GPIO_6 = 1 */
383 {EM2874_R80_GPIO_P0_CTRL, 0x43, 0xff, 000}, /* GPIO_7 = 0 */ 384 {EM2874_R80_GPIO_P0_CTRL, 0x43, 0xff, 000}, /* GPIO_7 = 0 */
384 {-1, -1, -1, -1}, 385 { -1, -1, -1, -1},
385}; 386};
386 387
387/* 2304:0242 PCTV QuatroStick (510e) 388/* 2304:0242 PCTV QuatroStick (510e)
@@ -391,10 +392,10 @@ static struct em28xx_reg_seq maxmedia_ub425_tc[] = {
391 * GPIO_7: LED, 1=active 392 * GPIO_7: LED, 1=active
392 */ 393 */
393static struct em28xx_reg_seq pctv_510e[] = { 394static struct em28xx_reg_seq pctv_510e[] = {
394 {EM2874_R80_GPIO_P0_CTRL, 0x10, 0xff, 100}, 395 {EM2874_R80_GPIO_P0_CTRL, 0x10, 0xff, 100},
395 {EM2874_R80_GPIO_P0_CTRL, 0x14, 0xff, 100}, /* GPIO_2 = 1 */ 396 {EM2874_R80_GPIO_P0_CTRL, 0x14, 0xff, 100}, /* GPIO_2 = 1 */
396 {EM2874_R80_GPIO_P0_CTRL, 0x54, 0xff, 050}, /* GPIO_6 = 1 */ 397 {EM2874_R80_GPIO_P0_CTRL, 0x54, 0xff, 050}, /* GPIO_6 = 1 */
397 { -1, -1, -1, -1}, 398 { -1, -1, -1, -1},
398}; 399};
399 400
400/* 2013:0251 PCTV QuatroStick nano (520e) 401/* 2013:0251 PCTV QuatroStick nano (520e)
@@ -404,11 +405,11 @@ static struct em28xx_reg_seq pctv_510e[] = {
404 * GPIO_7: LED, 1=active 405 * GPIO_7: LED, 1=active
405 */ 406 */
406static struct em28xx_reg_seq pctv_520e[] = { 407static struct em28xx_reg_seq pctv_520e[] = {
407 {EM2874_R80_GPIO_P0_CTRL, 0x10, 0xff, 100}, 408 {EM2874_R80_GPIO_P0_CTRL, 0x10, 0xff, 100},
408 {EM2874_R80_GPIO_P0_CTRL, 0x14, 0xff, 100}, /* GPIO_2 = 1 */ 409 {EM2874_R80_GPIO_P0_CTRL, 0x14, 0xff, 100}, /* GPIO_2 = 1 */
409 {EM2874_R80_GPIO_P0_CTRL, 0x54, 0xff, 050}, /* GPIO_6 = 1 */ 410 {EM2874_R80_GPIO_P0_CTRL, 0x54, 0xff, 050}, /* GPIO_6 = 1 */
410 {EM2874_R80_GPIO_P0_CTRL, 0xd4, 0xff, 000}, /* GPIO_7 = 1 */ 411 {EM2874_R80_GPIO_P0_CTRL, 0xd4, 0xff, 000}, /* GPIO_7 = 1 */
411 { -1, -1, -1, -1}, 412 { -1, -1, -1, -1},
412}; 413};
413 414
414/* 415/*
@@ -2030,6 +2031,18 @@ struct em28xx_board em28xx_boards[] = {
2030 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE | 2031 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
2031 EM28XX_I2C_FREQ_400_KHZ, 2032 EM28XX_I2C_FREQ_400_KHZ,
2032 }, 2033 },
2034 /*
2035 * 1b80:e346 KWorld USB ATSC TV Stick UB435-Q V2
2036 * Empia EM2874B + LG DT3305 + NXP TDA18271HDC2
2037 */
2038 [EM2874_BOARD_KWORLD_UB435Q_V2] = {
2039 .name = "KWorld USB ATSC TV Stick UB435-Q V2",
2040 .tuner_type = TUNER_ABSENT,
2041 .has_dvb = 1,
2042 .dvb_gpio = kworld_a340_digital,
2043 .tuner_gpio = default_tuner_gpio,
2044 .def_i2c_bus = 1,
2045 },
2033}; 2046};
2034const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards); 2047const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
2035 2048
@@ -2173,6 +2186,8 @@ struct usb_device_id em28xx_id_table[] = {
2173 .driver_info = EM2860_BOARD_GADMEI_UTV330 }, 2186 .driver_info = EM2860_BOARD_GADMEI_UTV330 },
2174 { USB_DEVICE(0x1b80, 0xa340), 2187 { USB_DEVICE(0x1b80, 0xa340),
2175 .driver_info = EM2870_BOARD_KWORLD_A340 }, 2188 .driver_info = EM2870_BOARD_KWORLD_A340 },
2189 { USB_DEVICE(0x1b80, 0xe346),
2190 .driver_info = EM2874_BOARD_KWORLD_UB435Q_V2 },
2176 { USB_DEVICE(0x2013, 0x024f), 2191 { USB_DEVICE(0x2013, 0x024f),
2177 .driver_info = EM28174_BOARD_PCTV_290E }, 2192 .driver_info = EM28174_BOARD_PCTV_290E },
2178 { USB_DEVICE(0x2013, 0x024c), 2193 { USB_DEVICE(0x2013, 0x024c),
@@ -2857,6 +2872,8 @@ void em28xx_release_resources(struct em28xx *dev)
2857 if (dev->def_i2c_bus) 2872 if (dev->def_i2c_bus)
2858 em28xx_i2c_unregister(dev, 1); 2873 em28xx_i2c_unregister(dev, 1);
2859 em28xx_i2c_unregister(dev, 0); 2874 em28xx_i2c_unregister(dev, 0);
2875 if (dev->clk)
2876 v4l2_clk_unregister_fixed(dev->clk);
2860 2877
2861 v4l2_ctrl_handler_free(&dev->ctrl_handler); 2878 v4l2_ctrl_handler_free(&dev->ctrl_handler);
2862 2879
diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c b/drivers/media/usb/em28xx/em28xx-dvb.c
index bb1e8dca80cd..344042bb845c 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -298,6 +298,18 @@ static struct lgdt3305_config em2870_lgdt3304_dev = {
298 .qam_if_khz = 4000, 298 .qam_if_khz = 4000,
299}; 299};
300 300
301static struct lgdt3305_config em2874_lgdt3305_dev = {
302 .i2c_addr = 0x0e,
303 .demod_chip = LGDT3305,
304 .spectral_inversion = 1,
305 .deny_i2c_rptr = 0,
306 .mpeg_mode = LGDT3305_MPEG_SERIAL,
307 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
308 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
309 .vsb_if_khz = 3250,
310 .qam_if_khz = 4000,
311};
312
301static struct s921_config sharp_isdbt = { 313static struct s921_config sharp_isdbt = {
302 .demod_address = 0x30 >> 1 314 .demod_address = 0x30 >> 1
303}; 315};
@@ -329,6 +341,11 @@ static struct tda18271_config kworld_a340_config = {
329 .std_map = &kworld_a340_std_map, 341 .std_map = &kworld_a340_std_map,
330}; 342};
331 343
344static struct tda18271_config kworld_ub435q_v2_config = {
345 .std_map = &kworld_a340_std_map,
346 .gate = TDA18271_GATE_DIGITAL,
347};
348
332static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = { 349static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
333 .demod_address = (0x1e >> 1), 350 .demod_address = (0x1e >> 1),
334 .no_tuner = 1, 351 .no_tuner = 1,
@@ -384,7 +401,10 @@ static struct drxk_config maxmedia_ub425_tc_drxk = {
384 .adr = 0x29, 401 .adr = 0x29,
385 .single_master = 1, 402 .single_master = 1,
386 .no_i2c_bridge = 1, 403 .no_i2c_bridge = 1,
404 .microcode_name = "dvb-demod-drxk-01.fw",
405 .chunk_size = 62,
387 .load_firmware_sync = true, 406 .load_firmware_sync = true,
407 .qam_demod_parameter_count = 2,
388}; 408};
389 409
390static struct drxk_config pctv_520e_drxk = { 410static struct drxk_config pctv_520e_drxk = {
@@ -424,7 +444,7 @@ static void hauppauge_hvr930c_init(struct em28xx *dev)
424 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65}, 444 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
425 {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32}, 445 {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
426 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8}, 446 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
427 { -1, -1, -1, -1}, 447 { -1, -1, -1, -1},
428 }; 448 };
429 struct em28xx_reg_seq hauppauge_hvr930c_end[] = { 449 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
430 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01}, 450 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
@@ -439,7 +459,7 @@ static void hauppauge_hvr930c_init(struct em28xx *dev)
439 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b}, 459 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
440 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65}, 460 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
441 461
442 { -1, -1, -1, -1}, 462 { -1, -1, -1, -1},
443 }; 463 };
444 464
445 struct { 465 struct {
@@ -491,13 +511,13 @@ static void terratec_h5_init(struct em28xx *dev)
491 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100}, 511 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
492 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50}, 512 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
493 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100}, 513 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
494 { -1, -1, -1, -1}, 514 { -1, -1, -1, -1},
495 }; 515 };
496 struct em28xx_reg_seq terratec_h5_end[] = { 516 struct em28xx_reg_seq terratec_h5_end[] = {
497 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100}, 517 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
498 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50}, 518 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
499 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100}, 519 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
500 { -1, -1, -1, -1}, 520 { -1, -1, -1, -1},
501 }; 521 };
502 struct { 522 struct {
503 unsigned char r[4]; 523 unsigned char r[4];
@@ -547,12 +567,12 @@ static void terratec_htc_stick_init(struct em28xx *dev)
547 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100}, 567 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
548 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50}, 568 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
549 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100}, 569 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
550 { -1, -1, -1, -1}, 570 { -1, -1, -1, -1},
551 }; 571 };
552 struct em28xx_reg_seq terratec_htc_stick_end[] = { 572 struct em28xx_reg_seq terratec_htc_stick_end[] = {
553 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100}, 573 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
554 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50}, 574 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
555 { -1, -1, -1, -1}, 575 { -1, -1, -1, -1},
556 }; 576 };
557 577
558 /* 578 /*
@@ -594,13 +614,13 @@ static void terratec_htc_usb_xs_init(struct em28xx *dev)
594 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100}, 614 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
595 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50}, 615 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
596 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100}, 616 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
597 { -1, -1, -1, -1}, 617 { -1, -1, -1, -1},
598 }; 618 };
599 struct em28xx_reg_seq terratec_htc_usb_xs_end[] = { 619 struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
600 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100}, 620 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
601 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50}, 621 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
602 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100}, 622 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
603 { -1, -1, -1, -1}, 623 { -1, -1, -1, -1},
604 }; 624 };
605 625
606 /* 626 /*
@@ -1227,18 +1247,14 @@ static int em28xx_dvb_init(struct em28xx *dev)
1227 dvb->fe[0]->ops.i2c_gate_ctrl = NULL; 1247 dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1228 1248
1229 /* attach tuner */ 1249 /* attach tuner */
1230 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], 1250 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1231 &dev->i2c_adap[dev->def_i2c_bus], 0x60)) { 1251 &dev->i2c_adap[dev->def_i2c_bus],
1252 &em28xx_cxd2820r_tda18271_config)) {
1232 dvb_frontend_detach(dvb->fe[0]); 1253 dvb_frontend_detach(dvb->fe[0]);
1233 result = -EINVAL; 1254 result = -EINVAL;
1234 goto out_free; 1255 goto out_free;
1235 } 1256 }
1236 } 1257 }
1237
1238 /* TODO: we need drx-3913k firmware in order to support DVB-T */
1239 em28xx_info("MaxMedia UB425-TC/Delock 61959: only DVB-C " \
1240 "supported by that driver version\n");
1241
1242 break; 1258 break;
1243 case EM2884_BOARD_PCTV_510E: 1259 case EM2884_BOARD_PCTV_510E:
1244 case EM2884_BOARD_PCTV_520E: 1260 case EM2884_BOARD_PCTV_520E:
@@ -1297,6 +1313,23 @@ static int em28xx_dvb_init(struct em28xx *dev)
1297 goto out_free; 1313 goto out_free;
1298 } 1314 }
1299 break; 1315 break;
1316 case EM2874_BOARD_KWORLD_UB435Q_V2:
1317 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1318 &em2874_lgdt3305_dev,
1319 &dev->i2c_adap[dev->def_i2c_bus]);
1320 if (!dvb->fe[0]) {
1321 result = -EINVAL;
1322 goto out_free;
1323 }
1324
1325 /* Attach the demodulator. */
1326 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1327 &dev->i2c_adap[dev->def_i2c_bus],
1328 &kworld_ub435q_v2_config)) {
1329 result = -EINVAL;
1330 goto out_free;
1331 }
1332 break;
1300 default: 1333 default:
1301 em28xx_errdev("/2: The frontend of your DVB/ATSC card" 1334 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
1302 " isn't supported yet\n"); 1335 " isn't supported yet\n");
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 9d103344f34a..fc5d60efd4ab 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -638,7 +638,7 @@ int em28xx_start_analog_streaming(struct vb2_queue *vq, unsigned int count)
638 if (rc) 638 if (rc)
639 return rc; 639 return rc;
640 640
641 if (dev->streaming_users++ == 0) { 641 if (dev->streaming_users == 0) {
642 /* First active streaming user, so allocate all the URBs */ 642 /* First active streaming user, so allocate all the URBs */
643 643
644 /* Allocate the USB bandwidth */ 644 /* Allocate the USB bandwidth */
@@ -657,7 +657,7 @@ int em28xx_start_analog_streaming(struct vb2_queue *vq, unsigned int count)
657 dev->packet_multiplier, 657 dev->packet_multiplier,
658 em28xx_urb_data_copy); 658 em28xx_urb_data_copy);
659 if (rc < 0) 659 if (rc < 0)
660 goto fail; 660 return rc;
661 661
662 /* 662 /*
663 * djh: it's not clear whether this code is still needed. I'm 663 * djh: it's not clear whether this code is still needed. I'm
@@ -675,7 +675,8 @@ int em28xx_start_analog_streaming(struct vb2_queue *vq, unsigned int count)
675 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f); 675 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
676 } 676 }
677 677
678fail: 678 dev->streaming_users++;
679
679 return rc; 680 return rc;
680} 681}
681 682
diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h
index 205e9038b1c0..f8726ad5d0a8 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -131,6 +131,7 @@
131#define EM2884_BOARD_TERRATEC_HTC_USB_XS 87 131#define EM2884_BOARD_TERRATEC_HTC_USB_XS 87
132#define EM2884_BOARD_C3TECH_DIGITAL_DUO 88 132#define EM2884_BOARD_C3TECH_DIGITAL_DUO 88
133#define EM2874_BOARD_DELOCK_61959 89 133#define EM2874_BOARD_DELOCK_61959 89
134#define EM2874_BOARD_KWORLD_UB435Q_V2 90
134 135
135/* Limits minimum and default number of buffers */ 136/* Limits minimum and default number of buffers */
136#define EM28XX_MIN_BUF 4 137#define EM28XX_MIN_BUF 4
@@ -492,6 +493,7 @@ struct em28xx {
492 493
493 struct v4l2_device v4l2_dev; 494 struct v4l2_device v4l2_dev;
494 struct v4l2_ctrl_handler ctrl_handler; 495 struct v4l2_ctrl_handler ctrl_handler;
496 struct v4l2_clk *clk;
495 struct em28xx_board board; 497 struct em28xx_board board;
496 498
497 /* Webcam specific fields */ 499 /* Webcam specific fields */
diff --git a/drivers/media/usb/gspca/conex.c b/drivers/media/usb/gspca/conex.c
index 38714df31ac4..2e15c80d6e3d 100644
--- a/drivers/media/usb/gspca/conex.c
+++ b/drivers/media/usb/gspca/conex.c
@@ -783,7 +783,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
783 struct sd *sd = (struct sd *) gspca_dev; 783 struct sd *sd = (struct sd *) gspca_dev;
784 784
785 /* create the JPEG header */ 785 /* create the JPEG header */
786 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 786 jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
787 gspca_dev->pixfmt.width,
787 0x22); /* JPEG 411 */ 788 0x22); /* JPEG 411 */
788 jpeg_set_qual(sd->jpeg_hdr, QUALITY); 789 jpeg_set_qual(sd->jpeg_hdr, QUALITY);
789 790
diff --git a/drivers/media/usb/gspca/cpia1.c b/drivers/media/usb/gspca/cpia1.c
index 064b53043b15..f23df4a9d8c5 100644
--- a/drivers/media/usb/gspca/cpia1.c
+++ b/drivers/media/usb/gspca/cpia1.c
@@ -1553,9 +1553,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
1553 sd->params.format.videoSize = VIDEOSIZE_CIF; 1553 sd->params.format.videoSize = VIDEOSIZE_CIF;
1554 1554
1555 sd->params.roi.colEnd = sd->params.roi.colStart + 1555 sd->params.roi.colEnd = sd->params.roi.colStart +
1556 (gspca_dev->width >> 3); 1556 (gspca_dev->pixfmt.width >> 3);
1557 sd->params.roi.rowEnd = sd->params.roi.rowStart + 1557 sd->params.roi.rowEnd = sd->params.roi.rowStart +
1558 (gspca_dev->height >> 2); 1558 (gspca_dev->pixfmt.height >> 2);
1559 1559
1560 /* And now set the camera to a known state */ 1560 /* And now set the camera to a known state */
1561 ret = do_command(gspca_dev, CPIA_COMMAND_SetGrabMode, 1561 ret = do_command(gspca_dev, CPIA_COMMAND_SetGrabMode,
diff --git a/drivers/media/usb/gspca/gspca.c b/drivers/media/usb/gspca/gspca.c
index 048507b27bb2..f3a7ace0fac9 100644
--- a/drivers/media/usb/gspca/gspca.c
+++ b/drivers/media/usb/gspca/gspca.c
@@ -504,8 +504,7 @@ static int frame_alloc(struct gspca_dev *gspca_dev, struct file *file,
504 unsigned int frsz; 504 unsigned int frsz;
505 int i; 505 int i;
506 506
507 i = gspca_dev->curr_mode; 507 frsz = gspca_dev->pixfmt.sizeimage;
508 frsz = gspca_dev->cam.cam_mode[i].sizeimage;
509 PDEBUG(D_STREAM, "frame alloc frsz: %d", frsz); 508 PDEBUG(D_STREAM, "frame alloc frsz: %d", frsz);
510 frsz = PAGE_ALIGN(frsz); 509 frsz = PAGE_ALIGN(frsz);
511 if (count >= GSPCA_MAX_FRAMES) 510 if (count >= GSPCA_MAX_FRAMES)
@@ -627,16 +626,14 @@ static struct usb_host_endpoint *alt_xfer(struct usb_host_interface *alt,
627static u32 which_bandwidth(struct gspca_dev *gspca_dev) 626static u32 which_bandwidth(struct gspca_dev *gspca_dev)
628{ 627{
629 u32 bandwidth; 628 u32 bandwidth;
630 int i;
631 629
632 /* get the (max) image size */ 630 /* get the (max) image size */
633 i = gspca_dev->curr_mode; 631 bandwidth = gspca_dev->pixfmt.sizeimage;
634 bandwidth = gspca_dev->cam.cam_mode[i].sizeimage;
635 632
636 /* if the image is compressed, estimate its mean size */ 633 /* if the image is compressed, estimate its mean size */
637 if (!gspca_dev->cam.needs_full_bandwidth && 634 if (!gspca_dev->cam.needs_full_bandwidth &&
638 bandwidth < gspca_dev->cam.cam_mode[i].width * 635 bandwidth < gspca_dev->pixfmt.width *
639 gspca_dev->cam.cam_mode[i].height) 636 gspca_dev->pixfmt.height)
640 bandwidth = bandwidth * 3 / 8; /* 0.375 */ 637 bandwidth = bandwidth * 3 / 8; /* 0.375 */
641 638
642 /* estimate the frame rate */ 639 /* estimate the frame rate */
@@ -650,7 +647,7 @@ static u32 which_bandwidth(struct gspca_dev *gspca_dev)
650 647
651 /* don't hope more than 15 fps with USB 1.1 and 648 /* don't hope more than 15 fps with USB 1.1 and
652 * image resolution >= 640x480 */ 649 * image resolution >= 640x480 */
653 if (gspca_dev->width >= 640 650 if (gspca_dev->pixfmt.width >= 640
654 && gspca_dev->dev->speed == USB_SPEED_FULL) 651 && gspca_dev->dev->speed == USB_SPEED_FULL)
655 bandwidth *= 15; /* 15 fps */ 652 bandwidth *= 15; /* 15 fps */
656 else 653 else
@@ -982,9 +979,7 @@ static void gspca_set_default_mode(struct gspca_dev *gspca_dev)
982 979
983 i = gspca_dev->cam.nmodes - 1; /* take the highest mode */ 980 i = gspca_dev->cam.nmodes - 1; /* take the highest mode */
984 gspca_dev->curr_mode = i; 981 gspca_dev->curr_mode = i;
985 gspca_dev->width = gspca_dev->cam.cam_mode[i].width; 982 gspca_dev->pixfmt = gspca_dev->cam.cam_mode[i];
986 gspca_dev->height = gspca_dev->cam.cam_mode[i].height;
987 gspca_dev->pixfmt = gspca_dev->cam.cam_mode[i].pixelformat;
988 983
989 /* does nothing if ctrl_handler == NULL */ 984 /* does nothing if ctrl_handler == NULL */
990 v4l2_ctrl_handler_setup(gspca_dev->vdev.ctrl_handler); 985 v4l2_ctrl_handler_setup(gspca_dev->vdev.ctrl_handler);
@@ -1105,10 +1100,8 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1105 struct v4l2_format *fmt) 1100 struct v4l2_format *fmt)
1106{ 1101{
1107 struct gspca_dev *gspca_dev = video_drvdata(file); 1102 struct gspca_dev *gspca_dev = video_drvdata(file);
1108 int mode;
1109 1103
1110 mode = gspca_dev->curr_mode; 1104 fmt->fmt.pix = gspca_dev->pixfmt;
1111 fmt->fmt.pix = gspca_dev->cam.cam_mode[mode];
1112 /* some drivers use priv internally, zero it before giving it to 1105 /* some drivers use priv internally, zero it before giving it to
1113 userspace */ 1106 userspace */
1114 fmt->fmt.pix.priv = 0; 1107 fmt->fmt.pix.priv = 0;
@@ -1140,6 +1133,12 @@ static int try_fmt_vid_cap(struct gspca_dev *gspca_dev,
1140 mode = mode2; 1133 mode = mode2;
1141 } 1134 }
1142 fmt->fmt.pix = gspca_dev->cam.cam_mode[mode]; 1135 fmt->fmt.pix = gspca_dev->cam.cam_mode[mode];
1136 if (gspca_dev->sd_desc->try_fmt) {
1137 /* pass original resolution to subdriver try_fmt */
1138 fmt->fmt.pix.width = w;
1139 fmt->fmt.pix.height = h;
1140 gspca_dev->sd_desc->try_fmt(gspca_dev, fmt);
1141 }
1143 /* some drivers use priv internally, zero it before giving it to 1142 /* some drivers use priv internally, zero it before giving it to
1144 userspace */ 1143 userspace */
1145 fmt->fmt.pix.priv = 0; 1144 fmt->fmt.pix.priv = 0;
@@ -1178,19 +1177,16 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1178 goto out; 1177 goto out;
1179 } 1178 }
1180 1179
1181 if (ret == gspca_dev->curr_mode) {
1182 ret = 0;
1183 goto out; /* same mode */
1184 }
1185
1186 if (gspca_dev->streaming) { 1180 if (gspca_dev->streaming) {
1187 ret = -EBUSY; 1181 ret = -EBUSY;
1188 goto out; 1182 goto out;
1189 } 1183 }
1190 gspca_dev->width = fmt->fmt.pix.width;
1191 gspca_dev->height = fmt->fmt.pix.height;
1192 gspca_dev->pixfmt = fmt->fmt.pix.pixelformat;
1193 gspca_dev->curr_mode = ret; 1184 gspca_dev->curr_mode = ret;
1185 if (gspca_dev->sd_desc->try_fmt)
1186 /* subdriver try_fmt can modify format parameters */
1187 gspca_dev->pixfmt = fmt->fmt.pix;
1188 else
1189 gspca_dev->pixfmt = gspca_dev->cam.cam_mode[ret];
1194 1190
1195 ret = 0; 1191 ret = 0;
1196out: 1192out:
@@ -1205,6 +1201,9 @@ static int vidioc_enum_framesizes(struct file *file, void *priv,
1205 int i; 1201 int i;
1206 __u32 index = 0; 1202 __u32 index = 0;
1207 1203
1204 if (gspca_dev->sd_desc->enum_framesizes)
1205 return gspca_dev->sd_desc->enum_framesizes(gspca_dev, fsize);
1206
1208 for (i = 0; i < gspca_dev->cam.nmodes; i++) { 1207 for (i = 0; i < gspca_dev->cam.nmodes; i++) {
1209 if (fsize->pixel_format != 1208 if (fsize->pixel_format !=
1210 gspca_dev->cam.cam_mode[i].pixelformat) 1209 gspca_dev->cam.cam_mode[i].pixelformat)
@@ -1471,8 +1470,9 @@ static int vidioc_streamon(struct file *file, void *priv,
1471 if (ret < 0) 1470 if (ret < 0)
1472 goto out; 1471 goto out;
1473 } 1472 }
1474 PDEBUG_MODE(gspca_dev, D_STREAM, "stream on OK", gspca_dev->pixfmt, 1473 PDEBUG_MODE(gspca_dev, D_STREAM, "stream on OK",
1475 gspca_dev->width, gspca_dev->height); 1474 gspca_dev->pixfmt.pixelformat,
1475 gspca_dev->pixfmt.width, gspca_dev->pixfmt.height);
1476 ret = 0; 1476 ret = 0;
1477out: 1477out:
1478 mutex_unlock(&gspca_dev->queue_lock); 1478 mutex_unlock(&gspca_dev->queue_lock);
diff --git a/drivers/media/usb/gspca/gspca.h b/drivers/media/usb/gspca/gspca.h
index ac0b11f46f50..300642dc1a17 100644
--- a/drivers/media/usb/gspca/gspca.h
+++ b/drivers/media/usb/gspca/gspca.h
@@ -88,6 +88,10 @@ typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
88typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev, 88typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev,
89 u8 *data, 89 u8 *data,
90 int len); 90 int len);
91typedef void (*cam_format_op) (struct gspca_dev *gspca_dev,
92 struct v4l2_format *fmt);
93typedef int (*cam_frmsize_op) (struct gspca_dev *gspca_dev,
94 struct v4l2_frmsizeenum *fsize);
91 95
92/* subdriver description */ 96/* subdriver description */
93struct sd_desc { 97struct sd_desc {
@@ -109,6 +113,8 @@ struct sd_desc {
109 cam_set_jpg_op set_jcomp; 113 cam_set_jpg_op set_jcomp;
110 cam_streamparm_op get_streamparm; 114 cam_streamparm_op get_streamparm;
111 cam_streamparm_op set_streamparm; 115 cam_streamparm_op set_streamparm;
116 cam_format_op try_fmt;
117 cam_frmsize_op enum_framesizes;
112#ifdef CONFIG_VIDEO_ADV_DEBUG 118#ifdef CONFIG_VIDEO_ADV_DEBUG
113 cam_set_reg_op set_register; 119 cam_set_reg_op set_register;
114 cam_get_reg_op get_register; 120 cam_get_reg_op get_register;
@@ -183,9 +189,7 @@ struct gspca_dev {
183 __u8 streaming; /* protected by both mutexes (*) */ 189 __u8 streaming; /* protected by both mutexes (*) */
184 190
185 __u8 curr_mode; /* current camera mode */ 191 __u8 curr_mode; /* current camera mode */
186 __u32 pixfmt; /* current mode parameters */ 192 struct v4l2_pix_format pixfmt; /* current mode parameters */
187 __u16 width;
188 __u16 height;
189 __u32 sequence; /* frame sequence number */ 193 __u32 sequence; /* frame sequence number */
190 194
191 wait_queue_head_t wq; /* wait queue */ 195 wait_queue_head_t wq; /* wait queue */
diff --git a/drivers/media/usb/gspca/jeilinj.c b/drivers/media/usb/gspca/jeilinj.c
index 8da3dde38385..19736e237b37 100644
--- a/drivers/media/usb/gspca/jeilinj.c
+++ b/drivers/media/usb/gspca/jeilinj.c
@@ -378,11 +378,12 @@ static int sd_start(struct gspca_dev *gspca_dev)
378 struct sd *dev = (struct sd *) gspca_dev; 378 struct sd *dev = (struct sd *) gspca_dev;
379 379
380 /* create the JPEG header */ 380 /* create the JPEG header */
381 jpeg_define(dev->jpeg_hdr, gspca_dev->height, gspca_dev->width, 381 jpeg_define(dev->jpeg_hdr, gspca_dev->pixfmt.height,
382 gspca_dev->pixfmt.width,
382 0x21); /* JPEG 422 */ 383 0x21); /* JPEG 422 */
383 jpeg_set_qual(dev->jpeg_hdr, dev->quality); 384 jpeg_set_qual(dev->jpeg_hdr, dev->quality);
384 PDEBUG(D_STREAM, "Start streaming at %dx%d", 385 PDEBUG(D_STREAM, "Start streaming at %dx%d",
385 gspca_dev->height, gspca_dev->width); 386 gspca_dev->pixfmt.height, gspca_dev->pixfmt.width);
386 jlj_start(gspca_dev); 387 jlj_start(gspca_dev);
387 return gspca_dev->usb_err; 388 return gspca_dev->usb_err;
388} 389}
diff --git a/drivers/media/usb/gspca/jl2005bcd.c b/drivers/media/usb/gspca/jl2005bcd.c
index fdaeeb14453f..5b481fa43099 100644
--- a/drivers/media/usb/gspca/jl2005bcd.c
+++ b/drivers/media/usb/gspca/jl2005bcd.c
@@ -455,7 +455,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
455 struct sd *sd = (struct sd *) gspca_dev; 455 struct sd *sd = (struct sd *) gspca_dev;
456 sd->cap_mode = gspca_dev->cam.cam_mode; 456 sd->cap_mode = gspca_dev->cam.cam_mode;
457 457
458 switch (gspca_dev->width) { 458 switch (gspca_dev->pixfmt.width) {
459 case 640: 459 case 640:
460 PDEBUG(D_STREAM, "Start streaming at vga resolution"); 460 PDEBUG(D_STREAM, "Start streaming at vga resolution");
461 jl2005c_stream_start_vga_lg(gspca_dev); 461 jl2005c_stream_start_vga_lg(gspca_dev);
diff --git a/drivers/media/usb/gspca/m5602/m5602_mt9m111.c b/drivers/media/usb/gspca/m5602/m5602_mt9m111.c
index cfa4663f8934..27fcef11aef4 100644
--- a/drivers/media/usb/gspca/m5602/m5602_mt9m111.c
+++ b/drivers/media/usb/gspca/m5602/m5602_mt9m111.c
@@ -266,7 +266,7 @@ static int mt9m111_set_hvflip(struct gspca_dev *gspca_dev)
266 return err; 266 return err;
267 267
268 data[0] = MT9M111_RMB_OVER_SIZED; 268 data[0] = MT9M111_RMB_OVER_SIZED;
269 if (gspca_dev->width == 640) { 269 if (gspca_dev->pixfmt.width == 640) {
270 data[1] = MT9M111_RMB_ROW_SKIP_2X | 270 data[1] = MT9M111_RMB_ROW_SKIP_2X |
271 MT9M111_RMB_COLUMN_SKIP_2X | 271 MT9M111_RMB_COLUMN_SKIP_2X |
272 (hflip << 1) | vflip; 272 (hflip << 1) | vflip;
diff --git a/drivers/media/usb/gspca/mars.c b/drivers/media/usb/gspca/mars.c
index ff2c5abf115b..779a8785f421 100644
--- a/drivers/media/usb/gspca/mars.c
+++ b/drivers/media/usb/gspca/mars.c
@@ -254,7 +254,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
254 int i; 254 int i;
255 255
256 /* create the JPEG header */ 256 /* create the JPEG header */
257 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 257 jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
258 gspca_dev->pixfmt.width,
258 0x21); /* JPEG 422 */ 259 0x21); /* JPEG 422 */
259 jpeg_set_qual(sd->jpeg_hdr, QUALITY); 260 jpeg_set_qual(sd->jpeg_hdr, QUALITY);
260 261
@@ -270,8 +271,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
270 data[0] = 0x00; /* address */ 271 data[0] = 0x00; /* address */
271 data[1] = 0x0c | 0x01; /* reg 0 */ 272 data[1] = 0x0c | 0x01; /* reg 0 */
272 data[2] = 0x01; /* reg 1 */ 273 data[2] = 0x01; /* reg 1 */
273 data[3] = gspca_dev->width / 8; /* h_size , reg 2 */ 274 data[3] = gspca_dev->pixfmt.width / 8; /* h_size , reg 2 */
274 data[4] = gspca_dev->height / 8; /* v_size , reg 3 */ 275 data[4] = gspca_dev->pixfmt.height / 8; /* v_size , reg 3 */
275 data[5] = 0x30; /* reg 4, MI, PAS5101 : 276 data[5] = 0x30; /* reg 4, MI, PAS5101 :
276 * 0x30 for 24mhz , 0x28 for 12mhz */ 277 * 0x30 for 24mhz , 0x28 for 12mhz */
277 data[6] = 0x02; /* reg 5, H start - was 0x04 */ 278 data[6] = 0x02; /* reg 5, H start - was 0x04 */
diff --git a/drivers/media/usb/gspca/mr97310a.c b/drivers/media/usb/gspca/mr97310a.c
index 68bb2f359666..f006e29ca019 100644
--- a/drivers/media/usb/gspca/mr97310a.c
+++ b/drivers/media/usb/gspca/mr97310a.c
@@ -521,7 +521,7 @@ static int start_cif_cam(struct gspca_dev *gspca_dev)
521 if (sd->sensor_type) 521 if (sd->sensor_type)
522 data[5] = 0xbb; 522 data[5] = 0xbb;
523 523
524 switch (gspca_dev->width) { 524 switch (gspca_dev->pixfmt.width) {
525 case 160: 525 case 160:
526 data[9] |= 0x04; /* reg 8, 2:1 scale down from 320 */ 526 data[9] |= 0x04; /* reg 8, 2:1 scale down from 320 */
527 /* fall thru */ 527 /* fall thru */
@@ -618,7 +618,7 @@ static int start_vga_cam(struct gspca_dev *gspca_dev)
618 data[10] = 0x18; 618 data[10] = 0x18;
619 } 619 }
620 620
621 switch (gspca_dev->width) { 621 switch (gspca_dev->pixfmt.width) {
622 case 160: 622 case 160:
623 data[9] |= 0x0c; /* reg 8, 4:1 scale down */ 623 data[9] |= 0x0c; /* reg 8, 4:1 scale down */
624 /* fall thru */ 624 /* fall thru */
@@ -847,7 +847,7 @@ static void setexposure(struct gspca_dev *gspca_dev, s32 expo, s32 min_clockdiv)
847 u8 clockdiv = (60 * expo + 7999) / 8000; 847 u8 clockdiv = (60 * expo + 7999) / 8000;
848 848
849 /* Limit framerate to not exceed usb bandwidth */ 849 /* Limit framerate to not exceed usb bandwidth */
850 if (clockdiv < min_clockdiv && gspca_dev->width >= 320) 850 if (clockdiv < min_clockdiv && gspca_dev->pixfmt.width >= 320)
851 clockdiv = min_clockdiv; 851 clockdiv = min_clockdiv;
852 else if (clockdiv < 2) 852 else if (clockdiv < 2)
853 clockdiv = 2; 853 clockdiv = 2;
diff --git a/drivers/media/usb/gspca/nw80x.c b/drivers/media/usb/gspca/nw80x.c
index 44c9964b1b3e..599f755e75b8 100644
--- a/drivers/media/usb/gspca/nw80x.c
+++ b/drivers/media/usb/gspca/nw80x.c
@@ -1708,7 +1708,7 @@ static void setautogain(struct gspca_dev *gspca_dev, s32 val)
1708 1708
1709 reg_r(gspca_dev, 0x1004, 1); 1709 reg_r(gspca_dev, 0x1004, 1);
1710 if (gspca_dev->usb_buf[0] & 0x04) { /* if AE_FULL_FRM */ 1710 if (gspca_dev->usb_buf[0] & 0x04) { /* if AE_FULL_FRM */
1711 sd->ae_res = gspca_dev->width * gspca_dev->height; 1711 sd->ae_res = gspca_dev->pixfmt.width * gspca_dev->pixfmt.height;
1712 } else { /* get the AE window size */ 1712 } else { /* get the AE window size */
1713 reg_r(gspca_dev, 0x1011, 8); 1713 reg_r(gspca_dev, 0x1011, 8);
1714 w = (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0] 1714 w = (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0]
@@ -1717,7 +1717,8 @@ static void setautogain(struct gspca_dev *gspca_dev, s32 val)
1717 - (gspca_dev->usb_buf[7] << 8) - gspca_dev->usb_buf[6]; 1717 - (gspca_dev->usb_buf[7] << 8) - gspca_dev->usb_buf[6];
1718 sd->ae_res = h * w; 1718 sd->ae_res = h * w;
1719 if (sd->ae_res == 0) 1719 if (sd->ae_res == 0)
1720 sd->ae_res = gspca_dev->width * gspca_dev->height; 1720 sd->ae_res = gspca_dev->pixfmt.width *
1721 gspca_dev->pixfmt.height;
1721 } 1722 }
1722} 1723}
1723 1724
@@ -1856,21 +1857,21 @@ static int sd_start(struct gspca_dev *gspca_dev)
1856 reg_w_buf(gspca_dev, cmd); 1857 reg_w_buf(gspca_dev, cmd);
1857 switch (sd->webcam) { 1858 switch (sd->webcam) {
1858 case P35u: 1859 case P35u:
1859 if (gspca_dev->width == 320) 1860 if (gspca_dev->pixfmt.width == 320)
1860 reg_w_buf(gspca_dev, nw801_start_qvga); 1861 reg_w_buf(gspca_dev, nw801_start_qvga);
1861 else 1862 else
1862 reg_w_buf(gspca_dev, nw801_start_vga); 1863 reg_w_buf(gspca_dev, nw801_start_vga);
1863 reg_w_buf(gspca_dev, nw801_start_2); 1864 reg_w_buf(gspca_dev, nw801_start_2);
1864 break; 1865 break;
1865 case Kr651us: 1866 case Kr651us:
1866 if (gspca_dev->width == 320) 1867 if (gspca_dev->pixfmt.width == 320)
1867 reg_w_buf(gspca_dev, kr651_start_qvga); 1868 reg_w_buf(gspca_dev, kr651_start_qvga);
1868 else 1869 else
1869 reg_w_buf(gspca_dev, kr651_start_vga); 1870 reg_w_buf(gspca_dev, kr651_start_vga);
1870 reg_w_buf(gspca_dev, kr651_start_2); 1871 reg_w_buf(gspca_dev, kr651_start_2);
1871 break; 1872 break;
1872 case Proscope: 1873 case Proscope:
1873 if (gspca_dev->width == 320) 1874 if (gspca_dev->pixfmt.width == 320)
1874 reg_w_buf(gspca_dev, proscope_start_qvga); 1875 reg_w_buf(gspca_dev, proscope_start_qvga);
1875 else 1876 else
1876 reg_w_buf(gspca_dev, proscope_start_vga); 1877 reg_w_buf(gspca_dev, proscope_start_vga);
diff --git a/drivers/media/usb/gspca/ov519.c b/drivers/media/usb/gspca/ov519.c
index 8937d79fd176..c95f32a0c02b 100644
--- a/drivers/media/usb/gspca/ov519.c
+++ b/drivers/media/usb/gspca/ov519.c
@@ -3468,7 +3468,7 @@ static int sd_isoc_init(struct gspca_dev *gspca_dev)
3468 3468
3469 switch (sd->bridge) { 3469 switch (sd->bridge) {
3470 case BRIDGE_OVFX2: 3470 case BRIDGE_OVFX2:
3471 if (gspca_dev->width != 800) 3471 if (gspca_dev->pixfmt.width != 800)
3472 gspca_dev->cam.bulk_size = OVFX2_BULK_SIZE; 3472 gspca_dev->cam.bulk_size = OVFX2_BULK_SIZE;
3473 else 3473 else
3474 gspca_dev->cam.bulk_size = 7 * 4096; 3474 gspca_dev->cam.bulk_size = 7 * 4096;
@@ -3507,8 +3507,8 @@ static void ov511_mode_init_regs(struct sd *sd)
3507 /* Here I'm assuming that snapshot size == image size. 3507 /* Here I'm assuming that snapshot size == image size.
3508 * I hope that's always true. --claudio 3508 * I hope that's always true. --claudio
3509 */ 3509 */
3510 hsegs = (sd->gspca_dev.width >> 3) - 1; 3510 hsegs = (sd->gspca_dev.pixfmt.width >> 3) - 1;
3511 vsegs = (sd->gspca_dev.height >> 3) - 1; 3511 vsegs = (sd->gspca_dev.pixfmt.height >> 3) - 1;
3512 3512
3513 reg_w(sd, R511_CAM_PXCNT, hsegs); 3513 reg_w(sd, R511_CAM_PXCNT, hsegs);
3514 reg_w(sd, R511_CAM_LNCNT, vsegs); 3514 reg_w(sd, R511_CAM_LNCNT, vsegs);
@@ -3541,7 +3541,7 @@ static void ov511_mode_init_regs(struct sd *sd)
3541 case SEN_OV7640: 3541 case SEN_OV7640:
3542 case SEN_OV7648: 3542 case SEN_OV7648:
3543 case SEN_OV76BE: 3543 case SEN_OV76BE:
3544 if (sd->gspca_dev.width == 320) 3544 if (sd->gspca_dev.pixfmt.width == 320)
3545 interlaced = 1; 3545 interlaced = 1;
3546 /* Fall through */ 3546 /* Fall through */
3547 case SEN_OV6630: 3547 case SEN_OV6630:
@@ -3551,7 +3551,7 @@ static void ov511_mode_init_regs(struct sd *sd)
3551 case 30: 3551 case 30:
3552 case 25: 3552 case 25:
3553 /* Not enough bandwidth to do 640x480 @ 30 fps */ 3553 /* Not enough bandwidth to do 640x480 @ 30 fps */
3554 if (sd->gspca_dev.width != 640) { 3554 if (sd->gspca_dev.pixfmt.width != 640) {
3555 sd->clockdiv = 0; 3555 sd->clockdiv = 0;
3556 break; 3556 break;
3557 } 3557 }
@@ -3584,7 +3584,8 @@ static void ov511_mode_init_regs(struct sd *sd)
3584 3584
3585 /* Check if we have enough bandwidth to disable compression */ 3585 /* Check if we have enough bandwidth to disable compression */
3586 fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1; 3586 fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1;
3587 needed = fps * sd->gspca_dev.width * sd->gspca_dev.height * 3 / 2; 3587 needed = fps * sd->gspca_dev.pixfmt.width *
3588 sd->gspca_dev.pixfmt.height * 3 / 2;
3588 /* 1000 isoc packets/sec */ 3589 /* 1000 isoc packets/sec */
3589 if (needed > 1000 * packet_size) { 3590 if (needed > 1000 * packet_size) {
3590 /* Enable Y and UV quantization and compression */ 3591 /* Enable Y and UV quantization and compression */
@@ -3646,8 +3647,8 @@ static void ov518_mode_init_regs(struct sd *sd)
3646 reg_w(sd, 0x38, 0x80); 3647 reg_w(sd, 0x38, 0x80);
3647 } 3648 }
3648 3649
3649 hsegs = sd->gspca_dev.width / 16; 3650 hsegs = sd->gspca_dev.pixfmt.width / 16;
3650 vsegs = sd->gspca_dev.height / 4; 3651 vsegs = sd->gspca_dev.pixfmt.height / 4;
3651 3652
3652 reg_w(sd, 0x29, hsegs); 3653 reg_w(sd, 0x29, hsegs);
3653 reg_w(sd, 0x2a, vsegs); 3654 reg_w(sd, 0x2a, vsegs);
@@ -3686,7 +3687,8 @@ static void ov518_mode_init_regs(struct sd *sd)
3686 * happened to be with revision < 2 cams using an 3687 * happened to be with revision < 2 cams using an
3687 * OV7620 and revision 2 cams using an OV7620AE. 3688 * OV7620 and revision 2 cams using an OV7620AE.
3688 */ 3689 */
3689 if (sd->revision > 0 && sd->gspca_dev.width == 640) { 3690 if (sd->revision > 0 &&
3691 sd->gspca_dev.pixfmt.width == 640) {
3690 reg_w(sd, 0x20, 0x60); 3692 reg_w(sd, 0x20, 0x60);
3691 reg_w(sd, 0x21, 0x1f); 3693 reg_w(sd, 0x21, 0x1f);
3692 } else { 3694 } else {
@@ -3812,8 +3814,8 @@ static void ov519_mode_init_regs(struct sd *sd)
3812 break; 3814 break;
3813 } 3815 }
3814 3816
3815 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4); 3817 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.pixfmt.width >> 4);
3816 reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3); 3818 reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.pixfmt.height >> 3);
3817 if (sd->sensor == SEN_OV7670 && 3819 if (sd->sensor == SEN_OV7670 &&
3818 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv) 3820 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3819 reg_w(sd, OV519_R12_X_OFFSETL, 0x04); 3821 reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
@@ -3947,14 +3949,16 @@ static void mode_init_ov_sensor_regs(struct sd *sd)
3947 } 3949 }
3948 case SEN_OV3610: 3950 case SEN_OV3610:
3949 if (qvga) { 3951 if (qvga) {
3950 xstart = (1040 - gspca_dev->width) / 2 + (0x1f << 4); 3952 xstart = (1040 - gspca_dev->pixfmt.width) / 2 +
3951 ystart = (776 - gspca_dev->height) / 2; 3953 (0x1f << 4);
3954 ystart = (776 - gspca_dev->pixfmt.height) / 2;
3952 } else { 3955 } else {
3953 xstart = (2076 - gspca_dev->width) / 2 + (0x10 << 4); 3956 xstart = (2076 - gspca_dev->pixfmt.width) / 2 +
3954 ystart = (1544 - gspca_dev->height) / 2; 3957 (0x10 << 4);
3958 ystart = (1544 - gspca_dev->pixfmt.height) / 2;
3955 } 3959 }
3956 xend = xstart + gspca_dev->width; 3960 xend = xstart + gspca_dev->pixfmt.width;
3957 yend = ystart + gspca_dev->height; 3961 yend = ystart + gspca_dev->pixfmt.height;
3958 /* Writing to the COMH register resets the other windowing regs 3962 /* Writing to the COMH register resets the other windowing regs
3959 to their default values, so we must do this first. */ 3963 to their default values, so we must do this first. */
3960 i2c_w_mask(sd, 0x12, qvga ? 0x40 : 0x00, 0xf0); 3964 i2c_w_mask(sd, 0x12, qvga ? 0x40 : 0x00, 0xf0);
@@ -4229,8 +4233,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
4229 struct sd *sd = (struct sd *) gspca_dev; 4233 struct sd *sd = (struct sd *) gspca_dev;
4230 4234
4231 /* Default for most bridges, allow bridge_mode_init_regs to override */ 4235 /* Default for most bridges, allow bridge_mode_init_regs to override */
4232 sd->sensor_width = sd->gspca_dev.width; 4236 sd->sensor_width = sd->gspca_dev.pixfmt.width;
4233 sd->sensor_height = sd->gspca_dev.height; 4237 sd->sensor_height = sd->gspca_dev.pixfmt.height;
4234 4238
4235 switch (sd->bridge) { 4239 switch (sd->bridge) {
4236 case BRIDGE_OV511: 4240 case BRIDGE_OV511:
@@ -4345,12 +4349,13 @@ static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
4345 ov51x_handle_button(gspca_dev, (in[8] >> 2) & 1); 4349 ov51x_handle_button(gspca_dev, (in[8] >> 2) & 1);
4346 if (in[8] & 0x80) { 4350 if (in[8] & 0x80) {
4347 /* Frame end */ 4351 /* Frame end */
4348 if ((in[9] + 1) * 8 != gspca_dev->width || 4352 if ((in[9] + 1) * 8 != gspca_dev->pixfmt.width ||
4349 (in[10] + 1) * 8 != gspca_dev->height) { 4353 (in[10] + 1) * 8 != gspca_dev->pixfmt.height) {
4350 PERR("Invalid frame size, got: %dx%d," 4354 PERR("Invalid frame size, got: %dx%d,"
4351 " requested: %dx%d\n", 4355 " requested: %dx%d\n",
4352 (in[9] + 1) * 8, (in[10] + 1) * 8, 4356 (in[9] + 1) * 8, (in[10] + 1) * 8,
4353 gspca_dev->width, gspca_dev->height); 4357 gspca_dev->pixfmt.width,
4358 gspca_dev->pixfmt.height);
4354 gspca_dev->last_packet_type = DISCARD_PACKET; 4359 gspca_dev->last_packet_type = DISCARD_PACKET;
4355 return; 4360 return;
4356 } 4361 }
@@ -4470,7 +4475,8 @@ static void ovfx2_pkt_scan(struct gspca_dev *gspca_dev,
4470 if (sd->first_frame) { 4475 if (sd->first_frame) {
4471 sd->first_frame--; 4476 sd->first_frame--;
4472 if (gspca_dev->image_len < 4477 if (gspca_dev->image_len <
4473 sd->gspca_dev.width * sd->gspca_dev.height) 4478 sd->gspca_dev.pixfmt.width *
4479 sd->gspca_dev.pixfmt.height)
4474 gspca_dev->last_packet_type = DISCARD_PACKET; 4480 gspca_dev->last_packet_type = DISCARD_PACKET;
4475 } 4481 }
4476 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); 4482 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
diff --git a/drivers/media/usb/gspca/ov534.c b/drivers/media/usb/gspca/ov534.c
index 03a33c46ca2c..90f0d637cd9d 100644
--- a/drivers/media/usb/gspca/ov534.c
+++ b/drivers/media/usb/gspca/ov534.c
@@ -1440,9 +1440,10 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1440 /* If this packet is marked as EOF, end the frame */ 1440 /* If this packet is marked as EOF, end the frame */
1441 } else if (data[1] & UVC_STREAM_EOF) { 1441 } else if (data[1] & UVC_STREAM_EOF) {
1442 sd->last_pts = 0; 1442 sd->last_pts = 0;
1443 if (gspca_dev->pixfmt == V4L2_PIX_FMT_YUYV 1443 if (gspca_dev->pixfmt.pixelformat == V4L2_PIX_FMT_YUYV
1444 && gspca_dev->image_len + len - 12 != 1444 && gspca_dev->image_len + len - 12 !=
1445 gspca_dev->width * gspca_dev->height * 2) { 1445 gspca_dev->pixfmt.width *
1446 gspca_dev->pixfmt.height * 2) {
1446 PDEBUG(D_PACK, "wrong sized frame"); 1447 PDEBUG(D_PACK, "wrong sized frame");
1447 goto discard; 1448 goto discard;
1448 } 1449 }
diff --git a/drivers/media/usb/gspca/ov534_9.c b/drivers/media/usb/gspca/ov534_9.c
index c4cd028fe0b4..47085cf2d723 100644
--- a/drivers/media/usb/gspca/ov534_9.c
+++ b/drivers/media/usb/gspca/ov534_9.c
@@ -59,6 +59,7 @@ enum sensors {
59 SENSOR_OV965x, /* ov9657 */ 59 SENSOR_OV965x, /* ov9657 */
60 SENSOR_OV971x, /* ov9712 */ 60 SENSOR_OV971x, /* ov9712 */
61 SENSOR_OV562x, /* ov5621 */ 61 SENSOR_OV562x, /* ov5621 */
62 SENSOR_OV361x, /* ov3610 */
62 NSENSORS 63 NSENSORS
63}; 64};
64 65
@@ -106,6 +107,274 @@ static const struct v4l2_pix_format ov562x_mode[] = {
106 } 107 }
107}; 108};
108 109
110enum ov361x {
111 ov361x_2048 = 0,
112 ov361x_1600,
113 ov361x_1024,
114 ov361x_640,
115 ov361x_320,
116 ov361x_160,
117 ov361x_last
118};
119
120static const struct v4l2_pix_format ov361x_mode[] = {
121 {0x800, 0x600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
122 .bytesperline = 0x800,
123 .sizeimage = 0x800 * 0x600,
124 .colorspace = V4L2_COLORSPACE_SRGB},
125 {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
126 .bytesperline = 1600,
127 .sizeimage = 1600 * 1200,
128 .colorspace = V4L2_COLORSPACE_SRGB},
129 {1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
130 .bytesperline = 768,
131 .sizeimage = 1024 * 768,
132 .colorspace = V4L2_COLORSPACE_SRGB},
133 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
134 .bytesperline = 640,
135 .sizeimage = 640 * 480,
136 .colorspace = V4L2_COLORSPACE_SRGB},
137 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
138 .bytesperline = 320,
139 .sizeimage = 320 * 240,
140 .colorspace = V4L2_COLORSPACE_SRGB},
141 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
142 .bytesperline = 160,
143 .sizeimage = 160 * 120,
144 .colorspace = V4L2_COLORSPACE_SRGB}
145};
146
147static const u8 ov361x_start_2048[][2] = {
148 {0x12, 0x80},
149 {0x13, 0xcf},
150 {0x14, 0x40},
151 {0x15, 0x00},
152 {0x01, 0x80},
153 {0x02, 0x80},
154 {0x04, 0x70},
155 {0x0d, 0x40},
156 {0x0f, 0x47},
157 {0x11, 0x81},
158 {0x32, 0x36},
159 {0x33, 0x0c},
160 {0x34, 0x00},
161 {0x35, 0x90},
162 {0x12, 0x00},
163 {0x17, 0x10},
164 {0x18, 0x90},
165 {0x19, 0x00},
166 {0x1a, 0xc0},
167};
168static const u8 ov361x_bridge_start_2048[][2] = {
169 {0xf1, 0x60},
170 {0x88, 0x00},
171 {0x89, 0x08},
172 {0x8a, 0x00},
173 {0x8b, 0x06},
174 {0x8c, 0x01},
175 {0x8d, 0x10},
176 {0x1c, 0x00},
177 {0x1d, 0x48},
178 {0x1d, 0x00},
179 {0x1d, 0xff},
180 {0x1c, 0x0a},
181 {0x1d, 0x2e},
182 {0x1d, 0x1e},
183};
184
185static const u8 ov361x_start_1600[][2] = {
186 {0x12, 0x80},
187 {0x13, 0xcf},
188 {0x14, 0x40},
189 {0x15, 0x00},
190 {0x01, 0x80},
191 {0x02, 0x80},
192 {0x04, 0x70},
193 {0x0d, 0x40},
194 {0x0f, 0x47},
195 {0x11, 0x81},
196 {0x32, 0x36},
197 {0x33, 0x0C},
198 {0x34, 0x00},
199 {0x35, 0x90},
200 {0x12, 0x00},
201 {0x17, 0x10},
202 {0x18, 0x90},
203 {0x19, 0x00},
204 {0x1a, 0xc0},
205};
206static const u8 ov361x_bridge_start_1600[][2] = {
207 {0xf1, 0x60}, /* Hsize[7:0] */
208 {0x88, 0x00}, /* Hsize[15:8] Write Only, can't read */
209 {0x89, 0x08}, /* Vsize[7:0] */
210 {0x8a, 0x00}, /* Vsize[15:8] Write Only, can't read */
211 {0x8b, 0x06}, /* for Iso */
212 {0x8c, 0x01}, /* RAW input */
213 {0x8d, 0x10},
214 {0x1c, 0x00}, /* RAW output, Iso transfer */
215 {0x1d, 0x48},
216 {0x1d, 0x00},
217 {0x1d, 0xff},
218 {0x1c, 0x0a}, /* turn off JPEG, Iso mode */
219 {0x1d, 0x2e}, /* for Iso */
220 {0x1d, 0x1e},
221};
222
223static const u8 ov361x_start_1024[][2] = {
224 {0x12, 0x80},
225 {0x13, 0xcf},
226 {0x14, 0x40},
227 {0x15, 0x00},
228 {0x01, 0x80},
229 {0x02, 0x80},
230 {0x04, 0x70},
231 {0x0d, 0x40},
232 {0x0f, 0x47},
233 {0x11, 0x81},
234 {0x32, 0x36},
235 {0x33, 0x0C},
236 {0x34, 0x00},
237 {0x35, 0x90},
238 {0x12, 0x40},
239 {0x17, 0x1f},
240 {0x18, 0x5f},
241 {0x19, 0x00},
242 {0x1a, 0x68},
243};
244static const u8 ov361x_bridge_start_1024[][2] = {
245 {0xf1, 0x60}, /* Hsize[7:0] */
246 {0x88, 0x00}, /* Hsize[15:8] Write Only, can't read */
247 {0x89, 0x04}, /* Vsize[7:0] */
248 {0x8a, 0x00}, /* Vsize[15:8] Write Only, can't read */
249 {0x8b, 0x03}, /* for Iso */
250 {0x8c, 0x01}, /* RAW input */
251 {0x8d, 0x10},
252 {0x1c, 0x00}, /* RAW output, Iso transfer */
253 {0x1d, 0x48},
254 {0x1d, 0x00},
255 {0x1d, 0xff},
256 {0x1c, 0x0a}, /* turn off JPEG, Iso mode */
257 {0x1d, 0x2e}, /* for Iso */
258 {0x1d, 0x1e},
259};
260
261static const u8 ov361x_start_640[][2] = {
262 {0x12, 0x80},
263 {0x13, 0xcf},
264 {0x14, 0x40},
265 {0x15, 0x00},
266 {0x01, 0x80},
267 {0x02, 0x80},
268 {0x04, 0x70},
269 {0x0d, 0x40},
270 {0x0f, 0x47},
271 {0x11, 0x81},
272 {0x32, 0x36},
273 {0x33, 0x0C},
274 {0x34, 0x00},
275 {0x35, 0x90},
276 {0x12, 0x40},
277 {0x17, 0x1f},
278 {0x18, 0x5f},
279 {0x19, 0x00},
280 {0x1a, 0x68},
281};
282
283static const u8 ov361x_bridge_start_640[][2] = {
284 {0xf1, 0x60}, /* Hsize[7:0]*/
285 {0x88, 0x00}, /* Hsize[15:8] Write Only, can't read */
286 {0x89, 0x04}, /* Vsize[7:0] */
287 {0x8a, 0x00}, /* Vsize[15:8] Write Only, can't read */
288 {0x8b, 0x03}, /* for Iso */
289 {0x8c, 0x01}, /* RAW input */
290 {0x8d, 0x10},
291 {0x1c, 0x00}, /* RAW output, Iso transfer */
292 {0x1d, 0x48},
293 {0x1d, 0x00},
294 {0x1d, 0xff},
295 {0x1c, 0x0a}, /* turn off JPEG, Iso mode */
296 {0x1d, 0x2e}, /* for Iso */
297 {0x1d, 0x1e},
298};
299
300static const u8 ov361x_start_320[][2] = {
301 {0x12, 0x80},
302 {0x13, 0xcf},
303 {0x14, 0x40},
304 {0x15, 0x00},
305 {0x01, 0x80},
306 {0x02, 0x80},
307 {0x04, 0x70},
308 {0x0d, 0x40},
309 {0x0f, 0x47},
310 {0x11, 0x81},
311 {0x32, 0x36},
312 {0x33, 0x0C},
313 {0x34, 0x00},
314 {0x35, 0x90},
315 {0x12, 0x40},
316 {0x17, 0x1f},
317 {0x18, 0x5f},
318 {0x19, 0x00},
319 {0x1a, 0x68},
320};
321
322static const u8 ov361x_bridge_start_320[][2] = {
323 {0xf1, 0x60}, /* Hsize[7:0] */
324 {0x88, 0x00}, /* Hsize[15:8] Write Only, can't read */
325 {0x89, 0x04}, /* Vsize[7:0] */
326 {0x8a, 0x00}, /* Vsize[15:8] Write Only, can't read */
327 {0x8b, 0x03}, /* for Iso */
328 {0x8c, 0x01}, /* RAW input */
329 {0x8d, 0x10},
330 {0x1c, 0x00}, /* RAW output, Iso transfer; */
331 {0x1d, 0x48},
332 {0x1d, 0x00},
333 {0x1d, 0xff},
334 {0x1c, 0x0a}, /* turn off JPEG, Iso mode */
335 {0x1d, 0x2e}, /* for Iso */
336 {0x1d, 0x1e},
337};
338
339static const u8 ov361x_start_160[][2] = {
340 {0x12, 0x80},
341 {0x13, 0xcf},
342 {0x14, 0x40},
343 {0x15, 0x00},
344 {0x01, 0x80},
345 {0x02, 0x80},
346 {0x04, 0x70},
347 {0x0d, 0x40},
348 {0x0f, 0x47},
349 {0x11, 0x81},
350 {0x32, 0x36},
351 {0x33, 0x0C},
352 {0x34, 0x00},
353 {0x35, 0x90},
354 {0x12, 0x40},
355 {0x17, 0x1f},
356 {0x18, 0x5f},
357 {0x19, 0x00},
358 {0x1a, 0x68},
359};
360
361static const u8 ov361x_bridge_start_160[][2] = {
362 {0xf1, 0x60}, /* Hsize[7:0] */
363 {0x88, 0x00}, /* Hsize[15:8] Write Only, can't read */
364 {0x89, 0x04}, /* Vsize[7:0] */
365 {0x8a, 0x00}, /* Vsize[15:8] Write Only, can't read */
366 {0x8b, 0x03}, /* for Iso */
367 {0x8c, 0x01}, /* RAW input */
368 {0x8d, 0x10},
369 {0x1c, 0x00}, /* RAW output, Iso transfer */
370 {0x1d, 0x48},
371 {0x1d, 0x00},
372 {0x1d, 0xff},
373 {0x1c, 0x0a}, /* turn off JPEG, Iso mode */
374 {0x1d, 0x2e}, /* for Iso */
375 {0x1d, 0x1e},
376};
377
109static const u8 bridge_init[][2] = { 378static const u8 bridge_init[][2] = {
110 {0x88, 0xf8}, 379 {0x88, 0xf8},
111 {0x89, 0xff}, 380 {0x89, 0xff},
@@ -898,7 +1167,7 @@ static int sccb_check_status(struct gspca_dev *gspca_dev)
898 int i; 1167 int i;
899 1168
900 for (i = 0; i < 5; i++) { 1169 for (i = 0; i < 5; i++) {
901 msleep(10); 1170 msleep(20);
902 data = reg_r(gspca_dev, OV534_REG_STATUS); 1171 data = reg_r(gspca_dev, OV534_REG_STATUS);
903 1172
904 switch (data) { 1173 switch (data) {
@@ -1221,6 +1490,13 @@ static int sd_init(struct gspca_dev *gspca_dev)
1221 sccb_w_array(gspca_dev, ov562x_init_2, 1490 sccb_w_array(gspca_dev, ov562x_init_2,
1222 ARRAY_SIZE(ov562x_init_2)); 1491 ARRAY_SIZE(ov562x_init_2));
1223 reg_w(gspca_dev, 0xe0, 0x00); 1492 reg_w(gspca_dev, 0xe0, 0x00);
1493 } else if ((sensor_id & 0xfff0) == 0x3610) {
1494 sd->sensor = SENSOR_OV361x;
1495 gspca_dev->cam.cam_mode = ov361x_mode;
1496 gspca_dev->cam.nmodes = ARRAY_SIZE(ov361x_mode);
1497 reg_w(gspca_dev, 0xe7, 0x3a);
1498 reg_w(gspca_dev, 0xf1, 0x60);
1499 sccb_write(gspca_dev, 0x12, 0x80);
1224 } else { 1500 } else {
1225 pr_err("Unknown sensor %04x", sensor_id); 1501 pr_err("Unknown sensor %04x", sensor_id);
1226 return -EINVAL; 1502 return -EINVAL;
@@ -1229,6 +1505,53 @@ static int sd_init(struct gspca_dev *gspca_dev)
1229 return gspca_dev->usb_err; 1505 return gspca_dev->usb_err;
1230} 1506}
1231 1507
1508static int sd_start_ov361x(struct gspca_dev *gspca_dev)
1509{
1510 sccb_write(gspca_dev, 0x12, 0x80);
1511 msleep(20);
1512 switch (gspca_dev->curr_mode % (ov361x_last)) {
1513 case ov361x_2048:
1514 reg_w_array(gspca_dev, ov361x_bridge_start_2048,
1515 ARRAY_SIZE(ov361x_bridge_start_2048));
1516 sccb_w_array(gspca_dev, ov361x_start_2048,
1517 ARRAY_SIZE(ov361x_start_2048));
1518 break;
1519 case ov361x_1600:
1520 reg_w_array(gspca_dev, ov361x_bridge_start_1600,
1521 ARRAY_SIZE(ov361x_bridge_start_1600));
1522 sccb_w_array(gspca_dev, ov361x_start_1600,
1523 ARRAY_SIZE(ov361x_start_1600));
1524 break;
1525 case ov361x_1024:
1526 reg_w_array(gspca_dev, ov361x_bridge_start_1024,
1527 ARRAY_SIZE(ov361x_bridge_start_1024));
1528 sccb_w_array(gspca_dev, ov361x_start_1024,
1529 ARRAY_SIZE(ov361x_start_1024));
1530 break;
1531 case ov361x_640:
1532 reg_w_array(gspca_dev, ov361x_bridge_start_640,
1533 ARRAY_SIZE(ov361x_bridge_start_640));
1534 sccb_w_array(gspca_dev, ov361x_start_640,
1535 ARRAY_SIZE(ov361x_start_640));
1536 break;
1537 case ov361x_320:
1538 reg_w_array(gspca_dev, ov361x_bridge_start_320,
1539 ARRAY_SIZE(ov361x_bridge_start_320));
1540 sccb_w_array(gspca_dev, ov361x_start_320,
1541 ARRAY_SIZE(ov361x_start_320));
1542 break;
1543 case ov361x_160:
1544 reg_w_array(gspca_dev, ov361x_bridge_start_160,
1545 ARRAY_SIZE(ov361x_bridge_start_160));
1546 sccb_w_array(gspca_dev, ov361x_start_160,
1547 ARRAY_SIZE(ov361x_start_160));
1548 break;
1549 }
1550 reg_w(gspca_dev, 0xe0, 0x00); /* start transfer */
1551
1552 return gspca_dev->usb_err;
1553}
1554
1232static int sd_start(struct gspca_dev *gspca_dev) 1555static int sd_start(struct gspca_dev *gspca_dev)
1233{ 1556{
1234 struct sd *sd = (struct sd *) gspca_dev; 1557 struct sd *sd = (struct sd *) gspca_dev;
@@ -1237,6 +1560,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
1237 return gspca_dev->usb_err; 1560 return gspca_dev->usb_err;
1238 if (sd->sensor == SENSOR_OV562x) 1561 if (sd->sensor == SENSOR_OV562x)
1239 return gspca_dev->usb_err; 1562 return gspca_dev->usb_err;
1563 if (sd->sensor == SENSOR_OV361x)
1564 return sd_start_ov361x(gspca_dev);
1240 1565
1241 switch (gspca_dev->curr_mode) { 1566 switch (gspca_dev->curr_mode) {
1242 case QVGA_MODE: /* 320x240 */ 1567 case QVGA_MODE: /* 320x240 */
@@ -1290,6 +1615,11 @@ static int sd_start(struct gspca_dev *gspca_dev)
1290 1615
1291static void sd_stopN(struct gspca_dev *gspca_dev) 1616static void sd_stopN(struct gspca_dev *gspca_dev)
1292{ 1617{
1618 if (((struct sd *)gspca_dev)->sensor == SENSOR_OV361x) {
1619 reg_w(gspca_dev, 0xe0, 0x01); /* stop transfer */
1620 /* reg_w(gspca_dev, 0x31, 0x09); */
1621 return;
1622 }
1293 reg_w(gspca_dev, 0xe0, 0x01); 1623 reg_w(gspca_dev, 0xe0, 0x01);
1294 set_led(gspca_dev, 0); 1624 set_led(gspca_dev, 0);
1295 reg_w(gspca_dev, 0xe0, 0x00); 1625 reg_w(gspca_dev, 0xe0, 0x00);
@@ -1425,6 +1755,8 @@ static int sd_init_controls(struct gspca_dev *gspca_dev)
1425 1755
1426 if (sd->sensor == SENSOR_OV971x) 1756 if (sd->sensor == SENSOR_OV971x)
1427 return 0; 1757 return 0;
1758 if (sd->sensor == SENSOR_OV361x)
1759 return 0;
1428 gspca_dev->vdev.ctrl_handler = hdl; 1760 gspca_dev->vdev.ctrl_handler = hdl;
1429 v4l2_ctrl_handler_init(hdl, 7); 1761 v4l2_ctrl_handler_init(hdl, 7);
1430 if (sd->sensor == SENSOR_OV562x) { 1762 if (sd->sensor == SENSOR_OV562x) {
diff --git a/drivers/media/usb/gspca/pac207.c b/drivers/media/usb/gspca/pac207.c
index 83519be94e58..cd79c180f67b 100644
--- a/drivers/media/usb/gspca/pac207.c
+++ b/drivers/media/usb/gspca/pac207.c
@@ -299,7 +299,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
299 pac207_write_regs(gspca_dev, 0x0042, pac207_sensor_init[3], 8); 299 pac207_write_regs(gspca_dev, 0x0042, pac207_sensor_init[3], 8);
300 300
301 /* Compression Balance */ 301 /* Compression Balance */
302 if (gspca_dev->width == 176) 302 if (gspca_dev->pixfmt.width == 176)
303 pac207_write_reg(gspca_dev, 0x4a, 0xff); 303 pac207_write_reg(gspca_dev, 0x4a, 0xff);
304 else 304 else
305 pac207_write_reg(gspca_dev, 0x4a, 0x30); 305 pac207_write_reg(gspca_dev, 0x4a, 0x30);
@@ -317,7 +317,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
317 mode = 0x00; 317 mode = 0x00;
318 else 318 else
319 mode = 0x02; 319 mode = 0x02;
320 if (gspca_dev->width == 176) { /* 176x144 */ 320 if (gspca_dev->pixfmt.width == 176) { /* 176x144 */
321 mode |= 0x01; 321 mode |= 0x01;
322 PDEBUG(D_STREAM, "pac207_start mode 176x144"); 322 PDEBUG(D_STREAM, "pac207_start mode 176x144");
323 } else { /* 352x288 */ 323 } else { /* 352x288 */
diff --git a/drivers/media/usb/gspca/pac7311.c b/drivers/media/usb/gspca/pac7311.c
index 1a5bdc853a80..25f86b1e74a8 100644
--- a/drivers/media/usb/gspca/pac7311.c
+++ b/drivers/media/usb/gspca/pac7311.c
@@ -326,7 +326,7 @@ static void setexposure(struct gspca_dev *gspca_dev, s32 val)
326 * 640x480 mode and page 4 reg 2 <= 3 then it must be 9 326 * 640x480 mode and page 4 reg 2 <= 3 then it must be 9
327 */ 327 */
328 reg_w(gspca_dev, 0xff, 0x01); 328 reg_w(gspca_dev, 0xff, 0x01);
329 if (gspca_dev->width != 640 && val <= 3) 329 if (gspca_dev->pixfmt.width != 640 && val <= 3)
330 reg_w(gspca_dev, 0x08, 0x09); 330 reg_w(gspca_dev, 0x08, 0x09);
331 else 331 else
332 reg_w(gspca_dev, 0x08, 0x08); 332 reg_w(gspca_dev, 0x08, 0x08);
@@ -337,7 +337,7 @@ static void setexposure(struct gspca_dev *gspca_dev, s32 val)
337 * camera to use higher compression or we may run out of 337 * camera to use higher compression or we may run out of
338 * bandwidth. 338 * bandwidth.
339 */ 339 */
340 if (gspca_dev->width == 640 && val == 2) 340 if (gspca_dev->pixfmt.width == 640 && val == 2)
341 reg_w(gspca_dev, 0x80, 0x01); 341 reg_w(gspca_dev, 0x80, 0x01);
342 else 342 else
343 reg_w(gspca_dev, 0x80, 0x1c); 343 reg_w(gspca_dev, 0x80, 0x1c);
@@ -615,7 +615,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
615 615
616 /* Start the new frame with the jpeg header */ 616 /* Start the new frame with the jpeg header */
617 pac_start_frame(gspca_dev, 617 pac_start_frame(gspca_dev,
618 gspca_dev->height, gspca_dev->width); 618 gspca_dev->pixfmt.height, gspca_dev->pixfmt.width);
619 } 619 }
620 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 620 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
621} 621}
diff --git a/drivers/media/usb/gspca/se401.c b/drivers/media/usb/gspca/se401.c
index 5f729b8aa2bd..5102cea50471 100644
--- a/drivers/media/usb/gspca/se401.c
+++ b/drivers/media/usb/gspca/se401.c
@@ -354,9 +354,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
354 354
355 /* set size + mode */ 355 /* set size + mode */
356 se401_write_req(gspca_dev, SE401_REQ_SET_WIDTH, 356 se401_write_req(gspca_dev, SE401_REQ_SET_WIDTH,
357 gspca_dev->width * mult, 0); 357 gspca_dev->pixfmt.width * mult, 0);
358 se401_write_req(gspca_dev, SE401_REQ_SET_HEIGHT, 358 se401_write_req(gspca_dev, SE401_REQ_SET_HEIGHT,
359 gspca_dev->height * mult, 0); 359 gspca_dev->pixfmt.height * mult, 0);
360 /* 360 /*
361 * HDG: disabled this as it does not seem to do anything 361 * HDG: disabled this as it does not seem to do anything
362 * se401_write_req(gspca_dev, SE401_REQ_SET_OUTPUT_MODE, 362 * se401_write_req(gspca_dev, SE401_REQ_SET_OUTPUT_MODE,
@@ -480,7 +480,7 @@ static void sd_complete_frame(struct gspca_dev *gspca_dev, u8 *data, int len)
480static void sd_pkt_scan_janggu(struct gspca_dev *gspca_dev, u8 *data, int len) 480static void sd_pkt_scan_janggu(struct gspca_dev *gspca_dev, u8 *data, int len)
481{ 481{
482 struct sd *sd = (struct sd *)gspca_dev; 482 struct sd *sd = (struct sd *)gspca_dev;
483 int imagesize = gspca_dev->width * gspca_dev->height; 483 int imagesize = gspca_dev->pixfmt.width * gspca_dev->pixfmt.height;
484 int i, plen, bits, pixels, info, count; 484 int i, plen, bits, pixels, info, count;
485 485
486 if (sd->restart_stream) 486 if (sd->restart_stream)
diff --git a/drivers/media/usb/gspca/sn9c20x.c b/drivers/media/usb/gspca/sn9c20x.c
index f4453d52801b..2a38621cf718 100644
--- a/drivers/media/usb/gspca/sn9c20x.c
+++ b/drivers/media/usb/gspca/sn9c20x.c
@@ -1955,7 +1955,7 @@ static int sd_isoc_init(struct gspca_dev *gspca_dev)
1955 return 0; 1955 return 0;
1956 } 1956 }
1957 1957
1958 switch (gspca_dev->width) { 1958 switch (gspca_dev->pixfmt.width) {
1959 case 160: /* 160x120 */ 1959 case 160: /* 160x120 */
1960 gspca_dev->alt = 2; 1960 gspca_dev->alt = 2;
1961 break; 1961 break;
@@ -1985,8 +1985,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
1985{ 1985{
1986 struct sd *sd = (struct sd *) gspca_dev; 1986 struct sd *sd = (struct sd *) gspca_dev;
1987 int mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 1987 int mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
1988 int width = gspca_dev->width; 1988 int width = gspca_dev->pixfmt.width;
1989 int height = gspca_dev->height; 1989 int height = gspca_dev->pixfmt.height;
1990 u8 fmt, scale = 0; 1990 u8 fmt, scale = 0;
1991 1991
1992 jpeg_define(sd->jpeg_hdr, height, width, 1992 jpeg_define(sd->jpeg_hdr, height, width,
diff --git a/drivers/media/usb/gspca/sonixb.c b/drivers/media/usb/gspca/sonixb.c
index d7ff3b9687c5..7277dbd2afcd 100644
--- a/drivers/media/usb/gspca/sonixb.c
+++ b/drivers/media/usb/gspca/sonixb.c
@@ -513,10 +513,7 @@ static void i2c_w(struct gspca_dev *gspca_dev, const u8 *buf)
513 if (gspca_dev->usb_buf[0] & 0x04) { 513 if (gspca_dev->usb_buf[0] & 0x04) {
514 if (gspca_dev->usb_buf[0] & 0x08) { 514 if (gspca_dev->usb_buf[0] & 0x08) {
515 dev_err(gspca_dev->v4l2_dev.dev, 515 dev_err(gspca_dev->v4l2_dev.dev,
516 "i2c error writing %02x %02x %02x %02x" 516 "i2c error writing %8ph\n", buf);
517 " %02x %02x %02x %02x\n",
518 buf[0], buf[1], buf[2], buf[3],
519 buf[4], buf[5], buf[6], buf[7]);
520 gspca_dev->usb_err = -EIO; 517 gspca_dev->usb_err = -EIO;
521 } 518 }
522 return; 519 return;
@@ -753,7 +750,7 @@ static void setexposure(struct gspca_dev *gspca_dev)
753 /* In 640x480, if the reg11 has less than 4, the image is 750 /* In 640x480, if the reg11 has less than 4, the image is
754 unstable (the bridge goes into a higher compression mode 751 unstable (the bridge goes into a higher compression mode
755 which we have not reverse engineered yet). */ 752 which we have not reverse engineered yet). */
756 if (gspca_dev->width == 640 && reg11 < 4) 753 if (gspca_dev->pixfmt.width == 640 && reg11 < 4)
757 reg11 = 4; 754 reg11 = 4;
758 755
759 /* frame exposure time in ms = 1000 * reg11 / 30 -> 756 /* frame exposure time in ms = 1000 * reg11 / 30 ->
diff --git a/drivers/media/usb/gspca/sonixj.c b/drivers/media/usb/gspca/sonixj.c
index 3b5ccb1c4cdf..c69b45d7cfbf 100644
--- a/drivers/media/usb/gspca/sonixj.c
+++ b/drivers/media/usb/gspca/sonixj.c
@@ -2204,7 +2204,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
2204 { 0x14, 0xe7, 0x1e, 0xdd }; 2204 { 0x14, 0xe7, 0x1e, 0xdd };
2205 2205
2206 /* create the JPEG header */ 2206 /* create the JPEG header */
2207 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 2207 jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
2208 gspca_dev->pixfmt.width,
2208 0x21); /* JPEG 422 */ 2209 0x21); /* JPEG 422 */
2209 2210
2210 /* initialize the bridge */ 2211 /* initialize the bridge */
diff --git a/drivers/media/usb/gspca/spca1528.c b/drivers/media/usb/gspca/spca1528.c
index 688592b289ea..f38fd8949609 100644
--- a/drivers/media/usb/gspca/spca1528.c
+++ b/drivers/media/usb/gspca/spca1528.c
@@ -255,7 +255,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
255 struct sd *sd = (struct sd *) gspca_dev; 255 struct sd *sd = (struct sd *) gspca_dev;
256 256
257 /* initialize the JPEG header */ 257 /* initialize the JPEG header */
258 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 258 jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
259 gspca_dev->pixfmt.width,
259 0x22); /* JPEG 411 */ 260 0x22); /* JPEG 411 */
260 261
261 /* the JPEG quality shall be 85% */ 262 /* the JPEG quality shall be 85% */
diff --git a/drivers/media/usb/gspca/spca500.c b/drivers/media/usb/gspca/spca500.c
index 9f8bf51fd64b..f011a309dd65 100644
--- a/drivers/media/usb/gspca/spca500.c
+++ b/drivers/media/usb/gspca/spca500.c
@@ -608,7 +608,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
608 __u8 xmult, ymult; 608 __u8 xmult, ymult;
609 609
610 /* create the JPEG header */ 610 /* create the JPEG header */
611 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 611 jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
612 gspca_dev->pixfmt.width,
612 0x22); /* JPEG 411 */ 613 0x22); /* JPEG 411 */
613 jpeg_set_qual(sd->jpeg_hdr, QUALITY); 614 jpeg_set_qual(sd->jpeg_hdr, QUALITY);
614 615
diff --git a/drivers/media/usb/gspca/sq905c.c b/drivers/media/usb/gspca/sq905c.c
index acb19fb9a3df..aa21edc9502d 100644
--- a/drivers/media/usb/gspca/sq905c.c
+++ b/drivers/media/usb/gspca/sq905c.c
@@ -272,7 +272,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
272 272
273 dev->cap_mode = gspca_dev->cam.cam_mode; 273 dev->cap_mode = gspca_dev->cam.cam_mode;
274 /* "Open the shutter" and set size, to start capture */ 274 /* "Open the shutter" and set size, to start capture */
275 switch (gspca_dev->width) { 275 switch (gspca_dev->pixfmt.width) {
276 case 640: 276 case 640:
277 PDEBUG(D_STREAM, "Start streaming at high resolution"); 277 PDEBUG(D_STREAM, "Start streaming at high resolution");
278 dev->cap_mode++; 278 dev->cap_mode++;
diff --git a/drivers/media/usb/gspca/sq930x.c b/drivers/media/usb/gspca/sq930x.c
index b10d0821111c..e274cf19a3ea 100644
--- a/drivers/media/usb/gspca/sq930x.c
+++ b/drivers/media/usb/gspca/sq930x.c
@@ -906,7 +906,8 @@ static int sd_isoc_init(struct gspca_dev *gspca_dev)
906 906
907 gspca_dev->cam.bulk_nurbs = 1; /* there must be one URB only */ 907 gspca_dev->cam.bulk_nurbs = 1; /* there must be one URB only */
908 sd->do_ctrl = 0; 908 sd->do_ctrl = 0;
909 gspca_dev->cam.bulk_size = gspca_dev->width * gspca_dev->height + 8; 909 gspca_dev->cam.bulk_size = gspca_dev->pixfmt.width *
910 gspca_dev->pixfmt.height + 8;
910 return 0; 911 return 0;
911} 912}
912 913
diff --git a/drivers/media/usb/gspca/stk014.c b/drivers/media/usb/gspca/stk014.c
index 8c0982607f25..b0c70fea760b 100644
--- a/drivers/media/usb/gspca/stk014.c
+++ b/drivers/media/usb/gspca/stk014.c
@@ -250,7 +250,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
250 int ret, value; 250 int ret, value;
251 251
252 /* create the JPEG header */ 252 /* create the JPEG header */
253 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 253 jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
254 gspca_dev->pixfmt.width,
254 0x22); /* JPEG 411 */ 255 0x22); /* JPEG 411 */
255 jpeg_set_qual(sd->jpeg_hdr, QUALITY); 256 jpeg_set_qual(sd->jpeg_hdr, QUALITY);
256 257
@@ -261,7 +262,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
261 set_par(gspca_dev, 0x00000000); 262 set_par(gspca_dev, 0x00000000);
262 set_par(gspca_dev, 0x8002e001); 263 set_par(gspca_dev, 0x8002e001);
263 set_par(gspca_dev, 0x14000000); 264 set_par(gspca_dev, 0x14000000);
264 if (gspca_dev->width > 320) 265 if (gspca_dev->pixfmt.width > 320)
265 value = 0x8002e001; /* 640x480 */ 266 value = 0x8002e001; /* 640x480 */
266 else 267 else
267 value = 0x4001f000; /* 320x240 */ 268 value = 0x4001f000; /* 320x240 */
diff --git a/drivers/media/usb/gspca/stk1135.c b/drivers/media/usb/gspca/stk1135.c
index 585868835ace..1fc80af2a189 100644
--- a/drivers/media/usb/gspca/stk1135.c
+++ b/drivers/media/usb/gspca/stk1135.c
@@ -48,42 +48,11 @@ struct sd {
48}; 48};
49 49
50static const struct v4l2_pix_format stk1135_modes[] = { 50static const struct v4l2_pix_format stk1135_modes[] = {
51 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, 51 /* default mode (this driver supports variable resolution) */
52 .bytesperline = 160,
53 .sizeimage = 160 * 120,
54 .colorspace = V4L2_COLORSPACE_SRGB},
55 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
56 .bytesperline = 176,
57 .sizeimage = 176 * 144,
58 .colorspace = V4L2_COLORSPACE_SRGB},
59 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
60 .bytesperline = 320,
61 .sizeimage = 320 * 240,
62 .colorspace = V4L2_COLORSPACE_SRGB},
63 {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
64 .bytesperline = 352,
65 .sizeimage = 352 * 288,
66 .colorspace = V4L2_COLORSPACE_SRGB},
67 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, 52 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
68 .bytesperline = 640, 53 .bytesperline = 640,
69 .sizeimage = 640 * 480, 54 .sizeimage = 640 * 480,
70 .colorspace = V4L2_COLORSPACE_SRGB}, 55 .colorspace = V4L2_COLORSPACE_SRGB},
71 {720, 576, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
72 .bytesperline = 720,
73 .sizeimage = 720 * 576,
74 .colorspace = V4L2_COLORSPACE_SRGB},
75 {800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
76 .bytesperline = 800,
77 .sizeimage = 800 * 600,
78 .colorspace = V4L2_COLORSPACE_SRGB},
79 {1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
80 .bytesperline = 1024,
81 .sizeimage = 1024 * 768,
82 .colorspace = V4L2_COLORSPACE_SRGB},
83 {1280, 1024, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
84 .bytesperline = 1280,
85 .sizeimage = 1280 * 1024,
86 .colorspace = V4L2_COLORSPACE_SRGB},
87}; 56};
88 57
89/* -- read a register -- */ 58/* -- read a register -- */
@@ -347,16 +316,16 @@ static void stk1135_configure_mt9m112(struct gspca_dev *gspca_dev)
347 sensor_write(gspca_dev, cfg[i].reg, cfg[i].val); 316 sensor_write(gspca_dev, cfg[i].reg, cfg[i].val);
348 317
349 /* set output size */ 318 /* set output size */
350 width = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].width; 319 width = gspca_dev->pixfmt.width;
351 height = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].height; 320 height = gspca_dev->pixfmt.height;
352 if (width <= 640) { /* use context A (half readout speed by default) */ 321 if (width <= 640 && height <= 512) { /* context A (half readout speed)*/
353 sensor_write(gspca_dev, 0x1a7, width); 322 sensor_write(gspca_dev, 0x1a7, width);
354 sensor_write(gspca_dev, 0x1aa, height); 323 sensor_write(gspca_dev, 0x1aa, height);
355 /* set read mode context A */ 324 /* set read mode context A */
356 sensor_write(gspca_dev, 0x0c8, 0x0000); 325 sensor_write(gspca_dev, 0x0c8, 0x0000);
357 /* set resize, read mode, vblank, hblank context A */ 326 /* set resize, read mode, vblank, hblank context A */
358 sensor_write(gspca_dev, 0x2c8, 0x0000); 327 sensor_write(gspca_dev, 0x2c8, 0x0000);
359 } else { /* use context B (full readout speed by default) */ 328 } else { /* context B (full readout speed) */
360 sensor_write(gspca_dev, 0x1a1, width); 329 sensor_write(gspca_dev, 0x1a1, width);
361 sensor_write(gspca_dev, 0x1a4, height); 330 sensor_write(gspca_dev, 0x1a4, height);
362 /* set read mode context B */ 331 /* set read mode context B */
@@ -484,8 +453,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
484 reg_w(gspca_dev, STK1135_REG_CISPO + 3, 0x00); 453 reg_w(gspca_dev, STK1135_REG_CISPO + 3, 0x00);
485 454
486 /* set capture end position */ 455 /* set capture end position */
487 width = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].width; 456 width = gspca_dev->pixfmt.width;
488 height = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].height; 457 height = gspca_dev->pixfmt.height;
489 reg_w(gspca_dev, STK1135_REG_CIEPO + 0, width & 0xff); 458 reg_w(gspca_dev, STK1135_REG_CIEPO + 0, width & 0xff);
490 reg_w(gspca_dev, STK1135_REG_CIEPO + 1, width >> 8); 459 reg_w(gspca_dev, STK1135_REG_CIEPO + 1, width >> 8);
491 reg_w(gspca_dev, STK1135_REG_CIEPO + 2, height & 0xff); 460 reg_w(gspca_dev, STK1135_REG_CIEPO + 2, height & 0xff);
@@ -643,6 +612,35 @@ static int sd_init_controls(struct gspca_dev *gspca_dev)
643 return 0; 612 return 0;
644} 613}
645 614
615static void stk1135_try_fmt(struct gspca_dev *gspca_dev, struct v4l2_format *fmt)
616{
617 fmt->fmt.pix.width = clamp(fmt->fmt.pix.width, 32U, 1280U);
618 fmt->fmt.pix.height = clamp(fmt->fmt.pix.height, 32U, 1024U);
619 /* round up to even numbers */
620 fmt->fmt.pix.width += (fmt->fmt.pix.width & 1);
621 fmt->fmt.pix.height += (fmt->fmt.pix.height & 1);
622
623 fmt->fmt.pix.bytesperline = fmt->fmt.pix.width;
624 fmt->fmt.pix.sizeimage = fmt->fmt.pix.width * fmt->fmt.pix.height;
625}
626
627static int stk1135_enum_framesizes(struct gspca_dev *gspca_dev,
628 struct v4l2_frmsizeenum *fsize)
629{
630 if (fsize->index != 0 || fsize->pixel_format != V4L2_PIX_FMT_SBGGR8)
631 return -EINVAL;
632
633 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
634 fsize->stepwise.min_width = 32;
635 fsize->stepwise.min_height = 32;
636 fsize->stepwise.max_width = 1280;
637 fsize->stepwise.max_height = 1024;
638 fsize->stepwise.step_width = 2;
639 fsize->stepwise.step_height = 2;
640
641 return 0;
642}
643
646/* sub-driver description */ 644/* sub-driver description */
647static const struct sd_desc sd_desc = { 645static const struct sd_desc sd_desc = {
648 .name = MODULE_NAME, 646 .name = MODULE_NAME,
@@ -653,6 +651,8 @@ static const struct sd_desc sd_desc = {
653 .stopN = sd_stopN, 651 .stopN = sd_stopN,
654 .pkt_scan = sd_pkt_scan, 652 .pkt_scan = sd_pkt_scan,
655 .dq_callback = stk1135_dq_callback, 653 .dq_callback = stk1135_dq_callback,
654 .try_fmt = stk1135_try_fmt,
655 .enum_framesizes = stk1135_enum_framesizes,
656}; 656};
657 657
658/* -- module initialisation -- */ 658/* -- module initialisation -- */
diff --git a/drivers/media/usb/gspca/stv06xx/stv06xx.c b/drivers/media/usb/gspca/stv06xx/stv06xx.c
index 55ee7a61c67f..49d209bbf9ee 100644
--- a/drivers/media/usb/gspca/stv06xx/stv06xx.c
+++ b/drivers/media/usb/gspca/stv06xx/stv06xx.c
@@ -452,7 +452,7 @@ frame_data:
452 NULL, 0); 452 NULL, 0);
453 453
454 if (sd->bridge == BRIDGE_ST6422) 454 if (sd->bridge == BRIDGE_ST6422)
455 sd->to_skip = gspca_dev->width * 4; 455 sd->to_skip = gspca_dev->pixfmt.width * 4;
456 456
457 if (chunk_len) 457 if (chunk_len)
458 PERR("Chunk length is " 458 PERR("Chunk length is "
diff --git a/drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c b/drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c
index 8206b7743300..8d785edcccf2 100644
--- a/drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c
+++ b/drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c
@@ -421,7 +421,7 @@ static int pb0100_set_autogain_target(struct gspca_dev *gspca_dev, __s32 val)
421 421
422 /* Number of pixels counted by the sensor when subsampling the pixels. 422 /* Number of pixels counted by the sensor when subsampling the pixels.
423 * Slightly larger than the real value to avoid oscillation */ 423 * Slightly larger than the real value to avoid oscillation */
424 totalpixels = gspca_dev->width * gspca_dev->height; 424 totalpixels = gspca_dev->pixfmt.width * gspca_dev->pixfmt.height;
425 totalpixels = totalpixels/(8*8) + totalpixels/(64*64); 425 totalpixels = totalpixels/(8*8) + totalpixels/(64*64);
426 426
427 brightpixels = (totalpixels * val) >> 8; 427 brightpixels = (totalpixels * val) >> 8;
diff --git a/drivers/media/usb/gspca/sunplus.c b/drivers/media/usb/gspca/sunplus.c
index af8767a9bd4c..a517d185febe 100644
--- a/drivers/media/usb/gspca/sunplus.c
+++ b/drivers/media/usb/gspca/sunplus.c
@@ -715,7 +715,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
715 int enable; 715 int enable;
716 716
717 /* create the JPEG header */ 717 /* create the JPEG header */
718 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 718 jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
719 gspca_dev->pixfmt.width,
719 0x22); /* JPEG 411 */ 720 0x22); /* JPEG 411 */
720 jpeg_set_qual(sd->jpeg_hdr, QUALITY); 721 jpeg_set_qual(sd->jpeg_hdr, QUALITY);
721 722
diff --git a/drivers/media/usb/gspca/topro.c b/drivers/media/usb/gspca/topro.c
index 4cb511ccc5f6..640c2fe760b3 100644
--- a/drivers/media/usb/gspca/topro.c
+++ b/drivers/media/usb/gspca/topro.c
@@ -3856,7 +3856,7 @@ static void setsharpness(struct gspca_dev *gspca_dev, s32 val)
3856 3856
3857 if (sd->bridge == BRIDGE_TP6800) { 3857 if (sd->bridge == BRIDGE_TP6800) {
3858 val |= 0x08; /* grid compensation enable */ 3858 val |= 0x08; /* grid compensation enable */
3859 if (gspca_dev->width == 640) 3859 if (gspca_dev->pixfmt.width == 640)
3860 reg_w(gspca_dev, TP6800_R78_FORMAT, 0x00); /* vga */ 3860 reg_w(gspca_dev, TP6800_R78_FORMAT, 0x00); /* vga */
3861 else 3861 else
3862 val |= 0x04; /* scaling down enable */ 3862 val |= 0x04; /* scaling down enable */
@@ -3880,7 +3880,7 @@ static void set_resolution(struct gspca_dev *gspca_dev)
3880 struct sd *sd = (struct sd *) gspca_dev; 3880 struct sd *sd = (struct sd *) gspca_dev;
3881 3881
3882 reg_w(gspca_dev, TP6800_R21_ENDP_1_CTL, 0x00); 3882 reg_w(gspca_dev, TP6800_R21_ENDP_1_CTL, 0x00);
3883 if (gspca_dev->width == 320) { 3883 if (gspca_dev->pixfmt.width == 320) {
3884 reg_w(gspca_dev, TP6800_R3F_FRAME_RATE, 0x06); 3884 reg_w(gspca_dev, TP6800_R3F_FRAME_RATE, 0x06);
3885 msleep(100); 3885 msleep(100);
3886 i2c_w(gspca_dev, CX0342_AUTO_ADC_CALIB, 0x01); 3886 i2c_w(gspca_dev, CX0342_AUTO_ADC_CALIB, 0x01);
@@ -3924,7 +3924,7 @@ static int get_fr_idx(struct gspca_dev *gspca_dev)
3924 3924
3925 /* 640x480 * 30 fps does not work */ 3925 /* 640x480 * 30 fps does not work */
3926 if (i == 6 /* if 30 fps */ 3926 if (i == 6 /* if 30 fps */
3927 && gspca_dev->width == 640) 3927 && gspca_dev->pixfmt.width == 640)
3928 i = 0x05; /* 15 fps */ 3928 i = 0x05; /* 15 fps */
3929 } else { 3929 } else {
3930 for (i = 0; i < ARRAY_SIZE(rates_6810) - 1; i++) { 3930 for (i = 0; i < ARRAY_SIZE(rates_6810) - 1; i++) {
@@ -3935,7 +3935,7 @@ static int get_fr_idx(struct gspca_dev *gspca_dev)
3935 3935
3936 /* 640x480 * 30 fps does not work */ 3936 /* 640x480 * 30 fps does not work */
3937 if (i == 7 /* if 30 fps */ 3937 if (i == 7 /* if 30 fps */
3938 && gspca_dev->width == 640) 3938 && gspca_dev->pixfmt.width == 640)
3939 i = 6; /* 15 fps */ 3939 i = 6; /* 15 fps */
3940 i |= 0x80; /* clock * 1 */ 3940 i |= 0x80; /* clock * 1 */
3941 } 3941 }
@@ -4554,7 +4554,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
4554{ 4554{
4555 struct sd *sd = (struct sd *) gspca_dev; 4555 struct sd *sd = (struct sd *) gspca_dev;
4556 4556
4557 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width); 4557 jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
4558 gspca_dev->pixfmt.width);
4558 set_dqt(gspca_dev, sd->quality); 4559 set_dqt(gspca_dev, sd->quality);
4559 if (sd->bridge == BRIDGE_TP6800) { 4560 if (sd->bridge == BRIDGE_TP6800) {
4560 if (sd->sensor == SENSOR_CX0342) 4561 if (sd->sensor == SENSOR_CX0342)
@@ -4737,7 +4738,7 @@ static void sd_dq_callback(struct gspca_dev *gspca_dev)
4737 (gspca_dev->usb_buf[26] << 8) + gspca_dev->usb_buf[25] + 4738 (gspca_dev->usb_buf[26] << 8) + gspca_dev->usb_buf[25] +
4738 (gspca_dev->usb_buf[29] << 8) + gspca_dev->usb_buf[28]) 4739 (gspca_dev->usb_buf[29] << 8) + gspca_dev->usb_buf[28])
4739 / 8; 4740 / 8;
4740 if (gspca_dev->width == 640) 4741 if (gspca_dev->pixfmt.width == 640)
4741 luma /= 4; 4742 luma /= 4;
4742 reg_w(gspca_dev, 0x7d, 0x00); 4743 reg_w(gspca_dev, 0x7d, 0x00);
4743 4744
diff --git a/drivers/media/usb/gspca/tv8532.c b/drivers/media/usb/gspca/tv8532.c
index 8591324a53e1..d497ba38af0d 100644
--- a/drivers/media/usb/gspca/tv8532.c
+++ b/drivers/media/usb/gspca/tv8532.c
@@ -268,7 +268,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
268 packet_type0 = packet_type1 = INTER_PACKET; 268 packet_type0 = packet_type1 = INTER_PACKET;
269 if (gspca_dev->empty_packet) { 269 if (gspca_dev->empty_packet) {
270 gspca_dev->empty_packet = 0; 270 gspca_dev->empty_packet = 0;
271 sd->packet = gspca_dev->height / 2; 271 sd->packet = gspca_dev->pixfmt.height / 2;
272 packet_type0 = FIRST_PACKET; 272 packet_type0 = FIRST_PACKET;
273 } else if (sd->packet == 0) 273 } else if (sd->packet == 0)
274 return; /* 2 more lines in 352x288 ! */ 274 return; /* 2 more lines in 352x288 ! */
@@ -284,9 +284,10 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
284 * - 4 bytes 284 * - 4 bytes
285 */ 285 */
286 gspca_frame_add(gspca_dev, packet_type0, 286 gspca_frame_add(gspca_dev, packet_type0,
287 data + 2, gspca_dev->width); 287 data + 2, gspca_dev->pixfmt.width);
288 gspca_frame_add(gspca_dev, packet_type1, 288 gspca_frame_add(gspca_dev, packet_type1,
289 data + gspca_dev->width + 5, gspca_dev->width); 289 data + gspca_dev->pixfmt.width + 5,
290 gspca_dev->pixfmt.width);
290} 291}
291 292
292static int sd_s_ctrl(struct v4l2_ctrl *ctrl) 293static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
diff --git a/drivers/media/usb/gspca/vicam.c b/drivers/media/usb/gspca/vicam.c
index a2275cfe0b81..103f6c4236b0 100644
--- a/drivers/media/usb/gspca/vicam.c
+++ b/drivers/media/usb/gspca/vicam.c
@@ -121,13 +121,13 @@ static int vicam_read_frame(struct gspca_dev *gspca_dev, u8 *data, int size)
121 121
122 memset(req_data, 0, 16); 122 memset(req_data, 0, 16);
123 req_data[0] = gain; 123 req_data[0] = gain;
124 if (gspca_dev->width == 256) 124 if (gspca_dev->pixfmt.width == 256)
125 req_data[1] |= 0x01; /* low nibble x-scale */ 125 req_data[1] |= 0x01; /* low nibble x-scale */
126 if (gspca_dev->height <= 122) { 126 if (gspca_dev->pixfmt.height <= 122) {
127 req_data[1] |= 0x10; /* high nibble y-scale */ 127 req_data[1] |= 0x10; /* high nibble y-scale */
128 unscaled_height = gspca_dev->height * 2; 128 unscaled_height = gspca_dev->pixfmt.height * 2;
129 } else 129 } else
130 unscaled_height = gspca_dev->height; 130 unscaled_height = gspca_dev->pixfmt.height;
131 req_data[2] = 0x90; /* unknown, does not seem to do anything */ 131 req_data[2] = 0x90; /* unknown, does not seem to do anything */
132 if (unscaled_height <= 200) 132 if (unscaled_height <= 200)
133 req_data[3] = 0x06; /* vend? */ 133 req_data[3] = 0x06; /* vend? */
diff --git a/drivers/media/usb/gspca/w996Xcf.c b/drivers/media/usb/gspca/w996Xcf.c
index 2165da0c7ce1..fb9fe2ef3a6f 100644
--- a/drivers/media/usb/gspca/w996Xcf.c
+++ b/drivers/media/usb/gspca/w996Xcf.c
@@ -430,11 +430,11 @@ static void w9968cf_set_crop_window(struct sd *sd)
430 #define SC(x) ((x) << 10) 430 #define SC(x) ((x) << 10)
431 431
432 /* Scaling factors */ 432 /* Scaling factors */
433 fw = SC(sd->gspca_dev.width) / max_width; 433 fw = SC(sd->gspca_dev.pixfmt.width) / max_width;
434 fh = SC(sd->gspca_dev.height) / max_height; 434 fh = SC(sd->gspca_dev.pixfmt.height) / max_height;
435 435
436 cw = (fw >= fh) ? max_width : SC(sd->gspca_dev.width) / fh; 436 cw = (fw >= fh) ? max_width : SC(sd->gspca_dev.pixfmt.width) / fh;
437 ch = (fw >= fh) ? SC(sd->gspca_dev.height) / fw : max_height; 437 ch = (fw >= fh) ? SC(sd->gspca_dev.pixfmt.height) / fw : max_height;
438 438
439 sd->sensor_width = max_width; 439 sd->sensor_width = max_width;
440 sd->sensor_height = max_height; 440 sd->sensor_height = max_height;
@@ -454,34 +454,34 @@ static void w9968cf_mode_init_regs(struct sd *sd)
454 454
455 w9968cf_set_crop_window(sd); 455 w9968cf_set_crop_window(sd);
456 456
457 reg_w(sd, 0x14, sd->gspca_dev.width); 457 reg_w(sd, 0x14, sd->gspca_dev.pixfmt.width);
458 reg_w(sd, 0x15, sd->gspca_dev.height); 458 reg_w(sd, 0x15, sd->gspca_dev.pixfmt.height);
459 459
460 /* JPEG width & height */ 460 /* JPEG width & height */
461 reg_w(sd, 0x30, sd->gspca_dev.width); 461 reg_w(sd, 0x30, sd->gspca_dev.pixfmt.width);
462 reg_w(sd, 0x31, sd->gspca_dev.height); 462 reg_w(sd, 0x31, sd->gspca_dev.pixfmt.height);
463 463
464 /* Y & UV frame buffer strides (in WORD) */ 464 /* Y & UV frame buffer strides (in WORD) */
465 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat == 465 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
466 V4L2_PIX_FMT_JPEG) { 466 V4L2_PIX_FMT_JPEG) {
467 reg_w(sd, 0x2c, sd->gspca_dev.width / 2); 467 reg_w(sd, 0x2c, sd->gspca_dev.pixfmt.width / 2);
468 reg_w(sd, 0x2d, sd->gspca_dev.width / 4); 468 reg_w(sd, 0x2d, sd->gspca_dev.pixfmt.width / 4);
469 } else 469 } else
470 reg_w(sd, 0x2c, sd->gspca_dev.width); 470 reg_w(sd, 0x2c, sd->gspca_dev.pixfmt.width);
471 471
472 reg_w(sd, 0x00, 0xbf17); /* reset everything */ 472 reg_w(sd, 0x00, 0xbf17); /* reset everything */
473 reg_w(sd, 0x00, 0xbf10); /* normal operation */ 473 reg_w(sd, 0x00, 0xbf10); /* normal operation */
474 474
475 /* Transfer size in WORDS (for UYVY format only) */ 475 /* Transfer size in WORDS (for UYVY format only) */
476 val = sd->gspca_dev.width * sd->gspca_dev.height; 476 val = sd->gspca_dev.pixfmt.width * sd->gspca_dev.pixfmt.height;
477 reg_w(sd, 0x3d, val & 0xffff); /* low bits */ 477 reg_w(sd, 0x3d, val & 0xffff); /* low bits */
478 reg_w(sd, 0x3e, val >> 16); /* high bits */ 478 reg_w(sd, 0x3e, val >> 16); /* high bits */
479 479
480 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat == 480 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
481 V4L2_PIX_FMT_JPEG) { 481 V4L2_PIX_FMT_JPEG) {
482 /* We may get called multiple times (usb isoc bw negotiat.) */ 482 /* We may get called multiple times (usb isoc bw negotiat.) */
483 jpeg_define(sd->jpeg_hdr, sd->gspca_dev.height, 483 jpeg_define(sd->jpeg_hdr, sd->gspca_dev.pixfmt.height,
484 sd->gspca_dev.width, 0x22); /* JPEG 420 */ 484 sd->gspca_dev.pixfmt.width, 0x22); /* JPEG 420 */
485 jpeg_set_qual(sd->jpeg_hdr, v4l2_ctrl_g_ctrl(sd->jpegqual)); 485 jpeg_set_qual(sd->jpeg_hdr, v4l2_ctrl_g_ctrl(sd->jpegqual));
486 w9968cf_upload_quantizationtables(sd); 486 w9968cf_upload_quantizationtables(sd);
487 v4l2_ctrl_grab(sd->jpegqual, true); 487 v4l2_ctrl_grab(sd->jpegqual, true);
diff --git a/drivers/media/usb/gspca/xirlink_cit.c b/drivers/media/usb/gspca/xirlink_cit.c
index 7eaf64eb867c..a41aa7817c54 100644
--- a/drivers/media/usb/gspca/xirlink_cit.c
+++ b/drivers/media/usb/gspca/xirlink_cit.c
@@ -1471,14 +1471,14 @@ static int cit_get_clock_div(struct gspca_dev *gspca_dev)
1471 1471
1472 while (clock_div > 3 && 1472 while (clock_div > 3 &&
1473 1000 * packet_size > 1473 1000 * packet_size >
1474 gspca_dev->width * gspca_dev->height * 1474 gspca_dev->pixfmt.width * gspca_dev->pixfmt.height *
1475 fps[clock_div - 1] * 3 / 2) 1475 fps[clock_div - 1] * 3 / 2)
1476 clock_div--; 1476 clock_div--;
1477 1477
1478 PDEBUG(D_PROBE, 1478 PDEBUG(D_PROBE,
1479 "PacketSize: %d, res: %dx%d -> using clockdiv: %d (%d fps)", 1479 "PacketSize: %d, res: %dx%d -> using clockdiv: %d (%d fps)",
1480 packet_size, gspca_dev->width, gspca_dev->height, clock_div, 1480 packet_size, gspca_dev->pixfmt.width, gspca_dev->pixfmt.height,
1481 fps[clock_div]); 1481 clock_div, fps[clock_div]);
1482 1482
1483 return clock_div; 1483 return clock_div;
1484} 1484}
@@ -1502,7 +1502,7 @@ static int cit_start_model0(struct gspca_dev *gspca_dev)
1502 cit_write_reg(gspca_dev, 0x0002, 0x0426); 1502 cit_write_reg(gspca_dev, 0x0002, 0x0426);
1503 cit_write_reg(gspca_dev, 0x0014, 0x0427); 1503 cit_write_reg(gspca_dev, 0x0014, 0x0427);
1504 1504
1505 switch (gspca_dev->width) { 1505 switch (gspca_dev->pixfmt.width) {
1506 case 160: /* 160x120 */ 1506 case 160: /* 160x120 */
1507 cit_write_reg(gspca_dev, 0x0004, 0x010b); 1507 cit_write_reg(gspca_dev, 0x0004, 0x010b);
1508 cit_write_reg(gspca_dev, 0x0001, 0x010a); 1508 cit_write_reg(gspca_dev, 0x0001, 0x010a);
@@ -1643,7 +1643,7 @@ static int cit_start_model1(struct gspca_dev *gspca_dev)
1643 cit_write_reg(gspca_dev, 0x00, 0x0101); 1643 cit_write_reg(gspca_dev, 0x00, 0x0101);
1644 cit_write_reg(gspca_dev, 0x00, 0x010a); 1644 cit_write_reg(gspca_dev, 0x00, 0x010a);
1645 1645
1646 switch (gspca_dev->width) { 1646 switch (gspca_dev->pixfmt.width) {
1647 case 128: /* 128x96 */ 1647 case 128: /* 128x96 */
1648 cit_write_reg(gspca_dev, 0x80, 0x0103); 1648 cit_write_reg(gspca_dev, 0x80, 0x0103);
1649 cit_write_reg(gspca_dev, 0x60, 0x0105); 1649 cit_write_reg(gspca_dev, 0x60, 0x0105);
@@ -1700,7 +1700,7 @@ static int cit_start_model1(struct gspca_dev *gspca_dev)
1700 } 1700 }
1701 1701
1702 /* Assorted init */ 1702 /* Assorted init */
1703 switch (gspca_dev->width) { 1703 switch (gspca_dev->pixfmt.width) {
1704 case 128: /* 128x96 */ 1704 case 128: /* 128x96 */
1705 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e); 1705 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
1706 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */ 1706 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
@@ -1753,7 +1753,7 @@ static int cit_start_model2(struct gspca_dev *gspca_dev)
1753 cit_write_reg(gspca_dev, 0x0000, 0x0108); 1753 cit_write_reg(gspca_dev, 0x0000, 0x0108);
1754 cit_write_reg(gspca_dev, 0x0001, 0x0133); 1754 cit_write_reg(gspca_dev, 0x0001, 0x0133);
1755 cit_write_reg(gspca_dev, 0x0001, 0x0102); 1755 cit_write_reg(gspca_dev, 0x0001, 0x0102);
1756 switch (gspca_dev->width) { 1756 switch (gspca_dev->pixfmt.width) {
1757 case 176: /* 176x144 */ 1757 case 176: /* 176x144 */
1758 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */ 1758 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1759 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */ 1759 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
@@ -1792,7 +1792,7 @@ static int cit_start_model2(struct gspca_dev *gspca_dev)
1792 1792
1793 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */ 1793 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
1794 1794
1795 switch (gspca_dev->width) { 1795 switch (gspca_dev->pixfmt.width) {
1796 case 176: /* 176x144 */ 1796 case 176: /* 176x144 */
1797 cit_write_reg(gspca_dev, 0x0050, 0x0111); 1797 cit_write_reg(gspca_dev, 0x0050, 0x0111);
1798 cit_write_reg(gspca_dev, 0x00d0, 0x0111); 1798 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
@@ -1840,7 +1840,7 @@ static int cit_start_model2(struct gspca_dev *gspca_dev)
1840 * Magic control of CMOS sensor. Only lower values like 1840 * Magic control of CMOS sensor. Only lower values like
1841 * 0-3 work, and picture shifts left or right. Don't change. 1841 * 0-3 work, and picture shifts left or right. Don't change.
1842 */ 1842 */
1843 switch (gspca_dev->width) { 1843 switch (gspca_dev->pixfmt.width) {
1844 case 176: /* 176x144 */ 1844 case 176: /* 176x144 */
1845 cit_model2_Packet1(gspca_dev, 0x0014, 0x0002); 1845 cit_model2_Packet1(gspca_dev, 0x0014, 0x0002);
1846 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */ 1846 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
@@ -1899,7 +1899,7 @@ static int cit_start_model2(struct gspca_dev *gspca_dev)
1899 * does not allow arbitrary values and apparently is a bit mask, to 1899 * does not allow arbitrary values and apparently is a bit mask, to
1900 * be activated only at appropriate time. Don't change it randomly! 1900 * be activated only at appropriate time. Don't change it randomly!
1901 */ 1901 */
1902 switch (gspca_dev->width) { 1902 switch (gspca_dev->pixfmt.width) {
1903 case 176: /* 176x144 */ 1903 case 176: /* 176x144 */
1904 cit_model2_Packet1(gspca_dev, 0x0026, 0x00c2); 1904 cit_model2_Packet1(gspca_dev, 0x0026, 0x00c2);
1905 break; 1905 break;
@@ -2023,7 +2023,7 @@ static int cit_start_model3(struct gspca_dev *gspca_dev)
2023 cit_model3_Packet1(gspca_dev, 0x009e, 0x0096); 2023 cit_model3_Packet1(gspca_dev, 0x009e, 0x0096);
2024 cit_model3_Packet1(gspca_dev, 0x009f, 0x000a); 2024 cit_model3_Packet1(gspca_dev, 0x009f, 0x000a);
2025 2025
2026 switch (gspca_dev->width) { 2026 switch (gspca_dev->pixfmt.width) {
2027 case 160: 2027 case 160:
2028 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */ 2028 cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
2029 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */ 2029 cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
@@ -2134,7 +2134,7 @@ static int cit_start_model3(struct gspca_dev *gspca_dev)
2134 like with the IBM netcam pro). */ 2134 like with the IBM netcam pro). */
2135 cit_write_reg(gspca_dev, clock_div, 0x0111); /* Clock Divider */ 2135 cit_write_reg(gspca_dev, clock_div, 0x0111); /* Clock Divider */
2136 2136
2137 switch (gspca_dev->width) { 2137 switch (gspca_dev->pixfmt.width) {
2138 case 160: 2138 case 160:
2139 cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */ 2139 cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */
2140 cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */ 2140 cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */
@@ -2211,7 +2211,7 @@ static int cit_start_model4(struct gspca_dev *gspca_dev)
2211 cit_write_reg(gspca_dev, 0xfffa, 0x0124); 2211 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2212 cit_model4_Packet1(gspca_dev, 0x0034, 0x0000); 2212 cit_model4_Packet1(gspca_dev, 0x0034, 0x0000);
2213 2213
2214 switch (gspca_dev->width) { 2214 switch (gspca_dev->pixfmt.width) {
2215 case 128: /* 128x96 */ 2215 case 128: /* 128x96 */
2216 cit_write_reg(gspca_dev, 0x0070, 0x0119); 2216 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2217 cit_write_reg(gspca_dev, 0x00d0, 0x0111); 2217 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
@@ -2531,7 +2531,7 @@ static int cit_start_ibm_netcam_pro(struct gspca_dev *gspca_dev)
2531 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */ 2531 cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
2532 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */ 2532 cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
2533 2533
2534 switch (gspca_dev->width) { 2534 switch (gspca_dev->pixfmt.width) {
2535 case 160: /* 160x120 */ 2535 case 160: /* 160x120 */
2536 cit_write_reg(gspca_dev, 0x0024, 0x010b); 2536 cit_write_reg(gspca_dev, 0x0024, 0x010b);
2537 cit_write_reg(gspca_dev, 0x0089, 0x0119); 2537 cit_write_reg(gspca_dev, 0x0089, 0x0119);
@@ -2635,7 +2635,7 @@ static int sd_isoc_init(struct gspca_dev *gspca_dev)
2635 struct usb_host_interface *alt; 2635 struct usb_host_interface *alt;
2636 int max_packet_size; 2636 int max_packet_size;
2637 2637
2638 switch (gspca_dev->width) { 2638 switch (gspca_dev->pixfmt.width) {
2639 case 160: 2639 case 160:
2640 max_packet_size = 450; 2640 max_packet_size = 450;
2641 break; 2641 break;
@@ -2659,7 +2659,7 @@ static int sd_isoc_nego(struct gspca_dev *gspca_dev)
2659 int ret, packet_size, min_packet_size; 2659 int ret, packet_size, min_packet_size;
2660 struct usb_host_interface *alt; 2660 struct usb_host_interface *alt;
2661 2661
2662 switch (gspca_dev->width) { 2662 switch (gspca_dev->pixfmt.width) {
2663 case 160: 2663 case 160:
2664 min_packet_size = 200; 2664 min_packet_size = 200;
2665 break; 2665 break;
@@ -2780,7 +2780,7 @@ static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
2780 case CIT_MODEL1: 2780 case CIT_MODEL1:
2781 case CIT_MODEL3: 2781 case CIT_MODEL3:
2782 case CIT_IBM_NETCAM_PRO: 2782 case CIT_IBM_NETCAM_PRO:
2783 switch (gspca_dev->width) { 2783 switch (gspca_dev->pixfmt.width) {
2784 case 160: /* 160x120 */ 2784 case 160: /* 160x120 */
2785 byte3 = 0x02; 2785 byte3 = 0x02;
2786 byte4 = 0x0a; 2786 byte4 = 0x0a;
@@ -2864,20 +2864,16 @@ static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
2864 if (data[i] == 0xff) { 2864 if (data[i] == 0xff) {
2865 if (i >= 4) 2865 if (i >= 4)
2866 PDEBUG(D_FRAM, 2866 PDEBUG(D_FRAM,
2867 "header found at offset: %d: %02x %02x 00 %02x %02x %02x\n", 2867 "header found at offset: %d: %02x %02x 00 %3ph\n",
2868 i - 1, 2868 i - 1,
2869 data[i - 4], 2869 data[i - 4],
2870 data[i - 3], 2870 data[i - 3],
2871 data[i], 2871 &data[i]);
2872 data[i + 1],
2873 data[i + 2]);
2874 else 2872 else
2875 PDEBUG(D_FRAM, 2873 PDEBUG(D_FRAM,
2876 "header found at offset: %d: 00 %02x %02x %02x\n", 2874 "header found at offset: %d: 00 %3ph\n",
2877 i - 1, 2875 i - 1,
2878 data[i], 2876 &data[i]);
2879 data[i + 1],
2880 data[i + 2]);
2881 return data + i + (sd->sof_len - 1); 2877 return data + i + (sd->sof_len - 1);
2882 } 2878 }
2883 break; 2879 break;
diff --git a/drivers/media/usb/gspca/zc3xx.c b/drivers/media/usb/gspca/zc3xx.c
index cbfc2f921427..7b95d8e88a20 100644
--- a/drivers/media/usb/gspca/zc3xx.c
+++ b/drivers/media/usb/gspca/zc3xx.c
@@ -6700,7 +6700,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
6700 }; 6700 };
6701 6701
6702 /* create the JPEG header */ 6702 /* create the JPEG header */
6703 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 6703 jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
6704 gspca_dev->pixfmt.width,
6704 0x21); /* JPEG 422 */ 6705 0x21); /* JPEG 422 */
6705 6706
6706 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; 6707 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c b/drivers/media/usb/hdpvr/hdpvr-core.c
index 6e5070774dc2..2f0c89cbac76 100644
--- a/drivers/media/usb/hdpvr/hdpvr-core.c
+++ b/drivers/media/usb/hdpvr/hdpvr-core.c
@@ -78,7 +78,8 @@ void hdpvr_delete(struct hdpvr_device *dev)
78 78
79static void challenge(u8 *bytes) 79static void challenge(u8 *bytes)
80{ 80{
81 u64 *i64P, tmp64; 81 __le64 *i64P;
82 u64 tmp64;
82 uint i, idx; 83 uint i, idx;
83 84
84 for (idx = 0; idx < 32; ++idx) { 85 for (idx = 0; idx < 32; ++idx) {
@@ -106,10 +107,10 @@ static void challenge(u8 *bytes)
106 for (i = 0; i < 3; i++) 107 for (i = 0; i < 3; i++)
107 bytes[1] *= bytes[6] + 1; 108 bytes[1] *= bytes[6] + 1;
108 for (i = 0; i < 3; i++) { 109 for (i = 0; i < 3; i++) {
109 i64P = (u64 *)bytes; 110 i64P = (__le64 *)bytes;
110 tmp64 = le64_to_cpup(i64P); 111 tmp64 = le64_to_cpup(i64P);
111 tmp64 <<= bytes[7] & 0x0f; 112 tmp64 = tmp64 + (tmp64 << (bytes[7] & 0x0f));
112 *i64P += cpu_to_le64(tmp64); 113 *i64P = cpu_to_le64(tmp64);
113 } 114 }
114 break; 115 break;
115 } 116 }
@@ -301,8 +302,6 @@ static int hdpvr_probe(struct usb_interface *interface,
301 goto error; 302 goto error;
302 } 303 }
303 304
304 dev->workqueue = 0;
305
306 /* init video transfer queues first of all */ 305 /* init video transfer queues first of all */
307 /* to prevent oops in hdpvr_delete() on error paths */ 306 /* to prevent oops in hdpvr_delete() on error paths */
308 INIT_LIST_HEAD(&dev->free_buff_list); 307 INIT_LIST_HEAD(&dev->free_buff_list);
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
index c4d51d78f837..ea05f678b559 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
@@ -2868,7 +2868,7 @@ static void pvr2_subdev_set_control(struct pvr2_hdw *hdw, int id,
2868 pvr2_subdev_set_control(hdw, id, #lab, (hdw)->lab##_val); \ 2868 pvr2_subdev_set_control(hdw, id, #lab, (hdw)->lab##_val); \
2869 } 2869 }
2870 2870
2871v4l2_std_id pvr2_hdw_get_detected_std(struct pvr2_hdw *hdw) 2871static v4l2_std_id pvr2_hdw_get_detected_std(struct pvr2_hdw *hdw)
2872{ 2872{
2873 v4l2_std_id std; 2873 v4l2_std_id std;
2874 std = (v4l2_std_id)hdw->std_mask_avail; 2874 std = (v4l2_std_id)hdw->std_mask_avail;
diff --git a/drivers/media/usb/siano/smsusb.c b/drivers/media/usb/siano/smsusb.c
index 03761c6f472f..05bd91a60c09 100644
--- a/drivers/media/usb/siano/smsusb.c
+++ b/drivers/media/usb/siano/smsusb.c
@@ -209,8 +209,10 @@ static int smsusb_sendrequest(void *context, void *buffer, size_t size)
209 struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) buffer; 209 struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) buffer;
210 int dummy; 210 int dummy;
211 211
212 if (dev->state != SMSUSB_ACTIVE) 212 if (dev->state != SMSUSB_ACTIVE) {
213 sms_debug("Device not active yet");
213 return -ENOENT; 214 return -ENOENT;
215 }
214 216
215 sms_debug("sending %s(%d) size: %d", 217 sms_debug("sending %s(%d) size: %d",
216 smscore_translate_msg(phdr->msg_type), phdr->msg_type, 218 smscore_translate_msg(phdr->msg_type), phdr->msg_type,
@@ -243,6 +245,9 @@ static int smsusb1_load_firmware(struct usb_device *udev, int id, int board_id)
243 int rc, dummy; 245 int rc, dummy;
244 char *fw_filename; 246 char *fw_filename;
245 247
248 if (id < 0)
249 id = sms_get_board(board_id)->default_mode;
250
246 if (id < DEVICE_MODE_DVBT || id > DEVICE_MODE_DVBT_BDA) { 251 if (id < DEVICE_MODE_DVBT || id > DEVICE_MODE_DVBT_BDA) {
247 sms_err("invalid firmware id specified %d", id); 252 sms_err("invalid firmware id specified %d", id);
248 return -EINVAL; 253 return -EINVAL;
@@ -445,14 +450,15 @@ static int smsusb_probe(struct usb_interface *intf,
445 char devpath[32]; 450 char devpath[32];
446 int i, rc; 451 int i, rc;
447 452
448 sms_info("interface number %d", 453 sms_info("board id=%lu, interface number %d",
454 id->driver_info,
449 intf->cur_altsetting->desc.bInterfaceNumber); 455 intf->cur_altsetting->desc.bInterfaceNumber);
450 456
451 if (sms_get_board(id->driver_info)->intf_num != 457 if (sms_get_board(id->driver_info)->intf_num !=
452 intf->cur_altsetting->desc.bInterfaceNumber) { 458 intf->cur_altsetting->desc.bInterfaceNumber) {
453 sms_err("interface number is %d expecting %d", 459 sms_debug("interface %d won't be used. Expecting interface %d to popup",
454 sms_get_board(id->driver_info)->intf_num, 460 intf->cur_altsetting->desc.bInterfaceNumber,
455 intf->cur_altsetting->desc.bInterfaceNumber); 461 sms_get_board(id->driver_info)->intf_num);
456 return -ENODEV; 462 return -ENODEV;
457 } 463 }
458 464
@@ -483,22 +489,32 @@ static int smsusb_probe(struct usb_interface *intf,
483 } 489 }
484 if ((udev->actconfig->desc.bNumInterfaces == 2) && 490 if ((udev->actconfig->desc.bNumInterfaces == 2) &&
485 (intf->cur_altsetting->desc.bInterfaceNumber == 0)) { 491 (intf->cur_altsetting->desc.bInterfaceNumber == 0)) {
486 sms_err("rom interface 0 is not used"); 492 sms_debug("rom interface 0 is not used");
487 return -ENODEV; 493 return -ENODEV;
488 } 494 }
489 495
490 if (id->driver_info == SMS1XXX_BOARD_SIANO_STELLAR_ROM) { 496 if (id->driver_info == SMS1XXX_BOARD_SIANO_STELLAR_ROM) {
491 sms_info("stellar device was found."); 497 /* Detected a Siano Stellar uninitialized */
498
492 snprintf(devpath, sizeof(devpath), "usb\\%d-%s", 499 snprintf(devpath, sizeof(devpath), "usb\\%d-%s",
493 udev->bus->busnum, udev->devpath); 500 udev->bus->busnum, udev->devpath);
494 sms_info("stellar device was found."); 501 sms_info("stellar device in cold state was found at %s.", devpath);
495 return smsusb1_load_firmware( 502 rc = smsusb1_load_firmware(
496 udev, smscore_registry_getmode(devpath), 503 udev, smscore_registry_getmode(devpath),
497 id->driver_info); 504 id->driver_info);
505
506 /* This device will reset and gain another USB ID */
507 if (!rc)
508 sms_info("stellar device now in warm state");
509 else
510 sms_err("Failed to put stellar in warm state. Error: %d", rc);
511
512 return rc;
513 } else {
514 rc = smsusb_init_device(intf, id->driver_info);
498 } 515 }
499 516
500 rc = smsusb_init_device(intf, id->driver_info); 517 sms_info("Device initialized with return code %d", rc);
501 sms_info("rc %d", rc);
502 sms_board_load_modules(id->driver_info); 518 sms_board_load_modules(id->driver_info);
503 return rc; 519 return rc;
504} 520}
@@ -550,10 +566,13 @@ static int smsusb_resume(struct usb_interface *intf)
550} 566}
551 567
552static const struct usb_device_id smsusb_id_table[] = { 568static const struct usb_device_id smsusb_id_table[] = {
569 /* This device is only present before firmware load */
553 { USB_DEVICE(0x187f, 0x0010), 570 { USB_DEVICE(0x187f, 0x0010),
554 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR }, 571 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR_ROM },
572 /* This device pops up after firmware load */
555 { USB_DEVICE(0x187f, 0x0100), 573 { USB_DEVICE(0x187f, 0x0100),
556 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR }, 574 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
575
557 { USB_DEVICE(0x187f, 0x0200), 576 { USB_DEVICE(0x187f, 0x0200),
558 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_A }, 577 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_A },
559 { USB_DEVICE(0x187f, 0x0201), 578 { USB_DEVICE(0x187f, 0x0201),
diff --git a/drivers/media/usb/tlg2300/pd-main.c b/drivers/media/usb/tlg2300/pd-main.c
index 95f94e5aa66d..3316caa4733b 100644
--- a/drivers/media/usb/tlg2300/pd-main.c
+++ b/drivers/media/usb/tlg2300/pd-main.c
@@ -232,7 +232,7 @@ static int firmware_download(struct usb_device *udev)
232 goto out; 232 goto out;
233 } 233 }
234 234
235 max_packet_size = udev->ep_out[0x1]->desc.wMaxPacketSize; 235 max_packet_size = le16_to_cpu(udev->ep_out[0x1]->desc.wMaxPacketSize);
236 log("\t\t download size : %d", (int)max_packet_size); 236 log("\t\t download size : %d", (int)max_packet_size);
237 237
238 for (offset = 0; offset < fwlength; offset += max_packet_size) { 238 for (offset = 0; offset < fwlength; offset += max_packet_size) {
diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index e52c3b97f304..29724af9b9ab 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -366,7 +366,7 @@ static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
366 } 366 }
367 return 0; 367 return 0;
368 } else { 368 } else {
369 return -1; 369 return -ENOENT;
370 } 370 }
371} 371}
372 372
@@ -1241,6 +1241,8 @@ static void ttusb_dec_init_v_pes(struct ttusb_dec *dec)
1241 1241
1242static int ttusb_dec_init_usb(struct ttusb_dec *dec) 1242static int ttusb_dec_init_usb(struct ttusb_dec *dec)
1243{ 1243{
1244 int result;
1245
1244 dprintk("%s\n", __func__); 1246 dprintk("%s\n", __func__);
1245 1247
1246 mutex_init(&dec->usb_mutex); 1248 mutex_init(&dec->usb_mutex);
@@ -1258,7 +1260,7 @@ static int ttusb_dec_init_usb(struct ttusb_dec *dec)
1258 return -ENOMEM; 1260 return -ENOMEM;
1259 } 1261 }
1260 dec->irq_buffer = usb_alloc_coherent(dec->udev,IRQ_PACKET_SIZE, 1262 dec->irq_buffer = usb_alloc_coherent(dec->udev,IRQ_PACKET_SIZE,
1261 GFP_ATOMIC, &dec->irq_dma_handle); 1263 GFP_KERNEL, &dec->irq_dma_handle);
1262 if(!dec->irq_buffer) { 1264 if(!dec->irq_buffer) {
1263 usb_free_urb(dec->irq_urb); 1265 usb_free_urb(dec->irq_urb);
1264 return -ENOMEM; 1266 return -ENOMEM;
@@ -1270,7 +1272,13 @@ static int ttusb_dec_init_usb(struct ttusb_dec *dec)
1270 dec->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1272 dec->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1271 } 1273 }
1272 1274
1273 return ttusb_dec_alloc_iso_urbs(dec); 1275 result = ttusb_dec_alloc_iso_urbs(dec);
1276 if (result) {
1277 usb_free_urb(dec->irq_urb);
1278 usb_free_coherent(dec->udev, IRQ_PACKET_SIZE,
1279 dec->irq_buffer, dec->irq_dma_handle);
1280 }
1281 return result;
1274} 1282}
1275 1283
1276static int ttusb_dec_boot_dsp(struct ttusb_dec *dec) 1284static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
@@ -1293,10 +1301,11 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
1293 1301
1294 dprintk("%s\n", __func__); 1302 dprintk("%s\n", __func__);
1295 1303
1296 if (request_firmware(&fw_entry, dec->firmware_name, &dec->udev->dev)) { 1304 result = request_firmware(&fw_entry, dec->firmware_name, &dec->udev->dev);
1305 if (result) {
1297 printk(KERN_ERR "%s: Firmware (%s) unavailable.\n", 1306 printk(KERN_ERR "%s: Firmware (%s) unavailable.\n",
1298 __func__, dec->firmware_name); 1307 __func__, dec->firmware_name);
1299 return 1; 1308 return result;
1300 } 1309 }
1301 1310
1302 firmware = fw_entry->data; 1311 firmware = fw_entry->data;
@@ -1306,7 +1315,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
1306 printk("%s: firmware size too small for DSP code (%zu < 60).\n", 1315 printk("%s: firmware size too small for DSP code (%zu < 60).\n",
1307 __func__, firmware_size); 1316 __func__, firmware_size);
1308 release_firmware(fw_entry); 1317 release_firmware(fw_entry);
1309 return -1; 1318 return -ENOENT;
1310 } 1319 }
1311 1320
1312 /* a 32 bit checksum over the first 56 bytes of the DSP Code is stored 1321 /* a 32 bit checksum over the first 56 bytes of the DSP Code is stored
@@ -1320,7 +1329,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
1320 "0x%08x != 0x%08x in file), file invalid.\n", 1329 "0x%08x != 0x%08x in file), file invalid.\n",
1321 __func__, crc32_csum, crc32_check); 1330 __func__, crc32_csum, crc32_check);
1322 release_firmware(fw_entry); 1331 release_firmware(fw_entry);
1323 return -1; 1332 return -ENOENT;
1324 } 1333 }
1325 memcpy(idstring, &firmware[36], 20); 1334 memcpy(idstring, &firmware[36], 20);
1326 idstring[20] = '\0'; 1335 idstring[20] = '\0';
@@ -1389,55 +1398,48 @@ static int ttusb_dec_init_stb(struct ttusb_dec *dec)
1389 dprintk("%s\n", __func__); 1398 dprintk("%s\n", __func__);
1390 1399
1391 result = ttusb_dec_get_stb_state(dec, &mode, &model, &version); 1400 result = ttusb_dec_get_stb_state(dec, &mode, &model, &version);
1401 if (result)
1402 return result;
1392 1403
1393 if (!result) { 1404 if (!mode) {
1394 if (!mode) { 1405 if (version == 0xABCDEFAB)
1395 if (version == 0xABCDEFAB) 1406 printk(KERN_INFO "ttusb_dec: no version "
1396 printk(KERN_INFO "ttusb_dec: no version " 1407 "info in Firmware\n");
1397 "info in Firmware\n"); 1408 else
1398 else 1409 printk(KERN_INFO "ttusb_dec: Firmware "
1399 printk(KERN_INFO "ttusb_dec: Firmware " 1410 "%x.%02x%c%c\n",
1400 "%x.%02x%c%c\n", 1411 version >> 24, (version >> 16) & 0xff,
1401 version >> 24, (version >> 16) & 0xff, 1412 (version >> 8) & 0xff, version & 0xff);
1402 (version >> 8) & 0xff, version & 0xff);
1403
1404 result = ttusb_dec_boot_dsp(dec);
1405 if (result)
1406 return result;
1407 else
1408 return 1;
1409 } else {
1410 /* We can't trust the USB IDs that some firmwares
1411 give the box */
1412 switch (model) {
1413 case 0x00070001:
1414 case 0x00070008:
1415 case 0x0007000c:
1416 ttusb_dec_set_model(dec, TTUSB_DEC3000S);
1417 break;
1418 case 0x00070009:
1419 case 0x00070013:
1420 ttusb_dec_set_model(dec, TTUSB_DEC2000T);
1421 break;
1422 case 0x00070011:
1423 ttusb_dec_set_model(dec, TTUSB_DEC2540T);
1424 break;
1425 default:
1426 printk(KERN_ERR "%s: unknown model returned "
1427 "by firmware (%08x) - please report\n",
1428 __func__, model);
1429 return -1;
1430 break;
1431 }
1432 1413
1414 result = ttusb_dec_boot_dsp(dec);
1415 if (result)
1416 return result;
1417 } else {
1418 /* We can't trust the USB IDs that some firmwares
1419 give the box */
1420 switch (model) {
1421 case 0x00070001:
1422 case 0x00070008:
1423 case 0x0007000c:
1424 ttusb_dec_set_model(dec, TTUSB_DEC3000S);
1425 break;
1426 case 0x00070009:
1427 case 0x00070013:
1428 ttusb_dec_set_model(dec, TTUSB_DEC2000T);
1429 break;
1430 case 0x00070011:
1431 ttusb_dec_set_model(dec, TTUSB_DEC2540T);
1432 break;
1433 default:
1434 printk(KERN_ERR "%s: unknown model returned "
1435 "by firmware (%08x) - please report\n",
1436 __func__, model);
1437 return -ENOENT;
1438 }
1433 if (version >= 0x01770000) 1439 if (version >= 0x01770000)
1434 dec->can_playback = 1; 1440 dec->can_playback = 1;
1435
1436 return 0;
1437 }
1438 } 1441 }
1439 else 1442 return 0;
1440 return result;
1441} 1443}
1442 1444
1443static int ttusb_dec_init_dvb(struct ttusb_dec *dec) 1445static int ttusb_dec_init_dvb(struct ttusb_dec *dec)
@@ -1539,19 +1541,7 @@ static void ttusb_dec_exit_dvb(struct ttusb_dec *dec)
1539 1541
1540static void ttusb_dec_exit_rc(struct ttusb_dec *dec) 1542static void ttusb_dec_exit_rc(struct ttusb_dec *dec)
1541{ 1543{
1542
1543 dprintk("%s\n", __func__); 1544 dprintk("%s\n", __func__);
1544 /* we have to check whether the irq URB is already submitted.
1545 * As the irq is submitted after the interface is changed,
1546 * this is the best method i figured out.
1547 * Any others?*/
1548 if (dec->interface == TTUSB_DEC_INTERFACE_IN)
1549 usb_kill_urb(dec->irq_urb);
1550
1551 usb_free_urb(dec->irq_urb);
1552
1553 usb_free_coherent(dec->udev,IRQ_PACKET_SIZE,
1554 dec->irq_buffer, dec->irq_dma_handle);
1555 1545
1556 if (dec->rc_input_dev) { 1546 if (dec->rc_input_dev) {
1557 input_unregister_device(dec->rc_input_dev); 1547 input_unregister_device(dec->rc_input_dev);
@@ -1566,6 +1556,20 @@ static void ttusb_dec_exit_usb(struct ttusb_dec *dec)
1566 1556
1567 dprintk("%s\n", __func__); 1557 dprintk("%s\n", __func__);
1568 1558
1559 if (enable_rc) {
1560 /* we have to check whether the irq URB is already submitted.
1561 * As the irq is submitted after the interface is changed,
1562 * this is the best method i figured out.
1563 * Any others?*/
1564 if (dec->interface == TTUSB_DEC_INTERFACE_IN)
1565 usb_kill_urb(dec->irq_urb);
1566
1567 usb_free_urb(dec->irq_urb);
1568
1569 usb_free_coherent(dec->udev, IRQ_PACKET_SIZE,
1570 dec->irq_buffer, dec->irq_dma_handle);
1571 }
1572
1569 dec->iso_stream_count = 0; 1573 dec->iso_stream_count = 0;
1570 1574
1571 for (i = 0; i < ISO_BUF_COUNT; i++) 1575 for (i = 0; i < ISO_BUF_COUNT; i++)
@@ -1623,6 +1627,7 @@ static int ttusb_dec_probe(struct usb_interface *intf,
1623{ 1627{
1624 struct usb_device *udev; 1628 struct usb_device *udev;
1625 struct ttusb_dec *dec; 1629 struct ttusb_dec *dec;
1630 int result;
1626 1631
1627 dprintk("%s\n", __func__); 1632 dprintk("%s\n", __func__);
1628 1633
@@ -1651,13 +1656,15 @@ static int ttusb_dec_probe(struct usb_interface *intf,
1651 1656
1652 dec->udev = udev; 1657 dec->udev = udev;
1653 1658
1654 if (ttusb_dec_init_usb(dec)) 1659 result = ttusb_dec_init_usb(dec);
1655 return 0; 1660 if (result)
1656 if (ttusb_dec_init_stb(dec)) { 1661 goto err_usb;
1657 ttusb_dec_exit_usb(dec); 1662 result = ttusb_dec_init_stb(dec);
1658 return 0; 1663 if (result)
1659 } 1664 goto err_stb;
1660 ttusb_dec_init_dvb(dec); 1665 result = ttusb_dec_init_dvb(dec);
1666 if (result)
1667 goto err_stb;
1661 1668
1662 dec->adapter.priv = dec; 1669 dec->adapter.priv = dec;
1663 switch (id->idProduct) { 1670 switch (id->idProduct) {
@@ -1696,6 +1703,11 @@ static int ttusb_dec_probe(struct usb_interface *intf,
1696 ttusb_init_rc(dec); 1703 ttusb_init_rc(dec);
1697 1704
1698 return 0; 1705 return 0;
1706err_stb:
1707 ttusb_dec_exit_usb(dec);
1708err_usb:
1709 kfree(dec);
1710 return result;
1699} 1711}
1700 1712
1701static void ttusb_dec_disconnect(struct usb_interface *intf) 1713static void ttusb_dec_disconnect(struct usb_interface *intf)
diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index a2f4501c23ca..0eb82106d2ff 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -664,7 +664,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
664 .size = 32, 664 .size = 32,
665 .offset = 0, 665 .offset = 0,
666 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 666 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
667 .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, 667 .data_type = UVC_CTRL_DATA_TYPE_SIGNED,
668 }, 668 },
669 { 669 {
670 .id = V4L2_CID_TILT_ABSOLUTE, 670 .id = V4L2_CID_TILT_ABSOLUTE,
@@ -674,7 +674,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
674 .size = 32, 674 .size = 32,
675 .offset = 32, 675 .offset = 32,
676 .v4l2_type = V4L2_CTRL_TYPE_INTEGER, 676 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
677 .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, 677 .data_type = UVC_CTRL_DATA_TYPE_SIGNED,
678 }, 678 },
679 { 679 {
680 .id = V4L2_CID_PRIVACY, 680 .id = V4L2_CID_PRIVACY,
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index 3394c3432011..899cb6d1c4a4 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -680,7 +680,8 @@ void uvc_video_clock_update(struct uvc_streaming *stream,
680 stream->dev->name, 680 stream->dev->name,
681 sof >> 16, div_u64(((u64)sof & 0xffff) * 1000000LLU, 65536), 681 sof >> 16, div_u64(((u64)sof & 0xffff) * 1000000LLU, 65536),
682 y, ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC, 682 y, ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC,
683 v4l2_buf->timestamp.tv_sec, v4l2_buf->timestamp.tv_usec, 683 v4l2_buf->timestamp.tv_sec,
684 (unsigned long)v4l2_buf->timestamp.tv_usec,
684 x1, first->host_sof, first->dev_sof, 685 x1, first->host_sof, first->dev_sof,
685 x2, last->host_sof, last->dev_sof, y1, y2); 686 x2, last->host_sof, last->dev_sof, y1, y2);
686 687
diff --git a/drivers/media/v4l2-core/tuner-core.c b/drivers/media/v4l2-core/tuner-core.c
index ddc9379eb276..20c09229a08e 100644
--- a/drivers/media/v4l2-core/tuner-core.c
+++ b/drivers/media/v4l2-core/tuner-core.c
@@ -43,7 +43,7 @@
43 43
44#define UNSET (-1U) 44#define UNSET (-1U)
45 45
46#define PREFIX (t->i2c->driver->driver.name) 46#define PREFIX (t->i2c->dev.driver->name)
47 47
48/* 48/*
49 * Driver modprobe parameters 49 * Driver modprobe parameters
@@ -247,7 +247,7 @@ static const struct analog_demod_ops tuner_analog_ops = {
247/** 247/**
248 * set_type - Sets the tuner type for a given device 248 * set_type - Sets the tuner type for a given device
249 * 249 *
250 * @c: i2c_client descriptoy 250 * @c: i2c_client descriptor
251 * @type: type of the tuner (e. g. tuner number) 251 * @type: type of the tuner (e. g. tuner number)
252 * @new_mode_mask: Indicates if tuner supports TV and/or Radio 252 * @new_mode_mask: Indicates if tuner supports TV and/or Radio
253 * @new_config: an optional parameter used by a few tuners to adjust 253 * @new_config: an optional parameter used by a few tuners to adjust
@@ -452,7 +452,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
452 } 452 }
453 453
454 tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n", 454 tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n",
455 c->adapter->name, c->driver->driver.name, c->addr << 1, type, 455 c->adapter->name, c->dev.driver->name, c->addr << 1, type,
456 t->mode_mask); 456 t->mode_mask);
457 return; 457 return;
458 458
@@ -556,7 +556,7 @@ static void tuner_lookup(struct i2c_adapter *adap,
556 int mode_mask; 556 int mode_mask;
557 557
558 if (pos->i2c->adapter != adap || 558 if (pos->i2c->adapter != adap ||
559 strcmp(pos->i2c->driver->driver.name, "tuner")) 559 strcmp(pos->i2c->dev.driver->name, "tuner"))
560 continue; 560 continue;
561 561
562 mode_mask = pos->mode_mask; 562 mode_mask = pos->mode_mask;
diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index c85d69da35bd..85a6a34128a8 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -189,30 +189,53 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
189 struct v4l2_subdev *sd, *tmp; 189 struct v4l2_subdev *sd, *tmp;
190 unsigned int notif_n_subdev = notifier->num_subdevs; 190 unsigned int notif_n_subdev = notifier->num_subdevs;
191 unsigned int n_subdev = min(notif_n_subdev, V4L2_MAX_SUBDEVS); 191 unsigned int n_subdev = min(notif_n_subdev, V4L2_MAX_SUBDEVS);
192 struct device *dev[n_subdev]; 192 struct device **dev;
193 int i = 0; 193 int i = 0;
194 194
195 if (!notifier->v4l2_dev) 195 if (!notifier->v4l2_dev)
196 return; 196 return;
197 197
198 dev = kmalloc(n_subdev * sizeof(*dev), GFP_KERNEL);
199 if (!dev) {
200 dev_err(notifier->v4l2_dev->dev,
201 "Failed to allocate device cache!\n");
202 }
203
198 mutex_lock(&list_lock); 204 mutex_lock(&list_lock);
199 205
200 list_del(&notifier->list); 206 list_del(&notifier->list);
201 207
202 list_for_each_entry_safe(sd, tmp, &notifier->done, async_list) { 208 list_for_each_entry_safe(sd, tmp, &notifier->done, async_list) {
203 dev[i] = get_device(sd->dev); 209 struct device *d;
210
211 d = get_device(sd->dev);
204 212
205 v4l2_async_cleanup(sd); 213 v4l2_async_cleanup(sd);
206 214
207 /* If we handled USB devices, we'd have to lock the parent too */ 215 /* If we handled USB devices, we'd have to lock the parent too */
208 device_release_driver(dev[i++]); 216 device_release_driver(d);
209 217
210 if (notifier->unbind) 218 if (notifier->unbind)
211 notifier->unbind(notifier, sd, sd->asd); 219 notifier->unbind(notifier, sd, sd->asd);
220
221 /*
222 * Store device at the device cache, in order to call
223 * put_device() on the final step
224 */
225 if (dev)
226 dev[i++] = d;
227 else
228 put_device(d);
212 } 229 }
213 230
214 mutex_unlock(&list_lock); 231 mutex_unlock(&list_lock);
215 232
233 /*
234 * Call device_attach() to reprobe devices
235 *
236 * NOTE: If dev allocation fails, i is 0, and the whole loop won't be
237 * executed.
238 */
216 while (i--) { 239 while (i--) {
217 struct device *d = dev[i]; 240 struct device *d = dev[i];
218 241
@@ -228,6 +251,7 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
228 } 251 }
229 put_device(d); 252 put_device(d);
230 } 253 }
254 kfree(dev);
231 255
232 notifier->v4l2_dev = NULL; 256 notifier->v4l2_dev = NULL;
233 257
diff --git a/drivers/media/v4l2-core/v4l2-clk.c b/drivers/media/v4l2-core/v4l2-clk.c
index b67de8642b5a..e18cc0469cf8 100644
--- a/drivers/media/v4l2-core/v4l2-clk.c
+++ b/drivers/media/v4l2-core/v4l2-clk.c
@@ -240,3 +240,42 @@ void v4l2_clk_unregister(struct v4l2_clk *clk)
240 kfree(clk); 240 kfree(clk);
241} 241}
242EXPORT_SYMBOL(v4l2_clk_unregister); 242EXPORT_SYMBOL(v4l2_clk_unregister);
243
244struct v4l2_clk_fixed {
245 unsigned long rate;
246 struct v4l2_clk_ops ops;
247};
248
249static unsigned long fixed_get_rate(struct v4l2_clk *clk)
250{
251 struct v4l2_clk_fixed *priv = clk->priv;
252 return priv->rate;
253}
254
255struct v4l2_clk *__v4l2_clk_register_fixed(const char *dev_id,
256 const char *id, unsigned long rate, struct module *owner)
257{
258 struct v4l2_clk *clk;
259 struct v4l2_clk_fixed *priv = kzalloc(sizeof(*priv), GFP_KERNEL);
260
261 if (!priv)
262 return ERR_PTR(-ENOMEM);
263
264 priv->rate = rate;
265 priv->ops.get_rate = fixed_get_rate;
266 priv->ops.owner = owner;
267
268 clk = v4l2_clk_register(&priv->ops, dev_id, id, priv);
269 if (IS_ERR(clk))
270 kfree(priv);
271
272 return clk;
273}
274EXPORT_SYMBOL(__v4l2_clk_register_fixed);
275
276void v4l2_clk_unregister_fixed(struct v4l2_clk *clk)
277{
278 kfree(clk->priv);
279 v4l2_clk_unregister(clk);
280}
281EXPORT_SYMBOL(v4l2_clk_unregister_fixed);
diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index 037d7a55aa8c..433d6d77942e 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -236,14 +236,14 @@ void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
236 v4l2_subdev_init(sd, ops); 236 v4l2_subdev_init(sd, ops);
237 sd->flags |= V4L2_SUBDEV_FL_IS_I2C; 237 sd->flags |= V4L2_SUBDEV_FL_IS_I2C;
238 /* the owner is the same as the i2c_client's driver owner */ 238 /* the owner is the same as the i2c_client's driver owner */
239 sd->owner = client->driver->driver.owner; 239 sd->owner = client->dev.driver->owner;
240 sd->dev = &client->dev; 240 sd->dev = &client->dev;
241 /* i2c_client and v4l2_subdev point to one another */ 241 /* i2c_client and v4l2_subdev point to one another */
242 v4l2_set_subdevdata(sd, client); 242 v4l2_set_subdevdata(sd, client);
243 i2c_set_clientdata(client, sd); 243 i2c_set_clientdata(client, sd);
244 /* initialize name */ 244 /* initialize name */
245 snprintf(sd->name, sizeof(sd->name), "%s %d-%04x", 245 snprintf(sd->name, sizeof(sd->name), "%s %d-%04x",
246 client->driver->driver.name, i2c_adapter_id(client->adapter), 246 client->dev.driver->name, i2c_adapter_id(client->adapter),
247 client->addr); 247 client->addr);
248} 248}
249EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init); 249EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init);
@@ -274,11 +274,11 @@ struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
274 loaded. This delay-load mechanism doesn't work if other drivers 274 loaded. This delay-load mechanism doesn't work if other drivers
275 want to use the i2c device, so explicitly loading the module 275 want to use the i2c device, so explicitly loading the module
276 is the best alternative. */ 276 is the best alternative. */
277 if (client == NULL || client->driver == NULL) 277 if (client == NULL || client->dev.driver == NULL)
278 goto error; 278 goto error;
279 279
280 /* Lock the module so we can safely get the v4l2_subdev pointer */ 280 /* Lock the module so we can safely get the v4l2_subdev pointer */
281 if (!try_module_get(client->driver->driver.owner)) 281 if (!try_module_get(client->dev.driver->owner))
282 goto error; 282 goto error;
283 sd = i2c_get_clientdata(client); 283 sd = i2c_get_clientdata(client);
284 284
@@ -287,7 +287,7 @@ struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
287 if (v4l2_device_register_subdev(v4l2_dev, sd)) 287 if (v4l2_device_register_subdev(v4l2_dev, sd))
288 sd = NULL; 288 sd = NULL;
289 /* Decrease the module use count to match the first try_module_get. */ 289 /* Decrease the module use count to match the first try_module_get. */
290 module_put(client->driver->driver.owner); 290 module_put(client->dev.driver->owner);
291 291
292error: 292error:
293 /* If we have a client but no subdev, then something went wrong and 293 /* If we have a client but no subdev, then something went wrong and
diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
index c3f080388684..60dcc0f3b32e 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -565,13 +565,13 @@ EXPORT_SYMBOL(v4l2_ctrl_get_menu);
565 * Returns NULL or an s64 type array containing the menu for given 565 * Returns NULL or an s64 type array containing the menu for given
566 * control ID. The total number of the menu items is returned in @len. 566 * control ID. The total number of the menu items is returned in @len.
567 */ 567 */
568const s64 const *v4l2_ctrl_get_int_menu(u32 id, u32 *len) 568const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len)
569{ 569{
570 static const s64 const qmenu_int_vpx_num_partitions[] = { 570 static const s64 qmenu_int_vpx_num_partitions[] = {
571 1, 2, 4, 8, 571 1, 2, 4, 8,
572 }; 572 };
573 573
574 static const s64 const qmenu_int_vpx_num_ref_frames[] = { 574 static const s64 qmenu_int_vpx_num_ref_frames[] = {
575 1, 2, 3, 575 1, 2, 3,
576 }; 576 };
577 577
@@ -583,7 +583,7 @@ const s64 const *v4l2_ctrl_get_int_menu(u32 id, u32 *len)
583 default: 583 default:
584 *len = 0; 584 *len = 0;
585 return NULL; 585 return NULL;
586 }; 586 }
587} 587}
588EXPORT_SYMBOL(v4l2_ctrl_get_int_menu); 588EXPORT_SYMBOL(v4l2_ctrl_get_int_menu);
589 589
diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
index 7c4371288215..73035ee0f4de 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -41,6 +41,8 @@ module_param(debug, bool, 0644);
41#define TRANS_QUEUED (1 << 0) 41#define TRANS_QUEUED (1 << 0)
42/* Instance is currently running in hardware */ 42/* Instance is currently running in hardware */
43#define TRANS_RUNNING (1 << 1) 43#define TRANS_RUNNING (1 << 1)
44/* Instance is currently aborting */
45#define TRANS_ABORT (1 << 2)
44 46
45 47
46/* Offset base for buffers on the destination queue - used to distinguish 48/* Offset base for buffers on the destination queue - used to distinguish
@@ -221,6 +223,14 @@ static void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx)
221 } 223 }
222 224
223 spin_lock_irqsave(&m2m_dev->job_spinlock, flags_job); 225 spin_lock_irqsave(&m2m_dev->job_spinlock, flags_job);
226
227 /* If the context is aborted then don't schedule it */
228 if (m2m_ctx->job_flags & TRANS_ABORT) {
229 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
230 dprintk("Aborted context\n");
231 return;
232 }
233
224 if (m2m_ctx->job_flags & TRANS_QUEUED) { 234 if (m2m_ctx->job_flags & TRANS_QUEUED) {
225 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job); 235 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
226 dprintk("On job queue already\n"); 236 dprintk("On job queue already\n");
@@ -280,6 +290,8 @@ static void v4l2_m2m_cancel_job(struct v4l2_m2m_ctx *m2m_ctx)
280 290
281 m2m_dev = m2m_ctx->m2m_dev; 291 m2m_dev = m2m_ctx->m2m_dev;
282 spin_lock_irqsave(&m2m_dev->job_spinlock, flags); 292 spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
293
294 m2m_ctx->job_flags |= TRANS_ABORT;
283 if (m2m_ctx->job_flags & TRANS_RUNNING) { 295 if (m2m_ctx->job_flags & TRANS_RUNNING) {
284 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags); 296 spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
285 m2m_dev->m2m_ops->job_abort(m2m_ctx->priv); 297 m2m_dev->m2m_ops->job_abort(m2m_ctx->priv);
@@ -480,13 +492,15 @@ int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
480 m2m_dev = m2m_ctx->m2m_dev; 492 m2m_dev = m2m_ctx->m2m_dev;
481 spin_lock_irqsave(&m2m_dev->job_spinlock, flags_job); 493 spin_lock_irqsave(&m2m_dev->job_spinlock, flags_job);
482 /* We should not be scheduled anymore, since we're dropping a queue. */ 494 /* We should not be scheduled anymore, since we're dropping a queue. */
483 INIT_LIST_HEAD(&m2m_ctx->queue); 495 if (m2m_ctx->job_flags & TRANS_QUEUED)
496 list_del(&m2m_ctx->queue);
484 m2m_ctx->job_flags = 0; 497 m2m_ctx->job_flags = 0;
485 498
486 spin_lock_irqsave(&q_ctx->rdy_spinlock, flags); 499 spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
487 /* Drop queue, since streamoff returns device to the same state as after 500 /* Drop queue, since streamoff returns device to the same state as after
488 * calling reqbufs. */ 501 * calling reqbufs. */
489 INIT_LIST_HEAD(&q_ctx->rdy_queue); 502 INIT_LIST_HEAD(&q_ctx->rdy_queue);
503 q_ctx->num_rdy = 0;
490 spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags); 504 spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
491 505
492 if (m2m_dev->curr_ctx == m2m_ctx) { 506 if (m2m_dev->curr_ctx == m2m_ctx) {
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index de0e87f0b2c3..b19b306c8f7f 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -241,7 +241,8 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
241 q->bufs[q->num_buffers + buffer] = vb; 241 q->bufs[q->num_buffers + buffer] = vb;
242 } 242 }
243 243
244 __setup_offsets(q, buffer); 244 if (memory == V4L2_MEMORY_MMAP)
245 __setup_offsets(q, buffer);
245 246
246 dprintk(1, "Allocated %d buffers, %d plane(s) each\n", 247 dprintk(1, "Allocated %d buffers, %d plane(s) each\n",
247 buffer, num_planes); 248 buffer, num_planes);
@@ -1015,6 +1016,10 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
1015 1016
1016 /* Check if the provided plane buffer is large enough */ 1017 /* Check if the provided plane buffer is large enough */
1017 if (planes[plane].length < q->plane_sizes[plane]) { 1018 if (planes[plane].length < q->plane_sizes[plane]) {
1019 dprintk(1, "qbuf: provided buffer size %u is less than "
1020 "setup size %u for plane %d\n",
1021 planes[plane].length,
1022 q->plane_sizes[plane], plane);
1018 ret = -EINVAL; 1023 ret = -EINVAL;
1019 goto err; 1024 goto err;
1020 } 1025 }
@@ -1205,8 +1210,11 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
1205 int ret; 1210 int ret;
1206 1211
1207 ret = __verify_length(vb, b); 1212 ret = __verify_length(vb, b);
1208 if (ret < 0) 1213 if (ret < 0) {
1214 dprintk(1, "%s(): plane parameters verification failed: %d\n",
1215 __func__, ret);
1209 return ret; 1216 return ret;
1217 }
1210 1218
1211 switch (q->memory) { 1219 switch (q->memory) {
1212 case V4L2_MEMORY_MMAP: 1220 case V4L2_MEMORY_MMAP:
@@ -2469,10 +2477,11 @@ size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
2469} 2477}
2470EXPORT_SYMBOL_GPL(vb2_read); 2478EXPORT_SYMBOL_GPL(vb2_read);
2471 2479
2472size_t vb2_write(struct vb2_queue *q, char __user *data, size_t count, 2480size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
2473 loff_t *ppos, int nonblocking) 2481 loff_t *ppos, int nonblocking)
2474{ 2482{
2475 return __vb2_perform_fileio(q, data, count, ppos, nonblocking, 0); 2483 return __vb2_perform_fileio(q, (char __user *) data, count,
2484 ppos, nonblocking, 0);
2476} 2485}
2477EXPORT_SYMBOL_GPL(vb2_write); 2486EXPORT_SYMBOL_GPL(vb2_write);
2478 2487
@@ -2633,7 +2642,7 @@ int vb2_fop_release(struct file *file)
2633} 2642}
2634EXPORT_SYMBOL_GPL(vb2_fop_release); 2643EXPORT_SYMBOL_GPL(vb2_fop_release);
2635 2644
2636ssize_t vb2_fop_write(struct file *file, char __user *buf, 2645ssize_t vb2_fop_write(struct file *file, const char __user *buf,
2637 size_t count, loff_t *ppos) 2646 size_t count, loff_t *ppos)
2638{ 2647{
2639 struct video_device *vdev = video_devdata(file); 2648 struct video_device *vdev = video_devdata(file);
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index 16ae3dcc7e29..2f860543912c 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -35,17 +35,61 @@ struct vb2_dma_sg_buf {
35 struct page **pages; 35 struct page **pages;
36 int write; 36 int write;
37 int offset; 37 int offset;
38 struct vb2_dma_sg_desc sg_desc; 38 struct sg_table sg_table;
39 size_t size;
40 unsigned int num_pages;
39 atomic_t refcount; 41 atomic_t refcount;
40 struct vb2_vmarea_handler handler; 42 struct vb2_vmarea_handler handler;
41}; 43};
42 44
43static void vb2_dma_sg_put(void *buf_priv); 45static void vb2_dma_sg_put(void *buf_priv);
44 46
47static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf,
48 gfp_t gfp_flags)
49{
50 unsigned int last_page = 0;
51 int size = buf->size;
52
53 while (size > 0) {
54 struct page *pages;
55 int order;
56 int i;
57
58 order = get_order(size);
59 /* Dont over allocate*/
60 if ((PAGE_SIZE << order) > size)
61 order--;
62
63 pages = NULL;
64 while (!pages) {
65 pages = alloc_pages(GFP_KERNEL | __GFP_ZERO |
66 __GFP_NOWARN | gfp_flags, order);
67 if (pages)
68 break;
69
70 if (order == 0) {
71 while (last_page--)
72 __free_page(buf->pages[last_page]);
73 return -ENOMEM;
74 }
75 order--;
76 }
77
78 split_page(pages, order);
79 for (i = 0; i < (1 << order); i++)
80 buf->pages[last_page++] = &pages[i];
81
82 size -= PAGE_SIZE << order;
83 }
84
85 return 0;
86}
87
45static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_flags) 88static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_flags)
46{ 89{
47 struct vb2_dma_sg_buf *buf; 90 struct vb2_dma_sg_buf *buf;
48 int i; 91 int ret;
92 int num_pages;
49 93
50 buf = kzalloc(sizeof *buf, GFP_KERNEL); 94 buf = kzalloc(sizeof *buf, GFP_KERNEL);
51 if (!buf) 95 if (!buf)
@@ -54,29 +98,23 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_fla
54 buf->vaddr = NULL; 98 buf->vaddr = NULL;
55 buf->write = 0; 99 buf->write = 0;
56 buf->offset = 0; 100 buf->offset = 0;
57 buf->sg_desc.size = size; 101 buf->size = size;
58 /* size is already page aligned */ 102 /* size is already page aligned */
59 buf->sg_desc.num_pages = size >> PAGE_SHIFT; 103 buf->num_pages = size >> PAGE_SHIFT;
60 104
61 buf->sg_desc.sglist = vzalloc(buf->sg_desc.num_pages * 105 buf->pages = kzalloc(buf->num_pages * sizeof(struct page *),
62 sizeof(*buf->sg_desc.sglist));
63 if (!buf->sg_desc.sglist)
64 goto fail_sglist_alloc;
65 sg_init_table(buf->sg_desc.sglist, buf->sg_desc.num_pages);
66
67 buf->pages = kzalloc(buf->sg_desc.num_pages * sizeof(struct page *),
68 GFP_KERNEL); 106 GFP_KERNEL);
69 if (!buf->pages) 107 if (!buf->pages)
70 goto fail_pages_array_alloc; 108 goto fail_pages_array_alloc;
71 109
72 for (i = 0; i < buf->sg_desc.num_pages; ++i) { 110 ret = vb2_dma_sg_alloc_compacted(buf, gfp_flags);
73 buf->pages[i] = alloc_page(GFP_KERNEL | __GFP_ZERO | 111 if (ret)
74 __GFP_NOWARN | gfp_flags); 112 goto fail_pages_alloc;
75 if (NULL == buf->pages[i]) 113
76 goto fail_pages_alloc; 114 ret = sg_alloc_table_from_pages(&buf->sg_table, buf->pages,
77 sg_set_page(&buf->sg_desc.sglist[i], 115 buf->num_pages, 0, size, gfp_flags);
78 buf->pages[i], PAGE_SIZE, 0); 116 if (ret)
79 } 117 goto fail_table_alloc;
80 118
81 buf->handler.refcount = &buf->refcount; 119 buf->handler.refcount = &buf->refcount;
82 buf->handler.put = vb2_dma_sg_put; 120 buf->handler.put = vb2_dma_sg_put;
@@ -85,18 +123,16 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_fla
85 atomic_inc(&buf->refcount); 123 atomic_inc(&buf->refcount);
86 124
87 dprintk(1, "%s: Allocated buffer of %d pages\n", 125 dprintk(1, "%s: Allocated buffer of %d pages\n",
88 __func__, buf->sg_desc.num_pages); 126 __func__, buf->num_pages);
89 return buf; 127 return buf;
90 128
129fail_table_alloc:
130 num_pages = buf->num_pages;
131 while (num_pages--)
132 __free_page(buf->pages[num_pages]);
91fail_pages_alloc: 133fail_pages_alloc:
92 while (--i >= 0)
93 __free_page(buf->pages[i]);
94 kfree(buf->pages); 134 kfree(buf->pages);
95
96fail_pages_array_alloc: 135fail_pages_array_alloc:
97 vfree(buf->sg_desc.sglist);
98
99fail_sglist_alloc:
100 kfree(buf); 136 kfree(buf);
101 return NULL; 137 return NULL;
102} 138}
@@ -104,14 +140,14 @@ fail_sglist_alloc:
104static void vb2_dma_sg_put(void *buf_priv) 140static void vb2_dma_sg_put(void *buf_priv)
105{ 141{
106 struct vb2_dma_sg_buf *buf = buf_priv; 142 struct vb2_dma_sg_buf *buf = buf_priv;
107 int i = buf->sg_desc.num_pages; 143 int i = buf->num_pages;
108 144
109 if (atomic_dec_and_test(&buf->refcount)) { 145 if (atomic_dec_and_test(&buf->refcount)) {
110 dprintk(1, "%s: Freeing buffer of %d pages\n", __func__, 146 dprintk(1, "%s: Freeing buffer of %d pages\n", __func__,
111 buf->sg_desc.num_pages); 147 buf->num_pages);
112 if (buf->vaddr) 148 if (buf->vaddr)
113 vm_unmap_ram(buf->vaddr, buf->sg_desc.num_pages); 149 vm_unmap_ram(buf->vaddr, buf->num_pages);
114 vfree(buf->sg_desc.sglist); 150 sg_free_table(&buf->sg_table);
115 while (--i >= 0) 151 while (--i >= 0)
116 __free_page(buf->pages[i]); 152 __free_page(buf->pages[i]);
117 kfree(buf->pages); 153 kfree(buf->pages);
@@ -124,7 +160,7 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, unsigned long vaddr,
124{ 160{
125 struct vb2_dma_sg_buf *buf; 161 struct vb2_dma_sg_buf *buf;
126 unsigned long first, last; 162 unsigned long first, last;
127 int num_pages_from_user, i; 163 int num_pages_from_user;
128 164
129 buf = kzalloc(sizeof *buf, GFP_KERNEL); 165 buf = kzalloc(sizeof *buf, GFP_KERNEL);
130 if (!buf) 166 if (!buf)
@@ -133,56 +169,41 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, unsigned long vaddr,
133 buf->vaddr = NULL; 169 buf->vaddr = NULL;
134 buf->write = write; 170 buf->write = write;
135 buf->offset = vaddr & ~PAGE_MASK; 171 buf->offset = vaddr & ~PAGE_MASK;
136 buf->sg_desc.size = size; 172 buf->size = size;
137 173
138 first = (vaddr & PAGE_MASK) >> PAGE_SHIFT; 174 first = (vaddr & PAGE_MASK) >> PAGE_SHIFT;
139 last = ((vaddr + size - 1) & PAGE_MASK) >> PAGE_SHIFT; 175 last = ((vaddr + size - 1) & PAGE_MASK) >> PAGE_SHIFT;
140 buf->sg_desc.num_pages = last - first + 1; 176 buf->num_pages = last - first + 1;
141
142 buf->sg_desc.sglist = vzalloc(
143 buf->sg_desc.num_pages * sizeof(*buf->sg_desc.sglist));
144 if (!buf->sg_desc.sglist)
145 goto userptr_fail_sglist_alloc;
146
147 sg_init_table(buf->sg_desc.sglist, buf->sg_desc.num_pages);
148 177
149 buf->pages = kzalloc(buf->sg_desc.num_pages * sizeof(struct page *), 178 buf->pages = kzalloc(buf->num_pages * sizeof(struct page *),
150 GFP_KERNEL); 179 GFP_KERNEL);
151 if (!buf->pages) 180 if (!buf->pages)
152 goto userptr_fail_pages_array_alloc; 181 return NULL;
153 182
154 num_pages_from_user = get_user_pages(current, current->mm, 183 num_pages_from_user = get_user_pages(current, current->mm,
155 vaddr & PAGE_MASK, 184 vaddr & PAGE_MASK,
156 buf->sg_desc.num_pages, 185 buf->num_pages,
157 write, 186 write,
158 1, /* force */ 187 1, /* force */
159 buf->pages, 188 buf->pages,
160 NULL); 189 NULL);
161 190
162 if (num_pages_from_user != buf->sg_desc.num_pages) 191 if (num_pages_from_user != buf->num_pages)
163 goto userptr_fail_get_user_pages; 192 goto userptr_fail_get_user_pages;
164 193
165 sg_set_page(&buf->sg_desc.sglist[0], buf->pages[0], 194 if (sg_alloc_table_from_pages(&buf->sg_table, buf->pages,
166 PAGE_SIZE - buf->offset, buf->offset); 195 buf->num_pages, buf->offset, size, 0))
167 size -= PAGE_SIZE - buf->offset; 196 goto userptr_fail_alloc_table_from_pages;
168 for (i = 1; i < buf->sg_desc.num_pages; ++i) { 197
169 sg_set_page(&buf->sg_desc.sglist[i], buf->pages[i],
170 min_t(size_t, PAGE_SIZE, size), 0);
171 size -= min_t(size_t, PAGE_SIZE, size);
172 }
173 return buf; 198 return buf;
174 199
200userptr_fail_alloc_table_from_pages:
175userptr_fail_get_user_pages: 201userptr_fail_get_user_pages:
176 dprintk(1, "get_user_pages requested/got: %d/%d]\n", 202 dprintk(1, "get_user_pages requested/got: %d/%d]\n",
177 num_pages_from_user, buf->sg_desc.num_pages); 203 num_pages_from_user, buf->num_pages);
178 while (--num_pages_from_user >= 0) 204 while (--num_pages_from_user >= 0)
179 put_page(buf->pages[num_pages_from_user]); 205 put_page(buf->pages[num_pages_from_user]);
180 kfree(buf->pages); 206 kfree(buf->pages);
181
182userptr_fail_pages_array_alloc:
183 vfree(buf->sg_desc.sglist);
184
185userptr_fail_sglist_alloc:
186 kfree(buf); 207 kfree(buf);
187 return NULL; 208 return NULL;
188} 209}
@@ -194,18 +215,18 @@ userptr_fail_sglist_alloc:
194static void vb2_dma_sg_put_userptr(void *buf_priv) 215static void vb2_dma_sg_put_userptr(void *buf_priv)
195{ 216{
196 struct vb2_dma_sg_buf *buf = buf_priv; 217 struct vb2_dma_sg_buf *buf = buf_priv;
197 int i = buf->sg_desc.num_pages; 218 int i = buf->num_pages;
198 219
199 dprintk(1, "%s: Releasing userspace buffer of %d pages\n", 220 dprintk(1, "%s: Releasing userspace buffer of %d pages\n",
200 __func__, buf->sg_desc.num_pages); 221 __func__, buf->num_pages);
201 if (buf->vaddr) 222 if (buf->vaddr)
202 vm_unmap_ram(buf->vaddr, buf->sg_desc.num_pages); 223 vm_unmap_ram(buf->vaddr, buf->num_pages);
224 sg_free_table(&buf->sg_table);
203 while (--i >= 0) { 225 while (--i >= 0) {
204 if (buf->write) 226 if (buf->write)
205 set_page_dirty_lock(buf->pages[i]); 227 set_page_dirty_lock(buf->pages[i]);
206 put_page(buf->pages[i]); 228 put_page(buf->pages[i]);
207 } 229 }
208 vfree(buf->sg_desc.sglist);
209 kfree(buf->pages); 230 kfree(buf->pages);
210 kfree(buf); 231 kfree(buf);
211} 232}
@@ -218,7 +239,7 @@ static void *vb2_dma_sg_vaddr(void *buf_priv)
218 239
219 if (!buf->vaddr) 240 if (!buf->vaddr)
220 buf->vaddr = vm_map_ram(buf->pages, 241 buf->vaddr = vm_map_ram(buf->pages,
221 buf->sg_desc.num_pages, 242 buf->num_pages,
222 -1, 243 -1,
223 PAGE_KERNEL); 244 PAGE_KERNEL);
224 245
@@ -274,7 +295,7 @@ static void *vb2_dma_sg_cookie(void *buf_priv)
274{ 295{
275 struct vb2_dma_sg_buf *buf = buf_priv; 296 struct vb2_dma_sg_buf *buf = buf_priv;
276 297
277 return &buf->sg_desc; 298 return &buf->sg_table;
278} 299}
279 300
280const struct vb2_mem_ops vb2_dma_sg_memops = { 301const struct vb2_mem_ops vb2_dma_sg_memops = {
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 94b8a3324319..d87f77f790d6 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -22,7 +22,7 @@
22#include <linux/jiffies.h> 22#include <linux/jiffies.h>
23#include <linux/of.h> 23#include <linux/of.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/i2c/at24.h> 25#include <linux/platform_data/at24.h>
26 26
27/* 27/*
28 * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. 28 * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable.
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 1a3163f1407e..29d5d988a51c 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -2448,7 +2448,6 @@ static int _mmc_blk_suspend(struct mmc_card *card)
2448 struct mmc_blk_data *md = mmc_get_drvdata(card); 2448 struct mmc_blk_data *md = mmc_get_drvdata(card);
2449 2449
2450 if (md) { 2450 if (md) {
2451 pm_runtime_get_sync(&card->dev);
2452 mmc_queue_suspend(&md->queue); 2451 mmc_queue_suspend(&md->queue);
2453 list_for_each_entry(part_md, &md->part, part) { 2452 list_for_each_entry(part_md, &md->part, part) {
2454 mmc_queue_suspend(&part_md->queue); 2453 mmc_queue_suspend(&part_md->queue);
@@ -2483,7 +2482,6 @@ static int mmc_blk_resume(struct mmc_card *card)
2483 list_for_each_entry(part_md, &md->part, part) { 2482 list_for_each_entry(part_md, &md->part, part) {
2484 mmc_queue_resume(&part_md->queue); 2483 mmc_queue_resume(&part_md->queue);
2485 } 2484 }
2486 pm_runtime_put(&card->dev);
2487 } 2485 }
2488 return 0; 2486 return 0;
2489} 2487}
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 3e227bd91e81..64145a32b917 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -342,7 +342,7 @@ int mmc_add_card(struct mmc_card *card)
342 break; 342 break;
343 } 343 }
344 344
345 if (mmc_sd_card_uhs(card) && 345 if (mmc_card_uhs(card) &&
346 (card->sd_bus_speed < ARRAY_SIZE(uhs_speeds))) 346 (card->sd_bus_speed < ARRAY_SIZE(uhs_speeds)))
347 uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed]; 347 uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed];
348 348
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index bf18b6bfce48..57a2b403bf8e 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -23,6 +23,7 @@
23#include <linux/log2.h> 23#include <linux/log2.h>
24#include <linux/regulator/consumer.h> 24#include <linux/regulator/consumer.h>
25#include <linux/pm_runtime.h> 25#include <linux/pm_runtime.h>
26#include <linux/pm_wakeup.h>
26#include <linux/suspend.h> 27#include <linux/suspend.h>
27#include <linux/fault-inject.h> 28#include <linux/fault-inject.h>
28#include <linux/random.h> 29#include <linux/random.h>
@@ -301,7 +302,7 @@ void mmc_start_bkops(struct mmc_card *card, bool from_exception)
301 } 302 }
302 303
303 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 304 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
304 EXT_CSD_BKOPS_START, 1, timeout, use_busy_signal); 305 EXT_CSD_BKOPS_START, 1, timeout, use_busy_signal, true);
305 if (err) { 306 if (err) {
306 pr_warn("%s: Error %d starting bkops\n", 307 pr_warn("%s: Error %d starting bkops\n",
307 mmc_hostname(card->host), err); 308 mmc_hostname(card->host), err);
@@ -918,31 +919,6 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
918EXPORT_SYMBOL(__mmc_claim_host); 919EXPORT_SYMBOL(__mmc_claim_host);
919 920
920/** 921/**
921 * mmc_try_claim_host - try exclusively to claim a host
922 * @host: mmc host to claim
923 *
924 * Returns %1 if the host is claimed, %0 otherwise.
925 */
926int mmc_try_claim_host(struct mmc_host *host)
927{
928 int claimed_host = 0;
929 unsigned long flags;
930
931 spin_lock_irqsave(&host->lock, flags);
932 if (!host->claimed || host->claimer == current) {
933 host->claimed = 1;
934 host->claimer = current;
935 host->claim_cnt += 1;
936 claimed_host = 1;
937 }
938 spin_unlock_irqrestore(&host->lock, flags);
939 if (host->ops->enable && claimed_host && host->claim_cnt == 1)
940 host->ops->enable(host);
941 return claimed_host;
942}
943EXPORT_SYMBOL(mmc_try_claim_host);
944
945/**
946 * mmc_release_host - release a host 922 * mmc_release_host - release a host
947 * @host: mmc host to release 923 * @host: mmc host to release
948 * 924 *
@@ -1382,22 +1358,31 @@ u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
1382{ 1358{
1383 int bit; 1359 int bit;
1384 1360
1385 ocr &= host->ocr_avail; 1361 /*
1362 * Sanity check the voltages that the card claims to
1363 * support.
1364 */
1365 if (ocr & 0x7F) {
1366 dev_warn(mmc_dev(host),
1367 "card claims to support voltages below defined range\n");
1368 ocr &= ~0x7F;
1369 }
1386 1370
1387 bit = ffs(ocr); 1371 ocr &= host->ocr_avail;
1388 if (bit) { 1372 if (!ocr) {
1389 bit -= 1; 1373 dev_warn(mmc_dev(host), "no support for card's volts\n");
1374 return 0;
1375 }
1390 1376
1377 if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) {
1378 bit = ffs(ocr) - 1;
1391 ocr &= 3 << bit; 1379 ocr &= 3 << bit;
1392 1380 mmc_power_cycle(host, ocr);
1393 mmc_host_clk_hold(host);
1394 host->ios.vdd = bit;
1395 mmc_set_ios(host);
1396 mmc_host_clk_release(host);
1397 } else { 1381 } else {
1398 pr_warning("%s: host doesn't support card's voltages\n", 1382 bit = fls(ocr) - 1;
1399 mmc_hostname(host)); 1383 ocr &= 3 << bit;
1400 ocr = 0; 1384 if (bit != host->ios.vdd)
1385 dev_warn(mmc_dev(host), "exceeding card's volts\n");
1401 } 1386 }
1402 1387
1403 return ocr; 1388 return ocr;
@@ -1422,7 +1407,7 @@ int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage)
1422 1407
1423} 1408}
1424 1409
1425int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage) 1410int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, u32 ocr)
1426{ 1411{
1427 struct mmc_command cmd = {0}; 1412 struct mmc_command cmd = {0};
1428 int err = 0; 1413 int err = 0;
@@ -1504,7 +1489,7 @@ power_cycle:
1504 if (err) { 1489 if (err) {
1505 pr_debug("%s: Signal voltage switch failed, " 1490 pr_debug("%s: Signal voltage switch failed, "
1506 "power cycling card\n", mmc_hostname(host)); 1491 "power cycling card\n", mmc_hostname(host));
1507 mmc_power_cycle(host); 1492 mmc_power_cycle(host, ocr);
1508 } 1493 }
1509 1494
1510 mmc_host_clk_release(host); 1495 mmc_host_clk_release(host);
@@ -1545,22 +1530,14 @@ void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type)
1545 * If a host does all the power sequencing itself, ignore the 1530 * If a host does all the power sequencing itself, ignore the
1546 * initial MMC_POWER_UP stage. 1531 * initial MMC_POWER_UP stage.
1547 */ 1532 */
1548void mmc_power_up(struct mmc_host *host) 1533void mmc_power_up(struct mmc_host *host, u32 ocr)
1549{ 1534{
1550 int bit;
1551
1552 if (host->ios.power_mode == MMC_POWER_ON) 1535 if (host->ios.power_mode == MMC_POWER_ON)
1553 return; 1536 return;
1554 1537
1555 mmc_host_clk_hold(host); 1538 mmc_host_clk_hold(host);
1556 1539
1557 /* If ocr is set, we use it */ 1540 host->ios.vdd = fls(ocr) - 1;
1558 if (host->ocr)
1559 bit = ffs(host->ocr) - 1;
1560 else
1561 bit = fls(host->ocr_avail) - 1;
1562
1563 host->ios.vdd = bit;
1564 if (mmc_host_is_spi(host)) 1541 if (mmc_host_is_spi(host))
1565 host->ios.chip_select = MMC_CS_HIGH; 1542 host->ios.chip_select = MMC_CS_HIGH;
1566 else 1543 else
@@ -1604,13 +1581,6 @@ void mmc_power_off(struct mmc_host *host)
1604 host->ios.clock = 0; 1581 host->ios.clock = 0;
1605 host->ios.vdd = 0; 1582 host->ios.vdd = 0;
1606 1583
1607
1608 /*
1609 * Reset ocr mask to be the highest possible voltage supported for
1610 * this mmc host. This value will be used at next power up.
1611 */
1612 host->ocr = 1 << (fls(host->ocr_avail) - 1);
1613
1614 if (!mmc_host_is_spi(host)) { 1584 if (!mmc_host_is_spi(host)) {
1615 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; 1585 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
1616 host->ios.chip_select = MMC_CS_DONTCARE; 1586 host->ios.chip_select = MMC_CS_DONTCARE;
@@ -1630,12 +1600,12 @@ void mmc_power_off(struct mmc_host *host)
1630 mmc_host_clk_release(host); 1600 mmc_host_clk_release(host);
1631} 1601}
1632 1602
1633void mmc_power_cycle(struct mmc_host *host) 1603void mmc_power_cycle(struct mmc_host *host, u32 ocr)
1634{ 1604{
1635 mmc_power_off(host); 1605 mmc_power_off(host);
1636 /* Wait at least 1 ms according to SD spec */ 1606 /* Wait at least 1 ms according to SD spec */
1637 mmc_delay(1); 1607 mmc_delay(1);
1638 mmc_power_up(host); 1608 mmc_power_up(host, ocr);
1639} 1609}
1640 1610
1641/* 1611/*
@@ -1723,6 +1693,28 @@ void mmc_detach_bus(struct mmc_host *host)
1723 mmc_bus_put(host); 1693 mmc_bus_put(host);
1724} 1694}
1725 1695
1696static void _mmc_detect_change(struct mmc_host *host, unsigned long delay,
1697 bool cd_irq)
1698{
1699#ifdef CONFIG_MMC_DEBUG
1700 unsigned long flags;
1701 spin_lock_irqsave(&host->lock, flags);
1702 WARN_ON(host->removed);
1703 spin_unlock_irqrestore(&host->lock, flags);
1704#endif
1705
1706 /*
1707 * If the device is configured as wakeup, we prevent a new sleep for
1708 * 5 s to give provision for user space to consume the event.
1709 */
1710 if (cd_irq && !(host->caps & MMC_CAP_NEEDS_POLL) &&
1711 device_can_wakeup(mmc_dev(host)))
1712 pm_wakeup_event(mmc_dev(host), 5000);
1713
1714 host->detect_change = 1;
1715 mmc_schedule_delayed_work(&host->detect, delay);
1716}
1717
1726/** 1718/**
1727 * mmc_detect_change - process change of state on a MMC socket 1719 * mmc_detect_change - process change of state on a MMC socket
1728 * @host: host which changed state. 1720 * @host: host which changed state.
@@ -1735,16 +1727,8 @@ void mmc_detach_bus(struct mmc_host *host)
1735 */ 1727 */
1736void mmc_detect_change(struct mmc_host *host, unsigned long delay) 1728void mmc_detect_change(struct mmc_host *host, unsigned long delay)
1737{ 1729{
1738#ifdef CONFIG_MMC_DEBUG 1730 _mmc_detect_change(host, delay, true);
1739 unsigned long flags;
1740 spin_lock_irqsave(&host->lock, flags);
1741 WARN_ON(host->removed);
1742 spin_unlock_irqrestore(&host->lock, flags);
1743#endif
1744 host->detect_change = 1;
1745 mmc_schedule_delayed_work(&host->detect, delay);
1746} 1731}
1747
1748EXPORT_SYMBOL(mmc_detect_change); 1732EXPORT_SYMBOL(mmc_detect_change);
1749 1733
1750void mmc_init_erase(struct mmc_card *card) 1734void mmc_init_erase(struct mmc_card *card)
@@ -2334,7 +2318,7 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
2334 pr_info("%s: %s: trying to init card at %u Hz\n", 2318 pr_info("%s: %s: trying to init card at %u Hz\n",
2335 mmc_hostname(host), __func__, host->f_init); 2319 mmc_hostname(host), __func__, host->f_init);
2336#endif 2320#endif
2337 mmc_power_up(host); 2321 mmc_power_up(host, host->ocr_avail);
2338 2322
2339 /* 2323 /*
2340 * Some eMMCs (with VCCQ always on) may not be reset after power up, so 2324 * Some eMMCs (with VCCQ always on) may not be reset after power up, so
@@ -2423,7 +2407,7 @@ int mmc_detect_card_removed(struct mmc_host *host)
2423 * rescan handle the card removal. 2407 * rescan handle the card removal.
2424 */ 2408 */
2425 cancel_delayed_work(&host->detect); 2409 cancel_delayed_work(&host->detect);
2426 mmc_detect_change(host, 0); 2410 _mmc_detect_change(host, 0, false);
2427 } 2411 }
2428 } 2412 }
2429 2413
@@ -2504,8 +2488,8 @@ void mmc_start_host(struct mmc_host *host)
2504 if (host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP) 2488 if (host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP)
2505 mmc_power_off(host); 2489 mmc_power_off(host);
2506 else 2490 else
2507 mmc_power_up(host); 2491 mmc_power_up(host, host->ocr_avail);
2508 mmc_detect_change(host, 0); 2492 _mmc_detect_change(host, 0, false);
2509} 2493}
2510 2494
2511void mmc_stop_host(struct mmc_host *host) 2495void mmc_stop_host(struct mmc_host *host)
@@ -2583,7 +2567,7 @@ int mmc_power_restore_host(struct mmc_host *host)
2583 return -EINVAL; 2567 return -EINVAL;
2584 } 2568 }
2585 2569
2586 mmc_power_up(host); 2570 mmc_power_up(host, host->card->ocr);
2587 ret = host->bus_ops->power_restore(host); 2571 ret = host->bus_ops->power_restore(host);
2588 2572
2589 mmc_bus_put(host); 2573 mmc_bus_put(host);
@@ -2657,28 +2641,6 @@ EXPORT_SYMBOL(mmc_cache_ctrl);
2657 2641
2658#ifdef CONFIG_PM 2642#ifdef CONFIG_PM
2659 2643
2660/**
2661 * mmc_suspend_host - suspend a host
2662 * @host: mmc host
2663 */
2664int mmc_suspend_host(struct mmc_host *host)
2665{
2666 /* This function is deprecated */
2667 return 0;
2668}
2669EXPORT_SYMBOL(mmc_suspend_host);
2670
2671/**
2672 * mmc_resume_host - resume a previously suspended host
2673 * @host: mmc host
2674 */
2675int mmc_resume_host(struct mmc_host *host)
2676{
2677 /* This function is deprecated */
2678 return 0;
2679}
2680EXPORT_SYMBOL(mmc_resume_host);
2681
2682/* Do the card removal on suspend if card is assumed removeable 2644/* Do the card removal on suspend if card is assumed removeable
2683 * Do that in pm notifier while userspace isn't yet frozen, so we will be able 2645 * Do that in pm notifier while userspace isn't yet frozen, so we will be able
2684 to sync the card. 2646 to sync the card.
@@ -2724,7 +2686,7 @@ int mmc_pm_notify(struct notifier_block *notify_block,
2724 spin_lock_irqsave(&host->lock, flags); 2686 spin_lock_irqsave(&host->lock, flags);
2725 host->rescan_disable = 0; 2687 host->rescan_disable = 0;
2726 spin_unlock_irqrestore(&host->lock, flags); 2688 spin_unlock_irqrestore(&host->lock, flags);
2727 mmc_detect_change(host, 0); 2689 _mmc_detect_change(host, 0, false);
2728 2690
2729 } 2691 }
2730 2692
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index 5345d156493e..443a584660f0 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -42,13 +42,13 @@ void mmc_set_ungated(struct mmc_host *host);
42void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode); 42void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
43void mmc_set_bus_width(struct mmc_host *host, unsigned int width); 43void mmc_set_bus_width(struct mmc_host *host, unsigned int width);
44u32 mmc_select_voltage(struct mmc_host *host, u32 ocr); 44u32 mmc_select_voltage(struct mmc_host *host, u32 ocr);
45int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage); 45int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, u32 ocr);
46int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage); 46int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage);
47void mmc_set_timing(struct mmc_host *host, unsigned int timing); 47void mmc_set_timing(struct mmc_host *host, unsigned int timing);
48void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type); 48void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
49void mmc_power_up(struct mmc_host *host); 49void mmc_power_up(struct mmc_host *host, u32 ocr);
50void mmc_power_off(struct mmc_host *host); 50void mmc_power_off(struct mmc_host *host);
51void mmc_power_cycle(struct mmc_host *host); 51void mmc_power_cycle(struct mmc_host *host, u32 ocr);
52 52
53static inline void mmc_delay(unsigned int ms) 53static inline void mmc_delay(unsigned int ms)
54{ 54{
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 6d02012a1d0b..f631f5a9bf79 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -13,6 +13,7 @@
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/stat.h> 15#include <linux/stat.h>
16#include <linux/pm_runtime.h>
16 17
17#include <linux/mmc/host.h> 18#include <linux/mmc/host.h>
18#include <linux/mmc/card.h> 19#include <linux/mmc/card.h>
@@ -934,6 +935,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
934 goto err; 935 goto err;
935 } 936 }
936 937
938 card->ocr = ocr;
937 card->type = MMC_TYPE_MMC; 939 card->type = MMC_TYPE_MMC;
938 card->rca = 1; 940 card->rca = 1;
939 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); 941 memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
@@ -1404,9 +1406,9 @@ static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type)
1404 if (notify_type == EXT_CSD_POWER_OFF_LONG) 1406 if (notify_type == EXT_CSD_POWER_OFF_LONG)
1405 timeout = card->ext_csd.power_off_longtime; 1407 timeout = card->ext_csd.power_off_longtime;
1406 1408
1407 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1409 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1408 EXT_CSD_POWER_OFF_NOTIFICATION, 1410 EXT_CSD_POWER_OFF_NOTIFICATION,
1409 notify_type, timeout); 1411 notify_type, timeout, true, false);
1410 if (err) 1412 if (err)
1411 pr_err("%s: Power Off Notification timed out, %u\n", 1413 pr_err("%s: Power Off Notification timed out, %u\n",
1412 mmc_hostname(card->host), timeout); 1414 mmc_hostname(card->host), timeout);
@@ -1477,6 +1479,9 @@ static int _mmc_suspend(struct mmc_host *host, bool is_suspend)
1477 1479
1478 mmc_claim_host(host); 1480 mmc_claim_host(host);
1479 1481
1482 if (mmc_card_suspended(host->card))
1483 goto out;
1484
1480 if (mmc_card_doing_bkops(host->card)) { 1485 if (mmc_card_doing_bkops(host->card)) {
1481 err = mmc_stop_bkops(host->card); 1486 err = mmc_stop_bkops(host->card);
1482 if (err) 1487 if (err)
@@ -1496,51 +1501,93 @@ static int _mmc_suspend(struct mmc_host *host, bool is_suspend)
1496 err = mmc_deselect_cards(host); 1501 err = mmc_deselect_cards(host);
1497 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); 1502 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200);
1498 1503
1499 if (!err) 1504 if (!err) {
1500 mmc_power_off(host); 1505 mmc_power_off(host);
1506 mmc_card_set_suspended(host->card);
1507 }
1501out: 1508out:
1502 mmc_release_host(host); 1509 mmc_release_host(host);
1503 return err; 1510 return err;
1504} 1511}
1505 1512
1506/* 1513/*
1507 * Suspend callback from host. 1514 * Suspend callback
1508 */ 1515 */
1509static int mmc_suspend(struct mmc_host *host) 1516static int mmc_suspend(struct mmc_host *host)
1510{ 1517{
1511 return _mmc_suspend(host, true); 1518 int err;
1512}
1513 1519
1514/* 1520 err = _mmc_suspend(host, true);
1515 * Shutdown callback 1521 if (!err) {
1516 */ 1522 pm_runtime_disable(&host->card->dev);
1517static int mmc_shutdown(struct mmc_host *host) 1523 pm_runtime_set_suspended(&host->card->dev);
1518{ 1524 }
1519 return _mmc_suspend(host, false); 1525
1526 return err;
1520} 1527}
1521 1528
1522/* 1529/*
1523 * Resume callback from host.
1524 *
1525 * This function tries to determine if the same card is still present 1530 * This function tries to determine if the same card is still present
1526 * and, if so, restore all state to it. 1531 * and, if so, restore all state to it.
1527 */ 1532 */
1528static int mmc_resume(struct mmc_host *host) 1533static int _mmc_resume(struct mmc_host *host)
1529{ 1534{
1530 int err; 1535 int err = 0;
1531 1536
1532 BUG_ON(!host); 1537 BUG_ON(!host);
1533 BUG_ON(!host->card); 1538 BUG_ON(!host->card);
1534 1539
1535 mmc_claim_host(host); 1540 mmc_claim_host(host);
1536 mmc_power_up(host); 1541
1537 mmc_select_voltage(host, host->ocr); 1542 if (!mmc_card_suspended(host->card))
1538 err = mmc_init_card(host, host->ocr, host->card); 1543 goto out;
1544
1545 mmc_power_up(host, host->card->ocr);
1546 err = mmc_init_card(host, host->card->ocr, host->card);
1547 mmc_card_clr_suspended(host->card);
1548
1549out:
1539 mmc_release_host(host); 1550 mmc_release_host(host);
1551 return err;
1552}
1553
1554/*
1555 * Shutdown callback
1556 */
1557static int mmc_shutdown(struct mmc_host *host)
1558{
1559 int err = 0;
1560
1561 /*
1562 * In a specific case for poweroff notify, we need to resume the card
1563 * before we can shutdown it properly.
1564 */
1565 if (mmc_can_poweroff_notify(host->card) &&
1566 !(host->caps2 & MMC_CAP2_FULL_PWR_CYCLE))
1567 err = _mmc_resume(host);
1568
1569 if (!err)
1570 err = _mmc_suspend(host, false);
1540 1571
1541 return err; 1572 return err;
1542} 1573}
1543 1574
1575/*
1576 * Callback for resume.
1577 */
1578static int mmc_resume(struct mmc_host *host)
1579{
1580 int err = 0;
1581
1582 if (!(host->caps & MMC_CAP_RUNTIME_RESUME)) {
1583 err = _mmc_resume(host);
1584 pm_runtime_set_active(&host->card->dev);
1585 pm_runtime_mark_last_busy(&host->card->dev);
1586 }
1587 pm_runtime_enable(&host->card->dev);
1588
1589 return err;
1590}
1544 1591
1545/* 1592/*
1546 * Callback for runtime_suspend. 1593 * Callback for runtime_suspend.
@@ -1552,18 +1599,11 @@ static int mmc_runtime_suspend(struct mmc_host *host)
1552 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) 1599 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
1553 return 0; 1600 return 0;
1554 1601
1555 mmc_claim_host(host); 1602 err = _mmc_suspend(host, true);
1556 1603 if (err)
1557 err = mmc_suspend(host);
1558 if (err) {
1559 pr_err("%s: error %d doing aggessive suspend\n", 1604 pr_err("%s: error %d doing aggessive suspend\n",
1560 mmc_hostname(host), err); 1605 mmc_hostname(host), err);
1561 goto out;
1562 }
1563 mmc_power_off(host);
1564 1606
1565out:
1566 mmc_release_host(host);
1567 return err; 1607 return err;
1568} 1608}
1569 1609
@@ -1574,18 +1614,14 @@ static int mmc_runtime_resume(struct mmc_host *host)
1574{ 1614{
1575 int err; 1615 int err;
1576 1616
1577 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) 1617 if (!(host->caps & (MMC_CAP_AGGRESSIVE_PM | MMC_CAP_RUNTIME_RESUME)))
1578 return 0; 1618 return 0;
1579 1619
1580 mmc_claim_host(host); 1620 err = _mmc_resume(host);
1581
1582 mmc_power_up(host);
1583 err = mmc_resume(host);
1584 if (err) 1621 if (err)
1585 pr_err("%s: error %d doing aggessive resume\n", 1622 pr_err("%s: error %d doing aggessive resume\n",
1586 mmc_hostname(host), err); 1623 mmc_hostname(host), err);
1587 1624
1588 mmc_release_host(host);
1589 return 0; 1625 return 0;
1590} 1626}
1591 1627
@@ -1595,7 +1631,7 @@ static int mmc_power_restore(struct mmc_host *host)
1595 1631
1596 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); 1632 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200);
1597 mmc_claim_host(host); 1633 mmc_claim_host(host);
1598 ret = mmc_init_card(host, host->ocr, host->card); 1634 ret = mmc_init_card(host, host->card->ocr, host->card);
1599 mmc_release_host(host); 1635 mmc_release_host(host);
1600 1636
1601 return ret; 1637 return ret;
@@ -1640,7 +1676,7 @@ static void mmc_attach_bus_ops(struct mmc_host *host)
1640int mmc_attach_mmc(struct mmc_host *host) 1676int mmc_attach_mmc(struct mmc_host *host)
1641{ 1677{
1642 int err; 1678 int err;
1643 u32 ocr; 1679 u32 ocr, rocr;
1644 1680
1645 BUG_ON(!host); 1681 BUG_ON(!host);
1646 WARN_ON(!host->claimed); 1682 WARN_ON(!host->claimed);
@@ -1666,23 +1702,12 @@ int mmc_attach_mmc(struct mmc_host *host)
1666 goto err; 1702 goto err;
1667 } 1703 }
1668 1704
1669 /* 1705 rocr = mmc_select_voltage(host, ocr);
1670 * Sanity check the voltages that the card claims to
1671 * support.
1672 */
1673 if (ocr & 0x7F) {
1674 pr_warning("%s: card claims to support voltages "
1675 "below the defined range. These will be ignored.\n",
1676 mmc_hostname(host));
1677 ocr &= ~0x7F;
1678 }
1679
1680 host->ocr = mmc_select_voltage(host, ocr);
1681 1706
1682 /* 1707 /*
1683 * Can we support the voltage of the card? 1708 * Can we support the voltage of the card?
1684 */ 1709 */
1685 if (!host->ocr) { 1710 if (!rocr) {
1686 err = -EINVAL; 1711 err = -EINVAL;
1687 goto err; 1712 goto err;
1688 } 1713 }
@@ -1690,7 +1715,7 @@ int mmc_attach_mmc(struct mmc_host *host)
1690 /* 1715 /*
1691 * Detect and init the card. 1716 * Detect and init the card.
1692 */ 1717 */
1693 err = mmc_init_card(host, host->ocr, NULL); 1718 err = mmc_init_card(host, rocr, NULL);
1694 if (err) 1719 if (err)
1695 goto err; 1720 goto err;
1696 1721
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index ef183483d5b6..e5b5eeb548d1 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -23,6 +23,40 @@
23 23
24#define MMC_OPS_TIMEOUT_MS (10 * 60 * 1000) /* 10 minute timeout */ 24#define MMC_OPS_TIMEOUT_MS (10 * 60 * 1000) /* 10 minute timeout */
25 25
26static inline int __mmc_send_status(struct mmc_card *card, u32 *status,
27 bool ignore_crc)
28{
29 int err;
30 struct mmc_command cmd = {0};
31
32 BUG_ON(!card);
33 BUG_ON(!card->host);
34
35 cmd.opcode = MMC_SEND_STATUS;
36 if (!mmc_host_is_spi(card->host))
37 cmd.arg = card->rca << 16;
38 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
39 if (ignore_crc)
40 cmd.flags &= ~MMC_RSP_CRC;
41
42 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
43 if (err)
44 return err;
45
46 /* NOTE: callers are required to understand the difference
47 * between "native" and SPI format status words!
48 */
49 if (status)
50 *status = cmd.resp[0];
51
52 return 0;
53}
54
55int mmc_send_status(struct mmc_card *card, u32 *status)
56{
57 return __mmc_send_status(card, status, false);
58}
59
26static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card) 60static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card)
27{ 61{
28 int err; 62 int err;
@@ -370,16 +404,18 @@ int mmc_spi_set_crc(struct mmc_host *host, int use_crc)
370 * @timeout_ms: timeout (ms) for operation performed by register write, 404 * @timeout_ms: timeout (ms) for operation performed by register write,
371 * timeout of zero implies maximum possible timeout 405 * timeout of zero implies maximum possible timeout
372 * @use_busy_signal: use the busy signal as response type 406 * @use_busy_signal: use the busy signal as response type
407 * @send_status: send status cmd to poll for busy
373 * 408 *
374 * Modifies the EXT_CSD register for selected card. 409 * Modifies the EXT_CSD register for selected card.
375 */ 410 */
376int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, 411int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
377 unsigned int timeout_ms, bool use_busy_signal) 412 unsigned int timeout_ms, bool use_busy_signal, bool send_status)
378{ 413{
379 int err; 414 int err;
380 struct mmc_command cmd = {0}; 415 struct mmc_command cmd = {0};
381 unsigned long timeout; 416 unsigned long timeout;
382 u32 status; 417 u32 status = 0;
418 bool ignore_crc = false;
383 419
384 BUG_ON(!card); 420 BUG_ON(!card);
385 BUG_ON(!card->host); 421 BUG_ON(!card->host);
@@ -408,17 +444,37 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
408 if (!use_busy_signal) 444 if (!use_busy_signal)
409 return 0; 445 return 0;
410 446
411 /* Must check status to be sure of no errors */ 447 /*
448 * Must check status to be sure of no errors
449 * If CMD13 is to check the busy completion of the timing change,
450 * disable the check of CRC error.
451 */
452 if (index == EXT_CSD_HS_TIMING &&
453 !(card->host->caps & MMC_CAP_WAIT_WHILE_BUSY))
454 ignore_crc = true;
455
412 timeout = jiffies + msecs_to_jiffies(MMC_OPS_TIMEOUT_MS); 456 timeout = jiffies + msecs_to_jiffies(MMC_OPS_TIMEOUT_MS);
413 do { 457 do {
414 err = mmc_send_status(card, &status); 458 if (send_status) {
415 if (err) 459 err = __mmc_send_status(card, &status, ignore_crc);
416 return err; 460 if (err)
461 return err;
462 }
417 if (card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) 463 if (card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
418 break; 464 break;
419 if (mmc_host_is_spi(card->host)) 465 if (mmc_host_is_spi(card->host))
420 break; 466 break;
421 467
468 /*
469 * We are not allowed to issue a status command and the host
470 * does'nt support MMC_CAP_WAIT_WHILE_BUSY, then we can only
471 * rely on waiting for the stated timeout to be sufficient.
472 */
473 if (!send_status) {
474 mmc_delay(timeout_ms);
475 return 0;
476 }
477
422 /* Timeout if the device never leaves the program state. */ 478 /* Timeout if the device never leaves the program state. */
423 if (time_after(jiffies, timeout)) { 479 if (time_after(jiffies, timeout)) {
424 pr_err("%s: Card stuck in programming state! %s\n", 480 pr_err("%s: Card stuck in programming state! %s\n",
@@ -445,36 +501,10 @@ EXPORT_SYMBOL_GPL(__mmc_switch);
445int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, 501int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
446 unsigned int timeout_ms) 502 unsigned int timeout_ms)
447{ 503{
448 return __mmc_switch(card, set, index, value, timeout_ms, true); 504 return __mmc_switch(card, set, index, value, timeout_ms, true, true);
449} 505}
450EXPORT_SYMBOL_GPL(mmc_switch); 506EXPORT_SYMBOL_GPL(mmc_switch);
451 507
452int mmc_send_status(struct mmc_card *card, u32 *status)
453{
454 int err;
455 struct mmc_command cmd = {0};
456
457 BUG_ON(!card);
458 BUG_ON(!card->host);
459
460 cmd.opcode = MMC_SEND_STATUS;
461 if (!mmc_host_is_spi(card->host))
462 cmd.arg = card->rca << 16;
463 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
464
465 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
466 if (err)
467 return err;
468
469 /* NOTE: callers are required to understand the difference
470 * between "native" and SPI format status words!
471 */
472 if (status)
473 *status = cmd.resp[0];
474
475 return 0;
476}
477
478static int 508static int
479mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode, 509mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode,
480 u8 len) 510 u8 len)
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 5e8823dc3ef6..6f42050b7ccc 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -13,6 +13,7 @@
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/stat.h> 15#include <linux/stat.h>
16#include <linux/pm_runtime.h>
16 17
17#include <linux/mmc/host.h> 18#include <linux/mmc/host.h>
18#include <linux/mmc/card.h> 19#include <linux/mmc/card.h>
@@ -721,6 +722,7 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr)
721 int err; 722 int err;
722 u32 max_current; 723 u32 max_current;
723 int retries = 10; 724 int retries = 10;
725 u32 pocr = ocr;
724 726
725try_again: 727try_again:
726 if (!retries) { 728 if (!retries) {
@@ -773,7 +775,8 @@ try_again:
773 */ 775 */
774 if (!mmc_host_is_spi(host) && rocr && 776 if (!mmc_host_is_spi(host) && rocr &&
775 ((*rocr & 0x41000000) == 0x41000000)) { 777 ((*rocr & 0x41000000) == 0x41000000)) {
776 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180); 778 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180,
779 pocr);
777 if (err == -EAGAIN) { 780 if (err == -EAGAIN) {
778 retries--; 781 retries--;
779 goto try_again; 782 goto try_again;
@@ -935,6 +938,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
935 if (IS_ERR(card)) 938 if (IS_ERR(card))
936 return PTR_ERR(card); 939 return PTR_ERR(card);
937 940
941 card->ocr = ocr;
938 card->type = MMC_TYPE_SD; 942 card->type = MMC_TYPE_SD;
939 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); 943 memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
940 } 944 }
@@ -1064,10 +1068,7 @@ static void mmc_sd_detect(struct mmc_host *host)
1064 } 1068 }
1065} 1069}
1066 1070
1067/* 1071static int _mmc_sd_suspend(struct mmc_host *host)
1068 * Suspend callback from host.
1069 */
1070static int mmc_sd_suspend(struct mmc_host *host)
1071{ 1072{
1072 int err = 0; 1073 int err = 0;
1073 1074
@@ -1075,34 +1076,77 @@ static int mmc_sd_suspend(struct mmc_host *host)
1075 BUG_ON(!host->card); 1076 BUG_ON(!host->card);
1076 1077
1077 mmc_claim_host(host); 1078 mmc_claim_host(host);
1079
1080 if (mmc_card_suspended(host->card))
1081 goto out;
1082
1078 if (!mmc_host_is_spi(host)) 1083 if (!mmc_host_is_spi(host))
1079 err = mmc_deselect_cards(host); 1084 err = mmc_deselect_cards(host);
1080 host->card->state &= ~MMC_STATE_HIGHSPEED; 1085 host->card->state &= ~MMC_STATE_HIGHSPEED;
1081 if (!err) 1086 if (!err) {
1082 mmc_power_off(host); 1087 mmc_power_off(host);
1088 mmc_card_set_suspended(host->card);
1089 }
1090
1091out:
1083 mmc_release_host(host); 1092 mmc_release_host(host);
1093 return err;
1094}
1095
1096/*
1097 * Callback for suspend
1098 */
1099static int mmc_sd_suspend(struct mmc_host *host)
1100{
1101 int err;
1102
1103 err = _mmc_sd_suspend(host);
1104 if (!err) {
1105 pm_runtime_disable(&host->card->dev);
1106 pm_runtime_set_suspended(&host->card->dev);
1107 }
1084 1108
1085 return err; 1109 return err;
1086} 1110}
1087 1111
1088/* 1112/*
1089 * Resume callback from host.
1090 *
1091 * This function tries to determine if the same card is still present 1113 * This function tries to determine if the same card is still present
1092 * and, if so, restore all state to it. 1114 * and, if so, restore all state to it.
1093 */ 1115 */
1094static int mmc_sd_resume(struct mmc_host *host) 1116static int _mmc_sd_resume(struct mmc_host *host)
1095{ 1117{
1096 int err; 1118 int err = 0;
1097 1119
1098 BUG_ON(!host); 1120 BUG_ON(!host);
1099 BUG_ON(!host->card); 1121 BUG_ON(!host->card);
1100 1122
1101 mmc_claim_host(host); 1123 mmc_claim_host(host);
1102 mmc_power_up(host); 1124
1103 mmc_select_voltage(host, host->ocr); 1125 if (!mmc_card_suspended(host->card))
1104 err = mmc_sd_init_card(host, host->ocr, host->card); 1126 goto out;
1127
1128 mmc_power_up(host, host->card->ocr);
1129 err = mmc_sd_init_card(host, host->card->ocr, host->card);
1130 mmc_card_clr_suspended(host->card);
1131
1132out:
1105 mmc_release_host(host); 1133 mmc_release_host(host);
1134 return err;
1135}
1136
1137/*
1138 * Callback for resume
1139 */
1140static int mmc_sd_resume(struct mmc_host *host)
1141{
1142 int err = 0;
1143
1144 if (!(host->caps & MMC_CAP_RUNTIME_RESUME)) {
1145 err = _mmc_sd_resume(host);
1146 pm_runtime_set_active(&host->card->dev);
1147 pm_runtime_mark_last_busy(&host->card->dev);
1148 }
1149 pm_runtime_enable(&host->card->dev);
1106 1150
1107 return err; 1151 return err;
1108} 1152}
@@ -1117,18 +1161,11 @@ static int mmc_sd_runtime_suspend(struct mmc_host *host)
1117 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) 1161 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
1118 return 0; 1162 return 0;
1119 1163
1120 mmc_claim_host(host); 1164 err = _mmc_sd_suspend(host);
1121 1165 if (err)
1122 err = mmc_sd_suspend(host);
1123 if (err) {
1124 pr_err("%s: error %d doing aggessive suspend\n", 1166 pr_err("%s: error %d doing aggessive suspend\n",
1125 mmc_hostname(host), err); 1167 mmc_hostname(host), err);
1126 goto out;
1127 }
1128 mmc_power_off(host);
1129 1168
1130out:
1131 mmc_release_host(host);
1132 return err; 1169 return err;
1133} 1170}
1134 1171
@@ -1139,18 +1176,14 @@ static int mmc_sd_runtime_resume(struct mmc_host *host)
1139{ 1176{
1140 int err; 1177 int err;
1141 1178
1142 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) 1179 if (!(host->caps & (MMC_CAP_AGGRESSIVE_PM | MMC_CAP_RUNTIME_RESUME)))
1143 return 0; 1180 return 0;
1144 1181
1145 mmc_claim_host(host); 1182 err = _mmc_sd_resume(host);
1146
1147 mmc_power_up(host);
1148 err = mmc_sd_resume(host);
1149 if (err) 1183 if (err)
1150 pr_err("%s: error %d doing aggessive resume\n", 1184 pr_err("%s: error %d doing aggessive resume\n",
1151 mmc_hostname(host), err); 1185 mmc_hostname(host), err);
1152 1186
1153 mmc_release_host(host);
1154 return 0; 1187 return 0;
1155} 1188}
1156 1189
@@ -1160,7 +1193,7 @@ static int mmc_sd_power_restore(struct mmc_host *host)
1160 1193
1161 host->card->state &= ~MMC_STATE_HIGHSPEED; 1194 host->card->state &= ~MMC_STATE_HIGHSPEED;
1162 mmc_claim_host(host); 1195 mmc_claim_host(host);
1163 ret = mmc_sd_init_card(host, host->ocr, host->card); 1196 ret = mmc_sd_init_card(host, host->card->ocr, host->card);
1164 mmc_release_host(host); 1197 mmc_release_host(host);
1165 1198
1166 return ret; 1199 return ret;
@@ -1205,7 +1238,7 @@ static void mmc_sd_attach_bus_ops(struct mmc_host *host)
1205int mmc_attach_sd(struct mmc_host *host) 1238int mmc_attach_sd(struct mmc_host *host)
1206{ 1239{
1207 int err; 1240 int err;
1208 u32 ocr; 1241 u32 ocr, rocr;
1209 1242
1210 BUG_ON(!host); 1243 BUG_ON(!host);
1211 WARN_ON(!host->claimed); 1244 WARN_ON(!host->claimed);
@@ -1229,31 +1262,12 @@ int mmc_attach_sd(struct mmc_host *host)
1229 goto err; 1262 goto err;
1230 } 1263 }
1231 1264
1232 /* 1265 rocr = mmc_select_voltage(host, ocr);
1233 * Sanity check the voltages that the card claims to
1234 * support.
1235 */
1236 if (ocr & 0x7F) {
1237 pr_warning("%s: card claims to support voltages "
1238 "below the defined range. These will be ignored.\n",
1239 mmc_hostname(host));
1240 ocr &= ~0x7F;
1241 }
1242
1243 if ((ocr & MMC_VDD_165_195) &&
1244 !(host->ocr_avail_sd & MMC_VDD_165_195)) {
1245 pr_warning("%s: SD card claims to support the "
1246 "incompletely defined 'low voltage range'. This "
1247 "will be ignored.\n", mmc_hostname(host));
1248 ocr &= ~MMC_VDD_165_195;
1249 }
1250
1251 host->ocr = mmc_select_voltage(host, ocr);
1252 1266
1253 /* 1267 /*
1254 * Can we support the voltage(s) of the card(s)? 1268 * Can we support the voltage(s) of the card(s)?
1255 */ 1269 */
1256 if (!host->ocr) { 1270 if (!rocr) {
1257 err = -EINVAL; 1271 err = -EINVAL;
1258 goto err; 1272 goto err;
1259 } 1273 }
@@ -1261,7 +1275,7 @@ int mmc_attach_sd(struct mmc_host *host)
1261 /* 1275 /*
1262 * Detect and init the card. 1276 * Detect and init the card.
1263 */ 1277 */
1264 err = mmc_sd_init_card(host, host->ocr, NULL); 1278 err = mmc_sd_init_card(host, rocr, NULL);
1265 if (err) 1279 if (err)
1266 goto err; 1280 goto err;
1267 1281
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index 80d89cff7306..4d721c6e2af0 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -593,23 +593,28 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
593 struct mmc_card *card; 593 struct mmc_card *card;
594 int err; 594 int err;
595 int retries = 10; 595 int retries = 10;
596 u32 rocr = 0;
597 u32 ocr_card = ocr;
596 598
597 BUG_ON(!host); 599 BUG_ON(!host);
598 WARN_ON(!host->claimed); 600 WARN_ON(!host->claimed);
599 601
602 /* to query card if 1.8V signalling is supported */
603 if (mmc_host_uhs(host))
604 ocr |= R4_18V_PRESENT;
605
600try_again: 606try_again:
601 if (!retries) { 607 if (!retries) {
602 pr_warning("%s: Skipping voltage switch\n", 608 pr_warning("%s: Skipping voltage switch\n",
603 mmc_hostname(host)); 609 mmc_hostname(host));
604 ocr &= ~R4_18V_PRESENT; 610 ocr &= ~R4_18V_PRESENT;
605 host->ocr &= ~R4_18V_PRESENT;
606 } 611 }
607 612
608 /* 613 /*
609 * Inform the card of the voltage 614 * Inform the card of the voltage
610 */ 615 */
611 if (!powered_resume) { 616 if (!powered_resume) {
612 err = mmc_send_io_op_cond(host, host->ocr, &ocr); 617 err = mmc_send_io_op_cond(host, ocr, &rocr);
613 if (err) 618 if (err)
614 goto err; 619 goto err;
615 } 620 }
@@ -632,8 +637,8 @@ try_again:
632 goto err; 637 goto err;
633 } 638 }
634 639
635 if ((ocr & R4_MEMORY_PRESENT) && 640 if ((rocr & R4_MEMORY_PRESENT) &&
636 mmc_sd_get_cid(host, host->ocr & ocr, card->raw_cid, NULL) == 0) { 641 mmc_sd_get_cid(host, ocr & rocr, card->raw_cid, NULL) == 0) {
637 card->type = MMC_TYPE_SD_COMBO; 642 card->type = MMC_TYPE_SD_COMBO;
638 643
639 if (oldcard && (oldcard->type != MMC_TYPE_SD_COMBO || 644 if (oldcard && (oldcard->type != MMC_TYPE_SD_COMBO ||
@@ -663,8 +668,9 @@ try_again:
663 * systems that claim 1.8v signalling in fact do not support 668 * systems that claim 1.8v signalling in fact do not support
664 * it. 669 * it.
665 */ 670 */
666 if (!powered_resume && (ocr & R4_18V_PRESENT) && mmc_host_uhs(host)) { 671 if (!powered_resume && (rocr & ocr & R4_18V_PRESENT)) {
667 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180); 672 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180,
673 ocr);
668 if (err == -EAGAIN) { 674 if (err == -EAGAIN) {
669 sdio_reset(host); 675 sdio_reset(host);
670 mmc_go_idle(host); 676 mmc_go_idle(host);
@@ -674,12 +680,10 @@ try_again:
674 goto try_again; 680 goto try_again;
675 } else if (err) { 681 } else if (err) {
676 ocr &= ~R4_18V_PRESENT; 682 ocr &= ~R4_18V_PRESENT;
677 host->ocr &= ~R4_18V_PRESENT;
678 } 683 }
679 err = 0; 684 err = 0;
680 } else { 685 } else {
681 ocr &= ~R4_18V_PRESENT; 686 ocr &= ~R4_18V_PRESENT;
682 host->ocr &= ~R4_18V_PRESENT;
683 } 687 }
684 688
685 /* 689 /*
@@ -759,6 +763,7 @@ try_again:
759 763
760 card = oldcard; 764 card = oldcard;
761 } 765 }
766 card->ocr = ocr_card;
762 mmc_fixup_device(card, NULL); 767 mmc_fixup_device(card, NULL);
763 768
764 if (card->type == MMC_TYPE_SD_COMBO) { 769 if (card->type == MMC_TYPE_SD_COMBO) {
@@ -981,8 +986,7 @@ static int mmc_sdio_resume(struct mmc_host *host)
981 986
982 /* Restore power if needed */ 987 /* Restore power if needed */
983 if (!mmc_card_keep_power(host)) { 988 if (!mmc_card_keep_power(host)) {
984 mmc_power_up(host); 989 mmc_power_up(host, host->card->ocr);
985 mmc_select_voltage(host, host->ocr);
986 /* 990 /*
987 * Tell runtime PM core we just powered up the card, 991 * Tell runtime PM core we just powered up the card,
988 * since it still believes the card is powered off. 992 * since it still believes the card is powered off.
@@ -1000,7 +1004,7 @@ static int mmc_sdio_resume(struct mmc_host *host)
1000 if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) { 1004 if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) {
1001 sdio_reset(host); 1005 sdio_reset(host);
1002 mmc_go_idle(host); 1006 mmc_go_idle(host);
1003 err = mmc_sdio_init_card(host, host->ocr, host->card, 1007 err = mmc_sdio_init_card(host, host->card->ocr, host->card,
1004 mmc_card_keep_power(host)); 1008 mmc_card_keep_power(host));
1005 } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) { 1009 } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
1006 /* We may have switched to 1-bit mode during suspend */ 1010 /* We may have switched to 1-bit mode during suspend */
@@ -1040,7 +1044,6 @@ static int mmc_sdio_resume(struct mmc_host *host)
1040static int mmc_sdio_power_restore(struct mmc_host *host) 1044static int mmc_sdio_power_restore(struct mmc_host *host)
1041{ 1045{
1042 int ret; 1046 int ret;
1043 u32 ocr;
1044 1047
1045 BUG_ON(!host); 1048 BUG_ON(!host);
1046 BUG_ON(!host->card); 1049 BUG_ON(!host->card);
@@ -1062,32 +1065,17 @@ static int mmc_sdio_power_restore(struct mmc_host *host)
1062 * for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and 1065 * for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and
1063 * harmless in other situations. 1066 * harmless in other situations.
1064 * 1067 *
1065 * With these steps taken, mmc_select_voltage() is also required to
1066 * restore the correct voltage setting of the card.
1067 */ 1068 */
1068 1069
1069 sdio_reset(host); 1070 sdio_reset(host);
1070 mmc_go_idle(host); 1071 mmc_go_idle(host);
1071 mmc_send_if_cond(host, host->ocr_avail); 1072 mmc_send_if_cond(host, host->ocr_avail);
1072 1073
1073 ret = mmc_send_io_op_cond(host, 0, &ocr); 1074 ret = mmc_send_io_op_cond(host, 0, NULL);
1074 if (ret) 1075 if (ret)
1075 goto out; 1076 goto out;
1076 1077
1077 if (host->ocr_avail_sdio) 1078 ret = mmc_sdio_init_card(host, host->card->ocr, host->card,
1078 host->ocr_avail = host->ocr_avail_sdio;
1079
1080 host->ocr = mmc_select_voltage(host, ocr & ~0x7F);
1081 if (!host->ocr) {
1082 ret = -EINVAL;
1083 goto out;
1084 }
1085
1086 if (mmc_host_uhs(host))
1087 /* to query card if 1.8V signalling is supported */
1088 host->ocr |= R4_18V_PRESENT;
1089
1090 ret = mmc_sdio_init_card(host, host->ocr, host->card,
1091 mmc_card_keep_power(host)); 1079 mmc_card_keep_power(host));
1092 if (!ret && host->sdio_irqs) 1080 if (!ret && host->sdio_irqs)
1093 mmc_signal_sdio_irq(host); 1081 mmc_signal_sdio_irq(host);
@@ -1108,7 +1096,7 @@ static int mmc_sdio_runtime_suspend(struct mmc_host *host)
1108static int mmc_sdio_runtime_resume(struct mmc_host *host) 1096static int mmc_sdio_runtime_resume(struct mmc_host *host)
1109{ 1097{
1110 /* Restore power and re-initialize. */ 1098 /* Restore power and re-initialize. */
1111 mmc_power_up(host); 1099 mmc_power_up(host, host->card->ocr);
1112 return mmc_sdio_power_restore(host); 1100 return mmc_sdio_power_restore(host);
1113} 1101}
1114 1102
@@ -1131,7 +1119,7 @@ static const struct mmc_bus_ops mmc_sdio_ops = {
1131int mmc_attach_sdio(struct mmc_host *host) 1119int mmc_attach_sdio(struct mmc_host *host)
1132{ 1120{
1133 int err, i, funcs; 1121 int err, i, funcs;
1134 u32 ocr; 1122 u32 ocr, rocr;
1135 struct mmc_card *card; 1123 struct mmc_card *card;
1136 1124
1137 BUG_ON(!host); 1125 BUG_ON(!host);
@@ -1145,23 +1133,13 @@ int mmc_attach_sdio(struct mmc_host *host)
1145 if (host->ocr_avail_sdio) 1133 if (host->ocr_avail_sdio)
1146 host->ocr_avail = host->ocr_avail_sdio; 1134 host->ocr_avail = host->ocr_avail_sdio;
1147 1135
1148 /*
1149 * Sanity check the voltages that the card claims to
1150 * support.
1151 */
1152 if (ocr & 0x7F) {
1153 pr_warning("%s: card claims to support voltages "
1154 "below the defined range. These will be ignored.\n",
1155 mmc_hostname(host));
1156 ocr &= ~0x7F;
1157 }
1158 1136
1159 host->ocr = mmc_select_voltage(host, ocr); 1137 rocr = mmc_select_voltage(host, ocr);
1160 1138
1161 /* 1139 /*
1162 * Can we support the voltage(s) of the card(s)? 1140 * Can we support the voltage(s) of the card(s)?
1163 */ 1141 */
1164 if (!host->ocr) { 1142 if (!rocr) {
1165 err = -EINVAL; 1143 err = -EINVAL;
1166 goto err; 1144 goto err;
1167 } 1145 }
@@ -1169,22 +1147,10 @@ int mmc_attach_sdio(struct mmc_host *host)
1169 /* 1147 /*
1170 * Detect and init the card. 1148 * Detect and init the card.
1171 */ 1149 */
1172 if (mmc_host_uhs(host)) 1150 err = mmc_sdio_init_card(host, rocr, NULL, 0);
1173 /* to query card if 1.8V signalling is supported */ 1151 if (err)
1174 host->ocr |= R4_18V_PRESENT; 1152 goto err;
1175 1153
1176 err = mmc_sdio_init_card(host, host->ocr, NULL, 0);
1177 if (err) {
1178 if (err == -EAGAIN) {
1179 /*
1180 * Retry initialization with S18R set to 0.
1181 */
1182 host->ocr &= ~R4_18V_PRESENT;
1183 err = mmc_sdio_init_card(host, host->ocr, NULL, 0);
1184 }
1185 if (err)
1186 goto err;
1187 }
1188 card = host->card; 1154 card = host->card;
1189 1155
1190 /* 1156 /*
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index 69e438ee043e..2cbb4516d353 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -255,7 +255,6 @@ struct atmel_mci_slot {
255#define ATMCI_CARD_PRESENT 0 255#define ATMCI_CARD_PRESENT 0
256#define ATMCI_CARD_NEED_INIT 1 256#define ATMCI_CARD_NEED_INIT 1
257#define ATMCI_SHUTDOWN 2 257#define ATMCI_SHUTDOWN 2
258#define ATMCI_SUSPENDED 3
259 258
260 int detect_pin; 259 int detect_pin;
261 int wp_pin; 260 int wp_pin;
@@ -589,6 +588,13 @@ static void atmci_timeout_timer(unsigned long data)
589 if (host->mrq->cmd->data) { 588 if (host->mrq->cmd->data) {
590 host->mrq->cmd->data->error = -ETIMEDOUT; 589 host->mrq->cmd->data->error = -ETIMEDOUT;
591 host->data = NULL; 590 host->data = NULL;
591 /*
592 * With some SDIO modules, sometimes DMA transfer hangs. If
593 * stop_transfer() is not called then the DMA request is not
594 * removed, following ones are queued and never computed.
595 */
596 if (host->state == STATE_DATA_XFER)
597 host->stop_transfer(host);
592 } else { 598 } else {
593 host->mrq->cmd->error = -ETIMEDOUT; 599 host->mrq->cmd->error = -ETIMEDOUT;
594 host->cmd = NULL; 600 host->cmd = NULL;
@@ -1803,12 +1809,14 @@ static void atmci_tasklet_func(unsigned long priv)
1803 if (unlikely(status)) { 1809 if (unlikely(status)) {
1804 host->stop_transfer(host); 1810 host->stop_transfer(host);
1805 host->data = NULL; 1811 host->data = NULL;
1806 if (status & ATMCI_DTOE) { 1812 if (data) {
1807 data->error = -ETIMEDOUT; 1813 if (status & ATMCI_DTOE) {
1808 } else if (status & ATMCI_DCRCE) { 1814 data->error = -ETIMEDOUT;
1809 data->error = -EILSEQ; 1815 } else if (status & ATMCI_DCRCE) {
1810 } else { 1816 data->error = -EILSEQ;
1811 data->error = -EIO; 1817 } else {
1818 data->error = -EIO;
1819 }
1812 } 1820 }
1813 } 1821 }
1814 1822
@@ -2520,70 +2528,10 @@ static int __exit atmci_remove(struct platform_device *pdev)
2520 return 0; 2528 return 0;
2521} 2529}
2522 2530
2523#ifdef CONFIG_PM_SLEEP
2524static int atmci_suspend(struct device *dev)
2525{
2526 struct atmel_mci *host = dev_get_drvdata(dev);
2527 int i;
2528
2529 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
2530 struct atmel_mci_slot *slot = host->slot[i];
2531 int ret;
2532
2533 if (!slot)
2534 continue;
2535 ret = mmc_suspend_host(slot->mmc);
2536 if (ret < 0) {
2537 while (--i >= 0) {
2538 slot = host->slot[i];
2539 if (slot
2540 && test_bit(ATMCI_SUSPENDED, &slot->flags)) {
2541 mmc_resume_host(host->slot[i]->mmc);
2542 clear_bit(ATMCI_SUSPENDED, &slot->flags);
2543 }
2544 }
2545 return ret;
2546 } else {
2547 set_bit(ATMCI_SUSPENDED, &slot->flags);
2548 }
2549 }
2550
2551 return 0;
2552}
2553
2554static int atmci_resume(struct device *dev)
2555{
2556 struct atmel_mci *host = dev_get_drvdata(dev);
2557 int i;
2558 int ret = 0;
2559
2560 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
2561 struct atmel_mci_slot *slot = host->slot[i];
2562 int err;
2563
2564 slot = host->slot[i];
2565 if (!slot)
2566 continue;
2567 if (!test_bit(ATMCI_SUSPENDED, &slot->flags))
2568 continue;
2569 err = mmc_resume_host(slot->mmc);
2570 if (err < 0)
2571 ret = err;
2572 else
2573 clear_bit(ATMCI_SUSPENDED, &slot->flags);
2574 }
2575
2576 return ret;
2577}
2578#endif
2579
2580static SIMPLE_DEV_PM_OPS(atmci_pm, atmci_suspend, atmci_resume);
2581
2582static struct platform_driver atmci_driver = { 2531static struct platform_driver atmci_driver = {
2583 .remove = __exit_p(atmci_remove), 2532 .remove = __exit_p(atmci_remove),
2584 .driver = { 2533 .driver = {
2585 .name = "atmel_mci", 2534 .name = "atmel_mci",
2586 .pm = &atmci_pm,
2587 .of_match_table = of_match_ptr(atmci_dt_ids), 2535 .of_match_table = of_match_ptr(atmci_dt_ids),
2588 }, 2536 },
2589}; 2537};
diff --git a/drivers/mmc/host/au1xmmc.c b/drivers/mmc/host/au1xmmc.c
index df9becdd2e99..f5443a6c4915 100644
--- a/drivers/mmc/host/au1xmmc.c
+++ b/drivers/mmc/host/au1xmmc.c
@@ -1157,11 +1157,6 @@ static int au1xmmc_remove(struct platform_device *pdev)
1157static int au1xmmc_suspend(struct platform_device *pdev, pm_message_t state) 1157static int au1xmmc_suspend(struct platform_device *pdev, pm_message_t state)
1158{ 1158{
1159 struct au1xmmc_host *host = platform_get_drvdata(pdev); 1159 struct au1xmmc_host *host = platform_get_drvdata(pdev);
1160 int ret;
1161
1162 ret = mmc_suspend_host(host->mmc);
1163 if (ret)
1164 return ret;
1165 1160
1166 au_writel(0, HOST_CONFIG2(host)); 1161 au_writel(0, HOST_CONFIG2(host));
1167 au_writel(0, HOST_CONFIG(host)); 1162 au_writel(0, HOST_CONFIG(host));
@@ -1178,7 +1173,7 @@ static int au1xmmc_resume(struct platform_device *pdev)
1178 1173
1179 au1xmmc_reset_controller(host); 1174 au1xmmc_reset_controller(host);
1180 1175
1181 return mmc_resume_host(host->mmc); 1176 return 0;
1182} 1177}
1183#else 1178#else
1184#define au1xmmc_suspend NULL 1179#define au1xmmc_suspend NULL
diff --git a/drivers/mmc/host/bfin_sdh.c b/drivers/mmc/host/bfin_sdh.c
index 94fae2f1baaf..2b7f37e82ca9 100644
--- a/drivers/mmc/host/bfin_sdh.c
+++ b/drivers/mmc/host/bfin_sdh.c
@@ -391,6 +391,7 @@ static void sdh_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
391 /* Disable 4 bit SDIO */ 391 /* Disable 4 bit SDIO */
392 cfg &= ~SD4E; 392 cfg &= ~SD4E;
393 } 393 }
394 bfin_write_SDH_CFG(cfg);
394 395
395 host->power_mode = ios->power_mode; 396 host->power_mode = ios->power_mode;
396#ifndef RSI_BLKSZ 397#ifndef RSI_BLKSZ
@@ -415,7 +416,6 @@ static void sdh_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
415 cfg &= ~SD_CMD_OD; 416 cfg &= ~SD_CMD_OD;
416# endif 417# endif
417 418
418
419 if (ios->power_mode != MMC_POWER_OFF) 419 if (ios->power_mode != MMC_POWER_OFF)
420 cfg |= PWR_ON; 420 cfg |= PWR_ON;
421 else 421 else
@@ -433,7 +433,6 @@ static void sdh_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
433 clk_ctl |= CLK_E; 433 clk_ctl |= CLK_E;
434 host->clk_div = clk_div; 434 host->clk_div = clk_div;
435 bfin_write_SDH_CLK_CTL(clk_ctl); 435 bfin_write_SDH_CLK_CTL(clk_ctl);
436
437 } else 436 } else
438 sdh_stop_clock(host); 437 sdh_stop_clock(host);
439 438
@@ -640,21 +639,15 @@ static int sdh_remove(struct platform_device *pdev)
640#ifdef CONFIG_PM 639#ifdef CONFIG_PM
641static int sdh_suspend(struct platform_device *dev, pm_message_t state) 640static int sdh_suspend(struct platform_device *dev, pm_message_t state)
642{ 641{
643 struct mmc_host *mmc = platform_get_drvdata(dev);
644 struct bfin_sd_host *drv_data = get_sdh_data(dev); 642 struct bfin_sd_host *drv_data = get_sdh_data(dev);
645 int ret = 0;
646
647 if (mmc)
648 ret = mmc_suspend_host(mmc);
649 643
650 peripheral_free_list(drv_data->pin_req); 644 peripheral_free_list(drv_data->pin_req);
651 645
652 return ret; 646 return 0;
653} 647}
654 648
655static int sdh_resume(struct platform_device *dev) 649static int sdh_resume(struct platform_device *dev)
656{ 650{
657 struct mmc_host *mmc = platform_get_drvdata(dev);
658 struct bfin_sd_host *drv_data = get_sdh_data(dev); 651 struct bfin_sd_host *drv_data = get_sdh_data(dev);
659 int ret = 0; 652 int ret = 0;
660 653
@@ -665,10 +658,6 @@ static int sdh_resume(struct platform_device *dev)
665 } 658 }
666 659
667 sdh_reset(); 660 sdh_reset();
668
669 if (mmc)
670 ret = mmc_resume_host(mmc);
671
672 return ret; 661 return ret;
673} 662}
674#else 663#else
diff --git a/drivers/mmc/host/cb710-mmc.c b/drivers/mmc/host/cb710-mmc.c
index 9d6e2b844404..1087b4c79cd6 100644
--- a/drivers/mmc/host/cb710-mmc.c
+++ b/drivers/mmc/host/cb710-mmc.c
@@ -667,12 +667,6 @@ static const struct mmc_host_ops cb710_mmc_host = {
667static int cb710_mmc_suspend(struct platform_device *pdev, pm_message_t state) 667static int cb710_mmc_suspend(struct platform_device *pdev, pm_message_t state)
668{ 668{
669 struct cb710_slot *slot = cb710_pdev_to_slot(pdev); 669 struct cb710_slot *slot = cb710_pdev_to_slot(pdev);
670 struct mmc_host *mmc = cb710_slot_to_mmc(slot);
671 int err;
672
673 err = mmc_suspend_host(mmc);
674 if (err)
675 return err;
676 670
677 cb710_mmc_enable_irq(slot, 0, ~0); 671 cb710_mmc_enable_irq(slot, 0, ~0);
678 return 0; 672 return 0;
@@ -681,11 +675,9 @@ static int cb710_mmc_suspend(struct platform_device *pdev, pm_message_t state)
681static int cb710_mmc_resume(struct platform_device *pdev) 675static int cb710_mmc_resume(struct platform_device *pdev)
682{ 676{
683 struct cb710_slot *slot = cb710_pdev_to_slot(pdev); 677 struct cb710_slot *slot = cb710_pdev_to_slot(pdev);
684 struct mmc_host *mmc = cb710_slot_to_mmc(slot);
685 678
686 cb710_mmc_enable_irq(slot, 0, ~0); 679 cb710_mmc_enable_irq(slot, 0, ~0);
687 680 return 0;
688 return mmc_resume_host(mmc);
689} 681}
690 682
691#endif /* CONFIG_PM */ 683#endif /* CONFIG_PM */
diff --git a/drivers/mmc/host/davinci_mmc.c b/drivers/mmc/host/davinci_mmc.c
index e9fa87df909c..d6153740b77f 100644
--- a/drivers/mmc/host/davinci_mmc.c
+++ b/drivers/mmc/host/davinci_mmc.c
@@ -193,7 +193,6 @@ struct mmc_davinci_host {
193#define DAVINCI_MMC_DATADIR_READ 1 193#define DAVINCI_MMC_DATADIR_READ 1
194#define DAVINCI_MMC_DATADIR_WRITE 2 194#define DAVINCI_MMC_DATADIR_WRITE 2
195 unsigned char data_dir; 195 unsigned char data_dir;
196 unsigned char suspended;
197 196
198 /* buffer is used during PIO of one scatterlist segment, and 197 /* buffer is used during PIO of one scatterlist segment, and
199 * is updated along with buffer_bytes_left. bytes_left applies 198 * is updated along with buffer_bytes_left. bytes_left applies
@@ -1435,38 +1434,23 @@ static int davinci_mmcsd_suspend(struct device *dev)
1435{ 1434{
1436 struct platform_device *pdev = to_platform_device(dev); 1435 struct platform_device *pdev = to_platform_device(dev);
1437 struct mmc_davinci_host *host = platform_get_drvdata(pdev); 1436 struct mmc_davinci_host *host = platform_get_drvdata(pdev);
1438 int ret;
1439 1437
1440 ret = mmc_suspend_host(host->mmc); 1438 writel(0, host->base + DAVINCI_MMCIM);
1441 if (!ret) { 1439 mmc_davinci_reset_ctrl(host, 1);
1442 writel(0, host->base + DAVINCI_MMCIM); 1440 clk_disable(host->clk);
1443 mmc_davinci_reset_ctrl(host, 1);
1444 clk_disable(host->clk);
1445 host->suspended = 1;
1446 } else {
1447 host->suspended = 0;
1448 }
1449 1441
1450 return ret; 1442 return 0;
1451} 1443}
1452 1444
1453static int davinci_mmcsd_resume(struct device *dev) 1445static int davinci_mmcsd_resume(struct device *dev)
1454{ 1446{
1455 struct platform_device *pdev = to_platform_device(dev); 1447 struct platform_device *pdev = to_platform_device(dev);
1456 struct mmc_davinci_host *host = platform_get_drvdata(pdev); 1448 struct mmc_davinci_host *host = platform_get_drvdata(pdev);
1457 int ret;
1458
1459 if (!host->suspended)
1460 return 0;
1461 1449
1462 clk_enable(host->clk); 1450 clk_enable(host->clk);
1463
1464 mmc_davinci_reset_ctrl(host, 0); 1451 mmc_davinci_reset_ctrl(host, 0);
1465 ret = mmc_resume_host(host->mmc);
1466 if (!ret)
1467 host->suspended = 0;
1468 1452
1469 return ret; 1453 return 0;
1470} 1454}
1471 1455
1472static const struct dev_pm_ops davinci_mmcsd_pm = { 1456static const struct dev_pm_ops davinci_mmcsd_pm = {
diff --git a/drivers/mmc/host/dw_mmc-exynos.c b/drivers/mmc/host/dw_mmc-exynos.c
index 6a1fa2110a05..3423c5ed50c7 100644
--- a/drivers/mmc/host/dw_mmc-exynos.c
+++ b/drivers/mmc/host/dw_mmc-exynos.c
@@ -14,8 +14,10 @@
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/mmc/host.h> 15#include <linux/mmc/host.h>
16#include <linux/mmc/dw_mmc.h> 16#include <linux/mmc/dw_mmc.h>
17#include <linux/mmc/mmc.h>
17#include <linux/of.h> 18#include <linux/of.h>
18#include <linux/of_gpio.h> 19#include <linux/of_gpio.h>
20#include <linux/slab.h>
19 21
20#include "dw_mmc.h" 22#include "dw_mmc.h"
21#include "dw_mmc-pltfm.h" 23#include "dw_mmc-pltfm.h"
@@ -30,16 +32,39 @@
30#define SDMMC_CLKSEL_TIMING(x, y, z) (SDMMC_CLKSEL_CCLK_SAMPLE(x) | \ 32#define SDMMC_CLKSEL_TIMING(x, y, z) (SDMMC_CLKSEL_CCLK_SAMPLE(x) | \
31 SDMMC_CLKSEL_CCLK_DRIVE(y) | \ 33 SDMMC_CLKSEL_CCLK_DRIVE(y) | \
32 SDMMC_CLKSEL_CCLK_DIVIDER(z)) 34 SDMMC_CLKSEL_CCLK_DIVIDER(z))
35#define SDMMC_CLKSEL_WAKEUP_INT BIT(11)
33 36
34#define EXYNOS4210_FIXED_CIU_CLK_DIV 2 37#define EXYNOS4210_FIXED_CIU_CLK_DIV 2
35#define EXYNOS4412_FIXED_CIU_CLK_DIV 4 38#define EXYNOS4412_FIXED_CIU_CLK_DIV 4
36 39
40/* Block number in eMMC */
41#define DWMCI_BLOCK_NUM 0xFFFFFFFF
42
43#define SDMMC_EMMCP_BASE 0x1000
44#define SDMMC_MPSECURITY (SDMMC_EMMCP_BASE + 0x0010)
45#define SDMMC_MPSBEGIN0 (SDMMC_EMMCP_BASE + 0x0200)
46#define SDMMC_MPSEND0 (SDMMC_EMMCP_BASE + 0x0204)
47#define SDMMC_MPSCTRL0 (SDMMC_EMMCP_BASE + 0x020C)
48
49/* SMU control bits */
50#define DWMCI_MPSCTRL_SECURE_READ_BIT BIT(7)
51#define DWMCI_MPSCTRL_SECURE_WRITE_BIT BIT(6)
52#define DWMCI_MPSCTRL_NON_SECURE_READ_BIT BIT(5)
53#define DWMCI_MPSCTRL_NON_SECURE_WRITE_BIT BIT(4)
54#define DWMCI_MPSCTRL_USE_FUSE_KEY BIT(3)
55#define DWMCI_MPSCTRL_ECB_MODE BIT(2)
56#define DWMCI_MPSCTRL_ENCRYPTION BIT(1)
57#define DWMCI_MPSCTRL_VALID BIT(0)
58
59#define EXYNOS_CCLKIN_MIN 50000000 /* unit: HZ */
60
37/* Variations in Exynos specific dw-mshc controller */ 61/* Variations in Exynos specific dw-mshc controller */
38enum dw_mci_exynos_type { 62enum dw_mci_exynos_type {
39 DW_MCI_TYPE_EXYNOS4210, 63 DW_MCI_TYPE_EXYNOS4210,
40 DW_MCI_TYPE_EXYNOS4412, 64 DW_MCI_TYPE_EXYNOS4412,
41 DW_MCI_TYPE_EXYNOS5250, 65 DW_MCI_TYPE_EXYNOS5250,
42 DW_MCI_TYPE_EXYNOS5420, 66 DW_MCI_TYPE_EXYNOS5420,
67 DW_MCI_TYPE_EXYNOS5420_SMU,
43}; 68};
44 69
45/* Exynos implementation specific driver private data */ 70/* Exynos implementation specific driver private data */
@@ -48,6 +73,7 @@ struct dw_mci_exynos_priv_data {
48 u8 ciu_div; 73 u8 ciu_div;
49 u32 sdr_timing; 74 u32 sdr_timing;
50 u32 ddr_timing; 75 u32 ddr_timing;
76 u32 cur_speed;
51}; 77};
52 78
53static struct dw_mci_exynos_compatible { 79static struct dw_mci_exynos_compatible {
@@ -66,44 +92,80 @@ static struct dw_mci_exynos_compatible {
66 }, { 92 }, {
67 .compatible = "samsung,exynos5420-dw-mshc", 93 .compatible = "samsung,exynos5420-dw-mshc",
68 .ctrl_type = DW_MCI_TYPE_EXYNOS5420, 94 .ctrl_type = DW_MCI_TYPE_EXYNOS5420,
95 }, {
96 .compatible = "samsung,exynos5420-dw-mshc-smu",
97 .ctrl_type = DW_MCI_TYPE_EXYNOS5420_SMU,
69 }, 98 },
70}; 99};
71 100
72static int dw_mci_exynos_priv_init(struct dw_mci *host) 101static int dw_mci_exynos_priv_init(struct dw_mci *host)
73{ 102{
74 struct dw_mci_exynos_priv_data *priv; 103 struct dw_mci_exynos_priv_data *priv = host->priv;
75 int idx;
76
77 priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
78 if (!priv) {
79 dev_err(host->dev, "mem alloc failed for private data\n");
80 return -ENOMEM;
81 }
82 104
83 for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) { 105 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420_SMU) {
84 if (of_device_is_compatible(host->dev->of_node, 106 mci_writel(host, MPSBEGIN0, 0);
85 exynos_compat[idx].compatible)) 107 mci_writel(host, MPSEND0, DWMCI_BLOCK_NUM);
86 priv->ctrl_type = exynos_compat[idx].ctrl_type; 108 mci_writel(host, MPSCTRL0, DWMCI_MPSCTRL_SECURE_WRITE_BIT |
109 DWMCI_MPSCTRL_NON_SECURE_READ_BIT |
110 DWMCI_MPSCTRL_VALID |
111 DWMCI_MPSCTRL_NON_SECURE_WRITE_BIT);
87 } 112 }
88 113
89 host->priv = priv;
90 return 0; 114 return 0;
91} 115}
92 116
93static int dw_mci_exynos_setup_clock(struct dw_mci *host) 117static int dw_mci_exynos_setup_clock(struct dw_mci *host)
94{ 118{
95 struct dw_mci_exynos_priv_data *priv = host->priv; 119 struct dw_mci_exynos_priv_data *priv = host->priv;
120 unsigned long rate = clk_get_rate(host->ciu_clk);
96 121
97 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5250 || 122 host->bus_hz = rate / (priv->ciu_div + 1);
98 priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420) 123 return 0;
99 host->bus_hz /= (priv->ciu_div + 1); 124}
100 else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412) 125
101 host->bus_hz /= EXYNOS4412_FIXED_CIU_CLK_DIV; 126#ifdef CONFIG_PM_SLEEP
102 else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210) 127static int dw_mci_exynos_suspend(struct device *dev)
103 host->bus_hz /= EXYNOS4210_FIXED_CIU_CLK_DIV; 128{
129 struct dw_mci *host = dev_get_drvdata(dev);
130
131 return dw_mci_suspend(host);
132}
133
134static int dw_mci_exynos_resume(struct device *dev)
135{
136 struct dw_mci *host = dev_get_drvdata(dev);
137
138 dw_mci_exynos_priv_init(host);
139 return dw_mci_resume(host);
140}
141
142/**
143 * dw_mci_exynos_resume_noirq - Exynos-specific resume code
144 *
145 * On exynos5420 there is a silicon errata that will sometimes leave the
146 * WAKEUP_INT bit in the CLKSEL register asserted. This bit is 1 to indicate
147 * that it fired and we can clear it by writing a 1 back. Clear it to prevent
148 * interrupts from going off constantly.
149 *
150 * We run this code on all exynos variants because it doesn't hurt.
151 */
152
153static int dw_mci_exynos_resume_noirq(struct device *dev)
154{
155 struct dw_mci *host = dev_get_drvdata(dev);
156 u32 clksel;
157
158 clksel = mci_readl(host, CLKSEL);
159 if (clksel & SDMMC_CLKSEL_WAKEUP_INT)
160 mci_writel(host, CLKSEL, clksel);
104 161
105 return 0; 162 return 0;
106} 163}
164#else
165#define dw_mci_exynos_suspend NULL
166#define dw_mci_exynos_resume NULL
167#define dw_mci_exynos_resume_noirq NULL
168#endif /* CONFIG_PM_SLEEP */
107 169
108static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr) 170static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr)
109{ 171{
@@ -121,23 +183,68 @@ static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr)
121static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios) 183static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios)
122{ 184{
123 struct dw_mci_exynos_priv_data *priv = host->priv; 185 struct dw_mci_exynos_priv_data *priv = host->priv;
186 unsigned int wanted = ios->clock;
187 unsigned long actual;
188 u8 div = priv->ciu_div + 1;
124 189
125 if (ios->timing == MMC_TIMING_UHS_DDR50) 190 if (ios->timing == MMC_TIMING_UHS_DDR50) {
126 mci_writel(host, CLKSEL, priv->ddr_timing); 191 mci_writel(host, CLKSEL, priv->ddr_timing);
127 else 192 /* Should be double rate for DDR mode */
193 if (ios->bus_width == MMC_BUS_WIDTH_8)
194 wanted <<= 1;
195 } else {
128 mci_writel(host, CLKSEL, priv->sdr_timing); 196 mci_writel(host, CLKSEL, priv->sdr_timing);
197 }
198
199 /* Don't care if wanted clock is zero */
200 if (!wanted)
201 return;
202
203 /* Guaranteed minimum frequency for cclkin */
204 if (wanted < EXYNOS_CCLKIN_MIN)
205 wanted = EXYNOS_CCLKIN_MIN;
206
207 if (wanted != priv->cur_speed) {
208 int ret = clk_set_rate(host->ciu_clk, wanted * div);
209 if (ret)
210 dev_warn(host->dev,
211 "failed to set clk-rate %u error: %d\n",
212 wanted * div, ret);
213 actual = clk_get_rate(host->ciu_clk);
214 host->bus_hz = actual / div;
215 priv->cur_speed = wanted;
216 host->current_speed = 0;
217 }
129} 218}
130 219
131static int dw_mci_exynos_parse_dt(struct dw_mci *host) 220static int dw_mci_exynos_parse_dt(struct dw_mci *host)
132{ 221{
133 struct dw_mci_exynos_priv_data *priv = host->priv; 222 struct dw_mci_exynos_priv_data *priv;
134 struct device_node *np = host->dev->of_node; 223 struct device_node *np = host->dev->of_node;
135 u32 timing[2]; 224 u32 timing[2];
136 u32 div = 0; 225 u32 div = 0;
226 int idx;
137 int ret; 227 int ret;
138 228
139 of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div); 229 priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
140 priv->ciu_div = div; 230 if (!priv) {
231 dev_err(host->dev, "mem alloc failed for private data\n");
232 return -ENOMEM;
233 }
234
235 for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) {
236 if (of_device_is_compatible(np, exynos_compat[idx].compatible))
237 priv->ctrl_type = exynos_compat[idx].ctrl_type;
238 }
239
240 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412)
241 priv->ciu_div = EXYNOS4412_FIXED_CIU_CLK_DIV - 1;
242 else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210)
243 priv->ciu_div = EXYNOS4210_FIXED_CIU_CLK_DIV - 1;
244 else {
245 of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div);
246 priv->ciu_div = div;
247 }
141 248
142 ret = of_property_read_u32_array(np, 249 ret = of_property_read_u32_array(np,
143 "samsung,dw-mshc-sdr-timing", timing, 2); 250 "samsung,dw-mshc-sdr-timing", timing, 2);
@@ -152,9 +259,131 @@ static int dw_mci_exynos_parse_dt(struct dw_mci *host)
152 return ret; 259 return ret;
153 260
154 priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); 261 priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div);
262 host->priv = priv;
155 return 0; 263 return 0;
156} 264}
157 265
266static inline u8 dw_mci_exynos_get_clksmpl(struct dw_mci *host)
267{
268 return SDMMC_CLKSEL_CCLK_SAMPLE(mci_readl(host, CLKSEL));
269}
270
271static inline void dw_mci_exynos_set_clksmpl(struct dw_mci *host, u8 sample)
272{
273 u32 clksel;
274 clksel = mci_readl(host, CLKSEL);
275 clksel = (clksel & ~0x7) | SDMMC_CLKSEL_CCLK_SAMPLE(sample);
276 mci_writel(host, CLKSEL, clksel);
277}
278
279static inline u8 dw_mci_exynos_move_next_clksmpl(struct dw_mci *host)
280{
281 u32 clksel;
282 u8 sample;
283
284 clksel = mci_readl(host, CLKSEL);
285 sample = (clksel + 1) & 0x7;
286 clksel = (clksel & ~0x7) | sample;
287 mci_writel(host, CLKSEL, clksel);
288 return sample;
289}
290
291static s8 dw_mci_exynos_get_best_clksmpl(u8 candiates)
292{
293 const u8 iter = 8;
294 u8 __c;
295 s8 i, loc = -1;
296
297 for (i = 0; i < iter; i++) {
298 __c = ror8(candiates, i);
299 if ((__c & 0xc7) == 0xc7) {
300 loc = i;
301 goto out;
302 }
303 }
304
305 for (i = 0; i < iter; i++) {
306 __c = ror8(candiates, i);
307 if ((__c & 0x83) == 0x83) {
308 loc = i;
309 goto out;
310 }
311 }
312
313out:
314 return loc;
315}
316
317static int dw_mci_exynos_execute_tuning(struct dw_mci_slot *slot, u32 opcode,
318 struct dw_mci_tuning_data *tuning_data)
319{
320 struct dw_mci *host = slot->host;
321 struct mmc_host *mmc = slot->mmc;
322 const u8 *blk_pattern = tuning_data->blk_pattern;
323 u8 *blk_test;
324 unsigned int blksz = tuning_data->blksz;
325 u8 start_smpl, smpl, candiates = 0;
326 s8 found = -1;
327 int ret = 0;
328
329 blk_test = kmalloc(blksz, GFP_KERNEL);
330 if (!blk_test)
331 return -ENOMEM;
332
333 start_smpl = dw_mci_exynos_get_clksmpl(host);
334
335 do {
336 struct mmc_request mrq = {NULL};
337 struct mmc_command cmd = {0};
338 struct mmc_command stop = {0};
339 struct mmc_data data = {0};
340 struct scatterlist sg;
341
342 cmd.opcode = opcode;
343 cmd.arg = 0;
344 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
345
346 stop.opcode = MMC_STOP_TRANSMISSION;
347 stop.arg = 0;
348 stop.flags = MMC_RSP_R1B | MMC_CMD_AC;
349
350 data.blksz = blksz;
351 data.blocks = 1;
352 data.flags = MMC_DATA_READ;
353 data.sg = &sg;
354 data.sg_len = 1;
355
356 sg_init_one(&sg, blk_test, blksz);
357 mrq.cmd = &cmd;
358 mrq.stop = &stop;
359 mrq.data = &data;
360 host->mrq = &mrq;
361
362 mci_writel(host, TMOUT, ~0);
363 smpl = dw_mci_exynos_move_next_clksmpl(host);
364
365 mmc_wait_for_req(mmc, &mrq);
366
367 if (!cmd.error && !data.error) {
368 if (!memcmp(blk_pattern, blk_test, blksz))
369 candiates |= (1 << smpl);
370 } else {
371 dev_dbg(host->dev,
372 "Tuning error: cmd.error:%d, data.error:%d\n",
373 cmd.error, data.error);
374 }
375 } while (start_smpl != smpl);
376
377 found = dw_mci_exynos_get_best_clksmpl(candiates);
378 if (found >= 0)
379 dw_mci_exynos_set_clksmpl(host, found);
380 else
381 ret = -EIO;
382
383 kfree(blk_test);
384 return ret;
385}
386
158/* Common capabilities of Exynos4/Exynos5 SoC */ 387/* Common capabilities of Exynos4/Exynos5 SoC */
159static unsigned long exynos_dwmmc_caps[4] = { 388static unsigned long exynos_dwmmc_caps[4] = {
160 MMC_CAP_UHS_DDR50 | MMC_CAP_1_8V_DDR | 389 MMC_CAP_UHS_DDR50 | MMC_CAP_1_8V_DDR |
@@ -171,6 +400,7 @@ static const struct dw_mci_drv_data exynos_drv_data = {
171 .prepare_command = dw_mci_exynos_prepare_command, 400 .prepare_command = dw_mci_exynos_prepare_command,
172 .set_ios = dw_mci_exynos_set_ios, 401 .set_ios = dw_mci_exynos_set_ios,
173 .parse_dt = dw_mci_exynos_parse_dt, 402 .parse_dt = dw_mci_exynos_parse_dt,
403 .execute_tuning = dw_mci_exynos_execute_tuning,
174}; 404};
175 405
176static const struct of_device_id dw_mci_exynos_match[] = { 406static const struct of_device_id dw_mci_exynos_match[] = {
@@ -180,6 +410,8 @@ static const struct of_device_id dw_mci_exynos_match[] = {
180 .data = &exynos_drv_data, }, 410 .data = &exynos_drv_data, },
181 { .compatible = "samsung,exynos5420-dw-mshc", 411 { .compatible = "samsung,exynos5420-dw-mshc",
182 .data = &exynos_drv_data, }, 412 .data = &exynos_drv_data, },
413 { .compatible = "samsung,exynos5420-dw-mshc-smu",
414 .data = &exynos_drv_data, },
183 {}, 415 {},
184}; 416};
185MODULE_DEVICE_TABLE(of, dw_mci_exynos_match); 417MODULE_DEVICE_TABLE(of, dw_mci_exynos_match);
@@ -194,13 +426,20 @@ static int dw_mci_exynos_probe(struct platform_device *pdev)
194 return dw_mci_pltfm_register(pdev, drv_data); 426 return dw_mci_pltfm_register(pdev, drv_data);
195} 427}
196 428
429const struct dev_pm_ops dw_mci_exynos_pmops = {
430 SET_SYSTEM_SLEEP_PM_OPS(dw_mci_exynos_suspend, dw_mci_exynos_resume)
431 .resume_noirq = dw_mci_exynos_resume_noirq,
432 .thaw_noirq = dw_mci_exynos_resume_noirq,
433 .restore_noirq = dw_mci_exynos_resume_noirq,
434};
435
197static struct platform_driver dw_mci_exynos_pltfm_driver = { 436static struct platform_driver dw_mci_exynos_pltfm_driver = {
198 .probe = dw_mci_exynos_probe, 437 .probe = dw_mci_exynos_probe,
199 .remove = __exit_p(dw_mci_pltfm_remove), 438 .remove = __exit_p(dw_mci_pltfm_remove),
200 .driver = { 439 .driver = {
201 .name = "dwmmc_exynos", 440 .name = "dwmmc_exynos",
202 .of_match_table = dw_mci_exynos_match, 441 .of_match_table = dw_mci_exynos_match,
203 .pm = &dw_mci_pltfm_pmops, 442 .pm = &dw_mci_exynos_pmops,
204 }, 443 },
205}; 444};
206 445
diff --git a/drivers/mmc/host/dw_mmc-pltfm.c b/drivers/mmc/host/dw_mmc-pltfm.c
index 20897529ea5e..5c4965655297 100644
--- a/drivers/mmc/host/dw_mmc-pltfm.c
+++ b/drivers/mmc/host/dw_mmc-pltfm.c
@@ -39,7 +39,6 @@ int dw_mci_pltfm_register(struct platform_device *pdev,
39{ 39{
40 struct dw_mci *host; 40 struct dw_mci *host;
41 struct resource *regs; 41 struct resource *regs;
42 int ret;
43 42
44 host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL); 43 host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL);
45 if (!host) 44 if (!host)
@@ -59,12 +58,6 @@ int dw_mci_pltfm_register(struct platform_device *pdev,
59 if (IS_ERR(host->regs)) 58 if (IS_ERR(host->regs))
60 return PTR_ERR(host->regs); 59 return PTR_ERR(host->regs);
61 60
62 if (drv_data && drv_data->init) {
63 ret = drv_data->init(host);
64 if (ret)
65 return ret;
66 }
67
68 platform_set_drvdata(pdev, host); 61 platform_set_drvdata(pdev, host);
69 return dw_mci_probe(host); 62 return dw_mci_probe(host);
70} 63}
diff --git a/drivers/mmc/host/dw_mmc-socfpga.c b/drivers/mmc/host/dw_mmc-socfpga.c
index 14b5961a851c..3e8e53ae3302 100644
--- a/drivers/mmc/host/dw_mmc-socfpga.c
+++ b/drivers/mmc/host/dw_mmc-socfpga.c
@@ -38,21 +38,6 @@ struct dw_mci_socfpga_priv_data {
38 38
39static int dw_mci_socfpga_priv_init(struct dw_mci *host) 39static int dw_mci_socfpga_priv_init(struct dw_mci *host)
40{ 40{
41 struct dw_mci_socfpga_priv_data *priv;
42
43 priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
44 if (!priv) {
45 dev_err(host->dev, "mem alloc failed for private data\n");
46 return -ENOMEM;
47 }
48
49 priv->sysreg = syscon_regmap_lookup_by_compatible("altr,sys-mgr");
50 if (IS_ERR(priv->sysreg)) {
51 dev_err(host->dev, "regmap for altr,sys-mgr lookup failed.\n");
52 return PTR_ERR(priv->sysreg);
53 }
54 host->priv = priv;
55
56 return 0; 41 return 0;
57} 42}
58 43
@@ -79,12 +64,24 @@ static void dw_mci_socfpga_prepare_command(struct dw_mci *host, u32 *cmdr)
79 64
80static int dw_mci_socfpga_parse_dt(struct dw_mci *host) 65static int dw_mci_socfpga_parse_dt(struct dw_mci *host)
81{ 66{
82 struct dw_mci_socfpga_priv_data *priv = host->priv; 67 struct dw_mci_socfpga_priv_data *priv;
83 struct device_node *np = host->dev->of_node; 68 struct device_node *np = host->dev->of_node;
84 u32 timing[2]; 69 u32 timing[2];
85 u32 div = 0; 70 u32 div = 0;
86 int ret; 71 int ret;
87 72
73 priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
74 if (!priv) {
75 dev_err(host->dev, "mem alloc failed for private data\n");
76 return -ENOMEM;
77 }
78
79 priv->sysreg = syscon_regmap_lookup_by_compatible("altr,sys-mgr");
80 if (IS_ERR(priv->sysreg)) {
81 dev_err(host->dev, "regmap for altr,sys-mgr lookup failed.\n");
82 return PTR_ERR(priv->sysreg);
83 }
84
88 ret = of_property_read_u32(np, "altr,dw-mshc-ciu-div", &div); 85 ret = of_property_read_u32(np, "altr,dw-mshc-ciu-div", &div);
89 if (ret) 86 if (ret)
90 dev_info(host->dev, "No dw-mshc-ciu-div specified, assuming 1"); 87 dev_info(host->dev, "No dw-mshc-ciu-div specified, assuming 1");
@@ -96,6 +93,7 @@ static int dw_mci_socfpga_parse_dt(struct dw_mci *host)
96 return ret; 93 return ret;
97 94
98 priv->hs_timing = SYSMGR_SDMMC_CTRL_SET(timing[0], timing[1]); 95 priv->hs_timing = SYSMGR_SDMMC_CTRL_SET(timing[0], timing[1]);
96 host->priv = priv;
99 return 0; 97 return 0;
100} 98}
101 99
@@ -113,7 +111,7 @@ static const struct of_device_id dw_mci_socfpga_match[] = {
113}; 111};
114MODULE_DEVICE_TABLE(of, dw_mci_socfpga_match); 112MODULE_DEVICE_TABLE(of, dw_mci_socfpga_match);
115 113
116int dw_mci_socfpga_probe(struct platform_device *pdev) 114static int dw_mci_socfpga_probe(struct platform_device *pdev)
117{ 115{
118 const struct dw_mci_drv_data *drv_data; 116 const struct dw_mci_drv_data *drv_data;
119 const struct of_device_id *match; 117 const struct of_device_id *match;
@@ -128,7 +126,7 @@ static struct platform_driver dw_mci_socfpga_pltfm_driver = {
128 .remove = __exit_p(dw_mci_pltfm_remove), 126 .remove = __exit_p(dw_mci_pltfm_remove),
129 .driver = { 127 .driver = {
130 .name = "dwmmc_socfpga", 128 .name = "dwmmc_socfpga",
131 .of_match_table = of_match_ptr(dw_mci_socfpga_match), 129 .of_match_table = dw_mci_socfpga_match,
132 .pm = &dw_mci_pltfm_pmops, 130 .pm = &dw_mci_pltfm_pmops,
133 }, 131 },
134}; 132};
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 018f365e5ae4..4bce0deec362 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -29,6 +29,7 @@
29#include <linux/irq.h> 29#include <linux/irq.h>
30#include <linux/mmc/host.h> 30#include <linux/mmc/host.h>
31#include <linux/mmc/mmc.h> 31#include <linux/mmc/mmc.h>
32#include <linux/mmc/sdio.h>
32#include <linux/mmc/dw_mmc.h> 33#include <linux/mmc/dw_mmc.h>
33#include <linux/bitops.h> 34#include <linux/bitops.h>
34#include <linux/regulator/consumer.h> 35#include <linux/regulator/consumer.h>
@@ -50,6 +51,9 @@
50#define DW_MCI_RECV_STATUS 2 51#define DW_MCI_RECV_STATUS 2
51#define DW_MCI_DMA_THRESHOLD 16 52#define DW_MCI_DMA_THRESHOLD 16
52 53
54#define DW_MCI_FREQ_MAX 200000000 /* unit: HZ */
55#define DW_MCI_FREQ_MIN 400000 /* unit: HZ */
56
53#ifdef CONFIG_MMC_DW_IDMAC 57#ifdef CONFIG_MMC_DW_IDMAC
54#define IDMAC_INT_CLR (SDMMC_IDMAC_INT_AI | SDMMC_IDMAC_INT_NI | \ 58#define IDMAC_INT_CLR (SDMMC_IDMAC_INT_AI | SDMMC_IDMAC_INT_NI | \
55 SDMMC_IDMAC_INT_CES | SDMMC_IDMAC_INT_DU | \ 59 SDMMC_IDMAC_INT_CES | SDMMC_IDMAC_INT_DU | \
@@ -76,42 +80,39 @@ struct idmac_desc {
76}; 80};
77#endif /* CONFIG_MMC_DW_IDMAC */ 81#endif /* CONFIG_MMC_DW_IDMAC */
78 82
79/** 83static const u8 tuning_blk_pattern_4bit[] = {
80 * struct dw_mci_slot - MMC slot state 84 0xff, 0x0f, 0xff, 0x00, 0xff, 0xcc, 0xc3, 0xcc,
81 * @mmc: The mmc_host representing this slot. 85 0xc3, 0x3c, 0xcc, 0xff, 0xfe, 0xff, 0xfe, 0xef,
82 * @host: The MMC controller this slot is using. 86 0xff, 0xdf, 0xff, 0xdd, 0xff, 0xfb, 0xff, 0xfb,
83 * @quirks: Slot-level quirks (DW_MCI_SLOT_QUIRK_XXX) 87 0xbf, 0xff, 0x7f, 0xff, 0x77, 0xf7, 0xbd, 0xef,
84 * @wp_gpio: If gpio_is_valid() we'll use this to read write protect. 88 0xff, 0xf0, 0xff, 0xf0, 0x0f, 0xfc, 0xcc, 0x3c,
85 * @ctype: Card type for this slot. 89 0xcc, 0x33, 0xcc, 0xcf, 0xff, 0xef, 0xff, 0xee,
86 * @mrq: mmc_request currently being processed or waiting to be 90 0xff, 0xfd, 0xff, 0xfd, 0xdf, 0xff, 0xbf, 0xff,
87 * processed, or NULL when the slot is idle. 91 0xbb, 0xff, 0xf7, 0xff, 0xf7, 0x7f, 0x7b, 0xde,
88 * @queue_node: List node for placing this node in the @queue list of 92};
89 * &struct dw_mci.
90 * @clock: Clock rate configured by set_ios(). Protected by host->lock.
91 * @flags: Random state bits associated with the slot.
92 * @id: Number of this slot.
93 * @last_detect_state: Most recently observed card detect state.
94 */
95struct dw_mci_slot {
96 struct mmc_host *mmc;
97 struct dw_mci *host;
98
99 int quirks;
100 int wp_gpio;
101
102 u32 ctype;
103
104 struct mmc_request *mrq;
105 struct list_head queue_node;
106 93
107 unsigned int clock; 94static const u8 tuning_blk_pattern_8bit[] = {
108 unsigned long flags; 95 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00,
109#define DW_MMC_CARD_PRESENT 0 96 0xff, 0xff, 0xcc, 0xcc, 0xcc, 0x33, 0xcc, 0xcc,
110#define DW_MMC_CARD_NEED_INIT 1 97 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xff, 0xff,
111 int id; 98 0xff, 0xee, 0xff, 0xff, 0xff, 0xee, 0xee, 0xff,
112 int last_detect_state; 99 0xff, 0xff, 0xdd, 0xff, 0xff, 0xff, 0xdd, 0xdd,
100 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb,
101 0xbb, 0xff, 0xff, 0xff, 0x77, 0xff, 0xff, 0xff,
102 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, 0xff,
103 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00,
104 0x00, 0xff, 0xff, 0xcc, 0xcc, 0xcc, 0x33, 0xcc,
105 0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xff,
106 0xff, 0xff, 0xee, 0xff, 0xff, 0xff, 0xee, 0xee,
107 0xff, 0xff, 0xff, 0xdd, 0xff, 0xff, 0xff, 0xdd,
108 0xdd, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff,
109 0xbb, 0xbb, 0xff, 0xff, 0xff, 0x77, 0xff, 0xff,
110 0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee,
113}; 111};
114 112
113static inline bool dw_mci_fifo_reset(struct dw_mci *host);
114static inline bool dw_mci_ctrl_all_reset(struct dw_mci *host);
115
115#if defined(CONFIG_DEBUG_FS) 116#if defined(CONFIG_DEBUG_FS)
116static int dw_mci_req_show(struct seq_file *s, void *v) 117static int dw_mci_req_show(struct seq_file *s, void *v)
117{ 118{
@@ -249,10 +250,15 @@ static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
249 250
250 cmdr = cmd->opcode; 251 cmdr = cmd->opcode;
251 252
252 if (cmdr == MMC_STOP_TRANSMISSION) 253 if (cmd->opcode == MMC_STOP_TRANSMISSION ||
254 cmd->opcode == MMC_GO_IDLE_STATE ||
255 cmd->opcode == MMC_GO_INACTIVE_STATE ||
256 (cmd->opcode == SD_IO_RW_DIRECT &&
257 ((cmd->arg >> 9) & 0x1FFFF) == SDIO_CCCR_ABORT))
253 cmdr |= SDMMC_CMD_STOP; 258 cmdr |= SDMMC_CMD_STOP;
254 else 259 else
255 cmdr |= SDMMC_CMD_PRV_DAT_WAIT; 260 if (cmd->opcode != MMC_SEND_STATUS && cmd->data)
261 cmdr |= SDMMC_CMD_PRV_DAT_WAIT;
256 262
257 if (cmd->flags & MMC_RSP_PRESENT) { 263 if (cmd->flags & MMC_RSP_PRESENT) {
258 /* We expect a response, so set this bit */ 264 /* We expect a response, so set this bit */
@@ -279,6 +285,40 @@ static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
279 return cmdr; 285 return cmdr;
280} 286}
281 287
288static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
289{
290 struct mmc_command *stop;
291 u32 cmdr;
292
293 if (!cmd->data)
294 return 0;
295
296 stop = &host->stop_abort;
297 cmdr = cmd->opcode;
298 memset(stop, 0, sizeof(struct mmc_command));
299
300 if (cmdr == MMC_READ_SINGLE_BLOCK ||
301 cmdr == MMC_READ_MULTIPLE_BLOCK ||
302 cmdr == MMC_WRITE_BLOCK ||
303 cmdr == MMC_WRITE_MULTIPLE_BLOCK) {
304 stop->opcode = MMC_STOP_TRANSMISSION;
305 stop->arg = 0;
306 stop->flags = MMC_RSP_R1B | MMC_CMD_AC;
307 } else if (cmdr == SD_IO_RW_EXTENDED) {
308 stop->opcode = SD_IO_RW_DIRECT;
309 stop->arg |= (1 << 31) | (0 << 28) | (SDIO_CCCR_ABORT << 9) |
310 ((cmd->arg >> 28) & 0x7);
311 stop->flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_AC;
312 } else {
313 return 0;
314 }
315
316 cmdr = stop->opcode | SDMMC_CMD_STOP |
317 SDMMC_CMD_RESP_CRC | SDMMC_CMD_RESP_EXP;
318
319 return cmdr;
320}
321
282static void dw_mci_start_command(struct dw_mci *host, 322static void dw_mci_start_command(struct dw_mci *host,
283 struct mmc_command *cmd, u32 cmd_flags) 323 struct mmc_command *cmd, u32 cmd_flags)
284{ 324{
@@ -293,9 +333,10 @@ static void dw_mci_start_command(struct dw_mci *host,
293 mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START); 333 mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START);
294} 334}
295 335
296static void send_stop_cmd(struct dw_mci *host, struct mmc_data *data) 336static inline void send_stop_abort(struct dw_mci *host, struct mmc_data *data)
297{ 337{
298 dw_mci_start_command(host, data->stop, host->stop_cmdr); 338 struct mmc_command *stop = data->stop ? data->stop : &host->stop_abort;
339 dw_mci_start_command(host, stop, host->stop_cmdr);
299} 340}
300 341
301/* DMA interface functions */ 342/* DMA interface functions */
@@ -304,10 +345,10 @@ static void dw_mci_stop_dma(struct dw_mci *host)
304 if (host->using_dma) { 345 if (host->using_dma) {
305 host->dma_ops->stop(host); 346 host->dma_ops->stop(host);
306 host->dma_ops->cleanup(host); 347 host->dma_ops->cleanup(host);
307 } else {
308 /* Data transfer was stopped by the interrupt handler */
309 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
310 } 348 }
349
350 /* Data transfer was stopped by the interrupt handler */
351 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
311} 352}
312 353
313static int dw_mci_get_dma_dir(struct mmc_data *data) 354static int dw_mci_get_dma_dir(struct mmc_data *data)
@@ -331,6 +372,14 @@ static void dw_mci_dma_cleanup(struct dw_mci *host)
331 dw_mci_get_dma_dir(data)); 372 dw_mci_get_dma_dir(data));
332} 373}
333 374
375static void dw_mci_idmac_reset(struct dw_mci *host)
376{
377 u32 bmod = mci_readl(host, BMOD);
378 /* Software reset of DMA */
379 bmod |= SDMMC_IDMAC_SWRESET;
380 mci_writel(host, BMOD, bmod);
381}
382
334static void dw_mci_idmac_stop_dma(struct dw_mci *host) 383static void dw_mci_idmac_stop_dma(struct dw_mci *host)
335{ 384{
336 u32 temp; 385 u32 temp;
@@ -344,6 +393,7 @@ static void dw_mci_idmac_stop_dma(struct dw_mci *host)
344 /* Stop the IDMAC running */ 393 /* Stop the IDMAC running */
345 temp = mci_readl(host, BMOD); 394 temp = mci_readl(host, BMOD);
346 temp &= ~(SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB); 395 temp &= ~(SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB);
396 temp |= SDMMC_IDMAC_SWRESET;
347 mci_writel(host, BMOD, temp); 397 mci_writel(host, BMOD, temp);
348} 398}
349 399
@@ -435,7 +485,7 @@ static int dw_mci_idmac_init(struct dw_mci *host)
435 p->des3 = host->sg_dma; 485 p->des3 = host->sg_dma;
436 p->des0 = IDMAC_DES0_ER; 486 p->des0 = IDMAC_DES0_ER;
437 487
438 mci_writel(host, BMOD, SDMMC_IDMAC_SWRESET); 488 dw_mci_idmac_reset(host);
439 489
440 /* Mask out interrupts - get Tx & Rx complete only */ 490 /* Mask out interrupts - get Tx & Rx complete only */
441 mci_writel(host, IDSTS, IDMAC_INT_CLR); 491 mci_writel(host, IDSTS, IDMAC_INT_CLR);
@@ -532,6 +582,78 @@ static void dw_mci_post_req(struct mmc_host *mmc,
532 data->host_cookie = 0; 582 data->host_cookie = 0;
533} 583}
534 584
585static void dw_mci_adjust_fifoth(struct dw_mci *host, struct mmc_data *data)
586{
587#ifdef CONFIG_MMC_DW_IDMAC
588 unsigned int blksz = data->blksz;
589 const u32 mszs[] = {1, 4, 8, 16, 32, 64, 128, 256};
590 u32 fifo_width = 1 << host->data_shift;
591 u32 blksz_depth = blksz / fifo_width, fifoth_val;
592 u32 msize = 0, rx_wmark = 1, tx_wmark, tx_wmark_invers;
593 int idx = (sizeof(mszs) / sizeof(mszs[0])) - 1;
594
595 tx_wmark = (host->fifo_depth) / 2;
596 tx_wmark_invers = host->fifo_depth - tx_wmark;
597
598 /*
599 * MSIZE is '1',
600 * if blksz is not a multiple of the FIFO width
601 */
602 if (blksz % fifo_width) {
603 msize = 0;
604 rx_wmark = 1;
605 goto done;
606 }
607
608 do {
609 if (!((blksz_depth % mszs[idx]) ||
610 (tx_wmark_invers % mszs[idx]))) {
611 msize = idx;
612 rx_wmark = mszs[idx] - 1;
613 break;
614 }
615 } while (--idx > 0);
616 /*
617 * If idx is '0', it won't be tried
618 * Thus, initial values are uesed
619 */
620done:
621 fifoth_val = SDMMC_SET_FIFOTH(msize, rx_wmark, tx_wmark);
622 mci_writel(host, FIFOTH, fifoth_val);
623#endif
624}
625
626static void dw_mci_ctrl_rd_thld(struct dw_mci *host, struct mmc_data *data)
627{
628 unsigned int blksz = data->blksz;
629 u32 blksz_depth, fifo_depth;
630 u16 thld_size;
631
632 WARN_ON(!(data->flags & MMC_DATA_READ));
633
634 if (host->timing != MMC_TIMING_MMC_HS200 &&
635 host->timing != MMC_TIMING_UHS_SDR104)
636 goto disable;
637
638 blksz_depth = blksz / (1 << host->data_shift);
639 fifo_depth = host->fifo_depth;
640
641 if (blksz_depth > fifo_depth)
642 goto disable;
643
644 /*
645 * If (blksz_depth) >= (fifo_depth >> 1), should be 'thld_size <= blksz'
646 * If (blksz_depth) < (fifo_depth >> 1), should be thld_size = blksz
647 * Currently just choose blksz.
648 */
649 thld_size = blksz;
650 mci_writel(host, CDTHRCTL, SDMMC_SET_RD_THLD(thld_size, 1));
651 return;
652
653disable:
654 mci_writel(host, CDTHRCTL, SDMMC_SET_RD_THLD(0, 0));
655}
656
535static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data) 657static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
536{ 658{
537 int sg_len; 659 int sg_len;
@@ -556,6 +678,14 @@ static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
556 (unsigned long)host->sg_cpu, (unsigned long)host->sg_dma, 678 (unsigned long)host->sg_cpu, (unsigned long)host->sg_dma,
557 sg_len); 679 sg_len);
558 680
681 /*
682 * Decide the MSIZE and RX/TX Watermark.
683 * If current block size is same with previous size,
684 * no need to update fifoth.
685 */
686 if (host->prev_blksz != data->blksz)
687 dw_mci_adjust_fifoth(host, data);
688
559 /* Enable the DMA interface */ 689 /* Enable the DMA interface */
560 temp = mci_readl(host, CTRL); 690 temp = mci_readl(host, CTRL);
561 temp |= SDMMC_CTRL_DMA_ENABLE; 691 temp |= SDMMC_CTRL_DMA_ENABLE;
@@ -581,10 +711,12 @@ static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
581 host->sg = NULL; 711 host->sg = NULL;
582 host->data = data; 712 host->data = data;
583 713
584 if (data->flags & MMC_DATA_READ) 714 if (data->flags & MMC_DATA_READ) {
585 host->dir_status = DW_MCI_RECV_STATUS; 715 host->dir_status = DW_MCI_RECV_STATUS;
586 else 716 dw_mci_ctrl_rd_thld(host, data);
717 } else {
587 host->dir_status = DW_MCI_SEND_STATUS; 718 host->dir_status = DW_MCI_SEND_STATUS;
719 }
588 720
589 if (dw_mci_submit_data_dma(host, data)) { 721 if (dw_mci_submit_data_dma(host, data)) {
590 int flags = SG_MITER_ATOMIC; 722 int flags = SG_MITER_ATOMIC;
@@ -606,6 +738,21 @@ static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
606 temp = mci_readl(host, CTRL); 738 temp = mci_readl(host, CTRL);
607 temp &= ~SDMMC_CTRL_DMA_ENABLE; 739 temp &= ~SDMMC_CTRL_DMA_ENABLE;
608 mci_writel(host, CTRL, temp); 740 mci_writel(host, CTRL, temp);
741
742 /*
743 * Use the initial fifoth_val for PIO mode.
744 * If next issued data may be transfered by DMA mode,
745 * prev_blksz should be invalidated.
746 */
747 mci_writel(host, FIFOTH, host->fifoth_val);
748 host->prev_blksz = 0;
749 } else {
750 /*
751 * Keep the current block size.
752 * It will be used to decide whether to update
753 * fifoth register next time.
754 */
755 host->prev_blksz = data->blksz;
609 } 756 }
610} 757}
611 758
@@ -632,24 +779,31 @@ static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg)
632static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit) 779static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
633{ 780{
634 struct dw_mci *host = slot->host; 781 struct dw_mci *host = slot->host;
782 unsigned int clock = slot->clock;
635 u32 div; 783 u32 div;
636 u32 clk_en_a; 784 u32 clk_en_a;
637 785
638 if (slot->clock != host->current_speed || force_clkinit) { 786 if (!clock) {
639 div = host->bus_hz / slot->clock; 787 mci_writel(host, CLKENA, 0);
640 if (host->bus_hz % slot->clock && host->bus_hz > slot->clock) 788 mci_send_cmd(slot,
789 SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
790 } else if (clock != host->current_speed || force_clkinit) {
791 div = host->bus_hz / clock;
792 if (host->bus_hz % clock && host->bus_hz > clock)
641 /* 793 /*
642 * move the + 1 after the divide to prevent 794 * move the + 1 after the divide to prevent
643 * over-clocking the card. 795 * over-clocking the card.
644 */ 796 */
645 div += 1; 797 div += 1;
646 798
647 div = (host->bus_hz != slot->clock) ? DIV_ROUND_UP(div, 2) : 0; 799 div = (host->bus_hz != clock) ? DIV_ROUND_UP(div, 2) : 0;
648 800
649 dev_info(&slot->mmc->class_dev, 801 if ((clock << div) != slot->__clk_old || force_clkinit)
650 "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ" 802 dev_info(&slot->mmc->class_dev,
651 " div = %d)\n", slot->id, host->bus_hz, slot->clock, 803 "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ div = %d)\n",
652 div ? ((host->bus_hz / div) >> 1) : host->bus_hz, div); 804 slot->id, host->bus_hz, clock,
805 div ? ((host->bus_hz / div) >> 1) :
806 host->bus_hz, div);
653 807
654 /* disable clock */ 808 /* disable clock */
655 mci_writel(host, CLKENA, 0); 809 mci_writel(host, CLKENA, 0);
@@ -676,9 +830,12 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
676 mci_send_cmd(slot, 830 mci_send_cmd(slot,
677 SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0); 831 SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
678 832
679 host->current_speed = slot->clock; 833 /* keep the clock with reflecting clock dividor */
834 slot->__clk_old = clock << div;
680 } 835 }
681 836
837 host->current_speed = clock;
838
682 /* Set the current slot bus width */ 839 /* Set the current slot bus width */
683 mci_writel(host, CTYPE, (slot->ctype << slot->id)); 840 mci_writel(host, CTYPE, (slot->ctype << slot->id));
684} 841}
@@ -700,7 +857,9 @@ static void __dw_mci_start_request(struct dw_mci *host,
700 857
701 host->pending_events = 0; 858 host->pending_events = 0;
702 host->completed_events = 0; 859 host->completed_events = 0;
860 host->cmd_status = 0;
703 host->data_status = 0; 861 host->data_status = 0;
862 host->dir_status = 0;
704 863
705 data = cmd->data; 864 data = cmd->data;
706 if (data) { 865 if (data) {
@@ -724,6 +883,8 @@ static void __dw_mci_start_request(struct dw_mci *host,
724 883
725 if (mrq->stop) 884 if (mrq->stop)
726 host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop); 885 host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop);
886 else
887 host->stop_cmdr = dw_mci_prep_stop_abort(host, cmd);
727} 888}
728 889
729static void dw_mci_start_request(struct dw_mci *host, 890static void dw_mci_start_request(struct dw_mci *host,
@@ -806,14 +967,13 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
806 regs &= ~((0x1 << slot->id) << 16); 967 regs &= ~((0x1 << slot->id) << 16);
807 968
808 mci_writel(slot->host, UHS_REG, regs); 969 mci_writel(slot->host, UHS_REG, regs);
970 slot->host->timing = ios->timing;
809 971
810 if (ios->clock) { 972 /*
811 /* 973 * Use mirror of ios->clock to prevent race with mmc
812 * Use mirror of ios->clock to prevent race with mmc 974 * core ios update when finding the minimum.
813 * core ios update when finding the minimum. 975 */
814 */ 976 slot->clock = ios->clock;
815 slot->clock = ios->clock;
816 }
817 977
818 if (drv_data && drv_data->set_ios) 978 if (drv_data && drv_data->set_ios)
819 drv_data->set_ios(slot->host, ios); 979 drv_data->set_ios(slot->host, ios);
@@ -939,6 +1099,38 @@ static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb)
939 } 1099 }
940} 1100}
941 1101
1102static int dw_mci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1103{
1104 struct dw_mci_slot *slot = mmc_priv(mmc);
1105 struct dw_mci *host = slot->host;
1106 const struct dw_mci_drv_data *drv_data = host->drv_data;
1107 struct dw_mci_tuning_data tuning_data;
1108 int err = -ENOSYS;
1109
1110 if (opcode == MMC_SEND_TUNING_BLOCK_HS200) {
1111 if (mmc->ios.bus_width == MMC_BUS_WIDTH_8) {
1112 tuning_data.blk_pattern = tuning_blk_pattern_8bit;
1113 tuning_data.blksz = sizeof(tuning_blk_pattern_8bit);
1114 } else if (mmc->ios.bus_width == MMC_BUS_WIDTH_4) {
1115 tuning_data.blk_pattern = tuning_blk_pattern_4bit;
1116 tuning_data.blksz = sizeof(tuning_blk_pattern_4bit);
1117 } else {
1118 return -EINVAL;
1119 }
1120 } else if (opcode == MMC_SEND_TUNING_BLOCK) {
1121 tuning_data.blk_pattern = tuning_blk_pattern_4bit;
1122 tuning_data.blksz = sizeof(tuning_blk_pattern_4bit);
1123 } else {
1124 dev_err(host->dev,
1125 "Undefined command(%d) for tuning\n", opcode);
1126 return -EINVAL;
1127 }
1128
1129 if (drv_data && drv_data->execute_tuning)
1130 err = drv_data->execute_tuning(slot, opcode, &tuning_data);
1131 return err;
1132}
1133
942static const struct mmc_host_ops dw_mci_ops = { 1134static const struct mmc_host_ops dw_mci_ops = {
943 .request = dw_mci_request, 1135 .request = dw_mci_request,
944 .pre_req = dw_mci_pre_req, 1136 .pre_req = dw_mci_pre_req,
@@ -947,6 +1139,7 @@ static const struct mmc_host_ops dw_mci_ops = {
947 .get_ro = dw_mci_get_ro, 1139 .get_ro = dw_mci_get_ro,
948 .get_cd = dw_mci_get_cd, 1140 .get_cd = dw_mci_get_cd,
949 .enable_sdio_irq = dw_mci_enable_sdio_irq, 1141 .enable_sdio_irq = dw_mci_enable_sdio_irq,
1142 .execute_tuning = dw_mci_execute_tuning,
950}; 1143};
951 1144
952static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq) 1145static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
@@ -978,7 +1171,7 @@ static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
978 spin_lock(&host->lock); 1171 spin_lock(&host->lock);
979} 1172}
980 1173
981static void dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd) 1174static int dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd)
982{ 1175{
983 u32 status = host->cmd_status; 1176 u32 status = host->cmd_status;
984 1177
@@ -1012,12 +1205,52 @@ static void dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd
1012 /* newer ip versions need a delay between retries */ 1205 /* newer ip versions need a delay between retries */
1013 if (host->quirks & DW_MCI_QUIRK_RETRY_DELAY) 1206 if (host->quirks & DW_MCI_QUIRK_RETRY_DELAY)
1014 mdelay(20); 1207 mdelay(20);
1208 }
1015 1209
1016 if (cmd->data) { 1210 return cmd->error;
1017 dw_mci_stop_dma(host); 1211}
1018 host->data = NULL; 1212
1213static int dw_mci_data_complete(struct dw_mci *host, struct mmc_data *data)
1214{
1215 u32 status = host->data_status;
1216
1217 if (status & DW_MCI_DATA_ERROR_FLAGS) {
1218 if (status & SDMMC_INT_DRTO) {
1219 data->error = -ETIMEDOUT;
1220 } else if (status & SDMMC_INT_DCRC) {
1221 data->error = -EILSEQ;
1222 } else if (status & SDMMC_INT_EBE) {
1223 if (host->dir_status ==
1224 DW_MCI_SEND_STATUS) {
1225 /*
1226 * No data CRC status was returned.
1227 * The number of bytes transferred
1228 * will be exaggerated in PIO mode.
1229 */
1230 data->bytes_xfered = 0;
1231 data->error = -ETIMEDOUT;
1232 } else if (host->dir_status ==
1233 DW_MCI_RECV_STATUS) {
1234 data->error = -EIO;
1235 }
1236 } else {
1237 /* SDMMC_INT_SBE is included */
1238 data->error = -EIO;
1019 } 1239 }
1240
1241 dev_err(host->dev, "data error, status 0x%08x\n", status);
1242
1243 /*
1244 * After an error, there may be data lingering
1245 * in the FIFO
1246 */
1247 dw_mci_fifo_reset(host);
1248 } else {
1249 data->bytes_xfered = data->blocks * data->blksz;
1250 data->error = 0;
1020 } 1251 }
1252
1253 return data->error;
1021} 1254}
1022 1255
1023static void dw_mci_tasklet_func(unsigned long priv) 1256static void dw_mci_tasklet_func(unsigned long priv)
@@ -1025,14 +1258,16 @@ static void dw_mci_tasklet_func(unsigned long priv)
1025 struct dw_mci *host = (struct dw_mci *)priv; 1258 struct dw_mci *host = (struct dw_mci *)priv;
1026 struct mmc_data *data; 1259 struct mmc_data *data;
1027 struct mmc_command *cmd; 1260 struct mmc_command *cmd;
1261 struct mmc_request *mrq;
1028 enum dw_mci_state state; 1262 enum dw_mci_state state;
1029 enum dw_mci_state prev_state; 1263 enum dw_mci_state prev_state;
1030 u32 status, ctrl; 1264 unsigned int err;
1031 1265
1032 spin_lock(&host->lock); 1266 spin_lock(&host->lock);
1033 1267
1034 state = host->state; 1268 state = host->state;
1035 data = host->data; 1269 data = host->data;
1270 mrq = host->mrq;
1036 1271
1037 do { 1272 do {
1038 prev_state = state; 1273 prev_state = state;
@@ -1049,16 +1284,23 @@ static void dw_mci_tasklet_func(unsigned long priv)
1049 cmd = host->cmd; 1284 cmd = host->cmd;
1050 host->cmd = NULL; 1285 host->cmd = NULL;
1051 set_bit(EVENT_CMD_COMPLETE, &host->completed_events); 1286 set_bit(EVENT_CMD_COMPLETE, &host->completed_events);
1052 dw_mci_command_complete(host, cmd); 1287 err = dw_mci_command_complete(host, cmd);
1053 if (cmd == host->mrq->sbc && !cmd->error) { 1288 if (cmd == mrq->sbc && !err) {
1054 prev_state = state = STATE_SENDING_CMD; 1289 prev_state = state = STATE_SENDING_CMD;
1055 __dw_mci_start_request(host, host->cur_slot, 1290 __dw_mci_start_request(host, host->cur_slot,
1056 host->mrq->cmd); 1291 mrq->cmd);
1057 goto unlock; 1292 goto unlock;
1058 } 1293 }
1059 1294
1060 if (!host->mrq->data || cmd->error) { 1295 if (cmd->data && err) {
1061 dw_mci_request_end(host, host->mrq); 1296 dw_mci_stop_dma(host);
1297 send_stop_abort(host, data);
1298 state = STATE_SENDING_STOP;
1299 break;
1300 }
1301
1302 if (!cmd->data || err) {
1303 dw_mci_request_end(host, mrq);
1062 goto unlock; 1304 goto unlock;
1063 } 1305 }
1064 1306
@@ -1069,8 +1311,7 @@ static void dw_mci_tasklet_func(unsigned long priv)
1069 if (test_and_clear_bit(EVENT_DATA_ERROR, 1311 if (test_and_clear_bit(EVENT_DATA_ERROR,
1070 &host->pending_events)) { 1312 &host->pending_events)) {
1071 dw_mci_stop_dma(host); 1313 dw_mci_stop_dma(host);
1072 if (data->stop) 1314 send_stop_abort(host, data);
1073 send_stop_cmd(host, data);
1074 state = STATE_DATA_ERROR; 1315 state = STATE_DATA_ERROR;
1075 break; 1316 break;
1076 } 1317 }
@@ -1090,60 +1331,27 @@ static void dw_mci_tasklet_func(unsigned long priv)
1090 1331
1091 host->data = NULL; 1332 host->data = NULL;
1092 set_bit(EVENT_DATA_COMPLETE, &host->completed_events); 1333 set_bit(EVENT_DATA_COMPLETE, &host->completed_events);
1093 status = host->data_status; 1334 err = dw_mci_data_complete(host, data);
1094
1095 if (status & DW_MCI_DATA_ERROR_FLAGS) {
1096 if (status & SDMMC_INT_DRTO) {
1097 data->error = -ETIMEDOUT;
1098 } else if (status & SDMMC_INT_DCRC) {
1099 data->error = -EILSEQ;
1100 } else if (status & SDMMC_INT_EBE &&
1101 host->dir_status ==
1102 DW_MCI_SEND_STATUS) {
1103 /*
1104 * No data CRC status was returned.
1105 * The number of bytes transferred will
1106 * be exaggerated in PIO mode.
1107 */
1108 data->bytes_xfered = 0;
1109 data->error = -ETIMEDOUT;
1110 } else {
1111 dev_err(host->dev,
1112 "data FIFO error "
1113 "(status=%08x)\n",
1114 status);
1115 data->error = -EIO;
1116 }
1117 /*
1118 * After an error, there may be data lingering
1119 * in the FIFO, so reset it - doing so
1120 * generates a block interrupt, hence setting
1121 * the scatter-gather pointer to NULL.
1122 */
1123 sg_miter_stop(&host->sg_miter);
1124 host->sg = NULL;
1125 ctrl = mci_readl(host, CTRL);
1126 ctrl |= SDMMC_CTRL_FIFO_RESET;
1127 mci_writel(host, CTRL, ctrl);
1128 } else {
1129 data->bytes_xfered = data->blocks * data->blksz;
1130 data->error = 0;
1131 }
1132 1335
1133 if (!data->stop) { 1336 if (!err) {
1134 dw_mci_request_end(host, host->mrq); 1337 if (!data->stop || mrq->sbc) {
1135 goto unlock; 1338 if (mrq->sbc)
1136 } 1339 data->stop->error = 0;
1340 dw_mci_request_end(host, mrq);
1341 goto unlock;
1342 }
1137 1343
1138 if (host->mrq->sbc && !data->error) { 1344 /* stop command for open-ended transfer*/
1139 data->stop->error = 0; 1345 if (data->stop)
1140 dw_mci_request_end(host, host->mrq); 1346 send_stop_abort(host, data);
1141 goto unlock;
1142 } 1347 }
1143 1348
1349 /*
1350 * If err has non-zero,
1351 * stop-abort command has been already issued.
1352 */
1144 prev_state = state = STATE_SENDING_STOP; 1353 prev_state = state = STATE_SENDING_STOP;
1145 if (!data->error) 1354
1146 send_stop_cmd(host, data);
1147 /* fall through */ 1355 /* fall through */
1148 1356
1149 case STATE_SENDING_STOP: 1357 case STATE_SENDING_STOP:
@@ -1151,9 +1359,19 @@ static void dw_mci_tasklet_func(unsigned long priv)
1151 &host->pending_events)) 1359 &host->pending_events))
1152 break; 1360 break;
1153 1361
1362 /* CMD error in data command */
1363 if (mrq->cmd->error && mrq->data)
1364 dw_mci_fifo_reset(host);
1365
1154 host->cmd = NULL; 1366 host->cmd = NULL;
1155 dw_mci_command_complete(host, host->mrq->stop); 1367 host->data = NULL;
1156 dw_mci_request_end(host, host->mrq); 1368
1369 if (mrq->stop)
1370 dw_mci_command_complete(host, mrq->stop);
1371 else
1372 host->cmd_status = 0;
1373
1374 dw_mci_request_end(host, mrq);
1157 goto unlock; 1375 goto unlock;
1158 1376
1159 case STATE_DATA_ERROR: 1377 case STATE_DATA_ERROR:
@@ -1697,7 +1915,6 @@ static void dw_mci_work_routine_card(struct work_struct *work)
1697 struct mmc_host *mmc = slot->mmc; 1915 struct mmc_host *mmc = slot->mmc;
1698 struct mmc_request *mrq; 1916 struct mmc_request *mrq;
1699 int present; 1917 int present;
1700 u32 ctrl;
1701 1918
1702 present = dw_mci_get_cd(mmc); 1919 present = dw_mci_get_cd(mmc);
1703 while (present != slot->last_detect_state) { 1920 while (present != slot->last_detect_state) {
@@ -1736,11 +1953,10 @@ static void dw_mci_work_routine_card(struct work_struct *work)
1736 case STATE_DATA_ERROR: 1953 case STATE_DATA_ERROR:
1737 if (mrq->data->error == -EINPROGRESS) 1954 if (mrq->data->error == -EINPROGRESS)
1738 mrq->data->error = -ENOMEDIUM; 1955 mrq->data->error = -ENOMEDIUM;
1739 if (!mrq->stop)
1740 break;
1741 /* fall through */ 1956 /* fall through */
1742 case STATE_SENDING_STOP: 1957 case STATE_SENDING_STOP:
1743 mrq->stop->error = -ENOMEDIUM; 1958 if (mrq->stop)
1959 mrq->stop->error = -ENOMEDIUM;
1744 break; 1960 break;
1745 } 1961 }
1746 1962
@@ -1763,23 +1979,10 @@ static void dw_mci_work_routine_card(struct work_struct *work)
1763 if (present == 0) { 1979 if (present == 0) {
1764 clear_bit(DW_MMC_CARD_PRESENT, &slot->flags); 1980 clear_bit(DW_MMC_CARD_PRESENT, &slot->flags);
1765 1981
1766 /* 1982 /* Clear down the FIFO */
1767 * Clear down the FIFO - doing so generates a 1983 dw_mci_fifo_reset(host);
1768 * block interrupt, hence setting the
1769 * scatter-gather pointer to NULL.
1770 */
1771 sg_miter_stop(&host->sg_miter);
1772 host->sg = NULL;
1773
1774 ctrl = mci_readl(host, CTRL);
1775 ctrl |= SDMMC_CTRL_FIFO_RESET;
1776 mci_writel(host, CTRL, ctrl);
1777
1778#ifdef CONFIG_MMC_DW_IDMAC 1984#ifdef CONFIG_MMC_DW_IDMAC
1779 ctrl = mci_readl(host, BMOD); 1985 dw_mci_idmac_reset(host);
1780 /* Software reset of DMA */
1781 ctrl |= SDMMC_IDMAC_SWRESET;
1782 mci_writel(host, BMOD, ctrl);
1783#endif 1986#endif
1784 1987
1785 } 1988 }
@@ -1901,6 +2104,7 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
1901 struct dw_mci_slot *slot; 2104 struct dw_mci_slot *slot;
1902 const struct dw_mci_drv_data *drv_data = host->drv_data; 2105 const struct dw_mci_drv_data *drv_data = host->drv_data;
1903 int ctrl_id, ret; 2106 int ctrl_id, ret;
2107 u32 freq[2];
1904 u8 bus_width; 2108 u8 bus_width;
1905 2109
1906 mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev); 2110 mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev);
@@ -1916,8 +2120,14 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
1916 slot->quirks = dw_mci_of_get_slot_quirks(host->dev, slot->id); 2120 slot->quirks = dw_mci_of_get_slot_quirks(host->dev, slot->id);
1917 2121
1918 mmc->ops = &dw_mci_ops; 2122 mmc->ops = &dw_mci_ops;
1919 mmc->f_min = DIV_ROUND_UP(host->bus_hz, 510); 2123 if (of_property_read_u32_array(host->dev->of_node,
1920 mmc->f_max = host->bus_hz; 2124 "clock-freq-min-max", freq, 2)) {
2125 mmc->f_min = DW_MCI_FREQ_MIN;
2126 mmc->f_max = DW_MCI_FREQ_MAX;
2127 } else {
2128 mmc->f_min = freq[0];
2129 mmc->f_max = freq[1];
2130 }
1921 2131
1922 if (host->pdata->get_ocr) 2132 if (host->pdata->get_ocr)
1923 mmc->ocr_avail = host->pdata->get_ocr(id); 2133 mmc->ocr_avail = host->pdata->get_ocr(id);
@@ -1964,9 +2174,6 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
1964 mmc->caps |= MMC_CAP_4_BIT_DATA; 2174 mmc->caps |= MMC_CAP_4_BIT_DATA;
1965 } 2175 }
1966 2176
1967 if (host->pdata->quirks & DW_MCI_QUIRK_HIGHSPEED)
1968 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
1969
1970 if (host->pdata->blk_settings) { 2177 if (host->pdata->blk_settings) {
1971 mmc->max_segs = host->pdata->blk_settings->max_segs; 2178 mmc->max_segs = host->pdata->blk_settings->max_segs;
1972 mmc->max_blk_size = host->pdata->blk_settings->max_blk_size; 2179 mmc->max_blk_size = host->pdata->blk_settings->max_blk_size;
@@ -2008,12 +2215,6 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
2008 /* Card initially undetected */ 2215 /* Card initially undetected */
2009 slot->last_detect_state = 0; 2216 slot->last_detect_state = 0;
2010 2217
2011 /*
2012 * Card may have been plugged in prior to boot so we
2013 * need to run the detect tasklet
2014 */
2015 queue_work(host->card_workqueue, &host->card_work);
2016
2017 return 0; 2218 return 0;
2018 2219
2019err_setup_bus: 2220err_setup_bus:
@@ -2074,36 +2275,57 @@ no_dma:
2074 return; 2275 return;
2075} 2276}
2076 2277
2077static bool mci_wait_reset(struct device *dev, struct dw_mci *host) 2278static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset)
2078{ 2279{
2079 unsigned long timeout = jiffies + msecs_to_jiffies(500); 2280 unsigned long timeout = jiffies + msecs_to_jiffies(500);
2080 unsigned int ctrl; 2281 u32 ctrl;
2081 2282
2082 mci_writel(host, CTRL, (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | 2283 ctrl = mci_readl(host, CTRL);
2083 SDMMC_CTRL_DMA_RESET)); 2284 ctrl |= reset;
2285 mci_writel(host, CTRL, ctrl);
2084 2286
2085 /* wait till resets clear */ 2287 /* wait till resets clear */
2086 do { 2288 do {
2087 ctrl = mci_readl(host, CTRL); 2289 ctrl = mci_readl(host, CTRL);
2088 if (!(ctrl & (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | 2290 if (!(ctrl & reset))
2089 SDMMC_CTRL_DMA_RESET)))
2090 return true; 2291 return true;
2091 } while (time_before(jiffies, timeout)); 2292 } while (time_before(jiffies, timeout));
2092 2293
2093 dev_err(dev, "Timeout resetting block (ctrl %#x)\n", ctrl); 2294 dev_err(host->dev,
2295 "Timeout resetting block (ctrl reset %#x)\n",
2296 ctrl & reset);
2094 2297
2095 return false; 2298 return false;
2096} 2299}
2097 2300
2301static inline bool dw_mci_fifo_reset(struct dw_mci *host)
2302{
2303 /*
2304 * Reseting generates a block interrupt, hence setting
2305 * the scatter-gather pointer to NULL.
2306 */
2307 if (host->sg) {
2308 sg_miter_stop(&host->sg_miter);
2309 host->sg = NULL;
2310 }
2311
2312 return dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET);
2313}
2314
2315static inline bool dw_mci_ctrl_all_reset(struct dw_mci *host)
2316{
2317 return dw_mci_ctrl_reset(host,
2318 SDMMC_CTRL_FIFO_RESET |
2319 SDMMC_CTRL_RESET |
2320 SDMMC_CTRL_DMA_RESET);
2321}
2322
2098#ifdef CONFIG_OF 2323#ifdef CONFIG_OF
2099static struct dw_mci_of_quirks { 2324static struct dw_mci_of_quirks {
2100 char *quirk; 2325 char *quirk;
2101 int id; 2326 int id;
2102} of_quirks[] = { 2327} of_quirks[] = {
2103 { 2328 {
2104 .quirk = "supports-highspeed",
2105 .id = DW_MCI_QUIRK_HIGHSPEED,
2106 }, {
2107 .quirk = "broken-cd", 2329 .quirk = "broken-cd",
2108 .id = DW_MCI_QUIRK_BROKEN_CARD_DETECTION, 2330 .id = DW_MCI_QUIRK_BROKEN_CARD_DETECTION,
2109 }, 2331 },
@@ -2158,6 +2380,15 @@ static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
2158 if (of_find_property(np, "enable-sdio-wakeup", NULL)) 2380 if (of_find_property(np, "enable-sdio-wakeup", NULL))
2159 pdata->pm_caps |= MMC_PM_WAKE_SDIO_IRQ; 2381 pdata->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
2160 2382
2383 if (of_find_property(np, "supports-highspeed", NULL))
2384 pdata->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
2385
2386 if (of_find_property(np, "caps2-mmc-hs200-1_8v", NULL))
2387 pdata->caps2 |= MMC_CAP2_HS200_1_8V_SDR;
2388
2389 if (of_find_property(np, "caps2-mmc-hs200-1_2v", NULL))
2390 pdata->caps2 |= MMC_CAP2_HS200_1_2V_SDR;
2391
2161 return pdata; 2392 return pdata;
2162} 2393}
2163 2394
@@ -2221,6 +2452,15 @@ int dw_mci_probe(struct dw_mci *host)
2221 host->bus_hz = clk_get_rate(host->ciu_clk); 2452 host->bus_hz = clk_get_rate(host->ciu_clk);
2222 } 2453 }
2223 2454
2455 if (drv_data && drv_data->init) {
2456 ret = drv_data->init(host);
2457 if (ret) {
2458 dev_err(host->dev,
2459 "implementation specific init failed\n");
2460 goto err_clk_ciu;
2461 }
2462 }
2463
2224 if (drv_data && drv_data->setup_clock) { 2464 if (drv_data && drv_data->setup_clock) {
2225 ret = drv_data->setup_clock(host); 2465 ret = drv_data->setup_clock(host);
2226 if (ret) { 2466 if (ret) {
@@ -2287,7 +2527,7 @@ int dw_mci_probe(struct dw_mci *host)
2287 } 2527 }
2288 2528
2289 /* Reset all blocks */ 2529 /* Reset all blocks */
2290 if (!mci_wait_reset(host->dev, host)) 2530 if (!dw_mci_ctrl_all_reset(host))
2291 return -ENODEV; 2531 return -ENODEV;
2292 2532
2293 host->dma_ops = host->pdata->dma_ops; 2533 host->dma_ops = host->pdata->dma_ops;
@@ -2317,8 +2557,8 @@ int dw_mci_probe(struct dw_mci *host)
2317 fifo_size = host->pdata->fifo_depth; 2557 fifo_size = host->pdata->fifo_depth;
2318 } 2558 }
2319 host->fifo_depth = fifo_size; 2559 host->fifo_depth = fifo_size;
2320 host->fifoth_val = ((0x2 << 28) | ((fifo_size/2 - 1) << 16) | 2560 host->fifoth_val =
2321 ((fifo_size/2) << 0)); 2561 SDMMC_SET_FIFOTH(0x2, fifo_size / 2 - 1, fifo_size / 2);
2322 mci_writel(host, FIFOTH, host->fifoth_val); 2562 mci_writel(host, FIFOTH, host->fifoth_val);
2323 2563
2324 /* disable clock to CIU */ 2564 /* disable clock to CIU */
@@ -2456,23 +2696,6 @@ EXPORT_SYMBOL(dw_mci_remove);
2456 */ 2696 */
2457int dw_mci_suspend(struct dw_mci *host) 2697int dw_mci_suspend(struct dw_mci *host)
2458{ 2698{
2459 int i, ret = 0;
2460
2461 for (i = 0; i < host->num_slots; i++) {
2462 struct dw_mci_slot *slot = host->slot[i];
2463 if (!slot)
2464 continue;
2465 ret = mmc_suspend_host(slot->mmc);
2466 if (ret < 0) {
2467 while (--i >= 0) {
2468 slot = host->slot[i];
2469 if (slot)
2470 mmc_resume_host(host->slot[i]->mmc);
2471 }
2472 return ret;
2473 }
2474 }
2475
2476 if (host->vmmc) 2699 if (host->vmmc)
2477 regulator_disable(host->vmmc); 2700 regulator_disable(host->vmmc);
2478 2701
@@ -2493,7 +2716,7 @@ int dw_mci_resume(struct dw_mci *host)
2493 } 2716 }
2494 } 2717 }
2495 2718
2496 if (!mci_wait_reset(host->dev, host)) { 2719 if (!dw_mci_ctrl_all_reset(host)) {
2497 ret = -ENODEV; 2720 ret = -ENODEV;
2498 return ret; 2721 return ret;
2499 } 2722 }
@@ -2501,8 +2724,15 @@ int dw_mci_resume(struct dw_mci *host)
2501 if (host->use_dma && host->dma_ops->init) 2724 if (host->use_dma && host->dma_ops->init)
2502 host->dma_ops->init(host); 2725 host->dma_ops->init(host);
2503 2726
2504 /* Restore the old value at FIFOTH register */ 2727 /*
2728 * Restore the initial value at FIFOTH register
2729 * And Invalidate the prev_blksz with zero
2730 */
2505 mci_writel(host, FIFOTH, host->fifoth_val); 2731 mci_writel(host, FIFOTH, host->fifoth_val);
2732 host->prev_blksz = 0;
2733
2734 /* Put in max timeout */
2735 mci_writel(host, TMOUT, 0xFFFFFFFF);
2506 2736
2507 mci_writel(host, RINTSTS, 0xFFFFFFFF); 2737 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2508 mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER | 2738 mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
@@ -2518,10 +2748,6 @@ int dw_mci_resume(struct dw_mci *host)
2518 dw_mci_set_ios(slot->mmc, &slot->mmc->ios); 2748 dw_mci_set_ios(slot->mmc, &slot->mmc->ios);
2519 dw_mci_setup_bus(slot, true); 2749 dw_mci_setup_bus(slot, true);
2520 } 2750 }
2521
2522 ret = mmc_resume_host(host->slot[i]->mmc);
2523 if (ret < 0)
2524 return ret;
2525 } 2751 }
2526 return 0; 2752 return 0;
2527} 2753}
diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
index 81b29941c5b9..6bf24ab917e6 100644
--- a/drivers/mmc/host/dw_mmc.h
+++ b/drivers/mmc/host/dw_mmc.h
@@ -53,6 +53,7 @@
53#define SDMMC_IDINTEN 0x090 53#define SDMMC_IDINTEN 0x090
54#define SDMMC_DSCADDR 0x094 54#define SDMMC_DSCADDR 0x094
55#define SDMMC_BUFADDR 0x098 55#define SDMMC_BUFADDR 0x098
56#define SDMMC_CDTHRCTL 0x100
56#define SDMMC_DATA(x) (x) 57#define SDMMC_DATA(x) (x)
57 58
58/* 59/*
@@ -128,6 +129,10 @@
128#define SDMMC_CMD_INDX(n) ((n) & 0x1F) 129#define SDMMC_CMD_INDX(n) ((n) & 0x1F)
129/* Status register defines */ 130/* Status register defines */
130#define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FFF) 131#define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FFF)
132/* FIFOTH register defines */
133#define SDMMC_SET_FIFOTH(m, r, t) (((m) & 0x7) << 28 | \
134 ((r) & 0xFFF) << 16 | \
135 ((t) & 0xFFF))
131/* Internal DMAC interrupt defines */ 136/* Internal DMAC interrupt defines */
132#define SDMMC_IDMAC_INT_AI BIT(9) 137#define SDMMC_IDMAC_INT_AI BIT(9)
133#define SDMMC_IDMAC_INT_NI BIT(8) 138#define SDMMC_IDMAC_INT_NI BIT(8)
@@ -142,6 +147,8 @@
142#define SDMMC_IDMAC_SWRESET BIT(0) 147#define SDMMC_IDMAC_SWRESET BIT(0)
143/* Version ID register define */ 148/* Version ID register define */
144#define SDMMC_GET_VERID(x) ((x) & 0xFFFF) 149#define SDMMC_GET_VERID(x) ((x) & 0xFFFF)
150/* Card read threshold */
151#define SDMMC_SET_RD_THLD(v, x) (((v) & 0x1FFF) << 16 | (x))
145 152
146/* Register access macros */ 153/* Register access macros */
147#define mci_readl(dev, reg) \ 154#define mci_readl(dev, reg) \
@@ -184,6 +191,52 @@ extern int dw_mci_resume(struct dw_mci *host);
184#endif 191#endif
185 192
186/** 193/**
194 * struct dw_mci_slot - MMC slot state
195 * @mmc: The mmc_host representing this slot.
196 * @host: The MMC controller this slot is using.
197 * @quirks: Slot-level quirks (DW_MCI_SLOT_QUIRK_XXX)
198 * @wp_gpio: If gpio_is_valid() we'll use this to read write protect.
199 * @ctype: Card type for this slot.
200 * @mrq: mmc_request currently being processed or waiting to be
201 * processed, or NULL when the slot is idle.
202 * @queue_node: List node for placing this node in the @queue list of
203 * &struct dw_mci.
204 * @clock: Clock rate configured by set_ios(). Protected by host->lock.
205 * @__clk_old: The last updated clock with reflecting clock divider.
206 * Keeping track of this helps us to avoid spamming the console
207 * with CONFIG_MMC_CLKGATE.
208 * @flags: Random state bits associated with the slot.
209 * @id: Number of this slot.
210 * @last_detect_state: Most recently observed card detect state.
211 */
212struct dw_mci_slot {
213 struct mmc_host *mmc;
214 struct dw_mci *host;
215
216 int quirks;
217 int wp_gpio;
218
219 u32 ctype;
220
221 struct mmc_request *mrq;
222 struct list_head queue_node;
223
224 unsigned int clock;
225 unsigned int __clk_old;
226
227 unsigned long flags;
228#define DW_MMC_CARD_PRESENT 0
229#define DW_MMC_CARD_NEED_INIT 1
230 int id;
231 int last_detect_state;
232};
233
234struct dw_mci_tuning_data {
235 const u8 *blk_pattern;
236 unsigned int blksz;
237};
238
239/**
187 * dw_mci driver data - dw-mshc implementation specific driver data. 240 * dw_mci driver data - dw-mshc implementation specific driver data.
188 * @caps: mmc subsystem specified capabilities of the controller(s). 241 * @caps: mmc subsystem specified capabilities of the controller(s).
189 * @init: early implementation specific initialization. 242 * @init: early implementation specific initialization.
@@ -203,5 +256,7 @@ struct dw_mci_drv_data {
203 void (*prepare_command)(struct dw_mci *host, u32 *cmdr); 256 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
204 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios); 257 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
205 int (*parse_dt)(struct dw_mci *host); 258 int (*parse_dt)(struct dw_mci *host);
259 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
260 struct dw_mci_tuning_data *tuning_data);
206}; 261};
207#endif /* _DW_MMC_H_ */ 262#endif /* _DW_MMC_H_ */
diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
index 66516339e3a0..de2139cf3444 100644
--- a/drivers/mmc/host/jz4740_mmc.c
+++ b/drivers/mmc/host/jz4740_mmc.c
@@ -880,8 +880,6 @@ static int jz4740_mmc_suspend(struct device *dev)
880{ 880{
881 struct jz4740_mmc_host *host = dev_get_drvdata(dev); 881 struct jz4740_mmc_host *host = dev_get_drvdata(dev);
882 882
883 mmc_suspend_host(host->mmc);
884
885 jz_gpio_bulk_suspend(jz4740_mmc_pins, jz4740_mmc_num_pins(host)); 883 jz_gpio_bulk_suspend(jz4740_mmc_pins, jz4740_mmc_num_pins(host));
886 884
887 return 0; 885 return 0;
@@ -893,8 +891,6 @@ static int jz4740_mmc_resume(struct device *dev)
893 891
894 jz_gpio_bulk_resume(jz4740_mmc_pins, jz4740_mmc_num_pins(host)); 892 jz_gpio_bulk_resume(jz4740_mmc_pins, jz4740_mmc_num_pins(host));
895 893
896 mmc_resume_host(host->mmc);
897
898 return 0; 894 return 0;
899} 895}
900 896
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index d135c76c4855..f32057972dd7 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -1730,37 +1730,28 @@ static int mmci_suspend(struct device *dev)
1730{ 1730{
1731 struct amba_device *adev = to_amba_device(dev); 1731 struct amba_device *adev = to_amba_device(dev);
1732 struct mmc_host *mmc = amba_get_drvdata(adev); 1732 struct mmc_host *mmc = amba_get_drvdata(adev);
1733 int ret = 0;
1734 1733
1735 if (mmc) { 1734 if (mmc) {
1736 struct mmci_host *host = mmc_priv(mmc); 1735 struct mmci_host *host = mmc_priv(mmc);
1737 1736 pm_runtime_get_sync(dev);
1738 ret = mmc_suspend_host(mmc); 1737 writel(0, host->base + MMCIMASK0);
1739 if (ret == 0) {
1740 pm_runtime_get_sync(dev);
1741 writel(0, host->base + MMCIMASK0);
1742 }
1743 } 1738 }
1744 1739
1745 return ret; 1740 return 0;
1746} 1741}
1747 1742
1748static int mmci_resume(struct device *dev) 1743static int mmci_resume(struct device *dev)
1749{ 1744{
1750 struct amba_device *adev = to_amba_device(dev); 1745 struct amba_device *adev = to_amba_device(dev);
1751 struct mmc_host *mmc = amba_get_drvdata(adev); 1746 struct mmc_host *mmc = amba_get_drvdata(adev);
1752 int ret = 0;
1753 1747
1754 if (mmc) { 1748 if (mmc) {
1755 struct mmci_host *host = mmc_priv(mmc); 1749 struct mmci_host *host = mmc_priv(mmc);
1756
1757 writel(MCI_IRQENABLE, host->base + MMCIMASK0); 1750 writel(MCI_IRQENABLE, host->base + MMCIMASK0);
1758 pm_runtime_put(dev); 1751 pm_runtime_put(dev);
1759
1760 ret = mmc_resume_host(mmc);
1761 } 1752 }
1762 1753
1763 return ret; 1754 return 0;
1764} 1755}
1765#endif 1756#endif
1766 1757
diff --git a/drivers/mmc/host/msm_sdcc.c b/drivers/mmc/host/msm_sdcc.c
index b900de4e7e94..9405ecdaf6cf 100644
--- a/drivers/mmc/host/msm_sdcc.c
+++ b/drivers/mmc/host/msm_sdcc.c
@@ -1416,28 +1416,10 @@ ioremap_free:
1416} 1416}
1417 1417
1418#ifdef CONFIG_PM 1418#ifdef CONFIG_PM
1419#ifdef CONFIG_MMC_MSM7X00A_RESUME_IN_WQ
1420static void
1421do_resume_work(struct work_struct *work)
1422{
1423 struct msmsdcc_host *host =
1424 container_of(work, struct msmsdcc_host, resume_task);
1425 struct mmc_host *mmc = host->mmc;
1426
1427 if (mmc) {
1428 mmc_resume_host(mmc);
1429 if (host->stat_irq)
1430 enable_irq(host->stat_irq);
1431 }
1432}
1433#endif
1434
1435
1436static int 1419static int
1437msmsdcc_suspend(struct platform_device *dev, pm_message_t state) 1420msmsdcc_suspend(struct platform_device *dev, pm_message_t state)
1438{ 1421{
1439 struct mmc_host *mmc = mmc_get_drvdata(dev); 1422 struct mmc_host *mmc = mmc_get_drvdata(dev);
1440 int rc = 0;
1441 1423
1442 if (mmc) { 1424 if (mmc) {
1443 struct msmsdcc_host *host = mmc_priv(mmc); 1425 struct msmsdcc_host *host = mmc_priv(mmc);
@@ -1445,14 +1427,11 @@ msmsdcc_suspend(struct platform_device *dev, pm_message_t state)
1445 if (host->stat_irq) 1427 if (host->stat_irq)
1446 disable_irq(host->stat_irq); 1428 disable_irq(host->stat_irq);
1447 1429
1448 if (mmc->card && mmc->card->type != MMC_TYPE_SDIO) 1430 msmsdcc_writel(host, 0, MMCIMASK0);
1449 rc = mmc_suspend_host(mmc);
1450 if (!rc)
1451 msmsdcc_writel(host, 0, MMCIMASK0);
1452 if (host->clks_on) 1431 if (host->clks_on)
1453 msmsdcc_disable_clocks(host, 0); 1432 msmsdcc_disable_clocks(host, 0);
1454 } 1433 }
1455 return rc; 1434 return 0;
1456} 1435}
1457 1436
1458static int 1437static int
@@ -1467,8 +1446,6 @@ msmsdcc_resume(struct platform_device *dev)
1467 1446
1468 msmsdcc_writel(host, host->saved_irq0mask, MMCIMASK0); 1447 msmsdcc_writel(host, host->saved_irq0mask, MMCIMASK0);
1469 1448
1470 if (mmc->card && mmc->card->type != MMC_TYPE_SDIO)
1471 mmc_resume_host(mmc);
1472 if (host->stat_irq) 1449 if (host->stat_irq)
1473 enable_irq(host->stat_irq); 1450 enable_irq(host->stat_irq);
1474#if BUSCLK_PWRSAVE 1451#if BUSCLK_PWRSAVE
diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c
index deecee08c288..45aa2206741d 100644
--- a/drivers/mmc/host/mvsdio.c
+++ b/drivers/mmc/host/mvsdio.c
@@ -775,9 +775,9 @@ static int mvsd_probe(struct platform_device *pdev)
775 775
776 spin_lock_init(&host->lock); 776 spin_lock_init(&host->lock);
777 777
778 host->base = devm_request_and_ioremap(&pdev->dev, r); 778 host->base = devm_ioremap_resource(&pdev->dev, r);
779 if (!host->base) { 779 if (IS_ERR(host->base)) {
780 ret = -ENOMEM; 780 ret = PTR_ERR(host->base);
781 goto out; 781 goto out;
782 } 782 }
783 783
@@ -838,33 +838,6 @@ static int mvsd_remove(struct platform_device *pdev)
838 return 0; 838 return 0;
839} 839}
840 840
841#ifdef CONFIG_PM
842static int mvsd_suspend(struct platform_device *dev, pm_message_t state)
843{
844 struct mmc_host *mmc = platform_get_drvdata(dev);
845 int ret = 0;
846
847 if (mmc)
848 ret = mmc_suspend_host(mmc);
849
850 return ret;
851}
852
853static int mvsd_resume(struct platform_device *dev)
854{
855 struct mmc_host *mmc = platform_get_drvdata(dev);
856 int ret = 0;
857
858 if (mmc)
859 ret = mmc_resume_host(mmc);
860
861 return ret;
862}
863#else
864#define mvsd_suspend NULL
865#define mvsd_resume NULL
866#endif
867
868static const struct of_device_id mvsdio_dt_ids[] = { 841static const struct of_device_id mvsdio_dt_ids[] = {
869 { .compatible = "marvell,orion-sdio" }, 842 { .compatible = "marvell,orion-sdio" },
870 { /* sentinel */ } 843 { /* sentinel */ }
@@ -874,8 +847,6 @@ MODULE_DEVICE_TABLE(of, mvsdio_dt_ids);
874static struct platform_driver mvsd_driver = { 847static struct platform_driver mvsd_driver = {
875 .probe = mvsd_probe, 848 .probe = mvsd_probe,
876 .remove = mvsd_remove, 849 .remove = mvsd_remove,
877 .suspend = mvsd_suspend,
878 .resume = mvsd_resume,
879 .driver = { 850 .driver = {
880 .name = DRIVER_NAME, 851 .name = DRIVER_NAME,
881 .of_match_table = mvsdio_dt_ids, 852 .of_match_table = mvsdio_dt_ids,
diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c
index c174c6a0d224..f7199c83f5cf 100644
--- a/drivers/mmc/host/mxcmmc.c
+++ b/drivers/mmc/host/mxcmmc.c
@@ -1250,28 +1250,20 @@ static int mxcmci_suspend(struct device *dev)
1250{ 1250{
1251 struct mmc_host *mmc = dev_get_drvdata(dev); 1251 struct mmc_host *mmc = dev_get_drvdata(dev);
1252 struct mxcmci_host *host = mmc_priv(mmc); 1252 struct mxcmci_host *host = mmc_priv(mmc);
1253 int ret = 0;
1254 1253
1255 if (mmc)
1256 ret = mmc_suspend_host(mmc);
1257 clk_disable_unprepare(host->clk_per); 1254 clk_disable_unprepare(host->clk_per);
1258 clk_disable_unprepare(host->clk_ipg); 1255 clk_disable_unprepare(host->clk_ipg);
1259 1256 return 0;
1260 return ret;
1261} 1257}
1262 1258
1263static int mxcmci_resume(struct device *dev) 1259static int mxcmci_resume(struct device *dev)
1264{ 1260{
1265 struct mmc_host *mmc = dev_get_drvdata(dev); 1261 struct mmc_host *mmc = dev_get_drvdata(dev);
1266 struct mxcmci_host *host = mmc_priv(mmc); 1262 struct mxcmci_host *host = mmc_priv(mmc);
1267 int ret = 0;
1268 1263
1269 clk_prepare_enable(host->clk_per); 1264 clk_prepare_enable(host->clk_per);
1270 clk_prepare_enable(host->clk_ipg); 1265 clk_prepare_enable(host->clk_ipg);
1271 if (mmc) 1266 return 0;
1272 ret = mmc_resume_host(mmc);
1273
1274 return ret;
1275} 1267}
1276 1268
1277static const struct dev_pm_ops mxcmci_pm_ops = { 1269static const struct dev_pm_ops mxcmci_pm_ops = {
diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c
index e1fa3ef735e0..50fc9df791b2 100644
--- a/drivers/mmc/host/mxs-mmc.c
+++ b/drivers/mmc/host/mxs-mmc.c
@@ -724,13 +724,9 @@ static int mxs_mmc_suspend(struct device *dev)
724 struct mmc_host *mmc = dev_get_drvdata(dev); 724 struct mmc_host *mmc = dev_get_drvdata(dev);
725 struct mxs_mmc_host *host = mmc_priv(mmc); 725 struct mxs_mmc_host *host = mmc_priv(mmc);
726 struct mxs_ssp *ssp = &host->ssp; 726 struct mxs_ssp *ssp = &host->ssp;
727 int ret = 0;
728
729 ret = mmc_suspend_host(mmc);
730 727
731 clk_disable_unprepare(ssp->clk); 728 clk_disable_unprepare(ssp->clk);
732 729 return 0;
733 return ret;
734} 730}
735 731
736static int mxs_mmc_resume(struct device *dev) 732static int mxs_mmc_resume(struct device *dev)
@@ -738,13 +734,9 @@ static int mxs_mmc_resume(struct device *dev)
738 struct mmc_host *mmc = dev_get_drvdata(dev); 734 struct mmc_host *mmc = dev_get_drvdata(dev);
739 struct mxs_mmc_host *host = mmc_priv(mmc); 735 struct mxs_mmc_host *host = mmc_priv(mmc);
740 struct mxs_ssp *ssp = &host->ssp; 736 struct mxs_ssp *ssp = &host->ssp;
741 int ret = 0;
742 737
743 clk_prepare_enable(ssp->clk); 738 clk_prepare_enable(ssp->clk);
744 739 return 0;
745 ret = mmc_resume_host(mmc);
746
747 return ret;
748} 740}
749 741
750static const struct dev_pm_ops mxs_mmc_pm_ops = { 742static const struct dev_pm_ops mxs_mmc_pm_ops = {
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index b94f38ec2a83..0b10a9030f4e 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -128,7 +128,6 @@ struct mmc_omap_slot {
128 128
129struct mmc_omap_host { 129struct mmc_omap_host {
130 int initialized; 130 int initialized;
131 int suspended;
132 struct mmc_request * mrq; 131 struct mmc_request * mrq;
133 struct mmc_command * cmd; 132 struct mmc_command * cmd;
134 struct mmc_data * data; 133 struct mmc_data * data;
@@ -1513,61 +1512,9 @@ static int mmc_omap_remove(struct platform_device *pdev)
1513 return 0; 1512 return 0;
1514} 1513}
1515 1514
1516#ifdef CONFIG_PM
1517static int mmc_omap_suspend(struct platform_device *pdev, pm_message_t mesg)
1518{
1519 int i, ret = 0;
1520 struct mmc_omap_host *host = platform_get_drvdata(pdev);
1521
1522 if (host == NULL || host->suspended)
1523 return 0;
1524
1525 for (i = 0; i < host->nr_slots; i++) {
1526 struct mmc_omap_slot *slot;
1527
1528 slot = host->slots[i];
1529 ret = mmc_suspend_host(slot->mmc);
1530 if (ret < 0) {
1531 while (--i >= 0) {
1532 slot = host->slots[i];
1533 mmc_resume_host(slot->mmc);
1534 }
1535 return ret;
1536 }
1537 }
1538 host->suspended = 1;
1539 return 0;
1540}
1541
1542static int mmc_omap_resume(struct platform_device *pdev)
1543{
1544 int i, ret = 0;
1545 struct mmc_omap_host *host = platform_get_drvdata(pdev);
1546
1547 if (host == NULL || !host->suspended)
1548 return 0;
1549
1550 for (i = 0; i < host->nr_slots; i++) {
1551 struct mmc_omap_slot *slot;
1552 slot = host->slots[i];
1553 ret = mmc_resume_host(slot->mmc);
1554 if (ret < 0)
1555 return ret;
1556
1557 host->suspended = 0;
1558 }
1559 return 0;
1560}
1561#else
1562#define mmc_omap_suspend NULL
1563#define mmc_omap_resume NULL
1564#endif
1565
1566static struct platform_driver mmc_omap_driver = { 1515static struct platform_driver mmc_omap_driver = {
1567 .probe = mmc_omap_probe, 1516 .probe = mmc_omap_probe,
1568 .remove = mmc_omap_remove, 1517 .remove = mmc_omap_remove,
1569 .suspend = mmc_omap_suspend,
1570 .resume = mmc_omap_resume,
1571 .driver = { 1518 .driver = {
1572 .name = DRIVER_NAME, 1519 .name = DRIVER_NAME,
1573 .owner = THIS_MODULE, 1520 .owner = THIS_MODULE,
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 6ac63df645c4..dbd32ad3b749 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -75,6 +75,7 @@
75#define ICE 0x1 75#define ICE 0x1
76#define ICS 0x2 76#define ICS 0x2
77#define CEN (1 << 2) 77#define CEN (1 << 2)
78#define CLKD_MAX 0x3FF /* max clock divisor: 1023 */
78#define CLKD_MASK 0x0000FFC0 79#define CLKD_MASK 0x0000FFC0
79#define CLKD_SHIFT 6 80#define CLKD_SHIFT 6
80#define DTO_MASK 0x000F0000 81#define DTO_MASK 0x000F0000
@@ -119,7 +120,8 @@
119 BRR_EN | BWR_EN | TC_EN | CC_EN) 120 BRR_EN | BWR_EN | TC_EN | CC_EN)
120 121
121#define MMC_AUTOSUSPEND_DELAY 100 122#define MMC_AUTOSUSPEND_DELAY 100
122#define MMC_TIMEOUT_MS 20 123#define MMC_TIMEOUT_MS 20 /* 20 mSec */
124#define MMC_TIMEOUT_US 20000 /* 20000 micro Sec */
123#define OMAP_MMC_MIN_CLOCK 400000 125#define OMAP_MMC_MIN_CLOCK 400000
124#define OMAP_MMC_MAX_CLOCK 52000000 126#define OMAP_MMC_MAX_CLOCK 52000000
125#define DRIVER_NAME "omap_hsmmc" 127#define DRIVER_NAME "omap_hsmmc"
@@ -171,6 +173,10 @@ struct omap_hsmmc_host {
171 unsigned char bus_mode; 173 unsigned char bus_mode;
172 unsigned char power_mode; 174 unsigned char power_mode;
173 int suspended; 175 int suspended;
176 u32 con;
177 u32 hctl;
178 u32 sysctl;
179 u32 capa;
174 int irq; 180 int irq;
175 int use_dma, dma_ch; 181 int use_dma, dma_ch;
176 struct dma_chan *tx_chan; 182 struct dma_chan *tx_chan;
@@ -183,7 +189,6 @@ struct omap_hsmmc_host {
183 int use_reg; 189 int use_reg;
184 int req_in_progress; 190 int req_in_progress;
185 struct omap_hsmmc_next next_data; 191 struct omap_hsmmc_next next_data;
186
187 struct omap_mmc_platform_data *pdata; 192 struct omap_mmc_platform_data *pdata;
188}; 193};
189 194
@@ -493,8 +498,8 @@ static u16 calc_divisor(struct omap_hsmmc_host *host, struct mmc_ios *ios)
493 498
494 if (ios->clock) { 499 if (ios->clock) {
495 dsor = DIV_ROUND_UP(clk_get_rate(host->fclk), ios->clock); 500 dsor = DIV_ROUND_UP(clk_get_rate(host->fclk), ios->clock);
496 if (dsor > 250) 501 if (dsor > CLKD_MAX)
497 dsor = 250; 502 dsor = CLKD_MAX;
498 } 503 }
499 504
500 return dsor; 505 return dsor;
@@ -597,25 +602,20 @@ static void omap_hsmmc_set_bus_mode(struct omap_hsmmc_host *host)
597static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host) 602static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
598{ 603{
599 struct mmc_ios *ios = &host->mmc->ios; 604 struct mmc_ios *ios = &host->mmc->ios;
600 struct omap_mmc_platform_data *pdata = host->pdata;
601 int context_loss = 0;
602 u32 hctl, capa; 605 u32 hctl, capa;
603 unsigned long timeout; 606 unsigned long timeout;
604 607
605 if (pdata->get_context_loss_count) {
606 context_loss = pdata->get_context_loss_count(host->dev);
607 if (context_loss < 0)
608 return 1;
609 }
610
611 dev_dbg(mmc_dev(host->mmc), "context was %slost\n",
612 context_loss == host->context_loss ? "not " : "");
613 if (host->context_loss == context_loss)
614 return 1;
615
616 if (!OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE) 608 if (!OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE)
617 return 1; 609 return 1;
618 610
611 if (host->con == OMAP_HSMMC_READ(host->base, CON) &&
612 host->hctl == OMAP_HSMMC_READ(host->base, HCTL) &&
613 host->sysctl == OMAP_HSMMC_READ(host->base, SYSCTL) &&
614 host->capa == OMAP_HSMMC_READ(host->base, CAPA))
615 return 0;
616
617 host->context_loss++;
618
619 if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { 619 if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) {
620 if (host->power_mode != MMC_POWER_OFF && 620 if (host->power_mode != MMC_POWER_OFF &&
621 (1 << ios->vdd) <= MMC_VDD_23_24) 621 (1 << ios->vdd) <= MMC_VDD_23_24)
@@ -655,9 +655,8 @@ static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
655 omap_hsmmc_set_bus_mode(host); 655 omap_hsmmc_set_bus_mode(host);
656 656
657out: 657out:
658 host->context_loss = context_loss; 658 dev_dbg(mmc_dev(host->mmc), "context is restored: restore count %d\n",
659 659 host->context_loss);
660 dev_dbg(mmc_dev(host->mmc), "context is restored\n");
661 return 0; 660 return 0;
662} 661}
663 662
@@ -666,15 +665,10 @@ out:
666 */ 665 */
667static void omap_hsmmc_context_save(struct omap_hsmmc_host *host) 666static void omap_hsmmc_context_save(struct omap_hsmmc_host *host)
668{ 667{
669 struct omap_mmc_platform_data *pdata = host->pdata; 668 host->con = OMAP_HSMMC_READ(host->base, CON);
670 int context_loss; 669 host->hctl = OMAP_HSMMC_READ(host->base, HCTL);
671 670 host->sysctl = OMAP_HSMMC_READ(host->base, SYSCTL);
672 if (pdata->get_context_loss_count) { 671 host->capa = OMAP_HSMMC_READ(host->base, CAPA);
673 context_loss = pdata->get_context_loss_count(host->dev);
674 if (context_loss < 0)
675 return;
676 host->context_loss = context_loss;
677 }
678} 672}
679 673
680#else 674#else
@@ -975,8 +969,7 @@ static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host *host,
975 unsigned long bit) 969 unsigned long bit)
976{ 970{
977 unsigned long i = 0; 971 unsigned long i = 0;
978 unsigned long limit = (loops_per_jiffy * 972 unsigned long limit = MMC_TIMEOUT_US;
979 msecs_to_jiffies(MMC_TIMEOUT_MS));
980 973
981 OMAP_HSMMC_WRITE(host->base, SYSCTL, 974 OMAP_HSMMC_WRITE(host->base, SYSCTL,
982 OMAP_HSMMC_READ(host->base, SYSCTL) | bit); 975 OMAP_HSMMC_READ(host->base, SYSCTL) | bit);
@@ -988,13 +981,13 @@ static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host *host,
988 if (mmc_slot(host).features & HSMMC_HAS_UPDATED_RESET) { 981 if (mmc_slot(host).features & HSMMC_HAS_UPDATED_RESET) {
989 while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit)) 982 while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit))
990 && (i++ < limit)) 983 && (i++ < limit))
991 cpu_relax(); 984 udelay(1);
992 } 985 }
993 i = 0; 986 i = 0;
994 987
995 while ((OMAP_HSMMC_READ(host->base, SYSCTL) & bit) && 988 while ((OMAP_HSMMC_READ(host->base, SYSCTL) & bit) &&
996 (i++ < limit)) 989 (i++ < limit))
997 cpu_relax(); 990 udelay(1);
998 991
999 if (OMAP_HSMMC_READ(host->base, SYSCTL) & bit) 992 if (OMAP_HSMMC_READ(host->base, SYSCTL) & bit)
1000 dev_err(mmc_dev(host->mmc), 993 dev_err(mmc_dev(host->mmc),
@@ -1178,9 +1171,6 @@ static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id)
1178 struct omap_mmc_slot_data *slot = &mmc_slot(host); 1171 struct omap_mmc_slot_data *slot = &mmc_slot(host);
1179 int carddetect; 1172 int carddetect;
1180 1173
1181 if (host->suspended)
1182 return IRQ_HANDLED;
1183
1184 sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch"); 1174 sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
1185 1175
1186 if (slot->card_detect) 1176 if (slot->card_detect)
@@ -1635,18 +1625,9 @@ static int omap_hsmmc_regs_show(struct seq_file *s, void *data)
1635{ 1625{
1636 struct mmc_host *mmc = s->private; 1626 struct mmc_host *mmc = s->private;
1637 struct omap_hsmmc_host *host = mmc_priv(mmc); 1627 struct omap_hsmmc_host *host = mmc_priv(mmc);
1638 int context_loss = 0;
1639
1640 if (host->pdata->get_context_loss_count)
1641 context_loss = host->pdata->get_context_loss_count(host->dev);
1642 1628
1643 seq_printf(s, "mmc%d:\n ctx_loss:\t%d:%d\n\nregs:\n", 1629 seq_printf(s, "mmc%d:\n ctx_loss:\t%d\n\nregs:\n",
1644 mmc->index, host->context_loss, context_loss); 1630 mmc->index, host->context_loss);
1645
1646 if (host->suspended) {
1647 seq_printf(s, "host suspended, can't read registers\n");
1648 return 0;
1649 }
1650 1631
1651 pm_runtime_get_sync(host->dev); 1632 pm_runtime_get_sync(host->dev);
1652 1633
@@ -1838,13 +1819,6 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
1838 1819
1839 mmc->ops = &omap_hsmmc_ops; 1820 mmc->ops = &omap_hsmmc_ops;
1840 1821
1841 /*
1842 * If regulator_disable can only put vcc_aux to sleep then there is
1843 * no off state.
1844 */
1845 if (mmc_slot(host).vcc_aux_disable_is_sleep)
1846 mmc_slot(host).no_off = 1;
1847
1848 mmc->f_min = OMAP_MMC_MIN_CLOCK; 1822 mmc->f_min = OMAP_MMC_MIN_CLOCK;
1849 1823
1850 if (pdata->max_freq > 0) 1824 if (pdata->max_freq > 0)
@@ -1874,7 +1848,7 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
1874 omap_hsmmc_context_save(host); 1848 omap_hsmmc_context_save(host);
1875 1849
1876 /* This can be removed once we support PBIAS with DT */ 1850 /* This can be removed once we support PBIAS with DT */
1877 if (host->dev->of_node && host->mapbase == 0x4809c000) 1851 if (host->dev->of_node && res->start == 0x4809c000)
1878 host->pbias_disable = 1; 1852 host->pbias_disable = 1;
1879 1853
1880 host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck"); 1854 host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck");
@@ -2119,23 +2093,12 @@ static void omap_hsmmc_complete(struct device *dev)
2119 2093
2120static int omap_hsmmc_suspend(struct device *dev) 2094static int omap_hsmmc_suspend(struct device *dev)
2121{ 2095{
2122 int ret = 0;
2123 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 2096 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
2124 2097
2125 if (!host) 2098 if (!host)
2126 return 0; 2099 return 0;
2127 2100
2128 if (host && host->suspended)
2129 return 0;
2130
2131 pm_runtime_get_sync(host->dev); 2101 pm_runtime_get_sync(host->dev);
2132 host->suspended = 1;
2133 ret = mmc_suspend_host(host->mmc);
2134
2135 if (ret) {
2136 host->suspended = 0;
2137 goto err;
2138 }
2139 2102
2140 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) { 2103 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) {
2141 omap_hsmmc_disable_irq(host); 2104 omap_hsmmc_disable_irq(host);
@@ -2145,23 +2108,19 @@ static int omap_hsmmc_suspend(struct device *dev)
2145 2108
2146 if (host->dbclk) 2109 if (host->dbclk)
2147 clk_disable_unprepare(host->dbclk); 2110 clk_disable_unprepare(host->dbclk);
2148err: 2111
2149 pm_runtime_put_sync(host->dev); 2112 pm_runtime_put_sync(host->dev);
2150 return ret; 2113 return 0;
2151} 2114}
2152 2115
2153/* Routine to resume the MMC device */ 2116/* Routine to resume the MMC device */
2154static int omap_hsmmc_resume(struct device *dev) 2117static int omap_hsmmc_resume(struct device *dev)
2155{ 2118{
2156 int ret = 0;
2157 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 2119 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
2158 2120
2159 if (!host) 2121 if (!host)
2160 return 0; 2122 return 0;
2161 2123
2162 if (host && !host->suspended)
2163 return 0;
2164
2165 pm_runtime_get_sync(host->dev); 2124 pm_runtime_get_sync(host->dev);
2166 2125
2167 if (host->dbclk) 2126 if (host->dbclk)
@@ -2172,16 +2131,9 @@ static int omap_hsmmc_resume(struct device *dev)
2172 2131
2173 omap_hsmmc_protect_card(host); 2132 omap_hsmmc_protect_card(host);
2174 2133
2175 /* Notify the core to resume the host */
2176 ret = mmc_resume_host(host->mmc);
2177 if (ret == 0)
2178 host->suspended = 0;
2179
2180 pm_runtime_mark_last_busy(host->dev); 2134 pm_runtime_mark_last_busy(host->dev);
2181 pm_runtime_put_autosuspend(host->dev); 2135 pm_runtime_put_autosuspend(host->dev);
2182 2136 return 0;
2183 return ret;
2184
2185} 2137}
2186 2138
2187#else 2139#else
diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
index 1956a3df7cf3..32fe11323f39 100644
--- a/drivers/mmc/host/pxamci.c
+++ b/drivers/mmc/host/pxamci.c
@@ -880,35 +880,6 @@ static int pxamci_remove(struct platform_device *pdev)
880 return 0; 880 return 0;
881} 881}
882 882
883#ifdef CONFIG_PM
884static int pxamci_suspend(struct device *dev)
885{
886 struct mmc_host *mmc = dev_get_drvdata(dev);
887 int ret = 0;
888
889 if (mmc)
890 ret = mmc_suspend_host(mmc);
891
892 return ret;
893}
894
895static int pxamci_resume(struct device *dev)
896{
897 struct mmc_host *mmc = dev_get_drvdata(dev);
898 int ret = 0;
899
900 if (mmc)
901 ret = mmc_resume_host(mmc);
902
903 return ret;
904}
905
906static const struct dev_pm_ops pxamci_pm_ops = {
907 .suspend = pxamci_suspend,
908 .resume = pxamci_resume,
909};
910#endif
911
912static struct platform_driver pxamci_driver = { 883static struct platform_driver pxamci_driver = {
913 .probe = pxamci_probe, 884 .probe = pxamci_probe,
914 .remove = pxamci_remove, 885 .remove = pxamci_remove,
@@ -916,9 +887,6 @@ static struct platform_driver pxamci_driver = {
916 .name = DRIVER_NAME, 887 .name = DRIVER_NAME,
917 .owner = THIS_MODULE, 888 .owner = THIS_MODULE,
918 .of_match_table = of_match_ptr(pxa_mmc_dt_ids), 889 .of_match_table = of_match_ptr(pxa_mmc_dt_ids),
919#ifdef CONFIG_PM
920 .pm = &pxamci_pm_ops,
921#endif
922 }, 890 },
923}; 891};
924 892
diff --git a/drivers/mmc/host/rtsx_pci_sdmmc.c b/drivers/mmc/host/rtsx_pci_sdmmc.c
index 375a880e0c5f..c46feda07d56 100644
--- a/drivers/mmc/host/rtsx_pci_sdmmc.c
+++ b/drivers/mmc/host/rtsx_pci_sdmmc.c
@@ -364,7 +364,7 @@ static int sd_rw_multi(struct realtek_pci_sdmmc *host, struct mmc_request *mrq)
364 struct mmc_host *mmc = host->mmc; 364 struct mmc_host *mmc = host->mmc;
365 struct mmc_card *card = mmc->card; 365 struct mmc_card *card = mmc->card;
366 struct mmc_data *data = mrq->data; 366 struct mmc_data *data = mrq->data;
367 int uhs = mmc_sd_card_uhs(card); 367 int uhs = mmc_card_uhs(card);
368 int read = (data->flags & MMC_DATA_READ) ? 1 : 0; 368 int read = (data->flags & MMC_DATA_READ) ? 1 : 0;
369 u8 cfg2, trans_mode; 369 u8 cfg2, trans_mode;
370 int err; 370 int err;
@@ -1197,37 +1197,6 @@ static const struct mmc_host_ops realtek_pci_sdmmc_ops = {
1197 .execute_tuning = sdmmc_execute_tuning, 1197 .execute_tuning = sdmmc_execute_tuning,
1198}; 1198};
1199 1199
1200#ifdef CONFIG_PM
1201static int rtsx_pci_sdmmc_suspend(struct platform_device *pdev,
1202 pm_message_t state)
1203{
1204 struct realtek_pci_sdmmc *host = platform_get_drvdata(pdev);
1205 struct mmc_host *mmc = host->mmc;
1206 int err;
1207
1208 dev_dbg(sdmmc_dev(host), "--> %s\n", __func__);
1209
1210 err = mmc_suspend_host(mmc);
1211 if (err)
1212 return err;
1213
1214 return 0;
1215}
1216
1217static int rtsx_pci_sdmmc_resume(struct platform_device *pdev)
1218{
1219 struct realtek_pci_sdmmc *host = platform_get_drvdata(pdev);
1220 struct mmc_host *mmc = host->mmc;
1221
1222 dev_dbg(sdmmc_dev(host), "--> %s\n", __func__);
1223
1224 return mmc_resume_host(mmc);
1225}
1226#else /* CONFIG_PM */
1227#define rtsx_pci_sdmmc_suspend NULL
1228#define rtsx_pci_sdmmc_resume NULL
1229#endif /* CONFIG_PM */
1230
1231static void init_extra_caps(struct realtek_pci_sdmmc *host) 1200static void init_extra_caps(struct realtek_pci_sdmmc *host)
1232{ 1201{
1233 struct mmc_host *mmc = host->mmc; 1202 struct mmc_host *mmc = host->mmc;
@@ -1367,8 +1336,6 @@ static struct platform_driver rtsx_pci_sdmmc_driver = {
1367 .probe = rtsx_pci_sdmmc_drv_probe, 1336 .probe = rtsx_pci_sdmmc_drv_probe,
1368 .remove = rtsx_pci_sdmmc_drv_remove, 1337 .remove = rtsx_pci_sdmmc_drv_remove,
1369 .id_table = rtsx_pci_sdmmc_ids, 1338 .id_table = rtsx_pci_sdmmc_ids,
1370 .suspend = rtsx_pci_sdmmc_suspend,
1371 .resume = rtsx_pci_sdmmc_resume,
1372 .driver = { 1339 .driver = {
1373 .owner = THIS_MODULE, 1340 .owner = THIS_MODULE,
1374 .name = DRV_NAME_RTSX_PCI_SDMMC, 1341 .name = DRV_NAME_RTSX_PCI_SDMMC,
diff --git a/drivers/mmc/host/s3cmci.c b/drivers/mmc/host/s3cmci.c
index 8d6794cdf899..2fce5ea5eb39 100644
--- a/drivers/mmc/host/s3cmci.c
+++ b/drivers/mmc/host/s3cmci.c
@@ -1949,39 +1949,10 @@ static struct platform_device_id s3cmci_driver_ids[] = {
1949 1949
1950MODULE_DEVICE_TABLE(platform, s3cmci_driver_ids); 1950MODULE_DEVICE_TABLE(platform, s3cmci_driver_ids);
1951 1951
1952
1953#ifdef CONFIG_PM
1954
1955static int s3cmci_suspend(struct device *dev)
1956{
1957 struct mmc_host *mmc = platform_get_drvdata(to_platform_device(dev));
1958
1959 return mmc_suspend_host(mmc);
1960}
1961
1962static int s3cmci_resume(struct device *dev)
1963{
1964 struct mmc_host *mmc = platform_get_drvdata(to_platform_device(dev));
1965
1966 return mmc_resume_host(mmc);
1967}
1968
1969static const struct dev_pm_ops s3cmci_pm = {
1970 .suspend = s3cmci_suspend,
1971 .resume = s3cmci_resume,
1972};
1973
1974#define s3cmci_pm_ops &s3cmci_pm
1975#else /* CONFIG_PM */
1976#define s3cmci_pm_ops NULL
1977#endif /* CONFIG_PM */
1978
1979
1980static struct platform_driver s3cmci_driver = { 1952static struct platform_driver s3cmci_driver = {
1981 .driver = { 1953 .driver = {
1982 .name = "s3c-sdi", 1954 .name = "s3c-sdi",
1983 .owner = THIS_MODULE, 1955 .owner = THIS_MODULE,
1984 .pm = s3cmci_pm_ops,
1985 }, 1956 },
1986 .id_table = s3cmci_driver_ids, 1957 .id_table = s3cmci_driver_ids,
1987 .probe = s3cmci_probe, 1958 .probe = s3cmci_probe,
diff --git a/drivers/mmc/host/sdhci-bcm-kona.c b/drivers/mmc/host/sdhci-bcm-kona.c
index 85472d3fd37f..7a190fe4dff1 100644
--- a/drivers/mmc/host/sdhci-bcm-kona.c
+++ b/drivers/mmc/host/sdhci-bcm-kona.c
@@ -316,19 +316,7 @@ err_pltfm_free:
316 316
317static int __exit sdhci_bcm_kona_remove(struct platform_device *pdev) 317static int __exit sdhci_bcm_kona_remove(struct platform_device *pdev)
318{ 318{
319 struct sdhci_host *host = platform_get_drvdata(pdev); 319 return sdhci_pltfm_unregister(pdev);
320 int dead;
321 u32 scratch;
322
323 dead = 0;
324 scratch = readl(host->ioaddr + SDHCI_INT_STATUS);
325 if (scratch == (u32)-1)
326 dead = 1;
327 sdhci_remove_host(host, dead);
328
329 sdhci_free_host(host);
330
331 return 0;
332} 320}
333 321
334static struct platform_driver sdhci_bcm_kona_driver = { 322static struct platform_driver sdhci_bcm_kona_driver = {
diff --git a/drivers/mmc/host/sdhci-bcm2835.c b/drivers/mmc/host/sdhci-bcm2835.c
index 36fa2df04660..f6d8d67c545f 100644
--- a/drivers/mmc/host/sdhci-bcm2835.c
+++ b/drivers/mmc/host/sdhci-bcm2835.c
@@ -178,13 +178,7 @@ err:
178 178
179static int bcm2835_sdhci_remove(struct platform_device *pdev) 179static int bcm2835_sdhci_remove(struct platform_device *pdev)
180{ 180{
181 struct sdhci_host *host = platform_get_drvdata(pdev); 181 return sdhci_pltfm_unregister(pdev);
182 int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
183
184 sdhci_remove_host(host, dead);
185 sdhci_pltfm_free(pdev);
186
187 return 0;
188} 182}
189 183
190static const struct of_device_id bcm2835_sdhci_of_match[] = { 184static const struct of_device_id bcm2835_sdhci_of_match[] = {
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index abc8cf01e6e3..461a4c3f4ef7 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -34,12 +34,40 @@
34/* VENDOR SPEC register */ 34/* VENDOR SPEC register */
35#define ESDHC_VENDOR_SPEC 0xc0 35#define ESDHC_VENDOR_SPEC 0xc0
36#define ESDHC_VENDOR_SPEC_SDIO_QUIRK (1 << 1) 36#define ESDHC_VENDOR_SPEC_SDIO_QUIRK (1 << 1)
37#define ESDHC_VENDOR_SPEC_VSELECT (1 << 1)
38#define ESDHC_VENDOR_SPEC_FRC_SDCLK_ON (1 << 8)
37#define ESDHC_WTMK_LVL 0x44 39#define ESDHC_WTMK_LVL 0x44
38#define ESDHC_MIX_CTRL 0x48 40#define ESDHC_MIX_CTRL 0x48
41#define ESDHC_MIX_CTRL_DDREN (1 << 3)
39#define ESDHC_MIX_CTRL_AC23EN (1 << 7) 42#define ESDHC_MIX_CTRL_AC23EN (1 << 7)
43#define ESDHC_MIX_CTRL_EXE_TUNE (1 << 22)
44#define ESDHC_MIX_CTRL_SMPCLK_SEL (1 << 23)
45#define ESDHC_MIX_CTRL_FBCLK_SEL (1 << 25)
40/* Bits 3 and 6 are not SDHCI standard definitions */ 46/* Bits 3 and 6 are not SDHCI standard definitions */
41#define ESDHC_MIX_CTRL_SDHCI_MASK 0xb7 47#define ESDHC_MIX_CTRL_SDHCI_MASK 0xb7
42 48
49/* dll control register */
50#define ESDHC_DLL_CTRL 0x60
51#define ESDHC_DLL_OVERRIDE_VAL_SHIFT 9
52#define ESDHC_DLL_OVERRIDE_EN_SHIFT 8
53
54/* tune control register */
55#define ESDHC_TUNE_CTRL_STATUS 0x68
56#define ESDHC_TUNE_CTRL_STEP 1
57#define ESDHC_TUNE_CTRL_MIN 0
58#define ESDHC_TUNE_CTRL_MAX ((1 << 7) - 1)
59
60#define ESDHC_TUNING_CTRL 0xcc
61#define ESDHC_STD_TUNING_EN (1 << 24)
62/* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
63#define ESDHC_TUNING_START_TAP 0x1
64
65#define ESDHC_TUNING_BLOCK_PATTERN_LEN 64
66
67/* pinctrl state */
68#define ESDHC_PINCTRL_STATE_100MHZ "state_100mhz"
69#define ESDHC_PINCTRL_STATE_200MHZ "state_200mhz"
70
43/* 71/*
44 * Our interpretation of the SDHCI_HOST_CONTROL register 72 * Our interpretation of the SDHCI_HOST_CONTROL register
45 */ 73 */
@@ -66,21 +94,60 @@
66 * As a result, the TC flag is not asserted and SW received timeout 94 * As a result, the TC flag is not asserted and SW received timeout
67 * exeception. Bit1 of Vendor Spec registor is used to fix it. 95 * exeception. Bit1 of Vendor Spec registor is used to fix it.
68 */ 96 */
69#define ESDHC_FLAG_MULTIBLK_NO_INT (1 << 1) 97#define ESDHC_FLAG_MULTIBLK_NO_INT BIT(1)
70 98/*
71enum imx_esdhc_type { 99 * The flag enables the workaround for ESDHC errata ENGcm07207 which
72 IMX25_ESDHC, 100 * affects i.MX25 and i.MX35.
73 IMX35_ESDHC, 101 */
74 IMX51_ESDHC, 102#define ESDHC_FLAG_ENGCM07207 BIT(2)
75 IMX53_ESDHC, 103/*
76 IMX6Q_USDHC, 104 * The flag tells that the ESDHC controller is an USDHC block that is
105 * integrated on the i.MX6 series.
106 */
107#define ESDHC_FLAG_USDHC BIT(3)
108/* The IP supports manual tuning process */
109#define ESDHC_FLAG_MAN_TUNING BIT(4)
110/* The IP supports standard tuning process */
111#define ESDHC_FLAG_STD_TUNING BIT(5)
112/* The IP has SDHCI_CAPABILITIES_1 register */
113#define ESDHC_FLAG_HAVE_CAP1 BIT(6)
114
115struct esdhc_soc_data {
116 u32 flags;
117};
118
119static struct esdhc_soc_data esdhc_imx25_data = {
120 .flags = ESDHC_FLAG_ENGCM07207,
121};
122
123static struct esdhc_soc_data esdhc_imx35_data = {
124 .flags = ESDHC_FLAG_ENGCM07207,
125};
126
127static struct esdhc_soc_data esdhc_imx51_data = {
128 .flags = 0,
129};
130
131static struct esdhc_soc_data esdhc_imx53_data = {
132 .flags = ESDHC_FLAG_MULTIBLK_NO_INT,
133};
134
135static struct esdhc_soc_data usdhc_imx6q_data = {
136 .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_MAN_TUNING,
137};
138
139static struct esdhc_soc_data usdhc_imx6sl_data = {
140 .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
141 | ESDHC_FLAG_HAVE_CAP1,
77}; 142};
78 143
79struct pltfm_imx_data { 144struct pltfm_imx_data {
80 int flags;
81 u32 scratchpad; 145 u32 scratchpad;
82 enum imx_esdhc_type devtype;
83 struct pinctrl *pinctrl; 146 struct pinctrl *pinctrl;
147 struct pinctrl_state *pins_default;
148 struct pinctrl_state *pins_100mhz;
149 struct pinctrl_state *pins_200mhz;
150 const struct esdhc_soc_data *socdata;
84 struct esdhc_platform_data boarddata; 151 struct esdhc_platform_data boarddata;
85 struct clk *clk_ipg; 152 struct clk *clk_ipg;
86 struct clk *clk_ahb; 153 struct clk *clk_ahb;
@@ -90,25 +157,20 @@ struct pltfm_imx_data {
90 MULTIBLK_IN_PROCESS, /* exact multiblock cmd in process */ 157 MULTIBLK_IN_PROCESS, /* exact multiblock cmd in process */
91 WAIT_FOR_INT, /* sent CMD12, waiting for response INT */ 158 WAIT_FOR_INT, /* sent CMD12, waiting for response INT */
92 } multiblock_status; 159 } multiblock_status;
93 160 u32 uhs_mode;
161 u32 is_ddr;
94}; 162};
95 163
96static struct platform_device_id imx_esdhc_devtype[] = { 164static struct platform_device_id imx_esdhc_devtype[] = {
97 { 165 {
98 .name = "sdhci-esdhc-imx25", 166 .name = "sdhci-esdhc-imx25",
99 .driver_data = IMX25_ESDHC, 167 .driver_data = (kernel_ulong_t) &esdhc_imx25_data,
100 }, { 168 }, {
101 .name = "sdhci-esdhc-imx35", 169 .name = "sdhci-esdhc-imx35",
102 .driver_data = IMX35_ESDHC, 170 .driver_data = (kernel_ulong_t) &esdhc_imx35_data,
103 }, { 171 }, {
104 .name = "sdhci-esdhc-imx51", 172 .name = "sdhci-esdhc-imx51",
105 .driver_data = IMX51_ESDHC, 173 .driver_data = (kernel_ulong_t) &esdhc_imx51_data,
106 }, {
107 .name = "sdhci-esdhc-imx53",
108 .driver_data = IMX53_ESDHC,
109 }, {
110 .name = "sdhci-usdhc-imx6q",
111 .driver_data = IMX6Q_USDHC,
112 }, { 174 }, {
113 /* sentinel */ 175 /* sentinel */
114 } 176 }
@@ -116,38 +178,34 @@ static struct platform_device_id imx_esdhc_devtype[] = {
116MODULE_DEVICE_TABLE(platform, imx_esdhc_devtype); 178MODULE_DEVICE_TABLE(platform, imx_esdhc_devtype);
117 179
118static const struct of_device_id imx_esdhc_dt_ids[] = { 180static const struct of_device_id imx_esdhc_dt_ids[] = {
119 { .compatible = "fsl,imx25-esdhc", .data = &imx_esdhc_devtype[IMX25_ESDHC], }, 181 { .compatible = "fsl,imx25-esdhc", .data = &esdhc_imx25_data, },
120 { .compatible = "fsl,imx35-esdhc", .data = &imx_esdhc_devtype[IMX35_ESDHC], }, 182 { .compatible = "fsl,imx35-esdhc", .data = &esdhc_imx35_data, },
121 { .compatible = "fsl,imx51-esdhc", .data = &imx_esdhc_devtype[IMX51_ESDHC], }, 183 { .compatible = "fsl,imx51-esdhc", .data = &esdhc_imx51_data, },
122 { .compatible = "fsl,imx53-esdhc", .data = &imx_esdhc_devtype[IMX53_ESDHC], }, 184 { .compatible = "fsl,imx53-esdhc", .data = &esdhc_imx53_data, },
123 { .compatible = "fsl,imx6q-usdhc", .data = &imx_esdhc_devtype[IMX6Q_USDHC], }, 185 { .compatible = "fsl,imx6sl-usdhc", .data = &usdhc_imx6sl_data, },
186 { .compatible = "fsl,imx6q-usdhc", .data = &usdhc_imx6q_data, },
124 { /* sentinel */ } 187 { /* sentinel */ }
125}; 188};
126MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids); 189MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids);
127 190
128static inline int is_imx25_esdhc(struct pltfm_imx_data *data) 191static inline int is_imx25_esdhc(struct pltfm_imx_data *data)
129{ 192{
130 return data->devtype == IMX25_ESDHC; 193 return data->socdata == &esdhc_imx25_data;
131}
132
133static inline int is_imx35_esdhc(struct pltfm_imx_data *data)
134{
135 return data->devtype == IMX35_ESDHC;
136} 194}
137 195
138static inline int is_imx51_esdhc(struct pltfm_imx_data *data) 196static inline int is_imx53_esdhc(struct pltfm_imx_data *data)
139{ 197{
140 return data->devtype == IMX51_ESDHC; 198 return data->socdata == &esdhc_imx53_data;
141} 199}
142 200
143static inline int is_imx53_esdhc(struct pltfm_imx_data *data) 201static inline int is_imx6q_usdhc(struct pltfm_imx_data *data)
144{ 202{
145 return data->devtype == IMX53_ESDHC; 203 return data->socdata == &usdhc_imx6q_data;
146} 204}
147 205
148static inline int is_imx6q_usdhc(struct pltfm_imx_data *data) 206static inline int esdhc_is_usdhc(struct pltfm_imx_data *data)
149{ 207{
150 return data->devtype == IMX6Q_USDHC; 208 return !!(data->socdata->flags & ESDHC_FLAG_USDHC);
151} 209}
152 210
153static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg) 211static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg)
@@ -164,7 +222,21 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
164 struct pltfm_imx_data *imx_data = pltfm_host->priv; 222 struct pltfm_imx_data *imx_data = pltfm_host->priv;
165 u32 val = readl(host->ioaddr + reg); 223 u32 val = readl(host->ioaddr + reg);
166 224
225 if (unlikely(reg == SDHCI_PRESENT_STATE)) {
226 u32 fsl_prss = val;
227 /* save the least 20 bits */
228 val = fsl_prss & 0x000FFFFF;
229 /* move dat[0-3] bits */
230 val |= (fsl_prss & 0x0F000000) >> 4;
231 /* move cmd line bit */
232 val |= (fsl_prss & 0x00800000) << 1;
233 }
234
167 if (unlikely(reg == SDHCI_CAPABILITIES)) { 235 if (unlikely(reg == SDHCI_CAPABILITIES)) {
236 /* ignore bit[0-15] as it stores cap_1 register val for mx6sl */
237 if (imx_data->socdata->flags & ESDHC_FLAG_HAVE_CAP1)
238 val &= 0xffff0000;
239
168 /* In FSL esdhc IC module, only bit20 is used to indicate the 240 /* In FSL esdhc IC module, only bit20 is used to indicate the
169 * ADMA2 capability of esdhc, but this bit is messed up on 241 * ADMA2 capability of esdhc, but this bit is messed up on
170 * some SOCs (e.g. on MX25, MX35 this bit is set, but they 242 * some SOCs (e.g. on MX25, MX35 this bit is set, but they
@@ -178,6 +250,25 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
178 } 250 }
179 } 251 }
180 252
253 if (unlikely(reg == SDHCI_CAPABILITIES_1)) {
254 if (esdhc_is_usdhc(imx_data)) {
255 if (imx_data->socdata->flags & ESDHC_FLAG_HAVE_CAP1)
256 val = readl(host->ioaddr + SDHCI_CAPABILITIES) & 0xFFFF;
257 else
258 /* imx6q/dl does not have cap_1 register, fake one */
259 val = SDHCI_SUPPORT_DDR50 | SDHCI_SUPPORT_SDR104
260 | SDHCI_SUPPORT_SDR50
261 | SDHCI_USE_SDR50_TUNING;
262 }
263 }
264
265 if (unlikely(reg == SDHCI_MAX_CURRENT) && esdhc_is_usdhc(imx_data)) {
266 val = 0;
267 val |= 0xFF << SDHCI_MAX_CURRENT_330_SHIFT;
268 val |= 0xFF << SDHCI_MAX_CURRENT_300_SHIFT;
269 val |= 0xFF << SDHCI_MAX_CURRENT_180_SHIFT;
270 }
271
181 if (unlikely(reg == SDHCI_INT_STATUS)) { 272 if (unlikely(reg == SDHCI_INT_STATUS)) {
182 if (val & ESDHC_INT_VENDOR_SPEC_DMA_ERR) { 273 if (val & ESDHC_INT_VENDOR_SPEC_DMA_ERR) {
183 val &= ~ESDHC_INT_VENDOR_SPEC_DMA_ERR; 274 val &= ~ESDHC_INT_VENDOR_SPEC_DMA_ERR;
@@ -224,7 +315,7 @@ static void esdhc_writel_le(struct sdhci_host *host, u32 val, int reg)
224 } 315 }
225 } 316 }
226 317
227 if (unlikely((imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT) 318 if (unlikely((imx_data->socdata->flags & ESDHC_FLAG_MULTIBLK_NO_INT)
228 && (reg == SDHCI_INT_STATUS) 319 && (reg == SDHCI_INT_STATUS)
229 && (val & SDHCI_INT_DATA_END))) { 320 && (val & SDHCI_INT_DATA_END))) {
230 u32 v; 321 u32 v;
@@ -256,10 +347,12 @@ static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
256{ 347{
257 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 348 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
258 struct pltfm_imx_data *imx_data = pltfm_host->priv; 349 struct pltfm_imx_data *imx_data = pltfm_host->priv;
350 u16 ret = 0;
351 u32 val;
259 352
260 if (unlikely(reg == SDHCI_HOST_VERSION)) { 353 if (unlikely(reg == SDHCI_HOST_VERSION)) {
261 reg ^= 2; 354 reg ^= 2;
262 if (is_imx6q_usdhc(imx_data)) { 355 if (esdhc_is_usdhc(imx_data)) {
263 /* 356 /*
264 * The usdhc register returns a wrong host version. 357 * The usdhc register returns a wrong host version.
265 * Correct it here. 358 * Correct it here.
@@ -268,6 +361,30 @@ static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
268 } 361 }
269 } 362 }
270 363
364 if (unlikely(reg == SDHCI_HOST_CONTROL2)) {
365 val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
366 if (val & ESDHC_VENDOR_SPEC_VSELECT)
367 ret |= SDHCI_CTRL_VDD_180;
368
369 if (esdhc_is_usdhc(imx_data)) {
370 if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
371 val = readl(host->ioaddr + ESDHC_MIX_CTRL);
372 else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
373 /* the std tuning bits is in ACMD12_ERR for imx6sl */
374 val = readl(host->ioaddr + SDHCI_ACMD12_ERR);
375 }
376
377 if (val & ESDHC_MIX_CTRL_EXE_TUNE)
378 ret |= SDHCI_CTRL_EXEC_TUNING;
379 if (val & ESDHC_MIX_CTRL_SMPCLK_SEL)
380 ret |= SDHCI_CTRL_TUNED_CLK;
381
382 ret |= (imx_data->uhs_mode & SDHCI_CTRL_UHS_MASK);
383 ret &= ~SDHCI_CTRL_PRESET_VAL_ENABLE;
384
385 return ret;
386 }
387
271 return readw(host->ioaddr + reg); 388 return readw(host->ioaddr + reg);
272} 389}
273 390
@@ -275,10 +392,59 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
275{ 392{
276 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 393 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
277 struct pltfm_imx_data *imx_data = pltfm_host->priv; 394 struct pltfm_imx_data *imx_data = pltfm_host->priv;
395 u32 new_val = 0;
278 396
279 switch (reg) { 397 switch (reg) {
398 case SDHCI_CLOCK_CONTROL:
399 new_val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
400 if (val & SDHCI_CLOCK_CARD_EN)
401 new_val |= ESDHC_VENDOR_SPEC_FRC_SDCLK_ON;
402 else
403 new_val &= ~ESDHC_VENDOR_SPEC_FRC_SDCLK_ON;
404 writel(new_val, host->ioaddr + ESDHC_VENDOR_SPEC);
405 return;
406 case SDHCI_HOST_CONTROL2:
407 new_val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
408 if (val & SDHCI_CTRL_VDD_180)
409 new_val |= ESDHC_VENDOR_SPEC_VSELECT;
410 else
411 new_val &= ~ESDHC_VENDOR_SPEC_VSELECT;
412 writel(new_val, host->ioaddr + ESDHC_VENDOR_SPEC);
413 imx_data->uhs_mode = val & SDHCI_CTRL_UHS_MASK;
414 if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
415 new_val = readl(host->ioaddr + ESDHC_MIX_CTRL);
416 if (val & SDHCI_CTRL_TUNED_CLK)
417 new_val |= ESDHC_MIX_CTRL_SMPCLK_SEL;
418 else
419 new_val &= ~ESDHC_MIX_CTRL_SMPCLK_SEL;
420 writel(new_val , host->ioaddr + ESDHC_MIX_CTRL);
421 } else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) {
422 u32 v = readl(host->ioaddr + SDHCI_ACMD12_ERR);
423 u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL);
424 new_val = readl(host->ioaddr + ESDHC_TUNING_CTRL);
425 if (val & SDHCI_CTRL_EXEC_TUNING) {
426 new_val |= ESDHC_STD_TUNING_EN |
427 ESDHC_TUNING_START_TAP;
428 v |= ESDHC_MIX_CTRL_EXE_TUNE;
429 m |= ESDHC_MIX_CTRL_FBCLK_SEL;
430 } else {
431 new_val &= ~ESDHC_STD_TUNING_EN;
432 v &= ~ESDHC_MIX_CTRL_EXE_TUNE;
433 m &= ~ESDHC_MIX_CTRL_FBCLK_SEL;
434 }
435
436 if (val & SDHCI_CTRL_TUNED_CLK)
437 v |= ESDHC_MIX_CTRL_SMPCLK_SEL;
438 else
439 v &= ~ESDHC_MIX_CTRL_SMPCLK_SEL;
440
441 writel(new_val, host->ioaddr + ESDHC_TUNING_CTRL);
442 writel(v, host->ioaddr + SDHCI_ACMD12_ERR);
443 writel(m, host->ioaddr + ESDHC_MIX_CTRL);
444 }
445 return;
280 case SDHCI_TRANSFER_MODE: 446 case SDHCI_TRANSFER_MODE:
281 if ((imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT) 447 if ((imx_data->socdata->flags & ESDHC_FLAG_MULTIBLK_NO_INT)
282 && (host->cmd->opcode == SD_IO_RW_EXTENDED) 448 && (host->cmd->opcode == SD_IO_RW_EXTENDED)
283 && (host->cmd->data->blocks > 1) 449 && (host->cmd->data->blocks > 1)
284 && (host->cmd->data->flags & MMC_DATA_READ)) { 450 && (host->cmd->data->flags & MMC_DATA_READ)) {
@@ -288,7 +454,7 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
288 writel(v, host->ioaddr + ESDHC_VENDOR_SPEC); 454 writel(v, host->ioaddr + ESDHC_VENDOR_SPEC);
289 } 455 }
290 456
291 if (is_imx6q_usdhc(imx_data)) { 457 if (esdhc_is_usdhc(imx_data)) {
292 u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL); 458 u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL);
293 /* Swap AC23 bit */ 459 /* Swap AC23 bit */
294 if (val & SDHCI_TRNS_AUTO_CMD23) { 460 if (val & SDHCI_TRNS_AUTO_CMD23) {
@@ -310,10 +476,10 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
310 val |= SDHCI_CMD_ABORTCMD; 476 val |= SDHCI_CMD_ABORTCMD;
311 477
312 if ((host->cmd->opcode == MMC_SET_BLOCK_COUNT) && 478 if ((host->cmd->opcode == MMC_SET_BLOCK_COUNT) &&
313 (imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT)) 479 (imx_data->socdata->flags & ESDHC_FLAG_MULTIBLK_NO_INT))
314 imx_data->multiblock_status = MULTIBLK_IN_PROCESS; 480 imx_data->multiblock_status = MULTIBLK_IN_PROCESS;
315 481
316 if (is_imx6q_usdhc(imx_data)) 482 if (esdhc_is_usdhc(imx_data))
317 writel(val << 16, 483 writel(val << 16,
318 host->ioaddr + SDHCI_TRANSFER_MODE); 484 host->ioaddr + SDHCI_TRANSFER_MODE);
319 else 485 else
@@ -379,8 +545,10 @@ static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
379 * The reset on usdhc fails to clear MIX_CTRL register. 545 * The reset on usdhc fails to clear MIX_CTRL register.
380 * Do it manually here. 546 * Do it manually here.
381 */ 547 */
382 if (is_imx6q_usdhc(imx_data)) 548 if (esdhc_is_usdhc(imx_data)) {
383 writel(0, host->ioaddr + ESDHC_MIX_CTRL); 549 writel(0, host->ioaddr + ESDHC_MIX_CTRL);
550 imx_data->is_ddr = 0;
551 }
384 } 552 }
385} 553}
386 554
@@ -409,8 +577,60 @@ static inline void esdhc_pltfm_set_clock(struct sdhci_host *host,
409 unsigned int clock) 577 unsigned int clock)
410{ 578{
411 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 579 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
580 struct pltfm_imx_data *imx_data = pltfm_host->priv;
581 unsigned int host_clock = clk_get_rate(pltfm_host->clk);
582 int pre_div = 2;
583 int div = 1;
584 u32 temp, val;
585
586 if (clock == 0) {
587 if (esdhc_is_usdhc(imx_data)) {
588 val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
589 writel(val & ~ESDHC_VENDOR_SPEC_FRC_SDCLK_ON,
590 host->ioaddr + ESDHC_VENDOR_SPEC);
591 }
592 goto out;
593 }
594
595 if (esdhc_is_usdhc(imx_data) && !imx_data->is_ddr)
596 pre_div = 1;
597
598 temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
599 temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
600 | ESDHC_CLOCK_MASK);
601 sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
602
603 while (host_clock / pre_div / 16 > clock && pre_div < 256)
604 pre_div *= 2;
605
606 while (host_clock / pre_div / div > clock && div < 16)
607 div++;
412 608
413 esdhc_set_clock(host, clock, clk_get_rate(pltfm_host->clk)); 609 host->mmc->actual_clock = host_clock / pre_div / div;
610 dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
611 clock, host->mmc->actual_clock);
612
613 if (imx_data->is_ddr)
614 pre_div >>= 2;
615 else
616 pre_div >>= 1;
617 div--;
618
619 temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
620 temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
621 | (div << ESDHC_DIVIDER_SHIFT)
622 | (pre_div << ESDHC_PREDIV_SHIFT));
623 sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
624
625 if (esdhc_is_usdhc(imx_data)) {
626 val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
627 writel(val | ESDHC_VENDOR_SPEC_FRC_SDCLK_ON,
628 host->ioaddr + ESDHC_VENDOR_SPEC);
629 }
630
631 mdelay(1);
632out:
633 host->clock = clock;
414} 634}
415 635
416static unsigned int esdhc_pltfm_get_ro(struct sdhci_host *host) 636static unsigned int esdhc_pltfm_get_ro(struct sdhci_host *host)
@@ -454,7 +674,192 @@ static int esdhc_pltfm_bus_width(struct sdhci_host *host, int width)
454 return 0; 674 return 0;
455} 675}
456 676
457static const struct sdhci_ops sdhci_esdhc_ops = { 677static void esdhc_prepare_tuning(struct sdhci_host *host, u32 val)
678{
679 u32 reg;
680
681 /* FIXME: delay a bit for card to be ready for next tuning due to errors */
682 mdelay(1);
683
684 reg = readl(host->ioaddr + ESDHC_MIX_CTRL);
685 reg |= ESDHC_MIX_CTRL_EXE_TUNE | ESDHC_MIX_CTRL_SMPCLK_SEL |
686 ESDHC_MIX_CTRL_FBCLK_SEL;
687 writel(reg, host->ioaddr + ESDHC_MIX_CTRL);
688 writel(val << 8, host->ioaddr + ESDHC_TUNE_CTRL_STATUS);
689 dev_dbg(mmc_dev(host->mmc),
690 "tunning with delay 0x%x ESDHC_TUNE_CTRL_STATUS 0x%x\n",
691 val, readl(host->ioaddr + ESDHC_TUNE_CTRL_STATUS));
692}
693
694static void esdhc_request_done(struct mmc_request *mrq)
695{
696 complete(&mrq->completion);
697}
698
699static int esdhc_send_tuning_cmd(struct sdhci_host *host, u32 opcode)
700{
701 struct mmc_command cmd = {0};
702 struct mmc_request mrq = {0};
703 struct mmc_data data = {0};
704 struct scatterlist sg;
705 char tuning_pattern[ESDHC_TUNING_BLOCK_PATTERN_LEN];
706
707 cmd.opcode = opcode;
708 cmd.arg = 0;
709 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
710
711 data.blksz = ESDHC_TUNING_BLOCK_PATTERN_LEN;
712 data.blocks = 1;
713 data.flags = MMC_DATA_READ;
714 data.sg = &sg;
715 data.sg_len = 1;
716
717 sg_init_one(&sg, tuning_pattern, sizeof(tuning_pattern));
718
719 mrq.cmd = &cmd;
720 mrq.cmd->mrq = &mrq;
721 mrq.data = &data;
722 mrq.data->mrq = &mrq;
723 mrq.cmd->data = mrq.data;
724
725 mrq.done = esdhc_request_done;
726 init_completion(&(mrq.completion));
727
728 disable_irq(host->irq);
729 spin_lock(&host->lock);
730 host->mrq = &mrq;
731
732 sdhci_send_command(host, mrq.cmd);
733
734 spin_unlock(&host->lock);
735 enable_irq(host->irq);
736
737 wait_for_completion(&mrq.completion);
738
739 if (cmd.error)
740 return cmd.error;
741 if (data.error)
742 return data.error;
743
744 return 0;
745}
746
747static void esdhc_post_tuning(struct sdhci_host *host)
748{
749 u32 reg;
750
751 reg = readl(host->ioaddr + ESDHC_MIX_CTRL);
752 reg &= ~ESDHC_MIX_CTRL_EXE_TUNE;
753 writel(reg, host->ioaddr + ESDHC_MIX_CTRL);
754}
755
756static int esdhc_executing_tuning(struct sdhci_host *host, u32 opcode)
757{
758 int min, max, avg, ret;
759
760 /* find the mininum delay first which can pass tuning */
761 min = ESDHC_TUNE_CTRL_MIN;
762 while (min < ESDHC_TUNE_CTRL_MAX) {
763 esdhc_prepare_tuning(host, min);
764 if (!esdhc_send_tuning_cmd(host, opcode))
765 break;
766 min += ESDHC_TUNE_CTRL_STEP;
767 }
768
769 /* find the maxinum delay which can not pass tuning */
770 max = min + ESDHC_TUNE_CTRL_STEP;
771 while (max < ESDHC_TUNE_CTRL_MAX) {
772 esdhc_prepare_tuning(host, max);
773 if (esdhc_send_tuning_cmd(host, opcode)) {
774 max -= ESDHC_TUNE_CTRL_STEP;
775 break;
776 }
777 max += ESDHC_TUNE_CTRL_STEP;
778 }
779
780 /* use average delay to get the best timing */
781 avg = (min + max) / 2;
782 esdhc_prepare_tuning(host, avg);
783 ret = esdhc_send_tuning_cmd(host, opcode);
784 esdhc_post_tuning(host);
785
786 dev_dbg(mmc_dev(host->mmc), "tunning %s at 0x%x ret %d\n",
787 ret ? "failed" : "passed", avg, ret);
788
789 return ret;
790}
791
792static int esdhc_change_pinstate(struct sdhci_host *host,
793 unsigned int uhs)
794{
795 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
796 struct pltfm_imx_data *imx_data = pltfm_host->priv;
797 struct pinctrl_state *pinctrl;
798
799 dev_dbg(mmc_dev(host->mmc), "change pinctrl state for uhs %d\n", uhs);
800
801 if (IS_ERR(imx_data->pinctrl) ||
802 IS_ERR(imx_data->pins_default) ||
803 IS_ERR(imx_data->pins_100mhz) ||
804 IS_ERR(imx_data->pins_200mhz))
805 return -EINVAL;
806
807 switch (uhs) {
808 case MMC_TIMING_UHS_SDR50:
809 pinctrl = imx_data->pins_100mhz;
810 break;
811 case MMC_TIMING_UHS_SDR104:
812 pinctrl = imx_data->pins_200mhz;
813 break;
814 default:
815 /* back to default state for other legacy timing */
816 pinctrl = imx_data->pins_default;
817 }
818
819 return pinctrl_select_state(imx_data->pinctrl, pinctrl);
820}
821
822static int esdhc_set_uhs_signaling(struct sdhci_host *host, unsigned int uhs)
823{
824 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
825 struct pltfm_imx_data *imx_data = pltfm_host->priv;
826 struct esdhc_platform_data *boarddata = &imx_data->boarddata;
827
828 switch (uhs) {
829 case MMC_TIMING_UHS_SDR12:
830 imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR12;
831 break;
832 case MMC_TIMING_UHS_SDR25:
833 imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR25;
834 break;
835 case MMC_TIMING_UHS_SDR50:
836 imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR50;
837 break;
838 case MMC_TIMING_UHS_SDR104:
839 imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR104;
840 break;
841 case MMC_TIMING_UHS_DDR50:
842 imx_data->uhs_mode = SDHCI_CTRL_UHS_DDR50;
843 writel(readl(host->ioaddr + ESDHC_MIX_CTRL) |
844 ESDHC_MIX_CTRL_DDREN,
845 host->ioaddr + ESDHC_MIX_CTRL);
846 imx_data->is_ddr = 1;
847 if (boarddata->delay_line) {
848 u32 v;
849 v = boarddata->delay_line <<
850 ESDHC_DLL_OVERRIDE_VAL_SHIFT |
851 (1 << ESDHC_DLL_OVERRIDE_EN_SHIFT);
852 if (is_imx53_esdhc(imx_data))
853 v <<= 1;
854 writel(v, host->ioaddr + ESDHC_DLL_CTRL);
855 }
856 break;
857 }
858
859 return esdhc_change_pinstate(host, uhs);
860}
861
862static struct sdhci_ops sdhci_esdhc_ops = {
458 .read_l = esdhc_readl_le, 863 .read_l = esdhc_readl_le,
459 .read_w = esdhc_readw_le, 864 .read_w = esdhc_readw_le,
460 .write_l = esdhc_writel_le, 865 .write_l = esdhc_writel_le,
@@ -465,6 +870,7 @@ static const struct sdhci_ops sdhci_esdhc_ops = {
465 .get_min_clock = esdhc_pltfm_get_min_clock, 870 .get_min_clock = esdhc_pltfm_get_min_clock,
466 .get_ro = esdhc_pltfm_get_ro, 871 .get_ro = esdhc_pltfm_get_ro,
467 .platform_bus_width = esdhc_pltfm_bus_width, 872 .platform_bus_width = esdhc_pltfm_bus_width,
873 .set_uhs_signaling = esdhc_set_uhs_signaling,
468}; 874};
469 875
470static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { 876static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
@@ -506,6 +912,14 @@ sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
506 912
507 of_property_read_u32(np, "max-frequency", &boarddata->f_max); 913 of_property_read_u32(np, "max-frequency", &boarddata->f_max);
508 914
915 if (of_find_property(np, "no-1-8-v", NULL))
916 boarddata->support_vsel = false;
917 else
918 boarddata->support_vsel = true;
919
920 if (of_property_read_u32(np, "fsl,delay-line", &boarddata->delay_line))
921 boarddata->delay_line = 0;
922
509 return 0; 923 return 0;
510} 924}
511#else 925#else
@@ -539,9 +953,8 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
539 goto free_sdhci; 953 goto free_sdhci;
540 } 954 }
541 955
542 if (of_id) 956 imx_data->socdata = of_id ? of_id->data : (struct esdhc_soc_data *)
543 pdev->id_entry = of_id->data; 957 pdev->id_entry->driver_data;
544 imx_data->devtype = pdev->id_entry->driver_data;
545 pltfm_host->priv = imx_data; 958 pltfm_host->priv = imx_data;
546 959
547 imx_data->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); 960 imx_data->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
@@ -568,29 +981,39 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
568 clk_prepare_enable(imx_data->clk_ipg); 981 clk_prepare_enable(imx_data->clk_ipg);
569 clk_prepare_enable(imx_data->clk_ahb); 982 clk_prepare_enable(imx_data->clk_ahb);
570 983
571 imx_data->pinctrl = devm_pinctrl_get_select_default(&pdev->dev); 984 imx_data->pinctrl = devm_pinctrl_get(&pdev->dev);
572 if (IS_ERR(imx_data->pinctrl)) { 985 if (IS_ERR(imx_data->pinctrl)) {
573 err = PTR_ERR(imx_data->pinctrl); 986 err = PTR_ERR(imx_data->pinctrl);
574 goto disable_clk; 987 goto disable_clk;
575 } 988 }
576 989
990 imx_data->pins_default = pinctrl_lookup_state(imx_data->pinctrl,
991 PINCTRL_STATE_DEFAULT);
992 if (IS_ERR(imx_data->pins_default)) {
993 err = PTR_ERR(imx_data->pins_default);
994 dev_err(mmc_dev(host->mmc), "could not get default state\n");
995 goto disable_clk;
996 }
997
577 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; 998 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
578 999
579 if (is_imx25_esdhc(imx_data) || is_imx35_esdhc(imx_data)) 1000 if (imx_data->socdata->flags & ESDHC_FLAG_ENGCM07207)
580 /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */ 1001 /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */
581 host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK 1002 host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK
582 | SDHCI_QUIRK_BROKEN_ADMA; 1003 | SDHCI_QUIRK_BROKEN_ADMA;
583 1004
584 if (is_imx53_esdhc(imx_data))
585 imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT;
586
587 /* 1005 /*
588 * The imx6q ROM code will change the default watermark level setting 1006 * The imx6q ROM code will change the default watermark level setting
589 * to something insane. Change it back here. 1007 * to something insane. Change it back here.
590 */ 1008 */
591 if (is_imx6q_usdhc(imx_data)) 1009 if (esdhc_is_usdhc(imx_data)) {
592 writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL); 1010 writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL);
1011 host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
1012 }
593 1013
1014 if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
1015 sdhci_esdhc_ops.platform_execute_tuning =
1016 esdhc_executing_tuning;
594 boarddata = &imx_data->boarddata; 1017 boarddata = &imx_data->boarddata;
595 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) { 1018 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
596 if (!host->mmc->parent->platform_data) { 1019 if (!host->mmc->parent->platform_data) {
@@ -650,6 +1073,23 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
650 break; 1073 break;
651 } 1074 }
652 1075
1076 /* sdr50 and sdr104 needs work on 1.8v signal voltage */
1077 if ((boarddata->support_vsel) && esdhc_is_usdhc(imx_data)) {
1078 imx_data->pins_100mhz = pinctrl_lookup_state(imx_data->pinctrl,
1079 ESDHC_PINCTRL_STATE_100MHZ);
1080 imx_data->pins_200mhz = pinctrl_lookup_state(imx_data->pinctrl,
1081 ESDHC_PINCTRL_STATE_200MHZ);
1082 if (IS_ERR(imx_data->pins_100mhz) ||
1083 IS_ERR(imx_data->pins_200mhz)) {
1084 dev_warn(mmc_dev(host->mmc),
1085 "could not get ultra high speed state, work on normal mode\n");
1086 /* fall back to not support uhs by specify no 1.8v quirk */
1087 host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V;
1088 }
1089 } else {
1090 host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V;
1091 }
1092
653 err = sdhci_add_host(host); 1093 err = sdhci_add_host(host);
654 if (err) 1094 if (err)
655 goto disable_clk; 1095 goto disable_clk;
diff --git a/drivers/mmc/host/sdhci-esdhc.h b/drivers/mmc/host/sdhci-esdhc.h
index a2a06420e463..a7d9f95a7b03 100644
--- a/drivers/mmc/host/sdhci-esdhc.h
+++ b/drivers/mmc/host/sdhci-esdhc.h
@@ -49,41 +49,4 @@
49 49
50#define ESDHC_HOST_CONTROL_RES 0x05 50#define ESDHC_HOST_CONTROL_RES 0x05
51 51
52static inline void esdhc_set_clock(struct sdhci_host *host, unsigned int clock,
53 unsigned int host_clock)
54{
55 int pre_div = 2;
56 int div = 1;
57 u32 temp;
58
59 if (clock == 0)
60 goto out;
61
62 temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
63 temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
64 | ESDHC_CLOCK_MASK);
65 sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
66
67 while (host_clock / pre_div / 16 > clock && pre_div < 256)
68 pre_div *= 2;
69
70 while (host_clock / pre_div / div > clock && div < 16)
71 div++;
72
73 dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
74 clock, host_clock / pre_div / div);
75
76 pre_div >>= 1;
77 div--;
78
79 temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
80 temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
81 | (div << ESDHC_DIVIDER_SHIFT)
82 | (pre_div << ESDHC_PREDIV_SHIFT));
83 sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
84 mdelay(1);
85out:
86 host->clock = clock;
87}
88
89#endif /* _DRIVERS_MMC_SDHCI_ESDHC_H */ 52#endif /* _DRIVERS_MMC_SDHCI_ESDHC_H */
diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c
index e328252ebf2a..0b249970b119 100644
--- a/drivers/mmc/host/sdhci-of-esdhc.c
+++ b/drivers/mmc/host/sdhci-of-esdhc.c
@@ -199,6 +199,14 @@ static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
199 199
200static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock) 200static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
201{ 201{
202
203 int pre_div = 2;
204 int div = 1;
205 u32 temp;
206
207 if (clock == 0)
208 goto out;
209
202 /* Workaround to reduce the clock frequency for p1010 esdhc */ 210 /* Workaround to reduce the clock frequency for p1010 esdhc */
203 if (of_find_compatible_node(NULL, NULL, "fsl,p1010-esdhc")) { 211 if (of_find_compatible_node(NULL, NULL, "fsl,p1010-esdhc")) {
204 if (clock > 20000000) 212 if (clock > 20000000)
@@ -207,8 +215,31 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
207 clock -= 5000000; 215 clock -= 5000000;
208 } 216 }
209 217
210 /* Set the clock */ 218 temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
211 esdhc_set_clock(host, clock, host->max_clk); 219 temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
220 | ESDHC_CLOCK_MASK);
221 sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
222
223 while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
224 pre_div *= 2;
225
226 while (host->max_clk / pre_div / div > clock && div < 16)
227 div++;
228
229 dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
230 clock, host->max_clk / pre_div / div);
231
232 pre_div >>= 1;
233 div--;
234
235 temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
236 temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
237 | (div << ESDHC_DIVIDER_SHIFT)
238 | (pre_div << ESDHC_PREDIV_SHIFT));
239 sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
240 mdelay(1);
241out:
242 host->clock = clock;
212} 243}
213 244
214#ifdef CONFIG_PM 245#ifdef CONFIG_PM
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index d7d6bc8968d2..8f753811fc7a 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -37,6 +37,12 @@
37#define PCI_DEVICE_ID_INTEL_BYT_SDIO 0x0f15 37#define PCI_DEVICE_ID_INTEL_BYT_SDIO 0x0f15
38#define PCI_DEVICE_ID_INTEL_BYT_SD 0x0f16 38#define PCI_DEVICE_ID_INTEL_BYT_SD 0x0f16
39#define PCI_DEVICE_ID_INTEL_BYT_EMMC2 0x0f50 39#define PCI_DEVICE_ID_INTEL_BYT_EMMC2 0x0f50
40#define PCI_DEVICE_ID_INTEL_MRFL_MMC 0x1190
41#define PCI_DEVICE_ID_INTEL_CLV_SDIO0 0x08f9
42#define PCI_DEVICE_ID_INTEL_CLV_SDIO1 0x08fa
43#define PCI_DEVICE_ID_INTEL_CLV_SDIO2 0x08fb
44#define PCI_DEVICE_ID_INTEL_CLV_EMMC0 0x08e5
45#define PCI_DEVICE_ID_INTEL_CLV_EMMC1 0x08e6
40 46
41/* 47/*
42 * PCI registers 48 * PCI registers
@@ -356,6 +362,28 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
356 .allow_runtime_pm = true, 362 .allow_runtime_pm = true,
357}; 363};
358 364
365/* Define Host controllers for Intel Merrifield platform */
366#define INTEL_MRFL_EMMC_0 0
367#define INTEL_MRFL_EMMC_1 1
368
369static int intel_mrfl_mmc_probe_slot(struct sdhci_pci_slot *slot)
370{
371 if ((PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_0) &&
372 (PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_1))
373 /* SD support is not ready yet */
374 return -ENODEV;
375
376 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
377 MMC_CAP_1_8V_DDR;
378
379 return 0;
380}
381
382static const struct sdhci_pci_fixes sdhci_intel_mrfl_mmc = {
383 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
384 .probe_slot = intel_mrfl_mmc_probe_slot,
385};
386
359/* O2Micro extra registers */ 387/* O2Micro extra registers */
360#define O2_SD_LOCK_WP 0xD3 388#define O2_SD_LOCK_WP 0xD3
361#define O2_SD_MULTI_VCC3V 0xEE 389#define O2_SD_MULTI_VCC3V 0xEE
@@ -939,6 +967,54 @@ static const struct pci_device_id pci_ids[] = {
939 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 967 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
940 }, 968 },
941 969
970
971 {
972 .vendor = PCI_VENDOR_ID_INTEL,
973 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO0,
974 .subvendor = PCI_ANY_ID,
975 .subdevice = PCI_ANY_ID,
976 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
977 },
978
979 {
980 .vendor = PCI_VENDOR_ID_INTEL,
981 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO1,
982 .subvendor = PCI_ANY_ID,
983 .subdevice = PCI_ANY_ID,
984 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
985 },
986
987 {
988 .vendor = PCI_VENDOR_ID_INTEL,
989 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO2,
990 .subvendor = PCI_ANY_ID,
991 .subdevice = PCI_ANY_ID,
992 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
993 },
994
995 {
996 .vendor = PCI_VENDOR_ID_INTEL,
997 .device = PCI_DEVICE_ID_INTEL_CLV_EMMC0,
998 .subvendor = PCI_ANY_ID,
999 .subdevice = PCI_ANY_ID,
1000 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
1001 },
1002
1003 {
1004 .vendor = PCI_VENDOR_ID_INTEL,
1005 .device = PCI_DEVICE_ID_INTEL_CLV_EMMC1,
1006 .subvendor = PCI_ANY_ID,
1007 .subdevice = PCI_ANY_ID,
1008 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
1009 },
1010
1011 {
1012 .vendor = PCI_VENDOR_ID_INTEL,
1013 .device = PCI_DEVICE_ID_INTEL_MRFL_MMC,
1014 .subvendor = PCI_ANY_ID,
1015 .subdevice = PCI_ANY_ID,
1016 .driver_data = (kernel_ulong_t)&sdhci_intel_mrfl_mmc,
1017 },
942 { 1018 {
943 .vendor = PCI_VENDOR_ID_O2, 1019 .vendor = PCI_VENDOR_ID_O2,
944 .device = PCI_DEVICE_ID_O2_8120, 1020 .device = PCI_DEVICE_ID_O2_8120,
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 7a7fb4f0d5a4..bd8a0982aec3 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -49,7 +49,6 @@ static unsigned int debug_quirks2;
49 49
50static void sdhci_finish_data(struct sdhci_host *); 50static void sdhci_finish_data(struct sdhci_host *);
51 51
52static void sdhci_send_command(struct sdhci_host *, struct mmc_command *);
53static void sdhci_finish_command(struct sdhci_host *); 52static void sdhci_finish_command(struct sdhci_host *);
54static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode); 53static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode);
55static void sdhci_tuning_timer(unsigned long data); 54static void sdhci_tuning_timer(unsigned long data);
@@ -981,7 +980,7 @@ static void sdhci_finish_data(struct sdhci_host *host)
981 tasklet_schedule(&host->finish_tasklet); 980 tasklet_schedule(&host->finish_tasklet);
982} 981}
983 982
984static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) 983void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
985{ 984{
986 int flags; 985 int flags;
987 u32 mask; 986 u32 mask;
@@ -1053,6 +1052,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
1053 1052
1054 sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND); 1053 sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND);
1055} 1054}
1055EXPORT_SYMBOL_GPL(sdhci_send_command);
1056 1056
1057static void sdhci_finish_command(struct sdhci_host *host) 1057static void sdhci_finish_command(struct sdhci_host *host)
1058{ 1058{
@@ -1435,7 +1435,8 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
1435 } 1435 }
1436 1436
1437 if (host->version >= SDHCI_SPEC_300 && 1437 if (host->version >= SDHCI_SPEC_300 &&
1438 (ios->power_mode == MMC_POWER_UP)) 1438 (ios->power_mode == MMC_POWER_UP) &&
1439 !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN))
1439 sdhci_enable_preset_value(host, false); 1440 sdhci_enable_preset_value(host, false);
1440 1441
1441 sdhci_set_clock(host, ios->clock); 1442 sdhci_set_clock(host, ios->clock);
@@ -1875,6 +1876,14 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1875 return 0; 1876 return 0;
1876 } 1877 }
1877 1878
1879 if (host->ops->platform_execute_tuning) {
1880 spin_unlock(&host->lock);
1881 enable_irq(host->irq);
1882 err = host->ops->platform_execute_tuning(host, opcode);
1883 sdhci_runtime_pm_put(host);
1884 return err;
1885 }
1886
1878 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); 1887 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
1879 1888
1880 /* 1889 /*
@@ -1981,6 +1990,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1981 if (!tuning_loop_counter || !timeout) { 1990 if (!tuning_loop_counter || !timeout) {
1982 ctrl &= ~SDHCI_CTRL_TUNED_CLK; 1991 ctrl &= ~SDHCI_CTRL_TUNED_CLK;
1983 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); 1992 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
1993 err = -EIO;
1984 } else { 1994 } else {
1985 if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) { 1995 if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) {
1986 pr_info(DRIVER_NAME ": Tuning procedure" 1996 pr_info(DRIVER_NAME ": Tuning procedure"
@@ -2491,6 +2501,14 @@ again:
2491 result = IRQ_HANDLED; 2501 result = IRQ_HANDLED;
2492 2502
2493 intmask = sdhci_readl(host, SDHCI_INT_STATUS); 2503 intmask = sdhci_readl(host, SDHCI_INT_STATUS);
2504
2505 /*
2506 * If we know we'll call the driver to signal SDIO IRQ, disregard
2507 * further indications of Card Interrupt in the status to avoid a
2508 * needless loop.
2509 */
2510 if (cardint)
2511 intmask &= ~SDHCI_INT_CARD_INT;
2494 if (intmask && --max_loops) 2512 if (intmask && --max_loops)
2495 goto again; 2513 goto again;
2496out: 2514out:
@@ -2546,8 +2564,6 @@ EXPORT_SYMBOL_GPL(sdhci_disable_irq_wakeups);
2546 2564
2547int sdhci_suspend_host(struct sdhci_host *host) 2565int sdhci_suspend_host(struct sdhci_host *host)
2548{ 2566{
2549 int ret;
2550
2551 if (host->ops->platform_suspend) 2567 if (host->ops->platform_suspend)
2552 host->ops->platform_suspend(host); 2568 host->ops->platform_suspend(host);
2553 2569
@@ -2559,19 +2575,6 @@ int sdhci_suspend_host(struct sdhci_host *host)
2559 host->flags &= ~SDHCI_NEEDS_RETUNING; 2575 host->flags &= ~SDHCI_NEEDS_RETUNING;
2560 } 2576 }
2561 2577
2562 ret = mmc_suspend_host(host->mmc);
2563 if (ret) {
2564 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
2565 host->flags |= SDHCI_NEEDS_RETUNING;
2566 mod_timer(&host->tuning_timer, jiffies +
2567 host->tuning_count * HZ);
2568 }
2569
2570 sdhci_enable_card_detection(host);
2571
2572 return ret;
2573 }
2574
2575 if (!device_may_wakeup(mmc_dev(host->mmc))) { 2578 if (!device_may_wakeup(mmc_dev(host->mmc))) {
2576 sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK); 2579 sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
2577 free_irq(host->irq, host); 2580 free_irq(host->irq, host);
@@ -2579,14 +2582,14 @@ int sdhci_suspend_host(struct sdhci_host *host)
2579 sdhci_enable_irq_wakeups(host); 2582 sdhci_enable_irq_wakeups(host);
2580 enable_irq_wake(host->irq); 2583 enable_irq_wake(host->irq);
2581 } 2584 }
2582 return ret; 2585 return 0;
2583} 2586}
2584 2587
2585EXPORT_SYMBOL_GPL(sdhci_suspend_host); 2588EXPORT_SYMBOL_GPL(sdhci_suspend_host);
2586 2589
2587int sdhci_resume_host(struct sdhci_host *host) 2590int sdhci_resume_host(struct sdhci_host *host)
2588{ 2591{
2589 int ret; 2592 int ret = 0;
2590 2593
2591 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { 2594 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
2592 if (host->ops->enable_dma) 2595 if (host->ops->enable_dma)
@@ -2615,7 +2618,6 @@ int sdhci_resume_host(struct sdhci_host *host)
2615 mmiowb(); 2618 mmiowb();
2616 } 2619 }
2617 2620
2618 ret = mmc_resume_host(host->mmc);
2619 sdhci_enable_card_detection(host); 2621 sdhci_enable_card_detection(host);
2620 2622
2621 if (host->ops->platform_resume) 2623 if (host->ops->platform_resume)
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index b037f188fe44..0a3ed01887db 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -288,6 +288,7 @@ struct sdhci_ops {
288 unsigned int (*get_ro)(struct sdhci_host *host); 288 unsigned int (*get_ro)(struct sdhci_host *host);
289 void (*platform_reset_enter)(struct sdhci_host *host, u8 mask); 289 void (*platform_reset_enter)(struct sdhci_host *host, u8 mask);
290 void (*platform_reset_exit)(struct sdhci_host *host, u8 mask); 290 void (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
291 int (*platform_execute_tuning)(struct sdhci_host *host, u32 opcode);
291 int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs); 292 int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
292 void (*hw_reset)(struct sdhci_host *host); 293 void (*hw_reset)(struct sdhci_host *host);
293 void (*platform_suspend)(struct sdhci_host *host); 294 void (*platform_suspend)(struct sdhci_host *host);
@@ -393,6 +394,8 @@ static inline void *sdhci_priv(struct sdhci_host *host)
393extern void sdhci_card_detect(struct sdhci_host *host); 394extern void sdhci_card_detect(struct sdhci_host *host);
394extern int sdhci_add_host(struct sdhci_host *host); 395extern int sdhci_add_host(struct sdhci_host *host);
395extern void sdhci_remove_host(struct sdhci_host *host, int dead); 396extern void sdhci_remove_host(struct sdhci_host *host, int dead);
397extern void sdhci_send_command(struct sdhci_host *host,
398 struct mmc_command *cmd);
396 399
397#ifdef CONFIG_PM 400#ifdef CONFIG_PM
398extern int sdhci_suspend_host(struct sdhci_host *host); 401extern int sdhci_suspend_host(struct sdhci_host *host);
diff --git a/drivers/mmc/host/sdricoh_cs.c b/drivers/mmc/host/sdricoh_cs.c
index 50adbd155f35..b7e305775314 100644
--- a/drivers/mmc/host/sdricoh_cs.c
+++ b/drivers/mmc/host/sdricoh_cs.c
@@ -516,9 +516,7 @@ static void sdricoh_pcmcia_detach(struct pcmcia_device *link)
516#ifdef CONFIG_PM 516#ifdef CONFIG_PM
517static int sdricoh_pcmcia_suspend(struct pcmcia_device *link) 517static int sdricoh_pcmcia_suspend(struct pcmcia_device *link)
518{ 518{
519 struct mmc_host *mmc = link->priv;
520 dev_dbg(&link->dev, "suspend\n"); 519 dev_dbg(&link->dev, "suspend\n");
521 mmc_suspend_host(mmc);
522 return 0; 520 return 0;
523} 521}
524 522
@@ -527,7 +525,6 @@ static int sdricoh_pcmcia_resume(struct pcmcia_device *link)
527 struct mmc_host *mmc = link->priv; 525 struct mmc_host *mmc = link->priv;
528 dev_dbg(&link->dev, "resume\n"); 526 dev_dbg(&link->dev, "resume\n");
529 sdricoh_reset(mmc_priv(mmc)); 527 sdricoh_reset(mmc_priv(mmc));
530 mmc_resume_host(mmc);
531 return 0; 528 return 0;
532} 529}
533#else 530#else
diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
index 36629a024aa1..d032b080ac4d 100644
--- a/drivers/mmc/host/sh_mmcif.c
+++ b/drivers/mmc/host/sh_mmcif.c
@@ -964,7 +964,7 @@ static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq)
964 964
965static int sh_mmcif_clk_update(struct sh_mmcif_host *host) 965static int sh_mmcif_clk_update(struct sh_mmcif_host *host)
966{ 966{
967 int ret = clk_enable(host->hclk); 967 int ret = clk_prepare_enable(host->hclk);
968 968
969 if (!ret) { 969 if (!ret) {
970 host->clk = clk_get_rate(host->hclk); 970 host->clk = clk_get_rate(host->hclk);
@@ -1018,7 +1018,7 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1018 } 1018 }
1019 if (host->power) { 1019 if (host->power) {
1020 pm_runtime_put_sync(&host->pd->dev); 1020 pm_runtime_put_sync(&host->pd->dev);
1021 clk_disable(host->hclk); 1021 clk_disable_unprepare(host->hclk);
1022 host->power = false; 1022 host->power = false;
1023 if (ios->power_mode == MMC_POWER_OFF) 1023 if (ios->power_mode == MMC_POWER_OFF)
1024 sh_mmcif_set_power(host, ios); 1024 sh_mmcif_set_power(host, ios);
@@ -1466,7 +1466,7 @@ static int sh_mmcif_probe(struct platform_device *pdev)
1466 1466
1467 mutex_init(&host->thread_lock); 1467 mutex_init(&host->thread_lock);
1468 1468
1469 clk_disable(host->hclk); 1469 clk_disable_unprepare(host->hclk);
1470 ret = mmc_add_host(mmc); 1470 ret = mmc_add_host(mmc);
1471 if (ret < 0) 1471 if (ret < 0)
1472 goto emmcaddh; 1472 goto emmcaddh;
@@ -1487,7 +1487,7 @@ ereqirq1:
1487ereqirq0: 1487ereqirq0:
1488 pm_runtime_suspend(&pdev->dev); 1488 pm_runtime_suspend(&pdev->dev);
1489eresume: 1489eresume:
1490 clk_disable(host->hclk); 1490 clk_disable_unprepare(host->hclk);
1491eclkupdate: 1491eclkupdate:
1492 clk_put(host->hclk); 1492 clk_put(host->hclk);
1493eclkget: 1493eclkget:
@@ -1505,7 +1505,7 @@ static int sh_mmcif_remove(struct platform_device *pdev)
1505 int irq[2]; 1505 int irq[2];
1506 1506
1507 host->dying = true; 1507 host->dying = true;
1508 clk_enable(host->hclk); 1508 clk_prepare_enable(host->hclk);
1509 pm_runtime_get_sync(&pdev->dev); 1509 pm_runtime_get_sync(&pdev->dev);
1510 1510
1511 dev_pm_qos_hide_latency_limit(&pdev->dev); 1511 dev_pm_qos_hide_latency_limit(&pdev->dev);
@@ -1530,7 +1530,7 @@ static int sh_mmcif_remove(struct platform_device *pdev)
1530 if (irq[1] >= 0) 1530 if (irq[1] >= 0)
1531 free_irq(irq[1], host); 1531 free_irq(irq[1], host);
1532 1532
1533 clk_disable(host->hclk); 1533 clk_disable_unprepare(host->hclk);
1534 mmc_free_host(host->mmc); 1534 mmc_free_host(host->mmc);
1535 pm_runtime_put_sync(&pdev->dev); 1535 pm_runtime_put_sync(&pdev->dev);
1536 pm_runtime_disable(&pdev->dev); 1536 pm_runtime_disable(&pdev->dev);
@@ -1538,28 +1538,21 @@ static int sh_mmcif_remove(struct platform_device *pdev)
1538 return 0; 1538 return 0;
1539} 1539}
1540 1540
1541#ifdef CONFIG_PM 1541#ifdef CONFIG_PM_SLEEP
1542static int sh_mmcif_suspend(struct device *dev) 1542static int sh_mmcif_suspend(struct device *dev)
1543{ 1543{
1544 struct sh_mmcif_host *host = dev_get_drvdata(dev); 1544 struct sh_mmcif_host *host = dev_get_drvdata(dev);
1545 int ret = mmc_suspend_host(host->mmc);
1546 1545
1547 if (!ret) 1546 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1548 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1549 1547
1550 return ret; 1548 return 0;
1551} 1549}
1552 1550
1553static int sh_mmcif_resume(struct device *dev) 1551static int sh_mmcif_resume(struct device *dev)
1554{ 1552{
1555 struct sh_mmcif_host *host = dev_get_drvdata(dev); 1553 return 0;
1556
1557 return mmc_resume_host(host->mmc);
1558} 1554}
1559#else 1555#endif
1560#define sh_mmcif_suspend NULL
1561#define sh_mmcif_resume NULL
1562#endif /* CONFIG_PM */
1563 1556
1564static const struct of_device_id mmcif_of_match[] = { 1557static const struct of_device_id mmcif_of_match[] = {
1565 { .compatible = "renesas,sh-mmcif" }, 1558 { .compatible = "renesas,sh-mmcif" },
@@ -1568,8 +1561,7 @@ static const struct of_device_id mmcif_of_match[] = {
1568MODULE_DEVICE_TABLE(of, mmcif_of_match); 1561MODULE_DEVICE_TABLE(of, mmcif_of_match);
1569 1562
1570static const struct dev_pm_ops sh_mmcif_dev_pm_ops = { 1563static const struct dev_pm_ops sh_mmcif_dev_pm_ops = {
1571 .suspend = sh_mmcif_suspend, 1564 SET_SYSTEM_SLEEP_PM_OPS(sh_mmcif_suspend, sh_mmcif_resume)
1572 .resume = sh_mmcif_resume,
1573}; 1565};
1574 1566
1575static struct platform_driver sh_mmcif_driver = { 1567static struct platform_driver sh_mmcif_driver = {
diff --git a/drivers/mmc/host/tifm_sd.c b/drivers/mmc/host/tifm_sd.c
index 43d962829f8e..d1760ebcac03 100644
--- a/drivers/mmc/host/tifm_sd.c
+++ b/drivers/mmc/host/tifm_sd.c
@@ -1030,7 +1030,7 @@ static void tifm_sd_remove(struct tifm_dev *sock)
1030 1030
1031static int tifm_sd_suspend(struct tifm_dev *sock, pm_message_t state) 1031static int tifm_sd_suspend(struct tifm_dev *sock, pm_message_t state)
1032{ 1032{
1033 return mmc_suspend_host(tifm_get_drvdata(sock)); 1033 return 0;
1034} 1034}
1035 1035
1036static int tifm_sd_resume(struct tifm_dev *sock) 1036static int tifm_sd_resume(struct tifm_dev *sock)
@@ -1044,8 +1044,6 @@ static int tifm_sd_resume(struct tifm_dev *sock)
1044 1044
1045 if (rc) 1045 if (rc)
1046 host->eject = 1; 1046 host->eject = 1;
1047 else
1048 rc = mmc_resume_host(mmc);
1049 1047
1050 return rc; 1048 return rc;
1051} 1049}
diff --git a/drivers/mmc/host/tmio_mmc_pio.c b/drivers/mmc/host/tmio_mmc_pio.c
index b3802256f954..f3b2d8ca1eca 100644
--- a/drivers/mmc/host/tmio_mmc_pio.c
+++ b/drivers/mmc/host/tmio_mmc_pio.c
@@ -1145,12 +1145,9 @@ int tmio_mmc_host_suspend(struct device *dev)
1145{ 1145{
1146 struct mmc_host *mmc = dev_get_drvdata(dev); 1146 struct mmc_host *mmc = dev_get_drvdata(dev);
1147 struct tmio_mmc_host *host = mmc_priv(mmc); 1147 struct tmio_mmc_host *host = mmc_priv(mmc);
1148 int ret = mmc_suspend_host(mmc);
1149 1148
1150 if (!ret) 1149 tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_ALL);
1151 tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_ALL); 1150 return 0;
1152
1153 return ret;
1154} 1151}
1155EXPORT_SYMBOL(tmio_mmc_host_suspend); 1152EXPORT_SYMBOL(tmio_mmc_host_suspend);
1156 1153
@@ -1163,7 +1160,7 @@ int tmio_mmc_host_resume(struct device *dev)
1163 1160
1164 /* The MMC core will perform the complete set up */ 1161 /* The MMC core will perform the complete set up */
1165 host->resuming = true; 1162 host->resuming = true;
1166 return mmc_resume_host(mmc); 1163 return 0;
1167} 1164}
1168EXPORT_SYMBOL(tmio_mmc_host_resume); 1165EXPORT_SYMBOL(tmio_mmc_host_resume);
1169 1166
diff --git a/drivers/mmc/host/via-sdmmc.c b/drivers/mmc/host/via-sdmmc.c
index 4f84586c6e9e..63fac78b3d46 100644
--- a/drivers/mmc/host/via-sdmmc.c
+++ b/drivers/mmc/host/via-sdmmc.c
@@ -1269,21 +1269,18 @@ static void via_init_sdc_pm(struct via_crdr_mmc_host *host)
1269static int via_sd_suspend(struct pci_dev *pcidev, pm_message_t state) 1269static int via_sd_suspend(struct pci_dev *pcidev, pm_message_t state)
1270{ 1270{
1271 struct via_crdr_mmc_host *host; 1271 struct via_crdr_mmc_host *host;
1272 int ret = 0;
1273 1272
1274 host = pci_get_drvdata(pcidev); 1273 host = pci_get_drvdata(pcidev);
1275 1274
1276 via_save_pcictrlreg(host); 1275 via_save_pcictrlreg(host);
1277 via_save_sdcreg(host); 1276 via_save_sdcreg(host);
1278 1277
1279 ret = mmc_suspend_host(host->mmc);
1280
1281 pci_save_state(pcidev); 1278 pci_save_state(pcidev);
1282 pci_enable_wake(pcidev, pci_choose_state(pcidev, state), 0); 1279 pci_enable_wake(pcidev, pci_choose_state(pcidev, state), 0);
1283 pci_disable_device(pcidev); 1280 pci_disable_device(pcidev);
1284 pci_set_power_state(pcidev, pci_choose_state(pcidev, state)); 1281 pci_set_power_state(pcidev, pci_choose_state(pcidev, state));
1285 1282
1286 return ret; 1283 return 0;
1287} 1284}
1288 1285
1289static int via_sd_resume(struct pci_dev *pcidev) 1286static int via_sd_resume(struct pci_dev *pcidev)
@@ -1316,8 +1313,6 @@ static int via_sd_resume(struct pci_dev *pcidev)
1316 via_restore_pcictrlreg(sdhost); 1313 via_restore_pcictrlreg(sdhost);
1317 via_init_sdc_pm(sdhost); 1314 via_init_sdc_pm(sdhost);
1318 1315
1319 ret = mmc_resume_host(sdhost->mmc);
1320
1321 return ret; 1316 return ret;
1322} 1317}
1323 1318
diff --git a/drivers/mmc/host/vub300.c b/drivers/mmc/host/vub300.c
index e9028ad05ffb..4262296c12fa 100644
--- a/drivers/mmc/host/vub300.c
+++ b/drivers/mmc/host/vub300.c
@@ -2392,26 +2392,12 @@ static void vub300_disconnect(struct usb_interface *interface)
2392#ifdef CONFIG_PM 2392#ifdef CONFIG_PM
2393static int vub300_suspend(struct usb_interface *intf, pm_message_t message) 2393static int vub300_suspend(struct usb_interface *intf, pm_message_t message)
2394{ 2394{
2395 struct vub300_mmc_host *vub300 = usb_get_intfdata(intf); 2395 return 0;
2396 if (!vub300 || !vub300->mmc) {
2397 return 0;
2398 } else {
2399 struct mmc_host *mmc = vub300->mmc;
2400 mmc_suspend_host(mmc);
2401 return 0;
2402 }
2403} 2396}
2404 2397
2405static int vub300_resume(struct usb_interface *intf) 2398static int vub300_resume(struct usb_interface *intf)
2406{ 2399{
2407 struct vub300_mmc_host *vub300 = usb_get_intfdata(intf); 2400 return 0;
2408 if (!vub300 || !vub300->mmc) {
2409 return 0;
2410 } else {
2411 struct mmc_host *mmc = vub300->mmc;
2412 mmc_resume_host(mmc);
2413 return 0;
2414 }
2415} 2401}
2416#else 2402#else
2417#define vub300_suspend NULL 2403#define vub300_suspend NULL
diff --git a/drivers/mmc/host/wbsd.c b/drivers/mmc/host/wbsd.c
index e954b7758876..1defd5ed3236 100644
--- a/drivers/mmc/host/wbsd.c
+++ b/drivers/mmc/host/wbsd.c
@@ -1814,28 +1814,11 @@ static void wbsd_pnp_remove(struct pnp_dev *dev)
1814 1814
1815#ifdef CONFIG_PM 1815#ifdef CONFIG_PM
1816 1816
1817static int wbsd_suspend(struct wbsd_host *host, pm_message_t state)
1818{
1819 BUG_ON(host == NULL);
1820
1821 return mmc_suspend_host(host->mmc);
1822}
1823
1824static int wbsd_resume(struct wbsd_host *host)
1825{
1826 BUG_ON(host == NULL);
1827
1828 wbsd_init_device(host);
1829
1830 return mmc_resume_host(host->mmc);
1831}
1832
1833static int wbsd_platform_suspend(struct platform_device *dev, 1817static int wbsd_platform_suspend(struct platform_device *dev,
1834 pm_message_t state) 1818 pm_message_t state)
1835{ 1819{
1836 struct mmc_host *mmc = platform_get_drvdata(dev); 1820 struct mmc_host *mmc = platform_get_drvdata(dev);
1837 struct wbsd_host *host; 1821 struct wbsd_host *host;
1838 int ret;
1839 1822
1840 if (mmc == NULL) 1823 if (mmc == NULL)
1841 return 0; 1824 return 0;
@@ -1844,12 +1827,7 @@ static int wbsd_platform_suspend(struct platform_device *dev,
1844 1827
1845 host = mmc_priv(mmc); 1828 host = mmc_priv(mmc);
1846 1829
1847 ret = wbsd_suspend(host, state);
1848 if (ret)
1849 return ret;
1850
1851 wbsd_chip_poweroff(host); 1830 wbsd_chip_poweroff(host);
1852
1853 return 0; 1831 return 0;
1854} 1832}
1855 1833
@@ -1872,7 +1850,8 @@ static int wbsd_platform_resume(struct platform_device *dev)
1872 */ 1850 */
1873 mdelay(5); 1851 mdelay(5);
1874 1852
1875 return wbsd_resume(host); 1853 wbsd_init_device(host);
1854 return 0;
1876} 1855}
1877 1856
1878#ifdef CONFIG_PNP 1857#ifdef CONFIG_PNP
@@ -1880,16 +1859,12 @@ static int wbsd_platform_resume(struct platform_device *dev)
1880static int wbsd_pnp_suspend(struct pnp_dev *pnp_dev, pm_message_t state) 1859static int wbsd_pnp_suspend(struct pnp_dev *pnp_dev, pm_message_t state)
1881{ 1860{
1882 struct mmc_host *mmc = dev_get_drvdata(&pnp_dev->dev); 1861 struct mmc_host *mmc = dev_get_drvdata(&pnp_dev->dev);
1883 struct wbsd_host *host;
1884 1862
1885 if (mmc == NULL) 1863 if (mmc == NULL)
1886 return 0; 1864 return 0;
1887 1865
1888 DBGF("Suspending...\n"); 1866 DBGF("Suspending...\n");
1889 1867 return 0;
1890 host = mmc_priv(mmc);
1891
1892 return wbsd_suspend(host, state);
1893} 1868}
1894 1869
1895static int wbsd_pnp_resume(struct pnp_dev *pnp_dev) 1870static int wbsd_pnp_resume(struct pnp_dev *pnp_dev)
@@ -1922,7 +1897,8 @@ static int wbsd_pnp_resume(struct pnp_dev *pnp_dev)
1922 */ 1897 */
1923 mdelay(5); 1898 mdelay(5);
1924 1899
1925 return wbsd_resume(host); 1900 wbsd_init_device(host);
1901 return 0;
1926} 1902}
1927 1903
1928#endif /* CONFIG_PNP */ 1904#endif /* CONFIG_PNP */
diff --git a/drivers/mmc/host/wmt-sdmmc.c b/drivers/mmc/host/wmt-sdmmc.c
index 34231d5168fc..e902ed7846b0 100644
--- a/drivers/mmc/host/wmt-sdmmc.c
+++ b/drivers/mmc/host/wmt-sdmmc.c
@@ -212,28 +212,14 @@ struct wmt_mci_priv {
212 212
213static void wmt_set_sd_power(struct wmt_mci_priv *priv, int enable) 213static void wmt_set_sd_power(struct wmt_mci_priv *priv, int enable)
214{ 214{
215 u32 reg_tmp; 215 u32 reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE);
216 if (enable) { 216
217 if (priv->power_inverted) { 217 if (enable ^ priv->power_inverted)
218 reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE); 218 reg_tmp &= ~BM_SD_OFF;
219 writeb(reg_tmp | BM_SD_OFF, 219 else
220 priv->sdmmc_base + SDMMC_BUSMODE); 220 reg_tmp |= BM_SD_OFF;
221 } else { 221
222 reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE); 222 writeb(reg_tmp, priv->sdmmc_base + SDMMC_BUSMODE);
223 writeb(reg_tmp & (~BM_SD_OFF),
224 priv->sdmmc_base + SDMMC_BUSMODE);
225 }
226 } else {
227 if (priv->power_inverted) {
228 reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE);
229 writeb(reg_tmp & (~BM_SD_OFF),
230 priv->sdmmc_base + SDMMC_BUSMODE);
231 } else {
232 reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE);
233 writeb(reg_tmp | BM_SD_OFF,
234 priv->sdmmc_base + SDMMC_BUSMODE);
235 }
236 }
237} 223}
238 224
239static void wmt_mci_read_response(struct mmc_host *mmc) 225static void wmt_mci_read_response(struct mmc_host *mmc)
@@ -939,28 +925,23 @@ static int wmt_mci_suspend(struct device *dev)
939 struct platform_device *pdev = to_platform_device(dev); 925 struct platform_device *pdev = to_platform_device(dev);
940 struct mmc_host *mmc = platform_get_drvdata(pdev); 926 struct mmc_host *mmc = platform_get_drvdata(pdev);
941 struct wmt_mci_priv *priv; 927 struct wmt_mci_priv *priv;
942 int ret;
943 928
944 if (!mmc) 929 if (!mmc)
945 return 0; 930 return 0;
946 931
947 priv = mmc_priv(mmc); 932 priv = mmc_priv(mmc);
948 ret = mmc_suspend_host(mmc); 933 reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE);
949 934 writeb(reg_tmp | BM_SOFT_RESET, priv->sdmmc_base +
950 if (!ret) { 935 SDMMC_BUSMODE);
951 reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE);
952 writeb(reg_tmp | BM_SOFT_RESET, priv->sdmmc_base +
953 SDMMC_BUSMODE);
954 936
955 reg_tmp = readw(priv->sdmmc_base + SDMMC_BLKLEN); 937 reg_tmp = readw(priv->sdmmc_base + SDMMC_BLKLEN);
956 writew(reg_tmp & 0x5FFF, priv->sdmmc_base + SDMMC_BLKLEN); 938 writew(reg_tmp & 0x5FFF, priv->sdmmc_base + SDMMC_BLKLEN);
957 939
958 writeb(0xFF, priv->sdmmc_base + SDMMC_STS0); 940 writeb(0xFF, priv->sdmmc_base + SDMMC_STS0);
959 writeb(0xFF, priv->sdmmc_base + SDMMC_STS1); 941 writeb(0xFF, priv->sdmmc_base + SDMMC_STS1);
960 942
961 clk_disable(priv->clk_sdmmc); 943 clk_disable(priv->clk_sdmmc);
962 } 944 return 0;
963 return ret;
964} 945}
965 946
966static int wmt_mci_resume(struct device *dev) 947static int wmt_mci_resume(struct device *dev)
@@ -969,7 +950,6 @@ static int wmt_mci_resume(struct device *dev)
969 struct platform_device *pdev = to_platform_device(dev); 950 struct platform_device *pdev = to_platform_device(dev);
970 struct mmc_host *mmc = platform_get_drvdata(pdev); 951 struct mmc_host *mmc = platform_get_drvdata(pdev);
971 struct wmt_mci_priv *priv; 952 struct wmt_mci_priv *priv;
972 int ret = 0;
973 953
974 if (mmc) { 954 if (mmc) {
975 priv = mmc_priv(mmc); 955 priv = mmc_priv(mmc);
@@ -987,10 +967,9 @@ static int wmt_mci_resume(struct device *dev)
987 writeb(reg_tmp | INT0_DI_INT_EN, priv->sdmmc_base + 967 writeb(reg_tmp | INT0_DI_INT_EN, priv->sdmmc_base +
988 SDMMC_INTMASK0); 968 SDMMC_INTMASK0);
989 969
990 ret = mmc_resume_host(mmc);
991 } 970 }
992 971
993 return ret; 972 return 0;
994} 973}
995 974
996static const struct dev_pm_ops wmt_mci_pm = { 975static const struct dev_pm_ops wmt_mci_pm = {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
index 6ca30739625f..8675d26a678b 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
@@ -98,6 +98,7 @@ enum {
98static struct mlx5_cmd_work_ent *alloc_cmd(struct mlx5_cmd *cmd, 98static struct mlx5_cmd_work_ent *alloc_cmd(struct mlx5_cmd *cmd,
99 struct mlx5_cmd_msg *in, 99 struct mlx5_cmd_msg *in,
100 struct mlx5_cmd_msg *out, 100 struct mlx5_cmd_msg *out,
101 void *uout, int uout_size,
101 mlx5_cmd_cbk_t cbk, 102 mlx5_cmd_cbk_t cbk,
102 void *context, int page_queue) 103 void *context, int page_queue)
103{ 104{
@@ -110,6 +111,8 @@ static struct mlx5_cmd_work_ent *alloc_cmd(struct mlx5_cmd *cmd,
110 111
111 ent->in = in; 112 ent->in = in;
112 ent->out = out; 113 ent->out = out;
114 ent->uout = uout;
115 ent->uout_size = uout_size;
113 ent->callback = cbk; 116 ent->callback = cbk;
114 ent->context = context; 117 ent->context = context;
115 ent->cmd = cmd; 118 ent->cmd = cmd;
@@ -534,6 +537,7 @@ static void cmd_work_handler(struct work_struct *work)
534 ent->lay = lay; 537 ent->lay = lay;
535 memset(lay, 0, sizeof(*lay)); 538 memset(lay, 0, sizeof(*lay));
536 memcpy(lay->in, ent->in->first.data, sizeof(lay->in)); 539 memcpy(lay->in, ent->in->first.data, sizeof(lay->in));
540 ent->op = be32_to_cpu(lay->in[0]) >> 16;
537 if (ent->in->next) 541 if (ent->in->next)
538 lay->in_ptr = cpu_to_be64(ent->in->next->dma); 542 lay->in_ptr = cpu_to_be64(ent->in->next->dma);
539 lay->inlen = cpu_to_be32(ent->in->len); 543 lay->inlen = cpu_to_be32(ent->in->len);
@@ -628,7 +632,8 @@ static int wait_func(struct mlx5_core_dev *dev, struct mlx5_cmd_work_ent *ent)
628 * 2. page queue commands do not support asynchrous completion 632 * 2. page queue commands do not support asynchrous completion
629 */ 633 */
630static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in, 634static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
631 struct mlx5_cmd_msg *out, mlx5_cmd_cbk_t callback, 635 struct mlx5_cmd_msg *out, void *uout, int uout_size,
636 mlx5_cmd_cbk_t callback,
632 void *context, int page_queue, u8 *status) 637 void *context, int page_queue, u8 *status)
633{ 638{
634 struct mlx5_cmd *cmd = &dev->cmd; 639 struct mlx5_cmd *cmd = &dev->cmd;
@@ -642,7 +647,8 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
642 if (callback && page_queue) 647 if (callback && page_queue)
643 return -EINVAL; 648 return -EINVAL;
644 649
645 ent = alloc_cmd(cmd, in, out, callback, context, page_queue); 650 ent = alloc_cmd(cmd, in, out, uout, uout_size, callback, context,
651 page_queue);
646 if (IS_ERR(ent)) 652 if (IS_ERR(ent))
647 return PTR_ERR(ent); 653 return PTR_ERR(ent);
648 654
@@ -670,10 +676,10 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
670 op = be16_to_cpu(((struct mlx5_inbox_hdr *)in->first.data)->opcode); 676 op = be16_to_cpu(((struct mlx5_inbox_hdr *)in->first.data)->opcode);
671 if (op < ARRAY_SIZE(cmd->stats)) { 677 if (op < ARRAY_SIZE(cmd->stats)) {
672 stats = &cmd->stats[op]; 678 stats = &cmd->stats[op];
673 spin_lock(&stats->lock); 679 spin_lock_irq(&stats->lock);
674 stats->sum += ds; 680 stats->sum += ds;
675 ++stats->n; 681 ++stats->n;
676 spin_unlock(&stats->lock); 682 spin_unlock_irq(&stats->lock);
677 } 683 }
678 mlx5_core_dbg_mask(dev, 1 << MLX5_CMD_TIME, 684 mlx5_core_dbg_mask(dev, 1 << MLX5_CMD_TIME,
679 "fw exec time for %s is %lld nsec\n", 685 "fw exec time for %s is %lld nsec\n",
@@ -826,7 +832,7 @@ static struct mlx5_cmd_msg *mlx5_alloc_cmd_msg(struct mlx5_core_dev *dev,
826 int n; 832 int n;
827 int i; 833 int i;
828 834
829 msg = kzalloc(sizeof(*msg), GFP_KERNEL); 835 msg = kzalloc(sizeof(*msg), flags);
830 if (!msg) 836 if (!msg)
831 return ERR_PTR(-ENOMEM); 837 return ERR_PTR(-ENOMEM);
832 838
@@ -1109,6 +1115,19 @@ void mlx5_cmd_use_polling(struct mlx5_core_dev *dev)
1109 up(&cmd->sem); 1115 up(&cmd->sem);
1110} 1116}
1111 1117
1118static void free_msg(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *msg)
1119{
1120 unsigned long flags;
1121
1122 if (msg->cache) {
1123 spin_lock_irqsave(&msg->cache->lock, flags);
1124 list_add_tail(&msg->list, &msg->cache->head);
1125 spin_unlock_irqrestore(&msg->cache->lock, flags);
1126 } else {
1127 mlx5_free_cmd_msg(dev, msg);
1128 }
1129}
1130
1112void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, unsigned long vector) 1131void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, unsigned long vector)
1113{ 1132{
1114 struct mlx5_cmd *cmd = &dev->cmd; 1133 struct mlx5_cmd *cmd = &dev->cmd;
@@ -1117,6 +1136,10 @@ void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, unsigned long vector)
1117 void *context; 1136 void *context;
1118 int err; 1137 int err;
1119 int i; 1138 int i;
1139 ktime_t t1, t2, delta;
1140 s64 ds;
1141 struct mlx5_cmd_stats *stats;
1142 unsigned long flags;
1120 1143
1121 for (i = 0; i < (1 << cmd->log_sz); i++) { 1144 for (i = 0; i < (1 << cmd->log_sz); i++) {
1122 if (test_bit(i, &vector)) { 1145 if (test_bit(i, &vector)) {
@@ -1141,9 +1164,29 @@ void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, unsigned long vector)
1141 } 1164 }
1142 free_ent(cmd, ent->idx); 1165 free_ent(cmd, ent->idx);
1143 if (ent->callback) { 1166 if (ent->callback) {
1167 t1 = timespec_to_ktime(ent->ts1);
1168 t2 = timespec_to_ktime(ent->ts2);
1169 delta = ktime_sub(t2, t1);
1170 ds = ktime_to_ns(delta);
1171 if (ent->op < ARRAY_SIZE(cmd->stats)) {
1172 stats = &cmd->stats[ent->op];
1173 spin_lock_irqsave(&stats->lock, flags);
1174 stats->sum += ds;
1175 ++stats->n;
1176 spin_unlock_irqrestore(&stats->lock, flags);
1177 }
1178
1144 callback = ent->callback; 1179 callback = ent->callback;
1145 context = ent->context; 1180 context = ent->context;
1146 err = ent->ret; 1181 err = ent->ret;
1182 if (!err)
1183 err = mlx5_copy_from_msg(ent->uout,
1184 ent->out,
1185 ent->uout_size);
1186
1187 mlx5_free_cmd_msg(dev, ent->out);
1188 free_msg(dev, ent->in);
1189
1147 free_cmd(ent); 1190 free_cmd(ent);
1148 callback(err, context); 1191 callback(err, context);
1149 } else { 1192 } else {
@@ -1160,7 +1203,8 @@ static int status_to_err(u8 status)
1160 return status ? -1 : 0; /* TBD more meaningful codes */ 1203 return status ? -1 : 0; /* TBD more meaningful codes */
1161} 1204}
1162 1205
1163static struct mlx5_cmd_msg *alloc_msg(struct mlx5_core_dev *dev, int in_size) 1206static struct mlx5_cmd_msg *alloc_msg(struct mlx5_core_dev *dev, int in_size,
1207 gfp_t gfp)
1164{ 1208{
1165 struct mlx5_cmd_msg *msg = ERR_PTR(-ENOMEM); 1209 struct mlx5_cmd_msg *msg = ERR_PTR(-ENOMEM);
1166 struct mlx5_cmd *cmd = &dev->cmd; 1210 struct mlx5_cmd *cmd = &dev->cmd;
@@ -1172,7 +1216,7 @@ static struct mlx5_cmd_msg *alloc_msg(struct mlx5_core_dev *dev, int in_size)
1172 ent = &cmd->cache.med; 1216 ent = &cmd->cache.med;
1173 1217
1174 if (ent) { 1218 if (ent) {
1175 spin_lock(&ent->lock); 1219 spin_lock_irq(&ent->lock);
1176 if (!list_empty(&ent->head)) { 1220 if (!list_empty(&ent->head)) {
1177 msg = list_entry(ent->head.next, typeof(*msg), list); 1221 msg = list_entry(ent->head.next, typeof(*msg), list);
1178 /* For cached lists, we must explicitly state what is 1222 /* For cached lists, we must explicitly state what is
@@ -1181,43 +1225,34 @@ static struct mlx5_cmd_msg *alloc_msg(struct mlx5_core_dev *dev, int in_size)
1181 msg->len = in_size; 1225 msg->len = in_size;
1182 list_del(&msg->list); 1226 list_del(&msg->list);
1183 } 1227 }
1184 spin_unlock(&ent->lock); 1228 spin_unlock_irq(&ent->lock);
1185 } 1229 }
1186 1230
1187 if (IS_ERR(msg)) 1231 if (IS_ERR(msg))
1188 msg = mlx5_alloc_cmd_msg(dev, GFP_KERNEL, in_size); 1232 msg = mlx5_alloc_cmd_msg(dev, gfp, in_size);
1189 1233
1190 return msg; 1234 return msg;
1191} 1235}
1192 1236
1193static void free_msg(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *msg)
1194{
1195 if (msg->cache) {
1196 spin_lock(&msg->cache->lock);
1197 list_add_tail(&msg->list, &msg->cache->head);
1198 spin_unlock(&msg->cache->lock);
1199 } else {
1200 mlx5_free_cmd_msg(dev, msg);
1201 }
1202}
1203
1204static int is_manage_pages(struct mlx5_inbox_hdr *in) 1237static int is_manage_pages(struct mlx5_inbox_hdr *in)
1205{ 1238{
1206 return be16_to_cpu(in->opcode) == MLX5_CMD_OP_MANAGE_PAGES; 1239 return be16_to_cpu(in->opcode) == MLX5_CMD_OP_MANAGE_PAGES;
1207} 1240}
1208 1241
1209int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out, 1242static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
1210 int out_size) 1243 int out_size, mlx5_cmd_cbk_t callback, void *context)
1211{ 1244{
1212 struct mlx5_cmd_msg *inb; 1245 struct mlx5_cmd_msg *inb;
1213 struct mlx5_cmd_msg *outb; 1246 struct mlx5_cmd_msg *outb;
1214 int pages_queue; 1247 int pages_queue;
1248 gfp_t gfp;
1215 int err; 1249 int err;
1216 u8 status = 0; 1250 u8 status = 0;
1217 1251
1218 pages_queue = is_manage_pages(in); 1252 pages_queue = is_manage_pages(in);
1253 gfp = callback ? GFP_ATOMIC : GFP_KERNEL;
1219 1254
1220 inb = alloc_msg(dev, in_size); 1255 inb = alloc_msg(dev, in_size, gfp);
1221 if (IS_ERR(inb)) { 1256 if (IS_ERR(inb)) {
1222 err = PTR_ERR(inb); 1257 err = PTR_ERR(inb);
1223 return err; 1258 return err;
@@ -1229,13 +1264,14 @@ int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
1229 goto out_in; 1264 goto out_in;
1230 } 1265 }
1231 1266
1232 outb = mlx5_alloc_cmd_msg(dev, GFP_KERNEL, out_size); 1267 outb = mlx5_alloc_cmd_msg(dev, gfp, out_size);
1233 if (IS_ERR(outb)) { 1268 if (IS_ERR(outb)) {
1234 err = PTR_ERR(outb); 1269 err = PTR_ERR(outb);
1235 goto out_in; 1270 goto out_in;
1236 } 1271 }
1237 1272
1238 err = mlx5_cmd_invoke(dev, inb, outb, NULL, NULL, pages_queue, &status); 1273 err = mlx5_cmd_invoke(dev, inb, outb, out, out_size, callback, context,
1274 pages_queue, &status);
1239 if (err) 1275 if (err)
1240 goto out_out; 1276 goto out_out;
1241 1277
@@ -1248,14 +1284,30 @@ int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
1248 err = mlx5_copy_from_msg(out, outb, out_size); 1284 err = mlx5_copy_from_msg(out, outb, out_size);
1249 1285
1250out_out: 1286out_out:
1251 mlx5_free_cmd_msg(dev, outb); 1287 if (!callback)
1288 mlx5_free_cmd_msg(dev, outb);
1252 1289
1253out_in: 1290out_in:
1254 free_msg(dev, inb); 1291 if (!callback)
1292 free_msg(dev, inb);
1255 return err; 1293 return err;
1256} 1294}
1295
1296int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
1297 int out_size)
1298{
1299 return cmd_exec(dev, in, in_size, out, out_size, NULL, NULL);
1300}
1257EXPORT_SYMBOL(mlx5_cmd_exec); 1301EXPORT_SYMBOL(mlx5_cmd_exec);
1258 1302
1303int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
1304 void *out, int out_size, mlx5_cmd_cbk_t callback,
1305 void *context)
1306{
1307 return cmd_exec(dev, in, in_size, out, out_size, callback, context);
1308}
1309EXPORT_SYMBOL(mlx5_cmd_exec_cb);
1310
1259static void destroy_msg_cache(struct mlx5_core_dev *dev) 1311static void destroy_msg_cache(struct mlx5_core_dev *dev)
1260{ 1312{
1261 struct mlx5_cmd *cmd = &dev->cmd; 1313 struct mlx5_cmd *cmd = &dev->cmd;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c b/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
index 9c7194b26ee2..80f6d127257a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
@@ -154,10 +154,10 @@ static ssize_t average_read(struct file *filp, char __user *buf, size_t count,
154 return 0; 154 return 0;
155 155
156 stats = filp->private_data; 156 stats = filp->private_data;
157 spin_lock(&stats->lock); 157 spin_lock_irq(&stats->lock);
158 if (stats->n) 158 if (stats->n)
159 field = div64_u64(stats->sum, stats->n); 159 field = div64_u64(stats->sum, stats->n);
160 spin_unlock(&stats->lock); 160 spin_unlock_irq(&stats->lock);
161 ret = snprintf(tbuf, sizeof(tbuf), "%llu\n", field); 161 ret = snprintf(tbuf, sizeof(tbuf), "%llu\n", field);
162 if (ret > 0) { 162 if (ret > 0) {
163 if (copy_to_user(buf, tbuf, ret)) 163 if (copy_to_user(buf, tbuf, ret))
@@ -175,10 +175,10 @@ static ssize_t average_write(struct file *filp, const char __user *buf,
175 struct mlx5_cmd_stats *stats; 175 struct mlx5_cmd_stats *stats;
176 176
177 stats = filp->private_data; 177 stats = filp->private_data;
178 spin_lock(&stats->lock); 178 spin_lock_irq(&stats->lock);
179 stats->sum = 0; 179 stats->sum = 0;
180 stats->n = 0; 180 stats->n = 0;
181 spin_unlock(&stats->lock); 181 spin_unlock_irq(&stats->lock);
182 182
183 *pos += count; 183 *pos += count;
184 184
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
index 2231d93cc7ad..64a61b286b2c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
@@ -354,7 +354,7 @@ int mlx5_create_map_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq, u8 vecidx,
354 in->hdr.opcode = cpu_to_be16(MLX5_CMD_OP_CREATE_EQ); 354 in->hdr.opcode = cpu_to_be16(MLX5_CMD_OP_CREATE_EQ);
355 in->ctx.log_sz_usr_page = cpu_to_be32(ilog2(eq->nent) << 24 | uar->index); 355 in->ctx.log_sz_usr_page = cpu_to_be32(ilog2(eq->nent) << 24 | uar->index);
356 in->ctx.intr = vecidx; 356 in->ctx.intr = vecidx;
357 in->ctx.log_page_size = PAGE_SHIFT - 12; 357 in->ctx.log_page_size = eq->buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT;
358 in->events_mask = cpu_to_be64(mask); 358 in->events_mask = cpu_to_be64(mask);
359 359
360 err = mlx5_cmd_exec(dev, in, inlen, &out, sizeof(out)); 360 err = mlx5_cmd_exec(dev, in, inlen, &out, sizeof(out));
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index bc0f5fb66e24..40a9f5ed814d 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -159,6 +159,36 @@ struct mlx5_reg_host_endianess {
159 u8 rsvd[15]; 159 u8 rsvd[15];
160}; 160};
161 161
162
163#define CAP_MASK(pos, size) ((u64)((1 << (size)) - 1) << (pos))
164
165enum {
166 MLX5_CAP_BITS_RW_MASK = CAP_MASK(MLX5_CAP_OFF_CMDIF_CSUM, 2) |
167 CAP_MASK(MLX5_CAP_OFF_DCT, 1),
168};
169
170/* selectively copy writable fields clearing any reserved area
171 */
172static void copy_rw_fields(struct mlx5_hca_cap *to, struct mlx5_hca_cap *from)
173{
174 u64 v64;
175
176 to->log_max_qp = from->log_max_qp & 0x1f;
177 to->log_max_ra_req_dc = from->log_max_ra_req_dc & 0x3f;
178 to->log_max_ra_res_dc = from->log_max_ra_res_dc & 0x3f;
179 to->log_max_ra_req_qp = from->log_max_ra_req_qp & 0x3f;
180 to->log_max_ra_res_qp = from->log_max_ra_res_qp & 0x3f;
181 to->log_max_atomic_size_qp = from->log_max_atomic_size_qp;
182 to->log_max_atomic_size_dc = from->log_max_atomic_size_dc;
183 v64 = be64_to_cpu(from->flags) & MLX5_CAP_BITS_RW_MASK;
184 to->flags = cpu_to_be64(v64);
185}
186
187enum {
188 HCA_CAP_OPMOD_GET_MAX = 0,
189 HCA_CAP_OPMOD_GET_CUR = 1,
190};
191
162static int handle_hca_cap(struct mlx5_core_dev *dev) 192static int handle_hca_cap(struct mlx5_core_dev *dev)
163{ 193{
164 struct mlx5_cmd_query_hca_cap_mbox_out *query_out = NULL; 194 struct mlx5_cmd_query_hca_cap_mbox_out *query_out = NULL;
@@ -180,7 +210,7 @@ static int handle_hca_cap(struct mlx5_core_dev *dev)
180 } 210 }
181 211
182 query_ctx.hdr.opcode = cpu_to_be16(MLX5_CMD_OP_QUERY_HCA_CAP); 212 query_ctx.hdr.opcode = cpu_to_be16(MLX5_CMD_OP_QUERY_HCA_CAP);
183 query_ctx.hdr.opmod = cpu_to_be16(0x1); 213 query_ctx.hdr.opmod = cpu_to_be16(HCA_CAP_OPMOD_GET_CUR);
184 err = mlx5_cmd_exec(dev, &query_ctx, sizeof(query_ctx), 214 err = mlx5_cmd_exec(dev, &query_ctx, sizeof(query_ctx),
185 query_out, sizeof(*query_out)); 215 query_out, sizeof(*query_out));
186 if (err) 216 if (err)
@@ -192,8 +222,7 @@ static int handle_hca_cap(struct mlx5_core_dev *dev)
192 goto query_ex; 222 goto query_ex;
193 } 223 }
194 224
195 memcpy(&set_ctx->hca_cap, &query_out->hca_cap, 225 copy_rw_fields(&set_ctx->hca_cap, &query_out->hca_cap);
196 sizeof(set_ctx->hca_cap));
197 226
198 if (dev->profile->mask & MLX5_PROF_MASK_QP_SIZE) 227 if (dev->profile->mask & MLX5_PROF_MASK_QP_SIZE)
199 set_ctx->hca_cap.log_max_qp = dev->profile->log_max_qp; 228 set_ctx->hca_cap.log_max_qp = dev->profile->log_max_qp;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/mr.c b/drivers/net/ethernet/mellanox/mlx5/core/mr.c
index 5b44e2e46daf..35e514dc7b7d 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/mr.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/mr.c
@@ -37,31 +37,41 @@
37#include "mlx5_core.h" 37#include "mlx5_core.h"
38 38
39int mlx5_core_create_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr, 39int mlx5_core_create_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr,
40 struct mlx5_create_mkey_mbox_in *in, int inlen) 40 struct mlx5_create_mkey_mbox_in *in, int inlen,
41 mlx5_cmd_cbk_t callback, void *context,
42 struct mlx5_create_mkey_mbox_out *out)
41{ 43{
42 struct mlx5_create_mkey_mbox_out out; 44 struct mlx5_create_mkey_mbox_out lout;
43 int err; 45 int err;
44 u8 key; 46 u8 key;
45 47
46 memset(&out, 0, sizeof(out)); 48 memset(&lout, 0, sizeof(lout));
47 spin_lock(&dev->priv.mkey_lock); 49 spin_lock_irq(&dev->priv.mkey_lock);
48 key = dev->priv.mkey_key++; 50 key = dev->priv.mkey_key++;
49 spin_unlock(&dev->priv.mkey_lock); 51 spin_unlock_irq(&dev->priv.mkey_lock);
50 in->seg.qpn_mkey7_0 |= cpu_to_be32(key); 52 in->seg.qpn_mkey7_0 |= cpu_to_be32(key);
51 in->hdr.opcode = cpu_to_be16(MLX5_CMD_OP_CREATE_MKEY); 53 in->hdr.opcode = cpu_to_be16(MLX5_CMD_OP_CREATE_MKEY);
52 err = mlx5_cmd_exec(dev, in, inlen, &out, sizeof(out)); 54 if (callback) {
55 err = mlx5_cmd_exec_cb(dev, in, inlen, out, sizeof(*out),
56 callback, context);
57 return err;
58 } else {
59 err = mlx5_cmd_exec(dev, in, inlen, &lout, sizeof(lout));
60 }
61
53 if (err) { 62 if (err) {
54 mlx5_core_dbg(dev, "cmd exec faile %d\n", err); 63 mlx5_core_dbg(dev, "cmd exec faile %d\n", err);
55 return err; 64 return err;
56 } 65 }
57 66
58 if (out.hdr.status) { 67 if (lout.hdr.status) {
59 mlx5_core_dbg(dev, "status %d\n", out.hdr.status); 68 mlx5_core_dbg(dev, "status %d\n", lout.hdr.status);
60 return mlx5_cmd_status_to_err(&out.hdr); 69 return mlx5_cmd_status_to_err(&lout.hdr);
61 } 70 }
62 71
63 mr->key = mlx5_idx_to_mkey(be32_to_cpu(out.mkey) & 0xffffff) | key; 72 mr->key = mlx5_idx_to_mkey(be32_to_cpu(lout.mkey) & 0xffffff) | key;
64 mlx5_core_dbg(dev, "out 0x%x, key 0x%x, mkey 0x%x\n", be32_to_cpu(out.mkey), key, mr->key); 73 mlx5_core_dbg(dev, "out 0x%x, key 0x%x, mkey 0x%x\n",
74 be32_to_cpu(lout.mkey), key, mr->key);
65 75
66 return err; 76 return err;
67} 77}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c b/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
index 7b12acf210f8..37b6ad1f9a1b 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
@@ -57,10 +57,13 @@ struct mlx5_pages_req {
57}; 57};
58 58
59struct fw_page { 59struct fw_page {
60 struct rb_node rb_node; 60 struct rb_node rb_node;
61 u64 addr; 61 u64 addr;
62 struct page *page; 62 struct page *page;
63 u16 func_id; 63 u16 func_id;
64 unsigned long bitmask;
65 struct list_head list;
66 unsigned free_count;
64}; 67};
65 68
66struct mlx5_query_pages_inbox { 69struct mlx5_query_pages_inbox {
@@ -94,6 +97,11 @@ enum {
94 MAX_RECLAIM_TIME_MSECS = 5000, 97 MAX_RECLAIM_TIME_MSECS = 5000,
95}; 98};
96 99
100enum {
101 MLX5_MAX_RECLAIM_TIME_MILI = 5000,
102 MLX5_NUM_4K_IN_PAGE = PAGE_SIZE / 4096,
103};
104
97static int insert_page(struct mlx5_core_dev *dev, u64 addr, struct page *page, u16 func_id) 105static int insert_page(struct mlx5_core_dev *dev, u64 addr, struct page *page, u16 func_id)
98{ 106{
99 struct rb_root *root = &dev->priv.page_root; 107 struct rb_root *root = &dev->priv.page_root;
@@ -101,6 +109,7 @@ static int insert_page(struct mlx5_core_dev *dev, u64 addr, struct page *page, u
101 struct rb_node *parent = NULL; 109 struct rb_node *parent = NULL;
102 struct fw_page *nfp; 110 struct fw_page *nfp;
103 struct fw_page *tfp; 111 struct fw_page *tfp;
112 int i;
104 113
105 while (*new) { 114 while (*new) {
106 parent = *new; 115 parent = *new;
@@ -113,25 +122,29 @@ static int insert_page(struct mlx5_core_dev *dev, u64 addr, struct page *page, u
113 return -EEXIST; 122 return -EEXIST;
114 } 123 }
115 124
116 nfp = kmalloc(sizeof(*nfp), GFP_KERNEL); 125 nfp = kzalloc(sizeof(*nfp), GFP_KERNEL);
117 if (!nfp) 126 if (!nfp)
118 return -ENOMEM; 127 return -ENOMEM;
119 128
120 nfp->addr = addr; 129 nfp->addr = addr;
121 nfp->page = page; 130 nfp->page = page;
122 nfp->func_id = func_id; 131 nfp->func_id = func_id;
132 nfp->free_count = MLX5_NUM_4K_IN_PAGE;
133 for (i = 0; i < MLX5_NUM_4K_IN_PAGE; i++)
134 set_bit(i, &nfp->bitmask);
123 135
124 rb_link_node(&nfp->rb_node, parent, new); 136 rb_link_node(&nfp->rb_node, parent, new);
125 rb_insert_color(&nfp->rb_node, root); 137 rb_insert_color(&nfp->rb_node, root);
138 list_add(&nfp->list, &dev->priv.free_list);
126 139
127 return 0; 140 return 0;
128} 141}
129 142
130static struct page *remove_page(struct mlx5_core_dev *dev, u64 addr) 143static struct fw_page *find_fw_page(struct mlx5_core_dev *dev, u64 addr)
131{ 144{
132 struct rb_root *root = &dev->priv.page_root; 145 struct rb_root *root = &dev->priv.page_root;
133 struct rb_node *tmp = root->rb_node; 146 struct rb_node *tmp = root->rb_node;
134 struct page *result = NULL; 147 struct fw_page *result = NULL;
135 struct fw_page *tfp; 148 struct fw_page *tfp;
136 149
137 while (tmp) { 150 while (tmp) {
@@ -141,9 +154,7 @@ static struct page *remove_page(struct mlx5_core_dev *dev, u64 addr)
141 } else if (tfp->addr > addr) { 154 } else if (tfp->addr > addr) {
142 tmp = tmp->rb_right; 155 tmp = tmp->rb_right;
143 } else { 156 } else {
144 rb_erase(&tfp->rb_node, root); 157 result = tfp;
145 result = tfp->page;
146 kfree(tfp);
147 break; 158 break;
148 } 159 }
149 } 160 }
@@ -176,12 +187,98 @@ static int mlx5_cmd_query_pages(struct mlx5_core_dev *dev, u16 *func_id,
176 return err; 187 return err;
177} 188}
178 189
190static int alloc_4k(struct mlx5_core_dev *dev, u64 *addr)
191{
192 struct fw_page *fp;
193 unsigned n;
194
195 if (list_empty(&dev->priv.free_list)) {
196 return -ENOMEM;
197 mlx5_core_warn(dev, "\n");
198 }
199
200 fp = list_entry(dev->priv.free_list.next, struct fw_page, list);
201 n = find_first_bit(&fp->bitmask, 8 * sizeof(fp->bitmask));
202 if (n >= MLX5_NUM_4K_IN_PAGE) {
203 mlx5_core_warn(dev, "alloc 4k bug\n");
204 return -ENOENT;
205 }
206 clear_bit(n, &fp->bitmask);
207 fp->free_count--;
208 if (!fp->free_count)
209 list_del(&fp->list);
210
211 *addr = fp->addr + n * 4096;
212
213 return 0;
214}
215
216static void free_4k(struct mlx5_core_dev *dev, u64 addr)
217{
218 struct fw_page *fwp;
219 int n;
220
221 fwp = find_fw_page(dev, addr & PAGE_MASK);
222 if (!fwp) {
223 mlx5_core_warn(dev, "page not found\n");
224 return;
225 }
226
227 n = (addr & ~PAGE_MASK) % 4096;
228 fwp->free_count++;
229 set_bit(n, &fwp->bitmask);
230 if (fwp->free_count == MLX5_NUM_4K_IN_PAGE) {
231 rb_erase(&fwp->rb_node, &dev->priv.page_root);
232 if (fwp->free_count != 1)
233 list_del(&fwp->list);
234 dma_unmap_page(&dev->pdev->dev, addr, PAGE_SIZE, DMA_BIDIRECTIONAL);
235 __free_page(fwp->page);
236 kfree(fwp);
237 } else if (fwp->free_count == 1) {
238 list_add(&fwp->list, &dev->priv.free_list);
239 }
240}
241
242static int alloc_system_page(struct mlx5_core_dev *dev, u16 func_id)
243{
244 struct page *page;
245 u64 addr;
246 int err;
247
248 page = alloc_page(GFP_HIGHUSER);
249 if (!page) {
250 mlx5_core_warn(dev, "failed to allocate page\n");
251 return -ENOMEM;
252 }
253 addr = dma_map_page(&dev->pdev->dev, page, 0,
254 PAGE_SIZE, DMA_BIDIRECTIONAL);
255 if (dma_mapping_error(&dev->pdev->dev, addr)) {
256 mlx5_core_warn(dev, "failed dma mapping page\n");
257 err = -ENOMEM;
258 goto out_alloc;
259 }
260 err = insert_page(dev, addr, page, func_id);
261 if (err) {
262 mlx5_core_err(dev, "failed to track allocated page\n");
263 goto out_mapping;
264 }
265
266 return 0;
267
268out_mapping:
269 dma_unmap_page(&dev->pdev->dev, addr, PAGE_SIZE, DMA_BIDIRECTIONAL);
270
271out_alloc:
272 __free_page(page);
273
274 return err;
275}
179static int give_pages(struct mlx5_core_dev *dev, u16 func_id, int npages, 276static int give_pages(struct mlx5_core_dev *dev, u16 func_id, int npages,
180 int notify_fail) 277 int notify_fail)
181{ 278{
182 struct mlx5_manage_pages_inbox *in; 279 struct mlx5_manage_pages_inbox *in;
183 struct mlx5_manage_pages_outbox out; 280 struct mlx5_manage_pages_outbox out;
184 struct page *page; 281 struct mlx5_manage_pages_inbox *nin;
185 int inlen; 282 int inlen;
186 u64 addr; 283 u64 addr;
187 int err; 284 int err;
@@ -196,27 +293,15 @@ static int give_pages(struct mlx5_core_dev *dev, u16 func_id, int npages,
196 memset(&out, 0, sizeof(out)); 293 memset(&out, 0, sizeof(out));
197 294
198 for (i = 0; i < npages; i++) { 295 for (i = 0; i < npages; i++) {
199 page = alloc_page(GFP_HIGHUSER); 296retry:
200 if (!page) { 297 err = alloc_4k(dev, &addr);
201 err = -ENOMEM;
202 mlx5_core_warn(dev, "failed to allocate page\n");
203 goto out_alloc;
204 }
205 addr = dma_map_page(&dev->pdev->dev, page, 0,
206 PAGE_SIZE, DMA_BIDIRECTIONAL);
207 if (dma_mapping_error(&dev->pdev->dev, addr)) {
208 mlx5_core_warn(dev, "failed dma mapping page\n");
209 __free_page(page);
210 err = -ENOMEM;
211 goto out_alloc;
212 }
213 err = insert_page(dev, addr, page, func_id);
214 if (err) { 298 if (err) {
215 mlx5_core_err(dev, "failed to track allocated page\n"); 299 if (err == -ENOMEM)
216 dma_unmap_page(&dev->pdev->dev, addr, PAGE_SIZE, DMA_BIDIRECTIONAL); 300 err = alloc_system_page(dev, func_id);
217 __free_page(page); 301 if (err)
218 err = -ENOMEM; 302 goto out_4k;
219 goto out_alloc; 303
304 goto retry;
220 } 305 }
221 in->pas[i] = cpu_to_be64(addr); 306 in->pas[i] = cpu_to_be64(addr);
222 } 307 }
@@ -226,7 +311,6 @@ static int give_pages(struct mlx5_core_dev *dev, u16 func_id, int npages,
226 in->func_id = cpu_to_be16(func_id); 311 in->func_id = cpu_to_be16(func_id);
227 in->num_entries = cpu_to_be32(npages); 312 in->num_entries = cpu_to_be32(npages);
228 err = mlx5_cmd_exec(dev, in, inlen, &out, sizeof(out)); 313 err = mlx5_cmd_exec(dev, in, inlen, &out, sizeof(out));
229 mlx5_core_dbg(dev, "err %d\n", err);
230 if (err) { 314 if (err) {
231 mlx5_core_warn(dev, "func_id 0x%x, npages %d, err %d\n", func_id, npages, err); 315 mlx5_core_warn(dev, "func_id 0x%x, npages %d, err %d\n", func_id, npages, err);
232 goto out_alloc; 316 goto out_alloc;
@@ -247,25 +331,22 @@ static int give_pages(struct mlx5_core_dev *dev, u16 func_id, int npages,
247 331
248out_alloc: 332out_alloc:
249 if (notify_fail) { 333 if (notify_fail) {
250 memset(in, 0, inlen); 334 nin = kzalloc(sizeof(*nin), GFP_KERNEL);
251 memset(&out, 0, sizeof(out)); 335 if (!nin) {
252 in->hdr.opcode = cpu_to_be16(MLX5_CMD_OP_MANAGE_PAGES); 336 mlx5_core_warn(dev, "allocation failed\n");
253 in->hdr.opmod = cpu_to_be16(MLX5_PAGES_CANT_GIVE); 337 goto out_4k;
254 if (mlx5_cmd_exec(dev, in, sizeof(*in), &out, sizeof(out)))
255 mlx5_core_warn(dev, "\n");
256 }
257 for (i--; i >= 0; i--) {
258 addr = be64_to_cpu(in->pas[i]);
259 page = remove_page(dev, addr);
260 if (!page) {
261 mlx5_core_err(dev, "BUG: can't remove page at addr 0x%llx\n",
262 addr);
263 continue;
264 } 338 }
265 dma_unmap_page(&dev->pdev->dev, addr, PAGE_SIZE, DMA_BIDIRECTIONAL); 339 memset(&out, 0, sizeof(out));
266 __free_page(page); 340 nin->hdr.opcode = cpu_to_be16(MLX5_CMD_OP_MANAGE_PAGES);
341 nin->hdr.opmod = cpu_to_be16(MLX5_PAGES_CANT_GIVE);
342 if (mlx5_cmd_exec(dev, nin, sizeof(*nin), &out, sizeof(out)))
343 mlx5_core_warn(dev, "page notify failed\n");
344 kfree(nin);
267 } 345 }
268 346
347out_4k:
348 for (i--; i >= 0; i--)
349 free_4k(dev, be64_to_cpu(in->pas[i]));
269out_free: 350out_free:
270 mlx5_vfree(in); 351 mlx5_vfree(in);
271 return err; 352 return err;
@@ -276,7 +357,6 @@ static int reclaim_pages(struct mlx5_core_dev *dev, u32 func_id, int npages,
276{ 357{
277 struct mlx5_manage_pages_inbox in; 358 struct mlx5_manage_pages_inbox in;
278 struct mlx5_manage_pages_outbox *out; 359 struct mlx5_manage_pages_outbox *out;
279 struct page *page;
280 int num_claimed; 360 int num_claimed;
281 int outlen; 361 int outlen;
282 u64 addr; 362 u64 addr;
@@ -315,13 +395,7 @@ static int reclaim_pages(struct mlx5_core_dev *dev, u32 func_id, int npages,
315 395
316 for (i = 0; i < num_claimed; i++) { 396 for (i = 0; i < num_claimed; i++) {
317 addr = be64_to_cpu(out->pas[i]); 397 addr = be64_to_cpu(out->pas[i]);
318 page = remove_page(dev, addr); 398 free_4k(dev, addr);
319 if (!page) {
320 mlx5_core_warn(dev, "FW reported unknown DMA address 0x%llx\n", addr);
321 } else {
322 dma_unmap_page(&dev->pdev->dev, addr, PAGE_SIZE, DMA_BIDIRECTIONAL);
323 __free_page(page);
324 }
325 } 399 }
326 400
327out_free: 401out_free:
@@ -381,14 +455,19 @@ int mlx5_satisfy_startup_pages(struct mlx5_core_dev *dev, int boot)
381 return give_pages(dev, func_id, npages, 0); 455 return give_pages(dev, func_id, npages, 0);
382} 456}
383 457
458enum {
459 MLX5_BLKS_FOR_RECLAIM_PAGES = 12
460};
461
384static int optimal_reclaimed_pages(void) 462static int optimal_reclaimed_pages(void)
385{ 463{
386 struct mlx5_cmd_prot_block *block; 464 struct mlx5_cmd_prot_block *block;
387 struct mlx5_cmd_layout *lay; 465 struct mlx5_cmd_layout *lay;
388 int ret; 466 int ret;
389 467
390 ret = (sizeof(lay->in) + sizeof(block->data) - 468 ret = (sizeof(lay->out) + MLX5_BLKS_FOR_RECLAIM_PAGES * sizeof(block->data) -
391 sizeof(struct mlx5_manage_pages_outbox)) / 8; 469 sizeof(struct mlx5_manage_pages_outbox)) /
470 FIELD_SIZEOF(struct mlx5_manage_pages_outbox, pas[0]);
392 471
393 return ret; 472 return ret;
394} 473}
@@ -427,6 +506,7 @@ int mlx5_reclaim_startup_pages(struct mlx5_core_dev *dev)
427void mlx5_pagealloc_init(struct mlx5_core_dev *dev) 506void mlx5_pagealloc_init(struct mlx5_core_dev *dev)
428{ 507{
429 dev->priv.page_root = RB_ROOT; 508 dev->priv.page_root = RB_ROOT;
509 INIT_LIST_HEAD(&dev->priv.free_list);
430} 510}
431 511
432void mlx5_pagealloc_cleanup(struct mlx5_core_dev *dev) 512void mlx5_pagealloc_cleanup(struct mlx5_core_dev *dev)
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index e6f92b450913..5e2054afe840 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -346,6 +346,12 @@ config CHARGER_BQ24190
346 help 346 help
347 Say Y to enable support for the TI BQ24190 battery charger. 347 Say Y to enable support for the TI BQ24190 battery charger.
348 348
349config CHARGER_BQ24735
350 tristate "TI BQ24735 battery charger support"
351 depends on I2C && GPIOLIB
352 help
353 Say Y to enable support for the TI BQ24735 battery charger.
354
349config CHARGER_SMB347 355config CHARGER_SMB347
350 tristate "Summit Microelectronics SMB347 Battery Charger" 356 tristate "Summit Microelectronics SMB347 Battery Charger"
351 depends on I2C 357 depends on I2C
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index a4b74177706f..372b4e8ab598 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -52,6 +52,7 @@ obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o
52obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o 52obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o
53obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o 53obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o
54obj-$(CONFIG_CHARGER_BQ24190) += bq24190_charger.o 54obj-$(CONFIG_CHARGER_BQ24190) += bq24190_charger.o
55obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
55obj-$(CONFIG_POWER_AVS) += avs/ 56obj-$(CONFIG_POWER_AVS) += avs/
56obj-$(CONFIG_CHARGER_SMB347) += smb347-charger.o 57obj-$(CONFIG_CHARGER_SMB347) += smb347-charger.o
57obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o 58obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c
index a4c4a10b3a41..19110aa613a1 100644
--- a/drivers/power/ab8500_charger.c
+++ b/drivers/power/ab8500_charger.c
@@ -766,7 +766,6 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,
766 ret = -ENXIO; 766 ret = -ENXIO;
767 break; 767 break;
768 } 768 }
769 break;
770 case USB_STAT_CARKIT_1: 769 case USB_STAT_CARKIT_1:
771 case USB_STAT_CARKIT_2: 770 case USB_STAT_CARKIT_2:
772 case USB_STAT_ACA_DOCK_CHARGER: 771 case USB_STAT_ACA_DOCK_CHARGER:
@@ -1387,8 +1386,12 @@ static int ab8500_charger_ac_en(struct ux500_charger *charger,
1387 * the GPADC module independant of the AB8500 chargers 1386 * the GPADC module independant of the AB8500 chargers
1388 */ 1387 */
1389 if (!di->vddadc_en_ac) { 1388 if (!di->vddadc_en_ac) {
1390 regulator_enable(di->regu); 1389 ret = regulator_enable(di->regu);
1391 di->vddadc_en_ac = true; 1390 if (ret)
1391 dev_warn(di->dev,
1392 "Failed to enable regulator\n");
1393 else
1394 di->vddadc_en_ac = true;
1392 } 1395 }
1393 1396
1394 /* Check if the requested voltage or current is valid */ 1397 /* Check if the requested voltage or current is valid */
@@ -1556,8 +1559,12 @@ static int ab8500_charger_usb_en(struct ux500_charger *charger,
1556 * the GPADC module independant of the AB8500 chargers 1559 * the GPADC module independant of the AB8500 chargers
1557 */ 1560 */
1558 if (!di->vddadc_en_usb) { 1561 if (!di->vddadc_en_usb) {
1559 regulator_enable(di->regu); 1562 ret = regulator_enable(di->regu);
1560 di->vddadc_en_usb = true; 1563 if (ret)
1564 dev_warn(di->dev,
1565 "Failed to enable regulator\n");
1566 else
1567 di->vddadc_en_usb = true;
1561 } 1568 }
1562 1569
1563 /* Enable USB charging */ 1570 /* Enable USB charging */
diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index 0727f9256138..df893dd1447d 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -605,9 +605,13 @@ static int bq2415x_set_battery_regulation_voltage(struct bq2415x_device *bq,
605{ 605{
606 int val = (mV/10 - 350) / 2; 606 int val = (mV/10 - 350) / 2;
607 607
608 /*
609 * According to datasheet, maximum battery regulation voltage is
610 * 4440mV which is b101111 = 47.
611 */
608 if (val < 0) 612 if (val < 0)
609 val = 0; 613 val = 0;
610 else if (val > 94) /* FIXME: Max is 94 or 122 ? Set max value ? */ 614 else if (val > 47)
611 return -EINVAL; 615 return -EINVAL;
612 616
613 return bq2415x_i2c_write_mask(bq, BQ2415X_REG_VOLTAGE, val, 617 return bq2415x_i2c_write_mask(bq, BQ2415X_REG_VOLTAGE, val,
diff --git a/drivers/power/bq24735-charger.c b/drivers/power/bq24735-charger.c
new file mode 100644
index 000000000000..d022b823305b
--- /dev/null
+++ b/drivers/power/bq24735-charger.c
@@ -0,0 +1,419 @@
1/*
2 * Battery charger driver for TI BQ24735
3 *
4 * Copyright (c) 2013, NVIDIA CORPORATION. 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 as published by
8 * the Free Software Foundation;
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#include <linux/err.h>
21#include <linux/gpio.h>
22#include <linux/i2c.h>
23#include <linux/init.h>
24#include <linux/interrupt.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/of.h>
28#include <linux/of_gpio.h>
29#include <linux/power_supply.h>
30#include <linux/slab.h>
31
32#include <linux/power/bq24735-charger.h>
33
34#define BQ24735_CHG_OPT 0x12
35#define BQ24735_CHG_OPT_CHARGE_DISABLE (1 << 0)
36#define BQ24735_CHG_OPT_AC_PRESENT (1 << 4)
37#define BQ24735_CHARGE_CURRENT 0x14
38#define BQ24735_CHARGE_CURRENT_MASK 0x1fc0
39#define BQ24735_CHARGE_VOLTAGE 0x15
40#define BQ24735_CHARGE_VOLTAGE_MASK 0x7ff0
41#define BQ24735_INPUT_CURRENT 0x3f
42#define BQ24735_INPUT_CURRENT_MASK 0x1f80
43#define BQ24735_MANUFACTURER_ID 0xfe
44#define BQ24735_DEVICE_ID 0xff
45
46struct bq24735 {
47 struct power_supply charger;
48 struct i2c_client *client;
49 struct bq24735_platform *pdata;
50};
51
52static inline struct bq24735 *to_bq24735(struct power_supply *psy)
53{
54 return container_of(psy, struct bq24735, charger);
55}
56
57static enum power_supply_property bq24735_charger_properties[] = {
58 POWER_SUPPLY_PROP_ONLINE,
59};
60
61static inline int bq24735_write_word(struct i2c_client *client, u8 reg,
62 u16 value)
63{
64 return i2c_smbus_write_word_data(client, reg, le16_to_cpu(value));
65}
66
67static inline int bq24735_read_word(struct i2c_client *client, u8 reg)
68{
69 s32 ret = i2c_smbus_read_word_data(client, reg);
70
71 return ret < 0 ? ret : le16_to_cpu(ret);
72}
73
74static int bq24735_update_word(struct i2c_client *client, u8 reg,
75 u16 mask, u16 value)
76{
77 unsigned int tmp;
78 int ret;
79
80 ret = bq24735_read_word(client, reg);
81 if (ret < 0)
82 return ret;
83
84 tmp = ret & ~mask;
85 tmp |= value & mask;
86
87 return bq24735_write_word(client, reg, tmp);
88}
89
90static inline int bq24735_enable_charging(struct bq24735 *charger)
91{
92 return bq24735_update_word(charger->client, BQ24735_CHG_OPT,
93 BQ24735_CHG_OPT_CHARGE_DISABLE,
94 ~BQ24735_CHG_OPT_CHARGE_DISABLE);
95}
96
97static inline int bq24735_disable_charging(struct bq24735 *charger)
98{
99 return bq24735_update_word(charger->client, BQ24735_CHG_OPT,
100 BQ24735_CHG_OPT_CHARGE_DISABLE,
101 BQ24735_CHG_OPT_CHARGE_DISABLE);
102}
103
104static int bq24735_config_charger(struct bq24735 *charger)
105{
106 struct bq24735_platform *pdata = charger->pdata;
107 int ret;
108 u16 value;
109
110 if (pdata->charge_current) {
111 value = pdata->charge_current & BQ24735_CHARGE_CURRENT_MASK;
112
113 ret = bq24735_write_word(charger->client,
114 BQ24735_CHARGE_CURRENT, value);
115 if (ret < 0) {
116 dev_err(&charger->client->dev,
117 "Failed to write charger current : %d\n",
118 ret);
119 return ret;
120 }
121 }
122
123 if (pdata->charge_voltage) {
124 value = pdata->charge_voltage & BQ24735_CHARGE_VOLTAGE_MASK;
125
126 ret = bq24735_write_word(charger->client,
127 BQ24735_CHARGE_VOLTAGE, value);
128 if (ret < 0) {
129 dev_err(&charger->client->dev,
130 "Failed to write charger voltage : %d\n",
131 ret);
132 return ret;
133 }
134 }
135
136 if (pdata->input_current) {
137 value = pdata->input_current & BQ24735_INPUT_CURRENT_MASK;
138
139 ret = bq24735_write_word(charger->client,
140 BQ24735_INPUT_CURRENT, value);
141 if (ret < 0) {
142 dev_err(&charger->client->dev,
143 "Failed to write input current : %d\n",
144 ret);
145 return ret;
146 }
147 }
148
149 return 0;
150}
151
152static bool bq24735_charger_is_present(struct bq24735 *charger)
153{
154 struct bq24735_platform *pdata = charger->pdata;
155 int ret;
156
157 if (pdata->status_gpio_valid) {
158 ret = gpio_get_value_cansleep(pdata->status_gpio);
159 return ret ^= pdata->status_gpio_active_low == 0;
160 } else {
161 int ac = 0;
162
163 ac = bq24735_read_word(charger->client, BQ24735_CHG_OPT);
164 if (ac < 0) {
165 dev_err(&charger->client->dev,
166 "Failed to read charger options : %d\n",
167 ac);
168 return false;
169 }
170 return (ac & BQ24735_CHG_OPT_AC_PRESENT) ? true : false;
171 }
172
173 return false;
174}
175
176static irqreturn_t bq24735_charger_isr(int irq, void *devid)
177{
178 struct power_supply *psy = devid;
179 struct bq24735 *charger = to_bq24735(psy);
180
181 if (bq24735_charger_is_present(charger))
182 bq24735_enable_charging(charger);
183 else
184 bq24735_disable_charging(charger);
185
186 power_supply_changed(psy);
187
188 return IRQ_HANDLED;
189}
190
191static int bq24735_charger_get_property(struct power_supply *psy,
192 enum power_supply_property psp,
193 union power_supply_propval *val)
194{
195 struct bq24735 *charger;
196
197 charger = container_of(psy, struct bq24735, charger);
198
199 switch (psp) {
200 case POWER_SUPPLY_PROP_ONLINE:
201 val->intval = bq24735_charger_is_present(charger) ? 1 : 0;
202 break;
203 default:
204 return -EINVAL;
205 }
206
207 return 0;
208}
209
210static struct bq24735_platform *bq24735_parse_dt_data(struct i2c_client *client)
211{
212 struct bq24735_platform *pdata;
213 struct device_node *np = client->dev.of_node;
214 u32 val;
215 int ret;
216 enum of_gpio_flags flags;
217
218 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
219 if (!pdata) {
220 dev_err(&client->dev,
221 "Memory alloc for bq24735 pdata failed\n");
222 return NULL;
223 }
224
225 pdata->status_gpio = of_get_named_gpio_flags(np, "ti,ac-detect-gpios",
226 0, &flags);
227
228 if (flags & OF_GPIO_ACTIVE_LOW)
229 pdata->status_gpio_active_low = 1;
230
231 ret = of_property_read_u32(np, "ti,charge-current", &val);
232 if (!ret)
233 pdata->charge_current = val;
234
235 ret = of_property_read_u32(np, "ti,charge-voltage", &val);
236 if (!ret)
237 pdata->charge_voltage = val;
238
239 ret = of_property_read_u32(np, "ti,input-current", &val);
240 if (!ret)
241 pdata->input_current = val;
242
243 return pdata;
244}
245
246static int bq24735_charger_probe(struct i2c_client *client,
247 const struct i2c_device_id *id)
248{
249 int ret;
250 struct bq24735 *charger;
251 struct power_supply *supply;
252 char *name;
253
254 charger = devm_kzalloc(&client->dev, sizeof(*charger), GFP_KERNEL);
255 if (!charger)
256 return -ENOMEM;
257
258 charger->pdata = client->dev.platform_data;
259
260 if (IS_ENABLED(CONFIG_OF) && !charger->pdata && client->dev.of_node)
261 charger->pdata = bq24735_parse_dt_data(client);
262
263 if (!charger->pdata) {
264 dev_err(&client->dev, "no platform data provided\n");
265 return -EINVAL;
266 }
267
268 name = (char *)charger->pdata->name;
269 if (!name) {
270 name = kasprintf(GFP_KERNEL, "bq24735@%s",
271 dev_name(&client->dev));
272 if (!name) {
273 dev_err(&client->dev, "Failed to alloc device name\n");
274 return -ENOMEM;
275 }
276 }
277
278 charger->client = client;
279
280 supply = &charger->charger;
281
282 supply->name = name;
283 supply->type = POWER_SUPPLY_TYPE_MAINS;
284 supply->properties = bq24735_charger_properties;
285 supply->num_properties = ARRAY_SIZE(bq24735_charger_properties);
286 supply->get_property = bq24735_charger_get_property;
287 supply->supplied_to = charger->pdata->supplied_to;
288 supply->num_supplicants = charger->pdata->num_supplicants;
289 supply->of_node = client->dev.of_node;
290
291 i2c_set_clientdata(client, charger);
292
293 ret = bq24735_read_word(client, BQ24735_MANUFACTURER_ID);
294 if (ret < 0) {
295 dev_err(&client->dev, "Failed to read manufacturer id : %d\n",
296 ret);
297 goto err_free_name;
298 } else if (ret != 0x0040) {
299 dev_err(&client->dev,
300 "manufacturer id mismatch. 0x0040 != 0x%04x\n", ret);
301 ret = -ENODEV;
302 goto err_free_name;
303 }
304
305 ret = bq24735_read_word(client, BQ24735_DEVICE_ID);
306 if (ret < 0) {
307 dev_err(&client->dev, "Failed to read device id : %d\n", ret);
308 goto err_free_name;
309 } else if (ret != 0x000B) {
310 dev_err(&client->dev,
311 "device id mismatch. 0x000b != 0x%04x\n", ret);
312 ret = -ENODEV;
313 goto err_free_name;
314 }
315
316 if (gpio_is_valid(charger->pdata->status_gpio)) {
317 ret = devm_gpio_request(&client->dev,
318 charger->pdata->status_gpio,
319 name);
320 if (ret) {
321 dev_err(&client->dev,
322 "Failed GPIO request for GPIO %d: %d\n",
323 charger->pdata->status_gpio, ret);
324 }
325
326 charger->pdata->status_gpio_valid = !ret;
327 }
328
329 ret = bq24735_config_charger(charger);
330 if (ret < 0) {
331 dev_err(&client->dev, "failed in configuring charger");
332 goto err_free_name;
333 }
334
335 /* check for AC adapter presence */
336 if (bq24735_charger_is_present(charger)) {
337 ret = bq24735_enable_charging(charger);
338 if (ret < 0) {
339 dev_err(&client->dev, "Failed to enable charging\n");
340 goto err_free_name;
341 }
342 }
343
344 ret = power_supply_register(&client->dev, supply);
345 if (ret < 0) {
346 dev_err(&client->dev, "Failed to register power supply: %d\n",
347 ret);
348 goto err_free_name;
349 }
350
351 if (client->irq) {
352 ret = devm_request_threaded_irq(&client->dev, client->irq,
353 NULL, bq24735_charger_isr,
354 IRQF_TRIGGER_RISING |
355 IRQF_TRIGGER_FALLING |
356 IRQF_ONESHOT,
357 supply->name, supply);
358 if (ret) {
359 dev_err(&client->dev,
360 "Unable to register IRQ %d err %d\n",
361 client->irq, ret);
362 goto err_unregister_supply;
363 }
364 }
365
366 return 0;
367err_unregister_supply:
368 power_supply_unregister(supply);
369err_free_name:
370 if (name != charger->pdata->name)
371 kfree(name);
372
373 return ret;
374}
375
376static int bq24735_charger_remove(struct i2c_client *client)
377{
378 struct bq24735 *charger = i2c_get_clientdata(client);
379
380 if (charger->client->irq)
381 devm_free_irq(&charger->client->dev, charger->client->irq,
382 &charger->charger);
383
384 power_supply_unregister(&charger->charger);
385
386 if (charger->charger.name != charger->pdata->name)
387 kfree(charger->charger.name);
388
389 return 0;
390}
391
392static const struct i2c_device_id bq24735_charger_id[] = {
393 { "bq24735-charger", 0 },
394 {}
395};
396MODULE_DEVICE_TABLE(i2c, bq24735_charger_id);
397
398static const struct of_device_id bq24735_match_ids[] = {
399 { .compatible = "ti,bq24735", },
400 { /* end */ }
401};
402MODULE_DEVICE_TABLE(of, bq24735_match_ids);
403
404static struct i2c_driver bq24735_charger_driver = {
405 .driver = {
406 .name = "bq24735-charger",
407 .owner = THIS_MODULE,
408 .of_match_table = bq24735_match_ids,
409 },
410 .probe = bq24735_charger_probe,
411 .remove = bq24735_charger_remove,
412 .id_table = bq24735_charger_id,
413};
414
415module_i2c_driver(bq24735_charger_driver);
416
417MODULE_DESCRIPTION("bq24735 battery charging driver");
418MODULE_AUTHOR("Darbha Sriharsha <dsriharsha@nvidia.com>");
419MODULE_LICENSE("GPL v2");
diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c
index e30e847600bb..7287c0efd6bf 100644
--- a/drivers/power/charger-manager.c
+++ b/drivers/power/charger-manager.c
@@ -1378,7 +1378,8 @@ static int charger_manager_register_sysfs(struct charger_manager *cm)
1378 charger = &desc->charger_regulators[i]; 1378 charger = &desc->charger_regulators[i];
1379 1379
1380 snprintf(buf, 10, "charger.%d", i); 1380 snprintf(buf, 10, "charger.%d", i);
1381 str = kzalloc(sizeof(char) * (strlen(buf) + 1), GFP_KERNEL); 1381 str = devm_kzalloc(cm->dev,
1382 sizeof(char) * (strlen(buf) + 1), GFP_KERNEL);
1382 if (!str) { 1383 if (!str) {
1383 ret = -ENOMEM; 1384 ret = -ENOMEM;
1384 goto err; 1385 goto err;
@@ -1452,30 +1453,23 @@ static int charger_manager_probe(struct platform_device *pdev)
1452 rtc_dev = NULL; 1453 rtc_dev = NULL;
1453 dev_err(&pdev->dev, "Cannot get RTC %s\n", 1454 dev_err(&pdev->dev, "Cannot get RTC %s\n",
1454 g_desc->rtc_name); 1455 g_desc->rtc_name);
1455 ret = -ENODEV; 1456 return -ENODEV;
1456 goto err_alloc;
1457 } 1457 }
1458 } 1458 }
1459 1459
1460 if (!desc) { 1460 if (!desc) {
1461 dev_err(&pdev->dev, "No platform data (desc) found\n"); 1461 dev_err(&pdev->dev, "No platform data (desc) found\n");
1462 ret = -ENODEV; 1462 return -ENODEV;
1463 goto err_alloc;
1464 } 1463 }
1465 1464
1466 cm = kzalloc(sizeof(struct charger_manager), GFP_KERNEL); 1465 cm = devm_kzalloc(&pdev->dev,
1467 if (!cm) { 1466 sizeof(struct charger_manager), GFP_KERNEL);
1468 ret = -ENOMEM; 1467 if (!cm)
1469 goto err_alloc; 1468 return -ENOMEM;
1470 }
1471 1469
1472 /* Basic Values. Unspecified are Null or 0 */ 1470 /* Basic Values. Unspecified are Null or 0 */
1473 cm->dev = &pdev->dev; 1471 cm->dev = &pdev->dev;
1474 cm->desc = kmemdup(desc, sizeof(struct charger_desc), GFP_KERNEL); 1472 cm->desc = desc;
1475 if (!cm->desc) {
1476 ret = -ENOMEM;
1477 goto err_alloc_desc;
1478 }
1479 cm->last_temp_mC = INT_MIN; /* denotes "unmeasured, yet" */ 1473 cm->last_temp_mC = INT_MIN; /* denotes "unmeasured, yet" */
1480 1474
1481 /* 1475 /*
@@ -1498,27 +1492,23 @@ static int charger_manager_probe(struct platform_device *pdev)
1498 } 1492 }
1499 1493
1500 if (!desc->charger_regulators || desc->num_charger_regulators < 1) { 1494 if (!desc->charger_regulators || desc->num_charger_regulators < 1) {
1501 ret = -EINVAL;
1502 dev_err(&pdev->dev, "charger_regulators undefined\n"); 1495 dev_err(&pdev->dev, "charger_regulators undefined\n");
1503 goto err_no_charger; 1496 return -EINVAL;
1504 } 1497 }
1505 1498
1506 if (!desc->psy_charger_stat || !desc->psy_charger_stat[0]) { 1499 if (!desc->psy_charger_stat || !desc->psy_charger_stat[0]) {
1507 dev_err(&pdev->dev, "No power supply defined\n"); 1500 dev_err(&pdev->dev, "No power supply defined\n");
1508 ret = -EINVAL; 1501 return -EINVAL;
1509 goto err_no_charger_stat;
1510 } 1502 }
1511 1503
1512 /* Counting index only */ 1504 /* Counting index only */
1513 while (desc->psy_charger_stat[i]) 1505 while (desc->psy_charger_stat[i])
1514 i++; 1506 i++;
1515 1507
1516 cm->charger_stat = kzalloc(sizeof(struct power_supply *) * (i + 1), 1508 cm->charger_stat = devm_kzalloc(&pdev->dev,
1517 GFP_KERNEL); 1509 sizeof(struct power_supply *) * i, GFP_KERNEL);
1518 if (!cm->charger_stat) { 1510 if (!cm->charger_stat)
1519 ret = -ENOMEM; 1511 return -ENOMEM;
1520 goto err_no_charger_stat;
1521 }
1522 1512
1523 for (i = 0; desc->psy_charger_stat[i]; i++) { 1513 for (i = 0; desc->psy_charger_stat[i]; i++) {
1524 cm->charger_stat[i] = power_supply_get_by_name( 1514 cm->charger_stat[i] = power_supply_get_by_name(
@@ -1526,8 +1516,7 @@ static int charger_manager_probe(struct platform_device *pdev)
1526 if (!cm->charger_stat[i]) { 1516 if (!cm->charger_stat[i]) {
1527 dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n", 1517 dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
1528 desc->psy_charger_stat[i]); 1518 desc->psy_charger_stat[i]);
1529 ret = -ENODEV; 1519 return -ENODEV;
1530 goto err_chg_stat;
1531 } 1520 }
1532 } 1521 }
1533 1522
@@ -1535,21 +1524,18 @@ static int charger_manager_probe(struct platform_device *pdev)
1535 if (!cm->fuel_gauge) { 1524 if (!cm->fuel_gauge) {
1536 dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n", 1525 dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
1537 desc->psy_fuel_gauge); 1526 desc->psy_fuel_gauge);
1538 ret = -ENODEV; 1527 return -ENODEV;
1539 goto err_chg_stat;
1540 } 1528 }
1541 1529
1542 if (desc->polling_interval_ms == 0 || 1530 if (desc->polling_interval_ms == 0 ||
1543 msecs_to_jiffies(desc->polling_interval_ms) <= CM_JIFFIES_SMALL) { 1531 msecs_to_jiffies(desc->polling_interval_ms) <= CM_JIFFIES_SMALL) {
1544 dev_err(&pdev->dev, "polling_interval_ms is too small\n"); 1532 dev_err(&pdev->dev, "polling_interval_ms is too small\n");
1545 ret = -EINVAL; 1533 return -EINVAL;
1546 goto err_chg_stat;
1547 } 1534 }
1548 1535
1549 if (!desc->temperature_out_of_range) { 1536 if (!desc->temperature_out_of_range) {
1550 dev_err(&pdev->dev, "there is no temperature_out_of_range\n"); 1537 dev_err(&pdev->dev, "there is no temperature_out_of_range\n");
1551 ret = -EINVAL; 1538 return -EINVAL;
1552 goto err_chg_stat;
1553 } 1539 }
1554 1540
1555 if (!desc->charging_max_duration_ms || 1541 if (!desc->charging_max_duration_ms ||
@@ -1570,14 +1556,13 @@ static int charger_manager_probe(struct platform_device *pdev)
1570 cm->charger_psy.name = cm->psy_name_buf; 1556 cm->charger_psy.name = cm->psy_name_buf;
1571 1557
1572 /* Allocate for psy properties because they may vary */ 1558 /* Allocate for psy properties because they may vary */
1573 cm->charger_psy.properties = kzalloc(sizeof(enum power_supply_property) 1559 cm->charger_psy.properties = devm_kzalloc(&pdev->dev,
1560 sizeof(enum power_supply_property)
1574 * (ARRAY_SIZE(default_charger_props) + 1561 * (ARRAY_SIZE(default_charger_props) +
1575 NUM_CHARGER_PSY_OPTIONAL), 1562 NUM_CHARGER_PSY_OPTIONAL), GFP_KERNEL);
1576 GFP_KERNEL); 1563 if (!cm->charger_psy.properties)
1577 if (!cm->charger_psy.properties) { 1564 return -ENOMEM;
1578 ret = -ENOMEM; 1565
1579 goto err_chg_stat;
1580 }
1581 memcpy(cm->charger_psy.properties, default_charger_props, 1566 memcpy(cm->charger_psy.properties, default_charger_props,
1582 sizeof(enum power_supply_property) * 1567 sizeof(enum power_supply_property) *
1583 ARRAY_SIZE(default_charger_props)); 1568 ARRAY_SIZE(default_charger_props));
@@ -1614,7 +1599,7 @@ static int charger_manager_probe(struct platform_device *pdev)
1614 if (ret) { 1599 if (ret) {
1615 dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n", 1600 dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n",
1616 cm->charger_psy.name); 1601 cm->charger_psy.name);
1617 goto err_register; 1602 return ret;
1618 } 1603 }
1619 1604
1620 /* Register extcon device for charger cable */ 1605 /* Register extcon device for charger cable */
@@ -1655,8 +1640,6 @@ err_reg_sysfs:
1655 charger = &desc->charger_regulators[i]; 1640 charger = &desc->charger_regulators[i];
1656 sysfs_remove_group(&cm->charger_psy.dev->kobj, 1641 sysfs_remove_group(&cm->charger_psy.dev->kobj,
1657 &charger->attr_g); 1642 &charger->attr_g);
1658
1659 kfree(charger->attr_g.name);
1660 } 1643 }
1661err_reg_extcon: 1644err_reg_extcon:
1662 for (i = 0; i < desc->num_charger_regulators; i++) { 1645 for (i = 0; i < desc->num_charger_regulators; i++) {
@@ -1674,16 +1657,7 @@ err_reg_extcon:
1674 } 1657 }
1675 1658
1676 power_supply_unregister(&cm->charger_psy); 1659 power_supply_unregister(&cm->charger_psy);
1677err_register: 1660
1678 kfree(cm->charger_psy.properties);
1679err_chg_stat:
1680 kfree(cm->charger_stat);
1681err_no_charger_stat:
1682err_no_charger:
1683 kfree(cm->desc);
1684err_alloc_desc:
1685 kfree(cm);
1686err_alloc:
1687 return ret; 1661 return ret;
1688} 1662}
1689 1663
@@ -1718,11 +1692,6 @@ static int charger_manager_remove(struct platform_device *pdev)
1718 1692
1719 try_charger_enable(cm, false); 1693 try_charger_enable(cm, false);
1720 1694
1721 kfree(cm->charger_psy.properties);
1722 kfree(cm->charger_stat);
1723 kfree(cm->desc);
1724 kfree(cm);
1725
1726 return 0; 1695 return 0;
1727} 1696}
1728 1697
diff --git a/drivers/power/isp1704_charger.c b/drivers/power/isp1704_charger.c
index fc04d191579b..1bb3a91b1acc 100644
--- a/drivers/power/isp1704_charger.c
+++ b/drivers/power/isp1704_charger.c
@@ -2,6 +2,7 @@
2 * ISP1704 USB Charger Detection driver 2 * ISP1704 USB Charger Detection driver
3 * 3 *
4 * Copyright (C) 2010 Nokia Corporation 4 * Copyright (C) 2010 Nokia Corporation
5 * Copyright (C) 2012 - 2013 Pali Rohár <pali.rohar@gmail.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * 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 * it under the terms of the GNU General Public License as published by
@@ -65,10 +66,6 @@ struct isp1704_charger {
65 unsigned present:1; 66 unsigned present:1;
66 unsigned online:1; 67 unsigned online:1;
67 unsigned current_max; 68 unsigned current_max;
68
69 /* temp storage variables */
70 unsigned long event;
71 unsigned max_power;
72}; 69};
73 70
74static inline int isp1704_read(struct isp1704_charger *isp, u32 reg) 71static inline int isp1704_read(struct isp1704_charger *isp, u32 reg)
@@ -231,56 +228,59 @@ static inline int isp1704_charger_detect(struct isp1704_charger *isp)
231 return ret; 228 return ret;
232} 229}
233 230
231static inline int isp1704_charger_detect_dcp(struct isp1704_charger *isp)
232{
233 if (isp1704_charger_detect(isp) &&
234 isp1704_charger_type(isp) == POWER_SUPPLY_TYPE_USB_DCP)
235 return true;
236 else
237 return false;
238}
239
234static void isp1704_charger_work(struct work_struct *data) 240static void isp1704_charger_work(struct work_struct *data)
235{ 241{
236 int detect;
237 unsigned long event;
238 unsigned power;
239 struct isp1704_charger *isp = 242 struct isp1704_charger *isp =
240 container_of(data, struct isp1704_charger, work); 243 container_of(data, struct isp1704_charger, work);
241 static DEFINE_MUTEX(lock); 244 static DEFINE_MUTEX(lock);
242 245
243 event = isp->event;
244 power = isp->max_power;
245
246 mutex_lock(&lock); 246 mutex_lock(&lock);
247 247
248 if (event != USB_EVENT_NONE) 248 switch (isp->phy->last_event) {
249 isp1704_charger_set_power(isp, 1);
250
251 switch (event) {
252 case USB_EVENT_VBUS: 249 case USB_EVENT_VBUS:
253 isp->online = true; 250 /* do not call wall charger detection more times */
251 if (!isp->present) {
252 isp->online = true;
253 isp->present = 1;
254 isp1704_charger_set_power(isp, 1);
255
256 /* detect wall charger */
257 if (isp1704_charger_detect_dcp(isp)) {
258 isp->psy.type = POWER_SUPPLY_TYPE_USB_DCP;
259 isp->current_max = 1800;
260 } else {
261 isp->psy.type = POWER_SUPPLY_TYPE_USB;
262 isp->current_max = 500;
263 }
254 264
255 /* detect charger */ 265 /* enable data pullups */
256 detect = isp1704_charger_detect(isp); 266 if (isp->phy->otg->gadget)
257 267 usb_gadget_connect(isp->phy->otg->gadget);
258 if (detect) {
259 isp->present = detect;
260 isp->psy.type = isp1704_charger_type(isp);
261 } 268 }
262 269
263 switch (isp->psy.type) { 270 if (isp->psy.type != POWER_SUPPLY_TYPE_USB_DCP) {
264 case POWER_SUPPLY_TYPE_USB_DCP:
265 isp->current_max = 1800;
266 break;
267 case POWER_SUPPLY_TYPE_USB_CDP:
268 /* 271 /*
269 * Only 500mA here or high speed chirp 272 * Only 500mA here or high speed chirp
270 * handshaking may break 273 * handshaking may break
271 */ 274 */
272 isp->current_max = 500; 275 if (isp->current_max > 500)
273 /* FALLTHROUGH */ 276 isp->current_max = 500;
274 case POWER_SUPPLY_TYPE_USB: 277
275 default: 278 if (isp->current_max > 100)
276 /* enable data pullups */ 279 isp->psy.type = POWER_SUPPLY_TYPE_USB_CDP;
277 if (isp->phy->otg->gadget)
278 usb_gadget_connect(isp->phy->otg->gadget);
279 } 280 }
280 break; 281 break;
281 case USB_EVENT_NONE: 282 case USB_EVENT_NONE:
282 isp->online = false; 283 isp->online = false;
283 isp->current_max = 0;
284 isp->present = 0; 284 isp->present = 0;
285 isp->current_max = 0; 285 isp->current_max = 0;
286 isp->psy.type = POWER_SUPPLY_TYPE_USB; 286 isp->psy.type = POWER_SUPPLY_TYPE_USB;
@@ -298,12 +298,6 @@ static void isp1704_charger_work(struct work_struct *data)
298 298
299 isp1704_charger_set_power(isp, 0); 299 isp1704_charger_set_power(isp, 0);
300 break; 300 break;
301 case USB_EVENT_ENUMERATED:
302 if (isp->present)
303 isp->current_max = 1800;
304 else
305 isp->current_max = power;
306 break;
307 default: 301 default:
308 goto out; 302 goto out;
309 } 303 }
@@ -314,16 +308,11 @@ out:
314} 308}
315 309
316static int isp1704_notifier_call(struct notifier_block *nb, 310static int isp1704_notifier_call(struct notifier_block *nb,
317 unsigned long event, void *power) 311 unsigned long val, void *v)
318{ 312{
319 struct isp1704_charger *isp = 313 struct isp1704_charger *isp =
320 container_of(nb, struct isp1704_charger, nb); 314 container_of(nb, struct isp1704_charger, nb);
321 315
322 isp->event = event;
323
324 if (power)
325 isp->max_power = *((unsigned *)power);
326
327 schedule_work(&isp->work); 316 schedule_work(&isp->work);
328 317
329 return NOTIFY_OK; 318 return NOTIFY_OK;
@@ -462,13 +451,13 @@ static int isp1704_charger_probe(struct platform_device *pdev)
462 if (isp->phy->otg->gadget) 451 if (isp->phy->otg->gadget)
463 usb_gadget_disconnect(isp->phy->otg->gadget); 452 usb_gadget_disconnect(isp->phy->otg->gadget);
464 453
454 if (isp->phy->last_event == USB_EVENT_NONE)
455 isp1704_charger_set_power(isp, 0);
456
465 /* Detect charger if VBUS is valid (the cable was already plugged). */ 457 /* Detect charger if VBUS is valid (the cable was already plugged). */
466 ret = isp1704_read(isp, ULPI_USB_INT_STS); 458 if (isp->phy->last_event == USB_EVENT_VBUS &&
467 isp1704_charger_set_power(isp, 0); 459 !isp->phy->otg->default_a)
468 if ((ret & ULPI_INT_VBUS_VALID) && !isp->phy->otg->default_a) {
469 isp->event = USB_EVENT_VBUS;
470 schedule_work(&isp->work); 460 schedule_work(&isp->work);
471 }
472 461
473 return 0; 462 return 0;
474fail2: 463fail2:
diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c
index d664ef58afa7..e0b22f9b6fdd 100644
--- a/drivers/power/max17042_battery.c
+++ b/drivers/power/max17042_battery.c
@@ -33,6 +33,7 @@
33#include <linux/power_supply.h> 33#include <linux/power_supply.h>
34#include <linux/power/max17042_battery.h> 34#include <linux/power/max17042_battery.h>
35#include <linux/of.h> 35#include <linux/of.h>
36#include <linux/regmap.h>
36 37
37/* Status register bits */ 38/* Status register bits */
38#define STATUS_POR_BIT (1 << 1) 39#define STATUS_POR_BIT (1 << 1)
@@ -67,6 +68,7 @@
67 68
68struct max17042_chip { 69struct max17042_chip {
69 struct i2c_client *client; 70 struct i2c_client *client;
71 struct regmap *regmap;
70 struct power_supply battery; 72 struct power_supply battery;
71 enum max170xx_chip_type chip_type; 73 enum max170xx_chip_type chip_type;
72 struct max17042_platform_data *pdata; 74 struct max17042_platform_data *pdata;
@@ -74,35 +76,6 @@ struct max17042_chip {
74 int init_complete; 76 int init_complete;
75}; 77};
76 78
77static int max17042_write_reg(struct i2c_client *client, u8 reg, u16 value)
78{
79 int ret = i2c_smbus_write_word_data(client, reg, value);
80
81 if (ret < 0)
82 dev_err(&client->dev, "%s: err %d\n", __func__, ret);
83
84 return ret;
85}
86
87static int max17042_read_reg(struct i2c_client *client, u8 reg)
88{
89 int ret = i2c_smbus_read_word_data(client, reg);
90
91 if (ret < 0)
92 dev_err(&client->dev, "%s: err %d\n", __func__, ret);
93
94 return ret;
95}
96
97static void max17042_set_reg(struct i2c_client *client,
98 struct max17042_reg_data *data, int size)
99{
100 int i;
101
102 for (i = 0; i < size; i++)
103 max17042_write_reg(client, data[i].addr, data[i].data);
104}
105
106static enum power_supply_property max17042_battery_props[] = { 79static enum power_supply_property max17042_battery_props[] = {
107 POWER_SUPPLY_PROP_PRESENT, 80 POWER_SUPPLY_PROP_PRESENT,
108 POWER_SUPPLY_PROP_CYCLE_COUNT, 81 POWER_SUPPLY_PROP_CYCLE_COUNT,
@@ -125,96 +98,98 @@ static int max17042_get_property(struct power_supply *psy,
125{ 98{
126 struct max17042_chip *chip = container_of(psy, 99 struct max17042_chip *chip = container_of(psy,
127 struct max17042_chip, battery); 100 struct max17042_chip, battery);
101 struct regmap *map = chip->regmap;
128 int ret; 102 int ret;
103 u32 data;
129 104
130 if (!chip->init_complete) 105 if (!chip->init_complete)
131 return -EAGAIN; 106 return -EAGAIN;
132 107
133 switch (psp) { 108 switch (psp) {
134 case POWER_SUPPLY_PROP_PRESENT: 109 case POWER_SUPPLY_PROP_PRESENT:
135 ret = max17042_read_reg(chip->client, MAX17042_STATUS); 110 ret = regmap_read(map, MAX17042_STATUS, &data);
136 if (ret < 0) 111 if (ret < 0)
137 return ret; 112 return ret;
138 113
139 if (ret & MAX17042_STATUS_BattAbsent) 114 if (data & MAX17042_STATUS_BattAbsent)
140 val->intval = 0; 115 val->intval = 0;
141 else 116 else
142 val->intval = 1; 117 val->intval = 1;
143 break; 118 break;
144 case POWER_SUPPLY_PROP_CYCLE_COUNT: 119 case POWER_SUPPLY_PROP_CYCLE_COUNT:
145 ret = max17042_read_reg(chip->client, MAX17042_Cycles); 120 ret = regmap_read(map, MAX17042_Cycles, &data);
146 if (ret < 0) 121 if (ret < 0)
147 return ret; 122 return ret;
148 123
149 val->intval = ret; 124 val->intval = data;
150 break; 125 break;
151 case POWER_SUPPLY_PROP_VOLTAGE_MAX: 126 case POWER_SUPPLY_PROP_VOLTAGE_MAX:
152 ret = max17042_read_reg(chip->client, MAX17042_MinMaxVolt); 127 ret = regmap_read(map, MAX17042_MinMaxVolt, &data);
153 if (ret < 0) 128 if (ret < 0)
154 return ret; 129 return ret;
155 130
156 val->intval = ret >> 8; 131 val->intval = data >> 8;
157 val->intval *= 20000; /* Units of LSB = 20mV */ 132 val->intval *= 20000; /* Units of LSB = 20mV */
158 break; 133 break;
159 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: 134 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
160 if (chip->chip_type == MAX17042) 135 if (chip->chip_type == MAX17042)
161 ret = max17042_read_reg(chip->client, MAX17042_V_empty); 136 ret = regmap_read(map, MAX17042_V_empty, &data);
162 else 137 else
163 ret = max17042_read_reg(chip->client, MAX17047_V_empty); 138 ret = regmap_read(map, MAX17047_V_empty, &data);
164 if (ret < 0) 139 if (ret < 0)
165 return ret; 140 return ret;
166 141
167 val->intval = ret >> 7; 142 val->intval = data >> 7;
168 val->intval *= 10000; /* Units of LSB = 10mV */ 143 val->intval *= 10000; /* Units of LSB = 10mV */
169 break; 144 break;
170 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 145 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
171 ret = max17042_read_reg(chip->client, MAX17042_VCELL); 146 ret = regmap_read(map, MAX17042_VCELL, &data);
172 if (ret < 0) 147 if (ret < 0)
173 return ret; 148 return ret;
174 149
175 val->intval = ret * 625 / 8; 150 val->intval = data * 625 / 8;
176 break; 151 break;
177 case POWER_SUPPLY_PROP_VOLTAGE_AVG: 152 case POWER_SUPPLY_PROP_VOLTAGE_AVG:
178 ret = max17042_read_reg(chip->client, MAX17042_AvgVCELL); 153 ret = regmap_read(map, MAX17042_AvgVCELL, &data);
179 if (ret < 0) 154 if (ret < 0)
180 return ret; 155 return ret;
181 156
182 val->intval = ret * 625 / 8; 157 val->intval = data * 625 / 8;
183 break; 158 break;
184 case POWER_SUPPLY_PROP_VOLTAGE_OCV: 159 case POWER_SUPPLY_PROP_VOLTAGE_OCV:
185 ret = max17042_read_reg(chip->client, MAX17042_OCVInternal); 160 ret = regmap_read(map, MAX17042_OCVInternal, &data);
186 if (ret < 0) 161 if (ret < 0)
187 return ret; 162 return ret;
188 163
189 val->intval = ret * 625 / 8; 164 val->intval = data * 625 / 8;
190 break; 165 break;
191 case POWER_SUPPLY_PROP_CAPACITY: 166 case POWER_SUPPLY_PROP_CAPACITY:
192 ret = max17042_read_reg(chip->client, MAX17042_RepSOC); 167 ret = regmap_read(map, MAX17042_RepSOC, &data);
193 if (ret < 0) 168 if (ret < 0)
194 return ret; 169 return ret;
195 170
196 val->intval = ret >> 8; 171 val->intval = data >> 8;
197 break; 172 break;
198 case POWER_SUPPLY_PROP_CHARGE_FULL: 173 case POWER_SUPPLY_PROP_CHARGE_FULL:
199 ret = max17042_read_reg(chip->client, MAX17042_FullCAP); 174 ret = regmap_read(map, MAX17042_FullCAP, &data);
200 if (ret < 0) 175 if (ret < 0)
201 return ret; 176 return ret;
202 177
203 val->intval = ret * 1000 / 2; 178 val->intval = data * 1000 / 2;
204 break; 179 break;
205 case POWER_SUPPLY_PROP_CHARGE_COUNTER: 180 case POWER_SUPPLY_PROP_CHARGE_COUNTER:
206 ret = max17042_read_reg(chip->client, MAX17042_QH); 181 ret = regmap_read(map, MAX17042_QH, &data);
207 if (ret < 0) 182 if (ret < 0)
208 return ret; 183 return ret;
209 184
210 val->intval = ret * 1000 / 2; 185 val->intval = data * 1000 / 2;
211 break; 186 break;
212 case POWER_SUPPLY_PROP_TEMP: 187 case POWER_SUPPLY_PROP_TEMP:
213 ret = max17042_read_reg(chip->client, MAX17042_TEMP); 188 ret = regmap_read(map, MAX17042_TEMP, &data);
214 if (ret < 0) 189 if (ret < 0)
215 return ret; 190 return ret;
216 191
217 val->intval = ret; 192 val->intval = data;
218 /* The value is signed. */ 193 /* The value is signed. */
219 if (val->intval & 0x8000) { 194 if (val->intval & 0x8000) {
220 val->intval = (0x7fff & ~val->intval) + 1; 195 val->intval = (0x7fff & ~val->intval) + 1;
@@ -226,11 +201,11 @@ static int max17042_get_property(struct power_supply *psy,
226 break; 201 break;
227 case POWER_SUPPLY_PROP_CURRENT_NOW: 202 case POWER_SUPPLY_PROP_CURRENT_NOW:
228 if (chip->pdata->enable_current_sense) { 203 if (chip->pdata->enable_current_sense) {
229 ret = max17042_read_reg(chip->client, MAX17042_Current); 204 ret = regmap_read(map, MAX17042_Current, &data);
230 if (ret < 0) 205 if (ret < 0)
231 return ret; 206 return ret;
232 207
233 val->intval = ret; 208 val->intval = data;
234 if (val->intval & 0x8000) { 209 if (val->intval & 0x8000) {
235 /* Negative */ 210 /* Negative */
236 val->intval = ~val->intval & 0x7fff; 211 val->intval = ~val->intval & 0x7fff;
@@ -244,12 +219,11 @@ static int max17042_get_property(struct power_supply *psy,
244 break; 219 break;
245 case POWER_SUPPLY_PROP_CURRENT_AVG: 220 case POWER_SUPPLY_PROP_CURRENT_AVG:
246 if (chip->pdata->enable_current_sense) { 221 if (chip->pdata->enable_current_sense) {
247 ret = max17042_read_reg(chip->client, 222 ret = regmap_read(map, MAX17042_AvgCurrent, &data);
248 MAX17042_AvgCurrent);
249 if (ret < 0) 223 if (ret < 0)
250 return ret; 224 return ret;
251 225
252 val->intval = ret; 226 val->intval = data;
253 if (val->intval & 0x8000) { 227 if (val->intval & 0x8000) {
254 /* Negative */ 228 /* Negative */
255 val->intval = ~val->intval & 0x7fff; 229 val->intval = ~val->intval & 0x7fff;
@@ -267,16 +241,15 @@ static int max17042_get_property(struct power_supply *psy,
267 return 0; 241 return 0;
268} 242}
269 243
270static int max17042_write_verify_reg(struct i2c_client *client, 244static int max17042_write_verify_reg(struct regmap *map, u8 reg, u32 value)
271 u8 reg, u16 value)
272{ 245{
273 int retries = 8; 246 int retries = 8;
274 int ret; 247 int ret;
275 u16 read_value; 248 u32 read_value;
276 249
277 do { 250 do {
278 ret = i2c_smbus_write_word_data(client, reg, value); 251 ret = regmap_write(map, reg, value);
279 read_value = max17042_read_reg(client, reg); 252 regmap_read(map, reg, &read_value);
280 if (read_value != value) { 253 if (read_value != value) {
281 ret = -EIO; 254 ret = -EIO;
282 retries--; 255 retries--;
@@ -284,50 +257,51 @@ static int max17042_write_verify_reg(struct i2c_client *client,
284 } while (retries && read_value != value); 257 } while (retries && read_value != value);
285 258
286 if (ret < 0) 259 if (ret < 0)
287 dev_err(&client->dev, "%s: err %d\n", __func__, ret); 260 pr_err("%s: err %d\n", __func__, ret);
288 261
289 return ret; 262 return ret;
290} 263}
291 264
292static inline void max17042_override_por( 265static inline void max17042_override_por(struct regmap *map,
293 struct i2c_client *client, u8 reg, u16 value) 266 u8 reg, u16 value)
294{ 267{
295 if (value) 268 if (value)
296 max17042_write_reg(client, reg, value); 269 regmap_write(map, reg, value);
297} 270}
298 271
299static inline void max10742_unlock_model(struct max17042_chip *chip) 272static inline void max10742_unlock_model(struct max17042_chip *chip)
300{ 273{
301 struct i2c_client *client = chip->client; 274 struct regmap *map = chip->regmap;
302 max17042_write_reg(client, MAX17042_MLOCKReg1, MODEL_UNLOCK1); 275 regmap_write(map, MAX17042_MLOCKReg1, MODEL_UNLOCK1);
303 max17042_write_reg(client, MAX17042_MLOCKReg2, MODEL_UNLOCK2); 276 regmap_write(map, MAX17042_MLOCKReg2, MODEL_UNLOCK2);
304} 277}
305 278
306static inline void max10742_lock_model(struct max17042_chip *chip) 279static inline void max10742_lock_model(struct max17042_chip *chip)
307{ 280{
308 struct i2c_client *client = chip->client; 281 struct regmap *map = chip->regmap;
309 max17042_write_reg(client, MAX17042_MLOCKReg1, MODEL_LOCK1); 282
310 max17042_write_reg(client, MAX17042_MLOCKReg2, MODEL_LOCK2); 283 regmap_write(map, MAX17042_MLOCKReg1, MODEL_LOCK1);
284 regmap_write(map, MAX17042_MLOCKReg2, MODEL_LOCK2);
311} 285}
312 286
313static inline void max17042_write_model_data(struct max17042_chip *chip, 287static inline void max17042_write_model_data(struct max17042_chip *chip,
314 u8 addr, int size) 288 u8 addr, int size)
315{ 289{
316 struct i2c_client *client = chip->client; 290 struct regmap *map = chip->regmap;
317 int i; 291 int i;
318 for (i = 0; i < size; i++) 292 for (i = 0; i < size; i++)
319 max17042_write_reg(client, addr + i, 293 regmap_write(map, addr + i,
320 chip->pdata->config_data->cell_char_tbl[i]); 294 chip->pdata->config_data->cell_char_tbl[i]);
321} 295}
322 296
323static inline void max17042_read_model_data(struct max17042_chip *chip, 297static inline void max17042_read_model_data(struct max17042_chip *chip,
324 u8 addr, u16 *data, int size) 298 u8 addr, u32 *data, int size)
325{ 299{
326 struct i2c_client *client = chip->client; 300 struct regmap *map = chip->regmap;
327 int i; 301 int i;
328 302
329 for (i = 0; i < size; i++) 303 for (i = 0; i < size; i++)
330 data[i] = max17042_read_reg(client, addr + i); 304 regmap_read(map, addr + i, &data[i]);
331} 305}
332 306
333static inline int max17042_model_data_compare(struct max17042_chip *chip, 307static inline int max17042_model_data_compare(struct max17042_chip *chip,
@@ -350,7 +324,7 @@ static int max17042_init_model(struct max17042_chip *chip)
350{ 324{
351 int ret; 325 int ret;
352 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); 326 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl);
353 u16 *temp_data; 327 u32 *temp_data;
354 328
355 temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL); 329 temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);
356 if (!temp_data) 330 if (!temp_data)
@@ -365,7 +339,7 @@ static int max17042_init_model(struct max17042_chip *chip)
365 ret = max17042_model_data_compare( 339 ret = max17042_model_data_compare(
366 chip, 340 chip,
367 chip->pdata->config_data->cell_char_tbl, 341 chip->pdata->config_data->cell_char_tbl,
368 temp_data, 342 (u16 *)temp_data,
369 table_size); 343 table_size);
370 344
371 max10742_lock_model(chip); 345 max10742_lock_model(chip);
@@ -378,7 +352,7 @@ static int max17042_verify_model_lock(struct max17042_chip *chip)
378{ 352{
379 int i; 353 int i;
380 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); 354 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl);
381 u16 *temp_data; 355 u32 *temp_data;
382 int ret = 0; 356 int ret = 0;
383 357
384 temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL); 358 temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);
@@ -398,40 +372,38 @@ static int max17042_verify_model_lock(struct max17042_chip *chip)
398static void max17042_write_config_regs(struct max17042_chip *chip) 372static void max17042_write_config_regs(struct max17042_chip *chip)
399{ 373{
400 struct max17042_config_data *config = chip->pdata->config_data; 374 struct max17042_config_data *config = chip->pdata->config_data;
375 struct regmap *map = chip->regmap;
401 376
402 max17042_write_reg(chip->client, MAX17042_CONFIG, config->config); 377 regmap_write(map, MAX17042_CONFIG, config->config);
403 max17042_write_reg(chip->client, MAX17042_LearnCFG, config->learn_cfg); 378 regmap_write(map, MAX17042_LearnCFG, config->learn_cfg);
404 max17042_write_reg(chip->client, MAX17042_FilterCFG, 379 regmap_write(map, MAX17042_FilterCFG,
405 config->filter_cfg); 380 config->filter_cfg);
406 max17042_write_reg(chip->client, MAX17042_RelaxCFG, config->relax_cfg); 381 regmap_write(map, MAX17042_RelaxCFG, config->relax_cfg);
407 if (chip->chip_type == MAX17047) 382 if (chip->chip_type == MAX17047)
408 max17042_write_reg(chip->client, MAX17047_FullSOCThr, 383 regmap_write(map, MAX17047_FullSOCThr,
409 config->full_soc_thresh); 384 config->full_soc_thresh);
410} 385}
411 386
412static void max17042_write_custom_regs(struct max17042_chip *chip) 387static void max17042_write_custom_regs(struct max17042_chip *chip)
413{ 388{
414 struct max17042_config_data *config = chip->pdata->config_data; 389 struct max17042_config_data *config = chip->pdata->config_data;
390 struct regmap *map = chip->regmap;
415 391
416 max17042_write_verify_reg(chip->client, MAX17042_RCOMP0, 392 max17042_write_verify_reg(map, MAX17042_RCOMP0, config->rcomp0);
417 config->rcomp0); 393 max17042_write_verify_reg(map, MAX17042_TempCo, config->tcompc0);
418 max17042_write_verify_reg(chip->client, MAX17042_TempCo, 394 max17042_write_verify_reg(map, MAX17042_ICHGTerm, config->ichgt_term);
419 config->tcompc0);
420 max17042_write_verify_reg(chip->client, MAX17042_ICHGTerm,
421 config->ichgt_term);
422 if (chip->chip_type == MAX17042) { 395 if (chip->chip_type == MAX17042) {
423 max17042_write_reg(chip->client, MAX17042_EmptyTempCo, 396 regmap_write(map, MAX17042_EmptyTempCo, config->empty_tempco);
424 config->empty_tempco); 397 max17042_write_verify_reg(map, MAX17042_K_empty0,
425 max17042_write_verify_reg(chip->client, MAX17042_K_empty0,
426 config->kempty0); 398 config->kempty0);
427 } else { 399 } else {
428 max17042_write_verify_reg(chip->client, MAX17047_QRTbl00, 400 max17042_write_verify_reg(map, MAX17047_QRTbl00,
429 config->qrtbl00); 401 config->qrtbl00);
430 max17042_write_verify_reg(chip->client, MAX17047_QRTbl10, 402 max17042_write_verify_reg(map, MAX17047_QRTbl10,
431 config->qrtbl10); 403 config->qrtbl10);
432 max17042_write_verify_reg(chip->client, MAX17047_QRTbl20, 404 max17042_write_verify_reg(map, MAX17047_QRTbl20,
433 config->qrtbl20); 405 config->qrtbl20);
434 max17042_write_verify_reg(chip->client, MAX17047_QRTbl30, 406 max17042_write_verify_reg(map, MAX17047_QRTbl30,
435 config->qrtbl30); 407 config->qrtbl30);
436 } 408 }
437} 409}
@@ -439,58 +411,60 @@ static void max17042_write_custom_regs(struct max17042_chip *chip)
439static void max17042_update_capacity_regs(struct max17042_chip *chip) 411static void max17042_update_capacity_regs(struct max17042_chip *chip)
440{ 412{
441 struct max17042_config_data *config = chip->pdata->config_data; 413 struct max17042_config_data *config = chip->pdata->config_data;
414 struct regmap *map = chip->regmap;
442 415
443 max17042_write_verify_reg(chip->client, MAX17042_FullCAP, 416 max17042_write_verify_reg(map, MAX17042_FullCAP,
444 config->fullcap); 417 config->fullcap);
445 max17042_write_reg(chip->client, MAX17042_DesignCap, 418 regmap_write(map, MAX17042_DesignCap, config->design_cap);
446 config->design_cap); 419 max17042_write_verify_reg(map, MAX17042_FullCAPNom,
447 max17042_write_verify_reg(chip->client, MAX17042_FullCAPNom,
448 config->fullcapnom); 420 config->fullcapnom);
449} 421}
450 422
451static void max17042_reset_vfsoc0_reg(struct max17042_chip *chip) 423static void max17042_reset_vfsoc0_reg(struct max17042_chip *chip)
452{ 424{
453 u16 vfSoc; 425 unsigned int vfSoc;
426 struct regmap *map = chip->regmap;
454 427
455 vfSoc = max17042_read_reg(chip->client, MAX17042_VFSOC); 428 regmap_read(map, MAX17042_VFSOC, &vfSoc);
456 max17042_write_reg(chip->client, MAX17042_VFSOC0Enable, VFSOC0_UNLOCK); 429 regmap_write(map, MAX17042_VFSOC0Enable, VFSOC0_UNLOCK);
457 max17042_write_verify_reg(chip->client, MAX17042_VFSOC0, vfSoc); 430 max17042_write_verify_reg(map, MAX17042_VFSOC0, vfSoc);
458 max17042_write_reg(chip->client, MAX17042_VFSOC0Enable, VFSOC0_LOCK); 431 regmap_write(map, MAX17042_VFSOC0Enable, VFSOC0_LOCK);
459} 432}
460 433
461static void max17042_load_new_capacity_params(struct max17042_chip *chip) 434static void max17042_load_new_capacity_params(struct max17042_chip *chip)
462{ 435{
463 u16 full_cap0, rep_cap, dq_acc, vfSoc; 436 u32 full_cap0, rep_cap, dq_acc, vfSoc;
464 u32 rem_cap; 437 u32 rem_cap;
465 438
466 struct max17042_config_data *config = chip->pdata->config_data; 439 struct max17042_config_data *config = chip->pdata->config_data;
440 struct regmap *map = chip->regmap;
467 441
468 full_cap0 = max17042_read_reg(chip->client, MAX17042_FullCAP0); 442 regmap_read(map, MAX17042_FullCAP0, &full_cap0);
469 vfSoc = max17042_read_reg(chip->client, MAX17042_VFSOC); 443 regmap_read(map, MAX17042_VFSOC, &vfSoc);
470 444
471 /* fg_vfSoc needs to shifted by 8 bits to get the 445 /* fg_vfSoc needs to shifted by 8 bits to get the
472 * perc in 1% accuracy, to get the right rem_cap multiply 446 * perc in 1% accuracy, to get the right rem_cap multiply
473 * full_cap0, fg_vfSoc and devide by 100 447 * full_cap0, fg_vfSoc and devide by 100
474 */ 448 */
475 rem_cap = ((vfSoc >> 8) * full_cap0) / 100; 449 rem_cap = ((vfSoc >> 8) * full_cap0) / 100;
476 max17042_write_verify_reg(chip->client, MAX17042_RemCap, (u16)rem_cap); 450 max17042_write_verify_reg(map, MAX17042_RemCap, rem_cap);
477 451
478 rep_cap = (u16)rem_cap; 452 rep_cap = rem_cap;
479 max17042_write_verify_reg(chip->client, MAX17042_RepCap, rep_cap); 453 max17042_write_verify_reg(map, MAX17042_RepCap, rep_cap);
480 454
481 /* Write dQ_acc to 200% of Capacity and dP_acc to 200% */ 455 /* Write dQ_acc to 200% of Capacity and dP_acc to 200% */
482 dq_acc = config->fullcap / dQ_ACC_DIV; 456 dq_acc = config->fullcap / dQ_ACC_DIV;
483 max17042_write_verify_reg(chip->client, MAX17042_dQacc, dq_acc); 457 max17042_write_verify_reg(map, MAX17042_dQacc, dq_acc);
484 max17042_write_verify_reg(chip->client, MAX17042_dPacc, dP_ACC_200); 458 max17042_write_verify_reg(map, MAX17042_dPacc, dP_ACC_200);
485 459
486 max17042_write_verify_reg(chip->client, MAX17042_FullCAP, 460 max17042_write_verify_reg(map, MAX17042_FullCAP,
487 config->fullcap); 461 config->fullcap);
488 max17042_write_reg(chip->client, MAX17042_DesignCap, 462 regmap_write(map, MAX17042_DesignCap,
489 config->design_cap); 463 config->design_cap);
490 max17042_write_verify_reg(chip->client, MAX17042_FullCAPNom, 464 max17042_write_verify_reg(map, MAX17042_FullCAPNom,
491 config->fullcapnom); 465 config->fullcapnom);
492 /* Update SOC register with new SOC */ 466 /* Update SOC register with new SOC */
493 max17042_write_reg(chip->client, MAX17042_RepSOC, vfSoc); 467 regmap_write(map, MAX17042_RepSOC, vfSoc);
494} 468}
495 469
496/* 470/*
@@ -500,59 +474,60 @@ static void max17042_load_new_capacity_params(struct max17042_chip *chip)
500 */ 474 */
501static inline void max17042_override_por_values(struct max17042_chip *chip) 475static inline void max17042_override_por_values(struct max17042_chip *chip)
502{ 476{
503 struct i2c_client *client = chip->client; 477 struct regmap *map = chip->regmap;
504 struct max17042_config_data *config = chip->pdata->config_data; 478 struct max17042_config_data *config = chip->pdata->config_data;
505 479
506 max17042_override_por(client, MAX17042_TGAIN, config->tgain); 480 max17042_override_por(map, MAX17042_TGAIN, config->tgain);
507 max17042_override_por(client, MAx17042_TOFF, config->toff); 481 max17042_override_por(map, MAx17042_TOFF, config->toff);
508 max17042_override_por(client, MAX17042_CGAIN, config->cgain); 482 max17042_override_por(map, MAX17042_CGAIN, config->cgain);
509 max17042_override_por(client, MAX17042_COFF, config->coff); 483 max17042_override_por(map, MAX17042_COFF, config->coff);
510 484
511 max17042_override_por(client, MAX17042_VALRT_Th, config->valrt_thresh); 485 max17042_override_por(map, MAX17042_VALRT_Th, config->valrt_thresh);
512 max17042_override_por(client, MAX17042_TALRT_Th, config->talrt_thresh); 486 max17042_override_por(map, MAX17042_TALRT_Th, config->talrt_thresh);
513 max17042_override_por(client, MAX17042_SALRT_Th, 487 max17042_override_por(map, MAX17042_SALRT_Th,
514 config->soc_alrt_thresh); 488 config->soc_alrt_thresh);
515 max17042_override_por(client, MAX17042_CONFIG, config->config); 489 max17042_override_por(map, MAX17042_CONFIG, config->config);
516 max17042_override_por(client, MAX17042_SHDNTIMER, config->shdntimer); 490 max17042_override_por(map, MAX17042_SHDNTIMER, config->shdntimer);
517 491
518 max17042_override_por(client, MAX17042_DesignCap, config->design_cap); 492 max17042_override_por(map, MAX17042_DesignCap, config->design_cap);
519 max17042_override_por(client, MAX17042_ICHGTerm, config->ichgt_term); 493 max17042_override_por(map, MAX17042_ICHGTerm, config->ichgt_term);
520 494
521 max17042_override_por(client, MAX17042_AtRate, config->at_rate); 495 max17042_override_por(map, MAX17042_AtRate, config->at_rate);
522 max17042_override_por(client, MAX17042_LearnCFG, config->learn_cfg); 496 max17042_override_por(map, MAX17042_LearnCFG, config->learn_cfg);
523 max17042_override_por(client, MAX17042_FilterCFG, config->filter_cfg); 497 max17042_override_por(map, MAX17042_FilterCFG, config->filter_cfg);
524 max17042_override_por(client, MAX17042_RelaxCFG, config->relax_cfg); 498 max17042_override_por(map, MAX17042_RelaxCFG, config->relax_cfg);
525 max17042_override_por(client, MAX17042_MiscCFG, config->misc_cfg); 499 max17042_override_por(map, MAX17042_MiscCFG, config->misc_cfg);
526 max17042_override_por(client, MAX17042_MaskSOC, config->masksoc); 500 max17042_override_por(map, MAX17042_MaskSOC, config->masksoc);
527 501
528 max17042_override_por(client, MAX17042_FullCAP, config->fullcap); 502 max17042_override_por(map, MAX17042_FullCAP, config->fullcap);
529 max17042_override_por(client, MAX17042_FullCAPNom, config->fullcapnom); 503 max17042_override_por(map, MAX17042_FullCAPNom, config->fullcapnom);
530 if (chip->chip_type == MAX17042) 504 if (chip->chip_type == MAX17042)
531 max17042_override_por(client, MAX17042_SOC_empty, 505 max17042_override_por(map, MAX17042_SOC_empty,
532 config->socempty); 506 config->socempty);
533 max17042_override_por(client, MAX17042_LAvg_empty, config->lavg_empty); 507 max17042_override_por(map, MAX17042_LAvg_empty, config->lavg_empty);
534 max17042_override_por(client, MAX17042_dQacc, config->dqacc); 508 max17042_override_por(map, MAX17042_dQacc, config->dqacc);
535 max17042_override_por(client, MAX17042_dPacc, config->dpacc); 509 max17042_override_por(map, MAX17042_dPacc, config->dpacc);
536 510
537 if (chip->chip_type == MAX17042) 511 if (chip->chip_type == MAX17042)
538 max17042_override_por(client, MAX17042_V_empty, config->vempty); 512 max17042_override_por(map, MAX17042_V_empty, config->vempty);
539 else 513 else
540 max17042_override_por(client, MAX17047_V_empty, config->vempty); 514 max17042_override_por(map, MAX17047_V_empty, config->vempty);
541 max17042_override_por(client, MAX17042_TempNom, config->temp_nom); 515 max17042_override_por(map, MAX17042_TempNom, config->temp_nom);
542 max17042_override_por(client, MAX17042_TempLim, config->temp_lim); 516 max17042_override_por(map, MAX17042_TempLim, config->temp_lim);
543 max17042_override_por(client, MAX17042_FCTC, config->fctc); 517 max17042_override_por(map, MAX17042_FCTC, config->fctc);
544 max17042_override_por(client, MAX17042_RCOMP0, config->rcomp0); 518 max17042_override_por(map, MAX17042_RCOMP0, config->rcomp0);
545 max17042_override_por(client, MAX17042_TempCo, config->tcompc0); 519 max17042_override_por(map, MAX17042_TempCo, config->tcompc0);
546 if (chip->chip_type) { 520 if (chip->chip_type) {
547 max17042_override_por(client, MAX17042_EmptyTempCo, 521 max17042_override_por(map, MAX17042_EmptyTempCo,
548 config->empty_tempco); 522 config->empty_tempco);
549 max17042_override_por(client, MAX17042_K_empty0, 523 max17042_override_por(map, MAX17042_K_empty0,
550 config->kempty0); 524 config->kempty0);
551 } 525 }
552} 526}
553 527
554static int max17042_init_chip(struct max17042_chip *chip) 528static int max17042_init_chip(struct max17042_chip *chip)
555{ 529{
530 struct regmap *map = chip->regmap;
556 int ret; 531 int ret;
557 int val; 532 int val;
558 533
@@ -597,31 +572,32 @@ static int max17042_init_chip(struct max17042_chip *chip)
597 max17042_load_new_capacity_params(chip); 572 max17042_load_new_capacity_params(chip);
598 573
599 /* Init complete, Clear the POR bit */ 574 /* Init complete, Clear the POR bit */
600 val = max17042_read_reg(chip->client, MAX17042_STATUS); 575 regmap_read(map, MAX17042_STATUS, &val);
601 max17042_write_reg(chip->client, MAX17042_STATUS, 576 regmap_write(map, MAX17042_STATUS, val & (~STATUS_POR_BIT));
602 val & (~STATUS_POR_BIT));
603 return 0; 577 return 0;
604} 578}
605 579
606static void max17042_set_soc_threshold(struct max17042_chip *chip, u16 off) 580static void max17042_set_soc_threshold(struct max17042_chip *chip, u16 off)
607{ 581{
608 u16 soc, soc_tr; 582 struct regmap *map = chip->regmap;
583 u32 soc, soc_tr;
609 584
610 /* program interrupt thesholds such that we should 585 /* program interrupt thesholds such that we should
611 * get interrupt for every 'off' perc change in the soc 586 * get interrupt for every 'off' perc change in the soc
612 */ 587 */
613 soc = max17042_read_reg(chip->client, MAX17042_RepSOC) >> 8; 588 regmap_read(map, MAX17042_RepSOC, &soc);
589 soc >>= 8;
614 soc_tr = (soc + off) << 8; 590 soc_tr = (soc + off) << 8;
615 soc_tr |= (soc - off); 591 soc_tr |= (soc - off);
616 max17042_write_reg(chip->client, MAX17042_SALRT_Th, soc_tr); 592 regmap_write(map, MAX17042_SALRT_Th, soc_tr);
617} 593}
618 594
619static irqreturn_t max17042_thread_handler(int id, void *dev) 595static irqreturn_t max17042_thread_handler(int id, void *dev)
620{ 596{
621 struct max17042_chip *chip = dev; 597 struct max17042_chip *chip = dev;
622 u16 val; 598 u32 val;
623 599
624 val = max17042_read_reg(chip->client, MAX17042_STATUS); 600 regmap_read(chip->regmap, MAX17042_STATUS, &val);
625 if ((val & STATUS_INTR_SOCMIN_BIT) || 601 if ((val & STATUS_INTR_SOCMIN_BIT) ||
626 (val & STATUS_INTR_SOCMAX_BIT)) { 602 (val & STATUS_INTR_SOCMAX_BIT)) {
627 dev_info(&chip->client->dev, "SOC threshold INTR\n"); 603 dev_info(&chip->client->dev, "SOC threshold INTR\n");
@@ -682,13 +658,20 @@ max17042_get_pdata(struct device *dev)
682} 658}
683#endif 659#endif
684 660
661static struct regmap_config max17042_regmap_config = {
662 .reg_bits = 8,
663 .val_bits = 16,
664 .val_format_endian = REGMAP_ENDIAN_NATIVE,
665};
666
685static int max17042_probe(struct i2c_client *client, 667static int max17042_probe(struct i2c_client *client,
686 const struct i2c_device_id *id) 668 const struct i2c_device_id *id)
687{ 669{
688 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 670 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
689 struct max17042_chip *chip; 671 struct max17042_chip *chip;
690 int ret; 672 int ret;
691 int reg; 673 int i;
674 u32 val;
692 675
693 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) 676 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
694 return -EIO; 677 return -EIO;
@@ -698,6 +681,12 @@ static int max17042_probe(struct i2c_client *client,
698 return -ENOMEM; 681 return -ENOMEM;
699 682
700 chip->client = client; 683 chip->client = client;
684 chip->regmap = devm_regmap_init_i2c(client, &max17042_regmap_config);
685 if (IS_ERR(chip->regmap)) {
686 dev_err(&client->dev, "Failed to initialize regmap\n");
687 return -EINVAL;
688 }
689
701 chip->pdata = max17042_get_pdata(&client->dev); 690 chip->pdata = max17042_get_pdata(&client->dev);
702 if (!chip->pdata) { 691 if (!chip->pdata) {
703 dev_err(&client->dev, "no platform data provided\n"); 692 dev_err(&client->dev, "no platform data provided\n");
@@ -706,15 +695,15 @@ static int max17042_probe(struct i2c_client *client,
706 695
707 i2c_set_clientdata(client, chip); 696 i2c_set_clientdata(client, chip);
708 697
709 ret = max17042_read_reg(chip->client, MAX17042_DevName); 698 regmap_read(chip->regmap, MAX17042_DevName, &val);
710 if (ret == MAX17042_IC_VERSION) { 699 if (val == MAX17042_IC_VERSION) {
711 dev_dbg(&client->dev, "chip type max17042 detected\n"); 700 dev_dbg(&client->dev, "chip type max17042 detected\n");
712 chip->chip_type = MAX17042; 701 chip->chip_type = MAX17042;
713 } else if (ret == MAX17047_IC_VERSION) { 702 } else if (val == MAX17047_IC_VERSION) {
714 dev_dbg(&client->dev, "chip type max17047/50 detected\n"); 703 dev_dbg(&client->dev, "chip type max17047/50 detected\n");
715 chip->chip_type = MAX17047; 704 chip->chip_type = MAX17047;
716 } else { 705 } else {
717 dev_err(&client->dev, "device version mismatch: %x\n", ret); 706 dev_err(&client->dev, "device version mismatch: %x\n", val);
718 return -EIO; 707 return -EIO;
719 } 708 }
720 709
@@ -733,13 +722,15 @@ static int max17042_probe(struct i2c_client *client,
733 chip->pdata->r_sns = MAX17042_DEFAULT_SNS_RESISTOR; 722 chip->pdata->r_sns = MAX17042_DEFAULT_SNS_RESISTOR;
734 723
735 if (chip->pdata->init_data) 724 if (chip->pdata->init_data)
736 max17042_set_reg(client, chip->pdata->init_data, 725 for (i = 0; i < chip->pdata->num_init_data; i++)
737 chip->pdata->num_init_data); 726 regmap_write(chip->regmap,
727 chip->pdata->init_data[i].addr,
728 chip->pdata->init_data[i].data);
738 729
739 if (!chip->pdata->enable_current_sense) { 730 if (!chip->pdata->enable_current_sense) {
740 max17042_write_reg(client, MAX17042_CGAIN, 0x0000); 731 regmap_write(chip->regmap, MAX17042_CGAIN, 0x0000);
741 max17042_write_reg(client, MAX17042_MiscCFG, 0x0003); 732 regmap_write(chip->regmap, MAX17042_MiscCFG, 0x0003);
742 max17042_write_reg(client, MAX17042_LearnCFG, 0x0007); 733 regmap_write(chip->regmap, MAX17042_LearnCFG, 0x0007);
743 } 734 }
744 735
745 ret = power_supply_register(&client->dev, &chip->battery); 736 ret = power_supply_register(&client->dev, &chip->battery);
@@ -754,9 +745,9 @@ static int max17042_probe(struct i2c_client *client,
754 IRQF_TRIGGER_FALLING, 745 IRQF_TRIGGER_FALLING,
755 chip->battery.name, chip); 746 chip->battery.name, chip);
756 if (!ret) { 747 if (!ret) {
757 reg = max17042_read_reg(client, MAX17042_CONFIG); 748 regmap_read(chip->regmap, MAX17042_CONFIG, &val);
758 reg |= CONFIG_ALRT_BIT_ENBL; 749 val |= CONFIG_ALRT_BIT_ENBL;
759 max17042_write_reg(client, MAX17042_CONFIG, reg); 750 regmap_write(chip->regmap, MAX17042_CONFIG, val);
760 max17042_set_soc_threshold(chip, 1); 751 max17042_set_soc_threshold(chip, 1);
761 } else { 752 } else {
762 client->irq = 0; 753 client->irq = 0;
@@ -765,8 +756,8 @@ static int max17042_probe(struct i2c_client *client,
765 } 756 }
766 } 757 }
767 758
768 reg = max17042_read_reg(chip->client, MAX17042_STATUS); 759 regmap_read(chip->regmap, MAX17042_STATUS, &val);
769 if (reg & STATUS_POR_BIT) { 760 if (val & STATUS_POR_BIT) {
770 INIT_WORK(&chip->work, max17042_init_worker); 761 INIT_WORK(&chip->work, max17042_init_worker);
771 schedule_work(&chip->work); 762 schedule_work(&chip->work);
772 } else { 763 } else {
@@ -786,7 +777,7 @@ static int max17042_remove(struct i2c_client *client)
786 return 0; 777 return 0;
787} 778}
788 779
789#ifdef CONFIG_PM 780#ifdef CONFIG_PM_SLEEP
790static int max17042_suspend(struct device *dev) 781static int max17042_suspend(struct device *dev)
791{ 782{
792 struct max17042_chip *chip = dev_get_drvdata(dev); 783 struct max17042_chip *chip = dev_get_drvdata(dev);
@@ -816,17 +807,11 @@ static int max17042_resume(struct device *dev)
816 807
817 return 0; 808 return 0;
818} 809}
819
820static const struct dev_pm_ops max17042_pm_ops = {
821 .suspend = max17042_suspend,
822 .resume = max17042_resume,
823};
824
825#define MAX17042_PM_OPS (&max17042_pm_ops)
826#else
827#define MAX17042_PM_OPS NULL
828#endif 810#endif
829 811
812static SIMPLE_DEV_PM_OPS(max17042_pm_ops, max17042_suspend,
813 max17042_resume);
814
830#ifdef CONFIG_OF 815#ifdef CONFIG_OF
831static const struct of_device_id max17042_dt_match[] = { 816static const struct of_device_id max17042_dt_match[] = {
832 { .compatible = "maxim,max17042" }, 817 { .compatible = "maxim,max17042" },
@@ -849,7 +834,7 @@ static struct i2c_driver max17042_i2c_driver = {
849 .driver = { 834 .driver = {
850 .name = "max17042", 835 .name = "max17042",
851 .of_match_table = of_match_ptr(max17042_dt_match), 836 .of_match_table = of_match_ptr(max17042_dt_match),
852 .pm = MAX17042_PM_OPS, 837 .pm = &max17042_pm_ops,
853 }, 838 },
854 .probe = max17042_probe, 839 .probe = max17042_probe,
855 .remove = max17042_remove, 840 .remove = max17042_remove,
diff --git a/drivers/power/pm2301_charger.c b/drivers/power/pm2301_charger.c
index ffa10ed83eb1..62c15af58c9a 100644
--- a/drivers/power/pm2301_charger.c
+++ b/drivers/power/pm2301_charger.c
@@ -205,7 +205,7 @@ static int pm2xxx_charger_batt_therm_mngt(struct pm2xxx_charger *pm2, int val)
205} 205}
206 206
207 207
208int pm2xxx_charger_die_therm_mngt(struct pm2xxx_charger *pm2, int val) 208static int pm2xxx_charger_die_therm_mngt(struct pm2xxx_charger *pm2, int val)
209{ 209{
210 queue_work(pm2->charger_wq, &pm2->check_main_thermal_prot_work); 210 queue_work(pm2->charger_wq, &pm2->check_main_thermal_prot_work);
211 211
@@ -722,8 +722,12 @@ static int pm2xxx_charger_ac_en(struct ux500_charger *charger,
722 722
723 dev_dbg(pm2->dev, "Enable AC: %dmV %dmA\n", vset, iset); 723 dev_dbg(pm2->dev, "Enable AC: %dmV %dmA\n", vset, iset);
724 if (!pm2->vddadc_en_ac) { 724 if (!pm2->vddadc_en_ac) {
725 regulator_enable(pm2->regu); 725 ret = regulator_enable(pm2->regu);
726 pm2->vddadc_en_ac = true; 726 if (ret)
727 dev_warn(pm2->dev,
728 "Failed to enable vddadc regulator\n");
729 else
730 pm2->vddadc_en_ac = true;
727 } 731 }
728 732
729 ret = pm2xxx_charging_init(pm2); 733 ret = pm2xxx_charging_init(pm2);
@@ -953,37 +957,24 @@ static int pm2xxx_runtime_suspend(struct device *dev)
953{ 957{
954 struct i2c_client *pm2xxx_i2c_client = to_i2c_client(dev); 958 struct i2c_client *pm2xxx_i2c_client = to_i2c_client(dev);
955 struct pm2xxx_charger *pm2; 959 struct pm2xxx_charger *pm2;
956 int ret = 0;
957 960
958 pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client); 961 pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client);
959 if (!pm2) {
960 dev_err(pm2->dev, "no pm2xxx_charger data supplied\n");
961 ret = -EINVAL;
962 return ret;
963 }
964
965 clear_lpn_pin(pm2); 962 clear_lpn_pin(pm2);
966 963
967 return ret; 964 return 0;
968} 965}
969 966
970static int pm2xxx_runtime_resume(struct device *dev) 967static int pm2xxx_runtime_resume(struct device *dev)
971{ 968{
972 struct i2c_client *pm2xxx_i2c_client = to_i2c_client(dev); 969 struct i2c_client *pm2xxx_i2c_client = to_i2c_client(dev);
973 struct pm2xxx_charger *pm2; 970 struct pm2xxx_charger *pm2;
974 int ret = 0;
975 971
976 pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client); 972 pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client);
977 if (!pm2) {
978 dev_err(pm2->dev, "no pm2xxx_charger data supplied\n");
979 ret = -EINVAL;
980 return ret;
981 }
982 973
983 if (gpio_is_valid(pm2->lpn_pin) && gpio_get_value(pm2->lpn_pin) == 0) 974 if (gpio_is_valid(pm2->lpn_pin) && gpio_get_value(pm2->lpn_pin) == 0)
984 set_lpn_pin(pm2); 975 set_lpn_pin(pm2);
985 976
986 return ret; 977 return 0;
987} 978}
988 979
989#endif 980#endif
diff --git a/drivers/power/tps65090-charger.c b/drivers/power/tps65090-charger.c
index bdd7b9b2546a..8fc9d6df87f6 100644
--- a/drivers/power/tps65090-charger.c
+++ b/drivers/power/tps65090-charger.c
@@ -15,15 +15,17 @@
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18#include <linux/delay.h>
18#include <linux/err.h> 19#include <linux/err.h>
19#include <linux/init.h> 20#include <linux/init.h>
20#include <linux/interrupt.h> 21#include <linux/interrupt.h>
21#include <linux/kernel.h> 22#include <linux/kernel.h>
22#include <linux/module.h> 23#include <linux/module.h>
23#include <linux/slab.h> 24#include <linux/of_device.h>
24#include <linux/delay.h>
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/power_supply.h> 26#include <linux/power_supply.h>
27#include <linux/slab.h>
28
27#include <linux/mfd/tps65090.h> 29#include <linux/mfd/tps65090.h>
28 30
29#define TPS65090_REG_INTR_STS 0x00 31#define TPS65090_REG_INTR_STS 0x00
@@ -185,10 +187,6 @@ static irqreturn_t tps65090_charger_isr(int irq, void *dev_id)
185 return IRQ_HANDLED; 187 return IRQ_HANDLED;
186} 188}
187 189
188#if defined(CONFIG_OF)
189
190#include <linux/of_device.h>
191
192static struct tps65090_platform_data * 190static struct tps65090_platform_data *
193 tps65090_parse_dt_charger_data(struct platform_device *pdev) 191 tps65090_parse_dt_charger_data(struct platform_device *pdev)
194{ 192{
@@ -210,13 +208,6 @@ static struct tps65090_platform_data *
210 return pdata; 208 return pdata;
211 209
212} 210}
213#else
214static struct tps65090_platform_data *
215 tps65090_parse_dt_charger_data(struct platform_device *pdev)
216{
217 return NULL;
218}
219#endif
220 211
221static int tps65090_charger_probe(struct platform_device *pdev) 212static int tps65090_charger_probe(struct platform_device *pdev)
222{ 213{
@@ -228,7 +219,7 @@ static int tps65090_charger_probe(struct platform_device *pdev)
228 219
229 pdata = dev_get_platdata(pdev->dev.parent); 220 pdata = dev_get_platdata(pdev->dev.parent);
230 221
231 if (!pdata && pdev->dev.of_node) 222 if (IS_ENABLED(CONFIG_OF) && !pdata && pdev->dev.of_node)
232 pdata = tps65090_parse_dt_charger_data(pdev); 223 pdata = tps65090_parse_dt_charger_data(pdev);
233 224
234 if (!pdata) { 225 if (!pdata) {
@@ -277,13 +268,13 @@ static int tps65090_charger_probe(struct platform_device *pdev)
277 if (ret) { 268 if (ret) {
278 dev_err(cdata->dev, "Unable to register irq %d err %d\n", irq, 269 dev_err(cdata->dev, "Unable to register irq %d err %d\n", irq,
279 ret); 270 ret);
280 goto fail_free_irq; 271 goto fail_unregister_supply;
281 } 272 }
282 273
283 ret = tps65090_config_charger(cdata); 274 ret = tps65090_config_charger(cdata);
284 if (ret < 0) { 275 if (ret < 0) {
285 dev_err(&pdev->dev, "charger config failed, err %d\n", ret); 276 dev_err(&pdev->dev, "charger config failed, err %d\n", ret);
286 goto fail_free_irq; 277 goto fail_unregister_supply;
287 } 278 }
288 279
289 /* Check for charger presence */ 280 /* Check for charger presence */
@@ -292,14 +283,14 @@ static int tps65090_charger_probe(struct platform_device *pdev)
292 if (ret < 0) { 283 if (ret < 0) {
293 dev_err(cdata->dev, "%s(): Error in reading reg 0x%x", __func__, 284 dev_err(cdata->dev, "%s(): Error in reading reg 0x%x", __func__,
294 TPS65090_REG_CG_STATUS1); 285 TPS65090_REG_CG_STATUS1);
295 goto fail_free_irq; 286 goto fail_unregister_supply;
296 } 287 }
297 288
298 if (status1 != 0) { 289 if (status1 != 0) {
299 ret = tps65090_enable_charging(cdata); 290 ret = tps65090_enable_charging(cdata);
300 if (ret < 0) { 291 if (ret < 0) {
301 dev_err(cdata->dev, "error enabling charger\n"); 292 dev_err(cdata->dev, "error enabling charger\n");
302 goto fail_free_irq; 293 goto fail_unregister_supply;
303 } 294 }
304 cdata->ac_online = 1; 295 cdata->ac_online = 1;
305 power_supply_changed(&cdata->ac); 296 power_supply_changed(&cdata->ac);
@@ -307,8 +298,6 @@ static int tps65090_charger_probe(struct platform_device *pdev)
307 298
308 return 0; 299 return 0;
309 300
310fail_free_irq:
311 devm_free_irq(cdata->dev, irq, cdata);
312fail_unregister_supply: 301fail_unregister_supply:
313 power_supply_unregister(&cdata->ac); 302 power_supply_unregister(&cdata->ac);
314 303
@@ -319,7 +308,6 @@ static int tps65090_charger_remove(struct platform_device *pdev)
319{ 308{
320 struct tps65090_charger *cdata = platform_get_drvdata(pdev); 309 struct tps65090_charger *cdata = platform_get_drvdata(pdev);
321 310
322 devm_free_irq(cdata->dev, cdata->irq, cdata);
323 power_supply_unregister(&cdata->ac); 311 power_supply_unregister(&cdata->ac);
324 312
325 return 0; 313 return 0;
diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
index d98abe911e37..f14108844e1a 100644
--- a/drivers/power/twl4030_charger.c
+++ b/drivers/power/twl4030_charger.c
@@ -495,10 +495,38 @@ static enum power_supply_property twl4030_charger_props[] = {
495 POWER_SUPPLY_PROP_CURRENT_NOW, 495 POWER_SUPPLY_PROP_CURRENT_NOW,
496}; 496};
497 497
498#ifdef CONFIG_OF
499static const struct twl4030_bci_platform_data *
500twl4030_bci_parse_dt(struct device *dev)
501{
502 struct device_node *np = dev->of_node;
503 struct twl4030_bci_platform_data *pdata;
504 u32 num;
505
506 if (!np)
507 return NULL;
508 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
509 if (!pdata)
510 return pdata;
511
512 if (of_property_read_u32(np, "ti,bb-uvolt", &num) == 0)
513 pdata->bb_uvolt = num;
514 if (of_property_read_u32(np, "ti,bb-uamp", &num) == 0)
515 pdata->bb_uamp = num;
516 return pdata;
517}
518#else
519static inline const struct twl4030_bci_platform_data *
520twl4030_bci_parse_dt(struct device *dev)
521{
522 return NULL;
523}
524#endif
525
498static int __init twl4030_bci_probe(struct platform_device *pdev) 526static int __init twl4030_bci_probe(struct platform_device *pdev)
499{ 527{
500 struct twl4030_bci *bci; 528 struct twl4030_bci *bci;
501 struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data; 529 const struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data;
502 int ret; 530 int ret;
503 u32 reg; 531 u32 reg;
504 532
@@ -506,6 +534,9 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
506 if (bci == NULL) 534 if (bci == NULL)
507 return -ENOMEM; 535 return -ENOMEM;
508 536
537 if (!pdata)
538 pdata = twl4030_bci_parse_dt(&pdev->dev);
539
509 bci->dev = &pdev->dev; 540 bci->dev = &pdev->dev;
510 bci->irq_chg = platform_get_irq(pdev, 0); 541 bci->irq_chg = platform_get_irq(pdev, 0);
511 bci->irq_bci = platform_get_irq(pdev, 1); 542 bci->irq_bci = platform_get_irq(pdev, 1);
@@ -581,8 +612,11 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
581 612
582 twl4030_charger_enable_ac(true); 613 twl4030_charger_enable_ac(true);
583 twl4030_charger_enable_usb(bci, true); 614 twl4030_charger_enable_usb(bci, true);
584 twl4030_charger_enable_backup(pdata->bb_uvolt, 615 if (pdata)
585 pdata->bb_uamp); 616 twl4030_charger_enable_backup(pdata->bb_uvolt,
617 pdata->bb_uamp);
618 else
619 twl4030_charger_enable_backup(0, 0);
586 620
587 return 0; 621 return 0;
588 622
@@ -631,10 +665,17 @@ static int __exit twl4030_bci_remove(struct platform_device *pdev)
631 return 0; 665 return 0;
632} 666}
633 667
668static const struct of_device_id twl_bci_of_match[] = {
669 {.compatible = "ti,twl4030-bci", },
670 { }
671};
672MODULE_DEVICE_TABLE(of, twl_bci_of_match);
673
634static struct platform_driver twl4030_bci_driver = { 674static struct platform_driver twl4030_bci_driver = {
635 .driver = { 675 .driver = {
636 .name = "twl4030_bci", 676 .name = "twl4030_bci",
637 .owner = THIS_MODULE, 677 .owner = THIS_MODULE,
678 .of_match_table = of_match_ptr(twl_bci_of_match),
638 }, 679 },
639 .remove = __exit_p(twl4030_bci_remove), 680 .remove = __exit_p(twl4030_bci_remove),
640}; 681};
diff --git a/drivers/s390/block/scm_blk.c b/drivers/s390/block/scm_blk.c
index 548209a9c43c..d0ab5019d885 100644
--- a/drivers/s390/block/scm_blk.c
+++ b/drivers/s390/block/scm_blk.c
@@ -118,22 +118,6 @@ static void scm_request_done(struct scm_request *scmrq)
118 spin_unlock_irqrestore(&list_lock, flags); 118 spin_unlock_irqrestore(&list_lock, flags);
119} 119}
120 120
121static int scm_open(struct block_device *blkdev, fmode_t mode)
122{
123 return scm_get_ref();
124}
125
126static void scm_release(struct gendisk *gendisk, fmode_t mode)
127{
128 scm_put_ref();
129}
130
131static const struct block_device_operations scm_blk_devops = {
132 .owner = THIS_MODULE,
133 .open = scm_open,
134 .release = scm_release,
135};
136
137static bool scm_permit_request(struct scm_blk_dev *bdev, struct request *req) 121static bool scm_permit_request(struct scm_blk_dev *bdev, struct request *req)
138{ 122{
139 return rq_data_dir(req) != WRITE || bdev->state != SCM_WR_PROHIBIT; 123 return rq_data_dir(req) != WRITE || bdev->state != SCM_WR_PROHIBIT;
@@ -256,7 +240,7 @@ static void scm_blk_request(struct request_queue *rq)
256 atomic_inc(&bdev->queued_reqs); 240 atomic_inc(&bdev->queued_reqs);
257 blk_start_request(req); 241 blk_start_request(req);
258 242
259 ret = scm_start_aob(scmrq->aob); 243 ret = eadm_start_aob(scmrq->aob);
260 if (ret) { 244 if (ret) {
261 SCM_LOG(5, "no subchannel"); 245 SCM_LOG(5, "no subchannel");
262 scm_request_requeue(scmrq); 246 scm_request_requeue(scmrq);
@@ -320,7 +304,7 @@ static void scm_blk_handle_error(struct scm_request *scmrq)
320 } 304 }
321 305
322restart: 306restart:
323 if (!scm_start_aob(scmrq->aob)) 307 if (!eadm_start_aob(scmrq->aob))
324 return; 308 return;
325 309
326requeue: 310requeue:
@@ -363,6 +347,10 @@ static void scm_blk_tasklet(struct scm_blk_dev *bdev)
363 blk_run_queue(bdev->rq); 347 blk_run_queue(bdev->rq);
364} 348}
365 349
350static const struct block_device_operations scm_blk_devops = {
351 .owner = THIS_MODULE,
352};
353
366int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev) 354int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
367{ 355{
368 struct request_queue *rq; 356 struct request_queue *rq;
diff --git a/drivers/s390/block/scm_blk_cluster.c b/drivers/s390/block/scm_blk_cluster.c
index c0d102e3a48b..27f930cd657f 100644
--- a/drivers/s390/block/scm_blk_cluster.c
+++ b/drivers/s390/block/scm_blk_cluster.c
@@ -187,7 +187,7 @@ bool scm_need_cluster_request(struct scm_request *scmrq)
187void scm_initiate_cluster_request(struct scm_request *scmrq) 187void scm_initiate_cluster_request(struct scm_request *scmrq)
188{ 188{
189 scm_prepare_cluster_request(scmrq); 189 scm_prepare_cluster_request(scmrq);
190 if (scm_start_aob(scmrq->aob)) 190 if (eadm_start_aob(scmrq->aob))
191 scm_request_requeue(scmrq); 191 scm_request_requeue(scmrq);
192} 192}
193 193
diff --git a/drivers/s390/char/Makefile b/drivers/s390/char/Makefile
index 17821a026c9c..b69ab17f13fa 100644
--- a/drivers/s390/char/Makefile
+++ b/drivers/s390/char/Makefile
@@ -3,7 +3,8 @@
3# 3#
4 4
5obj-y += ctrlchar.o keyboard.o defkeymap.o sclp.o sclp_rw.o sclp_quiesce.o \ 5obj-y += ctrlchar.o keyboard.o defkeymap.o sclp.o sclp_rw.o sclp_quiesce.o \
6 sclp_cmd.o sclp_config.o sclp_cpi_sys.o sclp_ocf.o sclp_ctl.o 6 sclp_cmd.o sclp_config.o sclp_cpi_sys.o sclp_ocf.o sclp_ctl.o \
7 sclp_early.o
7 8
8obj-$(CONFIG_TN3270) += raw3270.o 9obj-$(CONFIG_TN3270) += raw3270.o
9obj-$(CONFIG_TN3270_CONSOLE) += con3270.o 10obj-$(CONFIG_TN3270_CONSOLE) += con3270.o
diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index f93cc32eb818..71e974738014 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -564,6 +564,7 @@ static void __exit
564fs3270_exit(void) 564fs3270_exit(void)
565{ 565{
566 raw3270_unregister_notifier(&fs3270_notifier); 566 raw3270_unregister_notifier(&fs3270_notifier);
567 device_destroy(class3270, MKDEV(IBM_FS3270_MAJOR, 0));
567 __unregister_chrdev(IBM_FS3270_MAJOR, 0, 1, "fs3270"); 568 __unregister_chrdev(IBM_FS3270_MAJOR, 0, 1, "fs3270");
568} 569}
569 570
diff --git a/drivers/s390/char/sclp.h b/drivers/s390/char/sclp.h
index 40d1406289ed..6fbe09686d18 100644
--- a/drivers/s390/char/sclp.h
+++ b/drivers/s390/char/sclp.h
@@ -99,6 +99,7 @@ struct init_sccb {
99} __attribute__((packed)); 99} __attribute__((packed));
100 100
101extern u64 sclp_facilities; 101extern u64 sclp_facilities;
102
102#define SCLP_HAS_CHP_INFO (sclp_facilities & 0x8000000000000000ULL) 103#define SCLP_HAS_CHP_INFO (sclp_facilities & 0x8000000000000000ULL)
103#define SCLP_HAS_CHP_RECONFIG (sclp_facilities & 0x2000000000000000ULL) 104#define SCLP_HAS_CHP_RECONFIG (sclp_facilities & 0x2000000000000000ULL)
104#define SCLP_HAS_CPU_INFO (sclp_facilities & 0x0800000000000000ULL) 105#define SCLP_HAS_CPU_INFO (sclp_facilities & 0x0800000000000000ULL)
@@ -179,6 +180,10 @@ void sclp_sdias_exit(void);
179extern int sclp_console_pages; 180extern int sclp_console_pages;
180extern int sclp_console_drop; 181extern int sclp_console_drop;
181extern unsigned long sclp_console_full; 182extern unsigned long sclp_console_full;
183extern u8 sclp_fac84;
184extern unsigned long long sclp_rzm;
185extern unsigned long long sclp_rnmax;
186extern __initdata int sclp_early_read_info_sccb_valid;
182 187
183/* useful inlines */ 188/* useful inlines */
184 189
diff --git a/drivers/s390/char/sclp_cmd.c b/drivers/s390/char/sclp_cmd.c
index 77df9cb00688..eaa21d542c5c 100644
--- a/drivers/s390/char/sclp_cmd.c
+++ b/drivers/s390/char/sclp_cmd.c
@@ -28,168 +28,6 @@
28 28
29#include "sclp.h" 29#include "sclp.h"
30 30
31#define SCLP_CMDW_READ_SCP_INFO 0x00020001
32#define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
33
34struct read_info_sccb {
35 struct sccb_header header; /* 0-7 */
36 u16 rnmax; /* 8-9 */
37 u8 rnsize; /* 10 */
38 u8 _reserved0[24 - 11]; /* 11-15 */
39 u8 loadparm[8]; /* 24-31 */
40 u8 _reserved1[48 - 32]; /* 32-47 */
41 u64 facilities; /* 48-55 */
42 u8 _reserved2[84 - 56]; /* 56-83 */
43 u8 fac84; /* 84 */
44 u8 fac85; /* 85 */
45 u8 _reserved3[91 - 86]; /* 86-90 */
46 u8 flags; /* 91 */
47 u8 _reserved4[100 - 92]; /* 92-99 */
48 u32 rnsize2; /* 100-103 */
49 u64 rnmax2; /* 104-111 */
50 u8 _reserved5[4096 - 112]; /* 112-4095 */
51} __attribute__((packed, aligned(PAGE_SIZE)));
52
53static struct init_sccb __initdata early_event_mask_sccb __aligned(PAGE_SIZE);
54static struct read_info_sccb __initdata early_read_info_sccb;
55static int __initdata early_read_info_sccb_valid;
56
57u64 sclp_facilities;
58static u8 sclp_fac84;
59static unsigned long long rzm;
60static unsigned long long rnmax;
61
62static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
63{
64 int rc;
65
66 __ctl_set_bit(0, 9);
67 rc = sclp_service_call(cmd, sccb);
68 if (rc)
69 goto out;
70 __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA |
71 PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT);
72 local_irq_disable();
73out:
74 /* Contents of the sccb might have changed. */
75 barrier();
76 __ctl_clear_bit(0, 9);
77 return rc;
78}
79
80static void __init sclp_read_info_early(void)
81{
82 int rc;
83 int i;
84 struct read_info_sccb *sccb;
85 sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
86 SCLP_CMDW_READ_SCP_INFO};
87
88 sccb = &early_read_info_sccb;
89 for (i = 0; i < ARRAY_SIZE(commands); i++) {
90 do {
91 memset(sccb, 0, sizeof(*sccb));
92 sccb->header.length = sizeof(*sccb);
93 sccb->header.function_code = 0x80;
94 sccb->header.control_mask[2] = 0x80;
95 rc = sclp_cmd_sync_early(commands[i], sccb);
96 } while (rc == -EBUSY);
97
98 if (rc)
99 break;
100 if (sccb->header.response_code == 0x10) {
101 early_read_info_sccb_valid = 1;
102 break;
103 }
104 if (sccb->header.response_code != 0x1f0)
105 break;
106 }
107}
108
109static void __init sclp_event_mask_early(void)
110{
111 struct init_sccb *sccb = &early_event_mask_sccb;
112 int rc;
113
114 do {
115 memset(sccb, 0, sizeof(*sccb));
116 sccb->header.length = sizeof(*sccb);
117 sccb->mask_length = sizeof(sccb_mask_t);
118 rc = sclp_cmd_sync_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb);
119 } while (rc == -EBUSY);
120}
121
122void __init sclp_facilities_detect(void)
123{
124 struct read_info_sccb *sccb;
125
126 sclp_read_info_early();
127 if (!early_read_info_sccb_valid)
128 return;
129
130 sccb = &early_read_info_sccb;
131 sclp_facilities = sccb->facilities;
132 sclp_fac84 = sccb->fac84;
133 if (sccb->fac85 & 0x02)
134 S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
135 rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
136 rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
137 rzm <<= 20;
138
139 sclp_event_mask_early();
140}
141
142bool __init sclp_has_linemode(void)
143{
144 struct init_sccb *sccb = &early_event_mask_sccb;
145
146 if (sccb->header.response_code != 0x20)
147 return 0;
148 if (!(sccb->sclp_send_mask & (EVTYP_OPCMD_MASK | EVTYP_PMSGCMD_MASK)))
149 return 0;
150 if (!(sccb->sclp_receive_mask & (EVTYP_MSG_MASK | EVTYP_PMSGCMD_MASK)))
151 return 0;
152 return 1;
153}
154
155bool __init sclp_has_vt220(void)
156{
157 struct init_sccb *sccb = &early_event_mask_sccb;
158
159 if (sccb->header.response_code != 0x20)
160 return 0;
161 if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK)
162 return 1;
163 return 0;
164}
165
166unsigned long long sclp_get_rnmax(void)
167{
168 return rnmax;
169}
170
171unsigned long long sclp_get_rzm(void)
172{
173 return rzm;
174}
175
176/*
177 * This function will be called after sclp_facilities_detect(), which gets
178 * called from early.c code. Therefore the sccb should have valid contents.
179 */
180void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
181{
182 struct read_info_sccb *sccb;
183
184 if (!early_read_info_sccb_valid)
185 return;
186 sccb = &early_read_info_sccb;
187 info->is_valid = 1;
188 if (sccb->flags & 0x2)
189 info->has_dump = 1;
190 memcpy(&info->loadparm, &sccb->loadparm, LOADPARM_LEN);
191}
192
193static void sclp_sync_callback(struct sclp_req *req, void *data) 31static void sclp_sync_callback(struct sclp_req *req, void *data)
194{ 32{
195 struct completion *completion = data; 33 struct completion *completion = data;
@@ -356,14 +194,14 @@ struct assign_storage_sccb {
356 194
357int arch_get_memory_phys_device(unsigned long start_pfn) 195int arch_get_memory_phys_device(unsigned long start_pfn)
358{ 196{
359 if (!rzm) 197 if (!sclp_rzm)
360 return 0; 198 return 0;
361 return PFN_PHYS(start_pfn) >> ilog2(rzm); 199 return PFN_PHYS(start_pfn) >> ilog2(sclp_rzm);
362} 200}
363 201
364static unsigned long long rn2addr(u16 rn) 202static unsigned long long rn2addr(u16 rn)
365{ 203{
366 return (unsigned long long) (rn - 1) * rzm; 204 return (unsigned long long) (rn - 1) * sclp_rzm;
367} 205}
368 206
369static int do_assign_storage(sclp_cmdw_t cmd, u16 rn) 207static int do_assign_storage(sclp_cmdw_t cmd, u16 rn)
@@ -404,7 +242,7 @@ static int sclp_assign_storage(u16 rn)
404 if (rc) 242 if (rc)
405 return rc; 243 return rc;
406 start = rn2addr(rn); 244 start = rn2addr(rn);
407 storage_key_init_range(start, start + rzm); 245 storage_key_init_range(start, start + sclp_rzm);
408 return 0; 246 return 0;
409} 247}
410 248
@@ -462,7 +300,7 @@ static int sclp_mem_change_state(unsigned long start, unsigned long size,
462 istart = rn2addr(incr->rn); 300 istart = rn2addr(incr->rn);
463 if (start + size - 1 < istart) 301 if (start + size - 1 < istart)
464 break; 302 break;
465 if (start > istart + rzm - 1) 303 if (start > istart + sclp_rzm - 1)
466 continue; 304 continue;
467 if (online) 305 if (online)
468 rc |= sclp_assign_storage(incr->rn); 306 rc |= sclp_assign_storage(incr->rn);
@@ -526,7 +364,7 @@ static void __init add_memory_merged(u16 rn)
526 if (!first_rn) 364 if (!first_rn)
527 goto skip_add; 365 goto skip_add;
528 start = rn2addr(first_rn); 366 start = rn2addr(first_rn);
529 size = (unsigned long long ) num * rzm; 367 size = (unsigned long long) num * sclp_rzm;
530 if (start >= VMEM_MAX_PHYS) 368 if (start >= VMEM_MAX_PHYS)
531 goto skip_add; 369 goto skip_add;
532 if (start + size > VMEM_MAX_PHYS) 370 if (start + size > VMEM_MAX_PHYS)
@@ -574,7 +412,7 @@ static void __init insert_increment(u16 rn, int standby, int assigned)
574 } 412 }
575 if (!assigned) 413 if (!assigned)
576 new_incr->rn = last_rn + 1; 414 new_incr->rn = last_rn + 1;
577 if (new_incr->rn > rnmax) { 415 if (new_incr->rn > sclp_rnmax) {
578 kfree(new_incr); 416 kfree(new_incr);
579 return; 417 return;
580 } 418 }
@@ -617,7 +455,7 @@ static int __init sclp_detect_standby_memory(void)
617 455
618 if (OLDMEM_BASE) /* No standby memory in kdump mode */ 456 if (OLDMEM_BASE) /* No standby memory in kdump mode */
619 return 0; 457 return 0;
620 if (!early_read_info_sccb_valid) 458 if (!sclp_early_read_info_sccb_valid)
621 return 0; 459 return 0;
622 if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL) 460 if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL)
623 return 0; 461 return 0;
@@ -661,7 +499,7 @@ static int __init sclp_detect_standby_memory(void)
661 } 499 }
662 if (rc || list_empty(&sclp_mem_list)) 500 if (rc || list_empty(&sclp_mem_list))
663 goto out; 501 goto out;
664 for (i = 1; i <= rnmax - assigned; i++) 502 for (i = 1; i <= sclp_rnmax - assigned; i++)
665 insert_increment(0, 1, 0); 503 insert_increment(0, 1, 0);
666 rc = register_memory_notifier(&sclp_mem_nb); 504 rc = register_memory_notifier(&sclp_mem_nb);
667 if (rc) 505 if (rc)
diff --git a/drivers/s390/char/sclp_early.c b/drivers/s390/char/sclp_early.c
new file mode 100644
index 000000000000..f7aa080e9b28
--- /dev/null
+++ b/drivers/s390/char/sclp_early.c
@@ -0,0 +1,264 @@
1/*
2 * SCLP early driver
3 *
4 * Copyright IBM Corp. 2013
5 */
6
7#define KMSG_COMPONENT "sclp_early"
8#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
9
10#include <asm/ctl_reg.h>
11#include <asm/sclp.h>
12#include <asm/ipl.h>
13#include "sclp_sdias.h"
14#include "sclp.h"
15
16#define SCLP_CMDW_READ_SCP_INFO 0x00020001
17#define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
18
19struct read_info_sccb {
20 struct sccb_header header; /* 0-7 */
21 u16 rnmax; /* 8-9 */
22 u8 rnsize; /* 10 */
23 u8 _reserved0[24 - 11]; /* 11-15 */
24 u8 loadparm[8]; /* 24-31 */
25 u8 _reserved1[48 - 32]; /* 32-47 */
26 u64 facilities; /* 48-55 */
27 u8 _reserved2[84 - 56]; /* 56-83 */
28 u8 fac84; /* 84 */
29 u8 fac85; /* 85 */
30 u8 _reserved3[91 - 86]; /* 86-90 */
31 u8 flags; /* 91 */
32 u8 _reserved4[100 - 92]; /* 92-99 */
33 u32 rnsize2; /* 100-103 */
34 u64 rnmax2; /* 104-111 */
35 u8 _reserved5[4096 - 112]; /* 112-4095 */
36} __packed __aligned(PAGE_SIZE);
37
38static __initdata struct init_sccb early_event_mask_sccb __aligned(PAGE_SIZE);
39static __initdata struct read_info_sccb early_read_info_sccb;
40static __initdata char sccb_early[PAGE_SIZE] __aligned(PAGE_SIZE);
41static unsigned long sclp_hsa_size;
42
43__initdata int sclp_early_read_info_sccb_valid;
44u64 sclp_facilities;
45u8 sclp_fac84;
46unsigned long long sclp_rzm;
47unsigned long long sclp_rnmax;
48
49static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
50{
51 int rc;
52
53 __ctl_set_bit(0, 9);
54 rc = sclp_service_call(cmd, sccb);
55 if (rc)
56 goto out;
57 __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA |
58 PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT);
59 local_irq_disable();
60out:
61 /* Contents of the sccb might have changed. */
62 barrier();
63 __ctl_clear_bit(0, 9);
64 return rc;
65}
66
67static void __init sclp_read_info_early(void)
68{
69 int rc;
70 int i;
71 struct read_info_sccb *sccb;
72 sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
73 SCLP_CMDW_READ_SCP_INFO};
74
75 sccb = &early_read_info_sccb;
76 for (i = 0; i < ARRAY_SIZE(commands); i++) {
77 do {
78 memset(sccb, 0, sizeof(*sccb));
79 sccb->header.length = sizeof(*sccb);
80 sccb->header.function_code = 0x80;
81 sccb->header.control_mask[2] = 0x80;
82 rc = sclp_cmd_sync_early(commands[i], sccb);
83 } while (rc == -EBUSY);
84
85 if (rc)
86 break;
87 if (sccb->header.response_code == 0x10) {
88 sclp_early_read_info_sccb_valid = 1;
89 break;
90 }
91 if (sccb->header.response_code != 0x1f0)
92 break;
93 }
94}
95
96static void __init sclp_facilities_detect(void)
97{
98 struct read_info_sccb *sccb;
99
100 sclp_read_info_early();
101 if (!sclp_early_read_info_sccb_valid)
102 return;
103
104 sccb = &early_read_info_sccb;
105 sclp_facilities = sccb->facilities;
106 sclp_fac84 = sccb->fac84;
107 if (sccb->fac85 & 0x02)
108 S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
109 sclp_rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
110 sclp_rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
111 sclp_rzm <<= 20;
112}
113
114bool __init sclp_has_linemode(void)
115{
116 struct init_sccb *sccb = &early_event_mask_sccb;
117
118 if (sccb->header.response_code != 0x20)
119 return 0;
120 if (!(sccb->sclp_send_mask & (EVTYP_OPCMD_MASK | EVTYP_PMSGCMD_MASK)))
121 return 0;
122 if (!(sccb->sclp_receive_mask & (EVTYP_MSG_MASK | EVTYP_PMSGCMD_MASK)))
123 return 0;
124 return 1;
125}
126
127bool __init sclp_has_vt220(void)
128{
129 struct init_sccb *sccb = &early_event_mask_sccb;
130
131 if (sccb->header.response_code != 0x20)
132 return 0;
133 if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK)
134 return 1;
135 return 0;
136}
137
138unsigned long long sclp_get_rnmax(void)
139{
140 return sclp_rnmax;
141}
142
143unsigned long long sclp_get_rzm(void)
144{
145 return sclp_rzm;
146}
147
148/*
149 * This function will be called after sclp_facilities_detect(), which gets
150 * called from early.c code. Therefore the sccb should have valid contents.
151 */
152void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
153{
154 struct read_info_sccb *sccb;
155
156 if (!sclp_early_read_info_sccb_valid)
157 return;
158 sccb = &early_read_info_sccb;
159 info->is_valid = 1;
160 if (sccb->flags & 0x2)
161 info->has_dump = 1;
162 memcpy(&info->loadparm, &sccb->loadparm, LOADPARM_LEN);
163}
164
165static int __init sclp_cmd_early(sclp_cmdw_t cmd, void *sccb)
166{
167 int rc;
168
169 do {
170 rc = sclp_cmd_sync_early(cmd, sccb);
171 } while (rc == -EBUSY);
172
173 if (rc)
174 return -EIO;
175 if (((struct sccb_header *) sccb)->response_code != 0x0020)
176 return -EIO;
177 return 0;
178}
179
180static void __init sccb_init_eq_size(struct sdias_sccb *sccb)
181{
182 memset(sccb, 0, sizeof(*sccb));
183
184 sccb->hdr.length = sizeof(*sccb);
185 sccb->evbuf.hdr.length = sizeof(struct sdias_evbuf);
186 sccb->evbuf.hdr.type = EVTYP_SDIAS;
187 sccb->evbuf.event_qual = SDIAS_EQ_SIZE;
188 sccb->evbuf.data_id = SDIAS_DI_FCP_DUMP;
189 sccb->evbuf.event_id = 4712;
190 sccb->evbuf.dbs = 1;
191}
192
193static int __init sclp_set_event_mask(unsigned long receive_mask,
194 unsigned long send_mask)
195{
196 struct init_sccb *sccb = (void *) &sccb_early;
197
198 memset(sccb, 0, sizeof(*sccb));
199 sccb->header.length = sizeof(*sccb);
200 sccb->mask_length = sizeof(sccb_mask_t);
201 sccb->receive_mask = receive_mask;
202 sccb->send_mask = send_mask;
203 return sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb);
204}
205
206static long __init sclp_hsa_size_init(void)
207{
208 struct sdias_sccb *sccb = (void *) &sccb_early;
209
210 sccb_init_eq_size(sccb);
211 if (sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_DATA, sccb))
212 return -EIO;
213 if (sccb->evbuf.blk_cnt != 0)
214 return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
215 return 0;
216}
217
218static long __init sclp_hsa_copy_wait(void)
219{
220 struct sccb_header *sccb = (void *) &sccb_early;
221
222 memset(sccb, 0, PAGE_SIZE);
223 sccb->length = PAGE_SIZE;
224 if (sclp_cmd_early(SCLP_CMDW_READ_EVENT_DATA, sccb))
225 return -EIO;
226 return (((struct sdias_sccb *) sccb)->evbuf.blk_cnt - 1) * PAGE_SIZE;
227}
228
229unsigned long sclp_get_hsa_size(void)
230{
231 return sclp_hsa_size;
232}
233
234static void __init sclp_hsa_size_detect(void)
235{
236 long size;
237
238 /* First try synchronous interface (LPAR) */
239 if (sclp_set_event_mask(0, 0x40000010))
240 return;
241 size = sclp_hsa_size_init();
242 if (size < 0)
243 return;
244 if (size != 0)
245 goto out;
246 /* Then try asynchronous interface (z/VM) */
247 if (sclp_set_event_mask(0x00000010, 0x40000010))
248 return;
249 size = sclp_hsa_size_init();
250 if (size < 0)
251 return;
252 size = sclp_hsa_copy_wait();
253 if (size < 0)
254 return;
255out:
256 sclp_hsa_size = size;
257}
258
259void __init sclp_early_detect(void)
260{
261 sclp_facilities_detect();
262 sclp_hsa_size_detect();
263 sclp_set_event_mask(0, 0);
264}
diff --git a/drivers/s390/char/sclp_sdias.c b/drivers/s390/char/sclp_sdias.c
index b1032931a1c4..561a0414b352 100644
--- a/drivers/s390/char/sclp_sdias.c
+++ b/drivers/s390/char/sclp_sdias.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Sclp "store data in absolut storage" 2 * SCLP "store data in absolute storage"
3 * 3 *
4 * Copyright IBM Corp. 2003, 2007 4 * Copyright IBM Corp. 2003, 2013
5 * Author(s): Michael Holzheu 5 * Author(s): Michael Holzheu
6 */ 6 */
7 7
@@ -14,6 +14,7 @@
14#include <asm/debug.h> 14#include <asm/debug.h>
15#include <asm/ipl.h> 15#include <asm/ipl.h>
16 16
17#include "sclp_sdias.h"
17#include "sclp.h" 18#include "sclp.h"
18#include "sclp_rw.h" 19#include "sclp_rw.h"
19 20
@@ -22,46 +23,12 @@
22#define SDIAS_RETRIES 300 23#define SDIAS_RETRIES 300
23#define SDIAS_SLEEP_TICKS 50 24#define SDIAS_SLEEP_TICKS 50
24 25
25#define EQ_STORE_DATA 0x0
26#define EQ_SIZE 0x1
27#define DI_FCP_DUMP 0x0
28#define ASA_SIZE_32 0x0
29#define ASA_SIZE_64 0x1
30#define EVSTATE_ALL_STORED 0x0
31#define EVSTATE_NO_DATA 0x3
32#define EVSTATE_PART_STORED 0x10
33
34static struct debug_info *sdias_dbf; 26static struct debug_info *sdias_dbf;
35 27
36static struct sclp_register sclp_sdias_register = { 28static struct sclp_register sclp_sdias_register = {
37 .send_mask = EVTYP_SDIAS_MASK, 29 .send_mask = EVTYP_SDIAS_MASK,
38}; 30};
39 31
40struct sdias_evbuf {
41 struct evbuf_header hdr;
42 u8 event_qual;
43 u8 data_id;
44 u64 reserved2;
45 u32 event_id;
46 u16 reserved3;
47 u8 asa_size;
48 u8 event_status;
49 u32 reserved4;
50 u32 blk_cnt;
51 u64 asa;
52 u32 reserved5;
53 u32 fbn;
54 u32 reserved6;
55 u32 lbn;
56 u16 reserved7;
57 u16 dbs;
58} __attribute__((packed));
59
60struct sdias_sccb {
61 struct sccb_header hdr;
62 struct sdias_evbuf evbuf;
63} __attribute__((packed));
64
65static struct sdias_sccb sccb __attribute__((aligned(4096))); 32static struct sdias_sccb sccb __attribute__((aligned(4096)));
66static struct sdias_evbuf sdias_evbuf; 33static struct sdias_evbuf sdias_evbuf;
67 34
@@ -148,8 +115,8 @@ int sclp_sdias_blk_count(void)
148 sccb.hdr.length = sizeof(sccb); 115 sccb.hdr.length = sizeof(sccb);
149 sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf); 116 sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf);
150 sccb.evbuf.hdr.type = EVTYP_SDIAS; 117 sccb.evbuf.hdr.type = EVTYP_SDIAS;
151 sccb.evbuf.event_qual = EQ_SIZE; 118 sccb.evbuf.event_qual = SDIAS_EQ_SIZE;
152 sccb.evbuf.data_id = DI_FCP_DUMP; 119 sccb.evbuf.data_id = SDIAS_DI_FCP_DUMP;
153 sccb.evbuf.event_id = 4712; 120 sccb.evbuf.event_id = 4712;
154 sccb.evbuf.dbs = 1; 121 sccb.evbuf.dbs = 1;
155 122
@@ -208,13 +175,13 @@ int sclp_sdias_copy(void *dest, int start_blk, int nr_blks)
208 sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf); 175 sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf);
209 sccb.evbuf.hdr.type = EVTYP_SDIAS; 176 sccb.evbuf.hdr.type = EVTYP_SDIAS;
210 sccb.evbuf.hdr.flags = 0; 177 sccb.evbuf.hdr.flags = 0;
211 sccb.evbuf.event_qual = EQ_STORE_DATA; 178 sccb.evbuf.event_qual = SDIAS_EQ_STORE_DATA;
212 sccb.evbuf.data_id = DI_FCP_DUMP; 179 sccb.evbuf.data_id = SDIAS_DI_FCP_DUMP;
213 sccb.evbuf.event_id = 4712; 180 sccb.evbuf.event_id = 4712;
214#ifdef CONFIG_64BIT 181#ifdef CONFIG_64BIT
215 sccb.evbuf.asa_size = ASA_SIZE_64; 182 sccb.evbuf.asa_size = SDIAS_ASA_SIZE_64;
216#else 183#else
217 sccb.evbuf.asa_size = ASA_SIZE_32; 184 sccb.evbuf.asa_size = SDIAS_ASA_SIZE_32;
218#endif 185#endif
219 sccb.evbuf.event_status = 0; 186 sccb.evbuf.event_status = 0;
220 sccb.evbuf.blk_cnt = nr_blks; 187 sccb.evbuf.blk_cnt = nr_blks;
@@ -240,20 +207,19 @@ int sclp_sdias_copy(void *dest, int start_blk, int nr_blks)
240 } 207 }
241 208
242 switch (sdias_evbuf.event_status) { 209 switch (sdias_evbuf.event_status) {
243 case EVSTATE_ALL_STORED: 210 case SDIAS_EVSTATE_ALL_STORED:
244 TRACE("all stored\n"); 211 TRACE("all stored\n");
245 break; 212 break;
246 case EVSTATE_PART_STORED: 213 case SDIAS_EVSTATE_PART_STORED:
247 TRACE("part stored: %i\n", sdias_evbuf.blk_cnt); 214 TRACE("part stored: %i\n", sdias_evbuf.blk_cnt);
248 break; 215 break;
249 case EVSTATE_NO_DATA: 216 case SDIAS_EVSTATE_NO_DATA:
250 TRACE("no data\n"); 217 TRACE("no data\n");
251 /* fall through */ 218 /* fall through */
252 default: 219 default:
253 pr_err("Error from SCLP while copying hsa. " 220 pr_err("Error from SCLP while copying hsa. Event status = %x\n",
254 "Event status = %x\n", 221 sdias_evbuf.event_status);
255 sdias_evbuf.event_status); 222 rc = -EIO;
256 rc = -EIO;
257 } 223 }
258out: 224out:
259 mutex_unlock(&sdias_mutex); 225 mutex_unlock(&sdias_mutex);
diff --git a/drivers/s390/char/sclp_sdias.h b/drivers/s390/char/sclp_sdias.h
new file mode 100644
index 000000000000..f2431c414150
--- /dev/null
+++ b/drivers/s390/char/sclp_sdias.h
@@ -0,0 +1,46 @@
1/*
2 * SCLP "store data in absolute storage"
3 *
4 * Copyright IBM Corp. 2003, 2013
5 */
6
7#ifndef SCLP_SDIAS_H
8#define SCLP_SDIAS_H
9
10#include "sclp.h"
11
12#define SDIAS_EQ_STORE_DATA 0x0
13#define SDIAS_EQ_SIZE 0x1
14#define SDIAS_DI_FCP_DUMP 0x0
15#define SDIAS_ASA_SIZE_32 0x0
16#define SDIAS_ASA_SIZE_64 0x1
17#define SDIAS_EVSTATE_ALL_STORED 0x0
18#define SDIAS_EVSTATE_NO_DATA 0x3
19#define SDIAS_EVSTATE_PART_STORED 0x10
20
21struct sdias_evbuf {
22 struct evbuf_header hdr;
23 u8 event_qual;
24 u8 data_id;
25 u64 reserved2;
26 u32 event_id;
27 u16 reserved3;
28 u8 asa_size;
29 u8 event_status;
30 u32 reserved4;
31 u32 blk_cnt;
32 u64 asa;
33 u32 reserved5;
34 u32 fbn;
35 u32 reserved6;
36 u32 lbn;
37 u16 reserved7;
38 u16 dbs;
39} __packed;
40
41struct sdias_sccb {
42 struct sccb_header hdr;
43 struct sdias_evbuf evbuf;
44} __packed;
45
46#endif /* SCLP_SDIAS_H */
diff --git a/drivers/s390/char/zcore.c b/drivers/s390/char/zcore.c
index ffb1fcf0bf5b..3d8e4d63f514 100644
--- a/drivers/s390/char/zcore.c
+++ b/drivers/s390/char/zcore.c
@@ -328,9 +328,9 @@ static ssize_t zcore_read(struct file *file, char __user *buf, size_t count,
328 mem_offs = 0; 328 mem_offs = 0;
329 329
330 /* Copy from HSA data */ 330 /* Copy from HSA data */
331 if (*ppos < (ZFCPDUMP_HSA_SIZE + HEADER_SIZE)) { 331 if (*ppos < sclp_get_hsa_size() + HEADER_SIZE) {
332 size = min((count - hdr_count), (size_t) (ZFCPDUMP_HSA_SIZE 332 size = min((count - hdr_count),
333 - mem_start)); 333 (size_t) (sclp_get_hsa_size() - mem_start));
334 rc = memcpy_hsa_user(buf + hdr_count, mem_start, size); 334 rc = memcpy_hsa_user(buf + hdr_count, mem_start, size);
335 if (rc) 335 if (rc)
336 goto fail; 336 goto fail;
@@ -490,7 +490,7 @@ static ssize_t zcore_hsa_read(struct file *filp, char __user *buf,
490 static char str[18]; 490 static char str[18];
491 491
492 if (hsa_available) 492 if (hsa_available)
493 snprintf(str, sizeof(str), "%lx\n", ZFCPDUMP_HSA_SIZE); 493 snprintf(str, sizeof(str), "%lx\n", sclp_get_hsa_size());
494 else 494 else
495 snprintf(str, sizeof(str), "0\n"); 495 snprintf(str, sizeof(str), "0\n");
496 return simple_read_from_buffer(buf, count, ppos, str, strlen(str)); 496 return simple_read_from_buffer(buf, count, ppos, str, strlen(str));
@@ -584,17 +584,9 @@ static int __init sys_info_init(enum arch_id arch, unsigned long mem_end)
584 584
585static int __init check_sdias(void) 585static int __init check_sdias(void)
586{ 586{
587 int rc, act_hsa_size; 587 if (!sclp_get_hsa_size()) {
588
589 rc = sclp_sdias_blk_count();
590 if (rc < 0) {
591 TRACE("Could not determine HSA size\n"); 588 TRACE("Could not determine HSA size\n");
592 return rc; 589 return -ENODEV;
593 }
594 act_hsa_size = (rc - 1) * PAGE_SIZE;
595 if (act_hsa_size < ZFCPDUMP_HSA_SIZE) {
596 TRACE("HSA size too small: %i\n", act_hsa_size);
597 return -EINVAL;
598 } 590 }
599 return 0; 591 return 0;
600} 592}
@@ -662,7 +654,7 @@ static int __init zcore_reipl_init(void)
662 ipl_block = (void *) __get_free_page(GFP_KERNEL); 654 ipl_block = (void *) __get_free_page(GFP_KERNEL);
663 if (!ipl_block) 655 if (!ipl_block)
664 return -ENOMEM; 656 return -ENOMEM;
665 if (ipib_info.ipib < ZFCPDUMP_HSA_SIZE) 657 if (ipib_info.ipib < sclp_get_hsa_size())
666 rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE); 658 rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
667 else 659 else
668 rc = memcpy_real(ipl_block, (void *) ipib_info.ipib, PAGE_SIZE); 660 rc = memcpy_real(ipl_block, (void *) ipib_info.ipib, PAGE_SIZE);
diff --git a/drivers/s390/cio/eadm_sch.c b/drivers/s390/cio/eadm_sch.c
index aca7bfc113aa..3a2ee4a740b4 100644
--- a/drivers/s390/cio/eadm_sch.c
+++ b/drivers/s390/cio/eadm_sch.c
@@ -190,7 +190,7 @@ static struct subchannel *eadm_get_idle_sch(void)
190 return NULL; 190 return NULL;
191} 191}
192 192
193static int eadm_start_aob(struct aob *aob) 193int eadm_start_aob(struct aob *aob)
194{ 194{
195 struct eadm_private *private; 195 struct eadm_private *private;
196 struct subchannel *sch; 196 struct subchannel *sch;
@@ -218,6 +218,7 @@ out_unlock:
218 218
219 return ret; 219 return ret;
220} 220}
221EXPORT_SYMBOL_GPL(eadm_start_aob);
221 222
222static int eadm_subchannel_probe(struct subchannel *sch) 223static int eadm_subchannel_probe(struct subchannel *sch)
223{ 224{
@@ -380,11 +381,6 @@ static struct css_driver eadm_subchannel_driver = {
380 .restore = eadm_subchannel_restore, 381 .restore = eadm_subchannel_restore,
381}; 382};
382 383
383static struct eadm_ops eadm_ops = {
384 .eadm_start = eadm_start_aob,
385 .owner = THIS_MODULE,
386};
387
388static int __init eadm_sch_init(void) 384static int __init eadm_sch_init(void)
389{ 385{
390 int ret; 386 int ret;
@@ -404,7 +400,6 @@ static int __init eadm_sch_init(void)
404 if (ret) 400 if (ret)
405 goto cleanup; 401 goto cleanup;
406 402
407 register_eadm_ops(&eadm_ops);
408 return ret; 403 return ret;
409 404
410cleanup: 405cleanup:
@@ -415,7 +410,6 @@ cleanup:
415 410
416static void __exit eadm_sch_exit(void) 411static void __exit eadm_sch_exit(void)
417{ 412{
418 unregister_eadm_ops(&eadm_ops);
419 css_driver_unregister(&eadm_subchannel_driver); 413 css_driver_unregister(&eadm_subchannel_driver);
420 isc_unregister(EADM_SCH_ISC); 414 isc_unregister(EADM_SCH_ISC);
421 debug_unregister(eadm_debug); 415 debug_unregister(eadm_debug);
diff --git a/drivers/s390/cio/scm.c b/drivers/s390/cio/scm.c
index 46ec25632e8b..15268edc54ae 100644
--- a/drivers/s390/cio/scm.c
+++ b/drivers/s390/cio/scm.c
@@ -15,8 +15,6 @@
15#include "chsc.h" 15#include "chsc.h"
16 16
17static struct device *scm_root; 17static struct device *scm_root;
18static struct eadm_ops *eadm_ops;
19static DEFINE_MUTEX(eadm_ops_mutex);
20 18
21#define to_scm_dev(n) container_of(n, struct scm_device, dev) 19#define to_scm_dev(n) container_of(n, struct scm_device, dev)
22#define to_scm_drv(d) container_of(d, struct scm_driver, drv) 20#define to_scm_drv(d) container_of(d, struct scm_driver, drv)
@@ -73,49 +71,6 @@ void scm_driver_unregister(struct scm_driver *scmdrv)
73} 71}
74EXPORT_SYMBOL_GPL(scm_driver_unregister); 72EXPORT_SYMBOL_GPL(scm_driver_unregister);
75 73
76int scm_get_ref(void)
77{
78 int ret = 0;
79
80 mutex_lock(&eadm_ops_mutex);
81 if (!eadm_ops || !try_module_get(eadm_ops->owner))
82 ret = -ENOENT;
83 mutex_unlock(&eadm_ops_mutex);
84
85 return ret;
86}
87EXPORT_SYMBOL_GPL(scm_get_ref);
88
89void scm_put_ref(void)
90{
91 mutex_lock(&eadm_ops_mutex);
92 module_put(eadm_ops->owner);
93 mutex_unlock(&eadm_ops_mutex);
94}
95EXPORT_SYMBOL_GPL(scm_put_ref);
96
97void register_eadm_ops(struct eadm_ops *ops)
98{
99 mutex_lock(&eadm_ops_mutex);
100 eadm_ops = ops;
101 mutex_unlock(&eadm_ops_mutex);
102}
103EXPORT_SYMBOL_GPL(register_eadm_ops);
104
105void unregister_eadm_ops(struct eadm_ops *ops)
106{
107 mutex_lock(&eadm_ops_mutex);
108 eadm_ops = NULL;
109 mutex_unlock(&eadm_ops_mutex);
110}
111EXPORT_SYMBOL_GPL(unregister_eadm_ops);
112
113int scm_start_aob(struct aob *aob)
114{
115 return eadm_ops->eadm_start(aob);
116}
117EXPORT_SYMBOL_GPL(scm_start_aob);
118
119void scm_irq_handler(struct aob *aob, int error) 74void scm_irq_handler(struct aob *aob, int error)
120{ 75{
121 struct aob_rq_header *aobrq = (void *) aob->request.data; 76 struct aob_rq_header *aobrq = (void *) aob->request.data;
diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
index f379c7f3034c..2700a5a09bd4 100644
--- a/drivers/scsi/scsi_transport_srp.c
+++ b/drivers/scsi/scsi_transport_srp.c
@@ -24,12 +24,15 @@
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/string.h> 26#include <linux/string.h>
27#include <linux/delay.h>
27 28
28#include <scsi/scsi.h> 29#include <scsi/scsi.h>
30#include <scsi/scsi_cmnd.h>
29#include <scsi/scsi_device.h> 31#include <scsi/scsi_device.h>
30#include <scsi/scsi_host.h> 32#include <scsi/scsi_host.h>
31#include <scsi/scsi_transport.h> 33#include <scsi/scsi_transport.h>
32#include <scsi/scsi_transport_srp.h> 34#include <scsi/scsi_transport_srp.h>
35#include "scsi_priv.h"
33#include "scsi_transport_srp_internal.h" 36#include "scsi_transport_srp_internal.h"
34 37
35struct srp_host_attrs { 38struct srp_host_attrs {
@@ -38,7 +41,7 @@ struct srp_host_attrs {
38#define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data) 41#define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39 42
40#define SRP_HOST_ATTRS 0 43#define SRP_HOST_ATTRS 0
41#define SRP_RPORT_ATTRS 3 44#define SRP_RPORT_ATTRS 8
42 45
43struct srp_internal { 46struct srp_internal {
44 struct scsi_transport_template t; 47 struct scsi_transport_template t;
@@ -54,6 +57,36 @@ struct srp_internal {
54 57
55#define dev_to_rport(d) container_of(d, struct srp_rport, dev) 58#define dev_to_rport(d) container_of(d, struct srp_rport, dev)
56#define transport_class_to_srp_rport(dev) dev_to_rport((dev)->parent) 59#define transport_class_to_srp_rport(dev) dev_to_rport((dev)->parent)
60static inline struct Scsi_Host *rport_to_shost(struct srp_rport *r)
61{
62 return dev_to_shost(r->dev.parent);
63}
64
65/**
66 * srp_tmo_valid() - check timeout combination validity
67 *
68 * The combination of the timeout parameters must be such that SCSI commands
69 * are finished in a reasonable time. Hence do not allow the fast I/O fail
70 * timeout to exceed SCSI_DEVICE_BLOCK_MAX_TIMEOUT. Furthermore, these
71 * parameters must be such that multipath can detect failed paths timely.
72 * Hence do not allow all three parameters to be disabled simultaneously.
73 */
74int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo, int dev_loss_tmo)
75{
76 if (reconnect_delay < 0 && fast_io_fail_tmo < 0 && dev_loss_tmo < 0)
77 return -EINVAL;
78 if (reconnect_delay == 0)
79 return -EINVAL;
80 if (fast_io_fail_tmo > SCSI_DEVICE_BLOCK_MAX_TIMEOUT)
81 return -EINVAL;
82 if (dev_loss_tmo >= LONG_MAX / HZ)
83 return -EINVAL;
84 if (fast_io_fail_tmo >= 0 && dev_loss_tmo >= 0 &&
85 fast_io_fail_tmo >= dev_loss_tmo)
86 return -EINVAL;
87 return 0;
88}
89EXPORT_SYMBOL_GPL(srp_tmo_valid);
57 90
58static int srp_host_setup(struct transport_container *tc, struct device *dev, 91static int srp_host_setup(struct transport_container *tc, struct device *dev,
59 struct device *cdev) 92 struct device *cdev)
@@ -134,10 +167,465 @@ static ssize_t store_srp_rport_delete(struct device *dev,
134 167
135static DEVICE_ATTR(delete, S_IWUSR, NULL, store_srp_rport_delete); 168static DEVICE_ATTR(delete, S_IWUSR, NULL, store_srp_rport_delete);
136 169
170static ssize_t show_srp_rport_state(struct device *dev,
171 struct device_attribute *attr,
172 char *buf)
173{
174 static const char *const state_name[] = {
175 [SRP_RPORT_RUNNING] = "running",
176 [SRP_RPORT_BLOCKED] = "blocked",
177 [SRP_RPORT_FAIL_FAST] = "fail-fast",
178 [SRP_RPORT_LOST] = "lost",
179 };
180 struct srp_rport *rport = transport_class_to_srp_rport(dev);
181 enum srp_rport_state state = rport->state;
182
183 return sprintf(buf, "%s\n",
184 (unsigned)state < ARRAY_SIZE(state_name) ?
185 state_name[state] : "???");
186}
187
188static DEVICE_ATTR(state, S_IRUGO, show_srp_rport_state, NULL);
189
190static ssize_t srp_show_tmo(char *buf, int tmo)
191{
192 return tmo >= 0 ? sprintf(buf, "%d\n", tmo) : sprintf(buf, "off\n");
193}
194
195static int srp_parse_tmo(int *tmo, const char *buf)
196{
197 int res = 0;
198
199 if (strncmp(buf, "off", 3) != 0)
200 res = kstrtoint(buf, 0, tmo);
201 else
202 *tmo = -1;
203
204 return res;
205}
206
207static ssize_t show_reconnect_delay(struct device *dev,
208 struct device_attribute *attr, char *buf)
209{
210 struct srp_rport *rport = transport_class_to_srp_rport(dev);
211
212 return srp_show_tmo(buf, rport->reconnect_delay);
213}
214
215static ssize_t store_reconnect_delay(struct device *dev,
216 struct device_attribute *attr,
217 const char *buf, const size_t count)
218{
219 struct srp_rport *rport = transport_class_to_srp_rport(dev);
220 int res, delay;
221
222 res = srp_parse_tmo(&delay, buf);
223 if (res)
224 goto out;
225 res = srp_tmo_valid(delay, rport->fast_io_fail_tmo,
226 rport->dev_loss_tmo);
227 if (res)
228 goto out;
229
230 if (rport->reconnect_delay <= 0 && delay > 0 &&
231 rport->state != SRP_RPORT_RUNNING) {
232 queue_delayed_work(system_long_wq, &rport->reconnect_work,
233 delay * HZ);
234 } else if (delay <= 0) {
235 cancel_delayed_work(&rport->reconnect_work);
236 }
237 rport->reconnect_delay = delay;
238 res = count;
239
240out:
241 return res;
242}
243
244static DEVICE_ATTR(reconnect_delay, S_IRUGO | S_IWUSR, show_reconnect_delay,
245 store_reconnect_delay);
246
247static ssize_t show_failed_reconnects(struct device *dev,
248 struct device_attribute *attr, char *buf)
249{
250 struct srp_rport *rport = transport_class_to_srp_rport(dev);
251
252 return sprintf(buf, "%d\n", rport->failed_reconnects);
253}
254
255static DEVICE_ATTR(failed_reconnects, S_IRUGO, show_failed_reconnects, NULL);
256
257static ssize_t show_srp_rport_fast_io_fail_tmo(struct device *dev,
258 struct device_attribute *attr,
259 char *buf)
260{
261 struct srp_rport *rport = transport_class_to_srp_rport(dev);
262
263 return srp_show_tmo(buf, rport->fast_io_fail_tmo);
264}
265
266static ssize_t store_srp_rport_fast_io_fail_tmo(struct device *dev,
267 struct device_attribute *attr,
268 const char *buf, size_t count)
269{
270 struct srp_rport *rport = transport_class_to_srp_rport(dev);
271 int res;
272 int fast_io_fail_tmo;
273
274 res = srp_parse_tmo(&fast_io_fail_tmo, buf);
275 if (res)
276 goto out;
277 res = srp_tmo_valid(rport->reconnect_delay, fast_io_fail_tmo,
278 rport->dev_loss_tmo);
279 if (res)
280 goto out;
281 rport->fast_io_fail_tmo = fast_io_fail_tmo;
282 res = count;
283
284out:
285 return res;
286}
287
288static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
289 show_srp_rport_fast_io_fail_tmo,
290 store_srp_rport_fast_io_fail_tmo);
291
292static ssize_t show_srp_rport_dev_loss_tmo(struct device *dev,
293 struct device_attribute *attr,
294 char *buf)
295{
296 struct srp_rport *rport = transport_class_to_srp_rport(dev);
297
298 return srp_show_tmo(buf, rport->dev_loss_tmo);
299}
300
301static ssize_t store_srp_rport_dev_loss_tmo(struct device *dev,
302 struct device_attribute *attr,
303 const char *buf, size_t count)
304{
305 struct srp_rport *rport = transport_class_to_srp_rport(dev);
306 int res;
307 int dev_loss_tmo;
308
309 res = srp_parse_tmo(&dev_loss_tmo, buf);
310 if (res)
311 goto out;
312 res = srp_tmo_valid(rport->reconnect_delay, rport->fast_io_fail_tmo,
313 dev_loss_tmo);
314 if (res)
315 goto out;
316 rport->dev_loss_tmo = dev_loss_tmo;
317 res = count;
318
319out:
320 return res;
321}
322
323static DEVICE_ATTR(dev_loss_tmo, S_IRUGO | S_IWUSR,
324 show_srp_rport_dev_loss_tmo,
325 store_srp_rport_dev_loss_tmo);
326
327static int srp_rport_set_state(struct srp_rport *rport,
328 enum srp_rport_state new_state)
329{
330 enum srp_rport_state old_state = rport->state;
331
332 lockdep_assert_held(&rport->mutex);
333
334 switch (new_state) {
335 case SRP_RPORT_RUNNING:
336 switch (old_state) {
337 case SRP_RPORT_LOST:
338 goto invalid;
339 default:
340 break;
341 }
342 break;
343 case SRP_RPORT_BLOCKED:
344 switch (old_state) {
345 case SRP_RPORT_RUNNING:
346 break;
347 default:
348 goto invalid;
349 }
350 break;
351 case SRP_RPORT_FAIL_FAST:
352 switch (old_state) {
353 case SRP_RPORT_LOST:
354 goto invalid;
355 default:
356 break;
357 }
358 break;
359 case SRP_RPORT_LOST:
360 break;
361 }
362 rport->state = new_state;
363 return 0;
364
365invalid:
366 return -EINVAL;
367}
368
369/**
370 * srp_reconnect_work() - reconnect and schedule a new attempt if necessary
371 */
372static void srp_reconnect_work(struct work_struct *work)
373{
374 struct srp_rport *rport = container_of(to_delayed_work(work),
375 struct srp_rport, reconnect_work);
376 struct Scsi_Host *shost = rport_to_shost(rport);
377 int delay, res;
378
379 res = srp_reconnect_rport(rport);
380 if (res != 0) {
381 shost_printk(KERN_ERR, shost,
382 "reconnect attempt %d failed (%d)\n",
383 ++rport->failed_reconnects, res);
384 delay = rport->reconnect_delay *
385 min(100, max(1, rport->failed_reconnects - 10));
386 if (delay > 0)
387 queue_delayed_work(system_long_wq,
388 &rport->reconnect_work, delay * HZ);
389 }
390}
391
392static void __rport_fail_io_fast(struct srp_rport *rport)
393{
394 struct Scsi_Host *shost = rport_to_shost(rport);
395 struct srp_internal *i;
396
397 lockdep_assert_held(&rport->mutex);
398
399 if (srp_rport_set_state(rport, SRP_RPORT_FAIL_FAST))
400 return;
401 scsi_target_unblock(rport->dev.parent, SDEV_TRANSPORT_OFFLINE);
402
403 /* Involve the LLD if possible to terminate all I/O on the rport. */
404 i = to_srp_internal(shost->transportt);
405 if (i->f->terminate_rport_io)
406 i->f->terminate_rport_io(rport);
407}
408
409/**
410 * rport_fast_io_fail_timedout() - fast I/O failure timeout handler
411 */
412static void rport_fast_io_fail_timedout(struct work_struct *work)
413{
414 struct srp_rport *rport = container_of(to_delayed_work(work),
415 struct srp_rport, fast_io_fail_work);
416 struct Scsi_Host *shost = rport_to_shost(rport);
417
418 pr_info("fast_io_fail_tmo expired for SRP %s / %s.\n",
419 dev_name(&rport->dev), dev_name(&shost->shost_gendev));
420
421 mutex_lock(&rport->mutex);
422 if (rport->state == SRP_RPORT_BLOCKED)
423 __rport_fail_io_fast(rport);
424 mutex_unlock(&rport->mutex);
425}
426
427/**
428 * rport_dev_loss_timedout() - device loss timeout handler
429 */
430static void rport_dev_loss_timedout(struct work_struct *work)
431{
432 struct srp_rport *rport = container_of(to_delayed_work(work),
433 struct srp_rport, dev_loss_work);
434 struct Scsi_Host *shost = rport_to_shost(rport);
435 struct srp_internal *i = to_srp_internal(shost->transportt);
436
437 pr_info("dev_loss_tmo expired for SRP %s / %s.\n",
438 dev_name(&rport->dev), dev_name(&shost->shost_gendev));
439
440 mutex_lock(&rport->mutex);
441 WARN_ON(srp_rport_set_state(rport, SRP_RPORT_LOST) != 0);
442 scsi_target_unblock(rport->dev.parent, SDEV_TRANSPORT_OFFLINE);
443 mutex_unlock(&rport->mutex);
444
445 i->f->rport_delete(rport);
446}
447
448static void __srp_start_tl_fail_timers(struct srp_rport *rport)
449{
450 struct Scsi_Host *shost = rport_to_shost(rport);
451 int delay, fast_io_fail_tmo, dev_loss_tmo;
452
453 lockdep_assert_held(&rport->mutex);
454
455 if (!rport->deleted) {
456 delay = rport->reconnect_delay;
457 fast_io_fail_tmo = rport->fast_io_fail_tmo;
458 dev_loss_tmo = rport->dev_loss_tmo;
459 pr_debug("%s current state: %d\n",
460 dev_name(&shost->shost_gendev), rport->state);
461
462 if (delay > 0)
463 queue_delayed_work(system_long_wq,
464 &rport->reconnect_work,
465 1UL * delay * HZ);
466 if (fast_io_fail_tmo >= 0 &&
467 srp_rport_set_state(rport, SRP_RPORT_BLOCKED) == 0) {
468 pr_debug("%s new state: %d\n",
469 dev_name(&shost->shost_gendev),
470 rport->state);
471 scsi_target_block(&shost->shost_gendev);
472 queue_delayed_work(system_long_wq,
473 &rport->fast_io_fail_work,
474 1UL * fast_io_fail_tmo * HZ);
475 }
476 if (dev_loss_tmo >= 0)
477 queue_delayed_work(system_long_wq,
478 &rport->dev_loss_work,
479 1UL * dev_loss_tmo * HZ);
480 } else {
481 pr_debug("%s has already been deleted\n",
482 dev_name(&shost->shost_gendev));
483 srp_rport_set_state(rport, SRP_RPORT_FAIL_FAST);
484 scsi_target_unblock(&shost->shost_gendev,
485 SDEV_TRANSPORT_OFFLINE);
486 }
487}
488
489/**
490 * srp_start_tl_fail_timers() - start the transport layer failure timers
491 *
492 * Start the transport layer fast I/O failure and device loss timers. Do not
493 * modify a timer that was already started.
494 */
495void srp_start_tl_fail_timers(struct srp_rport *rport)
496{
497 mutex_lock(&rport->mutex);
498 __srp_start_tl_fail_timers(rport);
499 mutex_unlock(&rport->mutex);
500}
501EXPORT_SYMBOL(srp_start_tl_fail_timers);
502
503/**
504 * scsi_request_fn_active() - number of kernel threads inside scsi_request_fn()
505 */
506static int scsi_request_fn_active(struct Scsi_Host *shost)
507{
508 struct scsi_device *sdev;
509 struct request_queue *q;
510 int request_fn_active = 0;
511
512 shost_for_each_device(sdev, shost) {
513 q = sdev->request_queue;
514
515 spin_lock_irq(q->queue_lock);
516 request_fn_active += q->request_fn_active;
517 spin_unlock_irq(q->queue_lock);
518 }
519
520 return request_fn_active;
521}
522
523/**
524 * srp_reconnect_rport() - reconnect to an SRP target port
525 *
526 * Blocks SCSI command queueing before invoking reconnect() such that
527 * queuecommand() won't be invoked concurrently with reconnect() from outside
528 * the SCSI EH. This is important since a reconnect() implementation may
529 * reallocate resources needed by queuecommand().
530 *
531 * Notes:
532 * - This function neither waits until outstanding requests have finished nor
533 * tries to abort these. It is the responsibility of the reconnect()
534 * function to finish outstanding commands before reconnecting to the target
535 * port.
536 * - It is the responsibility of the caller to ensure that the resources
537 * reallocated by the reconnect() function won't be used while this function
538 * is in progress. One possible strategy is to invoke this function from
539 * the context of the SCSI EH thread only. Another possible strategy is to
540 * lock the rport mutex inside each SCSI LLD callback that can be invoked by
541 * the SCSI EH (the scsi_host_template.eh_*() functions and also the
542 * scsi_host_template.queuecommand() function).
543 */
544int srp_reconnect_rport(struct srp_rport *rport)
545{
546 struct Scsi_Host *shost = rport_to_shost(rport);
547 struct srp_internal *i = to_srp_internal(shost->transportt);
548 struct scsi_device *sdev;
549 int res;
550
551 pr_debug("SCSI host %s\n", dev_name(&shost->shost_gendev));
552
553 res = mutex_lock_interruptible(&rport->mutex);
554 if (res)
555 goto out;
556 scsi_target_block(&shost->shost_gendev);
557 while (scsi_request_fn_active(shost))
558 msleep(20);
559 res = i->f->reconnect(rport);
560 pr_debug("%s (state %d): transport.reconnect() returned %d\n",
561 dev_name(&shost->shost_gendev), rport->state, res);
562 if (res == 0) {
563 cancel_delayed_work(&rport->fast_io_fail_work);
564 cancel_delayed_work(&rport->dev_loss_work);
565
566 rport->failed_reconnects = 0;
567 srp_rport_set_state(rport, SRP_RPORT_RUNNING);
568 scsi_target_unblock(&shost->shost_gendev, SDEV_RUNNING);
569 /*
570 * If the SCSI error handler has offlined one or more devices,
571 * invoking scsi_target_unblock() won't change the state of
572 * these devices into running so do that explicitly.
573 */
574 spin_lock_irq(shost->host_lock);
575 __shost_for_each_device(sdev, shost)
576 if (sdev->sdev_state == SDEV_OFFLINE)
577 sdev->sdev_state = SDEV_RUNNING;
578 spin_unlock_irq(shost->host_lock);
579 } else if (rport->state == SRP_RPORT_RUNNING) {
580 /*
581 * srp_reconnect_rport() was invoked with fast_io_fail
582 * off. Mark the port as failed and start the TL failure
583 * timers if these had not yet been started.
584 */
585 __rport_fail_io_fast(rport);
586 scsi_target_unblock(&shost->shost_gendev,
587 SDEV_TRANSPORT_OFFLINE);
588 __srp_start_tl_fail_timers(rport);
589 } else if (rport->state != SRP_RPORT_BLOCKED) {
590 scsi_target_unblock(&shost->shost_gendev,
591 SDEV_TRANSPORT_OFFLINE);
592 }
593 mutex_unlock(&rport->mutex);
594
595out:
596 return res;
597}
598EXPORT_SYMBOL(srp_reconnect_rport);
599
600/**
601 * srp_timed_out() - SRP transport intercept of the SCSI timeout EH
602 *
603 * If a timeout occurs while an rport is in the blocked state, ask the SCSI
604 * EH to continue waiting (BLK_EH_RESET_TIMER). Otherwise let the SCSI core
605 * handle the timeout (BLK_EH_NOT_HANDLED).
606 *
607 * Note: This function is called from soft-IRQ context and with the request
608 * queue lock held.
609 */
610static enum blk_eh_timer_return srp_timed_out(struct scsi_cmnd *scmd)
611{
612 struct scsi_device *sdev = scmd->device;
613 struct Scsi_Host *shost = sdev->host;
614 struct srp_internal *i = to_srp_internal(shost->transportt);
615
616 pr_debug("timeout for sdev %s\n", dev_name(&sdev->sdev_gendev));
617 return i->f->reset_timer_if_blocked && scsi_device_blocked(sdev) ?
618 BLK_EH_RESET_TIMER : BLK_EH_NOT_HANDLED;
619}
620
137static void srp_rport_release(struct device *dev) 621static void srp_rport_release(struct device *dev)
138{ 622{
139 struct srp_rport *rport = dev_to_rport(dev); 623 struct srp_rport *rport = dev_to_rport(dev);
140 624
625 cancel_delayed_work_sync(&rport->reconnect_work);
626 cancel_delayed_work_sync(&rport->fast_io_fail_work);
627 cancel_delayed_work_sync(&rport->dev_loss_work);
628
141 put_device(dev->parent); 629 put_device(dev->parent);
142 kfree(rport); 630 kfree(rport);
143} 631}
@@ -185,6 +673,24 @@ static int srp_host_match(struct attribute_container *cont, struct device *dev)
185} 673}
186 674
187/** 675/**
676 * srp_rport_get() - increment rport reference count
677 */
678void srp_rport_get(struct srp_rport *rport)
679{
680 get_device(&rport->dev);
681}
682EXPORT_SYMBOL(srp_rport_get);
683
684/**
685 * srp_rport_put() - decrement rport reference count
686 */
687void srp_rport_put(struct srp_rport *rport)
688{
689 put_device(&rport->dev);
690}
691EXPORT_SYMBOL(srp_rport_put);
692
693/**
188 * srp_rport_add - add a SRP remote port to the device hierarchy 694 * srp_rport_add - add a SRP remote port to the device hierarchy
189 * @shost: scsi host the remote port is connected to. 695 * @shost: scsi host the remote port is connected to.
190 * @ids: The port id for the remote port. 696 * @ids: The port id for the remote port.
@@ -196,12 +702,15 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
196{ 702{
197 struct srp_rport *rport; 703 struct srp_rport *rport;
198 struct device *parent = &shost->shost_gendev; 704 struct device *parent = &shost->shost_gendev;
705 struct srp_internal *i = to_srp_internal(shost->transportt);
199 int id, ret; 706 int id, ret;
200 707
201 rport = kzalloc(sizeof(*rport), GFP_KERNEL); 708 rport = kzalloc(sizeof(*rport), GFP_KERNEL);
202 if (!rport) 709 if (!rport)
203 return ERR_PTR(-ENOMEM); 710 return ERR_PTR(-ENOMEM);
204 711
712 mutex_init(&rport->mutex);
713
205 device_initialize(&rport->dev); 714 device_initialize(&rport->dev);
206 715
207 rport->dev.parent = get_device(parent); 716 rport->dev.parent = get_device(parent);
@@ -210,6 +719,17 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
210 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id)); 719 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
211 rport->roles = ids->roles; 720 rport->roles = ids->roles;
212 721
722 if (i->f->reconnect)
723 rport->reconnect_delay = i->f->reconnect_delay ?
724 *i->f->reconnect_delay : 10;
725 INIT_DELAYED_WORK(&rport->reconnect_work, srp_reconnect_work);
726 rport->fast_io_fail_tmo = i->f->fast_io_fail_tmo ?
727 *i->f->fast_io_fail_tmo : 15;
728 rport->dev_loss_tmo = i->f->dev_loss_tmo ? *i->f->dev_loss_tmo : 60;
729 INIT_DELAYED_WORK(&rport->fast_io_fail_work,
730 rport_fast_io_fail_timedout);
731 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
732
213 id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id); 733 id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
214 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id); 734 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
215 735
@@ -259,6 +779,13 @@ void srp_rport_del(struct srp_rport *rport)
259 transport_remove_device(dev); 779 transport_remove_device(dev);
260 device_del(dev); 780 device_del(dev);
261 transport_destroy_device(dev); 781 transport_destroy_device(dev);
782
783 mutex_lock(&rport->mutex);
784 if (rport->state == SRP_RPORT_BLOCKED)
785 __rport_fail_io_fast(rport);
786 rport->deleted = true;
787 mutex_unlock(&rport->mutex);
788
262 put_device(dev); 789 put_device(dev);
263} 790}
264EXPORT_SYMBOL_GPL(srp_rport_del); 791EXPORT_SYMBOL_GPL(srp_rport_del);
@@ -310,6 +837,8 @@ srp_attach_transport(struct srp_function_template *ft)
310 if (!i) 837 if (!i)
311 return NULL; 838 return NULL;
312 839
840 i->t.eh_timed_out = srp_timed_out;
841
313 i->t.tsk_mgmt_response = srp_tsk_mgmt_response; 842 i->t.tsk_mgmt_response = srp_tsk_mgmt_response;
314 i->t.it_nexus_response = srp_it_nexus_response; 843 i->t.it_nexus_response = srp_it_nexus_response;
315 844
@@ -327,6 +856,15 @@ srp_attach_transport(struct srp_function_template *ft)
327 count = 0; 856 count = 0;
328 i->rport_attrs[count++] = &dev_attr_port_id; 857 i->rport_attrs[count++] = &dev_attr_port_id;
329 i->rport_attrs[count++] = &dev_attr_roles; 858 i->rport_attrs[count++] = &dev_attr_roles;
859 if (ft->has_rport_state) {
860 i->rport_attrs[count++] = &dev_attr_state;
861 i->rport_attrs[count++] = &dev_attr_fast_io_fail_tmo;
862 i->rport_attrs[count++] = &dev_attr_dev_loss_tmo;
863 }
864 if (ft->reconnect) {
865 i->rport_attrs[count++] = &dev_attr_reconnect_delay;
866 i->rport_attrs[count++] = &dev_attr_failed_reconnects;
867 }
330 if (ft->rport_delete) 868 if (ft->rport_delete)
331 i->rport_attrs[count++] = &dev_attr_delete; 869 i->rport_attrs[count++] = &dev_attr_delete;
332 i->rport_attrs[count++] = NULL; 870 i->rport_attrs[count++] = NULL;
diff --git a/drivers/staging/media/lirc/TODO b/drivers/staging/media/lirc/TODO
index b6cb593f55c6..cbea5d84fed3 100644
--- a/drivers/staging/media/lirc/TODO
+++ b/drivers/staging/media/lirc/TODO
@@ -2,6 +2,11 @@
2 (see drivers/media/IR/mceusb.c vs. lirc_mceusb.c in lirc cvs for an 2 (see drivers/media/IR/mceusb.c vs. lirc_mceusb.c in lirc cvs for an
3 example of a previously completed port). 3 example of a previously completed port).
4 4
5- lirc_bt829 uses registers on a Mach64 VT, which has a separate kernel
6 framebuffer driver (atyfb) and userland X driver (mach64). It can't
7 simply be converted to a normal PCI driver, but ideally it should be
8 coordinated with the other drivers.
9
5Please send patches to: 10Please send patches to:
6Jarod Wilson <jarod@wilsonet.com> 11Jarod Wilson <jarod@wilsonet.com>
7Greg Kroah-Hartman <greg@kroah.com> 12Greg Kroah-Hartman <greg@kroah.com>
diff --git a/drivers/staging/media/lirc/lirc_bt829.c b/drivers/staging/media/lirc/lirc_bt829.c
index fbbdce4c119f..30edc740ac25 100644
--- a/drivers/staging/media/lirc/lirc_bt829.c
+++ b/drivers/staging/media/lirc/lirc_bt829.c
@@ -63,7 +63,7 @@ static bool debug;
63 } while (0) 63 } while (0)
64 64
65static int atir_minor; 65static int atir_minor;
66static unsigned long pci_addr_phys; 66static phys_addr_t pci_addr_phys;
67static unsigned char *pci_addr_lin; 67static unsigned char *pci_addr_lin;
68 68
69static struct lirc_driver atir_driver; 69static struct lirc_driver atir_driver;
@@ -78,11 +78,11 @@ static struct pci_dev *do_pci_probe(void)
78 pci_addr_phys = 0; 78 pci_addr_phys = 0;
79 if (my_dev->resource[0].flags & IORESOURCE_MEM) { 79 if (my_dev->resource[0].flags & IORESOURCE_MEM) {
80 pci_addr_phys = my_dev->resource[0].start; 80 pci_addr_phys = my_dev->resource[0].start;
81 pr_info("memory at 0x%08X\n", 81 pr_info("memory at %pa\n", &pci_addr_phys);
82 (unsigned int)pci_addr_phys);
83 } 82 }
84 if (pci_addr_phys == 0) { 83 if (pci_addr_phys == 0) {
85 pr_err("no memory resource ?\n"); 84 pr_err("no memory resource ?\n");
85 pci_dev_put(my_dev);
86 return NULL; 86 return NULL;
87 } 87 }
88 } else { 88 } else {
@@ -120,13 +120,20 @@ static void atir_set_use_dec(void *data)
120int init_module(void) 120int init_module(void)
121{ 121{
122 struct pci_dev *pdev; 122 struct pci_dev *pdev;
123 int rc;
123 124
124 pdev = do_pci_probe(); 125 pdev = do_pci_probe();
125 if (pdev == NULL) 126 if (pdev == NULL)
126 return -ENODEV; 127 return -ENODEV;
127 128
128 if (!atir_init_start()) 129 rc = pci_enable_device(pdev);
129 return -ENODEV; 130 if (rc)
131 goto err_put_dev;
132
133 if (!atir_init_start()) {
134 rc = -ENODEV;
135 goto err_disable;
136 }
130 137
131 strcpy(atir_driver.name, "ATIR"); 138 strcpy(atir_driver.name, "ATIR");
132 atir_driver.minor = -1; 139 atir_driver.minor = -1;
@@ -142,17 +149,31 @@ int init_module(void)
142 atir_minor = lirc_register_driver(&atir_driver); 149 atir_minor = lirc_register_driver(&atir_driver);
143 if (atir_minor < 0) { 150 if (atir_minor < 0) {
144 pr_err("failed to register driver!\n"); 151 pr_err("failed to register driver!\n");
145 return atir_minor; 152 rc = atir_minor;
153 goto err_unmap;
146 } 154 }
147 dprintk("driver is registered on minor %d\n", atir_minor); 155 dprintk("driver is registered on minor %d\n", atir_minor);
148 156
149 return 0; 157 return 0;
158
159err_unmap:
160 iounmap(pci_addr_lin);
161err_disable:
162 pci_disable_device(pdev);
163err_put_dev:
164 pci_dev_put(pdev);
165 return rc;
150} 166}
151 167
152 168
153void cleanup_module(void) 169void cleanup_module(void)
154{ 170{
171 struct pci_dev *pdev = to_pci_dev(atir_driver.dev);
172
155 lirc_unregister_driver(atir_minor); 173 lirc_unregister_driver(atir_minor);
174 iounmap(pci_addr_lin);
175 pci_disable_device(pdev);
176 pci_dev_put(pdev);
156} 177}
157 178
158 179
diff --git a/drivers/staging/media/lirc/lirc_serial.c b/drivers/staging/media/lirc/lirc_serial.c
index f6bc4c91ab35..2e3a98575d47 100644
--- a/drivers/staging/media/lirc/lirc_serial.c
+++ b/drivers/staging/media/lirc/lirc_serial.c
@@ -707,7 +707,8 @@ static irqreturn_t irq_handler(int i, void *blah)
707 pr_warn("ignoring spike: %d %d %lx %lx %lx %lx\n", 707 pr_warn("ignoring spike: %d %d %lx %lx %lx %lx\n",
708 dcd, sense, 708 dcd, sense,
709 tv.tv_sec, lasttv.tv_sec, 709 tv.tv_sec, lasttv.tv_sec,
710 tv.tv_usec, lasttv.tv_usec); 710 (unsigned long)tv.tv_usec,
711 (unsigned long)lasttv.tv_usec);
711 continue; 712 continue;
712 } 713 }
713 714
@@ -719,7 +720,8 @@ static irqreturn_t irq_handler(int i, void *blah)
719 pr_warn("%d %d %lx %lx %lx %lx\n", 720 pr_warn("%d %d %lx %lx %lx %lx\n",
720 dcd, sense, 721 dcd, sense,
721 tv.tv_sec, lasttv.tv_sec, 722 tv.tv_sec, lasttv.tv_sec,
722 tv.tv_usec, lasttv.tv_usec); 723 (unsigned long)tv.tv_usec,
724 (unsigned long)lasttv.tv_usec);
723 data = PULSE_MASK; 725 data = PULSE_MASK;
724 } else if (deltv > 15) { 726 } else if (deltv > 15) {
725 data = PULSE_MASK; /* really long time */ 727 data = PULSE_MASK; /* really long time */
@@ -728,7 +730,8 @@ static irqreturn_t irq_handler(int i, void *blah)
728 pr_warn("AIEEEE: %d %d %lx %lx %lx %lx\n", 730 pr_warn("AIEEEE: %d %d %lx %lx %lx %lx\n",
729 dcd, sense, 731 dcd, sense,
730 tv.tv_sec, lasttv.tv_sec, 732 tv.tv_sec, lasttv.tv_sec,
731 tv.tv_usec, lasttv.tv_usec); 733 (unsigned long)tv.tv_usec,
734 (unsigned long)lasttv.tv_usec);
732 /* 735 /*
733 * detecting pulse while this 736 * detecting pulse while this
734 * MUST be a space! 737 * MUST be a space!
diff --git a/drivers/staging/media/lirc/lirc_zilog.c b/drivers/staging/media/lirc/lirc_zilog.c
index 11d5338b4f2f..0feeaadf29dc 100644
--- a/drivers/staging/media/lirc/lirc_zilog.c
+++ b/drivers/staging/media/lirc/lirc_zilog.c
@@ -61,6 +61,9 @@
61#include <media/lirc_dev.h> 61#include <media/lirc_dev.h>
62#include <media/lirc.h> 62#include <media/lirc.h>
63 63
64/* Max transfer size done by I2C transfer functions */
65#define MAX_XFER_SIZE 64
66
64struct IR; 67struct IR;
65 68
66struct IR_rx { 69struct IR_rx {
@@ -941,7 +944,14 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos)
941 schedule(); 944 schedule();
942 set_current_state(TASK_INTERRUPTIBLE); 945 set_current_state(TASK_INTERRUPTIBLE);
943 } else { 946 } else {
944 unsigned char buf[rbuf->chunk_size]; 947 unsigned char buf[MAX_XFER_SIZE];
948
949 if (rbuf->chunk_size > sizeof(buf)) {
950 zilog_error("chunk_size is too big (%d)!\n",
951 rbuf->chunk_size);
952 ret = -EINVAL;
953 break;
954 }
945 m = lirc_buffer_read(rbuf, buf); 955 m = lirc_buffer_read(rbuf, buf);
946 if (m == rbuf->chunk_size) { 956 if (m == rbuf->chunk_size) {
947 ret = copy_to_user((void *)outbuf+written, buf, 957 ret = copy_to_user((void *)outbuf+written, buf,
diff --git a/drivers/staging/media/msi3101/Kconfig b/drivers/staging/media/msi3101/Kconfig
index 76d5bbd4d93c..0c349c8595e4 100644
--- a/drivers/staging/media/msi3101/Kconfig
+++ b/drivers/staging/media/msi3101/Kconfig
@@ -1,4 +1,5 @@
1config USB_MSI3101 1config USB_MSI3101
2 tristate "Mirics MSi3101 SDR Dongle" 2 tristate "Mirics MSi3101 SDR Dongle"
3 depends on USB && VIDEO_DEV && VIDEO_V4L2 3 depends on USB && VIDEO_DEV && VIDEO_V4L2
4 select VIDEOBUF2_VMALLOC 4 select VIDEOBUF2_CORE
5 select VIDEOBUF2_VMALLOC
diff --git a/drivers/staging/media/solo6x10/solo6x10-disp.c b/drivers/staging/media/solo6x10/solo6x10-disp.c
index 32d9953bc36e..145295a5db72 100644
--- a/drivers/staging/media/solo6x10/solo6x10-disp.c
+++ b/drivers/staging/media/solo6x10/solo6x10-disp.c
@@ -176,18 +176,27 @@ static void solo_vout_config(struct solo_dev *solo_dev)
176static int solo_dma_vin_region(struct solo_dev *solo_dev, u32 off, 176static int solo_dma_vin_region(struct solo_dev *solo_dev, u32 off,
177 u16 val, int reg_size) 177 u16 val, int reg_size)
178{ 178{
179 u16 buf[64]; 179 u16 *buf;
180 int i; 180 const int n = 64, size = n * sizeof(*buf);
181 int ret = 0; 181 int i, ret = 0;
182
183 buf = kmalloc(size, GFP_KERNEL);
184 if (!buf)
185 return -ENOMEM;
182 186
183 for (i = 0; i < sizeof(buf) >> 1; i++) 187 for (i = 0; i < n; i++)
184 buf[i] = cpu_to_le16(val); 188 buf[i] = cpu_to_le16(val);
185 189
186 for (i = 0; i < reg_size; i += sizeof(buf)) 190 for (i = 0; i < reg_size; i += size) {
187 ret |= solo_p2m_dma(solo_dev, 1, buf, 191 ret = solo_p2m_dma(solo_dev, 1, buf,
188 SOLO_MOTION_EXT_ADDR(solo_dev) + off + i, 192 SOLO_MOTION_EXT_ADDR(solo_dev) + off + i,
189 sizeof(buf), 0, 0); 193 size, 0, 0);
194
195 if (ret)
196 break;
197 }
190 198
199 kfree(buf);
191 return ret; 200 return ret;
192} 201}
193 202
diff --git a/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c b/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c
index a4c589604b02..d582c5b84c14 100644
--- a/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c
+++ b/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c
@@ -95,38 +95,11 @@ static unsigned char vop_6110_pal_cif[] = {
95 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00, 0x00, 95 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00, 0x00,
96}; 96};
97 97
98struct vop_header { 98typedef __le32 vop_header[16];
99 /* VE_STATUS0 */
100 u32 mpeg_size:20, sad_motion_flag:1, video_motion_flag:1, vop_type:2,
101 channel:5, source_fl:1, interlace:1, progressive:1;
102
103 /* VE_STATUS1 */
104 u32 vsize:8, hsize:8, last_queue:4, nop0:8, scale:4;
105
106 /* VE_STATUS2 */
107 u32 mpeg_off;
108
109 /* VE_STATUS3 */
110 u32 jpeg_off;
111
112 /* VE_STATUS4 */
113 u32 jpeg_size:20, interval:10, nop1:2;
114
115 /* VE_STATUS5/6 */
116 u32 sec, usec;
117
118 /* VE_STATUS7/8/9 */
119 u32 nop2[3];
120
121 /* VE_STATUS10 */
122 u32 mpeg_size_alt:20, nop3:12;
123
124 u32 end_nops[5];
125} __packed;
126 99
127struct solo_enc_buf { 100struct solo_enc_buf {
128 enum solo_enc_types type; 101 enum solo_enc_types type;
129 struct vop_header *vh; 102 const vop_header *vh;
130 int motion; 103 int motion;
131}; 104};
132 105
@@ -346,7 +319,7 @@ static int enc_get_mpeg_dma(struct solo_dev *solo_dev, dma_addr_t dma,
346/* Build a descriptor queue out of an SG list and send it to the P2M for 319/* Build a descriptor queue out of an SG list and send it to the P2M for
347 * processing. */ 320 * processing. */
348static int solo_send_desc(struct solo_enc_dev *solo_enc, int skip, 321static int solo_send_desc(struct solo_enc_dev *solo_enc, int skip,
349 struct vb2_dma_sg_desc *vbuf, int off, int size, 322 struct sg_table *vbuf, int off, int size,
350 unsigned int base, unsigned int base_size) 323 unsigned int base, unsigned int base_size)
351{ 324{
352 struct solo_dev *solo_dev = solo_enc->solo_dev; 325 struct solo_dev *solo_dev = solo_enc->solo_dev;
@@ -359,7 +332,7 @@ static int solo_send_desc(struct solo_enc_dev *solo_enc, int skip,
359 332
360 solo_enc->desc_count = 1; 333 solo_enc->desc_count = 1;
361 334
362 for_each_sg(vbuf->sglist, sg, vbuf->num_pages, i) { 335 for_each_sg(vbuf->sgl, sg, vbuf->nents, i) {
363 struct solo_p2m_desc *desc; 336 struct solo_p2m_desc *desc;
364 dma_addr_t dma; 337 dma_addr_t dma;
365 int len; 338 int len;
@@ -430,84 +403,145 @@ static int solo_send_desc(struct solo_enc_dev *solo_enc, int skip,
430 solo_enc->desc_count - 1); 403 solo_enc->desc_count - 1);
431} 404}
432 405
406/* Extract values from VOP header - VE_STATUSxx */
407static inline int vop_interlaced(const vop_header *vh)
408{
409 return (__le32_to_cpu((*vh)[0]) >> 30) & 1;
410}
411
412static inline u8 vop_channel(const vop_header *vh)
413{
414 return (__le32_to_cpu((*vh)[0]) >> 24) & 0x1F;
415}
416
417static inline u8 vop_type(const vop_header *vh)
418{
419 return (__le32_to_cpu((*vh)[0]) >> 22) & 3;
420}
421
422static inline u32 vop_mpeg_size(const vop_header *vh)
423{
424 return __le32_to_cpu((*vh)[0]) & 0xFFFFF;
425}
426
427static inline u8 vop_hsize(const vop_header *vh)
428{
429 return (__le32_to_cpu((*vh)[1]) >> 8) & 0xFF;
430}
431
432static inline u8 vop_vsize(const vop_header *vh)
433{
434 return __le32_to_cpu((*vh)[1]) & 0xFF;
435}
436
437static inline u32 vop_mpeg_offset(const vop_header *vh)
438{
439 return __le32_to_cpu((*vh)[2]);
440}
441
442static inline u32 vop_jpeg_offset(const vop_header *vh)
443{
444 return __le32_to_cpu((*vh)[3]);
445}
446
447static inline u32 vop_jpeg_size(const vop_header *vh)
448{
449 return __le32_to_cpu((*vh)[4]) & 0xFFFFF;
450}
451
452static inline u32 vop_sec(const vop_header *vh)
453{
454 return __le32_to_cpu((*vh)[5]);
455}
456
457static inline u32 vop_usec(const vop_header *vh)
458{
459 return __le32_to_cpu((*vh)[6]);
460}
461
433static int solo_fill_jpeg(struct solo_enc_dev *solo_enc, 462static int solo_fill_jpeg(struct solo_enc_dev *solo_enc,
434 struct vb2_buffer *vb, struct vop_header *vh) 463 struct vb2_buffer *vb, const vop_header *vh)
435{ 464{
436 struct solo_dev *solo_dev = solo_enc->solo_dev; 465 struct solo_dev *solo_dev = solo_enc->solo_dev;
437 struct vb2_dma_sg_desc *vbuf = vb2_dma_sg_plane_desc(vb, 0); 466 struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0);
438 int frame_size; 467 int frame_size;
439 int ret; 468 int ret;
440 469
441 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME; 470 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
442 471
443 if (vb2_plane_size(vb, 0) < vh->jpeg_size + solo_enc->jpeg_len) 472 if (vb2_plane_size(vb, 0) < vop_jpeg_size(vh) + solo_enc->jpeg_len)
444 return -EIO; 473 return -EIO;
445 474
446 sg_copy_from_buffer(vbuf->sglist, vbuf->num_pages, 475 frame_size = (vop_jpeg_size(vh) + solo_enc->jpeg_len + (DMA_ALIGN - 1))
447 solo_enc->jpeg_header,
448 solo_enc->jpeg_len);
449
450 frame_size = (vh->jpeg_size + solo_enc->jpeg_len + (DMA_ALIGN - 1))
451 & ~(DMA_ALIGN - 1); 476 & ~(DMA_ALIGN - 1);
452 vb2_set_plane_payload(vb, 0, vh->jpeg_size + solo_enc->jpeg_len); 477 vb2_set_plane_payload(vb, 0, vop_jpeg_size(vh) + solo_enc->jpeg_len);
453 478
454 dma_map_sg(&solo_dev->pdev->dev, vbuf->sglist, vbuf->num_pages, 479 /* may discard all previous data in vbuf->sgl */
480 dma_map_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents,
455 DMA_FROM_DEVICE); 481 DMA_FROM_DEVICE);
456 ret = solo_send_desc(solo_enc, solo_enc->jpeg_len, vbuf, vh->jpeg_off, 482 ret = solo_send_desc(solo_enc, solo_enc->jpeg_len, vbuf,
457 frame_size, SOLO_JPEG_EXT_ADDR(solo_dev), 483 vop_jpeg_offset(vh) - SOLO_JPEG_EXT_ADDR(solo_dev),
458 SOLO_JPEG_EXT_SIZE(solo_dev)); 484 frame_size, SOLO_JPEG_EXT_ADDR(solo_dev),
459 dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sglist, vbuf->num_pages, 485 SOLO_JPEG_EXT_SIZE(solo_dev));
486 dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents,
460 DMA_FROM_DEVICE); 487 DMA_FROM_DEVICE);
488
489 /* add the header only after dma_unmap_sg() */
490 sg_copy_from_buffer(vbuf->sgl, vbuf->nents,
491 solo_enc->jpeg_header, solo_enc->jpeg_len);
492
461 return ret; 493 return ret;
462} 494}
463 495
464static int solo_fill_mpeg(struct solo_enc_dev *solo_enc, 496static int solo_fill_mpeg(struct solo_enc_dev *solo_enc,
465 struct vb2_buffer *vb, struct vop_header *vh) 497 struct vb2_buffer *vb, const vop_header *vh)
466{ 498{
467 struct solo_dev *solo_dev = solo_enc->solo_dev; 499 struct solo_dev *solo_dev = solo_enc->solo_dev;
468 struct vb2_dma_sg_desc *vbuf = vb2_dma_sg_plane_desc(vb, 0); 500 struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0);
469 int frame_off, frame_size; 501 int frame_off, frame_size;
470 int skip = 0; 502 int skip = 0;
471 int ret; 503 int ret;
472 504
473 if (vb2_plane_size(vb, 0) < vh->mpeg_size) 505 if (vb2_plane_size(vb, 0) < vop_mpeg_size(vh))
474 return -EIO; 506 return -EIO;
475 507
476 /* If this is a key frame, add extra header */ 508 /* If this is a key frame, add extra header */
477 if (!vh->vop_type) { 509 vb->v4l2_buf.flags &= ~(V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_PFRAME | V4L2_BUF_FLAG_BFRAME);
478 sg_copy_from_buffer(vbuf->sglist, vbuf->num_pages, 510 if (!vop_type(vh)) {
479 solo_enc->vop,
480 solo_enc->vop_len);
481
482 skip = solo_enc->vop_len; 511 skip = solo_enc->vop_len;
483
484 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME; 512 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
485 vb2_set_plane_payload(vb, 0, vh->mpeg_size + solo_enc->vop_len); 513 vb2_set_plane_payload(vb, 0, vop_mpeg_size(vh) + solo_enc->vop_len);
486 } else { 514 } else {
487 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_PFRAME; 515 vb->v4l2_buf.flags |= V4L2_BUF_FLAG_PFRAME;
488 vb2_set_plane_payload(vb, 0, vh->mpeg_size); 516 vb2_set_plane_payload(vb, 0, vop_mpeg_size(vh));
489 } 517 }
490 518
491 /* Now get the actual mpeg payload */ 519 /* Now get the actual mpeg payload */
492 frame_off = (vh->mpeg_off + sizeof(*vh)) 520 frame_off = (vop_mpeg_offset(vh) - SOLO_MP4E_EXT_ADDR(solo_dev) + sizeof(*vh))
493 % SOLO_MP4E_EXT_SIZE(solo_dev); 521 % SOLO_MP4E_EXT_SIZE(solo_dev);
494 frame_size = (vh->mpeg_size + skip + (DMA_ALIGN - 1)) 522 frame_size = (vop_mpeg_size(vh) + skip + (DMA_ALIGN - 1))
495 & ~(DMA_ALIGN - 1); 523 & ~(DMA_ALIGN - 1);
496 524
497 dma_map_sg(&solo_dev->pdev->dev, vbuf->sglist, vbuf->num_pages, 525 /* may discard all previous data in vbuf->sgl */
526 dma_map_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents,
498 DMA_FROM_DEVICE); 527 DMA_FROM_DEVICE);
499 ret = solo_send_desc(solo_enc, skip, vbuf, frame_off, frame_size, 528 ret = solo_send_desc(solo_enc, skip, vbuf, frame_off, frame_size,
500 SOLO_MP4E_EXT_ADDR(solo_dev), 529 SOLO_MP4E_EXT_ADDR(solo_dev),
501 SOLO_MP4E_EXT_SIZE(solo_dev)); 530 SOLO_MP4E_EXT_SIZE(solo_dev));
502 dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sglist, vbuf->num_pages, 531 dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents,
503 DMA_FROM_DEVICE); 532 DMA_FROM_DEVICE);
533
534 /* add the header only after dma_unmap_sg() */
535 if (!vop_type(vh))
536 sg_copy_from_buffer(vbuf->sgl, vbuf->nents,
537 solo_enc->vop, solo_enc->vop_len);
504 return ret; 538 return ret;
505} 539}
506 540
507static int solo_enc_fillbuf(struct solo_enc_dev *solo_enc, 541static int solo_enc_fillbuf(struct solo_enc_dev *solo_enc,
508 struct vb2_buffer *vb, struct solo_enc_buf *enc_buf) 542 struct vb2_buffer *vb, struct solo_enc_buf *enc_buf)
509{ 543{
510 struct vop_header *vh = enc_buf->vh; 544 const vop_header *vh = enc_buf->vh;
511 int ret; 545 int ret;
512 546
513 /* Check for motion flags */ 547 /* Check for motion flags */
@@ -531,8 +565,8 @@ static int solo_enc_fillbuf(struct solo_enc_dev *solo_enc,
531 565
532 if (!ret) { 566 if (!ret) {
533 vb->v4l2_buf.sequence = solo_enc->sequence++; 567 vb->v4l2_buf.sequence = solo_enc->sequence++;
534 vb->v4l2_buf.timestamp.tv_sec = vh->sec; 568 vb->v4l2_buf.timestamp.tv_sec = vop_sec(vh);
535 vb->v4l2_buf.timestamp.tv_usec = vh->usec; 569 vb->v4l2_buf.timestamp.tv_usec = vop_usec(vh);
536 } 570 }
537 571
538 vb2_buffer_done(vb, ret ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE); 572 vb2_buffer_done(vb, ret ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
@@ -605,15 +639,13 @@ static void solo_handle_ring(struct solo_dev *solo_dev)
605 639
606 /* FAIL... */ 640 /* FAIL... */
607 if (enc_get_mpeg_dma(solo_dev, solo_dev->vh_dma, off, 641 if (enc_get_mpeg_dma(solo_dev, solo_dev->vh_dma, off,
608 sizeof(struct vop_header))) 642 sizeof(vop_header)))
609 continue; 643 continue;
610 644
611 enc_buf.vh = (struct vop_header *)solo_dev->vh_buf; 645 enc_buf.vh = solo_dev->vh_buf;
612 enc_buf.vh->mpeg_off -= SOLO_MP4E_EXT_ADDR(solo_dev);
613 enc_buf.vh->jpeg_off -= SOLO_JPEG_EXT_ADDR(solo_dev);
614 646
615 /* Sanity check */ 647 /* Sanity check */
616 if (enc_buf.vh->mpeg_off != off) 648 if (vop_mpeg_offset(enc_buf.vh) != SOLO_MP4E_EXT_ADDR(solo_dev) + off)
617 continue; 649 continue;
618 650
619 if (solo_motion_detected(solo_enc)) 651 if (solo_motion_detected(solo_enc))
@@ -1329,7 +1361,7 @@ int solo_enc_v4l2_init(struct solo_dev *solo_dev, unsigned nr)
1329 1361
1330 init_waitqueue_head(&solo_dev->ring_thread_wait); 1362 init_waitqueue_head(&solo_dev->ring_thread_wait);
1331 1363
1332 solo_dev->vh_size = sizeof(struct vop_header); 1364 solo_dev->vh_size = sizeof(vop_header);
1333 solo_dev->vh_buf = pci_alloc_consistent(solo_dev->pdev, 1365 solo_dev->vh_buf = pci_alloc_consistent(solo_dev->pdev,
1334 solo_dev->vh_size, 1366 solo_dev->vh_size,
1335 &solo_dev->vh_dma); 1367 &solo_dev->vh_dma);
diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
index 6f91d2e34b2a..f1bbb8cb74e6 100644
--- a/drivers/staging/media/solo6x10/solo6x10.h
+++ b/drivers/staging/media/solo6x10/solo6x10.h
@@ -94,7 +94,6 @@
94#define SOLO_ENC_MODE_HD1 1 94#define SOLO_ENC_MODE_HD1 1
95#define SOLO_ENC_MODE_D1 9 95#define SOLO_ENC_MODE_D1 9
96 96
97#define SOLO_DEFAULT_GOP 30
98#define SOLO_DEFAULT_QP 3 97#define SOLO_DEFAULT_QP 3
99 98
100#ifndef V4L2_BUF_FLAG_MOTION_ON 99#ifndef V4L2_BUF_FLAG_MOTION_ON
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 6df632e0bb55..5be6e919f785 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -392,6 +392,25 @@ config RETU_WATCHDOG
392 To compile this driver as a module, choose M here: the 392 To compile this driver as a module, choose M here: the
393 module will be called retu_wdt. 393 module will be called retu_wdt.
394 394
395config MOXART_WDT
396 tristate "MOXART watchdog"
397 depends on ARCH_MOXART
398 help
399 Say Y here to include Watchdog timer support for the watchdog
400 existing on the MOXA ART SoC series platforms.
401
402 To compile this driver as a module, choose M here: the
403 module will be called moxart_wdt.
404
405config SIRFSOC_WATCHDOG
406 tristate "SiRFSOC watchdog"
407 depends on ARCH_SIRF
408 select WATCHDOG_CORE
409 default y
410 help
411 Support for CSR SiRFprimaII and SiRFatlasVI watchdog. When
412 the watchdog triggers the system will be reset.
413
395# AVR32 Architecture 414# AVR32 Architecture
396 415
397config AT32AP700X_WDT 416config AT32AP700X_WDT
@@ -866,6 +885,7 @@ config VIA_WDT
866config W83627HF_WDT 885config W83627HF_WDT
867 tristate "W83627HF/W83627DHG Watchdog Timer" 886 tristate "W83627HF/W83627DHG Watchdog Timer"
868 depends on X86 887 depends on X86
888 select WATCHDOG_CORE
869 ---help--- 889 ---help---
870 This is the driver for the hardware watchdog on the W83627HF chipset 890 This is the driver for the hardware watchdog on the W83627HF chipset
871 as used in Advantech PC-9578 and Tyan S2721-533 motherboards 891 as used in Advantech PC-9578 and Tyan S2721-533 motherboards
@@ -1125,6 +1145,13 @@ config LANTIQ_WDT
1125 help 1145 help
1126 Hardware driver for the Lantiq SoC Watchdog Timer. 1146 Hardware driver for the Lantiq SoC Watchdog Timer.
1127 1147
1148config RALINK_WDT
1149 tristate "Ralink SoC watchdog"
1150 select WATCHDOG_CORE
1151 depends on RALINK
1152 help
1153 Hardware driver for the Ralink SoC Watchdog Timer.
1154
1128# PARISC Architecture 1155# PARISC Architecture
1129 1156
1130# POWERPC Architecture 1157# POWERPC Architecture
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 8c7b8bcbbdc5..91bd95a64baf 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -55,6 +55,8 @@ obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
55obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o 55obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
56obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o 56obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
57obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o 57obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
58obj-$(CONFIG_MOXART_WDT) += moxart_wdt.o
59obj-$(CONFIG_SIRFSOC_WATCHDOG) += sirfsoc_wdt.o
58 60
59# AVR32 Architecture 61# AVR32 Architecture
60obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o 62obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
@@ -134,6 +136,7 @@ obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
134obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o 136obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
135octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o 137octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o
136obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o 138obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o
139obj-$(CONFIG_RALINK_WDT) += rt2880_wdt.o
137 140
138# PARISC Architecture 141# PARISC Architecture
139 142
diff --git a/drivers/watchdog/acquirewdt.c b/drivers/watchdog/acquirewdt.c
index 24a517777fa0..5cf1621def9c 100644
--- a/drivers/watchdog/acquirewdt.c
+++ b/drivers/watchdog/acquirewdt.c
@@ -60,8 +60,7 @@
60#include <linux/types.h> /* For standard types (like size_t) */ 60#include <linux/types.h> /* For standard types (like size_t) */
61#include <linux/errno.h> /* For the -ENODEV/... values */ 61#include <linux/errno.h> /* For the -ENODEV/... values */
62#include <linux/kernel.h> /* For printk/panic/... */ 62#include <linux/kernel.h> /* For printk/panic/... */
63#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV 63#include <linux/miscdevice.h> /* For struct miscdevice */
64 (WATCHDOG_MINOR) */
65#include <linux/watchdog.h> /* For the watchdog specific items */ 64#include <linux/watchdog.h> /* For the watchdog specific items */
66#include <linux/fs.h> /* For file operations */ 65#include <linux/fs.h> /* For file operations */
67#include <linux/ioport.h> /* For io-port access */ 66#include <linux/ioport.h> /* For io-port access */
@@ -337,4 +336,3 @@ module_exit(acq_exit);
337MODULE_AUTHOR("David Woodhouse"); 336MODULE_AUTHOR("David Woodhouse");
338MODULE_DESCRIPTION("Acquire Inc. Single Board Computer Watchdog Timer driver"); 337MODULE_DESCRIPTION("Acquire Inc. Single Board Computer Watchdog Timer driver");
339MODULE_LICENSE("GPL"); 338MODULE_LICENSE("GPL");
340MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/advantechwdt.c b/drivers/watchdog/advantechwdt.c
index cc6702fc5268..a8961addc59c 100644
--- a/drivers/watchdog/advantechwdt.c
+++ b/drivers/watchdog/advantechwdt.c
@@ -345,4 +345,3 @@ module_exit(advwdt_exit);
345MODULE_LICENSE("GPL"); 345MODULE_LICENSE("GPL");
346MODULE_AUTHOR("Marek Michalkiewicz <marekm@linux.org.pl>"); 346MODULE_AUTHOR("Marek Michalkiewicz <marekm@linux.org.pl>");
347MODULE_DESCRIPTION("Advantech Single Board Computer WDT driver"); 347MODULE_DESCRIPTION("Advantech Single Board Computer WDT driver");
348MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/alim1535_wdt.c b/drivers/watchdog/alim1535_wdt.c
index 41b84936a521..fbb7b94cabfd 100644
--- a/drivers/watchdog/alim1535_wdt.c
+++ b/drivers/watchdog/alim1535_wdt.c
@@ -452,4 +452,3 @@ module_exit(watchdog_exit);
452MODULE_AUTHOR("Alan Cox"); 452MODULE_AUTHOR("Alan Cox");
453MODULE_DESCRIPTION("ALi M1535 PMU Watchdog Timer driver"); 453MODULE_DESCRIPTION("ALi M1535 PMU Watchdog Timer driver");
454MODULE_LICENSE("GPL"); 454MODULE_LICENSE("GPL");
455MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/alim7101_wdt.c b/drivers/watchdog/alim7101_wdt.c
index 5eee55012e33..12f0b762b528 100644
--- a/drivers/watchdog/alim7101_wdt.c
+++ b/drivers/watchdog/alim7101_wdt.c
@@ -425,4 +425,3 @@ MODULE_DEVICE_TABLE(pci, alim7101_pci_tbl);
425MODULE_AUTHOR("Steve Hill"); 425MODULE_AUTHOR("Steve Hill");
426MODULE_DESCRIPTION("ALi M7101 PMU Computer Watchdog Timer driver"); 426MODULE_DESCRIPTION("ALi M7101 PMU Computer Watchdog Timer driver");
427MODULE_LICENSE("GPL"); 427MODULE_LICENSE("GPL");
428MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/ar7_wdt.c b/drivers/watchdog/ar7_wdt.c
index b3709f9cf5be..3a996576343a 100644
--- a/drivers/watchdog/ar7_wdt.c
+++ b/drivers/watchdog/ar7_wdt.c
@@ -46,7 +46,6 @@
46MODULE_AUTHOR("Nicolas Thill <nico@openwrt.org>"); 46MODULE_AUTHOR("Nicolas Thill <nico@openwrt.org>");
47MODULE_DESCRIPTION(LONGNAME); 47MODULE_DESCRIPTION(LONGNAME);
48MODULE_LICENSE("GPL"); 48MODULE_LICENSE("GPL");
49MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
50 49
51static int margin = 60; 50static int margin = 60;
52module_param(margin, int, 0); 51module_param(margin, int, 0);
diff --git a/drivers/watchdog/at32ap700x_wdt.c b/drivers/watchdog/at32ap700x_wdt.c
index b178e717ef09..afe7d17e6776 100644
--- a/drivers/watchdog/at32ap700x_wdt.c
+++ b/drivers/watchdog/at32ap700x_wdt.c
@@ -434,4 +434,3 @@ module_platform_driver_probe(at32_wdt_driver, at32_wdt_probe);
434MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>"); 434MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>");
435MODULE_DESCRIPTION("Watchdog driver for Atmel AT32AP700X"); 435MODULE_DESCRIPTION("Watchdog driver for Atmel AT32AP700X");
436MODULE_LICENSE("GPL"); 436MODULE_LICENSE("GPL");
437MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/at91rm9200_wdt.c b/drivers/watchdog/at91rm9200_wdt.c
index 1c75260b987c..dee6cc21d270 100644
--- a/drivers/watchdog/at91rm9200_wdt.c
+++ b/drivers/watchdog/at91rm9200_wdt.c
@@ -269,7 +269,7 @@ static struct platform_driver at91wdt_driver = {
269 .driver = { 269 .driver = {
270 .name = "at91_wdt", 270 .name = "at91_wdt",
271 .owner = THIS_MODULE, 271 .owner = THIS_MODULE,
272 .of_match_table = of_match_ptr(at91_wdt_dt_ids), 272 .of_match_table = at91_wdt_dt_ids,
273 }, 273 },
274}; 274};
275 275
@@ -297,5 +297,4 @@ module_exit(at91_wdt_exit);
297MODULE_AUTHOR("Andrew Victor"); 297MODULE_AUTHOR("Andrew Victor");
298MODULE_DESCRIPTION("Watchdog driver for Atmel AT91RM9200"); 298MODULE_DESCRIPTION("Watchdog driver for Atmel AT91RM9200");
299MODULE_LICENSE("GPL"); 299MODULE_LICENSE("GPL");
300MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
301MODULE_ALIAS("platform:at91_wdt"); 300MODULE_ALIAS("platform:at91_wdt");
diff --git a/drivers/watchdog/ath79_wdt.c b/drivers/watchdog/ath79_wdt.c
index 37cb09b27b63..9fa1f69dac13 100644
--- a/drivers/watchdog/ath79_wdt.c
+++ b/drivers/watchdog/ath79_wdt.c
@@ -329,4 +329,3 @@ MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org");
329MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org"); 329MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org");
330MODULE_LICENSE("GPL v2"); 330MODULE_LICENSE("GPL v2");
331MODULE_ALIAS("platform:" DRIVER_NAME); 331MODULE_ALIAS("platform:" DRIVER_NAME);
332MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/bcm2835_wdt.c b/drivers/watchdog/bcm2835_wdt.c
index 61566fc47f84..a6a2cebb2587 100644
--- a/drivers/watchdog/bcm2835_wdt.c
+++ b/drivers/watchdog/bcm2835_wdt.c
@@ -186,4 +186,3 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
186MODULE_AUTHOR("Lubomir Rintel <lkundrak@v3.sk>"); 186MODULE_AUTHOR("Lubomir Rintel <lkundrak@v3.sk>");
187MODULE_DESCRIPTION("Driver for Broadcom BCM2835 watchdog timer"); 187MODULE_DESCRIPTION("Driver for Broadcom BCM2835 watchdog timer");
188MODULE_LICENSE("GPL"); 188MODULE_LICENSE("GPL");
189MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/bcm63xx_wdt.c b/drivers/watchdog/bcm63xx_wdt.c
index a14a58d9d110..4eb188b87f8e 100644
--- a/drivers/watchdog/bcm63xx_wdt.c
+++ b/drivers/watchdog/bcm63xx_wdt.c
@@ -317,5 +317,4 @@ MODULE_AUTHOR("Miguel Gaio <miguel.gaio@efixo.com>");
317MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>"); 317MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
318MODULE_DESCRIPTION("Driver for the Broadcom BCM63xx SoC watchdog"); 318MODULE_DESCRIPTION("Driver for the Broadcom BCM63xx SoC watchdog");
319MODULE_LICENSE("GPL"); 319MODULE_LICENSE("GPL");
320MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
321MODULE_ALIAS("platform:bcm63xx-wdt"); 320MODULE_ALIAS("platform:bcm63xx-wdt");
diff --git a/drivers/watchdog/bfin_wdt.c b/drivers/watchdog/bfin_wdt.c
index 5d36d6fb4969..a3b6a5b30f9f 100644
--- a/drivers/watchdog/bfin_wdt.c
+++ b/drivers/watchdog/bfin_wdt.c
@@ -465,7 +465,6 @@ module_exit(bfin_wdt_exit);
465MODULE_AUTHOR("Michele d'Amico, Mike Frysinger <vapier@gentoo.org>"); 465MODULE_AUTHOR("Michele d'Amico, Mike Frysinger <vapier@gentoo.org>");
466MODULE_DESCRIPTION("Blackfin Watchdog Device Driver"); 466MODULE_DESCRIPTION("Blackfin Watchdog Device Driver");
467MODULE_LICENSE("GPL"); 467MODULE_LICENSE("GPL");
468MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
469 468
470module_param(timeout, uint, 0); 469module_param(timeout, uint, 0);
471MODULE_PARM_DESC(timeout, 470MODULE_PARM_DESC(timeout,
diff --git a/drivers/watchdog/cpu5wdt.c b/drivers/watchdog/cpu5wdt.c
index f270bb7bc456..f7ae49edb518 100644
--- a/drivers/watchdog/cpu5wdt.c
+++ b/drivers/watchdog/cpu5wdt.c
@@ -289,7 +289,6 @@ MODULE_AUTHOR("Heiko Ronsdorf <hero@ihg.uni-duisburg.de>");
289MODULE_DESCRIPTION("sma cpu5 watchdog driver"); 289MODULE_DESCRIPTION("sma cpu5 watchdog driver");
290MODULE_SUPPORTED_DEVICE("sma cpu5 watchdog"); 290MODULE_SUPPORTED_DEVICE("sma cpu5 watchdog");
291MODULE_LICENSE("GPL"); 291MODULE_LICENSE("GPL");
292MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
293 292
294module_param(port, int, 0); 293module_param(port, int, 0);
295MODULE_PARM_DESC(port, "base address of watchdog card, default is 0x91"); 294MODULE_PARM_DESC(port, "base address of watchdog card, default is 0x91");
diff --git a/drivers/watchdog/davinci_wdt.c b/drivers/watchdog/davinci_wdt.c
index bead7740c86a..dd625cca1ae5 100644
--- a/drivers/watchdog/davinci_wdt.c
+++ b/drivers/watchdog/davinci_wdt.c
@@ -267,5 +267,4 @@ MODULE_PARM_DESC(heartbeat,
267 __MODULE_STRING(DEFAULT_HEARTBEAT)); 267 __MODULE_STRING(DEFAULT_HEARTBEAT));
268 268
269MODULE_LICENSE("GPL"); 269MODULE_LICENSE("GPL");
270MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
271MODULE_ALIAS("platform:watchdog"); 270MODULE_ALIAS("platform:watchdog");
diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index e621098bf663..a46f5c7ee7ff 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -29,6 +29,7 @@
29#include <linux/miscdevice.h> 29#include <linux/miscdevice.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/moduleparam.h> 31#include <linux/moduleparam.h>
32#include <linux/of.h>
32#include <linux/pm.h> 33#include <linux/pm.h>
33#include <linux/platform_device.h> 34#include <linux/platform_device.h>
34#include <linux/spinlock.h> 35#include <linux/spinlock.h>
@@ -203,12 +204,12 @@ static long dw_wdt_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
203 204
204 switch (cmd) { 205 switch (cmd) {
205 case WDIOC_GETSUPPORT: 206 case WDIOC_GETSUPPORT:
206 return copy_to_user((struct watchdog_info *)arg, &dw_wdt_ident, 207 return copy_to_user((void __user *)arg, &dw_wdt_ident,
207 sizeof(dw_wdt_ident)) ? -EFAULT : 0; 208 sizeof(dw_wdt_ident)) ? -EFAULT : 0;
208 209
209 case WDIOC_GETSTATUS: 210 case WDIOC_GETSTATUS:
210 case WDIOC_GETBOOTSTATUS: 211 case WDIOC_GETBOOTSTATUS:
211 return put_user(0, (int *)arg); 212 return put_user(0, (int __user *)arg);
212 213
213 case WDIOC_KEEPALIVE: 214 case WDIOC_KEEPALIVE:
214 dw_wdt_set_next_heartbeat(); 215 dw_wdt_set_next_heartbeat();
@@ -252,17 +253,17 @@ static int dw_wdt_release(struct inode *inode, struct file *filp)
252 return 0; 253 return 0;
253} 254}
254 255
255#ifdef CONFIG_PM 256#ifdef CONFIG_PM_SLEEP
256static int dw_wdt_suspend(struct device *dev) 257static int dw_wdt_suspend(struct device *dev)
257{ 258{
258 clk_disable(dw_wdt.clk); 259 clk_disable_unprepare(dw_wdt.clk);
259 260
260 return 0; 261 return 0;
261} 262}
262 263
263static int dw_wdt_resume(struct device *dev) 264static int dw_wdt_resume(struct device *dev)
264{ 265{
265 int err = clk_enable(dw_wdt.clk); 266 int err = clk_prepare_enable(dw_wdt.clk);
266 267
267 if (err) 268 if (err)
268 return err; 269 return err;
@@ -271,12 +272,9 @@ static int dw_wdt_resume(struct device *dev)
271 272
272 return 0; 273 return 0;
273} 274}
275#endif /* CONFIG_PM_SLEEP */
274 276
275static const struct dev_pm_ops dw_wdt_pm_ops = { 277static SIMPLE_DEV_PM_OPS(dw_wdt_pm_ops, dw_wdt_suspend, dw_wdt_resume);
276 .suspend = dw_wdt_suspend,
277 .resume = dw_wdt_resume,
278};
279#endif /* CONFIG_PM */
280 278
281static const struct file_operations wdt_fops = { 279static const struct file_operations wdt_fops = {
282 .owner = THIS_MODULE, 280 .owner = THIS_MODULE,
@@ -309,7 +307,7 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
309 if (IS_ERR(dw_wdt.clk)) 307 if (IS_ERR(dw_wdt.clk))
310 return PTR_ERR(dw_wdt.clk); 308 return PTR_ERR(dw_wdt.clk);
311 309
312 ret = clk_enable(dw_wdt.clk); 310 ret = clk_prepare_enable(dw_wdt.clk);
313 if (ret) 311 if (ret)
314 return ret; 312 return ret;
315 313
@@ -326,7 +324,7 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
326 return 0; 324 return 0;
327 325
328out_disable_clk: 326out_disable_clk:
329 clk_disable(dw_wdt.clk); 327 clk_disable_unprepare(dw_wdt.clk);
330 328
331 return ret; 329 return ret;
332} 330}
@@ -335,20 +333,27 @@ static int dw_wdt_drv_remove(struct platform_device *pdev)
335{ 333{
336 misc_deregister(&dw_wdt_miscdev); 334 misc_deregister(&dw_wdt_miscdev);
337 335
338 clk_disable(dw_wdt.clk); 336 clk_disable_unprepare(dw_wdt.clk);
339 337
340 return 0; 338 return 0;
341} 339}
342 340
341#ifdef CONFIG_OF
342static const struct of_device_id dw_wdt_of_match[] = {
343 { .compatible = "snps,dw-wdt", },
344 { /* sentinel */ }
345};
346MODULE_DEVICE_TABLE(of, dw_wdt_of_match);
347#endif
348
343static struct platform_driver dw_wdt_driver = { 349static struct platform_driver dw_wdt_driver = {
344 .probe = dw_wdt_drv_probe, 350 .probe = dw_wdt_drv_probe,
345 .remove = dw_wdt_drv_remove, 351 .remove = dw_wdt_drv_remove,
346 .driver = { 352 .driver = {
347 .name = "dw_wdt", 353 .name = "dw_wdt",
348 .owner = THIS_MODULE, 354 .owner = THIS_MODULE,
349#ifdef CONFIG_PM 355 .of_match_table = of_match_ptr(dw_wdt_of_match),
350 .pm = &dw_wdt_pm_ops, 356 .pm = &dw_wdt_pm_ops,
351#endif /* CONFIG_PM */
352 }, 357 },
353}; 358};
354 359
@@ -357,4 +362,3 @@ module_platform_driver(dw_wdt_driver);
357MODULE_AUTHOR("Jamie Iles"); 362MODULE_AUTHOR("Jamie Iles");
358MODULE_DESCRIPTION("Synopsys DesignWare Watchdog Driver"); 363MODULE_DESCRIPTION("Synopsys DesignWare Watchdog Driver");
359MODULE_LICENSE("GPL"); 364MODULE_LICENSE("GPL");
360MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/ep93xx_wdt.c b/drivers/watchdog/ep93xx_wdt.c
index e0574844c313..833e81311848 100644
--- a/drivers/watchdog/ep93xx_wdt.c
+++ b/drivers/watchdog/ep93xx_wdt.c
@@ -179,4 +179,3 @@ MODULE_AUTHOR("Ray Lehtiniemi <rayl@mail.com>,"
179MODULE_DESCRIPTION("EP93xx Watchdog"); 179MODULE_DESCRIPTION("EP93xx Watchdog");
180MODULE_LICENSE("GPL"); 180MODULE_LICENSE("GPL");
181MODULE_VERSION(WDT_VERSION); 181MODULE_VERSION(WDT_VERSION);
182MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/eurotechwdt.c b/drivers/watchdog/eurotechwdt.c
index cd31b8a2a729..23ee53240c4c 100644
--- a/drivers/watchdog/eurotechwdt.c
+++ b/drivers/watchdog/eurotechwdt.c
@@ -477,4 +477,3 @@ module_exit(eurwdt_exit);
477MODULE_AUTHOR("Rodolfo Giometti"); 477MODULE_AUTHOR("Rodolfo Giometti");
478MODULE_DESCRIPTION("Driver for Eurotech CPU-1220/1410 on board watchdog"); 478MODULE_DESCRIPTION("Driver for Eurotech CPU-1220/1410 on board watchdog");
479MODULE_LICENSE("GPL"); 479MODULE_LICENSE("GPL");
480MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/gef_wdt.c b/drivers/watchdog/gef_wdt.c
index 3755833430dc..25beb30878d7 100644
--- a/drivers/watchdog/gef_wdt.c
+++ b/drivers/watchdog/gef_wdt.c
@@ -331,5 +331,4 @@ module_exit(gef_wdt_exit);
331MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com>"); 331MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com>");
332MODULE_DESCRIPTION("GE watchdog driver"); 332MODULE_DESCRIPTION("GE watchdog driver");
333MODULE_LICENSE("GPL"); 333MODULE_LICENSE("GPL");
334MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
335MODULE_ALIAS("platform:gef_wdt"); 334MODULE_ALIAS("platform:gef_wdt");
diff --git a/drivers/watchdog/geodewdt.c b/drivers/watchdog/geodewdt.c
index fcd599d4e225..4a6ae84b42bc 100644
--- a/drivers/watchdog/geodewdt.c
+++ b/drivers/watchdog/geodewdt.c
@@ -297,4 +297,3 @@ module_exit(geodewdt_exit);
297MODULE_AUTHOR("Advanced Micro Devices, Inc"); 297MODULE_AUTHOR("Advanced Micro Devices, Inc");
298MODULE_DESCRIPTION("Geode GX/LX Watchdog Driver"); 298MODULE_DESCRIPTION("Geode GX/LX Watchdog Driver");
299MODULE_LICENSE("GPL"); 299MODULE_LICENSE("GPL");
300MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/hpwdt.c b/drivers/watchdog/hpwdt.c
index 19f3c3fc65f4..45b979d9dd13 100644
--- a/drivers/watchdog/hpwdt.c
+++ b/drivers/watchdog/hpwdt.c
@@ -881,7 +881,6 @@ MODULE_AUTHOR("Tom Mingarelli");
881MODULE_DESCRIPTION("hp watchdog driver"); 881MODULE_DESCRIPTION("hp watchdog driver");
882MODULE_LICENSE("GPL"); 882MODULE_LICENSE("GPL");
883MODULE_VERSION(HPWDT_VERSION); 883MODULE_VERSION(HPWDT_VERSION);
884MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
885 884
886module_param(soft_margin, int, 0); 885module_param(soft_margin, int, 0);
887MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds"); 886MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds");
diff --git a/drivers/watchdog/i6300esb.c b/drivers/watchdog/i6300esb.c
index 2b2ea13d03ea..a72fe9361ddf 100644
--- a/drivers/watchdog/i6300esb.c
+++ b/drivers/watchdog/i6300esb.c
@@ -497,4 +497,3 @@ module_pci_driver(esb_driver);
497MODULE_AUTHOR("Ross Biro and David Härdeman"); 497MODULE_AUTHOR("Ross Biro and David Härdeman");
498MODULE_DESCRIPTION("Watchdog driver for Intel 6300ESB chipsets"); 498MODULE_DESCRIPTION("Watchdog driver for Intel 6300ESB chipsets");
499MODULE_LICENSE("GPL"); 499MODULE_LICENSE("GPL");
500MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/iTCO_wdt.c b/drivers/watchdog/iTCO_wdt.c
index 6130321da387..04f8af65acfd 100644
--- a/drivers/watchdog/iTCO_wdt.c
+++ b/drivers/watchdog/iTCO_wdt.c
@@ -56,8 +56,6 @@
56#include <linux/types.h> /* For standard types (like size_t) */ 56#include <linux/types.h> /* For standard types (like size_t) */
57#include <linux/errno.h> /* For the -ENODEV/... values */ 57#include <linux/errno.h> /* For the -ENODEV/... values */
58#include <linux/kernel.h> /* For printk/panic/... */ 58#include <linux/kernel.h> /* For printk/panic/... */
59#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV
60 (WATCHDOG_MINOR) */
61#include <linux/watchdog.h> /* For the watchdog specific items */ 59#include <linux/watchdog.h> /* For the watchdog specific items */
62#include <linux/init.h> /* For __init/__exit/... */ 60#include <linux/init.h> /* For __init/__exit/... */
63#include <linux/fs.h> /* For file operations */ 61#include <linux/fs.h> /* For file operations */
@@ -394,7 +392,7 @@ static int iTCO_wdt_probe(struct platform_device *dev)
394{ 392{
395 int ret = -ENODEV; 393 int ret = -ENODEV;
396 unsigned long val32; 394 unsigned long val32;
397 struct lpc_ich_info *ich_info = dev->dev.platform_data; 395 struct lpc_ich_info *ich_info = dev_get_platdata(&dev->dev);
398 396
399 if (!ich_info) 397 if (!ich_info)
400 goto out; 398 goto out;
@@ -582,5 +580,4 @@ MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
582MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver"); 580MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
583MODULE_VERSION(DRV_VERSION); 581MODULE_VERSION(DRV_VERSION);
584MODULE_LICENSE("GPL"); 582MODULE_LICENSE("GPL");
585MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
586MODULE_ALIAS("platform:" DRV_NAME); 583MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/drivers/watchdog/ib700wdt.c b/drivers/watchdog/ib700wdt.c
index eb6b5cc98ec6..7ae36690c449 100644
--- a/drivers/watchdog/ib700wdt.c
+++ b/drivers/watchdog/ib700wdt.c
@@ -382,6 +382,5 @@ module_exit(ibwdt_exit);
382MODULE_AUTHOR("Charles Howes <chowes@vsol.net>"); 382MODULE_AUTHOR("Charles Howes <chowes@vsol.net>");
383MODULE_DESCRIPTION("IB700 SBC watchdog driver"); 383MODULE_DESCRIPTION("IB700 SBC watchdog driver");
384MODULE_LICENSE("GPL"); 384MODULE_LICENSE("GPL");
385MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
386 385
387/* end of ib700wdt.c */ 386/* end of ib700wdt.c */
diff --git a/drivers/watchdog/ibmasr.c b/drivers/watchdog/ibmasr.c
index bc3fb8fe89ab..db0a34460e57 100644
--- a/drivers/watchdog/ibmasr.c
+++ b/drivers/watchdog/ibmasr.c
@@ -419,4 +419,3 @@ MODULE_PARM_DESC(nowayout,
419MODULE_DESCRIPTION("IBM Automatic Server Restart driver"); 419MODULE_DESCRIPTION("IBM Automatic Server Restart driver");
420MODULE_AUTHOR("Andrey Panin"); 420MODULE_AUTHOR("Andrey Panin");
421MODULE_LICENSE("GPL"); 421MODULE_LICENSE("GPL");
422MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/ie6xx_wdt.c b/drivers/watchdog/ie6xx_wdt.c
index e24ef6a6e064..70a240297c6d 100644
--- a/drivers/watchdog/ie6xx_wdt.c
+++ b/drivers/watchdog/ie6xx_wdt.c
@@ -344,5 +344,4 @@ module_exit(ie6xx_wdt_exit);
344MODULE_AUTHOR("Alexander Stein <alexander.stein@systec-electronic.com>"); 344MODULE_AUTHOR("Alexander Stein <alexander.stein@systec-electronic.com>");
345MODULE_DESCRIPTION("Intel Atom E6xx Watchdog Device Driver"); 345MODULE_DESCRIPTION("Intel Atom E6xx Watchdog Device Driver");
346MODULE_LICENSE("GPL"); 346MODULE_LICENSE("GPL");
347MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
348MODULE_ALIAS("platform:" DRIVER_NAME); 347MODULE_ALIAS("platform:" DRIVER_NAME);
diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
index 693ac3f4de5a..b4786bccc42c 100644
--- a/drivers/watchdog/imx2_wdt.c
+++ b/drivers/watchdog/imx2_wdt.c
@@ -322,6 +322,7 @@ static const struct of_device_id imx2_wdt_dt_ids[] = {
322 { .compatible = "fsl,imx21-wdt", }, 322 { .compatible = "fsl,imx21-wdt", },
323 { /* sentinel */ } 323 { /* sentinel */ }
324}; 324};
325MODULE_DEVICE_TABLE(of, imx2_wdt_dt_ids);
325 326
326static struct platform_driver imx2_wdt_driver = { 327static struct platform_driver imx2_wdt_driver = {
327 .remove = __exit_p(imx2_wdt_remove), 328 .remove = __exit_p(imx2_wdt_remove),
@@ -338,5 +339,4 @@ module_platform_driver_probe(imx2_wdt_driver, imx2_wdt_probe);
338MODULE_AUTHOR("Wolfram Sang"); 339MODULE_AUTHOR("Wolfram Sang");
339MODULE_DESCRIPTION("Watchdog driver for IMX2 and later"); 340MODULE_DESCRIPTION("Watchdog driver for IMX2 and later");
340MODULE_LICENSE("GPL v2"); 341MODULE_LICENSE("GPL v2");
341MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
342MODULE_ALIAS("platform:" DRIVER_NAME); 342MODULE_ALIAS("platform:" DRIVER_NAME);
diff --git a/drivers/watchdog/indydog.c b/drivers/watchdog/indydog.c
index 6d90f7a2ce22..1b5c25a47b87 100644
--- a/drivers/watchdog/indydog.c
+++ b/drivers/watchdog/indydog.c
@@ -214,4 +214,3 @@ module_exit(watchdog_exit);
214MODULE_AUTHOR("Guido Guenther <agx@sigxcpu.org>"); 214MODULE_AUTHOR("Guido Guenther <agx@sigxcpu.org>");
215MODULE_DESCRIPTION("Hardware Watchdog Device for SGI IP22"); 215MODULE_DESCRIPTION("Hardware Watchdog Device for SGI IP22");
216MODULE_LICENSE("GPL"); 216MODULE_LICENSE("GPL");
217MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/intel_scu_watchdog.c b/drivers/watchdog/intel_scu_watchdog.c
index 8ced25613956..e13e65e996aa 100644
--- a/drivers/watchdog/intel_scu_watchdog.c
+++ b/drivers/watchdog/intel_scu_watchdog.c
@@ -564,5 +564,4 @@ module_exit(intel_scu_watchdog_exit);
564MODULE_AUTHOR("Intel Corporation"); 564MODULE_AUTHOR("Intel Corporation");
565MODULE_DESCRIPTION("Intel SCU Watchdog Device Driver"); 565MODULE_DESCRIPTION("Intel SCU Watchdog Device Driver");
566MODULE_LICENSE("GPL"); 566MODULE_LICENSE("GPL");
567MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
568MODULE_VERSION(WDT_VER); 567MODULE_VERSION(WDT_VER);
diff --git a/drivers/watchdog/iop_wdt.c b/drivers/watchdog/iop_wdt.c
index d964faf1a250..b16013ffacc2 100644
--- a/drivers/watchdog/iop_wdt.c
+++ b/drivers/watchdog/iop_wdt.c
@@ -259,4 +259,3 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
259MODULE_AUTHOR("Curt E Bruns <curt.e.bruns@intel.com>"); 259MODULE_AUTHOR("Curt E Bruns <curt.e.bruns@intel.com>");
260MODULE_DESCRIPTION("iop watchdog timer driver"); 260MODULE_DESCRIPTION("iop watchdog timer driver");
261MODULE_LICENSE("GPL"); 261MODULE_LICENSE("GPL");
262MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/it8712f_wdt.c b/drivers/watchdog/it8712f_wdt.c
index f4cce6d66a55..41b3979a9d87 100644
--- a/drivers/watchdog/it8712f_wdt.c
+++ b/drivers/watchdog/it8712f_wdt.c
@@ -41,7 +41,6 @@
41MODULE_AUTHOR("Jorge Boncompte - DTI2 <jorge@dti2.net>"); 41MODULE_AUTHOR("Jorge Boncompte - DTI2 <jorge@dti2.net>");
42MODULE_DESCRIPTION("IT8712F Watchdog Driver"); 42MODULE_DESCRIPTION("IT8712F Watchdog Driver");
43MODULE_LICENSE("GPL"); 43MODULE_LICENSE("GPL");
44MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
45 44
46static int max_units = 255; 45static int max_units = 255;
47static int margin = 60; /* in seconds */ 46static int margin = 60; /* in seconds */
diff --git a/drivers/watchdog/it87_wdt.c b/drivers/watchdog/it87_wdt.c
index d3dcc6988b5f..e2bba68ae71e 100644
--- a/drivers/watchdog/it87_wdt.c
+++ b/drivers/watchdog/it87_wdt.c
@@ -772,4 +772,3 @@ module_exit(it87_wdt_exit);
772MODULE_AUTHOR("Oliver Schuster"); 772MODULE_AUTHOR("Oliver Schuster");
773MODULE_DESCRIPTION("Hardware Watchdog Device Driver for IT87xx EC-LPC I/O"); 773MODULE_DESCRIPTION("Hardware Watchdog Device Driver for IT87xx EC-LPC I/O");
774MODULE_LICENSE("GPL"); 774MODULE_LICENSE("GPL");
775MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/ixp4xx_wdt.c b/drivers/watchdog/ixp4xx_wdt.c
index 5580b4fff7fe..f20cc53ff719 100644
--- a/drivers/watchdog/ixp4xx_wdt.c
+++ b/drivers/watchdog/ixp4xx_wdt.c
@@ -208,5 +208,3 @@ module_param(nowayout, bool, 0);
208MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started"); 208MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
209 209
210MODULE_LICENSE("GPL"); 210MODULE_LICENSE("GPL");
211MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
212
diff --git a/drivers/watchdog/jz4740_wdt.c b/drivers/watchdog/jz4740_wdt.c
index d1afdf684c18..2de486a7eea1 100644
--- a/drivers/watchdog/jz4740_wdt.c
+++ b/drivers/watchdog/jz4740_wdt.c
@@ -222,5 +222,4 @@ module_platform_driver(jz4740_wdt_driver);
222MODULE_AUTHOR("Paul Cercueil <paul@crapouillou.net>"); 222MODULE_AUTHOR("Paul Cercueil <paul@crapouillou.net>");
223MODULE_DESCRIPTION("jz4740 Watchdog Driver"); 223MODULE_DESCRIPTION("jz4740 Watchdog Driver");
224MODULE_LICENSE("GPL"); 224MODULE_LICENSE("GPL");
225MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
226MODULE_ALIAS("platform:jz4740-wdt"); 225MODULE_ALIAS("platform:jz4740-wdt");
diff --git a/drivers/watchdog/kempld_wdt.c b/drivers/watchdog/kempld_wdt.c
index 5c3d4df63e68..a1a3638c579c 100644
--- a/drivers/watchdog/kempld_wdt.c
+++ b/drivers/watchdog/kempld_wdt.c
@@ -67,7 +67,7 @@ enum {
67 PRESCALER_12, 67 PRESCALER_12,
68}; 68};
69 69
70const u32 kempld_prescaler[] = { 70static const u32 kempld_prescaler[] = {
71 [PRESCALER_21] = (1 << 21) - 1, 71 [PRESCALER_21] = (1 << 21) - 1,
72 [PRESCALER_17] = (1 << 17) - 1, 72 [PRESCALER_17] = (1 << 17) - 1,
73 [PRESCALER_12] = (1 << 12) - 1, 73 [PRESCALER_12] = (1 << 12) - 1,
@@ -361,7 +361,7 @@ static long kempld_wdt_ioctl(struct watchdog_device *wdd, unsigned int cmd,
361 ret = kempld_wdt_keepalive(wdd); 361 ret = kempld_wdt_keepalive(wdd);
362 break; 362 break;
363 case WDIOC_GETPRETIMEOUT: 363 case WDIOC_GETPRETIMEOUT:
364 ret = put_user(wdt_data->pretimeout, (int *)arg); 364 ret = put_user(wdt_data->pretimeout, (int __user *)arg);
365 break; 365 break;
366 } 366 }
367 367
@@ -578,4 +578,3 @@ module_platform_driver(kempld_wdt_driver);
578MODULE_DESCRIPTION("KEM PLD Watchdog Driver"); 578MODULE_DESCRIPTION("KEM PLD Watchdog Driver");
579MODULE_AUTHOR("Michael Brunner <michael.brunner@kontron.com>"); 579MODULE_AUTHOR("Michael Brunner <michael.brunner@kontron.com>");
580MODULE_LICENSE("GPL"); 580MODULE_LICENSE("GPL");
581MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/ks8695_wdt.c b/drivers/watchdog/ks8695_wdt.c
index dce9ecffd44a..40ca5594a336 100644
--- a/drivers/watchdog/ks8695_wdt.c
+++ b/drivers/watchdog/ks8695_wdt.c
@@ -323,5 +323,4 @@ module_exit(ks8695_wdt_exit);
323MODULE_AUTHOR("Andrew Victor"); 323MODULE_AUTHOR("Andrew Victor");
324MODULE_DESCRIPTION("Watchdog driver for KS8695"); 324MODULE_DESCRIPTION("Watchdog driver for KS8695");
325MODULE_LICENSE("GPL"); 325MODULE_LICENSE("GPL");
326MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
327MODULE_ALIAS("platform:ks8695_wdt"); 326MODULE_ALIAS("platform:ks8695_wdt");
diff --git a/drivers/watchdog/lantiq_wdt.c b/drivers/watchdog/lantiq_wdt.c
index 088fd0c9d888..3b3148c764a3 100644
--- a/drivers/watchdog/lantiq_wdt.c
+++ b/drivers/watchdog/lantiq_wdt.c
@@ -249,4 +249,3 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
249MODULE_AUTHOR("John Crispin <blogic@openwrt.org>"); 249MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
250MODULE_DESCRIPTION("Lantiq SoC Watchdog"); 250MODULE_DESCRIPTION("Lantiq SoC Watchdog");
251MODULE_LICENSE("GPL"); 251MODULE_LICENSE("GPL");
252MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/m54xx_wdt.c b/drivers/watchdog/m54xx_wdt.c
index 173494a681e6..da6fa2b68074 100644
--- a/drivers/watchdog/m54xx_wdt.c
+++ b/drivers/watchdog/m54xx_wdt.c
@@ -223,4 +223,3 @@ module_param(nowayout, bool, 0);
223MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started"); 223MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
224 224
225MODULE_LICENSE("GPL"); 225MODULE_LICENSE("GPL");
226MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/machzwd.c b/drivers/watchdog/machzwd.c
index bf84f788e592..9826b59ef734 100644
--- a/drivers/watchdog/machzwd.c
+++ b/drivers/watchdog/machzwd.c
@@ -92,7 +92,6 @@ static unsigned short zf_readw(unsigned char port)
92MODULE_AUTHOR("Fernando Fuganti <fuganti@conectiva.com.br>"); 92MODULE_AUTHOR("Fernando Fuganti <fuganti@conectiva.com.br>");
93MODULE_DESCRIPTION("MachZ ZF-Logic Watchdog driver"); 93MODULE_DESCRIPTION("MachZ ZF-Logic Watchdog driver");
94MODULE_LICENSE("GPL"); 94MODULE_LICENSE("GPL");
95MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
96 95
97static bool nowayout = WATCHDOG_NOWAYOUT; 96static bool nowayout = WATCHDOG_NOWAYOUT;
98module_param(nowayout, bool, 0); 97module_param(nowayout, bool, 0);
diff --git a/drivers/watchdog/max63xx_wdt.c b/drivers/watchdog/max63xx_wdt.c
index cc9d328086ed..6d4f3998e1f6 100644
--- a/drivers/watchdog/max63xx_wdt.c
+++ b/drivers/watchdog/max63xx_wdt.c
@@ -258,4 +258,3 @@ MODULE_PARM_DESC(nodelay,
258 "(max6373/74 only, default=0)"); 258 "(max6373/74 only, default=0)");
259 259
260MODULE_LICENSE("GPL"); 260MODULE_LICENSE("GPL");
261MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/mixcomwd.c b/drivers/watchdog/mixcomwd.c
index 97d62ee50341..be86ea359eee 100644
--- a/drivers/watchdog/mixcomwd.c
+++ b/drivers/watchdog/mixcomwd.c
@@ -315,4 +315,3 @@ MODULE_AUTHOR("Gergely Madarasz <gorgo@itc.hu>");
315MODULE_DESCRIPTION("MixCom Watchdog driver"); 315MODULE_DESCRIPTION("MixCom Watchdog driver");
316MODULE_VERSION(VERSION); 316MODULE_VERSION(VERSION);
317MODULE_LICENSE("GPL"); 317MODULE_LICENSE("GPL");
318MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/moxart_wdt.c b/drivers/watchdog/moxart_wdt.c
new file mode 100644
index 000000000000..4166e4d116a8
--- /dev/null
+++ b/drivers/watchdog/moxart_wdt.c
@@ -0,0 +1,165 @@
1/*
2 * MOXA ART SoCs watchdog driver.
3 *
4 * Copyright (C) 2013 Jonas Jensen
5 *
6 * Jonas Jensen <jonas.jensen@gmail.com>
7 *
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
11 */
12
13#include <linux/clk.h>
14#include <linux/io.h>
15#include <linux/module.h>
16#include <linux/err.h>
17#include <linux/kernel.h>
18#include <linux/platform_device.h>
19#include <linux/watchdog.h>
20#include <linux/moduleparam.h>
21
22#define REG_COUNT 0x4
23#define REG_MODE 0x8
24#define REG_ENABLE 0xC
25
26struct moxart_wdt_dev {
27 struct watchdog_device dev;
28 void __iomem *base;
29 unsigned int clock_frequency;
30};
31
32static int heartbeat;
33
34static int moxart_wdt_stop(struct watchdog_device *wdt_dev)
35{
36 struct moxart_wdt_dev *moxart_wdt = watchdog_get_drvdata(wdt_dev);
37
38 writel(0, moxart_wdt->base + REG_ENABLE);
39
40 return 0;
41}
42
43static int moxart_wdt_start(struct watchdog_device *wdt_dev)
44{
45 struct moxart_wdt_dev *moxart_wdt = watchdog_get_drvdata(wdt_dev);
46
47 writel(moxart_wdt->clock_frequency * wdt_dev->timeout,
48 moxart_wdt->base + REG_COUNT);
49 writel(0x5ab9, moxart_wdt->base + REG_MODE);
50 writel(0x03, moxart_wdt->base + REG_ENABLE);
51
52 return 0;
53}
54
55static int moxart_wdt_set_timeout(struct watchdog_device *wdt_dev,
56 unsigned int timeout)
57{
58 wdt_dev->timeout = timeout;
59
60 return 0;
61}
62
63static const struct watchdog_info moxart_wdt_info = {
64 .identity = "moxart-wdt",
65 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING |
66 WDIOF_MAGICCLOSE,
67};
68
69static const struct watchdog_ops moxart_wdt_ops = {
70 .owner = THIS_MODULE,
71 .start = moxart_wdt_start,
72 .stop = moxart_wdt_stop,
73 .set_timeout = moxart_wdt_set_timeout,
74};
75
76static int moxart_wdt_probe(struct platform_device *pdev)
77{
78 struct moxart_wdt_dev *moxart_wdt;
79 struct device *dev = &pdev->dev;
80 struct device_node *node = dev->of_node;
81 struct resource *res;
82 struct clk *clk;
83 int err;
84 unsigned int max_timeout;
85 bool nowayout = WATCHDOG_NOWAYOUT;
86
87 moxart_wdt = devm_kzalloc(dev, sizeof(*moxart_wdt), GFP_KERNEL);
88 if (!moxart_wdt)
89 return -ENOMEM;
90
91 platform_set_drvdata(pdev, moxart_wdt);
92
93 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
94 moxart_wdt->base = devm_ioremap_resource(dev, res);
95 if (IS_ERR(moxart_wdt->base))
96 return PTR_ERR(moxart_wdt->base);
97
98 clk = of_clk_get(node, 0);
99 if (IS_ERR(clk)) {
100 pr_err("%s: of_clk_get failed\n", __func__);
101 return PTR_ERR(clk);
102 }
103
104 moxart_wdt->clock_frequency = clk_get_rate(clk);
105 if (moxart_wdt->clock_frequency == 0) {
106 pr_err("%s: incorrect clock frequency\n", __func__);
107 return -EINVAL;
108 }
109
110 max_timeout = UINT_MAX / moxart_wdt->clock_frequency;
111
112 moxart_wdt->dev.info = &moxart_wdt_info;
113 moxart_wdt->dev.ops = &moxart_wdt_ops;
114 moxart_wdt->dev.timeout = max_timeout;
115 moxart_wdt->dev.min_timeout = 1;
116 moxart_wdt->dev.max_timeout = max_timeout;
117 moxart_wdt->dev.parent = dev;
118
119 watchdog_init_timeout(&moxart_wdt->dev, heartbeat, dev);
120 watchdog_set_nowayout(&moxart_wdt->dev, nowayout);
121
122 watchdog_set_drvdata(&moxart_wdt->dev, moxart_wdt);
123
124 err = watchdog_register_device(&moxart_wdt->dev);
125 if (err)
126 return err;
127
128 dev_dbg(dev, "Watchdog enabled (heartbeat=%d sec, nowayout=%d)\n",
129 moxart_wdt->dev.timeout, nowayout);
130
131 return 0;
132}
133
134static int moxart_wdt_remove(struct platform_device *pdev)
135{
136 struct moxart_wdt_dev *moxart_wdt = platform_get_drvdata(pdev);
137
138 moxart_wdt_stop(&moxart_wdt->dev);
139 watchdog_unregister_device(&moxart_wdt->dev);
140
141 return 0;
142}
143
144static const struct of_device_id moxart_watchdog_match[] = {
145 { .compatible = "moxa,moxart-watchdog" },
146 { },
147};
148
149static struct platform_driver moxart_wdt_driver = {
150 .probe = moxart_wdt_probe,
151 .remove = moxart_wdt_remove,
152 .driver = {
153 .name = "moxart-watchdog",
154 .owner = THIS_MODULE,
155 .of_match_table = moxart_watchdog_match,
156 },
157};
158module_platform_driver(moxart_wdt_driver);
159
160module_param(heartbeat, int, 0);
161MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds");
162
163MODULE_DESCRIPTION("MOXART watchdog driver");
164MODULE_LICENSE("GPL");
165MODULE_AUTHOR("Jonas Jensen <jonas.jensen@gmail.com>");
diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
index d0ebebae607c..d82152077fd9 100644
--- a/drivers/watchdog/mpc8xxx_wdt.c
+++ b/drivers/watchdog/mpc8xxx_wdt.c
@@ -330,4 +330,3 @@ MODULE_AUTHOR("Dave Updegraff, Kumar Gala");
330MODULE_DESCRIPTION("Driver for watchdog timer in MPC8xx/MPC83xx/MPC86xx " 330MODULE_DESCRIPTION("Driver for watchdog timer in MPC8xx/MPC83xx/MPC86xx "
331 "uProcessors"); 331 "uProcessors");
332MODULE_LICENSE("GPL"); 332MODULE_LICENSE("GPL");
333MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/mtx-1_wdt.c b/drivers/watchdog/mtx-1_wdt.c
index b4341110ad4f..edb31ffd7927 100644
--- a/drivers/watchdog/mtx-1_wdt.c
+++ b/drivers/watchdog/mtx-1_wdt.c
@@ -257,5 +257,4 @@ module_platform_driver(mtx1_wdt_driver);
257MODULE_AUTHOR("Michael Stickel, Florian Fainelli"); 257MODULE_AUTHOR("Michael Stickel, Florian Fainelli");
258MODULE_DESCRIPTION("Driver for the MTX-1 watchdog"); 258MODULE_DESCRIPTION("Driver for the MTX-1 watchdog");
259MODULE_LICENSE("GPL"); 259MODULE_LICENSE("GPL");
260MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
261MODULE_ALIAS("platform:mtx1-wdt"); 260MODULE_ALIAS("platform:mtx1-wdt");
diff --git a/drivers/watchdog/mv64x60_wdt.c b/drivers/watchdog/mv64x60_wdt.c
index e4cf98019265..f9fa58409396 100644
--- a/drivers/watchdog/mv64x60_wdt.c
+++ b/drivers/watchdog/mv64x60_wdt.c
@@ -255,7 +255,7 @@ static struct miscdevice mv64x60_wdt_miscdev = {
255 255
256static int mv64x60_wdt_probe(struct platform_device *dev) 256static int mv64x60_wdt_probe(struct platform_device *dev)
257{ 257{
258 struct mv64x60_wdt_pdata *pdata = dev->dev.platform_data; 258 struct mv64x60_wdt_pdata *pdata = dev_get_platdata(&dev->dev);
259 struct resource *r; 259 struct resource *r;
260 int timeout = 10; 260 int timeout = 10;
261 261
@@ -323,5 +323,4 @@ module_exit(mv64x60_wdt_exit);
323MODULE_AUTHOR("James Chapman <jchapman@katalix.com>"); 323MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
324MODULE_DESCRIPTION("MV64x60 watchdog driver"); 324MODULE_DESCRIPTION("MV64x60 watchdog driver");
325MODULE_LICENSE("GPL"); 325MODULE_LICENSE("GPL");
326MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
327MODULE_ALIAS("platform:" MV64x60_WDT_NAME); 326MODULE_ALIAS("platform:" MV64x60_WDT_NAME);
diff --git a/drivers/watchdog/nuc900_wdt.c b/drivers/watchdog/nuc900_wdt.c
index b15b6efd91a1..a0d893b0930e 100644
--- a/drivers/watchdog/nuc900_wdt.c
+++ b/drivers/watchdog/nuc900_wdt.c
@@ -307,5 +307,4 @@ module_platform_driver(nuc900wdt_driver);
307MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); 307MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
308MODULE_DESCRIPTION("Watchdog driver for NUC900"); 308MODULE_DESCRIPTION("Watchdog driver for NUC900");
309MODULE_LICENSE("GPL"); 309MODULE_LICENSE("GPL");
310MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
311MODULE_ALIAS("platform:nuc900-wdt"); 310MODULE_ALIAS("platform:nuc900-wdt");
diff --git a/drivers/watchdog/nv_tco.c b/drivers/watchdog/nv_tco.c
index 59cf19eeea07..231e5b9d5c8e 100644
--- a/drivers/watchdog/nv_tco.c
+++ b/drivers/watchdog/nv_tco.c
@@ -513,4 +513,3 @@ module_exit(nv_tco_cleanup_module);
513MODULE_AUTHOR("Mike Waychison"); 513MODULE_AUTHOR("Mike Waychison");
514MODULE_DESCRIPTION("TCO timer driver for NV chipsets"); 514MODULE_DESCRIPTION("TCO timer driver for NV chipsets");
515MODULE_LICENSE("GPL"); 515MODULE_LICENSE("GPL");
516MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c
index 4dd281f2c33f..fb57103c8ebc 100644
--- a/drivers/watchdog/of_xilinx_wdt.c
+++ b/drivers/watchdog/of_xilinx_wdt.c
@@ -405,4 +405,3 @@ module_platform_driver(xwdt_driver);
405MODULE_AUTHOR("Alejandro Cabrera <aldaya@gmail.com>"); 405MODULE_AUTHOR("Alejandro Cabrera <aldaya@gmail.com>");
406MODULE_DESCRIPTION("Xilinx Watchdog driver"); 406MODULE_DESCRIPTION("Xilinx Watchdog driver");
407MODULE_LICENSE("GPL v2"); 407MODULE_LICENSE("GPL v2");
408MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/omap_wdt.c b/drivers/watchdog/omap_wdt.c
index af88ffd1068f..09cf0135e8ac 100644
--- a/drivers/watchdog/omap_wdt.c
+++ b/drivers/watchdog/omap_wdt.c
@@ -68,14 +68,14 @@ static void omap_wdt_reload(struct omap_wdt_dev *wdev)
68 void __iomem *base = wdev->base; 68 void __iomem *base = wdev->base;
69 69
70 /* wait for posted write to complete */ 70 /* wait for posted write to complete */
71 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x08) 71 while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x08)
72 cpu_relax(); 72 cpu_relax();
73 73
74 wdev->wdt_trgr_pattern = ~wdev->wdt_trgr_pattern; 74 wdev->wdt_trgr_pattern = ~wdev->wdt_trgr_pattern;
75 __raw_writel(wdev->wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR)); 75 writel_relaxed(wdev->wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR));
76 76
77 /* wait for posted write to complete */ 77 /* wait for posted write to complete */
78 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x08) 78 while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x08)
79 cpu_relax(); 79 cpu_relax();
80 /* reloaded WCRR from WLDR */ 80 /* reloaded WCRR from WLDR */
81} 81}
@@ -85,12 +85,12 @@ static void omap_wdt_enable(struct omap_wdt_dev *wdev)
85 void __iomem *base = wdev->base; 85 void __iomem *base = wdev->base;
86 86
87 /* Sequence to enable the watchdog */ 87 /* Sequence to enable the watchdog */
88 __raw_writel(0xBBBB, base + OMAP_WATCHDOG_SPR); 88 writel_relaxed(0xBBBB, base + OMAP_WATCHDOG_SPR);
89 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10) 89 while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x10)
90 cpu_relax(); 90 cpu_relax();
91 91
92 __raw_writel(0x4444, base + OMAP_WATCHDOG_SPR); 92 writel_relaxed(0x4444, base + OMAP_WATCHDOG_SPR);
93 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10) 93 while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x10)
94 cpu_relax(); 94 cpu_relax();
95} 95}
96 96
@@ -99,12 +99,12 @@ static void omap_wdt_disable(struct omap_wdt_dev *wdev)
99 void __iomem *base = wdev->base; 99 void __iomem *base = wdev->base;
100 100
101 /* sequence required to disable watchdog */ 101 /* sequence required to disable watchdog */
102 __raw_writel(0xAAAA, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */ 102 writel_relaxed(0xAAAA, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
103 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x10) 103 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10)
104 cpu_relax(); 104 cpu_relax();
105 105
106 __raw_writel(0x5555, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */ 106 writel_relaxed(0x5555, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
107 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x10) 107 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10)
108 cpu_relax(); 108 cpu_relax();
109} 109}
110 110
@@ -115,11 +115,11 @@ static void omap_wdt_set_timer(struct omap_wdt_dev *wdev,
115 void __iomem *base = wdev->base; 115 void __iomem *base = wdev->base;
116 116
117 /* just count up at 32 KHz */ 117 /* just count up at 32 KHz */
118 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04) 118 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x04)
119 cpu_relax(); 119 cpu_relax();
120 120
121 __raw_writel(pre_margin, base + OMAP_WATCHDOG_LDR); 121 writel_relaxed(pre_margin, base + OMAP_WATCHDOG_LDR);
122 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04) 122 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x04)
123 cpu_relax(); 123 cpu_relax();
124} 124}
125 125
@@ -135,11 +135,11 @@ static int omap_wdt_start(struct watchdog_device *wdog)
135 pm_runtime_get_sync(wdev->dev); 135 pm_runtime_get_sync(wdev->dev);
136 136
137 /* initialize prescaler */ 137 /* initialize prescaler */
138 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01) 138 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x01)
139 cpu_relax(); 139 cpu_relax();
140 140
141 __raw_writel((1 << 5) | (PTV << 2), base + OMAP_WATCHDOG_CNTRL); 141 writel_relaxed((1 << 5) | (PTV << 2), base + OMAP_WATCHDOG_CNTRL);
142 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01) 142 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x01)
143 cpu_relax(); 143 cpu_relax();
144 144
145 omap_wdt_set_timer(wdev, wdog->timeout); 145 omap_wdt_set_timer(wdev, wdog->timeout);
@@ -205,7 +205,7 @@ static const struct watchdog_ops omap_wdt_ops = {
205 205
206static int omap_wdt_probe(struct platform_device *pdev) 206static int omap_wdt_probe(struct platform_device *pdev)
207{ 207{
208 struct omap_wd_timer_platform_data *pdata = pdev->dev.platform_data; 208 struct omap_wd_timer_platform_data *pdata = dev_get_platdata(&pdev->dev);
209 struct watchdog_device *omap_wdt; 209 struct watchdog_device *omap_wdt;
210 struct resource *res, *mem; 210 struct resource *res, *mem;
211 struct omap_wdt_dev *wdev; 211 struct omap_wdt_dev *wdev;
@@ -275,7 +275,7 @@ static int omap_wdt_probe(struct platform_device *pdev)
275 } 275 }
276 276
277 pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n", 277 pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n",
278 __raw_readl(wdev->base + OMAP_WATCHDOG_REV) & 0xFF, 278 readl_relaxed(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
279 omap_wdt->timeout); 279 omap_wdt->timeout);
280 280
281 pm_runtime_put_sync(wdev->dev); 281 pm_runtime_put_sync(wdev->dev);
diff --git a/drivers/watchdog/orion_wdt.c b/drivers/watchdog/orion_wdt.c
index 4ea5fcccac02..44edca66d564 100644
--- a/drivers/watchdog/orion_wdt.c
+++ b/drivers/watchdog/orion_wdt.c
@@ -207,7 +207,7 @@ static struct platform_driver orion_wdt_driver = {
207 .driver = { 207 .driver = {
208 .owner = THIS_MODULE, 208 .owner = THIS_MODULE,
209 .name = "orion_wdt", 209 .name = "orion_wdt",
210 .of_match_table = of_match_ptr(orion_wdt_of_match_table), 210 .of_match_table = orion_wdt_of_match_table,
211 }, 211 },
212}; 212};
213 213
@@ -225,4 +225,3 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
225 225
226MODULE_LICENSE("GPL"); 226MODULE_LICENSE("GPL");
227MODULE_ALIAS("platform:orion_wdt"); 227MODULE_ALIAS("platform:orion_wdt");
228MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/pc87413_wdt.c b/drivers/watchdog/pc87413_wdt.c
index 5afb89b48650..5211d56b3681 100644
--- a/drivers/watchdog/pc87413_wdt.c
+++ b/drivers/watchdog/pc87413_wdt.c
@@ -580,8 +580,6 @@ MODULE_AUTHOR("Sven Anders <anders@anduras.de>, "
580MODULE_DESCRIPTION("PC87413 WDT driver"); 580MODULE_DESCRIPTION("PC87413 WDT driver");
581MODULE_LICENSE("GPL"); 581MODULE_LICENSE("GPL");
582 582
583MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
584
585module_param(io, int, 0); 583module_param(io, int, 0);
586MODULE_PARM_DESC(io, MODNAME " I/O port (default: " 584MODULE_PARM_DESC(io, MODNAME " I/O port (default: "
587 __MODULE_STRING(IO_DEFAULT) ")."); 585 __MODULE_STRING(IO_DEFAULT) ").");
diff --git a/drivers/watchdog/pcwd.c b/drivers/watchdog/pcwd.c
index 33e49a7f889f..e936f15dc7c7 100644
--- a/drivers/watchdog/pcwd.c
+++ b/drivers/watchdog/pcwd.c
@@ -61,7 +61,7 @@
61#include <linux/delay.h> /* For mdelay function */ 61#include <linux/delay.h> /* For mdelay function */
62#include <linux/timer.h> /* For timer related operations */ 62#include <linux/timer.h> /* For timer related operations */
63#include <linux/jiffies.h> /* For jiffies stuff */ 63#include <linux/jiffies.h> /* For jiffies stuff */
64#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */ 64#include <linux/miscdevice.h> /* For struct miscdevice */
65#include <linux/watchdog.h> /* For the watchdog specific items */ 65#include <linux/watchdog.h> /* For the watchdog specific items */
66#include <linux/reboot.h> /* For kernel_power_off() */ 66#include <linux/reboot.h> /* For kernel_power_off() */
67#include <linux/init.h> /* For __init/__exit/... */ 67#include <linux/init.h> /* For __init/__exit/... */
@@ -1011,5 +1011,3 @@ MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>, "
1011MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver"); 1011MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver");
1012MODULE_VERSION(WATCHDOG_VERSION); 1012MODULE_VERSION(WATCHDOG_VERSION);
1013MODULE_LICENSE("GPL"); 1013MODULE_LICENSE("GPL");
1014MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
1015MODULE_ALIAS_MISCDEV(TEMP_MINOR);
diff --git a/drivers/watchdog/pcwd_pci.c b/drivers/watchdog/pcwd_pci.c
index 7890f84edf76..b4864f254b48 100644
--- a/drivers/watchdog/pcwd_pci.c
+++ b/drivers/watchdog/pcwd_pci.c
@@ -40,7 +40,7 @@
40#include <linux/errno.h> /* For the -ENODEV/... values */ 40#include <linux/errno.h> /* For the -ENODEV/... values */
41#include <linux/kernel.h> /* For printk/panic/... */ 41#include <linux/kernel.h> /* For printk/panic/... */
42#include <linux/delay.h> /* For mdelay function */ 42#include <linux/delay.h> /* For mdelay function */
43#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */ 43#include <linux/miscdevice.h> /* For struct miscdevice */
44#include <linux/watchdog.h> /* For the watchdog specific items */ 44#include <linux/watchdog.h> /* For the watchdog specific items */
45#include <linux/notifier.h> /* For notifier support */ 45#include <linux/notifier.h> /* For notifier support */
46#include <linux/reboot.h> /* For reboot_notifier stuff */ 46#include <linux/reboot.h> /* For reboot_notifier stuff */
@@ -820,5 +820,3 @@ module_pci_driver(pcipcwd_driver);
820MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>"); 820MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
821MODULE_DESCRIPTION("Berkshire PCI-PC Watchdog driver"); 821MODULE_DESCRIPTION("Berkshire PCI-PC Watchdog driver");
822MODULE_LICENSE("GPL"); 822MODULE_LICENSE("GPL");
823MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
824MODULE_ALIAS_MISCDEV(TEMP_MINOR);
diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c
index 7b14d1847927..b731b5d129be 100644
--- a/drivers/watchdog/pcwd_usb.c
+++ b/drivers/watchdog/pcwd_usb.c
@@ -32,7 +32,7 @@
32#include <linux/errno.h> /* For the -ENODEV/... values */ 32#include <linux/errno.h> /* For the -ENODEV/... values */
33#include <linux/kernel.h> /* For printk/panic/... */ 33#include <linux/kernel.h> /* For printk/panic/... */
34#include <linux/delay.h> /* For mdelay function */ 34#include <linux/delay.h> /* For mdelay function */
35#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */ 35#include <linux/miscdevice.h> /* For struct miscdevice */
36#include <linux/watchdog.h> /* For the watchdog specific items */ 36#include <linux/watchdog.h> /* For the watchdog specific items */
37#include <linux/notifier.h> /* For notifier support */ 37#include <linux/notifier.h> /* For notifier support */
38#include <linux/reboot.h> /* For reboot_notifier stuff */ 38#include <linux/reboot.h> /* For reboot_notifier stuff */
@@ -72,8 +72,6 @@ do { \
72MODULE_AUTHOR(DRIVER_AUTHOR); 72MODULE_AUTHOR(DRIVER_AUTHOR);
73MODULE_DESCRIPTION(DRIVER_DESC); 73MODULE_DESCRIPTION(DRIVER_DESC);
74MODULE_LICENSE(DRIVER_LICENSE); 74MODULE_LICENSE(DRIVER_LICENSE);
75MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
76MODULE_ALIAS_MISCDEV(TEMP_MINOR);
77 75
78/* Module Parameters */ 76/* Module Parameters */
79module_param(debug, int, 0); 77module_param(debug, int, 0);
@@ -235,13 +233,17 @@ static int usb_pcwd_send_command(struct usb_pcwd_private *usb_pcwd,
235 unsigned char cmd, unsigned char *msb, unsigned char *lsb) 233 unsigned char cmd, unsigned char *msb, unsigned char *lsb)
236{ 234{
237 int got_response, count; 235 int got_response, count;
238 unsigned char buf[6]; 236 unsigned char *buf;
239 237
240 /* We will not send any commands if the USB PCWD device does 238 /* We will not send any commands if the USB PCWD device does
241 * not exist */ 239 * not exist */
242 if ((!usb_pcwd) || (!usb_pcwd->exists)) 240 if ((!usb_pcwd) || (!usb_pcwd->exists))
243 return -1; 241 return -1;
244 242
243 buf = kmalloc(6, GFP_KERNEL);
244 if (buf == NULL)
245 return 0;
246
245 /* The USB PC Watchdog uses a 6 byte report format. 247 /* The USB PC Watchdog uses a 6 byte report format.
246 * The board currently uses only 3 of the six bytes of the report. */ 248 * The board currently uses only 3 of the six bytes of the report. */
247 buf[0] = cmd; /* Byte 0 = CMD */ 249 buf[0] = cmd; /* Byte 0 = CMD */
@@ -256,8 +258,8 @@ static int usb_pcwd_send_command(struct usb_pcwd_private *usb_pcwd,
256 258
257 if (usb_control_msg(usb_pcwd->udev, usb_sndctrlpipe(usb_pcwd->udev, 0), 259 if (usb_control_msg(usb_pcwd->udev, usb_sndctrlpipe(usb_pcwd->udev, 0),
258 HID_REQ_SET_REPORT, HID_DT_REPORT, 260 HID_REQ_SET_REPORT, HID_DT_REPORT,
259 0x0200, usb_pcwd->interface_number, buf, sizeof(buf), 261 0x0200, usb_pcwd->interface_number, buf, 6,
260 USB_COMMAND_TIMEOUT) != sizeof(buf)) { 262 USB_COMMAND_TIMEOUT) != 6) {
261 dbg("usb_pcwd_send_command: error in usb_control_msg for " 263 dbg("usb_pcwd_send_command: error in usb_control_msg for "
262 "cmd 0x%x 0x%x 0x%x\n", cmd, *msb, *lsb); 264 "cmd 0x%x 0x%x 0x%x\n", cmd, *msb, *lsb);
263 } 265 }
@@ -277,6 +279,8 @@ static int usb_pcwd_send_command(struct usb_pcwd_private *usb_pcwd,
277 *lsb = usb_pcwd->cmd_data_lsb; 279 *lsb = usb_pcwd->cmd_data_lsb;
278 } 280 }
279 281
282 kfree(buf);
283
280 return got_response; 284 return got_response;
281} 285}
282 286
diff --git a/drivers/watchdog/pika_wdt.c b/drivers/watchdog/pika_wdt.c
index 329bc60ad7a2..0cdfee266690 100644
--- a/drivers/watchdog/pika_wdt.c
+++ b/drivers/watchdog/pika_wdt.c
@@ -299,5 +299,3 @@ module_exit(pikawdt_exit);
299MODULE_AUTHOR("Sean MacLennan <smaclennan@pikatech.com>"); 299MODULE_AUTHOR("Sean MacLennan <smaclennan@pikatech.com>");
300MODULE_DESCRIPTION("PIKA FPGA based Watchdog Timer"); 300MODULE_DESCRIPTION("PIKA FPGA based Watchdog Timer");
301MODULE_LICENSE("GPL"); 301MODULE_LICENSE("GPL");
302MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
303
diff --git a/drivers/watchdog/pnx4008_wdt.c b/drivers/watchdog/pnx4008_wdt.c
index b30bd430f591..1bdcc313e1d9 100644
--- a/drivers/watchdog/pnx4008_wdt.c
+++ b/drivers/watchdog/pnx4008_wdt.c
@@ -233,5 +233,4 @@ MODULE_PARM_DESC(nowayout,
233 "Set to 1 to keep watchdog running after device release"); 233 "Set to 1 to keep watchdog running after device release");
234 234
235MODULE_LICENSE("GPL"); 235MODULE_LICENSE("GPL");
236MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
237MODULE_ALIAS("platform:pnx4008-watchdog"); 236MODULE_ALIAS("platform:pnx4008-watchdog");
diff --git a/drivers/watchdog/pnx833x_wdt.c b/drivers/watchdog/pnx833x_wdt.c
index 1b62a7dfcc95..882fdcb46ad1 100644
--- a/drivers/watchdog/pnx833x_wdt.c
+++ b/drivers/watchdog/pnx833x_wdt.c
@@ -278,4 +278,3 @@ module_exit(watchdog_exit);
278MODULE_AUTHOR("Daniel Laird/Andre McCurdy"); 278MODULE_AUTHOR("Daniel Laird/Andre McCurdy");
279MODULE_DESCRIPTION("Hardware Watchdog Device for PNX833x"); 279MODULE_DESCRIPTION("Hardware Watchdog Device for PNX833x");
280MODULE_LICENSE("GPL"); 280MODULE_LICENSE("GPL");
281MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/rc32434_wdt.c b/drivers/watchdog/rc32434_wdt.c
index 9cf6bc7a234f..71e78ef4b736 100644
--- a/drivers/watchdog/rc32434_wdt.c
+++ b/drivers/watchdog/rc32434_wdt.c
@@ -25,8 +25,7 @@
25#include <linux/errno.h> /* For the -ENODEV/... values */ 25#include <linux/errno.h> /* For the -ENODEV/... values */
26#include <linux/kernel.h> /* For printk/panic/... */ 26#include <linux/kernel.h> /* For printk/panic/... */
27#include <linux/fs.h> /* For file operations */ 27#include <linux/fs.h> /* For file operations */
28#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV 28#include <linux/miscdevice.h> /* For struct miscdevice */
29 (WATCHDOG_MINOR) */
30#include <linux/watchdog.h> /* For the watchdog specific items */ 29#include <linux/watchdog.h> /* For the watchdog specific items */
31#include <linux/init.h> /* For __init/__exit/... */ 30#include <linux/init.h> /* For __init/__exit/... */
32#include <linux/platform_device.h> /* For platform_driver framework */ 31#include <linux/platform_device.h> /* For platform_driver framework */
@@ -329,4 +328,3 @@ MODULE_AUTHOR("Ondrej Zajicek <santiago@crfreenet.org>,"
329 "Florian Fainelli <florian@openwrt.org>"); 328 "Florian Fainelli <florian@openwrt.org>");
330MODULE_DESCRIPTION("Driver for the IDT RC32434 SoC watchdog"); 329MODULE_DESCRIPTION("Driver for the IDT RC32434 SoC watchdog");
331MODULE_LICENSE("GPL"); 330MODULE_LICENSE("GPL");
332MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/rdc321x_wdt.c b/drivers/watchdog/rdc321x_wdt.c
index b0f116c2fd53..082d06262959 100644
--- a/drivers/watchdog/rdc321x_wdt.c
+++ b/drivers/watchdog/rdc321x_wdt.c
@@ -231,7 +231,7 @@ static int rdc321x_wdt_probe(struct platform_device *pdev)
231 struct resource *r; 231 struct resource *r;
232 struct rdc321x_wdt_pdata *pdata; 232 struct rdc321x_wdt_pdata *pdata;
233 233
234 pdata = pdev->dev.platform_data; 234 pdata = dev_get_platdata(&pdev->dev);
235 if (!pdata) { 235 if (!pdata) {
236 dev_err(&pdev->dev, "no platform data supplied\n"); 236 dev_err(&pdev->dev, "no platform data supplied\n");
237 return -ENODEV; 237 return -ENODEV;
@@ -298,4 +298,3 @@ module_platform_driver(rdc321x_wdt_driver);
298MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>"); 298MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
299MODULE_DESCRIPTION("RDC321x watchdog driver"); 299MODULE_DESCRIPTION("RDC321x watchdog driver");
300MODULE_LICENSE("GPL"); 300MODULE_LICENSE("GPL");
301MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/rt2880_wdt.c b/drivers/watchdog/rt2880_wdt.c
new file mode 100644
index 000000000000..53d37fea183e
--- /dev/null
+++ b/drivers/watchdog/rt2880_wdt.c
@@ -0,0 +1,207 @@
1/*
2 * Ralink RT288x/RT3xxx/MT76xx built-in hardware watchdog timer
3 *
4 * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
6 *
7 * This driver was based on: drivers/watchdog/softdog.c
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 version 2 as published
11 * by the Free Software Foundation.
12 */
13
14#include <linux/clk.h>
15#include <linux/reset.h>
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/watchdog.h>
19#include <linux/miscdevice.h>
20#include <linux/moduleparam.h>
21#include <linux/platform_device.h>
22
23#include <asm/mach-ralink/ralink_regs.h>
24
25#define SYSC_RSTSTAT 0x38
26#define WDT_RST_CAUSE BIT(1)
27
28#define RALINK_WDT_TIMEOUT 30
29#define RALINK_WDT_PRESCALE 65536
30
31#define TIMER_REG_TMR1LOAD 0x00
32#define TIMER_REG_TMR1CTL 0x08
33
34#define TMRSTAT_TMR1RST BIT(5)
35
36#define TMR1CTL_ENABLE BIT(7)
37#define TMR1CTL_MODE_SHIFT 4
38#define TMR1CTL_MODE_MASK 0x3
39#define TMR1CTL_MODE_FREE_RUNNING 0x0
40#define TMR1CTL_MODE_PERIODIC 0x1
41#define TMR1CTL_MODE_TIMEOUT 0x2
42#define TMR1CTL_MODE_WDT 0x3
43#define TMR1CTL_PRESCALE_MASK 0xf
44#define TMR1CTL_PRESCALE_65536 0xf
45
46static struct clk *rt288x_wdt_clk;
47static unsigned long rt288x_wdt_freq;
48static void __iomem *rt288x_wdt_base;
49
50static bool nowayout = WATCHDOG_NOWAYOUT;
51module_param(nowayout, bool, 0);
52MODULE_PARM_DESC(nowayout,
53 "Watchdog cannot be stopped once started (default="
54 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
55
56static inline void rt_wdt_w32(unsigned reg, u32 val)
57{
58 iowrite32(val, rt288x_wdt_base + reg);
59}
60
61static inline u32 rt_wdt_r32(unsigned reg)
62{
63 return ioread32(rt288x_wdt_base + reg);
64}
65
66static int rt288x_wdt_ping(struct watchdog_device *w)
67{
68 rt_wdt_w32(TIMER_REG_TMR1LOAD, w->timeout * rt288x_wdt_freq);
69
70 return 0;
71}
72
73static int rt288x_wdt_start(struct watchdog_device *w)
74{
75 u32 t;
76
77 t = rt_wdt_r32(TIMER_REG_TMR1CTL);
78 t &= ~(TMR1CTL_MODE_MASK << TMR1CTL_MODE_SHIFT |
79 TMR1CTL_PRESCALE_MASK);
80 t |= (TMR1CTL_MODE_WDT << TMR1CTL_MODE_SHIFT |
81 TMR1CTL_PRESCALE_65536);
82 rt_wdt_w32(TIMER_REG_TMR1CTL, t);
83
84 rt288x_wdt_ping(w);
85
86 t = rt_wdt_r32(TIMER_REG_TMR1CTL);
87 t |= TMR1CTL_ENABLE;
88 rt_wdt_w32(TIMER_REG_TMR1CTL, t);
89
90 return 0;
91}
92
93static int rt288x_wdt_stop(struct watchdog_device *w)
94{
95 u32 t;
96
97 rt288x_wdt_ping(w);
98
99 t = rt_wdt_r32(TIMER_REG_TMR1CTL);
100 t &= ~TMR1CTL_ENABLE;
101 rt_wdt_w32(TIMER_REG_TMR1CTL, t);
102
103 return 0;
104}
105
106static int rt288x_wdt_set_timeout(struct watchdog_device *w, unsigned int t)
107{
108 w->timeout = t;
109 rt288x_wdt_ping(w);
110
111 return 0;
112}
113
114static int rt288x_wdt_bootcause(void)
115{
116 if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE)
117 return WDIOF_CARDRESET;
118
119 return 0;
120}
121
122static struct watchdog_info rt288x_wdt_info = {
123 .identity = "Ralink Watchdog",
124 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
125};
126
127static struct watchdog_ops rt288x_wdt_ops = {
128 .owner = THIS_MODULE,
129 .start = rt288x_wdt_start,
130 .stop = rt288x_wdt_stop,
131 .ping = rt288x_wdt_ping,
132 .set_timeout = rt288x_wdt_set_timeout,
133};
134
135static struct watchdog_device rt288x_wdt_dev = {
136 .info = &rt288x_wdt_info,
137 .ops = &rt288x_wdt_ops,
138 .min_timeout = 1,
139};
140
141static int rt288x_wdt_probe(struct platform_device *pdev)
142{
143 struct resource *res;
144 int ret;
145
146 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
147 rt288x_wdt_base = devm_ioremap_resource(&pdev->dev, res);
148 if (IS_ERR(rt288x_wdt_base))
149 return PTR_ERR(rt288x_wdt_base);
150
151 rt288x_wdt_clk = devm_clk_get(&pdev->dev, NULL);
152 if (IS_ERR(rt288x_wdt_clk))
153 return PTR_ERR(rt288x_wdt_clk);
154
155 device_reset(&pdev->dev);
156
157 rt288x_wdt_freq = clk_get_rate(rt288x_wdt_clk) / RALINK_WDT_PRESCALE;
158
159 rt288x_wdt_dev.dev = &pdev->dev;
160 rt288x_wdt_dev.bootstatus = rt288x_wdt_bootcause();
161
162 rt288x_wdt_dev.max_timeout = (0xfffful / rt288x_wdt_freq);
163 rt288x_wdt_dev.timeout = rt288x_wdt_dev.max_timeout;
164
165 watchdog_set_nowayout(&rt288x_wdt_dev, nowayout);
166
167 ret = watchdog_register_device(&rt288x_wdt_dev);
168 if (!ret)
169 dev_info(&pdev->dev, "Initialized\n");
170
171 return 0;
172}
173
174static int rt288x_wdt_remove(struct platform_device *pdev)
175{
176 watchdog_unregister_device(&rt288x_wdt_dev);
177
178 return 0;
179}
180
181static void rt288x_wdt_shutdown(struct platform_device *pdev)
182{
183 rt288x_wdt_stop(&rt288x_wdt_dev);
184}
185
186static const struct of_device_id rt288x_wdt_match[] = {
187 { .compatible = "ralink,rt2880-wdt" },
188 {},
189};
190MODULE_DEVICE_TABLE(of, rt288x_wdt_match);
191
192static struct platform_driver rt288x_wdt_driver = {
193 .probe = rt288x_wdt_probe,
194 .remove = rt288x_wdt_remove,
195 .shutdown = rt288x_wdt_shutdown,
196 .driver = {
197 .name = KBUILD_MODNAME,
198 .owner = THIS_MODULE,
199 .of_match_table = rt288x_wdt_match,
200 },
201};
202
203module_platform_driver(rt288x_wdt_driver);
204
205MODULE_DESCRIPTION("MediaTek/Ralink RT288x/RT3xxx hardware watchdog driver");
206MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org");
207MODULE_LICENSE("GPL v2");
diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
index 23aad7c6bf5d..7d8fd041ee25 100644
--- a/drivers/watchdog/s3c2410_wdt.c
+++ b/drivers/watchdog/s3c2410_wdt.c
@@ -29,7 +29,6 @@
29#include <linux/moduleparam.h> 29#include <linux/moduleparam.h>
30#include <linux/types.h> 30#include <linux/types.h>
31#include <linux/timer.h> 31#include <linux/timer.h>
32#include <linux/miscdevice.h> /* for MODULE_ALIAS_MISCDEV */
33#include <linux/watchdog.h> 32#include <linux/watchdog.h>
34#include <linux/init.h> 33#include <linux/init.h>
35#include <linux/platform_device.h> 34#include <linux/platform_device.h>
@@ -539,5 +538,4 @@ MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, "
539 "Dimitry Andric <dimitry.andric@tomtom.com>"); 538 "Dimitry Andric <dimitry.andric@tomtom.com>");
540MODULE_DESCRIPTION("S3C2410 Watchdog Device Driver"); 539MODULE_DESCRIPTION("S3C2410 Watchdog Device Driver");
541MODULE_LICENSE("GPL"); 540MODULE_LICENSE("GPL");
542MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
543MODULE_ALIAS("platform:s3c2410-wdt"); 541MODULE_ALIAS("platform:s3c2410-wdt");
diff --git a/drivers/watchdog/sa1100_wdt.c b/drivers/watchdog/sa1100_wdt.c
index ccd6b29e21bf..e1d39a1e9628 100644
--- a/drivers/watchdog/sa1100_wdt.c
+++ b/drivers/watchdog/sa1100_wdt.c
@@ -193,4 +193,3 @@ module_param(margin, int, 0);
193MODULE_PARM_DESC(margin, "Watchdog margin in seconds (default 60s)"); 193MODULE_PARM_DESC(margin, "Watchdog margin in seconds (default 60s)");
194 194
195MODULE_LICENSE("GPL"); 195MODULE_LICENSE("GPL");
196MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/sb_wdog.c b/drivers/watchdog/sb_wdog.c
index ea5d84a1fdad..3abae50773b8 100644
--- a/drivers/watchdog/sb_wdog.c
+++ b/drivers/watchdog/sb_wdog.c
@@ -341,7 +341,6 @@ MODULE_PARM_DESC(timeout,
341 "Watchdog timeout in microseconds (max/default 8388607 or 8.3ish secs)"); 341 "Watchdog timeout in microseconds (max/default 8388607 or 8.3ish secs)");
342 342
343MODULE_LICENSE("GPL"); 343MODULE_LICENSE("GPL");
344MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
345 344
346/* 345/*
347 * example code that can be put in a platform code area to utilize the 346 * example code that can be put in a platform code area to utilize the
diff --git a/drivers/watchdog/sbc60xxwdt.c b/drivers/watchdog/sbc60xxwdt.c
index 63632ec87c7e..2eef58a0cf05 100644
--- a/drivers/watchdog/sbc60xxwdt.c
+++ b/drivers/watchdog/sbc60xxwdt.c
@@ -387,4 +387,3 @@ module_exit(sbc60xxwdt_unload);
387MODULE_AUTHOR("Jakob Oestergaard <jakob@unthought.net>"); 387MODULE_AUTHOR("Jakob Oestergaard <jakob@unthought.net>");
388MODULE_DESCRIPTION("60xx Single Board Computer Watchdog Timer driver"); 388MODULE_DESCRIPTION("60xx Single Board Computer Watchdog Timer driver");
389MODULE_LICENSE("GPL"); 389MODULE_LICENSE("GPL");
390MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/sbc7240_wdt.c b/drivers/watchdog/sbc7240_wdt.c
index 719edc8fdeb3..5f268add17ce 100644
--- a/drivers/watchdog/sbc7240_wdt.c
+++ b/drivers/watchdog/sbc7240_wdt.c
@@ -309,5 +309,3 @@ MODULE_AUTHOR("Gilles Gigan");
309MODULE_DESCRIPTION("Watchdog device driver for single board" 309MODULE_DESCRIPTION("Watchdog device driver for single board"
310 " computers EPIC Nano 7240 from iEi"); 310 " computers EPIC Nano 7240 from iEi");
311MODULE_LICENSE("GPL"); 311MODULE_LICENSE("GPL");
312MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
313
diff --git a/drivers/watchdog/sbc8360.c b/drivers/watchdog/sbc8360.c
index d4781e05f017..da60560ca446 100644
--- a/drivers/watchdog/sbc8360.c
+++ b/drivers/watchdog/sbc8360.c
@@ -404,6 +404,5 @@ MODULE_AUTHOR("Ian E. Morgan <imorgan@webcon.ca>");
404MODULE_DESCRIPTION("SBC8360 watchdog driver"); 404MODULE_DESCRIPTION("SBC8360 watchdog driver");
405MODULE_LICENSE("GPL"); 405MODULE_LICENSE("GPL");
406MODULE_VERSION("1.01"); 406MODULE_VERSION("1.01");
407MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
408 407
409/* end of sbc8360.c */ 408/* end of sbc8360.c */
diff --git a/drivers/watchdog/sbc_epx_c3.c b/drivers/watchdog/sbc_epx_c3.c
index 0c3e9f66ef77..a1c502e0d8ec 100644
--- a/drivers/watchdog/sbc_epx_c3.c
+++ b/drivers/watchdog/sbc_epx_c3.c
@@ -220,4 +220,3 @@ MODULE_DESCRIPTION("Hardware Watchdog Device for Winsystems EPX-C3 SBC. "
220 "so only use it if you are *sure* you are running on this specific " 220 "so only use it if you are *sure* you are running on this specific "
221 "SBC system from Winsystems! It writes to IO ports 0x1ee and 0x1ef!"); 221 "SBC system from Winsystems! It writes to IO ports 0x1ee and 0x1ef!");
222MODULE_LICENSE("GPL"); 222MODULE_LICENSE("GPL");
223MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/sbc_fitpc2_wdt.c b/drivers/watchdog/sbc_fitpc2_wdt.c
index 90d5527ca886..a517d8bae757 100644
--- a/drivers/watchdog/sbc_fitpc2_wdt.c
+++ b/drivers/watchdog/sbc_fitpc2_wdt.c
@@ -263,5 +263,3 @@ module_param(nowayout, bool, 0);
263MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started"); 263MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
264 264
265MODULE_LICENSE("GPL"); 265MODULE_LICENSE("GPL");
266MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
267
diff --git a/drivers/watchdog/sc1200wdt.c b/drivers/watchdog/sc1200wdt.c
index 3fb83b0c28c2..3b9fff9dcf65 100644
--- a/drivers/watchdog/sc1200wdt.c
+++ b/drivers/watchdog/sc1200wdt.c
@@ -476,4 +476,3 @@ MODULE_AUTHOR("Zwane Mwaikambo <zwane@commfireservices.com>");
476MODULE_DESCRIPTION( 476MODULE_DESCRIPTION(
477 "Driver for National Semiconductor PC87307/PC97307 watchdog component"); 477 "Driver for National Semiconductor PC87307/PC97307 watchdog component");
478MODULE_LICENSE("GPL"); 478MODULE_LICENSE("GPL");
479MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/sc520_wdt.c b/drivers/watchdog/sc520_wdt.c
index 707e027e5002..f353e18b1a82 100644
--- a/drivers/watchdog/sc520_wdt.c
+++ b/drivers/watchdog/sc520_wdt.c
@@ -433,4 +433,3 @@ MODULE_AUTHOR("Scott and Bill Jennings");
433MODULE_DESCRIPTION( 433MODULE_DESCRIPTION(
434 "Driver for watchdog timer in AMD \"Elan\" SC520 uProcessor"); 434 "Driver for watchdog timer in AMD \"Elan\" SC520 uProcessor");
435MODULE_LICENSE("GPL"); 435MODULE_LICENSE("GPL");
436MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/sch311x_wdt.c b/drivers/watchdog/sch311x_wdt.c
index af7b136b1874..b96127ea3de1 100644
--- a/drivers/watchdog/sch311x_wdt.c
+++ b/drivers/watchdog/sch311x_wdt.c
@@ -26,8 +26,7 @@
26#include <linux/types.h> /* For standard types (like size_t) */ 26#include <linux/types.h> /* For standard types (like size_t) */
27#include <linux/errno.h> /* For the -ENODEV/... values */ 27#include <linux/errno.h> /* For the -ENODEV/... values */
28#include <linux/kernel.h> /* For printk/... */ 28#include <linux/kernel.h> /* For printk/... */
29#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV 29#include <linux/miscdevice.h> /* For struct miscdevice */
30 (WATCHDOG_MINOR) */
31#include <linux/watchdog.h> /* For the watchdog specific items */ 30#include <linux/watchdog.h> /* For the watchdog specific items */
32#include <linux/init.h> /* For __init/__exit/... */ 31#include <linux/init.h> /* For __init/__exit/... */
33#include <linux/fs.h> /* For file operations */ 32#include <linux/fs.h> /* For file operations */
@@ -545,5 +544,3 @@ module_exit(sch311x_wdt_exit);
545MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>"); 544MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
546MODULE_DESCRIPTION("SMSC SCH311x WatchDog Timer Driver"); 545MODULE_DESCRIPTION("SMSC SCH311x WatchDog Timer Driver");
547MODULE_LICENSE("GPL"); 546MODULE_LICENSE("GPL");
548MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
549
diff --git a/drivers/watchdog/scx200_wdt.c b/drivers/watchdog/scx200_wdt.c
index 8ae7c282d465..836377cf9271 100644
--- a/drivers/watchdog/scx200_wdt.c
+++ b/drivers/watchdog/scx200_wdt.c
@@ -37,7 +37,6 @@
37MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>"); 37MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
38MODULE_DESCRIPTION("NatSemi SCx200 Watchdog Driver"); 38MODULE_DESCRIPTION("NatSemi SCx200 Watchdog Driver");
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
41 40
42static int margin = 60; /* in seconds */ 41static int margin = 60; /* in seconds */
43module_param(margin, int, 0); 42module_param(margin, int, 0);
diff --git a/drivers/watchdog/shwdt.c b/drivers/watchdog/shwdt.c
index 5bca79457768..f9b8e06f3558 100644
--- a/drivers/watchdog/shwdt.c
+++ b/drivers/watchdog/shwdt.c
@@ -343,7 +343,6 @@ MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>");
343MODULE_DESCRIPTION("SuperH watchdog driver"); 343MODULE_DESCRIPTION("SuperH watchdog driver");
344MODULE_LICENSE("GPL"); 344MODULE_LICENSE("GPL");
345MODULE_ALIAS("platform:" DRV_NAME); 345MODULE_ALIAS("platform:" DRV_NAME);
346MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
347 346
348module_param(clock_division_ratio, int, 0); 347module_param(clock_division_ratio, int, 0);
349MODULE_PARM_DESC(clock_division_ratio, 348MODULE_PARM_DESC(clock_division_ratio,
diff --git a/drivers/watchdog/sirfsoc_wdt.c b/drivers/watchdog/sirfsoc_wdt.c
new file mode 100644
index 000000000000..ced3edc95957
--- /dev/null
+++ b/drivers/watchdog/sirfsoc_wdt.c
@@ -0,0 +1,226 @@
1/*
2 * Watchdog driver for CSR SiRFprimaII and SiRFatlasVI
3 *
4 * Copyright (c) 2013 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8
9#include <linux/module.h>
10#include <linux/watchdog.h>
11#include <linux/platform_device.h>
12#include <linux/moduleparam.h>
13#include <linux/of.h>
14#include <linux/io.h>
15#include <linux/uaccess.h>
16
17#define CLOCK_FREQ 1000000
18
19#define SIRFSOC_TIMER_COUNTER_LO 0x0000
20#define SIRFSOC_TIMER_MATCH_0 0x0008
21#define SIRFSOC_TIMER_INT_EN 0x0024
22#define SIRFSOC_TIMER_WATCHDOG_EN 0x0028
23#define SIRFSOC_TIMER_LATCH 0x0030
24#define SIRFSOC_TIMER_LATCHED_LO 0x0034
25
26#define SIRFSOC_TIMER_WDT_INDEX 5
27
28#define SIRFSOC_WDT_MIN_TIMEOUT 30 /* 30 secs */
29#define SIRFSOC_WDT_MAX_TIMEOUT (10 * 60) /* 10 mins */
30#define SIRFSOC_WDT_DEFAULT_TIMEOUT 30 /* 30 secs */
31
32static unsigned int timeout = SIRFSOC_WDT_DEFAULT_TIMEOUT;
33static bool nowayout = WATCHDOG_NOWAYOUT;
34
35module_param(timeout, uint, 0);
36module_param(nowayout, bool, 0);
37
38MODULE_PARM_DESC(timeout, "Default watchdog timeout (in seconds)");
39MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
40 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
41
42static unsigned int sirfsoc_wdt_gettimeleft(struct watchdog_device *wdd)
43{
44 u32 counter, match;
45 void __iomem *wdt_base;
46 int time_left;
47
48 wdt_base = watchdog_get_drvdata(wdd);
49 counter = readl(wdt_base + SIRFSOC_TIMER_COUNTER_LO);
50 match = readl(wdt_base +
51 SIRFSOC_TIMER_MATCH_0 + (SIRFSOC_TIMER_WDT_INDEX << 2));
52
53 time_left = match - counter;
54
55 return time_left / CLOCK_FREQ;
56}
57
58static int sirfsoc_wdt_updatetimeout(struct watchdog_device *wdd)
59{
60 u32 counter, timeout_ticks;
61 void __iomem *wdt_base;
62
63 timeout_ticks = wdd->timeout * CLOCK_FREQ;
64 wdt_base = watchdog_get_drvdata(wdd);
65
66 /* Enable the latch before reading the LATCH_LO register */
67 writel(1, wdt_base + SIRFSOC_TIMER_LATCH);
68
69 /* Set the TO value */
70 counter = readl(wdt_base + SIRFSOC_TIMER_LATCHED_LO);
71
72 counter += timeout_ticks;
73
74 writel(counter, wdt_base +
75 SIRFSOC_TIMER_MATCH_0 + (SIRFSOC_TIMER_WDT_INDEX << 2));
76
77 return 0;
78}
79
80static int sirfsoc_wdt_enable(struct watchdog_device *wdd)
81{
82 void __iomem *wdt_base = watchdog_get_drvdata(wdd);
83 sirfsoc_wdt_updatetimeout(wdd);
84
85 /*
86 * NOTE: If interrupt is not enabled
87 * then WD-Reset doesn't get generated at all.
88 */
89 writel(readl(wdt_base + SIRFSOC_TIMER_INT_EN)
90 | (1 << SIRFSOC_TIMER_WDT_INDEX),
91 wdt_base + SIRFSOC_TIMER_INT_EN);
92 writel(1, wdt_base + SIRFSOC_TIMER_WATCHDOG_EN);
93
94 return 0;
95}
96
97static int sirfsoc_wdt_disable(struct watchdog_device *wdd)
98{
99 void __iomem *wdt_base = watchdog_get_drvdata(wdd);
100
101 writel(0, wdt_base + SIRFSOC_TIMER_WATCHDOG_EN);
102 writel(readl(wdt_base + SIRFSOC_TIMER_INT_EN)
103 & (~(1 << SIRFSOC_TIMER_WDT_INDEX)),
104 wdt_base + SIRFSOC_TIMER_INT_EN);
105
106 return 0;
107}
108
109static int sirfsoc_wdt_settimeout(struct watchdog_device *wdd, unsigned int to)
110{
111 wdd->timeout = to;
112 sirfsoc_wdt_updatetimeout(wdd);
113
114 return 0;
115}
116
117#define OPTIONS (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE)
118
119static const struct watchdog_info sirfsoc_wdt_ident = {
120 .options = OPTIONS,
121 .firmware_version = 0,
122 .identity = "SiRFSOC Watchdog",
123};
124
125static struct watchdog_ops sirfsoc_wdt_ops = {
126 .owner = THIS_MODULE,
127 .start = sirfsoc_wdt_enable,
128 .stop = sirfsoc_wdt_disable,
129 .get_timeleft = sirfsoc_wdt_gettimeleft,
130 .ping = sirfsoc_wdt_updatetimeout,
131 .set_timeout = sirfsoc_wdt_settimeout,
132};
133
134static struct watchdog_device sirfsoc_wdd = {
135 .info = &sirfsoc_wdt_ident,
136 .ops = &sirfsoc_wdt_ops,
137 .timeout = SIRFSOC_WDT_DEFAULT_TIMEOUT,
138 .min_timeout = SIRFSOC_WDT_MIN_TIMEOUT,
139 .max_timeout = SIRFSOC_WDT_MAX_TIMEOUT,
140};
141
142static int sirfsoc_wdt_probe(struct platform_device *pdev)
143{
144 struct resource *res;
145 int ret;
146 void __iomem *base;
147
148 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
149 base = devm_ioremap_resource(&pdev->dev, res);
150 if (IS_ERR(base))
151 return PTR_ERR(base);
152
153 watchdog_set_drvdata(&sirfsoc_wdd, base);
154
155 watchdog_init_timeout(&sirfsoc_wdd, timeout, &pdev->dev);
156 watchdog_set_nowayout(&sirfsoc_wdd, nowayout);
157
158 ret = watchdog_register_device(&sirfsoc_wdd);
159 if (ret)
160 return ret;
161
162 platform_set_drvdata(pdev, &sirfsoc_wdd);
163
164 return 0;
165}
166
167static void sirfsoc_wdt_shutdown(struct platform_device *pdev)
168{
169 struct watchdog_device *wdd = platform_get_drvdata(pdev);
170
171 sirfsoc_wdt_disable(wdd);
172}
173
174static int sirfsoc_wdt_remove(struct platform_device *pdev)
175{
176 sirfsoc_wdt_shutdown(pdev);
177 return 0;
178}
179
180#ifdef CONFIG_PM_SLEEP
181static int sirfsoc_wdt_suspend(struct device *dev)
182{
183 return 0;
184}
185
186static int sirfsoc_wdt_resume(struct device *dev)
187{
188 struct watchdog_device *wdd = dev_get_drvdata(dev);
189
190 /*
191 * NOTE: Since timer controller registers settings are saved
192 * and restored back by the timer-prima2.c, so we need not
193 * update WD settings except refreshing timeout.
194 */
195 sirfsoc_wdt_updatetimeout(wdd);
196
197 return 0;
198}
199#endif
200
201static SIMPLE_DEV_PM_OPS(sirfsoc_wdt_pm_ops,
202 sirfsoc_wdt_suspend, sirfsoc_wdt_resume);
203
204static const struct of_device_id sirfsoc_wdt_of_match[] = {
205 { .compatible = "sirf,prima2-tick"},
206 {},
207};
208MODULE_DEVICE_TABLE(of, sirfsoc_wdt_of_match);
209
210static struct platform_driver sirfsoc_wdt_driver = {
211 .driver = {
212 .name = "sirfsoc-wdt",
213 .owner = THIS_MODULE,
214 .pm = &sirfsoc_wdt_pm_ops,
215 .of_match_table = of_match_ptr(sirfsoc_wdt_of_match),
216 },
217 .probe = sirfsoc_wdt_probe,
218 .remove = sirfsoc_wdt_remove,
219 .shutdown = sirfsoc_wdt_shutdown,
220};
221module_platform_driver(sirfsoc_wdt_driver);
222
223MODULE_DESCRIPTION("SiRF SoC watchdog driver");
224MODULE_AUTHOR("Xianglong Du <Xianglong.Du@csr.com>");
225MODULE_LICENSE("GPL v2");
226MODULE_ALIAS("platform:sirfsoc-wdt");
diff --git a/drivers/watchdog/smsc37b787_wdt.c b/drivers/watchdog/smsc37b787_wdt.c
index 6d665f9c1d58..445ea1ad1fa9 100644
--- a/drivers/watchdog/smsc37b787_wdt.c
+++ b/drivers/watchdog/smsc37b787_wdt.c
@@ -603,8 +603,6 @@ MODULE_DESCRIPTION("Driver for SMsC 37B787 watchdog component (Version "
603 VERSION ")"); 603 VERSION ")");
604MODULE_LICENSE("GPL"); 604MODULE_LICENSE("GPL");
605 605
606MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
607
608#ifdef SMSC_SUPPORT_MINUTES 606#ifdef SMSC_SUPPORT_MINUTES
609module_param(unit, int, 0); 607module_param(unit, int, 0);
610MODULE_PARM_DESC(unit, 608MODULE_PARM_DESC(unit,
diff --git a/drivers/watchdog/softdog.c b/drivers/watchdog/softdog.c
index b68b1e519d53..ef2638fee4a8 100644
--- a/drivers/watchdog/softdog.c
+++ b/drivers/watchdog/softdog.c
@@ -207,4 +207,3 @@ module_exit(watchdog_exit);
207MODULE_AUTHOR("Alan Cox"); 207MODULE_AUTHOR("Alan Cox");
208MODULE_DESCRIPTION("Software Watchdog Device Driver"); 208MODULE_DESCRIPTION("Software Watchdog Device Driver");
209MODULE_LICENSE("GPL"); 209MODULE_LICENSE("GPL");
210MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c
index 0e9d8c479c35..ce63a1bbf395 100644
--- a/drivers/watchdog/sp5100_tco.c
+++ b/drivers/watchdog/sp5100_tco.c
@@ -580,4 +580,3 @@ module_exit(sp5100_tco_cleanup_module);
580MODULE_AUTHOR("Priyanka Gupta"); 580MODULE_AUTHOR("Priyanka Gupta");
581MODULE_DESCRIPTION("TCO timer driver for SP5100/SB800 chipset"); 581MODULE_DESCRIPTION("TCO timer driver for SP5100/SB800 chipset");
582MODULE_LICENSE("GPL"); 582MODULE_LICENSE("GPL");
583MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/sp805_wdt.c b/drivers/watchdog/sp805_wdt.c
index 58df98aec122..3f786ce0a6f2 100644
--- a/drivers/watchdog/sp805_wdt.c
+++ b/drivers/watchdog/sp805_wdt.c
@@ -268,7 +268,6 @@ static int sp805_wdt_remove(struct amba_device *adev)
268 struct sp805_wdt *wdt = amba_get_drvdata(adev); 268 struct sp805_wdt *wdt = amba_get_drvdata(adev);
269 269
270 watchdog_unregister_device(&wdt->wdd); 270 watchdog_unregister_device(&wdt->wdd);
271 amba_set_drvdata(adev, NULL);
272 watchdog_set_drvdata(&wdt->wdd, NULL); 271 watchdog_set_drvdata(&wdt->wdd, NULL);
273 272
274 return 0; 273 return 0;
diff --git a/drivers/watchdog/stmp3xxx_rtc_wdt.c b/drivers/watchdog/stmp3xxx_rtc_wdt.c
index c97e98dcde62..d667f6b51d35 100644
--- a/drivers/watchdog/stmp3xxx_rtc_wdt.c
+++ b/drivers/watchdog/stmp3xxx_rtc_wdt.c
@@ -30,7 +30,7 @@ MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat period in seconds from 1 to "
30static int wdt_start(struct watchdog_device *wdd) 30static int wdt_start(struct watchdog_device *wdd)
31{ 31{
32 struct device *dev = watchdog_get_drvdata(wdd); 32 struct device *dev = watchdog_get_drvdata(wdd);
33 struct stmp3xxx_wdt_pdata *pdata = dev->platform_data; 33 struct stmp3xxx_wdt_pdata *pdata = dev_get_platdata(dev);
34 34
35 pdata->wdt_set_timeout(dev->parent, wdd->timeout * WDOG_TICK_RATE); 35 pdata->wdt_set_timeout(dev->parent, wdd->timeout * WDOG_TICK_RATE);
36 return 0; 36 return 0;
@@ -39,7 +39,7 @@ static int wdt_start(struct watchdog_device *wdd)
39static int wdt_stop(struct watchdog_device *wdd) 39static int wdt_stop(struct watchdog_device *wdd)
40{ 40{
41 struct device *dev = watchdog_get_drvdata(wdd); 41 struct device *dev = watchdog_get_drvdata(wdd);
42 struct stmp3xxx_wdt_pdata *pdata = dev->platform_data; 42 struct stmp3xxx_wdt_pdata *pdata = dev_get_platdata(dev);
43 43
44 pdata->wdt_set_timeout(dev->parent, 0); 44 pdata->wdt_set_timeout(dev->parent, 0);
45 return 0; 45 return 0;
@@ -108,4 +108,3 @@ module_platform_driver(stmp3xxx_wdt_driver);
108MODULE_DESCRIPTION("STMP3XXX RTC Watchdog Driver"); 108MODULE_DESCRIPTION("STMP3XXX RTC Watchdog Driver");
109MODULE_LICENSE("GPL v2"); 109MODULE_LICENSE("GPL v2");
110MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>"); 110MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>");
111MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/sunxi_wdt.c b/drivers/watchdog/sunxi_wdt.c
index f6caa77151c7..76332d893e12 100644
--- a/drivers/watchdog/sunxi_wdt.c
+++ b/drivers/watchdog/sunxi_wdt.c
@@ -217,7 +217,7 @@ static struct platform_driver sunxi_wdt_driver = {
217 .driver = { 217 .driver = {
218 .owner = THIS_MODULE, 218 .owner = THIS_MODULE,
219 .name = DRV_NAME, 219 .name = DRV_NAME,
220 .of_match_table = of_match_ptr(sunxi_wdt_dt_ids) 220 .of_match_table = sunxi_wdt_dt_ids,
221 }, 221 },
222}; 222};
223 223
diff --git a/drivers/watchdog/ts72xx_wdt.c b/drivers/watchdog/ts72xx_wdt.c
index c9b0c627fe7e..09d4831aa61f 100644
--- a/drivers/watchdog/ts72xx_wdt.c
+++ b/drivers/watchdog/ts72xx_wdt.c
@@ -192,7 +192,7 @@ static int ts72xx_wdt_open(struct inode *inode, struct file *file)
192 dev_err(&wdt->pdev->dev, 192 dev_err(&wdt->pdev->dev,
193 "failed to convert timeout (%d) to register value\n", 193 "failed to convert timeout (%d) to register value\n",
194 timeout); 194 timeout);
195 return -EINVAL; 195 return regval;
196 } 196 }
197 197
198 if (mutex_lock_interruptible(&wdt->lock)) 198 if (mutex_lock_interruptible(&wdt->lock))
@@ -305,7 +305,8 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd,
305 305
306 switch (cmd) { 306 switch (cmd) {
307 case WDIOC_GETSUPPORT: 307 case WDIOC_GETSUPPORT:
308 error = copy_to_user(argp, &winfo, sizeof(winfo)); 308 if (copy_to_user(argp, &winfo, sizeof(winfo)))
309 error = -EFAULT;
309 break; 310 break;
310 311
311 case WDIOC_GETSTATUS: 312 case WDIOC_GETSTATUS:
@@ -320,10 +321,9 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd,
320 case WDIOC_SETOPTIONS: { 321 case WDIOC_SETOPTIONS: {
321 int options; 322 int options;
322 323
323 if (get_user(options, p)) { 324 error = get_user(options, p);
324 error = -EFAULT; 325 if (error)
325 break; 326 break;
326 }
327 327
328 error = -EINVAL; 328 error = -EINVAL;
329 329
@@ -341,30 +341,26 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd,
341 341
342 case WDIOC_SETTIMEOUT: { 342 case WDIOC_SETTIMEOUT: {
343 int new_timeout; 343 int new_timeout;
344 int regval;
344 345
345 if (get_user(new_timeout, p)) { 346 error = get_user(new_timeout, p);
346 error = -EFAULT;
347 } else {
348 int regval;
349
350 regval = timeout_to_regval(new_timeout);
351 if (regval < 0) {
352 error = -EINVAL;
353 } else {
354 ts72xx_wdt_stop(wdt);
355 wdt->regval = regval;
356 ts72xx_wdt_start(wdt);
357 }
358 }
359 if (error) 347 if (error)
360 break; 348 break;
361 349
350 regval = timeout_to_regval(new_timeout);
351 if (regval < 0) {
352 error = regval;
353 break;
354 }
355 ts72xx_wdt_stop(wdt);
356 wdt->regval = regval;
357 ts72xx_wdt_start(wdt);
358
362 /*FALLTHROUGH*/ 359 /*FALLTHROUGH*/
363 } 360 }
364 361
365 case WDIOC_GETTIMEOUT: 362 case WDIOC_GETTIMEOUT:
366 if (put_user(regval_to_timeout(wdt->regval), p)) 363 error = put_user(regval_to_timeout(wdt->regval), p);
367 error = -EFAULT;
368 break; 364 break;
369 365
370 default: 366 default:
diff --git a/drivers/watchdog/txx9wdt.c b/drivers/watchdog/txx9wdt.c
index 88f23c5cfddb..0fd0e8ae62a8 100644
--- a/drivers/watchdog/txx9wdt.c
+++ b/drivers/watchdog/txx9wdt.c
@@ -176,5 +176,4 @@ module_platform_driver_probe(txx9wdt_driver, txx9wdt_probe);
176 176
177MODULE_DESCRIPTION("TXx9 Watchdog Driver"); 177MODULE_DESCRIPTION("TXx9 Watchdog Driver");
178MODULE_LICENSE("GPL"); 178MODULE_LICENSE("GPL");
179MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
180MODULE_ALIAS("platform:txx9wdt"); 179MODULE_ALIAS("platform:txx9wdt");
diff --git a/drivers/watchdog/ux500_wdt.c b/drivers/watchdog/ux500_wdt.c
index a614d84121c3..e029b5768f2c 100644
--- a/drivers/watchdog/ux500_wdt.c
+++ b/drivers/watchdog/ux500_wdt.c
@@ -88,7 +88,7 @@ static struct watchdog_device ux500_wdt = {
88static int ux500_wdt_probe(struct platform_device *pdev) 88static int ux500_wdt_probe(struct platform_device *pdev)
89{ 89{
90 int ret; 90 int ret;
91 struct ux500_wdt_data *pdata = pdev->dev.platform_data; 91 struct ux500_wdt_data *pdata = dev_get_platdata(&pdev->dev);
92 92
93 if (pdata) { 93 if (pdata) {
94 if (pdata->timeout > 0) 94 if (pdata->timeout > 0)
@@ -167,5 +167,4 @@ module_platform_driver(ux500_wdt_driver);
167MODULE_AUTHOR("Jonas Aaberg <jonas.aberg@stericsson.com>"); 167MODULE_AUTHOR("Jonas Aaberg <jonas.aberg@stericsson.com>");
168MODULE_DESCRIPTION("Ux500 Watchdog Driver"); 168MODULE_DESCRIPTION("Ux500 Watchdog Driver");
169MODULE_LICENSE("GPL"); 169MODULE_LICENSE("GPL");
170MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
171MODULE_ALIAS("platform:ux500_wdt"); 170MODULE_ALIAS("platform:ux500_wdt");
diff --git a/drivers/watchdog/w83627hf_wdt.c b/drivers/watchdog/w83627hf_wdt.c
index 92f1326f0cfc..e24b21082874 100644
--- a/drivers/watchdog/w83627hf_wdt.c
+++ b/drivers/watchdog/w83627hf_wdt.c
@@ -1,6 +1,9 @@
1/* 1/*
2 * w83627hf/thf WDT driver 2 * w83627hf/thf WDT driver
3 * 3 *
4 * (c) Copyright 2013 Guenter Roeck
5 * converted to watchdog infrastructure
6 *
4 * (c) Copyright 2007 Vlad Drukker <vlad@storewiz.com> 7 * (c) Copyright 2007 Vlad Drukker <vlad@storewiz.com>
5 * added support for W83627THF. 8 * added support for W83627THF.
6 * 9 *
@@ -31,31 +34,22 @@
31#include <linux/module.h> 34#include <linux/module.h>
32#include <linux/moduleparam.h> 35#include <linux/moduleparam.h>
33#include <linux/types.h> 36#include <linux/types.h>
34#include <linux/miscdevice.h>
35#include <linux/watchdog.h> 37#include <linux/watchdog.h>
36#include <linux/fs.h>
37#include <linux/ioport.h> 38#include <linux/ioport.h>
38#include <linux/notifier.h> 39#include <linux/notifier.h>
39#include <linux/reboot.h> 40#include <linux/reboot.h>
40#include <linux/init.h> 41#include <linux/init.h>
41#include <linux/spinlock.h>
42#include <linux/io.h> 42#include <linux/io.h>
43#include <linux/uaccess.h>
44
45 43
46#define WATCHDOG_NAME "w83627hf/thf/hg/dhg WDT" 44#define WATCHDOG_NAME "w83627hf/thf/hg/dhg WDT"
47#define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */ 45#define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */
48 46
49static unsigned long wdt_is_open;
50static char expect_close;
51static DEFINE_SPINLOCK(io_lock);
52
53/* You must set this - there is no sane way to probe for this board. */ 47/* You must set this - there is no sane way to probe for this board. */
54static int wdt_io = 0x2E; 48static int wdt_io = 0x2E;
55module_param(wdt_io, int, 0); 49module_param(wdt_io, int, 0);
56MODULE_PARM_DESC(wdt_io, "w83627hf/thf WDT io port (default 0x2E)"); 50MODULE_PARM_DESC(wdt_io, "w83627hf/thf WDT io port (default 0x2E)");
57 51
58static int timeout = WATCHDOG_TIMEOUT; /* in seconds */ 52static int timeout; /* in seconds */
59module_param(timeout, int, 0); 53module_param(timeout, int, 0);
60MODULE_PARM_DESC(timeout, 54MODULE_PARM_DESC(timeout,
61 "Watchdog timeout in seconds. 1 <= timeout <= 255, default=" 55 "Watchdog timeout in seconds. 1 <= timeout <= 255, default="
@@ -76,236 +70,147 @@ MODULE_PARM_DESC(nowayout,
76 (same as EFER) */ 70 (same as EFER) */
77#define WDT_EFDR (WDT_EFIR+1) /* Extended Function Data Register */ 71#define WDT_EFDR (WDT_EFIR+1) /* Extended Function Data Register */
78 72
79static void w83627hf_select_wd_register(void) 73#define W83627HF_LD_WDT 0x08
74
75static void superio_outb(int reg, int val)
80{ 76{
81 unsigned char c; 77 outb(reg, WDT_EFER);
78 outb(val, WDT_EFDR);
79}
80
81static inline int superio_inb(int reg)
82{
83 outb(reg, WDT_EFER);
84 return inb(WDT_EFDR);
85}
86
87static int superio_enter(void)
88{
89 if (!request_muxed_region(wdt_io, 2, WATCHDOG_NAME))
90 return -EBUSY;
91
82 outb_p(0x87, WDT_EFER); /* Enter extended function mode */ 92 outb_p(0x87, WDT_EFER); /* Enter extended function mode */
83 outb_p(0x87, WDT_EFER); /* Again according to manual */ 93 outb_p(0x87, WDT_EFER); /* Again according to manual */
84 94
85 outb(0x20, WDT_EFER); /* check chip version */ 95 return 0;
86 c = inb(WDT_EFDR); 96}
87 if (c == 0x82) { /* W83627THF */
88 outb_p(0x2b, WDT_EFER); /* select GPIO3 */
89 c = ((inb_p(WDT_EFDR) & 0xf7) | 0x04); /* select WDT0 */
90 outb_p(0x2b, WDT_EFER);
91 outb_p(c, WDT_EFDR); /* set GPIO3 to WDT0 */
92 } else if (c == 0x88 || c == 0xa0) { /* W83627EHF / W83627DHG */
93 outb_p(0x2d, WDT_EFER); /* select GPIO5 */
94 c = inb_p(WDT_EFDR) & ~0x01; /* PIN77 -> WDT0# */
95 outb_p(0x2d, WDT_EFER);
96 outb_p(c, WDT_EFDR); /* set GPIO5 to WDT0 */
97 }
98 97
99 outb_p(0x07, WDT_EFER); /* point to logical device number reg */ 98static void superio_select(int ld)
100 outb_p(0x08, WDT_EFDR); /* select logical device 8 (GPIO2) */ 99{
101 outb_p(0x30, WDT_EFER); /* select CR30 */ 100 superio_outb(0x07, ld);
102 outb_p(0x01, WDT_EFDR); /* set bit 0 to activate GPIO2 */
103} 101}
104 102
105static void w83627hf_unselect_wd_register(void) 103static void superio_exit(void)
106{ 104{
107 outb_p(0xAA, WDT_EFER); /* Leave extended function mode */ 105 outb_p(0xAA, WDT_EFER); /* Leave extended function mode */
106 release_region(wdt_io, 2);
108} 107}
109 108
110/* tyan motherboards seem to set F5 to 0x4C ? 109/* tyan motherboards seem to set F5 to 0x4C ?
111 * So explicitly init to appropriate value. */ 110 * So explicitly init to appropriate value. */
112 111
113static void w83627hf_init(void) 112static int w83627hf_init(struct watchdog_device *wdog)
114{ 113{
114 int ret;
115 unsigned char t; 115 unsigned char t;
116 116
117 w83627hf_select_wd_register(); 117 ret = superio_enter();
118 if (ret)
119 return ret;
120
121 superio_select(W83627HF_LD_WDT);
122 t = superio_inb(0x20); /* check chip version */
123 if (t == 0x82) { /* W83627THF */
124 t = (superio_inb(0x2b) & 0xf7);
125 superio_outb(0x2b, t | 0x04); /* set GPIO3 to WDT0 */
126 } else if (t == 0x88 || t == 0xa0) { /* W83627EHF / W83627DHG */
127 t = superio_inb(0x2d);
128 superio_outb(0x2d, t & ~0x01); /* set GPIO5 to WDT0 */
129 }
130
131 /* set CR30 bit 0 to activate GPIO2 */
132 t = superio_inb(0x30);
133 if (!(t & 0x01))
134 superio_outb(0x30, t | 0x01);
118 135
119 outb_p(0xF6, WDT_EFER); /* Select CRF6 */ 136 t = superio_inb(0xF6);
120 t = inb_p(WDT_EFDR); /* read CRF6 */
121 if (t != 0) { 137 if (t != 0) {
122 pr_info("Watchdog already running. Resetting timeout to %d sec\n", 138 pr_info("Watchdog already running. Resetting timeout to %d sec\n",
123 timeout); 139 wdog->timeout);
124 outb_p(timeout, WDT_EFDR); /* Write back to CRF6 */ 140 superio_outb(0xF6, wdog->timeout);
125 } 141 }
126 142
127 outb_p(0xF5, WDT_EFER); /* Select CRF5 */ 143 /* set second mode & disable keyboard turning off watchdog */
128 t = inb_p(WDT_EFDR); /* read CRF5 */ 144 t = superio_inb(0xF5) & ~0x0C;
129 t &= ~0x0C; /* set second mode & disable keyboard 145 /* enable the WDTO# output low pulse to the KBRST# pin */
130 turning off watchdog */ 146 t |= 0x02;
131 t |= 0x02; /* enable the WDTO# output low pulse 147 superio_outb(0xF5, t);
132 to the KBRST# pin (PIN60) */
133 outb_p(t, WDT_EFDR); /* Write back to CRF5 */
134
135 outb_p(0xF7, WDT_EFER); /* Select CRF7 */
136 t = inb_p(WDT_EFDR); /* read CRF7 */
137 t &= ~0xC0; /* disable keyboard & mouse turning off
138 watchdog */
139 outb_p(t, WDT_EFDR); /* Write back to CRF7 */
140
141 w83627hf_unselect_wd_register();
142}
143
144static void wdt_set_time(int timeout)
145{
146 spin_lock(&io_lock);
147
148 w83627hf_select_wd_register();
149 148
150 outb_p(0xF6, WDT_EFER); /* Select CRF6 */ 149 /* disable keyboard & mouse turning off watchdog */
151 outb_p(timeout, WDT_EFDR); /* Write Timeout counter to CRF6 */ 150 t = superio_inb(0xF7) & ~0xC0;
151 superio_outb(0xF7, t);
152 152
153 w83627hf_unselect_wd_register(); 153 superio_exit();
154 154
155 spin_unlock(&io_lock);
156}
157
158static int wdt_ping(void)
159{
160 wdt_set_time(timeout);
161 return 0; 155 return 0;
162} 156}
163 157
164static int wdt_disable(void) 158static int wdt_set_time(unsigned int timeout)
165{ 159{
166 wdt_set_time(0); 160 int ret;
167 return 0; 161
168} 162 ret = superio_enter();
163 if (ret)
164 return ret;
165
166 superio_select(W83627HF_LD_WDT);
167 superio_outb(0xF6, timeout);
168 superio_exit();
169 169
170static int wdt_set_heartbeat(int t)
171{
172 if (t < 1 || t > 255)
173 return -EINVAL;
174 timeout = t;
175 return 0; 170 return 0;
176} 171}
177 172
178static int wdt_get_time(void) 173static int wdt_start(struct watchdog_device *wdog)
179{ 174{
180 int timeleft; 175 return wdt_set_time(wdog->timeout);
181
182 spin_lock(&io_lock);
183
184 w83627hf_select_wd_register();
185
186 outb_p(0xF6, WDT_EFER); /* Select CRF6 */
187 timeleft = inb_p(WDT_EFDR); /* Read Timeout counter to CRF6 */
188
189 w83627hf_unselect_wd_register();
190
191 spin_unlock(&io_lock);
192
193 return timeleft;
194} 176}
195 177
196static ssize_t wdt_write(struct file *file, const char __user *buf, 178static int wdt_stop(struct watchdog_device *wdog)
197 size_t count, loff_t *ppos)
198{ 179{
199 if (count) { 180 return wdt_set_time(0);
200 if (!nowayout) {
201 size_t i;
202
203 expect_close = 0;
204
205 for (i = 0; i != count; i++) {
206 char c;
207 if (get_user(c, buf + i))
208 return -EFAULT;
209 if (c == 'V')
210 expect_close = 42;
211 }
212 }
213 wdt_ping();
214 }
215 return count;
216} 181}
217 182
218static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 183static int wdt_set_timeout(struct watchdog_device *wdog, unsigned int timeout)
219{ 184{
220 void __user *argp = (void __user *)arg; 185 wdog->timeout = timeout;
221 int __user *p = argp; 186
222 int timeval;
223 static const struct watchdog_info ident = {
224 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
225 WDIOF_MAGICCLOSE,
226 .firmware_version = 1,
227 .identity = "W83627HF WDT",
228 };
229
230 switch (cmd) {
231 case WDIOC_GETSUPPORT:
232 if (copy_to_user(argp, &ident, sizeof(ident)))
233 return -EFAULT;
234 break;
235 case WDIOC_GETSTATUS:
236 case WDIOC_GETBOOTSTATUS:
237 return put_user(0, p);
238 case WDIOC_SETOPTIONS:
239 {
240 int options, retval = -EINVAL;
241
242 if (get_user(options, p))
243 return -EFAULT;
244 if (options & WDIOS_DISABLECARD) {
245 wdt_disable();
246 retval = 0;
247 }
248 if (options & WDIOS_ENABLECARD) {
249 wdt_ping();
250 retval = 0;
251 }
252 return retval;
253 }
254 case WDIOC_KEEPALIVE:
255 wdt_ping();
256 break;
257 case WDIOC_SETTIMEOUT:
258 if (get_user(timeval, p))
259 return -EFAULT;
260 if (wdt_set_heartbeat(timeval))
261 return -EINVAL;
262 wdt_ping();
263 /* Fall */
264 case WDIOC_GETTIMEOUT:
265 return put_user(timeout, p);
266 case WDIOC_GETTIMELEFT:
267 timeval = wdt_get_time();
268 return put_user(timeval, p);
269 default:
270 return -ENOTTY;
271 }
272 return 0; 187 return 0;
273} 188}
274 189
275static int wdt_open(struct inode *inode, struct file *file) 190static unsigned int wdt_get_time(struct watchdog_device *wdog)
276{ 191{
277 if (test_and_set_bit(0, &wdt_is_open)) 192 unsigned int timeleft;
278 return -EBUSY; 193 int ret;
279 /*
280 * Activate
281 */
282 194
283 wdt_ping(); 195 ret = superio_enter();
284 return nonseekable_open(inode, file); 196 if (ret)
285} 197 return 0;
286 198
287static int wdt_close(struct inode *inode, struct file *file) 199 superio_select(W83627HF_LD_WDT);
288{ 200 timeleft = superio_inb(0xF6);
289 if (expect_close == 42) 201 superio_exit();
290 wdt_disable(); 202
291 else { 203 return timeleft;
292 pr_crit("Unexpected close, not stopping watchdog!\n");
293 wdt_ping();
294 }
295 expect_close = 0;
296 clear_bit(0, &wdt_is_open);
297 return 0;
298} 204}
299 205
300/* 206/*
301 * Notifier for system down 207 * Notifier for system down
302 */ 208 */
303
304static int wdt_notify_sys(struct notifier_block *this, unsigned long code, 209static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
305 void *unused) 210 void *unused)
306{ 211{
307 if (code == SYS_DOWN || code == SYS_HALT) 212 if (code == SYS_DOWN || code == SYS_HALT)
308 wdt_disable(); /* Turn the WDT off */ 213 wdt_set_time(0); /* Turn the WDT off */
309 214
310 return NOTIFY_DONE; 215 return NOTIFY_DONE;
311} 216}
@@ -314,19 +219,25 @@ static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
314 * Kernel Interfaces 219 * Kernel Interfaces
315 */ 220 */
316 221
317static const struct file_operations wdt_fops = { 222static struct watchdog_info wdt_info = {
318 .owner = THIS_MODULE, 223 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
319 .llseek = no_llseek, 224 .identity = "W83627HF Watchdog",
320 .write = wdt_write,
321 .unlocked_ioctl = wdt_ioctl,
322 .open = wdt_open,
323 .release = wdt_close,
324}; 225};
325 226
326static struct miscdevice wdt_miscdev = { 227static struct watchdog_ops wdt_ops = {
327 .minor = WATCHDOG_MINOR, 228 .owner = THIS_MODULE,
328 .name = "watchdog", 229 .start = wdt_start,
329 .fops = &wdt_fops, 230 .stop = wdt_stop,
231 .set_timeout = wdt_set_timeout,
232 .get_timeleft = wdt_get_time,
233};
234
235static struct watchdog_device wdt_dev = {
236 .info = &wdt_info,
237 .ops = &wdt_ops,
238 .timeout = WATCHDOG_TIMEOUT,
239 .min_timeout = 1,
240 .max_timeout = 255,
330}; 241};
331 242
332/* 243/*
@@ -344,50 +255,39 @@ static int __init wdt_init(void)
344 255
345 pr_info("WDT driver for the Winbond(TM) W83627HF/THF/HG/DHG Super I/O chip initialising\n"); 256 pr_info("WDT driver for the Winbond(TM) W83627HF/THF/HG/DHG Super I/O chip initialising\n");
346 257
347 if (wdt_set_heartbeat(timeout)) { 258 watchdog_init_timeout(&wdt_dev, timeout, NULL);
348 wdt_set_heartbeat(WATCHDOG_TIMEOUT); 259 watchdog_set_nowayout(&wdt_dev, nowayout);
349 pr_info("timeout value must be 1 <= timeout <= 255, using %d\n",
350 WATCHDOG_TIMEOUT);
351 }
352 260
353 if (!request_region(wdt_io, 1, WATCHDOG_NAME)) { 261 ret = w83627hf_init(&wdt_dev);
354 pr_err("I/O address 0x%04x already in use\n", wdt_io); 262 if (ret) {
355 ret = -EIO; 263 pr_err("failed to initialize watchdog (err=%d)\n", ret);
356 goto out; 264 return ret;
357 } 265 }
358 266
359 w83627hf_init();
360
361 ret = register_reboot_notifier(&wdt_notifier); 267 ret = register_reboot_notifier(&wdt_notifier);
362 if (ret != 0) { 268 if (ret != 0) {
363 pr_err("cannot register reboot notifier (err=%d)\n", ret); 269 pr_err("cannot register reboot notifier (err=%d)\n", ret);
364 goto unreg_regions; 270 return ret;
365 } 271 }
366 272
367 ret = misc_register(&wdt_miscdev); 273 ret = watchdog_register_device(&wdt_dev);
368 if (ret != 0) { 274 if (ret)
369 pr_err("cannot register miscdev on minor=%d (err=%d)\n",
370 WATCHDOG_MINOR, ret);
371 goto unreg_reboot; 275 goto unreg_reboot;
372 }
373 276
374 pr_info("initialized. timeout=%d sec (nowayout=%d)\n", 277 pr_info("initialized. timeout=%d sec (nowayout=%d)\n",
375 timeout, nowayout); 278 wdt_dev.timeout, nowayout);
376 279
377out:
378 return ret; 280 return ret;
281
379unreg_reboot: 282unreg_reboot:
380 unregister_reboot_notifier(&wdt_notifier); 283 unregister_reboot_notifier(&wdt_notifier);
381unreg_regions: 284 return ret;
382 release_region(wdt_io, 1);
383 goto out;
384} 285}
385 286
386static void __exit wdt_exit(void) 287static void __exit wdt_exit(void)
387{ 288{
388 misc_deregister(&wdt_miscdev); 289 watchdog_unregister_device(&wdt_dev);
389 unregister_reboot_notifier(&wdt_notifier); 290 unregister_reboot_notifier(&wdt_notifier);
390 release_region(wdt_io, 1);
391} 291}
392 292
393module_init(wdt_init); 293module_init(wdt_init);
@@ -396,4 +296,3 @@ module_exit(wdt_exit);
396MODULE_LICENSE("GPL"); 296MODULE_LICENSE("GPL");
397MODULE_AUTHOR("Pádraig Brady <P@draigBrady.com>"); 297MODULE_AUTHOR("Pádraig Brady <P@draigBrady.com>");
398MODULE_DESCRIPTION("w83627hf/thf WDT driver"); 298MODULE_DESCRIPTION("w83627hf/thf WDT driver");
399MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/w83697hf_wdt.c b/drivers/watchdog/w83697hf_wdt.c
index cd9f3c1e1af4..aaf2995d37f4 100644
--- a/drivers/watchdog/w83697hf_wdt.c
+++ b/drivers/watchdog/w83697hf_wdt.c
@@ -458,4 +458,3 @@ MODULE_LICENSE("GPL");
458MODULE_AUTHOR("Marcus Junker <junker@anduras.de>, " 458MODULE_AUTHOR("Marcus Junker <junker@anduras.de>, "
459 "Samuel Tardieu <sam@rfc1149.net>"); 459 "Samuel Tardieu <sam@rfc1149.net>");
460MODULE_DESCRIPTION("w83697hf/hg WDT driver"); 460MODULE_DESCRIPTION("w83697hf/hg WDT driver");
461MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/w83697ug_wdt.c b/drivers/watchdog/w83697ug_wdt.c
index 274be0bfaf24..ff58cb74671f 100644
--- a/drivers/watchdog/w83697ug_wdt.c
+++ b/drivers/watchdog/w83697ug_wdt.c
@@ -395,4 +395,3 @@ module_exit(wdt_exit);
395MODULE_LICENSE("GPL"); 395MODULE_LICENSE("GPL");
396MODULE_AUTHOR("Flemming Frandsen <ff@nrvissing.net>"); 396MODULE_AUTHOR("Flemming Frandsen <ff@nrvissing.net>");
397MODULE_DESCRIPTION("w83697ug/uf WDT driver"); 397MODULE_DESCRIPTION("w83697ug/uf WDT driver");
398MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/w83877f_wdt.c b/drivers/watchdog/w83877f_wdt.c
index 7874ae06232b..f0483c75ed32 100644
--- a/drivers/watchdog/w83877f_wdt.c
+++ b/drivers/watchdog/w83877f_wdt.c
@@ -406,4 +406,3 @@ module_exit(w83877f_wdt_unload);
406MODULE_AUTHOR("Scott and Bill Jennings"); 406MODULE_AUTHOR("Scott and Bill Jennings");
407MODULE_DESCRIPTION("Driver for watchdog timer in w83877f chip"); 407MODULE_DESCRIPTION("Driver for watchdog timer in w83877f chip");
408MODULE_LICENSE("GPL"); 408MODULE_LICENSE("GPL");
409MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/w83977f_wdt.c b/drivers/watchdog/w83977f_wdt.c
index 5d2c902825c2..91bf55a20024 100644
--- a/drivers/watchdog/w83977f_wdt.c
+++ b/drivers/watchdog/w83977f_wdt.c
@@ -527,4 +527,3 @@ module_exit(w83977f_wdt_exit);
527MODULE_AUTHOR("Jose Goncalves <jose.goncalves@inov.pt>"); 527MODULE_AUTHOR("Jose Goncalves <jose.goncalves@inov.pt>");
528MODULE_DESCRIPTION("Driver for watchdog timer in W83977F I/O chip"); 528MODULE_DESCRIPTION("Driver for watchdog timer in W83977F I/O chip");
529MODULE_LICENSE("GPL"); 529MODULE_LICENSE("GPL");
530MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/wafer5823wdt.c b/drivers/watchdog/wafer5823wdt.c
index 25aba6e00a23..db0da7ea4fd8 100644
--- a/drivers/watchdog/wafer5823wdt.c
+++ b/drivers/watchdog/wafer5823wdt.c
@@ -322,6 +322,5 @@ module_exit(wafwdt_exit);
322MODULE_AUTHOR("Justin Cormack"); 322MODULE_AUTHOR("Justin Cormack");
323MODULE_DESCRIPTION("ICP Wafer 5823 Single Board Computer WDT driver"); 323MODULE_DESCRIPTION("ICP Wafer 5823 Single Board Computer WDT driver");
324MODULE_LICENSE("GPL"); 324MODULE_LICENSE("GPL");
325MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
326 325
327/* end of wafer5823wdt.c */ 326/* end of wafer5823wdt.c */
diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
index 05d18b4c661b..461336c4519f 100644
--- a/drivers/watchdog/watchdog_core.c
+++ b/drivers/watchdog/watchdog_core.c
@@ -77,7 +77,7 @@ int watchdog_init_timeout(struct watchdog_device *wdd,
77 77
78 watchdog_check_min_max_timeout(wdd); 78 watchdog_check_min_max_timeout(wdd);
79 79
80 /* try to get the tiemout module parameter first */ 80 /* try to get the timeout module parameter first */
81 if (!watchdog_timeout_invalid(wdd, timeout_parm)) { 81 if (!watchdog_timeout_invalid(wdd, timeout_parm)) {
82 wdd->timeout = timeout_parm; 82 wdd->timeout = timeout_parm;
83 return ret; 83 return ret;
diff --git a/drivers/watchdog/wdrtas.c b/drivers/watchdog/wdrtas.c
index 3045debd5411..0240c60d14e3 100644
--- a/drivers/watchdog/wdrtas.c
+++ b/drivers/watchdog/wdrtas.c
@@ -48,8 +48,6 @@
48MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>"); 48MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>");
49MODULE_DESCRIPTION("RTAS watchdog driver"); 49MODULE_DESCRIPTION("RTAS watchdog driver");
50MODULE_LICENSE("GPL"); 50MODULE_LICENSE("GPL");
51MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
52MODULE_ALIAS_MISCDEV(TEMP_MINOR);
53 51
54static bool wdrtas_nowayout = WATCHDOG_NOWAYOUT; 52static bool wdrtas_nowayout = WATCHDOG_NOWAYOUT;
55static atomic_t wdrtas_miscdev_open = ATOMIC_INIT(0); 53static atomic_t wdrtas_miscdev_open = ATOMIC_INIT(0);
diff --git a/drivers/watchdog/wdt.c b/drivers/watchdog/wdt.c
index ee4333c01109..e0206b5b7d89 100644
--- a/drivers/watchdog/wdt.c
+++ b/drivers/watchdog/wdt.c
@@ -664,6 +664,4 @@ module_exit(wdt_exit);
664 664
665MODULE_AUTHOR("Alan Cox"); 665MODULE_AUTHOR("Alan Cox");
666MODULE_DESCRIPTION("Driver for ISA ICS watchdog cards (WDT500/501)"); 666MODULE_DESCRIPTION("Driver for ISA ICS watchdog cards (WDT500/501)");
667MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
668MODULE_ALIAS_MISCDEV(TEMP_MINOR);
669MODULE_LICENSE("GPL"); 667MODULE_LICENSE("GPL");
diff --git a/drivers/watchdog/wdt285.c b/drivers/watchdog/wdt285.c
index 5eec74053882..7355ddd0b207 100644
--- a/drivers/watchdog/wdt285.c
+++ b/drivers/watchdog/wdt285.c
@@ -224,7 +224,6 @@ static void __exit footbridge_watchdog_exit(void)
224MODULE_AUTHOR("Phil Blundell <pb@nexus.co.uk>"); 224MODULE_AUTHOR("Phil Blundell <pb@nexus.co.uk>");
225MODULE_DESCRIPTION("Footbridge watchdog driver"); 225MODULE_DESCRIPTION("Footbridge watchdog driver");
226MODULE_LICENSE("GPL"); 226MODULE_LICENSE("GPL");
227MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
228 227
229module_param(soft_margin, int, 0); 228module_param(soft_margin, int, 0);
230MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds"); 229MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds");
diff --git a/drivers/watchdog/wdt977.c b/drivers/watchdog/wdt977.c
index 65a402344933..a8e6f87f60c9 100644
--- a/drivers/watchdog/wdt977.c
+++ b/drivers/watchdog/wdt977.c
@@ -507,4 +507,3 @@ module_exit(wd977_exit);
507MODULE_AUTHOR("Woody Suwalski <woodys@xandros.com>"); 507MODULE_AUTHOR("Woody Suwalski <woodys@xandros.com>");
508MODULE_DESCRIPTION("W83977AF Watchdog driver"); 508MODULE_DESCRIPTION("W83977AF Watchdog driver");
509MODULE_LICENSE("GPL"); 509MODULE_LICENSE("GPL");
510MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/wdt_pci.c b/drivers/watchdog/wdt_pci.c
index 36a54c0e32dd..ee89ba4dea63 100644
--- a/drivers/watchdog/wdt_pci.c
+++ b/drivers/watchdog/wdt_pci.c
@@ -744,5 +744,3 @@ module_pci_driver(wdtpci_driver);
744MODULE_AUTHOR("JP Nollmann, Alan Cox"); 744MODULE_AUTHOR("JP Nollmann, Alan Cox");
745MODULE_DESCRIPTION("Driver for the ICS PCI-WDT500/501 watchdog cards"); 745MODULE_DESCRIPTION("Driver for the ICS PCI-WDT500/501 watchdog cards");
746MODULE_LICENSE("GPL"); 746MODULE_LICENSE("GPL");
747MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
748MODULE_ALIAS_MISCDEV(TEMP_MINOR);
diff --git a/drivers/watchdog/wm831x_wdt.c b/drivers/watchdog/wm831x_wdt.c
index d4e47eda4182..e243bd01c774 100644
--- a/drivers/watchdog/wm831x_wdt.c
+++ b/drivers/watchdog/wm831x_wdt.c
@@ -184,7 +184,7 @@ static const struct watchdog_ops wm831x_wdt_ops = {
184static int wm831x_wdt_probe(struct platform_device *pdev) 184static int wm831x_wdt_probe(struct platform_device *pdev)
185{ 185{
186 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 186 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
187 struct wm831x_pdata *chip_pdata; 187 struct wm831x_pdata *chip_pdata = dev_get_platdata(pdev->dev.parent);
188 struct wm831x_watchdog_pdata *pdata; 188 struct wm831x_watchdog_pdata *pdata;
189 struct wm831x_wdt_drvdata *driver_data; 189 struct wm831x_wdt_drvdata *driver_data;
190 struct watchdog_device *wm831x_wdt; 190 struct watchdog_device *wm831x_wdt;
@@ -231,12 +231,10 @@ static int wm831x_wdt_probe(struct platform_device *pdev)
231 wm831x_wdt->timeout = wm831x_wdt_cfgs[i].time; 231 wm831x_wdt->timeout = wm831x_wdt_cfgs[i].time;
232 232
233 /* Apply any configuration */ 233 /* Apply any configuration */
234 if (pdev->dev.parent->platform_data) { 234 if (chip_pdata)
235 chip_pdata = pdev->dev.parent->platform_data;
236 pdata = chip_pdata->watchdog; 235 pdata = chip_pdata->watchdog;
237 } else { 236 else
238 pdata = NULL; 237 pdata = NULL;
239 }
240 238
241 if (pdata) { 239 if (pdata) {
242 reg &= ~(WM831X_WDOG_SECACT_MASK | WM831X_WDOG_PRIMACT_MASK | 240 reg &= ~(WM831X_WDOG_SECACT_MASK | WM831X_WDOG_PRIMACT_MASK |
diff --git a/drivers/watchdog/xen_wdt.c b/drivers/watchdog/xen_wdt.c
index 92ad33d0cb71..7a42dffd39e5 100644
--- a/drivers/watchdog/xen_wdt.c
+++ b/drivers/watchdog/xen_wdt.c
@@ -362,4 +362,3 @@ MODULE_AUTHOR("Jan Beulich <jbeulich@novell.com>");
362MODULE_DESCRIPTION("Xen WatchDog Timer Driver"); 362MODULE_DESCRIPTION("Xen WatchDog Timer Driver");
363MODULE_VERSION(DRV_VERSION); 363MODULE_VERSION(DRV_VERSION);
364MODULE_LICENSE("GPL"); 364MODULE_LICENSE("GPL");
365MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 1cd2388ca5bd..1d641bb108d2 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -136,6 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
136Eoverflow: 136Eoverflow:
137 m->op->stop(m, p); 137 m->op->stop(m, p);
138 kfree(m->buf); 138 kfree(m->buf);
139 m->count = 0;
139 m->buf = kmalloc(m->size <<= 1, GFP_KERNEL); 140 m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
140 return !m->buf ? -ENOMEM : -EAGAIN; 141 return !m->buf ? -ENOMEM : -EAGAIN;
141} 142}
@@ -232,10 +233,10 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
232 goto Fill; 233 goto Fill;
233 m->op->stop(m, p); 234 m->op->stop(m, p);
234 kfree(m->buf); 235 kfree(m->buf);
236 m->count = 0;
235 m->buf = kmalloc(m->size <<= 1, GFP_KERNEL); 237 m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
236 if (!m->buf) 238 if (!m->buf)
237 goto Enomem; 239 goto Enomem;
238 m->count = 0;
239 m->version = 0; 240 m->version = 0;
240 pos = m->index; 241 pos = m->index;
241 p = m->op->start(m, &pos); 242 p = m->op->start(m, &pos);
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 2ab11dc38077..eff50e062be8 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -205,7 +205,6 @@ struct i2c_driver {
205 * @name: Indicates the type of the device, usually a chip name that's 205 * @name: Indicates the type of the device, usually a chip name that's
206 * generic enough to hide second-sourcing and compatible revisions. 206 * generic enough to hide second-sourcing and compatible revisions.
207 * @adapter: manages the bus segment hosting this I2C device 207 * @adapter: manages the bus segment hosting this I2C device
208 * @driver: device's driver, hence pointer to access routines
209 * @dev: Driver model device node for the slave. 208 * @dev: Driver model device node for the slave.
210 * @irq: indicates the IRQ generated by this device (if any) 209 * @irq: indicates the IRQ generated by this device (if any)
211 * @detected: member of an i2c_driver.clients list or i2c-core's 210 * @detected: member of an i2c_driver.clients list or i2c-core's
@@ -222,7 +221,6 @@ struct i2c_client {
222 /* _LOWER_ 7 bits */ 221 /* _LOWER_ 7 bits */
223 char name[I2C_NAME_SIZE]; 222 char name[I2C_NAME_SIZE];
224 struct i2c_adapter *adapter; /* the adapter we sit on */ 223 struct i2c_adapter *adapter; /* the adapter we sit on */
225 struct i2c_driver *driver; /* and our access routines */
226 struct device dev; /* the device structure */ 224 struct device dev; /* the device structure */
227 int irq; /* irq issued by device */ 225 int irq; /* irq issued by device */
228 struct list_head detected; 226 struct list_head detected;
diff --git a/include/linux/irq.h b/include/linux/irq.h
index 56bb0dc8b7d4..7dc10036eff5 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -70,6 +70,9 @@ typedef void (*irq_preflow_handler_t)(struct irq_data *data);
70 * IRQ_MOVE_PCNTXT - Interrupt can be migrated from process context 70 * IRQ_MOVE_PCNTXT - Interrupt can be migrated from process context
71 * IRQ_NESTED_TRHEAD - Interrupt nests into another thread 71 * IRQ_NESTED_TRHEAD - Interrupt nests into another thread
72 * IRQ_PER_CPU_DEVID - Dev_id is a per-cpu variable 72 * IRQ_PER_CPU_DEVID - Dev_id is a per-cpu variable
73 * IRQ_IS_POLLED - Always polled by another interrupt. Exclude
74 * it from the spurious interrupt detection
75 * mechanism and from core side polling.
73 */ 76 */
74enum { 77enum {
75 IRQ_TYPE_NONE = 0x00000000, 78 IRQ_TYPE_NONE = 0x00000000,
@@ -94,12 +97,14 @@ enum {
94 IRQ_NESTED_THREAD = (1 << 15), 97 IRQ_NESTED_THREAD = (1 << 15),
95 IRQ_NOTHREAD = (1 << 16), 98 IRQ_NOTHREAD = (1 << 16),
96 IRQ_PER_CPU_DEVID = (1 << 17), 99 IRQ_PER_CPU_DEVID = (1 << 17),
100 IRQ_IS_POLLED = (1 << 18),
97}; 101};
98 102
99#define IRQF_MODIFY_MASK \ 103#define IRQF_MODIFY_MASK \
100 (IRQ_TYPE_SENSE_MASK | IRQ_NOPROBE | IRQ_NOREQUEST | \ 104 (IRQ_TYPE_SENSE_MASK | IRQ_NOPROBE | IRQ_NOREQUEST | \
101 IRQ_NOAUTOEN | IRQ_MOVE_PCNTXT | IRQ_LEVEL | IRQ_NO_BALANCING | \ 105 IRQ_NOAUTOEN | IRQ_MOVE_PCNTXT | IRQ_LEVEL | IRQ_NO_BALANCING | \
102 IRQ_PER_CPU | IRQ_NESTED_THREAD | IRQ_NOTHREAD | IRQ_PER_CPU_DEVID) 106 IRQ_PER_CPU | IRQ_NESTED_THREAD | IRQ_NOTHREAD | IRQ_PER_CPU_DEVID | \
107 IRQ_IS_POLLED)
103 108
104#define IRQ_NO_BALANCING_MASK (IRQ_PER_CPU | IRQ_NO_BALANCING) 109#define IRQ_NO_BALANCING_MASK (IRQ_PER_CPU | IRQ_NO_BALANCING)
105 110
diff --git a/include/linux/mlx5/device.h b/include/linux/mlx5/device.h
index 5eb4e31af22b..da78875807fc 100644
--- a/include/linux/mlx5/device.h
+++ b/include/linux/mlx5/device.h
@@ -230,6 +230,15 @@ enum {
230 MLX5_MAX_PAGE_SHIFT = 31 230 MLX5_MAX_PAGE_SHIFT = 31
231}; 231};
232 232
233enum {
234 MLX5_ADAPTER_PAGE_SHIFT = 12
235};
236
237enum {
238 MLX5_CAP_OFF_DCT = 41,
239 MLX5_CAP_OFF_CMDIF_CSUM = 46,
240};
241
233struct mlx5_inbox_hdr { 242struct mlx5_inbox_hdr {
234 __be16 opcode; 243 __be16 opcode;
235 u8 rsvd[4]; 244 u8 rsvd[4];
@@ -319,9 +328,9 @@ struct mlx5_hca_cap {
319 u8 rsvd25[42]; 328 u8 rsvd25[42];
320 __be16 log_uar_page_sz; 329 __be16 log_uar_page_sz;
321 u8 rsvd26[28]; 330 u8 rsvd26[28];
322 u8 log_msx_atomic_size_qp; 331 u8 log_max_atomic_size_qp;
323 u8 rsvd27[2]; 332 u8 rsvd27[2];
324 u8 log_msx_atomic_size_dc; 333 u8 log_max_atomic_size_dc;
325 u8 rsvd28[76]; 334 u8 rsvd28[76];
326}; 335};
327 336
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h
index 6b8c496572c8..554548cd3dd4 100644
--- a/include/linux/mlx5/driver.h
+++ b/include/linux/mlx5/driver.h
@@ -483,6 +483,7 @@ struct mlx5_priv {
483 struct rb_root page_root; 483 struct rb_root page_root;
484 int fw_pages; 484 int fw_pages;
485 int reg_pages; 485 int reg_pages;
486 struct list_head free_list;
486 487
487 struct mlx5_core_health health; 488 struct mlx5_core_health health;
488 489
@@ -557,9 +558,11 @@ typedef void (*mlx5_cmd_cbk_t)(int status, void *context);
557struct mlx5_cmd_work_ent { 558struct mlx5_cmd_work_ent {
558 struct mlx5_cmd_msg *in; 559 struct mlx5_cmd_msg *in;
559 struct mlx5_cmd_msg *out; 560 struct mlx5_cmd_msg *out;
561 void *uout;
562 int uout_size;
560 mlx5_cmd_cbk_t callback; 563 mlx5_cmd_cbk_t callback;
561 void *context; 564 void *context;
562 int idx; 565 int idx;
563 struct completion done; 566 struct completion done;
564 struct mlx5_cmd *cmd; 567 struct mlx5_cmd *cmd;
565 struct work_struct work; 568 struct work_struct work;
@@ -570,6 +573,7 @@ struct mlx5_cmd_work_ent {
570 u8 token; 573 u8 token;
571 struct timespec ts1; 574 struct timespec ts1;
572 struct timespec ts2; 575 struct timespec ts2;
576 u16 op;
573}; 577};
574 578
575struct mlx5_pas { 579struct mlx5_pas {
@@ -653,6 +657,9 @@ void mlx5_cmd_use_polling(struct mlx5_core_dev *dev);
653int mlx5_cmd_status_to_err(struct mlx5_outbox_hdr *hdr); 657int mlx5_cmd_status_to_err(struct mlx5_outbox_hdr *hdr);
654int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out, 658int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
655 int out_size); 659 int out_size);
660int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
661 void *out, int out_size, mlx5_cmd_cbk_t callback,
662 void *context);
656int mlx5_cmd_alloc_uar(struct mlx5_core_dev *dev, u32 *uarn); 663int mlx5_cmd_alloc_uar(struct mlx5_core_dev *dev, u32 *uarn);
657int mlx5_cmd_free_uar(struct mlx5_core_dev *dev, u32 uarn); 664int mlx5_cmd_free_uar(struct mlx5_core_dev *dev, u32 uarn);
658int mlx5_alloc_uuars(struct mlx5_core_dev *dev, struct mlx5_uuar_info *uuari); 665int mlx5_alloc_uuars(struct mlx5_core_dev *dev, struct mlx5_uuar_info *uuari);
@@ -676,7 +683,9 @@ int mlx5_core_query_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
676int mlx5_core_arm_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq, 683int mlx5_core_arm_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
677 u16 lwm, int is_srq); 684 u16 lwm, int is_srq);
678int mlx5_core_create_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr, 685int mlx5_core_create_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr,
679 struct mlx5_create_mkey_mbox_in *in, int inlen); 686 struct mlx5_create_mkey_mbox_in *in, int inlen,
687 mlx5_cmd_cbk_t callback, void *context,
688 struct mlx5_create_mkey_mbox_out *out);
680int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr); 689int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr);
681int mlx5_core_query_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr, 690int mlx5_core_query_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr,
682 struct mlx5_query_mkey_mbox_out *out, int outlen); 691 struct mlx5_query_mkey_mbox_out *out, int outlen);
@@ -745,6 +754,11 @@ static inline u32 mlx5_idx_to_mkey(u32 mkey_idx)
745 return mkey_idx << 8; 754 return mkey_idx << 8;
746} 755}
747 756
757static inline u8 mlx5_mkey_variant(u32 mkey)
758{
759 return mkey & 0xff;
760}
761
748enum { 762enum {
749 MLX5_PROF_MASK_QP_SIZE = (u64)1 << 0, 763 MLX5_PROF_MASK_QP_SIZE = (u64)1 << 0,
750 MLX5_PROF_MASK_MR_CACHE = (u64)1 << 1, 764 MLX5_PROF_MASK_MR_CACHE = (u64)1 << 1,
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 842de3e21e70..176fdf824b14 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -240,6 +240,7 @@ struct mmc_part {
240struct mmc_card { 240struct mmc_card {
241 struct mmc_host *host; /* the host this device belongs to */ 241 struct mmc_host *host; /* the host this device belongs to */
242 struct device dev; /* the device */ 242 struct device dev; /* the device */
243 u32 ocr; /* the current OCR setting */
243 unsigned int rca; /* relative card address of device */ 244 unsigned int rca; /* relative card address of device */
244 unsigned int type; /* card type */ 245 unsigned int type; /* card type */
245#define MMC_TYPE_MMC 0 /* MMC card */ 246#define MMC_TYPE_MMC 0 /* MMC card */
@@ -257,6 +258,7 @@ struct mmc_card {
257#define MMC_CARD_REMOVED (1<<7) /* card has been removed */ 258#define MMC_CARD_REMOVED (1<<7) /* card has been removed */
258#define MMC_STATE_HIGHSPEED_200 (1<<8) /* card is in HS200 mode */ 259#define MMC_STATE_HIGHSPEED_200 (1<<8) /* card is in HS200 mode */
259#define MMC_STATE_DOING_BKOPS (1<<10) /* card is doing BKOPS */ 260#define MMC_STATE_DOING_BKOPS (1<<10) /* card is doing BKOPS */
261#define MMC_STATE_SUSPENDED (1<<11) /* card is suspended */
260 unsigned int quirks; /* card quirks */ 262 unsigned int quirks; /* card quirks */
261#define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */ 263#define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */
262#define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */ 264#define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */
@@ -420,10 +422,10 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
420#define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR) 422#define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR)
421#define mmc_card_ddr_mode(c) ((c)->state & MMC_STATE_HIGHSPEED_DDR) 423#define mmc_card_ddr_mode(c) ((c)->state & MMC_STATE_HIGHSPEED_DDR)
422#define mmc_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED) 424#define mmc_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED)
423#define mmc_sd_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED)
424#define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC) 425#define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC)
425#define mmc_card_removed(c) ((c) && ((c)->state & MMC_CARD_REMOVED)) 426#define mmc_card_removed(c) ((c) && ((c)->state & MMC_CARD_REMOVED))
426#define mmc_card_doing_bkops(c) ((c)->state & MMC_STATE_DOING_BKOPS) 427#define mmc_card_doing_bkops(c) ((c)->state & MMC_STATE_DOING_BKOPS)
428#define mmc_card_suspended(c) ((c)->state & MMC_STATE_SUSPENDED)
427 429
428#define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT) 430#define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT)
429#define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY) 431#define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
@@ -432,11 +434,12 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
432#define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR) 434#define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR)
433#define mmc_card_set_ddr_mode(c) ((c)->state |= MMC_STATE_HIGHSPEED_DDR) 435#define mmc_card_set_ddr_mode(c) ((c)->state |= MMC_STATE_HIGHSPEED_DDR)
434#define mmc_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED) 436#define mmc_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED)
435#define mmc_sd_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED)
436#define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC) 437#define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC)
437#define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED) 438#define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED)
438#define mmc_card_set_doing_bkops(c) ((c)->state |= MMC_STATE_DOING_BKOPS) 439#define mmc_card_set_doing_bkops(c) ((c)->state |= MMC_STATE_DOING_BKOPS)
439#define mmc_card_clr_doing_bkops(c) ((c)->state &= ~MMC_STATE_DOING_BKOPS) 440#define mmc_card_clr_doing_bkops(c) ((c)->state &= ~MMC_STATE_DOING_BKOPS)
441#define mmc_card_set_suspended(c) ((c)->state |= MMC_STATE_SUSPENDED)
442#define mmc_card_clr_suspended(c) ((c)->state &= ~MMC_STATE_SUSPENDED)
440 443
441/* 444/*
442 * Quirk add/remove for MMC products. 445 * Quirk add/remove for MMC products.
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index da51bec578c3..87079fc38011 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -151,7 +151,8 @@ extern int mmc_app_cmd(struct mmc_host *, struct mmc_card *);
151extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *, 151extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
152 struct mmc_command *, int); 152 struct mmc_command *, int);
153extern void mmc_start_bkops(struct mmc_card *card, bool from_exception); 153extern void mmc_start_bkops(struct mmc_card *card, bool from_exception);
154extern int __mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int, bool); 154extern int __mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int, bool,
155 bool);
155extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int); 156extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int);
156extern int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd); 157extern int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd);
157 158
@@ -188,7 +189,6 @@ extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
188 189
189extern int __mmc_claim_host(struct mmc_host *host, atomic_t *abort); 190extern int __mmc_claim_host(struct mmc_host *host, atomic_t *abort);
190extern void mmc_release_host(struct mmc_host *host); 191extern void mmc_release_host(struct mmc_host *host);
191extern int mmc_try_claim_host(struct mmc_host *host);
192 192
193extern void mmc_get_card(struct mmc_card *card); 193extern void mmc_get_card(struct mmc_card *card);
194extern void mmc_put_card(struct mmc_card *card); 194extern void mmc_put_card(struct mmc_card *card);
diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h
index 198f0fa44e9f..6ce7d2cd3c7a 100644
--- a/include/linux/mmc/dw_mmc.h
+++ b/include/linux/mmc/dw_mmc.h
@@ -15,6 +15,7 @@
15#define LINUX_MMC_DW_MMC_H 15#define LINUX_MMC_DW_MMC_H
16 16
17#include <linux/scatterlist.h> 17#include <linux/scatterlist.h>
18#include <linux/mmc/core.h>
18 19
19#define MAX_MCI_SLOTS 2 20#define MAX_MCI_SLOTS 2
20 21
@@ -129,6 +130,9 @@ struct dw_mci {
129 struct mmc_request *mrq; 130 struct mmc_request *mrq;
130 struct mmc_command *cmd; 131 struct mmc_command *cmd;
131 struct mmc_data *data; 132 struct mmc_data *data;
133 struct mmc_command stop_abort;
134 unsigned int prev_blksz;
135 unsigned char timing;
132 struct workqueue_struct *card_workqueue; 136 struct workqueue_struct *card_workqueue;
133 137
134 /* DMA interface members*/ 138 /* DMA interface members*/
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 3b0c33ae13e1..99f5709ac343 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -254,6 +254,7 @@ struct mmc_host {
254#define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS SDR50 mode */ 254#define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS SDR50 mode */
255#define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS SDR104 mode */ 255#define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS SDR104 mode */
256#define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS DDR50 mode */ 256#define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS DDR50 mode */
257#define MMC_CAP_RUNTIME_RESUME (1 << 20) /* Resume at runtime_resume. */
257#define MMC_CAP_DRIVER_TYPE_A (1 << 23) /* Host supports Driver Type A */ 258#define MMC_CAP_DRIVER_TYPE_A (1 << 23) /* Host supports Driver Type A */
258#define MMC_CAP_DRIVER_TYPE_C (1 << 24) /* Host supports Driver Type C */ 259#define MMC_CAP_DRIVER_TYPE_C (1 << 24) /* Host supports Driver Type C */
259#define MMC_CAP_DRIVER_TYPE_D (1 << 25) /* Host supports Driver Type D */ 260#define MMC_CAP_DRIVER_TYPE_D (1 << 25) /* Host supports Driver Type D */
@@ -309,7 +310,6 @@ struct mmc_host {
309 spinlock_t lock; /* lock for claim and bus ops */ 310 spinlock_t lock; /* lock for claim and bus ops */
310 311
311 struct mmc_ios ios; /* current io bus settings */ 312 struct mmc_ios ios; /* current io bus settings */
312 u32 ocr; /* the current OCR setting */
313 313
314 /* group bitfields together to minimize padding */ 314 /* group bitfields together to minimize padding */
315 unsigned int use_spi_crc:1; 315 unsigned int use_spi_crc:1;
@@ -382,9 +382,6 @@ static inline void *mmc_priv(struct mmc_host *host)
382#define mmc_classdev(x) (&(x)->class_dev) 382#define mmc_classdev(x) (&(x)->class_dev)
383#define mmc_hostname(x) (dev_name(&(x)->class_dev)) 383#define mmc_hostname(x) (dev_name(&(x)->class_dev))
384 384
385int mmc_suspend_host(struct mmc_host *);
386int mmc_resume_host(struct mmc_host *);
387
388int mmc_power_save_host(struct mmc_host *host); 385int mmc_power_save_host(struct mmc_host *host);
389int mmc_power_restore_host(struct mmc_host *host); 386int mmc_power_restore_host(struct mmc_host *host);
390 387
diff --git a/include/linux/i2c/at24.h b/include/linux/platform_data/at24.h
index 285025a9cdc9..c42aa89d34ee 100644
--- a/include/linux/i2c/at24.h
+++ b/include/linux/platform_data/at24.h
@@ -28,7 +28,7 @@
28 * 28 *
29 * void get_mac_addr(struct memory_accessor *mem_acc, void *context) 29 * void get_mac_addr(struct memory_accessor *mem_acc, void *context)
30 * { 30 * {
31 * u8 *mac_addr = ethernet_pdata->mac_addr; 31 * u8 *mac_addr = ethernet_pdata->mac_addr;
32 * off_t offset = context; 32 * off_t offset = context;
33 * 33 *
34 * // Read MAC addr from EEPROM 34 * // Read MAC addr from EEPROM
diff --git a/include/linux/platform_data/mmc-esdhc-imx.h b/include/linux/platform_data/mmc-esdhc-imx.h
index d44912d81578..75f70f6ac137 100644
--- a/include/linux/platform_data/mmc-esdhc-imx.h
+++ b/include/linux/platform_data/mmc-esdhc-imx.h
@@ -10,6 +10,8 @@
10#ifndef __ASM_ARCH_IMX_ESDHC_H 10#ifndef __ASM_ARCH_IMX_ESDHC_H
11#define __ASM_ARCH_IMX_ESDHC_H 11#define __ASM_ARCH_IMX_ESDHC_H
12 12
13#include <linux/types.h>
14
13enum wp_types { 15enum wp_types {
14 ESDHC_WP_NONE, /* no WP, neither controller nor gpio */ 16 ESDHC_WP_NONE, /* no WP, neither controller nor gpio */
15 ESDHC_WP_CONTROLLER, /* mmc controller internal WP */ 17 ESDHC_WP_CONTROLLER, /* mmc controller internal WP */
@@ -32,6 +34,7 @@ enum cd_types {
32 * @cd_gpio: gpio for card_detect interrupt 34 * @cd_gpio: gpio for card_detect interrupt
33 * @wp_type: type of write_protect method (see wp_types enum above) 35 * @wp_type: type of write_protect method (see wp_types enum above)
34 * @cd_type: type of card_detect method (see cd_types enum above) 36 * @cd_type: type of card_detect method (see cd_types enum above)
37 * @support_vsel: indicate it supports 1.8v switching
35 */ 38 */
36 39
37struct esdhc_platform_data { 40struct esdhc_platform_data {
@@ -41,5 +44,7 @@ struct esdhc_platform_data {
41 enum cd_types cd_type; 44 enum cd_types cd_type;
42 int max_bus_width; 45 int max_bus_width;
43 unsigned int f_max; 46 unsigned int f_max;
47 bool support_vsel;
48 unsigned int delay_line;
44}; 49};
45#endif /* __ASM_ARCH_IMX_ESDHC_H */ 50#endif /* __ASM_ARCH_IMX_ESDHC_H */
diff --git a/include/linux/power/bq24735-charger.h b/include/linux/power/bq24735-charger.h
new file mode 100644
index 000000000000..f536164a6069
--- /dev/null
+++ b/include/linux/power/bq24735-charger.h
@@ -0,0 +1,39 @@
1/*
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 as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#ifndef __CHARGER_BQ24735_H_
19#define __CHARGER_BQ24735_H_
20
21#include <linux/types.h>
22#include <linux/power_supply.h>
23
24struct bq24735_platform {
25 uint32_t charge_current;
26 uint32_t charge_voltage;
27 uint32_t input_current;
28
29 const char *name;
30
31 int status_gpio;
32 int status_gpio_active_low;
33 bool status_gpio_valid;
34
35 char **supplied_to;
36 size_t num_supplicants;
37};
38
39#endif /* __CHARGER_BQ24735_H_ */
diff --git a/include/linux/preempt_mask.h b/include/linux/preempt_mask.h
index 931bc616219f..d169820203dd 100644
--- a/include/linux/preempt_mask.h
+++ b/include/linux/preempt_mask.h
@@ -11,36 +11,23 @@
11 * - bits 0-7 are the preemption count (max preemption depth: 256) 11 * - bits 0-7 are the preemption count (max preemption depth: 256)
12 * - bits 8-15 are the softirq count (max # of softirqs: 256) 12 * - bits 8-15 are the softirq count (max # of softirqs: 256)
13 * 13 *
14 * The hardirq count can in theory reach the same as NR_IRQS. 14 * The hardirq count could in theory be the same as the number of
15 * In reality, the number of nested IRQS is limited to the stack 15 * interrupts in the system, but we run all interrupt handlers with
16 * size as well. For archs with over 1000 IRQS it is not practical 16 * interrupts disabled, so we cannot have nesting interrupts. Though
17 * to expect that they will all nest. We give a max of 10 bits for 17 * there are a few palaeontologic drivers which reenable interrupts in
18 * hardirq nesting. An arch may choose to give less than 10 bits. 18 * the handler, so we need more than one bit here.
19 * m68k expects it to be 8.
20 * 19 *
21 * - bits 16-25 are the hardirq count (max # of nested hardirqs: 1024) 20 * PREEMPT_MASK: 0x000000ff
22 * - bit 26 is the NMI_MASK 21 * SOFTIRQ_MASK: 0x0000ff00
23 * - bit 27 is the PREEMPT_ACTIVE flag 22 * HARDIRQ_MASK: 0x000f0000
24 * 23 * NMI_MASK: 0x00100000
25 * PREEMPT_MASK: 0x000000ff 24 * PREEMPT_ACTIVE: 0x00200000
26 * SOFTIRQ_MASK: 0x0000ff00
27 * HARDIRQ_MASK: 0x03ff0000
28 * NMI_MASK: 0x04000000
29 */ 25 */
30#define PREEMPT_BITS 8 26#define PREEMPT_BITS 8
31#define SOFTIRQ_BITS 8 27#define SOFTIRQ_BITS 8
28#define HARDIRQ_BITS 4
32#define NMI_BITS 1 29#define NMI_BITS 1
33 30
34#define MAX_HARDIRQ_BITS 10
35
36#ifndef HARDIRQ_BITS
37# define HARDIRQ_BITS MAX_HARDIRQ_BITS
38#endif
39
40#if HARDIRQ_BITS > MAX_HARDIRQ_BITS
41#error HARDIRQ_BITS too high!
42#endif
43
44#define PREEMPT_SHIFT 0 31#define PREEMPT_SHIFT 0
45#define SOFTIRQ_SHIFT (PREEMPT_SHIFT + PREEMPT_BITS) 32#define SOFTIRQ_SHIFT (PREEMPT_SHIFT + PREEMPT_BITS)
46#define HARDIRQ_SHIFT (SOFTIRQ_SHIFT + SOFTIRQ_BITS) 33#define HARDIRQ_SHIFT (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
@@ -60,15 +47,9 @@
60 47
61#define SOFTIRQ_DISABLE_OFFSET (2 * SOFTIRQ_OFFSET) 48#define SOFTIRQ_DISABLE_OFFSET (2 * SOFTIRQ_OFFSET)
62 49
63#ifndef PREEMPT_ACTIVE
64#define PREEMPT_ACTIVE_BITS 1 50#define PREEMPT_ACTIVE_BITS 1
65#define PREEMPT_ACTIVE_SHIFT (NMI_SHIFT + NMI_BITS) 51#define PREEMPT_ACTIVE_SHIFT (NMI_SHIFT + NMI_BITS)
66#define PREEMPT_ACTIVE (__IRQ_MASK(PREEMPT_ACTIVE_BITS) << PREEMPT_ACTIVE_SHIFT) 52#define PREEMPT_ACTIVE (__IRQ_MASK(PREEMPT_ACTIVE_BITS) << PREEMPT_ACTIVE_SHIFT)
67#endif
68
69#if PREEMPT_ACTIVE < (1 << (NMI_SHIFT + NMI_BITS))
70#error PREEMPT_ACTIVE is too low!
71#endif
72 53
73#define hardirq_count() (preempt_count() & HARDIRQ_MASK) 54#define hardirq_count() (preempt_count() & HARDIRQ_MASK)
74#define softirq_count() (preempt_count() & SOFTIRQ_MASK) 55#define softirq_count() (preempt_count() & SOFTIRQ_MASK)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 6f7ffa460089..7e35d4b9e14a 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -22,7 +22,7 @@ struct sched_param {
22#include <linux/errno.h> 22#include <linux/errno.h>
23#include <linux/nodemask.h> 23#include <linux/nodemask.h>
24#include <linux/mm_types.h> 24#include <linux/mm_types.h>
25#include <linux/preempt.h> 25#include <linux/preempt_mask.h>
26 26
27#include <asm/page.h> 27#include <asm/page.h>
28#include <asm/ptrace.h> 28#include <asm/ptrace.h>
diff --git a/include/media/lm3560.h b/include/media/lm3560.h
new file mode 100644
index 000000000000..46670706d6f8
--- /dev/null
+++ b/include/media/lm3560.h
@@ -0,0 +1,97 @@
1/*
2 * include/media/lm3560.h
3 *
4 * Copyright (C) 2013 Texas Instruments
5 *
6 * Contact: Daniel Jeong <gshark.jeong@gmail.com>
7 * Ldd-Mlp <ldd-mlp@list.ti.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __LM3560_H__
26#define __LM3560_H__
27
28#include <media/v4l2-subdev.h>
29
30#define LM3560_NAME "lm3560"
31#define LM3560_I2C_ADDR (0x53)
32
33/* FLASH Brightness
34 * min 62500uA, step 62500uA, max 1000000uA
35 */
36#define LM3560_FLASH_BRT_MIN 62500
37#define LM3560_FLASH_BRT_STEP 62500
38#define LM3560_FLASH_BRT_MAX 1000000
39#define LM3560_FLASH_BRT_uA_TO_REG(a) \
40 ((a) < LM3560_FLASH_BRT_MIN ? 0 : \
41 (((a) - LM3560_FLASH_BRT_MIN) / LM3560_FLASH_BRT_STEP))
42#define LM3560_FLASH_BRT_REG_TO_uA(a) \
43 ((a) * LM3560_FLASH_BRT_STEP + LM3560_FLASH_BRT_MIN)
44
45/* FLASH TIMEOUT DURATION
46 * min 32ms, step 32ms, max 1024ms
47 */
48#define LM3560_FLASH_TOUT_MIN 32
49#define LM3560_FLASH_TOUT_STEP 32
50#define LM3560_FLASH_TOUT_MAX 1024
51#define LM3560_FLASH_TOUT_ms_TO_REG(a) \
52 ((a) < LM3560_FLASH_TOUT_MIN ? 0 : \
53 (((a) - LM3560_FLASH_TOUT_MIN) / LM3560_FLASH_TOUT_STEP))
54#define LM3560_FLASH_TOUT_REG_TO_ms(a) \
55 ((a) * LM3560_FLASH_TOUT_STEP + LM3560_FLASH_TOUT_MIN)
56
57/* TORCH BRT
58 * min 31250uA, step 31250uA, max 250000uA
59 */
60#define LM3560_TORCH_BRT_MIN 31250
61#define LM3560_TORCH_BRT_STEP 31250
62#define LM3560_TORCH_BRT_MAX 250000
63#define LM3560_TORCH_BRT_uA_TO_REG(a) \
64 ((a) < LM3560_TORCH_BRT_MIN ? 0 : \
65 (((a) - LM3560_TORCH_BRT_MIN) / LM3560_TORCH_BRT_STEP))
66#define LM3560_TORCH_BRT_REG_TO_uA(a) \
67 ((a) * LM3560_TORCH_BRT_STEP + LM3560_TORCH_BRT_MIN)
68
69enum lm3560_led_id {
70 LM3560_LED0 = 0,
71 LM3560_LED1,
72 LM3560_LED_MAX
73};
74
75enum lm3560_peak_current {
76 LM3560_PEAK_1600mA = 0x00,
77 LM3560_PEAK_2300mA = 0x20,
78 LM3560_PEAK_3000mA = 0x40,
79 LM3560_PEAK_3600mA = 0x60
80};
81
82/* struct lm3560_platform_data
83 *
84 * @peak : peak current
85 * @max_flash_timeout: flash timeout
86 * @max_flash_brt: flash mode led brightness
87 * @max_torch_brt: torch mode led brightness
88 */
89struct lm3560_platform_data {
90 enum lm3560_peak_current peak;
91
92 u32 max_flash_timeout;
93 u32 max_flash_brt[LM3560_LED_MAX];
94 u32 max_torch_brt[LM3560_LED_MAX];
95};
96
97#endif /* __LM3560_H__ */
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h
index 34d2414f2b8c..865246b00127 100644
--- a/include/media/soc_camera.h
+++ b/include/media/soc_camera.h
@@ -146,9 +146,14 @@ struct soc_camera_subdev_desc {
146 /* sensor driver private platform data */ 146 /* sensor driver private platform data */
147 void *drv_priv; 147 void *drv_priv;
148 148
149 /* Optional regulators that have to be managed on power on/off events */ 149 /*
150 struct regulator_bulk_data *regulators; 150 * Set unbalanced_power to true to deal with legacy drivers, failing to
151 int num_regulators; 151 * balance their calls to subdevice's .s_power() method. clock_state is
152 * then used internally by helper functions, it shouldn't be touched by
153 * drivers or the platform code.
154 */
155 bool unbalanced_power;
156 unsigned long clock_state;
152 157
153 /* Optional callbacks to power on or off and reset the sensor */ 158 /* Optional callbacks to power on or off and reset the sensor */
154 int (*power)(struct device *, int); 159 int (*power)(struct device *, int);
@@ -162,6 +167,9 @@ struct soc_camera_subdev_desc {
162 int (*set_bus_param)(struct soc_camera_subdev_desc *, unsigned long flags); 167 int (*set_bus_param)(struct soc_camera_subdev_desc *, unsigned long flags);
163 unsigned long (*query_bus_param)(struct soc_camera_subdev_desc *); 168 unsigned long (*query_bus_param)(struct soc_camera_subdev_desc *);
164 void (*free_bus)(struct soc_camera_subdev_desc *); 169 void (*free_bus)(struct soc_camera_subdev_desc *);
170
171 /* Optional regulators that have to be managed on power on/off events */
172 struct v4l2_subdev_platform_data sd_pdata;
165}; 173};
166 174
167struct soc_camera_host_desc { 175struct soc_camera_host_desc {
@@ -202,9 +210,10 @@ struct soc_camera_link {
202 210
203 void *priv; 211 void *priv;
204 212
205 /* Optional regulators that have to be managed on power on/off events */ 213 /* Set by platforms to handle misbehaving drivers */
206 struct regulator_bulk_data *regulators; 214 bool unbalanced_power;
207 int num_regulators; 215 /* Used by soc-camera helper functions */
216 unsigned long clock_state;
208 217
209 /* Optional callbacks to power on or off and reset the sensor */ 218 /* Optional callbacks to power on or off and reset the sensor */
210 int (*power)(struct device *, int); 219 int (*power)(struct device *, int);
@@ -218,6 +227,12 @@ struct soc_camera_link {
218 unsigned long (*query_bus_param)(struct soc_camera_link *); 227 unsigned long (*query_bus_param)(struct soc_camera_link *);
219 void (*free_bus)(struct soc_camera_link *); 228 void (*free_bus)(struct soc_camera_link *);
220 229
230 /* Optional regulators that have to be managed on power on/off events */
231 struct regulator_bulk_data *regulators;
232 int num_regulators;
233
234 void *host_priv;
235
221 /* 236 /*
222 * Host part - keep at bottom and compatible to 237 * Host part - keep at bottom and compatible to
223 * struct soc_camera_host_desc 238 * struct soc_camera_host_desc
diff --git a/include/media/v4l2-clk.h b/include/media/v4l2-clk.h
index 0503a90b48bb..0b36cc138304 100644
--- a/include/media/v4l2-clk.h
+++ b/include/media/v4l2-clk.h
@@ -15,6 +15,7 @@
15#define MEDIA_V4L2_CLK_H 15#define MEDIA_V4L2_CLK_H
16 16
17#include <linux/atomic.h> 17#include <linux/atomic.h>
18#include <linux/export.h>
18#include <linux/list.h> 19#include <linux/list.h>
19#include <linux/mutex.h> 20#include <linux/mutex.h>
20 21
@@ -51,4 +52,20 @@ void v4l2_clk_disable(struct v4l2_clk *clk);
51unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk); 52unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk);
52int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate); 53int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate);
53 54
55struct module;
56
57struct v4l2_clk *__v4l2_clk_register_fixed(const char *dev_id,
58 const char *id, unsigned long rate, struct module *owner);
59void v4l2_clk_unregister_fixed(struct v4l2_clk *clk);
60
61static inline struct v4l2_clk *v4l2_clk_register_fixed(const char *dev_id,
62 const char *id,
63 unsigned long rate)
64{
65 return __v4l2_clk_register_fixed(dev_id, id, rate, THIS_MODULE);
66}
67
68#define v4l2_clk_name_i2c(name, size, adap, client) snprintf(name, size, \
69 "%d-%04x", adap, client)
70
54#endif 71#endif
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index 16550c439008..48f974866f13 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -35,7 +35,7 @@
35 printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg) 35 printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg)
36 36
37#define v4l_client_printk(level, client, fmt, arg...) \ 37#define v4l_client_printk(level, client, fmt, arg...) \
38 v4l_printk(level, (client)->driver->driver.name, (client)->adapter, \ 38 v4l_printk(level, (client)->dev.driver->name, (client)->adapter, \
39 (client)->addr, fmt , ## arg) 39 (client)->addr, fmt , ## arg)
40 40
41#define v4l_err(client, fmt, arg...) \ 41#define v4l_err(client, fmt, arg...) \
@@ -86,7 +86,7 @@ int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
86 const char * const *menu_items); 86 const char * const *menu_items);
87const char *v4l2_ctrl_get_name(u32 id); 87const char *v4l2_ctrl_get_name(u32 id);
88const char * const *v4l2_ctrl_get_menu(u32 id); 88const char * const *v4l2_ctrl_get_menu(u32 id);
89const s64 const *v4l2_ctrl_get_int_menu(u32 id, u32 *len); 89const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
90int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def); 90int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def);
91int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, 91int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu,
92 struct v4l2_queryctrl *qctrl, const char * const *menu_items); 92 struct v4l2_queryctrl *qctrl, const char * const *menu_items);
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index 47ada23345a1..16f7f2606516 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -571,7 +571,7 @@ static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
571 mutex_lock(ctrl->handler->lock); 571 mutex_lock(ctrl->handler->lock);
572} 572}
573 573
574/** v4l2_ctrl_lock() - Helper function to unlock the handler 574/** v4l2_ctrl_unlock() - Helper function to unlock the handler
575 * associated with the control. 575 * associated with the control.
576 * @ctrl: The control to unlock. 576 * @ctrl: The control to unlock.
577 */ 577 */
diff --git a/include/media/v4l2-fh.h b/include/media/v4l2-fh.h
index a62ee18cb7b7..528cdaf622e1 100644
--- a/include/media/v4l2-fh.h
+++ b/include/media/v4l2-fh.h
@@ -26,7 +26,9 @@
26#ifndef V4L2_FH_H 26#ifndef V4L2_FH_H
27#define V4L2_FH_H 27#define V4L2_FH_H
28 28
29#include <linux/fs.h>
29#include <linux/list.h> 30#include <linux/list.h>
31#include <linux/videodev2.h>
30 32
31struct video_device; 33struct video_device;
32struct v4l2_ctrl_handler; 34struct v4l2_ctrl_handler;
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index bfda0fe9aeb0..d67210a37ef3 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -559,6 +559,17 @@ struct v4l2_subdev_internal_ops {
559/* Set this flag if this subdev generates events. */ 559/* Set this flag if this subdev generates events. */
560#define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3) 560#define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
561 561
562struct regulator_bulk_data;
563
564struct v4l2_subdev_platform_data {
565 /* Optional regulators uset to power on/off the subdevice */
566 struct regulator_bulk_data *regulators;
567 int num_regulators;
568
569 /* Per-subdevice data, specific for a certain video host device */
570 void *host_priv;
571};
572
562/* Each instance of a subdev driver should create this struct, either 573/* Each instance of a subdev driver should create this struct, either
563 stand-alone or embedded in a larger struct. 574 stand-alone or embedded in a larger struct.
564 */ 575 */
@@ -592,6 +603,8 @@ struct v4l2_subdev {
592 struct v4l2_async_subdev *asd; 603 struct v4l2_async_subdev *asd;
593 /* Pointer to the managing notifier. */ 604 /* Pointer to the managing notifier. */
594 struct v4l2_async_notifier *notifier; 605 struct v4l2_async_notifier *notifier;
606 /* common part of subdevice platform data */
607 struct v4l2_subdev_platform_data *pdata;
595}; 608};
596 609
597#define media_entity_to_v4l2_subdev(ent) \ 610#define media_entity_to_v4l2_subdev(ent) \
@@ -622,13 +635,13 @@ struct v4l2_subdev_fh {
622 v4l2_subdev_get_try_##fun_name(struct v4l2_subdev_fh *fh, \ 635 v4l2_subdev_get_try_##fun_name(struct v4l2_subdev_fh *fh, \
623 unsigned int pad) \ 636 unsigned int pad) \
624 { \ 637 { \
625 BUG_ON(unlikely(pad >= vdev_to_v4l2_subdev( \ 638 BUG_ON(pad >= vdev_to_v4l2_subdev( \
626 fh->vfh.vdev)->entity.num_pads)); \ 639 fh->vfh.vdev)->entity.num_pads); \
627 return &fh->pad[pad].field_name; \ 640 return &fh->pad[pad].field_name; \
628 } 641 }
629 642
630__V4L2_SUBDEV_MK_GET_TRY(v4l2_mbus_framefmt, format, try_fmt) 643__V4L2_SUBDEV_MK_GET_TRY(v4l2_mbus_framefmt, format, try_fmt)
631__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, crop, try_compose) 644__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, crop, try_crop)
632__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, compose, try_compose) 645__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, compose, try_compose)
633#endif 646#endif
634 647
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 6781258d0b67..bd8218b15009 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -391,7 +391,7 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
391unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait); 391unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
392size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count, 392size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
393 loff_t *ppos, int nonblock); 393 loff_t *ppos, int nonblock);
394size_t vb2_write(struct vb2_queue *q, char __user *data, size_t count, 394size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
395 loff_t *ppos, int nonblock); 395 loff_t *ppos, int nonblock);
396 396
397/** 397/**
@@ -491,7 +491,7 @@ int vb2_ioctl_expbuf(struct file *file, void *priv,
491 491
492int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma); 492int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma);
493int vb2_fop_release(struct file *file); 493int vb2_fop_release(struct file *file);
494ssize_t vb2_fop_write(struct file *file, char __user *buf, 494ssize_t vb2_fop_write(struct file *file, const char __user *buf,
495 size_t count, loff_t *ppos); 495 size_t count, loff_t *ppos);
496ssize_t vb2_fop_read(struct file *file, char __user *buf, 496ssize_t vb2_fop_read(struct file *file, char __user *buf,
497 size_t count, loff_t *ppos); 497 size_t count, loff_t *ppos);
diff --git a/include/media/videobuf2-dma-sg.h b/include/media/videobuf2-dma-sg.h
index 0038526b8ef7..7b89852779af 100644
--- a/include/media/videobuf2-dma-sg.h
+++ b/include/media/videobuf2-dma-sg.h
@@ -15,16 +15,10 @@
15 15
16#include <media/videobuf2-core.h> 16#include <media/videobuf2-core.h>
17 17
18struct vb2_dma_sg_desc { 18static inline struct sg_table *vb2_dma_sg_plane_desc(
19 unsigned long size;
20 unsigned int num_pages;
21 struct scatterlist *sglist;
22};
23
24static inline struct vb2_dma_sg_desc *vb2_dma_sg_plane_desc(
25 struct vb2_buffer *vb, unsigned int plane_no) 19 struct vb2_buffer *vb, unsigned int plane_no)
26{ 20{
27 return (struct vb2_dma_sg_desc *)vb2_plane_cookie(vb, plane_no); 21 return (struct sg_table *)vb2_plane_cookie(vb, plane_no);
28} 22}
29 23
30extern const struct vb2_mem_ops vb2_dma_sg_memops; 24extern const struct vb2_mem_ops vb2_dma_sg_memops;
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index e393171e2fac..979874c627ee 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -67,12 +67,14 @@ enum rdma_node_type {
67 RDMA_NODE_IB_CA = 1, 67 RDMA_NODE_IB_CA = 1,
68 RDMA_NODE_IB_SWITCH, 68 RDMA_NODE_IB_SWITCH,
69 RDMA_NODE_IB_ROUTER, 69 RDMA_NODE_IB_ROUTER,
70 RDMA_NODE_RNIC 70 RDMA_NODE_RNIC,
71 RDMA_NODE_USNIC,
71}; 72};
72 73
73enum rdma_transport_type { 74enum rdma_transport_type {
74 RDMA_TRANSPORT_IB, 75 RDMA_TRANSPORT_IB,
75 RDMA_TRANSPORT_IWARP 76 RDMA_TRANSPORT_IWARP,
77 RDMA_TRANSPORT_USNIC
76}; 78};
77 79
78enum rdma_transport_type 80enum rdma_transport_type
@@ -1436,6 +1438,7 @@ struct ib_device {
1436 1438
1437 int uverbs_abi_ver; 1439 int uverbs_abi_ver;
1438 u64 uverbs_cmd_mask; 1440 u64 uverbs_cmd_mask;
1441 u64 uverbs_ex_cmd_mask;
1439 1442
1440 char node_desc[64]; 1443 char node_desc[64];
1441 __be64 node_guid; 1444 __be64 node_guid;
@@ -2384,4 +2387,17 @@ struct ib_flow *ib_create_flow(struct ib_qp *qp,
2384 struct ib_flow_attr *flow_attr, int domain); 2387 struct ib_flow_attr *flow_attr, int domain);
2385int ib_destroy_flow(struct ib_flow *flow_id); 2388int ib_destroy_flow(struct ib_flow *flow_id);
2386 2389
2390static inline int ib_check_mr_access(int flags)
2391{
2392 /*
2393 * Local write permission is required if remote write or
2394 * remote atomic permission is also requested.
2395 */
2396 if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
2397 !(flags & IB_ACCESS_LOCAL_WRITE))
2398 return -EINVAL;
2399
2400 return 0;
2401}
2402
2387#endif /* IB_VERBS_H */ 2403#endif /* IB_VERBS_H */
diff --git a/include/scsi/scsi_transport_srp.h b/include/scsi/scsi_transport_srp.h
index ff0f04ac91aa..4ebf6913b7b2 100644
--- a/include/scsi/scsi_transport_srp.h
+++ b/include/scsi/scsi_transport_srp.h
@@ -13,6 +13,27 @@ struct srp_rport_identifiers {
13 u8 roles; 13 u8 roles;
14}; 14};
15 15
16/**
17 * enum srp_rport_state - SRP transport layer state
18 * @SRP_RPORT_RUNNING: Transport layer operational.
19 * @SRP_RPORT_BLOCKED: Transport layer not operational; fast I/O fail timer
20 * is running and I/O has been blocked.
21 * @SRP_RPORT_FAIL_FAST: Fast I/O fail timer has expired; fail I/O fast.
22 * @SRP_RPORT_LOST: Device loss timer has expired; port is being removed.
23 */
24enum srp_rport_state {
25 SRP_RPORT_RUNNING,
26 SRP_RPORT_BLOCKED,
27 SRP_RPORT_FAIL_FAST,
28 SRP_RPORT_LOST,
29};
30
31/**
32 * struct srp_rport
33 * @lld_data: LLD private data.
34 * @mutex: Protects against concurrent rport reconnect / fast_io_fail /
35 * dev_loss_tmo activity.
36 */
16struct srp_rport { 37struct srp_rport {
17 /* for initiator and target drivers */ 38 /* for initiator and target drivers */
18 39
@@ -23,11 +44,43 @@ struct srp_rport {
23 44
24 /* for initiator drivers */ 45 /* for initiator drivers */
25 46
26 void *lld_data; /* LLD private data */ 47 void *lld_data;
48
49 struct mutex mutex;
50 enum srp_rport_state state;
51 bool deleted;
52 int reconnect_delay;
53 int failed_reconnects;
54 struct delayed_work reconnect_work;
55 int fast_io_fail_tmo;
56 int dev_loss_tmo;
57 struct delayed_work fast_io_fail_work;
58 struct delayed_work dev_loss_work;
27}; 59};
28 60
61/**
62 * struct srp_function_template
63 * @has_rport_state: Whether or not to create the state, fast_io_fail_tmo and
64 * dev_loss_tmo sysfs attribute for an rport.
65 * @reset_timer_if_blocked: Whether or srp_timed_out() should reset the command
66 * timer if the device on which it has been queued is blocked.
67 * @reconnect_delay: If not NULL, points to the default reconnect_delay value.
68 * @fast_io_fail_tmo: If not NULL, points to the default fast_io_fail_tmo value.
69 * @dev_loss_tmo: If not NULL, points to the default dev_loss_tmo value.
70 * @reconnect: Callback function for reconnecting to the target. See also
71 * srp_reconnect_rport().
72 * @terminate_rport_io: Callback function for terminating all outstanding I/O
73 * requests for an rport.
74 */
29struct srp_function_template { 75struct srp_function_template {
30 /* for initiator drivers */ 76 /* for initiator drivers */
77 bool has_rport_state;
78 bool reset_timer_if_blocked;
79 int *reconnect_delay;
80 int *fast_io_fail_tmo;
81 int *dev_loss_tmo;
82 int (*reconnect)(struct srp_rport *rport);
83 void (*terminate_rport_io)(struct srp_rport *rport);
31 void (*rport_delete)(struct srp_rport *rport); 84 void (*rport_delete)(struct srp_rport *rport);
32 /* for target drivers */ 85 /* for target drivers */
33 int (* tsk_mgmt_response)(struct Scsi_Host *, u64, u64, int); 86 int (* tsk_mgmt_response)(struct Scsi_Host *, u64, u64, int);
@@ -38,10 +91,36 @@ extern struct scsi_transport_template *
38srp_attach_transport(struct srp_function_template *); 91srp_attach_transport(struct srp_function_template *);
39extern void srp_release_transport(struct scsi_transport_template *); 92extern void srp_release_transport(struct scsi_transport_template *);
40 93
94extern void srp_rport_get(struct srp_rport *rport);
95extern void srp_rport_put(struct srp_rport *rport);
41extern struct srp_rport *srp_rport_add(struct Scsi_Host *, 96extern struct srp_rport *srp_rport_add(struct Scsi_Host *,
42 struct srp_rport_identifiers *); 97 struct srp_rport_identifiers *);
43extern void srp_rport_del(struct srp_rport *); 98extern void srp_rport_del(struct srp_rport *);
44 99extern int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo,
100 int dev_loss_tmo);
101extern int srp_reconnect_rport(struct srp_rport *rport);
102extern void srp_start_tl_fail_timers(struct srp_rport *rport);
45extern void srp_remove_host(struct Scsi_Host *); 103extern void srp_remove_host(struct Scsi_Host *);
46 104
105/**
106 * srp_chkready() - evaluate the transport layer state before I/O
107 *
108 * Returns a SCSI result code that can be returned by the LLD queuecommand()
109 * implementation. The role of this function is similar to that of
110 * fc_remote_port_chkready().
111 */
112static inline int srp_chkready(struct srp_rport *rport)
113{
114 switch (rport->state) {
115 case SRP_RPORT_RUNNING:
116 case SRP_RPORT_BLOCKED:
117 default:
118 return 0;
119 case SRP_RPORT_FAIL_FAST:
120 return DID_TRANSPORT_FAILFAST << 16;
121 case SRP_RPORT_LOST:
122 return DID_NO_CONNECT << 16;
123 }
124}
125
47#endif 126#endif
diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
index 083bb5a5aae2..1666aabbbb86 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -160,6 +160,10 @@ enum v4l2_colorfx {
160 * of controls. Total of 16 controls is reserved for this driver */ 160 * of controls. Total of 16 controls is reserved for this driver */
161#define V4L2_CID_USER_SI476X_BASE (V4L2_CID_USER_BASE + 0x1040) 161#define V4L2_CID_USER_SI476X_BASE (V4L2_CID_USER_BASE + 0x1040)
162 162
163/* The base for the TI VPE driver controls. Total of 16 controls is reserved for
164 * this driver */
165#define V4L2_CID_USER_TI_VPE_BASE (V4L2_CID_USER_BASE + 0x1050)
166
163/* MPEG-class control IDs */ 167/* MPEG-class control IDs */
164/* The MPEG controls are applicable to all codec controls 168/* The MPEG controls are applicable to all codec controls
165 * and the 'MPEG' part of the define is historical */ 169 * and the 'MPEG' part of the define is historical */
diff --git a/include/uapi/rdma/ib_user_verbs.h b/include/uapi/rdma/ib_user_verbs.h
index e3ddd86c90a6..cbfdd4ca9510 100644
--- a/include/uapi/rdma/ib_user_verbs.h
+++ b/include/uapi/rdma/ib_user_verbs.h
@@ -87,10 +87,11 @@ enum {
87 IB_USER_VERBS_CMD_CLOSE_XRCD, 87 IB_USER_VERBS_CMD_CLOSE_XRCD,
88 IB_USER_VERBS_CMD_CREATE_XSRQ, 88 IB_USER_VERBS_CMD_CREATE_XSRQ,
89 IB_USER_VERBS_CMD_OPEN_QP, 89 IB_USER_VERBS_CMD_OPEN_QP,
90#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING 90};
91 IB_USER_VERBS_CMD_CREATE_FLOW = IB_USER_VERBS_CMD_THRESHOLD, 91
92 IB_USER_VERBS_CMD_DESTROY_FLOW 92enum {
93#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */ 93 IB_USER_VERBS_EX_CMD_CREATE_FLOW = IB_USER_VERBS_CMD_THRESHOLD,
94 IB_USER_VERBS_EX_CMD_DESTROY_FLOW
94}; 95};
95 96
96/* 97/*
@@ -122,22 +123,24 @@ struct ib_uverbs_comp_event_desc {
122 * the rest of the command struct based on these value. 123 * the rest of the command struct based on these value.
123 */ 124 */
124 125
126#define IB_USER_VERBS_CMD_COMMAND_MASK 0xff
127#define IB_USER_VERBS_CMD_FLAGS_MASK 0xff000000u
128#define IB_USER_VERBS_CMD_FLAGS_SHIFT 24
129
130#define IB_USER_VERBS_CMD_FLAG_EXTENDED 0x80
131
125struct ib_uverbs_cmd_hdr { 132struct ib_uverbs_cmd_hdr {
126 __u32 command; 133 __u32 command;
127 __u16 in_words; 134 __u16 in_words;
128 __u16 out_words; 135 __u16 out_words;
129}; 136};
130 137
131#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING 138struct ib_uverbs_ex_cmd_hdr {
132struct ib_uverbs_cmd_hdr_ex { 139 __u64 response;
133 __u32 command;
134 __u16 in_words;
135 __u16 out_words;
136 __u16 provider_in_words; 140 __u16 provider_in_words;
137 __u16 provider_out_words; 141 __u16 provider_out_words;
138 __u32 cmd_hdr_reserved; 142 __u32 cmd_hdr_reserved;
139}; 143};
140#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
141 144
142struct ib_uverbs_get_context { 145struct ib_uverbs_get_context {
143 __u64 response; 146 __u64 response;
@@ -700,62 +703,71 @@ struct ib_uverbs_detach_mcast {
700 __u64 driver_data[0]; 703 __u64 driver_data[0];
701}; 704};
702 705
703#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING 706struct ib_uverbs_flow_spec_hdr {
704struct ib_kern_eth_filter { 707 __u32 type;
708 __u16 size;
709 __u16 reserved;
710 /* followed by flow_spec */
711 __u64 flow_spec_data[0];
712};
713
714struct ib_uverbs_flow_eth_filter {
705 __u8 dst_mac[6]; 715 __u8 dst_mac[6];
706 __u8 src_mac[6]; 716 __u8 src_mac[6];
707 __be16 ether_type; 717 __be16 ether_type;
708 __be16 vlan_tag; 718 __be16 vlan_tag;
709}; 719};
710 720
711struct ib_kern_spec_eth { 721struct ib_uverbs_flow_spec_eth {
712 __u32 type; 722 union {
713 __u16 size; 723 struct ib_uverbs_flow_spec_hdr hdr;
714 __u16 reserved; 724 struct {
715 struct ib_kern_eth_filter val; 725 __u32 type;
716 struct ib_kern_eth_filter mask; 726 __u16 size;
727 __u16 reserved;
728 };
729 };
730 struct ib_uverbs_flow_eth_filter val;
731 struct ib_uverbs_flow_eth_filter mask;
717}; 732};
718 733
719struct ib_kern_ipv4_filter { 734struct ib_uverbs_flow_ipv4_filter {
720 __be32 src_ip; 735 __be32 src_ip;
721 __be32 dst_ip; 736 __be32 dst_ip;
722}; 737};
723 738
724struct ib_kern_spec_ipv4 { 739struct ib_uverbs_flow_spec_ipv4 {
725 __u32 type; 740 union {
726 __u16 size; 741 struct ib_uverbs_flow_spec_hdr hdr;
727 __u16 reserved; 742 struct {
728 struct ib_kern_ipv4_filter val; 743 __u32 type;
729 struct ib_kern_ipv4_filter mask; 744 __u16 size;
745 __u16 reserved;
746 };
747 };
748 struct ib_uverbs_flow_ipv4_filter val;
749 struct ib_uverbs_flow_ipv4_filter mask;
730}; 750};
731 751
732struct ib_kern_tcp_udp_filter { 752struct ib_uverbs_flow_tcp_udp_filter {
733 __be16 dst_port; 753 __be16 dst_port;
734 __be16 src_port; 754 __be16 src_port;
735}; 755};
736 756
737struct ib_kern_spec_tcp_udp { 757struct ib_uverbs_flow_spec_tcp_udp {
738 __u32 type;
739 __u16 size;
740 __u16 reserved;
741 struct ib_kern_tcp_udp_filter val;
742 struct ib_kern_tcp_udp_filter mask;
743};
744
745struct ib_kern_spec {
746 union { 758 union {
759 struct ib_uverbs_flow_spec_hdr hdr;
747 struct { 760 struct {
748 __u32 type; 761 __u32 type;
749 __u16 size; 762 __u16 size;
750 __u16 reserved; 763 __u16 reserved;
751 }; 764 };
752 struct ib_kern_spec_eth eth;
753 struct ib_kern_spec_ipv4 ipv4;
754 struct ib_kern_spec_tcp_udp tcp_udp;
755 }; 765 };
766 struct ib_uverbs_flow_tcp_udp_filter val;
767 struct ib_uverbs_flow_tcp_udp_filter mask;
756}; 768};
757 769
758struct ib_kern_flow_attr { 770struct ib_uverbs_flow_attr {
759 __u32 type; 771 __u32 type;
760 __u16 size; 772 __u16 size;
761 __u16 priority; 773 __u16 priority;
@@ -767,13 +779,13 @@ struct ib_kern_flow_attr {
767 * struct ib_flow_spec_xxx 779 * struct ib_flow_spec_xxx
768 * struct ib_flow_spec_yyy 780 * struct ib_flow_spec_yyy
769 */ 781 */
782 struct ib_uverbs_flow_spec_hdr flow_specs[0];
770}; 783};
771 784
772struct ib_uverbs_create_flow { 785struct ib_uverbs_create_flow {
773 __u32 comp_mask; 786 __u32 comp_mask;
774 __u64 response;
775 __u32 qp_handle; 787 __u32 qp_handle;
776 struct ib_kern_flow_attr flow_attr; 788 struct ib_uverbs_flow_attr flow_attr;
777}; 789};
778 790
779struct ib_uverbs_create_flow_resp { 791struct ib_uverbs_create_flow_resp {
@@ -785,7 +797,6 @@ struct ib_uverbs_destroy_flow {
785 __u32 comp_mask; 797 __u32 comp_mask;
786 __u32 flow_handle; 798 __u32 flow_handle;
787}; 799};
788#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
789 800
790struct ib_uverbs_create_srq { 801struct ib_uverbs_create_srq {
791 __u64 response; 802 __u64 response;
diff --git a/kernel/bounds.c b/kernel/bounds.c
index 578782ef6ae1..5253204afdca 100644
--- a/kernel/bounds.c
+++ b/kernel/bounds.c
@@ -11,7 +11,7 @@
11#include <linux/kbuild.h> 11#include <linux/kbuild.h>
12#include <linux/page_cgroup.h> 12#include <linux/page_cgroup.h>
13#include <linux/log2.h> 13#include <linux/log2.h>
14#include <linux/spinlock.h> 14#include <linux/spinlock_types.h>
15 15
16void foo(void) 16void foo(void)
17{ 17{
diff --git a/kernel/irq/settings.h b/kernel/irq/settings.h
index 1162f1030f18..3320b84cc60f 100644
--- a/kernel/irq/settings.h
+++ b/kernel/irq/settings.h
@@ -14,6 +14,7 @@ enum {
14 _IRQ_NO_BALANCING = IRQ_NO_BALANCING, 14 _IRQ_NO_BALANCING = IRQ_NO_BALANCING,
15 _IRQ_NESTED_THREAD = IRQ_NESTED_THREAD, 15 _IRQ_NESTED_THREAD = IRQ_NESTED_THREAD,
16 _IRQ_PER_CPU_DEVID = IRQ_PER_CPU_DEVID, 16 _IRQ_PER_CPU_DEVID = IRQ_PER_CPU_DEVID,
17 _IRQ_IS_POLLED = IRQ_IS_POLLED,
17 _IRQF_MODIFY_MASK = IRQF_MODIFY_MASK, 18 _IRQF_MODIFY_MASK = IRQF_MODIFY_MASK,
18}; 19};
19 20
@@ -26,6 +27,7 @@ enum {
26#define IRQ_NOAUTOEN GOT_YOU_MORON 27#define IRQ_NOAUTOEN GOT_YOU_MORON
27#define IRQ_NESTED_THREAD GOT_YOU_MORON 28#define IRQ_NESTED_THREAD GOT_YOU_MORON
28#define IRQ_PER_CPU_DEVID GOT_YOU_MORON 29#define IRQ_PER_CPU_DEVID GOT_YOU_MORON
30#define IRQ_IS_POLLED GOT_YOU_MORON
29#undef IRQF_MODIFY_MASK 31#undef IRQF_MODIFY_MASK
30#define IRQF_MODIFY_MASK GOT_YOU_MORON 32#define IRQF_MODIFY_MASK GOT_YOU_MORON
31 33
@@ -147,3 +149,8 @@ static inline bool irq_settings_is_nested_thread(struct irq_desc *desc)
147{ 149{
148 return desc->status_use_accessors & _IRQ_NESTED_THREAD; 150 return desc->status_use_accessors & _IRQ_NESTED_THREAD;
149} 151}
152
153static inline bool irq_settings_is_polled(struct irq_desc *desc)
154{
155 return desc->status_use_accessors & _IRQ_IS_POLLED;
156}
diff --git a/kernel/irq/spurious.c b/kernel/irq/spurious.c
index 7b5f012bde9d..a1d8cc63b56e 100644
--- a/kernel/irq/spurious.c
+++ b/kernel/irq/spurious.c
@@ -67,8 +67,13 @@ static int try_one_irq(int irq, struct irq_desc *desc, bool force)
67 67
68 raw_spin_lock(&desc->lock); 68 raw_spin_lock(&desc->lock);
69 69
70 /* PER_CPU and nested thread interrupts are never polled */ 70 /*
71 if (irq_settings_is_per_cpu(desc) || irq_settings_is_nested_thread(desc)) 71 * PER_CPU, nested thread interrupts and interrupts explicitely
72 * marked polled are excluded from polling.
73 */
74 if (irq_settings_is_per_cpu(desc) ||
75 irq_settings_is_nested_thread(desc) ||
76 irq_settings_is_polled(desc))
72 goto out; 77 goto out;
73 78
74 /* 79 /*
@@ -268,7 +273,8 @@ try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
268void note_interrupt(unsigned int irq, struct irq_desc *desc, 273void note_interrupt(unsigned int irq, struct irq_desc *desc,
269 irqreturn_t action_ret) 274 irqreturn_t action_ret)
270{ 275{
271 if (desc->istate & IRQS_POLL_INPROGRESS) 276 if (desc->istate & IRQS_POLL_INPROGRESS ||
277 irq_settings_is_polled(desc))
272 return; 278 return;
273 279
274 /* we get here again via the threaded handler */ 280 /* we get here again via the threaded handler */
diff --git a/sound/ppc/keywest.c b/sound/ppc/keywest.c
index 01aecc2b5073..0d1c27e911b8 100644
--- a/sound/ppc/keywest.c
+++ b/sound/ppc/keywest.c
@@ -65,7 +65,7 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter)
65 * already bound. If not it means binding failed, and then there 65 * already bound. If not it means binding failed, and then there
66 * is no point in keeping the device instantiated. 66 * is no point in keeping the device instantiated.
67 */ 67 */
68 if (!keywest_ctx->client->driver) { 68 if (!keywest_ctx->client->dev.driver) {
69 i2c_unregister_device(keywest_ctx->client); 69 i2c_unregister_device(keywest_ctx->client);
70 keywest_ctx->client = NULL; 70 keywest_ctx->client = NULL;
71 return -ENODEV; 71 return -ENODEV;
@@ -76,7 +76,7 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter)
76 * This is safe because i2c-core holds the core_lock mutex for us. 76 * This is safe because i2c-core holds the core_lock mutex for us.
77 */ 77 */
78 list_add_tail(&keywest_ctx->client->detected, 78 list_add_tail(&keywest_ctx->client->detected,
79 &keywest_ctx->client->driver->clients); 79 &to_i2c_driver(keywest_ctx->client->dev.driver)->clients);
80 return 0; 80 return 0;
81} 81}
82 82
diff --git a/sound/soc/fsl/imx-wm8962.c b/sound/soc/fsl/imx-wm8962.c
index 361f94f09b11..61e48852b9e8 100644
--- a/sound/soc/fsl/imx-wm8962.c
+++ b/sound/soc/fsl/imx-wm8962.c
@@ -215,7 +215,7 @@ static int imx_wm8962_probe(struct platform_device *pdev)
215 goto fail; 215 goto fail;
216 } 216 }
217 codec_dev = of_find_i2c_device_by_node(codec_np); 217 codec_dev = of_find_i2c_device_by_node(codec_np);
218 if (!codec_dev || !codec_dev->driver) { 218 if (!codec_dev || !codec_dev->dev.driver) {
219 dev_err(&pdev->dev, "failed to find codec platform device\n"); 219 dev_err(&pdev->dev, "failed to find codec platform device\n");
220 ret = -EINVAL; 220 ret = -EINVAL;
221 goto fail; 221 goto fail;